libtool-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FYI: make sure AC_DEFUNs are processed before including a file in acloca


From: Alexandre Duret-Lutz
Subject: FYI: make sure AC_DEFUNs are processed before including a file in aclocal.m4
Date: Thu, 15 Apr 2004 09:51:25 +0200
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux)

I'm installing this on (automake's) HEAD.  

This fixes a problem occurring when an Autoconf macro is
conditionally redefined in a /usr/share/aclocal/ file: any
configure.ac that use this macro will cause the file to be
included.

E.g., this thread mentions the problem from the user point of view:
  http://mail.gnu.org/archive/html/libtool-patches/2003-07/msg00006.html
and this one from the (macro) author point of view:
  http://sources.redhat.com/ml/bug-automake/2003/msg00335.html

As discussed on
  http://mail.gnu.org/archive/html/libtool/2004-02/msg00014.html
the fix is one more step towards Akim's ultimate goal (no greps,
only traces) which is here
  http://sources.redhat.com/ml/bug-automake/2003/msg00321.html

2004-04-15  Alexandre Duret-Lutz  <address@hidden>

        * 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.

Index: NEWS
===================================================================
RCS file: /cvs/automake/automake/NEWS,v
retrieving revision 1.265
diff -u -r1.265 NEWS
--- NEWS        2 Apr 2004 07:14:24 -0000       1.265
+++ NEWS        15 Apr 2004 00:35:30 -0000
@@ -34,6 +34,10 @@
     endif
     liba_la_SOURCES = ...
 
+* aclocal now ensures that AC_DEFUNs and AU_DEFUNs it discovers are
+  really evaluated before it includes them in aclocal.m4.  This solves
+  nasty problems with conditional redefinitions of Autoconf macros.
+
 
 New in 1.8:
 
Index: aclocal.in
===================================================================
RCS file: /cvs/automake/automake/aclocal.in,v
retrieving revision 1.101
diff -u -r1.101 aclocal.in
--- aclocal.in  10 Apr 2004 17:18:01 -0000      1.101
+++ aclocal.in  15 Apr 2004 00:35:30 -0000
@@ -82,6 +82,9 @@
 # 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 @@
            # 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 @@
   # 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 @@
   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 @@
   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: tests/Makefile.am
===================================================================
RCS file: /cvs/automake/automake/tests/Makefile.am,v
retrieving revision 1.554
diff -u -r1.554 Makefile.am
--- tests/Makefile.am   12 Apr 2004 22:16:22 -0000      1.554
+++ tests/Makefile.am   15 Apr 2004 00:35:30 -0000
@@ -18,6 +18,7 @@
 acloca13.test \
 acloca14.test \
 acloca15.test \
+acloca16.test \
 acoutnoq.test \
 acoutpt.test \
 acoutpt2.test \
Index: tests/acloca16.test
===================================================================
RCS file: tests/acloca16.test
diff -N tests/acloca16.test
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ tests/acloca16.test 15 Apr 2004 00:35:31 -0000
@@ -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
+:

-- 
Alexandre Duret-Lutz





reply via email to

[Prev in Thread] Current Thread [Next in Thread]