shlib_wrap.sh 4.0 KB

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