This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PATCH: LDFLAGS handling in V3
- From: Mark Mitchell <mark at codesourcery dot com>
- To: Alexandre Oliva <aoliva at redhat dot com>
- Cc: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Fri, 30 Dec 2005 22:17:54 -0800
- Subject: Re: PATCH: LDFLAGS handling in V3
- References: <200507272135.j6RLZHH2024117@sethra.codesourcery.com> <or8xzrgaze.fsf@livre.redhat.lsd.ic.unicamp.br> <42E806F0.4050704@codesourcery.com> <42E81D58.5000108@codesourcery.com> <or64uuai3x.fsf@livre.redhat.lsd.ic.unicamp.br> <42E927F8.2090004@codesourcery.com> <orpst29142.fsf@livre.redhat.lsd.ic.unicamp.br> <42E98339.2070803@codesourcery.com> <42E9AD58.5020809@codesourcery.com> <orbr25qcci.fsf@livre.oliva.athome.lsd.ic.unicamp.br> <43461472.2030801@codesourcery.com> <orzmpl2zxv.fsf@livre.oliva.athome.lsd.ic.unicamp.br>
Alexandre Oliva wrote:
> Perhaps use -fsysroot instead, and arrange for your script to prefix
> only -f* flags with -Xcompiler, as opposed to handling everything
> except what you know to be special for libtool? Or maybe extend to
> --* as well, since libtool doesn't handle double-dash arguments?
>
>>Do you want me to try to skip the -Xcompiler for the options you list?
>
> Definitely. Not doing so would certainly break things.
I'm making a pass over my patch queue, trying to get things merged in.
So, I came back to this patch.
To refresh your memory, the point of this patch is that, at present,
putting "--sysroot=..." in LDFLAGS_FOR_TARGET at the top level does not
work, because libtool turns that into -Wl,--sysroot, which means the
driver never sees it, which means that it does not find things like
crt1.o. We agreed that LDFLAGS_FOR_TARGET was meant to be options to
the driver, and that, therefore, we needed to specifically mark these
options with -Xcompiler when passing them to libtool.
I believe this version addresses the issues you spotted in your review:
http://gcc.gnu.org/ml/libstdc++/2005-10/msg00026.html
Tested on x86_64-unknown-linux-gnu; OK?
Thanks,
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
(650) 331-3385 x713
2005-12-30 Mark Mitchell <mark@codesourcery.com>
* libtool-ldflags: New script.
2005-12-30 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
===================================================================
--- libtool-ldflags (revision 0)
+++ libtool-ldflags (revision 0)
@@ -0,0 +1,97 @@
+#! /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
+ case $arg in
+ -f*|--*)
+ # Libtool does not ascribe any special meaning options
+ # that begin with -f or with a double-dash. So, it will
+ # think these options are linker options, and prefix them
+ # with "-Wl,". Then, the compiler driver will ignore the
+ # options. So, we prefix these options with -Xcompiler to
+ # make clear to libtool that they are in fact compiler
+ # options.
+ result="$result -Xcompiler"
+ ;;
+ *)
+ # We do not want to add -Xcompiler to other options because
+ # that would prevent libtool itself from recognizing them.
+ ;;
+ esac
+
+ # 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 any embedded single quotes.
+ case $arg in
+ *"'"*)
+ # The following command creates the script:
+ # 1s,^X,,;s|'|'"'"'|g
+ # which removes a leading X, and then quotes and embedded single
+ # quotes.
+ sed_script="1s,^X,,;s|'|'\"'\"'|g"
+ # Add a leading "X" so that if $arg starts with a dash,
+ # the echo command will not try to interpret the argument
+ # as a command-line option.
+ arg="X$arg"
+ # Generate the quoted string.
+ quoted_arg=`echo "$arg" | sed -e "$sed_script"`
+ ;;
+ *)
+ quoted_arg=$arg
+ ;;
+ esac
+ # Surround the entire argument with single quotes.
+ quoted_arg="'"$quoted_arg"'"
+
+ # Add it to the string.
+ result="$result $quoted_arg"
+done
+
+# Output the string we have built up.
+echo "$result"
Property changes on: libtool-ldflags
___________________________________________________________________
Name: svn:executable
+ *
Index: libstdc++-v3/src/Makefile.am
===================================================================
--- libstdc++-v3/src/Makefile.am (revision 109078)
+++ libstdc++-v3/src/Makefile.am (working copy)
@@ -226,6 +226,8 @@ AM_CXXFLAGS = \
LTCXXCOMPILE = $(LIBTOOL) --tag CXX --mode=compile $(CXX) $(INCLUDES) \
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(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
@@ -233,7 +235,7 @@ LTCXXCOMPILE = $(LIBTOOL) --tag CXX --mo
# 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 $@
+ $(OPT_LDFLAGS) $(SECTION_LDFLAGS) $(AM_CXXFLAGS) $(LTLDFLAGS) -o $@
# Added bits to build debug library.
Index: libstdc++-v3/libsupc++/Makefile.am
===================================================================
--- libstdc++-v3/libsupc++/Makefile.am (revision 109078)
+++ libstdc++-v3/libsupc++/Makefile.am (working copy)
@@ -139,6 +139,8 @@ LTCXXCOMPILE = $(LIBTOOL) --tag CXX --ta
--mode=compile $(CXX) $(TOPLEVEL_INCLUDES) \
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(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
@@ -147,7 +149,7 @@ LTCXXCOMPILE = $(LIBTOOL) --tag CXX --ta
# compilation driver.
CXXLINK = $(LIBTOOL) --tag CXX --tag disable-shared \
--mode=link $(CXX) \
- $(OPT_LDFLAGS) $(SECTION_LDFLAGS) $(AM_CXXFLAGS) $(LDFLAGS) -o $@
+ $(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.