AC_CACHE_CHECK 应该如何重置?

发布于 2024-08-08 16:01:28 字数 273 浏览 6 评论 0原文

AC_CACHE_CHECK 应该如何重置?

在 autoconf 中我正在检查标头。我添加了一些逻辑,以便更努力地在 std 文件夹中查找可能不在默认包含路径中的头文件。我这样做的方法是首先尝试查找带有内置 AC_CHECK_HEADER 的头文件。如果找不到标头,我会修改 CPPFLAGS 并重试。

问题在于 autoconf 的缓存。我想强制检查(或绕过缓存检查)。如果我不强制检查,无论 autoconf 是否找到标头,它都会提取在第一次检查中找到的内容,呃。

谢谢, 陈兹

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哽咽笑 2024-08-15 16:01:28

取消设置缓存变量,例如ac_cv_header_syslog_h。您可以检查 config.log 来了解您感兴趣的缓存变量的准确拼写。不幸的是,无法移植地取消设置 shell 变量。 Autoconf 使用的内部解决方法是使用 $as_unset,如果支持的话,它会扩展为 unset。所以你可以写:

$as_unset ac_cv_header_syslog_h

不过,这应该适用于当今最合理的系统。

更好、更直接的解决方案可能是为第一轮检查正确设置 CPPFLAGS 。正如您所注意到的,您正在尝试的内容并没有得到真正的支持。

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.

无戏配角 2024-08-15 16:01:28

我已经实现了一个小宏,它可以完成这项工作(至少对我来说)。通过微小的更改,它可以用于使其他缓存变量无效:

# 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

和用法(在此循环中 $1 = 某个库(例如“netpbm”),$2 = 标头(例如“pbm.h ppm.h”),$3 = 位置(例如“/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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文