* automake.in (define_per_target_linker_variable): New function.
(handle_programs, handle_ltlibraries): Use it.
(%link_languages): New map.
(register_language): Fill it.
* lib/am/ltlibrary.am (%LTLIBRARY%): Do not append
$(%XLTLIBRARY%_LDFLAGS) to the command, this is now done by
define_per_target_linker_variable if needed.
* lib/am/program.am (%PROGRAM%%EXEEXT%): Likewise with
$(%XPROGRAM%_LDFLAGS).
* doc/automake.texi (Program and Library Variables): Mention
AM_LDFLAGS and AM_LIBTOOLFLAGS in the definition of maude_LDFLAGS
and maude_LIBTOOLFLAGS.
* tests/libtool9.test: New file.
* tests/Makefile.am (TESTS): Add it.
* NEWS: Explain the backward incompatibility.
Report from Akim Demaille.
+2005-01-03 Alexandre Duret-Lutz <adl@gnu.org>
+
+ Fix handling of per-target flags in link rules.
+ * automake.in (define_per_target_linker_variable): New function.
+ (handle_programs, handle_ltlibraries): Use it.
+ (%link_languages): New map.
+ (register_language): Fill it.
+ * lib/am/ltlibrary.am (%LTLIBRARY%): Do not append
+ $(%XLTLIBRARY%_LDFLAGS) to the command, this is now done by
+ define_per_target_linker_variable if needed.
+ * lib/am/program.am (%PROGRAM%%EXEEXT%): Likewise with
+ $(%XPROGRAM%_LDFLAGS).
+ * doc/automake.texi (Program and Library Variables): Mention
+ AM_LDFLAGS and AM_LIBTOOLFLAGS in the definition of maude_LDFLAGS
+ and maude_LIBTOOLFLAGS.
+ * tests/libtool9.test: New file.
+ * tests/Makefile.am (TESTS): Add it.
+ * NEWS: Explain the backward incompatibility.
+ Report from Akim Demaille.
+
2005-01-01 Alexandre Duret-Lutz <adl@gnu.org>
* doc/automake.texi (Requirements) <AC_CONFIG_FILES>: Discuss
- aclocal now also supports -Wmumble and -Wno-mumble options.
+ - Per-target flags are now correctly handled in link rules.
+
+ For instance maude_CFLAGS correctly overrides AM_CFLAGS; likewise
+ for maude_LDFLAGS and AM_LDFLAGS. Previous versions bogusly
+ preferred AM_CFLAGS over maude_CFLAGS while linking, and they
+ used both AM_LDFLAGS and maude_LDFLAGS on the same link command.
+
+ The fix for compiler flags (i.e., using maude_CFLAGS instead of
+ AM_CFLAGS) should not hurt any package since that is how _CFLAGS
+ is expected to work (and actually works during compilation).
+
+ However using maude_LDFLAGS "instead of" AM_LDFLAGS rather than
+ "in addition to" breaks backward compatibility with older versions.
+ If your package used both variables, as in
+
+ AM_LDFLAGS = common flags
+ bin_PROGRAMS = a b c
+ a_LDFLAGS = more flags
+ ...
+
+ and assumed *_LDFLAGS would sum up, you should rewrite it as
+
+ AM_LDFLAGS = common flags
+ bin_PROGRAMS = a b c
+ a_LDFLAGS = $(AM_LDFLAGS) more flags
+ ...
+
+ This new behavior of *_LDFLAGS is more coherent with other
+ per-target variables, and the way *_LDFLAGS variables were
+ considered internally.
+
- New targets mandated by GNU Coding Standards:
install-dvi
install-html
# This maps languages names onto objects.
my %languages = ();
+# Maps each linker variable onto a language object.
+my %link_languages = ();
# List of targets we must always output.
# FIXME: Complete, and remove falsely required targets.
# object extension.
my ($one_file, $unxformed, $obj, $where, %transform) = @_;
- my ($linker) = '';
+ my $linker = '';
# No point in continuing if _OBJECTS is defined.
return if reject_var ($one_file . '_OBJECTS',
set_seen ($xname . '_LDFLAGS');
# Determine program to use for link.
- my $xlink;
- if (var ($xname . '_LINK'))
- {
- $xlink = $xname . '_LINK';
- }
- else
- {
- $xlink = $linker ? $linker : 'LINK';
- }
+ my $xlink = &define_per_target_linker_variable ($linker, $xname);
# If the resulting program lies into a subdirectory,
# make sure this directory will exist.
NONLIBTOOL => 0, LIBTOOL => 1);
# Determine program to use for link.
- my $xlink;
- if (var ($xlib . '_LINK'))
- {
- $xlink = $xlib . '_LINK';
- }
- else
- {
- $xlink = $linker ? $linker : 'LINK';
- }
+ my $xlink = &define_per_target_linker_variable ($linker, $xlib);
my $rpathvar = "am_${xlib}_rpath";
my $rpath = "\$($rpathvar)";
# Fill indexes.
$extension_map{$_} = $lang->name foreach @{$lang->extensions};
$languages{$lang->name} = $lang;
+ my $link = $lang->linker;
+ if ($link)
+ {
+ if (exists $link_languages{$link})
+ {
+ prog_error ("`$link' has different definitions in "
+ . $lang->name . " and " . $link_languages{$link}->name)
+ if $lang->link ne $link_languages{$link}->link;
+ }
+ else
+ {
+ $link_languages{$link} = $lang;
+ }
+ }
# Update the pattern of known extensions.
accept_extensions (@{$lang->extensions});
{
my ($lang) = @_;
- my ($var, $value) = ($lang->lder, $lang->ld);
my $libtool_tag = '';
$libtool_tag = '--tag=' . $lang->libtool_tag . ' '
if $lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag};
INTERNAL);
}
+sub define_per_target_linker_variable ($$)
+{
+ my ($linker, $target) = @_;
+
+ # If the user wrote a custom link command, we don't define ours.
+ return "${target}_LINK"
+ if set_seen "${target}_LINK";
+
+ my $xlink = $linker ? $linker : 'LINK';
+
+ my $lang = $link_languages{$xlink};
+ prog_error "Unknown language for linker variable `$xlink'"
+ unless $lang;
+
+ my $link_command = $lang->link;
+ if (var 'LIBTOOL')
+ {
+ my $libtool_tag = '';
+ $libtool_tag = '--tag=' . $lang->libtool_tag . ' '
+ if $lang->libtool_tag && exists $libtool_tags{$lang->libtool_tag};
+
+ $link_command =
+ "\$(LIBTOOL) $libtool_tag\$(AM_LIBTOOLFLAGS) \$(LIBTOOLFLAGS) "
+ . "--mode=link " . $link_command;
+ }
+
+ # Rewrite each occurrence of `AM_$flag' in the link
+ # command into `${derived}_$flag' if it exists.
+ my $orig_command = $link_command;
+ my @flags = (@{$lang->flags}, 'LDFLAGS');
+ push @flags, 'LIBTOOLFLAGS' if var 'LIBTOOL';
+ for my $flag (@flags)
+ {
+ my $val = "${target}_$flag";
+ $link_command =~ s/\(AM_$flag\)/\($val\)/
+ if set_seen ($val);
+ }
+
+ # If the computed command is the same as the generic command, use
+ # the command linker variable.
+ return $lang->linker
+ if $link_command eq $orig_command;
+
+ &define_variable ("${target}_LINK", $link_command, INTERNAL);
+ return "${target}_LINK";
+}
+
################################################################
# &check_trailing_slash ($WHERE, $LINE)
@item maude_LDFLAGS
This variable is used to pass extra flags to the link step of a program
-or a shared library.
+or a shared library. It overrides the global @code{AM_LDFLAGS} variable.
@item maude_LIBTOOLFLAGS
This variable is used to pass extra options to @command{libtool}.
+It overrides the global @code{AM_LIBTOOLFLAGS} variable.
These options are output before @command{libtool}'s @code{--mode=MODE}
option, so they should not be mode-specific options (those belong to
the compiler or linker flags). @xref{Libtool Flags}.
-@set UPDATED 1 January 2005
+@set UPDATED 3 January 2005
@set UPDATED-MONTH January 2005
@set EDITION 1.9a
@set VERSION 1.9a
-@set UPDATED 1 January 2005
+@set UPDATED 3 January 2005
@set UPDATED-MONTH January 2005
@set EDITION 1.9a
@set VERSION 1.9a
## automake - create Makefile.in from Makefile.am
-## Copyright (C) 1994, 1995, 1996, 2003 Free Software Foundation, Inc.
+## Copyright (C) 1994, 1995, 1996, 2003, 2005 Free Software Foundation, Inc.
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
## 02111-1307, USA.
%LTLIBRARY%: $(%XLTLIBRARY%_OBJECTS) $(%XLTLIBRARY%_DEPENDENCIES) %DIRSTAMP%
- $(%XLINK%) %RPATH% $(%XLTLIBRARY%_LDFLAGS) $(%XLTLIBRARY%_OBJECTS) $(%XLTLIBRARY%_LIBADD) $(LIBS)
+ $(%XLINK%) %RPATH% $(%XLTLIBRARY%_OBJECTS) $(%XLTLIBRARY%_LIBADD) $(LIBS)
## automake - create Makefile.in from Makefile.am
-## Copyright (C) 1994, 1995, 1996, 1997, 2001, 2003
+## Copyright (C) 1994, 1995, 1996, 1997, 2001, 2003, 2005
## Free Software Foundation, Inc.
## This program is free software; you can redistribute it and/or modify
## Or maybe not... sadly, incremental linkers are rarer than losing
## systems.
@rm -f %PROGRAM%%EXEEXT%
- $(%XLINK%) $(%XPROGRAM%_LDFLAGS) $(%XPROGRAM%_OBJECTS) $(%XPROGRAM%_LDADD) $(LIBS)
+ $(%XLINK%) $(%XPROGRAM%_OBJECTS) $(%XPROGRAM%_LDADD) $(LIBS)
libtool6.test \
libtool7.test \
libtool8.test \
+libtool9.test \
license.test \
link_c_cxx.test \
link_dist.test \
libtool6.test \
libtool7.test \
libtool8.test \
+libtool9.test \
license.test \
link_c_cxx.test \
link_dist.test \
--- /dev/null
+#! /bin/sh
+# Copyright (C) 2005 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 xxx_LINK is defined for each target that requires specific
+# flags.
+# Quite similar to libtool7.test, using AM_LDFLAGS in addition to xxx_LDFLAGS.
+
+required='libtoolize gcc'
+. ./defs || exit 1
+
+set -e
+
+cat >> configure.in << 'END'
+AC_PROG_CC
+AM_PROG_CC_C_O
+AC_LIBTOOL_DLOPEN
+AM_PROG_LIBTOOL
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+AM_LDFLAGS = -module
+lib_LTLIBRARIES = libmod1.la mod2.la
+libmod1_la_SOURCES = mod1.c
+libmod1_la_LDFLAGS =
+libmod1_la_LIBADD = -dlopen mod2.la
+mod2_la_SOURCES = mod2.c
+
+bin_PROGRAMS = prg prg2
+prg_SOURCES = prg.c
+prg_LDADD = -dlopen libmod1.la -dlpreopen mod2.la
+prg_CPPFLAGS = -DXYZ=1
+prg2_SOURCES = prg.c
+prg2_CFLAGS =
+
+print:
+ @echo 1BEG: $(prg_DEPENDENCIES) :END1
+ @echo 2BEG: $(libmod1_la_DEPENDENCIES) :END2
+ @echo 3BEG: $(libmod1_la_LINK) :END3
+ @echo 4BEG: $(mod2_la_LINK) :END4
+ @echo 5BEG: $(prg_LINK) :END5
+ @echo 6BEG: $(prg2_LINK) :END6
+
+END
+
+mkdir liba
+
+cat > mod1.c << 'END'
+int
+mod1 ()
+{
+ return 1;
+}
+END
+
+cat > mod2.c << 'END'
+int
+mod2 ()
+{
+ return 2;
+}
+END
+
+cat > prg.c << 'END'
+int
+main ()
+{
+ return 0;
+}
+END
+
+libtoolize --force --copy
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing --copy
+
+./configure
+env LDFLAGS=ldflags AM_LDFLAGS=am_ldflags libmod1_la_LDFLAGS=lm1_la_ldflags \
+ CFLAGS=cflags AM_CFLAGS=am_cflags prg2_CFLAGS=prg2_cflags \
+ $MAKE -e print >output 2>&1
+cat output
+grep '1BEG: libmod1.la mod2.la :END1' output
+grep '2BEG: mod2.la :END2' output
+grep '3BEG:.* am_cflags cflags .*lm1_la_ldflags ldflags.* :END3' output
+grep '3BEG: .*am_ldflags.* :END3' output && exit 1
+grep '4BEG: :END4' output
+grep '5BEG: :END5' output
+grep '6BEG:.* prg2_cflags cflags .*am_ldflags ldflags.* :END6' output
+grep '6BEG: .*am_cflags.* :END6' output && exit 1
+$MAKE