Company make makefile Tool

Source: Internet
Author: User
Tags automake


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:

    • contains all executable files or libraries to be compiled.
    • contains the Source Code corresponding to the executable file or library.
    • contains files to be installed, such as header files and configuration files.
    • try to use the absolute directory of the installed system for the header file to be referenced.
    • do not add-I to xxx_cflags to specify the header file location, unless the header file to be referenced is not in/usr/include or/usr/local/include, it is located in a directory such as/opt/XXX/include.
    • do not add-l or-L to xxx_ldadd to specify the location of the library file. The correct method is to complete these tasks in Configure. ac.
    • to add debugging information, you must set the cflags or cxxflags environment variables and execute configure to ensure that debugging information is required based on environment variables during compilation. Do not use cflags, cxxflags, xxx_cflags, and xxx_cxxflags in makefile to set debugging information. Therefore, makefile. Am must be modified before each release, which is not conducive to CVS maintenance. The following is an example of makefile. am
       automake_options = foreignlib_ltlibraries = libmyproject. lalibmyproject_la_sources = libmyproject. clibmyproject_la_libadd = libmyproject_la_cppflags = $ (am_cppflags) libmyproject_la_ldflags = $ (am_ldflags) bin_programs = callback = myprojectbin. cmyprojectbin_ldadd = myprojectbin_cppflags = include_headers = libmyproject. hsysconfdir =/etcsysconf_data = libmyproject. conf 

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.