First, the diagram of each file in the process of generating configure
Second, Detailed introduction
AutoScan: Scan the source code to search for common portability issues, such as checking compilers, libraries, header files, etc., generating file Configure.scan, which is a prototype of CONFIGURE.AC.
Aclocal: Macros in user-defined macros and ACINCLUDE.M4 files are defined in the file aclocal.m4 by the macros that are required for configure.ac files, depending on the macros that have been installed. Aclocal is a Perl script that is defined as: "Aclocal-create aclocal.m4 by scanning configure.ac"
Automake: Build the structure defined in makefile.am makefile.in, and then configure the script to convert the generated makefile.in file to makefile. If you define some special macros in Configure.ac, such as Ac_prog_libtool, it will call libtoolize, otherwise it will generate config.guess and config.sub itself.
Autoconf: Expands the macro in CONFIGURE.AC to generate a configure script. This process may need to use the macros defined in ACLOCAL.M4.
Iii. Example 1. Test code (define two files Hello.h and hello.c)
/*hello.c*/
#include <iostream> #include "hello.h" using namespace Std;int Main () { chello A; return 0;}
/*hello.h*/
#ifndef __hello_h__#define __hello_h__#include<iostream>using namespace Std;class chello{public: CHello () {cout<< "hello!" <<endl;} ~chello () {cout<< "bye!" <<endl;}}; #endif
2. Operation steps (1) Installing dependent packages
[Email protected] autoconfig]# yum-y install Automake autoconf
Automake include: aclocal, Automake, etc.
Autoconf include: AutoScan, autoconf, etc.
(2) AutoScan
[Email protected] autoconfig]# ll-rw-r--r--1 root root 4 hello.cpp-rw-r--r--1 root root 189 June 4 Hello . H[[email protected] autoconfig]# autoscan[[email protected] autoconfig]# lltotal 12-rw-r--r--1 root root 0 June 4 autoscan.log-rw-r--r--1 root root 481 June 4 configure.scan-rw-r--r--1 root root The June 4 hello.cpp-rw-r--r-- 1 root root 189 June 4 hello.h
(3) Aclocal
[[Email protected] autoconfig]# mv Configure.scan configure.ac[[email protected] autoconfig]# vim configure.ac/* Red bold below Partially modified */#-*-Autoconf-*-# Process This file with Autoconf to produce a con Figure script. Ac_prereq ([2.69])ac_init (Hello, 1.0, [email protected])
am_init_automake (Hello, 1.0)Ac_config_srcdir ([hello.cpp]) ac_config_headers ([config.h])
# Checks for programs. ac_prog_cxxac_prog_cc# Checks for libraries.# Checks for headers files.# Checks for typedefs, structures, and compiler char acteristics.# Checks for library functions.ac_output (Makefile)[[email protected] autoconfig]# aclocal[[email protected] autoconfig]# lltotal 52-rw-r--r--1 root root 37794 June 4 Acloc Al.m4drwxr-xr-x 2 root root 4 autom4te.cache-rw-r--r--1 root root 0 June 4 autoscan.log-rw-r--r--1 root R Oot 492 June 4 configure.ac-rw-r--r--1 root root June 4 hello.cpp-rw-r--r--1 root root 189 June 4 Hello.h
The following is a brief description of the document (all comments starting with the "#"):
· The AC_PREREQ macro declares the autoconf version required for this file, and this example uses a version of 2.59.
· AC_INIT macro is used to define the name and version of the software, "Full-package-name" is the package name, "version" is the software version number, "Bug-report-address" Address the bug report (typically a software author email address).
· AC_CONFIG_SRCDIR macro is used to detect the existence of the specified source code files, to determine the validity of the source directory. Here is the hello.c under the current directory.
· The Ac_config_header macro is used to generate the Config.h file for autoheader use.
· The AC_PROG_CC is used to specify the compiler, and if not specified, the default gcc is selected.
· Ac_output is used to set the Configure to produce the file, if makefile,configure will check it out of the results into the makefile.in file to produce the appropriate makefile. When using Automake, some additional parameters are required, which are generated with the Aclocal tool.
(3) autoconf
[[email protected] autoconfig]# autoconf[[email protected] autoconfig]# lltotal 204-rw-r--r--1 root root 37794 jun
4 aclocal.m4drwxr-xr-x 2 root root bayi June 4 autom4te.cache-rw-r--r--1 root root 0 June 4 autoscan.log- Rwxr-xr-x 1 root root 154727 June 4 Configure-rw-r--r--1 root root 492 June 4 configure.ac-rw-r--r--1 Root root hello.cpp-rw-r--r--June 4 1 root root 189 June 4 hello.h
At this point, you can see that configure has been generated
(4) Autoheader
[[email protected] autoconfig]# autoheader[[email protected] autoconfig]# lltotal 208-rw-r--r--1 root root 37794 June 4 aclocal.m4drwxr-xr-x 2 root root bayi June 4 autom4te.cache-rw-r--r--1 root root 0 June 4 Autoscan.lo g-rw-r--r--1 root root 625 June 4 config.h.in-rwxr-xr-x 1 root root 154727 June 4 configure-rw-r--r--1 root ro OT 492 June 4 configure.ac-rw-r--r--1 root root 4 hello.cpp-rw-r--r--1 root root 189 June 4 hello.h
Autoheader generated configure.h.in if Ac_config_header is defined in Configure.ac, then this file is required;
(5) makefile.am
[[email protected] autoconfig]# vim Makefile.am[[email protected] autoconfig]# cat makefile.am automake_options=foreign Bin_programs=hello Hello_sources=hello.cpp hello.h
· Automake_options is the option to set Automake. Since GNU has strict specifications for its own software release, such as the need to attach a license statement file copying, or Automake execution will be an error. Automake offers 3 software levels: foreign, GNU, and GnitS, which are selected by default and GNU. This example requires a foreign level, which detects only the necessary files.
bin_programs defines the execution file name to be generated. If you want to produce multiple execution files, each file name is separated by a space.
hello_sources defines "Hello" as the original file required for the execution of the program. If the "Hello" program is generated by more than one original file, all the original files it uses must be listed and separated by a space. For example: if the target body "Hello" requires "hello.c", "hello.h" two dependent files, then define HELLO_SOURCES=HELLO.C hello.h.
(6) Automake
[[email protected] autoconfig]# automake--add-missingconfigure.ac:6: Warning:am_init_automake:two-and Three-arguments forms are deprecated. For more info, See:configure.ac:6: Http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT _005fautomake-invocationconfigure.ac:6: Installing './install-sh ' configure.ac:6: Installing './missing ' [[Email protected] autoconfig]# lltotal 236-rw-r--r--1 root root 37794 June 4 Aclocal.m4drwxr-xr-x 2 root root Bayi June 4 autom4te.cache-rw-r--r--1 root root 0 June 4 autoscan.log-rw-r--r--1 root root 625 June 4 config.h.in-rwx R-xr-x 1 root root 154727 June 4 configure-rw-r--r--1 root root 492 June 4 configure.ac-rw-r--r--1 root root 105 June 4 hello.cpp-rw-r--r--1 root root 189 June 4 hello.hlrwxrwxrwx 1 root root June 4 install-sh/usr /share/automake-1.13/install-sh-rw-r--r--1 root root 4 makefile.am-rw-r--r--1 root root 22227 June 4 make File.inlrwxrwxrwX 1 root root 4 missing-/usr/share/automake-1.13/missing
This step is mainly to generate makefile.in, plus the--add-missing parameter, will complement the missing script;
(6) test
[[email protected] autoconfig]#/configure[[email protected] autoconfig]# Make[[email protected] autoconfig]#./ Hellohello! bye!
Operate as many open-source software as you normally install
(7) Packaging
[[email protected] autoconfig]# make Dist[[email protected] autoconfig]# lltotal 436-rw-r--r--1 root root 37794 June 4 A Clocal.m4drwxr-xr-x 2 root root Bayi June 4 autom4te.cache-rw-r--r--1 root root 0 June 4 autoscan.log-rw-r--r--1 Root root 758 June 4 config.h-rw-r--r--1 root root 625 June 4 config.h.in-rw-r--r--1 root root 11031 June 4 Confi G.log-rwxr-xr-x 1 root root 32557 June 4 Config.status-rwxr-xr-x 1 root root 154727 June 4 configure-rw-r--r--1 root roo T 492 June 4 configure.aclrwxrwxrwx 1 root root 4 June Depcomp-/usr/share/automake-1.13/depcomp-rwxr-xr-x 1 root root 22250 June 4 hello-rw-r--r--1 root root 72021 June 4hello-1.0.tar.gz-rw-r--r--1 root root hello.cpp-rw-r--r--June 4 1 root root 189 June 4 hello.h-rw-r--r--1 root root 26008 Ju N 4 hello.olrwxrwxrwx 1 root root 4 Install-sh-/usr/share/automake-1.13/install-sh-rw-r--r--1 root Roo T 23564 June 4 makefile-rw-r--r--1 root root 4 June 4 makefile.am-rw-r--r--1 root root 23869 June MAKEFILE.INLR wxrwxrwx 1 root root 4 missing-/usr/share/automake-1.13/missing-rw-r--r--1 root root June 4 Stam P-h1
If the careful words can be found, the crowd has appeared hello-1.0.tar.gz is the compiled files have been packaged.
Generate configure files using Automake, autoconf under Linux