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