[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
FYI: rewrite &handle_lib_objects using &transform_variable_recursively
From: |
Alexandre Duret-Lutz |
Subject: |
FYI: rewrite &handle_lib_objects using &transform_variable_recursively |
Date: |
Sun, 02 Feb 2003 00:17:04 +0100 |
User-agent: |
Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.2 (i386-pc-linux-gnu) |
I'm installing this on HEAD. One more step toward the
eradication of A::DC::permutations.
2003-02-01 Alexandre Duret-Lutz <address@hidden>
* 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.
Index: NEWS
===================================================================
RCS file: /cvs/automake/automake/NEWS,v
retrieving revision 1.202
diff -u -r1.202 NEWS
--- NEWS 28 Jan 2003 23:24:25 -0000 1.202
+++ NEWS 1 Feb 2003 23:11:05 -0000
@@ -18,8 +18,10 @@
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
@@ -27,6 +29,8 @@
if COND2
bin_PROGRAMS = a2
endif
+
+ Likewise for _LDADD and _LIBADD variables.
* install-sh now understands --version and --help.
Index: automake.in
===================================================================
RCS file: /cvs/automake/automake/automake.in,v
retrieving revision 1.1423
diff -u -r1.1423 automake.in
--- automake.in 31 Jan 2003 23:40:58 -0000 1.1423
+++ automake.in 1 Feb 2003 23:11:13 -0000
@@ -2921,99 +2921,72 @@
# 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 =~ /address@hidden@$/;
-
- # Automatically handle LIBOBJS and ALLOCA substitutions.
- # Basically this means adding entries to dep_files.
- if ($lsearch =~ /^\@(LT)address@hidden/)
- {
- handle_LIBOBJS ($var, $cond, $1);
- $seen_libobjs = 1;
- push (@dep_list, $lsearch);
- }
- elsif ($lsearch =~ /^\@(LT)address@hidden/)
- {
- handle_ALLOCA ($var, $cond, $1);
- push (@dep_list, $lsearch);
- }
- }
-
- 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);
- }
- }
+ transform_variable_recursively
+ ($var, $xname . '_DEPENDENCIES', 'am__DEPENDENCIES', ! $xname, INTERNAL,
+ # Transformation function, run on each filename.
+ sub {
+ my ($subvar, $val, @cond_stack) = @_;
+
+ 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 !~ /address@hidden@$/)
+ {
+ # 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)address@hidden/)
+ {
+ handle_LIBOBJS ($subvar, TRUE->merge (@cond_stack), $1);
+ $seen_libobjs = 1;
+ return $val;
+ }
+ elsif ($val =~ /^\@(LT)address@hidden/)
+ {
+ handle_ALLOCA ($subvar, TRUE->merge (@cond_stack), $1);
+ return $val;
+ }
+ else
+ {
+ return ();
+ }
+ });
return $seen_libobjs;
}
Index: tests/Makefile.am
===================================================================
RCS file: /cvs/automake/automake/tests/Makefile.am,v
retrieving revision 1.466
diff -u -r1.466 Makefile.am
--- tests/Makefile.am 31 Jan 2003 23:40:58 -0000 1.466
+++ tests/Makefile.am 1 Feb 2003 23:11:13 -0000
@@ -100,6 +100,8 @@
cond28.test \
cond29.test \
cond30.test \
+cond31.test \
+cond32.test \
condd.test \
condinc.test \
condinc2.test \
Index: tests/cond11.test
===================================================================
RCS file: /cvs/automake/automake/tests/cond11.test,v
retrieving revision 1.2
diff -u -r1.2 cond11.test
--- tests/cond11.test 8 Sep 2002 13:07:55 -0000 1.2
+++ tests/cond11.test 1 Feb 2003 23:11:14 -0000
@@ -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 @@
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
-
-#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
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE -e print > stdout
+cat stdout
+grep 'BEG: faz.la :END' stdout
+
+./configure two=yes
+$MAKE -e print > stdout
+cat stdout
+grep 'BEG: :END' stdout
Index: tests/cond29.test
===================================================================
RCS file: /cvs/automake/automake/tests/cond29.test,v
retrieving revision 1.1
diff -u -r1.1 cond29.test
--- tests/cond29.test 28 Jan 2003 23:24:25 -0000 1.1
+++ tests/cond29.test 1 Feb 2003 23:11:14 -0000
@@ -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 @@
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
Index: tests/cond31.test
===================================================================
RCS file: tests/cond31.test
diff -N tests/cond31.test
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/cond31.test 1 Feb 2003 23:11:14 -0000
@@ -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
Index: tests/cond32.test
===================================================================
RCS file: tests/cond32.test
diff -N tests/cond32.test
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/cond32.test 1 Feb 2003 23:11:14 -0000
@@ -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
--
Alexandre Duret-Lutz
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- FYI: rewrite &handle_lib_objects using &transform_variable_recursively,
Alexandre Duret-Lutz <=