From: Alexandre Duret-Lutz Date: Thu, 15 Apr 2004 07:51:47 +0000 (+0000) Subject: * aclocal.in (%map_traced_defs): New variable. X-Git-Tag: Release-1-8b~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0606a17988f33cd395122665bc4b31727bf9826a;p=thirdparty%2Fautomake.git * aclocal.in (%map_traced_defs): New variable. (scan_m4_files): Normalize filenames. (trace_used_macros): Trace for AC_DEFUN and AU_DEFUN, also ask for the filename and the first argument. Populate %map_traced_defs. (write_aclocal): Use $map_traced_defs to filter out unused definitions. * tests/acloca15.test: New file. * tests/Makefile.am (TESTS): Add acloca15.test. --- diff --git a/ChangeLog b/ChangeLog index e2033f300..9122883ba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2004-04-15 Alexandre Duret-Lutz + + * aclocal.in (%map_traced_defs): New variable. + (scan_m4_files): Normalize filenames. + (trace_used_macros): Trace for AC_DEFUN and AU_DEFUN, also + ask for the filename and the first argument. Populate + %map_traced_defs. + (write_aclocal): Use $map_traced_defs to filter out unused + definitions. + * tests/acloca15.test: New file. + * tests/Makefile.am (TESTS): Add acloca15.test. + 2004-04-12 Alexandre Duret-Lutz * automake.in ($automake_needs_to_reprocess_all_files): Remove. diff --git a/NEWS b/NEWS index c7021ccc8..44221972d 100644 --- a/NEWS +++ b/NEWS @@ -34,6 +34,14 @@ New in 1.8a: endif liba_la_SOURCES = ... +* aclocal now ensures that AC_DEFUNs and AU_DEFUNs it discovers are + really evaluated, before it decides to include them in aclocal.m4. + This solves nasty problems with conditional redefinitions of + Autoconf macros in /usr/share/aclocal/*.m4 files causing extraneous + *.m4 files to be included in any project using these macros. + (Calls to AC_PROG_EGREP causing libtool.m4 to be included is the + most famous instance of this bug.) + New in 1.8: diff --git a/aclocal.in b/aclocal.in index c8d4c4a07..0a07dc6d8 100644 --- a/aclocal.in +++ b/aclocal.in @@ -82,6 +82,9 @@ $force_output = 0; # Map macro names to file names. %map = (); +# Ditto, but records the last definition of each macro as returned by --trace. +%map_traced_defs = (); + # Map file names to file contents. %file_contents = (); @@ -159,7 +162,7 @@ sub scan_m4_files (@) # Skip some files when running out of srcdir. next if $file eq 'aclocal.m4'; - $fullfile = $m4dir . '/' . $file; + $fullfile = File::Spec->canonpath ("$m4dir/$file"); &scan_file ($fullfile); } closedir (DIR); @@ -414,7 +417,9 @@ sub trace_used_macros () # All candidate files. $traces .= join (' ', grep { exists $files{$_} } @file_order) . " "; # All candidate macros. - $traces .= join (' ', map { "--trace='$_:\$n'" } (keys %macro_seen)); + $traces .= join (' ', map { "--trace='$_:\$f:\$n:\$1'" } ('AC_DEFUN', + 'AU_DEFUN', + keys %macro_seen)); print STDERR "aclocal: running $traces $configure_ac\n" if $verbose; @@ -425,7 +430,12 @@ sub trace_used_macros () while ($_ = $tracefh->getline) { chomp; - $traced{$_} = 1 if $macro_seen{$_}; + my ($file, $macro, $arg1) = split (/:/); + + $traced{$macro} = 1 if $macro_seen{$macro}; + + $map_traced_defs{$arg1} = $file + if $macro eq 'AC_DEFUN' || $macro eq 'AU_DEFUN'; } $tracefh->close; @@ -451,7 +461,17 @@ sub write_aclocal ($@) my ($output_file, @macros) = @_; my $output = ''; - my %files = map { $map{$_} => 1 } @macros; + my %files = (); + # Get the list of files containing definitions for the macros used. + # (Filter out unused macro definitions with $map_traced_defs. This + # can happen when an Autoconf macro is conditionally defined: + # aclocal sees the potential definition, but this definition is + # actually never processed and the Autoconf implementation is used + # instead.) + for my $m (@macros) + { + $files{$map{$m}} = 1 if $map{$m} eq $map_traced_defs{$m}; + } $files{'acinclude.m4'} = 1 if -f 'acinclude.m4'; %files = strip_redundant_includes %files; delete $files{$configure_ac}; diff --git a/tests/Makefile.am b/tests/Makefile.am index 4ae37e57e..cebf448af 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -18,6 +18,7 @@ acloca12.test \ acloca13.test \ acloca14.test \ acloca15.test \ +acloca16.test \ acoutnoq.test \ acoutpt.test \ acoutpt2.test \ diff --git a/tests/Makefile.in b/tests/Makefile.in index e6b0f58f4..f457c2b73 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -133,6 +133,7 @@ acloca12.test \ acloca13.test \ acloca14.test \ acloca15.test \ +acloca16.test \ acoutnoq.test \ acoutpt.test \ acoutpt2.test \ diff --git a/tests/acloca16.test b/tests/acloca16.test new file mode 100755 index 000000000..cc1e04403 --- /dev/null +++ b/tests/acloca16.test @@ -0,0 +1,40 @@ +#! /bin/sh +# Copyright (C) 2004 Free Software Foundation, Inc. +# +# This file is part of GNU Automake. +# +# GNU Automake 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. +# +# GNU Automake 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 Automake; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +# Make sure aclocal does not include definitions that are not actually +# evaluated. + +. ./defs || exit 1 + +set -e + +cat >> configure.in << 'END' +AC_SUBST([POM]) +END + +mkdir m4 +cat >m4/some.m4 <<'EOF' +AC_DEFUN([AM_SOME_MACRO], +[AC_DEFUN([AC_SUBST], [GREPME])]) +EOF + +$ACLOCAL -I m4 +grep m4/some.m4 aclocal.m4 && exit 1 +: