shlib revision 174993
1169689Skan#!/bin/sh
2169689Skan##############################################################################
3169689Skan# Copyright (c) 1998-2003,2005 Free Software Foundation, Inc.                #
4169689Skan#                                                                            #
5169689Skan# Permission is hereby granted, free of charge, to any person obtaining a    #
6169689Skan# copy of this software and associated documentation files (the "Software"), #
7169689Skan# to deal in the Software without restriction, including without limitation  #
8169689Skan# the rights to use, copy, modify, merge, publish, distribute, distribute    #
9169689Skan# with modifications, sublicense, and/or sell copies of the Software, and to #
10169689Skan# permit persons to whom the Software is furnished to do so, subject to the  #
11169689Skan# following conditions:                                                      #
12169689Skan#                                                                            #
13169689Skan# The above copyright notice and this permission notice shall be included in #
14169689Skan# all copies or substantial portions of the Software.                        #
15169689Skan#                                                                            #
16169689Skan# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
17169689Skan# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   #
18169689Skan# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    #
19169689Skan# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      #
20169689Skan# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING    #
21169689Skan# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER        #
22169689Skan# DEALINGS IN THE SOFTWARE.                                                  #
23169689Skan#                                                                            #
24169689Skan# Except as contained in this notice, the name(s) of the above copyright     #
25169689Skan# holders shall not be used in advertising or otherwise to promote the sale, #
26169689Skan# use or other dealings in this Software without prior written               #
27169689Skan# authorization.                                                             #
28169689Skan##############################################################################
29169689Skan#
30169689Skan# Author: Thomas E. Dickey <dickey@clark.net> 1996
31169689Skan#
32169689Skan# $Id: shlib,v 1.11 2007/01/13 17:09:52 tom Exp $
33169689Skan# Use this script as a wrapper when running executables linked to shared
34169689Skan# libraries on systems that use the $LD_LIBRARY_PATH variable and don't embed
35169689Skan# the soname's path within the linked executable (such as IRIX), e.g,
36169689Skan#
37169689Skan#	shlib knight
38169689Skan#
39169689Skan# Setting LD_LIBRARY_PATH, overrides/supplements the loader's normal search
40169689Skan# path, and works on most systems.  The drawback is that then the environment
41169689Skan# variable has to be set to run the programs within this directory tree.
42169689Skan#
43169689Skan# For Linux (and other systems using the GNU loader), we can use the rpath
44169689Skan# directive, which embeds the pathname of the library within the executable.
45169689Skan# Using the Linux loader's rpath directive introduces a constraint, since
46169689Skan# it's embedded into the binary, and means that the binary cannot be moved
47169689Skan# around (though it'll work if the $exec_prefix convention that puts the bin
48169689Skan# and lib directories under the same parent is followed).
49169689Skan#
50169689Skan# Using the actual soname (e.g., ../lib/libncurses.so) alone, is a more
51169689Skan# flexible solution; you can link without having to set the environment
52169689Skan# variable, and on some systems (IRIX) you can even run the resulting binaries
53169689Skan# without setting LD_LIBRARY_PATH.
54169689Skan#
55169689Skan# Using a conventional link, with -L and -l options on Linux results in a
56169689Skan# statically linked executable, which we don't want at all.
57169689Skan#
58169689Skan# Special cases:
59169689Skan#
60169689Skan#	BeOS R4.5 uses $LIBRARY_PATH rather than $LD_LIBRARY_PATH.
61169689Skan#	Cygwin uses $PATH
62169689Skan#	Mac OS X uses $DYLD_LIBRARY_PATH
63169689Skan#
64169689Skan# Other cases not handled by this script:
65169689Skan#
66169689Skan#	AIX uses $LIBPATH
67169689Skan#	IRIX64 may use $LD_LIBRARY64_PATH or $LD_LIBRARYN32_PATH
68169689Skan#	Solaris may use $LD_LIBRARY_PATH_64
69169689Skan#
70169689SkanCDPATH=
71169689Skan#
72169689Skan# Make sure that we use the PATH that was set in run_tic.sh
73169689Skanif test -n "$SHLIB_PATH" ; then
74169689Skan	PATH=$SHLIB_PATH
75169689Skan	export PATH
76169689Skanfi
77169689Skan
78169689Skan# Find the lib-directory for this build tree
79169689Skanq=""
80169689Skanfor p in lib ../lib ../../lib ../../../lib
81169689Skando
82169689Skan	if test -d $p; then
83169689Skan		q=`cd $p; pwd`
84169689Skan		break
85169689Skan	elif test -f configure && test ! -d ../$p ; then
86169689Skan		break
87169689Skan	fi
88169689Skandone
89169689Skan
90169689Skan# Set the environment variable.
91169689Skanif test -n "$q" ; then
92169689Skan	system=
93169689Skan	if test -n "$SHLIB_HOST" ; then
94169689Skan		system="$SHLIB_HOST"
95169689Skan	elif test -n "$PATHEXT" ; then
96169689Skan		system=cygwin
97169689Skan	elif test -n "$LIBRARY_PATH" ; then
98169689Skan		system=beos
99169689Skan	elif test -n "$DYLD_LIBRARY_PATH" ; then
100169689Skan		system=darwin
101169689Skan	elif test -n "$LD_LIBRARY_PATH"; then
102169689Skan		system=unix
103169689Skan	else
104169689Skan		for r in $q/*.*
105169689Skan		do
106169689Skan			if test -f "$r"
107169689Skan			then
108169689Skan				case $r in
109169689Skan				*.dll)
110169689Skan					system=cygwin
111169689Skan					;;
112169689Skan				*.dylib)
113169689Skan					system=darwin
114169689Skan					;;
115169689Skan				esac
116169689Skan			fi
117169689Skan			test -n "$system" && break
118169689Skan		done
119169689Skan	fi
120169689Skan
121169689Skan	case .$system in
122169689Skan	.cygwin*)
123169689Skan		variable=PATH
124169689Skan		;;
125169689Skan	.beos*)
126169689Skan		variable=LIBRARY_PATH
127169689Skan		;;
128169689Skan	.darwin*)
129169689Skan		variable=DYLD_LIBRARY_PATH
130169689Skan		;;
131169689Skan	*)
132169689Skan		variable=LD_LIBRARY_PATH
133169689Skan		;;
134169689Skan	esac
135169689Skan
136169689Skan	eval 'test -z "$'$variable'" && '$variable'=":"'
137169689Skan	eval $variable'="$q:$'$variable'"'
138169689Skan	eval 'export '$variable
139169689Skanfi
140169689Skan
141169689Skaneval "$*"
142169689Skan