Subject: bug#14560: [PATCH 1/2] tests: expose automake bug#14560

From: Stefano Lattarini <[email-masked]>
Date: Wed, 12 Jun 2013 12:26:16 +0200

Automake needlessly generates definition of make variables related
to C compilation when two or more user-defined suffix rules are
present in a single Makefile.am.

* t/suffix-extra-c-stuff-pr14560.sh: New test, exposing the bug.
This test is still xfailing.
* t/no-extra-c-stuff.sh: New test, check for a potential related
regression.  This regression is not actually present here (so this
test passes), but it still took place in our first attempt at
fixing bug#14560 -- so this test has proven to be actually useful.
* t/no-extra-makefile-code.sh: Improve comments, and tighten the
grepping checks a little.
* t/list-of-tests.mk (handwritten_TESTS): Add the new tests.
(XFAIL_TESTS): Add the new xfailing test.

Signed-off-by: Stefano Lattarini <[email-masked]>
---
 t/list-of-tests.mk                |  3 ++
 t/no-extra-c-stuff.sh             | 74 +++++++++++++++++++++++++++++++++++++++
 t/no-extra-makefile-code.sh       |  9 +++--
 t/suffix-extra-c-stuff-pr14560.sh | 37 ++++++++++++++++++++
 4 files changed, 121 insertions(+), 2 deletions(-)
 create mode 100644 t/no-extra-c-stuff.sh
 create mode 100644 t/suffix-extra-c-stuff-pr14560.sh

diff --git a/t/list-of-tests.mk b/t/list-of-tests.mk
index 1d7cf87..f2eb648 100644
--- a/t/list-of-tests.mk
+++ b/t/list-of-tests.mk
@@ -42,6 +42,7 @@ t/remake-timing-bug-pr8365.sh \
 t/lex-subobj-nodep.sh \
 t/subobj-indir-pr13928.sh \
 t/subobj-vpath-pr13928.sh \
+t/suffix-extra-c-stuff-pr14560.sh \
 t/remake-am-pr10111.sh \
 t/remake-m4-pr10111.sh \
 $(perl_fake_XFAIL_TESTS)
@@ -695,6 +696,7 @@ t/mkinst2.sh \
 t/mkinst3.sh \
 t/mmode.sh \
 t/mmodely.sh \
+t/no-extra-c-stuff.sh \
 t/no-extra-makefile-code.sh \
 t/no-spurious-install-recursive.sh \
 t/nobase.sh \
@@ -1069,6 +1071,7 @@ t/suffix-chain.tap \
 t/suffix-custom-pr14441.sh \
 t/suffix-custom-subobj.sh \
 t/suffix-custom-subobj-and-specflg.sh \
+t/suffix-extra-c-stuff-pr14560.sh \
 t/symlink.sh \
 t/symlink2.sh \
 t/syntax.sh \
diff --git a/t/no-extra-c-stuff.sh b/t/no-extra-c-stuff.sh
new file mode 100644
index 0000000..de0dd12
--- /dev/null
+++ b/t/no-extra-c-stuff.sh
@@ -0,0 +1,74 @@
+#! /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 Automake doesn't generated rules or definitions related
+# to compilation of C sources for a project that doesn't use nor need
+# a C Compiler.  Inspired by the issues reported in automake bug#14560.
+
+am_create_testdir=empty
+. test-init.sh
+
+cat > configure.ac <<END
+AC_INIT([$me], [1.0])
+AC_CONFIG_AUX_DIR([.])
+AM_INIT_AUTOMAKE
+AC_CONFIG_FILES([
+    Makefile
+    sub/Makefile
+    sub2/Makefile
+])
+AC_PROG_CXX
+AC_PROG_F77
+AC_OUTPUT
+END
+
+cat > Makefile.am <<END
+SUBDIRS = sub sub2
+bin_PROGRAMS = bar
+bar_SOURCES = bar.cc
+END
+
+mkdir sub sub2
+
+cat > sub/Makefile.am <<END
+bin_PROGRAMS = foo
+foo_SOURCES = foo.f
+END
+
+cat > sub2/Makefile.am <<END
+bin_PROGRAMS = baz
+baz_SOURCES = baz.cxx
+END
+
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+test   -f install-sh
+test ! -e compile
+
+# Sanity checks.
+$FGREP '$(CXX)' Makefile.in
+$FGREP '$(CXX)' sub2/Makefile.in
+$FGREP '$(F77)' Makefile.in sub2/Makefile.in && exit 1
+$FGREP '$(F77)' sub/Makefile.in
+$FGREP '$(CXX)' sub/Makefile.in && exit 1
+
+$EGREP '(^COMPILE|$\(CC\)|AM_V_CC)' \
+  Makefile.in sub/Makefile.in sub2/Makefile.in && exit 1
+
+:
diff --git a/t/no-extra-makefile-code.sh b/t/no-extra-makefile-code.sh
index 086b6c6..64ef502 100644
--- a/t/no-extra-makefile-code.sh
+++ b/t/no-extra-makefile-code.sh
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright (C) 1996-2013 Free Software Foundation, Inc.
+# Copyright (C) 2011-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
@@ -25,12 +25,17 @@ echo AC_OUTPUT >> configure.ac
 
 : > Makefile.am
 
+# Automake shouldn't need nor require these.
 rm -f depcomp compile
 
 $ACLOCAL
+
+# Don't use '--add-missing' here, so that we can implicitly
+# check that the auxiliary scripts 'compile' and 'depcomp'
+# are not spuriously required by Automake.
 $AUTOMAKE
 
-$EGREP 'DEFAULT_INCLUDES|@am__isrc@|-compile|\$\(OBJEXT\)|tab\.[ch]' \
+$EGREP 'INCLUDES|@am__isrc@|-compile|\$\(OBJEXT\)|tab\.[ch]' \
   Makefile.in && exit 1
 
 :
diff --git a/t/suffix-extra-c-stuff-pr14560.sh b/t/suffix-extra-c-stuff-pr14560.sh
new file mode 100644
index 0000000..45fdd17
--- /dev/null
+++ b/t/suffix-extra-c-stuff-pr14560.sh
@@ -0,0 +1,37 @@
+#! /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/>.
+
+# Automake bug#14560: if multiple user-specified suffix rules were
+# present, Automake could generate useless definitions and rules
+# related to C compilation.
+
+. test-init.sh
+
+cat > Makefile.am <<'END'
+.foo.bar:
+	foo2bar -o $@ $<
+.baz.qux:
+	baz2qux -o $@ $<
+bin_SCRIPTS = a.bar b.qux
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+$EGREP '\$\(CC\)|COMPILE|AM_V_CC|-compile|INCLUDES' Makefile.in && exit 1
+
+:
-- 
1.8.3.rc3.260.g1462b67