The GNU build system, also known as the Autotools, is a suite of programming tools designed to assist in making source-code packages portable to many Unix-like systems.
It can be difficult to make a software program portable: the C compiler differs from system to system; certain library functions are missing on some systems; header files may have different names. One way to handle this is write conditional code, with code blocks selected by means of preprocessor directives (#ifdef
); but because of the wide variety of build environments this approach quickly becomes unmanageable. The GNU build system is designed to address this problem more manageably.
The GNU build system is part of the GNU toolchain and is widely used in many free-software and open-source packages. The tools comprising the GNU build system are free-software-licensed under the GNU General Public License with special license exceptions[1][2] permitting use of the GNU build system with proprietary software.
Contents |
The GNU build system comprises the GNU utility programs Autoconf, Automake, and Libtool.[3] Other related tools frequently used with the GNU build system are GNU’s make program, GNU gettext, pkg-config, and the GNU Compiler Collection, also called GCC.
Autoconf generates a configure
script based on the contents of a configure.ac
file which characterizes a particular body of source code. The configure
script, when run, scans the build environment and generates a subordinate config.status
script which, in turn, converts other input files and most commonly Makefile.in
into output files (Makefile
) which are appropriate for that build environment. Finally the make
program uses Makefile
to generate executable programs from source code.
The complexity of the GNU build system reflects the variety of circumstances under which a body of source code may be built.
make
which only re-compiles that part of the body of the source code affected by the change..in
file has changed then it suffices to re-run config.status
and make
.configure
(which runs config.status
) and make
. (For this reason source code using the GNU build system is normally distributed without the files that configure
generates.)configure.ac
and the .in
files need to be changed and all subsequent steps also followed.To process files, autoconf uses the GNU implementation of the m4 macro system.
Autoconf comes with several auxiliary programs such as Autoheader, which is used to help manage C header files; Autoscan, which can create an initial input file for Autoconf; and ifnames
, which can list C pre-processor identifiers used in the program.
Automake helps to create portable Makefile
s, which are in turn processed with the make utility. It takes its input as Makefile.am
, and turns it into Makefile.in
, which is used by the configure script to generate the file Makefile
output.
Libtool helps manage the creation of static and dynamic libraries on various Unix-like operating systems. Libtool accomplishes this by abstracting the library-creation process, hiding differences between various systems (e.g. GNU/Linux systems vs. Solaris).
Gnulib simplifies the process of making software that uses Autoconf and Automake portable to a wide range of systems.
The GNU build system allows a programmer to write cross-platform software. It also makes the build process easier on a user who wants to compile the program on his or her own computer. The user does not need to have GNU build system components installed on the computer but only needs to run the supplied configure
script which has no dependencies other than the presence of a Bourne-compatible shell.
The GNU build system uses Bourne-compatible shell scripts to assist the user in the configuration and build process. The GNU build system can be used both for building native programs on the build machine and also for cross-compiling to other architectures.[4]
Cross-compiling software to run on a Windows host from a GNU/Linux or other Unix-like build system is also possible, using MinGW, however native compilation is often desirable on operating systems (such as the Microsoft Windows family of systems) that cannot run Bourne shell scripts on their own. This makes building such software on the Windows operating system a bit harder than on a Unix-like system which provides the Bourne shell as a standard component. One can install the Cygwin or MSYS system on top of Windows to provide a Unix-like compatibility layer, though, allowing configure scripts to run. Cygwin also provides the GNU Compiler Collection, GNU make, and other software that provides a nearly complete Unix-like system within Windows; MSYS also provides GNU make and other tools designed to work with the MinGW version of GCC.
Projects which use the GNU build system may or may not provide a configure script within their Version control systems (such as CVS or Subversion). If a project that uses the GNU build system does not have a generated ./configure
file available for the user, the user must generate it. One possible way this can be done is to execute the autoreconf tool at a shell prompt:
$ autoreconf
This will invoke aclocal, autoconf, autoheader and automake as needed. In some cases, more commands may be necessary. Another common convention is then to provide a script, often named autogen.sh
or bootstrap
, that runs all the needed pre-build tools.
One limitation has been that the autoconf-generated configure
can be slow because it executes programs like the C compiler many times in order to test whether various libraries, header files, and language features are present.
|