* aclocal.in (@file_order): New variable, to make sure
authorAlexandre Duret-Lutz <adl@gnu.org>
Thu, 28 Aug 2003 22:49:58 +0000 (22:49 +0000)
committerAlexandre Duret-Lutz <adl@gnu.org>
Thu, 28 Aug 2003 22:49:58 +0000 (22:49 +0000)
files are output in the opposite order of the -I arguments.
(scan_file): Fill it.
(trace_used_macros, write_aclocal): Use it.
(scan_m4_files): Reverse the directory contents, so that
macros from the lexicographically greatest files are preferred.
* tests/aclocal9.test, tests/acloca10.test, tests/acloca11.test:
New files.
* tests/Makefile.am (TESTS): Add them.

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

index 277e051..a025756 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2003-08-29  Alexandre Duret-Lutz  <adl@gnu.org>
+
+       * aclocal.in (@file_order): New variable, to make sure
+       files are output in the opposite order of the -I arguments.
+       (scan_file): Fill it.
+       (trace_used_macros, write_aclocal): Use it.
+       (scan_m4_files): Reverse the directory contents, so that
+       macros from the lexicographically greatest files are preferred.
+       * tests/aclocal9.test, tests/acloca10.test, tests/acloca11.test:
+       New files.
+       * tests/Makefile.am (TESTS): Add them.
+
 2003-08-24  Alexandre Duret-Lutz  <adl@gnu.org>
 
        For Debian Bug #206299:
index 53c0374..b134cab 100644 (file)
@@ -73,6 +73,10 @@ $force_output = 0;
 # Which files have been seen.
 %file_seen = ();
 
+# Remember the order into which we scanned the files.
+# It's important to output the contents of aclocal.m4 in the opposite order.
+@file_order = ();
+
 # Map macro names to file names.
 %map = ();
 
@@ -228,7 +232,6 @@ sub parse_arguments (@)
        close (DEFAULT_DIRLIST);
     }
 
-
     return @dirlist;
 }
 
@@ -313,7 +316,9 @@ sub scan_m4_files (@)
          }
 
        local ($file, $fullfile);
-       foreach $file (sort grep (! /^\./, readdir (DIR)))
+       # We reverse the directory contents so that foo2.m4 gets
+       # used in preference to foo1.m4.
+       foreach $file (reverse sort grep (! /^\./, readdir (DIR)))
        {
            # Only examine .m4 files.
            next unless $file =~ /\.m4$/;
@@ -424,35 +429,41 @@ sub add_file ($)
 # Scan a single M4 file.  Return contents.
 sub scan_file ($)
 {
-    local ($file) = @_;
+  local ($file) = @_;
+
+  unshift @file_order, $file;
 
-    my $fh = new Automake::XFile $file;
-    my $contents = '';
-    while ($_ = $fh->getline)
+  my $fh = new Automake::XFile $file;
+  my $contents = '';
+  while ($_ = $fh->getline)
     {
-       # Ignore `##' lines.
-       next if /^##/;
+      # Ignore `##' lines.
+      next if /^##/;
 
-       $contents .= $_;
+      $contents .= $_;
 
-       if (/$ac_defun_rx/)
+      if (/$ac_defun_rx/)
        {
-           if (! defined $map{$1 || $2})
+         if (! defined $map{$1 || $2})
            {
-               $map{$1 || $2} = $file;
+             print STDERR "aclocal: found macro $1 in $file: $.\n"
+               if $verbose;
+             $map{$1 || $2} = $file;
+           }
+         else
+           {
+             # Note: we used to give an error here if we saw a
+             # duplicated macro.  However, this turns out to be
+             # extremely unpopular.  It causes actual problems which
+             # are hard to work around, especially when you must
+             # mix-and-match tool versions.
+             print STDERR "aclocal: ignoring macro $1 in $file: $.\n"
+               if $verbose;
            }
-
-           # Note: we used to give an error here if we saw a
-           # duplicated macro.  However, this turns out to be
-           # extremely unpopular.  It causes actual problems which
-           # are hard to work around, especially when you must
-           # mix-and-match tool versions.
-
-           print STDERR "aclocal: found macro $1 in $file: $.\n" if $verbose;
        }
     }
 
-    return $contents;
+  return $contents;
 }
 
 sub trace_used_macros ($)
@@ -464,7 +475,7 @@ sub trace_used_macros ($)
   my $traces = ($ENV{AUTOM4TE} || 'autom4te');
   $traces .= " --language Autoconf-without-aclocal-m4 $filename ";
   # All candidate files.
-  $traces .= join (' ', sort keys %files) . " ";
+  $traces .= join (' ', grep { exists $files{$_} } @file_order) . " ";
   # All candidate macros.
   $traces .= join (' ', map { "--trace='$_:\$n'" } (keys %macro_seen));
 
@@ -493,7 +504,7 @@ sub write_aclocal ($@)
   my %files = map { $map{$_} => 1 } @macros;
   $files{'acinclude.m4'} = 1 if -f 'acinclude.m4';
 
-  for $file (sort keys %files)
+  for $file (grep { exists $files{$_} } @file_order)
     {
       my $mtime = mtime $file;
       $greatest_mtime = $mtime if $greatest_mtime < $mtime;
index a321395..b70ad8b 100644 (file)
@@ -11,6 +11,10 @@ aclocal5.test \
 aclocal6.test \
 aclocal7.test \
 aclocal8.test \
+aclocal9.test \
+acloca10.test \
+acloca11.test \
+acloca12.test \
 acoutnoq.test \
 acoutpt.test \
 acoutpt2.test \
index 91c256a..155727b 100644 (file)
@@ -120,6 +120,10 @@ aclocal5.test \
 aclocal6.test \
 aclocal7.test \
 aclocal8.test \
+aclocal9.test \
+acloca10.test \
+acloca11.test \
+acloca12.test \
 acoutnoq.test \
 acoutpt.test \
 acoutpt2.test \
diff --git a/tests/acloca10.test b/tests/acloca10.test
new file mode 100755 (executable)
index 0000000..b41b291
--- /dev/null
@@ -0,0 +1,55 @@
+#! /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 define macros in the same order as -I's.
+# This is the same as aclocal9.test, with the macro calls reversed.
+# (It did make a difference.)
+
+. ./defs || exit 1
+
+set -e
+
+cat >> configure.in << 'END'
+MACRO2
+MACRO1
+END
+
+mkdir m4_1 m4_2
+
+cat >m4_1/somedefs.m4 <<EOF
+AC_DEFUN([MACRO1], [echo macro11 >> foo])
+AC_DEFUN([MACRO2], [echo macro21 > foo])
+EOF
+
+cat >m4_2/somedefs.m4 <<EOF
+AC_DEFUN([MACRO1], [echo macro12 >> foo])
+EOF
+
+$ACLOCAL -I m4_1 -I m4_2
+$AUTOCONF
+./configure
+grep macro11 foo
+grep macro21 foo
+
+$ACLOCAL -I m4_2 -I m4_1
+$AUTOCONF
+./configure
+grep macro12 foo
+grep macro21 foo
diff --git a/tests/acloca11.test b/tests/acloca11.test
new file mode 100755 (executable)
index 0000000..5c61672
--- /dev/null
@@ -0,0 +1,48 @@
+#! /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 that when two files define the same macro in the same
+# directory, the macro from the lexically greatest file is used.
+
+. ./defs || exit 1
+
+set -e
+
+cat >> configure.in << 'END'
+MACRO2
+MACRO1
+END
+
+mkdir m4
+
+cat >m4/version1.m4 <<EOF
+AC_DEFUN([MACRO1], [echo macro11 >> foo])
+AC_DEFUN([MACRO2], [echo macro21 > foo])
+EOF
+
+cat >m4/version2.m4 <<EOF
+AC_DEFUN([MACRO1], [echo macro12 >> foo])
+EOF
+
+$ACLOCAL -I m4
+$AUTOCONF
+./configure
+grep macro12 foo
+grep macro21 foo
diff --git a/tests/acloca12.test b/tests/acloca12.test
new file mode 100755 (executable)
index 0000000..3db8104
--- /dev/null
@@ -0,0 +1,49 @@
+#! /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 that when two files define the same macro in the same
+# directory, the macro from the lexically greatest file is used.
+# Same as acloca11.test, but without calling MACRO2.
+
+. ./defs || exit 1
+
+set -e
+
+cat >> configure.in << 'END'
+MACRO1
+END
+
+mkdir m4
+
+cat >m4/version1.m4 <<EOF
+AC_DEFUN([MACRO1], [echo macro11 >> foo])
+AC_DEFUN([MACRO2], [echo macro21 > foo])
+EOF
+
+cat >m4/version2.m4 <<EOF
+AC_DEFUN([MACRO1], [echo macro12 >> foo])
+EOF
+
+$ACLOCAL --verbose -I m4
+$AUTOCONF
+./configure
+grep macro11 foo && exit 1
+grep macro21 foo && exit 1
+grep macro12 foo