Node:Autoconf Language, Next:configure.ac Layout, Previous:Shell Script Compiler, Up:Writing configure.ac
The Autoconf language is very different from many other computer languages because it treats actual code the same as plain text. Whereas in C, for instance, data and instructions have very different syntactic status, in Autoconf their status is rigorously the same. Therefore, we need a means to distinguish literal strings from text to be expanded: quotation.
When calling macros that take arguments, there must not be any blank
space between the macro name and the open parenthesis. Arguments should
be enclosed within the M4 quote characters
], and be
separated by commas. Any leading spaces in arguments are ignored,
unless they are quoted. You may safely leave out the quotes when the
argument is simple text, but always quote complex arguments such
as other macro calls. This rule applies recursively for every macro
call, including macros called from other macros.
AC_CHECK_HEADER([stdio.h], [AC_DEFINE([HAVE_STDIO_H])], [AC_MSG_ERROR([Sorry, can't do anything for you])])
is quoted properly. You may safely simplify its quotation to:
AC_CHECK_HEADER(stdio.h, [AC_DEFINE(HAVE_STDIO_H)], [AC_MSG_ERROR([Sorry, can't do anything for you])])
Notice that the argument of
AC_MSG_ERROR is still quoted;
otherwise, its comma would have been interpreted as an argument separator.
The following example is wrong and dangerous, as it is underquoted:
AC_CHECK_HEADER(stdio.h, AC_DEFINE(HAVE_STDIO_H), AC_MSG_ERROR([Sorry, can't do anything for you]))
In other cases, you may have to use text that also resembles a macro
call. You must quote that text even when it is not passed as a macro
echo "Hard rock was here! --[AC_DC]"
which will result in
echo "Hard rock was here! --AC_DC"
When you use the same text in a macro argument, you must therefore have
an extra quotation level (since one is stripped away by the macro
substitution). In general, then, it is a good idea to use double
quoting for all literal string arguments:
AC_MSG_WARN([[AC_DC stinks --Iron Maiden]])
You are now able to understand one of the constructs of Autoconf that
has been continually misunderstood... 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([char b;],, [AC_MSG_ERROR([you lose])])
is incorrect: here, the first argument of
char b; and will be expanded once, which results in
char b10;. (There was an idiom common in Autoconf's past to
address this issue via the M4
changequote primitive, but do not
use it!) Let's take a closer look: the author meant the first argument
to be understood as a literal, and therefore it must be quoted twice:
AC_COMPILE_IFELSE([[char b;]],, [AC_MSG_ERROR([you lose])])
Voilà, you actually produce
char b; this time!
The careful reader will notice that, according to these guidelines, the
AC_CHECK_HEADER example above is actually
lacking three pairs of quotes! Nevertheless, for the sake of readability,
double quotation of literals is used only where needed in this manual.
Some macros take optional arguments, which this documentation represents
as [arg] (not to be confused with the quote characters). You may
just leave them empty, or use
 to make the emptiness of the
argument explicit, or you may simply omit the trailing commas. The
three lines below are equivalent:
AC_CHECK_HEADERS(stdio.h, , , ) AC_CHECK_HEADERS(stdio.h,,,) AC_CHECK_HEADERS(stdio.h)
It is best to put each macro call on its own line in
configure.ac. Most of the macros don't add extra newlines; they
rely on the newline after the macro call to terminate the commands.
This approach makes the generated
configure script a little
easier to read by not inserting lots of blank lines. It is generally
safe to set shell variables on the same line as a macro call, because
the shell allows assignments without intervening newlines.
You can include comments in
configure.ac files by starting them
#. For example, it is helpful to begin
configure.ac files with a line like this:
# Process this file with autoconf to produce a configure script.