1 # Copyright (C) 2004, 2005, 2007, 2009 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 # A list of ld library path environment variables that might need to be
22 # Some variables represent ABI-specific paths, and if these variables
23 # aren't defined, the dynamic loader might fall back on a more general
24 # variable. We must do the same when trying to read the current setting
25 # of such a path. Each element of this list is therefore itself a list:
26 # the first element of each sublist specifies the name of the variable,
27 # and the other elements specify fallback alternatives. We use FOO as a
28 # shorthand for { FOO }.
29 set ld_library_path_vars {
33 { LD_LIBRARYN32_PATH LD_LIBRARY_PATH }
34 { LD_LIBRARY64_PATH LD_LIBRARY_PATH }
35 { LD_LIBRARY_PATH_32 LD_LIBRARY_PATH }
36 { LD_LIBRARY_PATH_64 LD_LIBRARY_PATH }
40 # Set up the global orig_FOO_saved variables. We define this as a function
41 # to avoid polluting the global namespace with local variables.
42 proc init_ld_library_path_env_vars { } {
43 global ld_library_path_vars
45 foreach spec $ld_library_path_vars {
46 set var orig_[string tolower [lindex $spec 0]]_saved
51 init_ld_library_path_env_vars
52 set orig_environment_saved 0
53 set orig_gcc_exec_prefix_saved 0
54 set orig_gcc_exec_prefix_checked 0
55 set ld_library_path_multilib unset
57 #######################################
58 # proc set_ld_library_path_env_vars { }
59 #######################################
61 proc set_ld_library_path_env_vars { } {
62 global ld_library_path
63 global orig_environment_saved
64 global ld_library_path_vars
65 global orig_gcc_exec_prefix_saved
66 global orig_gcc_exec_prefix_checked
67 global orig_gcc_exec_prefix
68 global TEST_GCC_EXEC_PREFIX
69 global ld_library_path_multilib
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
78 set orig_gcc_exec_prefix_checked 1
81 # Set GCC_EXEC_PREFIX for the compiler under test to pick up files not in
82 # the build tree from a specified location (normally the install tree).
83 if [info exists TEST_GCC_EXEC_PREFIX] {
84 setenv GCC_EXEC_PREFIX "$TEST_GCC_EXEC_PREFIX"
87 # Setting the ld library path causes trouble when testing cross-compilers.
88 if { [is_remote target] } {
92 set ld_library_path_multilib [board_info target multilib_flags]
94 foreach spec $ld_library_path_vars {
95 set var [lindex $spec 0]
96 set lvar [string tolower $var]
99 global orig_${lvar}_saved
101 if { $orig_environment_saved == 0 } {
102 if [info exists env($var)] {
103 set orig_$lvar [set env($var)]
104 set orig_${lvar}_saved 1
107 set value $ld_library_path
108 foreach extra $spec {
109 set lextra [string tolower $extra]
110 if [set orig_${lextra}_saved] {
111 add_path value [set orig_$lextra]
117 set orig_environment_saved 1
118 verbose -log "set_ld_library_path_env_vars: ld_library_path=$ld_library_path"
121 #######################################
122 # proc restore_ld_library_path_env_vars { }
123 #######################################
125 proc restore_ld_library_path_env_vars { } {
126 global orig_environment_saved
127 global ld_library_path_vars
128 global orig_gcc_exec_prefix_saved
129 global orig_gcc_exec_prefix
132 if { $orig_gcc_exec_prefix_saved } {
133 setenv GCC_EXEC_PREFIX "$orig_gcc_exec_prefix"
134 } elseif [info exists env(GCC_EXEC_PREFIX)] {
135 unsetenv GCC_EXEC_PREFIX
138 if { $orig_environment_saved == 0 } {
142 foreach spec $ld_library_path_vars {
143 set var [lindex $spec 0]
144 set lvar [string tolower $var]
147 global orig_${lvar}_saved
149 if [set orig_${lvar}_saved] {
150 setenv $var [set orig_$lvar]
151 } elseif [info exists env($var)] {
157 #######################################
158 # proc get_shlib_extension { }
159 #######################################
161 proc get_shlib_extension { } {
164 if { [ istarget *-*-darwin* ] } {
165 set shlib_ext "dylib"
166 } elseif { [ istarget *-*-cygwin* ] || [ istarget *-*-mingw* ] } {
168 } elseif { [ istarget hppa*-*-hpux* ] } {
176 # If DIR is not an empty string, add it to the end of variable UPPATH,
177 # which represents a colon-separated path.
178 proc add_path { uppath dir } {
182 if { [info exists path] && $path != "" } {
189 # Return the directory that contains the shared libgcc for this multilib,
190 # or "" if we don't know.
191 proc find_libgcc_s { compiler } {
192 # Remote host testing requires an installed compiler (get_multilibs
193 # imposes the same restriction). It is up to the board file or
194 # tester to make sure that the installed compiler's libraries
195 # can be found in the library path.
196 if { [is_remote host] } {
199 # The same goes if we can't find the compiler.
200 set compiler_path [which [lindex $compiler 0]]
201 if { $compiler_path == "" } {
204 # Run the compiler with the current multilib flags to get the
205 # relative multilib directory.
206 set subdir [eval exec $compiler [board_info target multilib_flags] \
207 --print-multi-directory]
208 # We are only interested in cases where libgcc_s is in the same
209 # directory as the compiler itself.
210 set dir [file dirname $compiler_path]
211 if { $subdir != "." } {
212 set dir [file join $dir $subdir]
214 if { ![file exists $dir] } {