shlib revision 166124
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# 32166124Srafan# $Id: shlib,v 1.10 2005/06/25 22:41:17 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` 84166124Srafan elif test -f configure && test ! -d ../$p ; then 85166124Srafan break 8650276Speter fi 8750276Speterdone 88166124Srafan 89166124Srafan# Set the environment variable. 9050276Speterif test -n "$q" ; then 91166124Srafan system= 92166124Srafan if test -n "$SHLIB_HOST" ; then 93166124Srafan system="$SHLIB_HOST" 94166124Srafan elif test -n "$PATHEXT" ; then 95166124Srafan system=cygwin 9662449Speter elif test -n "$LIBRARY_PATH" ; then 97166124Srafan system=beos 98166124Srafan elif test -n "$DYLD_LIBRARY_PATH" ; then 99166124Srafan system=darwin 100166124Srafan elif test -n "$LD_LIBRARY_PATH"; then 101166124Srafan system=unix 10250276Speter else 103166124Srafan for r in $q/*.* 104166124Srafan do 105166124Srafan if test -f "$r" 106166124Srafan then 107166124Srafan case $r in 108166124Srafan *.dll) 109166124Srafan system=cygwin 110166124Srafan ;; 111166124Srafan *.dylib) 112166124Srafan system=darwin 113166124Srafan ;; 114166124Srafan esac 115166124Srafan fi 116166124Srafan test -n "$system" && break 117166124Srafan done 11850276Speter fi 119166124Srafan 120166124Srafan case .$system in 121166124Srafan .cygwin*) 122166124Srafan variable=PATH 123166124Srafan ;; 124166124Srafan .beos*) 125166124Srafan variable=LIBRARY_PATH 126166124Srafan ;; 127166124Srafan .darwin*) 128166124Srafan variable=DYLD_LIBRARY_PATH 129166124Srafan ;; 130166124Srafan *) 131166124Srafan variable=LD_LIBRARY_PATH 132166124Srafan ;; 133166124Srafan esac 134166124Srafan 135166124Srafan eval 'test -z "$'$variable'" && '$variable'=":"' 136166124Srafan eval $variable'="$q:$'$variable'"' 137166124Srafan eval 'export '$variable 13850276Speterfi 139166124Srafan 14050276Spetereval "$*" 141