You should always quote an argument that might contain a macro name, comma, parenthesis, or a leading blank or newline. This rule applies recursively for every macro call, including macros called from other macros. For more details on quoting rules, see Programming in M4.
AC_CHECK_HEADER([stdio.h], [AC_DEFINE([HAVE_STDIO_H], , [Define to 1 if you have <stdio.h>.])], [AC_MSG_ERROR([sorry, can't do anything for you])])
is quoted properly. Because ‘1’ cannot contain a macro call, you may safely simplify the quotation to
AC_CHECK_HEADER([stdio.h], [AC_DEFINE([HAVE_STDIO_H], 1, [Define to 1 if you have <stdio.h>.])], [AC_MSG_ERROR([sorry, can't do anything for you])])
However, the argument of
AC_MSG_ERROR must be quoted: otherwise, its comma would be
interpreted as an argument separator.
Also, the second and third arguments
of ‘AC_CHECK_HEADER’ must be quoted, since they contain
The three arguments ‘HAVE_STDIO_H’, ‘stdio.h’, and ‘Define to 1 if you have <stdio.h>.’ do not need quoting, but if you unwisely defined a macro with a name like ‘Define’ or ‘stdio’, then they would need quoting. Cautious Autoconf users would keep the quotes.
The following example is wrong and dangerous, as it is underquoted:
AC_CHECK_HEADER(stdio.h, AC_DEFINE(HAVE_STDIO_H, 1, Define to 1 if you have <stdio.h>.), AC_MSG_ERROR([sorry, can't do anything for you]))
The rule of thumb is that whenever you expect macro expansion, expect quote expansion; i.e., expect one level of quotes to be lost. For instance:
AC_COMPILE_IFELSE(AC_LANG_SOURCE([char b;]), , [AC_MSG_ERROR([you lose])])
is incorrect: here, the first argument of
‘char b;’ and is expanded once, which results in
‘char b10;’; and the
AC_LANG_SOURCE is also expanded prior
to being passed to
The author meant the first argument
to be understood as a literal, and therefore it must be quoted twice;
likewise, the intermediate
AC_LANG_SOURCE macro should be quoted
once so that it is only expanded after the rest of the body of
AC_COMPILE_IFELSE is in place:
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char b;]])], , [AC_MSG_ERROR([you lose])])
Voilà, you actually produce ‘char b;’ this time!
On the other hand, descriptions (e.g., the last parameter of
AS_HELP_STRING) should not be double quoted.
These arguments are treated as whitespace-separated
lists of text to be reformatted, and are not subject to macro expansion.
Even if these descriptions are short and are not actually broken, double
quoting them yields weird results.