Previous: , Up: Autoconf Language   [Contents][Index]

5.2.1.3 Macro name quoting

You need to quote macro names which you want Autoconf to pass through to the configure script without expanding. You should also quote a word that looks as if it may be a macro, in case a macro of that name is added at a later date. kAre they actually forbidden?) You must quote that text whether it is passed as a macro argument or not.

The macros that Autoconf makes available begin with ‘AC_’, ‘AU_’, ‘AH_’, ‘AS_’ or ‘m4_’. The names of macros that Automake makes available begin with ‘AM_’. (There are also a handful of others that don’t follow this pattern: others not following this pattern: dnl, __file__, __line__ and __oline.)

For example, in order for the following to appear in configure

echo "Hard rock was here!  --AC_DC"

you need to quote the ‘AC_DC’ part, to protect your script in case Autoconf ever adds a macro AC_DC. This will be achieved with either of these two approaches in configure.ac (quoting just the potential problems, or quoting the entire line):

echo "Hard rock was here!  --[AC_DC]"
[echo "Hard rock was here!  --AC_DC"]

When you use the same text in a macro argument, you must have an extra quotation level (since one is stripped away by the macro substitution), either around just the problematic portions, or over the entire argument:

AC_MSG_WARN([[AC_DC] stinks  --Iron Maiden])
AC_MSG_WARN([[AC_DC stinks  --Iron Maiden]])

In general, then, it is a good idea to use double quoting for all literal string arguments.

To be really safe, you can silence an autoconf warning about a possibly unexpanded macro, because it collides with the namespace of macros reserved for the Autoconf language. To achieve this, you can either use creative shell constructs, or use a quadrigraph:

echo "Hard rock was here!  --AC""_DC"
AC_MSG_WARN([[AC@&t@_DC stinks  --Iron Maiden]])

If you need to pass through a macro name to the produced configure script, you need to use m4_pattern_allow and quote the occurence of the name, thus:

m4_pattern_allow([dnl])
echo fun fact: [dnl] stands for Discard to Next Line

dnl is a built-in M4 macro that leads to the rest of the line being discarded, so the following line in configure.ac

echo fun fact: dnl stands for Discard to Next Line

will lead to the following being output when configure is run:

fun fact: 

Previous: , Up: Autoconf Language   [Contents][Index]