1 # Copyright 2004-2016 Free Software Foundation, Inc.
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.
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.
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/>.
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
24 proc gdb_find_gnatmake {} {
27 set root "$tool_root_dir/gcc"
30 if ![is_remote host] {
31 set file [lookfor_file $root gnatmake]
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";
38 set GM [transform gnatmake]
44 proc gdb_find_gdc {} {
46 print "Tool Root: $tool_root_dir"
48 if {![is_remote host]} {
49 set file [lookfor_file $tool_root_dir gdc]
51 set file [lookfor_file $tool_root_dir gcc/gdc]
54 set CC "$file -B[file dirname $file]/"
56 set CC [transform gdc]
59 set CC [transform gdc]
65 proc gdb_find_gfortran {} {
68 if {![is_remote host]} {
69 set file [lookfor_file $tool_root_dir gfortran]
71 set file [lookfor_file $tool_root_dir gcc/gfortran]
74 set CC "$file -B[file dirname $file]/"
76 set CC [transform gfortran]
79 set CC [transform gfortran]
89 if {![is_remote host]} {
90 set file [lookfor_file $tool_root_dir gccgo]
92 set root [file dirname $file]
93 set GO "$file -B$root/gcc/"
98 set GO [transform gccgo]
104 proc gdb_find_go_linker {} {
108 proc gdb_find_ldd {} {
109 global LDD_FOR_TARGET
110 if [info exists LDD_FOR_TARGET] {
111 set ldd $LDD_FOR_TARGET
118 proc gdb_find_objcopy {} {
119 global OBJCOPY_FOR_TARGET
120 if [info exists OBJCOPY_FOR_TARGET] {
121 set objcopy $OBJCOPY_FOR_TARGET
123 set objcopy [transform objcopy]
128 # find target objdump
129 proc gdb_find_objdump {} {
130 global OBJDUMP_FOR_TARGET
131 if [info exists OBJDUMP_FOR_TARGET] {
132 set objdump $OBJDUMP_FOR_TARGET
134 set objdump [transform objdump]
139 proc gdb_find_readelf {} {
140 global READELF_FOR_TARGET
141 if [info exists READELF_FOR_TARGET] {
142 set readelf $READELF_FOR_TARGET
144 set readelf [transform readelf]
149 proc gdb_default_target_compile {source destfile type options} {
150 global target_triplet
152 global CFLAGS_FOR_TARGET
153 global compiler_flags
155 if { $destfile == "" && $type != "preprocess" && $type != "none" } {
156 error "Must supply an output filename for the compile to default_target_compile"
162 set compiler_type "c"
165 # linker_opts_order is one of "sources-then-flags", "flags-then-sources".
166 # The order matters for things like -Wl,--as-needed. The default is to
167 # preserve existing behavior.
168 set linker_opts_order "sources-then-flags"
170 set dest [target_info name]
172 if {[info exists CFLAGS_FOR_TARGET]} {
173 append add_flags " $CFLAGS_FOR_TARGET"
176 if {[info exists target_info(host,name)]} {
177 set host [host_info name]
185 set compiler_type "ada"
186 if {[board_info $dest exists adaflags]} {
187 append add_flags " [target_info adaflags]"
189 if {[board_info $dest exists gnatmake]} {
190 set compiler [target_info gnatmake]
192 set compiler [find_gnatmake]
197 set compiler_type "c++"
198 if {[board_info $dest exists cxxflags]} {
199 append add_flags " [target_info cxxflags]"
201 append add_flags " [g++_include_flags]"
202 if {[board_info $dest exists c++compiler]} {
203 set compiler [target_info c++compiler]
205 set compiler [find_g++]
210 set compiler_type "d"
211 if {[board_info $dest exists dflags]} {
212 append add_flags " [target_info dflags]"
214 if {[board_info $dest exists dcompiler]} {
215 set compiler [target_info dcompiler]
217 set compiler [find_gdc]
222 set compiler_type "f77"
223 if {[board_info $dest exists f77flags]} {
224 append add_flags " [target_info f77flags]"
226 if {[board_info $dest exists f77compiler]} {
227 set compiler [target_info f77compiler]
229 set compiler [find_g77]
234 set compiler_type "f90"
235 if {[board_info $dest exists f90flags]} {
236 append add_flags " [target_info f90flags]"
238 if {[board_info $dest exists f90compiler]} {
239 set compiler [target_info f90compiler]
241 set compiler [find_gfortran]
246 set compiler_type "go"
247 if {[board_info $dest exists goflags]} {
248 append add_flags " [target_info goflags]"
250 if {[board_info $dest exists gocompiler]} {
251 set compiler [target_info gocompiler]
253 set compiler [find_go]
255 if {[board_info $dest exists golinker]} {
256 set linker [target_info golinker]
258 set linker [find_go_linker]
260 if {[board_info $dest exists golinker_opts_order]} {
261 set linker_opts_order [target_info golinker_opts_order]
265 if {[regexp "^dest=" $i]} {
266 regsub "^dest=" $i "" tmp
267 if {[board_info $tmp exists name]} {
268 set dest [board_info $tmp name]
273 if {[regexp "^compiler=" $i]} {
274 regsub "^compiler=" $i "" tmp
277 if {[regexp "^early_flags=" $i]} {
278 regsub "^early_flags=" $i "" tmp
279 append early_flags " $tmp"
281 if {[regexp "^additional_flags=" $i]} {
282 regsub "^additional_flags=" $i "" tmp
283 append add_flags " $tmp"
285 if {[regexp "^ldflags=" $i]} {
286 regsub "^ldflags=" $i "" tmp
287 append ldflags " $tmp"
289 if {[regexp "^libs=" $i]} {
290 regsub "^libs=" $i "" tmp
293 if {[regexp "^incdir=" $i]} {
294 regsub "^incdir=" $i "-I" tmp
295 append add_flags " $tmp"
297 if {[regexp "^libdir=" $i]} {
298 regsub "^libdir=" $i "-L" tmp
299 append add_flags " $tmp"
301 if {[regexp "^ldscript=" $i]} {
302 regsub "^ldscript=" $i "" ldscript
304 if {[regexp "^redirect=" $i]} {
305 regsub "^redirect=" $i "" redirect
307 if {[regexp "^optimize=" $i]} {
308 regsub "^optimize=" $i "" optimize
310 if {[regexp "^timeout=" $i]} {
311 regsub "^timeout=" $i "" timeout
315 if {[board_info $host exists cflags_for_target]} {
316 append add_flags " [board_info $host cflags_for_target]"
320 global CXX_FOR_TARGET
322 global F77_FOR_TARGET
323 global F90_FOR_TARGET
324 global GNATMAKE_FOR_TARGET
326 global GO_LD_FOR_TARGET
328 if {[info exists GNATMAKE_FOR_TARGET]} {
329 if { $compiler_type == "ada" } {
330 set compiler $GNATMAKE_FOR_TARGET
334 if {[info exists CC_FOR_TARGET]} {
335 if { $compiler == "" } {
336 set compiler $CC_FOR_TARGET
340 if {[info exists CXX_FOR_TARGET]} {
341 if { $compiler_type == "c++" } {
342 set compiler $CXX_FOR_TARGET
346 if {[info exists D_FOR_TARGET]} {
347 if { $compiler_type == "d" } {
348 set compiler $D_FOR_TARGET
352 if {[info exists F77_FOR_TARGET]} {
353 if { $compiler_type == "f77" } {
354 set compiler $F77_FOR_TARGET
358 if {[info exists F90_FOR_TARGET]} {
359 if { $compiler_type == "f90" } {
360 set compiler $F90_FOR_TARGET
364 if { $compiler_type == "go" } {
365 if {[info exists GO_FOR_TARGET]} {
366 set compiler $GO_FOR_TARGET
368 if {[info exists GO_LD_FOR_TARGET]} {
369 set linker $GO_LD_FOR_TARGET
373 if { $type == "executable" && $linker != "" } {
377 if { $compiler == "" } {
378 set compiler [board_info $dest compiler]
379 if { $compiler == "" } {
380 return "default_target_compile: No compiler to compile with"
384 if {![is_remote host]} {
385 if { [which $compiler] == 0 } {
386 return "default_target_compile: Can't find $compiler."
390 if {$type == "object"} {
391 append add_flags " -c"
394 if { $type == "preprocess" } {
395 append add_flags " -E"
398 if { $type == "assembly" } {
399 append add_flags " -S"
402 if {[board_info $dest exists cflags]} {
403 append add_flags " [board_info $dest cflags]"
406 if { $type == "executable" } {
407 if {[board_info $dest exists ldflags]} {
408 append add_flags " [board_info $dest ldflags]"
410 if { $compiler_type == "c++" } {
411 append add_flags " [g++_link_flags]"
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]} {
419 append add_flags " -R$tool_root_dir/libstdc++"
420 } elseif {[regexp ".*(osf|irix5|linux).*" $target_triplet]} {
422 append add_flags " -Wl,-rpath,$tool_root_dir/libstdc++"
428 if {![info exists ldscript]} {
429 set ldscript [board_info $dest ldscript]
433 if { $i == "debug" } {
434 if {[board_info $dest exists debug_flags]} {
435 append add_flags " [board_info $dest debug_flags]"
437 append add_flags " -g"
442 if {[info exists optimize]} {
443 append add_flags " $optimize"
446 if { $type == "executable" } {
447 append add_flags " $ldflags"
449 if {[file exists $x]} {
452 append add_flags " $x"
456 if {[board_info $dest exists libs]} {
457 append add_flags " [board_info $dest libs]"
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
465 if {[board_info $dest exists mathlib]} {
466 append add_flags " [board_info $dest mathlib]"
468 append add_flags " -lm"
471 # This must be added here.
472 append add_flags " $ldscript"
474 if {[board_info $dest exists remote_link]} {
476 append add_flags " -Wl,-r"
478 if {[board_info $dest exists output_format]} {
479 append add_flags " -Wl,-oformat,[board_info $dest output_format]"
483 if {[board_info $dest exists multilib_flags]} {
484 append add_flags " [board_info $dest multilib_flags]"
487 verbose "doing compile"
490 if {[is_remote host]} {
492 set file [remote_download host $x]
494 warning "Unable to download $x to host."
495 return "Unable to download $x to host."
497 append sources " $file"
504 if {[is_remote host]} {
505 append add_flags " -o " [file tail $destfile]
506 remote_file host delete [file tail $destfile]
508 if { $destfile != "" } {
509 append add_flags " -o $destfile"
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.
518 set opts "$early_flags $add_flags $sources"
521 switch $linker_opts_order {
522 "flags-then-sources" {
523 set opts "$early_flags $add_flags $sources"
525 "sources-then-flags" {
526 set opts "$early_flags $sources $add_flags"
529 error "Invalid value for board_info linker_opts_order"
534 set opts "$early_flags $sources $add_flags"
538 if {[is_remote host]} {
539 if {[host_info exists use_at]} {
540 set fid [open "atfile" "w"]
543 set opts "@[remote_download host atfile]"
544 remote_file build delete atfile
548 verbose "Invoking the compiler as $compiler $opts" 2
550 if {[info exists redirect]} {
551 verbose "Redirecting output to $redirect" 2
552 set status [remote_exec host "$compiler $opts" "" "" $redirect]
554 if {[info exists timeout]} {
555 verbose "Setting timeout to $timeout" 2
556 set status [remote_exec host "$compiler $opts" "" "" "" $timeout]
558 set status [remote_exec host "$compiler $opts"]
562 set compiler_flags $opts
563 if {[is_remote host]} {
564 remote_upload host [file tail $destfile] $destfile
565 remote_file host delete [file tail $destfile]
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]"
572 if { [lindex $status 1] != "" } {
573 verbose -log "output is:\n[lindex $status 1]" 2
575 if { [lindex $status 0] != 0 && "${comp_output}" == "" } {
576 set comp_output "exit status is [lindex $status 0]"
578 return ${comp_output}
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).
586 set use_gdb_compile 0
587 if {[info procs find_gnatmake] == ""} {
588 rename gdb_find_gnatmake find_gnatmake
589 set use_gdb_compile 1
592 if {[info procs find_gfortran] == ""} {
593 rename gdb_find_gfortran find_gfortran
594 set use_gdb_compile 1
597 if {[info procs find_go_linker] == ""} {
598 rename gdb_find_go find_go
599 rename gdb_find_go_linker find_go_linker
600 set use_gdb_compile 1
603 if {[info procs find_gdc] == ""} {
604 rename gdb_find_gdc find_gdc
605 set use_gdb_compile 1
608 if {$use_gdb_compile} {
609 catch {rename default_target_compile {}}
610 rename gdb_default_target_compile default_target_compile
614 # Provide 'lreverse' missing in Tcl before 7.5.
616 if {[info procs lreverse] == ""} {
617 proc lreverse { arg } {
619 while { [llength $retval] < [llength $arg] } {
620 lappend retval [lindex $arg end-[llength $retval]]