* automake.in (file_contents_internal): if a rule is conditionally
authorRichard Boulton <richard@tartarus.org>
Wed, 8 Aug 2001 16:44:05 +0000 (16:44 +0000)
committerRichard Boulton <richard@tartarus.org>
Wed, 8 Aug 2001 16:44:05 +0000 (16:44 +0000)
defined, define the standard automake definition for it for those
conditions which are not conditionally defined.
(invert_conditions): New function: invert a list of conditionals.

* tests/cond14.test: New file.
* tests/cond15.test: New file.
* tests/Makefile.am (TESTS): Added cond14.test and cond15.test.

ChangeLog
automake.in
tests/Makefile.am
tests/Makefile.in
tests/cond14.test [new file with mode: 0755]
tests/cond15.test [new file with mode: 0755]

index 64049ae..76ae5ce 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2001-08-08  Richard Boulton <richard@tartarus.org>
+
+       * automake.in (file_contents_internal): if a rule is conditionally
+       defined, define the standard automake definition for it for those
+       conditions which are not conditionally defined.
+       (invert_conditions): New function: invert a list of conditionals.
+
+       * tests/cond14.test: New file.
+       * tests/cond15.test: New file.
+       * tests/Makefile.am (TESTS): Added cond14.test and cond15.test.
+
 2001-08-05  Tom Tromey  <tromey@redhat.com>
 
        * tests/Makefile.am (TESTS): Added dejagnu2.test.
index dde18f5..a49d9a7 100755 (executable)
@@ -5991,6 +5991,31 @@ sub variable_conditions_reduce
     return @ret;
 }
 
+# @CONDS
+# invert_conditions (@CONDS)
+# --------------------------
+# Invert a list of conditionals.  Returns a set of conditionals which
+# are never true for any of the input conditionals, and when taken
+# together with the input conditionals cover all possible cases.
+# 
+# For example: invert_conditions("A_TRUE B_TRUE", "A_FALSE B_FALSE") will
+# return ("A_FALSE B_TRUE", "A_TRUE B_FALSE")
+sub invert_conditions
+{
+    my (@conds) = @_;
+
+    my @notconds = ();
+    foreach my $cond (@conds)
+    {
+       foreach my $perm (variable_conditions_permutations (split(' ', $cond)))
+       {
+           push @notconds, $perm
+                   if ! conditional_is_redundant ($perm, @conds);
+       }
+    }
+    return variable_conditions_reduce (@notconds);
+}
+
 # Return a list of permutations of a conditional string.
 sub variable_conditions_permutations
 {
@@ -6919,14 +6944,42 @@ sub file_contents_internal ($$%)
                }
              else
                {
-                 # Free lance dependency.  Output the rule for all the
+                 # Free-lance dependency.  Output the rule for all the
                  # targets instead of one by one.
-                 if (!defined $targets{$targets}
-                     && $cond ne 'FALSE')
+
+                 # Work out all the conditions for which the target hasn't
+                 # been defined
+                 my @undefined_conds;
+                 if (defined $target_conditional{$targets})
                    {
-                     $paragraph =~ s/^/make_condition (@cond_stack)/gme;
-                     $result_rules .= "$spacing$comment$paragraph\n"
-                         if rule_define ($targets, $is_am, $cond, $file);
+                     my @defined_conds = keys %{$target_conditional{$targets}};
+                     @undefined_conds = invert_conditions(@defined_conds);
+                   }
+                 else
+                   {
+                     if (defined $targets{$targets})
+                       {
+                         # No conditions for which target hasn't been defined
+                         @undefined_conds = ();
+                       }
+                     else
+                       {
+                         # Target hasn't been defined for any conditions
+                         @undefined_conds = ("");
+                       }
+                   }
+
+                 if ($cond ne 'FALSE')
+                   {
+                     my $undefined_cond;
+                     for $undefined_cond (@undefined_conds)
+                     {
+                         my $condparagraph = $paragraph;
+                         $condparagraph =~ s/^/make_condition (@cond_stack, $undefined_cond)/gme;
+                         $result_rules .= "$spacing$comment$condparagraph\n"
+                             if rule_define ($targets, $is_am,
+                                             "$cond $undefined_cond", $file);
+                     }
                    }
                  $comment = $spacing = '';
                  last;
index 42234dd..174cf3a 100644 (file)
@@ -67,6 +67,8 @@ cond10.test \
 cond11.test \
 cond12.test \
 cond13.test \
+cond14.test \
+cond15.test \
 cond16.test \
 cond17.test \
 condincl.test \
index 78d13b6..11c605d 100644 (file)
@@ -135,6 +135,8 @@ cond10.test \
 cond11.test \
 cond12.test \
 cond13.test \
+cond14.test \
+cond15.test \
 cond16.test \
 cond17.test \
 condincl.test \
@@ -168,6 +170,7 @@ dash.test \
 defun.test \
 defun2.test \
 dejagnu.test \
+dejagnu2.test \
 depacl.test \
 depacl2.test \
 depcomp.test \
diff --git a/tests/cond14.test b/tests/cond14.test
new file mode 100755 (executable)
index 0000000..253874e
--- /dev/null
@@ -0,0 +1,36 @@
+#! /bin/sh
+
+# Test for bug in conditionals.
+# Report from Robert Boehne
+
+. $srcdir/defs || exit 1
+
+cat >> configure.in << 'END'
+AC_PROG_CC
+AM_CONDITIONAL(COND1, true)
+END
+
+cat > Makefile.am << 'END'
+
+if COND1
+BUILD_helldl = helldl
+helldl_SOURCES = dlmain.c
+helldl_DEPENDENCIES = libhello.la
+else
+BUILD_helldl = 
+bin_SCRIPTS = helldl
+helldl$(EXEEXT):
+       rm -f $@
+       echo '#! /bin/sh' > $@
+       echo '-dlopen is unsupported' >> $@
+       chmod +x $@
+endif
+
+bin_PROGRAMS = $(BUILD_helldl)
+END
+
+$ACLOCAL || exit 1
+$AUTOMAKE || exit 1
+
+num=`grep 'helldl$(EXEEXT):' Makefile.in | wc -l`
+test $num -eq 2
diff --git a/tests/cond15.test b/tests/cond15.test
new file mode 100755 (executable)
index 0000000..abc764f
--- /dev/null
@@ -0,0 +1,45 @@
+#! /bin/sh
+
+# Regression test for conditionally defined overriding of automatic rules.
+
+. $srcdir/defs || exit 1
+
+cat >> configure.in << 'END'
+AC_PROG_CC
+AM_CONDITIONAL(COND1, true)
+AM_CONDITIONAL(COND2, true)
+END
+
+cat > Makefile.am << 'END'
+
+if COND1
+if COND2
+bin_SCRIPTS = helldl
+helldl$(EXEEXT):
+       rm -f $@
+       echo '#! /bin/sh' > $@
+       echo '-dlopen is unsupported' >> $@
+       chmod +x $@
+endif
+else
+if COND2
+else
+bin_SCRIPTS = helldl
+helldl$(EXEEXT):
+       rm -f $@
+       echo '#! /bin/sh' > $@
+       echo '-dlopen is unsupported' >> $@
+       chmod +x $@
+endif
+endif
+
+bin_PROGRAMS = helldl
+END
+
+$ACLOCAL || exit 1
+$AUTOMAKE || exit 1
+
+num1=`grep 'helldl$(EXEEXT):' Makefile.in | wc -l`
+num2=`grep '@COND1_FALSE@@COND2_TRUE@helldl$(EXEEXT):' Makefile.in | wc -l`
+test $num1 -eq 4 || exit 1
+test $num2 -eq 1 || exit 1