autoconf: Quoting and Parameters

1 
1 8.1.3 Quoting and Parameters
1 ----------------------------
1 
1 When M4 encounters `$' within a macro definition, followed immediately
1 by a character it recognizes (`0'...`9', `#', `@', or `*'), it will
1 perform M4 parameter expansion.  This happens regardless of how many
1 layers of quotes the parameter expansion is nested within, or even if
1 it occurs in text that will be rescanned as a comment.
1 
1      define([none], [$1])
1      =>
1      define([one], [[$1]])
1      =>
1      define([two], [[[$1]]])
1      =>
1      define([comment], [# $1])
1      =>
1      define([active], [ACTIVE])
1      =>
1      none([active])
1      =>ACTIVE
1      one([active])
1      =>active
1      two([active])
1      =>[active]
1      comment([active])
1      =># active
1 
1    On the other hand, since autoconf generates shell code, you often
1 want to output shell variable expansion, rather than performing M4
1 parameter expansion.  To do this, you must use M4 quoting to separate
1 the `$' from the next character in the definition of your macro.  If
1 the macro definition occurs in single-quoted text, then insert another
1 level of quoting; if the usage is already inside a double-quoted
1 string, then split it into concatenated strings.
1 
1      define([single], [a single-quoted $[]1 definition])
1      =>
1      define([double], [[a double-quoted $][1 definition]])
1      =>
1      single
1      =>a single-quoted $1 definition
1      double
1      =>a double-quoted $1 definition
1 
1    Posix states that M4 implementations are free to provide
1 implementation extensions when `${' is encountered in a macro
1 definition.  Autoconf reserves the longer sequence `${{' for use with
1 planned extensions that will be available in the future GNU M4 2.0, but
1 guarantees that all other instances of `${' will be output literally.
1 Therefore, this idiom can also be used to output shell code parameter
1 references:
1 
1      define([first], [${1}])first
1      =>${1}
1 
1    Posix also states that `$11' should expand to the first parameter
1 concatenated with a literal `1', although some versions of GNU M4
1 expand the eleventh parameter instead.  For portability, you should
1 only use single-digit M4 parameter expansion.
1 
1    With this in mind, we can explore the cases where macros invoke
1 macros...
1