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.
# 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);
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);
}
################################################################
&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);
}
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.
--- /dev/null
+#! /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