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
 
4034 dpurdie 16
our $ScmPlatform;
17
our $ScmNoToolsTest;
18
 
227 dpurdie 19
##############################################################################
20
#   Configuration information
21
#   Cross reference from CrossCompiler Alias to actual paths
22
#   Structure:
23
#   Hash reference: Array of toolchain information
369 dpurdie 24
#       Mandatory
25
#          ROOT             => Root of compiler
26
#          BASE             => Base for binaries
27
#       Optional
28
#          CC_OPTS          => Additonal Compiler options
4034 dpurdie 29
#          CC_OPTSP         => Production Compiler options
30
#          CC_OPTSD         => Debug Compiler options
369 dpurdie 31
#          UNCONTROLLED     => Boolean to create warning
3967 dpurdie 32
#          PACKAGE_ARCH     => Packageing architecture
33
#          VERSION          => Version reported by GCC
34
#          MACHINE          => Machine reported by GCC
4034 dpurdie 35
#          COMPILER_OPTIONS => Toolset specific compiler initial options
36
#                              This is a comma seperated list
369 dpurdie 37
 
227 dpurdie 38
my %ToolsetConfig = (
39
 
369 dpurdie 40
    'i386-unknown-linux-gnu'    => {
41
        ROOT => '/opt/crosstool/gcc-4.1.1-glibc-2.5/i586-unknown-linux-gnu',
42
        BASE => 'bin/i586-unknown-linux-gnu-',
3967 dpurdie 43
       VERSION      => '4.1.1',
44
       MACHINE      => 'i586-unknown-linux-gnu'
369 dpurdie 45
    },
227 dpurdie 46
 
369 dpurdie 47
    'arm-9tdmi-linux-gnu'       => {
48
        ROOT => '/opt/crosstool/gcc-4.1.1-glibc-2.5/arm-9tdmi-linux-gnu',
3967 dpurdie 49
        BASE => 'bin/arm-9tdmi-linux-gnu-',
50
        VERSION      => '4.1.1',
51
        MACHINE      => 'arm-9tdmi-linux-gnu'
369 dpurdie 52
        },
247 dpurdie 53
 
369 dpurdie 54
    'powerpc-603e-linux-gnu'    => {
55
       ROOT => '/opt/crosstool/gcc-4.1.1-glibc-2.5/powerpc-603e-linux-gnu',
3967 dpurdie 56
       BASE => 'bin/powerpc-603e-linux-gnu-',
57
       VERSION      => '4.1.1',
58
       MACHINE      => 'powerpc-603e-linux-gnu'
369 dpurdie 59
    },
337 dpurdie 60
 
369 dpurdie 61
    'arm-926ejs-linux-gnueabi'  => {
62
       ROOT => '/opt/crosstool/gcc-4.4.3-glibc-2.9/arm-926ejs-linux-gnueabi',
63
       BASE => 'bin/arm-926ejs-linux-gnueabi-',
64
       CC_OPTS => '-Wno-psabi',
3967 dpurdie 65
       VERSION      => '4.4.3',
66
       MACHINE      => 'arm-926ejs-linux-gnueabi'
369 dpurdie 67
    },
68
 
3967 dpurdie 69
    'i686-linux-gnu'    => {
70
       ROOT         => '/usr',
71
       BASE         => 'bin/',
72
       PACKAGE_ARCH => 'i386',
73
       VERSION      => '4.6',
74
       MACHINE      => 'i686-linux-gnu'
75
    },
76
 
227 dpurdie 77
    #
78
    #   Old (not to be used) version of the embedded toolchain
4003 dpurdie 79
    #   This was deprecated in favor of gcc-4.1.1-glibc-2.5
227 dpurdie 80
    #   It is not possible to reproduce old packages using the old compiler
81
    #   This is a known issue
82
    #
369 dpurdie 83
    'i386-unknown-linux-gnu.glibc-2.3.2' => {
84
       ROOT => '/opt/crosstool/gcc-4.1.0-glibc-2.3.2/i386-unknown-linux-gnu',
85
       BASE => 'bin/i386-unknown-linux-gnu-'
86
    },
227 dpurdie 87
 
369 dpurdie 88
    'arm-9tdmi-linux-gnu.glibc-2.3.2' => {
89
       ROOT => '/opt/crosstool/gcc-4.1.0-glibc-2.3.2/arm-9tdmi-linux-gnu',
90
       BASE => 'bin/arm-9tdmi-linux-gnu-'
91
    },
227 dpurdie 92
 
93
    #
94
    #   Not too sure where this is used
95
    #
369 dpurdie 96
    'armv4l-unknown-linux-gcc' => {
97
       ROOT => '/opt/host/armv4l',
98
       BASE => 'bin/armv4l-unknown-linux-'
99
    },
227 dpurdie 100
 
101
    #
102
    #   The compiler for the current local machine
103
    #
369 dpurdie 104
    'i386-unknown-linux-gcc' => {
105
       ROOT => '/usr',
106
       BASE => 'bin/',
107
       UNCONTROLLED => 1,
3967 dpurdie 108
       PACKAGE_ARCH => 'i386',
369 dpurdie 109
    },
110
);
227 dpurdie 111
 
112
#
113
#   Cross reference from GCCTarget to GBE_MACHTYPE for which it can
114
#   build using the 'native gcc'. This is NOT the preferred mode of operation
115
#   as the compiler is not as controlled as the cross compilers.
116
#
117
my %NativeCompilers = (
118
    'Linux i386'       => 'linux_i386',
119
    );
120
 
121
##############################################################################
122
#   ToolsetInit()
123
#       Runtime initialisation
124
#
125
##############################################################################
126
 
127
ToolsetInit();
128
 
129
sub ToolsetInit
130
{
4034 dpurdie 131
    my( $GCCTarget, $GCCToolchain, $GCCRoot, $GCCBin, $GCCAr, $GCCObjCopy );
132
    my( $GCCFlags,  $GCCFlagsP, $GCCFlagsD );
3967 dpurdie 133
    my( $PkgArch);
4034 dpurdie 134
    my( $arg_alias, $tools_found, $compiler_tool );
227 dpurdie 135
 
136
#.. Toolset configuration
137
#
138
    $::ScmToolsetVersion = "1.0.0";             # our version
139
    $::ScmToolsetGenerate = 0;                  # GEN generate optional
140
    $::ScmToolsetCompilerPath = 1;              # Exports Compiler path to makefile via SCM_COMPILERPATH
271 dpurdie 141
    $::ScmToolsetProgDependancies = 0;          # handle Prog dependancies myself
339 dpurdie 142
    $::ScmToolsetSoName = 1;                    # Shared library supports SoName
227 dpurdie 143
 
144
#.. Standard.rul requirements
145
#
146
    $::s = "asm";
147
    $::o = "o";
148
    $::so = "so";
149
    $::a = "a";
150
    $::exe = "";
151
 
152
#.. Parse arguments
153
#
154
    foreach $_ ( @::ScmToolsetArgs ) {
155
        if (/^--Target=(.*)/) {                 # OS Version
156
            $GCCTarget = "$1";
157
 
158
        } elsif (/^--CrossAlias=(.*)/) {        # CrossCompiler target-alias
159
            $arg_alias = $1;
160
 
4034 dpurdie 161
        } elsif (/^--CompilerTool=(.*)/) {      # CrossCompiler located in package
162
            $compiler_tool = $1;
163
 
227 dpurdie 164
        } else {
165
            Message( "gcc toolset: unknown option $_ -- ignored\n" );
166
        }
167
    }
168
 
169
    foreach $_ ( @::ScmPlatformArgs ) {
170
        if (/^--product=(.*)/) {                # GBE product
171
 
172
        } else {
173
            Message( "gcc toolset: unknown platform argument $_ -- ignored\n" );
174
        }
175
    }
176
 
177
    Error ("TOOLSET/gcc - Target undefined" )
178
        unless ($GCCTarget);
179
 
4034 dpurdie 180
    #
181
    #   If the toolset is not required, then do not process any futher
182
    #   We may not find the compiler
183
    #
184
    return
185
        if ($ScmNoToolsTest);
186
 
227 dpurdie 187
#.. Cross compile support
4034 dpurdie 188
#   Compiler provided in package, rather than install on machine
227 dpurdie 189
#
4034 dpurdie 190
if ( $compiler_tool  )
191
{
192
    #
193
    #   The GCC toolset will handle a compiler provided within a package
194
    #   Initial requirement was for ANDROID NDKs where the compiler is
195
    #   a part of the NDK and will change.
196
    #
197
    #   Compilers in packages will have a file in gbe/COMPILERS/<compiler_tool>
198
    #   that contains data specifically designed for this toolset
199
    #
200
    Verbose("Locate compiler in package: $compiler_tool");
201
    my @toolList;
202
    my $toolPath;
203
    my $toolPkg;
204
    for my $entry (@{$::ScmBuildPkgRules{$ScmPlatform} })
205
    {
206
        my $tpath = join('/', $entry->{ROOT}, 'gbe', 'COMPILERS' , $compiler_tool);
207
        if ( -f $tpath  )
208
        {
209
            push @toolList, $entry->{NAME};
210
            $toolPath = $tpath;
211
            $toolPkg = $entry;
212
        }
213
    }
214
    Error ("Multiple packages provide required compiler:", @toolList)
215
        if ( scalar(@toolList) > 1 );
216
    Error ("Required compiler not found in any package", "Compiler: $compiler_tool")
217
        unless ( scalar(@toolList) == 1 );
218
 
219
    #
220
    #   Process the compiler info file
221
    #   Rip out the data and create a hash of item/values
222
    #   File format:
223
    #       '#' is a line comment
224
    #       item=value
225
    #
226
    my %data;
227
    open (my $DATA, '<', $toolPath ) || Error("Cannot open compiler datafile. $!", "File: $toolPath");
228
    while ( <$DATA> )
229
    {
230
        $_ =~ s~\s+$~~;
231
        next if ( m~^#~ );
232
        m~(.*?)\s*=\s*(.*)~;
233
        $data{$1} = $2;
234
    }
235
    close $DATA;
236
 
237
    #
238
    #   Force this compilers data into the ToolsetConfig hash
239
    #
240
    $arg_alias = $compiler_tool;
241
    %ToolsetConfig = ();
242
 
243
    $ToolsetConfig{$arg_alias}{ROOT} = join('/', $toolPkg->{ROOT}, $data{ROOT} );
244
    $ToolsetConfig{$arg_alias}{BASE} = $data{BASE} . '-';
245
    $ToolsetConfig{$arg_alias}{CC_OPTS} = $data{CFLAGS};
246
    $ToolsetConfig{$arg_alias}{CC_OPTSP} = $data{CFLAGSP};
247
    $ToolsetConfig{$arg_alias}{CC_OPTSD} = $data{CFLAGSD};
248
    $ToolsetConfig{$arg_alias}{VERSION} = $data{VERSION};
249
    $ToolsetConfig{$arg_alias}{MACHINE} = $data{MACHINE};
250
    $ToolsetConfig{$arg_alias}{COMPILER_OPTIONS} = $data{COMPILER_OPTIONS};
251
}
252
 
253
#.. Cross compile support
254
#
227 dpurdie 255
#   Toolchain=root,[bin]
256
#
257
    if ( $arg_alias )
258
    {
259
        if ( exists $ToolsetConfig{ $arg_alias } )
260
        {
369 dpurdie 261
            $GCCToolchain = $ToolsetConfig{ $arg_alias };
262
            $tools_found = (-d $GCCToolchain->{ROOT});
227 dpurdie 263
            Warning ("gcc toolset: CrossPlatform toolchain not found for: $arg_alias",
369 dpurdie 264
                     "Path: $GCCToolchain->{ROOT}" ) unless $tools_found;
227 dpurdie 265
        }
266
        else
267
        {
268
            Error("gcc toolset: CrossPlatform Alias not configured: $arg_alias");
269
        }
369 dpurdie 270
 
271
        Warning ("Uncontrolled toolchain used: $arg_alias")
272
            if ( exists($GCCToolchain->{UNCONTROLLED}) && $GCCToolchain->{UNCONTROLLED} );
227 dpurdie 273
    }
274
 
275
    #
276
    #   If no Cross compiler toolchain is found (preferred method), then attempt
277
    #   to match a native compiler. Only known targets allow a native build
278
    #
279
    unless ( $tools_found )
280
    {
281
        if ( exists ( $NativeCompilers{$GCCTarget} ))
282
        {
283
            if ( $NativeCompilers{$GCCTarget} eq $::GBE_MACHTYPE )
284
            {
285
                $tools_found = 1;
369 dpurdie 286
                $GCCToolchain = undef;
227 dpurdie 287
            }
288
        }
289
    }
290
 
291
    #
292
    #   Must have a toolset by now, either a cross compiler or Native
293
    #
294
    Error ("gcc toolset: Toolchain not found for: $GCCTarget" )
295
        unless ( $tools_found );
296
 
297
 
369 dpurdie 298
    if ( defined $GCCToolchain )
227 dpurdie 299
    {
300
        #
369 dpurdie 301
        #   Parse GCCToolchain. Potential parts to create
302
        #       GCCRoot     - Location to find the effective /usr/include directory
303
        #       GCCBin      - Path to the gcc executable
304
        #       GCCAr       - Path to the ar executable
4034 dpurdie 305
        #       GCCFlags    - Additional compiler flags. Also Production and Debug
227 dpurdie 306
        #
369 dpurdie 307
        $GCCRoot = $GCCToolchain->{ROOT};
308
        $GCCBin = '${GCC_ROOT}/' . $GCCToolchain->{BASE} . 'gcc';
309
        $GCCAr =  '${GCC_ROOT}/' . $GCCToolchain->{BASE} . 'ar';
373 dpurdie 310
        $GCCObjCopy =  '${GCC_ROOT}/' . $GCCToolchain->{BASE} . 'objcopy';
369 dpurdie 311
        $GCCFlags = $GCCToolchain->{CC_OPTS};
4034 dpurdie 312
        $GCCFlagsP = $GCCToolchain->{CC_OPTSP};
313
        $GCCFlagsD = $GCCToolchain->{CC_OPTSD};
3967 dpurdie 314
        $PkgArch = $GCCToolchain->{PACKAGE_ARCH};
227 dpurdie 315
    }
316
    else
317
    {
373 dpurdie 318
        $GCCRoot = '/usr';
319
        $GCCBin = 'gcc';
320
        $GCCAr = 'ar';
321
        $GCCObjCopy =  'objcopy';
227 dpurdie 322
    }
323
 
324
#.. Define GCC environment
325
#
326
    PlatformDefine( "
327
#################################################
328
# GCC toolchain definitions 
329
#
330
#..");
369 dpurdie 331
    PlatformDefine( "GCC_TARGET         := $GCCTarget" );
332
    PlatformDefine( "GCC_ROOT           := $GCCRoot" );
333
    PlatformDefine( "GCC_CC             := $GCCBin" );
334
    PlatformDefine( "GCC_AR             := $GCCAr" );
373 dpurdie 335
    PlatformDefine( "GCC_OBJCOPY        := $GCCObjCopy" );
369 dpurdie 336
    PlatformDefine( "GCC_CFLAGS         := $GCCFlags" ) if defined $GCCFlags;
4034 dpurdie 337
    PlatformDefine( "GCC_CFLAGSP        := $GCCFlagsP" ) if defined $GCCFlagsP;
338
    PlatformDefine( "GCC_CFLAGSD        := $GCCFlagsD" ) if defined $GCCFlagsD;
369 dpurdie 339
 
227 dpurdie 340
    #
341
    #   Required since this toolset advertises: ScmToolsetCompilerPath
342
    #
369 dpurdie 343
    PlatformDefine( "SCM_COMPILERPATH   := \$\{GCC_CC\}" );
3967 dpurdie 344
 
345
    #
346
    #   Sanity checking
347
    #
348
    PlatformDefine( "GCC_EVERSION       := " . $GCCToolchain->{VERSION} ) if defined $GCCToolchain->{VERSION};
349
    PlatformDefine( "GCC_EMACHINE       := " . $GCCToolchain->{MACHINE} ) if defined $GCCToolchain->{MACHINE};
350
 
351
    #
352
    #   Option indication of packaging architecture
353
    #   Used by non-embedded systems for packaging. See debian_packager
354
    #
355
    PlatformDefine( "PACKAGE_ARCH       := $PkgArch" ) if (defined $PkgArch);
369 dpurdie 356
    PlatformDefine( "" );
227 dpurdie 357
 
358
#.. Piece the world together
359
#
3967 dpurdie 360
    Init( 'gcc' );
227 dpurdie 361
    ToolsetDefines( "gcc.def" );
362
    ToolsetRules( "gcc.rul" );
363
    ToolsetRules( "standard.rul" );
364
 
365
#   Create a standard data structure
366
#   This is a hash of hashes
367
#       The first hash is keyed by CompileOption keyword
368
#       The second hash contains pairs of values to set or remove
369
#
370
    %::ScmToolsetCompilerOptions =
371
    (
372
        #
373
        #   Control the thread model to use
374
        #   This will affect the compiler options and the linker options
375
        #
376
        'staticprogs'        => { 'STATIC_PROGS' , '1' },      # Progams link staticlly
377
        'no_staticprogs'     => { 'STATIC_PROGS' , undef },    # Default
4034 dpurdie 378
        'noversiondll'       => { 'NO_VERSIONED_DLLS', 1 },    # Matches usage elsewhere
227 dpurdie 379
    );
380
 
381
    #
382
    #   Set default options
383
    #
384
    $::ScmCompilerOpts{'STATIC_PROGS'} = undef;
4034 dpurdie 385
    $::ScmCompilerOpts{'NO_VERSIONED_DLLS'} = undef;
386
 
387
    #
388
    #   Process toolset-specfic compiler options
389
    #
390
    if ( exists $GCCToolchain->{COMPILER_OPTIONS} )
391
    {
392
        CompileOptions('*', split(',',$GCCToolchain->{COMPILER_OPTIONS}) );
393
    }
227 dpurdie 394
}
395
 
396
 
397
###############################################################################
398
#   ToolsetCC( $source, $obj, \@args )
399
#       This subroutine takes the user options and builds the rule(s)
400
#       required to compile the source file 'source' to 'obj'
401
#
402
###############################################################################
403
 
404
sub ToolsetCC
405
{
406
    my( $source, $obj, $pArgs ) = @_;
407
    my( $cflags, $file ) = "";
408
 
409
    foreach $_ ( @$pArgs ) {
410
        if (/--Shared$/) {                      # Building a 'shared' object
411
            $cflags  = "$cflags \$(SHCFLAGS)";
412
        } else {
413
            Message( "CC: unknown option $_ -- ignored\n" );
414
        }
415
    }
416
 
417
    MakePrint( "\n\t\$(CC)\n" );
418
    if ( $cflags )
419
    {                                           # object specific CFLAGS
420
        MakePadded( 4, "\$(OBJDIR)/$obj.$::o:" );
421
        MakePrint( "\tCFLAGS +=$cflags\n" );
422
    }
423
 
424
    $file = StripExt( $obj );                   # Metric working file
425
    ToolsetGenerate( "\$(OBJDIR)/$file.met" );
426
}
427
 
428
 
429
###############################################################################
430
#   ToolsetCCDepend( $depend, \@sources )
431
#       This subroutine takes the user options and builds the
432
#       rule(s) required to build the dependencies for the source
433
#       files 'sources' to 'depend'.
434
#
435
###############################################################################
436
 
437
sub ToolsetCCDepend
438
{
439
    MakePrint( "\t\$(CCDEPEND)\n" );
440
}
441
 
442
 
443
###############################################################################
444
#   ToolsetCXX( $source, $obj, \@args )
445
#       This subroutine takes the user options and builds the rule(s)
446
#       required to compile the source file 'source' to 'obj'
447
#
448
###############################################################################
449
 
450
sub ToolsetCXX
451
{
452
    my( $source, $obj, $pArgs ) = @_;
453
    my( $cflags, $file ) = "";
454
 
455
    foreach $_ ( @$pArgs ) {
456
        if (/--Shared$/) {                      # Building a 'shared' object
457
            $cflags  = "$cflags \$(SHCXXFLAGS)";
458
        } else {
459
            Message( "CXX: unknown option $_ -- ignored\n" );
460
        }
461
    }
462
 
463
    MakePrint( "\n\t\$(CXX)\n" );
464
    if ( $cflags )
465
    {                                           # object specific CFLAGS
466
        MakePadded( 4, "\$(OBJDIR)/$obj.$::o:" );
467
        MakePrint( "\tCXXFLAGS +=$cflags\n" );
468
    }
469
 
470
    $file = StripExt( $obj );                   # Metric working file
471
    ToolsetGenerate( "\$(OBJDIR)/$file.met" );
472
}
473
 
474
 
475
###############################################################################
476
#   ToolsetCXXDepend( $depend, \@sources )
477
#       This subroutine takes the user options and builds the
478
#       rule(s) required to build the dependencies for the source
479
#       files 'sources' to 'depend'.
480
#
481
###############################################################################
482
 
483
sub ToolsetCXXDepend
484
{
287 dpurdie 485
    ToolsetCCDepend();
227 dpurdie 486
}
487
 
488
 
489
###############################################################################
490
#   ToolsetAS( $source, $obj, \@args )
491
#       This subroutine takes the user options and builds the rule(s)
492
#       required to compile the source file 'source' to 'obj'
493
#
494
###############################################################################
495
 
496
sub ToolsetAS
497
{
498
    MakePrint( "\n\t\$(AS)\n" );
499
}
500
 
501
sub ToolsetASDepend
502
{
503
}
504
 
505
 
506
###############################################################################
507
#   ToolsetAR( $name, \@args, \@objs )
508
#       This subroutine takes the user options and builds the rules
509
#       required to build the library 'name'.
510
#
511
#   Arguments:
512
#       n/a
513
#
514
#   Output:
515
#       $(BINDIR)/name$.${a}:   .... ]
516
#           $(AR)
517
#
518
#       name_ld += ...  Linker command file
519
#           :
520
#
521
#       name_dp += ...  Dependency list
522
#           :
523
#
524
###############################################################################
525
 
526
sub ToolsetAR
527
{
528
    my( $name, $pArgs, $pObjs ) = @_;
529
 
530
#.. Parse arguments
531
#
532
    foreach $_ ( @$pArgs )
533
    {
534
        Message( "AR: unknown option $_ -- ignored\n" );
535
    }
536
 
537
#.. Target
538
#
539
    MakePrint( "#.. Library ($name)\n\n" );     # label
540
 
541
    MakeEntry( "\$(LIBDIR)/$name\$(GBE_TYPE).$::a:\t",
542
        "", "\\\n\t\t", ".$::o", @$pObjs );
543
 
544
#.. Build library rule (just append to standard rule)
545
#
546
    MakePrint( "\n\t\$(AR)\n\n" );
547
}
548
 
549
 
550
###############################################################################
551
#   ToolsetARMerge( $name, \@args, \@libs )
552
#       This subroutine takes the user options and builds the rules
553
#       required to build the library 'name' by merging the specified
554
#       libaries
555
#
556
#   Arguments:
557
#       --xxx                   No arguments currently defined
558
#
559
#   Output:
560
#       [ $(LIBDIR)/name$.${a}:   .... ]
561
#           ...
562
#
563
###############################################################################
564
 
565
sub ToolsetARMerge
566
{
567
    MakePrint( "\n\t\$(ARMERGE)\n\n" );
568
}
569
 
570
 
571
###############################################################################
289 dpurdie 572
#   ToolsetSHLD( $name, \@args, \@objs, \@libraries, $ver )
227 dpurdie 573
#       This subroutine takes the user options and builds the rules
339 dpurdie 574
#       required to link the Shared Library 'name'.
227 dpurdie 575
#
576
#   Arguments:
577
#   n/a
578
#
579
#   Output:
580
#       $(LIBDIR)/name:     $(LIBDIR)/shared
581
#           ln -s $shared $name
582
#
583
#       $(LIBDIR)/name.dep: $(GBE_OBJDIR)
584
#       $(LIBDIR)/name.dep: $(GBE_LIBDIR)
585
#       $(LIBDIR)/name.dep: $(GBE_PLATFORM).mk
586
#           $(SHLDDEPEND)
587
#
588
#       $(LIBDIR)/shared:   SHNAME=name
589
#       $(LIBDIR)/shared:   SHBASE=base
590
#       $(LIBDIR)/shared:   $(LIBDIR)/name.dep  \
591
#           $(OBJECTS)
592
#                           
593
#       ifneq "$(findstring $(IFLAG),23)" ""
594
#       -include            "$(LIBDIR)/name.dep"
595
#       endif
596
#
597
#       name_ld += ...
598
#           :
599
#
600
###############################################################################
601
 
602
sub ToolsetSHLD
603
{
289 dpurdie 604
    my( $name, $pArgs, $pObjs, $pLibs, $ver ) = @_;
373 dpurdie 605
    my( $linkname, $soname, $shared, $dbgname, $def, $def_pref, $multi_scan );
4034 dpurdie 606
    my $sosuffix;
607
    my $noVersionedLib = $::ScmCompilerOpts{'NO_VERSIONED_DLLS'};
227 dpurdie 608
 
4034 dpurdie 609
 
227 dpurdie 610
#.. Parse arguments
611
#
612
    foreach $_ ( @$pArgs )
613
    {
614
        if (/^--Def=(.*?)(\,(.*))?$/) {         # Library definition
615
            #
616
            #   Locate the Def file.
617
            #   If it is a generate file so it will be in the SRCS hash
618
            #   Otherwise the user will have to use Src to locate the file
619
            #
620
            $def = MakeSrcResolve($1);
621
            $def_pref = '';
622
            if ( $1 =~ m~\.def$~ ) {
623
                $def_pref = '--version-script='; # Old def file
624
            }
625
        } elsif ( /^--MultiScan/i ) {
626
            $multi_scan = 1;
627
 
628
        } elsif ( /^--NoMultiScan/i ) {
629
            $multi_scan = 0;
630
 
339 dpurdie 631
        } elsif ( /^--SoNameSuffix=(.*)/i ) {
632
            $sosuffix = $1;
633
 
4034 dpurdie 634
        } elsif (/^--NoVersionDll/i) {
635
            $noVersionedLib = 1;
636
 
227 dpurdie 637
        } else {
638
            Message( "SHLD: unknown option $_ -- ignored\n" );
639
        }
640
    }
641
 
4034 dpurdie 642
    #
643
    # Determine the 'soname' in none has been provided
644
    #
645
    $sosuffix = '.' . $ver
646
        unless ( defined $sosuffix );
647
    $sosuffix = ''
648
        if ( $noVersionedLib );
649
 
339 dpurdie 650
#.. Various library names
227 dpurdie 651
#
339 dpurdie 652
    $linkname = "$name\$(GBE_TYPE).$::so";
4034 dpurdie 653
    $shared = $noVersionedLib ? $linkname : "$linkname.$ver";
339 dpurdie 654
    $soname = "$linkname$sosuffix";
4034 dpurdie 655
 
373 dpurdie 656
    my $shared_path = "\$(LIBDIR)/${shared}";
657
    my $dbg_path =  $shared_path . '.dbg';
227 dpurdie 658
 
659
#.. Cleanup rules
660
#
661
#   map     Map file
662
#   ln      Link from LIBDIR to BINDIR
663
#
261 dpurdie 664
    ToolsetGenerate( "\$(LIBDIR)/${name}.map" );
665
    ToolsetGenerate( "\$(LIBDIR)/${shared}" );
339 dpurdie 666
    ToolsetGenerate( "\$(BINDIR)/${soname}" );
373 dpurdie 667
    ToolsetGenerate( $dbg_path );
227 dpurdie 668
 
669
#.. Build rules
670
#
671
#   name        Base name
672
#   shared      Library name, includes GBE_TYPE specification
673
#
674
    my ($io) = ToolsetPrinter::New();
335 dpurdie 675
    my $dep = $io->SetShldTarget($shared);
227 dpurdie 676
 
677
    $io->Label( "Shared library", $name );
339 dpurdie 678
    PackageShlibAddFiles( $name, "\$(LIBDIR)/$shared" );
373 dpurdie 679
    PackageShlibAddFiles( $name, $dbg_path );
4034 dpurdie 680
 
227 dpurdie 681
    $io->Prt( "\$(LIBDIR)/${shared}:\tSHBASE=${name}\n" );
339 dpurdie 682
    $io->Prt( "\$(LIBDIR)/${shared}:\tSHNAME=${soname}\n" );
683
    $io->Prt( "\$(LIBDIR)/${shared}: \\\n\t\t${dep}" );
321 dpurdie 684
    $io->Entry( "", "", " \\\n\t\t", ".$::o", @$pObjs );
227 dpurdie 685
    $io->Prt( "\\\n\t\t$def" ) if($def);
373 dpurdie 686
    $io->Prt( "\n\t\$(SHLD)" );
687
    $io->Prt( "\n\t\$(call LDSTRIP,$shared_path,$dbg_path)\n\n" );
321 dpurdie 688
 
339 dpurdie 689
#
690
#   Create soft links
691
#       'Real Name' to its 'Link Name'
692
#       'Real Name' to 'SoName' in the BINDIR (for testing I think)
693
#       'Real Name' to 'SoName' in the LIBDIR (if different)
694
#
4034 dpurdie 695
    if ( $shared ne $linkname)
696
    {
697
        $io->Label( "Shared library Symbolic Links", $name );
698
        PackageShlibAddFiles( $name, "\$(LIBDIR)/$linkname" );
699
        $io->Prt( "\$(LIBDIR)/$linkname:\t\\\n" .
700
                  "\t\t\$(GBE_BINDIR)\\\n" .
701
                  "\t\t\$(LIBDIR)/${shared}\n" .
702
                  "\t\$(AA_PRE)(rm -f \$@; ln -s ./$shared \$@)\n\n" );
703
    }
704
 
705
    $io->Label( "Shared library BINDIR Symbolic Links", $name );
706
    PackageShlibAddFiles( $name, "\$(BINDIR)/$soname" );
707
    $io->Prt( "\$(BINDIR)/$soname:\t\\\n" .
339 dpurdie 708
              "\t\t\$(GBE_BINDIR)\\\n" .
709
              "\t\t\$(LIBDIR)/${shared}\n" .
4034 dpurdie 710
              "\t\$(AA_PRE)(rm -f \$@; ln -s ../\$(LIBDIR)/$shared \$@)\n\n" );
339 dpurdie 711
 
4034 dpurdie 712
    if ( $soname ne $shared )
339 dpurdie 713
    {
714
        $io->Label( "Shared library SoName Symbolic Links", $name );
715
        PackageShlibAddFiles( $name, "\$(LIBDIR)/$soname" );
716
        $io->Prt( "\$(LIBDIR)/$soname:\t\\\n" .
717
                  "\t\t\$(GBE_LIBDIR)\\\n" .
718
                  "\t\t\$(LIBDIR)/${shared}\n" .
719
                  "\t\$(AA_PRE)(rm -f \$@; ln -s ./$shared \$@)\n" );
720
    }
721
 
227 dpurdie 722
#.. Linker command file
723
#
724
#       Now the fun part... piecing together a variable $(name_shld)
725
#       which ends up in the command file.
726
#
339 dpurdie 727
    $io->Newline();
227 dpurdie 728
    $io->SetTag( "${name}_shld" );              # command tag
729
    $io->SetTerm( "\n" );
730
 
731
    $io->Label( "Linker commands", $name );     # label
732
 
733
                                                # object list
734
    $io->ObjList( $name, $pObjs, \&ToolsetObjRecipe );
735
 
736
    ToolsetLibStd( $pLibs );                    # push standard libraries
737
 
738
    $io->Cmd( "-Wl,$def_pref$def" ) if ($def);
739
 
740
    $io->Cmd( "-Wl,--start-group" ) if ($multi_scan);
741
    $io->LibList( $name, $pLibs, \&ToolsetLibRecipe );
742
    $io->Cmd( "-Wl,--end-group" ) if ($multi_scan);
743
 
744
    $io->Newline();
745
 
335 dpurdie 746
    #.. Dependency link,
747
    #   Create a library dependency file
748
    #       Create command file to build applicaton dependency list
749
    #       from the list of dependent libraries
750
    #
751
    #       Create makefile directives to include the dependency
752
    #       list into the makefile.
753
    #
754
    $io->DepRules( $pLibs, \&ToolsetLibRecipe, "\$(LIBDIR)/${shared}" );
339 dpurdie 755
    $io->SHLDDEPEND($name, $soname);
227 dpurdie 756
}
757
 
758
 
759
###############################################################################
271 dpurdie 760
# Function        : ToolsetLD
227 dpurdie 761
#
271 dpurdie 762
# Description     : Takes the user options and builds the rules required to
763
#                   link the program 'name'.
227 dpurdie 764
#
271 dpurdie 765
# Inputs          : $name           - base name of the program
766
#                   $pArgs          - Ref to program arguments
767
#                   $pObjs          - Ref to program objects
768
#                   $pLibs          - Ref to program library list
227 dpurdie 769
#
271 dpurdie 770
# Returns         : Nothing
227 dpurdie 771
#
271 dpurdie 772
# Output:         : Rules and recipes to create a program
773
#                       Create program rules and recipes
774
#                       Create linker input script
775
#                       Create library dependency list
776
#                       Include library dependency information
227 dpurdie 777
#
778
sub ToolsetLD
779
{
780
    my( $name, $pArgs, $pObjs, $pLibs ) = @_;
781
    my $static = $::ScmCompilerOpts{'STATIC_PROGS'};
782
    my $multi_scan;
783
 
784
#.. Parse arguments
785
#
786
    foreach $_ ( @$pArgs )
787
    {
788
        if ( m/^--Static$/ ) {
789
            $static = 1;
790
 
791
        } elsif ( m/^--Shared/ ) {
792
            $static = 0;
793
 
794
        } elsif ( /^--MultiScan/i ) {
795
            $multi_scan = 1;
796
 
797
        } elsif ( /^--NoMultiScan/i ) {
798
            $multi_scan = 0;
799
 
800
        } else {
801
            Message( "LD: unknown option $_ -- ignored\n" );
802
        }
803
    }
804
 
271 dpurdie 805
#.. Names of programs and components
806
#
807
    my $base = "\$(BINDIR)/${name}";
808
    my $full = $base . $::exe;
809
    my $map  = $base . '.map';
810
    my $ld  =  $base . '.ld';
373 dpurdie 811
    my $dbg =  $base . '.dbg';
271 dpurdie 812
 
227 dpurdie 813
#.. Cleanup rules
814
#
271 dpurdie 815
    ToolsetGenerate( $ld );
816
    ToolsetGenerate( $map );
373 dpurdie 817
    ToolsetGenerate( $dbg );
227 dpurdie 818
 
819
#.. Build rules
820
#
821
    my ($io) = ToolsetPrinter::New();
335 dpurdie 822
    my $dep = $io->SetLdTarget( $name );
227 dpurdie 823
 
271 dpurdie 824
    $io->Prt( "$full : $dep " );
825
    $io->Entry( "", "", "\\\n\t", ".$::o ", @$pObjs );
373 dpurdie 826
    $io->Prt( "\n\t\$(LD)" );
827
    $io->Prt( "\n\t\$(call LDSTRIP,$full,$dbg)\n\n" );
227 dpurdie 828
 
271 dpurdie 829
 
227 dpurdie 830
#.. Linker command file
831
#
832
#       Now the fun part... piecing together a variable $(name_ld)
833
#       which ends up in the command file.
834
#
835
    $io->SetTag( "${name}_ld" );                # macro tag
836
    $io->SetTerm( "\n" );
837
 
838
    $io->Label( "Linker commands", $name );     # label
839
 
840
    $io->Cmd( "-static" ) if ($static);         # Link as a static program
841
 
842
                                                # object list
843
    $io->ObjList( $name, $pObjs, \&ToolsetObjRecipe );
844
 
845
    ToolsetLibStd( $pLibs );                    # push standard libraries
846
 
847
                                                # library list
848
    $io->Cmd( "-Wl,--start-group" ) if ($multi_scan);
849
    $io->LibList( $name, $pLibs, \&ToolsetLibRecipe );
850
    $io->Cmd( "-Wl,--end-group" ) if ($multi_scan);
851
 
852
    $io->Newline();
853
 
335 dpurdie 854
    #.. Dependency link,
855
    #   Create a library dependency file
856
    #       Create command file to build applicaton dependency list
857
    #       from the list of dependent libraries
858
    #
859
    #       Create makefile directives to include the dependency
860
    #       list into the makefile.
861
    #
862
    $io->DepRules( $pLibs, \&ToolsetLibRecipe, $base );
863
    $io->LDDEPEND();
271 dpurdie 864
 
865
#.. Package up the program and other artifacts
866
#
867
    PackageProgAddFiles ( $name, $full );
373 dpurdie 868
    PackageProgAddFiles ( $name, $dbg );
271 dpurdie 869
 
227 dpurdie 870
}
871
 
872
 
873
########################################################################
874
#
875
#   Push standard "system" libraries. This is a helper function
876
#   used within this toolset.
877
#
878
#   Arguments:
879
#       $plib       Reference to library array.
880
#
881
########################################################################
882
 
883
sub ToolsetLibStd
884
{
885
}
886
 
887
 
888
########################################################################
889
#
890
#   Generate a linker object recipe.  This is a helper function used 
891
#   within this toolset.
892
#
893
#   Arguments:
894
#       $io         I/O stream
895
#
896
#       $target     Name of the target
897
#
898
#       $obj        Library specification
899
#
900
########################################################################
901
 
902
sub ToolsetObjRecipe
903
{
904
    my ($io, $target, $obj) = @_;
905
 
906
    $io->Cmd( "\$(strip $obj).$::o" );
907
}
908
 
909
 
910
###############################################################################
911
#
912
#   Parse a linker lib list
913
#   This is a helper function used within this toolset
914
#
915
#   Arguments:
916
#       $target     Name of the target
917
#
918
#       $lib        Library specification
919
#
920
#       $tag        Tag (user specified)
921
#
922
#       $dp         If building a depend list, the full target name.
923
#
924
###############################################################################
925
 
926
sub ToolsetLibRecipe
927
{
928
    my ($io, $target, $lib, $dp) = @_;
929
 
930
    if ( ! defined($dp) ) {                     # linker
931
        $lib =~ s/^lib//;                       # .. remove leading 'lib'
932
        $io->Cmd( "-l$lib" );
933
 
934
    } else {                                    # depend
935
        $io->Cmd( "$dp:\t@(vlib2,$lib,GCC_LIB)" );
936
 
937
    }
938
}
939
 
940
#.. Successful termination
941
1;
942