]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
* automake.in: Don't declare TRUE and FALSE, import them from
authorAlexandre Duret-Lutz <adl@gnu.org>
Wed, 13 Nov 2002 20:11:32 +0000 (20:11 +0000)
committerAlexandre Duret-Lutz <adl@gnu.org>
Wed, 13 Nov 2002 20:11:32 +0000 (20:11 +0000)
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.

ChangeLog
automake.in
lib/Automake/Conditional.pm
tests/cond12.test

index 87f54cd30e90565217c4cb35066527608b796c1e..e2c036ca556d8171acca0a14c76ac68b83e14c2b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+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
index 13c7edd2b253efde4da4564bc34735c9c6e66129..aa75ec2fe225a0cb0d6812e7ec550048a52b8b0d 100755 (executable)
@@ -116,7 +116,7 @@ use Automake::General;
 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;
@@ -294,10 +294,6 @@ use constant COMPILE_ORDINARY => 2;
 # 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
 
 ## ---------------------------------- ##
@@ -6784,7 +6780,7 @@ sub variable_conditions_recursive_sub
        }
       else
        {
-         push (@new_conds, variable_conditions_reduce (@subvar_conds));
+         push (@new_conds, Automake::Conditional::reduce (@subvar_conds));
        }
     }
 
@@ -6824,33 +6820,6 @@ sub variable_conditions_recursive_sub
 }
 
 
-# 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)
 # --------------------------
@@ -6873,7 +6842,7 @@ sub invert_conditions
     # 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)
index 26a16a5c211c56f664c0a1d729313b4a0ffe34a9..31e025152a47542b761bae8b908e6da71b36d5da 100644 (file)
@@ -19,6 +19,11 @@ package Automake::Conditional;
 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
@@ -67,6 +72,11 @@ 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
@@ -138,7 +148,10 @@ both create the C<"FALSE"> conditional).
 # 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 ($;@)
 {
@@ -166,7 +179,7 @@ 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;
@@ -370,10 +383,6 @@ Return 0 otherwise.
 
 =cut
 
-# $BOOLEAN
-# &conditional_implies_any ($COND, @CONDS)
-# ----------------------------------------
-# Returns true iff $COND implies any of the conditions in @CONDS.
 sub implies_any ($@)
 {
   my ($self, @conds) = @_;
@@ -385,13 +394,62 @@ sub implies_any ($@)
   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
index cfcd7e3fb01e82e78f4421b9a1a2fb26d79cdf14..a51702702b255aebfab20966fe3eaf9cf891568e 100755 (executable)
 # 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);
 
@@ -99,7 +98,5 @@ check_reduce(["FOO BAR", "BAR FOO"], ["BAR FOO"]);
 
 exit $failed;
 END
-cat $amfile >>automake_tmp
-chmod +x automake_tmp
-
-./automake_tmp
+chmod +x run
+$PERL -w -I $perllibdir ./run