Workaround debian change to default value of --as-needed.
[deliverable/binutils-gdb.git] / gdb / testsuite / lib / future.exp
1 # Copyright 2004-2015 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_find_objcopy {} {
98 global OBJCOPY_FOR_TARGET
99 if [info exists OBJCOPY_FOR_TARGET] {
100 set objcopy $OBJCOPY_FOR_TARGET
101 } else {
102 set objcopy [transform objcopy]
103 }
104 return $objcopy
105 }
106
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
112 } else {
113 set objdump [transform objdump]
114 }
115 return $objdump
116 }
117
118 proc gdb_find_readelf {} {
119 global READELF_FOR_TARGET
120 if [info exists READELF_FOR_TARGET] {
121 set readelf $READELF_FOR_TARGET
122 } else {
123 set readelf [transform readelf]
124 }
125 return $readelf
126 }
127
128 proc gdb_default_target_compile {source destfile type options} {
129 global target_triplet
130 global tool_root_dir
131 global CFLAGS_FOR_TARGET
132 global compiler_flags
133
134 if { $destfile == "" && $type != "preprocess" && $type != "none" } {
135 error "Must supply an output filename for the compile to default_target_compile"
136 }
137
138 set early_flags ""
139 set add_flags ""
140 set libs ""
141 set compiler_type "c"
142 set compiler ""
143 set linker ""
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"
148 set ldflags ""
149 set dest [target_info name]
150
151 if {[info exists CFLAGS_FOR_TARGET]} {
152 append add_flags " $CFLAGS_FOR_TARGET"
153 }
154
155 if {[info exists target_info(host,name)]} {
156 set host [host_info name]
157 } else {
158 set host "unix"
159 }
160
161 foreach i $options {
162
163 if { $i == "ada" } {
164 set compiler_type "ada"
165 if {[board_info $dest exists adaflags]} {
166 append add_flags " [target_info adaflags]"
167 }
168 if {[board_info $dest exists gnatmake]} {
169 set compiler [target_info gnatmake]
170 } else {
171 set compiler [find_gnatmake]
172 }
173 }
174
175 if { $i == "c++" } {
176 set compiler_type "c++"
177 if {[board_info $dest exists cxxflags]} {
178 append add_flags " [target_info cxxflags]"
179 }
180 append add_flags " [g++_include_flags]"
181 if {[board_info $dest exists c++compiler]} {
182 set compiler [target_info c++compiler]
183 } else {
184 set compiler [find_g++]
185 }
186 }
187
188 if { $i == "f77" } {
189 set compiler_type "f77"
190 if {[board_info $dest exists f77flags]} {
191 append add_flags " [target_info f77flags]"
192 }
193 if {[board_info $dest exists f77compiler]} {
194 set compiler [target_info f77compiler]
195 } else {
196 set compiler [find_g77]
197 }
198 }
199
200 if { $i == "f90" } {
201 set compiler_type "f90"
202 if {[board_info $dest exists f90flags]} {
203 append add_flags " [target_info f90flags]"
204 }
205 if {[board_info $dest exists f90compiler]} {
206 set compiler [target_info f90compiler]
207 } else {
208 set compiler [find_gfortran]
209 }
210 }
211
212 if { $i == "go" } {
213 set compiler_type "go"
214 if {[board_info $dest exists goflags]} {
215 append add_flags " [target_info goflags]"
216 }
217 if {[board_info $dest exists gocompiler]} {
218 set compiler [target_info gocompiler]
219 } else {
220 set compiler [find_go]
221 }
222 if {[board_info $dest exists golinker]} {
223 set linker [target_info golinker]
224 } else {
225 set linker [find_go_linker]
226 }
227 if {[board_info $dest exists golinker_opts_order]} {
228 set linker_opts_order [target_info golinker_opts_order]
229 }
230 }
231
232 if {[regexp "^dest=" $i]} {
233 regsub "^dest=" $i "" tmp
234 if {[board_info $tmp exists name]} {
235 set dest [board_info $tmp name]
236 } else {
237 set dest $tmp
238 }
239 }
240 if {[regexp "^compiler=" $i]} {
241 regsub "^compiler=" $i "" tmp
242 set compiler $tmp
243 }
244 if {[regexp "^early_flags=" $i]} {
245 regsub "^early_flags=" $i "" tmp
246 append early_flags " $tmp"
247 }
248 if {[regexp "^additional_flags=" $i]} {
249 regsub "^additional_flags=" $i "" tmp
250 append add_flags " $tmp"
251 }
252 if {[regexp "^ldflags=" $i]} {
253 regsub "^ldflags=" $i "" tmp
254 append ldflags " $tmp"
255 }
256 if {[regexp "^libs=" $i]} {
257 regsub "^libs=" $i "" tmp
258 append libs " $tmp"
259 }
260 if {[regexp "^incdir=" $i]} {
261 regsub "^incdir=" $i "-I" tmp
262 append add_flags " $tmp"
263 }
264 if {[regexp "^libdir=" $i]} {
265 regsub "^libdir=" $i "-L" tmp
266 append add_flags " $tmp"
267 }
268 if {[regexp "^ldscript=" $i]} {
269 regsub "^ldscript=" $i "" ldscript
270 }
271 if {[regexp "^redirect=" $i]} {
272 regsub "^redirect=" $i "" redirect
273 }
274 if {[regexp "^optimize=" $i]} {
275 regsub "^optimize=" $i "" optimize
276 }
277 if {[regexp "^timeout=" $i]} {
278 regsub "^timeout=" $i "" timeout
279 }
280 }
281
282 if {[board_info $host exists cflags_for_target]} {
283 append add_flags " [board_info $host cflags_for_target]"
284 }
285
286 global CC_FOR_TARGET
287 global CXX_FOR_TARGET
288 global F77_FOR_TARGET
289 global F90_FOR_TARGET
290 global GNATMAKE_FOR_TARGET
291 global GO_FOR_TARGET
292 global GO_LD_FOR_TARGET
293
294 if {[info exists GNATMAKE_FOR_TARGET]} {
295 if { $compiler_type == "ada" } {
296 set compiler $GNATMAKE_FOR_TARGET
297 }
298 }
299
300 if {[info exists CC_FOR_TARGET]} {
301 if { $compiler == "" } {
302 set compiler $CC_FOR_TARGET
303 }
304 }
305
306 if {[info exists CXX_FOR_TARGET]} {
307 if { $compiler_type == "c++" } {
308 set compiler $CXX_FOR_TARGET
309 }
310 }
311
312 if {[info exists F77_FOR_TARGET]} {
313 if { $compiler_type == "f77" } {
314 set compiler $F77_FOR_TARGET
315 }
316 }
317
318 if {[info exists F90_FOR_TARGET]} {
319 if { $compiler_type == "f90" } {
320 set compiler $F90_FOR_TARGET
321 }
322 }
323
324 if { $compiler_type == "go" } {
325 if {[info exists GO_FOR_TARGET]} {
326 set compiler $GO_FOR_TARGET
327 }
328 if {[info exists GO_LD_FOR_TARGET]} {
329 set linker $GO_LD_FOR_TARGET
330 }
331 }
332
333 if { $type == "executable" && $linker != "" } {
334 set compiler $linker
335 }
336
337 if { $compiler == "" } {
338 set compiler [board_info $dest compiler]
339 if { $compiler == "" } {
340 return "default_target_compile: No compiler to compile with"
341 }
342 }
343
344 if {![is_remote host]} {
345 if { [which $compiler] == 0 } {
346 return "default_target_compile: Can't find $compiler."
347 }
348 }
349
350 if {$type == "object"} {
351 append add_flags " -c"
352 }
353
354 if { $type == "preprocess" } {
355 append add_flags " -E"
356 }
357
358 if { $type == "assembly" } {
359 append add_flags " -S"
360 }
361
362 if {[board_info $dest exists cflags]} {
363 append add_flags " [board_info $dest cflags]"
364 }
365
366 if { $type == "executable" } {
367 if {[board_info $dest exists ldflags]} {
368 append add_flags " [board_info $dest ldflags]"
369 }
370 if { $compiler_type == "c++" } {
371 append add_flags " [g++_link_flags]"
372 }
373 if {[isnative]} {
374 # This is a lose.
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]} {
378 # Solaris 2
379 append add_flags " -R$tool_root_dir/libstdc++"
380 } elseif {[regexp ".*(osf|irix5|linux).*" $target_triplet]} {
381 # OSF/1 or IRIX 5
382 append add_flags " -Wl,-rpath,$tool_root_dir/libstdc++"
383 } elseif {[regexp ".*hppa.*" $target_triplet]} {
384 # HP-UX
385 append add_flags " -Wl,-a,shared_archive"
386 }
387 }
388 }
389 }
390
391 if {![info exists ldscript]} {
392 set ldscript [board_info $dest ldscript]
393 }
394
395 foreach i $options {
396 if { $i == "debug" } {
397 if {[board_info $dest exists debug_flags]} {
398 append add_flags " [board_info $dest debug_flags]"
399 } else {
400 append add_flags " -g"
401 }
402 }
403 }
404
405 if {[info exists optimize]} {
406 append add_flags " $optimize"
407 }
408
409 if { $type == "executable" } {
410 append add_flags " $ldflags"
411 foreach x $libs {
412 if {[file exists $x]} {
413 append source " $x"
414 } else {
415 append add_flags " $x"
416 }
417 }
418
419 if {[board_info $dest exists libs]} {
420 append add_flags " [board_info $dest libs]"
421 }
422
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
427 # the linker script.
428 if {[board_info $dest exists mathlib]} {
429 append add_flags " [board_info $dest mathlib]"
430 } else {
431 append add_flags " -lm"
432 }
433
434 # This must be added here.
435 append add_flags " $ldscript"
436
437 if {[board_info $dest exists remote_link]} {
438 # Relink option.
439 append add_flags " -Wl,-r"
440 }
441 if {[board_info $dest exists output_format]} {
442 append add_flags " -Wl,-oformat,[board_info $dest output_format]"
443 }
444 }
445
446 if {[board_info $dest exists multilib_flags]} {
447 append add_flags " [board_info $dest multilib_flags]"
448 }
449
450 verbose "doing compile"
451
452 set sources ""
453 if {[is_remote host]} {
454 foreach x $source {
455 set file [remote_download host $x]
456 if { $file == "" } {
457 warning "Unable to download $x to host."
458 return "Unable to download $x to host."
459 } else {
460 append sources " $file"
461 }
462 }
463 } else {
464 set sources $source
465 }
466
467 if {[is_remote host]} {
468 append add_flags " -o " [file tail $destfile]
469 remote_file host delete [file tail $destfile]
470 } else {
471 if { $destfile != "" } {
472 append add_flags " -o $destfile"
473 }
474 }
475
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.
479 switch $type {
480 "object" {
481 set opts "$early_flags $add_flags $sources"
482 }
483 "executable" {
484 switch $linker_opts_order {
485 "flags-then-sources" {
486 set opts "$early_flags $add_flags $sources"
487 }
488 "sources-then-flags" {
489 set opts "$early_flags $sources $add_flags"
490 }
491 default {
492 error "Invalid value for board_info linker_opts_order"
493 }
494 }
495 }
496 default {
497 set opts "$early_flags $sources $add_flags"
498 }
499 }
500
501 if {[is_remote host]} {
502 if {[host_info exists use_at]} {
503 set fid [open "atfile" "w"]
504 puts $fid "$opts"
505 close $fid
506 set opts "@[remote_download host atfile]"
507 remote_file build delete atfile
508 }
509 }
510
511 verbose "Invoking the compiler as $compiler $opts" 2
512
513 if {[info exists redirect]} {
514 verbose "Redirecting output to $redirect" 2
515 set status [remote_exec host "$compiler $opts" "" "" $redirect]
516 } else {
517 if {[info exists timeout]} {
518 verbose "Setting timeout to $timeout" 2
519 set status [remote_exec host "$compiler $opts" "" "" "" $timeout]
520 } else {
521 set status [remote_exec host "$compiler $opts"]
522 }
523 }
524
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]
529 }
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]"
534 }
535 if { [lindex $status 1] != "" } {
536 verbose -log "output is:\n[lindex $status 1]" 2
537 }
538 if { [lindex $status 0] != 0 && "${comp_output}" == "" } {
539 set comp_output "exit status is [lindex $status 0]"
540 }
541 return ${comp_output}
542 }
543
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).
548
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
553 }
554
555 if {[info procs find_gfortran] == ""} {
556 rename gdb_find_gfortran find_gfortran
557 set use_gdb_compile 1
558 }
559
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
564 }
565
566 if {$use_gdb_compile} {
567 catch {rename default_target_compile {}}
568 rename gdb_default_target_compile default_target_compile
569 }
570
571
572 # Provide 'lreverse' missing in Tcl before 7.5.
573
574 if {[info procs lreverse] == ""} {
575 proc lreverse { arg } {
576 set retval {}
577 while { [llength $retval] < [llength $arg] } {
578 lappend retval [lindex $arg end-[llength $retval]]
579 }
580 return $retval
581 }
582 }
This page took 0.043237 seconds and 4 git commands to generate.