1# Copyright (C) 2004, 2005, 2007 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 19set orig_environment_saved 0 20set orig_ld_library_path_saved 0 21set orig_ld_run_path_saved 0 22set orig_shlib_path_saved 0 23set orig_ld_libraryn32_path_saved 0 24set orig_ld_library64_path_saved 0 25set orig_ld_library_path_32_saved 0 26set orig_ld_library_path_64_saved 0 27set orig_dyld_library_path_saved 0 28set orig_path_saved 0 29 30####################################### 31# proc set_ld_library_path_env_vars { } 32####################################### 33 34proc 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_libraryn32_path_saved 41 global orig_ld_library64_path_saved 42 global orig_ld_library_path_32_saved 43 global orig_ld_library_path_64_saved 44 global orig_dyld_library_path_saved 45 global orig_path_saved 46 global orig_ld_library_path 47 global orig_ld_run_path 48 global orig_shlib_path 49 global orig_ld_libraryn32_path 50 global orig_ld_library64_path 51 global orig_ld_library_path_32 52 global orig_ld_library_path_64 53 global orig_dyld_library_path 54 global orig_path 55 global GCC_EXEC_PREFIX 56 57 # Set the relocated compiler prefix, but only if the user hasn't specified one. 58 if { [info exists GCC_EXEC_PREFIX] && ![info exists env(GCC_EXEC_PREFIX)] } { 59 setenv GCC_EXEC_PREFIX "$GCC_EXEC_PREFIX" 60 } 61 62 # Setting the ld library path causes trouble when testing cross-compilers. 63 if { [is_remote target] } { 64 return 65 } 66 67 if { $orig_environment_saved == 0 } { 68 global env 69 70 set orig_environment_saved 1 71 72 # Save the original environment. 73 if [info exists env(LD_LIBRARY_PATH)] { 74 set orig_ld_library_path "$env(LD_LIBRARY_PATH)" 75 set orig_ld_library_path_saved 1 76 } 77 if [info exists env(LD_RUN_PATH)] { 78 set orig_ld_run_path "$env(LD_RUN_PATH)" 79 set orig_ld_run_path_saved 1 80 } 81 if [info exists env(SHLIB_PATH)] { 82 set orig_shlib_path "$env(SHLIB_PATH)" 83 set orig_shlib_path_saved 1 84 } 85 if [info exists env(LD_LIBRARYN32_PATH)] { 86 set orig_ld_libraryn32_path "$env(LD_LIBRARYN32_PATH)" 87 set orig_ld_libraryn32_path_saved 1 88 } 89 if [info exists env(LD_LIBRARY64_PATH)] { 90 set orig_ld_library64_path "$env(LD_LIBRARY64_PATH)" 91 set orig_ld_library64_path_saved 1 92 } 93 if [info exists env(LD_LIBRARY_PATH_32)] { 94 set orig_ld_library_path_32 "$env(LD_LIBRARY_PATH_32)" 95 set orig_ld_library_path_32_saved 1 96 } 97 if [info exists env(LD_LIBRARY_PATH_64)] { 98 set orig_ld_library_path_64 "$env(LD_LIBRARY_PATH_64)" 99 set orig_ld_library_path_64_saved 1 100 } 101 if [info exists env(DYLD_LIBRARY_PATH)] { 102 set orig_dyld_library_path "$env(DYLD_LIBRARY_PATH)" 103 set orig_dyld_library_path_saved 1 104 } 105 if [info exists env(PATH)] { 106 set orig_path "$env(PATH)" 107 set orig_path_saved 1 108 } 109 } 110 111 # We need to set ld library path in the environment. Currently, 112 # unix.exp doesn't set the environment correctly for all systems. 113 # It only sets SHLIB_PATH and LD_LIBRARY_PATH when it executes a 114 # program. We also need the environment set for compilations, etc. 115 # 116 # On IRIX 6, we have to set variables akin to LD_LIBRARY_PATH, but 117 # called LD_LIBRARYN32_PATH (for the N32 ABI) and LD_LIBRARY64_PATH 118 # (for the 64-bit ABI). The same applies to Darwin (DYLD_LIBRARY_PATH), 119 # Solaris 32 bit (LD_LIBRARY_PATH_32), Solaris 64 bit (LD_LIBRARY_PATH_64), 120 # and HP-UX (SHLIB_PATH). In some cases, the variables are independent 121 # of LD_LIBRARY_PATH, and in other cases LD_LIBRARY_PATH is used if the 122 # variable is not defined. 123 # 124 # Doing this is somewhat of a hack as ld_library_path gets repeated in 125 # SHLIB_PATH and LD_LIBRARY_PATH when unix_load sets these variables. 126 if { $orig_ld_library_path_saved } { 127 setenv LD_LIBRARY_PATH "$ld_library_path:$orig_ld_library_path" 128 } else { 129 setenv LD_LIBRARY_PATH "$ld_library_path" 130 } 131 if { $orig_ld_run_path_saved } { 132 setenv LD_RUN_PATH "$ld_library_path:$orig_ld_run_path" 133 } else { 134 setenv LD_RUN_PATH "$ld_library_path" 135 } 136 # The default shared library dynamic path search for 64-bit 137 # HP-UX executables searches LD_LIBRARY_PATH before SHLIB_PATH. 138 # LD_LIBRARY_PATH isn't used for 32-bit executables. Thus, we 139 # set LD_LIBRARY_PATH and SHLIB_PATH as if they were independent. 140 if { $orig_shlib_path_saved } { 141 setenv SHLIB_PATH "$ld_library_path:$orig_shlib_path" 142 } else { 143 setenv SHLIB_PATH "$ld_library_path" 144 } 145 if { $orig_ld_libraryn32_path_saved } { 146 setenv LD_LIBRARYN32_PATH "$ld_library_path:$orig_ld_libraryn32_path" 147 } elseif { $orig_ld_library_path_saved } { 148 setenv LD_LIBRARYN32_PATH "$ld_library_path:$orig_ld_library_path" 149 } else { 150 setenv LD_LIBRARYN32_PATH "$ld_library_path" 151 } 152 if { $orig_ld_library64_path_saved } { 153 setenv LD_LIBRARY64_PATH "$ld_library_path:$orig_ld_library64_path" 154 } elseif { $orig_ld_library_path_saved } { 155 setenv LD_LIBRARY64_PATH "$ld_library_path:$orig_ld_library_path" 156 } else { 157 setenv LD_LIBRARY64_PATH "$ld_library_path" 158 } 159 if { $orig_ld_library_path_32_saved } { 160 setenv LD_LIBRARY_PATH_32 "$ld_library_path:$orig_ld_library_path_32" 161 } elseif { $orig_ld_library_path_saved } { 162 setenv LD_LIBRARY_PATH_32 "$ld_library_path:$orig_ld_library_path" 163 } else { 164 setenv LD_LIBRARY_PATH_32 "$ld_library_path" 165 } 166 if { $orig_ld_library_path_64_saved } { 167 setenv LD_LIBRARY_PATH_64 "$ld_library_path:$orig_ld_library_path_64" 168 } elseif { $orig_ld_library_path_saved } { 169 setenv LD_LIBRARY_PATH_64 "$ld_library_path:$orig_ld_library_path" 170 } else { 171 setenv LD_LIBRARY_PATH_64 "$ld_library_path" 172 } 173 if { $orig_dyld_library_path_saved } { 174 setenv DYLD_LIBRARY_PATH "$ld_library_path:$orig_dyld_library_path" 175 } else { 176 setenv DYLD_LIBRARY_PATH "$ld_library_path" 177 } 178 if { [istarget *-*-cygwin*] || [istarget *-*-mingw*] } { 179 if { $orig_path_saved } { 180 setenv PATH "$ld_library_path:$orig_path" 181 } else { 182 setenv PATH "$ld_library_path" 183 } 184 } 185 186 verbose -log "set_ld_library_path_env_vars: ld_library_path=$ld_library_path" 187} 188 189####################################### 190# proc restore_ld_library_path_env_vars { } 191####################################### 192 193proc restore_ld_library_path_env_vars { } { 194 global orig_environment_saved 195 global orig_ld_library_path_saved 196 global orig_ld_run_path_saved 197 global orig_shlib_path_saved 198 global orig_ld_libraryn32_path_saved 199 global orig_ld_library64_path_saved 200 global orig_ld_library_path_32_saved 201 global orig_ld_library_path_64_saved 202 global orig_dyld_library_path_saved 203 global orig_path_saved 204 global orig_ld_library_path 205 global orig_ld_run_path 206 global orig_shlib_path 207 global orig_ld_libraryn32_path 208 global orig_ld_library64_path 209 global orig_ld_library_path_32 210 global orig_ld_library_path_64 211 global orig_dyld_library_path 212 global orig_path 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_libraryn32_path_saved } { 234 setenv LD_LIBRARYN32_PATH "$orig_ld_libraryn32_path" 235 } elseif [info exists env(LD_LIBRARYN32_PATH)] { 236 unsetenv LD_LIBRARYN32_PATH 237 } 238 if { $orig_ld_library64_path_saved } { 239 setenv LD_LIBRARY64_PATH "$orig_ld_library64_path" 240 } elseif [info exists env(LD_LIBRARY64_PATH)] { 241 unsetenv LD_LIBRARY64_PATH 242 } 243 if { $orig_ld_library_path_32_saved } { 244 setenv LD_LIBRARY_PATH_32 "$orig_ld_library_path_32" 245 } elseif [info exists env(LD_LIBRARY_PATH_32)] { 246 unsetenv LD_LIBRARY_PATH_32 247 } 248 if { $orig_ld_library_path_64_saved } { 249 setenv LD_LIBRARY_PATH_64 "$orig_ld_library_path_64" 250 } elseif [info exists env(LD_LIBRARY_PATH_64)] { 251 unsetenv LD_LIBRARY_PATH_64 252 } 253 if { $orig_dyld_library_path_saved } { 254 setenv DYLD_LIBRARY_PATH "$orig_dyld_library_path" 255 } elseif [info exists env(DYLD_LIBRARY_PATH)] { 256 unsetenv DYLD_LIBRARY_PATH 257 } 258 if { $orig_path_saved } { 259 setenv PATH "$orig_path" 260 } elseif [info exists env(PATH)] { 261 unsetenv PATH 262 } 263} 264 265####################################### 266# proc get_shlib_extension { } 267####################################### 268 269proc get_shlib_extension { } { 270 global shlib_ext 271 272 if { [ istarget *-*-darwin* ] } { 273 set shlib_ext "dylib" 274 } elseif { [ istarget *-*-cygwin* ] || [ istarget *-*-mingw* ] } { 275 set shlib_ext "dll" 276 } elseif { [ istarget hppa*-*-hpux* ] } { 277 set shlib_ext "sl" 278 } else { 279 set shlib_ext "so" 280 } 281 return $shlib_ext 282} 283 284