bug-autoconf
[Top][All Lists]
Advanced

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

Re: Problem with AC_REQUIRE expansion order


From: Eric Blake
Subject: Re: Problem with AC_REQUIRE expansion order
Date: Mon, 04 Aug 2008 22:26:40 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.16) Gecko/20080708 Thunderbird/2.0.0.16 Mnenhy/0.7.5.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Andreas Schwab on 6/27/2008 7:06 AM:
| When AC_USE_SYSTEM_EXTENSIONS is expanded from a macro that also expands
| AC_PROG_CC for the first time then expansion order is wrong:
|
| $ cat configure.ac
| AC_INIT
| AC_DEFUN([FOO],[
| AC_PROG_CC
| AC_USE_SYSTEM_EXTENSIONS
| ])
| FOO
| AC_OUTPUT
|
| This is also a problem with legacy configure scripts, since AC_AIX and
| AC_MINIX are now aliases of AC_USE_SYSTEM_EXTENSIONS.

The above file failed even with autoconf 2.60 or 2.61, even when I used
AC_AIX and AC_MINIX instead of AC_USE_SYSTEM_EXTENSIONS, so at first, I
didn't see the regression.

But I finally figured out what you were complaining about.  It turns out
that AC_GNU_SOURCE didn't need to invoke the preprocessor or compiler
prior to 2.62; but it does now that it forwards to
AC_USE_SYSTEM_EXTENSIONS and inherited the additional compiler-dependent
checks.  In other words, the regression occurs on this file (works in
2.61, fails in 2.62):

AC_INIT
AC_DEFUN([FOO],[
AC_PROG_CC
AC_GNU_SOURCE
])
FOO
AC_OUTPUT

This really boils down to a bigger problem, that has been present for some
time now, and something related has come up on the list a few times [1].
Basically, AC_PROG_CC doesn't AC_REQUIRE its own body, and this is because
the user is allowed to specify alternate compilers in the argument to
AC_PROG_CC, but the AC_REQUIRE mechanism doesn't really preserve
arguments.  We need a way to honor the user's list while still ensuring
that the body of AC_PROG_CC gets hoisted by any macro that does
AC_REQUIRE([AC_PROG_CC]).  And in the process, that should make AC_PROG_CC
usable within AS_IF, although I have not tested that yet.

[1] http://lists.gnu.org/archive/html/bug-autoconf/2007-03/msg00012.html

I've tested that this patch fixes the above configure.ac on cygwin (on top
of my other AC_USE_SYSTEM_EXTENSIONS patch); and am currently running the
full testsuite on both Linux and cygwin (unfortunately, the complete
testsuite takes several hours on cygwin).  Any comments on my approach?

For those who want to test this patch prior to committing it to the
official repository, you can do:

$ git fetch git://repo.or.cz/autoconf/ericb.git refs/heads/master

or view it at http://repo.or.cz/w/autoconf/ericb.git

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkiX1oAACgkQ84KuGfSFAYAgDQCgmD6iPbIr3a+XucteM8Npu+aV
ixcAnjxY4W+26wT96TM94dGi3Q+nEpw/
=zLON
-----END PGP SIGNATURE-----
>From c308e3f1a6d2a3667b22f4228be2d3b8a7f6e4df Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Mon, 4 Aug 2008 22:10:24 -0600
Subject: [PATCH] Fix autoconf 2.62 regression in AC_GNU_SOURCE vs. AC_PROG_CC.

* lib/autoconf/c.m4 (AC_PROG_CC): Put user selection of
compilers into earlier diversion...
(_AC_PROG_CC): ...so that remaining code can be split into new
macro that is guaranteed to be emitted once by first AC_REQUIRE.
* lib/autoconf/specific.m4 (AC_USE_SYSTEM_EXTENSIONS): Require the
compiler to be found first.
* tests/c.at (AC_USE_SYSTEM_EXTENSIONS): Add to the test.
Reported by Andreas Schwab.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog                |   10 ++++++++++
 lib/autoconf/c.m4        |   23 ++++++++++++++++++-----
 lib/autoconf/specific.m4 |    1 +
 tests/c.at               |   20 ++++++++++++++++++++
 4 files changed, 49 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8aa2d51..911154b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2008-08-04  Eric Blake  <address@hidden>
 
+       Fix autoconf 2.62 regression in AC_GNU_SOURCE vs. AC_PROG_CC.
+       * lib/autoconf/c.m4 (AC_PROG_CC): Put user selection of
+       compilers into earlier diversion...
+       (_AC_PROG_CC): ...so that remaining code can be split into new
+       macro that is guaranteed to be emitted once by first AC_REQUIRE.
+       * lib/autoconf/specific.m4 (AC_USE_SYSTEM_EXTENSIONS): Require the
+       compiler to be found first.
+       * tests/c.at (AC_USE_SYSTEM_EXTENSIONS): Add to the test.
+       Reported by Andreas Schwab.
+
        Fix autoheader 2.62 regression on AC_DEFINE([__EXTENSIONS__]).
        * lib/autoconf/specific.m4 (AC_USE_SYSTEM_EXTENSIONS): Use a
        unique key for the AH_VERBATIM.
diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4
index ffaa06e..fbefeb6 100644
--- a/lib/autoconf/c.m4
+++ b/lib/autoconf/c.m4
@@ -1,7 +1,7 @@
 # This file is part of Autoconf.                       -*- Autoconf -*-
 # Programming languages support.
-# Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software
-# Foundation, Inc.
+# Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free
+# Software Foundation, Inc.
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -544,18 +544,31 @@ AU_DEFUN([ac_cv_prog_gcc],
 # COMPILER ... is a space separated list of C compilers to search for.
 # This just gives the user an opportunity to specify an alternative
 # search list for the C compiler.
+#
+# We want to honor the user's list, while still respecting the many
+# macros that do AC_REQUIRE([AC_PROG_CC]) expecting to get the entire
+# C compiler check in advance.  Hence, the AC_REQUIRE'd body and
+# dumping of the user's list in an earlier diversion.
 AN_MAKEVAR([CC],  [AC_PROG_CC])
 AN_PROGRAM([cc],  [AC_PROG_CC])
 AN_PROGRAM([gcc], [AC_PROG_CC])
 AC_DEFUN([AC_PROG_CC],
+[AC_REQUIRE([_AC_PROG_CC])dnl
+m4_expand_once([m4_divert_text([DEFAULTS],
+  [ac_prog_cc_list=])])dnl
+m4_ifval([$1], [m4_divert_text([INIT_PREPARE],
+  [ac_prog_cc_list='$1'])])dnl
+])
+
+AC_DEFUN([_AC_PROG_CC],
 [AC_LANG_PUSH(C)dnl
 AC_ARG_VAR([CC],     [C compiler command])dnl
 AC_ARG_VAR([CFLAGS], [C compiler flags])dnl
 _AC_ARG_VAR_LDFLAGS()dnl
 _AC_ARG_VAR_LIBS()dnl
 _AC_ARG_VAR_CPPFLAGS()dnl
-m4_ifval([$1],
-      [AC_CHECK_TOOLS(CC, [$1])],
+AS_IF([test -n "$ac_prog_cc_list"],
+[AC_CHECK_TOOLS(CC, [$ac_prog_cc_list])],
 [AC_CHECK_TOOL(CC, gcc)
 if test -z "$CC"; then
   dnl Here we want:
@@ -595,7 +608,7 @@ fi
 _AC_PROG_CC_G
 _AC_PROG_CC_C89
 AC_LANG_POP(C)dnl
-])# AC_PROG_CC
+])# _AC_PROG_CC
 
 
 # _AC_PROG_CC_G
diff --git a/lib/autoconf/specific.m4 b/lib/autoconf/specific.m4
index 5fcfe37..0fd439e 100644
--- a/lib/autoconf/specific.m4
+++ b/lib/autoconf/specific.m4
@@ -386,6 +386,7 @@ matches *mingw32*])# AC_MINGW32
 AC_DEFUN([AC_USE_SYSTEM_EXTENSIONS],
 [AC_BEFORE([$0], [AC_COMPILE_IFELSE])dnl
 AC_BEFORE([$0], [AC_RUN_IFELSE])dnl
+AC_REQUIRE([AC_PROG_CC])dnl
 
   AC_CHECK_HEADER([minix/config.h], [MINIX=yes], [MINIX=])
   if test "$MINIX" = yes; then
diff --git a/tests/c.at b/tests/c.at
index bc07c6e..3c5e167 100644
--- a/tests/c.at
+++ b/tests/c.at
@@ -254,4 +254,24 @@ _AT_CHECK_AC_MACRO(
 AC_DEFINE([__EXTENSIONS__], [1], [Manually defined for Solaris])
 ]])
 
+# Some existing configure.ac want to use both AC_GNU_SOURCE and
+# AC_PROG_CC from a single macro; this was broken in 2.62 when
+# AC_GNU_SOURCE started requiring the compiler.
+
+_AT_CHECK_AC_MACRO(
+[[AC_DEFUN([FOO], [
+AC_PROG_CC
+AC_GNU_SOURCE
+])
+FOO
+]])
+
+_AT_CHECK_AC_MACRO(
+[[AC_DEFUN([FOO], [
+AC_PROG_CC
+AC_USE_SYSTEM_EXTENSIONS
+])
+FOO
+]])
+
 AT_CLEANUP
-- 
1.5.6.4


reply via email to

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