shlib_wrap.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/bin/sh
  2. [ $# -ne 0 ] || set -x # debug mode without arguments:-)
  3. THERE="`echo $0 | sed -e 's|[^/]*$||' 2>/dev/null`.."
  4. [ -d "${THERE}" ] || exec "$@" # should never happen...
  5. # Alternative to this is to parse ${THERE}/Makefile...
  6. LIBCRYPTOSO="${THERE}/libcrypto.so"
  7. if [ -f "$LIBCRYPTOSO" ]; then
  8. while [ -h "$LIBCRYPTOSO" ]; do
  9. LIBCRYPTOSO="${THERE}/`ls -l "$LIBCRYPTOSO" | sed -e 's|.*\-> ||'`"
  10. done
  11. SOSUFFIX=`echo ${LIBCRYPTOSO} | sed -e 's|.*\.so||' 2>/dev/null`
  12. LIBSSLSO="${THERE}/libssl.so${SOSUFFIX}"
  13. fi
  14. SYSNAME=`(uname -s) 2>/dev/null`;
  15. case "$SYSNAME" in
  16. SunOS|IRIX*)
  17. # SunOS and IRIX run-time linkers evaluate alternative
  18. # variables depending on target ABI...
  19. rld_var=LD_LIBRARY_PATH
  20. case "`(/usr/bin/file "$LIBCRYPTOSO") 2>/dev/null`" in
  21. *ELF\ 64*SPARC*)
  22. [ -n "$LD_LIBRARY_PATH_64" ] && rld_var=LD_LIBRARY_PATH_64
  23. ;;
  24. *ELF\ N32*MIPS*)
  25. [ -n "$LD_LIBRARYN32_PATH" ] && rld_var=LD_LIBRARYN32_PATH
  26. _RLDN32_LIST="$LIBCRYPTOSO:$LIBSSLSO:DEFAULT"; export _RLDN32_LIST
  27. ;;
  28. *ELF\ 64*MIPS*)
  29. [ -n "$LD_LIBRARY64_PATH" ] && rld_var=LD_LIBRARY64_PATH
  30. _RLD64_LIST="$LIBCRYPTOSO:$LIBSSLSO:DEFAULT"; export _RLD64_LIST
  31. ;;
  32. esac
  33. eval $rld_var=\"${THERE}:'$'$rld_var\"; export $rld_var
  34. unset rld_var
  35. ;;
  36. *) LD_LIBRARY_PATH="${THERE}:$LD_LIBRARY_PATH" # Linux, ELF HP-UX
  37. DYLD_LIBRARY_PATH="${THERE}:$DYLD_LIBRARY_PATH" # MacOS X
  38. SHLIB_PATH="${THERE}:$SHLIB_PATH" # legacy HP-UX
  39. LIBPATH="${THERE}:$LIBPATH" # AIX, OS/2
  40. export LD_LIBRARY_PATH DYLD_LIBRARY_PATH SHLIB_PATH LIBPATH
  41. # Even though $PATH is adjusted [for Windows sake], it doesn't
  42. # necessarily does the trick. Trouble is that with introduction
  43. # of SafeDllSearchMode in XP/2003 it's more appropriate to copy
  44. # .DLLs in vicinity of executable, which is done elsewhere...
  45. if [ "$OSTYPE" != msdosdjgpp ]; then
  46. PATH="${THERE}:$PATH"; export PATH
  47. fi
  48. ;;
  49. esac
  50. if [ -f "$LIBCRYPTOSO" ]; then
  51. # Following three lines are major excuse for isolating them into
  52. # this wrapper script. Original reason for setting LD_PRELOAD
  53. # was to make it possible to pass 'make test' when user linked
  54. # with -rpath pointing to previous version installation. Wrapping
  55. # it into a script makes it possible to do so on multi-ABI
  56. # platforms.
  57. case "$SYSNAME" in
  58. *BSD) LD_PRELOAD="$LIBCRYPTOSO:$LIBSSLSO" ;; # *BSD
  59. *) LD_PRELOAD="$LIBCRYPTOSO $LIBSSLSO" ;; # SunOS, Linux, ELF HP-UX
  60. esac
  61. _RLD_LIST="$LIBCRYPTOSO:$LIBSSLSO:DEFAULT" # Tru64, o32 IRIX
  62. export LD_PRELOAD _RLD_LIST
  63. fi
  64. exec "$@"