[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Automake-NG] [PATCH 3/4] compile: add extra -I opts from config headers
From: |
Stefano Lattarini |
Subject: |
[Automake-NG] [PATCH 3/4] compile: add extra -I opts from config headers at make runtime |
Date: |
Mon, 28 May 2012 11:35:04 +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 @address@hidden
* 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.
Signed-off-by: Stefano Lattarini <address@hidden>
---
automake.in | 25 +--------------------
lib/am/compile.am | 13 ++++++++++-
m4/init.m4 | 4 ----
t/confh4.sh | 49 +++++++++++++++++++++++++++++++++-------
t/no-extra-makefile-code.sh | 4 ++--
t/nostdinc.sh | 45 ++++++++++++++++++++++++-------------
t/stdinc-no-repeated.sh | 52 +++++++++++++++++++++++++++++++++++++++++++
7 files changed, 137 insertions(+), 55 deletions(-)
create mode 100755 t/stdinc-no-repeated.sh
diff --git a/automake.in b/automake.in
index fb53813..e23049c 100644
--- a/automake.in
+++ b/automake.in
@@ -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 address@hidden@`
- # 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;
diff --git a/lib/am/compile.am b/lib/am/compile.am
index 7b37da2..6e515e5 100644
--- a/lib/am/compile.am
+++ b/lib/am/compile.am
@@ -14,7 +14,18 @@
## 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:
diff --git a/m4/init.m4 b/m4/init.m4
index a0f04db..0abf787 100644
--- a/m4/init.m4
+++ b/m4/init.m4
@@ -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
diff --git a/t/confh4.sh b/t/confh4.sh
index 665e04a..a87b38e 100755
--- a/t/confh4.sh
+++ b/t/confh4.sh
@@ -21,27 +21,60 @@
# > 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
:
diff --git a/t/no-extra-makefile-code.sh b/t/no-extra-makefile-code.sh
index 1742dc4..f0246b7 100755
--- a/t/no-extra-makefile-code.sh
+++ b/t/no-extra-makefile-code.sh
@@ -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
:
diff --git a/t/nostdinc.sh b/t/nostdinc.sh
index 8b780a6..62e752e 100755
--- a/t/nostdinc.sh
+++ b/t/nostdinc.sh
@@ -16,11 +16,7 @@
# 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
index 0000000..159cda5
--- /dev/null
+++ b/t/stdinc-no-repeated.sh
@@ -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
+
+:
--
1.7.9.5