1 # Copyright (C) 1992-2019, 2020, 2024 Free Software Foundation, Inc.
3 # This file is part of DejaGnu.
5 # DejaGnu is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # DejaGnu is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with DejaGnu. If not, see <http://www.gnu.org/licenses/>.
18 # This file was written by Rob Savoye <rob@welcomehome.org> and
19 # extensively modified by Bob Manson <manson@cygnus.com>.
21 # A hairy pattern to recognize text.
22 set text "\[- A-Za-z0-9\.\;\"\_\:\'\`\(\)\!\#\=\+\?\&\*]"
24 # This is a collection of support procs for the target data
25 # structures. We use a named array, since Tcl has no real data
26 # structures. Here's the special index words for the array:
27 # Required fields are:
28 # name - the name of the target. (mostly for error messages) This
29 # should also be the string used for this target's array.
30 # It should also be the same as the linker script so we
31 # can find them dynamically.
32 # Optional fields are:
33 # ldflags - the flags required to produce a fully linked executable.
34 # config - the target canonical for this target. This is a regexp
35 # as passed to istarget or isnative.
36 # cflags - the flags required to produce an object file from a
38 # connect - the connectmode for this target. This is for both IP and
40 # hostname - the hostname of the target. This is for TCP/IP based
41 # connections, and is also used for versions of tip that
43 # serial - the serial port. This is typically /dev/tty? or com?:.
44 # baud - the baud rate for a serial port connection.
45 # netport - the IP port.
46 # x10 - parameters for the x10 controller (used to reboot)
47 # fileid - the fileid or spawn id of of the connection.
48 # prompt - a regexp for matching the prompt.
49 # ioport - the port for I/O on dual port systems.
51 # there are three main arrays, indexed in with "target", "build", and "host".
52 # all other targets are indexed with a name usually based on the linker script
53 # like "idp", or "ex93x.ld".
56 # Set the target connection.
58 proc push_target { name } {
60 push_config target $name
63 # Set the host connection.
65 proc push_host { name } {
67 push_config host $name
70 # Set the build connection.
72 proc push_build { name } {
74 push_config build $name
77 # Set the config for the current host or target connection.
79 proc push_config { type name } {
82 verbose "pushing config for $type, name is $name"
83 if {[info exists target_info($type,name)]} {
84 if { $target_info($type,name) == $name } {
85 error "pushing config for $type, '$name' twice"
88 set target_info($type,name) $name
91 # Set the current connection for target or host.
93 proc pop_config { type } {
96 if {[info exists target_info($type,name)]} {
97 unset target_info($type,name)
101 # Unset the target connection.
103 proc pop_target { } {
107 # Unset the host connection.
113 # Remove extraneous warnings from TEXT.
116 # ld.so: warning: /usr/lib/libc.so.1.8.1 has older revision than expected 9
118 proc prune_warnings { text } {
121 # remove the \r part of "\r\n" so we don't break all the patterns
123 regsub -all -- "\r" $text "" text
125 # This is from sun4's. Do it for all machines for now.
126 # The "\\1" is to try to preserve a "\n" but only if necessary.
127 if {[ishost "sparc-*-sunos*"]} {
128 regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text
131 # See Brendan for the raison d'etre of this one.
132 # http://en.wikipedia.org/wiki/Brendan_Kehoe
133 if {[ishost "alpha*-*-*"]} {
134 regsub -all "(^|\n)(/usr/(ucb|bin)/ld.*without exceptions was\[^\n\]+\n?)" $text "\\1" text
136 if {[ishost "hppa*-*-hpux*"]} {
137 # Ignore the compiler's warnings about PA incompatibility.
138 regsub -all "(^|\n)\[^\n\]*PA 2.0 object file \[^\n\]* was detected. The linked output may not run on a PA 1.x system." $text "" text
140 regsub -all "(^|\n)\[^\n\]*PA 2.0 object file \[^\n\]* was detected. The linked output may not run on a PA 1.x system." $text "" text
142 # And the linker's +vcompatwarnings verbage.
143 regsub -all "(^|\n)\[^\n\]*Linker features were used that may not be supported\[^\n\]*.\[^\n\]*." $text "" text
145 # Ignore these warnings, which the HP aCC compiler seems to
146 # generate on HP-UX 10.30 and 11.0. (Something is probably
147 # wrong with some system headers, but still...)
149 # This particular warning always is given with a line of warning
150 # text, followed by a source line, followed by a line with "^^^"
151 # underlining an offending symbol name. Here we slurp up the
152 # warning text and the next two lines, assuming that they are
153 # the source line and underline chars.
155 regsub -all "Warning .*The linkage directive is ignored for an object or function declared static..\[^\n\]*.\[^\n\]*." $text "" text
157 # Ignore these warnings, which I often see from the ANSI C
158 # compiler installed on HP-UX 11.0 machines. (Something is
159 # probably wrong with an installation, or perhaps NLS isn't
160 # quite healthy yet on 11.0. In either case, it's easier to
161 # "fix" this nit here, than it is to track down & fix the
164 # This particular warning always is given with a line of warning
165 # text, followed by line that says "Using internal messages".
167 regsub -all "Warning: Unable to open pxdb message catalog.*" $text "" text
168 regsub -all ".* Using internal messages.*" $text "" text
170 # Another form of the "unable to find message catalog" warning.
172 regsub -all "cpp: warning .*Possibly incorrect message catalog." $text "" text
174 # Another odd warning on 11.0.
176 regsub -all "aCC .assigner.: Warning .*Could not find library for -l.*" $text "" text
178 # Oh heck, just keep adding 'em here...
180 regsub -all "aCC .assigner.: Warning .*Could not satisfy instantiation request for \[^\n\]* contained in\[^\n\]*\n\t/lib/pa20_64/lib\[a-zA-Z0-9\]*.sl" $text "" text
182 # Remove the lines that are output by the HP F77 compiler to
183 # indicate the functions that are being compiled.
184 upvar compiler_type compiler_type
185 if { [info exists compiler_type] && $compiler_type eq "f77" } {
186 regsub -all "\[ \ta-zA-Z_0-9\./\]*:\[\r\n\]+" $text "" text
189 # Ignore the warnings about unknown options
190 regsub -all ".*warning \[0-9\]+: Unknown option.*ignored.*" $text "" text
195 regsub -all "(^|\n)\[^\n\]*linker input file unused since linking not done" $text "" text
196 regsub -all "(^|\n)\[^\n\]*file path prefix \[^\n\]* never used" $text "" text
198 # This is from sun4's. Do it for all machines for now.
199 # The "\\1" is to try to preserve a "\n" but only if necessary.
200 regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text
202 # This happens when compiling on Alpha OSF/1 with cc -g -O.
203 regsub -all "(^|\n)(\n*uopt: Warning: file not optimized; use -g3 if both optimization and debug wanted\n?)+" $text "\\1" text
205 # This happens when compiling on Alpha OSF using gas.
206 regsub -all "(^|\n)(/usr/.*/ld:\nWarning: Linking some objects which contain exception information sections\n\tand some which do not. This may cause fatal runtime exception handling\n\tproblems\[^\n\]*\n?)+" $text "\\1" text
208 # This happens on SunOS with cc -g -O.
209 regsub -all "(^|\n)(cc: Warning: -O conflicts with -g. -O turned off.\n?)+" $text "\\1" text
211 # This happens when assembling code with the native HP assembler
212 regsub -all "(^|\n)(as:\[^\n\]*err#13.\n .warning.\[^\n\]*\n?)+" $text "\\1" text
214 # When using the HP assembler, -g isn't supported.
215 regsub -all "(^|\n)(cc1: warning: -g is only supported when using GAS on this processor\[^\n\]*\ncc1: warning:\[^\n\]*\n?)+" $text "\\1" text
216 regsub -all "(^|\n)(cc1plus: warning: -g is only supported when using GAS on this processor\[^\n\]*\ncc1plus: warning:\[^\n\]*\n?)+" $text "\\1" text
218 # This happens when testing across NFS.
219 regsub -all "(^|\n)((NFS|nfs) server \[^\n\]* not responding\[^\n\]*\n?)+" $text "\\1" text
220 regsub -all "(^|\n)((NFS|nfs) server \[^\n\]* (ok|is alive again)\[^\n\]*\n?)+" $text "\\1" text
222 # This happens when testing across NFS on osf4.
223 regsub -all "(^|\n)(NFS3 server \[^\n\]* not responding still trying\[^\n\]*\n?)+" $text "\\1" text
224 regsub -all "(^|\n)(NFS3 server \[^\n\]* ok\[^\n\]*\n?)+" $text "\\1" text
226 # When using the IRIX 6 o32 assembler, -g isn't supported
227 regsub -all "(^|\n)(cc1: warning: `-g' not supported by this configuration of GCC\[^\n\]*\n?)+" $text "\\1" text
228 regsub -all "(^|\n)(cc1plus: warning: `-g' not supported by this configuration of GCC\[^\n\]*\n?)+" $text "\\1" text
230 regsub -all "(^|\n)(cc1: warning: -mabi=32 does not support -g\[^\n\]*\n?)+" $text "\\1" text
231 regsub -all "(^|\n)(cc1plus: warning: -mabi=32 does not support -g\[^\n\]*\n?)+" $text "\\1" text
233 # This happens with the o32 assembler on IRIX 6.
234 regsub -all "(^|\n)(as: Warning: -O3 is not supported for assembly compiles for ucode compilers; changing to -O2.\n?)+" $text "\\1" text
236 # This happens when using g++ on a DWARF system.
237 regsub -all "(^|\n)(cc1plus: warning: -g option not supported for C\\+\\+ on systems using the DWARF debugging format\n?)+" $text "\\1" text
239 # This is from sun4's. Do it for all machines for now.
240 # The "\\1" is to try to preserve a "\n" but only if necessary.
241 regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text
243 # See Brendan for the raison d'etre of this one.
244 # http://en.wikipedia.org/wiki/Brendan_Kehoe
245 if {[string match "alpha*-*-*" $host_triplet]} {
246 regsub -all "(^|\n)(/usr/(ucb|bin)/ld.*without exceptions was\[^\n\]+\n?)" $text "\\1" text
249 # Don't pay attention to the AIX4 linker warnings.
250 regsub -all "(^|\n)(ld:.*WARNING: Duplicate.*ld:.*Use the -bload\[^\n\]*\n?)" $text "\\1" text
252 # Or the IRIX 6 ones.
253 regsub -all "(^|\n)(ld(|32|64): WARNING \[^\n\]*\n?)+" $text "\\1" text
254 regsub -all "(^|\n)(ld(|32|64): Giving up.*Use -wall\[^\n\]*\n?)+" $text "\\1" text
256 # Or the NetBSD ones.
257 regsub -all "(^|\n)(\[^\n\]*: In function\[^\n\]*\n\[^\n\]\[^\n\]*warning: this program uses \[^\n\]*)" $text "\\1" text
258 regsub -all "(^|\n)(\[^\n\]*: In function\[^\n\]*\n\[^\n\]\[^\n\]*warning: reference to compatibility \[^\n\]*)" $text "\\1" text
259 regsub -all "(^|\n)(\[^\n\]*:\[0-9\]+: warning: \[^\n\]* possibly used unsafely, use \[^\n\]*\n?)" $text "\\1" text
260 regsub -all "(^|\n)(\[^\n\]*: warning: reference to compatibility glob\[^\n\]*\n?)" $text "\\1" text
262 # Or the OpenBSD ones.
263 regsub -all "(^|\n)(\[^\n\]*: In function\[^\n\]*\n\[^\n\]\[^\n\]*warning: \[^\n\]* is (often|almost always) misused, please use \[^\n\]*\n?)" $text "\\1" text
264 regsub -all "(^|\n)(\[^\n\]*: warning: \[^\n\]* is (often|almost always) misused, please use \[^\n\]*\n?)" $text "\\1" text
266 # GNU ld warns about functions marked as dangerous in GNU libc.
267 regsub -all "(^|\n)\[^\n\]*: \[Ii\]n function\[^\n\]*\n\[^\n\]\[^\n\]*is dangerous\[^\n\]*" $text "" text
268 regsub -all "(^|\n)\[^\n\]*: \[Ii\]n function\[^\n\]*\n\[^\n\]\[^\n\]*the use of \[^\n\]* is dangerous, better use \[^\n\]*" $text "" text
269 regsub -all "(^|\n)\[^\n\]*is dangerous\[^\n\]*" $text "" text
271 # Libgloss libnosys defines functions that warn when linked in
272 regsub -all "(^|\n)\[^\n\]*: \[Ii\]n function\[^\n\]*\n\[^\n\]\[^\n\]*is not implemented and will always fail\[^\n\]*" $text "" text
273 regsub -all "(^|\n)\[^\n\]*is not implemented and will always fail\[^\n\]*" $text "" text
275 # libstdc++-v3 tests can emit cpplib warnings due to duplicate -isystem / -I flags
276 regsub -all "(^|\n)\[^\n\]*: warning: changing search order for system directory\[^\n\]*" $text "" text
277 regsub -all "(^|\n)\[^\n\]*: warning: as it has already been specified\[^\n\]*" $text "" text
279 # Cygwin cc1 warns about -fpic and -fPIC
280 regsub -all "(^|\n)\[^\n\]*: warning: -f(pic|PIC) ignored for target \[^\n\]*" $text "" text
282 # Ignore linker warning when searching 64bit libraries in /lib.
283 regsub -all "(^|\n)\[^\n\]*: skipping incompatible \[^\n\]* when searching for \[^\n\]*" $text "" text
285 # It might be tempting to get carried away and delete blank lines, etc.
286 # Just delete *exactly* what we're ask to, and that's it.
290 # Invoke the compiler. This gets interesting cause the compiler may
291 # not be on the same machine we're running DejaGnu on.
293 proc target_compile {source destfile type options} {
294 set target [target_info name]
295 if { [info procs ${target}_compile] ne "" } {
296 return [${target}_compile $source $destfile $type $options]
298 return [default_target_compile $source $destfile $type $options]
302 proc default_target_compile {source destfile type options} {
303 global target_triplet
305 global CFLAGS_FOR_TARGET
306 global LDFLAGS_FOR_TARGET
307 global compiler_flags
309 if { $destfile eq "" && $type ne "preprocess" && $type ne "none" } {
310 error "Must supply an output filename for the compile to default_target_compile"
316 set compiler_type "c"
319 # linker_opts_order is one of "sources-then-flags", "flags-then-sources".
320 # The order matters for things like -Wl,--as-needed. The default is to
321 # preserve existing behavior.
322 set linker_opts_order "sources-then-flags"
324 set dest [target_info name]
326 if {[info exists CFLAGS_FOR_TARGET]} {
327 append add_flags " $CFLAGS_FOR_TARGET"
330 if {[info exists LDFLAGS_FOR_TARGET]} {
331 append ldflags " $LDFLAGS_FOR_TARGET"
334 if {[host_info exists]} {
335 set host [host_info name]
343 set compiler_type "ada"
344 if {[board_info $dest exists adaflags]} {
345 append add_flags " [board_info $dest adaflags]"
347 if {[board_info $dest exists gnatmake]} {
348 set compiler [board_info $dest gnatmake]
350 set compiler [find_gnatmake]
355 set compiler_type "c++"
356 if {[board_info $dest exists cxxflags]} {
357 append add_flags " [board_info $dest cxxflags]"
359 append add_flags " [g++_include_flags]"
360 if {[board_info $dest exists c++compiler]} {
361 set compiler [board_info $dest c++compiler]
363 set compiler [find_g++]
368 set compiler_type "d"
369 if {[board_info $dest exists dflags]} {
370 append add_flags " [board_info $dest dflags]"
372 if {[board_info $dest exists dcompiler]} {
373 set compiler [board_info $dest dcompiler]
375 set compiler [find_gdc]
380 set compiler_type "f77"
381 if {[board_info $dest exists f77flags]} {
382 append add_flags " [board_info $dest f77flags]"
384 if {[board_info $dest exists f77compiler]} {
385 set compiler [board_info $dest f77compiler]
387 set compiler [find_g77]
392 set compiler_type "f90"
393 if {[board_info $dest exists f90flags]} {
394 append add_flags " [board_info $dest f90flags]"
396 if {[board_info $dest exists f90compiler]} {
397 set compiler [board_info $dest f90compiler]
399 set compiler [find_gfortran]
404 set compiler_type "go"
405 if {[board_info $dest exists goflags]} {
406 append add_flags " [board_info $dest goflags]"
408 if {[board_info $dest exists gocompiler]} {
409 set compiler [board_info $dest gocompiler]
411 set compiler [find_go]
413 if {[board_info $dest exists golinker]} {
414 set linker [board_info $dest golinker]
416 set linker [find_go_linker]
418 if {[board_info $dest exists golinker_opts_order]} {
419 set linker_opts_order [board_info $dest golinker_opts_order]
423 if { $i eq "rust" } {
424 set compiler_type "rust"
425 if {[board_info $dest exists rustflags]} {
426 append add_flags " [board_info $dest rustflags]"
428 if {[board_info $dest exists rustcompiler]} {
429 set compiler [board_info $dest rustcompiler]
431 set compiler [find_rustc]
435 if {[regexp "^dest=" $i]} {
436 regsub "^dest=" $i "" tmp
437 if {[board_info $tmp exists name]} {
438 set dest [board_info $tmp name]
443 if {[regexp "^compiler=" $i]} {
444 regsub "^compiler=" $i "" tmp
447 if {[regexp "^linker=" $i]} {
448 regsub "^linker=" $i "" tmp
451 if {[regexp "^early_flags=" $i]} {
452 regsub "^early_flags=" $i "" tmp
453 append early_flags " $tmp"
455 if {[regexp "^additional_flags=" $i]} {
456 regsub "^additional_flags=" $i "" tmp
457 append add_flags " $tmp"
459 if {[regexp "^ldflags=" $i]} {
460 regsub "^ldflags=" $i "" tmp
461 append ldflags " $tmp"
463 if {[regexp "^libs=" $i]} {
464 regsub "^libs=" $i "" tmp
467 if {[regexp "^incdir=" $i]} {
468 regsub "^incdir=" $i "-I" tmp
469 append add_flags " $tmp"
471 if {[regexp "^libdir=" $i]} {
472 regsub "^libdir=" $i "-L" tmp
473 append add_flags " $tmp"
475 if {[regexp "^ldscript=" $i]} {
476 regsub "^ldscript=" $i "" ldscript
478 if {[regexp "^redirect=" $i]} {
479 regsub "^redirect=" $i "" redirect
481 if {[regexp "^optimize=" $i]} {
482 regsub "^optimize=" $i "" optimize
484 if {[regexp "^timeout=" $i]} {
485 regsub "^timeout=" $i "" timeout
489 if {[board_info $host exists cflags_for_target]} {
490 append add_flags " [board_info $host cflags_for_target]"
494 global CXX_FOR_TARGET
496 global F77_FOR_TARGET
497 global F90_FOR_TARGET
498 global GNATMAKE_FOR_TARGET
500 global GO_LD_FOR_TARGET
501 global RUSTC_FOR_TARGET
503 if {[info exists GNATMAKE_FOR_TARGET]} {
504 if { $compiler_type eq "ada" } {
505 set compiler $GNATMAKE_FOR_TARGET
509 if {[info exists CC_FOR_TARGET]} {
510 if { $compiler eq "" } {
511 set compiler $CC_FOR_TARGET
515 if {[info exists CXX_FOR_TARGET]} {
516 if { $compiler_type eq "c++" } {
517 set compiler $CXX_FOR_TARGET
521 if {[info exists D_FOR_TARGET]} {
522 if { $compiler_type eq "d" } {
523 set compiler $D_FOR_TARGET
527 if {[info exists F77_FOR_TARGET]} {
528 if { $compiler_type eq "f77" } {
529 set compiler $F77_FOR_TARGET
533 if {[info exists F90_FOR_TARGET]} {
534 if { $compiler_type eq "f90" } {
535 set compiler $F90_FOR_TARGET
539 if { $compiler_type eq "go" } {
540 if {[info exists GO_FOR_TARGET]} {
541 set compiler $GO_FOR_TARGET
543 if {[info exists GO_LD_FOR_TARGET]} {
544 set linker $GO_LD_FOR_TARGET
548 if {[info exists RUSTC_FOR_TARGET]} {
549 if {$compiler_type eq "rust"} {
550 set compiler $RUSTC_FOR_TARGET
554 if { $type eq "executable" && $linker ne "" } {
558 if { $compiler eq "" } {
559 if { [board_info $dest exists compiler] } {
560 set compiler [board_info $dest compiler]
561 } elseif { $compiler_type eq "c" } {
562 set compiler [find_gcc]
564 if { $compiler eq "" } {
565 return "default_target_compile: No compiler to compile with"
569 if {![isremote host]} {
570 if { [which $compiler] == 0 } {
571 return "default_target_compile: Can't find $compiler."
575 if {$type eq "object"} {
576 if {$compiler_type eq "rust"} {
577 append add_flags " --emit obj"
579 append add_flags " -c"
583 if { $type eq "preprocess" } {
584 append add_flags " -E"
587 if { $type eq "assembly" } {
588 if {$compiler_type eq "rust"} {
589 append add_flags " --emit asm"
591 append add_flags " -S"
595 if {[board_info $dest exists cflags]} {
596 append add_flags " [board_info $dest cflags]"
599 if { $type eq "executable" } {
601 if {[board_info $dest exists ldflags]} {
602 append extra_ldflags " [board_info $dest ldflags]"
604 if { $compiler_type eq "c++" } {
605 append extra_ldflags " [g++_link_flags]"
609 catch "glob -nocomplain $tool_root_dir/libstdc++/libstdc++.so* $tool_root_dir/libstdc++/libstdc++.sl" tmp
611 if {[regexp ".*solaris2.*" $target_triplet]} {
613 append extra_ldflags " -R$tool_root_dir/libstdc++"
614 } elseif {[regexp ".*(osf|irix5|linux).*" $target_triplet]} {
616 append extra_ldflags " -Wl,-rpath,$tool_root_dir/libstdc++"
617 } elseif {[regexp ".*hppa.*" $target_triplet]} {
619 append extra_ldflags " -Wl,-a,shared_archive"
623 if { $extra_ldflags ne "" } {
624 if { $compiler_type eq "ada" } {
625 append add_flags " -largs $extra_ldflags -margs"
627 append add_flags " $extra_ldflags"
632 if {![info exists ldscript]} {
633 set ldscript [board_info $dest ldscript]
637 if { $i eq "debug" } {
638 if {[board_info $dest exists debug_flags]} {
639 append add_flags " [board_info $dest debug_flags]"
641 append add_flags " -g"
646 if {[info exists optimize]} {
647 append add_flags " $optimize"
650 if { $type eq "executable" } {
651 set extra_ldflags "$ldflags"
653 if {[file exists $x]} {
656 append extra_ldflags " $x"
660 if {[board_info $dest exists libs]} {
661 append extra_ldflags " [board_info $dest libs]"
664 # This probably isn't such a good idea, but it avoids nasty
665 # hackiness in the testsuites.
666 # The math library must be linked in before the C library. The C
667 # library is linked in by the linker script, so this must be before
669 if {[board_info $dest exists mathlib]} {
670 append extra_ldflags " [board_info $dest mathlib]"
672 append extra_ldflags " -lm"
675 # This must be added here.
676 append extra_ldflags " $ldscript"
678 if {[board_info $dest exists remote_link]} {
680 append extra_ldflags " -Wl,-r"
682 if {[board_info $dest exists output_format]} {
683 append extra_ldflags " -Wl,-oformat,[board_info $dest \
686 if { $extra_ldflags ne "" } {
687 if { $compiler_type eq "ada" } {
688 append add_flags " -largs $extra_ldflags -margs"
690 append add_flags " $extra_ldflags"
695 if {[board_info $dest exists multilib_flags]} {
696 set multilib_flags [board_info $dest multilib_flags]
697 if { $compiler_type eq "ada" } {
698 set add_flags "$multilib_flags -largs $multilib_flags -margs\
701 set add_flags "$multilib_flags $add_flags"
705 verbose "doing compile"
708 if {[isremote host]} {
710 set file [remote_download host $x]
712 warning "Unable to download $x to host."
713 return "Unable to download $x to host."
715 append sources " $file"
722 if {[isremote host]} {
723 append add_flags " -o a.out"
724 remote_file host delete a.out
726 if { $destfile ne "" } {
727 append add_flags " -o $destfile"
731 # This is obscure: we put SOURCES at the end when building an
732 # object, because otherwise, in some situations, libtool will
733 # become confused about the name of the actual source file.
736 set opts "$early_flags $add_flags $sources"
739 switch $linker_opts_order {
740 "flags-then-sources" {
741 set opts "$early_flags $add_flags $sources"
743 "sources-then-flags" {
744 set opts "$early_flags $sources $add_flags"
747 error "Invalid value for board_info linker_opts_order"
752 set opts "$early_flags $sources $add_flags"
756 if {[isremote host]} {
757 if {[host_info exists use_at]} {
758 set fid [open "atfile" "w"]
761 set opts "@[remote_download host atfile]"
762 remote_file build delete atfile
766 verbose "Invoking the compiler as $compiler $opts" 2
768 if {[info exists redirect]} {
769 verbose "Redirecting output to $redirect" 2
770 set status [remote_exec host "$compiler $opts" "" "" $redirect]
772 if {[info exists timeout]} {
773 verbose "Setting timeout to $timeout" 2
774 set status [remote_exec host "$compiler $opts" "" "" "" $timeout]
776 set status [remote_exec host "$compiler $opts"]
780 set compiler_flags $opts
781 if {[isremote host]} {
782 remote_upload host a.out $destfile
783 remote_file host delete a.out
785 set comp_output [prune_warnings [lindex $status 1]]
786 regsub "^\[\r\n\]+" $comp_output "" comp_output
787 if { [lindex $status 0] != 0 } {
788 verbose -log "compiler exited with status [lindex $status 0]"
790 if { [lindex $status 1] ne "" } {
791 verbose "output is:\n[lindex $status 1]" 2
793 if { [lindex $status 0] != 0 && $comp_output eq "" } {
794 set comp_output "exit status is [lindex $status 0]"
799 proc reboot_target { } {
800 set result [remote_reboot target]
801 puts "REBOOT_TARGET: \"$result\""
805 # Invoke this if you really want as to be called directly, rather than
806 # calling the compiler. FLAGS are any additional flags to pass to the
809 proc target_assemble { source destfile flags } {
810 return [default_target_assemble $source $destfile $flags]
813 proc default_target_assemble { source destfile flags } {
815 global ASFLAGS_FOR_TARGET
817 if {[info exists AS_FOR_TARGET]} {
818 set AS $AS_FOR_TARGET
820 if {![board_info target exists assembler]} {
823 set AS [board_info target assembler]
827 if {[info exists ASFLAGS_FOR_TARGET]} {
828 append flags " $ASFLAGS_FOR_TARGET"
831 if {[isremote host]} {
832 set source [remote_download host $source]
837 set status [remote_exec host "$AS $source $flags -o $dest"]
838 if {[isremote host]} {
839 remote_upload host $dest $destfile
842 set comp_output [prune_warnings [lindex $status 1]]
843 if { [lindex $status 0] != 0 } {
844 verbose -log "assembler exited with status [lindex $status 0]"
846 if { [lindex $status 1] ne "" } {
847 verbose "assembler output is:\n[lindex $status 1]" 2
852 # Invoke this if you really want ld to be called directly, rather than
853 # calling the compiler. FLAGS are any additional flags to pass to the
856 proc target_link { objects destfile flags } {
857 return [default_link target $objects $destfile $flags]
860 proc default_link { board objects destfile flags } {
862 global LDFLAGS_FOR_TARGET
864 # return -L's in ldflags
865 proc only--Ls { ldflags } {
867 set ldflags [split $ldflags]
868 set len [llength $ldflags]
869 for { set i 0 } { $i < $len } { incr i } {
870 # Note: We ignore the situation where a -L is actually the
871 # argument to an option.
872 set arg [lindex $ldflags $i]
873 regsub "^-Wl," $arg "" arg
874 if {[regexp "^-L" $arg]} {
875 # Is the directory in the next arg, or part of this one?
876 if { $arg eq "-L" } {
877 if { $i + 1 < $len } {
878 append result " -L [lindex $ldflags $i+1]"
882 append result " $arg"
889 if {[info exists LD_FOR_TARGET]} {
890 set LD $LD_FOR_TARGET
892 if {![board_info target exists linker]} {
895 set LD [board_info target linker]
899 if {[info exists LDFLAGS_FOR_TARGET]} {
900 append flags " $LDFLAGS_FOR_TARGET"
903 # `ldflags' consists of arguments to gcc (that are then
904 # passed to ld), not arguments to ld directly.
906 if {[board_info $board exists ldflags]} {
907 set ldflags [board_info $board ldflags]
908 set ldflags [only--Ls $ldflags]
909 append flags " $ldflags"
912 if {[board_info $board exists ldscript]} {
913 # strip leading -Wl, if present
914 set ldscript [board_info $board ldscript]
915 regsub "^-Wl," $ldscript "" ldscript
916 append flags " $ldscript"
919 if {[isremote host]} {
922 set nobjects "$nobjects [remote_download host $x]"
924 set objects $nobjects
929 set status [remote_exec host "$LD $objects $flags -o $dest"]
930 if {[isremote host]} {
931 remote_upload host $dest $destfile
934 set comp_output [prune_warnings [lindex $status 1]]
935 if { [lindex $status 0] != 0 } {
936 verbose -log "linker exited with status [lindex $status 0]"
938 if { [lindex $status 1] ne "" } {
939 verbose "linker output is:\n[lindex $status 1]" 2