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