+2002-05-31 Richard Boulton <richard@tartarus.org>
+
+ Fix PR automake/326:
+ * automake.in (define_objects_from_sources): Calculate the result in
+ all conditions before passing this to subobjname to pick a name to
+ store the result in.
+ (subobjname): Expect a list of condition/value pairs as input.
+ Combine this list and use it as the key to determine the variable name.
+ * test/cond22.test: New file.
+ * tests/Makefile.am (TESTS): Add cond21.test
+
2002-05-30 Paul Eggert <eggert@twinsun.com>
* lib/am/distdir.am (distdir): Don't assume that 'grep -F' works;
my %require_file_found = ();
# This keeps track of all variables defined by subobjname.
-# The key is the variable _content_, and the value is the variable name.
+# The value stored is the variable names.
+# The key has the form "(COND1)VAL1(COND2)VAL2..." where VAL1 and VAL2
+# are the values of the variable for condition COND1 and COND2.
my %subobjvar = ();
# This hash records helper variables used to implement '+=' in conditionals.
return @result;
}
-# $BOOL
+# ($LINKER, $OBJVAR)
# define_objects_from_sources ($VAR, $OBJVAR, $NODEFINE, $ONE_FILE,
# $OBJ, $PARENT, $TOPPARENT)
# ---------------------------------------------------------------------
$vars_scanned{$var} = 1;
my $needlinker = "";
+ my @allresults = ();
foreach my $cond (variable_conditions ($var))
{
my @result;
$needlinker = "true" if @transformed;
}
}
-
- # Find an name for the variable, unless imposed.
- $objvar = subobjname (@result) unless defined $objvar;
- # Define _OBJECTS conditionally.
- define_pretty_variable ($objvar, $cond, (@result))
- unless $nodefine;
+ push (@allresults, [$cond, @result]);
+ }
+ # Find a name for the variable, unless imposed.
+ $objvar = subobjname (@allresults) unless defined $objvar;
+ # Define _OBJECTS conditionally
+ unless ($nodefine)
+ {
+ foreach my $pair (@allresults)
+ {
+ my ($cond, @result) = @$pair;
+ define_pretty_variable ($objvar, $cond, @result);
+ }
}
delete $vars_scanned{$var};
# $VARNAME
-# subobjname (@OBJECTS)
-# ---------------------
-# Return a name for an object variable that holds @OBJECTS.
+# subobjname (@DEFINITIONS)
+# -------------------------
+# Return a name for an object variable that with definitions @DEFINITIONS.
+# @DEFINITIONS is a list of pair [$COND, @OBJECTS].
#
-# If we already have an object variable containing @OBJECTS, reuse it.
+# If we already have an object variable containing @DEFINITIONS, reuse it.
# This way, we avoid combinatorial explosion of the generated
# variables. Especially, in a Makefile such as:
#
# small C programs, all testing the same set of source files.
sub subobjname (@)
{
- my $key = "@_";
+ my $key = '';
+ foreach my $pair (@_)
+ {
+ my ($cond, @values) = @$pair;
+ $key .= "($cond)@values";
+ }
return $subobjvar{$key} if exists $subobjvar{$key};
--- /dev/null
+#! /bin/sh
+
+# Regression test for bug when sources listed in conditional.
+# Report from Richard Boulton. PR/326.
+
+. $srcdir/defs || exit 1
+
+set -e
+
+cat >> configure.in << 'END'
+AC_PROG_CC
+AM_CONDITIONAL(ONE, true)
+AM_CONDITIONAL(TWO, false)
+AM_CONDITIONAL(THREE, false)
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+bin_PROGRAMS = targ
+
+if ONE
+SONE = one.c
+endif
+
+if TWO
+STWO =
+else
+STWO = two.c
+endif
+
+if THREE
+STHREE =
+else
+STHREE = three.c
+endif
+
+if THREE
+STHREE2 =
+else
+STHREE2 = three2.c
+endif
+
+targ_SOURCES = $(SONE) $(STWO) $(STHREE) $(STHREE2)
+
+echo:
+ echo BEG: $(targ_OBJECTS) :END;
+END
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+./configure
+OBJEXT=oo $MAKE -e echo > output
+cat output
+$FGREP 'BEG: one.oo two.oo three.oo three2.oo :END' output