Using Autotools

If you want to build your program on another system, using make only could be quite difficult. The C compiler could be different. Some common C functions could be missing, have another name, declared in a different header and so on. This can be handled by enabling difference piece of code in your sources using preprocessor directive #if, #ifdef and others. But the user will have to define himself all these tuning which is not easy as there is a lots of systems with a lots of variations.

Free softwares are mainly distributed as sources. It is crucial to be able to recompile them on various system without much technical knowledge. Autotools is designed to solve this and you probably have already use it using the magic combination "./configure; make; make install". You may have noticed that many files are involved in this build process; globally all that stuff seems very complicated. So what's happening when you compile such software ?

2.3.1. Input files

An Autotools project comes at least with a configure script, named configure, and a makefile template named There is normally, one in each directory of the project. There are several other files used by an Autotools project but they are not stricly necessary or are generated automatically.

If you look inside these files, you will see that they are quite complex. Do not worry, these files are generated by Autotools from other templates easier to write as explained in Section 3.1 ― Using Autotools. For the moment, we do not care, we consider these files exist as it is the case when you get a source package.

2.3.2. Configure

In fact, you don't need Autotools to build an autotools package, configure is a shell script running on the most basic shell: sh. It probes your system checking each characteristic and writes makefiles from the templates.

In order to build a project using a library, you need more information about it, so additional files. For a library used in a C program, you need the corresponding header files. This has to be installed on your system and is typically found in a so called development package. By example for the library libxml2, there are two packages:

  • libxml2 necessary to run a program using it and installed automatically as a dependency of such program.
  • libxml2-devel necessary to build a program using it. If you don't have it configure will display an error message.
Figure 2-2Configure process

configure creates all files in the directory where it is called. This directory is the build directory. If you run it from the source directory, using ./configure, the build directory will be the same.

configure accepts several options in the command line. They are used to install the files in different directories, to disable some parts of the project in order to get a smaller executable or if you haven't one needed library or force a value for some make variable (see Section 2.2.1 ― Variables). You can get a list of them by running configure --help. Here is a list of the most common ones:


List all available options

--host host

Compile to run on another system (cross compilation)

--prefix dir

Select the root directory for installing the project, default /usr/local

configure generates a few additional files which are less important. config.log is a log file useful when something goes wrong to get more details. config.status is another shell script, it can be run to restore the current configuration. config.h is a header file generated like Makefile from a template if it exists.

2.3.3. make

The makefiles generated by configure are quite complex but are standard makefiles. They define all standard targets needed by GNU standard.

  • make or make all builds the program.
  • make install installs the program.
  • make distclean removes all files generated by configure, to let the project in the state it was when unpacking the distribution package.