1ebfedea0SLionel Sambuc#!/bin/sh 2ebfedea0SLionel Sambuc 3ebfedea0SLionel Sambuc[ $# -ne 0 ] || set -x # debug mode without arguments:-) 4ebfedea0SLionel Sambuc 5ebfedea0SLionel SambucTHERE="`echo $0 | sed -e 's|[^/]*$||' 2>/dev/null`.." 6ebfedea0SLionel Sambuc[ -d "${THERE}" ] || exec "$@" # should never happen... 7ebfedea0SLionel Sambuc 8ebfedea0SLionel Sambuc# Alternative to this is to parse ${THERE}/Makefile... 9ebfedea0SLionel SambucLIBCRYPTOSO="${THERE}/libcrypto.so" 10ebfedea0SLionel Sambucif [ -f "$LIBCRYPTOSO" ]; then 11ebfedea0SLionel Sambuc while [ -h "$LIBCRYPTOSO" ]; do 12ebfedea0SLionel Sambuc LIBCRYPTOSO="${THERE}/`ls -l "$LIBCRYPTOSO" | sed -e 's|.*\-> ||'`" 13ebfedea0SLionel Sambuc done 14ebfedea0SLionel Sambuc SOSUFFIX=`echo ${LIBCRYPTOSO} | sed -e 's|.*\.so||' 2>/dev/null` 15ebfedea0SLionel Sambuc LIBSSLSO="${THERE}/libssl.so${SOSUFFIX}" 16ebfedea0SLionel Sambucfi 17ebfedea0SLionel Sambuc 18ebfedea0SLionel SambucSYSNAME=`(uname -s) 2>/dev/null`; 19ebfedea0SLionel Sambuccase "$SYSNAME" in 20ebfedea0SLionel SambucSunOS|IRIX*) 21ebfedea0SLionel Sambuc # SunOS and IRIX run-time linkers evaluate alternative 22ebfedea0SLionel Sambuc # variables depending on target ABI... 23ebfedea0SLionel Sambuc rld_var=LD_LIBRARY_PATH 24ebfedea0SLionel Sambuc case "`(/usr/bin/file "$LIBCRYPTOSO") 2>/dev/null`" in 25ebfedea0SLionel Sambuc *ELF\ 64*SPARC*|*ELF\ 64*AMD64*) 26ebfedea0SLionel Sambuc [ -n "$LD_LIBRARY_PATH_64" ] && rld_var=LD_LIBRARY_PATH_64 27ebfedea0SLionel Sambuc LD_PRELOAD_64="$LIBCRYPTOSO $LIBSSLSO"; export LD_PRELOAD_64 28ebfedea0SLionel Sambuc preload_var=LD_PRELOAD_64 29ebfedea0SLionel Sambuc ;; 30ebfedea0SLionel Sambuc # Why are newly built .so's preloaded anyway? Because run-time 31ebfedea0SLionel Sambuc # .so lookup path embedded into application takes precedence 32ebfedea0SLionel Sambuc # over LD_LIBRARY_PATH and as result application ends up linking 33ebfedea0SLionel Sambuc # to previously installed .so's. On IRIX instead of preloading 34ebfedea0SLionel Sambuc # newly built .so's we trick run-time linker to fail to find 35ebfedea0SLionel Sambuc # the installed .so by setting _RLD_ROOT variable. 36ebfedea0SLionel Sambuc *ELF\ 32*MIPS*) 37ebfedea0SLionel Sambuc #_RLD_LIST="$LIBCRYPTOSO:$LIBSSLSO:DEFAULT"; export _RLD_LIST 38ebfedea0SLionel Sambuc _RLD_ROOT=/no/such/dir; export _RLD_ROOT 39ebfedea0SLionel Sambuc eval $rld_var=\"/usr/lib'${'$rld_var':+:$'$rld_var'}'\" 40ebfedea0SLionel Sambuc preload_var=_RLD_LIST 41ebfedea0SLionel Sambuc ;; 42ebfedea0SLionel Sambuc *ELF\ N32*MIPS*) 43ebfedea0SLionel Sambuc [ -n "$LD_LIBRARYN32_PATH" ] && rld_var=LD_LIBRARYN32_PATH 44ebfedea0SLionel Sambuc #_RLDN32_LIST="$LIBCRYPTOSO:$LIBSSLSO:DEFAULT"; export _RLDN32_LIST 45ebfedea0SLionel Sambuc _RLDN32_ROOT=/no/such/dir; export _RLDN32_ROOT 46ebfedea0SLionel Sambuc eval $rld_var=\"/usr/lib32'${'$rld_var':+:$'$rld_var'}'\" 47ebfedea0SLionel Sambuc preload_var=_RLDN32_LIST 48ebfedea0SLionel Sambuc ;; 49ebfedea0SLionel Sambuc *ELF\ 64*MIPS*) 50ebfedea0SLionel Sambuc [ -n "$LD_LIBRARY64_PATH" ] && rld_var=LD_LIBRARY64_PATH 51ebfedea0SLionel Sambuc #_RLD64_LIST="$LIBCRYPTOSO:$LIBSSLSO:DEFAULT"; export _RLD64_LIST 52ebfedea0SLionel Sambuc _RLD64_ROOT=/no/such/dir; export _RLD64_ROOT 53ebfedea0SLionel Sambuc eval $rld_var=\"/usr/lib64'${'$rld_var':+:$'$rld_var'}'\" 54ebfedea0SLionel Sambuc preload_var=_RLD64_LIST 55ebfedea0SLionel Sambuc ;; 56ebfedea0SLionel Sambuc esac 57ebfedea0SLionel Sambuc eval $rld_var=\"${THERE}'${'$rld_var':+:$'$rld_var'}'\"; export $rld_var 58ebfedea0SLionel Sambuc unset rld_var 59ebfedea0SLionel Sambuc ;; 60ebfedea0SLionel Sambuc*) LD_LIBRARY_PATH="${THERE}:$LD_LIBRARY_PATH" # Linux, ELF HP-UX 61ebfedea0SLionel Sambuc DYLD_LIBRARY_PATH="${THERE}:$DYLD_LIBRARY_PATH" # MacOS X 62ebfedea0SLionel Sambuc SHLIB_PATH="${THERE}:$SHLIB_PATH" # legacy HP-UX 63ebfedea0SLionel Sambuc LIBPATH="${THERE}:$LIBPATH" # AIX, OS/2 64ebfedea0SLionel Sambuc export LD_LIBRARY_PATH DYLD_LIBRARY_PATH SHLIB_PATH LIBPATH 65ebfedea0SLionel Sambuc # Even though $PATH is adjusted [for Windows sake], it doesn't 66ebfedea0SLionel Sambuc # necessarily does the trick. Trouble is that with introduction 67ebfedea0SLionel Sambuc # of SafeDllSearchMode in XP/2003 it's more appropriate to copy 68ebfedea0SLionel Sambuc # .DLLs in vicinity of executable, which is done elsewhere... 69ebfedea0SLionel Sambuc if [ "$OSTYPE" != msdosdjgpp ]; then 70ebfedea0SLionel Sambuc PATH="${THERE}:$PATH"; export PATH 71ebfedea0SLionel Sambuc fi 72ebfedea0SLionel Sambuc ;; 73ebfedea0SLionel Sambucesac 74ebfedea0SLionel Sambuc 75ebfedea0SLionel Sambucif [ -f "$LIBCRYPTOSO" -a -z "$preload_var" ]; then 76ebfedea0SLionel Sambuc # Following three lines are major excuse for isolating them into 77ebfedea0SLionel Sambuc # this wrapper script. Original reason for setting LD_PRELOAD 78ebfedea0SLionel Sambuc # was to make it possible to pass 'make test' when user linked 79ebfedea0SLionel Sambuc # with -rpath pointing to previous version installation. Wrapping 80ebfedea0SLionel Sambuc # it into a script makes it possible to do so on multi-ABI 81ebfedea0SLionel Sambuc # platforms. 82ebfedea0SLionel Sambuc case "$SYSNAME" in 83ebfedea0SLionel Sambuc *BSD|QNX) LD_PRELOAD="$LIBCRYPTOSO:$LIBSSLSO" ;; # *BSD, QNX 84ebfedea0SLionel Sambuc *) LD_PRELOAD="$LIBCRYPTOSO $LIBSSLSO" ;; # SunOS, Linux, ELF HP-UX 85ebfedea0SLionel Sambuc esac 86ebfedea0SLionel Sambuc _RLD_LIST="$LIBCRYPTOSO:$LIBSSLSO:DEFAULT" # Tru64, o32 IRIX 87ebfedea0SLionel Sambuc DYLD_INSERT_LIBRARIES="$LIBCRYPTOSO:$LIBSSLSO" # MacOS X 88ebfedea0SLionel Sambuc export LD_PRELOAD _RLD_LIST DYLD_INSERT_LIBRARIES 89ebfedea0SLionel Sambucfi 90ebfedea0SLionel Sambuc 91ebfedea0SLionel Sambuccmd="$1${EXE_EXT}" 92ebfedea0SLionel Sambucshift 93*0a6a1f1dSLionel Sambucif [ $# -eq 0 ]; then 94*0a6a1f1dSLionel Sambuc exec "$cmd" # old sh, such as Tru64 4.x, fails to expand empty "$@" 95*0a6a1f1dSLionel Sambucelse 96ebfedea0SLionel Sambuc exec "$cmd" "$@" 97*0a6a1f1dSLionel Sambucfi 98