Autotools is a series of tools, consisting mainly of autoconf, Automake, Perl locales, and M4, and contains 5 commands:
The following diagram is the flowchart used by Autotools:
installation of Autotools: apt-get Install autoconf automake autotools-dev M4
Autotools Use simple examples as follows: preparing the program source codemkdir demo_conf VI hello.cpp contents are as follows: #include <iostream> using namespace std; int main () {cout << "hello\n"; }
using the AutoScan command, scan the working directory and generate Configure.scan files$ AutoScan $ ls autoscan.log configure.scan hello.cpp
Rename the Configure.scan file to Configure.ac (or configure.in) and make the appropriate modifications. In the Configure.ac file, #号开始的是行注释, the other is M4 macros command; Configure.ac The main function of the macros inside is to detect the system $ mv configure.scan configure.ac vi configure.ac The revised contents are as follows: # -*- Autoconf -*- # Process this file with autoconf to produce a configure script. ac_prereq ([2.68]) ac_init (hello, 1.0, zhunian0322@163.com) Ac_config_srcdir ([hello.cpp]) ac_config_headers ([config.h]) am_init_automake (hello , 1.0) # checks for programs. ac_prog_cxx # checks for libraries. # checks for header files.   # checks for typedefs, structures, and compiler characteristics . # checks for library functions. AC_CONFIG_FILES ([ Makefile]) ac_output configure.ac file Description: ac_prereq Declares the autoconf version required by this article. As in this example, the version 2.68 ac_init is used to define the name, version, author e-mail, etc. of the software ac_config_srcdir is used to detect the existence of source code files and to determine the validity of the source directory. This is used to generate config.h files for the hello.cpp ac_config_headers in the current directory so that the Autoheader command uses AM _init_automake is manually added and is a prerequisite for Automake macros to specify the software name and software version number ac_proc_cxx to specify the compiler. Here is g++ ac_proc_cc is gcc ac_config_files is used to generate the corresponding makefile file ac_output is used to set up configure The file to be generated, if it is madefile,configure will bring the results of its check into the makefile.in file when the makefile is produced. When using Automake, you need some additional parameters, these additional macros are generated with aclocal tools
using the aclocal command, scan the Configure.ac file to generate the Aclocal.m4 file, which handles the local macro definition, based on the macros already installed \ Macros in user-defined macros and ACINCLUDE.M4 files define the macro set that configure.ac files require in ACLOCAL.M4$ aclocal $ ls aclocal.m4 autom4te.cache autoscan.log configure.ac hello.cpp
Use the autoconf command to generate the Configure file. This command expands the macros in the Configure.ac file to generate the Configure script. $ autoconf $ ls aclocal.m4 autom4te.cache autoscan.log Configure Configure.ac Hello.cpp
Use the Autoheader command to generate a config.h.in file. This command typically duplicates the user-appended symbol definition in the Acconfig.h file$ autoheader $ ls aclocal.m4 autoscan.log Configure hello.cpp Autom4te.cache config.h.in configure.ac
Create makefile.am files manually. The Automake tool converts makefile.am to makefile.in files according to the parameters in the configure.in$ vi makefile.am Add content: autumake_options = foreign Bin_programs = Hello hello_sources = hello.cpp makefile.am file contents Explains automake_options options for setting up Automake. Since GNU has strict specifications for its own software release, such as the need for a license declaration file, copying, etc., automake execution will be an error. The Automake offers 3 levels of software: Foreign, GNU, GnitS, for users to choose. The default level is GNU. Bin_programs defines the execution file name to be generated. If you want to produce multiple execution files, each filename is separated by a space hello_sources defines "Hello" as the original file required to execute the program. If the "Hello" program is generated by multiple source files, you must list all the source files it uses and separate them with spaces. If you want to define multiple executable programs, you need to create a corresponding file_sources for each executable program
Use the Automake command to generate makefile.in files. Use the option "--add-missing" to have Automake automatically add some necessary script files $ automake --add-missing configure.ac:8: installing './install-sh '; error while making link: Operation not supported configure.ac:8: installing './missing '; error while making link: operation not supported makefile.am: installing './install '; error while making link: operation not supported <pre name= "code" class= "plain" > makefile.am: required file './news ' not found makefile.am: required file './readme ' not found makefile.am: required file '. AUTHORS ' not found makefile.am: required file './changelog ' not found Makefile.am:installing './copying ' using GNU general public License v3 file; Error while making link:operation not SupporteDMakefile.am:Consider adding the copying file to the version control systemMakefile.am:for your code, to avoid questions about which license your project uses. Makefile.am:installing './depcomp '; Error while making Link:operation not supported description: configure.ac:8: installing './install-sh '; error while making link: Operation not supported configure.ac:8: installing './missing '; error while making link: operation not supported makefile.am: installing './depcomp '; error while making link: operation not supported # #因为把工程放在FAT32分区上, and it doesn't support link. Need to move to ext3. makefile.am: required file './news ' not found makefile.am: required file './readme ' not found makefile.am: required file './authors ' &NBSP;NOT&NBSP;FOUND&NBSP;&NBsp makefile.am: required file './changelog ' not found # #使用touch command to create these 4 files $ cp -rvf /demo_conf/ /home/gino/ $ cd /home/gino/demo_conf/ $ touch NEWS $ touch readme $ touch authors $ touch ChangeLog $ automake --add-missing $ ls ACLOCAL.M4 autoscan.log config.h.in configure hello install-sh Makefile.in README authors changelog config.log configure.ac hello.cpp makefile missing stamp-h1 autom4te.cache config.h config.status depcomp hello.o makefile.am news
Use the Configure command to turn makefile.in into makefile $ ./configure checking for a bsd-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p ... /bin/mkdir -p checking for gawk... no checking for mawk... mawk checking whether make sets $ (make) ... yes checking for g++... g++ checking whether the c++ compiler works... yes checking for c++ compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for Suffix of object files... o checking whether we are using the gnu c++ compiler... yes checking whether g++ accepts -g... yes checking for style of include used by make... gnu checking dependency style of g++... gcc3 configure: creating ./config.status config.status: creating makefile config.status: creating config.h config.status: config.h is unchanged Config.status : executing depfiles commands Makefile's usage make command, which executes the compile code and defaults to the make all command. The make clean command clears the compile-time obj file. The Make install command installs the target file into the system. The make uninstall command unloads the target file from the system. The Make Dist command packs programs and related documents into a compressed document for publication. Make-n Non-execution mode, output all execution commands, but not executed. Make-c Read makefile before changing to specified directory make-h Show all make options