23.4.3 Caching results
Autoconf provides a caching facility, whereby the results of a test may
be stored in a cache file. The cache file is itself a Bourne shell
script which is sourced by the `configure' script to set any
`cache variables' to values that are present in the cache file.
The next time `configure' is run, the cache will be consulted for a
prior result. If there is a prior result, the value is re-used and the
code that performs that test is skipped. This speeds up subsequent runs
of `configure' and configuration of deep trees, which can share a
cache file in the top-level directory (see section 3. How to run configure and make).
A custom macro is not required to do caching, though it is considered
best practice. Sometimes it doesn't make sense for a macro to do
caching--tests for system aspects which may frequently change should not
be cached. For example, a test for free disk space should not employ
caching as it is a dynamic characteristic.
The `AC_CACHE_CHECK' macro is a convenient wrapper for caching the
results of tests. You simply provide a description of the test, the
name of a cache variable to store the test result to, and the body of
the test. If the test has not been run before, the cache will be primed
with the result. If the result is already in the cache, then the cache
variable will be set and the test will be skipped. Note that the name
of the cache variable must contain `_cv_' in order to be saved
correctly.
Here is the code for an Autoconf macro that ties together many of the
concepts introduced in this chapter:
|
# AC_PROG_CC_G
# ------------
AC_DEFUN(AC_PROG_CC_G,
[AC_CACHE_CHECK(whether ${CC-cc} accepts -g, ac_cv_prog_cc_g,
[echo 'void f(){}' > conftest.c
if test -z "${CC-cc} -g -c conftest.c 2>&1`"; then
ac_cv_prog_cc_g=yes
else
ac_cv_prog_cc_g=no
fi
rm -f conftest*
])]) # AC_PROG_CC_G
|
|