head 1.28; access; symbols SHTOOL_2_0_8:1.28 SHTOOL_2_0_7:1.27 SHTOOL_2_0_6:1.26 SHTOOL_2_0_5:1.26 SHTOOL_2_0_4:1.26 SHTOOL_2_0_3:1.25 SHTOOL_2_0_2:1.25 SHTOOL_2_0_1:1.24 SHTOOL_2_0_0:1.24 SHTOOL_2_0b3:1.24 SHTOOL_2_0b2:1.24 SHTOOL_2_0b1:1.24 SHTOOL_1_6:1.18.0.2 SHTOOL_1_6_2:1.18 SHTOOL_1_6_1:1.18 SHTOOL_1_6_0:1.18 SHTOOL_1_5:1.16.0.2 SHTOOL_1_5_4:1.16 SHTOOL_1_5_3:1.16 SHTOOL_1_5_2:1.16 SHTOOL_1_5_1:1.14 SHTOOL_1_5_0:1.14 SHTOOL_1_4_9:1.14 SHTOOL_1_4_8:1.11 SHTOOL_1_4_7:1.10 SHTOOL_1_4_6:1.10 SHTOOL_1_4_5:1.10 SHTOOL_1_4_4:1.10 SHTOOL_1_4_3:1.10 SHTOOL_1_4_2:1.10 SHTOOL_1_4_1:1.10 SHTOOL_1_4_0:1.9 SHTOOL_1_3_3:1.7 SHTOOL_1_3_2:1.5 SHTOOL_1_3_1:1.4 SHTOOL_1_3_0:1.4 SHTOOL_1_2_9:1.1.1.1 SHTOOL_1_2_8:1.1.1.1 SHTOOL_1_2_7:1.1.1.1 SHTOOL_1_2_6:1.1.1.1 SHTOOL_1_2_5:1.1.1.1 SHTOOL_1_2_4:1.1.1.1 SHTOOL_1_2_3:1.1.1.1 SHTOOL_1_2_2:1.1.1.1 SHTOOL_1_2_1:1.1.1.1 SHTOOL_1_2_0:1.1.1.1 SHTOOL_1_1_0:1.1.1.1 RSE:1.1.1; locks; strict; comment @# @; 1.28 date 2008.04.02.20.13.44; author rse; state Exp; branches; next 1.27; commitid eB5Wirx8MdMyDzXs; 1.27 date 2007.05.19.19.09.39; author rse; state Exp; branches; next 1.26; commitid OPUF1UBbllBTwzis; 1.26 date 2006.02.04.09.43.25; author rse; state Exp; branches; next 1.25; commitid oWk7BmnyAitJtfkr; 1.25 date 2005.06.15.08.14.35; author rse; state Exp; branches; next 1.24; 1.24 date 2004.02.12.16.06.27; author rse; state Exp; branches; next 1.23; 1.23 date 2004.01.01.16.54.20; author rse; state Exp; branches; next 1.22; 1.22 date 2003.08.13.14.20.34; author rse; state Exp; branches; next 1.21; 1.21 date 2003.04.29.08.01.01; author rse; state Exp; branches; next 1.20; 1.20 date 2003.04.04.16.36.01; author rse; state Exp; branches; next 1.19; 1.19 date 2003.02.11.13.00.50; author rse; state Exp; branches; next 1.18; 1.18 date 2001.12.31.15.06.04; author rse; state Exp; branches; next 1.17; 1.17 date 2001.09.23.10.58.10; author rse; state Exp; branches; next 1.16; 1.16 date 2001.01.29.14.06.27; author rse; state Exp; branches; next 1.15; 1.15 date 2001.01.17.09.55.11; author rse; state Exp; branches; next 1.14; 1.14 date 2000.04.13.13.59.08; author rse; state Exp; branches; next 1.13; 1.13 date 2000.04.05.16.40.48; author rse; state Exp; branches; next 1.12; 1.12 date 2000.03.24.15.22.51; author rse; state Exp; branches; next 1.11; 1.11 date 2000.03.12.11.12.21; author rse; state Exp; branches; next 1.10; 1.10 date 99.07.06.13.30.48; author rse; state Exp; branches; next 1.9; 1.9 date 99.07.01.15.04.36; author rse; state Exp; branches; next 1.8; 1.8 date 99.07.01.15.02.48; author rse; state Exp; branches; next 1.7; 1.7 date 99.07.01.11.55.08; author rse; state Exp; branches; next 1.6; 1.6 date 99.06.29.17.37.34; author rse; state Exp; branches; next 1.5; 1.5 date 99.06.28.15.18.44; author rse; state Exp; branches; next 1.4; 1.4 date 99.06.17.07.35.08; author rse; state Exp; branches; next 1.3; 1.3 date 99.06.12.14.46.37; author rse; state Exp; branches; next 1.2; 1.2 date 99.06.12.14.08.49; author rse; state Exp; branches; next 1.1; 1.1 date 99.04.29.11.19.50; author rse; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 99.04.29.11.19.50; author rse; state Exp; branches; next ; desc @@ 1.28 log @adjust copyright for year 2008 @ text @## ## slo -- Separate linker options by library class ## Copyright (c) 1998-2008 Ralf S. Engelschall ## ## This file is part of shtool and 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 file 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, ## USA, or contact Ralf S. Engelschall . ## str_tool="slo" str_usage="[-p|--prefix ] -- -L -l [-L -l ...]" arg_spec="1+" opt_spec="p:" opt_alias="p:prefix" opt_p="SLO_" . ./sh.common DIFS="$IFS" # parse out -L and -l options from command line DIRS='' LIBS='' ARGV='' optprev='' for opt do # concatenate with previous option if exists if [ ".$optprev" != . ]; then opt="${optprev}${opt}"; optprev='' fi # remember options for arg if used stand-alone if [ ".$opt" = ".-L" ] || [ ".$opt" = ".-l" ]; then optprev="$opt" continue; fi # split argument into option plus option argument arg="`echo $opt | cut -c3-`" opt="`echo $opt | cut -c1-2`" # store into containers case $opt in -L) DIRS="$DIRS:$arg" ;; -l) LIBS="$LIBS:$arg" ;; *) ARGV="$ARGV $opt" ;; esac done # set linker default directories DIRS_DEFAULT='/lib:/usr/lib' if [ ".$LD_LIBRARY_PATH" != . ]; then DIRS_DEFAULT="$DIRS_DEFAULT:$LD_LIBRARY_PATH" fi # sort options by class DIRS_OBJ='' LIBS_OBJ='' DIRS_PIC='' LIBS_PIC='' DIRS_DSO='' LIBS_DSO='' # for each library... OIFS="$IFS"; IFS=':' for lib in $LIBS; do [ ".$lib" = . ] && continue found='no' found_indefdir='no' found_type='' found_dir='' # for each directory... OIFS2="$IFS"; IFS=":$DIFS" for dir in ${DIRS} switch-to-defdirs ${DIRS_DEFAULT}; do [ ".$dir" = . ] && continue [ ".$dir" = .switch-to-defdirs ] && found_indefdir=yes [ ! -d $dir ] && continue # search the file OIFS3="$IFS"; IFS="$DIFS" for file in '' `cd $dir && env -i /bin/ls lib${lib}.* 2>/dev/null`; do [ ".$file" = . ] && continue case $file in *.so|*.so.[0-9]*|*.sl|*.sl.[0-9]* ) found=yes; found_type=DSO; break ;; *.lo|*.la ) found=yes; found_type=PIC ;; *.a ) if [ ".$found_type" = . ]; then found=yes found_type=OBJ fi ;; esac done IFS="$OIFS3" if [ ".$found" = .yes ]; then found_dir="$dir" break fi done IFS="$OIFS2" if [ ".$found" = .yes ]; then if [ ".$found_indefdir" != .yes ]; then eval "dirlist=\"\${DIRS_${found_type}}:\"" case "$dirlist" in *:$found_dir:* ) ;; * ) eval "DIRS_${found_type}=\"\$DIRS_${found_type}:${found_dir}\"" ;; esac eval "LIBS_${found_type}=\"\$LIBS_${found_type}:$lib\"" else eval "LIBS_${found_type}=\"\$LIBS_${found_type}:$lib\"" fi else LIBS_OBJ="$LIBS_OBJ:$lib" #dirlist="`echo $DIRS $DIRS_DEFAULT | sed -e 's/:/ /g'`" #echo "slo:Warning: library \"$lib\" not found in any of the following dirs:" 2>&1 #echo "slo:Warning: $dirlist" 1>&1 fi done IFS="$OIFS" # also pass-through unused dirs even if it's useless OIFS="$IFS"; IFS=':' for dir in $DIRS; do dirlist="${DIRS_OBJ}:${DIRS_PIC}:${DIRS_DSO}:" case "$dirlist" in *:$dir:* ) ;; * ) DIRS_OBJ="$DIRS_OBJ:$dir" ;; esac done IFS="$OIFS" # reassemble the options but separated by type for type in OBJ PIC DSO; do OIFS="$IFS"; IFS=':' eval "libs=\"\$LIBS_${type}\"" opts='' for lib in $libs; do [ ".$lib" = . ] && continue opts="$opts -l$lib" done eval "LIBS_${type}=\"$opts\"" eval "dirs=\"\$DIRS_${type}\"" opts='' for dir in $dirs; do [ ".$dir" = . ] && continue opts="$opts -L$dir" done eval "DIRS_${type}=\"$opts\"" IFS="$OIFS" done # give back results for var in ARGV DIRS_OBJ LIBS_OBJ DIRS_PIC LIBS_PIC DIRS_DSO LIBS_DSO; do eval "val=\"\$${var}\"" val="`echo $val | sed -e 's/^ *//'`" echo "${opt_p}${var}=\"${val}\"" done shtool_exit 0 ## ## manual page ## =pod =head1 NAME B - B separate linker options by library class =head1 SYNOPSIS B [B<-p>|B<--prefix> I] -- B<-L>I B<-l>I [B<-L>I B<-l>I ...] =head1 DESCRIPTION This command separates the linker options ``B<-L>'' and ``B<-l>'' by library class. It's argument line can actually be an arbitrary command line where those options are contained. B parses these two options only and ignores the remaining contents. The result is a trivial shell script on C which defines six variables containing the ``B<-L>'' and ``B<-l>'' options sorted by class: ``C'' and ``C'' contains the ``B<-L>'' and ``B<-l>'' options of static libraries, ``C'' and ``C'' contains the ``B<-L>'' and ``B<-l>'' options of static libraries containing PIC ("Position Independent Code") and ``C'' and ``C'' contains the ``B<-L>'' and ``B<-l>'' options of shared libraries. The B<-p> option can be used to change the default variable prefix from "C" to I. The intent of this separation is to provide a way between static and shared libraries which is important if one wants to link custom DSOs against libraries, because not all platforms all one to link these DSOs against shared libraries. So one first has to separate out the shared libraries and link the DSO only against the static libraries. One can use this command also to just sort the options. =head1 OPTIONS The following command line options are available. =over 4 =item B<-p>, B<--prefix> I FIXME =item B<-L>I Directory where libraries are searched in. =item B<-l>I Library to search for. =back =head1 EXAMPLE # configure.in LINK_STD="$LDFLAGS $LIBS" eval `shtool slo $LINK_STD` LINK_DSO="$SLO_DIRS_OBJ $SLO_LIBS_OBJ $SLO_DIRS_PIC $SLO_LIBS_PIC" : =head1 HISTORY The B B command was originally written by Ralf S. Engelschall Erse@@engelschall.comE in 1998 for B. It was later taken over into B. =head1 SEE ALSO shtool(1), ld(1). =cut @ 1.27 log @Adjust copyright for year 2007. @ text @d3 1 a3 1 ## Copyright (c) 1998-2007 Ralf S. Engelschall @ 1.26 log @Adjust copyright for year 2006 @ text @d3 1 a3 1 ## Copyright (c) 1998-2006 Ralf S. Engelschall @ 1.25 log @Adjust copyright for year 2005 @ text @d3 1 a3 1 ## Copyright (c) 1998-2005 Ralf S. Engelschall @ 1.24 log @Embedded the command documentation from shtool.pod into the individual sh.xxxx scripts and this way split the large shtool(1) manual page into individual manual pages shtool-xxxx(1). Submitted partly by: Thomas Lotterer @ text @d3 1 a3 1 ## Copyright (c) 1998-2004 Ralf S. Engelschall @ 1.23 log @Bump copyright year for 2004 @ text @a3 1 ## Originally written for Apache d179 85 @ 1.22 log @Replace "[ x -o/-a x ]" constructs with "[ x ] ||/&& [ x ]" and "egrep"/"fgrep" constructs with compatible "grep" or "case" constructs. This way GNU shtool is now more POSIX 1003.1-2001 compliant. Submitted by: Paul Eggert @ text @d3 1 a3 1 ## Copyright (c) 1998-2003 Ralf S. Engelschall @ 1.21 log @Use "env -i /bin/ls" construct in "shtool rotate" and "shtool slo" commands to make sure we have a consistent output not adjusted by some environment variables like LANG, LS_COLORS, LS_OPTIONS, etc. Hint by: Manuel Hendel @ text @d46 1 a46 1 if [ ".$opt" = ".-L" -o ".$opt" = ".-l" ]; then d125 4 a128 3 if [ ".`echo \"$dirlist\" | fgrep :$found_dir:`" = . ]; then eval "DIRS_${found_type}=\"\$DIRS_${found_type}:${found_dir}\"" fi d146 4 a149 3 if [ ".`echo \"$dirlist\" | fgrep :$dir:`" = . ]; then DIRS_OBJ="$DIRS_OBJ:$dir" fi @ 1.20 log @1. Make sure "shtool rotate" does still correctly determine the size of a file if its filename contains whitespaces. 2. Consistently use "/bin/ls" instead of "ls" internally to avoid problems with other "ls" in PATH while still not becoming unportable (because "/bin/ls" is really on every reasonable Unix-style platform the "ls" command). @ text @d94 1 a94 1 for file in '' `cd $dir && /bin/ls lib${lib}.* 2>/dev/null`; do @ 1.19 log @Bump year in copyright messages to cover new year 2003. @ text @d94 1 a94 1 for file in '' `cd $dir && ls lib${lib}.* 2>/dev/null`; do @ 1.18 log @bump copyright years @ text @d3 1 a3 1 ## Copyright (c) 1998-2002 Ralf S. Engelschall @ 1.17 log @*** empty log message *** @ text @d3 1 a3 1 ## Copyright (c) 1998-2001 Ralf S. Engelschall @ 1.16 log @*** empty log message *** @ text @d23 1 a23 1 str_usage="[-p] -- -L -l [-L -l ...]" d26 1 @ 1.15 log @*** empty log message *** @ text @d75 1 a75 1 OIFS="$IFS" IFS=':' d85 1 a85 1 OIFS2="$IFS" IFS=":$DIFS" d92 1 a92 1 OIFS3="$IFS" IFS="$DIFS" d141 1 a141 1 OIFS="$IFS" IFS=':' d152 1 a152 1 OIFS="$IFS" IFS=':' @ 1.14 log @*** empty log message *** @ text @d3 1 a3 1 ## Copyright (c) 1998-2000 Ralf S. Engelschall @ 1.13 log @*** empty log message *** @ text @d44 1 a44 1 # remember options for arg when used stand-alone @ 1.12 log @*** empty log message *** @ text @d23 1 a23 1 str_usage="[-p] -- -L -l [ -L -l ... ]" @ 1.11 log @*** empty log message *** @ text @d23 1 a23 1 str_usage="-- -L -l [ -L -l ... ]" d25 2 a26 1 opt_spec="" d175 1 a175 1 echo "SLO_${var}=\"${val}\"" @ 1.10 log @*** empty log message *** @ text @d3 1 a3 1 ## Copyright (c) 1998-1999 Ralf S. Engelschall @ 1.9 log @*** empty log message *** @ text @d149 1 a149 1 # reassemble the options but seperated by type @ 1.8 log @*** empty log message *** @ text @d97 2 a98 2 found_type=DSO; break @ 1.7 log @*** empty log message *** @ text @d29 1 a29 1 DIFS="$IFS" d102 1 a102 1 found_type=PIC @ 1.6 log @*** empty log message *** @ text @d29 1 a29 2 DIFS=' ' d35 1 a35 2 optprev="" OIFS="$IFS" IFS="$DIFS" a57 1 IFS="$OIFS" a149 1 OIFS="$IFS" IFS="$DIFS" d151 1 a151 1 OIFS2="$IFS" IFS=':' d167 1 a167 1 IFS="$OIFS2" a168 1 IFS="$OIFS" a170 1 OIFS="$IFS" IFS="$DIFS" a175 1 IFS="$OIFS" @ 1.5 log @*** empty log message *** @ text @d29 1 a29 1 DIFS=' d110 1 a110 1 found_type=OBJ @ 1.4 log @*** empty log message *** @ text @d27 1 a27 1 . sh.common @ 1.3 log @*** empty log message *** @ text @d23 1 a23 1 str_usage="-- -Lxx -lxx [ -Lxx -lxx ... ]" @ 1.2 log @*** empty log message *** @ text @d6 15 @ 1.1 log @Initial revision @ text @a0 1 #!/bin/sh d2 1 a2 1 ## slo -- Separate Linker Options by library class d4 1 a4 1 ## Usage: slo -Lxx -lxx [ -Lxx -lxx ... ] d7 7 a16 1 # a17 1 # a46 1 # a47 1 # a52 1 # a53 1 # a126 1 # a127 1 # a136 1 # a137 1 # a159 1 # a160 1 # @ 1.1.1.1 log @Import of shtool 1.1.0 @ text @@