]> git.ipfire.org Git - thirdparty/openssl.git/blob - util/shlib_wrap.sh.in
Configure,util/shlib_wrap.sh: harmonize -Wl and -rpath handling.
[thirdparty/openssl.git] / util / shlib_wrap.sh.in
1 #!/bin/sh
2
3 # To test this OpenSSL version's applications against another version's
4 # shared libraries, simply set
5 #
6 # OPENSSL_REGRESSION=/path/to/other/OpenSSL/build/tree
7 if [ -n "$OPENSSL_REGRESSION" ]; then
8 shlibwrap="$OPENSSL_REGRESSION/util/shlib_wrap.sh"
9 if [ -x "$shlibwrap" ]; then
10 # We clear OPENSSL_REGRESSION to avoid a loop, should the shlib_wrap.sh
11 # we exec also support that mechanism...
12 OPENSSL_REGRESSION= exec "$shlibwrap" "$@"
13 else
14 if [ -f "$shlibwrap" ]; then
15 echo "Not permitted to run $shlibwrap" >&2
16 else
17 echo "No $shlibwrap, perhaps OPENSSL_REGRESSION isn't properly set?" >&2
18 fi
19 exit 1
20 fi
21 fi
22
23 [ $# -ne 0 ] || set -x # debug mode without arguments:-)
24
25 THERE="`echo $0 | sed -e 's|[^/]*$||' 2>/dev/null`.."
26 [ -d "${THERE}" ] || exec "$@" # should never happen...
27
28 # Alternative to this is to parse ${THERE}/Makefile...
29 LIBCRYPTOSO="${THERE}/libcrypto.so"
30 if [ -f "$LIBCRYPTOSO" ]; then
31 while [ -h "$LIBCRYPTOSO" ]; do
32 LIBCRYPTOSO="${THERE}/`ls -l "$LIBCRYPTOSO" | sed -e 's|.*\-> ||'`"
33 done
34 SOSUFFIX=`echo ${LIBCRYPTOSO} | sed -e 's|.*\.so||' 2>/dev/null`
35 LIBSSLSO="${THERE}/libssl.so${SOSUFFIX}"
36 fi
37
38 SYSNAME=`(uname -s) 2>/dev/null`;
39 case "$SYSNAME" in
40 SunOS|IRIX*)
41 # SunOS and IRIX run-time linkers evaluate alternative
42 # variables depending on target ABI...
43 rld_var=LD_LIBRARY_PATH
44 case "`(/usr/bin/file "$LIBCRYPTOSO") 2>/dev/null`" in
45 *ELF\ 64*SPARC*|*ELF\ 64*AMD64*)
46 [ -n "$LD_LIBRARY_PATH_64" ] && rld_var=LD_LIBRARY_PATH_64
47 LD_PRELOAD_64="$LIBCRYPTOSO $LIBSSLSO"; export LD_PRELOAD_64
48 preload_var=LD_PRELOAD_64
49 ;;
50 *ELF\ 32*SPARC*|*ELF\ 32*80386*)
51 # We only need to change LD_PRELOAD_32 and LD_LIBRARY_PATH_32
52 # on a multi-arch system. Otherwise, trust the fallbacks.
53 if [ -f /lib/64/ld.so.1 ]; then
54 [ -n "$LD_LIBRARY_PATH_32" ] && rld_var=LD_LIBRARY_PATH_32
55 LD_PRELOAD_32="$LIBCRYPTOSO $LIBSSLSO"; export LD_PRELOAD_32
56 preload_var=LD_PRELOAD_32
57 fi
58 ;;
59 # Why are newly built .so's preloaded anyway? Because run-time
60 # .so lookup path embedded into application takes precedence
61 # over LD_LIBRARY_PATH and as result application ends up linking
62 # to previously installed .so's. On IRIX instead of preloading
63 # newly built .so's we trick run-time linker to fail to find
64 # the installed .so by setting _RLD_ROOT variable.
65 *ELF\ 32*MIPS*)
66 #_RLD_LIST="$LIBCRYPTOSO:$LIBSSLSO:DEFAULT"; export _RLD_LIST
67 _RLD_ROOT=/no/such/dir; export _RLD_ROOT
68 eval $rld_var=\"/usr/lib'${'$rld_var':+:$'$rld_var'}'\"
69 preload_var=_RLD_LIST
70 ;;
71 *ELF\ N32*MIPS*)
72 [ -n "$LD_LIBRARYN32_PATH" ] && rld_var=LD_LIBRARYN32_PATH
73 #_RLDN32_LIST="$LIBCRYPTOSO:$LIBSSLSO:DEFAULT"; export _RLDN32_LIST
74 _RLDN32_ROOT=/no/such/dir; export _RLDN32_ROOT
75 eval $rld_var=\"/usr/lib32'${'$rld_var':+:$'$rld_var'}'\"
76 preload_var=_RLDN32_LIST
77 ;;
78 *ELF\ 64*MIPS*)
79 [ -n "$LD_LIBRARY64_PATH" ] && rld_var=LD_LIBRARY64_PATH
80 #_RLD64_LIST="$LIBCRYPTOSO:$LIBSSLSO:DEFAULT"; export _RLD64_LIST
81 _RLD64_ROOT=/no/such/dir; export _RLD64_ROOT
82 eval $rld_var=\"/usr/lib64'${'$rld_var':+:$'$rld_var'}'\"
83 preload_var=_RLD64_LIST
84 ;;
85 esac
86 eval $rld_var=\"${THERE}'${'$rld_var':+:$'$rld_var'}'\"; export $rld_var
87 unset rld_var
88 ;;
89 *) LD_LIBRARY_PATH="${THERE}:$LD_LIBRARY_PATH" # Linux, ELF HP-UX
90 DYLD_LIBRARY_PATH="${THERE}:$DYLD_LIBRARY_PATH" # MacOS X
91 SHLIB_PATH="${THERE}:$SHLIB_PATH" # legacy HP-UX
92 LIBPATH="${THERE}:$LIBPATH" # AIX, OS/2
93 export LD_LIBRARY_PATH DYLD_LIBRARY_PATH SHLIB_PATH LIBPATH
94 # Even though $PATH is adjusted [for Windows sake], it doesn't
95 # necessarily does the trick. Trouble is that with introduction
96 # of SafeDllSearchMode in XP/2003 it's more appropriate to copy
97 # .DLLs in vicinity of executable, which is done elsewhere...
98 if [ "$OSTYPE" != msdosdjgpp ]; then
99 PATH="${THERE}:$PATH"; export PATH
100 fi
101 ;;
102 esac
103
104 {- output_off() unless grep (/-rpath\b/, @{$config{LDFLAGS}}); ""; -}
105 if [ -f "$LIBCRYPTOSO" -a -z "$preload_var" ]; then
106 # Following three lines are major excuse for isolating them into
107 # this wrapper script. Original reason for setting LD_PRELOAD
108 # was to make it possible to pass 'make test' when user linked
109 # with -rpath pointing to previous version installation. Wrapping
110 # it into a script makes it possible to do so on multi-ABI
111 # platforms.
112 case "$SYSNAME" in
113 *BSD) LD_PRELOAD="$LIBCRYPTOSO:$LIBSSLSO" ;; # *BSD
114 *) LD_PRELOAD="$LIBCRYPTOSO $LIBSSLSO" ;; # SunOS, Linux, ELF HP-UX
115 esac
116 _RLD_LIST="$LIBCRYPTOSO:$LIBSSLSO:DEFAULT" # Tru64, o32 IRIX
117 DYLD_INSERT_LIBRARIES="$LIBCRYPTOSO:$LIBSSLSO" # MacOS X
118 export LD_PRELOAD _RLD_LIST DYLD_INSERT_LIBRARIES
119 fi
120 {- output_on() unless grep (/-rpath\b/, @{$config{LDFLAGS}}); ""; -}
121
122 cmd="$1"; [ -x "$cmd" ] || cmd="$cmd${EXE_EXT}"
123 shift
124 if [ $# -eq 0 ]; then
125 exec "$cmd" # old sh, such as Tru64 4.x, fails to expand empty "$@"
126 else
127 exec "$cmd" "$@"
128 fi