1 # Copyright 2004-2015 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_gfortran {} {
47 if {![is_remote host]} {
48 set file [lookfor_file $tool_root_dir gfortran]
50 set file [lookfor_file $tool_root_dir gcc/gfortran]
53 set CC "$file -B[file dirname $file]/"
55 set CC [transform gfortran]
58 set CC [transform gfortran]
68 if {![is_remote host]} {
69 set file [lookfor_file $tool_root_dir gccgo]
71 set root [file dirname $file]
72 set GO "$file -B$root/gcc/"
77 set GO [transform gccgo]
83 proc gdb_find_go_linker {} {
87 proc gdb_find_ldd {} {
89 if [info exists LDD_FOR_TARGET] {
90 set ldd $LDD_FOR_TARGET
97 proc gdb_find_objcopy {} {
98 global OBJCOPY_FOR_TARGET
99 if [info exists OBJCOPY_FOR_TARGET] {
100 set objcopy $OBJCOPY_FOR_TARGET
102 set objcopy [transform objcopy]
107 # find target objdump
108 proc gdb_find_objdump {} {
109 global OBJDUMP_FOR_TARGET
110 if [info exists OBJDUMP_FOR_TARGET] {
111 set objdump $OBJDUMP_FOR_TARGET
113 set objdump [transform objdump]
118 proc gdb_find_readelf {} {
119 global READELF_FOR_TARGET
120 if [info exists READELF_FOR_TARGET] {
121 set readelf $READELF_FOR_TARGET
123 set readelf [transform readelf]
128 proc gdb_default_target_compile {source destfile type options} {
129 global target_triplet
131 global CFLAGS_FOR_TARGET
132 global compiler_flags
134 if { $destfile == "" && $type != "preprocess" && $type != "none" } {
135 error "Must supply an output filename for the compile to default_target_compile"
141 set compiler_type "c"
144 # linker_opts_order is one of "sources-then-flags", "flags-then-sources".
145 # The order matters for things like -Wl,--as-needed. The default is to
146 # preserve existing behavior.
147 set linker_opts_order "sources-then-flags"
149 set dest [target_info name]
151 if {[info exists CFLAGS_FOR_TARGET]} {
152 append add_flags " $CFLAGS_FOR_TARGET"
155 if {[info exists target_info(host,name)]} {
156 set host [host_info name]
164 set compiler_type "ada"
165 if {[board_info $dest exists adaflags]} {
166 append add_flags " [target_info adaflags]"
168 if {[board_info $dest exists gnatmake]} {
169 set compiler [target_info gnatmake]
171 set compiler [find_gnatmake]
176 set compiler_type "c++"
177 if {[board_info $dest exists cxxflags]} {
178 append add_flags " [target_info cxxflags]"
180 append add_flags " [g++_include_flags]"
181 if {[board_info $dest exists c++compiler]} {
182 set compiler [target_info c++compiler]
184 set compiler [find_g++]
189 set compiler_type "f77"
190 if {[board_info $dest exists f77flags]} {
191 append add_flags " [target_info f77flags]"
193 if {[board_info $dest exists f77compiler]} {
194 set compiler [target_info f77compiler]
196 set compiler [find_g77]
201 set compiler_type "f90"
202 if {[board_info $dest exists f90flags]} {
203 append add_flags " [target_info f90flags]"
205 if {[board_info $dest exists f90compiler]} {
206 set compiler [target_info f90compiler]
208 set compiler [find_gfortran]
213 set compiler_type "go"
214 if {[board_info $dest exists goflags]} {
215 append add_flags " [target_info goflags]"
217 if {[board_info $dest exists gocompiler]} {
218 set compiler [target_info gocompiler]
220 set compiler [find_go]
222 if {[board_info $dest exists golinker]} {
223 set linker [target_info golinker]
225 set linker [find_go_linker]
227 if {[board_info $dest exists golinker_opts_order]} {
228 set linker_opts_order [target_info golinker_opts_order]
232 if {[regexp "^dest=" $i]} {
233 regsub "^dest=" $i "" tmp
234 if {[board_info $tmp exists name]} {
235 set dest [board_info $tmp name]
240 if {[regexp "^compiler=" $i]} {
241 regsub "^compiler=" $i "" tmp
244 if {[regexp "^early_flags=" $i]} {
245 regsub "^early_flags=" $i "" tmp
246 append early_flags " $tmp"
248 if {[regexp "^additional_flags=" $i]} {
249 regsub "^additional_flags=" $i "" tmp
250 append add_flags " $tmp"
252 if {[regexp "^ldflags=" $i]} {
253 regsub "^ldflags=" $i "" tmp
254 append ldflags " $tmp"
256 if {[regexp "^libs=" $i]} {
257 regsub "^libs=" $i "" tmp
260 if {[regexp "^incdir=" $i]} {
261 regsub "^incdir=" $i "-I" tmp
262 append add_flags " $tmp"
264 if {[regexp "^libdir=" $i]} {
265 regsub "^libdir=" $i "-L" tmp
266 append add_flags " $tmp"
268 if {[regexp "^ldscript=" $i]} {
269 regsub "^ldscript=" $i "" ldscript
271 if {[regexp "^redirect=" $i]} {
272 regsub "^redirect=" $i "" redirect
274 if {[regexp "^optimize=" $i]} {
275 regsub "^optimize=" $i "" optimize
277 if {[regexp "^timeout=" $i]} {
278 regsub "^timeout=" $i "" timeout
282 if {[board_info $host exists cflags_for_target]} {
283 append add_flags " [board_info $host cflags_for_target]"
287 global CXX_FOR_TARGET
288 global F77_FOR_TARGET
289 global F90_FOR_TARGET
290 global GNATMAKE_FOR_TARGET
292 global GO_LD_FOR_TARGET
294 if {[info exists GNATMAKE_FOR_TARGET]} {
295 if { $compiler_type == "ada" } {
296 set compiler $GNATMAKE_FOR_TARGET
300 if {[info exists CC_FOR_TARGET]} {
301 if { $compiler == "" } {
302 set compiler $CC_FOR_TARGET
306 if {[info exists CXX_FOR_TARGET]} {
307 if { $compiler_type == "c++" } {
308 set compiler $CXX_FOR_TARGET
312 if {[info exists F77_FOR_TARGET]} {
313 if { $compiler_type == "f77" } {
314 set compiler $F77_FOR_TARGET
318 if {[info exists F90_FOR_TARGET]} {
319 if { $compiler_type == "f90" } {
320 set compiler $F90_FOR_TARGET
324 if { $compiler_type == "go" } {
325 if {[info exists GO_FOR_TARGET]} {
326 set compiler $GO_FOR_TARGET
328 if {[info exists GO_LD_FOR_TARGET]} {
329 set linker $GO_LD_FOR_TARGET
333 if { $type == "executable" && $linker != "" } {
337 if { $compiler == "" } {
338 set compiler [board_info $dest compiler]
339 if { $compiler == "" } {
340 return "default_target_compile: No compiler to compile with"
344 if {![is_remote host]} {
345 if { [which $compiler] == 0 } {
346 return "default_target_compile: Can't find $compiler."
350 if {$type == "object"} {
351 append add_flags " -c"
354 if { $type == "preprocess" } {
355 append add_flags " -E"
358 if { $type == "assembly" } {
359 append add_flags " -S"
362 if {[board_info $dest exists cflags]} {
363 append add_flags " [board_info $dest cflags]"
366 if { $type == "executable" } {
367 if {[board_info $dest exists ldflags]} {
368 append add_flags " [board_info $dest ldflags]"
370 if { $compiler_type == "c++" } {
371 append add_flags " [g++_link_flags]"
375 catch "glob -nocomplain $tool_root_dir/libstdc++/libstdc++.so* $tool_root_dir/libstdc++/libstdc++.sl" tmp
376 if { ${tmp} != "" } {
377 if {[regexp ".*solaris2.*" $target_triplet]} {
379 append add_flags " -R$tool_root_dir/libstdc++"
380 } elseif {[regexp ".*(osf|irix5|linux).*" $target_triplet]} {
382 append add_flags " -Wl,-rpath,$tool_root_dir/libstdc++"
383 } elseif {[regexp ".*hppa.*" $target_triplet]} {
385 append add_flags " -Wl,-a,shared_archive"
391 if {![info exists ldscript]} {
392 set ldscript [board_info $dest ldscript]
396 if { $i == "debug" } {
397 if {[board_info $dest exists debug_flags]} {
398 append add_flags " [board_info $dest debug_flags]"
400 append add_flags " -g"
405 if {[info exists optimize]} {
406 append add_flags " $optimize"
409 if { $type == "executable" } {
410 append add_flags " $ldflags"
412 if {[file exists $x]} {
415 append add_flags " $x"
419 if {[board_info $dest exists libs]} {
420 append add_flags " [board_info $dest libs]"
423 # This probably isn't such a good idea, but it avoids nasty
424 # hackiness in the testsuites.
425 # The math library must be linked in before the C library. The C
426 # library is linked in by the linker script, so this must be before
428 if {[board_info $dest exists mathlib]} {
429 append add_flags " [board_info $dest mathlib]"
431 append add_flags " -lm"
434 # This must be added here.
435 append add_flags " $ldscript"
437 if {[board_info $dest exists remote_link]} {
439 append add_flags " -Wl,-r"
441 if {[board_info $dest exists output_format]} {
442 append add_flags " -Wl,-oformat,[board_info $dest output_format]"
446 if {[board_info $dest exists multilib_flags]} {
447 append add_flags " [board_info $dest multilib_flags]"
450 verbose "doing compile"
453 if {[is_remote host]} {
455 set file [remote_download host $x]
457 warning "Unable to download $x to host."
458 return "Unable to download $x to host."
460 append sources " $file"
467 if {[is_remote host]} {
468 append add_flags " -o " [file tail $destfile]
469 remote_file host delete [file tail $destfile]
471 if { $destfile != "" } {
472 append add_flags " -o $destfile"
476 # This is obscure: we put SOURCES at the end when building an
477 # object, because otherwise, in some situations, libtool will
478 # become confused about the name of the actual source file.
481 set opts "$early_flags $add_flags $sources"
484 switch $linker_opts_order {
485 "flags-then-sources" {
486 set opts "$early_flags $add_flags $sources"
488 "sources-then-flags" {
489 set opts "$early_flags $sources $add_flags"
492 error "Invalid value for board_info linker_opts_order"
497 set opts "$early_flags $sources $add_flags"
501 if {[is_remote host]} {
502 if {[host_info exists use_at]} {
503 set fid [open "atfile" "w"]
506 set opts "@[remote_download host atfile]"
507 remote_file build delete atfile
511 verbose "Invoking the compiler as $compiler $opts" 2
513 if {[info exists redirect]} {
514 verbose "Redirecting output to $redirect" 2
515 set status [remote_exec host "$compiler $opts" "" "" $redirect]
517 if {[info exists timeout]} {
518 verbose "Setting timeout to $timeout" 2
519 set status [remote_exec host "$compiler $opts" "" "" "" $timeout]
521 set status [remote_exec host "$compiler $opts"]
525 set compiler_flags $opts
526 if {[is_remote host]} {
527 remote_upload host [file tail $destfile] $destfile
528 remote_file host delete [file tail $destfile]
530 set comp_output [prune_warnings [lindex $status 1]]
531 regsub "^\[\r\n\]+" $comp_output "" comp_output
532 if { [lindex $status 0] != 0 } {
533 verbose -log "compiler exited with status [lindex $status 0]"
535 if { [lindex $status 1] != "" } {
536 verbose -log "output is:\n[lindex $status 1]" 2
538 if { [lindex $status 0] != 0 && "${comp_output}" == "" } {
539 set comp_output "exit status is [lindex $status 0]"
541 return ${comp_output}
544 # See if the version of dejaGNU being used to run the testsuite is
545 # recent enough to contain support for building Ada programs or not.
546 # If not, then use the functions above in place of the ones provided
547 # by dejaGNU. This is only temporary (brobecker/2004-03-31).
549 set use_gdb_compile 0
550 if {[info procs find_gnatmake] == ""} {
551 rename gdb_find_gnatmake find_gnatmake
552 set use_gdb_compile 1
555 if {[info procs find_gfortran] == ""} {
556 rename gdb_find_gfortran find_gfortran
557 set use_gdb_compile 1
560 if {[info procs find_go_linker] == ""} {
561 rename gdb_find_go find_go
562 rename gdb_find_go_linker find_go_linker
563 set use_gdb_compile 1
566 if {$use_gdb_compile} {
567 catch {rename default_target_compile {}}
568 rename gdb_default_target_compile default_target_compile
572 # Provide 'lreverse' missing in Tcl before 7.5.
574 if {[info procs lreverse] == ""} {
575 proc lreverse { arg } {
577 while { [llength $retval] < [llength $arg] } {
578 lappend retval [lindex $arg end-[llength $retval]]