automake-patches
[Top][All Lists]
Advanced

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

FYI: honnor m4_include in aclocal


From: Alexandre Duret-Lutz
Subject: FYI: honnor m4_include in aclocal
Date: Sun, 07 Sep 2003 15:26:34 +0200
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3 (gnu/linux)

The rebuild rule will run aclocal each time a configure
dependency changes.  However configure dependencies also include
m4_included files, and so far aclocal was ignoring these files.
So when such a file was changed, make would run aclocal, but
aclocal would not update aclocal.m4 because it didn't noticed
any change.

I'm installing the following fix on HEAD.

2003-09-07  Alexandre Duret-Lutz  <address@hidden>

        Changes to m4_included files should also cause aclocal.m4 to change.
        * aclocal.in (m4_include_rx): New variable.
        (scan_configure_dep): New function.
        (scan_configure, add_file): Simplify using scan_configure_dep.
        * tests/Makefile.am (TESTS): Add acloca13.test.
        * tests/aclocal13.test: New file.
 
Index: aclocal.in
===================================================================
RCS file: /cvs/automake/automake/aclocal.in,v
retrieving revision 1.92
diff -u -r1.92 aclocal.in
--- aclocal.in  7 Sep 2003 10:14:25 -0000       1.92
+++ aclocal.in  7 Sep 2003 13:20:14 -0000
@@ -39,6 +39,7 @@
 use Automake::Channels;
 use Automake::XFile;
 use Automake::FileUtils;
+use File::Basename;
 use File::stat;
 
 # Note that this isn't pkgdatadir, but a separate directory.
@@ -96,6 +97,9 @@
 # Matches an AC_REQUIRE line.
 $ac_require_rx = "AC_REQUIRE\\((?:\\[([^]]+)\\]|([^],)\n]+))\\)";
 
+# Matches an m4_include line
+$m4_include_rx = "(?:m4_)?s?include\\((?:\\[([^]]+)\\]|([^],)\n]+))\\)";
+
 
 
 local (@dirlist) = &parse_arguments (@ARGV);
@@ -238,40 +242,13 @@
 
 sub scan_configure ()
 {
-  if (! open (CONFIGURE, $configure_ac))
-    {
-      print STDERR "aclocal: couldn't open `$configure_ac': $!\n";
-      exit 1;
-    }
-
-  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')
     {
       &add_file ('acinclude.m4');
     }
 
-  while (<CONFIGURE>)
-    {
-      # Remove comments from current line.
-      s/\bdnl\b.*$//;
-      s/\#.*$//;
-
-      # Search for things we know about.  The "search" sub is
-      # constructed dynamically by scan_m4_files.  The last
-      # parenthetical match makes sure we don't match things that
-      # look like macro assignments or AC_SUBSTs.
-      if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
-       {
-         # Macro not found, but AM_ prefix found.
-         warn "aclocal: $configure_ac: $.: macro `$2' not found in library\n";
-         $exit_code = 1;
-       }
-    }
-
-  close (CONFIGURE);
+  &scan_configure_dep ($configure_ac);
 }
 
 ################################################################
@@ -369,26 +346,39 @@
     &add_file ($map{$macro});
 }
 
-# Add a file to output.
-sub add_file ($)
+# scan_contents ($file)
+# --------------------------------
+my %scanned_configure_dep = ();
+sub scan_configure_dep ($)
 {
-  local ($file) = @_;
-
-  # Only add a file once.
-  return if ($file_seen{$file});
-  $file_seen{$file} = 1;
+  my ($file) = @_;
+  # Do not scan a file twice.
+  return ()
+    if exists $scanned_configure_dep{$file};
+  $scanned_configure_dep = 1;
 
   my $mtime = mtime $file;
   $greatest_mtime = $mtime if $greatest_mtime < $mtime;
 
-  my (@rlist);
-  foreach (split ("\n", $file_contents{$file}))
+  my $contents = exists $file_contents{$file} ?
+    $file_contents{$file} : contents $file;
+
+  my $line = 0;
+  my @rlist = ();
+  my @ilist = ();
+  foreach (split ("\n", $contents))
     {
+      ++$line;
       # Remove comments from current line.
       s/\bdnl\b.*$//;
       s/\#.*$//;
 
-      if (/$ac_require_rx/g)
+      while (/$m4_include_rx/g)
+       {
+         push (@ilist, $1 || $2);
+       }
+
+      while (/$ac_require_rx/g)
        {
          push (@rlist, $1 || $2);
        }
@@ -400,16 +390,27 @@
       if (! &search && /(^|\s+)(AM_[A-Z0-9_]+)($|[^\]\)=A-Z0-9_])/)
        {
          # Macro not found, but AM_ prefix found.
-         warn "aclocal: $configure_ac: $.: macro `$2' not found in library\n";
+         warn "aclocal: $file: $line: macro `$2' not found in library\n";
          $exit_code = 1;
        }
     }
 
-  local ($macro);
-  foreach $macro (@rlist)
-    {
-      &add_macro ($macro);
-    }
+
+  &add_macro ($_) foreach (@rlist);
+  my $dirname = dirname $file;
+  scan_configure_dep (File::Spec->rel2abs ($_, $dirname)) foreach (@ilist);
+}
+
+# Add a file to output.
+sub add_file ($)
+{
+  local ($file) = @_;
+
+  # Only add a file once.
+  return if ($file_seen{$file});
+  $file_seen{$file} = 1;
+
+  scan_configure_dep $file;
 }
 
 # Point to the documentation for underquoted AC_DEFUN only once.
Index: tests/Makefile.am
===================================================================
RCS file: /cvs/automake/automake/tests/Makefile.am,v
retrieving revision 1.515
diff -u -r1.515 Makefile.am
--- tests/Makefile.am   7 Sep 2003 09:55:36 -0000       1.515
+++ tests/Makefile.am   7 Sep 2003 13:20:14 -0000
@@ -15,6 +15,7 @@
 acloca10.test \
 acloca11.test \
 acloca12.test \
+acloca13.test \
 acoutnoq.test \
 acoutpt.test \
 acoutpt2.test \
Index: tests/acloca13.test
===================================================================
RCS file: tests/acloca13.test
diff -N tests/acloca13.test
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ tests/acloca13.test 7 Sep 2003 13:20:14 -0000
@@ -0,0 +1,62 @@
+#! /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 changes to m4_included files also cause aclocal.m4 to change.
+
+. ./defs || exit 1
+
+set -e
+
+cat >> configure.in << 'END'
+m4_include([somefile.m4])
+END
+
+mkdir m4
+
+echo MACRO1 >somefile.m4
+echo HELLO >m4/otherfile.m4
+
+cat >m4/version1.m4 <<EOF
+AC_DEFUN([MACRO1])
+AC_DEFUN([MACRO2])
+m4_sinclude(otherfile.m4)
+EOF
+
+cat >m4/version2.m4 <<EOF
+AC_DEFUN([MACRO1])
+EOF
+
+$ACLOCAL -I m4
+grep version2 aclocal.m4
+grep version1 aclocal.m4 && exit 1
+
+$sleep
+echo MACRO2 >somefile.m4
+
+$ACLOCAL -I m4
+grep version2 aclocal.m4 && exit 1
+grep version1 aclocal.m4
+
+$sleep
+# aclocal.m4 should change if we touch otherfile.m4
+touch m4/otherfile.m4
+$sleep
+$ACLOCAL -I m4
+test `ls -1t aclocal.m4 m4/otherfile.m4 | sed 1q` = aclocal.m4
-- 
Alexandre Duret-Lutz





reply via email to

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