Linux--autoconf and Automake use

Source: Internet
Author: User
Tags perl script automake

autoconf and Automake use

  

first, generate makefile flowchart

second, specific examples

Order of execution: AutoScan; aclocal; Autoconf Autoheader; Automake--add-missing;./configure; make;./helloworld;

1. Build Catalogue

Create a HelloWorld directory under your working directory to store HelloWorld programs and related files, such as under/home/my/build:

$ mkdir helloword$ CD HelloWorld

2, HELLOWORLD.C

Edit the file, and then save the exit after completion. Now in the HelloWorld directory there should be a helloworld.c you wrote yourself.

  int Main (intChar* * argv)        {printf ("");           return0

3. Generate Configure

After execution in the Hellowrold directory will generate a file: Configure.scan, you can take it as a blueprint for configure.ac.

4. Generate Configure.ac now rename Configure.scan to Configure.ac, and edit it, modify it as follows, and remove irrelevant statements:
#-*-Autoconf-*-# Process Thisfile with autoconf to produce a configure script. Ac_prereq ([2.69]) #AC_INIT ([ full-package-name], [VERSION], [bug-report-ADDRESS]) Ac_init (HelloWorld,1.0, [email protected]163. com) Am_init_automake (HelloWorld, 1.0 ) #这句话很重要, or the following aclocal error Ac_config_srcdir ([HELLOWORLD.C]) ac_config_headers ([config.h]) # Checks forprograms. AC_PROG_CC # Checks forlibraries. # Checks forheader files. # Checks fortypedefs, structures, and compiler characteristics. # Checks forLibrary functions. Ac_config_files ([Makefile]) Ac_output

5, the implementation of Aclocal and autoconf

Then execute the commands aclocal and autoconf, respectively, will produce ACLOCAL.M4 and configure two files:

$ aclocal $ls aclocal.m4 configure.ac helloworld.c $ autoconf $ ls aclocal.m4configure

You can see that the CONFIGURE.AC content is a macro definition that, after autoconf processing, becomes a shell script that examines system features, environment variables, and the parameters that the software must have.

Autoconf is a tool used to generate automatic configuration software source code scripts (configure). The Configure script can run independently of the autoconf and does not require user intervention during the run.

To generate the Configure file, you must tell autoconf how to find the macro you are using. The way is to use the Aclocal program to generate your ACLOCAL.M4.

Aclocal automatically generates ACLOCAL.M4 files based on the contents of the Configure.ac file. Aclocal is a Perl script that is defined as: "Aclocal-create aclocal.m4 by scanning configure.ac".

Autoconf creates configure from Configure.ac, a template file that enumerates the various parameters required to compile the software.

Autoconf needs the GNU M4 macro processor to handle ACLOCAL.M4, generating configure scripts.

M4 is a macro processor. Copies the input to the output while expanding the macro. A macro can be either inline or user-defined. In addition to the ability to expand macros, M4 also has built-in functions for referencing files, executing commands, integer arithmetic, text manipulation, looping, and so on. M4 can be either the front end of the compiler or a single macro processor.

6. Execute Autoheader autoheade before executing automake--add-missing, generate config.h.in 7, new makefile.am
automake_options=foreignbin_programs=helloworldhelloworld_sources

Automake will generate makefile.in based on the makefile.am you write. Macros and targets defined in makefile.am instruct Automake to generate the specified code. For example, macro Bin_programs will cause the compilation and connection targets to be generated.

8. Running Automake
? Autoconf_ Automake--add-Missingconfigure.ac:7: Warning:am_init_automake:two-and three-arguments forms are deprecated. For more info, See:configure.ac:7: http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocationConfigure.ac: A: Installing'./compile'Configure.ac:7: Installing'./install-sh'Configure.ac:7: Installing'./missing'Makefile.am:installing'./depcomp'

Automake will produce some files based on the makefile.am file, including the most important makefile.in.

9, execute configure generate makefile
? ./configurechecking forA bsd-compatible install .../usr/bin/install-cchecking whether build environment isSane ... yeschecking forA Thread-safe mkdir-p .... /install-sh-c-dchecking forgawk ... nochecking forMawk ... nochecking forNawk ... nochecking forawk ... awkchecking whether make sets $ (make) ... yeschecking whether make supports nested variables ... yeschecking  forgcc ... gccchecking whether the C compiler works ... yeschecking forC compilerdefaultOutput file name ... a. outchecking forsuffix of executables...checking whether we is cross compiling ... nochecking forSuffix ofObjectfiles ... ochecking whether we areusingThe GNU C compiler ... yeschecking whether GCC accepts-g ... yeschecking forgcc option to accept ISO C89 ... none neededchecking whether GCC understands-C and-o together ... yeschecking forstyle of include used by make ... Gnuchecking dependency style of gcc ... gcc3checking that generated files is newer than configure ... Doneconfigure:creati Ng./config.statusconfig.status:creating Makefileconfig.status:creating config.hconfig.status:executing depfiles Commands
?  ls-l Makefile
-rw-rw-r--1 Yutao yutao 15035 Oct 10:40 Makefile

As you can see, at this point the makefile has been produced.

10. Compiling code with Makefile
?  make/applications/xcode.app/contents/developer/usr/bin/make  all--dhave_config_h-i.     -G-O2-MT HELLOWORLD.O-MD-MP-MF. Deps/helloworld. Tpo-c-F. Deps/helloworld. Tpo. deps/HelloWorld. POGCC  -g-o2-   o HelloWorld helloworld.o

11. Running HelloWorld
?  . /HelloworldhelloWorld!!!!

This HelloWorld is compiled, if you follow the above steps to do, it should also be easy to compile the correct HelloWorld file. You can also try using some other make commands, such as make Clean,make Install,make Dist, to see what effects they will give you. How do you feel? I can write such a professional makefile, the boss will be very impressed with you.

three, the order detailed1, AutoScan

AutoScan is used to scan the source code directory for generating Configure.scan files. AutoScan can use directory names as parameters, but if you do not use parameters, then AutoScan will assume that the current directory is being used. AutoScan will scan the source files in the directory you have specified and create a Configure.scan file.

2, Configure.scan

Configure.scan contains the basic options for system configuration, which are all macro definitions. We need to rename it to Configure.ac.

3, Aclocal

Aclocal is a Perl scripting program. Aclocal automatically generates ACLOCAL.M4 files based on the contents of the Configure.ac file. The definition of aclocal is: "Aclocal-create aclocal.m4 by scanning configure.ac".

4, autoconf

Use autoconf to generate configure files according to configure.in and ACLOCAL.M4. Configure is a script that can set up the source program to accommodate a variety of operating system platforms, and generate the appropriate makefile based on different systems, so that your source code can be compiled on different operating system platforms.

The contents of the Configure.ac file are macros that, after autoconf processing, become shell scripts that examine system features, environment variables, and the parameters that the software must have. The order of macros in the Configure.ac file is not specified, but you must add Ac_init macros and Ac_output macros to the front and last sides of all macros.

In the Configure.ini:

#号表示注释, the content behind this macro will be ignored. Ac_init (FILE)  // This macro is used to check the path where the source code is located.  Am_init_automake (Package, version)  // This macro is a must, which describes the name of the packages we are going to generate and their version number: package is the name of the packages, Version is the revision number. When you use the Make Dist command, it will give you a helloworld-1.0.tar.gz-like software release package with the name and version number of the corresponding package.  ac_prog_cc  // This macro will check the C compiler used by the system.  ac_output (FILE)  // This macro is the name of the makefile that we want to output. 

When we use automake, we actually need to use some other macros, but we can use aclocal to help us generate them automatically.   After executing the aclocal we will get the Aclocal.m4 file. After generating the CONFIGURE.AC and ACLOCAL.M4 two macro files, we can use the autoconf to generate the Configure file.

5, makefile.am

Makefile.am is used to generate makefile.in, which you need to write manually. Some of the content is defined in makefile.am:

Automake_options // when executing automake, it checks the directory for the existence of various files in the standard GNU software package, such as authors, CHANGELOG, news, etc. When we set it to foreign, Automake will use the standard of the generic package to check.  bin_programs  // This is the file name that specifies the executable file that we want to produce. If you want to produce more than one executable file, separate the names with a space between them.  helloworld_sources  // This is the source code that is required to specify the "HelloWorld" to be produced. If it uses more than one source file, separate them with a space number. For example need HELLOWORLD.H,HELLOWORLD.C then please write helloworld_sources= helloworld.h helloworld.c. 

If you define more than one executable file in Bin_programs, you define a relative filename_sources for each executable file.

6, Automake

Use Automake to generate makefile.in according to Configure.in and makefile.am.

The--add-missing  // definition is "add missing standard file to package", which will let Automake add some of the files that are necessary for a standards-only software bundle. 

The makefile.in file produced by Automake is in accordance with the GNU Makefile Convention, and then we can produce the appropriate Makefile file just by executing the Configure Shell script.

  

7, Makefile

In makefile, which complies with the GNU Makefiel Convention, contains some basic pre-defined actions:

Make//according to makefile compile source code, connect, generate target file, executable file.  Make Clean//clears the object file (the file with the suffix ". O") and the executable file that resulted from the last make command. Make Install//installs the successfully compiled executable file into the system directory, typically the/usr/local/bin directory. Make list//generates a release package file (that is, distribution packages). This command packages the executable and related files into a tar.gz compressed file that is used as the software package for the release. It generates a file with a name similar to "package-version.tar.gz" in the current directory. Package and version are the Am_init_automake (package, version) that we defined in Configure.ac. Make Distcheck//build and test the release package to determine the correctness of the release package. This will automatically unpack the package file, execute the Configure command, and execute make to confirm that the compilation does not appear to be wrong, and that the package is ready to be released. Make Distclean//like make clean, but it also removes all configure generated files, including makefile. 

Linux--autoconf and Automake use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.