Make Tool Overview
Makefile is generated using GNU automake tools for standardization, universality, and portability. Unless it is a investigational project, it is generally not recommended that you write makefile yourself.
The GNU makefile generation tool is composed of aclocal, Autoconf, libtoolize, and automake.
Aclocal generates the M4 script.
Autoconf generates configure Based on Configure. AC (called Configure. in earlier versions.
Libtoolize: generate the script required by the dynamic library.
Automake: Generate makefile. In Based on makefile. am.
Configure: Generate makefile Based on makefile. In.
Prerequisites
Ubuntu 8.04
Sudo apt-GetInstall autoconfsudo apt-GetInstall automakesudo apt-GetInstall libtool
RedHat 5.x
The RPM packages of make tools are located on the installation disc. The RPM packages of different versions have the same name except the version number.
Rpm-IVH autoconf-xxx.rpm rpm-IVH automake-xxx.rpm rpm-IVH libtool-xxx.rpm
Generation steps
For example, the project name is myproject, And the directory is as follows:
-- Myproject ++ -- Configure. AC + -- makefile. Am + -- SRC ++ makefile. Am + libmyproject. C + myprojectbin. c
The generation process is as follows:
$ Aclocal $ Autoconf $ libtoolize-F-C $ automake-A $ touch news $ touch readme $ touch authors $ touch changelogs $ automake $./configure $ make $ sudo make install
Configure. AC
Configure. AC writing principles.
-
- All third-party libraries that need to be used must be detected by functions such as pkg_check_modules. In addition to checking whether a required library exists before compilation, this type of script can automatically add xxx_ldadd to makefile to ensure the simplicity of makefile. am. In addition, some library header files and library files are relatively large, it is difficult to write in a simple sentence.
-
- CodeThe required macros are defined in Configure. ac.
- The custom configure parameter should be implemented in Configure. ac. The following is an example of Configure. ac.
#-*-Autoconf -*- # Process this file with Autoconf to produce a configure script. Ac_prereq ([2.59]) ac_init ([full-package-name], [Version], [bug-Report-address]) ac_config_srcdir ([src/myprojectbin. c]) am_init_automake () # Checks for programs. Ac_prog_cxxac_prog_ccac_prog_libtool # Checks for libraries. Pkg_check_modules ([libmyproject_la], [glib-2.0], [], [ac_msg_error ([ "Error! You need to have libglib2.0 installed ." ]) Pkg_check_exists ([cppunit], [], [ac_msg_error (["error! You need to have libcppunit-dev installed. Try sudo apt-Get install libcppunit-Dev. "]) # Checks for header files. Ac_check_headers ([stdlib. h stdio. H]) # Checks for typedefs, structures, and compiler characteristics. Ac_header_stdboolac_type_size_tac_arg_with (debug, [as_help_string ([-- With-Debug], [enable debugging output])], [ If Test $ withval! = "No" ; Then ac_subst (am_cflags ,[ "-G3-O0-wall" ]) Ac_subst (am_cxxflags, ["-G3-O0-wall"]) ac_define ([with_debug], 1) Fi]) # Cppunit_cflags = 'pkg-config -- cflags cppunit' # Cppunit_libs = 'pkg-config -- libs cppunit' # Am_cppflags = "$ cppunit_cflags" # Am_ldflags = "$ cppunit_libs" # Ac_subst (am_cppflags) # Ac_subst (am_ldflags) # Checks for library functions. Merge ([memset]) ac_define (_ largefile64_source) ac_define (_ xopen_source, [500]) ac_define (_ file_offset_bits, [64]) ac_define (_ gnu_source) ac_config_files ([makefile src/makefile]) ac_output
Makefile. AM
The writing principle of makefile. Am is: