Subversion Repositories DevTools

Rev

Rev 7322 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7307 dpurdie 1
########################################################################
2
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
227 dpurdie 3
#
7307 dpurdie 4
# Module name   : GCC.PL
5
# Module type   : JATS Utility
6
# Compiler(s)   : Perl
7
# Environment(s): jats
227 dpurdie 8
#
7307 dpurdie 9
# Description   : GCC C/C++ toolset
227 dpurdie 10
#
7307 dpurdie 11
#......................................................................#
227 dpurdie 12
 
13
use strict;
14
use warnings;
15
 
4728 dpurdie 16
# Global variables
4034 dpurdie 17
our $ScmPlatform;
18
our $ScmNoToolsTest;
19
 
4728 dpurdie 20
#   Misc variables
21
my $UseGcov = 0;
7323 dpurdie 22
my $UseProfile = 0;
4835 dpurdie 23
my $LcovExplicitBranch = '';
4728 dpurdie 24
my $UseCppcheck = 0;
5744 dpurdie 25
my $GCCRPath;
7307 dpurdie 26
my @ldFixups;
4728 dpurdie 27
 
227 dpurdie 28
##############################################################################
29
#   Configuration information
30
#   Cross reference from CrossCompiler Alias to actual paths
31
#   Structure:
32
#   Hash reference: Array of toolchain information
369 dpurdie 33
#       Mandatory
34
#          ROOT             => Root of compiler
35
#          BASE             => Base for binaries
36
#       Optional
37
#          CC_OPTS          => Additonal Compiler options
4034 dpurdie 38
#          CC_OPTSP         => Production Compiler options
39
#          CC_OPTSD         => Debug Compiler options
5744 dpurdie 40
#          CXX_OPTS         => Additional C++ Options
7322 dpurdie 41
#          LDFLAGS          => Linker flags
369 dpurdie 42
#          UNCONTROLLED     => Boolean to create warning
7322 dpurdie 43
#          DEPRECATED       => Boolean to create warning
44
#          DISCONTINUED     => Boolean to create error and not build anything
3967 dpurdie 45
#          PACKAGE_ARCH     => Packageing architecture
46
#          VERSION          => Version reported by GCC
47
#          MACHINE          => Machine reported by GCC
5796 dpurdie 48
#          RPATH            => Relative Path to compiler installed runtime
49
#                              Absolute or Relative
4034 dpurdie 50
#          COMPILER_OPTIONS => Toolset specific compiler initial options
51
#                              This is a comma seperated list
227 dpurdie 52
my %ToolsetConfig = (
53
 
369 dpurdie 54
    'i386-unknown-linux-gnu'    => {
5708 dpurdie 55
        ROOT        => '/opt/crosstool/gcc-4.1.1-glibc-2.5/i586-unknown-linux-gnu',
56
        BASE        => 'bin/i586-unknown-linux-gnu-',
3967 dpurdie 57
       VERSION      => '4.1.1',
58
       MACHINE      => 'i586-unknown-linux-gnu'
369 dpurdie 59
    },
227 dpurdie 60
 
369 dpurdie 61
    'arm-9tdmi-linux-gnu'       => {
5708 dpurdie 62
        ROOT        => '/opt/crosstool/gcc-4.1.1-glibc-2.5/arm-9tdmi-linux-gnu',
63
        BASE        => 'bin/arm-9tdmi-linux-gnu-',
64
        VERSION     => '4.1.1',
65
        MACHINE     => 'arm-9tdmi-linux-gnu'
369 dpurdie 66
        },
247 dpurdie 67
 
369 dpurdie 68
    'powerpc-603e-linux-gnu'    => {
5708 dpurdie 69
       ROOT         => '/opt/crosstool/gcc-4.1.1-glibc-2.5/powerpc-603e-linux-gnu',
70
       BASE         => 'bin/powerpc-603e-linux-gnu-',
3967 dpurdie 71
       VERSION      => '4.1.1',
72
       MACHINE      => 'powerpc-603e-linux-gnu'
369 dpurdie 73
    },
337 dpurdie 74
 
369 dpurdie 75
    'arm-926ejs-linux-gnueabi'  => {
5708 dpurdie 76
       ROOT         => '/opt/crosstool/gcc-4.4.3-glibc-2.9/arm-926ejs-linux-gnueabi',
77
       BASE         => 'bin/arm-926ejs-linux-gnueabi-',
78
       CC_OPTS      => '-Wno-psabi',
3967 dpurdie 79
       VERSION      => '4.4.3',
80
       MACHINE      => 'arm-926ejs-linux-gnueabi'
369 dpurdie 81
    },
82
 
5708 dpurdie 83
    'arm-926ejs-linux-gnueabi-v2'  => {
84
       ROOT         => '/opt/crosstool/gcc-5.2.0-glibc-2.17/arm-926ejs-linux-gnueabi',
85
       BASE         => 'bin/arm-926ejs-linux-gnueabi-',
86
       CC_OPTS      => '-Wno-psabi',
5736 dpurdie 87
       CXX_OPTS     => '-std=gnu++11',
5708 dpurdie 88
       VERSION      => '5.2.0',
89
       MACHINE      => 'arm-926ejs-linux-gnueabi'
90
    },
91
 
92
    'powerpc-603e-linux-gnu-v2'  => {
93
       ROOT         => '/opt/crosstool/gcc-5.2.0-glibc-2.17/powerpc-603e-linux-gnu',
94
       BASE         => 'bin/powerpc-603e-linux-gnu-',
5736 dpurdie 95
       CXX_OPTS     => '-std=gnu++11',
5708 dpurdie 96
       VERSION      => '5.2.0',
97
       MACHINE      => 'powerpc-603e-linux-gnu'
98
    },
99
 
3967 dpurdie 100
    'i686-linux-gnu'    => {
101
       ROOT         => '/usr',
102
       BASE         => 'bin/',
103
       PACKAGE_ARCH => 'i386',
104
       VERSION      => '4.6',
105
       MACHINE      => 'i686-linux-gnu'
106
    },
107
 
5716 dpurdie 108
    'i686-vix_ubuntu12_c11-linux-gnu'    => {
109
       ROOT         => '/opt/crosstool/gcc-5.2.0-glibc-2.17/i686-vix_ubuntu12_c11-linux-gnu',
110
       BASE         => 'bin/i686-vix_ubuntu12_c11-linux-gnu-',
111
       PACKAGE_ARCH => 'i386',
5736 dpurdie 112
       CXX_OPTS     => '-std=gnu++11',
5716 dpurdie 113
       VERSION      => '5.2.0',
5744 dpurdie 114
       MACHINE      => 'i686-vix_ubuntu12_c11-linux-gnu',
5796 dpurdie 115
       RPATH        => '/lib/i686-vix_ubuntu12_c11-linux-gnu',
5716 dpurdie 116
    },
117
 
4109 dpurdie 118
    'arm-iwmmxt-linux-gnueabi'  => {
5708 dpurdie 119
       ROOT         => '/opt/marvel',
120
       BASE         => 'bin/arm-iwmmxt-linux-gnueabi-',
4109 dpurdie 121
       VERSION      => '4.2.4',
122
       MACHINE      => 'arm-iwmmxt-linux-gnueabi'
123
    },
124
 
5619 dpurdie 125
    'arm-unknown-linux-gnueabi-sk20-4.1.1.0'  => {
5708 dpurdie 126
       ROOT         => '/opt/arm-unknown-linux-gnueabi-sk20-4.1.1.0',
127
       BASE         => 'bin/arm-unknown-linux-gnueabi-',
5330 dpurdie 128
       VERSION      => '4.8.2',
129
       MACHINE      => 'arm-unknown-linux-gnueabi'
130
    },
131
 
7307 dpurdie 132
    'gmx-sdk-imx6-toolchain-5.0.0.0'  => {
133
       ROOT         => '/opt/gmx-sdk-imx6-toolchain-5.0.0.0',
134
       BASE         => 'bin/arm-unknown-linux-gnueabi-',
135
       VERSION      => '4.9.1',
136
       MACHINE      => 'arm-unknown-linux-gnueabi',
137
       COMPILER_OPTIONS =>  'pic,brokenldscripts',
138
    },
139
 
7320 dpurdie 140
    # Ubuntu14
4814 dpurdie 141
    'x86_64-linux-gnu'    => {
142
       ROOT         => '/usr',
143
       BASE         => 'bin/',
144
       PACKAGE_ARCH => 'amd64',
7320 dpurdie 145
       CXX_OPTS     => '-std=gnu++11',
4814 dpurdie 146
       VERSION      => '4.8',
4928 dpurdie 147
       MACHINE      => 'x86_64-linux-gnu',
5115 dpurdie 148
       COMPILER_OPTIONS =>  'pic'               # Always create PIC
4814 dpurdie 149
    },
4109 dpurdie 150
 
7320 dpurdie 151
    # Ubuntu16
6133 dpurdie 152
    'x86_64-linux-gnu-5.4'    => {
153
       ROOT         => '/usr',
154
       BASE         => 'bin/',
155
       PACKAGE_ARCH => 'amd64',
7320 dpurdie 156
       CXX_OPTS     => '-std=gnu++11',
6133 dpurdie 157
       VERSION      => '5.4.0',
158
       MACHINE      => 'x86_64-linux-gnu',
159
       COMPILER_OPTIONS =>  'pic'               # Always create PIC
160
    },
161
 
162
    'x86_64-redhat-linux-4.8.5' => {
163
        ROOT         => '/usr',
164
        BASE         => 'bin/',
7304 dpurdie 165
        PACKAGE_ARCH => 'x86_64',
7320 dpurdie 166
        CXX_OPTS     => '-std=gnu++11',
6133 dpurdie 167
        VERSION      => '4.8.5',
168
        MACHINE      => 'x86_64-redhat-linux',
169
        COMPILER_OPTIONS =>  'pic'               # Always create PIC
170
        },
171
 
7323 dpurdie 172
    # STIB Parkeon
173
    'arm-linux-gnueabi-4.6.3' => {
174
        ROOT         => '/opt/parkeon-arm-linux-gnueabi-4.6',
175
        BASE         => 'bin/arm-linux-gnueabi-',
176
        PACKAGE_ARCH => 'armel',
177
        #CXX_OPTS     => '',
178
        VERSION      => '4.6.3',
179
        MACHINE      => 'arm-linux-gnueabi',
180
        COMPILER_OPTIONS =>  'pic'               # Always create PIC
181
        },
182
 
183
 
227 dpurdie 184
    #
185
    #   Old (not to be used) version of the embedded toolchain
4003 dpurdie 186
    #   This was deprecated in favor of gcc-4.1.1-glibc-2.5
227 dpurdie 187
    #   It is not possible to reproduce old packages using the old compiler
188
    #   This is a known issue
189
    #
369 dpurdie 190
    'i386-unknown-linux-gnu.glibc-2.3.2' => {
5708 dpurdie 191
       ROOT         => '/opt/crosstool/gcc-4.1.0-glibc-2.3.2/i386-unknown-linux-gnu',
192
       BASE         => 'bin/i386-unknown-linux-gnu-'
369 dpurdie 193
    },
227 dpurdie 194
 
369 dpurdie 195
    'arm-9tdmi-linux-gnu.glibc-2.3.2' => {
5708 dpurdie 196
       ROOT         => '/opt/crosstool/gcc-4.1.0-glibc-2.3.2/arm-9tdmi-linux-gnu',
197
       BASE         => 'bin/arm-9tdmi-linux-gnu-'
369 dpurdie 198
    },
227 dpurdie 199
 
200
    #
201
    #   Not too sure where this is used
202
    #
369 dpurdie 203
    'armv4l-unknown-linux-gcc' => {
5708 dpurdie 204
       ROOT         => '/opt/host/armv4l',
205
       BASE         => 'bin/armv4l-unknown-linux-'
369 dpurdie 206
    },
227 dpurdie 207
 
208
    #
209
    #   The compiler for the current local machine
210
    #
369 dpurdie 211
    'i386-unknown-linux-gcc' => {
5708 dpurdie 212
       ROOT         => '/usr',
213
       BASE         => 'bin/',
369 dpurdie 214
       UNCONTROLLED => 1,
3967 dpurdie 215
       PACKAGE_ARCH => 'i386',
369 dpurdie 216
    },
217
);
227 dpurdie 218
 
219
#
220
#   Cross reference from GCCTarget to GBE_MACHTYPE for which it can
221
#   build using the 'native gcc'. This is NOT the preferred mode of operation
222
#   as the compiler is not as controlled as the cross compilers.
223
#
224
my %NativeCompilers = (
225
    'Linux i386'       => 'linux_i386',
226
    );
227
 
228
##############################################################################
229
#   ToolsetInit()
230
#       Runtime initialisation
231
#
232
##############################################################################
233
 
234
ToolsetInit();
235
 
236
sub ToolsetInit
237
{
5731 dpurdie 238
    my( $GCCTarget, $GCCToolchain, $GCCRoot, $GCCBin, $GCCAr, $GCCObjCopy, $GCCGcovTool );
4728 dpurdie 239
    my( $GCCFlags,  $GCCFlagsP, $GCCFlagsD, $LDFlags );
5726 dpurdie 240
    my( $GCCXXFlags );
3967 dpurdie 241
    my( $PkgArch);
4034 dpurdie 242
    my( $arg_alias, $tools_found, $compiler_tool );
227 dpurdie 243
 
244
#.. Toolset configuration
7323 dpurdie 245
#   Also $::ScmToolsetProperties{}
227 dpurdie 246
#
247
    $::ScmToolsetVersion = "1.0.0";             # our version
248
    $::ScmToolsetGenerate = 0;                  # GEN generate optional
249
    $::ScmToolsetCompilerPath = 1;              # Exports Compiler path to makefile via SCM_COMPILERPATH
271 dpurdie 250
    $::ScmToolsetProgDependancies = 0;          # handle Prog dependancies myself
339 dpurdie 251
    $::ScmToolsetSoName = 1;                    # Shared library supports SoName
227 dpurdie 252
 
253
#.. Standard.rul requirements
254
#
255
    $::s = "asm";
256
    $::o = "o";
257
    $::so = "so";
258
    $::a = "a";
259
    $::exe = "";
260
 
261
#.. Parse arguments
262
#
263
    foreach $_ ( @::ScmToolsetArgs ) {
264
        if (/^--Target=(.*)/) {                 # OS Version
265
            $GCCTarget = "$1";
266
 
267
        } elsif (/^--CrossAlias=(.*)/) {        # CrossCompiler target-alias
268
            $arg_alias = $1;
269
 
4728 dpurdie 270
        } elsif (/^--UseGcov/) {                # Compile for code coverage
271
            $UseGcov = 1;
272
 
7323 dpurdie 273
        } elsif (/^--UseProfile/) {             # Compile for profiling
274
            $UseProfile = 1;
275
 
4835 dpurdie 276
        } elsif (/^--LcovExplicitBranch/) {     # Version of lcov requires explicit branch coverage
277
            $LcovExplicitBranch = ' --rc lcov_branch_coverage=1';
278
 
4728 dpurdie 279
        } elsif (/^--UseCppcheck/) {            # Use cppcheck as the lint tool
280
            $UseCppcheck = 1;
281
 
4034 dpurdie 282
        } elsif (/^--CompilerTool=(.*)/) {      # CrossCompiler located in package
283
            $compiler_tool = $1;
284
 
227 dpurdie 285
        } else {
286
            Message( "gcc toolset: unknown option $_ -- ignored\n" );
287
        }
288
    }
289
 
290
    foreach $_ ( @::ScmPlatformArgs ) {
291
        if (/^--product=(.*)/) {                # GBE product
292
 
293
        } else {
294
            Message( "gcc toolset: unknown platform argument $_ -- ignored\n" );
295
        }
296
    }
297
 
298
    Error ("TOOLSET/gcc - Target undefined" )
299
        unless ($GCCTarget);
300
 
4034 dpurdie 301
    #
302
    #   If the toolset is not required, then do not process any futher
303
    #   We may not find the compiler
304
    #
305
    return
306
        if ($ScmNoToolsTest);
307
 
227 dpurdie 308
#.. Cross compile support
4034 dpurdie 309
#   Compiler provided in package, rather than install on machine
227 dpurdie 310
#
4034 dpurdie 311
if ( $compiler_tool  )
312
{
313
    #
314
    #   The GCC toolset will handle a compiler provided within a package
315
    #   Initial requirement was for ANDROID NDKs where the compiler is
316
    #   a part of the NDK and will change.
317
    #
318
    #   Compilers in packages will have a file in gbe/COMPILERS/<compiler_tool>
319
    #   that contains data specifically designed for this toolset
320
    #
321
    Verbose("Locate compiler in package: $compiler_tool");
322
    my @toolList;
323
    my $toolPath;
324
    my $toolPkg;
325
    for my $entry (@{$::ScmBuildPkgRules{$ScmPlatform} })
326
    {
327
        my $tpath = join('/', $entry->{ROOT}, 'gbe', 'COMPILERS' , $compiler_tool);
328
        if ( -f $tpath  )
329
        {
330
            push @toolList, $entry->{NAME};
331
            $toolPath = $tpath;
332
            $toolPkg = $entry;
333
        }
334
    }
335
    Error ("Multiple packages provide required compiler:", @toolList)
336
        if ( scalar(@toolList) > 1 );
337
    Error ("Required compiler not found in any package", "Compiler: $compiler_tool")
338
        unless ( scalar(@toolList) == 1 );
339
 
340
    #
341
    #   Process the compiler info file
342
    #   Rip out the data and create a hash of item/values
343
    #   File format:
344
    #       '#' is a line comment
345
    #       item=value
346
    #
347
    my %data;
348
    open (my $DATA, '<', $toolPath ) || Error("Cannot open compiler datafile. $!", "File: $toolPath");
349
    while ( <$DATA> )
350
    {
351
        $_ =~ s~\s+$~~;
352
        next if ( m~^#~ );
353
        m~(.*?)\s*=\s*(.*)~;
354
        $data{$1} = $2;
355
    }
356
    close $DATA;
357
 
358
    #
359
    #   Force this compilers data into the ToolsetConfig hash
360
    #
361
    $arg_alias = $compiler_tool;
362
    %ToolsetConfig = ();
363
 
364
    $ToolsetConfig{$arg_alias}{ROOT} = join('/', $toolPkg->{ROOT}, $data{ROOT} );
365
    $ToolsetConfig{$arg_alias}{BASE} = $data{BASE} . '-';
366
    $ToolsetConfig{$arg_alias}{CC_OPTS} = $data{CFLAGS};
367
    $ToolsetConfig{$arg_alias}{CC_OPTSP} = $data{CFLAGSP};
368
    $ToolsetConfig{$arg_alias}{CC_OPTSD} = $data{CFLAGSD};
5726 dpurdie 369
    $ToolsetConfig{$arg_alias}{CXX_OPTS} = $data{CXXFLAGS};
7322 dpurdie 370
    $ToolsetConfig{$arg_alias}{LDFLAGS} = $data{LDFLAGS};
4034 dpurdie 371
    $ToolsetConfig{$arg_alias}{VERSION} = $data{VERSION};
372
    $ToolsetConfig{$arg_alias}{MACHINE} = $data{MACHINE};
373
    $ToolsetConfig{$arg_alias}{COMPILER_OPTIONS} = $data{COMPILER_OPTIONS};
5744 dpurdie 374
    $ToolsetConfig{$arg_alias}{RAPTH} = $data{RPATH};
7322 dpurdie 375
    $ToolsetConfig{$arg_alias}{DEPRECATED} = $data{DEPRECATED};
376
    $ToolsetConfig{$arg_alias}{DISCONTINUED} = $data{DISCONTINUED};
4034 dpurdie 377
}
378
 
379
#.. Cross compile support
380
#
227 dpurdie 381
#   Toolchain=root,[bin]
382
#
383
    if ( $arg_alias )
384
    {
385
        if ( exists $ToolsetConfig{ $arg_alias } )
386
        {
369 dpurdie 387
            $GCCToolchain = $ToolsetConfig{ $arg_alias };
5330 dpurdie 388
            my $testCompilerPath = $GCCToolchain->{ROOT} . '/' . $GCCToolchain->{BASE} . 'gcc';
389
            $tools_found = (-d $GCCToolchain->{ROOT}) && ( -f $testCompilerPath);
227 dpurdie 390
            Warning ("gcc toolset: CrossPlatform toolchain not found for: $arg_alias",
5708 dpurdie 391
                     "Path    : $GCCToolchain->{ROOT}" ,
392
                     "Compiler: $testCompilerPath " 
5330 dpurdie 393
                      ) unless $tools_found;
227 dpurdie 394
        }
395
        else
396
        {
397
            Error("gcc toolset: CrossPlatform Alias not configured: $arg_alias");
398
        }
369 dpurdie 399
 
400
        Warning ("Uncontrolled toolchain used: $arg_alias")
401
            if ( exists($GCCToolchain->{UNCONTROLLED}) && $GCCToolchain->{UNCONTROLLED} );
7322 dpurdie 402
 
403
        Warning ("Deprecated toolchain used: $arg_alias")
404
            if ( exists($GCCToolchain->{DEPRECATED}) && $GCCToolchain->{DEPRECATED} );
405
 
406
        Error ("Discontinued toolchain used: $arg_alias")
407
            if ( exists($GCCToolchain->{DISCONTINUED}) && $GCCToolchain->{DISCONTINUED} );
227 dpurdie 408
    }
409
 
410
    #
411
    #   If no Cross compiler toolchain is found (preferred method), then attempt
412
    #   to match a native compiler. Only known targets allow a native build
413
    #
414
    unless ( $tools_found )
415
    {
416
        if ( exists ( $NativeCompilers{$GCCTarget} ))
417
        {
418
            if ( $NativeCompilers{$GCCTarget} eq $::GBE_MACHTYPE )
419
            {
420
                $tools_found = 1;
369 dpurdie 421
                $GCCToolchain = undef;
227 dpurdie 422
            }
423
        }
424
    }
425
 
426
    #
427
    #   Must have a toolset by now, either a cross compiler or Native
428
    #
429
    Error ("gcc toolset: Toolchain not found for: $GCCTarget" )
430
        unless ( $tools_found );
431
 
432
 
369 dpurdie 433
    if ( defined $GCCToolchain )
227 dpurdie 434
    {
435
        #
369 dpurdie 436
        #   Parse GCCToolchain. Potential parts to create
437
        #       GCCRoot     - Location to find the effective /usr/include directory
438
        #       GCCBin      - Path to the gcc executable
439
        #       GCCAr       - Path to the ar executable
4034 dpurdie 440
        #       GCCFlags    - Additional compiler flags. Also Production and Debug
227 dpurdie 441
        #
369 dpurdie 442
        $GCCRoot = $GCCToolchain->{ROOT};
443
        $GCCBin = '${GCC_ROOT}/' . $GCCToolchain->{BASE} . 'gcc';
444
        $GCCAr =  '${GCC_ROOT}/' . $GCCToolchain->{BASE} . 'ar';
5731 dpurdie 445
        $GCCGcovTool = '${GCC_ROOT}/' . $GCCToolchain->{BASE} . 'gcov';
373 dpurdie 446
        $GCCObjCopy =  '${GCC_ROOT}/' . $GCCToolchain->{BASE} . 'objcopy';
5796 dpurdie 447
        if (exists $GCCToolchain->{RPATH}) {
448
            if( $GCCToolchain->{RPATH} =~ m~^/~ ) {
449
                $GCCRPath = $GCCToolchain->{RPATH}; 
450
            } else {
451
                $GCCRPath = '${GCC_ROOT}/' . $GCCToolchain->{RPATH};
452
            }
453
        }
369 dpurdie 454
        $GCCFlags = $GCCToolchain->{CC_OPTS};
4034 dpurdie 455
        $GCCFlagsP = $GCCToolchain->{CC_OPTSP};
456
        $GCCFlagsD = $GCCToolchain->{CC_OPTSD};
5726 dpurdie 457
        $GCCXXFlags = $GCCToolchain->{CXX_OPTS};
7322 dpurdie 458
        $LDFlags = $GCCToolchain->{LDFLAGS} if defined($GCCToolchain->{LDFLAGS});
3967 dpurdie 459
        $PkgArch = $GCCToolchain->{PACKAGE_ARCH};
7304 dpurdie 460
        SetGlobalOption('PACKAGE_ARCH', $PkgArch) if defined $PkgArch;
227 dpurdie 461
    }
462
    else
463
    {
373 dpurdie 464
        $GCCRoot = '/usr';
465
        $GCCBin = 'gcc';
466
        $GCCAr = 'ar';
467
        $GCCObjCopy =  'objcopy';
227 dpurdie 468
    }
4728 dpurdie 469
 
470
    #
471
    #   When running under gcov we need to instruct GCC to perform code coverage
472
    #   generation in both C flags and LD flags
473
    #
474
    if ( $UseGcov )
475
    {
476
        $GCCFlags .= ' -coverage';
477
        $LDFlags  .= ' -coverage';
478
    }
479
 
480
    #
481
    #   When running with cppcheck we need to include it in our environment
482
    #
483
    if ( $UseCppcheck )
484
    {
485
        ToolsetRequire( "cppcheck" );
486
        PlatformDefine( "CPPCHECK_PLATFORM := unix32" );
487
    }
488
 
227 dpurdie 489
 
490
#.. Define GCC environment
491
#
492
    PlatformDefine( "
493
#################################################
494
# GCC toolchain definitions 
495
#
496
#..");
369 dpurdie 497
    PlatformDefine( "GCC_TARGET         := $GCCTarget" );
498
    PlatformDefine( "GCC_ROOT           := $GCCRoot" );
499
    PlatformDefine( "GCC_CC             := $GCCBin" );
500
    PlatformDefine( "GCC_AR             := $GCCAr" );
373 dpurdie 501
    PlatformDefine( "GCC_OBJCOPY        := $GCCObjCopy" );
5731 dpurdie 502
    PlatformDefine( "GCC_GCOVTOOL       := $GCCGcovTool" );
369 dpurdie 503
    PlatformDefine( "GCC_CFLAGS         := $GCCFlags" ) if defined $GCCFlags;
4034 dpurdie 504
    PlatformDefine( "GCC_CFLAGSP        := $GCCFlagsP" ) if defined $GCCFlagsP;
505
    PlatformDefine( "GCC_CFLAGSD        := $GCCFlagsD" ) if defined $GCCFlagsD;
4728 dpurdie 506
    PlatformDefine( "GCC_LDFLAGS        := $LDFlags" ) if defined $LDFlags;
5726 dpurdie 507
    PlatformDefine( "GCC_CXXFLAGS       := $GCCXXFlags" ) if defined $GCCXXFlags;
369 dpurdie 508
 
5726 dpurdie 509
 
227 dpurdie 510
    #
511
    #   Required since this toolset advertises: ScmToolsetCompilerPath
512
    #
369 dpurdie 513
    PlatformDefine( "SCM_COMPILERPATH   := \$\{GCC_CC\}" );
3967 dpurdie 514
 
515
    #
516
    #   Sanity checking
517
    #
518
    PlatformDefine( "GCC_EVERSION       := " . $GCCToolchain->{VERSION} ) if defined $GCCToolchain->{VERSION};
519
    PlatformDefine( "GCC_EMACHINE       := " . $GCCToolchain->{MACHINE} ) if defined $GCCToolchain->{MACHINE};
520
 
521
    #
522
    #   Option indication of packaging architecture
523
    #   Used by non-embedded systems for packaging. See debian_packager
524
    #
525
    PlatformDefine( "PACKAGE_ARCH       := $PkgArch" ) if (defined $PkgArch);
369 dpurdie 526
    PlatformDefine( "" );
227 dpurdie 527
 
528
#.. Piece the world together
529
#
3967 dpurdie 530
    Init( 'gcc' );
227 dpurdie 531
    ToolsetDefines( "gcc.def" );
532
    ToolsetRules( "gcc.rul" );
533
    ToolsetRules( "standard.rul" );
534
 
4094 dpurdie 535
 
536
    PlatformDefine( "CTAGS_EXE:= ctags" );
537
    ToolsetRequire( "exctags" );                # and Exuberant Ctags
538
 
227 dpurdie 539
#   Create a standard data structure
540
#   This is a hash of hashes
541
#       The first hash is keyed by CompileOption keyword
542
#       The second hash contains pairs of values to set or remove
543
#
544
    %::ScmToolsetCompilerOptions =
545
    (
546
        #
547
        #   Control the thread model to use
548
        #   This will affect the compiler options and the linker options
549
        #
550
        'staticprogs'        => { 'STATIC_PROGS' , '1' },      # Progams link staticlly
551
        'no_staticprogs'     => { 'STATIC_PROGS' , undef },    # Default
4034 dpurdie 552
        'noversiondll'       => { 'NO_VERSIONED_DLLS', 1 },    # Matches usage elsewhere
5115 dpurdie 553
        'pic'                => { 'GEN_PIC' , '1' },           # Force PIC for static libs
554
        'nopic'              => { 'GEN_PIC' , undef },         # No Pic on Static libs
7323 dpurdie 555
        'brokenldscripts'    => { 'BROKEN_LDSCRIPTS' , 1 },    # the linker is broken and cannot handle linker scripts
227 dpurdie 556
    );
557
 
558
    #
559
    #   Set default options
560
    #
561
    $::ScmCompilerOpts{'STATIC_PROGS'} = undef;
4034 dpurdie 562
    $::ScmCompilerOpts{'NO_VERSIONED_DLLS'} = undef;
7323 dpurdie 563
    $::ScmCompilerOpts{'USE_PROFILE'} = 1 if $UseProfile;
4034 dpurdie 564
 
565
    #
566
    #   Process toolset-specfic compiler options
567
    #
568
    if ( exists $GCCToolchain->{COMPILER_OPTIONS} )
569
    {
570
        CompileOptions('*', split(',',$GCCToolchain->{COMPILER_OPTIONS}) );
571
    }
227 dpurdie 572
}
573
 
4094 dpurdie 574
###############################################################################
575
#   ToolsetCTAGS()
576
#       This subroutine takes the user options and builds the rules
577
#       required to build the CTAGS database.
578
#
579
#   Arguments:
580
#       --xxx                   No arguments currently defined
581
#
582
#   Output:
583
#       [ctags:]
584
#           $(EXCTAGS)
585
#
586
###############################################################################
227 dpurdie 587
 
4094 dpurdie 588
sub ToolsetCTAGS
589
{
590
    EXCTAGS( @_ );
591
}
592
 
593
 
227 dpurdie 594
###############################################################################
595
#   ToolsetCC( $source, $obj, \@args )
596
#       This subroutine takes the user options and builds the rule(s)
597
#       required to compile the source file 'source' to 'obj'
598
#
599
###############################################################################
600
 
601
sub ToolsetCC
602
{
603
    my( $source, $obj, $pArgs ) = @_;
604
    my( $cflags, $file ) = "";
605
 
606
    foreach $_ ( @$pArgs ) {
607
        if (/--Shared$/) {                      # Building a 'shared' object
608
            $cflags  = "$cflags \$(SHCFLAGS)";
609
        } else {
610
            Message( "CC: unknown option $_ -- ignored\n" );
611
        }
612
    }
613
 
614
    MakePrint( "\n\t\$(CC)\n" );
615
    if ( $cflags )
616
    {                                           # object specific CFLAGS
617
        MakePadded( 4, "\$(OBJDIR)/$obj.$::o:" );
618
        MakePrint( "\tCFLAGS +=$cflags\n" );
619
    }
620
 
621
    $file = StripExt( $obj );                   # Metric working file
622
    ToolsetGenerate( "\$(OBJDIR)/$file.met" );
4728 dpurdie 623
 
624
    if ( $UseGcov )
625
    {
626
        ToolsetGenerate( '$(OBJDIR)/' . $file . '.gcno' );
627
        ToolsetGenerate( '$(OBJDIR)/' . $file . '.gcda' );
628
    }
227 dpurdie 629
}
630
 
631
 
632
###############################################################################
633
#   ToolsetCCDepend( $depend, \@sources )
634
#       This subroutine takes the user options and builds the
635
#       rule(s) required to build the dependencies for the source
636
#       files 'sources' to 'depend'.
637
#
638
###############################################################################
639
 
640
sub ToolsetCCDepend
641
{
642
    MakePrint( "\t\$(CCDEPEND)\n" );
643
}
644
 
645
 
646
###############################################################################
647
#   ToolsetCXX( $source, $obj, \@args )
648
#       This subroutine takes the user options and builds the rule(s)
649
#       required to compile the source file 'source' to 'obj'
650
#
651
###############################################################################
652
 
653
sub ToolsetCXX
654
{
655
    my( $source, $obj, $pArgs ) = @_;
656
    my( $cflags, $file ) = "";
657
 
658
    foreach $_ ( @$pArgs ) {
659
        if (/--Shared$/) {                      # Building a 'shared' object
660
            $cflags  = "$cflags \$(SHCXXFLAGS)";
661
        } else {
662
            Message( "CXX: unknown option $_ -- ignored\n" );
663
        }
664
    }
665
 
666
    MakePrint( "\n\t\$(CXX)\n" );
667
    if ( $cflags )
668
    {                                           # object specific CFLAGS
669
        MakePadded( 4, "\$(OBJDIR)/$obj.$::o:" );
670
        MakePrint( "\tCXXFLAGS +=$cflags\n" );
671
    }
672
 
673
    $file = StripExt( $obj );                   # Metric working file
674
    ToolsetGenerate( "\$(OBJDIR)/$file.met" );
4728 dpurdie 675
 
676
    if ( $UseGcov )
677
    {
678
        ToolsetGenerate( '$(OBJDIR)/' . $file . '.gcno' );
679
        ToolsetGenerate( '$(OBJDIR)/' . $file . '.gcda' );
680
    }
227 dpurdie 681
}
682
 
683
 
684
###############################################################################
685
#   ToolsetCXXDepend( $depend, \@sources )
686
#       This subroutine takes the user options and builds the
687
#       rule(s) required to build the dependencies for the source
688
#       files 'sources' to 'depend'.
689
#
690
###############################################################################
691
 
692
sub ToolsetCXXDepend
693
{
287 dpurdie 694
    ToolsetCCDepend();
227 dpurdie 695
}
696
 
697
 
698
###############################################################################
699
#   ToolsetAS( $source, $obj, \@args )
700
#       This subroutine takes the user options and builds the rule(s)
701
#       required to compile the source file 'source' to 'obj'
702
#
703
###############################################################################
704
 
705
sub ToolsetAS
706
{
707
    MakePrint( "\n\t\$(AS)\n" );
708
}
709
 
710
sub ToolsetASDepend
711
{
712
}
713
 
714
 
715
###############################################################################
716
#   ToolsetAR( $name, \@args, \@objs )
717
#       This subroutine takes the user options and builds the rules
718
#       required to build the library 'name'.
719
#
720
#   Arguments:
721
#       n/a
722
#
723
#   Output:
724
#       $(BINDIR)/name$.${a}:   .... ]
725
#           $(AR)
726
#
727
#       name_ld += ...  Linker command file
728
#           :
729
#
730
#       name_dp += ...  Dependency list
731
#           :
732
#
733
###############################################################################
734
 
735
sub ToolsetAR
736
{
737
    my( $name, $pArgs, $pObjs ) = @_;
738
 
739
#.. Parse arguments
740
#
741
    foreach $_ ( @$pArgs )
742
    {
743
        Message( "AR: unknown option $_ -- ignored\n" );
744
    }
745
 
746
#.. Target
747
#
748
    MakePrint( "#.. Library ($name)\n\n" );     # label
749
 
750
    MakeEntry( "\$(LIBDIR)/$name\$(GBE_TYPE).$::a:\t",
751
        "", "\\\n\t\t", ".$::o", @$pObjs );
752
 
753
#.. Build library rule (just append to standard rule)
754
#
755
    MakePrint( "\n\t\$(AR)\n\n" );
756
}
757
 
758
 
759
###############################################################################
760
#   ToolsetARMerge( $name, \@args, \@libs )
761
#       This subroutine takes the user options and builds the rules
762
#       required to build the library 'name' by merging the specified
763
#       libaries
764
#
765
#   Arguments:
766
#       --xxx                   No arguments currently defined
767
#
768
#   Output:
769
#       [ $(LIBDIR)/name$.${a}:   .... ]
770
#           ...
771
#
772
###############################################################################
773
 
774
sub ToolsetARMerge
775
{
776
    MakePrint( "\n\t\$(ARMERGE)\n\n" );
777
}
778
 
779
 
780
###############################################################################
289 dpurdie 781
#   ToolsetSHLD( $name, \@args, \@objs, \@libraries, $ver )
227 dpurdie 782
#       This subroutine takes the user options and builds the rules
339 dpurdie 783
#       required to link the Shared Library 'name'.
227 dpurdie 784
#
785
#   Arguments:
786
#   n/a
787
#
788
#   Output:
789
#       $(LIBDIR)/name:     $(LIBDIR)/shared
790
#           ln -s $shared $name
791
#
792
#       $(LIBDIR)/name.dep: $(GBE_OBJDIR)
793
#       $(LIBDIR)/name.dep: $(GBE_LIBDIR)
794
#       $(LIBDIR)/name.dep: $(GBE_PLATFORM).mk
795
#           $(SHLDDEPEND)
796
#
797
#       $(LIBDIR)/shared:   SHNAME=name
798
#       $(LIBDIR)/shared:   SHBASE=base
799
#       $(LIBDIR)/shared:   $(LIBDIR)/name.dep  \
800
#           $(OBJECTS)
801
#                           
802
#       ifneq "$(findstring $(IFLAG),23)" ""
803
#       -include            "$(LIBDIR)/name.dep"
804
#       endif
805
#
806
#       name_ld += ...
807
#           :
808
#
809
###############################################################################
810
 
811
sub ToolsetSHLD
812
{
289 dpurdie 813
    my( $name, $pArgs, $pObjs, $pLibs, $ver ) = @_;
7307 dpurdie 814
    my( $linkname, $soname, $shared, $dbgname, @preReqFiles, @scripts, $multi_scan );
4034 dpurdie 815
    my $sosuffix;
816
    my $noVersionedLib = $::ScmCompilerOpts{'NO_VERSIONED_DLLS'};
7307 dpurdie 817
    my $brokenLd = $::ScmCompilerOpts{'BROKEN_LDSCRIPTS'};
227 dpurdie 818
 
819
#.. Parse arguments
820
#
821
    foreach $_ ( @$pArgs )
822
    {
823
        if (/^--Def=(.*?)(\,(.*))?$/) {         # Library definition
824
            #
825
            #   Locate the Def file.
826
            #   If it is a generate file so it will be in the SRCS hash
827
            #   Otherwise the user will have to use Src to locate the file
828
            #
7307 dpurdie 829
            my $def = MakeSrcResolve($1);
830
 
831
            if ($brokenLd) {
832
                #   The linker cannot handle the linker script
833
                #   The work around is to split the script into two that it can handle
834
                #   Only works with a Linker Script with VERSION and EXTERN entries    
835
                my $index = scalar @ldFixups; 
836
                my %data;
837
                $data{src} = $def;
838
                $data{vs} = '$(OBJDIR)/linkscript_' . $index . '.def';
839
                $data{ls} = '$(OBJDIR)/linkscript_' . $index . '.scr';
840
                push @ldFixups, \%data;
841
 
842
                push @scripts, $data{ls};
843
                push @scripts, '--version-script=' . $data{vs};
844
 
845
                push @preReqFiles, $data{vs};
846
                push @preReqFiles, $data{ls};
847
 
848
            }  else {
849
                # Normal operation. Linker is not broken
850
                push @preReqFiles, $def;
851
                if ( $1 =~ m~\.def$~ ) {
852
                    $def = '--version-script=' .$def; # Old def file
853
                }
854
                push @scripts, $def;
227 dpurdie 855
            }
7307 dpurdie 856
 
227 dpurdie 857
        } elsif ( /^--MultiScan/i ) {
858
            $multi_scan = 1;
859
 
860
        } elsif ( /^--NoMultiScan/i ) {
861
            $multi_scan = 0;
862
 
339 dpurdie 863
        } elsif ( /^--SoNameSuffix=(.*)/i ) {
864
            $sosuffix = $1;
865
 
4034 dpurdie 866
        } elsif (/^--NoVersionDll/i) {
867
            $noVersionedLib = 1;
868
 
227 dpurdie 869
        } else {
870
            Message( "SHLD: unknown option $_ -- ignored\n" );
871
        }
872
    }
873
 
4034 dpurdie 874
    #
7321 dpurdie 875
    # Determine the 'soname' if none has been provided
4034 dpurdie 876
    #
877
    $sosuffix = '.' . $ver
878
        unless ( defined $sosuffix );
879
    $sosuffix = ''
880
        if ( $noVersionedLib );
881
 
339 dpurdie 882
#.. Various library names
227 dpurdie 883
#
339 dpurdie 884
    $linkname = "$name\$(GBE_TYPE).$::so";
4034 dpurdie 885
    $shared = $noVersionedLib ? $linkname : "$linkname.$ver";
339 dpurdie 886
    $soname = "$linkname$sosuffix";
4034 dpurdie 887
 
373 dpurdie 888
    my $shared_path = "\$(LIBDIR)/${shared}";
889
    my $dbg_path =  $shared_path . '.dbg';
227 dpurdie 890
 
891
#.. Cleanup rules
892
#
893
#   map     Map file
894
#   ln      Link from LIBDIR to BINDIR
895
#
261 dpurdie 896
    ToolsetGenerate( "\$(LIBDIR)/${name}.map" );
897
    ToolsetGenerate( "\$(LIBDIR)/${shared}" );
339 dpurdie 898
    ToolsetGenerate( "\$(BINDIR)/${soname}" );
373 dpurdie 899
    ToolsetGenerate( $dbg_path );
227 dpurdie 900
 
901
#.. Build rules
902
#
903
#   name        Base name
904
#   shared      Library name, includes GBE_TYPE specification
905
#
906
    my ($io) = ToolsetPrinter::New();
335 dpurdie 907
    my $dep = $io->SetShldTarget($shared);
227 dpurdie 908
 
909
    $io->Label( "Shared library", $name );
339 dpurdie 910
    PackageShlibAddFiles( $name, "\$(LIBDIR)/$shared" );
373 dpurdie 911
    PackageShlibAddFiles( $name, $dbg_path );
4034 dpurdie 912
 
227 dpurdie 913
    $io->Prt( "\$(LIBDIR)/${shared}:\tSHBASE=${name}\n" );
339 dpurdie 914
    $io->Prt( "\$(LIBDIR)/${shared}:\tSHNAME=${soname}\n" );
915
    $io->Prt( "\$(LIBDIR)/${shared}: \\\n\t\t${dep}" );
321 dpurdie 916
    $io->Entry( "", "", " \\\n\t\t", ".$::o", @$pObjs );
7307 dpurdie 917
    $io->Entry( "", "", " \\\n\t\t", "", @preReqFiles );
373 dpurdie 918
    $io->Prt( "\n\t\$(SHLD)" );
919
    $io->Prt( "\n\t\$(call LDSTRIP,$shared_path,$dbg_path)\n\n" );
321 dpurdie 920
 
339 dpurdie 921
#
922
#   Create soft links
923
#       'Real Name' to its 'Link Name'
924
#       'Real Name' to 'SoName' in the BINDIR (for testing I think)
925
#       'Real Name' to 'SoName' in the LIBDIR (if different)
926
#
4034 dpurdie 927
    if ( $shared ne $linkname)
928
    {
929
        $io->Label( "Shared library Symbolic Links", $name );
5882 dpurdie 930
        PackageShlibAddFiles( $name, "\$(LIBDIR)/$linkname", 'symlink=1' );
4034 dpurdie 931
        $io->Prt( "\$(LIBDIR)/$linkname:\t\\\n" .
932
                  "\t\t\$(GBE_BINDIR)\\\n" .
933
                  "\t\t\$(LIBDIR)/${shared}\n" .
5882 dpurdie 934
                  "\t\$(AA_PRE)(rm -f \$@; ln -s $shared \$@)\n\n" );
4034 dpurdie 935
    }
936
 
937
    $io->Label( "Shared library BINDIR Symbolic Links", $name );
5882 dpurdie 938
#    PackageShlibAddFiles( $name, "\$(BINDIR)/$soname", 'symlink=1' );
4034 dpurdie 939
    $io->Prt( "\$(BINDIR)/$soname:\t\\\n" .
339 dpurdie 940
              "\t\t\$(GBE_BINDIR)\\\n" .
941
              "\t\t\$(LIBDIR)/${shared}\n" .
4034 dpurdie 942
              "\t\$(AA_PRE)(rm -f \$@; ln -s ../\$(LIBDIR)/$shared \$@)\n\n" );
339 dpurdie 943
 
4034 dpurdie 944
    if ( $soname ne $shared )
339 dpurdie 945
    {
946
        $io->Label( "Shared library SoName Symbolic Links", $name );
5882 dpurdie 947
        PackageShlibAddFiles( $name, "\$(LIBDIR)/$soname", 'symlink=1' );
339 dpurdie 948
        $io->Prt( "\$(LIBDIR)/$soname:\t\\\n" .
949
                  "\t\t\$(GBE_LIBDIR)\\\n" .
950
                  "\t\t\$(LIBDIR)/${shared}\n" .
5882 dpurdie 951
                  "\t\$(AA_PRE)(rm -f \$@; ln -s $shared \$@)\n" );
339 dpurdie 952
    }
953
 
227 dpurdie 954
#.. Linker command file
955
#
956
#       Now the fun part... piecing together a variable $(name_shld)
957
#       which ends up in the command file.
958
#
339 dpurdie 959
    $io->Newline();
227 dpurdie 960
    $io->SetTag( "${name}_shld" );              # command tag
961
    $io->SetTerm( "\n" );
962
 
963
    $io->Label( "Linker commands", $name );     # label
964
 
965
                                                # object list
966
    $io->ObjList( $name, $pObjs, \&ToolsetObjRecipe );
967
 
968
    ToolsetLibStd( $pLibs );                    # push standard libraries
969
 
7307 dpurdie 970
    $io->Cmd( "-Wl," . join (',', @scripts) ) if (@scripts);
227 dpurdie 971
 
972
    $io->Cmd( "-Wl,--start-group" ) if ($multi_scan);
973
    $io->LibList( $name, $pLibs, \&ToolsetLibRecipe );
974
    $io->Cmd( "-Wl,--end-group" ) if ($multi_scan);
975
 
976
    $io->Newline();
977
 
335 dpurdie 978
    #.. Dependency link,
979
    #   Create a library dependency file
980
    #       Create command file to build applicaton dependency list
981
    #       from the list of dependent libraries
982
    #
983
    #       Create makefile directives to include the dependency
984
    #       list into the makefile.
985
    #
986
    $io->DepRules( $pLibs, \&ToolsetLibRecipe, "\$(LIBDIR)/${shared}" );
339 dpurdie 987
    $io->SHLDDEPEND($name, $soname);
227 dpurdie 988
}
989
 
990
 
991
###############################################################################
271 dpurdie 992
# Function        : ToolsetLD
227 dpurdie 993
#
271 dpurdie 994
# Description     : Takes the user options and builds the rules required to
995
#                   link the program 'name'.
227 dpurdie 996
#
271 dpurdie 997
# Inputs          : $name           - base name of the program
998
#                   $pArgs          - Ref to program arguments
999
#                   $pObjs          - Ref to program objects
1000
#                   $pLibs          - Ref to program library list
227 dpurdie 1001
#
271 dpurdie 1002
# Returns         : Nothing
227 dpurdie 1003
#
271 dpurdie 1004
# Output:         : Rules and recipes to create a program
1005
#                       Create program rules and recipes
1006
#                       Create linker input script
1007
#                       Create library dependency list
1008
#                       Include library dependency information
227 dpurdie 1009
#
1010
sub ToolsetLD
1011
{
1012
    my( $name, $pArgs, $pObjs, $pLibs ) = @_;
1013
    my $static = $::ScmCompilerOpts{'STATIC_PROGS'};
1014
    my $multi_scan;
1015
 
1016
#.. Parse arguments
1017
#
1018
    foreach $_ ( @$pArgs )
1019
    {
1020
        if ( m/^--Static$/ ) {
1021
            $static = 1;
1022
 
1023
        } elsif ( m/^--Shared/ ) {
1024
            $static = 0;
1025
 
1026
        } elsif ( /^--MultiScan/i ) {
1027
            $multi_scan = 1;
1028
 
1029
        } elsif ( /^--NoMultiScan/i ) {
1030
            $multi_scan = 0;
1031
 
1032
        } else {
1033
            Message( "LD: unknown option $_ -- ignored\n" );
1034
        }
1035
    }
1036
 
271 dpurdie 1037
#.. Names of programs and components
1038
#
1039
    my $base = "\$(BINDIR)/${name}";
1040
    my $full = $base . $::exe;
1041
    my $map  = $base . '.map';
1042
    my $ld  =  $base . '.ld';
373 dpurdie 1043
    my $dbg =  $base . '.dbg';
271 dpurdie 1044
 
227 dpurdie 1045
#.. Cleanup rules
1046
#
271 dpurdie 1047
    ToolsetGenerate( $ld );
1048
    ToolsetGenerate( $map );
373 dpurdie 1049
    ToolsetGenerate( $dbg );
227 dpurdie 1050
 
1051
#.. Build rules
1052
#
1053
    my ($io) = ToolsetPrinter::New();
335 dpurdie 1054
    my $dep = $io->SetLdTarget( $name );
227 dpurdie 1055
 
271 dpurdie 1056
    $io->Prt( "$full : $dep " );
1057
    $io->Entry( "", "", "\\\n\t", ".$::o ", @$pObjs );
373 dpurdie 1058
    $io->Prt( "\n\t\$(LD)" );
1059
    $io->Prt( "\n\t\$(call LDSTRIP,$full,$dbg)\n\n" );
227 dpurdie 1060
 
271 dpurdie 1061
 
227 dpurdie 1062
#.. Linker command file
1063
#
1064
#       Now the fun part... piecing together a variable $(name_ld)
1065
#       which ends up in the command file.
1066
#
1067
    $io->SetTag( "${name}_ld" );                # macro tag
1068
    $io->SetTerm( "\n" );
1069
 
1070
    $io->Label( "Linker commands", $name );     # label
1071
 
1072
    $io->Cmd( "-static" ) if ($static);         # Link as a static program
1073
 
1074
                                                # object list
1075
    $io->ObjList( $name, $pObjs, \&ToolsetObjRecipe );
1076
 
1077
    ToolsetLibStd( $pLibs );                    # push standard libraries
1078
 
1079
                                                # library list
1080
    $io->Cmd( "-Wl,--start-group" ) if ($multi_scan);
1081
    $io->LibList( $name, $pLibs, \&ToolsetLibRecipe );
1082
    $io->Cmd( "-Wl,--end-group" ) if ($multi_scan);
1083
 
5744 dpurdie 1084
    #   Add Compilers sysroot library path
1085
    #   Only required for a 'native' compiler that is not fully installed on the host
7323 dpurdie 1086
    #   ie: The run-time can't locate the required glibc components
5796 dpurdie 1087
    if ($GCCRPath)
1088
    {
1089
        $io->Cmd( "-Wl,-rpath=$GCCRPath" );
1090
        $io->Cmd( "-Wl,--dynamic-linker=$GCCRPath/ld-linux.so.2" ) if ($GCCRPath);
1091
    }
5744 dpurdie 1092
 
227 dpurdie 1093
    $io->Newline();
1094
 
335 dpurdie 1095
    #.. Dependency link,
1096
    #   Create a library dependency file
1097
    #       Create command file to build applicaton dependency list
1098
    #       from the list of dependent libraries
1099
    #
1100
    #       Create makefile directives to include the dependency
1101
    #       list into the makefile.
1102
    #
1103
    $io->DepRules( $pLibs, \&ToolsetLibRecipe, $base );
1104
    $io->LDDEPEND();
271 dpurdie 1105
 
1106
#.. Package up the program and other artifacts
1107
#
1108
    PackageProgAddFiles ( $name, $full );
7322 dpurdie 1109
    PackageProgAddFiles ( $name, $dbg, "Class=debug" );
271 dpurdie 1110
 
227 dpurdie 1111
}
1112
 
4778 dpurdie 1113
  #-------------------------------------------------------------------------------
1114
# Function        : ToolsetPostprocess 
1115
#
1116
# Description     : Last chance by the toolset to perform processing
1117
#                   All Directives have been processed
1118
#
1119
#                   If automated unit test are being used,
1120
#                   then we need to post process the results
1121
#
1122
# Inputs          : None
1123
#
1124
# Returns         : 
1125
#
1126
sub ToolsetPostprocess
1127
{
1128
    ToolsetPreprocessTests();
1129
    ToolsetPostprocessTests();
1130
    ToolsetCollateTestResults();
7307 dpurdie 1131
    ToolsetGenLdScripts();
4778 dpurdie 1132
}
227 dpurdie 1133
 
4728 dpurdie 1134
###############################################################################
1135
# Function        : ToolsetPreprocessTests
1136
#
5884 dpurdie 1137
# Description     : Generate $(OBJDIR)/lcov-baseline.info 
1138
#                   Generate full coverage info
4728 dpurdie 1139
#
1140
# Inputs          : None
1141
#
1142
# Returns         : Nothing
1143
#
1144
# Output:         : Rules and recipes to run before unit tests
1145
#
1146
sub ToolsetPreprocessTests
1147
{
1148
    my ($io) = ToolsetPrinter::New();
1149
    if ( $UseGcov && scalar(keys %::OBJSOURCE) > 0 )
1150
    {
5884 dpurdie 1151
        #
1152
        #   Setup Env so that the files created by GCOV are within the package
1153
        #   being created. Elsewise they will be created all over the file 
1154
        #   system in the original location where the external objects were created.
1155
        #
1156
        $io->PrtLn('GCOV_PREFIX := $(abspath $(INTERFACEDIR)/gcov)' );
1157
        $io->PrtLn('GCOV_PREFIX_STRIP := 0' );
1158
        $io->PrtLn('export GCOV_PREFIX GCOV_PREFIX_STRIP' );
1159
        $io->Newline();
1160
 
1161
        #
1162
        #   GCOV_PKGBASE - used to 'extract' coverage artifacts
1163
        #   Used to limit the coverage report to files that are within this package
1164
        #   Ideally it should be the root of the package, but this is not always known
1165
        #   Use the first two path elements of the current package
1166
        #       Really just want to filter out compiler bits
1167
        #     
1168
 
1169
        $io->PrtLn('GCOV_PKGBASE :=  $(subst $(space),/,$(space)$(wordlist 1,2,$(subst /,$(space),$(CURDIR))))' );
1170
        $io->PrtLn('GCOV_VERBOSE :=  $(if $(VERBOSE_OPT),,--quiet)' );
1171
        $io->Newline();
1172
 
4778 dpurdie 1173
        my $ruleName = 'preprocess_gcov_data';
4728 dpurdie 1174
        my $finaldir='$(LOCALDIR)/lcov/$(GBE_PLATFORM)$(GBE_TYPE)';
1175
        my $final=$finaldir . '/lcov-final.info';
1176
 
4778 dpurdie 1177
        ToolsetAddUnitTestPreProcess($ruleName);
1178
        $io->PrtLn('.PHONY: ' . $ruleName );
7323 dpurdie 1179
        $io->PrtLn($ruleName . ': $(OBJDIR)' );
5884 dpurdie 1180
        $io->PrtLn("\t" . '${XX_PRE}$(rm) -f ${GCOV_PREFIX}/$(CURDIR)/$(OBJDIR)/*.gcda' );
1181
        $io->PrtLn("\t" . '${XX_PRE}$(rm) -f $(OBJDIR)/*.gcda' );
4728 dpurdie 1182
        $io->PrtLn("\t" . '${XX_PRE}$(rm) -f ' . $final);
1183
        $io->PrtLn("\t" . '${XX_PRE}lcov'
5884 dpurdie 1184
                        . ' $(GCOV_VERBOSE)'
4835 dpurdie 1185
                        . ' --capture'
1186
                        . ' --initial'
5884 dpurdie 1187
                        . ' --base-directory $(CURDIR)'
4835 dpurdie 1188
                        . ' --directory $(OBJDIR)'
5731 dpurdie 1189
                        . ' --gcov-tool $(GCC_GCOVTOOL)' 
5884 dpurdie 1190
                       . ' --output-file $(OBJDIR)/lcov-baseline.info' );
4778 dpurdie 1191
        $io->Newline();
5884 dpurdie 1192
        ToolsetGenerate( '$(OBJDIR)/lcov-baseline.info' );
4728 dpurdie 1193
    }
1194
}
1195
 
1196
 
1197
###############################################################################
1198
# Function        : ToolsetPostprocessTests
1199
#
5884 dpurdie 1200
# Description     : Merge this sub-components bits into the the final coverage
1201
#                   file in lcov-baseline.info
1202
#                   
1203
#                   Need to locate the .gcda files and place them in the same directory
1204
#                   as the .gcno files that were created during preprocssing
1205
#                   
1206
#                   Then we can add our trace bits into the file coverage file
4728 dpurdie 1207
#
1208
# Inputs          : None
1209
#
1210
# Returns         : Nothing
1211
#
1212
# Output:         : Rules and recipes to run after the unit tests
1213
#
1214
sub ToolsetPostprocessTests
1215
{
1216
    my ($io) = ToolsetPrinter::New();
1217
    if ( $UseGcov && scalar(keys %::OBJSOURCE) > 0 )
1218
    {
4778 dpurdie 1219
        my $ruleName = 'postprocess_gcov_data';
4728 dpurdie 1220
        my $finaldir='$(LOCALDIR)/lcov/$(GBE_PLATFORM)$(GBE_TYPE)';
1221
        my $final=$finaldir . '/lcov-final.info';
1222
 
4778 dpurdie 1223
        ToolsetAddUnitTestPostProcess($ruleName);
1224
 
1225
        $io->PrtLn('.PHONY: ' . $ruleName );
1226
        $io->PrtLn($ruleName . ':' );
5884 dpurdie 1227
        $io->PrtPart("\t" . '$(XX_PRE)if [ -d "${GCOV_PREFIX}/$(CURDIR)/$(OBJDIR)" ]; then' ); 
1228
        $io->PrtPart("\t\t" . 'cd ${GCOV_PREFIX}/$(CURDIR);');
1229
        $io->PrtPart("\t\t" . 'find $(OBJDIR) -name \'*.gcda\' -exec cp --parent {} $(CURDIR) \\; ;');
1230
#        $io->PrtPart("\t" . 'else');
1231
#        $io->PrtPart("\t\t" . 'echo NO .gcda DATA for $(CURDIR);');
1232
        $io->PrtLn  ("\t" . 'fi' );
4728 dpurdie 1233
        $io->PrtLn  ("\t" . '$(XX_PRE)$(mkdir) -p ' . $finaldir);
5884 dpurdie 1234
        $io->PrtPart("\t" . '$(XX_PRE)GCDA_COUNT=$$(find $(OBJDIR) -name "*.gcda" | wc -l);' ); 
1235
        $io->PrtPart("\t" . 'if [ "$${GCDA_COUNT}" -eq "0" ]; then ');
4728 dpurdie 1236
        $io->PrtPart("\t\t" . 'if [ ! -e ' . $final . " ]; then");
1237
        $io->PrtPart("\t\t\t" . '$(cp) $(OBJDIR)/lcov-baseline.info ' . $final . ';');
1238
        $io->PrtPart("\t\t" . 'else');
1239
        $io->PrtPart("\t\t\t" . 'lcov'
5884 dpurdie 1240
                          . ' $(GCOV_VERBOSE)'
4835 dpurdie 1241
                          . $LcovExplicitBranch
4728 dpurdie 1242
                          . ' --add-tracefile $(OBJDIR)/lcov-baseline.info'
1243
                          . ' --add-tracefile ' . $final
5731 dpurdie 1244
                          . ' --gcov-tool $(GCC_GCOVTOOL)' 
4728 dpurdie 1245
                          . ' --output-file $(OBJDIR)/lcov-merge.info'
1246
                          . ';'); 
1247
        $io->PrtPart("\t\t\t" . '$(rm) -f ' . $final . ';');
1248
        $io->PrtPart("\t\t\t" . '$(mv) $(OBJDIR)/lcov-merge.info ' . $final . ';');
1249
        $io->PrtPart("\t\t" . 'fi' . ';');
1250
        $io->PrtPart("\t" . 'else');
1251
        $io->PrtPart("\t\t" . 'lcov'
5884 dpurdie 1252
                        . ' $(GCOV_VERBOSE)'
1253
                        . $LcovExplicitBranch
4728 dpurdie 1254
                        . ' --capture'
5884 dpurdie 1255
                        . ' --base-directory $(CURDIR)'
4728 dpurdie 1256
                        . ' --directory $(OBJDIR)'
5731 dpurdie 1257
                        . ' --gcov-tool $(GCC_GCOVTOOL)' 
4728 dpurdie 1258
                        . ' --output-file $(OBJDIR)/lcov-capture.info' 
1259
                        . ';'); 
1260
        $io->PrtPart("\t\t" . 'if [ ! -e ' . $final . " ]; then");
1261
        $io->PrtPart("\t\t\t" . 'lcov'
5884 dpurdie 1262
                          . ' $(GCOV_VERBOSE)'
4835 dpurdie 1263
                          . $LcovExplicitBranch
4728 dpurdie 1264
                          . ' --add-tracefile $(OBJDIR)/lcov-baseline.info'
5884 dpurdie 1265
                          . ' --add-tracefile $(OBJDIR)/lcov-capture.info'
5731 dpurdie 1266
                          . ' --gcov-tool $(GCC_GCOVTOOL)' 
4728 dpurdie 1267
                          . ' --output-file ' .  $final
1268
                          . ';'); 
1269
        $io->PrtPart("\t\t" . 'else');
1270
        $io->PrtPart("\t\t\t" . 'lcov'
5884 dpurdie 1271
                          . ' $(GCOV_VERBOSE)'
4835 dpurdie 1272
                          . $LcovExplicitBranch
4728 dpurdie 1273
                          . ' --add-tracefile $(OBJDIR)/lcov-baseline.info'
5884 dpurdie 1274
                          . ' --add-tracefile $(OBJDIR)/lcov-capture.info'
4728 dpurdie 1275
                          . ' --add-tracefile ' . $final
5731 dpurdie 1276
                          . ' --gcov-tool $(GCC_GCOVTOOL)' 
4728 dpurdie 1277
                          . ' --output-file $(OBJDIR)/lcov-merge.info'
1278
                          . ';'); 
1279
        $io->PrtPart("\t\t\t" . '$(rm) -f ' . $final . ';');
1280
        $io->PrtPart("\t\t\t" . '$(mv) $(OBJDIR)/lcov-merge.info ' . $final . ';');
1281
        $io->PrtPart("\t\t" . 'fi' . ';');
1282
        $io->PrtLn  ("\t" . 'fi');
4778 dpurdie 1283
        $io->Newline();
5817 dpurdie 1284
 
1285
        ToolsetGenerate ('$(OBJDIR)/lcov-capture.info' );
1286
        ToolsetGenerate ($final);
1287
 
4728 dpurdie 1288
    }
1289
}
1290
 
1291
 
1292
###############################################################################
1293
# Function        : ToolsetCollateTestResults
1294
#
5884 dpurdie 1295
# Description     : Process the lcov-final.info by
1296
#                       Extract parts generated by files in this package
1297
#                       Remove parts generated by files in the interface directory
1298
#                           They are the results of a 'BuildPkgArchive'
4728 dpurdie 1299
#
1300
# Inputs          : None
1301
#
1302
# Returns         : Nothing
1303
#
1304
# Output:         : Rules and recipes to run after unit test result 
1305
#                   postprocessing.
1306
#
1307
sub ToolsetCollateTestResults
1308
{
1309
    my ($io) = ToolsetPrinter::New();
1310
    if ( $UseGcov && scalar(keys %::OBJSOURCE) > 0 )
1311
    {
4778 dpurdie 1312
        my $ruleName = 'collate_gcov_results';
5884 dpurdie 1313
        my $finaldir = '$(LOCALDIR)/lcov/$(GBE_PLATFORM)$(GBE_TYPE)';
1314
        my $final     = $finaldir . '/lcov-final.info';
5885 dpurdie 1315
        my $finalTmp  = $finaldir . '/lcov-extracted.info';
1316
        my $finalTmp1 = $finaldir . '/lcov-filtered.info';
4778 dpurdie 1317
 
5884 dpurdie 1318
        ToolsetGenerate ( $final );
1319
        ToolsetGenerate ( $finalTmp );
1320
        ToolsetGenerate ( $finalTmp1 );
1321
 
4778 dpurdie 1322
        ToolsetAddUnitTestCollateProcess($ruleName);
4728 dpurdie 1323
 
1324
        my $reportdir='$(PKGDIR)/lcov/$(GBE_PLATFORM)$(GBE_TYPE)';
1325
        my $reportindex=$reportdir . '/index.html';
4778 dpurdie 1326
        $io->PrtLn('.PHONY: ' . $ruleName );
1327
        $io->PrtLn($ruleName . ': ' . $reportindex);
5884 dpurdie 1328
 
4728 dpurdie 1329
        $io->Newline();
1330
        $io->PrtLn($reportindex . ': ' . $final);
5884 dpurdie 1331
        $io->PrtPart("\t" . 'lcov'
1332
                        . ' $(GCOV_VERBOSE)'
1333
                        . $LcovExplicitBranch
1334
                        . ' --extract '. $final .' "$(GCOV_PKGBASE)/*"'
1335
                        . ' --gcov-tool $(GCC_GCOVTOOL)' 
1336
                        . ' --output-file ' . $finalTmp
1337
                        . ';'); 
1338
        $io->PrtPart("\t" . 'lcov'
1339
                        . ' $(GCOV_VERBOSE)'
1340
                        . $LcovExplicitBranch
1341
                        . ' --remove '. $finalTmp .' "$(abspath $(INTERFACEDIR))/*"'
1342
                        . ' --gcov-tool $(GCC_GCOVTOOL)' 
1343
                        . ' --output-file ' .$finalTmp1
1344
                        . ';'); 
4728 dpurdie 1345
        $io->PrtLn("\t" . 'genhtml'
5884 dpurdie 1346
                      . ' $(GCOV_VERBOSE)'
4728 dpurdie 1347
                      . ' --frames'
1348
                      . ' --show-details'
1349
                      . ' --function-coverage'
1350
                      . ' --branch-coverage'
1351
                      . ' --output-directory ' . $reportdir
1352
                      . ' --legend'
5885 dpurdie 1353
                      . ' --demangle-cpp' 
1354
                      . ' --title "$(GBE_PBASE) $(BUILDVER)"'
5884 dpurdie 1355
                      . ' ' . $finalTmp1);
4778 dpurdie 1356
        $io->Newline();
4728 dpurdie 1357
    }
1358
}
1359
 
7307 dpurdie 1360
#-------------------------------------------------------------------------------
1361
# Function        : ToolsetGenLdScripts 
1362
#
1363
# Description     : Generate Linker (ld) scripts to to support the Broken Linker
1364
#                   Enabled via BROKEN_LDSCRIPTS
1365
#                   The linker cannot handle a linkerscript with a 'VERSION" section
1366
#                   The linker can handle a linker script with an EXTERN section
1367
#                   and a --version-script
1368
#                   
1369
#                   This workaround will take the linker script and break it into two
1370
#                   parts. This must be done at make-time in case the linker script is
1371
#                   generated.
1372
#                   
1373
#                   Use a feature of Pattern Rules. Handling of multiple targets
1374
#                   The pattern (%) is a '.'. 
1375
#                   It may be substituted as $* in the output.
1376
#                   
1377
#                   file1%out file2%out : infile
1378
#                       SomeProg file1$*out file2$*out      - Using pattern substitution
1379
#                       SomeProg file1.out file2.out        - Alternate command
1380
#                   
1381
# Inputs          : None 
1382
#
1383
# Returns         : Nothing
1384
#
1385
sub ToolsetGenLdScripts
1386
{
1387
    return unless @ldFixups;
1388
    Verbose('ToolsetGenLdScripts');
4728 dpurdie 1389
 
7307 dpurdie 1390
    my ($io) = ToolsetPrinter::New();
1391
    $io->PrtLn('# Broken Linker Support');
1392
    foreach my $entry (@ldFixups)
1393
    {
1394
        (my $ls = $entry->{ls}) =~ s~\.~%~;
1395
        (my $vs = $entry->{vs}) =~ s~\.~%~;
1396
 
1397
        $io->Newline();
1398
        $io->PrtLn("$vs $ls:  $entry->{src} \$(SCM_MAKEFILE)" );
1399
 
1400
        $io->PrtLn("\t\$(GBE_PERL) -Mjats_runtime_gcc -e splitscript -- --src=$entry->{src} --vs=$entry->{vs} --ls=$entry->{ls}" );
1401
        ToolsetGenerate ($entry->{vs} );
1402
        ToolsetGenerate ($entry->{ls} );
1403
    }
1404
}
1405
 
4728 dpurdie 1406
###############################################################################
1407
#   ToolsetARLINT( $name, \@args, \@objs )
1408
#       This subroutine takes the user options and builds the rules
1409
#       required to lint the static library 'name'.
1410
#
1411
#   Arguments:
1412
#       --xxx                   No arguments currently defined
1413
#
1414
#   Output:
1415
#       [ $(LIBDIR)/name$_lint:   .... ]
1416
#           $(ARLINT)
1417
#
1418
###############################################################################
1419
 
1420
sub ToolsetARLINT
1421
{
1422
    if ( $UseCppcheck )
1423
    {
1424
        CppcheckAR( @_ );
1425
    }
1426
}
1427
 
1428
 
1429
###############################################################################
1430
#   ToolsetSHLDLINT $name, \@args, \@objs, \@libraries )
1431
#       This subroutine takes the user options and builds the rules
1432
#       required to lint the shared library 'name'.
1433
#
1434
#   Arguments:
1435
#       (none)
1436
#
1437
#   Output:
1438
#       [ $(LIBDIR)/$name_lint:   .... ]
1439
#           $(SHLIBLINT)
1440
#
1441
###############################################################################
1442
 
1443
sub ToolsetSHLDLINT
1444
{
1445
    if ( $UseCppcheck )
1446
    {
1447
        CppcheckSHLD( @_ );
1448
    }
1449
}
1450
 
1451
 
1452
###############################################################################
1453
#   ToolsetLD( $name, \@args, \@objs, \@libraries, \@csrc, \@cxxsrc )
1454
#       This subroutine takes the user options and builds the rules
1455
#       required to lint the program 'name'.
1456
#
1457
#   Arguments:
1458
#       (none)
1459
#
1460
#   Output:
1461
#       [ $(BINDIR)/$name_lint:   .... ]
1462
#           $(LDLINT)
1463
#
1464
###############################################################################
1465
 
1466
sub ToolsetLDLINT
1467
{
1468
    if ( $UseCppcheck )
1469
    {
1470
        CppcheckLD( @_ );
1471
    }
1472
}
1473
 
227 dpurdie 1474
########################################################################
1475
#
1476
#   Push standard "system" libraries. This is a helper function
1477
#   used within this toolset.
1478
#
1479
#   Arguments:
1480
#       $plib       Reference to library array.
1481
#
1482
########################################################################
1483
 
1484
sub ToolsetLibStd
1485
{
1486
}
1487
 
1488
 
1489
########################################################################
1490
#
1491
#   Generate a linker object recipe.  This is a helper function used 
1492
#   within this toolset.
1493
#
1494
#   Arguments:
1495
#       $io         I/O stream
1496
#
1497
#       $target     Name of the target
1498
#
1499
#       $obj        Library specification
1500
#
1501
########################################################################
1502
 
1503
sub ToolsetObjRecipe
1504
{
1505
    my ($io, $target, $obj) = @_;
1506
 
1507
    $io->Cmd( "\$(strip $obj).$::o" );
1508
}
1509
 
1510
 
1511
###############################################################################
1512
#
1513
#   Parse a linker lib list
1514
#   This is a helper function used within this toolset
1515
#
1516
#   Arguments:
1517
#       $target     Name of the target
1518
#
1519
#       $lib        Library specification
1520
#
1521
#       $tag        Tag (user specified)
1522
#
1523
#       $dp         If building a depend list, the full target name.
1524
#
1525
###############################################################################
1526
 
1527
sub ToolsetLibRecipe
1528
{
1529
    my ($io, $target, $lib, $dp) = @_;
1530
 
1531
    if ( ! defined($dp) ) {                     # linker
1532
        $lib =~ s/^lib//;                       # .. remove leading 'lib'
1533
        $io->Cmd( "-l$lib" );
1534
 
1535
    } else {                                    # depend
1536
        $io->Cmd( "$dp:\t@(vlib2,$lib,GCC_LIB)" );
1537
 
1538
    }
1539
}
1540
 
1541
#.. Successful termination
1542
1;
1543