bug-autoconf
[Top][All Lists]
Advanced

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

AC_SUBST is temperamental in expanding its first argument.


From: Nick Bowler
Subject: AC_SUBST is temperamental in expanding its first argument.
Date: Wed, 15 Aug 2012 22:50:27 -0400

Hi folks,

I noticed today (using Autoconf 2.69, although the problem is still
present in Git) that when the first argument of AC_SUBST contains
macro names, the behaviour is very odd.  Consider the following:

% cat >configure.ac <<'EOF'
AC_INIT([test], [0])

m4_define([FOO], [baz])
AC_SUBST([FOO], [bar])

AC_CONFIG_FILES([test])
AC_OUTPUT
EOF

% cat >test.in <<'EOF'
@FOO@
EOF

This produces no error messages at autoconf time and none at configure
time.  Nevertheless, the substituted value of FOO is the empty string,
instead of bar, as expected.  Sure enough, in the output variables
section of config.log, we see FOO='' instead of FOO='bar'.  Looking
at the generated configure script, we see that AC_SUBST has produced
baz=bar in the output, instead of the expected FOO=bar.  But this is
the only place: everywhere else is still using FOO.

The Autoconf manual does not say anything about the (non-)expansion of
the first argument to AC_SUBST.  However, if we look at the definition
of AC_SUBST in autoconf/lib/autoconf/general.m4, the reason for the
problem seems clear.  The full definition is reproduced here:

  m4_define([AC_SUBST],
  [AS_IDENTIFIER_IF([$1], [],
    [m4_fatal([$0: `$1' is not a valid shell variable name])])]dnl
  [AC_SUBST_TRACE([$1])]dnl
  [m4_pattern_allow([^$1$])]dnl
  [m4_ifvaln([$2], [$1=$2])[]]dnl
  [m4_set_add([_AC_SUBST_VARS], [$1])])# AC_SUBST

Note that the second argument of m4_ifvaln will be expanded further
if it is substituted (i.e., if $2 is non-empty).  Further inspection
reveals that none of the other positions in which $1 appear have any
more expansion done on them.  Therefore, I believe the correct fix is
to add additional quoting to this argument, as in:

  [m4_ifvaln([$2], [[$1]=$2])[]]dnl

Making this change corrects the problem, and as expected, @FOO@ is
substituted with bar.

Cheers,
  Nick



reply via email to

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