]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/lib/gnat.exp
gnat.exp: Handle multilib.
[thirdparty/gcc.git] / gcc / testsuite / lib / gnat.exp
1 # Copyright (C) 2006, 2007, 2008 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 written by James A. Morrison (ja2morri@uwaterloo.ca)
18 # based on gcc.exp written by Rob Savoye (rob@cygnus.com).
19
20 # This file is loaded by the tool init file (eg: unix.exp). It provides
21 # default definitions for gnat_start, etc. and other supporting cast members.
22
23 # These globals are used if no compiler arguments are provided.
24 # They are also used by the various testsuites to define the environment:
25 # where to find stdio.h, libc.a, etc.
26
27 load_lib libgloss.exp
28 load_lib prune.exp
29 load_lib gcc-defs.exp
30 load_lib timeout.exp
31
32 #
33 # GNAT_UNDER_TEST is the compiler under test.
34 #
35
36 #
37 # default_gnat_version -- extract and print the version number of the compiler
38 #
39
40 proc default_gnat_version { } {
41 global GNAT_UNDER_TEST
42
43 gnat_init
44
45 # ignore any arguments after the command
46 set compiler [lindex $GNAT_UNDER_TEST 0]
47
48 if ![is_remote host] {
49 set compiler_name [which $compiler]
50 } else {
51 set compiler_name $compiler
52 }
53
54 # verify that the compiler exists
55 if { $compiler_name != 0 } then {
56 set tmp [remote_exec host "$compiler -v"]
57 set status [lindex $tmp 0]
58 set output [lindex $tmp 1]
59 regexp " version \[^\n\r\]*" $output version
60 if { $status == 0 && [info exists version] } then {
61 clone_output "$compiler_name $version\n"
62 } else {
63 clone_output "Couldn't determine version of $compiler_name: $output\n"
64 }
65 } else {
66 # compiler does not exist (this should have already been detected)
67 warning "$compiler does not exist"
68 }
69 }
70
71 # gnat_init -- called at the start of each .exp script.
72 #
73 # There currently isn't much to do, but always using it allows us to
74 # make some enhancements without having to go back and rewrite the scripts.
75 #
76
77 set gnat_initialized 0
78
79 proc gnat_init { args } {
80 global rootme
81 global tmpdir
82 global libdir
83 global gluefile wrap_flags
84 global gnat_initialized
85 global GNAT_UNDER_TEST
86 global GNAT_UNDER_TEST_ORIG
87 global TOOL_EXECUTABLE
88 global gnat_libgcc_s_path
89 global gnat_target_current
90
91 set gnat_target_current ""
92
93 if { $gnat_initialized == 1 } { return }
94
95 if ![info exists GNAT_UNDER_TEST] then {
96 if [info exists TOOL_EXECUTABLE] {
97 set GNAT_UNDER_TEST "$TOOL_EXECUTABLE"
98 } else {
99 set GNAT_UNDER_TEST "[local_find_gnatmake]"
100 }
101 set GNAT_UNDER_TEST_ORIG "$GNAT_UNDER_TEST"
102 }
103
104 if ![info exists tmpdir] then {
105 set tmpdir /tmp
106 }
107
108 set gnat_libgcc_s_path "${rootme}"
109 # Leave this here since Ada should support multilibs at some point.
110 set compiler [lindex $GNAT_UNDER_TEST 0]
111 # if { [is_remote host] == 0 && [which $compiler] != 0 } {
112 # foreach i "[exec $compiler --print-multi-lib]" {
113 # set mldir ""
114 # regexp -- "\[a-z0-9=/\.-\]*;" $i mldir
115 # set mldir [string trimright $mldir "\;@"]
116 # if { "$mldir" == "." } {
117 # continue
118 # }
119 # if { [llength [glob -nocomplain ${rootme}/${mldir}/libgcc_s*.so.*]] >= 1 } {
120 # append gnat_libgcc_s_path ":${rootme}/${mldir}"
121 # }
122 # }
123 # }
124 }
125
126 proc gnat_target_compile { source dest type options } {
127 global rootme
128 global tmpdir
129 global gluefile wrap_flags
130 global srcdir
131 global GNAT_UNDER_TEST
132 global GNAT_UNDER_TEST_ORIG
133 global TOOL_OPTIONS
134 global ld_library_path
135 global gnat_libgcc_s_path
136 global gnat_target_current
137
138 # If we detect a change of target we need to recompute
139 # the appropriate RTS by calling get_multilibs.
140 if { $gnat_target_current!="[current_target_name]" } {
141 set gnat_target_current "[current_target_name]"
142 if [info exists TOOL_OPTIONS] {
143 set gnat_rts_opt "--RTS=[get_multilibs ${TOOL_OPTIONS}]/libada"
144 } else {
145 set gnat_rts_opt "--RTS=[get_multilibs]/libada"
146 }
147 set GNAT_UNDER_TEST "$GNAT_UNDER_TEST_ORIG $gnat_rts_opt"
148 }
149
150 set ld_library_path ".:${gnat_libgcc_s_path}"
151 lappend options "compiler=$GNAT_UNDER_TEST -q -f"
152 lappend options "timeout=[timeout_value]"
153
154 if { [target_info needs_status_wrapper]!="" && [info exists gluefile] } {
155 lappend options "libs=${gluefile}"
156 lappend options "ldflags=$wrap_flags"
157 }
158
159 # TOOL_OPTIONS must come first, so that it doesn't override testcase
160 # specific options.
161 if [info exists TOOL_OPTIONS] {
162 set options [concat "additional_flags=$TOOL_OPTIONS" $options]
163 }
164
165 # If we have built libada along with the compiler, point the test harness
166 # at it (and associated headers).
167
168 # set sourcename [string range $source 0 [expr [string length $source] - 5]]
169 # set dest ""
170
171 return [target_compile $source $dest $type $options]
172 }
173
174 #
175 # gnat_pass -- utility to record a testcase passed
176 #
177
178 proc gnat_pass { testcase cflags } {
179 if { "$cflags" == "" } {
180 pass "$testcase"
181 } else {
182 pass "$testcase, $cflags"
183 }
184 }
185
186 #
187 # gnat_fail -- utility to record a testcase failed
188 #
189
190 proc gnat_fail { testcase cflags } {
191 if { "$cflags" == "" } {
192 fail "$testcase"
193 } else {
194 fail "$testcase, $cflags"
195 }
196 }
197
198 #
199 # gnat_finish -- called at the end of every .exp script that calls gnat_init
200 #
201 # The purpose of this proc is to hide all quirks of the testing environment
202 # from the testsuites. It also exists to undo anything that gnat_init did
203 # (that needs undoing).
204 #
205
206 proc gnat_finish { } {
207 # The testing harness apparently requires this.
208 global errorInfo
209
210 if [info exists errorInfo] then {
211 unset errorInfo
212 }
213
214 # Might as well reset these (keeps our caller from wondering whether
215 # s/he has to or not).
216 global prms_id bug_id
217 set prms_id 0
218 set bug_id 0
219 }
220
221 proc gnat_exit { } {
222 global gluefile
223
224 if [info exists gluefile] {
225 file_on_build delete $gluefile
226 unset gluefile
227 }
228 }
229
230 # Prune messages from GNAT that aren't useful.
231
232 proc prune_gnat_output { text } {
233 #send_user "Before:$text\n"
234 regsub -all "(^|\n)\[^\n\]*: In (function|method) \[^\n\]*" $text "" text
235 regsub -all "(^|\n)\[^\n\]*: At top level:\[^\n\]*" $text "" text
236
237 # prune the output from gnatmake.
238 regsub -all "(^|\n)\[^\n\]*gnatmake: [^\n\]*" $text "" text
239
240 # It would be nice to avoid passing anything to gnat that would cause it to
241 # issue these messages (since ignoring them seems like a hack on our part),
242 # but that's too difficult in the general case. For example, sometimes
243 # you need to use -B to point gnat at crt0.o, but there are some targets
244 # that don't have crt0.o.
245 regsub -all "(^|\n)\[^\n\]*file path prefix \[^\n\]* never used" $text "" text
246 regsub -all "(^|\n)\[^\n\]*linker input file unused since linking not done" $text "" text
247
248 #send_user "After:$text\n"
249
250 return $text
251 }
252
253 # find_gnatmake for some version of DejaGnu will hardcode a -I...rts/ada flag
254 # which prevent multilib from working, so define a new one.
255
256 proc local_find_gnatmake {} {
257 global tool_root_dir
258
259 if ![is_remote host] {
260 set file [lookfor_file $tool_root_dir gnatmake]
261 if { $file == "" } {
262 set file [lookfor_file $tool_root_dir gcc/gnatmake]
263 }
264 if { $file != "" } {
265 set root [file dirname $file]
266 set CC "$file --GCC=$root/xgcc --GNATBIND=$root/gnatbind --GNATLINK=$root/gnatlink -cargs -B$root -largs -B$root -margs -B$root";
267 } else {
268 set CC [transform gnatmake]
269 }
270 } else {
271 set CC [transform gnatmake]
272 }
273 return $CC
274 }
275
276 # If this is an older version of DejaGnu (without runtest_file_p),
277 # provide one and assume the old syntax: foo1.exp bar1.c foo2.exp bar2.c.
278 # This can be deleted after next DejaGnu release.
279
280 if { [info procs runtest_file_p] == "" } then {
281 proc runtest_file_p { runtests testcase } {
282 if { $runtests != "" && [regexp "\[.\]\[cC\]" $runtests] } then {
283 if { [lsearch $runtests [file tail $testcase]] >= 0 } then {
284 return 1
285 } else {
286 return 0
287 }
288 }
289 return 1
290 }
291 }
292
293 # Provide a definition of this if missing (delete after next DejaGnu release).
294
295 if { [info procs prune_warnings] == "" } then {
296 proc prune_warnings { text } {
297 return $text
298 }
299 }