Go to the first, previous, next, last section, table of contents.

Results of Tests

Once configure has determined whether a feature exists, what can it do to record that information? There are four sorts of things it can do: define a C preprocessor symbol, set a variable in the output files, save the result in a cache file for future configure runs, and print a message letting the user know the result of the test.

Defining C Preprocessor Symbols

A common action to take in response to a feature test is to define a C preprocessor symbol indicating the results of the test. That is done by calling AC_DEFINE or AC_DEFINE_UNQUOTED.

By default, AC_OUTPUT places the symbols defined by these macros into the output variable DEFS, which contains an option `-Dsymbol=value' for each symbol defined. Unlike in Autoconf version 1, there is no variable DEFS defined while configure is running. To check whether Autoconf macros have already defined a certain C preprocessor symbol, test the value of the appropriate cache variable, as in this example:

if test "$ac_cv_func_vprintf" != yes; then

If AC_CONFIG_HEADER has been called, then instead of creating DEFS, AC_OUTPUT creates a header file by substituting the correct values into #define statements in a template file. See section Configuration Header Files, for more information about this kind of output.

Macro: AC_DEFINE (variable [, value [, description]])
Define C preprocessor variable variable. If value is given, set variable to that value (verbatim), otherwise set it to 1. value should not contain literal newlines, and if you are not using AC_CONFIG_HEADER it should not contain any `#' characters, as make tends to eat them. To use a shell variable (which you need to do in order to define a value containing the m4 quote characters `[' or `]'), use AC_DEFINE_UNQUOTED instead. description is only useful if you are using AC_CONFIG_HEADER. In this case, description is put into the generated `config.h.in' as the comment before the macro define; the macro need not be mentioned in `acconfig.h'. The following example defines the C preprocessor variable EQUATION to be the string constant `"$a > $b"':


Macro: AC_DEFINE_UNQUOTED (variable [, value [, description]])
Like AC_DEFINE, but three shell expansions are performed--once--on variable and value: variable expansion (`$'), command substitution (``'), and backslash escaping (`\'). Single and double quote characters in the value have no special meaning. Use this macro instead of AC_DEFINE when variable or value is a shell variable. Examples:

AC_DEFINE_UNQUOTED(config_machfile, "${machfile}")
AC_DEFINE_UNQUOTED(GETGROUPS_T, $ac_cv_type_getgroups)

Due to the syntactical bizarreness of the Bourne shell, do not use semicolons to separate AC_DEFINE or AC_DEFINE_UNQUOTED calls from other macro calls or shell code; that can cause syntax errors in the resulting configure script. Use either spaces or newlines. That is, do this:


or this:

  LIBS="$LIBS -lelf")

instead of this:


Setting Output Variables

One way to record the results of tests is to set output variables, which are shell variables whose values are substituted into files that configure outputs. The two macros below create new output variables. See section Preset Output Variables, for a list of output variables that are always available.

Macro: AC_SUBST (variable)
Create an output variable from a shell variable. Make AC_OUTPUT substitute the variable variable into output files (typically one or more `Makefile's). This means that AC_OUTPUT will replace instances of `@variable@' in input files with the value that the shell variable variable has when AC_OUTPUT is called. The value of variable should not contain literal newlines.

Macro: AC_SUBST_FILE (variable)
Another way to create an output variable from a shell variable. Make AC_OUTPUT insert (without substitutions) the contents of the file named by shell variable variable into output files. This means that AC_OUTPUT will replace instances of `@variable@' in output files (such as `Makefile.in') with the contents of the file that the shell variable variable names when AC_OUTPUT is called. Set the variable to `/dev/null' for cases that do not have a file to insert.

This macro is useful for inserting `Makefile' fragments containing special dependencies or other make directives for particular host or target types into `Makefile's. For example, `configure.in' could contain:


and then a `Makefile.in' could contain:

@[email protected]

Caching Results

To avoid checking for the same features repeatedly in various configure scripts (or repeated runs of one script), configure saves the results of many of its checks in a cache file. If, when a configure script runs, it finds a cache file, it reads from it the results from previous runs and avoids rerunning those checks. As a result, configure can run much faster than if it had to perform all of the checks every time.

Macro: AC_CACHE_VAL (cache-id, commands-to-set-it)
Ensure that the results of the check identified by cache-id are available. If the results of the check were in the cache file that was read, and configure was not given the `--quiet' or `--silent' option, print a message saying that the result was cached; otherwise, run the shell commands commands-to-set-it. Those commands should have no side effects except for setting the variable cache-id. In particular, they should not call AC_DEFINE; the code that follows the call to AC_CACHE_VAL should do that, based on the cached value. Also, they should not print any messages, for example with AC_MSG_CHECKING; do that before calling AC_CACHE_VAL, so the messages are printed regardless of whether the results of the check are retrieved from the cache or determined by running the shell commands. If the shell commands are run to determine the value, the value will be saved in the cache file just before configure creates its output files. See section Cache Variable Names, for how to choose the name of the cache-id variable.

Macro: AC_CACHE_CHECK (message, cache-id, commands)
A wrapper for AC_CACHE_VAL that takes care of printing the messages. This macro provides a convenient shorthand for the most common way to use these macros. It calls AC_MSG_CHECKING for message, then AC_CACHE_VAL with the cache-id and commands arguments, and AC_MSG_RESULT with cache-id.

Loads values from existing cache file, or creates a new cache file if a cache file is not found. Called automatically from AC_INIT.

Flushes all cached values to the cache file. Called automatically from AC_OUTPUT, but it can be quite useful to call AC_CACHE_SAVE at key points in configure.in. Doing so checkpoints the cache in case of an early configure script abort.

Cache Variable Names

The names of cache variables should have the following format:


for example, `ac_cv_header_stat_broken' or `ac_cv_prog_gcc_traditional'. The parts of the variable name are:

An abbreviation for your package or organization; the same prefix you begin local Autoconf macros with, except lowercase by convention. For cache values used by the distributed Autoconf macros, this value is `ac'.
Indicates that this shell variable is a cache value.
A convention for classifying cache values, to produce a rational naming system. The values used in Autoconf are listed in section Macro Names.
Which member of the class of cache values this test applies to. For example, which function (`alloca'), program (`gcc'), or output variable (`INSTALL').
Any particular behavior of the specific member that this test applies to. For example, `broken' or `set'. This part of the name may be omitted if it does not apply.

The values assigned to cache variables may not contain newlines. Usually, their values will be boolean (`yes' or `no') or the names of files or functions; so this is not an important restriction.

Cache Files

A cache file is a shell script that caches the results of configure tests run on one system so they can be shared between configure scripts and configure runs. It is not useful on other systems. If its contents are invalid for some reason, the user may delete or edit it.

By default, configure uses `./config.cache' as the cache file, creating it if it does not exist already. configure accepts the `--cache-file=file' option to use a different cache file; that is what configure does when it calls configure scripts in subdirectories, so they share the cache. See section Configuring Other Packages in Subdirectories, for information on configuring subdirectories with the AC_CONFIG_SUBDIRS macro.

Giving `--cache-file=/dev/null' disables caching, for debugging configure. `config.status' only pays attention to the cache file if it is given the `--recheck' option, which makes it rerun configure. If you are anticipating a long debugging period, you can also disable cache loading and saving for a configure script by redefining the cache macros at the start of `configure.in':

define([AC_CACHE_LOAD], )dnl
define([AC_CACHE_SAVE], )dnl
 ... rest of configure.in ...

It is wrong to try to distribute cache files for particular system types. There is too much room for error in doing that, and too much administrative overhead in maintaining them. For any features that can't be guessed automatically, use the standard method of the canonical system type and linking files (see section Manual Configuration).

The cache file on a particular system will gradually accumulate whenever someone runs a configure script; it will be initially nonexistent. Running configure merges the new cache results with the existing cache file. The site initialization script can specify a site-wide cache file to use instead of the default, to make it work transparently, as long as the same C compiler is used every time (see section Setting Site Defaults).

If your configure script, or a macro called from configure.in, happens to abort the configure process, it may be useful to checkpoint the cache a few times at key points. Doing so will reduce the amount of time it takes to re-run the configure script with (hopefully) the error that caused the previous abort corrected.

 ... AC_INIT, etc. ...
dnl checks for programs
 ... more program checks ...

dnl checks for libraries
AC_CHECK_LIB(nsl, gethostbyname)
AC_CHECK_LIB(socket, connect)
 ... more lib checks ...

dnl Might abort...
AM_PATH_GTK(1.0.2, , exit 1)
AM_PATH_GTKMM(0.9.5, , exit 1)

Printing Messages

configure scripts need to give users running them several kinds of information. The following macros print messages in ways appropriate for each kind. The arguments to all of them get enclosed in shell double quotes, so the shell performs variable and backquote substitution on them. You can print a message containing a comma by quoting the message with the m4 quote characters:

AC_MSG_RESULT([never mind, I found the BASIC compiler])

These macros are all wrappers around the echo shell command. configure scripts should rarely need to run echo directly to print messages for the user. Using these macros makes it easy to change how and when each kind of message is printed; such changes need only be made to the macro definitions, and all of the callers change automatically.

Macro: AC_MSG_CHECKING (feature-description)
Notify the user that configure is checking for a particular feature. This macro prints a message that starts with `checking ' and ends with `...' and no newline. It must be followed by a call to AC_MSG_RESULT to print the result of the check and the newline. The feature-description should be something like `whether the Fortran compiler accepts C++ comments' or `for c89'.

This macro prints nothing if configure is run with the `--quiet' or `--silent' option.

Macro: AC_MSG_RESULT (result-description)
Notify the user of the results of a check. result-description is almost always the value of the cache variable for the check, typically `yes', `no', or a file name. This macro should follow a call to AC_MSG_CHECKING, and the result-description should be the completion of the message printed by the call to AC_MSG_CHECKING.

This macro prints nothing if configure is run with the `--quiet' or `--silent' option.

Macro: AC_MSG_ERROR (error-description)
Notify the user of an error that prevents configure from completing. This macro prints an error message on the standard error output and exits configure with a nonzero status. error-description should be something like `invalid value $HOME for \$HOME'.

Macro: AC_MSG_WARN (problem-description)
Notify the configure user of a possible problem. This macro prints the message on the standard error output; configure continues running afterward, so macros that call AC_MSG_WARN should provide a default (back-up) behavior for the situations they warn about. problem-description should be something like `ln -s seems to make hard links'.

The following two macros are an obsolete alternative to AC_MSG_CHECKING and AC_MSG_RESULT.

Macro: AC_CHECKING (feature-description)
This macro is similar to AC_MSG_CHECKING, except that it prints a newline after the feature-description. It is useful mainly to print a general description of the overall purpose of a group of feature checks, e.g.,

AC_CHECKING(if stack overflow is detectable)

Macro: AC_VERBOSE (result-description)
This macro is similar to AC_MSG_RESULT, except that it is meant to follow a call to AC_CHECKING instead of AC_MSG_CHECKING; it starts the message it prints with a tab. It is considered obsolete.

Go to the first, previous, next, last section, table of contents.