Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 dpurdie 1
# -*- mode: perl; tabs: 8; indent-width: 4; show-tabs: yes; -*-
2
#
3
# Module name   : GCC
4
# Module type   : Makefile system
5
# Compiler(s)   : ANSI C
6
# Environment(s): GCC
7
#
8
# Description:
9
#       GCC C/C++ toolset
10
#
11
#............................................................................#
12
 
13
use strict;
14
use warnings;
15
 
16
##############################################################################
17
#   Configuration information
18
#   Cross reference from CrossCompiler Alias to actual paths
19
#   Structure:
20
#   Hash reference: Array of toolchain information
21
#           Root of compiler
22
#           Path to gcc
23
#           Path to ar
24
#
25
#
26
my %ToolsetConfig = (
27
    #
28
    #   Preferred version of the embedded toolchain
29
    #
337 dpurdie 30
    'i386-unknown-linux-gnu'    => ['/opt/crosstool/gcc-4.1.1-glibc-2.5/i586-unknown-linux-gnu',
31
                                    'bin/i586-unknown-linux-gnu-gcc' ],
227 dpurdie 32
 
337 dpurdie 33
    'arm-9tdmi-linux-gnu'       => ['/opt/crosstool/gcc-4.1.1-glibc-2.5/arm-9tdmi-linux-gnu',
34
                                    'bin/arm-9tdmi-linux-gnu-gcc' ],
227 dpurdie 35
 
337 dpurdie 36
    'powerpc-603e-linux-gnu'    => ['/opt/crosstool/gcc-4.1.1-glibc-2.5/powerpc-603e-linux-gnu',
37
                                    'bin/powerpc-603e-linux-gnu-gcc'],
247 dpurdie 38
 
337 dpurdie 39
    'arm-926ejs-linux-gnueabi'  => ['/opt/crosstool/gcc-4.4.3-glibc-2.9/arm-926ejs-linux-gnueabi',
40
                                    'bin/arm-926ejs-linux-gnueabi-gcc' ],
41
 
227 dpurdie 42
    #
43
    #   Old (not to be used) version of the embedded toolchain
44
    #   This was depricated in favor of gcc-4.1.1-glibc-2.5
45
    #   It is not possible to reproduce old packages using the old compiler
46
    #   This is a known issue
47
    #
48
    'i386-unknown-linux-gnu.glibc-2.3.2' => ['/opt/crosstool/gcc-4.1.0-glibc-2.3.2/i386-unknown-linux-gnu',
49
                                 'bin/i386-unknown-linux-gnu-gcc' ],
50
 
51
    'arm-9tdmi-linux-gnu.glibc-2.3.2'    => ['/opt/crosstool/gcc-4.1.0-glibc-2.3.2/arm-9tdmi-linux-gnu',
52
                                 'bin/arm-9tdmi-linux-gnu-gcc' ],
53
 
54
    #
55
    #   Not too sure where this is used
56
    #
57
    'armv4l-unknown-linux-gcc' => [ '/opt/host/armv4l',
58
                                    'bin/armv4l-unknown-linux-gcc' ],
59
 
60
    #
61
    #   The compiler for the current local machine
62
    #
63
    'i386-unknown-linux-gcc' => [ '/opt/host/i386',
64
                                  'bin/i386-unknown-linux-gcc' ],
65
 
66
    );
67
 
68
#
69
#   Cross reference from GCCTarget to GBE_MACHTYPE for which it can
70
#   build using the 'native gcc'. This is NOT the preferred mode of operation
71
#   as the compiler is not as controlled as the cross compilers.
72
#
73
my %NativeCompilers = (
74
    'Linux i386'       => 'linux_i386',
75
    );
76
 
77
##############################################################################
78
#   ToolsetInit()
79
#       Runtime initialisation
80
#
81
##############################################################################
82
 
83
ToolsetInit();
84
 
85
sub ToolsetInit
86
{
87
    my( $GCCTarget, @GCCToolchain, $GCCRoot, $GCCBin, $GCCAr );
88
    my( $arg_alias, $tools_found );
89
 
90
#.. Toolset configuration
91
#
92
    $::ScmToolsetVersion = "1.0.0";             # our version
93
    $::ScmToolsetGenerate = 0;                  # GEN generate optional
94
    $::ScmToolsetCompilerPath = 1;              # Exports Compiler path to makefile via SCM_COMPILERPATH
271 dpurdie 95
    $::ScmToolsetProgDependancies = 0;          # handle Prog dependancies myself
339 dpurdie 96
    $::ScmToolsetSoName = 1;                    # Shared library supports SoName
227 dpurdie 97
 
98
#.. Standard.rul requirements
99
#
100
    $::s = "asm";
101
    $::o = "o";
102
    $::so = "so";
103
    $::a = "a";
104
    $::exe = "";
105
 
106
#.. Parse arguments
107
#
108
    foreach $_ ( @::ScmToolsetArgs ) {
109
        if (/^--Target=(.*)/) {                 # OS Version
110
            $GCCTarget = "$1";
111
 
112
        } elsif (/^--CrossAlias=(.*)/) {        # CrossCompiler target-alias
113
            $arg_alias = $1;
114
 
115
        } else {
116
            Message( "gcc toolset: unknown option $_ -- ignored\n" );
117
        }
118
    }
119
 
120
    foreach $_ ( @::ScmPlatformArgs ) {
121
        if (/^--product=(.*)/) {                # GBE product
122
 
123
        } else {
124
            Message( "gcc toolset: unknown platform argument $_ -- ignored\n" );
125
        }
126
    }
127
 
128
    Error ("TOOLSET/gcc - Target undefined" )
129
        unless ($GCCTarget);
130
 
131
#.. Cross compile support
132
#
133
#   Toolchain=root,[bin]
134
#
135
    if ( $arg_alias )
136
    {
137
        if ( exists $ToolsetConfig{ $arg_alias } )
138
        {
139
            @GCCToolchain = @{$ToolsetConfig{ $arg_alias }};
140
            $tools_found = (-d $GCCToolchain[0]);
141
            Warning ("gcc toolset: CrossPlatform toolchain not found for: $arg_alias",
142
                     "Path: $GCCToolchain[0]" ) unless $tools_found;
143
        }
144
        else
145
        {
146
            Error("gcc toolset: CrossPlatform Alias not configured: $arg_alias");
147
        }
148
    }
149
 
150
    #
151
    #   If no Cross compiler toolchain is found (preferred method), then attempt
152
    #   to match a native compiler. Only known targets allow a native build
153
    #
154
    unless ( $tools_found )
155
    {
156
        if ( exists ( $NativeCompilers{$GCCTarget} ))
157
        {
158
            if ( $NativeCompilers{$GCCTarget} eq $::GBE_MACHTYPE )
159
            {
160
                $tools_found = 1;
161
                @GCCToolchain = ();
162
            }
163
        }
164
    }
165
 
166
    #
167
    #   Must have a toolset by now, either a cross compiler or Native
168
    #
169
    Error ("gcc toolset: Toolchain not found for: $GCCTarget" )
170
        unless ( $tools_found );
171
 
172
 
173
    if ( @GCCToolchain )
174
    {
175
        #
176
        #   Parse GCCToolchain. Potentially three parts
177
        #   [0] - GCCRoot - Location to find the effective /usr/include directory
178
        #   [1] - GCCBin  - Path to the gcc executable
179
        #                   If relative, then its relative to GCCRoot
180
        #   [2] - GCCAr   - Path to the ar executable
181
        #                   If relative, then its relative to GCCRoot
182
        #                   If not defined then its the same as GCCBin with gcc replaced with ar
183
        #
184
        $GCCRoot = $GCCToolchain[0];
185
 
186
        #   GCC_CC definition
187
        #
188
        if ( $GCCToolchain[1] )
189
        {                                           # user specification
190
            if ( substr($GCCToolchain[1],0,1) ne "/") {
191
                $GCCBin = $GCCToolchain[0].'/'.$GCCToolchain[1];
192
            } else {
193
                $GCCBin = $GCCToolchain[1];         # abs path
194
            }
195
        }
196
        else
197
        {                                           # default
198
            $GCCBin = $GCCToolchain[0] . '/bin/gcc';
199
        }
200
 
201
        #   GCC_AR definition
202
        #
203
        if ( defined($GCCToolchain[2]) && $GCCToolchain[2] )
204
        {                                           # user specification
205
            if ( substr($GCCToolchain[2],0,1) ne "/") {
206
                $GCCAr = $GCCToolchain[0].'/'.$GCCToolchain[2];
207
            } else {
208
                $GCCAr = $GCCToolchain[2];          # abs path
209
            }
210
        } 
211
        else 
212
        {                                           # default, base on GCCBin
213
            $GCCAr = substr($GCCBin,0,length($GCCBin)-3)."ar";
214
        }
215
    }
216
    else
217
    {
218
        $GCCRoot = "/usr";
219
        $GCCBin = "gcc";
220
        $GCCAr = "ar";
221
    }
222
 
223
#.. Define GCC environment
224
#
225
    PlatformDefine( "
226
#################################################
227
# GCC toolchain definitions 
228
#
229
#..");
230
    PlatformDefine( "GCC_TARGET\t".     ":=$GCCTarget" );
231
    PlatformDefine( "GCC_ROOT\t".       ":=$GCCRoot" );
232
    PlatformDefine( "GCC_CC\t\t".       ":=$GCCBin" );
233
    PlatformDefine( "GCC_AR\t\t".       ":=$GCCAr" );
234
    PlatformDefine( "" );
235
 
236
    #
237
    #   Required since this toolset advertises: ScmToolsetCompilerPath
238
    #
239
    PlatformDefine( "SCM_COMPILERPATH\t\t".       ":=$GCCBin" );
240
 
241
 
242
#.. Piece the world together
243
#
244
    Init( "gcc" );
245
    ToolsetDefines( "gcc.def" );
246
    ToolsetRules( "gcc.rul" );
247
    ToolsetRules( "standard.rul" );
248
 
249
#   Create a standard data structure
250
#   This is a hash of hashes
251
#       The first hash is keyed by CompileOption keyword
252
#       The second hash contains pairs of values to set or remove
253
#
254
    %::ScmToolsetCompilerOptions =
255
    (
256
        #
257
        #   Control the thread model to use
258
        #   This will affect the compiler options and the linker options
259
        #
260
        'staticprogs'        => { 'STATIC_PROGS' , '1' },      # Progams link staticlly
261
        'no_staticprogs'     => { 'STATIC_PROGS' , undef },    # Default
262
    );
263
 
264
    #
265
    #   Set default options
266
    #
267
    $::ScmCompilerOpts{'STATIC_PROGS'} = undef;
268
}
269
 
270
 
271
###############################################################################
272
#   ToolsetCC( $source, $obj, \@args )
273
#       This subroutine takes the user options and builds the rule(s)
274
#       required to compile the source file 'source' to 'obj'
275
#
276
###############################################################################
277
 
278
sub ToolsetCC
279
{
280
    my( $source, $obj, $pArgs ) = @_;
281
    my( $cflags, $file ) = "";
282
 
283
    foreach $_ ( @$pArgs ) {
284
        if (/--Shared$/) {                      # Building a 'shared' object
285
            $cflags  = "$cflags \$(SHCFLAGS)";
286
        } else {
287
            Message( "CC: unknown option $_ -- ignored\n" );
288
        }
289
    }
290
 
291
    MakePrint( "\n\t\$(CC)\n" );
292
    if ( $cflags )
293
    {                                           # object specific CFLAGS
294
        MakePadded( 4, "\$(OBJDIR)/$obj.$::o:" );
295
        MakePrint( "\tCFLAGS +=$cflags\n" );
296
    }
297
 
298
    $file = StripExt( $obj );                   # Metric working file
299
    ToolsetGenerate( "\$(OBJDIR)/$file.met" );
300
}
301
 
302
 
303
###############################################################################
304
#   ToolsetCCDepend( $depend, \@sources )
305
#       This subroutine takes the user options and builds the
306
#       rule(s) required to build the dependencies for the source
307
#       files 'sources' to 'depend'.
308
#
309
###############################################################################
310
 
311
sub ToolsetCCDepend
312
{
313
    MakePrint( "\t\$(CCDEPEND)\n" );
314
}
315
 
316
 
317
###############################################################################
318
#   ToolsetCXX( $source, $obj, \@args )
319
#       This subroutine takes the user options and builds the rule(s)
320
#       required to compile the source file 'source' to 'obj'
321
#
322
###############################################################################
323
 
324
sub ToolsetCXX
325
{
326
    my( $source, $obj, $pArgs ) = @_;
327
    my( $cflags, $file ) = "";
328
 
329
    foreach $_ ( @$pArgs ) {
330
        if (/--Shared$/) {                      # Building a 'shared' object
331
            $cflags  = "$cflags \$(SHCXXFLAGS)";
332
        } else {
333
            Message( "CXX: unknown option $_ -- ignored\n" );
334
        }
335
    }
336
 
337
    MakePrint( "\n\t\$(CXX)\n" );
338
    if ( $cflags )
339
    {                                           # object specific CFLAGS
340
        MakePadded( 4, "\$(OBJDIR)/$obj.$::o:" );
341
        MakePrint( "\tCXXFLAGS +=$cflags\n" );
342
    }
343
 
344
    $file = StripExt( $obj );                   # Metric working file
345
    ToolsetGenerate( "\$(OBJDIR)/$file.met" );
346
}
347
 
348
 
349
###############################################################################
350
#   ToolsetCXXDepend( $depend, \@sources )
351
#       This subroutine takes the user options and builds the
352
#       rule(s) required to build the dependencies for the source
353
#       files 'sources' to 'depend'.
354
#
355
###############################################################################
356
 
357
sub ToolsetCXXDepend
358
{
287 dpurdie 359
    ToolsetCCDepend();
227 dpurdie 360
}
361
 
362
 
363
###############################################################################
364
#   ToolsetAS( $source, $obj, \@args )
365
#       This subroutine takes the user options and builds the rule(s)
366
#       required to compile the source file 'source' to 'obj'
367
#
368
###############################################################################
369
 
370
sub ToolsetAS
371
{
372
    MakePrint( "\n\t\$(AS)\n" );
373
}
374
 
375
sub ToolsetASDepend
376
{
377
}
378
 
379
 
380
###############################################################################
381
#   ToolsetAR( $name, \@args, \@objs )
382
#       This subroutine takes the user options and builds the rules
383
#       required to build the library 'name'.
384
#
385
#   Arguments:
386
#       n/a
387
#
388
#   Output:
389
#       $(BINDIR)/name$.${a}:   .... ]
390
#           $(AR)
391
#
392
#       name_ld += ...  Linker command file
393
#           :
394
#
395
#       name_dp += ...  Dependency list
396
#           :
397
#
398
###############################################################################
399
 
400
sub ToolsetAR
401
{
402
    my( $name, $pArgs, $pObjs ) = @_;
403
 
404
#.. Parse arguments
405
#
406
    foreach $_ ( @$pArgs )
407
    {
408
        Message( "AR: unknown option $_ -- ignored\n" );
409
    }
410
 
411
#.. Target
412
#
413
    MakePrint( "#.. Library ($name)\n\n" );     # label
414
 
415
    MakeEntry( "\$(LIBDIR)/$name\$(GBE_TYPE).$::a:\t",
416
        "", "\\\n\t\t", ".$::o", @$pObjs );
417
 
418
#.. Build library rule (just append to standard rule)
419
#
420
    MakePrint( "\n\t\$(AR)\n\n" );
421
}
422
 
423
 
424
###############################################################################
425
#   ToolsetARMerge( $name, \@args, \@libs )
426
#       This subroutine takes the user options and builds the rules
427
#       required to build the library 'name' by merging the specified
428
#       libaries
429
#
430
#   Arguments:
431
#       --xxx                   No arguments currently defined
432
#
433
#   Output:
434
#       [ $(LIBDIR)/name$.${a}:   .... ]
435
#           ...
436
#
437
###############################################################################
438
 
439
sub ToolsetARMerge
440
{
441
    MakePrint( "\n\t\$(ARMERGE)\n\n" );
442
}
443
 
444
 
445
###############################################################################
289 dpurdie 446
#   ToolsetSHLD( $name, \@args, \@objs, \@libraries, $ver )
227 dpurdie 447
#       This subroutine takes the user options and builds the rules
339 dpurdie 448
#       required to link the Shared Library 'name'.
227 dpurdie 449
#
450
#   Arguments:
451
#   n/a
452
#
453
#   Output:
454
#       $(LIBDIR)/name:     $(LIBDIR)/shared
455
#           ln -s $shared $name
456
#
457
#       $(LIBDIR)/name.dep: $(GBE_OBJDIR)
458
#       $(LIBDIR)/name.dep: $(GBE_LIBDIR)
459
#       $(LIBDIR)/name.dep: $(GBE_PLATFORM).mk
460
#           $(SHLDDEPEND)
461
#
462
#       $(LIBDIR)/shared:   SHNAME=name
463
#       $(LIBDIR)/shared:   SHBASE=base
464
#       $(LIBDIR)/shared:   $(LIBDIR)/name.dep  \
465
#           $(OBJECTS)
466
#                           
467
#       ifneq "$(findstring $(IFLAG),23)" ""
468
#       -include            "$(LIBDIR)/name.dep"
469
#       endif
470
#
471
#       name_ld += ...
472
#           :
473
#
474
###############################################################################
475
 
476
sub ToolsetSHLD
477
{
289 dpurdie 478
    my( $name, $pArgs, $pObjs, $pLibs, $ver ) = @_;
339 dpurdie 479
    my( $linkname, $soname, $shared, $def, $def_pref, $multi_scan );
480
    my $sosuffix = '.' . $ver;
227 dpurdie 481
 
482
#.. Parse arguments
483
#
484
    foreach $_ ( @$pArgs )
485
    {
486
        if (/^--Def=(.*?)(\,(.*))?$/) {         # Library definition
487
            #
488
            #   Locate the Def file.
489
            #   If it is a generate file so it will be in the SRCS hash
490
            #   Otherwise the user will have to use Src to locate the file
491
            #
492
            $def = MakeSrcResolve($1);
493
            $def_pref = '';
494
            if ( $1 =~ m~\.def$~ ) {
495
                $def_pref = '--version-script='; # Old def file
496
            }
497
        } elsif ( /^--MultiScan/i ) {
498
            $multi_scan = 1;
499
 
500
        } elsif ( /^--NoMultiScan/i ) {
501
            $multi_scan = 0;
502
 
339 dpurdie 503
        } elsif ( /^--SoNameSuffix=(.*)/i ) {
504
            $sosuffix = $1;
505
 
227 dpurdie 506
        } else {
507
            Message( "SHLD: unknown option $_ -- ignored\n" );
508
        }
509
    }
510
 
339 dpurdie 511
#.. Various library names
227 dpurdie 512
#
339 dpurdie 513
    $linkname = "$name\$(GBE_TYPE).$::so";
514
    $shared = "$linkname.$ver";
515
    $soname = "$linkname$sosuffix";
227 dpurdie 516
 
517
#.. Cleanup rules
518
#
519
#   map     Map file
520
#   ln      Link from LIBDIR to BINDIR
521
#
261 dpurdie 522
    ToolsetGenerate( "\$(LIBDIR)/${name}.map" );
523
    ToolsetGenerate( "\$(LIBDIR)/${shared}" );
339 dpurdie 524
    ToolsetGenerate( "\$(BINDIR)/${soname}" );
227 dpurdie 525
 
526
#.. Build rules
527
#
528
#   name        Base name
529
#   shared      Library name, includes GBE_TYPE specification
530
#
531
    my ($io) = ToolsetPrinter::New();
335 dpurdie 532
    my $dep = $io->SetShldTarget($shared);
227 dpurdie 533
 
534
    $io->Label( "Shared library", $name );
339 dpurdie 535
    PackageShlibAddFiles( $name, "\$(LIBDIR)/$shared" );
536
 
227 dpurdie 537
    $io->Prt( "\$(LIBDIR)/${shared}:\tSHBASE=${name}\n" );
339 dpurdie 538
    $io->Prt( "\$(LIBDIR)/${shared}:\tSHNAME=${soname}\n" );
539
    $io->Prt( "\$(LIBDIR)/${shared}: \\\n\t\t${dep}" );
321 dpurdie 540
    $io->Entry( "", "", " \\\n\t\t", ".$::o", @$pObjs );
227 dpurdie 541
    $io->Prt( "\\\n\t\t$def" ) if($def);
321 dpurdie 542
    $io->Prt( "\n\t\$(SHLD)\n\n" );
543
 
227 dpurdie 544
 
339 dpurdie 545
#
546
#   Create soft links
547
#       'Real Name' to its 'Link Name'
548
#       'Real Name' to 'SoName' in the BINDIR (for testing I think)
549
#       'Real Name' to 'SoName' in the LIBDIR (if different)
550
#
551
    $io->Label( "Shared library Symbolic Links", $name );
552
    PackageShlibAddFiles( $name, "\$(LIBDIR)/$linkname" );
553
    $io->Prt( "\$(LIBDIR)/$linkname:\t\\\n" .
554
              "\t\t\$(GBE_BINDIR)\\\n" .
555
              "\t\t\$(LIBDIR)/${shared}\n" .
556
              "\t\$(AA_PRE)(rm -f \$@; ln -s ./$shared \$@)\n" .
557
              "\t\$(AA_PRE)(rm -f \$(BINDIR)/$soname; ln -s ../\$(LIBDIR)/$shared \$(BINDIR)/$soname)\n\n" );
558
 
559
    if ( $soname ne $shared && $soname ne $linkname)
560
    {
561
        $io->Label( "Shared library SoName Symbolic Links", $name );
562
        PackageShlibAddFiles( $name, "\$(LIBDIR)/$soname" );
563
        $io->Prt( "\$(LIBDIR)/$soname:\t\\\n" .
564
                  "\t\t\$(GBE_LIBDIR)\\\n" .
565
                  "\t\t\$(LIBDIR)/${shared}\n" .
566
                  "\t\$(AA_PRE)(rm -f \$@; ln -s ./$shared \$@)\n" );
567
    }
568
 
227 dpurdie 569
#.. Linker command file
570
#
571
#       Now the fun part... piecing together a variable $(name_shld)
572
#       which ends up in the command file.
573
#
339 dpurdie 574
    $io->Newline();
227 dpurdie 575
    $io->SetTag( "${name}_shld" );              # command tag
576
    $io->SetTerm( "\n" );
577
 
578
    $io->Label( "Linker commands", $name );     # label
579
 
580
                                                # object list
581
    $io->ObjList( $name, $pObjs, \&ToolsetObjRecipe );
582
 
583
    ToolsetLibStd( $pLibs );                    # push standard libraries
584
 
585
    $io->Cmd( "-Wl,$def_pref$def" ) if ($def);
586
 
587
    $io->Cmd( "-Wl,--start-group" ) if ($multi_scan);
588
    $io->LibList( $name, $pLibs, \&ToolsetLibRecipe );
589
    $io->Cmd( "-Wl,--end-group" ) if ($multi_scan);
590
 
591
    $io->Newline();
592
 
335 dpurdie 593
    #.. Dependency link,
594
    #   Create a library dependency file
595
    #       Create command file to build applicaton dependency list
596
    #       from the list of dependent libraries
597
    #
598
    #       Create makefile directives to include the dependency
599
    #       list into the makefile.
600
    #
601
    $io->DepRules( $pLibs, \&ToolsetLibRecipe, "\$(LIBDIR)/${shared}" );
339 dpurdie 602
    $io->SHLDDEPEND($name, $soname);
227 dpurdie 603
}
604
 
605
 
606
###############################################################################
271 dpurdie 607
# Function        : ToolsetLD
227 dpurdie 608
#
271 dpurdie 609
# Description     : Takes the user options and builds the rules required to
610
#                   link the program 'name'.
227 dpurdie 611
#
271 dpurdie 612
# Inputs          : $name           - base name of the program
613
#                   $pArgs          - Ref to program arguments
614
#                   $pObjs          - Ref to program objects
615
#                   $pLibs          - Ref to program library list
227 dpurdie 616
#
271 dpurdie 617
# Returns         : Nothing
227 dpurdie 618
#
271 dpurdie 619
# Output:         : Rules and recipes to create a program
620
#                       Create program rules and recipes
621
#                       Create linker input script
622
#                       Create library dependency list
623
#                       Include library dependency information
227 dpurdie 624
#
625
sub ToolsetLD
626
{
627
    my( $name, $pArgs, $pObjs, $pLibs ) = @_;
628
    my $static = $::ScmCompilerOpts{'STATIC_PROGS'};
629
    my $multi_scan;
630
 
631
#.. Parse arguments
632
#
633
    foreach $_ ( @$pArgs )
634
    {
635
        if ( m/^--Static$/ ) {
636
            $static = 1;
637
 
638
        } elsif ( m/^--Shared/ ) {
639
            $static = 0;
640
 
641
        } elsif ( /^--MultiScan/i ) {
642
            $multi_scan = 1;
643
 
644
        } elsif ( /^--NoMultiScan/i ) {
645
            $multi_scan = 0;
646
 
647
        } else {
648
            Message( "LD: unknown option $_ -- ignored\n" );
649
        }
650
    }
651
 
271 dpurdie 652
#.. Names of programs and components
653
#
654
    my $base = "\$(BINDIR)/${name}";
655
    my $full = $base . $::exe;
656
    my $map  = $base . '.map';
657
    my $ld  =  $base . '.ld';
658
 
227 dpurdie 659
#.. Cleanup rules
660
#
271 dpurdie 661
    ToolsetGenerate( $ld );
662
    ToolsetGenerate( $map );
227 dpurdie 663
 
664
#.. Build rules
665
#
666
    my ($io) = ToolsetPrinter::New();
335 dpurdie 667
    my $dep = $io->SetLdTarget( $name );
227 dpurdie 668
 
271 dpurdie 669
    $io->Prt( "$full : $dep " );
670
    $io->Entry( "", "", "\\\n\t", ".$::o ", @$pObjs );
671
    $io->Prt( "\n\t\$(LD)\n\n" );
227 dpurdie 672
 
271 dpurdie 673
 
227 dpurdie 674
#.. Linker command file
675
#
676
#       Now the fun part... piecing together a variable $(name_ld)
677
#       which ends up in the command file.
678
#
679
    $io->SetTag( "${name}_ld" );                # macro tag
680
    $io->SetTerm( "\n" );
681
 
682
    $io->Label( "Linker commands", $name );     # label
683
 
684
    $io->Cmd( "-static" ) if ($static);         # Link as a static program
685
 
686
                                                # object list
687
    $io->ObjList( $name, $pObjs, \&ToolsetObjRecipe );
688
 
689
    ToolsetLibStd( $pLibs );                    # push standard libraries
690
 
691
                                                # library list
692
    $io->Cmd( "-Wl,--start-group" ) if ($multi_scan);
693
    $io->LibList( $name, $pLibs, \&ToolsetLibRecipe );
694
    $io->Cmd( "-Wl,--end-group" ) if ($multi_scan);
695
 
696
    $io->Newline();
697
 
335 dpurdie 698
    #.. Dependency link,
699
    #   Create a library dependency file
700
    #       Create command file to build applicaton dependency list
701
    #       from the list of dependent libraries
702
    #
703
    #       Create makefile directives to include the dependency
704
    #       list into the makefile.
705
    #
706
    $io->DepRules( $pLibs, \&ToolsetLibRecipe, $base );
707
    $io->LDDEPEND();
271 dpurdie 708
 
709
#.. Package up the program and other artifacts
710
#
711
    PackageProgAddFiles ( $name, $full );
712
 
227 dpurdie 713
}
714
 
715
 
716
########################################################################
717
#
718
#   Push standard "system" libraries. This is a helper function
719
#   used within this toolset.
720
#
721
#   Arguments:
722
#       $plib       Reference to library array.
723
#
724
########################################################################
725
 
726
sub ToolsetLibStd
727
{
728
}
729
 
730
 
731
########################################################################
732
#
733
#   Generate a linker object recipe.  This is a helper function used 
734
#   within this toolset.
735
#
736
#   Arguments:
737
#       $io         I/O stream
738
#
739
#       $target     Name of the target
740
#
741
#       $obj        Library specification
742
#
743
########################################################################
744
 
745
sub ToolsetObjRecipe
746
{
747
    my ($io, $target, $obj) = @_;
748
 
749
    $io->Cmd( "\$(strip $obj).$::o" );
750
}
751
 
752
 
753
###############################################################################
754
#
755
#   Parse a linker lib list
756
#   This is a helper function used within this toolset
757
#
758
#   Arguments:
759
#       $target     Name of the target
760
#
761
#       $lib        Library specification
762
#
763
#       $tag        Tag (user specified)
764
#
765
#       $dp         If building a depend list, the full target name.
766
#
767
###############################################################################
768
 
769
sub ToolsetLibRecipe
770
{
771
    my ($io, $target, $lib, $dp) = @_;
772
 
773
    if ( ! defined($dp) ) {                     # linker
774
        $lib =~ s/^lib//;                       # .. remove leading 'lib'
775
        $io->Cmd( "-l$lib" );
776
 
777
    } else {                                    # depend
778
        $io->Cmd( "$dp:\t@(vlib2,$lib,GCC_LIB)" );
779
 
780
    }
781
}
782
 
783
#.. Successful termination
784
1;
785