config headers: don't emit rules for headers not generated by autoheader
authorStefano Lattarini <stefano.lattarini@gmail.com>
Fri, 28 Sep 2012 19:27:41 +0000 (21:27 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Tue, 2 Oct 2012 15:12:51 +0000 (17:12 +0200)
This change fixed automake bug#12495.

Even if an AC_CONFIG_HEADERS invocation is passed a list of several files
as the first argument, only the first one of those file is considered by
autoheader for automatic generation of the corresponding '.in' template.
This is done on purpose, and is clearly documented in the Autoconf manual,
which (as of the 2.69 version) reads something like this:

    The autoheader program searches for the first invocation of
    AC_CONFIG_HEADERS in configure sources to determine the name of
    the template.  If the first call of AC_CONFIG_HEADERS specifies
    more than one input file name, autoheader uses the first one.

That is, an invocation like:

    AC_CONFIG_HEADERS([config.h config2.h])

should cause autoheader to generate only a 'config.h.in' template,
and not also a 'config2.h.in' one.

Accordingly, automake, when tracing AC_CONFIG_HEADERS, should generate
remake rules only for the template associated to the first input file
name passed to that macro.  In some situations, however, automake failed
to properly limit itself in this way; for example, with an input like:

    AC_CONFIG_HEADERS([config.h sub/foo.h])

in configure.ac, and with the 'sub' directory listed in the SUBDIRS
variable of the top-level Makefile, automake would erroneously generate
in 'sub/Makefile.in' a rule to remake the 'foo.h.in' template by
invoking autoheader.

This issue was likely introduced in commit 'Release-1-8-23-g262bb92'
of 2004-01-05.

* NEWS: Update.
* doc/automake.texi (Optional): Improve wording in the description of
hat rules automake generates in response to an 'AC_CONFIG_HEADERS'
invocation.
* lib/am/remake-hdr.am: Only emit autoheader-invoking remake rules for
the %CONFIG_HIN% template if that corresponds to the first argument of
AC_CONFIG_HEADERS, as explaned above.  Do so using the automake-time
conditional %?FIRST-HDR%, that is properly passed ...
* automake.in (handle_configure): ... from a 'file_contents' invocation
in here.
* t/autohdr-subdir-pr12495.sh: New test.
* t/list-of-tests.mk: Add it.
* THANKS: Update.

Helped-by: Hib Eris <hib@hiberis.nl>
Signed-off-by: Stefano Lattarini <stefano.lattarini@gmail.com>
NEWS
THANKS
automake.in
doc/automake.texi
lib/am/remake-hdr.am
t/autohdr-subdir-pr12495.sh [new file with mode: 0755]
t/list-of-tests.mk

diff --git a/NEWS b/NEWS
index d67407f..aaa3ad3 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,4 @@
-New in 1.12.4:
+New in 1.12.5:
 
 * WARNING: Future backward-incompatibilities!
 
@@ -61,6 +61,18 @@ New in 1.12.4:
     giving more useful warnings than a bare "command not found" from a
     make recipe would.
 
+Bugs fixed in 1.12.5:
+
+* Long-standing bugs:
+
+  - Automake no longer generates spurious remake rules invoking autoheader
+    to regenerate the template corresponding to header files specified after
+    the first one in AC_CONFIG_HEADERS (automake bug#12495).
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+New in 1.12.4:
+
 * Warnings and deprecations:
 
   - Warnings in the 'obsolete' category are enabled by default both in
diff --git a/THANKS b/THANKS
index ca95db8..88f539c 100644 (file)
--- a/THANKS
+++ b/THANKS
@@ -143,6 +143,7 @@ Harald Dunkel                   harald@CoWare.com
 Harlan Stenn                    Harlan.Stenn@pfcs.com
 He Li                           tippa000@yahoo.com
 Henrik Frystyk Nielsen          frystyk@w3.org
+Hib Eris                        hib@hiberis.nl
 Ian Lance Taylor                ian@cygnus.com
 Ignacy Gawedzki                 i@lri.fr
 Илья Н. Голубев                 gin@mo.msk.ru
index 0983def..4c5ed2c 100644 (file)
@@ -4225,6 +4225,7 @@ sub handle_configure ($$$@)
            file_contents ('remake-hdr',
                           new Automake::Location,
                           FILES            => "@files",
+                          'FIRST-HDR'      => ($hdr_index == 1),
                           CONFIG_H         => $cn_sans_dir,
                           CONFIG_HIN       => $ins[0],
                           CONFIG_H_DEPS    => "@ins",
index 0838822..914c1e8 100644 (file)
@@ -2979,9 +2979,11 @@ Automake will require the sources file declared with
 macro.
 
 @item AC_CONFIG_HEADERS
-Automake will generate rules to rebuild these headers.  Older versions
-of Automake required the use of @code{AM_CONFIG_HEADER}
-(@pxref{Macros}); this is no longer the case.
+Automake will generate rules to rebuild these headers from the
+corresponding templates (usually, the template for a @file{foo.h}
+header being @file{foo.h.in}).  Older versions of Automake required
+the use of @code{AM_CONFIG_HEADER} (@pxref{Macros}); this is no
+longer the case.
 
 As with @code{AC_CONFIG_FILES} (@pxref{Requirements}), parts of the
 specification using shell variables will be ignored as far as
index f61400a..3c7e346 100644 (file)
@@ -30,7 +30,7 @@
 
 ## Only the first file of AC_CONFIG_HEADERS is assumed to be generated
 ## by autoheader.
-if %?FIRST%
+if %?FIRST-HDR%
 %CONFIG_HIN%: %MAINTAINER-MODE% $(am__configure_deps) %FILES%
 ## Cater to parallel BSD make.
        ($(am__cd) $(top_srcdir) && $(AUTOHEADER))
@@ -71,4 +71,4 @@ if %?FIRST%
 ## by config.status, there is no reason to make things complex for
 ## config.hin.
        touch $@
-endif %?FIRST%
+endif %?FIRST-HDR%
diff --git a/t/autohdr-subdir-pr12495.sh b/t/autohdr-subdir-pr12495.sh
new file mode 100755 (executable)
index 0000000..77d2522
--- /dev/null
@@ -0,0 +1,80 @@
+#! /bin/sh
+# Copyright (C) 2012 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/>.
+
+# Related to automake bug#12495: Automake shouldn't generate useless
+# remake rules for AC_CONFIG_HEADERS arguments after the first one,
+# not even when subdirs are involved.
+
+. ./defs || exit 1
+
+cat >> configure.ac << 'END'
+AC_CONFIG_HEADERS([a.h b.h sub/c.h])
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+mkdir sub
+echo SUBDIRS = sub > Makefile.am
+: > sub/Makefile.am
+
+$ACLOCAL
+$AUTOCONF
+$AUTOHEADER
+# Even if an AC_CONFIG_HEADERS invocation is passed several files in
+# the first argument, only the first one is considered by autoheader
+# for automatic generation.  Otherwise, the present test case would
+test -f a.h.in && test ! -f c.h.in && test ! -f sub/c.h.in \
+  || fatal_ "unexpected autoheader behavior with multiple" \
+            "AC_CONFIG_HEADERS arguments"
+# Automake should require the missing headers though.
+AUTOMAKE_fails -Wno-error -Wnone
+grep "^configure\.ac:4:.* required file 'b.h.in' not found" stderr
+grep "^configure\.ac:4:.* required file 'sub/c.h.in' not found" stderr
+: > b.h.in
+: > sub/c.h.in
+$AUTOMAKE
+
+./configure
+
+# Automake should regenerate this.
+grep '^$(srcdir)/a\.h\.in:' Makefile.in
+# But not these.
+grep '[bc]\.h\.in.*:' Makefile.in sub/Makefile.in && exit 1
+
+test -f a.h && test -f b.h && test -f sub/c.h \
+  || fatal_ "unexpected ./configure behavior with multiple" \
+            "AC_CONFIG_HEADERS arguments"
+
+rm -f a.h.in a.h
+$MAKE
+test -f a.h.in
+test -f a.h
+
+ocwd=$(pwd)
+for x in b c; do
+  test $x = b || cd sub
+  rm -f $x.h.in
+  $MAKE $x.h.in 2>stderr && { cat stderr >&2; exit 1; }
+  cat stderr >&2
+  test ! -f $x.h.in
+  if using_gmake; then
+    grep "No rule to make target [\`\"']$x\.h\.in[\`\"']" stderr
+  fi
+  : > $x.h.in
+  cd "$ocwd" || fatal_ "cannot chdir back"
+done
+
+:
index 6effe77..b3ff6b2 100644 (file)
@@ -158,6 +158,7 @@ t/autohdr.sh \
 t/autohdr2.sh \
 t/autohdr3.sh \
 t/autohdr4.sh \
+t/autohdr-subdir-pr12495.sh \
 t/autohdrdry.sh \
 t/automake-cmdline.tap \
 t/auxdir.sh \