1 # Copyright 2004-2013 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_default_target_compile {source destfile type options} {
100 global CFLAGS_FOR_TARGET
101 global compiler_flags
103 if { $destfile == "" && $type != "preprocess" && $type != "none" } {
104 error "Must supply an output filename for the compile to default_target_compile"
109 set compiler_type "c"
112 # linker_opts_order is one of "sources-then-flags", "flags-then-sources".
113 # The order shouldn't matter. It's done this way to preserve
115 set linker_opts_order "sources-then-flags"
117 set dest [target_info name]
119 if {[info exists CFLAGS_FOR_TARGET]} {
120 append add_flags " $CFLAGS_FOR_TARGET"
123 if {[info exists target_info(host,name)]} {
124 set host [host_info name]
132 set compiler_type "ada"
133 if {[board_info $dest exists adaflags]} {
134 append add_flags " [target_info adaflags]"
136 if {[board_info $dest exists gnatmake]} {
137 set compiler [target_info gnatmake]
139 set compiler [find_gnatmake]
144 set compiler_type "c++"
145 if {[board_info $dest exists cxxflags]} {
146 append add_flags " [target_info cxxflags]"
148 append add_flags " [g++_include_flags]"
149 if {[board_info $dest exists c++compiler]} {
150 set compiler [target_info c++compiler]
152 set compiler [find_g++]
157 set compiler_type "f77"
158 if {[board_info $dest exists f77flags]} {
159 append add_flags " [target_info f77flags]"
161 if {[board_info $dest exists f77compiler]} {
162 set compiler [target_info f77compiler]
164 set compiler [find_g77]
169 set compiler_type "f90"
170 if {[board_info $dest exists f90flags]} {
171 append add_flags " [target_info f90flags]"
173 if {[board_info $dest exists f90compiler]} {
174 set compiler [target_info f90compiler]
176 set compiler [find_gfortran]
181 set compiler_type "go"
182 if {[board_info $dest exists goflags]} {
183 append add_flags " [target_info goflags]"
185 if {[board_info $dest exists gocompiler]} {
186 set compiler [target_info gocompiler]
188 set compiler [find_go]
190 if {[board_info $dest exists golinker]} {
191 set linker [target_info golinker]
193 set linker [find_go_linker]
195 if {[board_info $dest exists golinker_opts_order]} {
196 set linker_opts_order [target_info golinker_opts_order]
200 if {[regexp "^dest=" $i]} {
201 regsub "^dest=" $i "" tmp
202 if {[board_info $tmp exists name]} {
203 set dest [board_info $tmp name]
208 if {[regexp "^compiler=" $i]} {
209 regsub "^compiler=" $i "" tmp
212 if {[regexp "^additional_flags=" $i]} {
213 regsub "^additional_flags=" $i "" tmp
214 append add_flags " $tmp"
216 if {[regexp "^ldflags=" $i]} {
217 regsub "^ldflags=" $i "" tmp
218 append ldflags " $tmp"
220 if {[regexp "^libs=" $i]} {
221 regsub "^libs=" $i "" tmp
224 if {[regexp "^incdir=" $i]} {
225 regsub "^incdir=" $i "-I" tmp
226 append add_flags " $tmp"
228 if {[regexp "^libdir=" $i]} {
229 regsub "^libdir=" $i "-L" tmp
230 append add_flags " $tmp"
232 if {[regexp "^ldscript=" $i]} {
233 regsub "^ldscript=" $i "" ldscript
235 if {[regexp "^redirect=" $i]} {
236 regsub "^redirect=" $i "" redirect
238 if {[regexp "^optimize=" $i]} {
239 regsub "^optimize=" $i "" optimize
241 if {[regexp "^timeout=" $i]} {
242 regsub "^timeout=" $i "" timeout
246 if {[board_info $host exists cflags_for_target]} {
247 append add_flags " [board_info $host cflags_for_target]"
251 global CXX_FOR_TARGET
252 global F77_FOR_TARGET
253 global F90_FOR_TARGET
254 global GNATMAKE_FOR_TARGET
256 global GO_LD_FOR_TARGET
258 if {[info exists GNATMAKE_FOR_TARGET]} {
259 if { $compiler_type == "ada" } {
260 set compiler $GNATMAKE_FOR_TARGET
264 if {[info exists CC_FOR_TARGET]} {
265 if { $compiler == "" } {
266 set compiler $CC_FOR_TARGET
270 if {[info exists CXX_FOR_TARGET]} {
271 if { $compiler_type == "c++" } {
272 set compiler $CXX_FOR_TARGET
276 if {[info exists F77_FOR_TARGET]} {
277 if { $compiler_type == "f77" } {
278 set compiler $F77_FOR_TARGET
282 if {[info exists F90_FOR_TARGET]} {
283 if { $compiler_type == "f90" } {
284 set compiler $F90_FOR_TARGET
288 if { $compiler_type == "go" } {
289 if {[info exists GO_FOR_TARGET]} {
290 set compiler $GO_FOR_TARGET
292 if {[info exists GO_LD_FOR_TARGET]} {
293 set linker $GO_LD_FOR_TARGET
297 if { $type == "executable" && $linker != "" } {
301 if { $compiler == "" } {
302 set compiler [board_info $dest compiler]
303 if { $compiler == "" } {
304 return "default_target_compile: No compiler to compile with"
308 if {![is_remote host]} {
309 if { [which $compiler] == 0 } {
310 return "default_target_compile: Can't find $compiler."
314 if {$type == "object"} {
315 append add_flags " -c"
318 if { $type == "preprocess" } {
319 append add_flags " -E"
322 if { $type == "assembly" } {
323 append add_flags " -S"
326 if {[board_info $dest exists cflags]} {
327 append add_flags " [board_info $dest cflags]"
330 if { $type == "executable" } {
331 if {[board_info $dest exists ldflags]} {
332 append add_flags " [board_info $dest ldflags]"
334 if { $compiler_type == "c++" } {
335 append add_flags " [g++_link_flags]"
339 catch "glob -nocomplain $tool_root_dir/libstdc++/libstdc++.so* $tool_root_dir/libstdc++/libstdc++.sl" tmp
340 if { ${tmp} != "" } {
341 if {[regexp ".*solaris2.*" $target_triplet]} {
343 append add_flags " -R$tool_root_dir/libstdc++"
344 } elseif {[regexp ".*(osf|irix5|linux).*" $target_triplet]} {
346 append add_flags " -Wl,-rpath,$tool_root_dir/libstdc++"
347 } elseif {[regexp ".*hppa.*" $target_triplet]} {
349 append add_flags " -Wl,-a,shared_archive"
355 if {![info exists ldscript]} {
356 set ldscript [board_info $dest ldscript]
360 if { $i == "debug" } {
361 if {[board_info $dest exists debug_flags]} {
362 append add_flags " [board_info $dest debug_flags]"
364 append add_flags " -g"
369 if {[info exists optimize]} {
370 append add_flags " $optimize"
373 if { $type == "executable" } {
374 append add_flags " $ldflags"
376 if {[file exists $x]} {
379 append add_flags " $x"
383 if {[board_info $dest exists libs]} {
384 append add_flags " [board_info $dest libs]"
387 # This probably isn't such a good idea, but it avoids nasty
388 # hackiness in the testsuites.
389 # The math library must be linked in before the C library. The C
390 # library is linked in by the linker script, so this must be before
392 if {[board_info $dest exists mathlib]} {
393 append add_flags " [board_info $dest mathlib]"
395 append add_flags " -lm"
398 # This must be added here.
399 append add_flags " $ldscript"
401 if {[board_info $dest exists remote_link]} {
403 append add_flags " -Wl,-r"
405 if {[board_info $dest exists output_format]} {
406 append add_flags " -Wl,-oformat,[board_info $dest output_format]"
410 if {[board_info $dest exists multilib_flags]} {
411 append add_flags " [board_info $dest multilib_flags]"
414 verbose "doing compile"
417 if {[is_remote host]} {
419 set file [remote_download host $x]
421 warning "Unable to download $x to host."
422 return "Unable to download $x to host."
424 append sources " $file"
431 if {[is_remote host]} {
432 append add_flags " -o " [file tail $destfile]
433 remote_file host delete [file tail $destfile]
435 if { $destfile != "" } {
436 append add_flags " -o $destfile"
440 # This is obscure: we put SOURCES at the end when building an
441 # object, because otherwise, in some situations, libtool will
442 # become confused about the name of the actual source file.
445 set opts "$add_flags $sources"
448 switch $linker_opts_order {
449 "flags-then-sources" {
450 set opts "$add_flags $sources"
452 "sources-then-flags" {
453 set opts "$sources $add_flags"
456 error "Invalid value for board_info linker_opts_order"
461 set opts "$sources $add_flags"
465 if {[is_remote host]} {
466 if {[host_info exists use_at]} {
467 set fid [open "atfile" "w"]
470 set opts "@[remote_download host atfile]"
471 remote_file build delete atfile
475 verbose "Invoking the compiler as $compiler $opts" 2
477 if {[info exists redirect]} {
478 verbose "Redirecting output to $redirect" 2
479 set status [remote_exec host "$compiler $opts" "" "" $redirect]
481 if {[info exists timeout]} {
482 verbose "Setting timeout to $timeout" 2
483 set status [remote_exec host "$compiler $opts" "" "" "" $timeout]
485 set status [remote_exec host "$compiler $opts"]
489 set compiler_flags $opts
490 if {[is_remote host]} {
491 remote_upload host [file tail $destfile] $destfile
492 remote_file host delete [file tail $destfile]
494 set comp_output [prune_warnings [lindex $status 1]]
495 regsub "^\[\r\n\]+" $comp_output "" comp_output
496 if { [lindex $status 0] != 0 } {
497 verbose -log "compiler exited with status [lindex $status 0]"
499 if { [lindex $status 1] != "" } {
500 verbose -log "output is:\n[lindex $status 1]" 2
502 if { [lindex $status 0] != 0 && "${comp_output}" == "" } {
503 set comp_output "exit status is [lindex $status 0]"
505 return ${comp_output}
508 # See if the version of dejaGNU being used to run the testsuite is
509 # recent enough to contain support for building Ada programs or not.
510 # If not, then use the functions above in place of the ones provided
511 # by dejaGNU. This is only temporary (brobecker/2004-03-31).
513 set use_gdb_compile 0
514 if {[info procs find_gnatmake] == ""} {
515 rename gdb_find_gnatmake find_gnatmake
516 set use_gdb_compile 1
519 if {[info procs find_gfortran] == ""} {
520 rename gdb_find_gfortran find_gfortran
521 set use_gdb_compile 1
524 if {[info procs find_go_linker] == ""} {
525 rename gdb_find_go find_go
526 rename gdb_find_go_linker find_go_linker
527 set use_gdb_compile 1
530 if {$use_gdb_compile} {
531 catch {rename default_target_compile {}}
532 rename gdb_default_target_compile default_target_compile
536 # Provide 'lreverse' missing in Tcl before 7.5.
538 if {[info procs lreverse] == ""} {
539 proc lreverse { arg } {
541 while { [llength $retval] < [llength $arg] } {
542 lappend retval [lindex $arg end-[llength $retval]]