#!/bin/sh
################################################################################
# Copyright 1996 by Thomas E. Dickey <dickey@clark.net>                        #
# All Rights Reserved.                                                         #
#                                                                              #
# Permission to use, copy, modify, and distribute this software and its        #
# documentation for any purpose and without fee is hereby granted, provided    #
# that the above copyright notice appear in all copies and that both that      #
# copyright notice and this permission notice appear in supporting             #
# documentation, and that the name of the above listed copyright holder(s) not #
# be used in advertising or publicity pertaining to distribution of the        #
# software without specific, written prior permission. THE ABOVE LISTED        #
# COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,    #
# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT #
# SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY SPECIAL,        #
# INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM   #
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE   #
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR    #
# PERFORMANCE OF THIS SOFTWARE.                                                #
################################################################################
# $Id: shlib,v 1.3 1996/06/17 21:45:36 tom Exp $
# Use this script as a wrapper when running executables linked to shared
# libraries on systems that use the $LD_LIBRARY_PATH variable and don't embed
# the soname's path within the linked executable (such as IRIX), e.g,
#
#	shlib knight
#
# Setting LD_LIBRARY_PATH, overrides/supplements the loader's normal search
# path, and works on most systems.  The drawback is that then the environment
# variable has to be set to run the programs within this directory tree.
#
# For Linux (and other systems using the GNU loader), we can use the rpath
# directive, which embeds the pathname of the library within the executable.
# Using the Linux loader's rpath directive introduces a constraint, since
# it's embedded into the binary, and means that the binary cannot be moved
# around (though it'll work if the $exec_prefix convention that puts the bin
# and lib directories under the same parent is followed).
#
# Using the actual soname (e.g., ../lib/libncurses.so) alone, is a more
# flexible solution; you can link without having to set the environment
# variable, and on some systems (IRIX) you can even run the resulting binaries
# without setting LD_LIBRARY_PATH.
#
# Using a conventional link, with -L and -l options on Linux results in a
# statically linked executable, which we don't want at all.
#
q=""
for p in lib ../lib
do
	if test -d $p; then
		q="$p"
	fi
done
if test -n "$q" ; then
	if test -n "$LD_LIBRARY_PATH"; then
		LD_LIBRARY_PATH="$q:$LD_LIBRARY_PATH"
	else
		LD_LIBRARY_PATH="$q"
	fi
	export LD_LIBRARY_PATH
fi
eval "$*"
