From: Stefano Lattarini Date: Thu, 3 May 2012 10:00:35 +0000 (+0200) Subject: [ng] vars: simplify logic for appending conditionally X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=87508438b9e3d80046c890e3e5168138d61eb269;p=thirdparty%2Fautomake.git [ng] vars: simplify logic for appending conditionally This will make the generated Makefiles more bloated, but that should be OK, since eventually further refactorings will change the format used to output conditional variables extending, and the resulting Makefiles will once again be smaller and cleaner. * lib/Automake/Variable.pm (define): When appending to an existing variable *defined in another condition*, don't bother to avoid the creation of intermediate internal variables when that's not really needed; just create them unconditionally. (_new): Don't reset $self->{'last-append'} anymore, it has been removed (it was only used in the 'define' function). Signed-off-by: Stefano Lattarini --- diff --git a/lib/Automake/Variable.pm b/lib/Automake/Variable.pm index 1e227c32e..0c83b6650 100644 --- a/lib/Automake/Variable.pm +++ b/lib/Automake/Variable.pm @@ -423,7 +423,6 @@ 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:]]+)$/) { @@ -799,8 +798,6 @@ 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. $def->set_owner ($owner, $where->clone) @@ -809,63 +806,24 @@ sub define ($$$$$$$$) # 2. append (+=) to a variable defined for *another* condition elsif ($type eq '+' && ! $self->conditions->false) { - # * Generally, $cond is not TRUE. For instance: + # * If we have an input like: # FOO = foo # if COND # FOO += bar # endif - # In this case, we declare an helper variable conditionally, - # and append it to FOO: + # we declare an helper variable conditionally, and append + # it to FOO: # FOO = foo $(am__append_1) # @COND_TRUE@am__append_1 = bar # Of course if FOO is defined under several conditions, we add # $(am__append_1) to each definitions. - # - # * If $cond is TRUE, we don't need the helper variable. E.g., in - # if COND1 - # FOO = foo1 - # else - # FOO = foo2 - # endif - # FOO += bar - # we can add bar directly to all definition of FOO, and output - # @COND_TRUE@FOO = foo1 bar - # @COND_FALSE@FOO = foo2 bar - - my $lastappend = []; - # Do we need an helper variable? - if ($cond != TRUE) - { - # 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)"; - } - } + my $num = ++$_appendvar; + my $hvar = "am__append_$num"; + &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. foreach my $vcond ($self->conditions->conds) @@ -895,7 +853,6 @@ sub define ($$$$$$$$) $where, $pretty); } } - $self->{'last-append'} = $lastappend; } # 3. first assignment (=, :=, or +=) else diff --git a/t/cond38.sh b/t/cond38.sh index 71ae69a0c..e63d8d181 100755 --- a/t/cond38.sh +++ b/t/cond38.sh @@ -59,9 +59,6 @@ $AUTOCONF $AUTOMAKE ./configure -# Make sure no extra variable was created for the last 3 items. -grep 'append.*=.* h iXYZ jZYX' Makefile -# Check good ordering. $MAKE test :