manpagez: man pages & more
info autoconf
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.9 Configuration Header Files

When a package contains more than a few tests that define C preprocessor symbols, the command lines to pass ‘-D’ options to the compiler can get quite long. This causes two problems. One is that the make output is hard to visually scan for errors. More seriously, the command lines can exceed the length limits of some operating systems. As an alternative to passing ‘-D’ options to the compiler, configure scripts can create a C header file containing ‘#define’ directives. The AC_CONFIG_HEADERS macro selects this kind of output. Though it can be called anywhere between AC_INIT and AC_OUTPUT, it is customary to call it right after AC_INIT.

The package should ‘#include’ the configuration header file before any other header files, to prevent inconsistencies in declarations (for example, if it redefines const).

To provide for VPATH builds, remember to pass the C compiler a ‘-I.’ option (or ‘-I..’; whichever directory contains ‘config.h’). Even if you use ‘#include "config.h"’, the preprocessor searches only the directory of the currently read file, i.e., the source directory, not the build directory.

With the appropriate ‘-I’ option, you can use ‘#include <config.h>’. Actually, it’s a good habit to use it, because in the rare case when the source directory contains another ‘config.h’, the build directory should be searched first.

Macro: AC_CONFIG_HEADERS (header …, [cmds] @ovar{init-cmds})

This macro is one of the instantiating macros; see Performing Configuration Actions. Make AC_OUTPUT create the file(s) in the blank-or-newline-separated list header containing C preprocessor #define statements, and replace ‘@DEFS@’ in generated files with ‘-DHAVE_CONFIG_H’ instead of the value of DEFS. The usual name for header is ‘config.h’.

If header already exists and its contents are identical to what AC_OUTPUT would put in it, it is left alone. Doing this allows making some changes in the configuration without needlessly causing object files that depend on the header file to be recompiled.

Usually the input file is named ‘’; however, you can override the input file name by appending to header a colon-separated list of input files. For example, you might need to make the input file name acceptable to DOS variants:


This macro is defined as the name of the first declared config header and undefined if no config headers have been declared up to this point. A third-party macro may, for example, require use of a config header without invoking AC_CONFIG_HEADERS twice, like this:

        [m4_ifndef([AH_HEADER], [AC_CONFIG_HEADERS([config.h])])])

See section Performing Configuration Actions, for more details on header.

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on April 26, 2012 using texi2html 5.0.

© 2000-2019
Individual documents may contain additional copyright information.