[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: tracing from aclocal
From: |
Alexandre Duret-Lutz |
Subject: |
Re: tracing from aclocal |
Date: |
Sun, 24 Aug 2003 04:00:36 +0200 |
User-agent: |
Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3 (gnu/linux) |
I'm finally installing this patch as follows.
2003-08-24 Alexandre Duret-Lutz <address@hidden>
* aclocal.in (write_aclocal): Take an output file and list of
used macros in arguments and make up the file contents here.
(trace_used_macros): New function.
(add_file): Do not update $output.
($output): Delete.
(MAIN): Call trace_used_macros. Then rewrite aclocal.m4 only
for these traced macros. This should shorten aclocal.m4 by
stripping out unused macros.
* automake.texi (Invoking aclocal): Document ${AUTOM4TE}.
* tests/aclibobj.test: Make sure configure.in exists by the time
aclocal runs.
* tests/aclocal8.test: New file.
* tests/Makefile.am (TESTS): Add aclocal8.test.
Suggested by Bruno Haible and Akim Demaille.
Index: NEWS
===================================================================
RCS file: /cvs/automake/automake/NEWS,v
retrieving revision 1.222
diff -u -r1.222 NEWS
--- NEWS 17 Aug 2003 18:09:10 -0000 1.222
+++ NEWS 24 Aug 2003 01:54:42 -0000
@@ -71,6 +71,11 @@
Autom4te's cache isn't needlessly invalidated. This behavior can
be switched off with the new `--force' option.
+ - aclocal now uses Autoconf's --trace to detect macros which are actually
+ used and will no longer include unused macros simply because they
+ where mentioned. This was often the case for macros called
+ conditionally.
+
- New option no-dist-gzip.
- install-sh now understands --version and --help.
Index: aclocal.in
===================================================================
RCS file: /cvs/automake/automake/aclocal.in,v
retrieving revision 1.85
diff -u -r1.85 aclocal.in
--- aclocal.in 21 Aug 2003 08:49:24 -0000 1.85
+++ aclocal.in 24 Aug 2003 01:54:42 -0000
@@ -58,9 +58,6 @@
# Exit status.
$exit_status = 0;
-# Text to output.
-$output = '';
-
# Output file name.
$output_file = 'aclocal.m4';
@@ -103,9 +100,10 @@
&scan_m4_files (@dirlist);
&scan_configure;
if (! $exit_status)
-{
- &write_aclocal;
-}
+ {
+ my %macro_traced = &trace_used_macros;
+ &write_aclocal ($output_file, keys %macro_traced);
+ }
&check_acinclude;
exit $exit_status;
@@ -457,22 +455,75 @@
return $contents;
}
+sub trace_used_macros ($)
+{
+ my ($filename) = @_;
+
+ my %files = map { $map{$_} => 1 } keys %macro_seen;
+
+ my $traces = ($ENV{AUTOM4TE} || 'autom4te');
+ $traces .= " --language Autoconf-without-aclocal-m4 $filename ";
+ # All candidate files.
+ $traces .= join (' ', sort keys %files) . " ";
+ # All candidate macros.
+ $traces .= join (' ', map { "--trace='$_:\$n'" } (keys %macro_seen));
+
+ print STDERR "aclocal: running $traces $configure_ac\n" if $verbose;
+
+ my $tracefh = new Automake::XFile ("$traces $configure_ac |");
+
+ my %traced = ();
+
+ while ($_ = $tracefh->getline)
+ {
+ chomp;
+ $traced{$_} = 1 if $macro_seen{$_};
+ }
+ return %traced;
+}
+
################################################################
# Write output.
-sub write_aclocal ()
+sub write_aclocal ($@)
{
- # Nothing to output?!
- # FIXME: Shouldn't we diagnose this?
- return if ! length ($output);
-
-# We used to print `# $output_file generated automatically etc.' But
-# this creates spurious differences when using autoreconf. Autoreconf
-# creates aclocal.m4t and then rename it to aclocal.m4, but the
-# rebuild rules generated by Automake create aclocal.m4 directly --
-# this would gives two ways to get the same file, with a different
-# name in the header.
- $output = "# generated automatically by aclocal $VERSION -*- Autoconf -*-
+ my ($output_file, @macros) = @_;
+ my $output = '';
+
+ my %files = map { $map{$_} => 1 } @macros;
+ $files{'acinclude.m4'} = 1 if -f 'acinclude.m4';
+
+ for $file (sort keys %files)
+ {
+ my $mtime = mtime $file;
+ $greatest_mtime = $mtime if $greatest_mtime < $mtime;
+
+ # If the file to add looks like path outside the project,
+ # copy it to the output.
+ # The regex catches filenames starting with things like
+ # / \ c:\ ../ ./../ etc.
+ if ($file =~ m,^(?:(?:\w:)?[\\/]|(?:\.[\\/]+)*\.\.[\\/]),)
+ {
+ $output .= $file_contents{$file} . "\n";
+ }
+ else
+ {
+ # Otherwise, simply include the file.
+ $output .= "m4_include([$file])\n";
+ }
+ }
+
+ # Nothing to output?!
+ # FIXME: Shouldn't we diagnose this?
+ return if ! length ($output);
+
+ # We used to print `# $output_file generated automatically etc.' But
+ # this creates spurious differences when using autoreconf. Autoreconf
+ # creates aclocal.m4t and then rename it to aclocal.m4, but the
+ # rebuild rules generated by Automake create aclocal.m4 directly --
+ # this would gives two ways to get the same file, with a different
+ # name in the header.
+ $output = "# generated automatically by aclocal $VERSION -*- Autoconf -*-
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
# Free Software Foundation, Inc.
@@ -487,29 +538,30 @@
$output";
- # We try not to update $output_file unless necessary, because
- # doing so invalidate Autom4te's cache and therefore slows down
- # tools called after aclocal.
- #
- # We need to overwrite $output_file in the following situations.
- # * The --force option is in use.
- # * One of the dependencies is younger.
- # (Not updating $output_file in this situation would cause
- # make to call aclocal in loop.)
- # * The contents of the current file are different from what
- # we have computed.
- if (!$force_output
- && $greatest_mtime < mtime ($output_file)
- && $output eq contents ($output_file))
- {
- print STDERR "aclocal: $output_file unchanged\n" if $verbose;
- return;
- }
-
- print STDERR "aclocal: writing $output_file\n" if $verbose;
-
- my $out = new Automake::XFile "> $output_file";
- print $out $output;
+ # We try not to update $output_file unless necessary, because
+ # doing so invalidate Autom4te's cache and therefore slows down
+ # tools called after aclocal.
+ #
+ # We need to overwrite $output_file in the following situations.
+ # * The --force option is in use.
+ # * One of the dependencies is younger.
+ # (Not updating $output_file in this situation would cause
+ # make to call aclocal in loop.)
+ # * The contents of the current file are different from what
+ # we have computed.
+ if (!$force_output
+ && $greatest_mtime < mtime ($output_file)
+ && $output eq contents ($output_file))
+ {
+ print STDERR "aclocal: $output_file unchanged\n" if $verbose;
+ return;
+ }
+
+ print STDERR "aclocal: writing $output_file\n" if $verbose;
+
+ my $out = new Automake::XFile "> $output_file";
+ print $out $output;
+ return;
}
### Setup "GNU" style for perl-mode and cperl-mode.
Index: automake.texi
===================================================================
RCS file: /cvs/automake/automake/automake.texi,v
retrieving revision 1.349
diff -u -r1.349 automake.texi
--- automake.texi 17 Aug 2003 18:09:10 -0000 1.349
+++ automake.texi 24 Aug 2003 01:54:47 -0000
@@ -1350,6 +1350,16 @@
automatically included in @file{aclocal.m4}. We recommend against
using @file{acinclude.m4} in new packages (@pxref{Local Macros}).
address@hidden AUTOM4TE
+While computing @file{aclocal.m4}, @code{aclocal} runs @code{autom4te}
+(@pxref{Using autom4te, , Using @code{Autom4te}, autoconf, The
+Autoconf Manual}) in order to trace the macros which are really used,
+and omit from @file{aclocal.m4} all macros which are mentioned but
+otherwise unexpanded (this can happen when a macro is called
+conditionally). @code{autom4te} is expected to be in the @code{PATH},
+just as @code{autoconf}. Its location can be overridden using the
address@hidden environment variable.
+
@menu
* aclocal options:: Options supported by aclocal
* Macro search path:: How aclocal finds .m4 files
Index: tests/aclibobj.test
===================================================================
RCS file: /cvs/automake/automake/tests/aclibobj.test,v
retrieving revision 1.3
diff -u -r1.3 aclibobj.test
--- tests/aclibobj.test 8 Sep 2002 13:07:54 -0000 1.3
+++ tests/aclibobj.test 24 Aug 2003 01:54:49 -0000
@@ -1,5 +1,5 @@
#! /bin/sh
-# Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+# Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
#
# This file is part of GNU Automake.
#
@@ -22,12 +22,10 @@
. ./defs || exit 1
-cat > X << 'END'
-AC_INIT
-AM_INIT_AUTOMAKE(nonesuch, nonesuch)
+cat >> configure.in << 'END'
AC_PROG_CC
AC_PROG_RANLIB
-AC_OUTPUT(Makefile)
+AC_OUTPUT
END
cat > Makefile.am << 'END'
@@ -43,7 +41,7 @@
set -e
-cp X configure.in
+cp configure.in X
echo 'AC_LIBSOURCE(maude.c)' >> configure.in
$AUTOMAKE
Index: tests/aclocal8.test
===================================================================
RCS file: tests/aclocal8.test
diff -N tests/aclocal8.test
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/aclocal8.test 24 Aug 2003 01:54:49 -0000
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 2003 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 require unused macros.
+
+. ./defs || exit 1
+
+set -e
+
+cat >> configure.in << 'END'
+SOME_DEFS
+END
+
+mkdir m4
+cat >m4/somedefs.m4 <<EOF
+AC_DEFUN([SOME_DEFS], [
+ m4_if([a], [a], [MACRO1], [MACRO2])
+])
+EOF
+
+echo 'AC_DEFUN([MACRO1],)' >m4/macro1.m4
+echo 'AC_DEFUN([MACRO2],)' >m4/macro2.m4
+
+$ACLOCAL -I m4
+grep macro1.m4 aclocal.m4
+grep macro2.m4 aclocal.m4 && exit 1
+:
--
Alexandre Duret-Lutz
Re: tracing from aclocal, Alexandre Duret-Lutz, 2003/08/18