Home | History | Annotate | Line # | Download | only in dist
libtool-ldflags revision 1.1.1.1
      1  1.1  mrg #! /bin/sh
      2  1.1  mrg 
      3  1.1  mrg # Script to translate LDFLAGS into a form suitable for use with libtool.
      4  1.1  mrg 
      5  1.1  mrg # Copyright (C) 2005 Free Software Foundation, Inc.
      6  1.1  mrg #
      7  1.1  mrg # This file is free software; you can redistribute it and/or modify
      8  1.1  mrg # it under the terms of the GNU General Public License as published by
      9  1.1  mrg # the Free Software Foundation; either version 2 of the License, or
     10  1.1  mrg # (at your option) any later version.
     11  1.1  mrg # 
     12  1.1  mrg # This program is distributed in the hope that it will be useful,
     13  1.1  mrg # but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  1.1  mrg # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15  1.1  mrg # GNU General Public License for more details.
     16  1.1  mrg # 
     17  1.1  mrg # You should have received a copy of the GNU General Public License
     18  1.1  mrg # along with this program; if not, write to the Free Software
     19  1.1  mrg # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
     20  1.1  mrg # MA 02110-1301, USA. 
     21  1.1  mrg 
     22  1.1  mrg # Contributed by CodeSourcery, LLC.
     23  1.1  mrg 
     24  1.1  mrg # This script is designed to be used from a Makefile that uses libtool
     25  1.1  mrg # to build libraries as follows: 
     26  1.1  mrg #
     27  1.1  mrg #   LTLDFLAGS = $(shell libtool-ldflags $(LDFLAGS))
     28  1.1  mrg #
     29  1.1  mrg # Then, use (LTLDFLAGS) in place of $(LDFLAGS) in your link line.
     30  1.1  mrg 
     31  1.1  mrg # The output of the script.  This string is built up as we process the
     32  1.1  mrg # arguments.
     33  1.1  mrg result=
     34  1.1  mrg prev_arg=
     35  1.1  mrg 
     36  1.1  mrg for arg
     37  1.1  mrg do
     38  1.1  mrg     case $arg in
     39  1.1  mrg 	-f*|--*)
     40  1.1  mrg 	    # Libtool does not ascribe any special meaning options
     41  1.1  mrg 	    # that begin with -f or with a double-dash.  So, it will
     42  1.1  mrg 	    # think these options are linker options, and prefix them
     43  1.1  mrg 	    # with "-Wl,".  Then, the compiler driver will ignore the
     44  1.1  mrg 	    # options.  So, we prefix these options with -Xcompiler to
     45  1.1  mrg 	    # make clear to libtool that they are in fact compiler
     46  1.1  mrg 	    # options.
     47  1.1  mrg 	    case $prev_arg in
     48  1.1  mrg 		-Xpreprocessor|-Xcompiler|-Xlinker)
     49  1.1  mrg 		    # This option is already prefixed; don't prefix it again.
     50  1.1  mrg 		    ;;
     51  1.1  mrg 		*)
     52  1.1  mrg 		    result="$result -Xcompiler"
     53  1.1  mrg 		    ;;
     54  1.1  mrg 	    esac
     55  1.1  mrg 	    ;;
     56  1.1  mrg 	*)
     57  1.1  mrg 	    # We do not want to add -Xcompiler to other options because
     58  1.1  mrg 	    # that would prevent libtool itself from recognizing them.
     59  1.1  mrg 	    ;;
     60  1.1  mrg     esac
     61  1.1  mrg     prev_arg=$arg
     62  1.1  mrg 
     63  1.1  mrg     # If $(LDFLAGS) is (say):
     64  1.1  mrg     #   a "b'c d" e
     65  1.1  mrg     # then the user expects that:
     66  1.1  mrg     #   $(LD) $(LDFLAGS)
     67  1.1  mrg     # will pass three arguments to $(LD):
     68  1.1  mrg     #   1) a
     69  1.1  mrg     #   2) b'c d
     70  1.1  mrg     #   3) e
     71  1.1  mrg     # We must ensure, therefore, that the arguments are appropriately
     72  1.1  mrg     # quoted so that using:
     73  1.1  mrg     #   libtool --mode=link ... $(LTLDFLAGS)
     74  1.1  mrg     # will result in the same number of arguments being passed to
     75  1.1  mrg     # libtool.   In other words, when this script was invoked, the shell 
     76  1.1  mrg     # removed one level of quoting, present in $(LDFLAGS); we have to put 
     77  1.1  mrg     # it back.
     78  1.1  mrg 
     79  1.1  mrg     # Quote any embedded single quotes.
     80  1.1  mrg     case $arg in
     81  1.1  mrg 	*"'"*)
     82  1.1  mrg 	    # The following command creates the script:
     83  1.1  mrg 	    #   1s,^X,,;s|'|'"'"'|g
     84  1.1  mrg 	    # which removes a leading X, and then quotes and embedded single
     85  1.1  mrg 	    # quotes.
     86  1.1  mrg 	    sed_script="1s,^X,,;s|'|'\"'\"'|g"
     87  1.1  mrg 	    # Add a leading "X" so that if $arg starts with a dash,
     88  1.1  mrg 	    # the echo command will not try to interpret the argument
     89  1.1  mrg 	    # as a command-line option.
     90  1.1  mrg 	    arg="X$arg"
     91  1.1  mrg 	    # Generate the quoted string.
     92  1.1  mrg 	    quoted_arg=`echo "$arg" | sed -e "$sed_script"`
     93  1.1  mrg 	    ;;
     94  1.1  mrg 	*)
     95  1.1  mrg 	    quoted_arg=$arg
     96  1.1  mrg 	    ;;
     97  1.1  mrg     esac
     98  1.1  mrg     # Surround the entire argument with single quotes.
     99  1.1  mrg     quoted_arg="'"$quoted_arg"'" 
    100  1.1  mrg 
    101  1.1  mrg     # Add it to the string.
    102  1.1  mrg     result="$result $quoted_arg"
    103  1.1  mrg done
    104  1.1  mrg 
    105  1.1  mrg # Output the string we have built up.
    106  1.1  mrg echo "$result"
    107