150276Speter#!/bin/sh
250276Speter##############################################################################
3166124Srafan# Copyright (c) 1998-2003,2005 Free Software Foundation, Inc.                #
450276Speter#                                                                            #
550276Speter# Permission is hereby granted, free of charge, to any person obtaining a    #
650276Speter# copy of this software and associated documentation files (the "Software"), #
750276Speter# to deal in the Software without restriction, including without limitation  #
850276Speter# the rights to use, copy, modify, merge, publish, distribute, distribute    #
950276Speter# with modifications, sublicense, and/or sell copies of the Software, and to #
1050276Speter# permit persons to whom the Software is furnished to do so, subject to the  #
1150276Speter# following conditions:                                                      #
1250276Speter#                                                                            #
1350276Speter# The above copyright notice and this permission notice shall be included in #
1450276Speter# all copies or substantial portions of the Software.                        #
1550276Speter#                                                                            #
1650276Speter# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #
1750276Speter# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   #
1850276Speter# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    #
1950276Speter# THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER      #
2050276Speter# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING    #
2150276Speter# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER        #
2250276Speter# DEALINGS IN THE SOFTWARE.                                                  #
2350276Speter#                                                                            #
2450276Speter# Except as contained in this notice, the name(s) of the above copyright     #
2550276Speter# holders shall not be used in advertising or otherwise to promote the sale, #
2650276Speter# use or other dealings in this Software without prior written               #
2750276Speter# authorization.                                                             #
2850276Speter##############################################################################
2950276Speter#
3050276Speter# Author: Thomas E. Dickey <dickey@clark.net> 1996
3150276Speter#
32174993Srafan# $Id: shlib,v 1.11 2007/01/13 17:09:52 tom Exp $
3350276Speter# Use this script as a wrapper when running executables linked to shared
3450276Speter# libraries on systems that use the $LD_LIBRARY_PATH variable and don't embed
3550276Speter# the soname's path within the linked executable (such as IRIX), e.g,
3650276Speter#
3750276Speter#	shlib knight
3850276Speter#
3950276Speter# Setting LD_LIBRARY_PATH, overrides/supplements the loader's normal search
4050276Speter# path, and works on most systems.  The drawback is that then the environment
4150276Speter# variable has to be set to run the programs within this directory tree.
4250276Speter#
4350276Speter# For Linux (and other systems using the GNU loader), we can use the rpath
4450276Speter# directive, which embeds the pathname of the library within the executable.
4550276Speter# Using the Linux loader's rpath directive introduces a constraint, since
4650276Speter# it's embedded into the binary, and means that the binary cannot be moved
4750276Speter# around (though it'll work if the $exec_prefix convention that puts the bin
4850276Speter# and lib directories under the same parent is followed).
4950276Speter#
5050276Speter# Using the actual soname (e.g., ../lib/libncurses.so) alone, is a more
5150276Speter# flexible solution; you can link without having to set the environment
5250276Speter# variable, and on some systems (IRIX) you can even run the resulting binaries
5350276Speter# without setting LD_LIBRARY_PATH.
5450276Speter#
5550276Speter# Using a conventional link, with -L and -l options on Linux results in a
5650276Speter# statically linked executable, which we don't want at all.
5750276Speter#
5862449Speter# Special cases:
5962449Speter#
6062449Speter#	BeOS R4.5 uses $LIBRARY_PATH rather than $LD_LIBRARY_PATH.
61166124Srafan#	Cygwin uses $PATH
62166124Srafan#	Mac OS X uses $DYLD_LIBRARY_PATH
6350276Speter#
64166124Srafan# Other cases not handled by this script:
65166124Srafan#
66166124Srafan#	AIX uses $LIBPATH
67166124Srafan#	IRIX64 may use $LD_LIBRARY64_PATH or $LD_LIBRARYN32_PATH
68166124Srafan#	Solaris may use $LD_LIBRARY_PATH_64
69166124Srafan#
70166124SrafanCDPATH=
71166124Srafan#
7250276Speter# Make sure that we use the PATH that was set in run_tic.sh
73166124Srafanif test -n "$SHLIB_PATH" ; then
74166124Srafan	PATH=$SHLIB_PATH
7550276Speter	export PATH
7650276Speterfi
7750276Speter
78166124Srafan# Find the lib-directory for this build tree
7950276Speterq=""
80166124Srafanfor p in lib ../lib ../../lib ../../../lib
8150276Speterdo
8250276Speter	if test -d $p; then
83166124Srafan		q=`cd $p; pwd`
84174993Srafan		break
85166124Srafan	elif test -f configure && test ! -d ../$p ; then
86166124Srafan		break
8750276Speter	fi
8850276Speterdone
89166124Srafan
90166124Srafan# Set the environment variable.
9150276Speterif test -n "$q" ; then
92166124Srafan	system=
93166124Srafan	if test -n "$SHLIB_HOST" ; then
94166124Srafan		system="$SHLIB_HOST"
95166124Srafan	elif test -n "$PATHEXT" ; then
96166124Srafan		system=cygwin
9762449Speter	elif test -n "$LIBRARY_PATH" ; then
98166124Srafan		system=beos
99166124Srafan	elif test -n "$DYLD_LIBRARY_PATH" ; then
100166124Srafan		system=darwin
101166124Srafan	elif test -n "$LD_LIBRARY_PATH"; then
102166124Srafan		system=unix
10350276Speter	else
104166124Srafan		for r in $q/*.*
105166124Srafan		do
106166124Srafan			if test -f "$r"
107166124Srafan			then
108166124Srafan				case $r in
109166124Srafan				*.dll)
110166124Srafan					system=cygwin
111166124Srafan					;;
112166124Srafan				*.dylib)
113166124Srafan					system=darwin
114166124Srafan					;;
115166124Srafan				esac
116166124Srafan			fi
117166124Srafan			test -n "$system" && break
118166124Srafan		done
11950276Speter	fi
120166124Srafan
121166124Srafan	case .$system in
122166124Srafan	.cygwin*)
123166124Srafan		variable=PATH
124166124Srafan		;;
125166124Srafan	.beos*)
126166124Srafan		variable=LIBRARY_PATH
127166124Srafan		;;
128166124Srafan	.darwin*)
129166124Srafan		variable=DYLD_LIBRARY_PATH
130166124Srafan		;;
131166124Srafan	*)
132166124Srafan		variable=LD_LIBRARY_PATH
133166124Srafan		;;
134166124Srafan	esac
135166124Srafan
136166124Srafan	eval 'test -z "$'$variable'" && '$variable'=":"'
137166124Srafan	eval $variable'="$q:$'$variable'"'
138166124Srafan	eval 'export '$variable
13950276Speterfi
140166124Srafan
14150276Spetereval "$*"
142