]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
* automake.in (handle_lib_objects): Compute _DEPENDENCIES variables
authorAlexandre Duret-Lutz <adl@gnu.org>
Sat, 1 Feb 2003 23:17:22 +0000 (23:17 +0000)
committerAlexandre Duret-Lutz <adl@gnu.org>
Sat, 1 Feb 2003 23:17:22 +0000 (23:17 +0000)
using transform_variable_recursively instead of
variable_conditions_recursive and variable_value_as_list_recursive
to avoid combinatorial explosion.
(handle_lib_objects_cond): Merge into handle_lib_objects.
* tests/cond11.test: Don't grep internal details in Makefile.in,
run $MAKE to make sure the resulting Makefile runs as expected.
* tests/cond29.test: Also exercise conditional _LDADD.
* tests/cond31.test, tests/cond32.test: New files.
* tests/Makefile.am (TESTS): Add tests/cond31.test and
tests/cond32.test.

ChangeLog
NEWS
automake.in
tests/Makefile.am
tests/Makefile.in
tests/cond11.test
tests/cond29.test
tests/cond31.test [new file with mode: 0755]
tests/cond32.test [new file with mode: 0755]

index 7c70adf95dde900b055b451e9fd0d5b2b703c197..419931a9665bd9b85cb06e471549fca7c359e394 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2003-02-01  Alexandre Duret-Lutz  <adl@gnu.org>
+
+       * automake.in (handle_lib_objects): Compute _DEPENDENCIES variables
+       using transform_variable_recursively instead of
+       variable_conditions_recursive and variable_value_as_list_recursive
+       to avoid combinatorial explosion.
+       (handle_lib_objects_cond): Merge into handle_lib_objects.
+       * tests/cond11.test: Don't grep internal details in Makefile.in,
+       run $MAKE to make sure the resulting Makefile runs as expected.
+       * tests/cond29.test: Also exercise conditional _LDADD.
+       * tests/cond31.test, tests/cond32.test: New files.
+       * tests/Makefile.am (TESTS): Add tests/cond31.test and
+       tests/cond32.test.
+
 2003-01-31  Alexandre Duret-Lutz  <adl@gnu.org>
 
        * automake.in (handle_lib_objects_cond): Ignore -dlopen and
diff --git a/NEWS b/NEWS
index 2134ac8c4435a857cf05ee368880ea2d1188f6b4..89a5dc4a6752a858a525fac23535ad6de3ba85f7 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -18,8 +18,10 @@ New in 1.7a:
     endif
     ...
 
-* It is now allowed to define bin_PROGRAMS (or any *_PROGRAMS variable)
-  in several conditions.  As in
+  Likewise for _LDADD and _LIBADD variables.
+
+* Automake now supports bin_PROGRAMS (or any *_PROGRAMS variable)
+  being defined in several conditions.  As in
 
     if COND1
       bin_PROGRAMS = a1
@@ -28,6 +30,8 @@ New in 1.7a:
       bin_PROGRAMS = a2
     endif
 
+  Likewise for _LDADD and _LIBADD variables.
+
 * install-sh now understands --version and --help.
 
 * Cleanup the definitions of $(distdir) and $(top_distdir).
index c6045cb99e64750f3d13331eca944b6654b785f8..0ee9668d77a27e8ec191448c49e41a8bfdada38b 100755 (executable)
@@ -2921,99 +2921,72 @@ sub handle_source_transform
 # Returns 1 if LIBOBJS seen, 0 otherwise.
 sub handle_lib_objects
 {
-    my ($xname, $var) = @_;
+  my ($xname, $var) = @_;
 
-    prog_error "handle_lib_objects: $var undefined"
-      if ! variable_defined ($var);
-
-    my $ret = 0;
-    # FIXME: Should define am__LDADD_n variables using
-    # traverse_variable_recursively to limit combinatorial explosion.
-    foreach my $cond (variable_conditions_recursive ($var)->conds)
-      {
-       if (&handle_lib_objects_cond ($xname, $var, $cond))
-         {
-           $ret = 1;
-         }
-      }
-    return $ret;
-}
-
-# Subroutine of handle_lib_objects: handle a particular condition.
-sub handle_lib_objects_cond
-{
-  my ($xname, $var, $cond) = @_;
-
-  # We recognize certain things that are commonly put in LIBADD or
-  # LDADD.
-  my @dep_list = ();
+  prog_error "handle_lib_objects: `$var' undefined"
+    if ! variable_defined ($var);
+  prog_error ("handle_lib_objects: unexpected variable name `$var'")
+    unless $var =~ /^(.*)(?:LIB|LD)ADD$/;
+  my $prefix = $1 || 'AM_';
 
   my $seen_libobjs = 0;
   my $flagvar = 0;
 
-  foreach my $lsearch (&variable_value_as_list_recursive ($var, $cond))
-    {
-      if (! $flagvar && $lsearch =~ /^-/)
-       {
-         # Skip -lfoo and -Ldir; these are explicitly allowed.
-         next if $lsearch =~ /^-[lL]/;
-         # Skip -dlopen and -dlpreopen; these are explicitly allowed
-         # for Libtool libraries or programs.  (Actually we are a bit
-         # laxest here since this code also applies to non-libtool
-         # libraries or programs, for which -dlopen and -dlopreopen
-         # are pure non-sence.  Diagnosting this doesn't seems very
-         # important: the developer will quickly get complaints from
-         # the linker.)
-         next if $lsearch =~ /^-dl(?:pre)?open$/;
-
-         prog_error ("unexpected variable name `$var'")
-           unless $var =~ /^(.*)(?:LIB|LD)ADD$/;
-
-         my $prefix = $1 || 'AM_';
-         # Only get this error once.
-         $flagvar = 1;
-         err_var ($var, "linker flags such as `$lsearch' belong in "
-                  . "`${prefix}LDFLAGS");
-       }
-
-      # Assume we have a file of some sort, and push it onto the
-      # dependency list.  Autoconf substitutions are not pushed;
-      # rarely is a new dependency substituted into e.g. foo_LDADD
-      # -- but bad things (e.g. -lX11) are routinely substituted.
-      # Note that LIBOBJS and ALLOCA are exceptions to this rule,
-      # and handled specially below.
-      push (@dep_list, $lsearch)
-       unless $lsearch =~ /^\@.*\@$/;
-
-      # Automatically handle LIBOBJS and ALLOCA substitutions.
-      # Basically this means adding entries to dep_files.
-      if ($lsearch =~ /^\@(LT)?LIBOBJS\@$/)
-       {
-         handle_LIBOBJS ($var, $cond, $1);
-         $seen_libobjs = 1;
-         push (@dep_list, $lsearch);
-       }
-      elsif ($lsearch =~ /^\@(LT)?ALLOCA\@$/)
-       {
-         handle_ALLOCA ($var, $cond, $1);
-         push (@dep_list, $lsearch);
-       }
-    }
+  transform_variable_recursively
+    ($var, $xname . '_DEPENDENCIES', 'am__DEPENDENCIES', ! $xname, INTERNAL,
+     # Transformation function, run on each filename.
+     sub {
+       my ($subvar, $val, @cond_stack) = @_;
 
-  if ($xname ne '')
-    {
-      my $depvar = $xname . '_DEPENDENCIES';
-      if ((condition_ambiguous_p ($depvar, $cond,
-                                   variable_conditions ($depvar)))[0] ne '')
-       {
-         # Note that we've examined this.
-         &examine_variable ($depvar);
-       }
-      else
-       {
-         define_pretty_variable ($depvar, $cond, INTERNAL, @dep_list);
-       }
-    }
+       if ($val =~ /^-/)
+        {
+          # Skip -lfoo and -Ldir silently; these are explicitly allowed.
+          if ($val !~ /^-[lL]/ &&
+              # Skip -dlopen and -dlpreopen; these are explicitly allowed
+              # for Libtool libraries or programs.  (Actually we are a bit
+              # laxest here since this code also applies to non-libtool
+              # libraries or programs, for which -dlopen and -dlopreopen
+              # are pure non-sence.  Diagnosting this doesn't seems very
+              # important: the developer will quickly get complaints from
+              # the linker.)
+              $val !~ /^-dl(?:pre)?open$/ &&
+              # Only get this error once.
+              ! $flagvar)
+            {
+              $flagvar = 1;
+              # FIXME: should display a stack of nested variables
+              # as context when $var != $subvar.
+              err_var ($var, "linker flags such as `$val' belong in "
+                       . "`${prefix}LDFLAGS");
+            }
+          return ();
+        }
+       elsif ($val !~ /^\@.*\@$/)
+        {
+          # Assume we have a file of some sort, and output it into the
+          # dependency variable.  Autoconf substitutions are not output;
+          # rarely is a new dependency substituted into e.g. foo_LDADD
+          # -- but bad things (e.g. -lX11) are routinely substituted.
+          # Note that LIBOBJS and ALLOCA are exceptions to this rule,
+          # and handled specially below.
+          return $val;
+        }
+       elsif ($val =~ /^\@(LT)?LIBOBJS\@$/)
+        {
+          handle_LIBOBJS ($subvar, TRUE->merge (@cond_stack), $1);
+          $seen_libobjs = 1;
+          return $val;
+        }
+       elsif ($val =~ /^\@(LT)?ALLOCA\@$/)
+        {
+          handle_ALLOCA ($subvar, TRUE->merge (@cond_stack), $1);
+          return $val;
+        }
+       else
+        {
+          return ();
+        }
+     });
 
   return $seen_libobjs;
 }
index 6a87dcb65ce2812e8378be2e403aa79c09fefc81..babc0873c9e148ab3e44a7ad68cc4daa7609c0ce 100644 (file)
@@ -100,6 +100,8 @@ cond27.test \
 cond28.test \
 cond29.test \
 cond30.test \
+cond31.test \
+cond32.test \
 condd.test \
 condinc.test \
 condinc2.test \
index 0e6e1e40e16dc5468165b08919cc6e728cda89a4..03d94e07e2ad1cfe8f9903a2688323dfeaa9ff01 100644 (file)
@@ -194,6 +194,8 @@ cond27.test \
 cond28.test \
 cond29.test \
 cond30.test \
+cond31.test \
+cond32.test \
 condd.test \
 condinc.test \
 condinc2.test \
index 139ba86bb93d71c08ca6ee4e58be7be13eebc80e..584538cbc84c393a6b7d9d44cb1f8ad2e9149db3 100755 (executable)
@@ -1,5 +1,5 @@
 #! /bin/sh
-# Copyright (C) 2001, 2002  Free Software Foundation, Inc.
+# Copyright (C) 2001, 2002, 2003  Free Software Foundation, Inc.
 #
 # This file is part of GNU Automake.
 #
 
 . ./defs || exit 1
 
-cat > configure.in << 'END'
-AC_INIT(Makefile.am)
-AM_INIT_AUTOMAKE(foo,0.0)
+set -e
+
+cat >> configure.in << 'END'
 AC_PROG_CC
-AM_CONDITIONAL(USE_A,[test x = x])
-AC_OUTPUT(Makefile)
-AC_SUBST(SUBSTVAR)
+AM_CONDITIONAL([USE_A], [test -z $two])
+AC_SUBST([SUBSTVAR], [bar])
+AC_OUTPUT
 END
 
 cat > Makefile.am << 'END'
@@ -44,16 +44,25 @@ endif
 noinst_PROGRAMS = foo
 foo_SOURCES = foo.c
 LDADD = $(SUBSTVAR) $(foolibs)
+
+print:
+       @echo BEG: $(foo_DEPENDENCIES) :END
 END
 
 : > config.guess
 : > config.sub
 : > compile
 
-$ACLOCAL || exit 1
-$AUTOMAKE || exit 1
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE -e print > stdout
+cat stdout
+grep 'BEG: faz.la :END' stdout
 
-#Should be two dependency setting lines
-count=`grep 'foo_DEPENDENCIES =' Makefile.in | wc -l|sed 's/ //g'`
-test "x$count" = "x2" &&
-  grep '^.USE_A_TRUE.foo_DEPENDENCIES =' Makefile.in
+./configure two=yes
+$MAKE -e print > stdout
+cat stdout
+grep 'BEG: :END' stdout
index 03ba2406322499c090c80e8e51c9588fe28a25ba..f456ff3dac3b7c3a93801342f29b28304fc9f73d 100755 (executable)
 # (This is related to PR/352.)
 #
 # On this test, Automake 1.7.x would compute all 2**22 = 4194304 possible
-# combinations of conditionals, eating all memory, swap, or cpu time it can
-# found.  Although this test wont print `FAIL' if it fails, it will take
-# long enough so it can't go unnoticed.
+# combinations of conditionals (it would do this three times, to define
+# a01_DEPENDENCIES, a02_DEPENDENCIES, and to rewrite bin_PROGRAM), eating
+# all memory, swap, or cpu time it can found.  Although this test won't 
+# print `FAIL' if it fails, it will take long enough so it can't go unnoticed.
 
 . ./defs
 
@@ -32,12 +33,17 @@ set -e
 
 echo AC_PROG_CC >>configure.in
 
-echo 'bin_PROGRAMS = a' > Makefile.am
+cat >Makefile.am <<EOF
+bin_PROGRAMS = a
+a02_LDADD =
+EOF
 
 for i in 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22; do
 cat >>Makefile.am <<EOF
 if C$i
 bin_PROGRAMS += a$i
+a01_LDADD = foo${i}.o
+a02_LDADD += bar${i}.o
 endif C$i
 EOF
 echo "AM_CONDITIONAL([C$i], [:])" >>configure.in
diff --git a/tests/cond31.test b/tests/cond31.test
new file mode 100755 (executable)
index 0000000..b7c8dac
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/sh
+# Copyright (C) 2003  Free Software Foundation, Inc.
+#
+# This file is part of GNU Automake.
+#
+# GNU Automake is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# GNU Automake is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Automake; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+# Make sure we define conditional _DEPENDENCIES correctly.
+
+. ./defs
+
+set -e
+
+cat >>configure.in <<'EOF'
+AC_PROG_CC
+AM_CONDITIONAL(C1, [test -z "$two"])
+AM_CONDITIONAL(C2, [test -n "$two"])
+AC_OUTPUT
+EOF
+
+cat >>Makefile.am <<'EOF'
+bin_PROGRAMS = a
+a_LDADD = c0.o -L/some/where
+if C1
+a_LDADD += c1.o -llibfoo.a
+endif
+if C2
+a_LDADD += c2.o -dlopen c3.la
+endif
+print:
+       @echo BEG: $(a_DEPENDENCIES) :END
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE -e print > stdout
+cat stdout
+grep 'BEG: c0.o c1.o :END' stdout
+
+./configure two=yes
+$MAKE -e print > stdout
+cat stdout
+grep 'BEG: c0.o c2.o c3.la :END' stdout
diff --git a/tests/cond32.test b/tests/cond32.test
new file mode 100755 (executable)
index 0000000..47051b7
--- /dev/null
@@ -0,0 +1,62 @@
+#!/bin/sh
+# Copyright (C) 2003  Free Software Foundation, Inc.
+#
+# This file is part of GNU Automake.
+#
+# GNU Automake is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# GNU Automake is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Automake; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+# Make sure the user can override a conditional _DEPENDENCIES.
+
+. ./defs
+
+set -e
+
+cat >>configure.in <<'EOF'
+AC_PROG_CC
+AM_CONDITIONAL(C1, [test -z "$two"])
+AM_CONDITIONAL(C2, [test -n "$two"])
+AC_SUBST([MYSUB], [foo.o])
+AC_OUTPUT
+EOF
+
+cat >>Makefile.am <<'EOF'
+bin_PROGRAMS = a
+if C1
+a_LDADD = $(MYSUB)
+a_DEPENDENCIES = $(MYSUB) nonsense.a
+# Note that `nonsense.a' is there just to make sure Automake insn't
+# using some self computed a_DEPENDENCIES variable.
+endif
+if C2
+a_LDADD = bar.o
+endif
+print:
+       @echo BEG: $(a_DEPENDENCIES) :END
+EOF
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE -e print > stdout
+cat stdout
+grep 'BEG: foo.o nonsense.a :END' stdout
+
+./configure two=yes
+$MAKE -e print > stdout
+cat stdout
+grep 'BEG: bar.o :END' stdout