]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/lib/future.exp
Update years in copyright notice for the GDB files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / lib / future.exp
CommitLineData
8acc9f48 1# Copyright 2004-2013 Free Software Foundation, Inc.
42159ca5
TT
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
a766d390
DE
63proc gdb_find_go {} {
64 global tool_root_dir
65
66 set GO ""
67
68 if {![is_remote host]} {
69 set file [lookfor_file $tool_root_dir gccgo]
70 if { $file != "" } {
71 set root [file dirname $file]
72 set GO "$file -B$root/gcc/"
73 }
74 }
75
76 if { $GO == "" } {
77 set GO [transform gccgo]
78 }
79
80 return $GO
81}
82
83proc gdb_find_go_linker {} {
84 return [find_go]
85}
86
42159ca5
TT
87proc gdb_default_target_compile {source destfile type options} {
88 global target_triplet
89 global tool_root_dir
90 global CFLAGS_FOR_TARGET
91 global compiler_flags
92
93 if { $destfile == "" && $type != "preprocess" && $type != "none" } {
94 error "Must supply an output filename for the compile to default_target_compile"
95 }
96
97 set add_flags ""
98 set libs ""
99 set compiler_type "c"
100 set compiler ""
a766d390
DE
101 set linker ""
102 # linker_opts_order is one of "sources-then-flags", "flags-then-sources".
103 # The order shouldn't matter. It's done this way to preserve
104 # existing behavior.
105 set linker_opts_order "sources-then-flags"
42159ca5
TT
106 set ldflags ""
107 set dest [target_info name]
108
109 if {[info exists CFLAGS_FOR_TARGET]} {
110 append add_flags " $CFLAGS_FOR_TARGET"
111 }
112
113 if {[info exists target_info(host,name)]} {
114 set host [host_info name]
115 } else {
116 set host "unix"
117 }
118
119 foreach i $options {
120
121 if { $i == "ada" } {
122 set compiler_type "ada"
123 if {[board_info $dest exists adaflags]} {
124 append add_flags " [target_info adaflags]"
125 }
126 if {[board_info $dest exists gnatmake]} {
127 set compiler [target_info gnatmake]
128 } else {
129 set compiler [find_gnatmake]
130 }
131 }
132
133 if { $i == "c++" } {
134 set compiler_type "c++"
135 if {[board_info $dest exists cxxflags]} {
136 append add_flags " [target_info cxxflags]"
137 }
138 append add_flags " [g++_include_flags]"
139 if {[board_info $dest exists c++compiler]} {
140 set compiler [target_info c++compiler]
141 } else {
142 set compiler [find_g++]
143 }
144 }
145
146 if { $i == "f77" } {
147 set compiler_type "f77"
148 if {[board_info $dest exists f77flags]} {
149 append add_flags " [target_info f77flags]"
150 }
151 if {[board_info $dest exists f77compiler]} {
152 set compiler [target_info f77compiler]
153 } else {
154 set compiler [find_g77]
155 }
156 }
157
158 if { $i == "f90" } {
159 set compiler_type "f90"
160 if {[board_info $dest exists f90flags]} {
161 append add_flags " [target_info f90flags]"
162 }
163 if {[board_info $dest exists f90compiler]} {
164 set compiler [target_info f90compiler]
165 } else {
166 set compiler [find_gfortran]
167 }
168 }
169
a766d390
DE
170 if { $i == "go" } {
171 set compiler_type "go"
172 if {[board_info $dest exists goflags]} {
173 append add_flags " [target_info goflags]"
174 }
175 if {[board_info $dest exists gocompiler]} {
176 set compiler [target_info gocompiler]
177 } else {
178 set compiler [find_go]
179 }
180 if {[board_info $dest exists golinker]} {
181 set linker [target_info golinker]
182 } else {
183 set linker [find_go_linker]
184 }
185 if {[board_info $dest exists golinker_opts_order]} {
186 set linker_opts_order [target_info golinker_opts_order]
187 }
188 }
189
42159ca5
TT
190 if {[regexp "^dest=" $i]} {
191 regsub "^dest=" $i "" tmp
192 if {[board_info $tmp exists name]} {
193 set dest [board_info $tmp name]
194 } else {
195 set dest $tmp
196 }
197 }
198 if {[regexp "^compiler=" $i]} {
199 regsub "^compiler=" $i "" tmp
200 set compiler $tmp
201 }
202 if {[regexp "^additional_flags=" $i]} {
203 regsub "^additional_flags=" $i "" tmp
204 append add_flags " $tmp"
205 }
206 if {[regexp "^ldflags=" $i]} {
207 regsub "^ldflags=" $i "" tmp
208 append ldflags " $tmp"
209 }
210 if {[regexp "^libs=" $i]} {
211 regsub "^libs=" $i "" tmp
212 append libs " $tmp"
213 }
214 if {[regexp "^incdir=" $i]} {
215 regsub "^incdir=" $i "-I" tmp
216 append add_flags " $tmp"
217 }
218 if {[regexp "^libdir=" $i]} {
219 regsub "^libdir=" $i "-L" tmp
220 append add_flags " $tmp"
221 }
222 if {[regexp "^ldscript=" $i]} {
223 regsub "^ldscript=" $i "" ldscript
224 }
225 if {[regexp "^redirect=" $i]} {
226 regsub "^redirect=" $i "" redirect
227 }
228 if {[regexp "^optimize=" $i]} {
229 regsub "^optimize=" $i "" optimize
230 }
231 if {[regexp "^timeout=" $i]} {
232 regsub "^timeout=" $i "" timeout
233 }
234 }
235
236 if {[board_info $host exists cflags_for_target]} {
237 append add_flags " [board_info $host cflags_for_target]"
238 }
239
240 global CC_FOR_TARGET
241 global CXX_FOR_TARGET
242 global F77_FOR_TARGET
243 global F90_FOR_TARGET
244 global GNATMAKE_FOR_TARGET
a766d390
DE
245 global GO_FOR_TARGET
246 global GO_LD_FOR_TARGET
42159ca5
TT
247
248 if {[info exists GNATMAKE_FOR_TARGET]} {
249 if { $compiler_type == "ada" } {
250 set compiler $GNATMAKE_FOR_TARGET
251 }
252 }
253
254 if {[info exists CC_FOR_TARGET]} {
255 if { $compiler == "" } {
256 set compiler $CC_FOR_TARGET
257 }
258 }
259
260 if {[info exists CXX_FOR_TARGET]} {
261 if { $compiler_type == "c++" } {
262 set compiler $CXX_FOR_TARGET
263 }
264 }
265
266 if {[info exists F77_FOR_TARGET]} {
267 if { $compiler_type == "f77" } {
268 set compiler $F77_FOR_TARGET
269 }
270 }
271
272 if {[info exists F90_FOR_TARGET]} {
273 if { $compiler_type == "f90" } {
274 set compiler $F90_FOR_TARGET
275 }
276 }
277
a766d390
DE
278 if { $compiler_type == "go" } {
279 if {[info exists GO_FOR_TARGET]} {
280 set compiler $GO_FOR_TARGET
281 }
282 if {[info exists GO_LD_FOR_TARGET]} {
283 set linker $GO_LD_FOR_TARGET
284 }
285 }
286
287 if { $type == "executable" && $linker != "" } {
288 set compiler $linker
289 }
290
42159ca5
TT
291 if { $compiler == "" } {
292 set compiler [board_info $dest compiler]
293 if { $compiler == "" } {
294 return "default_target_compile: No compiler to compile with"
295 }
296 }
297
298 if {![is_remote host]} {
299 if { [which $compiler] == 0 } {
300 return "default_target_compile: Can't find $compiler."
301 }
302 }
303
304 if {$type == "object"} {
305 append add_flags " -c"
306 }
307
308 if { $type == "preprocess" } {
309 append add_flags " -E"
310 }
311
312 if { $type == "assembly" } {
313 append add_flags " -S"
314 }
315
316 if {[board_info $dest exists cflags]} {
317 append add_flags " [board_info $dest cflags]"
318 }
319
320 if { $type == "executable" } {
321 if {[board_info $dest exists ldflags]} {
322 append add_flags " [board_info $dest ldflags]"
323 }
324 if { $compiler_type == "c++" } {
325 append add_flags " [g++_link_flags]"
326 }
327 if {[isnative]} {
328 # This is a lose.
329 catch "glob -nocomplain $tool_root_dir/libstdc++/libstdc++.so* $tool_root_dir/libstdc++/libstdc++.sl" tmp
330 if { ${tmp} != "" } {
331 if {[regexp ".*solaris2.*" $target_triplet]} {
332 # Solaris 2
333 append add_flags " -R$tool_root_dir/libstdc++"
334 } elseif {[regexp ".*(osf|irix5|linux).*" $target_triplet]} {
335 # OSF/1 or IRIX 5
336 append add_flags " -Wl,-rpath,$tool_root_dir/libstdc++"
337 } elseif {[regexp ".*hppa.*" $target_triplet]} {
338 # HP-UX
339 append add_flags " -Wl,-a,shared_archive"
340 }
341 }
342 }
343 }
344
345 if {![info exists ldscript]} {
346 set ldscript [board_info $dest ldscript]
347 }
348
349 foreach i $options {
350 if { $i == "debug" } {
351 if {[board_info $dest exists debug_flags]} {
352 append add_flags " [board_info $dest debug_flags]"
353 } else {
354 append add_flags " -g"
355 }
356 }
357 }
358
359 if {[info exists optimize]} {
360 append add_flags " $optimize"
361 }
362
363 if { $type == "executable" } {
364 append add_flags " $ldflags"
365 foreach x $libs {
366 if {[file exists $x]} {
367 append source " $x"
368 } else {
369 append add_flags " $x"
370 }
371 }
372
373 if {[board_info $dest exists libs]} {
374 append add_flags " [board_info $dest libs]"
375 }
376
377 # This probably isn't such a good idea, but it avoids nasty
378 # hackiness in the testsuites.
379 # The math library must be linked in before the C library. The C
380 # library is linked in by the linker script, so this must be before
381 # the linker script.
382 if {[board_info $dest exists mathlib]} {
383 append add_flags " [board_info $dest mathlib]"
384 } else {
385 append add_flags " -lm"
386 }
387
388 # This must be added here.
389 append add_flags " $ldscript"
390
391 if {[board_info $dest exists remote_link]} {
392 # Relink option.
393 append add_flags " -Wl,-r"
394 }
395 if {[board_info $dest exists output_format]} {
396 append add_flags " -Wl,-oformat,[board_info $dest output_format]"
397 }
398 }
399
400 if {[board_info $dest exists multilib_flags]} {
401 append add_flags " [board_info $dest multilib_flags]"
402 }
403
404 verbose "doing compile"
405
406 set sources ""
407 if {[is_remote host]} {
408 foreach x $source {
409 set file [remote_download host $x]
410 if { $file == "" } {
411 warning "Unable to download $x to host."
412 return "Unable to download $x to host."
413 } else {
414 append sources " $file"
415 }
416 }
417 } else {
418 set sources $source
419 }
420
421 if {[is_remote host]} {
422 append add_flags " -o a.out"
423 remote_file host delete a.out
424 } else {
425 if { $destfile != "" } {
426 append add_flags " -o $destfile"
427 }
428 }
429
430 # This is obscure: we put SOURCES at the end when building an
431 # object, because otherwise, in some situations, libtool will
432 # become confused about the name of the actual source file.
a766d390
DE
433 switch $type {
434 "object" {
435 set opts "$add_flags $sources"
436 }
437 "executable" {
438 switch $linker_opts_order {
439 "flags-then-sources" {
440 set opts "$add_flags $sources"
441 }
442 "sources-then-flags" {
443 set opts "$sources $add_flags"
444 }
445 default {
446 error "Invalid value for board_info linker_opts_order"
447 }
448 }
449 }
450 default {
451 set opts "$sources $add_flags"
452 }
42159ca5
TT
453 }
454
455 if {[is_remote host]} {
456 if {[host_info exists use_at]} {
457 set fid [open "atfile" "w"]
458 puts $fid "$opts"
459 close $fid
460 set opts "@[remote_download host atfile]"
461 remote_file build delete atfile
462 }
463 }
464
465 verbose "Invoking the compiler as $compiler $opts" 2
466
467 if {[info exists redirect]} {
468 verbose "Redirecting output to $redirect" 2
469 set status [remote_exec host "$compiler $opts" "" "" $redirect]
470 } else {
471 if {[info exists timeout]} {
472 verbose "Setting timeout to $timeout" 2
473 set status [remote_exec host "$compiler $opts" "" "" "" $timeout]
474 } else {
475 set status [remote_exec host "$compiler $opts"]
476 }
477 }
478
479 set compiler_flags $opts
480 if {[is_remote host]} {
481 remote_upload host a.out $destfile
482 remote_file host delete a.out
483 }
484 set comp_output [prune_warnings [lindex $status 1]]
485 regsub "^\[\r\n\]+" $comp_output "" comp_output
486 if { [lindex $status 0] != 0 } {
487 verbose -log "compiler exited with status [lindex $status 0]"
488 }
489 if { [lindex $status 1] != "" } {
490 verbose -log "output is:\n[lindex $status 1]" 2
491 }
492 if { [lindex $status 0] != 0 && "${comp_output}" == "" } {
493 set comp_output "exit status is [lindex $status 0]"
494 }
495 return ${comp_output}
496}
497
498# See if the version of dejaGNU being used to run the testsuite is
499# recent enough to contain support for building Ada programs or not.
500# If not, then use the functions above in place of the ones provided
501# by dejaGNU. This is only temporary (brobecker/2004-03-31).
502
503set use_gdb_compile 0
504if {[info procs find_gnatmake] == ""} {
505 rename gdb_find_gnatmake find_gnatmake
506 set use_gdb_compile 1
507}
508
509if {[info procs find_gfortran] == ""} {
510 rename gdb_find_gfortran find_gfortran
511 set use_gdb_compile 1
512}
513
a766d390
DE
514if {[info procs find_go_linker] == ""} {
515 rename gdb_find_go find_go
516 rename gdb_find_go_linker find_go_linker
bb2af9cc 517 set use_gdb_compile 1
a766d390
DE
518}
519
42159ca5
TT
520if {$use_gdb_compile} {
521 catch {rename default_target_compile {}}
522 rename gdb_default_target_compile default_target_compile
523}
9cc8e32c
JK
524
525
526# Provide 'lreverse' missing in Tcl before 7.5.
527
528if {[info procs lreverse] == ""} {
529 proc lreverse { arg } {
530 set retval {}
531 while { [llength $retval] < [llength $arg] } {
532 lappend retval [lindex $arg end-[llength $retval]]
533 }
534 return $retval
535 }
536}