2
0

shlib_wrap.sh 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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*|*ELF\ 64*AMD64*)
  22. [ -n "$LD_LIBRARY_PATH_64" ] && rld_var=LD_LIBRARY_PATH_64
  23. LD_PRELOAD_64="$LIBCRYPTOSO $LIBSSLSO"; export LD_PRELOAD_64
  24. preload_var=LD_PRELOAD_64
  25. ;;
  26. # Why are newly built .so's preloaded anyway? Because run-time
  27. # .so lookup path embedded into application takes precedence
  28. # over LD_LIBRARY_PATH and as result application ends up linking
  29. # to previously installed .so's. On IRIX instead of preloading
  30. # newly built .so's we trick run-time linker to fail to find
  31. # the installed .so by setting _RLD_ROOT variable.
  32. *ELF\ 32*MIPS*)
  33. #_RLD_LIST="$LIBCRYPTOSO:$LIBSSLSO:DEFAULT"; export _RLD_LIST
  34. _RLD_ROOT=/no/such/dir; export _RLD_ROOT
  35. eval $rld_var=\"/usr/lib'${'$rld_var':+:$'$rld_var'}'\"
  36. preload_var=_RLD_LIST
  37. ;;
  38. *ELF\ N32*MIPS*)
  39. [ -n "$LD_LIBRARYN32_PATH" ] && rld_var=LD_LIBRARYN32_PATH
  40. #_RLDN32_LIST="$LIBCRYPTOSO:$LIBSSLSO:DEFAULT"; export _RLDN32_LIST
  41. _RLDN32_ROOT=/no/such/dir; export _RLDN32_ROOT
  42. eval $rld_var=\"/usr/lib32'${'$rld_var':+:$'$rld_var'}'\"
  43. preload_var=_RLDN32_LIST
  44. ;;
  45. *ELF\ 64*MIPS*)
  46. [ -n "$LD_LIBRARY64_PATH" ] && rld_var=LD_LIBRARY64_PATH
  47. #_RLD64_LIST="$LIBCRYPTOSO:$LIBSSLSO:DEFAULT"; export _RLD64_LIST
  48. _RLD64_ROOT=/no/such/dir; export _RLD64_ROOT
  49. eval $rld_var=\"/usr/lib64'${'$rld_var':+:$'$rld_var'}'\"
  50. preload_var=_RLD64_LIST
  51. ;;
  52. esac
  53. eval $rld_var=\"${THERE}'${'$rld_var':+:$'$rld_var'}'\"; export $rld_var
  54. unset rld_var
  55. ;;
  56. *) LD_LIBRARY_PATH="${THERE}:$LD_LIBRARY_PATH" # Linux, ELF HP-UX
  57. DYLD_LIBRARY_PATH="${THERE}:$DYLD_LIBRARY_PATH" # MacOS X
  58. SHLIB_PATH="${THERE}:$SHLIB_PATH" # legacy HP-UX
  59. LIBPATH="${THERE}:$LIBPATH" # AIX, OS/2
  60. export LD_LIBRARY_PATH DYLD_LIBRARY_PATH SHLIB_PATH LIBPATH
  61. # Even though $PATH is adjusted [for Windows sake], it doesn't
  62. # necessarily does the trick. Trouble is that with introduction
  63. # of SafeDllSearchMode in XP/2003 it's more appropriate to copy
  64. # .DLLs in vicinity of executable, which is done elsewhere...
  65. if [ "$OSTYPE" != msdosdjgpp ]; then
  66. PATH="${THERE}:$PATH"; export PATH
  67. fi
  68. ;;
  69. esac
  70. if [ -f "$LIBCRYPTOSO" -a -z "$preload_var" ]; then
  71. # Following three lines are major excuse for isolating them into
  72. # this wrapper script. Original reason for setting LD_PRELOAD
  73. # was to make it possible to pass 'make test' when user linked
  74. # with -rpath pointing to previous version installation. Wrapping
  75. # it into a script makes it possible to do so on multi-ABI
  76. # platforms.
  77. case "$SYSNAME" in
  78. *BSD|QNX) LD_PRELOAD="$LIBCRYPTOSO:$LIBSSLSO" ;; # *BSD, QNX
  79. *) LD_PRELOAD="$LIBCRYPTOSO $LIBSSLSO" ;; # SunOS, Linux, ELF HP-UX
  80. esac
  81. _RLD_LIST="$LIBCRYPTOSO:$LIBSSLSO:DEFAULT" # Tru64, o32 IRIX
  82. DYLD_INSERT_LIBRARIES="$LIBCRYPTOSO:$LIBSSLSO" # MacOS X
  83. export LD_PRELOAD _RLD_LIST DYLD_INSERT_LIBRARIES
  84. fi
  85. exec "$@"