我正在创建一个项目并使用GNU Autoconf工具进行配置和制作。我已经设置了所有的库检查和头文件检查,但似乎无法弄清楚如何检查系统上是否存在可执行文件,如果它不存在则会失败。
我试过了:
AC_CHECK_PROG(TEST,testprogram,testprogram,AC_MSG_ERROR(Cannot find testprogram.))
当我configure
运行并输出时:
Checking for testprogram... find: `testprogram. 15426 5 ': No such file or directory
但不会失败。
答案 0 :(得分:24)
我发现这是最短的方法。
AC_CHECK_PROG(FFMPEG_CHECK,ffmpeg,yes)
AS_IF([test x"$FFMPEG_CHECK" != x"yes"], [AC_MSG_ERROR([Please install ffmpeg before configuring.])])
答案 1 :(得分:10)
尝试这是我刚刚从我的项目中提取的内容,它在路径中寻找名为quantlib-config
的内容:
# borrowed from a check for gnome in GNU gretl: def. a check for quantlib-config
AC_DEFUN(AC_PROG_QUANTLIB, [AC_CHECK_PROG(QUANTLIB,quantlib-config,yes)])
AC_PROG_QUANTLIB
if test x"${QUANTLIB}" == x"yes" ; then
# use quantlib-config for QL settings
[.... more stuff omitted here ...]
else
AC_MSG_ERROR([Please install QuantLib before trying to build RQuantLib.])
fi
答案 2 :(得分:4)
与上述类似,但通过导出条件变量也具有interact with automake的优势
AC_CHECK_PROG([ffmpeg],[ffmpeg],[yes],[no])
AM_CONDITIONAL([FOUND_FFMPEG], [test "x$ffmpeg" = xyes])
AM_COND_IF([FOUND_FFMPEG],,[AC_MSG_ERROR([required program 'ffmpeg' not found.])])
答案 3 :(得分:2)
使用AC_CHECK_PROG时,这是我遇到的最简洁的版本:
AC_CHECK_PROG(BOGUS,[bogus],[bogus],[no])
test "$BOGUS" == "no" && AC_MSG_ERROR([Required program 'bogus' not found.])
当程序丢失时,将生成此输出:
./configure
...cut...
checking for bogus... no
configure: error: Required program 'bogus' not found.
或者当与内置的autoconf程序检查结合使用时,请改为使用:
AC_PROG_YACC
AC_PROG_LEX
test "$YACC" == ":" && AC_MSG_ERROR([Required program 'bison' not found.])
test "$LEX" == ":" && AC_MSG_ERROR([Required program 'flex' not found.])
答案 4 :(得分:1)
在寻找这个问题时偶然发现,我应该注意,如果你想让你的程序只是在pathm中查看,那么运行时测试就足够了:
if ! which programname >/dev/null ; then
AC_MSG_ERROR([Missing programname]
fi
答案 5 :(得分:1)
这不是一个简短的方法,而是一个通用的方法(尽管当有数十个程序要检查时,它可能也是最简短的方法)。取自a project of mine(前缀NA_
代表“ N ot A utotools”)。
通用宏
dnl ***************************************************************************
dnl NA_REQ_PROGS(prog1, [descr1][, prog2, [descr2][, etc., [...]]])
dnl
dnl Checks whether one or more programs have been provided by the user or can
dnl be retrieved automatically. For each program `progx` an uppercase variable
dnl named `PROGX` containing the path where `progx` is located will be created.
dnl If a program is not reachable and the user has not provided any path for it
dnl an error will be generated. The program names given to this function will
dnl be advertised among the `influential environment variables` visible when
dnl launching `./configure --help`.
dnl ***************************************************************************
AC_DEFUN([NA_REQ_PROGS], [
m4_if([$#], [0], [], [
AC_ARG_VAR(m4_translit([$1], [a-z], [A-Z]), [$2])
AS_IF([test "x@S|@{]m4_translit([$1], [a-z], [A-Z])[}" = x], [
AC_PATH_PROG(m4_translit([$1], [a-z], [A-Z]), [$1])
AS_IF([test "x@S|@{]m4_translit([$1], [a-z], [A-Z])[}" = x], [
AC_MSG_ERROR([$1 utility not found])
])
])
m4_if(m4_eval([$# + 1 >> 1]), [1], [], [NA_REQ_PROGS(m4_shift2($*))])
])
])
示例用法
NA_REQ_PROGS(
[find], [Unix find utility],
[xargs], [Unix xargs utility],
[customprogram], [Some custom program],
[etcetera], [Et cetera]
)
这样您就可以在Makefile.am
内完成
$(XARGS)
或
$(CUSTOMPROGRAM)
以此类推。
功能
./configure --help
时,它会在可见的“有影响力的环境变量”中公告程序,以便为程序提供替代路径。何时应使用