那么autoconf中的单方括号和双方括号有什么区别?
Autoconf docs显示以下示例:
AC_CHECK_TYPES([float_t], [], [], [[#include <math.h>]])
恕我直言,它也适用于单括号:
AC_CHECK_TYPES([float_t], [], [], [#include <math.h>])
答案 0 :(得分:1)
如果您对宏参数使用[[ ]]
,则可以根据需要在宏参数内部使用[
和]
。另一方面,如果您将[]
用作宏参数,则[
和]
在宏参数中保留其特殊的autoconf / m4含义。
如果宏参数中的实际文本包含方括号,例如,
dnl Minimum working example configure.ac. To run:
dnl touch Makefile.am && autoreconf -vis . && ./configure
AC_PREREQ([2.69])
AC_INIT([stackoverflow53609622], [0.0.1], [bugs@example.com])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_PROG_CC
AC_MSG_CHECKING([compile example 1])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
const char hw[] = "Hello, World\n";
const char hs[] = "Hello, Stackoverflow\n";
]])], [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])])
AC_MSG_CHECKING([compile example 2])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
const char hw[[]] = "Hello, World\n";
const char hs[[]] = "Hello, Stackoverflow\n";
])], [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])])
AC_MSG_CHECKING([compile example 3])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
const char hw[] = "Hello, World\n";
const char hs[] = "Hello, Stackoverflow\n";
])], [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
示例1和2将测试编译C程序
const char hw[] = "Hello, World\n";
const char hs[] = "Hello, Stackoverflow\n";
但是示例3将测试编译损坏的C程序
const char hw = "Hello, World\n";
const char hs = "Hello, Stackoverflow\n";
将不会编译(有关编译器错误消息,请参见config.log
)。
但是,如果将不平衡的括号放在宏参数文本中,则m4
仍将对宏参数的开始或结束位置感到困惑。 AFAIK唯一的解决方法是使用四边形(@<:@
使用[
,@:>@
使用]
):
AC_MSG_CHECKING([compile example 4])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
const char hw[] = "Hello, World @<:@-:\n";
const char hs[] = "Hello, Stackoverflow\n";
]])], [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])])
AC_MSG_CHECKING([compile example 5])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
const char hw[] = "Hello, World :-@:>@\n";
const char hs[] = "Hello, Stackoverflow\n";
]])], [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])])
以下操作将在autoreconf
或configure
时失败,这表明出了点问题,您应该从中明确指出。
AC_MSG_CHECKING([compile example 6])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
const char hw[] = "Hello, World :-[\n";
const char hs[] = "Hello, Stackoverflow\n";
]])], [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])])
AC_MSG_CHECKING([compile example 7])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
const char hw[] = "Hello, World :-]\n";
const char hs[] = "Hello, Stackoverflow\n";
]])], [AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no])])
要进一步阅读,您可以从https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/html_node/M4-Quotation.html开始,然后从那里更深入地挖掘。