"Linux technology" Autotools make Makefile Process detailed "turn"

Source: Internet
Author: User
Tags configuration settings automake

Transferred from: http://www.cnblogs.com/lcw/p/3159461.html
Preface makefile can help make complete its mission, but admittedly, writing makefile is really not an easy task, especially for a larger project. So, is there an easy way to generate makefile and at the same time allow us to enjoy making the advantages? Autotools series of tools is precisely for this purpose, it just user input simple target file, dependent files, file directory, etc. can easily generate makefile, this is undoubtedly the vast number of users hope. In addition, these tools can also complete the collection of system configuration information, so as to easily handle a variety of portability issues. It is based on this, now Linux software development is generally used autotools to make makefile. But this tool for beginners like us is still a stranger, the use of online find more scattered, so here I take the whole process of record down, to benefit people self-interest! Autotools use flow as previously stated, Autotools is a series of tools, and the reader first confirms that the system has the following tools (which can be viewed with the which command). aclocal AutoScan autoconf Aut Oheader Automake use of Autotools is primarily the use of script files from each tool to generate the final makefile. The overall process is this: • Use aclocal to generate a "aclocal.m4" file that mainly handles local macro definitions; • Overwrite the "Configure.scan" file and rename it to "Configure.inchand use the autoconf file to generate the Configure file. Next, a simple hello.c example is used to familiarize yourself with the Autotools generation makefile process. First look at the effect1. AutoScan first runs the AutoScan command, which examines the source file in the given directory and its subtree, and checks in the current directory and its subtree if no directory is given. It searches the source file for general portability issues and creates a file "Configure.scan", which is the "configure" to be used next autoconf.inch"prototype. 2. Autoconf Configure.in is autoconf's script configuration file, its prototype file is "Configure.scan" (note) here to rename Configure.scan configure.ac, and manually modify the contents of it. This file is mainly used to define the basic information of the program (name, version number, etc.), the tests that need to be done before compiling, the directories to generate the makefile files, and so on, as shown in the following Configure.ac123456789Ten One A - - the - - - + - + A at - - -1#-*-Autoconf-*-2# Process Thisfile with autoconf to produce a configure script. 3 4Ac_prereq ([2.68]) 5#AC_INIT ([Full-package-name], [VERSION], [bug-report-ADDRESS]) 6Ac_config_srcdir ([hello.c])7ac_config_headers ([config.h])8 9#add-me-------------TenAc_init (Hello,1.0, [email protected]) OneAm_init_automake (Hello,1.0) A -# Checks forprograms. -AC_PROG_CC the -# Checks forlibraries. - -# Checks forheader files. +ac_check_headers ([stdlib.h]) - +# Checks fortypedefs, structures, and compiler characteristics. A at# Checks forLibrary functions. - -ac_config_files ([Makefile]) -ac_output where add-me----The following two sentences are added, Ac_init macro is used to define the name and version of the software and other information; Am_init_automake is a necessary macro for automake, and the parameters are the name and version number of the software suite to be generated. The following explains the other code • Behavior comments that begin with the "#" sign. Ac_prereq macros declare the autoconf version required for this file, as in this example, version 2. -. · Ac_init macros are used to define information such as the name and version of the software L. Am_init_automake is the author plus, it is the necessary macro for Automake, as before, the package is the name of the software suite to be generated, version is the revision number. 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_config_files macro is used to generate the corresponding makefile file. • In the middle of the comments can be added to the user test program, test function library, test header files and other macro definitions. The next step is to run aclocal, which generates a "ACLOCAL.M4" file that handles the local macro definition primarily. Then run autoconf to generate the "Configure" executable file. 3. Autoheader then uses the Autoheader command, which is responsible for generating the config.h.in file. The tool typically copies the user-attached symbol definitions from the "acconfig.h" file, so there is no symbolic definition attached here, so you do not need to create a "acconfig.h" file. As shown below:4. Automake This step is an important step in creating makefile, automake the script configuration file to use is makefile.am, and the user needs to create the file himself. After that, the Automake tool converts it to makefile.inch. In this example, the file created is makefile.am as follows:123automake_options=Foreignbin_programs=hellohellohello_sources=hello.c The corresponding entry for the script file is explained below. • Automake_options is the option to set the 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 three software levels: foreign, GNU, and GnitS, which allows the user to choose the default level of GNU. In this case, using the foreign level, it detects only the necessary files. Bin_programs defines the name of the execution file 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", "sunq.c", "hello.h" three dependent files, then define Hello_sources=hello.c sunq.c. You can then use Automake to generate "configure.inch"File, use options here"-adding-missing "allows Automake to automatically add some required script files. The configure.in file can be generated after automake. 5. Run configure in this step, the makefile.in is turned into the final makefile by running the automatic configuration settings file configure. As shown below123456789Ten One A - - the - - - + - + A at - - - - - in - to + - the *[email protected]-dell:~/desktop/autotools$./configurechecking forA bsd-compatible install .../usr/bin/install-cchecking whether build environment isSane ... yeschecking forA thread-safe mkdir-p .../bin/mkdir-pchecking forgawk ... nochecking forMawk mawkchecking Whether make sets $ (make) ... 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 forstyle of include used by make ... Gnuchecking dependency style of gcc ... gcc3checking how to run the C preprocessor ... gcc-echecking forgrep that handlesLongLines And-e .../bin/grepchecking forEgrep .../bin/grep-echecking forANSI C header files ... yeschecking forsys/types.h ... yeschecking forsys/stat.h ... yeschecking forstdlib.h ... yeschecking for string. H. yeschecking formemory.h ... yeschecking forstrings.h ... yeschecking forinttypes.h ... yeschecking forstdint.h ... yeschecking forunistd.h ... yeschecking forstdlib.h ... (cached) yesconfigure:creating./config.statusconfig.status:creating Makefileconfig.status:executing depfiles commands can see that The system information is collected when the Configure is run and can be easily configured by the user in the Configure command. In the.There are two types of custom parameters for/configure, one is switch (--enable-xxx or--disable-xxx), the other is open, which is followed by a string of characters (--with-xxx=yyyy) parameter. Readers can try out their own methods of use. In addition, readers can view the "Config.log" file in the same directory to facilitate debugging. So far, the makefile can be generated automatically. Recall the entire step, the user no longer need to customize the different rules, and only need to enter a simple file and directory name, which greatly facilitates the user's use. Autotools generated makefile has the following main functions in addition to the normal compilation function:1. Make type make to execute the "make all" command by default, that is, the target body is all, and its execution is as follows:123456789Ten One A[email protected]-dell:~/desktop/autotools$ MAKECD.&&/bin/bash./config.status config.hconfig.status:creating config.hmake All-ammake[1]: Entering directory '/home/mystery/desktop/autotools'Gcc-dhave_config_h-i. -G-O2-MT HELLO.O-MD-MP-MF. Deps/hello. Tpo-c-o hello.o HELLO.CMV-F. Deps/hello. Tpo. deps/Hello. POGCC-g-o2-o Hello hello.ocd.&&/bin/bash./config.status config.hconfig.status:creating config.hconfig.status:config.h isunchangedmake[1]: Leaving directory '/home/mystery/desktop/autotools'The executable "Hello" and "run" are generated in this directory./Hello "can show normal results as follows:12[email protected]-dell:~/desktop/autotools$./Hello!!! Hello World!!!2. Make install will install the program into the system directory, and if you run hello directly, the correct result can also occur. 3. Made clean at this point, make clears the previously compiled executable and target files (ObjectFile, *. O), as shown below:123[email protected]-dell:~/desktop/autotools$ make Cleantest-Z"Hello"|| RM-F Hellorm-F *. O4. Make dist at this point, you package the program and related documents as a compressed document for publishing, as follows:123[email protected]-dell:~/desktop/autotools$ make Dist[email protected]-dell:~/desktop/autotools$ ls hello-1.0-Tar.gzhello-1.0-tar.gz Visible This command generates a Hello-1.0-tar.gz of compressed files. It is not difficult to see from the above, Autotools is indeed the software maintenance and release of the necessary tools, in view of this, now gun software is generally made by automake.

"Linux technology" Autotools make Makefile Process detailed "turn"

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.