我正在创建一个 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/