autotools - 为什么 autoconf 会缓存我的宏?

标签 autotools autoconf

我正在创建一个 android.m4 文件,以便轻松查找 android SDK/NDK 中程序的路径。

android.m4 文件包含一个名为 _android_path_found_notfound 的辅助函数:

# _android_path_found_notfound(variable, program, path, found, notfound)
#
# search for a program in path. If found, 'variable' is set to the absolute path,
# then executes 'found', otherwise, 'variable' is set to '' and 'notfound' is run
m4_define([_android_path_found_notfound],
    [AC_PATH_PROG([_android_temp_],[$2],[_android_notfound],[$3])
     AS_IF( [test x"$_android_temp_" = x"_android_notfound"],
        [$1=""
        AC_SUBST([$1],[])
        $5],
        [$1="$_android_temp_"
        AC_SUBST([$1],[$_android_temp_])
        $4] )])

以及许多使用该辅助函数的函数:

AC_DEFUN([AC_PROG_ANDROID],
     [_android_path_found_notfound([ANDROID],[android],[$ANDROID_HOME:$PATH],[$1],[$2])]
)

AC_DEFUN([AC_PROG_DX],
     [_android_path_found_notfound([DX],[dx],[$ANDROID_HOME:$PATH],[$1],[$2])]
)

...

但是,当我运行一个调用 AC_PROG_ANDROID 然后调用 AC_PROG_DX 的配置脚本时,我得到:

checking for android... /opt/android-sdk-update-manager/tools/android
checking for dx... (cached) /opt/android-sdk-update-manager/tools/android

第二行指向与第一行相同的程序,并显示(缓存)。为什么结果会被缓存?

最佳答案

AC_PATH_PROG 将其结果保存在特定于 autoconf 的变量中,该变量链接到 AC_PATH_PROG 中给定的变量。因此,如果您说 AC_PATH_PROG([something],...,那么它会记住“something”的答案。由于您的 AC_PROG_ANDROID 和 AC_PROG_DX 都设置了值 _android_temp_,因此其结果将被缓存并稍后使用。

修复此问题的最简单方法可能是对 AC_PROG_ANDROID 和 AC_PROG_DX 使用不同的变量

关于autotools - 为什么 autoconf 会缓存我的宏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16218020/

相关文章:

c++ - 如何在通过自动工具构建的项目中使用Google Test?

autotools - Makefile.am 创建空目录

c - 如何在 AC_COMPILE_IFELSE 程序中使用 AC_CHECK_HEADER header

Autotools:top_srcdir 和 abs_top_srcdir 为空

autotools - 如何为 GNU Autotools 重新配置大型程序

PHP_NEW_EXTENSION() 什么都不做

c - Autoconf 检查 struct flock

c - Autoconf 问题 : “error: C compiler cannot create executables”

linux - 如何在我的安装脚本中使 chgrp 命令可选?

c++ - 在 autotools 项目中包含一个(仅 header )库