automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fix for += in conditionals (condd.test).


From: Alexandre Duret-Lutz
Subject: Fix for += in conditionals (condd.test).
Date: Thu, 02 May 2002 10:40:04 +0200
User-agent: Gnus/5.090006 (Oort Gnus v0.06) Emacs/21.2 (i386-debian-linux-gnu)

This takes care of rewriting

  FOO = foo
  if COND
    FOO += bar
  endif

into

  FOO = foo $(am__append_1)
  @address@hidden = bar

Or  

  if COND1
    FOO = foo1
  else
    FOO = foo2
  endif
  FOO += bar

into

  @address@hidden = foo1 bar
  @address@hidden = foo2 bar

Or a mix of these two cases.


This is half a bug-fix, half a new feature.  
Do you think it should go on branch-1-6?

Index: ChangeLog
===================================================================
RCS file: /cvs/automake/automake/ChangeLog,v
retrieving revision 1.1832
diff -u -r1.1832 ChangeLog
--- ChangeLog   30 Apr 2002 22:13:50 -0000      1.1832
+++ ChangeLog   2 May 2002 08:36:33 -0000
@@ -1,3 +1,18 @@
+2002-05-02  Alexandre Duret-Lutz  <address@hidden>
+
+       Fix for condd.test:
+       * automake.in (%appendvar): New.
+       (initialize_per_input): Clear it.
+       (macro_define): Handle += for variable defined in another condition.
+       * automake.texi (Conditional Sources): Use conditional += in
+       the example.
+       (General Operation, Conditionals): Remove note about broken +=.
+       * tests/cond21.test: New file.
+       * tests/condd.test: Also test conditional append to a _SOURCE
+       variable.  Create missing directories.
+       * tests/Makefile.am (TESTS): Add cond21.test.
+       (XFAILS): Remove condd.test.
+
 2002-04-30  Alexandre Duret-Lutz  <address@hidden>
 
        * lib/am/ltlib.am (clean-%DIR%LTLIBRARIES): Erase so_locations
Index: TODO
===================================================================
RCS file: /cvs/automake/automake/TODO,v
retrieving revision 1.416
diff -u -r1.416 TODO
--- TODO        25 Apr 2002 07:48:32 -0000      1.416
+++ TODO        2 May 2002 08:36:33 -0000
@@ -173,97 +173,6 @@
   stamp-h.in must be in dir with h.in file
   stamp-h must be in dir with output file
 
-* conditionals and macros
-  Our current scheme cause combinatoric explosion.
-
-  In fact, to be honest, I no longer understand very well why we perform
-  such a closure.  I mean, as is, Automake transforms (this is
-  cond3.test)
-
-    | bin_PROGRAMS = targ
-    |
-    | if ONE
-    | SONE = one.c
-    | else
-    | SONE =
-    | endif
-    |
-    | if TWO
-    | STWO = two.c
-    | else
-    | STWO =
-    | endif
-    |
-    | if THREE
-    | STHREE = three.c
-    | else
-    | STHREE =
-    | endif
-    |
-    | targ_SOURCES = $(SONE) $(STWO) $(STHREE)
-
-  into
-
-    | @ONE_FALSE@@THREE_FALSE@@address@hidden = two.$(OBJEXT)
-    | @ONE_FALSE@@THREE_FALSE@@address@hidden =
-    | @ONE_FALSE@@THREE_TRUE@@address@hidden = two.$(OBJEXT) \
-    | @ONE_FALSE@@THREE_TRUE@@TWO_TRUE@ three.$(OBJEXT)
-    | @ONE_FALSE@@THREE_TRUE@@address@hidden = three.$(OBJEXT)
-    | @ONE_TRUE@@THREE_FALSE@@address@hidden = one.$(OBJEXT) \
-    | @ONE_TRUE@@THREE_FALSE@@TWO_TRUE@ two.$(OBJEXT)
-    | @ONE_TRUE@@THREE_FALSE@@address@hidden = one.$(OBJEXT)
-    | @ONE_TRUE@@THREE_TRUE@@address@hidden = one.$(OBJEXT) \
-    | @ONE_TRUE@@THREE_TRUE@@TWO_TRUE@ two.$(OBJEXT) three.$(OBJEXT)
-    | @ONE_TRUE@@THREE_TRUE@@address@hidden = one.$(OBJEXT) \
-    | @ONE_TRUE@@THREE_TRUE@@TWO_FALSE@ three.$(OBJEXT)
-
-  why don't we just output
-
-    | @address@hidden = one.$(OBJEXT)
-    | @address@hidden =
-    |
-    | @address@hidden = two.$(OBJEXT)
-    | @address@hidden =
-    |
-    | @address@hidden = three.$(OBJEXT)
-    | @address@hidden =
-    |
-    | am_targ_OBJECTS = $(am_SONE_OBJECTS) $(am_STWO_OBJECTS) 
$(am_STHREE_OBJECTS)
-
-  which means also, why do we look for the closure of PROGRAMS, instead
-  of just adding $(EXEEXT) to all its components and sub components
-  (i.e., inside sub vars such as $(SONE) above being a sub var of
-  targ_SOURCES)?
-
-
-  Aaaaaaaaaaah!  I think I know... Must be because of `+='.
-
-  Hm... No.  Indeed we transform
-
-    | FOO = foo
-    | if BAR
-    | FOO += BAR
-    | endif
-
-  into
-
-    | @address@hidden = foo bar
-    | @address@hidden = foo
-
-  but this seems good to me too?
-
-    | FOO = foo $(BAR_FOO)
-    | @address@hidden = bar
-    | @address@hidden =
-
-
-* foo=bar
-  if cond
-  foo += joe
-  endif
-  ... this ought to work.  The fix is probably complicated, but might
-  come for free when we rewrite the handling of conditionals.
-
 * `distcheck' and `dist' should depend on `all'
 
 * Add code to generate foo-config script like gnome, gtk
Index: automake.in
===================================================================
RCS file: /cvs/automake/automake/automake.in,v
retrieving revision 1.1294
diff -u -r1.1294 automake.in
--- automake.in 25 Apr 2002 16:47:04 -0000      1.1294
+++ automake.in 2 May 2002 08:36:34 -0000
@@ -608,6 +608,11 @@
 # The key is the variable _content_, and the value is the variable name.
 my %subobjvar = ();
 
+# This hash records helper variables used to implement '+=' in conditionals.
+# Keys have the form "VAR:CONDITIONS".  The value associated to a key is
+# the named of the helper variable used to append to VAR in CONDITIONS.
+my %appendvar = ();
+
 ## --------------------------------- ##
 ## Forward subroutine declarations.  ##
 ## --------------------------------- ##
@@ -746,6 +751,8 @@
     %require_file_found = ();
 
     %subobjvar = ();
+
+    %appendvar = ();
 }
 
 
@@ -5590,6 +5597,18 @@
     my ($var, $cond) = @_;
     foreach my $vcond (keys %{$var_value{$var}})
     {
+       # Note that these rules doesn't consider the following
+       # example as ambiguous.
+       #
+       #   if COND1
+       #     FOO = foo
+       #   endif
+       #   if COND2
+       #     FOO = bar
+       #   endif
+       #
+       # It's up to the user to not define COND1 and COND2
+       # simultaneously.
        my $message;
        if ($vcond eq $cond)
        {
@@ -5649,7 +5668,9 @@
   $value =~ s/\\$//mg
     if $type eq '+' && $var_is_am;
 
-  # Differentiate the first assignment (including with `+=').
+  # Differentiate assignment types.
+
+  # 1. append (+=) to a variable defined for current condition
   if ($type eq '+' && defined $var_value{$var}{$cond})
     {
       if (chomp $var_value{$var}{$cond})
@@ -5664,6 +5685,63 @@
        }
        $var_value{$var}{$cond} .= $value;
     }
+  # 2. append (+=) to a variable defined for *another* condition
+  elsif ($type eq '+' && keys %{$var_value{$var}})
+    {
+      # * Generally, $cond is not TRUE.  For instance:
+      #     FOO = foo
+      #     if COND
+      #       FOO += bar
+      #     endif
+      #   In this case, we declare an helper variable conditionally,
+      #   and append it to FOO:
+      #     FOO = foo $(am__append_1)
+      #     @address@hidden = bar
+      #   Of course if FOO is defined under several conditions, we add
+      #   $(am__append_1) to each definitions.
+      #
+      # * If $cond is TRUE, we don't need the helper variable.  E.g., in
+      #     if COND1
+      #       FOO = foo1
+      #     else
+      #       FOO = foo2
+      #     endif
+      #     FOO += bar
+      #   we can add bar directly to all definition of FOO, and output
+      #     @address@hidden = foo1 bar
+      #     @address@hidden = foo2 bar
+
+      # Do we need an helper variable?
+      if ($cond ne 'TRUE')
+        {
+           # Does the helper variable already exists?
+           my $key = "$var:$cond";
+           if (exists $appendvar{$key})
+             {
+               # Yes, let's simply append to it.
+               $var = $appendvar{$key};
+               $var_is_am = 1;
+             }
+           else
+             {
+               # No, create it.
+               my $num = 1 + keys (%appendvar);
+               my $hvar = "am__append_$num";
+               $appendvar{$key} = $hvar;
+               &macro_define ($hvar, 1, '+', $cond, $value, $where);
+               push @var_list, $hvar;
+               # Now HVAR is to be added to VAR.
+               $value = "\$($hvar)";
+             }
+       }
+
+      # Add VALUE to all definitions of VAR.
+      foreach my $vcond (keys %{$var_value{$var}})
+        {
+           &macro_define ($var, $var_is_am, '+', $vcond, $value, $where);
+       }
+    }
+  # 3. first assignment (=, :=, or +=)
   else
     {
       # The first assignment to a macro sets its location.  Ideally I
Index: automake.texi
===================================================================
RCS file: /cvs/automake/automake/automake.texi,v
retrieving revision 1.274
diff -u -r1.274 automake.texi
--- automake.texi       22 Apr 2002 18:25:05 -0000      1.274
+++ automake.texi       2 May 2002 08:36:35 -0000
@@ -238,10 +238,6 @@
 specified on the left.  Automake will translate the operator into
 an ordinary @samp{=} operator; @samp{+=} will thus work with any make program.
 
-Note that it is only valid to append to a macro in the same conditional
-context as the macro was originally defined. @xref{Conditional Append}, for
-more information.
-
 Automake tries to group comments with adjoining targets and macro
 definitions in an intelligent way.
 @c FIXME: What does this imply practically?
@@ -2015,17 +2011,17 @@
 @samp{EXTRA_} variable, because Automake will examine the contents of
 each variable to construct the complete list of source files.
 
-If your program uses a lot of files, you will probably prefer to use an
-intermediate variable to hold conditional sources.
+If your program uses a lot of files, you will probably prefer a
+conditional @code{+=}.
 
 @example
 bin_PROGRAMS = hello
+hello_SOURCES = hello-common.c
 if LINUX
-hello_cond = hello-linux.c
+hello_cond += hello-linux.c
 else
-hello_cond = hello-generic.c
+hello_cond += hello-generic.c
 endif
-hello_SOURCES = hello-common.c $(hello_cond)
 @end example
 
 @node Conditional Programs,  , Conditional Sources, A Program
@@ -4459,30 +4455,6 @@
 
 @noindent
 Unbalanced conditions are errors.
-
address@hidden Append}
-Conditionals do not interact very smoothly with the append operator.
-In particular, an append must happen in the same conditional context as
-the original assignment.  This means that the following will not work:
-
address@hidden
-DBG = foo
-if DEBUG
-DBG += bar
-endif DEBUG
address@hidden example
-
-The behaviour which is probably desired in this situation can be obtained
-using a temporary variable:
-
address@hidden
-if DEBUG
-TMP_DBG = bar
-endif DEBUG
-DBG = foo $(TMP_DBG)
address@hidden example
-
-This restriction may be lifted in future versions of automake.
 
 Note that conditionals in Automake are not the same as conditionals in
 GNU Make.  Automake conditionals are checked at configure time by the
Index: tests/Makefile.am
===================================================================
RCS file: /cvs/automake/automake/tests/Makefile.am,v
retrieving revision 1.393
diff -u -r1.393 Makefile.am
--- tests/Makefile.am   25 Apr 2002 07:55:03 -0000      1.393
+++ tests/Makefile.am   2 May 2002 08:36:35 -0000
@@ -1,6 +1,6 @@
 ## Process this file with automake to create Makefile.in
 
-XFAIL_TESTS = condd.test subdir5.test auxdir2.test cond17.test
+XFAIL_TESTS = subdir5.test auxdir2.test cond17.test
 
 TESTS =        \
 acinclude.test \
@@ -81,6 +81,7 @@
 cond18.test \
 cond19.test \
 cond20.test \
+cond21.test \
 condd.test \
 condincl.test \
 condincl2.test \
Index: tests/Makefile.in
===================================================================
RCS file: /cvs/automake/automake/tests/Makefile.in,v
retrieving revision 1.510
diff -u -r1.510 Makefile.in
--- tests/Makefile.in   25 Apr 2002 07:55:04 -0000      1.510
+++ tests/Makefile.in   2 May 2002 08:36:35 -0000
@@ -84,7 +84,7 @@
 sysconfdir = @sysconfdir@
 target_alias = @target_alias@
 
-XFAIL_TESTS = condd.test subdir5.test auxdir2.test cond17.test
+XFAIL_TESTS = subdir5.test auxdir2.test cond17.test
 
 TESTS = \
 acinclude.test \
@@ -165,6 +165,7 @@
 cond18.test \
 cond19.test \
 cond20.test \
+cond21.test \
 condd.test \
 condincl.test \
 condincl2.test \
Index: tests/cond21.test
===================================================================
RCS file: tests/cond21.test
diff -N tests/cond21.test
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ tests/cond21.test   2 May 2002 08:36:35 -0000
@@ -0,0 +1,65 @@
+#! /bin/sh
+
+# Check for use of = and += in different conditions.
+
+. $srcdir/defs || exit 1
+
+cat >> configure.in << 'END'
+AC_PROG_CC
+AM_CONDITIONAL(COND1, true)
+AM_CONDITIONAL(COND2, true)
+AM_CONDITIONAL(COND3, true)
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+
+FOO = foo
+if COND1
+  FOO += foo1
+else
+  FOO += foon1
+endif
+if COND2
+  FOO += foo2
+else
+  FOO += foon2
+endif
+## Note that we add `foo1b' after `foo2'; however because it is appended in
+## the same condition as `foo1', it should use the same helper variable
+## and thus appear right after `foo1' in the output.
+if COND1
+  FOO += foo1b
+else
+  FOO += foon1b
+endif
+
+if COND1
+if COND2
+  BAR = bar12
+else
+  BAR = bar1n2
+endif
+else
+  BAR = barn1
+endif
+
+BAR += bar
+
+if COND3
+  BAR += bar3
+endif
+
+test:
+       @echo BAR: $(BAR) :BAR
+       @echo FOO: $(FOO) :FOO
+END
+
+set -e
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+./configure
+$MAKE test | fgrep 'BAR: bar12 bar bar3 :BAR'
+$MAKE test | fgrep 'FOO: foo foo1 foo1b foo2 :FOO'
Index: tests/condd.test
===================================================================
RCS file: /cvs/automake/automake/tests/condd.test,v
retrieving revision 1.1
diff -u -r1.1 condd.test
--- tests/condd.test    20 Oct 2001 19:12:34 -0000      1.1
+++ tests/condd.test    2 May 2002 08:36:35 -0000
@@ -5,6 +5,7 @@
 . $srcdir/defs || exit 1
 
 cat >> configure.in << 'END'
+AC_PROG_CC
 AM_CONDITIONAL(COND1, true)
 END
 
@@ -13,7 +14,18 @@
 if COND1
 SUBDIRS += bar
 endif
+
+# Small example from the manual
+bin_PROGRAMS = hello
+hello_SOURCES = hello-common.c
+if COND1
+hello_SOURCES += hello-cond1.c
+else
+hello_SOURCES += hello-generic.c
+endif
 END
+
+mkdir foo bar
 
 $ACLOCAL || exit 1
 $AUTOMAKE

-- 
Alexandre Duret-Lutz




reply via email to

[Prev in Thread] Current Thread [Next in Thread]