]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
[ng] compile: add extra -I opts from config headers at make runtime
authorStefano Lattarini <stefano.lattarini@gmail.com>
Sun, 27 May 2012 18:27:24 +0000 (20:27 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Tue, 29 May 2012 10:48:25 +0000 (12:48 +0200)
Unless the 'no-stdinc' option is in use, automake automatically adds
to the compiler's include path (through the use of '-I' options placed
in the $(DEFAULT_INCLUDES) variable) the $(srcdir), the current
directory, and all the directories where header files specified with
AC_CONFIG_HEADERS macro are placed.  It also tries to remove unseemly
duplicated '-I' entries, for  example simplifying "-I. -I$(srcdir)" to
"-I." when in a non-VPATH build (in which case '$(srcdir)' is simply
'.').

Before this change, that preprocessing was done both at automake runtime
and configure runtime; with GNU make features, we can simplify it a bit
and move almost all of it at make runtime instead.

* automake.in (handle_compile): Remove automake-time preprocessing, and
support for further configure-time preprocessing, of the intended contents
of $(DEFAULT_INCLUDES); instead, move all of them ...
* lib/am/compile.am (DEFAULT_INCLUDES) [%?STDINC%]: ... here.
* m4/init.m4: Remove AC_SUBST of @am__isrc@.
* t/no-extra-makefile-code.sh: Trivially adjust.
* t/nostdinc.sh: Adjust by preferring more "semantic" checks to grepping
checks.
* t/confh4.sh: Adjust and extend.
* t/stdinc-no-repeated.sh: New test.
* Makefile.am (do_subst): Remove a now-unneeded hack.

Signed-off-by: Stefano Lattarini <stefano.lattarini@gmail.com>
Makefile.am
automake.in
lib/am/compile.am
m4/init.m4
t/confh4.sh
t/no-extra-makefile-code.sh
t/nostdinc.sh
t/stdinc-no-repeated.sh [new file with mode: 0755]

index 7b4a8a67e979939a7cba6e6d7475699bfd8d8903..533faef45469a88e0ca881444410c8f1a13ad89d 100644 (file)
@@ -31,16 +31,11 @@ EXTRA_DIST =
 # then use config.status to substitute the remainder where a single
 # expansion is sufficient.  We use a funny notation here to avoid
 # configure substitutions in our text.
-do_subst = sed $(strip \
+do_subst = sed $(strip \
   $(foreach x, data am bin doc pkgvdata script automake_ac system_ac, \
               -e 's,@$(x)dir@,$($(x)dir),g')) \
   -e "s,[@]configure_input@,Generated from $(<F) do not edit by hand.,g" \
-## Hack to avoid a spurious substitution in the Automake script (part 1).
-  -e 's,[@]am__isrc[@],!!@!!am__isrc!!@!!,g' \
-  | $(SHELL) ./config.status --file=- \
-## Hack to avoid a spurious substitution in the Automake script (part 2).
-  | sed -e 's,!!@!!am__isrc!!@!!,@''am__isrc@,g' \
-) <$< >$@-t
+  <"$<" | $(SHELL) ./config.status --file=- >"$@-t"
 
 # Generated  files shouldn't contain unexpanded '@substitutions@', and
 # should be made read-only, to prevent them from being edited by mistake
index fb53813ccf1b5c93b17d050fcf1e7b430ee86e44..e23049c801ac2e137762867832bc97dedea3401a 100644 (file)
@@ -2275,29 +2275,6 @@ sub handle_compile ()
 {
    return if ! $must_handle_compiled_objects;
 
-    # Boilerplate.
-    my $default_includes = '';
-    if (! option 'nostdinc')
-      {
-       my @incs = ('-I.', subst ('am__isrc'));
-
-       my $var = var 'AM_CONFIG_HEADERS';
-       if ($var)
-         {
-           foreach my $hdr (split (' ', $var->variable_value))
-             {
-               push @incs, '-I' . dirname ($hdr);
-             }
-         }
-       # We want '-I. -I$(srcdir)', but the latter -I is redundant
-       # and unaesthetic in non-VPATH builds.  We use `-I.@am__isrc@`
-       # instead.  It will be replaced by '-I.' or '-I. -I$(srcdir)'.
-       # Items in AM_CONFIG_HEADERS are never in $(srcdir) so it
-        # is safe to just put @am__isrc@ right after '-I.', without a
-        # space.
-       ($default_includes = ' ' . uniq (@incs)) =~ s/ @/@/;
-      }
-
     my (@mostly_rms, @dist_rms);
     foreach my $item (sort keys %compile_clean_files)
     {
@@ -2318,7 +2295,7 @@ sub handle_compile ()
     my ($coms, $vars, $rules) =
       &file_contents_internal (1, "$libdir/am/compile.am",
                               new Automake::Location,
-                              ('DEFAULT_INCLUDES' => $default_includes,
+                              ('STDINC' => ! option 'nostdinc',
                                'MOSTLYRMS' => join ("\n", @mostly_rms),
                                'DISTRMS' => join ("\n", @dist_rms)));
     $output_vars .= $vars;
index 7b37da23a49bee0b8051c867d0f511e0749cd4fe..6e515e51fce85c66ef31417544cdd69051e3b10a 100644 (file)
 ## You should have received a copy of the GNU General Public License
 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-DEFAULT_INCLUDES = %DEFAULT_INCLUDES%
+if %?STDINC%
+DEFAULT_INCLUDES = \
+  $(call am__memoize,DEFAULT_INCLUDES,$(strip \
+## We want '-I. -I$(srcdir)', but the latter -I is redundant and
+## unaesthetic in non-VPATH builds, so get rid of it if it is not
+## actually needed.
+    $(call am__uniq, -I. -I$(srcdir) \
+      $(foreach am__h, $(AM_CONFIG_HEADERS), \
+        $(patsubst %/,%,-I$(dir $(am__h)))))))
+else !%?STDINC%
+DEFAULT_INCLUDES =
+endif !%?STDINC%
 
 mostlyclean-am: mostlyclean-compile
 mostlyclean-compile:
index a0f04dba55216074ed2fef4677c04c2eba42e978..0abf7879ef184a6d9845edf76fafd672519edbc4 100644 (file)
@@ -21,10 +21,6 @@ m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl
 AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl
 AC_REQUIRE([AC_PROG_INSTALL])dnl
 if test "`cd $srcdir && pwd`" != "`pwd`"; then
-  # Use -I$(srcdir) only when $(srcdir) != ., so that make's output
-  # is not polluted with repeated "-I."
-  AC_SUBST([am__isrc], [' -I$(srcdir)'])_AM_SUBST_NOTMAKE([am__isrc])dnl
-  # test to see if srcdir already configured
   if test -f $srcdir/config.status; then
     AC_MSG_ERROR([source directory already configured; run "make distclean" there first])
   fi
index 665e04a0a952634625294efcdef458c2482e1fa1..a87b38e4fcb1499f4e1f712f71e741a4b2164e6e 100755 (executable)
 # > How-To-Repeat:
 #  Use AM_CONFIG_HEADER(subdir/config.h) to place configuration
 #  header in subdirectory and observe that it is not included.
+# Also check that our preprocessing code is smart enough not to pass
+# repeated '-I<DIR>' options on the compiler command line.
 
 . ./defs || Exit 1
 
 cat >> configure.ac << 'END'
-AC_CONFIG_FILES([include/Makefile])
+AC_CONFIG_FILES([include/Makefile sub/Makefile])
 AC_CONFIG_HEADERS([include/config.h])
-AC_PROG_CC
+AC_PROG_FGREP
+AC_OUTPUT
 END
 
-cat > Makefile.am << 'END'
+mkdir include sub
+: > include/config.h.in
+
+cat > c-defs.am << 'END'
+## To bring in the definition of DEFAULT_INCLUDES
+CC = who-cares
+AUTOMAKE_OPTIONS = no-dependencies
 bin_PROGRAMS = foo
-foo_SOURCES = foo.c
 END
 
-mkdir include
-: > include/Makefile.am
-: > include/config.h.in
+cat > Makefile.am << 'END'
+include $(top_srcdir)/c-defs.am
+.PHONY: test-default-includes
+test-default-includes:
+       echo ' ' $(DEFAULT_INCLUDES) ' ' \
+         | $(FGREP) ' -I$(top_builddir)/include '
+END
+
+cp Makefile.am sub
+
+cat > include/Makefile.am << 'END'
+include $(top_srcdir)/c-defs.am
+.PHONY: test-default-includes
+test-default-includes:
+       echo ' ' $(DEFAULT_INCLUDES) ' ' | $(FGREP) ' -I. '
+       case ' $(DEFAULT_INCLUDES) ' in \
+         *'$(top_builddir)'*) exit 1;; \
+         *include*) exit 1;; \
+         *-I.*-I.*) exit 1;; \
+         *' -I. ') exit 0;; \
+         *) exit 1;; \
+       esac
+END
 
 $ACLOCAL
+$AUTOCONF
 $AUTOMAKE
 
-grep '^ *DEFAULT_INCLUDES *=.* -I\$(top_builddir)/include' Makefile.in
+./configure
+
+$MAKE test-default-includes
+$MAKE -C sub test-default-includes
+$MAKE -C include test-default-includes
 
 :
index 1742dc433718a247676d54da5f7f41a7494777d3..f0246b769f672d36e925c788a61f01f450614dae 100755 (executable)
@@ -30,7 +30,7 @@ rm -f depcomp compile
 $ACLOCAL
 $AUTOMAKE
 
-$EGREP 'DEFAULT_INCLUDES|@am__isrc@|-compile|\$\(OBJEXT\)|tab\.[ch]' \
-  Makefile.in && Exit 1
+$EGREP 'DEFAULT_INCLUDES|-compile|\$\(OBJEXT\)|tab\.[ch]' Makefile.in \
+  && Exit 1
 
 :
index 8b780a6e5cdc6e2a658441ab503fbc8c6230f56d..62e752e6ac1c1d2d4fea4ae604d386bebe6f2320 100755 (executable)
 
 # Test to make sure nostdinc option works correctly.
 
-# We don't require a C compiler explicitly, because the first part of the
-# test (where 'Makefile.in' is grepped) does not require one.  Insted, we
-# just skip the rest of the test if configure fails to find a working C
-# compiler.
-
+required=cc
 . ./defs || Exit 1
 
 cat >> configure.ac << 'END'
@@ -31,26 +27,43 @@ END
 cat > Makefile.am << 'END'
 AUTOMAKE_OPTIONS = nostdinc
 bin_PROGRAMS = foo
-foo_SOURCES = foo.c
 END
 
-$ACLOCAL
-$AUTOMAKE
+cat > foo.c << 'END'
+#include <stdlib.h>
+int main (void)
+{
+  exit (0);
+}
+END
 
-$EGREP '(-I *\.|-I.*srcdir|am__isrc)' Makefile.in && Exit 1
+# This shouldn't be picked up.
+cat > stdlib.h << 'END'
+#error "stdlib.h from source dir included"
+choke me
+END
 
-# We'll test the fully-processed Makefile too.
+$ACLOCAL
 $AUTOCONF
+$AUTOMAKE --add-missing
 
 # Test with $builddir != $srcdir
 mkdir build
 cd build
-../configure || Exit $?
-$EGREP '.*-I *(\.|\$.srcdir.)' Makefile && Exit 1
+../configure
+$MAKE V=1 > output || { cat output; Exit 1; }
+cat output
+grep '.*-I *\.' stdout && Exit 1
+$MAKE clean
+# Shouldn't be picked up from builddir either.
+cp ../stdlib.h .
+$MAKE
+cd ..
 
 # Test with $builddir = $srcdir
-cd ..
-./configure || Exit $?
-$EGREP '.*-I *(\.|\$.srcdir.)' Makefile && Exit 1
+./configure
+$MAKE V=1 > output || { cat output; Exit 1; }
+cat output
+grep '.*-I *\.' output && Exit 1
 
-Exit 0
+:
diff --git a/t/stdinc-no-repeated.sh b/t/stdinc-no-repeated.sh
new file mode 100755 (executable)
index 0000000..159cda5
--- /dev/null
@@ -0,0 +1,52 @@
+#!/bin/sh
+# Copyright (C) 2009-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/>.
+
+# Check that automake rules do not use repeated "-I $(srcdir)" in the
+# compiler invocation.
+
+required=cc
+. ./defs || Exit 1
+
+cat >> configure.ac << 'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+echo 'bin_PROGRAMS = foo' > Makefile.am
+echo 'int main (void) { return 0; }' > foo.c
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+
+# Test with $builddir != $srcdir
+mkdir build
+cd build
+../configure
+$MAKE V=1 > stdout || { cat stdout; Exit 1; }
+cat stdout
+grep '.*-I *\. .*-I *\.\. ' stdout
+grep '.*-I *\. .*-I *\. ' stdout && Exit 1
+cd ..
+
+# Test with $builddir = $srcdir
+./configure
+$MAKE V=1 > stdout || { cat stdout; Exit 1; }
+cat stdout
+grep '.*-I *\.  ' stdout
+grep '.*-I *\..*-I *\.' stdout && Exit 1
+
+: