]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
* lib/Automake/Variable.pm (define, _new): Remember the helper
authorAlexandre Duret-Lutz <adl@gnu.org>
Thu, 23 Jun 2005 22:19:56 +0000 (22:19 +0000)
committerAlexandre Duret-Lutz <adl@gnu.org>
Thu, 23 Jun 2005 22:19:56 +0000 (22:19 +0000)
variable created for the last conditional += on each variable, and
only append further += in the same condition to this last helper
variable, not to older helper variables.  This way the order of
the items appended to the variable is preserved.
* tests/cond21.test: Adjust.
* tests/cond38.test: New file.
* tests/Makefile.am (TESTS): Add cond38.test.
Report from Ed Hartnett.

ChangeLog
THANKS
lib/Automake/Variable.pm
tests/Makefile.am
tests/Makefile.in
tests/cond21.test
tests/cond38.test [new file with mode: 0755]

index 3e01c40a68ef74032732ba78744b58ff766d1be6..1085ef8b4024938d622ac0cf44b4fdfe7f83de55 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2005-06-24  Alexandre Duret-Lutz  <adl@gnu.org>
+
+       * lib/Automake/Variable.pm (define, _new): Remember the helper
+       variable created for the last conditional += on each variable, and
+       only append further += in the same condition to this last helper
+       variable, not to older helper variables.  This way the order of
+       the items appended to the variable is preserved.
+       * tests/cond21.test: Adjust.
+       * tests/cond38.test: New file.
+       * tests/Makefile.am (TESTS): Add cond38.test.
+       Report from Ed Hartnett.
+
 2005-06-22  Alexandre Duret-Lutz  <adl@gnu.org>
 
        * tests/aclocal5.test: Adjust to recent CVS Autoconf changes.
diff --git a/THANKS b/THANKS
index 3d13303f6deabcc722f6be4a68006b2a5883aa26..5552ef5d0fea85fbd318dd9771c4aab69ae5d07a 100644 (file)
--- a/THANKS
+++ b/THANKS
@@ -56,6 +56,7 @@ Dieter Baron          dillo@stieltjes.smc.univie.ac.at
 Dmitry Mikhin          dmitrym@acres.com.au
 Doug Evans             devans@cygnus.com
 Duncan Gibson          duncan@thermal.esa.int
+Ed Hartnett            ed@unidata.ucar.edu
 Eleftherios Gkioulekas lf@amath.washington.edu
 Elena A. Vengerova     helen@oktetlabs.ru
 Elmar Hoffmann         elho@elho.net
index bd87f254d82c5a58f0782d35ece15e4ad20fc576..549630920640fd0e8670a1a6180087089c056cb3 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2003, 2004  Free Software Foundation, Inc.
+# Copyright (C) 2003, 2004, 2005  Free Software Foundation, Inc.
 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -193,10 +193,8 @@ my %_silent_variable_override =
    JAVAC => 1,
    JAVAROOT => 1);
 
-# This hash records helper variables used to implement conditional '+='.
-# Keys have the form "VAR:CONDITIONS".  The value associated to a key is
-# the named of the helper variable used to append to VAR in CONDITIONS.
-my %_appendvar = ();
+# Count of helper variables used to implement conditional '+='.
+my $_appendvar;
 
 # Each call to C<Automake::Variable::traverse_recursively> gets an
 # unique label. This is used to detect recursively defined variables.
@@ -335,7 +333,7 @@ sub reset ()
 {
   %_variable_dict = ();
   %_primary_dict = ();
-  %_appendvar = ();
+  $_appendvar = 0;
   @_var_order = ();
   %_gen_varname = ();
   $_traversal = 0;
@@ -436,6 +434,7 @@ sub _new ($$)
   my ($class, $name) = @_;
   my $self = Automake::Item::new ($class, $name);
   $self->{'scanned'} = 0;
+  $self->{'last-append'} = []; # helper variable for last conditional append.
   $_variable_dict{$name} = $self;
   if ($name =~ /_([[:alnum:]]+)$/)
     {
@@ -892,6 +891,7 @@ sub define ($$$$$$$$)
   if ($type eq '+' && ! $new_var)
     {
       $def->append ($value, $comment);
+      $self->{'last-append'} = [];
 
       # Only increase owners.  A VAR_CONFIGURE variable augmented in a
       # Makefile.am becomes a VAR_MAKEFILE variable.
@@ -924,32 +924,39 @@ sub define ($$$$$$$$)
       #     @COND_TRUE@FOO = foo1 bar
       #     @COND_FALSE@FOO = foo2 bar
 
+      my $lastappend = [];
       # Do we need an helper variable?
       if ($cond != TRUE)
         {
-           # Does the helper variable already exists?
-           my $key = "$var:" . $cond->string;
-           if (exists $_appendvar{$key})
-             {
-               # Yes, let's simply append to it.
-               $var = $_appendvar{$key};
-               $owner = VAR_AUTOMAKE;
-               $self = var ($var);
-               $def = $self->rdef ($cond);
-               $new_var = 0;
-             }
-           else
-             {
-               # No, create it.
-               my $num = 1 + keys (%_appendvar);
-               my $hvar = "am__append_$num";
-               $_appendvar{$key} = $hvar;
-               &define ($hvar, VAR_AUTOMAKE, '+',
-                        $cond, $value, $comment, $where, $pretty);
-               # Now HVAR is to be added to VAR.
-               $comment = '';
-               $value = "\$($hvar)";
-             }
+         # Can we reuse the helper variable created for the previous
+         # append?  (We cannot reuse older helper variables because
+         # we must preserve the order of items appended to the
+         # variable.)
+         my $condstr = $cond->string;
+         my $key = "$var:$condstr";
+         my ($appendvar, $appendvarcond) = @{$self->{'last-append'}};
+         if ($appendvar && $condstr eq $appendvarcond)
+           {
+             # Yes, let's simply append to it.
+             $var = $appendvar;
+             $owner = VAR_AUTOMAKE;
+             $self = var ($var);
+             $def = $self->rdef ($cond);
+             $new_var = 0;
+           }
+         else
+           {
+             # No, create it.
+             my $num = ++$_appendvar;
+             my $hvar = "am__append_$num";
+             $lastappend = [$hvar, $condstr];
+             &define ($hvar, VAR_AUTOMAKE, '+',
+                      $cond, $value, $comment, $where, $pretty);
+
+             # Now HVAR is to be added to VAR.
+             $comment = '';
+             $value = "\$($hvar)";
+           }
        }
 
       # Add VALUE to all definitions of SELF.
@@ -980,6 +987,7 @@ sub define ($$$$$$$$)
                       $where, $pretty);
            }
        }
+      $self->{'last-append'} = $lastappend;
     }
   # 3. first assignment (=, :=, or +=)
   else
index 452b4f7b0f1dfc1a963967c09d884b62135eb443..75e92e09b0f8a6f3a56a6de981fc9e3e6be631bc 100644 (file)
@@ -138,6 +138,7 @@ cond34.test \
 cond35.test \
 cond36.test \
 cond37.test \
+cond38.test \
 condd.test \
 condhook.test \
 condinc.test \
index c4557e6774e0b3055d5bb09029215792c40ea426..0c89e00bb06fe7321c82f6f4278092bdf35169ea 100644 (file)
@@ -258,6 +258,7 @@ cond34.test \
 cond35.test \
 cond36.test \
 cond37.test \
+cond38.test \
 condd.test \
 condhook.test \
 condinc.test \
index c6fbd20ec79f2667374952e41abbe92053085805..56f682cbfa050852e1118f29af2c65616bf3e2ff 100755 (executable)
@@ -1,5 +1,5 @@
 #! /bin/sh
-# Copyright (C) 2002  Free Software Foundation, Inc.
+# Copyright (C) 2002, 2005  Free Software Foundation, Inc.
 #
 # This file is part of GNU Automake.
 #
@@ -43,9 +43,6 @@ if COND2
 else
   FOO += foon2
 endif
-## Note that we add `foo1b' after `foo2'; however because it is appended in
-## the same condition as `foo1', it should use the same helper variable
-## and thus appear right after `foo1' in the output.
 if COND1
   FOO += foo1b
 else
@@ -80,4 +77,4 @@ $AUTOCONF
 $AUTOMAKE -a
 ./configure
 $MAKE test | $FGREP 'BAR: bar12 bar bar3 :BAR'
-$MAKE test | $FGREP 'FOO: foo foo1 foo1b foo2 :FOO'
+$MAKE test | $FGREP 'FOO: foo foo1 foo2 foo1b :FOO'
diff --git a/tests/cond38.test b/tests/cond38.test
new file mode 100755 (executable)
index 0000000..154c127
--- /dev/null
@@ -0,0 +1,71 @@
+#!/bin/sh
+# Copyright (C) 2005  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., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+# Check conditional variable ordering.
+# Report from Ed Hartnett.
+
+. ./defs
+
+set -e
+
+cat >>configure.in <<'EOF'
+AM_CONDITIONAL([CASE_A], :)
+AM_CONDITIONAL([CASE_B], :)
+AC_OUTPUT
+EOF
+
+cat >>Makefile.am <<'EOF'
+SUBDIRS = a
+if CASE_A
+SUBDIRS += b
+endif
+SUBDIRS += c
+if CASE_A
+SUBDIRS += d
+if CASE_B
+SUBDIRS += e
+endif
+SUBDIRS += f
+endif
+SUBDIRS += g
+if CASE_B
+SUBDIRS += h
+endif
+if CASE_B
+SUBDIRS += iXYZ
+SUBDIRS += jZYX
+endif
+print:
+       @echo BEG: $(SUBDIRS) :END
+EOF
+
+mkdir a b c d e f g h iXYZ jZYX
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE print >stdout
+cat stdout
+# Check good ordering
+grep 'BEG: a b c d e f g h iXYZ jZYX :END' stdout
+# Make sure no extra variable was created for the last 3 items.
+grep 'append.*=.* h iXYZ jZYX' Makefile