autoconf: Caching Results

1 
1 7.4 Caching Results
1 ===================
1 
1 To avoid checking for the same features repeatedly in various
1 `configure' scripts (or in repeated runs of one script), `configure'
11 can optionally save the results of many checks in a "cache file" (⇒
 Cache Files).  If a `configure' script runs with caching enabled and
1 finds a cache file, it reads the results of previous runs from the
1 cache and avoids rerunning those checks.  As a result, `configure' can
1 then run much faster than if it had to perform all of the checks every
1 time.
1 
1  -- Macro: AC_CACHE_VAL (CACHE-ID, COMMANDS-TO-SET-IT)
1      Ensure that the results of the check identified by CACHE-ID are
1      available.  If the results of the check were in the cache file
1      that was read, and `configure' was not given the `--quiet' or
1      `--silent' option, print a message saying that the result was
1      cached; otherwise, run the shell commands COMMANDS-TO-SET-IT.  If
1      the shell commands are run to determine the value, the value is
1      saved in the cache file just before `configure' creates its output
1      files.  ⇒Cache Variable Names, for how to choose the name
1      of the CACHE-ID variable.
1 
1      The COMMANDS-TO-SET-IT _must have no side effects_ except for
1      setting the variable CACHE-ID, see below.
1 
1  -- Macro: AC_CACHE_CHECK (MESSAGE, CACHE-ID, COMMANDS-TO-SET-IT)
1      A wrapper for `AC_CACHE_VAL' that takes care of printing the
1      messages.  This macro provides a convenient shorthand for the most
1      common way to use these macros.  It calls `AC_MSG_CHECKING' for
1      MESSAGE, then `AC_CACHE_VAL' with the CACHE-ID and COMMANDS
1      arguments, and `AC_MSG_RESULT' with CACHE-ID.
1 
1      The COMMANDS-TO-SET-IT _must have no side effects_ except for
1      setting the variable CACHE-ID, see below.
1 
1    It is common to find buggy macros using `AC_CACHE_VAL' or
1 `AC_CACHE_CHECK', because people are tempted to call `AC_DEFINE' in the
1 COMMANDS-TO-SET-IT.  Instead, the code that _follows_ the call to
1 `AC_CACHE_VAL' should call `AC_DEFINE', by examining the value of the
1 cache variable.  For instance, the following macro is broken:
1 
1      AC_DEFUN([AC_SHELL_TRUE],
1      [AC_CACHE_CHECK([whether true(1) works], [my_cv_shell_true_works],
1                      [my_cv_shell_true_works=no
1                       (true) 2>/dev/null && my_cv_shell_true_works=yes
1                       if test "x$my_cv_shell_true_works" = xyes; then
1                         AC_DEFINE([TRUE_WORKS], [1],
1                                   [Define if `true(1)' works properly.])
1                       fi])
1      ])
1 
1 This fails if the cache is enabled: the second time this macro is run,
1 `TRUE_WORKS' _will not be defined_.  The proper implementation is:
1 
1      AC_DEFUN([AC_SHELL_TRUE],
1      [AC_CACHE_CHECK([whether true(1) works], [my_cv_shell_true_works],
1                      [my_cv_shell_true_works=no
1                       (true) 2>/dev/null && my_cv_shell_true_works=yes])
1       if test "x$my_cv_shell_true_works" = xyes; then
1         AC_DEFINE([TRUE_WORKS], [1],
1                   [Define if `true(1)' works properly.])
1       fi
1      ])
1 
1    Also, COMMANDS-TO-SET-IT should not print any messages, for example
1 with `AC_MSG_CHECKING'; do that before calling `AC_CACHE_VAL', so the
1 messages are printed regardless of whether the results of the check are
1 retrieved from the cache or determined by running the shell commands.
1 

Menu