Makefile ZT easily

xiaoxiao2021-03-06  46

Makefile Xu Meming Yansi

If you use Red Hat Linux to find all the above-mentioned soft rpm files, FreeBSD also has ready-made packages to install directly, or you can also download the original gear back DIY. The following example is done in the environment of Red Hat Linux 5.2 CLE2. 3. A simple example

The Makefile generated by Automake can also make the program compilation and links.

How to generate program files (such as Manual Page, INFO files, DVI files)

Taking the original program package to disperse, it is considered, so the original program is stored.

The directory architecture is best in line with GNU standard practice, and I will take Hello.c as an example.

child.

Built a new subdirectory in the working directory, then build a one under the DEVEL

`` Hello '' subdirectory, this directory will be used as us to store this Hello and related

Places of archives:

% MKDir Devel

% CD Devel

% MKDIR Hello

% CD Hello

Write a Hello.c file with the editor.

#include

INT main (int Argc, char ** argv)

{

Printf (`` Hello, GNU! / n ');

Return 0;

}

Next, use AutoConf and Automake to help us produce your Makefile file.

1. Produce a sharxt of configure.in with AutoScan, perform AutoScan

Have a configure.scan file, we can use it as configure.in

Set of blueprints.

% AutoScan

% LS

Configure.scan hello.c

2. Edit the configure.scan file, as shown below, and change its file name

Configure.in

DNL Process this file with autoc to produce a conce

Fighe script.

AC_INIT (Hello.c)

AM_INIT_AUTOMAKE (Hello, 1.0)

DNL CHECKS for Program.

AC_PROG_CC

DNL CHECKS for Libraries.

DNL CHECKS for Header Files.

DNL CHECKS for Typedefs, Structures, And Compiler Ch

Aracteristics.

DNL Checks for Library Functions.

AC_OUTPUT (MAKEFILE)

3. Execute aclocal and autoconf, which generate ACLOCAL.M4 and CONFIGUREs.

File

% ACLOCAL

% AutoConf

% LS

Aclocal.m4 configure configure.in Hello.c

4. Edit the Makefile.Am file, the content is as follows

Automake_Options = Foreign

BIN_PROGRAMS = Hello

Hello_sources = Hello.c

5. Execute Automake --Add-missing, Automake will generate according to Makefile.Am file

Some files contain the most important makefile.in

% Automake --Add-missing

Automake: configure.in: installing `./install-sh'automake: configure.in: installing`/mkinstalldirs'

Automake: configure.in: installing `./missing '

6. Finally, execute ./configure,

% ./configure

Creating cache ./config.cache

Checking for a BSD Compatible Install ... / usr / bin / in

Stall -c

Checking WHether Build Environment Is Sane ... YES

Checking WHETHER Make Set $ ​​{make} ... YES

Checking for Working Aclocal ... Found

Checking for Working AutoConf ... Found

Checking for Working Automake ... Found

Checking for Working AutoHeader ... found

Checking for working makeinfo ... found

Checking for GCC ... GCC

Checking WHETHER THE C Compiler (GCC) Works ... YES

Checking WHETHER THE C Compiler (GCC) IS A Cross-Co Mpiler ... no

Checking WHETHER WE Are Using GNU C ... YES

Checking WHETER GCC Accepts -g ... YES

Updating cache ./config.cache

Creating ./config.status

Creating makefile

Now you have produced a Makefile file in your directory, the next `` Make '' directive

Start compilation of Hello.c into executive files, execute ./hello and gnu sound!

% make

GCC -DPackage = / "Hello /" -dversion = / "1.0 /" -i. -i. -g -O2 -c HE

Llo.c

GCC -G -O2 -O Hello Hello.o

% ./hello

Hello! GNU!

You can also try `` make clean ',' 'make install' ',' 'make dist' '

What is the result. You can also give your boss, let him

This is a look at you :-)

4. A exploration

The above process of producing Makefile is very different from the way it is written in the past, abandoning the tradition

Define the rules of make, using Automake only need to use some of the already defined giant

I.e. We write the giant set and goals (Target) in the Makefile.Am file, Automake

After reading the Makefile.Am file, this string has defined this string to expand and generate the corresponding

Makefile.in file, then then by configure this shell script

Makefile.in produces suitable Makefile.

[Figure 1: Process for producing Makefile using AutoConf and Automake]

The above figure shows the files you want to use in the examples in the previous section and the generated files, as an asterisk

(*) Represents the executable file. In this example, you can use the AutoConf and Automake Tools.

The generated file has configure.scan, ACLOCAL.M4, Configure, Makefile.in,

We need to join the settlers for configure.in and makefile.am.

4.1 Edit Configure.in

AutoConf is a tool for generating a 'configure' file. 'configure' is a

Shell Script, which automatically sets the original program to meet the Unix system on a variety of different platforms

The characteristics of the system, and produce a suitable Makefile file or C standard according to the system parameters and the environment.

Header file, allowing the original program to be easily edited on these different platforms

Translated. AutoConf reads the configure.in file and generates 'configure'.

Shell script.

The content of the Configure.in file is a series of gnu m4, these giants have passed

The autoconf will become a shell script for checking system features. Configure.in

The order of the gap is not particularly regulations, but every configure.in file must be all

Join the AC_INIT gather before gathering, then add AC_OUTPUT giant at the end of all gauges

set. We can first scan the original gear with AutoScan to generate a configure.scan file.

Do some modifications to configure.scan to configure.IN files. Used in the example

The gauge is as follows:

DNL

The words behind this gather will not be processed and can be considered as an annotation.

AC_INIT (File)

This gauge is used to check the path where the original code is located, and AutoScan will automatically generate, we

Don't modify it.

AM_INIT_AUTOMAKE (Package, Version)

This is the huge set of automake, and package is the soft cover we have to produce.

The name of the part, Version is the version number.

AC_PROG_CC

Check the C compiler available to the system. If the original program is written with C, you need this giant.

set.

AC_OUTPUT (File)

Set the file to be generated by configure, if it is makefile,

Configure will take the result of it checks into the Makefile.IN file and then generate

Suitable Makefile.

In fact, when we use Automake, we must also have some other gatherings, these extra giants

Set us with ACLOCAL to help us. Perform ACLOCAL will generate aclocal.m4

Set, if there is no special purpose, we can do not need to modify it, the giant generated by ACLOCAL

I will tell Automake how to do it.

With the two files with configure.in and aclocal.m4, you can do AutoConf.

To generate Configure files.

4.2 Edit Makefile.Am

Next we want to edit the makefile.Am file, Automake will be based on configure.in

The gauge turns made to makefile.IN file. Makefile.Am file definitions we

The goal to produce:

Automake_Options

Set the option of Automake. Automake is mainly helping to develop a GNU software.

Maintain the software kit, so when executing Automake, check if there is a standard in the directory

The file files should be provided in the gnu software kit, such as file files such as 'News', 'Author', 'Changelog'. Automake will be gently soft when it is foreign.

The standard of the body kit is checked.

BIN_PROGRAMS

Define the implementation file name we have to produce. If you want to generate multiple execution files, each file name

Separate with a blank character.

Hello_sources

Define the original file required by 'Hello'. If 'Hello'

It is generated by multiple original files, and the original files used to be used must be listed.

The character is separated. Suppose the 'Hello' is needed to 'Hello.c', 'main.c',

Definition of three files of 'hello.h'

Hello_sources = hello.c main.c hello.h

If we define multiple execution files, you must define relative to each execution file.

Filename_sources.

Edit your Makefile.AM file, you can use Automake --Add-missing to generate

Makefile.in. Plus - ADD-MISSING Options is to tell Automake to help us

Enter the files necessary for packaging a software kit. AUTOMAKE produced made made of makefile.in

The file is completely conforming to the GNU Makefile, we only need to perform configure

Shell Script can produce a suitable Makefile file.

4.3 Using Makefile

There are several preset targets that use the makefile file generated by Configure to use, we

Just take the following brief description as follows:

Make ALL produces the target we set, that is, the execution file in this example. Only Make can also be compiled, and then the original code is started, and then connect, and the execution file is generated. Make Clean Clears the previously compiled executive file (Object file, * .o). The Make DistClean is also cleared by clearing the Makefile generated by Configure in addition to clearing the execution file and destination. Make Install is installed into the system. If the original code is compiled, and the execution result is correct, it can be installed to the system preset execution file storage path. If we use bin_programs to gather, the program will be installed to / usr / local / bin. Make Dist Package the program and related files into a compressed file for district. It will generate a file that is named by package-version.tar.gz executing. Package and Version These two variables are defined by am_init_automake (package, version) in the configure.in file. In this example, 'Hello-1.0.Tar.gz' file will be generated. Make DistCheck and make Dist are similar, but the addition of the compressive file after the package is normal. In addition to putting the program and the relevant file into tar.gz file, this automatically unspeak this compressed file, executes configure, and performs Make ALL's action. After confirming compilation, this tar.gz file is ready It is good for spreading. This check is non-commonly useful, check the kit, basically gives any people who have GNU development environment to recompile. In addition to Hello-1.Tar.gz, in addition to the red hat linux, you can also correctly recompile the FreeBSD 2.2.x. It should be noted that the software kit produced by using AutoConf and Automake is available in an environment where AutoConf and Automake is installed, because configure is a shell script, which is designed to execute under the SHELL of general Unix. . But if you want to modify the configure.in and makefile.Am files, you must have AutoConf and Automake when new Configure and makefile.in files are generated. 5. Related messages AutoConf and Automake feature are very powerful, you can find detailed usage from the INFO files they attach. You can also find related configure.in or makefile.Am files from many existing GNU software or Open Source software, which is the best example of learning AutoConf and Automake more techniques. This introduction only uses autoconf and automake's fur, if you join the ranks of open source software development, I hope this file can help you have a simple basis for generating makefile. Others related to the development of GNU program or C programming and Makefile, I suggest you read from GNU Coding Standards3 (GNU coding standard), which contains GNU Makefile conventions, as well as standard procedures for developing GNU software kits and Convention. These GNU software's online description files can be found on http://www.gnu.org/.

6. Conclusion Via AUTOCONF and Automake assistant, generating a makefile does not seem to be as difficult as before, and using AutoConf also makes us spread and compile the program between different platforms or Unix, this is A number of burden is reduced by developing programs on UNIX systems. Properly use these GNU tool software to help us easier to develop programs, and easier to maintain the original code. About this document ... easily generate Makefile1 This document was generated using the LaTeX2HTML translator Version 98.2 beta6 (August 14th, 1998) Copyright (C) 1993, 1994, 1995, 1996, Nikos Drakos, Computer Based Learning Unit, University of .. leeds Copyright (C) 1997, 1998, Ross Moore, Mathematics Department, Macquarie University, Sydney The command line arguments were: latex2html -split 0 -show_section_numbers automake.tex The translation was initiated by on 1999-02-11 Footnotes .. ./title1 This document uses ChiLatex production. ... Standards3 GNU Coding Standards, Richard Stallman. 1999-02-11Posted On September 13, 2004 5:18 PM

转载请注明原文地址:https://www.9cbs.com/read-117369.html

New Post(0)