autoconf: Quotation Rule Of Thumb

1 
1 8.1.8 Quotation Rule Of Thumb
1 -----------------------------
1 
1 To conclude, the quotation rule of thumb is:
1 
1              _One pair of quotes per pair of parentheses._
1 
1    Never over-quote, never under-quote, in particular in the definition
1 of macros.  In the few places where the macros need to use brackets
1 (usually in C program text or regular expressions), properly quote _the
1 arguments_!
1 
1    It is common to read Autoconf programs with snippets like:
1 
1      AC_TRY_LINK(
1      changequote(<<, >>)dnl
1      <<#include <time.h>
1      #ifndef tzname /* For SGI.  */
1      extern char *tzname[]; /* RS6000 and others reject char **tzname.  */
1      #endif>>,
1      changequote([, ])dnl
1      [atoi (*tzname);], ac_cv_var_tzname=yes, ac_cv_var_tzname=no)
1 
1 which is incredibly useless since `AC_TRY_LINK' is _already_ double
1 quoting, so you just need:
1 
1      AC_TRY_LINK(
1      [#include <time.h>
1      #ifndef tzname /* For SGI.  */
1      extern char *tzname[]; /* RS6000 and others reject char **tzname.  */
1      #endif],
1                  [atoi (*tzname);],
1                  [ac_cv_var_tzname=yes],
1                  [ac_cv_var_tzname=no])
1 
1 The M4-fluent reader might note that these two examples are rigorously
1 equivalent, since M4 swallows both the `changequote(<<, >>)' and `<<'
1 `>>' when it "collects" the arguments: these quotes are not part of the
1 arguments!
1 
1    Simplified, the example above is just doing this:
1 
1      changequote(<<, >>)dnl
1      <<[]>>
1      changequote([, ])dnl
1 
1 instead of simply:
1 
1      [[]]
1 
1    With macros that do not double quote their arguments (which is the
1 rule), double-quote the (risky) literals:
1 
1      AC_LINK_IFELSE([AC_LANG_PROGRAM(
1      [[#include <time.h>
1      #ifndef tzname /* For SGI.  */
1      extern char *tzname[]; /* RS6000 and others reject char **tzname.  */
1      #endif]],
1                                      [atoi (*tzname);])],
1                     [ac_cv_var_tzname=yes],
1                     [ac_cv_var_tzname=no])
1 
1    Please note that the macro `AC_TRY_LINK' is obsolete, so you really
1 should be using `AC_LINK_IFELSE' instead.
1 
1    ⇒Quadrigraphs, for what to do if you run into a hopeless case
1 where quoting does not suffice.
1 
1    When you create a `configure' script using newly written macros,
1 examine it carefully to check whether you need to add more quotes in
1 your macros.  If one or more words have disappeared in the M4 output,
1 you need more quotes.  When in doubt, quote.
1 
1    However, it's also possible to put on too many layers of quotes.  If
1 this happens, the resulting `configure' script may contain unexpanded
1 macros.  The `autoconf' program checks for this problem by looking for
1 the string `AC_' in `configure'.  However, this heuristic does not work
1 in general: for example, it does not catch overquoting in `AC_DEFINE'
1 descriptions.
1