On Fri, Mar 09, 2001 at 01:53:17PM +0100, Lars J. Aas wrote:
: When I bootstrap with the current Automake CVS sources, the strudels (@s)
: between the conditionals are missing:
: 
: > 
:@SIMAGE_JPEG_SUPPORT_FALSESIMAGE_PIC_SUPPORT_FALSESIMAGE_PNG_SUPPORT_FALSESIMAGE_RGB_SUPPORT_FALSESIMAGE_TGA_SUPPORT_FALSESIMAGE_TIFF_SUPPORT_FALSESIMAGE_UNGIF_SUPPORT_TRUE@am_libsimage@SUFFIX@_la_OBJECTS
: = \

I found out that this bug goes all the way back to automake.in r1.915.
> revision 1.915
> date: 2001/02/25 18:42:41;  author: akim;  state: Exp;  lines: +73 -49
> Internally just store the conditionals as space separated lists of
> CONDITIONS (instead of @CONDITIONS@).
> * automake.in (&conditional_true_when, &variable_conditions_sub):
> Split conditions at spaces.
> (&handle_dependencies, &variable_conditions_permutations): Don't
> put @ around conditions.
> (&variable_conditions_cmp): There are no @ to strip.
> (&make_condition): New.
> (&define_pretty_variable, &read_main_am_file, &read_am_file): Use
> it.
> (&read_main_am_file, &read_am_file): Stop playing with @ by hand.
> Join @conditional_stack with spaces.
> (&read_main_am_file): Adjust the output of variables.
> Output `TRUE = true' under the condition `TEST' as `@TEST@TRUE =
> true' and no longer `@TEST@TRUE = @TEST@true'.
> (&variable_conditions_cmp): Rename as...
> (&by_condition): this.
> Sort in a human pleasant order.
> Use it everywhere a human can see conditions.
> (&variable_conditions_reduce): Don't sort conditions, that's
> pointless.
> * tests/cond.test, ctarget1.test, pluseq3.test: Strengthen.

The
> Join @conditional_stack with spaces.
doesn't seem to do it's job.

The diff is attached.

  Lars J
-- 
Innovation is one percent inspiration and ninetynine percent perspiration,
and in my case; twice that...  -- Norville Barnes, `The Hudsucker Proxy'
--- automake.1.914      Fri Mar  9 18:40:51 2001
+++ automake.1.915      Fri Mar  9 18:38:41 2001
@@ -2959,7 +2959,7 @@
            # We define this as a conditional variable because BSD
            # make can't handle backslashes for continuing comments on
            # the following line.
-           &define_pretty_variable ('DEP_FILES', "\@AMDEP\@", @deplist);
+           &define_pretty_variable ('DEP_FILES', 'AMDEP', @deplist);
 
            # Generate each `include' individually.  Irix 6 make will
            # not properly include several files resulting from a
@@ -5326,6 +5326,24 @@
     return defined $targets{$target};
 }
 
+
+# &make_condition (@CONDITIONS)
+# -----------------------------
+# Transform a list of conditions (themselves can be an internal list
+# of conditions, e.g., @CONDITIONS = ('cond1 cond2', 'cond3')) into a
+# Make conditional (a pattern for AC_SUBST).
+# Correctly returns the empty string when there are no conditions.
+sub make_condition
+{
+    my $res = join ('@@', @_);
+    return ''
+      unless $res;
+
+    $res = '@' . $res . '@';
+    $res =~ s/ /@@/;
+    return $res;
+}
+
 # See if two conditionals are the same.
 sub conditional_same
 {
@@ -5342,11 +5360,11 @@
 {
   print STDERR "%conditional =\n";
   print STDERR "{\n";
-  foreach my $var (keys %conditional)
+  foreach my $var (sort keys %conditional)
     {
       print STDERR "  $var = \n";
       print STDERR "  {\n";
-      foreach my $vcond (keys %{${conditional{$var}}})
+      foreach my $vcond (sort by_condition keys %{$conditional{$var}})
       {
        print STDERR "    $vcond => $conditional{$var}{$vcond}\n";
       }
@@ -5355,6 +5373,7 @@
   print STDERR "}\n";
 }
 
+
 # $BOOLEAN
 # &conditional_true_when ($COND, $WHEN)
 # -------------------------------------
@@ -5368,13 +5387,9 @@
     my ($cond, $when) = @_;
 
     # Check each component of $cond, which looks @COND1@@COND2@.
-    foreach my $comp (split ('@', $cond))
+    foreach my $comp (split (' ', $cond))
     {
-       # The way we split will give null strings between each
-       # condition.
-       next if ! $comp;
-
-       if (index ($when, '@' . $comp . '@') == -1)
+       if (index ($when, $comp) == -1)
        {
            return 0;
        }
@@ -5511,7 +5526,7 @@
        $uniqify{$cond} = 1;
     }
 
-    @uniq_list = sort keys %uniqify;
+    @uniq_list = sort by_condition keys %uniqify;
     # Note we cannot just do `return sort keys %uniqify', because this
     # function is sometimes used in a scalar context.
     return @uniq_list;
@@ -5553,9 +5568,8 @@
        my %allconds = ();
        foreach my $item (@new_conds)
        {
-           foreach (split ('@', $item))
+           foreach (split (' ', $item))
            {
-               next if ! $_;
                s/_(TRUE|FALSE)$//;
                $allconds{$_ . '_TRUE'} = 1;
            }
@@ -5620,7 +5634,7 @@
     foreach my $this_cond (@this_conds)
     {
        my @perms =
-           &variable_conditions_permutations (split('@', $this_cond));
+           &variable_conditions_permutations (split(' ', $this_cond));
        foreach my $perm (@perms)
        {
            my $ok = 1;
@@ -5647,25 +5661,32 @@
     return @new_conds;
 }
 
-# Subroutine for variable_conditions_sort
-sub variable_conditions_cmp
-{
-    my $as = $a;
-    $as =~ s/[^@]//g;
-    my $bs = $b;
-    $bs =~ s/[^@]//g;
-    return (length ($as) <=> length ($bs)
+
+# Compare condition names.
+# Issue them in alphabetical order, foo_TRUE before foo_FALSE.
+sub by_condition
+{
+    $a =~ /^(.*)_(TRUE|FALSE)$/;
+    my ($aname, $abool) = ($1, $2);
+    $b =~ /^(.*)_(TRUE|FALSE)$/;
+    my ($bname, $bbool) = ($1, $2);
+    return ($aname cmp $bname
+           # Don't bother with IFs, given that TRUE is after FALSE
+           # just cmp in the reverse order.
+           || $bbool cmp $abool
+           # Just in case...
            || $a cmp $b);
 }
 
-# Sort a list of conditionals so that only the exclusive ones are
-# retained.  For example, if both @COND1_TRUE@@COND2_TRUE@ and
-# @COND1_TRUE@ are in the list, discard the latter.
+
+# Filter a list of conditionals so that only the exclusive ones are
+# retained.  For example, if both `COND1_TRUE COND2_TRUE' and
+# `COND1_TRUE' are in the list, discard the latter.
 sub variable_conditions_reduce
 {
     my (@conds) = @_;
     my @ret = ();
-    foreach my $cond (sort variable_conditions_cmp @conds)
+    foreach my $cond (@conds)
     {
        next
          if ! conditionals_true_when (($cond), (@ret));
@@ -5691,13 +5712,13 @@
     my @ret;
     foreach my $sub (&variable_conditions_permutations (@comps))
     {
-       push (@ret, '@' . $comp . '@' . $sub);
-       push (@ret, '@' . $neg . '@' . $sub);
+       push (@ret, $comp . $sub);
+       push (@ret, $neg . $sub);
     }
     if (! @ret)
     {
-       push (@ret, '@' . $comp . '@');
-       push (@ret, '@' . $neg . '@');
+       push (@ret, $comp);
+       push (@ret, $neg);
     }
     return @ret;
 }
@@ -5923,7 +5944,9 @@
        {
            ${$conditional{$var}}{$cond} = $contents{$var};
        }
-       &pretty_print ($cond . $var . ' = ', $cond, @value);
+        my $make_condition = &make_condition ($cond);
+       &pretty_print ($make_condition . $var . ' = ',
+                      $make_condition, @value);
        $content_seen{$var} = 1;
     }
 }
@@ -6073,7 +6096,8 @@
        {
            if ($was_rule)
            {
-               $output_trailer .= join ('', @conditional_stack) . $_;
+               $output_trailer .= &make_condition (@conditional_stack);
+               $output_trailer .= $_;
                $saw_bk = /\\$/;
            }
            else
@@ -6084,7 +6108,7 @@
                $contents{$last_var_name} .= $_;
                if (@conditional_stack)
                {
-                   my $cond_string = join ('', @conditional_stack);
+                   my $cond_string = join (' ', @conditional_stack);
                    ${conditional{$last_var_name}}{$cond_string} .= $_;
                }
            }
@@ -6093,7 +6117,7 @@
        {
            &am_line_error ($., "$1 does not appear in AM_CONDITIONAL")
                if (! $configure_cond{$1});
-           push (@conditional_stack, "\@" . $1 . "_TRUE\@");
+           push (@conditional_stack, "$1_TRUE");
        }
        elsif (/$ELSE_PATTERN/o)
        {
@@ -6101,14 +6125,14 @@
            {
                &am_line_error ($., "else without if");
            }
-           elsif ($conditional_stack[$#conditional_stack] =~ /_FALSE\@$/)
+           elsif ($conditional_stack[$#conditional_stack] =~ /_FALSE$/)
            {
                &am_line_error ($., "else after else");
            }
            else
            {
                $conditional_stack[$#conditional_stack]
-                   =~ s/_TRUE\@$/_FALSE\@/;
+                   =~ s/_TRUE$/_FALSE/;
            }
        }
        elsif (/$ENDIF_PATTERN/o)
@@ -6137,9 +6161,9 @@
            # Value here doesn't matter; for targets we only note
            # existence.
            $targets{$1} = 1;
-           my $cond_string = join ('', @conditional_stack);
            if (@conditional_stack)
            {
+               my $cond_string = join (' ', @conditional_stack);
                if ($target_conditional{$1})
                {
                    &check_ambiguous_conditional ($1, $cond_string);
@@ -6147,7 +6171,9 @@
                ${$target_conditional{$1}}{$cond_string} = '1';
            }
            $content_lines{$1} = $.;
-           $output_trailer .= $comment . $spacing . $cond_string . $_;
+           $output_trailer .= $comment . $spacing;
+            $output_trailer .= &make_condition (@conditional_stack);
+            $output_trailer .= $_;
            $comment = $spacing = '';
            $saw_bk = /\\$/;
 
@@ -6233,7 +6259,7 @@
            # Handle conditionalized macros.
            if (@conditional_stack)
            {
-               my $cond_string = join ('', @conditional_stack);
+               my $cond_string = join (' ', @conditional_stack);
                my $done = 0;
                if ($conditional{$last_var_name})
                {
@@ -6295,8 +6321,9 @@
            # This isn't an error; it is probably a continued rule.
            # In fact, this is what we assume.
            $was_rule = 1;
-           $output_trailer .= ($comment . $spacing
-                               . join ('', @conditional_stack) . $_);
+           $output_trailer .= $comment . $spacing;
+           $output_trailer .= &make_condition  (@conditional_stack);
+           $output_trailer .= $_;
            $comment = $spacing = '';
            $saw_bk = /\\$/;
        }
@@ -6388,17 +6415,14 @@
        $output_vars .= $am_vars{$var};
        if ($conditional{$var})
        {
-           foreach my $vcond (keys %{$conditional{$var}})
+           foreach my $vcond (sort by_condition keys %{$conditional{$var}})
            {
                my $val = ${$conditional{$var}}{$vcond};
-               $output_vars .= ($vcond . $var . ' '
-                                . $def_type{$var} . "= ");
-               foreach my $line (split ("\n", $val))
-               {
-                   $output_vars .= $vcond . $line . "\n";
-               }
-               $output_vars .= "\n"
-                   if $val eq '';
+               my $output_var = ($var . ' '
+                                 . $def_type{$var} . "= "
+                                 . $val);
+               $output_var =~ s/^/&make_condition ($vcond)/meg;
+               $output_vars .= $output_var . "\n";
            }
        }
        else

Reply via email to