This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PATCH: LDFLAGS handling in V3
Mark Mitchell wrote:
Here's a patch.
Daniel points out it's better to actually include the patch...
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
(916) 791-8304
2005-07-28 Mark Mitchell <mark@codesourcery.com>
* libtool-ldflags: New script.
2005-07-27 Mark Mitchell <mark@codesourcery.com>
* src/Makefile.am (LTLDFLAGS): New variable.
(CXXLINK): Use it.
* libsupc++/Makefile.am (LLDFLAGS): New variable.
(CXXLINK): Use it.
* src/Makefile.in: Regenerated.
* libsupc++/Makefile.in: Likewise.
Index: libtool-ldflags
===================================================================
RCS file: libtool-ldflags
diff -N libtool-ldflags
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- libtool-ldflags 28 Jul 2005 20:41:25 -0000
***************
*** 0 ****
--- 1,76 ----
+ #! /bin/sh
+
+ # Script to translate LDFLAGS into a form suitable for use with libtool.
+
+ # Copyright (C) 2005 Free Software Foundation, Inc.
+ #
+ # This file 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 of the License, or
+ # (at your option) any later version.
+ #
+ # This program 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 this program; if not, write to the Free Software
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ # MA 02110-1301, USA.
+
+ # Contributed by CodeSourcery, LLC.
+
+ # This script is designed to be used from a Makefile that uses libtool
+ # to build libraries as follows:
+ #
+ # LTLDFLAGS = $(shell libtool-ldflags $(LDFLAGS))
+ #
+ # Then, use (LTLDFLAGS) in place of $(LDFLAGS) in your link line.
+
+ # The output of the script. This string is built up as we process the
+ # arguments.
+ result=
+
+ for arg; do
+ # Even though the arguments are "linker flags", they are designed
+ # to be passed to the GCC driver. We do not want libtool to
+ # prefix them with "-Wl," when providing them to the driver,
+ # because then the driver will pass them on to the linker without
+ # looking at them. Instead, we want the driver itself to see
+ # these options.
+ result="$result -Xcompiler"
+
+ # If $(LDFLAGS) is (say):
+ # a "b'c d" e
+ # then the user expects that:
+ # $(LD) $(LDFLAGS)
+ # will pass three arguments to $(LD):
+ # 1) a
+ # 2) b'c d
+ # 3) e
+ # We must ensure, therefore, that the arguments are appropriately
+ # quoted so that using:
+ # libtool --mode=link ... $(LTLDFLAGS)
+ # will result in the same number of arguments being passed to
+ # libtool. In other words, when this script was invoked, the shell
+ # removed one level of quoting, present in $(LDFLAGS); we have to put
+ # it back.
+
+ # Quote the argument, using single quotes -- after replacing any
+ # embedded single quotes with:
+ # '"'"'
+ # which will preserve the single quotes in the output.
+
+ # The following command creates the script:
+ # s|'|'"'"'|g
+ sed_script="s|'|'\"'\"'|g"
+
+ # Quote the argument.
+ quoted_arg="'`echo "$arg" | sed -e "$sed_script"`'"
+ # Add it to the string.
+ result="$result $quoted_arg"
+ done
+
+ # Output the string we have built up.
+ echo "$result"
Index: libstdc++-v3/src/Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/src/Makefile.am,v
retrieving revision 1.149
diff -c -5 -p -r1.149 Makefile.am
*** libstdc++-v3/src/Makefile.am 17 Jun 2005 07:33:53 -0000 1.149
--- libstdc++-v3/src/Makefile.am 28 Jul 2005 20:41:25 -0000
*************** AM_CXXFLAGS = \
*** 203,220 ****
# CXXLINK, just after $(LIBTOOL), so that libtool doesn't have to
# attempt to infer which configuration to use
LTCXXCOMPILE = $(LIBTOOL) --tag CXX --mode=compile $(CXX) $(INCLUDES) \
$(AM_CPPFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(AM_CXXFLAGS)
# 3) We'd have a problem when building the shared libstdc++ object if
# the rules automake generates would be used. We cannot allow g++ to
# be used since this would add -lstdc++ to the link line which of
# course is problematic at this point. So, we get the top-level
# directory to configure libstdc++-v3 to use gcc as the C++
# compilation driver.
CXXLINK = $(LIBTOOL) --tag CXX --mode=link $(CXX) \
! $(OPT_LDFLAGS) $(SECTION_LDFLAGS) $(AM_CXXFLAGS) $(LDFLAGS) -o $@
# Added bits to build debug library.
if GLIBCXX_BUILD_DEBUG
all-local: build_debug
--- 203,222 ----
# CXXLINK, just after $(LIBTOOL), so that libtool doesn't have to
# attempt to infer which configuration to use
LTCXXCOMPILE = $(LIBTOOL) --tag CXX --mode=compile $(CXX) $(INCLUDES) \
$(AM_CPPFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(AM_CXXFLAGS)
+ LTLDFLAGS = $(shell $(top_srcdir)/../libtool-ldflags $(LDFLAGS))
+
# 3) We'd have a problem when building the shared libstdc++ object if
# the rules automake generates would be used. We cannot allow g++ to
# be used since this would add -lstdc++ to the link line which of
# course is problematic at this point. So, we get the top-level
# directory to configure libstdc++-v3 to use gcc as the C++
# compilation driver.
CXXLINK = $(LIBTOOL) --tag CXX --mode=link $(CXX) \
! $(OPT_LDFLAGS) $(SECTION_LDFLAGS) $(AM_CXXFLAGS) $(LTLDFLAGS) -o $@
# Added bits to build debug library.
if GLIBCXX_BUILD_DEBUG
all-local: build_debug
Index: libstdc++-v3/libsupc++/Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/libsupc++/Makefile.am,v
retrieving revision 1.51
diff -c -5 -p -r1.51 Makefile.am
*** libstdc++-v3/libsupc++/Makefile.am 28 Jun 2005 19:52:24 -0000 1.51
--- libstdc++-v3/libsupc++/Makefile.am 28 Jul 2005 20:41:25 -0000
*************** cp-demangle.o: cp-demangle.c
*** 136,154 ****
# CXX undo the affect of disable-shared.
LTCXXCOMPILE = $(LIBTOOL) --tag CXX --tag disable-shared \
--mode=compile $(CXX) $(TOPLEVEL_INCLUDES) \
$(AM_CPPFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(AM_CXXFLAGS)
# 3) We'd have a problem when building the shared libstdc++ object if
# the rules automake generates would be used. We cannot allow g++ to
# be used since this would add -lstdc++ to the link line which of
# course is problematic at this point. So, we get the top-level
# directory to configure libstdc++-v3 to use gcc as the C++
# compilation driver.
CXXLINK = $(LIBTOOL) --tag CXX --tag disable-shared \
--mode=link $(CXX) \
! $(OPT_LDFLAGS) $(SECTION_LDFLAGS) $(AM_CXXFLAGS) $(LDFLAGS) -o $@
# We have to have rules modified from the default to counteract SUN make
# prepending each of $(glibcxxinstall_HEADERS) with VPATH below.
install-glibcxxinstallHEADERS: $(glibcxxinstall_HEADERS)
@$(NORMAL_INSTALL)
--- 136,156 ----
# CXX undo the affect of disable-shared.
LTCXXCOMPILE = $(LIBTOOL) --tag CXX --tag disable-shared \
--mode=compile $(CXX) $(TOPLEVEL_INCLUDES) \
$(AM_CPPFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(AM_CXXFLAGS)
+ LTLDFLAGS = $(shell $(top_srcdir)/../libtool-ldflags $(LDFLAGS))
+
# 3) We'd have a problem when building the shared libstdc++ object if
# the rules automake generates would be used. We cannot allow g++ to
# be used since this would add -lstdc++ to the link line which of
# course is problematic at this point. So, we get the top-level
# directory to configure libstdc++-v3 to use gcc as the C++
# compilation driver.
CXXLINK = $(LIBTOOL) --tag CXX --tag disable-shared \
--mode=link $(CXX) \
! $(OPT_LDFLAGS) $(SECTION_LDFLAGS) $(AM_CXXFLAGS) $(LTLDFLAGS) -o $@
# We have to have rules modified from the default to counteract SUN make
# prepending each of $(glibcxxinstall_HEADERS) with VPATH below.
install-glibcxxinstallHEADERS: $(glibcxxinstall_HEADERS)
@$(NORMAL_INSTALL)