]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
[ng] vars: simplify logic for appending conditionally
authorStefano Lattarini <stefano.lattarini@gmail.com>
Thu, 3 May 2012 10:00:35 +0000 (12:00 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Thu, 31 May 2012 08:23:13 +0000 (10:23 +0200)
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 <stefano.lattarini@gmail.com>
lib/Automake/Variable.pm
t/cond38.sh

index 1e227c32e6796069c1f01b7bf4ed57222c90a443..0c83b6650466ac7b627880286d8557740a51b263 100644 (file)
@@ -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
index 71ae69a0cf39e235000ebc0e6e6ff7c52bafb213..e63d8d181257d8a740db97ac12fd421ec63c09ac 100755 (executable)
@@ -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
 
 :