bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: m4 brackets question


From: Eric Blake
Subject: Re: m4 brackets question
Date: Tue, 13 Sep 2011 15:45:19 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.20) Gecko/20110831 Fedora/3.1.12-2.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.12

On 09/13/2011 03:09 PM, Bruno Haible wrote:
Please, can you turn off these "m4 comments" for Autoconf 3.0?

You can turn them off yourself with m4_changecom(). This hasn't been a regularly requested feature, but I'm worried about the backwards-compatibility aspect of doing it globally.


Now about the macros in gnulib. I guess this one is not problematic?
There are many #include statements like this.

   tanl.m4:54:    AC_CHECK_DECL([tanl], , [HAVE_DECL_TANL=0], 
[#include<math.h>])

Underquoted (and autoconf has magic in AC_CHECK_DECL that tries to deal with the underquoting, since this is so common), since the fourth argument of AC_CHECK_DECL is supposed to allow further m4 macro expansion when used properly. Should be:

AC_CHECK_DECL([tanl], , [HAVE_DECL_TANL=0], [[#include <math.h>]])

Note how the fourth argument is double-quoted, since we want the # to be treated as a literal output character, and not single-quoted, since we don't want any further macro expansion done by AC_CHECK_DECL to mistakenly treat #include <math.h> as anything needing m4 expansion.


Which of the following code lines should be changed, for maintainability?

   absolute-header.m4:87:      s#^/[^/]#//&#

Underquoted. I'd recommend using | instead of # in the sed snippet, at which point you then need double-quoting to get the literal bracket expression into the output. Minimal double quoting:

  s|^/[[^/]]|//&|

or copy-and-pastable double-quoting:

[
  s|^/[^/]|//&|
]

   csharpcomp.m4:15:  AC_MSG_CHECKING([for C[#] compiler])

Correctly double-quoted (with minimal range), also possible to use maximal double-quoting as:

AC_MSG_CHECKING([[for C# compiler]])

   csharpexec.m4:15:  AC_MSG_CHECKING([for C[#] program execution engine])
   csharp.m4:11:  AC_MSG_CHECKING([for preferred C[#] implementation])

Likewise for these two.

   csharp.m4:13:    [  --enable-csharp[[=IMPL]]  choose preferred C[#] 
implementation (pnet or mono)],

The second argument to AC_ARG_ENABLE should generally be using AS_HELP_STRING to get better line-wrapping capabilities. As written, this is a literal string and properly quoted, but if rewritten to use AS_HELP_STRING, it is overquoted (AS_HELP_STRING, and any other macro that does word wrapping with no further m4 expansion, already documents that no double-quoting is needed; that is, any macro argument that does not fit the rule of thumb where using double-quoting prevents further macro expansion, because no further macro expansion will occur, should already be documented as such).

   csharp.m4:21:        [Define if pnet is the preferred C# implementation.])
   csharp.m4:25:        [Define if mono is the preferred C# implementation.])

Properly quoted: AC_DEFINE documents that the third argument is one of those contexts that does word wrapping with no further m4 expansion.

   include_next.m4:226:               
gl_absolute_header_sed='\#'"${gl_dirsep_regex}"']m4_defn([gl_HEADER_NAME])[#{
   include_next.m4:227:                   
s#.*"\(.*'"${gl_dirsep_regex}"']m4_defn([gl_HEADER_NAME])[\)".*#\1#
   include_next.m4:228:                   s#^/[^/]#//&#

What started this conversation, and rather difficult to decipher. Hence my recommendation to use s||| instead of s###, at which point you need double-quoting to preserve literal bracket regex.

   po.m4:122:          cat "$ac_given_srcdir/$ac_dir/POTFILES.in" | sed -e "/^#/d" -e "/^[ ${gt_tab}]*\$/d" -e 
"s,.*,     $top_srcdir/&  \\\\," | sed -e "\$s/\(.*\) \\\\/\1/">  "$ac_dir/POTFILES"

Similar to the include_next question about why we are using # as the sed delimiter.

--
Eric Blake   address@hidden    +1-801-349-2682
Libvirt virtualization library http://libvirt.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]