OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [dejagnu/] [lib/] [target.exp] - Blame information for rev 1767

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# Copyright (C) 92, 93, 94, 95, 96, 97, 98, 1999, 2000 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 2 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, write to the Free Software
15
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
 
17
# Please email any bugs, comments, and/or additions to this file to:
18
# bug-dejagnu@prep.ai.mit.edu
19
 
20
# This file was written by Rob Savoye. (rob@cygnus.com)
21
# and extensively modified by Bob Manson. (manson@cygnus.com)
22
 
23
# a hairy pattern to recognize text
24
set text "\[- A-Za-z0-9\.\;\"\_\:\'\`\(\)\!\#\=\+\?\&\*]"
25
 
26
#
27
# this is a collection of support procs for the target data
28
# structures. We use a named array, since Tcl has no real data
29
# structures. Here's the special index words for the array:
30
#       Required fields are:
31
#           name    - the name of the target. (mostly for error messages) This
32
#                     should also be the string used for this target's array.
33
#                     It should also be the same as the linker script so we
34
#                     can find them dynamically.
35
#       Optional fields are:
36
#           ldflags - the flags required to produce a fully linked executable.
37
#           config  - the target canonical for this target. This is a regexp
38
#                     as passed to istarget or isnative.
39
#           cflags  - the flags required to produce an object file from a
40
#                     source file.
41
#           connect - the connectmode for this target. This is for both IP and
42
#                     serial connections.
43
#           hostname  - the hostname of the target. This is for TCP/IP based
44
#                     connections, and is also used for versions of tip that
45
#                     use /etc/remote.
46
#           serial  - the serial port. This is typically /dev/tty? or com?:.
47
#           baud    - the baud rate for a serial port connection.
48
#           netport - the IP port.
49
#           x10     - parameters for the x10 controller (used to reboot)
50
#           fileid  - the fileid or spawn id of of the connection.
51
#           prompt  - a regexp for matching the prompt.
52
#           ioport  - the port for I/O on dual port systems.
53
#
54
# there are three main arrays, indexed in with "target", "build", and "host".
55
# all other targets are indexed with a name usually based on the linker script
56
# like "idp", or "ex93x.ld".
57
#
58
 
59
#
60
# Set the target connection.
61
#
62
proc push_target { name } {
63
    global target_abbrev
64
 
65
    pop_config  target
66
    push_config target $name
67
}
68
 
69
#
70
# Set the host connnection.
71
#
72
proc push_host { name } {
73
    pop_config host
74
    push_config host $name
75
}
76
 
77
#
78
# Set the build connnection.
79
#
80
proc push_build { name } {
81
    pop_config build
82
    push_config build $name
83
}
84
 
85
#
86
# Set the config for the current host or target connection.
87
#
88
proc push_config { type name } {
89
    global target_info
90
 
91
    verbose "pushing config for $type, name is $name"
92
    if [info exists target_info($type,name)] {
93
        if { $target_info($type,name) == $name } {
94
            error "pushing config for $type, '$name' twice"
95
        }
96
    }
97
    set target_info($type,name) $name
98
}
99
 
100
#
101
# Set the current connection for target or host.
102
#
103
proc pop_config { type  } {
104
    global target_info
105
 
106
    if [info exists target_info(${type},name)] {
107
        unset target_info(${type},name)
108
    }
109
}
110
 
111
#
112
# Unset the target connection.
113
#
114
proc pop_target { } {
115
    pop_config target
116
}
117
 
118
#
119
# Unset the host connection.
120
#
121
proc pop_host { } {
122
    pop_config host
123
}
124
 
125
#
126
# Remove extraneous warnings we don't care about
127
#
128
proc prune_warnings { text } {
129
    global host_triplet;
130
 
131
    # remove the \r part of "\r\n" so we don't break all the patterns
132
    # we want to match.
133
    regsub -all -- "\r" $text "" text
134
 
135
    # This is from sun4's.  Do it for all machines for now.
136
    # The "\\1" is to try to preserve a "\n" but only if necessary.
137
    if [ishost "sparc-*-sunos*"] {
138
        regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text
139
    }
140
 
141
    # See Brendan for the raison d'etre of this one.
142
    if [ishost "alpha*-*-*"] {
143
        regsub -all "(^|\n)(/usr/(ucb|bin)/ld.*without exceptions was\[^\n\]+\n?)" $text "\\1" text
144
    }
145
    if [ishost "hppa*-*-hpux*"] {
146
       # Ignore the compiler's warnings about PA incompatibility.
147
       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
148
 
149
       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
150
 
151
       # And the linker's +vcompatwarnings verbage.
152
       regsub -all "(^|\n)\[^\n\]*Linker features were used that may not be supported\[^\n\]*.\[^\n\]*." $text "" text
153
 
154
       # Ignore these warnings, which the HP aCC compiler seems to
155
       # generate on HP-UX 10.30 and 11.0.  (Something is probably
156
       # wrong with some system headers, but still...)
157
       #
158
       # This particular warning always is given with a line of warning
159
       # text, followed by a source line, followed by a line with "^^^"
160
       # underlining an offending symbol name.  Here we slurp up the
161
       # warning text and the next two lines, assuming that they are
162
       # the source line and underline chars.
163
       #
164
       regsub -all "Warning .*The linkage directive is ignored for an object or function declared static..\[^\n\]*.\[^\n\]*." $text "" text
165
 
166
       # Ignore these warnings, which I often see from the ANSI C
167
       # compiler installed on HP-UX 11.0 machines.  (Something is
168
       # probably wrong with an installation, or perhaps NLS isn't
169
       # quite healthy yet on 11.0.  In either case, it's easier to
170
       # "fix" this nit here, than it is to track down & fix the
171
       # root cause.)
172
       #
173
       # This particular warning always is given with a line of warning
174
       # text, followed by line that says "Using internal messages".
175
       #
176
       regsub -all "Warning: Unable to open pxdb message catalog.*" $text "" text
177
       regsub -all ".* Using internal messages.*" $text "" text
178
 
179
       # Another form of the "unable to find message catalog" warning.
180
       #
181
       regsub -all "cpp: warning .*Possibly incorrect message catalog." $text "" text
182
 
183
       # Another odd warning on 11.0.
184
       #
185
       regsub -all "aCC .assigner.: Warning .*Could not find library for -l.*" $text "" text
186
 
187
       # Oh heck, just keep adding 'em here...
188
       #
189
       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
190
 
191
      # Remove the lines that are output by the HP F77 compiler to
192
      # indicate the functions that are being compiled.
193
      upvar compiler_type compiler_type
194
      if { [info exists compiler_type] && $compiler_type == "f77" } {
195
          regsub -all "\[ \ta-zA-Z_0-9\./\]*:\[\r\n\]+" $text "" text
196
      }
197
 
198
      # Ignore the warnings about unknown options
199
      regsub -all ".*warning \[0-9\]+: Unknown option.*ignored.*" $text "" text
200
 
201
      }
202
 
203
    # Ignore these.
204
    regsub -all "(^|\n)\[^\n\]*linker input file unused since linking not done" $text "" text
205
    regsub -all "(^|\n)\[^\n\]*file path prefix \[^\n\]* never used" $text "" text
206
 
207
    # This is from sun4's.  Do it for all machines for now.
208
    # The "\\1" is to try to preserve a "\n" but only if necessary.
209
    regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text
210
 
211
    # This happens when compiling on Alpha OSF/1 with cc -g -O.
212
    regsub -all "(^|\n)(\n*uopt: Warning: file not optimized; use -g3 if both optimization and debug wanted\n?)+" $text "\\1" text
213
 
214
    # This happens when compiling on Alpha OSF using gas.
215
    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
216
 
217
    # This happens on SunOS with cc -g -O.
218
    regsub -all "(^|\n)(cc: Warning: -O conflicts with -g. -O turned off.\n?)+" $text "\\1" text
219
 
220
    # This happens when assembling code with the native HP assembler
221
    regsub -all "(^|\n)(as:\[^\n\]*err#13.\n  .warning.\[^\n\]*\n?)+" $text "\\1" text
222
 
223
    # When using the HP assembler, -g isn't supported.
224
    regsub -all "(^|\n)(cc1: warning: -g is only supported when using GAS on this processor\[^\n\]*\ncc1: warning:\[^\n\]*\n?)+" $text "\\1" text
225
    regsub -all "(^|\n)(cc1plus: warning: -g is only supported when using GAS on this processor\[^\n\]*\ncc1plus: warning:\[^\n\]*\n?)+" $text "\\1" text
226
 
227
    # This happens when testing across NFS.
228
    regsub -all "(^|\n)(NFS server \[^\n\]* not responding still trying\[^\n\]*\n?)+" $text "\\1" text
229
    regsub -all "(^|\n)(NFS server \[^\n\]* ok\[^\n\]*\n?)+" $text "\\1" text
230
 
231
    # This happens when testing across NFS on osf4.
232
    regsub -all "(^|\n)(NFS3 server \[^\n\]* not responding still trying\[^\n\]*\n?)+" $text "\\1" text
233
    regsub -all "(^|\n)(NFS3 server \[^\n\]* ok\[^\n\]*\n?)+" $text "\\1" text
234
 
235
    # When using the IRIX 6 o32 assembler, -g isn't supported
236
    regsub -all "(^|\n)(cc1: warning: `-g' not supported by this configuration of GCC\[^\n\]*\n?)+" $text "\\1" text
237
    regsub -all "(^|\n)(cc1plus: warning: `-g' not supported by this configuration of GCC\[^\n\]*\n?)+" $text "\\1" text
238
 
239
    regsub -all "(^|\n)(cc1: warning: -mabi=32 does not support -g\[^\n\]*\n?)+" $text "\\1" text
240
    regsub -all "(^|\n)(cc1plus: warning: -mabi=32 does not support -g\[^\n\]*\n?)+" $text "\\1" text
241
 
242
    # This happens with the o32 assembler on IRIX 6.
243
    regsub -all "(^|\n)(as: Warning: -O3 is not supported for assembly compiles for ucode compilers; changing to -O2.\n?)+" $text "\\1" text
244
 
245
    # This happens when using g++ on a DWARF system.
246
    regsub -all "(^|\n)(cc1plus: warning: -g option not supported for C\\+\\+ on systems using the DWARF debugging format\n?)+" $text "\\1" text
247
 
248
    # This is from sun4's.  Do it for all machines for now.
249
    # The "\\1" is to try to preserve a "\n" but only if necessary.
250
    regsub -all "(^|\n)(ld.so: warning:\[^\n\]*\n?)+" $text "\\1" text
251
 
252
    # See Brendan for the raison d'etre of this one.
253
    if [string match "alpha*-*-*" $host_triplet] {
254
        regsub -all "(^|\n)(/usr/(ucb|bin)/ld.*without exceptions was\[^\n\]+\n?)" $text "\\1" text
255
    }
256
 
257
    # Don't pay attention to the AIX4 linker warnings.
258
    regsub -all "(^|\n)(ld:.*WARNING: Duplicate.*ld:.*Use the -bload\[^\n\]*\n?)" $text "\\1" text
259
 
260
    # Or the IRIX 6 ones.
261
    regsub -all "(^|\n)(ld(|32|64): WARNING \[^\n\]*\n?)+" $text "\\1" text
262
    regsub -all "(^|\n)(ld(|32|64): Giving up.*Use -wall\[^\n\]*\n?)+" $text "\\1" text
263
 
264
    # Or the NetBSD ones.
265
    regsub -all "(^|\n)(\[^\n\]*:\[0-9\]+: warning: \[^\n\]* possibly used unsafely, use \[^\n\]*\n?)" $text "\\1" text
266
    regsub -all "(^|\n)(\[^\n\]*: warning: reference to compatibility glob\[^\n\]*\n?)" $text "\\1" text
267
 
268
    # GNU ld warns about functions marked as dangerous in GNU libc.
269
    regsub -all "(^|\n)\[^\n\]*: In function\[^\n\]*\n\[^\n\]\[^\n\]*function is dangerous\[^\n\]*" $text "" text
270
 
271
    # Libgloss libnosys defines functions that warn when linked in
272
    regsub -all "(^|\n)\[^\n\]*: In function\[^\n\]*\n\[^\n\]\[^\n\]*is not implemented and will always fail\[^\n\]*" $text "" text
273
 
274
    # It might be tempting to get carried away and delete blank lines, etc.
275
    # Just delete *exactly* what we're ask to, and that's it.
276
    return $text
277
}
278
 
279
#
280
# Invoke the compiler. This gets interesting cause the compiler may
281
# not be on the same machine we're running DejaGnu on.
282
#
283
 
284
proc target_compile {source destfile type options} {
285
    set target [target_info name];
286
    if { [info proc ${target}_compile] != "" } {
287
        return [${target}_compile $source $destfile $type $options];
288
    } else {
289
        return [default_target_compile $source $destfile $type $options];
290
    }
291
}
292
 
293
proc default_target_compile {source destfile type options} {
294
    global target_triplet
295
    global tool_root_dir
296
    global CFLAGS_FOR_TARGET
297
    global compiler_flags
298
 
299
    if { $destfile == "" && $type != "preprocess" && $type != "none" } {
300
        error "Must supply an output filename for the compile to default_target_compile"
301
    }
302
 
303
    set add_flags ""
304
    set libs ""
305
    set compiler_type "c"
306
    set compiler ""
307
    set ldflags ""
308
    set dest [target_info name]
309
 
310
    if [info exists CFLAGS_FOR_TARGET] {
311
        append add_flags " $CFLAGS_FOR_TARGET"
312
    }
313
 
314
    if [info exists target_info(host,name)] {
315
        set host [host_info name];
316
    } else {
317
        set host "unix";
318
    }
319
 
320
    foreach i $options {
321
        if { $i == "c++" } {
322
            set compiler_type "c++"
323
            if [board_info $dest exists cxxflags] {
324
                append add_flags " [target_info cxxflags]"
325
            }
326
            append add_flags " [g++_include_flags]";
327
            if [board_info $dest exists c++compiler] {
328
                set compiler [target_info c++compiler];
329
            } else {
330
                set compiler [find_g++];
331
            }
332
        }
333
 
334
        if { $i == "f77" } {
335
            set compiler_type "f77"
336
            if [board_info $dest exists f77flags] {
337
                append add_flags " [target_info f77flags]"
338
            }
339
#           append add_flags " [f77_include_flags]"
340
            if [board_info $dest exists f77compiler] {
341
                set compiler [target_info f77compiler]
342
            } else {
343
                set compiler [find_g77]
344
            }
345
        }
346
 
347
        if [regexp "^dest=" $i] {
348
            regsub "^dest=" $i "" tmp
349
            if [board_info $tmp exists name] {
350
                set dest [board_info $tmp name];
351
            } else {
352
                set dest $tmp;
353
            }
354
        }
355
        if [regexp "^compiler=" $i] {
356
            regsub "^compiler=" $i "" tmp
357
            set compiler $tmp
358
        }
359
        if [regexp "^additional_flags=" $i] {
360
            regsub "^additional_flags=" $i "" tmp
361
            append add_flags " $tmp"
362
        }
363
        if [regexp "^ldflags=" $i] {
364
            regsub "^ldflags=" $i "" tmp
365
            append ldflags " $tmp"
366
        }
367
        if [regexp "^libs=" $i] {
368
            regsub "^libs=" $i "" tmp
369
            append libs " $tmp"
370
        }
371
        if [regexp "^incdir=" $i] {
372
            regsub "^incdir=" $i "-I" tmp
373
            append add_flags " $tmp"
374
        }
375
        if [regexp "^libdir=" $i] {
376
            regsub "^libdir=" $i "-L" tmp
377
            append add_flags " $tmp"
378
        }
379
        if [regexp "^ldscript=" $i] {
380
            regsub "^ldscript=" $i "" ldscript
381
        }
382
        if [regexp "^redirect=" $i] {
383
            regsub "^redirect=" $i "" redirect
384
        }
385
        if [regexp "^optimize=" $i] {
386
            regsub "^optimize=" $i "" optimize
387
        }
388
        if [regexp "^timeout=" $i] {
389
            regsub "^timeout=" $i "" timeout
390
        }
391
    }
392
 
393
    if [board_info $host exists cflags_for_target] {
394
        append add_flags " [board_info $host cflags_for_target]";
395
    }
396
 
397
    global CC_FOR_TARGET
398
    global CXX_FOR_TARGET
399
    global F77_FOR_TARGET
400
 
401
    if [info exists CC_FOR_TARGET] {
402
        if { $compiler == "" } {
403
            set compiler $CC_FOR_TARGET
404
        }
405
    }
406
 
407
    if [info exists CXX_FOR_TARGET] {
408
        if { $compiler_type == "c++" } {
409
            set compiler $CXX_FOR_TARGET
410
        }
411
    }
412
 
413
    if [info exists F77_FOR_TARGET] {
414
        if { $compiler_type == "f77" } {
415
            set compiler $F77_FOR_TARGET
416
        }
417
    }
418
 
419
    if { $compiler == "" } {
420
        set compiler [board_info $dest compiler];
421
        if { $compiler == "" } {
422
            return "default_target_compile: No compiler to compile with";
423
        }
424
    }
425
 
426
    if ![is_remote host] {
427
        if { [which $compiler] == 0 } {
428
            return "default_target_compile: Can't find $compiler."
429
        }
430
    }
431
 
432
    if {$type == "object"} {
433
        append add_flags " -c"
434
    }
435
 
436
    if { $type == "preprocess" } {
437
        append add_flags " -E"
438
    }
439
 
440
    if { $type == "assembly" } {
441
        append add_flags " -S"
442
    }
443
 
444
    if [board_info $dest exists cflags] {
445
        append add_flags " [board_info $dest cflags]"
446
    }
447
 
448
    if { $type == "executable" } {
449
        # This must be added here.
450
        # if [board_info $dest exists ldscript] {
451
        #     append add_flags " [board_info $dest ldscript]"
452
        # }
453
 
454
        if [board_info $dest exists ldflags] {
455
            append add_flags " [board_info $dest ldflags]"
456
        }
457
        if { $compiler_type == "c++" } {
458
            append add_flags " [g++_link_flags]";
459
        }
460
        if [isnative] {
461
            # This is a lose.
462
            catch "glob -nocomplain $tool_root_dir/libstdc++/libstdc++.so* $tool_root_dir/libstdc++/libstdc++.sl" tmp
463
            if { ${tmp} != "" } {
464
                if [regexp ".*solaris2.*" $target_triplet] {
465
                    # Solaris 2
466
                    append add_flags " -R$tool_root_dir/libstdc++"
467
                } elseif [regexp ".*(osf|irix5|linux).*" $target_triplet] {
468
                    # OSF/1 or Irix5
469
                    append add_flags " -Wl,-rpath,$tool_root_dir/libstdc++"
470
                } elseif [regexp ".*hppa.*" $target_triplet] {
471
                    # HP/UX
472
                    append add_flags " -Wl,-a,shared_archive"
473
                }
474
            }
475
        }
476
    }
477
 
478
    if ![info exists ldscript] {
479
        set ldscript [board_info $dest ldscript]
480
    }
481
 
482
    foreach i $options {
483
        if { $i == "debug" } {
484
            if [board_info $dest exists debug_flags] {
485
                append add_flags " [board_info $dest debug_flags]";
486
            } else {
487
                append add_flags " -g"
488
            }
489
        }
490
    }
491
 
492
    if [info exists optimize] {
493
        append add_flags " $optimize";
494
    }
495
 
496
    if { $type == "executable" } {
497
        foreach x $libs {
498
            if [file exists $x] {
499
                append source " $x"
500
            } else {
501
                append add_flags " $x";
502
            }
503
        }
504
        append add_flags " $ldflags"
505
 
506
        if [board_info $dest exists libs] {
507
            append add_flags " [board_info $dest libs]"
508
        }
509
 
510
        # This probably isn't such a good idea, but it avoids nasty
511
        # hackiness in the testsuites.
512
        # The math library must be linked in before the C library.  The C
513
        # library is linked in by the linker script, so this must be before
514
        # the linker script.
515
        if [board_info $dest exists mathlib] {
516
            append add_flags " [board_info $dest mathlib]"
517
        } else {
518
            append add_flags " -lm"
519
        }
520
 
521
        # This must be added here.
522
        append add_flags " $ldscript";
523
 
524
        if [board_info $dest exists remote_link] {
525
            # Relink option.
526
            append add_flags " -Wl,-r"
527
        }
528
        if [board_info $dest exists output_format] {
529
            append add_flags " -Wl,-oformat,[board_info $dest output_format]";
530
        }
531
    }
532
 
533
    if [board_info $dest exists multilib_flags] {
534
        append add_flags " [board_info $dest multilib_flags]";
535
    }
536
 
537
    verbose "doing compile"
538
 
539
    set sources ""
540
    if [is_remote host] {
541
        foreach x $source {
542
            set file [remote_download host $x];
543
            if { $file == "" } {
544
                warning "Unable to download $x to host."
545
                return "Unable to download $x to host."
546
            } else {
547
                append sources " $file";
548
            }
549
        }
550
    } else {
551
        set sources $source
552
    }
553
 
554
    if [is_remote host] {
555
        append add_flags " -o a.out"
556
        remote_file host delete a.out;
557
    } else {
558
        if { $destfile != "" } {
559
            append add_flags " -o $destfile";
560
        }
561
    }
562
 
563
    # This is obscure: we put SOURCES at the end when building an
564
    # object, because otherwise, in some situations, libtool will
565
    # become confused about the name of the actual source file.
566
    if {$type == "object"} {
567
        set opts "$add_flags $sources"
568
    } else {
569
        set opts "$sources $add_flags"
570
    }
571
 
572
    if [is_remote host] {
573
        if [host_info exists use_at] {
574
            set fid [open "atfile" "w"];
575
            puts $fid "$opts";
576
            close $fid;
577
            set opts "@[remote_download host atfile]"
578
            remote_file build delete atfile
579
        }
580
    }
581
 
582
    verbose "Invoking the compiler as $compiler $opts" 2
583
 
584
    if [info exists redirect] {
585
        verbose "Redirecting output to $redirect" 2
586
        set status [remote_exec host "$compiler $opts" "" "" $redirect];
587
    } else {
588
        if [info exists timeout] {
589
            verbose "Setting timeout to $timeout" 2
590
            set status [remote_exec host "$compiler $opts" "" "" "" $timeout];
591
        } else {
592
            set status [remote_exec host "$compiler $opts"];
593
        }
594
    }
595
 
596
    set compiler_flags $opts
597
    if [is_remote host] {
598
        remote_upload host a.out $destfile;
599
        remote_file host delete a.out;
600
    }
601
    set comp_output [prune_warnings [lindex $status 1]];
602
    regsub "^\[\r\n\]+" $comp_output "" comp_output;
603
    if { [lindex $status 0] != 0 } {
604
        verbose -log "compiler exited with status [lindex $status 0]";
605
    }
606
    if { [lindex $status 1] != "" } {
607
        verbose -log "output is:\n[lindex $status 1]" 2;
608
    }
609
    if { [lindex $status 0] != 0 && "${comp_output}" == "" } {
610
        set comp_output "exit status is [lindex $status 0]";
611
    }
612
    return ${comp_output};
613
}
614
 
615
proc reboot_target { } {
616
    set result [remote_reboot target]
617
    puts "REBOOT_TARGET: \"$result\""
618
    return ${result};
619
}
620
 
621
#
622
# Invoke this if you really want as to be called directly, rather than
623
# calling the compiler. FLAGS are any additional flags to pass to the
624
# assembler.
625
#
626
proc target_assemble { source destfile flags } {
627
    return [default_target_assemble $source $destfile $flags];
628
}
629
 
630
proc default_target_assemble { source destfile flags } {
631
    global AS_FOR_TARGET
632
    global ASFLAGS_FOR_TARGET
633
 
634
    if [info exists AS_FOR_TARGET] {
635
        set AS "$AS_FOR_TARGET";
636
    } else {
637
        if ![board_info target exists assembler] {
638
            set AS [find_gas];
639
        } else {
640
            set AS [board_info target assembler];
641
        }
642
    }
643
 
644
    if [info exists ASFLAGS_FOR_TARGET] {
645
        append flags " $ASFLAGS_FOR_TARGET";
646
    }
647
 
648
    if [is_remote host] {
649
        set source [remote_download host $source];
650
        set dest "a.out"
651
    } else {
652
        set dest $destfile
653
    }
654
    set status [remote_exec host "$AS $source $flags -o $dest"]
655
    if [is_remote host] {
656
        remote_upload host $dest $destfile
657
    }
658
 
659
    set comp_output [prune_warnings [lindex $status 1]];
660
    if { [lindex $status 0] != 0 } {
661
        verbose -log "assembler exited with status [lindex $status 0]";
662
    }
663
    if { [lindex $status 1] != "" } {
664
        verbose -log "assembler output is:\n[lindex $status 1]" 2;
665
    }
666
    return ${comp_output};
667
}
668
 
669
#
670
# Invoke this if you really want ld to be called directly, rather than
671
# calling the compiler. FLAGS are any additional flags to pass to the
672
# linker.
673
#
674
proc target_link { objects destfile flags } {
675
    return [default_link target "$objects" "$destfile" $flags];
676
}
677
 
678
proc default_link { board objects destfile flags } {
679
    global LD_FOR_TARGET
680
    global LDFLAGS_FOR_TARGET
681
 
682
    # return -L's in ldflags
683
    proc only--Ls { ldflags } {
684
        set result ""
685
        set ldflags [split $ldflags]
686
        set len [llength $ldflags]
687
        for { set i 0 } { $i < $len } { incr i } {
688
            # ??? We ignore the situation where a -L is actually the argument
689
            # to an option.
690
            set arg [lindex $ldflags $i]
691
            regsub "^-Wl," $arg "" arg
692
            if [regexp "^-L" $arg] {
693
                # Is the directory in the next arg, or part of this one?
694
                if { "$arg" == "-L" } {
695
                    if { $i + 1 < $len } {
696
                        append result " -L [lindex $ldflags $i+1]"
697
                        incr i
698
                    }
699
                } else {
700
                    append result " $arg"
701
                }
702
            }
703
        }
704
        return $result
705
    }
706
 
707
    if [info exists LD_FOR_TARGET] {
708
        set LD "$LD_FOR_TARGET";
709
    } else {
710
        if ![board_info target exists linker] {
711
            set LD [find_ld];
712
        } else {
713
            set LD [board_info target linker];
714
        }
715
    }
716
 
717
    if [info exists LDFLAGS_FOR_TARGET] {
718
        append flags " $LDFLAGS_FOR_TARGET";
719
    }
720
 
721
    # `ldflags' consists of arguments to gcc (that are then
722
    # passed to ld), not arguments to ld directly.
723
    # We need the -L's.
724
    if [board_info $board exists ldflags] {
725
        set ldflags [board_info $board ldflags]
726
        set ldflags [only--Ls $ldflags]
727
        append flags " $ldflags"
728
    }
729
 
730
    if [board_info $board exists ldscript] {
731
        # strip leading -Wl, if present
732
        set ldscript [board_info $board ldscript]
733
        regsub "^-Wl," $ldscript "" ldscript
734
        append flags " $ldscript"
735
    }
736
 
737
    if [is_remote host] {
738
        foreach x $objects {
739
            set nobjects "$nobjects [remote_download host $x]";
740
        }
741
        set objects "$nobjects";
742
        set dest "a.out";
743
    } else {
744
        set dest $destfile;
745
    }
746
    set status [remote_exec host "$LD $objects $flags -o $dest"]
747
    if [is_remote host] {
748
        remote_upload host $dest $destfile;
749
    }
750
 
751
    set comp_output [prune_warnings [lindex $status 1]];
752
    if { [lindex $status 0] != 0 } {
753
        verbose -log "linker exited with status [lindex $status 0]";
754
    }
755
    if { [lindex $status 1] != "" } {
756
        verbose -log "linker output is:\n[lindex $status 1]" 2;
757
    }
758
    return ${comp_output};
759
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.