OSDN Git Service

49accd09687f59af270ad9bc9304fafdadeabf96
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / lib / target-libpath.exp
1 # Copyright (C) 2004, 2005, 2007, 2009 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 # A list of ld library path environment variables that might need to be
20 # defined.
21 #
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 {
30     LD_LIBRARY_PATH
31     LD_RUN_PATH
32     SHLIB_PATH
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 }
37     DYLD_LIBRARY_PATH
38 }
39
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
44
45     foreach spec $ld_library_path_vars {
46         set var orig_[string tolower [lindex $spec 0]]_saved
47         global $var
48         set $var 0
49     }
50 }
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
56
57 #######################################
58 # proc set_ld_library_path_env_vars { }
59 #######################################
60
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
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 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"
85     }
86
87     # Setting the ld library path causes trouble when testing cross-compilers.
88     if { [is_remote target] } {
89         return
90     }
91
92     set ld_library_path_multilib [board_info target multilib_flags]
93
94     foreach spec $ld_library_path_vars {
95         set var [lindex $spec 0]
96         set lvar [string tolower $var]
97
98         global orig_$lvar
99         global orig_${lvar}_saved
100
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
105             }
106         }
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]
112                 break
113             }
114         }
115         setenv $var $value
116     }
117     set orig_environment_saved 1
118     verbose -log "set_ld_library_path_env_vars: ld_library_path=$ld_library_path"
119 }
120
121 #######################################
122 # proc restore_ld_library_path_env_vars { }
123 #######################################
124
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
130     global env
131
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
136     }
137
138     if { $orig_environment_saved == 0 } {
139         return
140     }
141
142     foreach spec $ld_library_path_vars {
143         set var [lindex $spec 0]
144         set lvar [string tolower $var]
145
146         global orig_$lvar
147         global orig_${lvar}_saved
148
149         if [set orig_${lvar}_saved] {
150             setenv $var [set orig_$lvar]
151         } elseif [info exists env($var)] {
152             unsetenv $var
153         }
154     }
155 }
156
157 #######################################
158 # proc get_shlib_extension { }
159 #######################################
160
161 proc get_shlib_extension { } {
162     global shlib_ext
163
164     if { [ istarget *-*-darwin* ] } {
165         set shlib_ext "dylib"
166     } elseif { [ istarget *-*-cygwin* ] || [ istarget *-*-mingw* ] } {
167         set shlib_ext "dll"
168     } elseif { [ istarget hppa*-*-hpux* ] } {
169         set shlib_ext "sl"
170     } else {
171         set shlib_ext "so"
172     }
173     return $shlib_ext
174 }
175
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 } {
179     upvar $uppath path
180
181     if { $dir != "" } {
182         if { [info exists path] && $path != "" } {
183             append path ":"
184         }
185         append path $dir
186     }
187 }
188
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] } {
197         return ""
198     }
199     # The same goes if we can't find the compiler.
200     set compiler_path [which [lindex $compiler 0]]
201     if { $compiler_path == "" } {
202         return ""
203     }
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]
213     }
214     if { ![file exists $dir] } {
215         return ""
216     }
217     return $dir
218 }