如何在autoconf:configure.ac中使用字符串变量

时间:2013-03-21 07:14:39

标签: autotools m4

如何在configure.ac

中使用变量
if test "$foo" = "yes"; then
    AC_MSG_ERROR([this string is being used in WARN as well as ERROR])
else
    AC_MSG_WARN([this string is being used in WARN as well as ERROR])
fi

在变量中定义字符串“此字符串在WARN中使用以及ERROR”是有意义的,然后在 AC_MSG_WARN 中使用该变量的 AC_MSG_ERROR 即可。最好的方法是什么?

除此之外,m4是否有任何宏可以通过将字符串和$ foo作为参数来替换整个if?

1 个答案:

答案 0 :(得分:3)

这应该有效:

msg="this string is being used in WARN as well as ERROR"
if test "$foo" = "yes"; then
    AC_MSG_ERROR([$msg])
else
    AC_MSG_WARN([$msg])
fi
  

除此之外,m4是否有任何宏可以通过将字符串和$ foo作为参数来替换整个if?

如果你写一个,它会。 :-)。 if-else不在m4中,它位于m4的输出中,即configure shell脚本。类似的东西:

AC_DEFUN([AX_TEST_FOO], [
    pushdef([MSG],$1)
    pushdef([FOO],$2)
    AS_IF([test $FOO = yes], [AC_MSG_ERROR([$MSG])], [AC_MSG_WARN([$MSG])])
    popdef([FOO])
    popdef([MSG])
])

调用如:

AX_TEST_FOO(["this string is being used in WARN as well as ERROR"], [$foo])

应该很接近。我没试过。