#!/bin/sh
#
# Put the path to the socks shared library in our LD_LIBRARY_PATH so when we
# preload the library, ld.so will find it...
#
if test -n "${SOCKS5_SHLIB_RUNPATH}" ; then
	SOCKS5_SHLIB_RUNPATH="${SOCKS5_SHLIB_RUNPATH}/"
elif test -n "@SHLIB_DIR@"; then
	SOCKS5_SHLIB_RUNPATH="@SHLIB_DIR@/"
else 
	SOCKS5_SHLIB_RUNPATH="./"
fi

#
# Some OS's use PRELOADS=lib while others use _RLD_LIST=lib:DEFAULT.  Hopefully 
# this can handle all those cases.  At any rate, this is basically causing the
# socks5 shared libary to be used to resolve symbols before other libraries,
# hence we get socks's connect before we get libc's connect...
#
# Also, on SunOS 4*, LD_LIBRARY_PATH has no effect on, so we need to put the path
# in front of it.  We make the path overridable with SOCKS5_SHLIB_RUNPATH...
#
case `uname -rs` in
SunOS*4.*)
	@PRELOADS@=${SOCKS5_SHLIB_RUNPATH}@SHLIB_LIB@@PRELOADA@
	export @PRELOADS@
	;;
*)
	if test -z "$LD_LIBRARY_PATH" ; then
		LD_LIBRARY_PATH=${SOCKS5_SHLIB_RUNPATH}
	else
		LD_LIBRARY_PATH=${SOCKS5_SHLIB_RUNPATH}:${LD_LIBRARY_PATH}
		export LD_LIBRARY_PATH
	fi

	@PRELOADS@=@SHLIB_LIB@@PRELOADA@
	export LD_LIBRARY_PATH
	;;
esac
# 
# Run the actual program...
#
export @PRELOADS@
exec $*
