GNU Autotools generates portable build interfaces from project metadata. Autoconf probes the build environment and emits configure; Automake generates portable Makefile.in templates from Makefile.am; Libtool abstracts platform-specific library linking. The generated files are designed for source releases, whereas maintainers edit the .ac, .am, and m4 inputs.
Input and Generated Files #
A project normally contains these inputs:
configure.acis an m4 program that declares package metadata, probes, substitutions, output files, and optional headers.Makefile.amdescribes build targets with Automake variables such asbin_PROGRAMS,lib_LTLIBRARIES, andprogram_SOURCES.m4/contains project or third-party m4 macros, conventionally imported byaclocal.config.h.inis anautoheadertemplate for configuration macros.
A maintainer runs autoreconf -fi to invoke the required generators. That command runs aclocal, autoconf, autoheader when headers are declared, and automake --add-missing when Automake is used. The result includes configure, aclocal.m4, Makefile.in, helper scripts under build-aux/, and config.h.in where applicable.
A user then runs the generated configuration script out of tree:
mkdir build
cd build
../configure --prefix=/usr/local
make
make check
make installThe script writes config.status, which records selected substitutions and can regenerate configured outputs without repeating every probe. config.log records compiler tests and diagnostics, making it the first file to inspect after a configuration failure.
Autoconf #
autoconf expands configure.ac through GNU m4 and emits a shell configure script. Macros such as AC_PROG_CC locate and test a compiler; AC_CHECK_HEADERS and AC_CHECK_FUNCS test interfaces; AC_SUBST exports a variable for template substitution. AC_CONFIG_FILES lists templates that config.status turns into output files, and AC_OUTPUT completes the configuration declaration.
AC_INIT([example], [1.0])
AC_CONFIG_SRCDIR([src/main.c])
AC_PROG_CC
AC_CHECK_HEADERS([sys/epoll.h])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([Makefile src/Makefile])
AC_OUTPUTA successful probe must answer a specific build question. Cross compilation makes run-time probes unsafe because the build host cannot execute target binaries. Autoconf exposes --build, --host, cache variables, and AC_CACHE_CHECK so a project can distinguish compilation from execution tests.
autoheader scans configuration macros and emits config.h.in. configure substitutes each discovered #undef with an appropriate #define or leaves it undefined in config.h. Multiple headers are supported when AC_CONFIG_HEADERS lists multiple names; each listed header has its own .in template and configured output.
Automake #
Automake translates Makefile.am into a portable Makefile.in; configure substitutes compiler paths, installation directories, and feature results into the final Makefile. For example:
bin_PROGRAMS = tool
tool_SOURCES = main.c parse.c parse.h
AM_CPPFLAGS = -I$(top_srcdir)/include
Automake supplies conventional targets such as all, check, install, installcheck, clean, distclean, and dist. make distcheck builds a distribution archive in a fresh tree, runs the configured test suite, verifies installation and uninstallation, and confirms that distclean removes generated files.
Automake primaries define classes of output: PROGRAMS, LIBRARIES,
LTLIBRARIES, HEADERS, SCRIPTS, DATA, and related forms. Prefixes such as
bin_, lib_, include_, noinst_, and check_ select installation or build
behavior. Automake derives object dependencies for declared sources, while
BUILT_SOURCES, EXTRA_DIST, and dist_ variables handle generated prerequisites
and files that automatic distribution discovery would miss.
aclocal constructs aclocal.m4 by collecting macros required by configure.ac, including macros found through AC_CONFIG_MACRO_DIRS. Version-controlled projects commonly include generated configure and Makefile.in in release archives because an end user needs only a shell and Make, not every Autotools generator.
Templates and Substitutions #
A .in file contains literal text and @VARIABLE@ substitutions created by AC_SUBST. Automake-generated Makefile.in files also define Make variables from those substitutions, so recipes can use $(VARIABLE). A template does not execute shell syntax merely because it passes through configure; quote shell values in configure.ac and validate values used by generated scripts.
Libtool #
Libtool supplies libtool, a generated wrapper used by Automake’s
*_LTLIBRARIES targets. It separates a portable library name such as
libexample.la from platform outputs such as a shared object, import library, or
static archive. libtoolize installs the macro and helper files needed by a
project. Library version information belongs in -version-info according to
Libtool’s current/age/revision interface rules; release numbering instead uses
-release. Neither value is a direct copy of the package version.
Before publishing, maintainers run autoreconf -fi, an out-of-tree
../configure, make, make check, and make distcheck. Release users unpack
the archive and need only ./configure, Make, and the declared build tools;
DESTDIR can stage make install for packaging. Generated configure --help,
config.log, config.status --recheck, and make -n expose concrete behavior.
Comments
Read or comment on GitHub (sign-in required to comment)