23.4.3 Caching results

back: using m4 correctly
forward: future directions for macro writers
fastback: future directions for macro writers
up: implementation specifics
fastforward: future directions for macro writers
top: autoconf, automake, and libtool
contents: table of contents
index: index
about: about this document

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 convient 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 

This document was generated by Gary V. Vaughan on May, 24 2001 using texi2html

GNU Autoconf, Automake and Libtool
GNU Autoconf, Automake, and Libtool
ISBN: 1578701902
EAN: 2147483647
Year: 2002
Pages: 290

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net