Automake::Conditional.
* lib/Automake/Conditional.pm (TRUE, FALSE): New constants.
(new): Simplify using FALSE.
(reduce): New function, moved from ...
* automake.in (variable_conditions_reduce): ... here.
(variable_conditions_recursive_sub, invert_conditions):
Adjust calls to Automake::Conditional::reduce.
* tests/cond12.test: Adjust to use Automake::Conditional.
+2002-11-13 Alexandre Duret-Lutz <adl@gnu.org>
+
+ * automake.in: Don't declare TRUE and FALSE, import them from
+ Automake::Conditional.
+ * lib/Automake/Conditional.pm (TRUE, FALSE): New constants.
+ (new): Simplify using FALSE.
+ (reduce): New function, moved from ...
+ * automake.in (variable_conditions_reduce): ... here.
+ (variable_conditions_recursive_sub, invert_conditions):
+ Adjust calls to Automake::Conditional::reduce.
+ * tests/cond12.test: Adjust to use Automake::Conditional.
+
2002-11-09 Jim Meyering <jim@meyering.net>
Make install-sh work even when names contain spaces or
use Automake::XFile;
use Automake::Channels;
use Automake::Location;
-use Automake::Conditional;
+use Automake::Conditional qw/TRUE FALSE/;
use File::Basename;
use Tie::RefHash;
use Carp;
# We can't always associate a location to a variable or a rule,
# when its defined by Automake. We use INTERNAL in this case.
use constant INTERNAL => new Automake::Location;
-
-# The TRUE and FALSE conditionals.
-use constant TRUE => new Automake::Conditional;
-use constant FALSE => new Automake::Conditional "FALSE";
\f
## ---------------------------------- ##
}
else
{
- push (@new_conds, variable_conditions_reduce (@subvar_conds));
+ push (@new_conds, Automake::Conditional::reduce (@subvar_conds));
}
}
}
-# 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.
-# If the list is empty, return TRUE
-sub variable_conditions_reduce
-{
- my (@conds) = @_;
- my @ret = ();
- my $cond;
- while (@conds > 0)
- {
- $cond = shift @conds;
-
- # FALSE is absorbent.
- return FALSE
- if $cond == FALSE;
-
- if (! $cond->redundant_wrt (@ret, @conds))
- {
- push (@ret, $cond);
- }
- }
-
- return TRUE if @ret == 0;
- return @ret;
-}
-
# @CONDS
# invert_conditions (@CONDS)
# --------------------------
# Generate all permutation for all inputs.
my @perm = map { variable_conditions_permutations ($_->conds); } @conds;
# Remove redundant conditions.
- @perm = variable_conditions_reduce @perm;
+ @perm = Automake::Conditional::reduce @perm;
# Now remove all conditions which imply one of the input conditions.
foreach my $perm (@perm)
use strict;
use Carp;
+require Exporter;
+use vars '@ISA', '@EXPORT_OK';
+@ISA = qw/Exporter/;
+@EXPORT_OK = qw/TRUE FALSE reduce/;
+
=head1 NAME
Automake::Conditional - record a conjunction of conditions
# (Not in this example)
if ($cond->implies_any ($other, $both)) { ... }
+ # Remove superfluous conditions.
+ # (Returns @cons = ($both) in this example, because
+ # $other and $cond are implied by $both.)
+ @conds = Automake::Conditional::reduce ($other, $both, $cond);
+
=head1 DESCRIPTION
A C<Conditional> is a conjunction of atomic conditions. In Automake they
# associated object conditions. This is used by `new' to reuse
# Conditional objects with identical conditions.
use vars '%_conditional_singletons';
-%_conditional_singletons = ();
+# Do NOT reset this hash here. It's already empty by default,
+# and any reset would otherwise occur AFTER the `TRUE' and `FALSE'
+# constants definitions.
+# %_conditional_singletons = ();
sub new ($;@)
{
|| ($cond =~ /^(.*)_TRUE$/ && exists $self->{'hash'}{"${1}_FALSE"})
|| ($cond =~ /^(.*)_FALSE$/ && exists $self->{'hash'}{"${1}_TRUE"}))
{
- return new Automake::Conditional 'FALSE';
+ return &FALSE;
}
$self->{'hash'}{$cond} = 1;
=cut
-# $BOOLEAN
-# &conditional_implies_any ($COND, @CONDS)
-# ----------------------------------------
-# Returns true iff $COND implies any of the conditions in @CONDS.
sub implies_any ($@)
{
my ($self, @conds) = @_;
return 0;
}
+=head2 Other helper functions
+
+=over 4
+
+=item C<TRUE>
+
+The C<"TRUE"> conditional.
+
+=item C<FALSE>
+
+The C<"FALSE"> conditional.
+
+=cut
+
+use constant TRUE => new Automake::Conditional "TRUE";
+use constant FALSE => new Automake::Conditional "FALSE";
+
+=item C<reduce (@conds)>
+
+Filter a list of conditionals so that only the exclusive ones are
+retained. For example, if both C<COND1_TRUE COND2_TRUE> and
+C<COND1_TRUE> are in the list, discard the latter.
+If the input list is empty, return C<(TRUE)>.
+
+=cut
+
+sub reduce (@)
+{
+ my (@conds) = @_;
+ my @ret = ();
+ my $cond;
+ while (@conds > 0)
+ {
+ $cond = shift @conds;
+
+ # FALSE is absorbent.
+ return FALSE
+ if $cond == FALSE;
+
+ if (! $cond->redundant_wrt (@ret, @conds))
+ {
+ push (@ret, $cond);
+ }
+ }
+
+ return TRUE if @ret == 0;
+ return @ret;
+}
+
=head1 HISTORY
C<AM_CONDITIONAL>s and supporting code were added to Automake 1.1o by
Ian Lance Taylor <ian@cygnus.org> in 1997. Since then it has been
improved by Tom Tromey <tromey@redhat.com>, Richard Boulton
<richard@tartarus.org>, Raja R Harinath <harinath@cs.umn.edu>, and
-Akim Demaile <akim@epita.fr>. Alexandre Duret-Lutz <adl@gnu.org>
+Akim Demaille <akim@epita.fr>. Alexandre Duret-Lutz <adl@gnu.org>
extracted the code out of Automake to create this package in 2002.
=cut
# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
-# Test behaviour of variable_conditions_reduce()
-# This checks the result of variable_conditions_reduce() for a wide variety
-# of cases.
+# This checks the result of Automake::Conditional::reduce() for
+# a wide variety of cases.
. ./defs || exit 1
-# FIXME: probably ought to let use override this like we do in `defs'.
-amfile=../../automake
+set -e
+
+cat << 'END' > run
+use Automake::Conditional;
-sed 1q $amfile >>automake_tmp
-cat << 'END' >> automake_tmp
my $failed = 0;
sub check_reduce($$) {
my ($inref, $outref) = @_;
my @inconds = map { new Automake::Conditional $_ } @$inref;
my @outconds = map { (new Automake::Conditional $_)->string } @$outref;
my @res =
- map { $_->string } (&Automake::variable_conditions_reduce (@inconds));
+ map { $_->string } (Automake::Conditional::reduce (@inconds));
my $result = join (",", sort @res);
my $exresult = join (",", @outconds);
exit $failed;
END
-cat $amfile >>automake_tmp
-chmod +x automake_tmp
-
-./automake_tmp
+chmod +x run
+$PERL -w -I $perllibdir ./run