How to Use AutoMake in Ubuntu

Source: Internet
Author: User
Tags automake
The company's projects use both handwritten makefiles and automake. There is no uniform rule, and it has always been to take others' makefile files and change them for reuse. I have been free recently. I have carefully understood makefile and automake, and found that makefile is difficult to write. automake is much simpler, So I sorted out the usage of automake, the procedure for future reference is as follows: 1. execute the autoscan command in the directory where the source code is stored to generate configur

The company's projects use both handwritten makefiles and automake. There is no uniform rule, and it has always been to take others' makefile files and change them for reuse. I have been free recently. I have carefully understood makefile and automake, and found it difficult to write makefile. automake is much simpler, So I sorted out the usage of automake as a reference for the future.

The procedure is as follows:
1. Execute the autoscan command in the directory where the source code is stored to generate the configure. scan file.
2. Rename the configure. scan file to configure. in or configure. ac, and modify the default configuration as follows:

Configure. in file:

# Process this file with Autoconf to produce a configure script.
AC_INIT (Main. cpp) # specify the file where the main function is located
AM_INIT_AUTOMAKE (hello, 1.0) # specify the program name and version
# Checks for programs.
# Check available Compilers
AC_PROG_CC # C language compiler
AC_PROG_CPP # C ++ Compiler
AC_PROG_CXX
# Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_OUTPUT (Makefile)

3. Run the aclocal and autoconf commands to generate the aclocal. m4 and configure files respectively.

4. Create a file named Makefile. am and enter the corresponding content.

 

Makefile. am file:

AUTOMAKE_OPTIONS = foreign

Bin_PROGRAMS = helloworld

Helloworld_SOURCES = helloworld. c

5. Run automake -- add-missing to generate Makefile. in Based on the Makefile. am file.
6. Execute the./configure script file, which generates the final Makefile according to the Makefile. in file.
The Makefile file is automatically generated in the directory where the source code is located.

As shown in


 

If you think there are too many steps above, you can also use the autoreconf tool, which will call the above tool in sequence, the steps are as follows:
1. Execute the autoscan command in the directory where the source code is stored to generate the configure. scan file.
2. Rename the configure. scan file to configure. in and modify its default configuration.
3. Create a file named Makefile. am and enter the corresponding content.
4. Run autoreconf -- install to generate Makefile. in, configure, config. h. in according to the Makefile. am and configure. in files.
5. Execute the./configure script file, which generates the final Makefile according to the Makefile. in file.

As shown in


 

The entire Makefile generation process is described above, including two key files, configure. in And Makefile. am, these two files need to be manually written. The following is a simple example. The detailed explanation is not available at present. After some experience, write it again.

Configure. in file:

# Process this file with Autoconf to produce a configure script.
AC_INIT (Main. cpp) # specify the file where the main function is located
AM_INIT_AUTOMAKE (hello, 1.0) # specify the program name and version
# Checks for programs.
# Check available Compilers
AC_PROG_CC # C language compiler
AC_PROG_CPP # C ++ Compiler
AC_PROG_CXX
# Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_OUTPUT (Makefile)

Makefile. am file:

Bin_PROGRAMS = hello # Name of the generated executable file.
Hello_SOURCES = Main. cpp A. h A. cpp B. h B. cpp # source file on which the program depends

Related reading:

Http://www.linuxidc.com/Linux/2006-09/202.htm of automake generation of Makefile in Linux

Use GNU Autoconf/Automake to create a Makefile http://www.linuxidc.com/Linux/2012-01/51950.htm

For more information about Ubuntu, see Ubuntu special page http://www.linuxidc.com/topicnews.aspx? Tid = 2

Related Article

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.