15

The following code from my configuration.ac file does not work (note the nested square brackets with [default=no]):

AC_ARG_ENABLE(debug,
    [  --enable-debug          build with debugging support [default=no].],
    [DEBUG="$enableval"],
    [DEBUG="no"]
)

How can I escape those brackets?

user278429
  • 391
  • 2
  • 6

3 Answers3

24

Found it! From this tutorial:

M4 arguments are quoted with [ and ]. There is NO WAY to escape these, however, you have several options if you wish to insert ['s or ]'s:

  1. Use a `Quadrigraph'. @<:@ gives you [ and @:>@ gives you ].
  2. Balance your quotes. M4 will turn [[]] in to []. Beware of using this in arguments to macros. Sometimes, you need to double quote as well ([[[]]]).
  3. Change the quoting using: changequote(<<,>>) to change the quoting to << and >>. The autoconf documentation (rightly, in my opinion) warns against the (over) use of this, since it can lead to unexpected results.
  4. Avoid [ and ] where ever possible. This is my personal choice.

My new code is therefore:

AC_ARG_ENABLE(debug,
    AS_HELP_STRING(
        [--enable-debug],
        [build with debugging symbols @<:@default=no@:>@]),
    [enable_debug="$enableval"],
    [enable_debug="no"]
)
Darren Ng
  • 373
  • 5
  • 12
user278429
  • 391
  • 2
  • 6
9

Brackets are kind of escape characters, so as you do for '\', you may escape brackets [] with brackets, eg :

AC_ARG_ENABLE(debug, [ --enable-debug build with debugging support [[default=no]].], [DEBUG="$enableval"], [DEBUG="no"] )

Note: [[ ]default=no[ ]] may not work as you expect as m4 should search the end_bracket from the end. It should so be expanded to [ ]default=no[ ].

bipen
  • 36,319
  • 9
  • 49
  • 62
jbar
  • 91
  • 1
  • 1
-1

use AC_HELP_STRING

Anycorn
  • 50,217
  • 42
  • 167
  • 261