Work around bug in AIX 7.1 awk in report card tool
[dejagnu.git] / lib / target.exp
blob17c635a193d56bac20d81fe02586d78fbf0dfc44
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
37 #                     source file.
38 #           connect - the connectmode for this target. This is for both IP and
39 #                     serial connections.
40 #           hostname  - the hostname of the target. This is for TCP/IP based
41 #                     connections, and is also used for versions of tip that
42 #                     use /etc/remote.
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 } {
59     pop_config target
60     push_config target $name
63 # Set the host connection.
65 proc push_host { name } {
66     pop_config host
67     push_config host $name
70 # Set the build connection.
72 proc push_build { name } {
73     pop_config build
74     push_config build $name
77 # Set the config for the current host or target connection.
79 proc push_config { type name } {
80     global target_info
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"
86         }
87     }
88     set target_info($type,name) $name
91 # Set the current connection for target or host.
93 proc pop_config { type  } {
94     global target_info
96     if {[info exists target_info($type,name)]} {
97         unset target_info($type,name)
98     }
101 # Unset the target connection.
103 proc pop_target { } {
104     pop_config target
107 # Unset the host connection.
109 proc pop_host { } {
110     pop_config host
113 # Remove extraneous warnings from TEXT.
115 # An example is:
116 # ld.so: warning: /usr/lib/libc.so.1.8.1 has older revision than expected 9
118 proc prune_warnings { text } {
119     global host_triplet
121     # remove the \r part of "\r\n" so we don't break all the patterns
122     # we want to match.
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
129     }
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
135     }
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...)
148         #
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.
154         #
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
162         # root cause.)
163         #
164         # This particular warning always is given with a line of warning
165         # text, followed by line that says "Using internal messages".
166         #
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.
171         #
172         regsub -all "cpp: warning .*Possibly incorrect message catalog." $text "" text
174         # Another odd warning on 11.0.
175         #
176         regsub -all "aCC .assigner.: Warning .*Could not find library for -l.*" $text "" text
178         # Oh heck, just keep adding 'em here...
179         #
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
187         }
189         # Ignore the warnings about unknown options
190         regsub -all ".*warning \[0-9\]+: Unknown option.*ignored.*" $text "" text
192     }
194     # Ignore these.
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
247     }
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.
287     return $text
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]
297     } else {
298         return [default_target_compile $source $destfile $type $options]
299     }
302 proc default_target_compile {source destfile type options} {
303     global target_triplet
304     global tool_root_dir
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"
311     }
313     set early_flags ""
314     set add_flags ""
315     set libs ""
316     set compiler_type "c"
317     set compiler ""
318     set linker ""
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"
323     set ldflags ""
324     set dest [target_info name]
326     if {[info exists CFLAGS_FOR_TARGET]} {
327         append add_flags " $CFLAGS_FOR_TARGET"
328     }
330     if {[info exists LDFLAGS_FOR_TARGET]} {
331         append ldflags " $LDFLAGS_FOR_TARGET"
332     }
334     if {[host_info exists]} {
335         set host [host_info name]
336     } else {
337         set host "unix"
338     }
340     foreach i $options {
342         if { $i eq "ada" } {
343             set compiler_type "ada"
344             if {[board_info $dest exists adaflags]} {
345                 append add_flags " [board_info $dest adaflags]"
346             }
347             if {[board_info $dest exists gnatmake]} {
348                 set compiler [board_info $dest gnatmake]
349             } else {
350                 set compiler [find_gnatmake]
351             }
352         }
354         if { $i eq "c++" } {
355             set compiler_type "c++"
356             if {[board_info $dest exists cxxflags]} {
357                 append add_flags " [board_info $dest cxxflags]"
358             }
359             append add_flags " [g++_include_flags]"
360             if {[board_info $dest exists c++compiler]} {
361                 set compiler [board_info $dest c++compiler]
362             } else {
363                 set compiler [find_g++]
364             }
365         }
367         if { $i eq "d" } {
368             set compiler_type "d"
369             if {[board_info $dest exists dflags]} {
370                 append add_flags " [board_info $dest dflags]"
371             }
372             if {[board_info $dest exists dcompiler]} {
373                 set compiler [board_info $dest dcompiler]
374             } else {
375                 set compiler [find_gdc]
376             }
377         }
379         if { $i eq "f77" } {
380             set compiler_type "f77"
381             if {[board_info $dest exists f77flags]} {
382                 append add_flags " [board_info $dest f77flags]"
383             }
384             if {[board_info $dest exists f77compiler]} {
385                 set compiler [board_info $dest f77compiler]
386             } else {
387                 set compiler [find_g77]
388             }
389         }
391         if { $i eq "f90" } {
392             set compiler_type "f90"
393             if {[board_info $dest exists f90flags]} {
394                 append add_flags " [board_info $dest f90flags]"
395             }
396             if {[board_info $dest exists f90compiler]} {
397                 set compiler [board_info $dest f90compiler]
398             } else {
399                 set compiler [find_gfortran]
400             }
401         }
403         if { $i eq "go" } {
404             set compiler_type "go"
405             if {[board_info $dest exists goflags]} {
406                 append add_flags " [board_info $dest goflags]"
407             }
408             if {[board_info $dest exists gocompiler]} {
409                 set compiler [board_info $dest gocompiler]
410             } else {
411                 set compiler [find_go]
412             }
413             if {[board_info $dest exists golinker]} {
414                 set linker [board_info $dest golinker]
415             } else {
416                 set linker [find_go_linker]
417             }
418             if {[board_info $dest exists golinker_opts_order]} {
419                 set linker_opts_order [board_info $dest golinker_opts_order]
420             }
421         }
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]"
427             }
428             if {[board_info $dest exists rustcompiler]} {
429                 set compiler [board_info $dest rustcompiler]
430             } else {
431                 set compiler [find_rustc]
432             }
433         }
435         if {[regexp "^dest=" $i]} {
436             regsub "^dest=" $i "" tmp
437             if {[board_info $tmp exists name]} {
438                 set dest [board_info $tmp name]
439             } else {
440                 set dest $tmp
441             }
442         }
443         if {[regexp "^compiler=" $i]} {
444             regsub "^compiler=" $i "" tmp
445             set compiler $tmp
446         }
447         if {[regexp "^linker=" $i]} {
448             regsub "^linker=" $i "" tmp
449             set linker $tmp
450         }
451         if {[regexp "^early_flags=" $i]} {
452             regsub "^early_flags=" $i "" tmp
453             append early_flags " $tmp"
454         }
455         if {[regexp "^additional_flags=" $i]} {
456             regsub "^additional_flags=" $i "" tmp
457             append add_flags " $tmp"
458         }
459         if {[regexp "^ldflags=" $i]} {
460             regsub "^ldflags=" $i "" tmp
461             append ldflags " $tmp"
462         }
463         if {[regexp "^libs=" $i]} {
464             regsub "^libs=" $i "" tmp
465             append libs " $tmp"
466         }
467         if {[regexp "^incdir=" $i]} {
468             regsub "^incdir=" $i "-I" tmp
469             append add_flags " $tmp"
470         }
471         if {[regexp "^libdir=" $i]} {
472             regsub "^libdir=" $i "-L" tmp
473             append add_flags " $tmp"
474         }
475         if {[regexp "^ldscript=" $i]} {
476             regsub "^ldscript=" $i "" ldscript
477         }
478         if {[regexp "^redirect=" $i]} {
479             regsub "^redirect=" $i "" redirect
480         }
481         if {[regexp "^optimize=" $i]} {
482             regsub "^optimize=" $i "" optimize
483         }
484         if {[regexp "^timeout=" $i]} {
485             regsub "^timeout=" $i "" timeout
486         }
487     }
489     if {[board_info $host exists cflags_for_target]} {
490         append add_flags " [board_info $host cflags_for_target]"
491     }
493     global CC_FOR_TARGET
494     global CXX_FOR_TARGET
495     global D_FOR_TARGET
496     global F77_FOR_TARGET
497     global F90_FOR_TARGET
498     global GNATMAKE_FOR_TARGET
499     global GO_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
506         }
507     }
509     if {[info exists CC_FOR_TARGET]} {
510         if { $compiler eq "" } {
511             set compiler $CC_FOR_TARGET
512         }
513     }
515     if {[info exists CXX_FOR_TARGET]} {
516         if { $compiler_type eq "c++" } {
517             set compiler $CXX_FOR_TARGET
518         }
519     }
521     if {[info exists D_FOR_TARGET]} {
522         if { $compiler_type eq "d" } {
523             set compiler $D_FOR_TARGET
524         }
525     }
527     if {[info exists F77_FOR_TARGET]} {
528         if { $compiler_type eq "f77" } {
529             set compiler $F77_FOR_TARGET
530         }
531     }
533     if {[info exists F90_FOR_TARGET]} {
534         if { $compiler_type eq "f90" } {
535             set compiler $F90_FOR_TARGET
536         }
537     }
539     if { $compiler_type eq "go" } {
540         if {[info exists GO_FOR_TARGET]} {
541             set compiler $GO_FOR_TARGET
542         }
543         if {[info exists GO_LD_FOR_TARGET]} {
544             set linker $GO_LD_FOR_TARGET
545         }
546     }
548     if {[info exists RUSTC_FOR_TARGET]} {
549         if {$compiler_type eq "rust"} {
550             set compiler $RUSTC_FOR_TARGET
551         }
552     }
554     if { $type eq "executable" && $linker ne "" } {
555         set compiler $linker
556     }
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]
563         }
564         if { $compiler eq "" } {
565             return "default_target_compile: No compiler to compile with"
566         }
567     }
569     if {![isremote host]} {
570         if { [which $compiler] == 0 } {
571             return "default_target_compile: Can't find $compiler."
572         }
573     }
575     if {$type eq "object"} {
576         if {$compiler_type eq "rust"} {
577             append add_flags " --emit obj"
578         } else {
579             append add_flags " -c"
580         }
581     }
583     if { $type eq "preprocess" } {
584         append add_flags " -E"
585     }
587     if { $type eq "assembly" } {
588         if {$compiler_type eq "rust"} {
589             append add_flags " --emit asm"
590         } else {
591             append add_flags " -S"
592         }
593     }
595     if {[board_info $dest exists cflags]} {
596         append add_flags " [board_info $dest cflags]"
597     }
599     if { $type eq "executable" } {
600         set extra_ldflags ""
601         if {[board_info $dest exists ldflags]} {
602             append extra_ldflags " [board_info $dest ldflags]"
603         }
604         if { $compiler_type eq "c++" } {
605             append extra_ldflags " [g++_link_flags]"
606         }
607         if {[isnative]} {
608             # This is a lose.
609             catch "glob -nocomplain $tool_root_dir/libstdc++/libstdc++.so* $tool_root_dir/libstdc++/libstdc++.sl" tmp
610             if { $tmp ne "" } {
611                 if {[regexp ".*solaris2.*" $target_triplet]} {
612                     # Solaris 2
613                     append extra_ldflags " -R$tool_root_dir/libstdc++"
614                 } elseif {[regexp ".*(osf|irix5|linux).*" $target_triplet]} {
615                     # OSF/1 or IRIX 5
616                     append extra_ldflags " -Wl,-rpath,$tool_root_dir/libstdc++"
617                 } elseif {[regexp ".*hppa.*" $target_triplet]} {
618                     # HP-UX
619                     append extra_ldflags " -Wl,-a,shared_archive"
620                 }
621             }
622         }
623         if { $extra_ldflags ne "" } {
624             if { $compiler_type eq "ada" } {
625                 append add_flags " -largs $extra_ldflags -margs"
626             } else {
627                 append add_flags " $extra_ldflags"
628             }
629         }
630     }
632     if {![info exists ldscript]} {
633         set ldscript [board_info $dest ldscript]
634     }
636     foreach i $options {
637         if { $i eq "debug" } {
638             if {[board_info $dest exists debug_flags]} {
639                 append add_flags " [board_info $dest debug_flags]"
640             } else {
641                 append add_flags " -g"
642             }
643         }
644     }
646     if {[info exists optimize]} {
647         append add_flags " $optimize"
648     }
650     if { $type eq "executable" } {
651         set extra_ldflags "$ldflags"
652         foreach x $libs {
653             if {[file exists $x]} {
654                 append source " $x"
655             } else {
656                 append extra_ldflags " $x"
657             }
658         }
660         if {[board_info $dest exists libs]} {
661             append extra_ldflags " [board_info $dest libs]"
662         }
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
668         # the linker script.
669         if {[board_info $dest exists mathlib]} {
670             append extra_ldflags " [board_info $dest mathlib]"
671         } else {
672             append extra_ldflags " -lm"
673         }
675         # This must be added here.
676         append extra_ldflags " $ldscript"
678         if {[board_info $dest exists remote_link]} {
679             # Relink option.
680             append extra_ldflags " -Wl,-r"
681         }
682         if {[board_info $dest exists output_format]} {
683             append extra_ldflags " -Wl,-oformat,[board_info $dest \
684                                                  output_format]"
685         }
686         if { $extra_ldflags ne "" } {
687             if { $compiler_type eq "ada" } {
688                 append add_flags " -largs $extra_ldflags -margs"
689             } else {
690                 append add_flags " $extra_ldflags"
691             }
692         }
693     }
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\
699                            $add_flags"
700         } else {
701             set add_flags "$multilib_flags $add_flags"
702         }
703     }
705     verbose "doing compile"
707     set sources ""
708     if {[isremote host]} {
709         foreach x $source {
710             set file [remote_download host $x]
711             if { $file eq "" } {
712                 warning "Unable to download $x to host."
713                 return "Unable to download $x to host."
714             } else {
715                 append sources " $file"
716             }
717         }
718     } else {
719         set sources $source
720     }
722     if {[isremote host]} {
723         append add_flags " -o a.out"
724         remote_file host delete a.out
725     } else {
726         if { $destfile ne "" } {
727             append add_flags " -o $destfile"
728         }
729     }
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.
734     switch $type {
735         "object" {
736             set opts "$early_flags $add_flags $sources"
737         }
738         "executable" {
739             switch $linker_opts_order {
740                 "flags-then-sources" {
741                     set opts "$early_flags $add_flags $sources"
742                 }
743                 "sources-then-flags" {
744                     set opts "$early_flags $sources $add_flags"
745                 }
746                 default {
747                     error "Invalid value for board_info linker_opts_order"
748                 }
749             }
750         }
751         default {
752             set opts "$early_flags $sources $add_flags"
753         }
754     }
756     if {[isremote host]} {
757         if {[host_info exists use_at]} {
758             set fid [open "atfile" "w"]
759             puts $fid $opts
760             close $fid
761             set opts "@[remote_download host atfile]"
762             remote_file build delete atfile
763         }
764     }
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]
771     } else {
772         if {[info exists timeout]} {
773             verbose "Setting timeout to $timeout" 2
774             set status [remote_exec host "$compiler $opts" "" "" "" $timeout]
775         } else {
776             set status [remote_exec host "$compiler $opts"]
777         }
778     }
780     set compiler_flags $opts
781     if {[isremote host]} {
782         remote_upload host a.out $destfile
783         remote_file host delete a.out
784     }
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]"
789     }
790     if { [lindex $status 1] ne "" } {
791         verbose "output is:\n[lindex $status 1]" 2
792     }
793     if { [lindex $status 0] != 0 && $comp_output eq "" } {
794         set comp_output "exit status is [lindex $status 0]"
795     }
796     return $comp_output
799 proc reboot_target { } {
800     set result [remote_reboot target]
801     puts "REBOOT_TARGET: \"$result\""
802     return $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
807 # assembler.
809 proc target_assemble { source destfile flags } {
810     return [default_target_assemble $source $destfile $flags]
813 proc default_target_assemble { source destfile flags } {
814     global AS_FOR_TARGET
815     global ASFLAGS_FOR_TARGET
817     if {[info exists AS_FOR_TARGET]} {
818         set AS $AS_FOR_TARGET
819     } else {
820         if {![board_info target exists assembler]} {
821             set AS [find_gas]
822         } else {
823             set AS [board_info target assembler]
824         }
825     }
827     if {[info exists ASFLAGS_FOR_TARGET]} {
828         append flags " $ASFLAGS_FOR_TARGET"
829     }
831     if {[isremote host]} {
832         set source [remote_download host $source]
833         set dest "a.out"
834     } else {
835         set dest $destfile
836     }
837     set status [remote_exec host "$AS $source $flags -o $dest"]
838     if {[isremote host]} {
839         remote_upload host $dest $destfile
840     }
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]"
845     }
846     if { [lindex $status 1] ne "" } {
847         verbose "assembler output is:\n[lindex $status 1]" 2
848     }
849     return $comp_output
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
854 # linker.
856 proc target_link { objects destfile flags } {
857     return [default_link target $objects $destfile $flags]
860 proc default_link { board objects destfile flags } {
861     global LD_FOR_TARGET
862     global LDFLAGS_FOR_TARGET
864     # return -L's in ldflags
865     proc only--Ls { ldflags } {
866         set result ""
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]"
879                         incr i
880                     }
881                 } else {
882                     append result " $arg"
883                 }
884             }
885         }
886         return $result
887     }
889     if {[info exists LD_FOR_TARGET]} {
890         set LD $LD_FOR_TARGET
891     } else {
892         if {![board_info target exists linker]} {
893             set LD [find_ld]
894         } else {
895             set LD [board_info target linker]
896         }
897     }
899     if {[info exists LDFLAGS_FOR_TARGET]} {
900         append flags " $LDFLAGS_FOR_TARGET"
901     }
903     # `ldflags' consists of arguments to gcc (that are then
904     # passed to ld), not arguments to ld directly.
905     # We need the -L's.
906     if {[board_info $board exists ldflags]} {
907         set ldflags [board_info $board ldflags]
908         set ldflags [only--Ls $ldflags]
909         append flags " $ldflags"
910     }
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"
917     }
919     if {[isremote host]} {
920         set nobjects ""
921         foreach x $objects {
922             set nobjects "$nobjects [remote_download host $x]"
923         }
924         set objects $nobjects
925         set dest "a.out"
926     } else {
927         set dest $destfile
928     }
929     set status [remote_exec host "$LD $objects $flags -o $dest"]
930     if {[isremote host]} {
931         remote_upload host $dest $destfile
932     }
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]"
937     }
938     if { [lindex $status 1] ne "" } {
939         verbose "linker output is:\n[lindex $status 1]" 2
940     }
941     return $comp_output