如何在 autoconf 检查程序时设置常量?

How can I set a constant in autoconf checking for a program?

我正在使用 autotools,我有一个 configure.ac 脚本这样说:

AC_CHECK_PROG(RASPIVID, raspivid, yes)

但是,生成的 config.h 文件不显示 RASPIVID 常量。我做错了什么吗?

AC_CHECK_PROG 宏本身不会对 config.h 做任何事情。来自 the manual:

AC_CHECK_PROG (variable, prog-to-check-for, value-if-found, [value-if-not-found], [path = '$PATH'], [reject])

Check whether program prog-to-check-for exists in path. If it is found, set variable to value-if-found, otherwise to value-if-not-found, if given. Always pass over reject (an absolute file name) even if it is the first found in the search path; in that case, set variable using the absolute file name of the prog-to-check-for found that is not reject. If variable was already set, do nothing. Calls AC_SUBST for variable. The result of this test can be overridden by setting the variable variable or the cache variable ac_cv_prog_variable.

所以AC_CHECK_PROG(RASPIVID, raspivid, yes)会检查raspivid是否存在。如果是,它会将 shell 变量 RASPIVID 设置为值 yes,因此您可以在 AC_CHECK_PROG 调用之后执行测试,例如:

AC_CHECK_PROG([RASPIVID], [raspivid], [yes])
AS_IF([test "x$RASPIVID" = xyes],
    [AC_DEFINE([HAVE_RASPIVID], [1], [raspivid is available.])])

AC_SUBST 将如文档中所述调用,因此您可以在 makefile 或任何输出文件中使用 $(RASPIVID)