more uses of standard_output_file
[deliverable/binutils-gdb.git] / gdb / testsuite / lib / future.exp
1 # Copyright 2004-2013 Free Software Foundation, Inc.
2 #
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.
7 #
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.
12 #
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/>.
15
16 load_lib libgloss.exp
17
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
22 # requirement.
23
24 proc gdb_find_gnatmake {} {
25 global tool_root_dir
26
27 set root "$tool_root_dir/gcc"
28 set GM ""
29
30 if ![is_remote host] {
31 set file [lookfor_file $root gnatmake]
32 if { $file != "" } {
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";
34 }
35 }
36
37 if {$GM == ""} {
38 set GM [transform gnatmake]
39 }
40
41 return $GM
42 }
43
44 proc gdb_find_gfortran {} {
45 global tool_root_dir
46
47 if {![is_remote host]} {
48 set file [lookfor_file $tool_root_dir gfortran]
49 if { $file == "" } {
50 set file [lookfor_file $tool_root_dir gcc/gfortran]
51 }
52 if { $file != "" } {
53 set CC "$file -B[file dirname $file]/"
54 } else {
55 set CC [transform gfortran]
56 }
57 } else {
58 set CC [transform gfortran]
59 }
60 return $CC
61 }
62
63 proc gdb_find_go {} {
64 global tool_root_dir
65
66 set GO ""
67
68 if {![is_remote host]} {
69 set file [lookfor_file $tool_root_dir gccgo]
70 if { $file != "" } {
71 set root [file dirname $file]
72 set GO "$file -B$root/gcc/"
73 }
74 }
75
76 if { $GO == "" } {
77 set GO [transform gccgo]
78 }
79
80 return $GO
81 }
82
83 proc gdb_find_go_linker {} {
84 return [find_go]
85 }
86
87 proc gdb_find_ldd {} {
88 global LDD_FOR_TARGET
89 if [info exists LDD_FOR_TARGET] {
90 set ldd $LDD_FOR_TARGET
91 } else {
92 set ldd "ldd"
93 }
94 return $ldd
95 }
96
97 proc gdb_default_target_compile {source destfile type options} {
98 global target_triplet
99 global tool_root_dir
100 global CFLAGS_FOR_TARGET
101 global compiler_flags
102
103 if { $destfile == "" && $type != "preprocess" && $type != "none" } {
104 error "Must supply an output filename for the compile to default_target_compile"
105 }
106
107 set add_flags ""
108 set libs ""
109 set compiler_type "c"
110 set compiler ""
111 set linker ""
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
114 # existing behavior.
115 set linker_opts_order "sources-then-flags"
116 set ldflags ""
117 set dest [target_info name]
118
119 if {[info exists CFLAGS_FOR_TARGET]} {
120 append add_flags " $CFLAGS_FOR_TARGET"
121 }
122
123 if {[info exists target_info(host,name)]} {
124 set host [host_info name]
125 } else {
126 set host "unix"
127 }
128
129 foreach i $options {
130
131 if { $i == "ada" } {
132 set compiler_type "ada"
133 if {[board_info $dest exists adaflags]} {
134 append add_flags " [target_info adaflags]"
135 }
136 if {[board_info $dest exists gnatmake]} {
137 set compiler [target_info gnatmake]
138 } else {
139 set compiler [find_gnatmake]
140 }
141 }
142
143 if { $i == "c++" } {
144 set compiler_type "c++"
145 if {[board_info $dest exists cxxflags]} {
146 append add_flags " [target_info cxxflags]"
147 }
148 append add_flags " [g++_include_flags]"
149 if {[board_info $dest exists c++compiler]} {
150 set compiler [target_info c++compiler]
151 } else {
152 set compiler [find_g++]
153 }
154 }
155
156 if { $i == "f77" } {
157 set compiler_type "f77"
158 if {[board_info $dest exists f77flags]} {
159 append add_flags " [target_info f77flags]"
160 }
161 if {[board_info $dest exists f77compiler]} {
162 set compiler [target_info f77compiler]
163 } else {
164 set compiler [find_g77]
165 }
166 }
167
168 if { $i == "f90" } {
169 set compiler_type "f90"
170 if {[board_info $dest exists f90flags]} {
171 append add_flags " [target_info f90flags]"
172 }
173 if {[board_info $dest exists f90compiler]} {
174 set compiler [target_info f90compiler]
175 } else {
176 set compiler [find_gfortran]
177 }
178 }
179
180 if { $i == "go" } {
181 set compiler_type "go"
182 if {[board_info $dest exists goflags]} {
183 append add_flags " [target_info goflags]"
184 }
185 if {[board_info $dest exists gocompiler]} {
186 set compiler [target_info gocompiler]
187 } else {
188 set compiler [find_go]
189 }
190 if {[board_info $dest exists golinker]} {
191 set linker [target_info golinker]
192 } else {
193 set linker [find_go_linker]
194 }
195 if {[board_info $dest exists golinker_opts_order]} {
196 set linker_opts_order [target_info golinker_opts_order]
197 }
198 }
199
200 if {[regexp "^dest=" $i]} {
201 regsub "^dest=" $i "" tmp
202 if {[board_info $tmp exists name]} {
203 set dest [board_info $tmp name]
204 } else {
205 set dest $tmp
206 }
207 }
208 if {[regexp "^compiler=" $i]} {
209 regsub "^compiler=" $i "" tmp
210 set compiler $tmp
211 }
212 if {[regexp "^additional_flags=" $i]} {
213 regsub "^additional_flags=" $i "" tmp
214 append add_flags " $tmp"
215 }
216 if {[regexp "^ldflags=" $i]} {
217 regsub "^ldflags=" $i "" tmp
218 append ldflags " $tmp"
219 }
220 if {[regexp "^libs=" $i]} {
221 regsub "^libs=" $i "" tmp
222 append libs " $tmp"
223 }
224 if {[regexp "^incdir=" $i]} {
225 regsub "^incdir=" $i "-I" tmp
226 append add_flags " $tmp"
227 }
228 if {[regexp "^libdir=" $i]} {
229 regsub "^libdir=" $i "-L" tmp
230 append add_flags " $tmp"
231 }
232 if {[regexp "^ldscript=" $i]} {
233 regsub "^ldscript=" $i "" ldscript
234 }
235 if {[regexp "^redirect=" $i]} {
236 regsub "^redirect=" $i "" redirect
237 }
238 if {[regexp "^optimize=" $i]} {
239 regsub "^optimize=" $i "" optimize
240 }
241 if {[regexp "^timeout=" $i]} {
242 regsub "^timeout=" $i "" timeout
243 }
244 }
245
246 if {[board_info $host exists cflags_for_target]} {
247 append add_flags " [board_info $host cflags_for_target]"
248 }
249
250 global CC_FOR_TARGET
251 global CXX_FOR_TARGET
252 global F77_FOR_TARGET
253 global F90_FOR_TARGET
254 global GNATMAKE_FOR_TARGET
255 global GO_FOR_TARGET
256 global GO_LD_FOR_TARGET
257
258 if {[info exists GNATMAKE_FOR_TARGET]} {
259 if { $compiler_type == "ada" } {
260 set compiler $GNATMAKE_FOR_TARGET
261 }
262 }
263
264 if {[info exists CC_FOR_TARGET]} {
265 if { $compiler == "" } {
266 set compiler $CC_FOR_TARGET
267 }
268 }
269
270 if {[info exists CXX_FOR_TARGET]} {
271 if { $compiler_type == "c++" } {
272 set compiler $CXX_FOR_TARGET
273 }
274 }
275
276 if {[info exists F77_FOR_TARGET]} {
277 if { $compiler_type == "f77" } {
278 set compiler $F77_FOR_TARGET
279 }
280 }
281
282 if {[info exists F90_FOR_TARGET]} {
283 if { $compiler_type == "f90" } {
284 set compiler $F90_FOR_TARGET
285 }
286 }
287
288 if { $compiler_type == "go" } {
289 if {[info exists GO_FOR_TARGET]} {
290 set compiler $GO_FOR_TARGET
291 }
292 if {[info exists GO_LD_FOR_TARGET]} {
293 set linker $GO_LD_FOR_TARGET
294 }
295 }
296
297 if { $type == "executable" && $linker != "" } {
298 set compiler $linker
299 }
300
301 if { $compiler == "" } {
302 set compiler [board_info $dest compiler]
303 if { $compiler == "" } {
304 return "default_target_compile: No compiler to compile with"
305 }
306 }
307
308 if {![is_remote host]} {
309 if { [which $compiler] == 0 } {
310 return "default_target_compile: Can't find $compiler."
311 }
312 }
313
314 if {$type == "object"} {
315 append add_flags " -c"
316 }
317
318 if { $type == "preprocess" } {
319 append add_flags " -E"
320 }
321
322 if { $type == "assembly" } {
323 append add_flags " -S"
324 }
325
326 if {[board_info $dest exists cflags]} {
327 append add_flags " [board_info $dest cflags]"
328 }
329
330 if { $type == "executable" } {
331 if {[board_info $dest exists ldflags]} {
332 append add_flags " [board_info $dest ldflags]"
333 }
334 if { $compiler_type == "c++" } {
335 append add_flags " [g++_link_flags]"
336 }
337 if {[isnative]} {
338 # This is a lose.
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]} {
342 # Solaris 2
343 append add_flags " -R$tool_root_dir/libstdc++"
344 } elseif {[regexp ".*(osf|irix5|linux).*" $target_triplet]} {
345 # OSF/1 or IRIX 5
346 append add_flags " -Wl,-rpath,$tool_root_dir/libstdc++"
347 } elseif {[regexp ".*hppa.*" $target_triplet]} {
348 # HP-UX
349 append add_flags " -Wl,-a,shared_archive"
350 }
351 }
352 }
353 }
354
355 if {![info exists ldscript]} {
356 set ldscript [board_info $dest ldscript]
357 }
358
359 foreach i $options {
360 if { $i == "debug" } {
361 if {[board_info $dest exists debug_flags]} {
362 append add_flags " [board_info $dest debug_flags]"
363 } else {
364 append add_flags " -g"
365 }
366 }
367 }
368
369 if {[info exists optimize]} {
370 append add_flags " $optimize"
371 }
372
373 if { $type == "executable" } {
374 append add_flags " $ldflags"
375 foreach x $libs {
376 if {[file exists $x]} {
377 append source " $x"
378 } else {
379 append add_flags " $x"
380 }
381 }
382
383 if {[board_info $dest exists libs]} {
384 append add_flags " [board_info $dest libs]"
385 }
386
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
391 # the linker script.
392 if {[board_info $dest exists mathlib]} {
393 append add_flags " [board_info $dest mathlib]"
394 } else {
395 append add_flags " -lm"
396 }
397
398 # This must be added here.
399 append add_flags " $ldscript"
400
401 if {[board_info $dest exists remote_link]} {
402 # Relink option.
403 append add_flags " -Wl,-r"
404 }
405 if {[board_info $dest exists output_format]} {
406 append add_flags " -Wl,-oformat,[board_info $dest output_format]"
407 }
408 }
409
410 if {[board_info $dest exists multilib_flags]} {
411 append add_flags " [board_info $dest multilib_flags]"
412 }
413
414 verbose "doing compile"
415
416 set sources ""
417 if {[is_remote host]} {
418 foreach x $source {
419 set file [remote_download host $x]
420 if { $file == "" } {
421 warning "Unable to download $x to host."
422 return "Unable to download $x to host."
423 } else {
424 append sources " $file"
425 }
426 }
427 } else {
428 set sources $source
429 }
430
431 if {[is_remote host]} {
432 append add_flags " -o " [file tail $destfile]
433 remote_file host delete [file tail $destfile]
434 } else {
435 if { $destfile != "" } {
436 append add_flags " -o $destfile"
437 }
438 }
439
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.
443 switch $type {
444 "object" {
445 set opts "$add_flags $sources"
446 }
447 "executable" {
448 switch $linker_opts_order {
449 "flags-then-sources" {
450 set opts "$add_flags $sources"
451 }
452 "sources-then-flags" {
453 set opts "$sources $add_flags"
454 }
455 default {
456 error "Invalid value for board_info linker_opts_order"
457 }
458 }
459 }
460 default {
461 set opts "$sources $add_flags"
462 }
463 }
464
465 if {[is_remote host]} {
466 if {[host_info exists use_at]} {
467 set fid [open "atfile" "w"]
468 puts $fid "$opts"
469 close $fid
470 set opts "@[remote_download host atfile]"
471 remote_file build delete atfile
472 }
473 }
474
475 verbose "Invoking the compiler as $compiler $opts" 2
476
477 if {[info exists redirect]} {
478 verbose "Redirecting output to $redirect" 2
479 set status [remote_exec host "$compiler $opts" "" "" $redirect]
480 } else {
481 if {[info exists timeout]} {
482 verbose "Setting timeout to $timeout" 2
483 set status [remote_exec host "$compiler $opts" "" "" "" $timeout]
484 } else {
485 set status [remote_exec host "$compiler $opts"]
486 }
487 }
488
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]
493 }
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]"
498 }
499 if { [lindex $status 1] != "" } {
500 verbose -log "output is:\n[lindex $status 1]" 2
501 }
502 if { [lindex $status 0] != 0 && "${comp_output}" == "" } {
503 set comp_output "exit status is [lindex $status 0]"
504 }
505 return ${comp_output}
506 }
507
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).
512
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
517 }
518
519 if {[info procs find_gfortran] == ""} {
520 rename gdb_find_gfortran find_gfortran
521 set use_gdb_compile 1
522 }
523
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
528 }
529
530 if {$use_gdb_compile} {
531 catch {rename default_target_compile {}}
532 rename gdb_default_target_compile default_target_compile
533 }
534
535
536 # Provide 'lreverse' missing in Tcl before 7.5.
537
538 if {[info procs lreverse] == ""} {
539 proc lreverse { arg } {
540 set retval {}
541 while { [llength $retval] < [llength $arg] } {
542 lappend retval [lindex $arg end-[llength $retval]]
543 }
544 return $retval
545 }
546 }
This page took 0.051735 seconds and 4 git commands to generate.