automake-patches
[Top][All Lists]
Advanced

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

[PATCH 1/3] compile: rewrite AC_PROG_CC with AM_PROG_CC_C_O contents


From: Stefano Lattarini
Subject: [PATCH 1/3] compile: rewrite AC_PROG_CC with AM_PROG_CC_C_O contents
Date: Fri, 24 May 2013 20:21:02 +0200

This is a much simpler rewrite than the one we attempted in the past,
and that was later removed by commit 'v1.13.1d-137-g32eb770' of
2013-05-11 (compile: avoid AC_PROG_CC messy rewrite).

Not only this change simplifies the code a little, but has the welcome
collateral effect of making automatic dependency tracking work better
with compilers that doesn't grasp the '-c' and '-o' options together.
Issues in that setup have been caught by several failures in the target
'check-no-cc-c-o'.

Unfortunately, this change has less welcome collateral effects:

  1. AM_PROG_AR must now be called *after* AC_PROG_CC;

  2. Autoconf emits extra warnings when used with Automake-generated
     aclocal.m4.

These are unacceptable regressions for a release, but since we are
going to fix them soon enough in a follow-up patch (surely to be
applied before Automake 1.14 is released) we don't worry too much.

* m4/init.m4: Redefine AC_PROG_CC early, to automatically invoke
AM_PROG_CC_C_O as well.  Accordingly, drop now-unneeded "automagical"
AM_PROG_CC_C_O expansion at later time (which took place thanks to
a AC_CONFIG_COMMANDS_PRE call).
* m4/minuso.m4 (AM_PROG_CC_C_O): Ensure the expansion of the body
of this macro takes place with C as "current Autoconf language" (use
AC_LANG_PUSH/AC_LANG_POP).
* m4/ar-lib.m4 (AM_PROG_AR): Likewise.  Also, require this macro to
be expanded *after* AC_PROG_CC (so that any rewrite of $CC, if required,
has already taken place).
* t/add-missing.tap: Adjust to avoid spurious failures.
* t/aclocal-deps.sh: Likewise, by having AM_PROG_AR called *after*
AC_PROG_CC.
* t/subobj-clean-lt-pr10697.sh: Likewise.
* t/alloca.sh: Likewise.
* t/condlib.sh: Likewise.
* t/discover.sh: Likewise.
* t/objc-megademo.sh: Likewise.
* t/ccnoco.sh: Extend a little.
* t/ccnoco-deps.sh: New test.
* t/ccnoco-lib.sh: Likewise.
* t/ccnoco-lt.sh: Likewise.
* t/list-of-tests.mk: Add them.

Signed-off-by: Stefano Lattarini <address@hidden>
---
 configure.ac                 |  5 +++
 m4/ar-lib.m4                 |  6 ++--
 m4/init.m4                   | 10 +++---
 m4/minuso.m4                 |  4 ++-
 t/aclocal-deps.sh            |  2 +-
 t/add-missing.tap            |  6 ++--
 t/alloca.sh                  |  2 +-
 t/ccnoco-deps.sh             | 82 ++++++++++++++++++++++++++++++++++++++++++++
 t/ccnoco-lib.sh              | 73 +++++++++++++++++++++++++++++++++++++++
 t/ccnoco-lt.sh               | 76 ++++++++++++++++++++++++++++++++++++++++
 t/ccnoco.sh                  | 13 +++++--
 t/condlib.sh                 |  2 +-
 t/discover.sh                |  2 +-
 t/list-of-tests.mk           |  3 ++
 t/objc-megademo.sh           |  6 ++--
 t/subobj-clean-lt-pr10697.sh |  2 +-
 16 files changed, 272 insertions(+), 22 deletions(-)
 create mode 100755 t/ccnoco-deps.sh
 create mode 100755 t/ccnoco-lib.sh
 create mode 100755 t/ccnoco-lt.sh

diff --git a/configure.ac b/configure.ac
index 1a0620f..74b7c1c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -387,6 +387,11 @@ AC_ARG_VAR([AM_TEST_RUNNER_SHELL],
 
 # Look for C, C++ and fortran compilers to be used in the testsuite.
 
+dnl We don't care whether the C Compiler supports "-c -o" together
+dnl or not.  OTOH, we don't want $CC to be rewritten, so we must
+dnl redefine AM_PROG_CC_C_O to be a no-op.
+m4_define([AM_PROG_CC_C_O], [])
+
 dnl We don't want to abort our configuration script if no C compiler is
 dnl available, as such a compiler is only required to run part of the
 dnl testsuite, not to build or install Automake.  Ditto for C++, Fortran
diff --git a/m4/ar-lib.m4 b/m4/ar-lib.m4
index f895f6b..53c8c2a 100644
--- a/m4/ar-lib.m4
+++ b/m4/ar-lib.m4
@@ -13,13 +13,15 @@
 AC_DEFUN([AM_PROG_AR],
 [AC_BEFORE([$0], [LT_INIT])dnl
 AC_BEFORE([$0], [AC_PROG_LIBTOOL])dnl
+AC_BEFORE([AC_PROG_CC])
 AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
 AC_REQUIRE_AUX_FILE([ar-lib])dnl
 AC_CHECK_TOOLS([AR], [ar lib "link -lib"], [false])
 : ${AR=ar}
 
 AC_CACHE_CHECK([the archiver ($AR) interface], [am_cv_ar_interface],
-  [am_cv_ar_interface=ar
+  [AC_LANG_PUSH([C])
+   am_cv_ar_interface=ar
    AC_COMPILE_IFELSE([AC_LANG_SOURCE([[int some_variable = 0;]])],
      [am_ar_try='$AR cru libconftest.a conftest.$ac_objext >&AS_MESSAGE_LOG_FD'
       AC_TRY_EVAL([am_ar_try])
@@ -36,7 +38,7 @@ AC_CACHE_CHECK([the archiver ($AR) interface], 
[am_cv_ar_interface],
       fi
       rm -f conftest.lib libconftest.a
      ])
-   ])
+   AC_LANG_POP([C])])
 
 case $am_cv_ar_interface in
 ar)
diff --git a/m4/init.m4 b/m4/init.m4
index a6f2733..fb6ed58 100644
--- a/m4/init.m4
+++ b/m4/init.m4
@@ -9,6 +9,10 @@
 # This macro actually does too much.  Some checks are only needed if
 # your package does certain things.  But this isn't really a big deal.
 
+dnl Redefine AC_PROG_CC to automatically invoke AM_PROG_CC_C_O.
+m4_define([AC_PROG_CC], m4_defn([AC_PROG_CC])[AM_PROG_CC_C_O
+])
+
 # AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
 # AM_INIT_AUTOMAKE([OPTIONS])
 # -----------------------------------------------
@@ -110,12 +114,6 @@ AC_PROVIDE_IFELSE([AC_PROG_OBJCXX],
                  [m4_define([AC_PROG_OBJCXX],
                             
m4_defn([AC_PROG_OBJCXX])[_AM_DEPENDENCIES([OBJCXX])])])dnl
 ])
-dnl Automatically invoke AM_PROG_CC_C_O as necessary.  Since AC_PROG_CC is
-dnl usually called after AM_INIT_AUTOMAKE, we arrange for the test to be
-dnl done later by AC_CONFIG_COMMANDS_PRE.
-AC_CONFIG_COMMANDS_PRE([AC_PROVIDE_IFELSE(
-    [AC_PROG_CC],
-    [AC_LANG_PUSH([C]) AM_PROG_CC_C_O AC_LANG_POP([C])])])dnl
 AC_REQUIRE([AM_SILENT_RULES])dnl
 dnl The testsuite driver may need to know about EXEEXT, so add the
 dnl 'am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen.  This
diff --git a/m4/minuso.m4 b/m4/minuso.m4
index 06f74c9..3e68f2b 100644
--- a/m4/minuso.m4
+++ b/m4/minuso.m4
@@ -9,7 +9,8 @@
 # --------------
 # Like AC_PROG_CC_C_O, but changed for automake.
 AC_DEFUN_ONCE([AM_PROG_CC_C_O],
-[AC_REQUIRE([AC_PROG_CC_C_O])dnl
+[AC_LANG_PUSH([C])
+AC_REQUIRE([AC_PROG_CC_C_O])dnl
 AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
 AC_REQUIRE_AUX_FILE([compile])dnl
 # FIXME: we rely on the cache variable name because
@@ -25,6 +26,7 @@ if test "$am_t" != yes; then
    # and then we could set am__CC="\$(top_srcdir)/compile \$(CC)"
    CC="$am_aux_dir/compile $CC"
 fi
+AC_LANG_POP([C])
 dnl Make sure AC_PROG_CC is never called again, or it will override our
 dnl setting of CC.
 m4_define([AC_PROG_CC],
diff --git a/t/aclocal-deps.sh b/t/aclocal-deps.sh
index 630282e..5fb6177 100644
--- a/t/aclocal-deps.sh
+++ b/t/aclocal-deps.sh
@@ -22,9 +22,9 @@ required=cc
 
 cat >>configure.ac <<EOF
 AC_CONFIG_MACRO_DIR([m4])
+AC_PROG_CC
 AC_PROG_RANLIB
 AM_PROG_AR
-AC_PROG_CC
 MY_MACRO
 AC_CONFIG_FILES([lib/Makefile])
 AC_OUTPUT
diff --git a/t/add-missing.tap b/t/add-missing.tap
index 053b9a1..e0a628b 100644
--- a/t/add-missing.tap
+++ b/t/add-missing.tap
@@ -248,6 +248,7 @@ check_ <<'END'
 depcomp/C
 == Files ==
 depcomp
+compile
 == configure.ac ==
 AC_PROG_CC
 == Makefile.am ==
@@ -272,10 +273,9 @@ compile
 == Files ==
 compile
 == configure.ac ==
-# Using AC_PROG_CC and AC_OUTPUT in configure.ac should be enough.
+# Using AC_PROG_CC in configure.ac should be enough.
 # No need to also define, say, xxx_PROGRAMS in Makefile.am.
 AC_PROG_CC
-AC_OUTPUT
 END
 
 # For config.guess and config.sub.
@@ -297,6 +297,7 @@ check_ <<'END'
 ylwrap/Lex
 == Files ==
 ylwrap
+compile
 == configure.ac ==
 AC_PROG_CC
 AC_PROG_LEX
@@ -311,6 +312,7 @@ check_ <<'END'
 ylwrap/Yacc
 == Files ==
 ylwrap
+compile
 == configure.ac ==
 AC_PROG_CC
 AC_PROG_YACC
diff --git a/t/alloca.sh b/t/alloca.sh
index 7829dbf..ef6398f 100644
--- a/t/alloca.sh
+++ b/t/alloca.sh
@@ -19,8 +19,8 @@
 . test-init.sh
 
 cat >> configure.ac <<'END'
-AM_PROG_AR
 AC_PROG_CC
+AM_PROG_AR
 END
 
 cat > Makefile.am << 'END'
diff --git a/t/ccnoco-deps.sh b/t/ccnoco-deps.sh
new file mode 100755
index 0000000..d4931d5
--- /dev/null
+++ b/t/ccnoco-deps.sh
@@ -0,0 +1,82 @@
+#! /bin/sh
+# Copyright (C) 2013 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
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Check that dependency tracking can also work with compilers that
+# doesn't understand '-c -o', even if the AM_PROG_CC_C_O macro is not
+# explicitly called.
+
+required=gcc # For 'cc-no-c-o'.
+. test-init.sh
+
+echo '#define myStr "Hello"' > foobar.h
+
+cat > foo.c << 'END'
+#include <stdio.h>
+#include "foobar.h"
+int main (void)
+{
+  printf ("%s\n", myStr);
+  return 0;
+}
+END
+
+cat > Makefile.am <<'END'
+bin_PROGRAMS = foo
+foo_SOURCES = foo.c foobar.h
+check-deps: all
+       test -n '$(DEPDIR)' && test -d '$(DEPDIR)'
+       ls -l $(DEPDIR)
+       grep 'stdio\.h' $(DEPDIR)/foo.Po
+       grep 'foobar\.h' $(DEPDIR)/foo.Po
+check-updated: all
+       is_newest foo foobar.h
+END
+
+# We deliberately don't invoke AM_PROG_CC_C_O here.
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+# Make sure the compiler doesn't understand '-c -o'.
+CC=$am_testaux_builddir/cc-no-c-o; export CC
+
+./configure >stdout || { cat stdout; exit 1; }
+cat stdout
+$EGREP 'understands? -c and -o together.* no$' stdout
+grep '^checking dependency style .*\.\.\. gcc' stdout
+
+$MAKE check-deps
+
+if ! cross_compiling; then
+  ./foo
+  test "$(./foo)" = Hello
+fi
+
+$sleep
+echo '#define myStr "Howdy"' > foobar.h
+$MAKE check-updated
+
+if ! cross_compiling; then
+  ./foo
+  test "$(./foo)" = Howdy
+fi
+
+:
diff --git a/t/ccnoco-lib.sh b/t/ccnoco-lib.sh
new file mode 100755
index 0000000..0e6a375
--- /dev/null
+++ b/t/ccnoco-lib.sh
@@ -0,0 +1,73 @@
+#! /bin/sh
+# Copyright (C) 2001-2013 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
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test to make sure we can compile when the compiler doesn't
+# understand '-c -o'.
+
+required=gcc # For cc-no-c-o.
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+$CC --version || exit 1
+$CC -v || exit 1
+AC_PROG_RANLIB
+AM_PROG_AR
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+mylibsdir = $(libdir)/my-libs
+mylibs_LIBRARIES = libwish.a
+libwish_a_SOURCES = a.c
+# Make sure we need something strange.
+libwish_CFLAGS = -O0
+END
+
+cat > a.c << 'END'
+int wish_granted (void)
+{
+   return 0;
+}
+END
+
+# Make sure the compiler doesn't understand '-c -o'
+CC=$am_testaux_builddir/cc-no-c-o; export CC
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --copy --add-missing
+
+for vpath in : false; do
+  if $vpath; then
+    srcdir=..
+    mkdir build
+    cd build
+  else
+    srcdir=.
+  fi
+  $srcdir/configure >stdout || { cat stdout; exit 1; }
+  cat stdout
+  $EGREP 'understands? -c and -o together.* no$' stdout
+  # No repeated checks please.
+  test $(grep -c ".*-c['\" ].*-o['\" ]" stdout) -eq 1
+  $MAKE
+  cd $srcdir
+done
+
+$MAKE distcheck
+
+:
diff --git a/t/ccnoco-lt.sh b/t/ccnoco-lt.sh
new file mode 100755
index 0000000..793987b
--- /dev/null
+++ b/t/ccnoco-lt.sh
@@ -0,0 +1,76 @@
+#! /bin/sh
+# Copyright (C) 2001-2013 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
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Test to make sure we can compile libtool libraries when the compiler
+# doesn't understand '-c -o'.
+
+required='gcc libtoolize' # For cc-no-c-o.
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AM_PROG_AR
+LT_INIT
+$CC --version
+$CC -v
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+lib_LTLIBRARIES = libwish.la
+END
+
+cat > libwish.c << 'END'
+int wish_granted (void)
+{
+   return 0;
+}
+END
+
+# Make sure the compiler doesn't understand '-c -o'.
+CC=$am_testaux_builddir/cc-no-c-o; export CC
+
+libtoolize --verbose --install
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --copy --add-missing
+
+for vpath in : false; do
+  if $vpath; then
+    srcdir=..
+    mkdir build
+    cd build
+  else
+    srcdir=.
+  fi
+  $srcdir/configure >stdout || { cat stdout; exit 1; }
+  cat stdout
+  $EGREP 'understands? -c and -o together.* no$' stdout
+  # No repeated checks please.
+  test $(grep ".*-c['\" ].*-o['\" ]" stdout \
+          | $FGREP -v ' -c -o file.o' | wc -l) -eq 1
+  # Once we have rewritten $CC to use our 'compile' wrapper script,
+  # libtool should pick it up correctly, and not mess with the
+  # redefinition.
+  grep '^checking if .*/compile .*supports -c -o file\.o\.\.\. yes' stdout
+  # And of course, we should be able to build our package.
+  $MAKE
+  cd $srcdir
+done
+
+$MAKE distcheck
+
+:
diff --git a/t/ccnoco.sh b/t/ccnoco.sh
index be9be37..f9ee218 100644
--- a/t/ccnoco.sh
+++ b/t/ccnoco.sh
@@ -22,7 +22,8 @@ required=gcc # For cc-no-c-o.
 
 cat >> configure.ac << 'END'
 AC_PROG_CC
-$CC --version; $CC -v; # For debugging.
+$CC --version || exit 1
+$CC -v || exit 1
 AC_OUTPUT
 END
 
@@ -42,7 +43,7 @@ int main ()
 }
 END
 
-# Make sure the compiler doesn't understand '-c -o'
+# Make sure the compiler doesn't understand '-c -o'.
 CC=$am_testaux_builddir/cc-no-c-o; export CC
 
 $ACLOCAL
@@ -57,9 +58,15 @@ for vpath in : false; do
   else
     srcdir=.
   fi
-  $srcdir/configure
+  $srcdir/configure >stdout || { cat stdout; exit 1; }
+  cat stdout
+  $EGREP 'understands? -c and -o together.* no$' stdout
+  # No repeated checks please.
+  test $(grep -c ".*-c['\" ].*-o['\" ]" stdout) -eq 1
   $MAKE
   cd $srcdir
 done
 
+$MAKE distcheck
+
 :
diff --git a/t/condlib.sh b/t/condlib.sh
index e01a60a..da5d7e6 100644
--- a/t/condlib.sh
+++ b/t/condlib.sh
@@ -22,8 +22,8 @@
 cat >> configure.ac << 'END'
 AC_PROG_RANLIB
 AM_MAINTAINER_MODE
-AM_PROG_AR
 AC_PROG_CC
+AM_PROG_AR
 END
 
 cat > Makefile.am << 'END'
diff --git a/t/discover.sh b/t/discover.sh
index f841c5b..5d564b5 100644
--- a/t/discover.sh
+++ b/t/discover.sh
@@ -19,9 +19,9 @@
 . test-init.sh
 
 cat >> configure.ac << 'END'
+AC_PROG_CC
 AC_PROG_RANLIB
 AM_PROG_AR
-AC_PROG_CC
 AC_LIBOBJ([fsusage])
 AC_OUTPUT
 END
diff --git a/t/list-of-tests.mk b/t/list-of-tests.mk
index ce3639c..7f77227 100644
--- a/t/list-of-tests.mk
+++ b/t/list-of-tests.mk
@@ -208,8 +208,11 @@ t/canon7.sh \
 t/canon8.sh \
 t/canon-name.sh \
 t/ccnoco.sh \
+t/ccnoco-lib.sh \
+t/ccnoco-lt.sh \
 t/ccnoco3.sh \
 t/ccnoco4.sh \
+t/ccnoco-deps.sh \
 t/check.sh \
 t/check2.sh \
 t/check4.sh \
diff --git a/t/objc-megademo.sh b/t/objc-megademo.sh
index 07764cd..3eb366d 100644
--- a/t/objc-megademo.sh
+++ b/t/objc-megademo.sh
@@ -31,14 +31,14 @@ AC_CONFIG_MACRO_DIR([m4])
 
 AM_INIT_AUTOMAKE
 
-AM_PROG_AR
-LT_INIT
-
 AC_PROG_CC
 AC_PROG_CXX
 AC_PROG_OBJC
 AC_PROG_OBJCXX
 
+AM_PROG_AR
+LT_INIT
+
 AC_LANG_PUSH([Objective C])
 AC_CACHE_CHECK(
   [whether the Objective C compiler really works],
diff --git a/t/subobj-clean-lt-pr10697.sh b/t/subobj-clean-lt-pr10697.sh
index 053ce41..897f966 100644
--- a/t/subobj-clean-lt-pr10697.sh
+++ b/t/subobj-clean-lt-pr10697.sh
@@ -25,9 +25,9 @@ required='cc libtoolize'
 . test-init.sh
 
 cat >> configure.ac << 'END'
+AC_PROG_CC
 AM_PROG_AR
 AC_PROG_LIBTOOL
-AC_PROG_CC
 AC_OUTPUT
 END
 
-- 
1.8.3.rc2




reply via email to

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