A brief tutorial on the GNU project management tools make, autoscan, autoupdate, aclocal, autoconf, automake, configure.ac, and Makefile.am

When programming in a Linux environment, Makefiles are unavoidable. It may not be difficult to write a Makefile by hand, but it is not so easy to write a Makefile that conforms to free software conventions.

Therefore, GNU has developed a set of tools for generating Makefiles, which is the subject of this article. Let's start with the simplest hello program and play with this program together.

1. Project directory and program code preparation

Assume that our project directory is ~/Desktop/makefiletest/, and write the hello.c file in this directory with the following content:

#include <stdio.h>

int main()
{
	printf("Hello makefile!\n");

	return 0;
}

2. Makefile.am file preparation

Write the Makefile.am file in the project root directory with the following content:

AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=hello
hello_SOURCE=hello.c

3. autoscan generates configure.ac

Execute the autoscan command on the command line in the project root directory. It will scan the source code files in the current directory and generate the configure.scan file.

Rename the configure.scan file to configure.ac (some versions will be changed to configure.in), and then edit the file as follows:

#                                               -*- Autoconf -*-

# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.71])
AC_INIT([hello],[1.1])
AC_CONFIG_SRCDIR([hello.c])
#AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE

# Checks for programs.
AC_PROG_CC

# Checks for libraries.

# Checks for header files.

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.

AC_CONFIG_FILES([Makefile])
AC_OUTPUT

The main thing is to modify the AC_INIT line and add the AM_INIT_AUTOMAKE line.

Then execute the autoupdate command.

4.aclocal generates aclocal.m4

Execute the aclocal command in the project update directory to generate the aclocal.m4 file.

5. autoconf generates configure

Execute the autoconf command in the project directory to generate the configure file.

6.automake generates Makefile.in

Execute the automake command in the project directory to generate the Makefile.in file.

 7.configure generate Makefile

Execute the configure command in the project directory to generate a Makefile.

 8.make executes the compilation result

Execute the make command in the project directory to generate the hello executable file.

Execute the hello program and get the output:

 At this point, the entire GNU project management tool has been played around.

Guess you like

Origin blog.csdn.net/ctbinzi/article/details/131599368