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 proc gdb_find_readelf {} {
108 global READELF_FOR_TARGET
109 if [info exists READELF_FOR_TARGET] {
110 set readelf $READELF_FOR_TARGET
112 set readelf [transform readelf]
117 proc gdb_default_target_compile {source destfile type options} {
118 global target_triplet
120 global CFLAGS_FOR_TARGET
121 global compiler_flags
123 if { $destfile == "" && $type != "preprocess" && $type != "none" } {
124 error "Must supply an output filename for the compile to default_target_compile"
129 set compiler_type "c"
132 # linker_opts_order is one of "sources-then-flags", "flags-then-sources".
133 # The order shouldn't matter. It's done this way to preserve
135 set linker_opts_order "sources-then-flags"
137 set dest [target_info name]
139 if {[info exists CFLAGS_FOR_TARGET]} {
140 append add_flags " $CFLAGS_FOR_TARGET"
143 if {[info exists target_info(host,name)]} {
144 set host [host_info name]
152 set compiler_type "ada"
153 if {[board_info $dest exists adaflags]} {
154 append add_flags " [target_info adaflags]"
156 if {[board_info $dest exists gnatmake]} {
157 set compiler [target_info gnatmake]
159 set compiler [find_gnatmake]
164 set compiler_type "c++"
165 if {[board_info $dest exists cxxflags]} {
166 append add_flags " [target_info cxxflags]"
168 append add_flags " [g++_include_flags]"
169 if {[board_info $dest exists c++compiler]} {
170 set compiler [target_info c++compiler]
172 set compiler [find_g++]
177 set compiler_type "f77"
178 if {[board_info $dest exists f77flags]} {
179 append add_flags " [target_info f77flags]"
181 if {[board_info $dest exists f77compiler]} {
182 set compiler [target_info f77compiler]
184 set compiler [find_g77]
189 set compiler_type "f90"
190 if {[board_info $dest exists f90flags]} {
191 append add_flags " [target_info f90flags]"
193 if {[board_info $dest exists f90compiler]} {
194 set compiler [target_info f90compiler]
196 set compiler [find_gfortran]
201 set compiler_type "go"
202 if {[board_info $dest exists goflags]} {
203 append add_flags " [target_info goflags]"
205 if {[board_info $dest exists gocompiler]} {
206 set compiler [target_info gocompiler]
208 set compiler [find_go]
210 if {[board_info $dest exists golinker]} {
211 set linker [target_info golinker]
213 set linker [find_go_linker]
215 if {[board_info $dest exists golinker_opts_order]} {
216 set linker_opts_order [target_info golinker_opts_order]
220 if {[regexp "^dest=" $i]} {
221 regsub "^dest=" $i "" tmp
222 if {[board_info $tmp exists name]} {
223 set dest [board_info $tmp name]
228 if {[regexp "^compiler=" $i]} {
229 regsub "^compiler=" $i "" tmp
232 if {[regexp "^additional_flags=" $i]} {
233 regsub "^additional_flags=" $i "" tmp
234 append add_flags " $tmp"
236 if {[regexp "^ldflags=" $i]} {
237 regsub "^ldflags=" $i "" tmp
238 append ldflags " $tmp"
240 if {[regexp "^libs=" $i]} {
241 regsub "^libs=" $i "" tmp
244 if {[regexp "^incdir=" $i]} {
245 regsub "^incdir=" $i "-I" tmp
246 append add_flags " $tmp"
248 if {[regexp "^libdir=" $i]} {
249 regsub "^libdir=" $i "-L" tmp
250 append add_flags " $tmp"
252 if {[regexp "^ldscript=" $i]} {
253 regsub "^ldscript=" $i "" ldscript
255 if {[regexp "^redirect=" $i]} {
256 regsub "^redirect=" $i "" redirect
258 if {[regexp "^optimize=" $i]} {
259 regsub "^optimize=" $i "" optimize
261 if {[regexp "^timeout=" $i]} {
262 regsub "^timeout=" $i "" timeout
266 if {[board_info $host exists cflags_for_target]} {
267 append add_flags " [board_info $host cflags_for_target]"
271 global CXX_FOR_TARGET
272 global F77_FOR_TARGET
273 global F90_FOR_TARGET
274 global GNATMAKE_FOR_TARGET
276 global GO_LD_FOR_TARGET
278 if {[info exists GNATMAKE_FOR_TARGET]} {
279 if { $compiler_type == "ada" } {
280 set compiler $GNATMAKE_FOR_TARGET
284 if {[info exists CC_FOR_TARGET]} {
285 if { $compiler == "" } {
286 set compiler $CC_FOR_TARGET
290 if {[info exists CXX_FOR_TARGET]} {
291 if { $compiler_type == "c++" } {
292 set compiler $CXX_FOR_TARGET
296 if {[info exists F77_FOR_TARGET]} {
297 if { $compiler_type == "f77" } {
298 set compiler $F77_FOR_TARGET
302 if {[info exists F90_FOR_TARGET]} {
303 if { $compiler_type == "f90" } {
304 set compiler $F90_FOR_TARGET
308 if { $compiler_type == "go" } {
309 if {[info exists GO_FOR_TARGET]} {
310 set compiler $GO_FOR_TARGET
312 if {[info exists GO_LD_FOR_TARGET]} {
313 set linker $GO_LD_FOR_TARGET
317 if { $type == "executable" && $linker != "" } {
321 if { $compiler == "" } {
322 set compiler [board_info $dest compiler]
323 if { $compiler == "" } {
324 return "default_target_compile: No compiler to compile with"
328 if {![is_remote host]} {
329 if { [which $compiler] == 0 } {
330 return "default_target_compile: Can't find $compiler."
334 if {$type == "object"} {
335 append add_flags " -c"
338 if { $type == "preprocess" } {
339 append add_flags " -E"
342 if { $type == "assembly" } {
343 append add_flags " -S"
346 if {[board_info $dest exists cflags]} {
347 append add_flags " [board_info $dest cflags]"
350 if { $type == "executable" } {
351 if {[board_info $dest exists ldflags]} {
352 append add_flags " [board_info $dest ldflags]"
354 if { $compiler_type == "c++" } {
355 append add_flags " [g++_link_flags]"
359 catch "glob -nocomplain $tool_root_dir/libstdc++/libstdc++.so* $tool_root_dir/libstdc++/libstdc++.sl" tmp
360 if { ${tmp} != "" } {
361 if {[regexp ".*solaris2.*" $target_triplet]} {
363 append add_flags " -R$tool_root_dir/libstdc++"
364 } elseif {[regexp ".*(osf|irix5|linux).*" $target_triplet]} {
366 append add_flags " -Wl,-rpath,$tool_root_dir/libstdc++"
367 } elseif {[regexp ".*hppa.*" $target_triplet]} {
369 append add_flags " -Wl,-a,shared_archive"
375 if {![info exists ldscript]} {
376 set ldscript [board_info $dest ldscript]
380 if { $i == "debug" } {
381 if {[board_info $dest exists debug_flags]} {
382 append add_flags " [board_info $dest debug_flags]"
384 append add_flags " -g"
389 if {[info exists optimize]} {
390 append add_flags " $optimize"
393 if { $type == "executable" } {
394 append add_flags " $ldflags"
396 if {[file exists $x]} {
399 append add_flags " $x"
403 if {[board_info $dest exists libs]} {
404 append add_flags " [board_info $dest libs]"
407 # This probably isn't such a good idea, but it avoids nasty
408 # hackiness in the testsuites.
409 # The math library must be linked in before the C library. The C
410 # library is linked in by the linker script, so this must be before
412 if {[board_info $dest exists mathlib]} {
413 append add_flags " [board_info $dest mathlib]"
415 append add_flags " -lm"
418 # This must be added here.
419 append add_flags " $ldscript"
421 if {[board_info $dest exists remote_link]} {
423 append add_flags " -Wl,-r"
425 if {[board_info $dest exists output_format]} {
426 append add_flags " -Wl,-oformat,[board_info $dest output_format]"
430 if {[board_info $dest exists multilib_flags]} {
431 append add_flags " [board_info $dest multilib_flags]"
434 verbose "doing compile"
437 if {[is_remote host]} {
439 set file [remote_download host $x]
441 warning "Unable to download $x to host."
442 return "Unable to download $x to host."
444 append sources " $file"
451 if {[is_remote host]} {
452 append add_flags " -o " [file tail $destfile]
453 remote_file host delete [file tail $destfile]
455 if { $destfile != "" } {
456 append add_flags " -o $destfile"
460 # This is obscure: we put SOURCES at the end when building an
461 # object, because otherwise, in some situations, libtool will
462 # become confused about the name of the actual source file.
465 set opts "$add_flags $sources"
468 switch $linker_opts_order {
469 "flags-then-sources" {
470 set opts "$add_flags $sources"
472 "sources-then-flags" {
473 set opts "$sources $add_flags"
476 error "Invalid value for board_info linker_opts_order"
481 set opts "$sources $add_flags"
485 if {[is_remote host]} {
486 if {[host_info exists use_at]} {
487 set fid [open "atfile" "w"]
490 set opts "@[remote_download host atfile]"
491 remote_file build delete atfile
495 verbose "Invoking the compiler as $compiler $opts" 2
497 if {[info exists redirect]} {
498 verbose "Redirecting output to $redirect" 2
499 set status [remote_exec host "$compiler $opts" "" "" $redirect]
501 if {[info exists timeout]} {
502 verbose "Setting timeout to $timeout" 2
503 set status [remote_exec host "$compiler $opts" "" "" "" $timeout]
505 set status [remote_exec host "$compiler $opts"]
509 set compiler_flags $opts
510 if {[is_remote host]} {
511 remote_upload host [file tail $destfile] $destfile
512 remote_file host delete [file tail $destfile]
514 set comp_output [prune_warnings [lindex $status 1]]
515 regsub "^\[\r\n\]+" $comp_output "" comp_output
516 if { [lindex $status 0] != 0 } {
517 verbose -log "compiler exited with status [lindex $status 0]"
519 if { [lindex $status 1] != "" } {
520 verbose -log "output is:\n[lindex $status 1]" 2
522 if { [lindex $status 0] != 0 && "${comp_output}" == "" } {
523 set comp_output "exit status is [lindex $status 0]"
525 return ${comp_output}
528 # See if the version of dejaGNU being used to run the testsuite is
529 # recent enough to contain support for building Ada programs or not.
530 # If not, then use the functions above in place of the ones provided
531 # by dejaGNU. This is only temporary (brobecker/2004-03-31).
533 set use_gdb_compile 0
534 if {[info procs find_gnatmake] == ""} {
535 rename gdb_find_gnatmake find_gnatmake
536 set use_gdb_compile 1
539 if {[info procs find_gfortran] == ""} {
540 rename gdb_find_gfortran find_gfortran
541 set use_gdb_compile 1
544 if {[info procs find_go_linker] == ""} {
545 rename gdb_find_go find_go
546 rename gdb_find_go_linker find_go_linker
547 set use_gdb_compile 1
550 if {$use_gdb_compile} {
551 catch {rename default_target_compile {}}
552 rename gdb_default_target_compile default_target_compile
556 # Provide 'lreverse' missing in Tcl before 7.5.
558 if {[info procs lreverse] == ""} {
559 proc lreverse { arg } {
561 while { [llength $retval] < [llength $arg] } {
562 lappend retval [lindex $arg end-[llength $retval]]