automake-patches
[Top][All Lists]
Advanced

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

aclocal --force


From: Alexandre Duret-Lutz
Subject: aclocal --force
Date: Tue, 06 May 2003 00:04:28 +0200
User-agent: Gnus/5.090016 (Oort Gnus v0.16) Emacs/21.3 (gnu/linux)

Touching aclocal.m4 invalidates Autom4te's cache.

Right now, autoreconf tries to prevent needless updates of
aclocal.m4 by instructing aclocal to output aclocal.m4t and
overwriting aclocal.m4 only if aclocal.m4t turns out to be
different.

Comparing the contents is not enough, because aclocal.m4 depends
on its *.m4 constituents.  If one of the *.m4 is younger than
aclocal.m4 and autoreconf decides not to update aclocal.m4, then
aclocal will be called again at `make' time (this in turn will
cause the other autotools to be rerun).

The following patch does what Akim and I have discussed this
weekend: implements the `avoid needless updates of aclocal.m4'
feature in aclocal itself, because only aclocal knows about
aclocal.m4's dependencies.

The next step is to update autoreconf.


2003-05-05  Alexandre Duret-Lutz  <address@hidden>

        * lib/Automake/General.pm (contents): New function.
        * aclocal.in (greatest_mtime, force_output): New globals.
        (scan_configure, add_file): Update $greatest_mtime.
        (parse_arguments): Parse --force.
        (write_aclocal): Do not overwrite $output_file unless needed.
        * automake.texi (aclocal options): Document --force.
        * tests/aclocal7.test: New file.
        * tests/Makefile.am (TESTS): Add aclocal7.test.

Index: NEWS
===================================================================
RCS file: /cvs/automake/automake/NEWS,v
retrieving revision 1.213
diff -u -r1.213 NEWS
--- NEWS        25 Apr 2003 18:39:20 -0000      1.213
+++ NEWS        5 May 2003 21:56:37 -0000
@@ -117,6 +117,10 @@
   older versions of Automake; this variable should be considered obsolete
   and will be flagged as such when running `automake -Wobsolete'.
 
+* aclocal will avoid touching aclocal.m4 when possible, so that
+  Autom4te's cache isn't needlessly invalidated.  This behavior can
+  be switched off with the new `--force' option.
+
 
 New in 1.7:
 * Autoconf 2.54 is required.
Index: aclocal.in
===================================================================
RCS file: /cvs/automake/automake/aclocal.in,v
retrieving revision 1.78
diff -u -r1.78 aclocal.in
--- aclocal.in  24 Apr 2003 18:48:03 -0000      1.78
+++ aclocal.in  5 May 2003 21:56:37 -0000
@@ -35,6 +35,7 @@
 
 use Automake::General;
 use Automake::XFile;
+use File::stat;
 
 # Some constants.
 $VERSION = '@VERSION@';
@@ -64,6 +65,12 @@
 # Output file name.
 $output_file = 'aclocal.m4';
 
+# Modification time of the youngest dependency.
+$greatest_mtime = 0;
+
+# Option --force.
+$force_output = 0;
+
 # Which macros have been seen.
 %macro_seen = ();
 
@@ -118,6 +125,7 @@
   --acdir=DIR           directory holding config files
   --help                print this help, then exit
   -I DIR                add directory to search list for .m4 files
+  --force               always update output file
   --output=FILE         put output in FILE (default aclocal.m4)
   --print-ac-dir        print name of directory holding m4 files
   --verbose             don't be silent
@@ -154,6 +162,10 @@
        {
            $print_and_exit = 1;
        }
+       elsif ($arglist[0] eq '--force')
+       {
+           $force_output = 1;
+       }
        elsif ($arglist[0] eq '--verbose')
        {
            ++$verbose;
@@ -232,6 +244,9 @@
     open (CONFIGURE, $configure_ac)
        || die "aclocal: couldn't open `$configure_ac': $!\n";
 
+    my $mtime = mtime $configure_ac;
+    $greatest_mtime = $mtime if $greatest_mtime < $mtime;
+
     # Make sure we include acinclude.m4 if it exists.
     if (-f 'acinclude.m4')
     {
@@ -357,6 +372,9 @@
     return if ($file_seen{$file});
     $file_seen{$file} = 1;
 
+    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
@@ -440,20 +458,17 @@
 # Write output.
 sub write_aclocal ()
 {
+    # Nothing to output?!
+    # FIXME: Shouldn't we diagnose this?
     return if ! length ($output);
 
-    print STDERR "aclocal: writing $output_file\n" if $verbose;
-
-    my $out = new Automake::XFile "> $output_file";
-
 # 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.
-    print $out
-"# generated automatically by aclocal $VERSION -*- Autoconf -*-
+    $output = "# generated automatically by aclocal $VERSION -*- Autoconf -*-
 
 # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
 # Free Software Foundation, Inc.
@@ -467,6 +482,30 @@
 # PARTICULAR PURPOSE.
 
 $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;
 }
 
 ### Setup "GNU" style for perl-mode and cperl-mode.
Index: automake.texi
===================================================================
RCS file: /cvs/automake/automake/automake.texi,v
retrieving revision 1.335
diff -u -r1.335 automake.texi
--- automake.texi       5 May 2003 19:56:21 -0000       1.335
+++ automake.texi       5 May 2003 21:56:42 -0000
@@ -1392,6 +1392,12 @@
 Add the directory @var{dir} to the list of directories searched for
 @file{.m4} files.
 
address@hidden --force
address@hidden --force
+Always overwrite the output file.  The default is to overwrite the output
+file only when really needed, i.e., when its contents changes or if one
+of its dependencies is younger.
+
 @item address@hidden
 @opindex --output
 Cause the output to be put into @var{file} instead of @file{aclocal.m4}.
Index: lib/Automake/General.pm
===================================================================
RCS file: /cvs/automake/automake/lib/Automake/General.pm,v
retrieving revision 1.1
diff -u -r1.1 General.pm
--- lib/Automake/General.pm     2 Oct 2001 17:17:45 -0000       1.1
+++ lib/Automake/General.pm     5 May 2003 21:56:43 -0000
@@ -1,4 +1,4 @@
-# Copyright 2001 Free Software Foundation, Inc.
+# Copyright (C) 2001, 2003  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
@@ -29,7 +29,7 @@
 
 @ISA = qw (Exporter);
 @EXPORT = qw (&debug &find_configure_ac &find_file &getopt &mktmpdir &mtime
-              &uniq &update_file &verbose &xsystem
+              &uniq &update_file &verbose &xsystem &contents
              $debug $help $me $tmp $verbose $version);
 
 # Variable we share with the main package.  Be sure to have a single
@@ -331,4 +331,36 @@
 }
 
 
+# contents ($FILENAME)
+# --------------------
+# Swallow the contents of file $FILENAME.
+sub contents ($)
+{
+  my ($file) = @_;
+  print STDERR "$me: reading $file\n" if $verbose;
+  local $/;                    # Turn on slurp-mode.
+  my $f = new Automake::XFile "< $file";
+  my $contents = $f->getline;
+  $f->close;
+  return $contents;
+}
+
+
 1; # for require
+
+### Setup "GNU" style for perl-mode and cperl-mode.
+## Local Variables:
+## perl-indent-level: 2
+## perl-continued-statement-offset: 2
+## perl-continued-brace-offset: 0
+## perl-brace-offset: 0
+## perl-brace-imaginary-offset: 0
+## perl-label-offset: -2
+## cperl-indent-level: 2
+## cperl-brace-offset: 0
+## cperl-continued-brace-offset: 0
+## cperl-label-offset: -2
+## cperl-extra-newline-before-brace: t
+## cperl-merge-trailing-else: nil
+## cperl-continued-statement-offset: 2
+## End:
Index: tests/Makefile.am
===================================================================
RCS file: /cvs/automake/automake/tests/Makefile.am,v
retrieving revision 1.490
diff -u -r1.490 Makefile.am
--- tests/Makefile.am   27 Apr 2003 18:14:36 -0000      1.490
+++ tests/Makefile.am   5 May 2003 21:56:43 -0000
@@ -9,6 +9,7 @@
 aclocal4.test \
 aclocal5.test \
 aclocal6.test \
+aclocal7.test \
 acoutnoq.test \
 acoutpt.test \
 acoutpt2.test \
Index: tests/Makefile.in
===================================================================
RCS file: /cvs/automake/automake/tests/Makefile.in,v
retrieving revision 1.630
diff -u -r1.630 Makefile.in
--- tests/Makefile.in   27 Apr 2003 18:14:36 -0000      1.630
+++ tests/Makefile.in   5 May 2003 21:56:43 -0000
@@ -120,6 +120,7 @@
 aclocal4.test \
 aclocal5.test \
 aclocal6.test \
+aclocal7.test \
 acoutnoq.test \
 acoutpt.test \
 acoutpt2.test \
Index: tests/aclocal7.test
===================================================================
RCS file: tests/aclocal7.test
diff -N tests/aclocal7.test
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ tests/aclocal7.test 5 May 2003 21:56:43 -0000
@@ -0,0 +1,57 @@
+#! /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 overwrite aclocal.m4 needlessly.
+
+. ./defs || exit 1
+
+set -e
+
+cat >> configure.in << 'END'
+SOME_DEFS
+END
+
+mkdir m4
+echo 'AC_DEFUN([SOME_DEFS], [])' > m4/somedefs.m4
+
+$sleep
+
+$ACLOCAL -I m4
+
+$sleep
+
+touch foo
+$ACLOCAL -I m4
+
+# aclocal.m4 should not have been updated, so `foo' should be younger
+test `ls -1t aclocal.m4 foo | sed 1q` = foo
+
+$sleep
+$ACLOCAL -I m4 --force
+test `ls -1t aclocal.m4 foo | sed 1q` = aclocal.m4
+
+touch m4/somedefs.m4
+$sleep
+touch foo
+$sleep
+$ACLOCAL -I m4
+
+# aclocal.m4 should have been updated, although its contents haven't changed.
+test `ls -1t aclocal.m4 foo | sed 1q` = aclocal.m4
-- 
Alexandre Duret-Lutz





reply via email to

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