Overview of Autotools Primary Concepts
Autotools is a suite of programming tools (autoconf, automake, libtool) designed to make source code packages portable across Unix-like systems. Here are its core concepts:
Primary Components
Autoconf - Generates
configure
scripts that check system featuresAutomake - Creates portable
Makefile.in
templates fromMakefile.am
filesLibtool - Manages the creation of static and shared libraries portably
Workflow
Developer writes:
configure.ac
(input for autoconf)Makefile.am
(input for automake)
Running
autoreconf
generates:configure
scriptMakefile.in
templates
End user runs:
./configure
→ generates ``Makefile``smake
→ builds the softwaremake install
→ installs the software
Frequently Used Variables
Project Information Variables (set in configure.ac)
AC_INIT([package], [version], [bug-report])
- Initializes package infoAC_CONFIG_SRCDIR([file])
- Identifies project locationAC_CONFIG_HEADERS([config.h])
- Sets up config headerAC_CONFIG_FILES([Makefile dir/Makefile])
- Specifies output files
Build Control Variables (often set before running configure)
CC
- C compiler to use (e.g.,CC=gcc
)CFLAGS
- C compiler flagsCXX
- C++ compilerCXXFLAGS
- C++ compiler flagsLDFLAGS
- Linker flagsLIBS
- Libraries to link againstCPPFLAGS
- C preprocessor flags (-I, -D options)prefix
- Installation prefix (/usr/local by default)exec_prefix
- Architecture-dependent files prefixbindir
- User executables directorylibdir
- Library files directoryincludedir
- Header files directorydatarootdir
- Read-only architecture-independent data root
Automake Variables (set in Makefile.am)
bin_PROGRAMS
- Programs to install in bindirlib_LIBRARIES
- Libraries to install in libdirinclude_HEADERS
- Headers to install in includedirSOURCES
- Source files for a targetCFLAGS
,CXXFLAGS
- Package-specific flagsLDADD
- Additional linker flags for a targetSUBDIRS
- Subdirectories to process recursivelyEXTRA_DIST
- Additional files to include in distributionBUILT_SOURCES
- Generated sources needed before compilationTESTS
- Test programs to run withmake check
Commonly Used Macros
AC_PROG_CC
- Check for C compilerAC_PROG_CXX
- Check for C++ compilerAC_CHECK_LIB
- Check for library presenceAC_CHECK_HEADER
- Check for header presenceAC_PATH_PROG
- Check for program in PATHAC_MSG_CHECKING
/AC_MSG_RESULT
- User feedback during configureAM_INIT_AUTOMAKE
- Initialize automakePKG_CHECK_MODULES
- Check for pkg-config modules
Autotools provides a robust, portable build system that handles platform differences automatically, though it has a steep learning curve. The variables listed above are the most commonly used to control the build process.