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