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

标签 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

在变量中定义字符串“this string is being using in WARN as well as ERROR”是有意义的,然后在 AC_MSG_WARNAC_MSG_ERROR。最好的方法是什么?

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

最佳答案

这应该有效:

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

In addition to that, does m4 has any macro which can replace this entire if else by taking string and $foo as argument ?

如果你写一个,它就会的。 :-)。 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])

应该很接近。我没试过。

关于autotools - 如何在 autoconf :configure. ac 中使用字符串变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15541534/

相关文章:

autotools - "Help"字符串变量替换为 "configure --help"

java - 在 Eclipse 和 Java 中使用 m4 宏

m4 - 使用 M4 写入临时文件

linux - M4 未展开 .m4 文件中的所有宏

linux - config/config.guess 被符号链接(symbolic link)到第三方包中的错误文件

c - make 使用 autotools 给出 undefined reference 错误,而自定义 Makefile 工作正常

c - 2个程序的自动工具

c++ - 自动工具编译器

openmp - 在 autoconf 和 automake 中启用 OpenMP 检查和标志