aboutsummaryrefslogtreecommitdiff
path: root/libtool-ldflags
blob: 5ade7a2b60206afbb8f970a9bb60fd2741ad603b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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"