From f86b0d37c78d0bcb11f860b95b327ceddeead55f Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Sat, 1 Feb 2003 23:17:22 +0000 Subject: [PATCH] * 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. --- ChangeLog | 14 +++++ NEWS | 8 ++- automake.in | 147 +++++++++++++++++++--------------------------- tests/Makefile.am | 2 + tests/Makefile.in | 2 + tests/cond11.test | 35 +++++++---- tests/cond29.test | 14 +++-- tests/cond31.test | 59 +++++++++++++++++++ tests/cond32.test | 62 +++++++++++++++++++ 9 files changed, 237 insertions(+), 106 deletions(-) create mode 100755 tests/cond31.test create mode 100755 tests/cond32.test diff --git a/ChangeLog b/ChangeLog index 7c70adf9..419931a9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2003-02-01 Alexandre Duret-Lutz + + * 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 * automake.in (handle_lib_objects_cond): Ignore -dlopen and diff --git a/NEWS b/NEWS index 2134ac8c..89a5dc4a 100644 --- 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). diff --git a/automake.in b/automake.in index c6045cb9..0ee9668d 100755 --- a/automake.in +++ b/automake.in @@ -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; } diff --git a/tests/Makefile.am b/tests/Makefile.am index 6a87dcb6..babc0873 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -100,6 +100,8 @@ cond27.test \ cond28.test \ cond29.test \ cond30.test \ +cond31.test \ +cond32.test \ condd.test \ condinc.test \ condinc2.test \ diff --git a/tests/Makefile.in b/tests/Makefile.in index 0e6e1e40..03d94e07 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -194,6 +194,8 @@ cond27.test \ cond28.test \ cond29.test \ cond30.test \ +cond31.test \ +cond32.test \ condd.test \ condinc.test \ condinc2.test \ diff --git a/tests/cond11.test b/tests/cond11.test index 139ba86b..584538cb 100755 --- a/tests/cond11.test +++ b/tests/cond11.test @@ -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. # @@ -24,13 +24,13 @@ . ./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 diff --git a/tests/cond29.test b/tests/cond29.test index 03ba2406..f456ff3d 100755 --- a/tests/cond29.test +++ b/tests/cond29.test @@ -22,9 +22,10 @@ # (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 <>Makefile.am <>configure.in diff --git a/tests/cond31.test b/tests/cond31.test new file mode 100755 index 00000000..b7c8dacf --- /dev/null +++ b/tests/cond31.test @@ -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 index 00000000..47051b7b --- /dev/null +++ b/tests/cond32.test @@ -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 -- 2.43.5