* aclocal.in (%map_traced_defs): New variable.
authorAlexandre Duret-Lutz <adl@gnu.org>
Thu, 15 Apr 2004 07:51:47 +0000 (07:51 +0000)
committerAlexandre Duret-Lutz <adl@gnu.org>
Thu, 15 Apr 2004 07:51:47 +0000 (07:51 +0000)
(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.

ChangeLog
NEWS
aclocal.in
tests/Makefile.am
tests/Makefile.in
tests/acloca16.test [new file with mode: 0755]

index e2033f3..9122883 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2004-04-15  Alexandre Duret-Lutz  <adl@gnu.org>
+
+       * 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  <adl@gnu.org>
 
        * automake.in ($automake_needs_to_reprocess_all_files): Remove.
diff --git a/NEWS b/NEWS
index c7021cc..4422197 100644 (file)
--- 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.)
+
 \f
 New in 1.8:
 
index c8d4c4a..0a07dc6 100644 (file)
@@ -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};
index 4ae37e5..cebf448 100644 (file)
@@ -18,6 +18,7 @@ acloca12.test \
 acloca13.test \
 acloca14.test \
 acloca15.test \
+acloca16.test \
 acoutnoq.test \
 acoutpt.test \
 acoutpt2.test \
index e6b0f58..f457c2b 100644 (file)
@@ -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 (executable)
index 0000000..cc1e044
--- /dev/null
@@ -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
+: