PR testsuite/12040:
[deliverable/binutils-gdb.git] / gdb / testsuite / lib / future.exp
CommitLineData
42159ca5
TT
1# Copyright 2004, 2007, 2008, 2009, 2010, 2011 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 this program. If not, see <http://www.gnu.org/licenses/>.
15
16load_lib libgloss.exp
17
18# FIXME:brobecker/2004-03-31:
19# The following functions should eventually be part of dejagnu. Even after
20# these functions becomes available in dejagnu, we will keep for a while
21# a copy here in order to avoid increasing the dejagnu version
22# requirement.
23
24proc gdb_find_gnatmake {} {
25 global tool_root_dir
26
27 set root "$tool_root_dir/gcc"
28 set GM ""
29
30 if ![is_remote host] {
31 set file [lookfor_file $root gnatmake]
32 if { $file != "" } {
33 set GM "$file -I$root/ada/rts --GCC=$root/xgcc --GNATBIND=$root/gnatbind --GNATLINK=$root/gnatlink -cargs -B$root -largs --GCC=$root/xgcc -margs";
34 }
35 }
36
37 if {$GM == ""} {
38 set GM [transform gnatmake]
39 }
40
41 return $GM
42}
43
44proc gdb_find_gfortran {} {
45 global tool_root_dir
46
47 if {![is_remote host]} {
48 set file [lookfor_file $tool_root_dir gfortran]
49 if { $file == "" } {
50 set file [lookfor_file $tool_root_dir gcc/gfortran]
51 }
52 if { $file != "" } {
53 set CC "$file -B[file dirname $file]/"
54 } else {
55 set CC [transform gfortran]
56 }
57 } else {
58 set CC [transform gfortran]
59 }
60 return $CC
61}
62
63proc gdb_default_target_compile {source destfile type options} {
64 global target_triplet
65 global tool_root_dir
66 global CFLAGS_FOR_TARGET
67 global compiler_flags
68
69 if { $destfile == "" && $type != "preprocess" && $type != "none" } {
70 error "Must supply an output filename for the compile to default_target_compile"
71 }
72
73 set add_flags ""
74 set libs ""
75 set compiler_type "c"
76 set compiler ""
77 set ldflags ""
78 set dest [target_info name]
79
80 if {[info exists CFLAGS_FOR_TARGET]} {
81 append add_flags " $CFLAGS_FOR_TARGET"
82 }
83
84 if {[info exists target_info(host,name)]} {
85 set host [host_info name]
86 } else {
87 set host "unix"
88 }
89
90 foreach i $options {
91
92 if { $i == "ada" } {
93 set compiler_type "ada"
94 if {[board_info $dest exists adaflags]} {
95 append add_flags " [target_info adaflags]"
96 }
97 if {[board_info $dest exists gnatmake]} {
98 set compiler [target_info gnatmake]
99 } else {
100 set compiler [find_gnatmake]
101 }
102 }
103
104 if { $i == "c++" } {
105 set compiler_type "c++"
106 if {[board_info $dest exists cxxflags]} {
107 append add_flags " [target_info cxxflags]"
108 }
109 append add_flags " [g++_include_flags]"
110 if {[board_info $dest exists c++compiler]} {
111 set compiler [target_info c++compiler]
112 } else {
113 set compiler [find_g++]
114 }
115 }
116
117 if { $i == "f77" } {
118 set compiler_type "f77"
119 if {[board_info $dest exists f77flags]} {
120 append add_flags " [target_info f77flags]"
121 }
122 if {[board_info $dest exists f77compiler]} {
123 set compiler [target_info f77compiler]
124 } else {
125 set compiler [find_g77]
126 }
127 }
128
129 if { $i == "f90" } {
130 set compiler_type "f90"
131 if {[board_info $dest exists f90flags]} {
132 append add_flags " [target_info f90flags]"
133 }
134 if {[board_info $dest exists f90compiler]} {
135 set compiler [target_info f90compiler]
136 } else {
137 set compiler [find_gfortran]
138 }
139 }
140
141 if {[regexp "^dest=" $i]} {
142 regsub "^dest=" $i "" tmp
143 if {[board_info $tmp exists name]} {
144 set dest [board_info $tmp name]
145 } else {
146 set dest $tmp
147 }
148 }
149 if {[regexp "^compiler=" $i]} {
150 regsub "^compiler=" $i "" tmp
151 set compiler $tmp
152 }
153 if {[regexp "^additional_flags=" $i]} {
154 regsub "^additional_flags=" $i "" tmp
155 append add_flags " $tmp"
156 }
157 if {[regexp "^ldflags=" $i]} {
158 regsub "^ldflags=" $i "" tmp
159 append ldflags " $tmp"
160 }
161 if {[regexp "^libs=" $i]} {
162 regsub "^libs=" $i "" tmp
163 append libs " $tmp"
164 }
165 if {[regexp "^incdir=" $i]} {
166 regsub "^incdir=" $i "-I" tmp
167 append add_flags " $tmp"
168 }
169 if {[regexp "^libdir=" $i]} {
170 regsub "^libdir=" $i "-L" tmp
171 append add_flags " $tmp"
172 }
173 if {[regexp "^ldscript=" $i]} {
174 regsub "^ldscript=" $i "" ldscript
175 }
176 if {[regexp "^redirect=" $i]} {
177 regsub "^redirect=" $i "" redirect
178 }
179 if {[regexp "^optimize=" $i]} {
180 regsub "^optimize=" $i "" optimize
181 }
182 if {[regexp "^timeout=" $i]} {
183 regsub "^timeout=" $i "" timeout
184 }
185 }
186
187 if {[board_info $host exists cflags_for_target]} {
188 append add_flags " [board_info $host cflags_for_target]"
189 }
190
191 global CC_FOR_TARGET
192 global CXX_FOR_TARGET
193 global F77_FOR_TARGET
194 global F90_FOR_TARGET
195 global GNATMAKE_FOR_TARGET
196
197 if {[info exists GNATMAKE_FOR_TARGET]} {
198 if { $compiler_type == "ada" } {
199 set compiler $GNATMAKE_FOR_TARGET
200 }
201 }
202
203 if {[info exists CC_FOR_TARGET]} {
204 if { $compiler == "" } {
205 set compiler $CC_FOR_TARGET
206 }
207 }
208
209 if {[info exists CXX_FOR_TARGET]} {
210 if { $compiler_type == "c++" } {
211 set compiler $CXX_FOR_TARGET
212 }
213 }
214
215 if {[info exists F77_FOR_TARGET]} {
216 if { $compiler_type == "f77" } {
217 set compiler $F77_FOR_TARGET
218 }
219 }
220
221 if {[info exists F90_FOR_TARGET]} {
222 if { $compiler_type == "f90" } {
223 set compiler $F90_FOR_TARGET
224 }
225 }
226
227 if { $compiler == "" } {
228 set compiler [board_info $dest compiler]
229 if { $compiler == "" } {
230 return "default_target_compile: No compiler to compile with"
231 }
232 }
233
234 if {![is_remote host]} {
235 if { [which $compiler] == 0 } {
236 return "default_target_compile: Can't find $compiler."
237 }
238 }
239
240 if {$type == "object"} {
241 append add_flags " -c"
242 }
243
244 if { $type == "preprocess" } {
245 append add_flags " -E"
246 }
247
248 if { $type == "assembly" } {
249 append add_flags " -S"
250 }
251
252 if {[board_info $dest exists cflags]} {
253 append add_flags " [board_info $dest cflags]"
254 }
255
256 if { $type == "executable" } {
257 if {[board_info $dest exists ldflags]} {
258 append add_flags " [board_info $dest ldflags]"
259 }
260 if { $compiler_type == "c++" } {
261 append add_flags " [g++_link_flags]"
262 }
263 if {[isnative]} {
264 # This is a lose.
265 catch "glob -nocomplain $tool_root_dir/libstdc++/libstdc++.so* $tool_root_dir/libstdc++/libstdc++.sl" tmp
266 if { ${tmp} != "" } {
267 if {[regexp ".*solaris2.*" $target_triplet]} {
268 # Solaris 2
269 append add_flags " -R$tool_root_dir/libstdc++"
270 } elseif {[regexp ".*(osf|irix5|linux).*" $target_triplet]} {
271 # OSF/1 or IRIX 5
272 append add_flags " -Wl,-rpath,$tool_root_dir/libstdc++"
273 } elseif {[regexp ".*hppa.*" $target_triplet]} {
274 # HP-UX
275 append add_flags " -Wl,-a,shared_archive"
276 }
277 }
278 }
279 }
280
281 if {![info exists ldscript]} {
282 set ldscript [board_info $dest ldscript]
283 }
284
285 foreach i $options {
286 if { $i == "debug" } {
287 if {[board_info $dest exists debug_flags]} {
288 append add_flags " [board_info $dest debug_flags]"
289 } else {
290 append add_flags " -g"
291 }
292 }
293 }
294
295 if {[info exists optimize]} {
296 append add_flags " $optimize"
297 }
298
299 if { $type == "executable" } {
300 append add_flags " $ldflags"
301 foreach x $libs {
302 if {[file exists $x]} {
303 append source " $x"
304 } else {
305 append add_flags " $x"
306 }
307 }
308
309 if {[board_info $dest exists libs]} {
310 append add_flags " [board_info $dest libs]"
311 }
312
313 # This probably isn't such a good idea, but it avoids nasty
314 # hackiness in the testsuites.
315 # The math library must be linked in before the C library. The C
316 # library is linked in by the linker script, so this must be before
317 # the linker script.
318 if {[board_info $dest exists mathlib]} {
319 append add_flags " [board_info $dest mathlib]"
320 } else {
321 append add_flags " -lm"
322 }
323
324 # This must be added here.
325 append add_flags " $ldscript"
326
327 if {[board_info $dest exists remote_link]} {
328 # Relink option.
329 append add_flags " -Wl,-r"
330 }
331 if {[board_info $dest exists output_format]} {
332 append add_flags " -Wl,-oformat,[board_info $dest output_format]"
333 }
334 }
335
336 if {[board_info $dest exists multilib_flags]} {
337 append add_flags " [board_info $dest multilib_flags]"
338 }
339
340 verbose "doing compile"
341
342 set sources ""
343 if {[is_remote host]} {
344 foreach x $source {
345 set file [remote_download host $x]
346 if { $file == "" } {
347 warning "Unable to download $x to host."
348 return "Unable to download $x to host."
349 } else {
350 append sources " $file"
351 }
352 }
353 } else {
354 set sources $source
355 }
356
357 if {[is_remote host]} {
358 append add_flags " -o a.out"
359 remote_file host delete a.out
360 } else {
361 if { $destfile != "" } {
362 append add_flags " -o $destfile"
363 }
364 }
365
366 # This is obscure: we put SOURCES at the end when building an
367 # object, because otherwise, in some situations, libtool will
368 # become confused about the name of the actual source file.
369 if {$type == "object"} {
370 set opts "$add_flags $sources"
371 } else {
372 set opts "$sources $add_flags"
373 }
374
375 if {[is_remote host]} {
376 if {[host_info exists use_at]} {
377 set fid [open "atfile" "w"]
378 puts $fid "$opts"
379 close $fid
380 set opts "@[remote_download host atfile]"
381 remote_file build delete atfile
382 }
383 }
384
385 verbose "Invoking the compiler as $compiler $opts" 2
386
387 if {[info exists redirect]} {
388 verbose "Redirecting output to $redirect" 2
389 set status [remote_exec host "$compiler $opts" "" "" $redirect]
390 } else {
391 if {[info exists timeout]} {
392 verbose "Setting timeout to $timeout" 2
393 set status [remote_exec host "$compiler $opts" "" "" "" $timeout]
394 } else {
395 set status [remote_exec host "$compiler $opts"]
396 }
397 }
398
399 set compiler_flags $opts
400 if {[is_remote host]} {
401 remote_upload host a.out $destfile
402 remote_file host delete a.out
403 }
404 set comp_output [prune_warnings [lindex $status 1]]
405 regsub "^\[\r\n\]+" $comp_output "" comp_output
406 if { [lindex $status 0] != 0 } {
407 verbose -log "compiler exited with status [lindex $status 0]"
408 }
409 if { [lindex $status 1] != "" } {
410 verbose -log "output is:\n[lindex $status 1]" 2
411 }
412 if { [lindex $status 0] != 0 && "${comp_output}" == "" } {
413 set comp_output "exit status is [lindex $status 0]"
414 }
415 return ${comp_output}
416}
417
418# See if the version of dejaGNU being used to run the testsuite is
419# recent enough to contain support for building Ada programs or not.
420# If not, then use the functions above in place of the ones provided
421# by dejaGNU. This is only temporary (brobecker/2004-03-31).
422
423set use_gdb_compile 0
424if {[info procs find_gnatmake] == ""} {
425 rename gdb_find_gnatmake find_gnatmake
426 set use_gdb_compile 1
427}
428
429if {[info procs find_gfortran] == ""} {
430 rename gdb_find_gfortran find_gfortran
431 set use_gdb_compile 1
432}
433
434if {$use_gdb_compile} {
435 catch {rename default_target_compile {}}
436 rename gdb_default_target_compile default_target_compile
437}
This page took 0.041572 seconds and 4 git commands to generate.