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