autoconf-patches
[Top][All Lists]
Advanced

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

Re: autoupdate fun


From: Ralf Wildenhues
Subject: Re: autoupdate fun
Date: Sat, 25 Mar 2006 11:44:57 +0100
User-agent: Mutt/1.5.9i

[ this thread starts at:
  http://lists.gnu.org/archive/html/autoconf-patches/2006-03/msg00118.html ]

Hi Stepan,

* Stepan Kasal wrote on Wed, Mar 22, 2006 at 12:49:20AM CET:
> On Mon, Mar 20, 2006 at 09:33:50PM +0100, Ralf Wildenhues wrote:
> >   AC_LANG_SAVE
> >   AC_LANG_SAVE
> > 
> > will lead to m4 looping endlessly.

The fun with AC_LANG_SAVE is not really new, BTW:
http://lists.gnu.org/archive/html/autoconf/2002-12/msg00067.html aka
http://bugs.debian.org/172858 is a report against 2.57, but apparently
the bug was hidden in 2.58.  Let's fix that now, once and for all.

> >   AC_HELP_STRING([--enable-foo], [foo bar])
> > 
> > will turn into
> >   AS_HELP_STRING(--enable-foo,foo bar)

>   I have a patch prepared on my disk.
> The problem was that if configure.ac started with
>       AC_PREREQ(2.54)
>       m4_define([gnumeric_version_epoch], [1])
>       ...
> then the m4_define disappeared after an autoupdate run.
> 
> The fix happen to be quite a big change, but I'm quite sure it makes
> things more consistent.  Please see the attached patch.

OK.  This response has become quite long, much longer than I intended.
So the summary first: Yes, I think your patch is good, but I ask you to
please write a good ChangeLog entry and add some explanatory comments to
the end of bin/autoupdate.in, to let future users know about your
insights.  Feel free to grab from this post if you like.  I wrote some
tests which would be good to be committed along with the changes that
fix the respective issues: in the patch below.


Long winded explanation, with lots of examples (attached):

First observation: your patch seems to fix the AS_HELP_STRING issue,
but with AC_LANG_SAVE, autoupdate still hangs.

An analysis of what autoupdate does:
- After AC_INIT, both 2.59 and HEAD `autoupdate' expand toplevel
  (outside of any macros) m4/m4sugar macros.  This is fixed by Stepan's
  patch.
- Inside AU_DEFUN'ed macros, m4/m4sugar macros are always expanded.
  Not a bug, but a feature: this functionality is needed to express the
  updated code, i.e., to tell autoupdate what to output.
- That in turn means that macros that are *supposed* to be replaced by
  m4sugar code need to prevent that from being expanded by autoupdate.
  This applies to AC_FOREACH and AC_LANG_SAVE.


The trick to get around the bug goes as follows (shamelessly copied from
the implementation of AC_INIT):  We both AU_DEFUN the macro and
m4_define/AC_DEFUN it *after that*.  That way, autoconf will see the
second definition and expand that.  The first, AU_DEFUNed one will be
quoted twice, so it is copied literally into the output by autoupdate.

There's a couple of small glitches left:
- we'd like `autoconf -W obsolete' to warn (this is inhibited by the
  overriding AC_DEFUNed definition).  We achieve that by manually adding
  the diagnosis to the AC_DEFUNed definition.
- we need to exempt these macros from the generated tests: mktests.sh
  assumes that an AC_DEFUNed macro is not obsolete, and we can't replace
  AC_LANG_SAVE automatically (the user has to do this herself).


So, then I did a small audit of all obsolete macro implementations.
Luckily only shows up trivial issues:

- that the replacement of AC_COMPILE_CHECK uses itself-obsolete
  AS_MESSAGE; fixed below,

- that
    AC_MSG_RESULT_UNQUOTED([`echo done`])
  turns into
    _AS_ECHO_UNQUOTED([$as_me:$LINENO: result: `echo done`],[AS_MESSAGE_LOG_FD])
    _AS_ECHO_UNQUOTED([${ECHO_T}`echo done`])

  which is quite ugly but working (and I don't know any higher level
  interface to achieve the same thing), so let's ignore that,

- that AC_COMPILE_CHECK, AC_HAVE_LIBRARY, AC_LINK_FILES,
  AC_OUTPUT_COMMANDS are all ok, despite looking pretty weird.  :)


> IIRC, I tested the patch back then, so the only step remaining is to
> write an autotest check for this.  I even have an impression that it
> existed on my disk at certain moment, but it not there now. :-(
> 
> Then we shall test whether the bugs below survive this patch.

Well, my patch needs to go in after yours (otherwise the AC_LANG_SAVE
test will cause a hang).  Then I think we're through with this.  :-)

Cheers,
Ralf

        * lib/autoconf/general.m4 (AC_COMPILE_CHECK): Prefer
        AC_MSG_CHECKING over obsolete AC_CHECKING in autoupdated code.
        Remove stray newline in output.
        (AC_FOREACH): AU_DEFUN this as literal for autoupdate, and also
        AC_DEFUN this for autoconf, including the obsoletion diagnose.
        Fixes autoupdating of code where the replacement output contains
        m4sugar macros.
        * lib/autoconf/lang.m4 (AC_LANG_SAVE): Likewise.
        * tests/mktests.sh (ac_exclude_list): Add AC_FOREACH.
         (au_exclude_list): Add AC_LANG_SAVE.
        * tests/tools.at: Several new tests for all of this.
        * doc/autoconf.texi (Obsoleting Macros): Give a hint about the
        hairy details.
        The AC_LANG_SAVE issue was reported against Libtool by
        Dalibor Topic <address@hidden>, and against 2.57 by
        Kristian Kvilekval <address@hidden>.

Index: doc/autoconf.texi
===================================================================
RCS file: /cvsroot/autoconf/autoconf/doc/autoconf.texi,v
retrieving revision 1.971
diff -u -r1.971 autoconf.texi
--- doc/autoconf.texi   21 Mar 2006 21:51:07 -0000      1.971
+++ doc/autoconf.texi   25 Mar 2006 00:58:10 -0000
@@ -9927,6 +9927,12 @@
 include information on what to do after running @command{autoupdate};
 @command{autoupdate} will print it as a warning, and include it
 in the updated @file{configure.ac} file.
+
+The details of this macro are hairy: if @command{autoconf} encounters an
address@hidden macro, all macros inside its second argument are expanded
+as usual.  However, when @command{autoupdate} is run, only M4 and M4sugar
+macros will be expanded here, while all other macros are disabled and will
+appear literally in the updated @file{configure.ac}.
 @end defmac
 
 @defmac AU_ALIAS (@var{old-name}, @var{new-name})
Index: lib/autoconf/general.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/autoconf/general.m4,v
retrieving revision 1.891
diff -u -r1.891 general.m4
--- lib/autoconf/general.m4     16 Mar 2006 13:33:18 -0000      1.891
+++ lib/autoconf/general.m4     25 Mar 2006 00:12:16 -0000
@@ -192,7 +192,10 @@
 
 # AU::AC_FOREACH(VARIABLE, LIST, EXPRESSION)
 # ------------------------------------------
-AU_ALIAS([AC_FOREACH], [m4_foreach_w])
+AU_DEFUN([AC_FOREACH], [[m4_foreach_w($@)]])
+AC_DEFUN([AC_FOREACH], [m4_foreach_w($@)dnl
+AC_DIAGNOSE([obsolete], [The macro `AC_FOREACH' is obsolete.
+You should run autoupdate.])])
 
 
 
@@ -2319,9 +2322,8 @@
 #                  ACTION-IF-FOUND, [ACTION-IF-NOT-FOUND])
 # --------------------------------------------------------
 AU_DEFUN([AC_COMPILE_CHECK],
-[m4_ifvaln([$1], [AC_CHECKING([for $1])])dnl
-AC_LINK_IFELSE([AC_LANG_PROGRAM([[$2]], [[$3]])], [$4], [$5])
-])
+[m4_ifvaln([$1], [AC_MSG_CHECKING([for $1])])dnl
+AC_LINK_IFELSE([AC_LANG_PROGRAM([[$2]], [[$3]])], [$4], [$5])])
 
 
 
Index: lib/autoconf/lang.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/autoconf/lang.m4,v
retrieving revision 1.174
diff -u -r1.174 lang.m4
--- lib/autoconf/lang.m4        20 Mar 2006 14:46:12 -0000      1.174
+++ lib/autoconf/lang.m4        25 Mar 2006 00:12:16 -0000
@@ -161,9 +161,13 @@
 # ------------
 # Save the current language, but don't change language.
 AU_DEFUN([AC_LANG_SAVE],
-[m4_pushdef([_AC_LANG], _AC_LANG)],
+[[AC_LANG_SAVE]],
 [Instead of using `AC_LANG', `AC_LANG_SAVE', and `AC_LANG_RESTORE',
 you should use `AC_LANG_PUSH' and `AC_LANG_POP'.])
+AC_DEFUN([AC_LANG_SAVE],
+[m4_pushdef([_AC_LANG], _AC_LANG)dnl
+AC_DIAGNOSE([obsolete], [The macro `AC_LANG_SAVE' is obsolete.
+You should run autoupdate.])])
 
 
 # AC_LANG_RESTORE
Index: tests/mktests.sh
===================================================================
RCS file: /cvsroot/autoconf/autoconf/tests/mktests.sh,v
retrieving revision 1.44
diff -u -r1.44 mktests.sh
--- tests/mktests.sh    6 Mar 2006 21:13:22 -0000       1.44
+++ tests/mktests.sh    25 Mar 2006 00:20:19 -0000
@@ -133,6 +133,9 @@
 # - AC_SYS_RESTARTABLE_SYSCALLS, AC_FUNC_WAIT3
 #   Obsolete, checked in semantics.
 #
+# - AC_FOREACH
+#   Obsolete, but needs to be AC_DEFUN'ed.
+#
 ac_exclude_list='^AC_ARG_VAR$
 ^AC_CANONICALIZE|AC_PREFIX_PROGRAM|AC_PREREQ$
 
^AC_CHECK_(ALIGNOF|DECL|FILE|FUNC|HEADER|LIB|MEMBER|PROG|SIZEOF|(TARGET_)?TOOL|TYPE)S?$
@@ -156,6 +159,7 @@
 ^AC_(CYGWIN|CYGWIN32|EMXOS2|MING32|EXEEXT|OBJEXT)$
 ^AC_PATH_XTRA$
 ^AC_SYS_RESTARTABLE_SYSCALLS$
+^AC_FOREACH$
 _AC_'
 
 
@@ -167,6 +171,8 @@
 
 # au_exclude_list
 # ---------------
+# AC_LANG_SAVE
+#    needs user interaction to be removed.
 # AC_LANG_RESTORE
 #    cannot be used alone.
 # AC_LINK_FILES, AC_PREREQ
@@ -177,7 +183,7 @@
 #    are empty.
 # AC_CYGWIN, AC_MINGW32, AC_EMXOS2
 #    are using AC_REQUIRE.
-au_exclude_list='^AC_LANG_RESTORE$
+au_exclude_list='^AC_LANG_(SAVE|RESTORE)$
 ^AC_LINK_FILES|AC_PREREQ$
 ^AC_(INIT|OUTPUT)$
 ^AC_C_CROSS|AC_PROG_CC_STDC$
Index: tests/tools.at
===================================================================
RCS file: /cvsroot/autoconf/autoconf/tests/tools.at,v
retrieving revision 1.80
diff -u -r1.80 tools.at
--- tests/tools.at      14 Feb 2006 23:18:51 -0000      1.80
+++ tests/tools.at      25 Mar 2006 10:29:10 -0000
@@ -594,3 +594,128 @@
 AT_CHECK([grep 'AC_HEADER_STDC' configure.ac], 0, [ignore], [ignore])
 
 AT_CLEANUP
+
+
+# autoupdating OLD to NEW
+# -----------------------
+
+# The example taken from the code comments.
+AT_SETUP([autoupdating OLD to NEW])
+
+AT_DATA([aclocal.m4],
+[[AU_DEFUN([OLD], [NEW([$1, $2], m4@&address@hidden([$1 + $2]))])
+AC_DEFUN([NEW], [echo "sum($1) = $2"])
+]])
+
+AT_DATA([configure.ac],
+[[AC_INIT
+OLD(1, 2)
+NEW([0, 0], [0])
+]])
+
+# Checking `autoupdate'.
+AT_CHECK_AUTOUPDATE
+AT_CHECK_AUTOCONF
+AT_CHECK_CONFIGURE
+AT_CHECK([[grep 'NEW(\[1, 2], *\[3])' configure.ac]], 0, [ignore], [ignore])
+AT_CHECK([[grep 'NEW(\[0, 0], *\[0])' configure.ac]], 0, [ignore], [ignore])
+
+AT_CLEANUP
+
+
+# autoupdating AC_HELP_STRING
+# ---------------------------
+AT_SETUP([autoupdating AC_HELP_STRING])
+
+AT_DATA([configure.ac],
+[[AC_INIT
+AC_ARG_ENABLE([foo], [AC_HELP_STRING([--enable-foo], [foo bar])], [:], [:])
+]])
+
+# Checking `autoupdate'.
+AT_CHECK_AUTOUPDATE([], [], [], [ignore])
+AT_CHECK_AUTOCONF
+AT_CHECK_CONFIGURE([], [], [], [ignore])
+AT_CHECK([[grep '\[--enable-foo], *\[foo bar]' configure.ac]], 0, [ignore], 
[ignore])
+
+AT_CLEANUP
+
+
+# autoupdating with m4sugar
+# -------------------------
+AT_SETUP([autoupdating with m4sugar])
+
+AT_DATA([aclocal.m4],
+[[AU_DEFUN([OLD],
+[m4@&address@hidden([foo], [bar])dn@&address@hidden
+echo "foo $1 foo"
+m4@&address@hidden([foo])dn@&address@hidden
+])
+]])
+
+touch foo.in
+
+AT_DATA([configure.ac],
+[[AC_PREREQ(2.54)
+m4_define([gnumeric_version_epoch], [1])
+AC_INIT
+OLD([ bla  bla ])
+AC_FOREACH([name], [n1 n2],
+           [echo name
+])
+AC_CHECKING([for feature])
+AC_MSG_RESULT_UNQUOTED([`echo done`])
+
+AC_OUTPUT([foo])
+]])
+
+# Checking `autoupdate'.
+AT_CHECK_AUTOUPDATE([], [], [], [ignore])
+AT_CHECK_AUTOCONF
+AT_CHECK_CONFIGURE([], [], [], [ignore])
+
+AT_CLEANUP
+
+
+# autoupdating AC_LANG_SAVE
+# -------------------------
+AT_SETUP([autoupdating AC_LANG_SAVE])
+
+AT_DATA([configure.ac],
+[[AC_INIT
+AC_LANG_SAVE
+AC_LANG_RESTORE
+AC_LANG_SAVE
+AC_LANG_RESTORE
+]])
+
+# Checking `autoupdate'.
+AT_CHECK_AUTOUPDATE([], [], [], [ignore])
+AT_CHECK_AUTOCONF
+AT_CHECK_CONFIGURE([], [], [], [ignore])
+
+AT_CLEANUP
+
+
+# autoupdating AC_FOREACH
+# -----------------------
+AT_SETUP([autoupdating AC_FOREACH])
+
+AT_DATA([aclocal.m4],
+[[AU_DEFUN([OLD], [AC_FOREACH([myvar], [4 5 6], [' myvar'])])
+]])
+
+AT_DATA([configure.ac],
+[[AC_INIT
+echo AC_FOREACH([myvar], [1 2 3], [' myvar'])OLD
+]])
+
+# Checking `autoupdate'.
+AT_CHECK_AUTOUPDATE
+AT_CHECK([[grep 'echo 1 2 3 4 5 6' configure.ac]], 1, [ignore], [ignore])
+AT_CHECK([[grep 'm4@&address@hidden' configure.ac]], 0, [ignore], [ignore])
+AT_CHECK_AUTOCONF
+AT_CHECK_CONFIGURE([], [0], [stdout])
+AT_CHECK([[grep ' 1 2 3 4 5 6' stdout]], 0, [ignore], [ignore])
+
+AT_CLEANUP




reply via email to

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