automake-patches
[Top][All Lists]
Advanced

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

FYI: follow -I's for m4_include ordering in aclocal


From: Alexandre Duret-Lutz
Subject: FYI: follow -I's for m4_include ordering in aclocal
Date: Fri, 29 Aug 2003 00:49:35 +0200
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3 (gnu/linux)

I'm installing this on HEAD.  This ensures that when macros are
included from different directories, their ordering in
aclocal.m4 is reversed from the -I order.  This is in case two
included files define the same macro: macros from the first -I
directory should be defined after the other so they overwrite
them.  The macros are also passed in that order to autom4te.

When they come from the same directory, it sounds more logical
to order files lexicographically so that foo2.m4 is prefered
over foo1.m4.  (It also means that the list of m4_include will
be lexicographically ordered in aclocal.m4, which sounds neat.)

2003-08-29  Alexandre Duret-Lutz  <address@hidden>

        * 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.

Index: aclocal.in
===================================================================
RCS file: /cvs/automake/automake/aclocal.in,v
retrieving revision 1.86
diff -u -r1.86 aclocal.in
--- aclocal.in  24 Aug 2003 02:00:55 -0000      1.86
+++ aclocal.in  28 Aug 2003 22:46:54 -0000
@@ -73,6 +73,10 @@
 # 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.
address@hidden = ();
+
 # Map macro names to file names.
 %map = ();
 
@@ -228,7 +232,6 @@
        close (DEFAULT_DIRLIST);
     }
 
-
     return @dirlist;
 }
 
@@ -313,7 +316,9 @@
          }
 
        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 @@
 # 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 @@
   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 @@
   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: tests/Makefile.am
===================================================================
RCS file: /cvs/automake/automake/tests/Makefile.am,v
retrieving revision 1.512
diff -u -r1.512 Makefile.am
--- tests/Makefile.am   24 Aug 2003 22:34:59 -0000      1.512
+++ tests/Makefile.am   28 Aug 2003 22:46:56 -0000
@@ -11,6 +11,10 @@
 aclocal6.test \
 aclocal7.test \
 aclocal8.test \
+aclocal9.test \
+acloca10.test \
+acloca11.test \
+acloca12.test \
 acoutnoq.test \
 acoutpt.test \
 acoutpt2.test \
Index: tests/Makefile.in
===================================================================
RCS file: /cvs/automake/automake/tests/Makefile.in,v
retrieving revision 1.659
diff -u -r1.659 Makefile.in
--- tests/Makefile.in   24 Aug 2003 22:34:59 -0000      1.659
+++ tests/Makefile.in   28 Aug 2003 22:46:56 -0000
@@ -120,6 +120,10 @@
 aclocal6.test \
 aclocal7.test \
 aclocal8.test \
+aclocal9.test \
+acloca10.test \
+acloca11.test \
+acloca12.test \
 acoutnoq.test \
 acoutpt.test \
 acoutpt2.test \
Index: tests/acloca10.test
===================================================================
RCS file: tests/acloca10.test
diff -N tests/acloca10.test
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ tests/acloca10.test 28 Aug 2003 22:46:56 -0000
@@ -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
Index: tests/acloca11.test
===================================================================
RCS file: tests/acloca11.test
diff -N tests/acloca11.test
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ tests/acloca11.test 28 Aug 2003 22:46:56 -0000
@@ -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
Index: tests/acloca12.test
===================================================================
RCS file: tests/acloca12.test
diff -N tests/acloca12.test
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ tests/acloca12.test 28 Aug 2003 22:46:56 -0000
@@ -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
-- 
Alexandre Duret-Lutz





reply via email to

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