Changes to m4_included files should also cause aclocal.m4 to change.
authorAlexandre Duret-Lutz <adl@gnu.org>
Sun, 7 Sep 2003 13:26:44 +0000 (13:26 +0000)
committerAlexandre Duret-Lutz <adl@gnu.org>
Sun, 7 Sep 2003 13:26:44 +0000 (13:26 +0000)
* 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.

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

index 671c06c..378c30c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2003-09-07  Alexandre Duret-Lutz  <adl@gnu.org>
 
+       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.
+
        * tests/instsh.test: Do not reset $ACLOCAL and $AUTOMAKE now
        that we have fake version in the $PATH.
 
index 96e1968..8a1e612 100644 (file)
@@ -39,6 +39,7 @@ use Automake::Configure_ac;
 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 @@ $ac_defun_rx = "A[CU]_DEFUN\\((?:\\[([^]]+)\\]|([^],)\n]+))";
 # Matches an AC_REQUIRE line.
 $ac_require_rx = "AC_REQUIRE\\((?:\\[([^]]+)\\]|([^],)\n]+))\\)";
 
+# Matches an m4_include line
+$m4_include_rx = "(?:m4_)?s?include\\((?:\\[([^]]+)\\]|([^],)\n]+))\\)";
+
 \f
 
 local (@dirlist) = &parse_arguments (@ARGV);
@@ -238,40 +242,13 @@ sub parse_arguments (@)
 
 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 @@ sub add_macro ($)
     &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 @@ sub add_file ($)
       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 ae6ed26..5b0a28f 100644 (file)
@@ -15,6 +15,7 @@ aclocal9.test \
 acloca10.test \
 acloca11.test \
 acloca12.test \
+acloca13.test \
 acoutnoq.test \
 acoutpt.test \
 acoutpt2.test \
index dff977e..a0e255a 100644 (file)
@@ -125,6 +125,7 @@ aclocal9.test \
 acloca10.test \
 acloca11.test \
 acloca12.test \
+acloca13.test \
 acoutnoq.test \
 acoutpt.test \
 acoutpt2.test \
diff --git a/tests/acloca13.test b/tests/acloca13.test
new file mode 100755 (executable)
index 0000000..8386f20
--- /dev/null
@@ -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