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, 开发者_StackOverflowI 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
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.
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
精彩评论