>>> "Ed" == Ed Hartnett <[EMAIL PROTECTED]> writes:
Ed> The following automake file attempts to add two subdirs, Ed> "fortran" and "nf_test", if the BUILD_F77 automake Ed> conditional is true. But this fails: Ed> SUBDIRS = man Ed> if BUILD_F77 Ed> SUBDIRS += fortran Ed> endif Ed> SUBDIRS += libsrc nc_test ncgen ncdump nctest Ed> # If we're building the f77 API, test it too. Ed> if BUILD_F77 Ed> SUBDIRS += nf_test Ed> endif Ed> The problem is that nf_test is not added to the end of the Ed> list Thanks for the report. I'm installing the following fix on HEAD and branch-1-9. 2005-06-24 Alexandre Duret-Lutz <[EMAIL PROTECTED]> * 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. Index: THANKS =================================================================== RCS file: /cvs/automake/automake/THANKS,v retrieving revision 1.269 diff -u -r1.269 THANKS --- THANKS 22 Jun 2005 15:07:26 -0000 1.269 +++ THANKS 23 Jun 2005 22:09:07 -0000 @@ -56,6 +56,7 @@ Dmitry Mikhin [EMAIL PROTECTED] Doug Evans [EMAIL PROTECTED] Duncan Gibson [EMAIL PROTECTED] +Ed Hartnett [EMAIL PROTECTED] Eleftherios Gkioulekas [EMAIL PROTECTED] Elena A. Vengerova [EMAIL PROTECTED] Elmar Hoffmann [EMAIL PROTECTED] Index: lib/Automake/Variable.pm =================================================================== RCS file: /cvs/automake/automake/lib/Automake/Variable.pm,v retrieving revision 1.37 diff -u -r1.37 Variable.pm --- lib/Automake/Variable.pm 14 May 2005 20:28:51 -0000 1.37 +++ lib/Automake/Variable.pm 23 Jun 2005 22:09:08 -0000 @@ -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 @@ 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 @@ { %_variable_dict = (); %_primary_dict = (); - %_appendvar = (); + $_appendvar = 0; @_var_order = (); %_gen_varname = (); $_traversal = 0; @@ -436,6 +434,7 @@ 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 @@ 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 @@ # @[EMAIL PROTECTED] = foo1 bar # @[EMAIL PROTECTED] = 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 @@ $where, $pretty); } } + $self->{'last-append'} = $lastappend; } # 3. first assignment (=, :=, or +=) else Index: tests/Makefile.am =================================================================== RCS file: /cvs/automake/automake/tests/Makefile.am,v retrieving revision 1.588 diff -u -r1.588 Makefile.am --- tests/Makefile.am 8 Jun 2005 19:41:25 -0000 1.588 +++ tests/Makefile.am 23 Jun 2005 22:09:08 -0000 @@ -138,6 +138,7 @@ cond35.test \ cond36.test \ cond37.test \ +cond38.test \ condd.test \ condhook.test \ condinc.test \ Index: tests/cond21.test =================================================================== RCS file: /cvs/automake/automake/tests/cond21.test,v retrieving revision 1.5 diff -u -r1.5 cond21.test --- tests/cond21.test 14 May 2005 20:28:54 -0000 1.5 +++ tests/cond21.test 23 Jun 2005 22:09:09 -0000 @@ -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 @@ 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 @@ $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' Index: tests/cond38.test =================================================================== RCS file: tests/cond38.test diff -N tests/cond38.test --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ tests/cond38.test 23 Jun 2005 22:09:09 -0000 @@ -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 -- Alexandre Duret-Lutz