]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/lib/target-libpath.exp
Update copyright years.
[thirdparty/gcc.git] / gcc / testsuite / lib / target-libpath.exp
1 # Copyright (C) 2004-2021 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.
16
17 # This file was contributed by John David Anglin (dave.anglin@nrc-cnrc.gc.ca)
18
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_path_saved 0
27 set orig_gcc_exec_prefix_saved 0
28 set orig_gcc_exec_prefix_checked 0
29
30
31 #######################################
32 # proc set_gcc_exec_prefix_env_var { }
33 #######################################
34
35 proc set_gcc_exec_prefix_env_var { } {
36 global TEST_GCC_EXEC_PREFIX
37 global env
38
39 # Set GCC_EXEC_PREFIX for the compiler under test to pick up files not in
40 # the build tree from a specified location (normally the install tree).
41 if [info exists TEST_GCC_EXEC_PREFIX] {
42 setenv GCC_EXEC_PREFIX "$TEST_GCC_EXEC_PREFIX"
43 }
44 }
45
46 #######################################
47 # proc set_ld_library_path_env_vars { }
48 #######################################
49
50 proc set_ld_library_path_env_vars { } {
51 global ld_library_path
52 global orig_environment_saved
53 global orig_ld_library_path_saved
54 global orig_ld_run_path_saved
55 global orig_shlib_path_saved
56 global orig_ld_library_path_32_saved
57 global orig_ld_library_path_64_saved
58 global orig_dyld_library_path_saved
59 global orig_path_saved
60 global orig_gcc_exec_prefix_saved
61 global orig_gcc_exec_prefix_checked
62 global orig_ld_library_path
63 global orig_ld_run_path
64 global orig_shlib_path
65 global orig_ld_library_path_32
66 global orig_ld_library_path_64
67 global orig_dyld_library_path
68 global orig_path
69 global orig_gcc_exec_prefix
70 global env
71
72 # Save the original GCC_EXEC_PREFIX.
73 if { $orig_gcc_exec_prefix_checked == 0 } {
74 if [info exists env(GCC_EXEC_PREFIX)] {
75 set orig_gcc_exec_prefix "$env(GCC_EXEC_PREFIX)"
76 set orig_gcc_exec_prefix_saved 1
77 }
78 set orig_gcc_exec_prefix_checked 1
79 }
80
81 set_gcc_exec_prefix_env_var
82
83 # Setting the ld library path causes trouble when testing cross-compilers.
84 if { [is_remote target] } {
85 return
86 }
87
88 if { $orig_environment_saved == 0 } {
89 set orig_environment_saved 1
90
91 # Save the original environment.
92 if [info exists env(LD_LIBRARY_PATH)] {
93 set orig_ld_library_path "$env(LD_LIBRARY_PATH)"
94 set orig_ld_library_path_saved 1
95 }
96 if [info exists env(LD_RUN_PATH)] {
97 set orig_ld_run_path "$env(LD_RUN_PATH)"
98 set orig_ld_run_path_saved 1
99 }
100 if [info exists env(SHLIB_PATH)] {
101 set orig_shlib_path "$env(SHLIB_PATH)"
102 set orig_shlib_path_saved 1
103 }
104 if [info exists env(LD_LIBRARY_PATH_32)] {
105 set orig_ld_library_path_32 "$env(LD_LIBRARY_PATH_32)"
106 set orig_ld_library_path_32_saved 1
107 }
108 if [info exists env(LD_LIBRARY_PATH_64)] {
109 set orig_ld_library_path_64 "$env(LD_LIBRARY_PATH_64)"
110 set orig_ld_library_path_64_saved 1
111 }
112 if [info exists env(DYLD_LIBRARY_PATH)] {
113 set orig_dyld_library_path "$env(DYLD_LIBRARY_PATH)"
114 set orig_dyld_library_path_saved 1
115 }
116 if [info exists env(PATH)] {
117 set orig_path "$env(PATH)"
118 set orig_path_saved 1
119 }
120 }
121
122 # We need to set ld library path in the environment. Currently,
123 # unix.exp doesn't set the environment correctly for all systems.
124 # It only sets SHLIB_PATH and LD_LIBRARY_PATH when it executes a
125 # program. We also need the environment set for compilations, etc.
126 #
127 # On Darwin, we have to set variables akin to LD_LIBRARY_PATH, but called
128 # DYLD_LIBRARY_PATH. The same applies to Solaris 32 bit
129 # (LD_LIBRARY_PATH_32), Solaris 64 bit (LD_LIBRARY_PATH_64), and HP-UX
130 # (SHLIB_PATH). In some cases, the variables are independent of
131 # LD_LIBRARY_PATH, and in other cases LD_LIBRARY_PATH is used if the
132 # variable is not defined.
133 #
134 # Doing this is somewhat of a hack as ld_library_path gets repeated in
135 # SHLIB_PATH and LD_LIBRARY_PATH when unix_load sets these variables.
136 if { $orig_ld_library_path_saved } {
137 setenv LD_LIBRARY_PATH "$ld_library_path:$orig_ld_library_path"
138 } else {
139 setenv LD_LIBRARY_PATH "$ld_library_path"
140 }
141 if { $orig_ld_run_path_saved } {
142 setenv LD_RUN_PATH "$ld_library_path:$orig_ld_run_path"
143 } else {
144 setenv LD_RUN_PATH "$ld_library_path"
145 }
146 # The default shared library dynamic path search for 64-bit
147 # HP-UX executables searches LD_LIBRARY_PATH before SHLIB_PATH.
148 # LD_LIBRARY_PATH isn't used for 32-bit executables. Thus, we
149 # set LD_LIBRARY_PATH and SHLIB_PATH as if they were independent.
150 if { $orig_shlib_path_saved } {
151 setenv SHLIB_PATH "$ld_library_path:$orig_shlib_path"
152 } else {
153 setenv SHLIB_PATH "$ld_library_path"
154 }
155 if { $orig_ld_library_path_32_saved } {
156 setenv LD_LIBRARY_PATH_32 "$ld_library_path:$orig_ld_library_path_32"
157 } elseif { $orig_ld_library_path_saved } {
158 setenv LD_LIBRARY_PATH_32 "$ld_library_path:$orig_ld_library_path"
159 } else {
160 setenv LD_LIBRARY_PATH_32 "$ld_library_path"
161 }
162 if { $orig_ld_library_path_64_saved } {
163 setenv LD_LIBRARY_PATH_64 "$ld_library_path:$orig_ld_library_path_64"
164 } elseif { $orig_ld_library_path_saved } {
165 setenv LD_LIBRARY_PATH_64 "$ld_library_path:$orig_ld_library_path"
166 } else {
167 setenv LD_LIBRARY_PATH_64 "$ld_library_path"
168 }
169 if { $orig_dyld_library_path_saved } {
170 setenv DYLD_LIBRARY_PATH "$ld_library_path:$orig_dyld_library_path"
171 } else {
172 setenv DYLD_LIBRARY_PATH "$ld_library_path"
173 }
174 if { [istarget *-*-cygwin*] || [istarget *-*-mingw*] } {
175 if { $orig_path_saved } {
176 setenv PATH "$ld_library_path:$orig_path"
177 } else {
178 setenv PATH "$ld_library_path"
179 }
180 }
181
182 verbose -log "LD_LIBRARY_PATH=[getenv LD_LIBRARY_PATH]"
183 verbose -log "LD_RUN_PATH=[getenv LD_RUN_PATH]"
184 verbose -log "SHLIB_PATH=[getenv SHLIB_PATH]"
185 verbose -log "LD_LIBRARY_PATH_32=[getenv LD_LIBRARY_PATH_32]"
186 verbose -log "LD_LIBRARY_PATH_64=[getenv LD_LIBRARY_PATH_64]"
187 verbose -log "DYLD_LIBRARY_PATH=[getenv DYLD_LIBRARY_PATH]"
188 }
189
190 #######################################
191 # proc restore_gcc_exec_prefix_env_var { }
192 #######################################
193
194 proc restore_gcc_exec_prefix_env_var { } {
195 global orig_gcc_exec_prefix_saved
196 global orig_gcc_exec_prefix
197 global env
198
199 if { $orig_gcc_exec_prefix_saved } {
200 setenv GCC_EXEC_PREFIX "$orig_gcc_exec_prefix"
201 } elseif [info exists env(GCC_EXEC_PREFIX)] {
202 unsetenv GCC_EXEC_PREFIX
203 }
204 }
205
206 #######################################
207 # proc restore_ld_library_path_env_vars { }
208 #######################################
209
210 proc restore_ld_library_path_env_vars { } {
211 global orig_environment_saved
212 global orig_ld_library_path_saved
213 global orig_ld_run_path_saved
214 global orig_shlib_path_saved
215 global orig_ld_library_path_32_saved
216 global orig_ld_library_path_64_saved
217 global orig_dyld_library_path_saved
218 global orig_path_saved
219 global orig_ld_library_path
220 global orig_ld_run_path
221 global orig_shlib_path
222 global orig_ld_library_path_32
223 global orig_ld_library_path_64
224 global orig_dyld_library_path
225 global orig_path
226 global env
227
228 restore_gcc_exec_prefix_env_var
229
230 if { $orig_environment_saved == 0 } {
231 return
232 }
233
234 if { $orig_ld_library_path_saved } {
235 setenv LD_LIBRARY_PATH "$orig_ld_library_path"
236 } elseif [info exists env(LD_LIBRARY_PATH)] {
237 unsetenv LD_LIBRARY_PATH
238 }
239 if { $orig_ld_run_path_saved } {
240 setenv LD_RUN_PATH "$orig_ld_run_path"
241 } elseif [info exists env(LD_RUN_PATH)] {
242 unsetenv LD_RUN_PATH
243 }
244 if { $orig_shlib_path_saved } {
245 setenv SHLIB_PATH "$orig_shlib_path"
246 } elseif [info exists env(SHLIB_PATH)] {
247 unsetenv SHLIB_PATH
248 }
249 if { $orig_ld_library_path_32_saved } {
250 setenv LD_LIBRARY_PATH_32 "$orig_ld_library_path_32"
251 } elseif [info exists env(LD_LIBRARY_PATH_32)] {
252 unsetenv LD_LIBRARY_PATH_32
253 }
254 if { $orig_ld_library_path_64_saved } {
255 setenv LD_LIBRARY_PATH_64 "$orig_ld_library_path_64"
256 } elseif [info exists env(LD_LIBRARY_PATH_64)] {
257 unsetenv LD_LIBRARY_PATH_64
258 }
259 if { $orig_dyld_library_path_saved } {
260 setenv DYLD_LIBRARY_PATH "$orig_dyld_library_path"
261 } elseif [info exists env(DYLD_LIBRARY_PATH)] {
262 unsetenv DYLD_LIBRARY_PATH
263 }
264 if { $orig_path_saved } {
265 setenv PATH "$orig_path"
266 } elseif [info exists env(PATH)] {
267 unsetenv PATH
268 }
269 }
270
271 #######################################
272 # proc get_shlib_extension { }
273 #######################################
274
275 proc get_shlib_extension { } {
276 global shlib_ext
277
278 if { [istarget *-*-darwin*] } {
279 set shlib_ext "dylib"
280 } elseif { [istarget *-*-cygwin*] || [istarget *-*-mingw*] } {
281 set shlib_ext "dll"
282 } elseif { [istarget hppa*-*-hpux*] } {
283 set shlib_ext "sl"
284 } else {
285 set shlib_ext "so"
286 }
287 return $shlib_ext
288 }
289