1 # Copyright 2004, 2007-2012 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_default_target_compile {source destfile type options} {
90 global CFLAGS_FOR_TARGET
93 if { $destfile == "" && $type != "preprocess" && $type != "none" } {
94 error "Must supply an output filename for the compile to default_target_compile"
102 # linker_opts_order is one of "sources-then-flags", "flags-then-sources".
103 # The order shouldn't matter. It's done this way to preserve
105 set linker_opts_order "sources-then-flags"
107 set dest [target_info name]
109 if {[info exists CFLAGS_FOR_TARGET]} {
110 append add_flags " $CFLAGS_FOR_TARGET"
113 if {[info exists target_info(host,name)]} {
114 set host [host_info name]
122 set compiler_type "ada"
123 if {[board_info $dest exists adaflags]} {
124 append add_flags " [target_info adaflags]"
126 if {[board_info $dest exists gnatmake]} {
127 set compiler [target_info gnatmake]
129 set compiler [find_gnatmake]
134 set compiler_type "c++"
135 if {[board_info $dest exists cxxflags]} {
136 append add_flags " [target_info cxxflags]"
138 append add_flags " [g++_include_flags]"
139 if {[board_info $dest exists c++compiler]} {
140 set compiler [target_info c++compiler]
142 set compiler [find_g++]
147 set compiler_type "f77"
148 if {[board_info $dest exists f77flags]} {
149 append add_flags " [target_info f77flags]"
151 if {[board_info $dest exists f77compiler]} {
152 set compiler [target_info f77compiler]
154 set compiler [find_g77]
159 set compiler_type "f90"
160 if {[board_info $dest exists f90flags]} {
161 append add_flags " [target_info f90flags]"
163 if {[board_info $dest exists f90compiler]} {
164 set compiler [target_info f90compiler]
166 set compiler [find_gfortran]
171 set compiler_type "go"
172 if {[board_info $dest exists goflags]} {
173 append add_flags " [target_info goflags]"
175 if {[board_info $dest exists gocompiler]} {
176 set compiler [target_info gocompiler]
178 set compiler [find_go]
180 if {[board_info $dest exists golinker]} {
181 set linker [target_info golinker]
183 set linker [find_go_linker]
185 if {[board_info $dest exists golinker_opts_order]} {
186 set linker_opts_order [target_info golinker_opts_order]
190 if {[regexp "^dest=" $i]} {
191 regsub "^dest=" $i "" tmp
192 if {[board_info $tmp exists name]} {
193 set dest [board_info $tmp name]
198 if {[regexp "^compiler=" $i]} {
199 regsub "^compiler=" $i "" tmp
202 if {[regexp "^additional_flags=" $i]} {
203 regsub "^additional_flags=" $i "" tmp
204 append add_flags " $tmp"
206 if {[regexp "^ldflags=" $i]} {
207 regsub "^ldflags=" $i "" tmp
208 append ldflags " $tmp"
210 if {[regexp "^libs=" $i]} {
211 regsub "^libs=" $i "" tmp
214 if {[regexp "^incdir=" $i]} {
215 regsub "^incdir=" $i "-I" tmp
216 append add_flags " $tmp"
218 if {[regexp "^libdir=" $i]} {
219 regsub "^libdir=" $i "-L" tmp
220 append add_flags " $tmp"
222 if {[regexp "^ldscript=" $i]} {
223 regsub "^ldscript=" $i "" ldscript
225 if {[regexp "^redirect=" $i]} {
226 regsub "^redirect=" $i "" redirect
228 if {[regexp "^optimize=" $i]} {
229 regsub "^optimize=" $i "" optimize
231 if {[regexp "^timeout=" $i]} {
232 regsub "^timeout=" $i "" timeout
236 if {[board_info $host exists cflags_for_target]} {
237 append add_flags " [board_info $host cflags_for_target]"
241 global CXX_FOR_TARGET
242 global F77_FOR_TARGET
243 global F90_FOR_TARGET
244 global GNATMAKE_FOR_TARGET
246 global GO_LD_FOR_TARGET
248 if {[info exists GNATMAKE_FOR_TARGET]} {
249 if { $compiler_type == "ada" } {
250 set compiler $GNATMAKE_FOR_TARGET
254 if {[info exists CC_FOR_TARGET]} {
255 if { $compiler == "" } {
256 set compiler $CC_FOR_TARGET
260 if {[info exists CXX_FOR_TARGET]} {
261 if { $compiler_type == "c++" } {
262 set compiler $CXX_FOR_TARGET
266 if {[info exists F77_FOR_TARGET]} {
267 if { $compiler_type == "f77" } {
268 set compiler $F77_FOR_TARGET
272 if {[info exists F90_FOR_TARGET]} {
273 if { $compiler_type == "f90" } {
274 set compiler $F90_FOR_TARGET
278 if { $compiler_type == "go" } {
279 if {[info exists GO_FOR_TARGET]} {
280 set compiler $GO_FOR_TARGET
282 if {[info exists GO_LD_FOR_TARGET]} {
283 set linker $GO_LD_FOR_TARGET
287 if { $type == "executable" && $linker != "" } {
291 if { $compiler == "" } {
292 set compiler [board_info $dest compiler]
293 if { $compiler == "" } {
294 return "default_target_compile: No compiler to compile with"
298 if {![is_remote host]} {
299 if { [which $compiler] == 0 } {
300 return "default_target_compile: Can't find $compiler."
304 if {$type == "object"} {
305 append add_flags " -c"
308 if { $type == "preprocess" } {
309 append add_flags " -E"
312 if { $type == "assembly" } {
313 append add_flags " -S"
316 if {[board_info $dest exists cflags]} {
317 append add_flags " [board_info $dest cflags]"
320 if { $type == "executable" } {
321 if {[board_info $dest exists ldflags]} {
322 append add_flags " [board_info $dest ldflags]"
324 if { $compiler_type == "c++" } {
325 append add_flags " [g++_link_flags]"
329 catch "glob -nocomplain $tool_root_dir/libstdc++/libstdc++.so* $tool_root_dir/libstdc++/libstdc++.sl" tmp
330 if { ${tmp} != "" } {
331 if {[regexp ".*solaris2.*" $target_triplet]} {
333 append add_flags " -R$tool_root_dir/libstdc++"
334 } elseif {[regexp ".*(osf|irix5|linux).*" $target_triplet]} {
336 append add_flags " -Wl,-rpath,$tool_root_dir/libstdc++"
337 } elseif {[regexp ".*hppa.*" $target_triplet]} {
339 append add_flags " -Wl,-a,shared_archive"
345 if {![info exists ldscript]} {
346 set ldscript [board_info $dest ldscript]
350 if { $i == "debug" } {
351 if {[board_info $dest exists debug_flags]} {
352 append add_flags " [board_info $dest debug_flags]"
354 append add_flags " -g"
359 if {[info exists optimize]} {
360 append add_flags " $optimize"
363 if { $type == "executable" } {
364 append add_flags " $ldflags"
366 if {[file exists $x]} {
369 append add_flags " $x"
373 if {[board_info $dest exists libs]} {
374 append add_flags " [board_info $dest libs]"
377 # This probably isn't such a good idea, but it avoids nasty
378 # hackiness in the testsuites.
379 # The math library must be linked in before the C library. The C
380 # library is linked in by the linker script, so this must be before
382 if {[board_info $dest exists mathlib]} {
383 append add_flags " [board_info $dest mathlib]"
385 append add_flags " -lm"
388 # This must be added here.
389 append add_flags " $ldscript"
391 if {[board_info $dest exists remote_link]} {
393 append add_flags " -Wl,-r"
395 if {[board_info $dest exists output_format]} {
396 append add_flags " -Wl,-oformat,[board_info $dest output_format]"
400 if {[board_info $dest exists multilib_flags]} {
401 append add_flags " [board_info $dest multilib_flags]"
404 verbose "doing compile"
407 if {[is_remote host]} {
409 set file [remote_download host $x]
411 warning "Unable to download $x to host."
412 return "Unable to download $x to host."
414 append sources " $file"
421 if {[is_remote host]} {
422 append add_flags " -o a.out"
423 remote_file host delete a.out
425 if { $destfile != "" } {
426 append add_flags " -o $destfile"
430 # This is obscure: we put SOURCES at the end when building an
431 # object, because otherwise, in some situations, libtool will
432 # become confused about the name of the actual source file.
435 set opts "$add_flags $sources"
438 switch $linker_opts_order {
439 "flags-then-sources" {
440 set opts "$add_flags $sources"
442 "sources-then-flags" {
443 set opts "$sources $add_flags"
446 error "Invalid value for board_info linker_opts_order"
451 set opts "$sources $add_flags"
455 if {[is_remote host]} {
456 if {[host_info exists use_at]} {
457 set fid [open "atfile" "w"]
460 set opts "@[remote_download host atfile]"
461 remote_file build delete atfile
465 verbose "Invoking the compiler as $compiler $opts" 2
467 if {[info exists redirect]} {
468 verbose "Redirecting output to $redirect" 2
469 set status [remote_exec host "$compiler $opts" "" "" $redirect]
471 if {[info exists timeout]} {
472 verbose "Setting timeout to $timeout" 2
473 set status [remote_exec host "$compiler $opts" "" "" "" $timeout]
475 set status [remote_exec host "$compiler $opts"]
479 set compiler_flags $opts
480 if {[is_remote host]} {
481 remote_upload host a.out $destfile
482 remote_file host delete a.out
484 set comp_output [prune_warnings [lindex $status 1]]
485 regsub "^\[\r\n\]+" $comp_output "" comp_output
486 if { [lindex $status 0] != 0 } {
487 verbose -log "compiler exited with status [lindex $status 0]"
489 if { [lindex $status 1] != "" } {
490 verbose -log "output is:\n[lindex $status 1]" 2
492 if { [lindex $status 0] != 0 && "${comp_output}" == "" } {
493 set comp_output "exit status is [lindex $status 0]"
495 return ${comp_output}
498 # See if the version of dejaGNU being used to run the testsuite is
499 # recent enough to contain support for building Ada programs or not.
500 # If not, then use the functions above in place of the ones provided
501 # by dejaGNU. This is only temporary (brobecker/2004-03-31).
503 set use_gdb_compile 0
504 if {[info procs find_gnatmake] == ""} {
505 rename gdb_find_gnatmake find_gnatmake
506 set use_gdb_compile 1
509 if {[info procs find_gfortran] == ""} {
510 rename gdb_find_gfortran find_gfortran
511 set use_gdb_compile 1
514 if {[info procs find_go_linker] == ""} {
515 rename gdb_find_go find_go
516 rename gdb_find_go_linker find_go_linker
517 set use_gdb_compile 1
520 if {$use_gdb_compile} {
521 catch {rename default_target_compile {}}
522 rename gdb_default_target_compile default_target_compile