Reverting merge from trunk
[official-gcc.git] / gcc / testsuite / lib / target-libpath.exp
blobd6ad01388400e3b1f6fc58da473dd0af0a46adfc
1 # Copyright (C) 2004-2013 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with GCC; see the file COPYING3. If not see
15 # <http://www.gnu.org/licenses/>.
17 # This file was contributed by John David Anglin (dave.anglin@nrc-cnrc.gc.ca)
19 set orig_environment_saved 0
20 set orig_ld_library_path_saved 0
21 set orig_ld_run_path_saved 0
22 set orig_shlib_path_saved 0
23 set orig_ld_library_path_32_saved 0
24 set orig_ld_library_path_64_saved 0
25 set orig_dyld_library_path_saved 0
26 set orig_gcc_exec_prefix_saved 0
27 set orig_gcc_exec_prefix_checked 0
30 #######################################
31 # proc set_ld_library_path_env_vars { }
32 #######################################
34 proc set_ld_library_path_env_vars { } {
35 global ld_library_path
36 global orig_environment_saved
37 global orig_ld_library_path_saved
38 global orig_ld_run_path_saved
39 global orig_shlib_path_saved
40 global orig_ld_library_path_32_saved
41 global orig_ld_library_path_64_saved
42 global orig_dyld_library_path_saved
43 global orig_gcc_exec_prefix_saved
44 global orig_gcc_exec_prefix_checked
45 global orig_ld_library_path
46 global orig_ld_run_path
47 global orig_shlib_path
48 global orig_ld_library_path_32
49 global orig_ld_library_path_64
50 global orig_dyld_library_path
51 global orig_gcc_exec_prefix
52 global TEST_GCC_EXEC_PREFIX
53 global env
55 # Save the original GCC_EXEC_PREFIX.
56 if { $orig_gcc_exec_prefix_checked == 0 } {
57 if [info exists env(GCC_EXEC_PREFIX)] {
58 set orig_gcc_exec_prefix "$env(GCC_EXEC_PREFIX)"
59 set orig_gcc_exec_prefix_saved 1
61 set orig_gcc_exec_prefix_checked 1
64 # Set GCC_EXEC_PREFIX for the compiler under test to pick up files not in
65 # the build tree from a specified location (normally the install tree).
66 if [info exists TEST_GCC_EXEC_PREFIX] {
67 setenv GCC_EXEC_PREFIX "$TEST_GCC_EXEC_PREFIX"
70 # Setting the ld library path causes trouble when testing cross-compilers.
71 if { [is_remote target] } {
72 return
75 if { $orig_environment_saved == 0 } {
76 set orig_environment_saved 1
78 # Save the original environment.
79 if [info exists env(LD_LIBRARY_PATH)] {
80 set orig_ld_library_path "$env(LD_LIBRARY_PATH)"
81 set orig_ld_library_path_saved 1
83 if [info exists env(LD_RUN_PATH)] {
84 set orig_ld_run_path "$env(LD_RUN_PATH)"
85 set orig_ld_run_path_saved 1
87 if [info exists env(SHLIB_PATH)] {
88 set orig_shlib_path "$env(SHLIB_PATH)"
89 set orig_shlib_path_saved 1
91 if [info exists env(LD_LIBRARY_PATH_32)] {
92 set orig_ld_library_path_32 "$env(LD_LIBRARY_PATH_32)"
93 set orig_ld_library_path_32_saved 1
95 if [info exists env(LD_LIBRARY_PATH_64)] {
96 set orig_ld_library_path_64 "$env(LD_LIBRARY_PATH_64)"
97 set orig_ld_library_path_64_saved 1
99 if [info exists env(DYLD_LIBRARY_PATH)] {
100 set orig_dyld_library_path "$env(DYLD_LIBRARY_PATH)"
101 set orig_dyld_library_path_saved 1
105 # We need to set ld library path in the environment. Currently,
106 # unix.exp doesn't set the environment correctly for all systems.
107 # It only sets SHLIB_PATH and LD_LIBRARY_PATH when it executes a
108 # program. We also need the environment set for compilations, etc.
110 # On Darwin, we have to set variables akin to LD_LIBRARY_PATH, but called
111 # DYLD_LIBRARY_PATH. The same applies to Solaris 32 bit
112 # (LD_LIBRARY_PATH_32), Solaris 64 bit (LD_LIBRARY_PATH_64), and HP-UX
113 # (SHLIB_PATH). In some cases, the variables are independent of
114 # LD_LIBRARY_PATH, and in other cases LD_LIBRARY_PATH is used if the
115 # variable is not defined.
117 # Doing this is somewhat of a hack as ld_library_path gets repeated in
118 # SHLIB_PATH and LD_LIBRARY_PATH when unix_load sets these variables.
119 if { $orig_ld_library_path_saved } {
120 setenv LD_LIBRARY_PATH "$ld_library_path:$orig_ld_library_path"
121 } else {
122 setenv LD_LIBRARY_PATH "$ld_library_path"
124 if { $orig_ld_run_path_saved } {
125 setenv LD_RUN_PATH "$ld_library_path:$orig_ld_run_path"
126 } else {
127 setenv LD_RUN_PATH "$ld_library_path"
129 # The default shared library dynamic path search for 64-bit
130 # HP-UX executables searches LD_LIBRARY_PATH before SHLIB_PATH.
131 # LD_LIBRARY_PATH isn't used for 32-bit executables. Thus, we
132 # set LD_LIBRARY_PATH and SHLIB_PATH as if they were independent.
133 if { $orig_shlib_path_saved } {
134 setenv SHLIB_PATH "$ld_library_path:$orig_shlib_path"
135 } else {
136 setenv SHLIB_PATH "$ld_library_path"
138 if { $orig_ld_library_path_32_saved } {
139 setenv LD_LIBRARY_PATH_32 "$ld_library_path:$orig_ld_library_path_32"
140 } elseif { $orig_ld_library_path_saved } {
141 setenv LD_LIBRARY_PATH_32 "$ld_library_path:$orig_ld_library_path"
142 } else {
143 setenv LD_LIBRARY_PATH_32 "$ld_library_path"
145 if { $orig_ld_library_path_64_saved } {
146 setenv LD_LIBRARY_PATH_64 "$ld_library_path:$orig_ld_library_path_64"
147 } elseif { $orig_ld_library_path_saved } {
148 setenv LD_LIBRARY_PATH_64 "$ld_library_path:$orig_ld_library_path"
149 } else {
150 setenv LD_LIBRARY_PATH_64 "$ld_library_path"
152 if { $orig_dyld_library_path_saved } {
153 setenv DYLD_LIBRARY_PATH "$ld_library_path:$orig_dyld_library_path"
154 } else {
155 setenv DYLD_LIBRARY_PATH "$ld_library_path"
158 verbose -log "set_ld_library_path_env_vars: ld_library_path=$ld_library_path"
161 #######################################
162 # proc restore_ld_library_path_env_vars { }
163 #######################################
165 proc restore_ld_library_path_env_vars { } {
166 global orig_environment_saved
167 global orig_ld_library_path_saved
168 global orig_ld_run_path_saved
169 global orig_shlib_path_saved
170 global orig_ld_library_path_32_saved
171 global orig_ld_library_path_64_saved
172 global orig_dyld_library_path_saved
173 global orig_gcc_exec_prefix_saved
174 global orig_ld_library_path
175 global orig_ld_run_path
176 global orig_shlib_path
177 global orig_ld_library_path_32
178 global orig_ld_library_path_64
179 global orig_dyld_library_path
180 global orig_gcc_exec_prefix
181 global env
183 if { $orig_gcc_exec_prefix_saved } {
184 setenv GCC_EXEC_PREFIX "$orig_gcc_exec_prefix"
185 } elseif [info exists env(GCC_EXEC_PREFIX)] {
186 unsetenv GCC_EXEC_PREFIX
189 if { $orig_environment_saved == 0 } {
190 return
193 if { $orig_ld_library_path_saved } {
194 setenv LD_LIBRARY_PATH "$orig_ld_library_path"
195 } elseif [info exists env(LD_LIBRARY_PATH)] {
196 unsetenv LD_LIBRARY_PATH
198 if { $orig_ld_run_path_saved } {
199 setenv LD_RUN_PATH "$orig_ld_run_path"
200 } elseif [info exists env(LD_RUN_PATH)] {
201 unsetenv LD_RUN_PATH
203 if { $orig_shlib_path_saved } {
204 setenv SHLIB_PATH "$orig_shlib_path"
205 } elseif [info exists env(SHLIB_PATH)] {
206 unsetenv SHLIB_PATH
208 if { $orig_ld_library_path_32_saved } {
209 setenv LD_LIBRARY_PATH_32 "$orig_ld_library_path_32"
210 } elseif [info exists env(LD_LIBRARY_PATH_32)] {
211 unsetenv LD_LIBRARY_PATH_32
213 if { $orig_ld_library_path_64_saved } {
214 setenv LD_LIBRARY_PATH_64 "$orig_ld_library_path_64"
215 } elseif [info exists env(LD_LIBRARY_PATH_64)] {
216 unsetenv LD_LIBRARY_PATH_64
218 if { $orig_dyld_library_path_saved } {
219 setenv DYLD_LIBRARY_PATH "$orig_dyld_library_path"
220 } elseif [info exists env(DYLD_LIBRARY_PATH)] {
221 unsetenv DYLD_LIBRARY_PATH
225 #######################################
226 # proc get_shlib_extension { }
227 #######################################
229 proc get_shlib_extension { } {
230 global shlib_ext
232 if { [istarget *-*-darwin*] } {
233 set shlib_ext "dylib"
234 } elseif { [istarget *-*-cygwin*] || [istarget *-*-mingw*] } {
235 set shlib_ext "dll"
236 } elseif { [istarget hppa*-*-hpux*] } {
237 set shlib_ext "sl"
238 } else {
239 set shlib_ext "so"
241 return $shlib_ext