Autotool Notes—autoconf and configure.in

This just covers the configure.in file. Actually, since about November, 2003, the preferred name of this file is configure.ac.

The master autoconf documentation can be found at http://www.gnu.org/software/autoconf/manual/autoconf.pdf.

autoconf helps overcome the interplatform complexities of building projects (called “packages”).


Standard configure.ac layout...

Making sense out of the above, this is the order suggested by GNU.

- autoconf requirements
- AC_INIT(package, version, bug-report-address)
- information on the package
- checks for programs
- checks for libraries
- checks for header files
- checks for types
- checks for structures
- checks for compiler characteristics
- checks for library functions
- checks for system services
- AC_CONFIG_FILES([file...])
- AC_OUTPUT

Macros

The following are notes on macros used in configure.ac. For a general tutorial, see http://vipe.technion.ac.il/~shlomif/lecture/Autotools/slides/simple_project/configure.in.html for examples and elaboration.

For a narrower, but more explicit treatment, see also http://www.homac.de/cgi-bin/index.pl?page=autotools_tut.

   
  The two required macros..
  AC_INIT(package-name, e-mail) first macro with the name of the package (project) and the e-mail address of the one to blame.
  AC_OUTPUT(Makefile man/Makefile
    etc.)
generates output makefiles; first argument is a whitespace-separated list of files; looks for these files (and also these files with suffix .in) and converts them to output files while substituting the output variable values; accepts optional arguments with command to be executed before and/or after.
  Other macros..
  AC_PREREQ(autoconf-version) ensures that at least the indicated version is essential to the build; older versions are not up to it.
  AC_REVISION(info) no dollar signs or double quotes.
  AC_COPYRIGHT(notice) will show up on both the head of configure and in configure --version.
  AM_INIT_AUTOMAKE(project, version) initializes automake.
  AM_PROG_LIBTOOL initializes libtool.
  AC_PROG_CC checks for C compiler.
  AC_PROG_CXX checks for C++ compiler.
  AC_CHECK_PROG(VAR, prog,
    SUCC-VAR-VALUE, FAIL-VAR_VAL)
checks to see if prog exists on $PATH; if extant, VAR gets what is in SUCC-VAR-VAL, if not, FAIL-VAR-VAL.
  AC_CHECK_LIB(lib-, sym)) checks for present of symbol in a library; can run optional shell codes as third and fourth arguments on success or failure; upon success, will prepend -llib to compiler flags and define macro HAVE_LIB(lib).
  AC_MSG_ERROR(error-message) can be passed as last argument to AC_CHECK_LIB and others to cause error-message to get printed out prior to exiting with failure.
  AC_HEADER_STDC checks for standard headers.
  AC_CHECK_HEADERS(header-list) checks for presence of headers specified as first argument; if found, HAVE_header is defined (with header in all caps).
  AC_C_CONST checks for typedefs, structures, etc..
  AC_HEADER_TIME checks out compiler characteristics.
  AC_CHECK_FUNCS(func-list) checks for presence of standard C library functions; if found, HAVE_func is defined.
  AC_DEFINE(define) can be used anywhere in configure.ac to define a C-preprocessor macro; accepts and optional argument to indicate value of macro, AC_DEFINE(DEBUG_LEVEL, 9); for shell expansion, use AC_DEFINE_UNQUOTED.
  AC_ARG_ENABLE allows for definition of another command-line option (see tutorial).
  AC_SUBST(substring) aids in substitution of occurrences of one file for another.
  AC_OUTPUT(Makefile, man/Makeifle) puts out files.

Preset output variables...

   
  CFLAGS debugging and optimization options; by default empty unless AC_PROG_CC is set up with a value.
  configure_input comment saying that the file was generated automatically; use @configure_input@ near the top of every file (like file.sh.in to remind editors that the target is generated.
  CPPFLAGS header-file search directories, etc.; empty if not set.
  CXXFLAGS debugging and optimization options for C++.
  DEFS place to pass -D options to compiler.
  LDFLAGS place to pass stripping (-s) and path (-L) options to the linker.
  LIBS place to pass -l options to linker.
  builddir always ‘.’.
  top_builddir points to top of project tree (root).
  many others...

Configuration header theory...

When a package contains more than just a few -D options, the command line gets too long to scan visually for errors and the command-line length of a target environment might even get exceeded. Alernatively, AC_CONFIG_HEADERS is used, right after AC_INIT, to create (eventually) config.h which should be included in every source file in some way.

To get config.h.in generated, do...

	AC_CONFIG_HEADERS(config.h)

Each symbol needs its own AC_DEFINE or AC_DEFINE_UNQUOTED mention in configure.ac with the third argument used. Use autoheader for when things go wrong; it will help find more than autoconf.