views:

102

answers:

2

How should AC_CACHE_CHECK be reset?

In autoconf I am checking for headers. I've added some logic to try a little harder to find header files in std folders that might not be in the default include path. The way I do this is first attempt to find a header file with the built-in AC_CHECK_HEADER. If header is not found, I modify the CPPFLAGS and try again.

The problem with this is autoconf's caching. I want to force the check (or bypass the cache check.) If I do not force it, whether autoconf finds the header or not, it will pull what it found in the first check, ugh.

Thanks, Chenz

+1  A: 

Unset the cache variable, such as ac_cv_header_syslog_h. You can check config.log for the exact spelling of the cache variable you are interested in. Unfortunately, unsetting a shell variable cannot be done portably. The internal workaround that Autoconf uses is using $as_unset, which expands to unset if it's supported. So you could write:

$as_unset ac_cv_header_syslog_h

This should work in most reasonable systems nowadays, though.

A better and more straightforward solution might be to just set CPPFLAGS correctly for the first round of checks. As you noticed, what you are trying isn't really supported.

Peter Eisentraut
@Peter: Thank you for the comment. I would recommend to use autoconf-style `AS_UNSET([var_name])` function. I am coding my own function on the top of `AC_CHECK_HEADERS` and the problem is that I don't know in advance the variable name(s) to unset (but I know the headers). I guess I need to reconstruct the name. What can you recommend?
dma_k
A: 

I have implemented a small macro, that does the job (at least for me). With minor changes it can be used to invalidate other cache variables:

# SYNOPSIS
#
# AX_RESET_HEADERS_CACHE(headers ...)
#
# DESCRIPTION
#
# This macro invalidates the headers cache variables created by previous AC_CHECK_HEADER/AC_CHECK_HEADERS checks.
#
AC_DEFUN([AX_RESET_HEADERS_CACHE], [
    AS_FOR([AX_var], [ax_var], [$1], [
        dnl You can replace "ac_cv_header_" with any prefix from http://www.gnu.org/software/autoconf/manual/html_node/Cache-Variable-Index.html
        AS_VAR_PUSHDEF([ax_Var], [ac_cv_header_${ax_var}])
        AS_UNSET([ax_Var])
        AS_VAR_POPDEF([ax_Var])
    ])
]) # AX_RESET_HEADERS_CACHE

and usage (in this loop $1 = some library (e.g. "netpbm"), $2 = headers (e.g. "pbm.h ppm.h"), $3 = locations (e.g. "/usr/include /usr/local/include")):

for ac_test_location in $3 
do
    dnl Save the current state
    ax_probe_library_save_CPPFLAGS=${CPPFLAGS}

    CPPFLAGS="$CPPFLAGS -I${ac_test_location}"

    AC_MSG_CHECKING([$1 for $2 in ${ac_test_location}])
    AS_ECHO()
    _AS_ECHO_LOG([CPPFLAGS="${CPPFLAGS}"])

    AC_CHECK_HEADERS([$2], [ac_lib_$1=yes], [ac_lib_$1=no])

    dnl We have found the location, leave the loop:
    if test "${ac_lib_$1}" = "yes"
    then
        break;
    fi

    dnl Restore the state to original in case of unsuccessful attempt
    CPPFLAGS=${ax_probe_library_save_CPPFLAGS}
    AX_RESET_HEADERS_CACHE([$2])
done
dma_k