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