Index: ChangeLog
from Akim Demaille <[EMAIL PROTECTED]>
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.
Index: automake.in
--- automake.in Sat, 24 Feb 2001 01:48:46 +0100 akim (am/f/39_automake.i 1.68 755)
+++ automake.in Sat, 24 Feb 2001 13:26:13 +0100 akim (am/f/39_automake.i 1.68 755)
@@ -2926,7 +2926,7 @@ sub handle_dependencies
# 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
@@ -5283,6 +5283,24 @@ sub target_defined
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
{
@@ -5299,11 +5317,11 @@ sub conditional_dump ()
{
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";
}
@@ -5312,6 +5330,7 @@ sub conditional_dump ()
print STDERR "}\n";
}
+
# $BOOLEAN
# &conditional_true_when ($COND, $WHEN)
# -------------------------------------
@@ -5325,13 +5344,9 @@ sub conditional_true_when ($$)
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;
}
@@ -5468,7 +5483,7 @@ sub variable_conditions
$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;
@@ -5510,9 +5525,8 @@ sub variable_conditions_sub
my %allconds = ();
foreach my $item (@new_conds)
{
- foreach (split ('@', $item))
+ foreach (split (' ', $item))
{
- next if ! $_;
s/_(TRUE|FALSE)$//;
$allconds{$_ . '_TRUE'} = 1;
}
@@ -5577,7 +5591,7 @@ sub variable_conditions_sub
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;
@@ -5604,25 +5618,32 @@ sub variable_conditions_sub
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));
@@ -5648,13 +5669,13 @@ sub variable_conditions_permutations
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;
}
@@ -5880,7 +5901,9 @@ sub define_pretty_variable
{
${$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;
}
}
@@ -6030,7 +6053,8 @@ sub read_am_file
{
if ($was_rule)
{
- $output_trailer .= join ('', @conditional_stack) . $_;
+ $output_trailer .= &make_condition (@conditional_stack);
+ $output_trailer .= $_;
$saw_bk = /\\$/;
}
else
@@ -6041,7 +6065,7 @@ sub read_am_file
$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} .= $_;
}
}
@@ -6050,7 +6074,7 @@ sub read_am_file
{
&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)
{
@@ -6058,14 +6082,14 @@ sub read_am_file
{
&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)
@@ -6094,9 +6118,9 @@ sub read_am_file
# 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);
@@ -6104,7 +6128,9 @@ sub read_am_file
${$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 = /\\$/;
@@ -6190,7 +6216,7 @@ sub read_am_file
# 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})
{
@@ -6252,8 +6278,9 @@ sub read_am_file
# 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 = /\\$/;
}
@@ -6345,17 +6372,14 @@ sub read_main_am_file
$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
Index: tests/Makefile.in
--- tests/Makefile.in Wed, 21 Feb 2001 21:04:28 +0100 akim (am/h/14_Makefile.i 1.15
644)
+++ tests/Makefile.in Sat, 24 Feb 2001 13:28:47 +0100 akim (am/h/14_Makefile.i 1.15
+644)
@@ -145,6 +145,7 @@
confvar.test \
confvar2.test \
copy.test \
+ctarget1.test \
cxxansi.test \
cxxcpp.test \
cxxlibobj.test \
@@ -331,6 +332,7 @@
texinfo7.test \
texinfo8.test \
unused.test \
+vartar.test \
version.test \
version2.test \
version3.test \
Index: tests/cond.test
--- tests/cond.test Sun, 18 Feb 2001 20:02:57 +0100 akim (am/e/11_cond.test 1.2 775)
+++ tests/cond.test Sat, 24 Feb 2001 12:55:22 +0100 akim (am/e/11_cond.test 1.2 775)
@@ -18,6 +18,10 @@
endif
END
-$AUTOMAKE || exit 1
+set -e
+$AUTOMAKE
-grep '^@TEST_TRUE@' Makefile.in
+grep '^@TEST_TRUE@VAR = true$' Makefile.in
+grep '^@TEST_FALSE@VAR = false$' Makefile.in
+
+exit 0
Index: tests/ctarget1.test
--- tests/ctarget1.test Fri, 23 Feb 2001 00:01:11 +0100 akim (am/h/24_ctarget1.t 1.1
755)
+++ tests/ctarget1.test Sat, 24 Feb 2001 12:47:11 +0100 akim (am/h/24_ctarget1.t 1.1
+755)
@@ -13,7 +13,7 @@
cat > Makefile.am << 'END'
if TEST
target: true
- action
+ action
else
target: false
endif
@@ -21,7 +21,7 @@
$AUTOMAKE || exit 1
-grep '^@TEST_TRUE@target: true' Makefile.in || exit 1
-grep '^@TEST_TRUE@ action' Makefile.in || exit 1
-grep '^@TEST_FALSE@target: false' Makefile.in || exit 1
+grep '^@TEST_TRUE@target: true$' Makefile.in || exit 1
+grep '^@TEST_TRUE@ action$' Makefile.in || exit 1
+grep '^@TEST_FALSE@target: false$' Makefile.in || exit 1
exit 0
Index: tests/pluseq3.test
--- tests/pluseq3.test Sat, 13 Jan 2001 18:11:09 +0100 akim (am/b/29_pluseq3.te 1.1
775)
+++ tests/pluseq3.test Sat, 24 Feb 2001 13:28:28 +0100 akim (am/b/29_pluseq3.te 1.1
+775)
@@ -25,7 +25,13 @@
: > doz
: > dog
-$AUTOMAKE || exit 1
+set -e
-grep 'CHECK_TRUE.*doz' Makefile.in || exit 1
-grep 'CHECK_FALSE.*dog' Makefile.in
+$AUTOMAKE
+
+grep '^@CHECK_TRUE@data_DATA = zar \\$' Makefile.in
+grep '^@CHECK_TRUE@ doz$' Makefile.in
+
+grep '^@CHECK_FALSE@data_DATA = dog$' Makefile.in
+
+exit 0