Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
261 dpurdie 1
#..
6177 dpurdie 2
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
261 dpurdie 3
#
4
# Module name   : JATS
5
# Module type   : JATS Toolset
6
# Compiler(s)   : Perl
7
# Environment(s): JATS
8
#
9
# Description:
10
#       This file provides Toolset initialisation and plugin functions
11
#       to makelib.pl2
12
#
13
# Contents:     VERIX rules as used for the Verix V SDK
14
#
15
#............................................................................#
16
 
17
use strict;
18
use warnings;
19
use JatsVersionUtils;
20
 
21
#
22
#   Globals
23
#
24
our $ScmBuildVersionFull;                   # Full Build Version Number
25
 
26
 
27
##############################################################################
28
#   ToolsetInit()
29
#       Runtime initialisation
30
#
31
##############################################################################
32
 
33
ToolsetInit();
34
 
35
sub ToolsetInit
36
{
37
    my( $version, $flavour );
38
    my $no_defines;
39
    my( @defines );
40
    my $board = '';
41
 
42
#.. Parse Toolset arguments
43
#
44
    Debug( "verix(@::ScmToolsetArgs)\n" );
45
 
46
    $version = 0;                               # Default (not great)
47
    foreach $_ ( @::ScmToolsetArgs ) {
48
        if (/^--Version=(.*)/) {                # Compiler version
49
            $version = "$1";
50
        } else {
51
            Message( "verix: unknown toolset argument $_ -- ignored" );
52
        }
53
    }
54
 
55
#.. Parse Platform Arguments
56
#
57
    foreach $_ ( @::ScmPlatformArgs ) {
58
        if (/^--product=(.*)/) {                # GBE product
59
 
60
        } else {
61
            Message( "verix: unknown platform argument $_ -- ignored" );
62
        }
63
    }
64
 
65
 
66
#.. Standard.rul requirements
67
#
68
    $::s = 'asm';                           # Assembler source file
69
    $::o = 'o';                             # Object file
70
    $::a = 'a';                             # Library file - Cannot build
71
    $::so = '';                             # Shared library - Not Supported
72
    $::exe = '.out';                        # Executables
73
 
74
#.. Toolset configuration
75
#
76
    $::ScmToolsetVersion = "1.0.0";         # our version
77
    $::ScmToolsetGenerate = 0;              # generate optional
78
    $::ScmToolsetProgDependancies = 0;      # handle Prog dependancies myself
79
 
80
#.. Define VERIX environment
81
#
82
    #
83
    #   Define initialisation targets
84
    #   These will be used to ensure that correct versions of the toolset are present
85
    #
86
    Init( "verix" );
87
 
88
    ToolsetDefine ( "#################################################" );
89
    ToolsetDefine ( "# VERIX V compiler version" );
90
    ToolsetDefine ( "#" );
91
    ToolsetDefine ( "#" );
92
    ToolsetDefines( "VERIX.DEF" );
93
    ToolsetRules  ( "VERIX.RUL" );
94
    ToolsetRules  ( "STANDARD.RUL" );
95
 
96
    #
97
    #   Other toolsets used
98
    #
99
    PlatformDefine ("LINT_COFILE\t= verix.LNT");
100
    PlatformDefine ("LINT_PRJ_FILE\t=lint.vrx");
101
    ToolsetRequire( "pclint" );                 # using pclint
102
 
103
 
104
#.. Extend the CompilerOption directive
105
#   Create a standard data structure
106
#   This is a hash of hashes
107
#       The first hash is keyed by CompileOption keyword
108
#       The second hash contains pairs of values to set or remove
109
#
110
    %::ScmToolsetCompilerOptions =
111
    (
112
        'systemlib='          => { 'VRX_SYSLIBS'  ,\&AddList }, # Extend System Libs
113
        'incpath='            => { 'VRX_INCPATH'  ,\&AddList }, # Extend Inc Path
114
        'nowarn='             => { 'NOWARNLIST'   ,\&NoWarns }, # Suppress warnings
115
        'timeoptimization'    => { 'OPT_MODE' , 'time'  },      # Time optimize
116
        'spaceoptimization'   => { 'OPT_MODE' , 'space' },      # Space optimize
117
        'defaultoptimization' => { 'OPT_MODE' , undef },        # Default (?space)
118
        'noaddlibs'           => { 'ADDLINKLIBS' , undef },     # Don't add link libs
119
        'addlibs'             => { 'ADDLINKLIBS' , '1' },       # default
120
    );
121
 
122
 
123
    #
124
    #   Set default options
125
    #       $::ScmCompilerOpts{'xxxx'} = 'yyy';
126
    #
127
    $::ScmCompilerOpts{'VRX_SYSLIBS'} = [];
128
    $::ScmCompilerOpts{'VRX_INCPATH'} = [];
129
    $::ScmCompilerOpts{'NOWARNLIST'}  = '';
130
    $::ScmCompilerOpts{'OPT_MODE'}    = 'space';
131
    $::ScmCompilerOpts{'ADDLINKLIBS'} = '1';
132
 
133
}
134
 
135
#-------------------------------------------------------------------------------
136
# Function        : AddList
137
#
138
# Description     : Add a path to a list
139
#
140
# Inputs          : $key        - Name of the Option
141
#                   $value      - Option Value. Comma sep list of paths
142
#                   $ukey       - User key (within $::ScmCompilerOpts)
143
#
144
# Returns         : New sting to save
145
#
146
sub AddList
147
{
148
    my ($key, $value, $ukey) = @_;
149
    push  @{$::ScmCompilerOpts{$ukey}} , '$(VERIX)/' . $value;
150
    return $::ScmCompilerOpts{$ukey};
151
}
152
 
153
#-------------------------------------------------------------------------------
154
# Function        : NoWarns
155
#
156
# Description     : ScmToolsetCompilerOptions  extension function
157
#                   Accumulates the NoWarn options as a comma seperated list
158
#
159
# Inputs          : $key        - Name of the Option
160
#                   $value      - Option Value. Comma sep list of numbers
161
#                   $ukey       - User key (within $::ScmCompilerOpts)
162
#
163
# Returns         : New sting to save
164
#
165
sub NoWarns
166
{
167
    my ($key, $value, $ukey) = @_;
168
    my @NoWarnList =  split (',', $::ScmCompilerOpts{$ukey});
169
    UniquePush ( \@NoWarnList, split (',', $value) );
170
    return join ',', @NoWarnList;
171
}
172
 
173
 
174
 
175
###############################################################################
176
#   ToolsetCC( $source, $obj, \@args )
177
#       This subroutine takes the user options and builds the rule(s)
178
#       required to compile the source file 'source' to 'obj'
179
#
180
#
181
###############################################################################
182
 
183
sub ToolsetCC
184
{
185
    ToolsetCC_common( "CC", @_ );
186
}
187
 
188
###############################################################################
189
#   ToolsetCCDepend( $depend, \@sources )
190
#       This subroutine takes the user options and builds the
191
#       rule(s) required to build the dependencies for the source
192
#       files 'sources' to 'depend'.
193
#
194
###############################################################################
195
 
196
sub ToolsetCCDepend
197
{
198
    MakePrint( "\t\$(CCDEPEND)\n" );
199
}
200
 
201
 
202
###############################################################################
203
#   ToolsetCXX( $source, $obj, \@args )
204
#       This subroutine takes the user options and builds the rule(s)
205
#       required to compile the source file 'source' to 'obj'
206
#
207
###############################################################################
208
 
209
sub ToolsetCXX
210
{
211
    ToolsetCC_common( "CXX", @_ );
212
}
213
 
214
###############################################################################
215
#   ToolsetCXXDepend( $depend, \@sources )
216
#       This subroutine takes the user options and builds the
217
#       rule(s) required to build the dependencies for the source
218
#       files 'sources' to 'depend'.
219
#
220
###############################################################################
221
 
222
sub ToolsetCXXDepend
223
{
287 dpurdie 224
    ToolsetCCDepend();
261 dpurdie 225
}
226
 
227
###############################################################################
228
#   ToolsetCXX( $name, $source, $obj, $pArgs )
229
#       This subroutine takes the user options and builds the rule(s)
230
#       required to compile the source file 'source' to 'obj'
231
#
232
###############################################################################
233
 
234
sub ToolsetCC_common
235
{
236
    my( $name, $source, $obj, $pArgs ) = @_;
237
 
238
 
239
    #
240
    #   Mark any 'lst' file for deletion
241
    #
242
    ToolsetGenerate( "\$(OBJDIR)/$obj.lst" );
243
 
244
    #
245
    #   Simple rule to create object file
246
    #
247
    MakePrint( "\n\t\$($name)\n" );
248
}
249
 
250
 
251
 
252
###############################################################################
253
#   ToolsetAS( $source, $obj, \@args )
254
#       This subroutine takes the user options and builds the rule(s)
255
#       required to compile the source file 'source' to 'obj'
256
#
257
###############################################################################
258
 
259
sub ToolsetAS
260
{
261
    MakePrint( "\n\t\$(AS)\n" );
262
}
263
 
264
sub ToolsetASDepend
265
{
266
}
267
 
268
#-------------------------------------------------------------------------------
269
# Function        : ToolsetAR
270
#
271
# Description     : Build rules to create a static library
272
#
273
# Inputs          : $name   - Name of the output library
274
#                   $pArgs  - Library arguments
275
#                   $pObjs  - Objects to go into the library
276
#
277
# Returns         : Nothing
278
#
279
 
280
sub ToolsetAR
281
{
282
    my( $name, $pArgs, $pObjs ) = @_;
283
 
284
#.. Parse arguments
285
#
286
    foreach $_ ( @$pArgs )
287
    {
288
        Message( "AR: unknown option $_ -- ignored\n" );
289
    }
290
 
291
#.. Target
292
#
293
    MakePrint( "#.. Library ($name)\n\n" );     # label
294
 
295
    MakeEntry( "\$(LIBDIR)/$name\$(GBE_TYPE).$::a:\t",
296
        "", "\\\n\t\t", ".$::o", @$pObjs );
297
 
298
#.. Build library rule (just append to standard rule)
299
#
300
    MakePrint( "\n\t\$(AR)\n\n" );
301
}
302
 
303
#-------------------------------------------------------------------------------
304
# Function        : ToolsetARMerge
305
#
306
# Description     : This subroutine takes the user options and builds the rules
307
#                   required to build the library 'name' by merging the specified
308
#                   libaries
309
#
310
# Inputs          : $name   - Name of the output library
311
#                   $pArgs  - Library arguments
312
#                   $pLibs  - Libraries to be merged
313
#
314
# Returns         : Nothing
315
#
316
# Returns         : 
317
#
318
 
319
sub ToolsetARMerge
320
{
321
    MakePrint( "\n\t\$(ARMERGE)\n\n" );
322
}
323
 
324
#-------------------------------------------------------------------------------
325
#   ToolsetLD( $name, \@pArgs, \@pObjs, \@pLibs )
326
#       This subroutine takes the user options and builds the rules
327
#       required to link the program 'name'.
328
#
329
#   Toolset is configured to suppress partial creation of the Package
330
#   Rules. This function must create the complete rule and recipe set.
331
#
332
#   Arguments:
333
#       $name           - Name of the output
334
#       $pArgs          - Ref to array of args
335
#       $pObjs          - Ref to array of objects
336
#       $pLibs          - Ref to array of libs
337
#
338
#  Options:
339
#       --NoAddLibs     - Do not add system libraries
340
#       --AddLibs       - Do add system libraries (default -ish)
341
#
342
#       --Map           - Add Map File
343
#       --NoMap         - No Map File (Default)
344
#       --Sign          - Sign file for RAM   - Default certificate name
345
#       --Sign=xxxx     - Sign file for RAM   - Name the certificate
346
#       --SignFlash      - Sign file for Flash - Default certificate name
347
#       --SignFlash=xxxx - Sign file for Flash - Name the certificate
348
#
349
#       --Heap=nnnn     - Set heap size
350
#       --Stack=nnnn    - Set Stack Size
351
#       --Flags=nnnn    - Set flags
352
#       --Debugable     - Mark as debugable
353
#       --NoDebugable   - Mark as non-debugable
354
#       --Version=n.n   - Set version
355
#       --Version       - Use Build Major, Minor
356
#       --ShowHeader    - Just show the header
357
#       --NoShowHeader  - Default
358
#
359
#   Output:
360
#       Generates makefile rules and recipes to create a program
361
#
362
 
363
sub ToolsetLD
364
{
365
    my( $name, $pArgs, $pObjs, $pLibs ) = @_;
366
 
367
    my $addlibs = $::ScmCompilerOpts{'ADDLINKLIBS'} ;
368
    my $map_file;
369
    my $certificate;
370
    my $flash;
371
 
372
    my $header;
373
    my $heap;
374
    my $stack;
375
    my $flags;
376
    my $debugable = 0;
377
    my $version;
378
 
379
#.. Parse arguments
380
#
381
 
382
    foreach ( @$pArgs )
383
    {
384
        if ( m{^--(No)?AddLib}i ) {
385
            $addlibs = ! $1;
386
 
387
        } elsif ( m {^--Sign(=(.+))?}i  ) {
388
            $certificate = $2 ? $2 : $name;
389
            $flash = 0;
390
 
391
        } elsif ( m {^--SignFlash(=(.+))?}i  ) {
392
            $certificate = $2 ? $2 : $name;
393
            $flash = 1;
394
 
395
        } elsif ( m {^--(No)?Map}i  ) {
396
            $map_file = ! $1;
397
 
398
        } elsif ( m {^--(No)?ShowHeader}i  ) {
399
            $header = ! $1;
400
 
401
        } elsif ( m {^--Heap=(\d+)}i  ) {
402
            $heap = $1;
403
 
404
        } elsif ( m {^--Stack=(\d+)}i  ) {
405
            $stack = $1;
406
 
407
        } elsif ( m {^--Flags=(\d+)}i  ) {
408
            $flags = $1;
409
            Error ("Header Flags must be in the range 0 ..255") if ( $flags > 255 );
410
 
411
        } elsif ( m {^--(No)?Debug}i  ) {
412
            $debugable = $1 ? 2 : 1;
413
 
414
        } elsif ( m {^--Version(=(.+))?}i  ) {
415
            my $major;
416
            my $minor;
417
 
418
            if ( $2 )
419
            {
420
                $version = $2;
421
                Error ("LD: Version must be in the form m.n") unless ( $version =~ m~(\d+)\.(\d+)~ );
422
                ( $major, $minor) = ($1, $2);
423
            }
424
            else
425
            {
426
                ($major, $minor) = SplitVersion($ScmBuildVersionFull);
427
                $version = "$major.$minor";
428
            }
429
            Error ("LD: Version number($version). Major number must be in the range 0 .. 255" ) if ( $major > 255 );
430
            Error ("LD: Version number($version). Minor number must be in the range 0 .. 255" ) if ( $minor > 255 );
431
 
432
        } else {
433
            Error( "LD: unknown option $_ -- ignored\n" );
434
        }
435
    }
436
 
437
    #
438
    #   Determine the target output name
439
    #
440
    my $root = "\$(BINDIR)/$name";
441
    my $full = $root . $::exe;
442
    my $map  = $root . '.map';
443
 
444
    #.. Packageing
445
    #   Have supressed default Prog building
446
    #   Need to specify the files to Package
447
    #
448
    PackageProgAddFiles ( $name, $full );
449
    PackageProgAddFiles ( $name, $map, 'Class=map' ) if $map_file;
450
 
451
 
452
    #.. Cleanup rules
453
    #
454
    ToolsetGenerate( $map );
455
    ToolsetGenerate( "$root.axf" );
456
    ToolsetGenerate( "$root.srt" );
457
    ToolsetGenerate( "$root.bak" );
458
 
459
    #
460
    #   Add standard system libraries to the complete list of libraries
461
    #
462
    push @$pLibs, 'ACT2000' if ( $addlibs );
463
 
464
    #.. Build rules
465
    #
466
    my ($io) = ToolsetPrinter::New();
335 dpurdie 467
    my $dep = $io->SetLdTarget( $name );
261 dpurdie 468
 
469
    #.. Dependency link,
335 dpurdie 470
    #   Create a library dependency file
471
    #       Create command file to build applicaton dependency list
472
    #       from the list of dependent libraries
261 dpurdie 473
    #
335 dpurdie 474
    #       Create makefile directives to include the dependency
475
    #       list into the makefile.
261 dpurdie 476
    #
335 dpurdie 477
    $io->DepRules( $pLibs, \&ToolsetLibRecipe );        # library depends rules
478
    $io->LDDEPEND();                                    # standard LDDEPEND rules
261 dpurdie 479
 
480
    #
481
    #   List the object files
482
    #   Create a definition for the objects
483
    #
335 dpurdie 484
    $io->Label( "Object files", $name );                # label
261 dpurdie 485
    $io->StartDef ("${name}_obj");
486
    $io->ObjList( $name, $pObjs, \&ToolsetObjRecipe );
487
    $io->EndDef ();
488
    $io->Newline();
489
 
490
    #
491
    #   Define the program and its dependencies
492
    #   Place the .dep file first - this will ensure that failure
493
    #   to create this file will create an error before the object
494
    #   files are compiled. This makes it obvious what the error is.
495
    #
496
    $io->Label( "Program", $name );                     # label
497
    $io->Prt( "$full : \t$dep" );                       # Dependencies
498
    $io->Prt( "\\\n\t\$(${name}_obj)" .
499
              " \\\n\t\$(${name}_lib)\n" );
500
 
501
    #
502
    #   Recipe to build the program
503
    #
504
    $io->PrtLn( "\t\$(LD)" );
505
 
506
    #
507
    #   Append header modification recipe entries
508
    #
509
    $io->PrtLn( "\t\$(call HEADER,-q -v $version,\"Set Version: $version\")" ) if $version;
510
    $io->PrtLn( "\t\$(call HEADER,-q -s $stack,\"Set stack: $stack\")" ) if $stack;
511
    $io->PrtLn( "\t\$(call HEADER,-q -h $heap,\"Set Heap: $heap\")" ) if $heap;
512
    $io->PrtLn( "\t\$(call HEADER,-q -f $flags,\"Set Flags: $flags\")" ) if defined $flags;
513
    $io->PrtLn( "\t\$(call HEADER,-q -d,\"Mark Debugable\")" ) if $debugable == 1;
514
    $io->PrtLn( "\t\$(call HEADER,-q -n,\"Mark Non Debuggable\")" )if $debugable == 2;
515
    $io->PrtLn( "\t\$(call HEADER,,\"Show Header\")" ) if $header;
516
    $io->PrtLn( "");
517
 
518
 
519
    #.. Linker command file
520
    #
521
    #       Create a variable $(name_ld) which will be the linker
522
    #       command line. Use previosly defined values
523
    #
524
    $io->Label( "Linker commands", $name );         # label
525
    $io->StartDef ("${name}_ld");
526
    $io->Def( "\$(${name}_obj)" );                  # Object file list variable
527
    $io->Def( "\$(${name}_lib)" );                  # Library list variable
528
    $io->EndDef ();
529
    $io->Newline();
530
 
531
    #.. Sign the output file
532
    #
533
    #
534
    if ( $certificate )
535
    {
536
 
537
        my $cert = "\$(BINDIR)/$certificate.crt";
538
        my $sign = "$full.P7S";
539
        my $opts =  $flash ? '-L' : '';
540
 
541
        #
542
        #   Mark files to be built and packaged as a part of the program
543
        #
544
        ProgAddExtra ($name, $sign );
545
        PackageProgAddFiles ( $name, $sign );
546
        PackageProgAddFiles ( $name, $cert );
547
 
548
        #
549
        #   Create rule to sign the program
550
        #
551
        $io->Label( "Sign Program", $name );        # label
552
        $io->PrtLn( "$sign : $full" );
553
        $io->PrtLn( "\t\$(call FILESIGNATURE,$full,$cert,$opts)" );
554
 
555
        #
556
        #   File to clean up
557
        #
558
        ToolsetGenerate ( $sign );
559
        ToolsetGenerate ( $cert );
560
    }
561
 
562
}
563
 
564
 
565
########################################################################
566
#
567
#   Generate a linker object recipe.  This is a helper function used 
568
#   within this toolset.
569
#
570
#   Arguments:
571
#       $io         I/O stream
572
#
573
#       $target     Name of the target
574
#
575
#       $obj        Library specification
576
#
577
########################################################################
578
 
579
sub ToolsetObjRecipe
580
{
581
    my ($io, $target, $obj) = @_;
582
 
583
    $io->Def( "$obj.$::o" );
584
}
585
 
586
 
587
###############################################################################
588
#
589
#   Parse a linker lib list
590
#   This is a helper function used within this toolset
591
#
592
#   Used to create a variable that will be fedd into 'cmdfile'
593
#   The output will then be included in the makefile
594
#   The output extends the definitions of the program being built
595
#   to contain the absolute pathnames to the libraries being consumed.
596
#
597
#   Arguments:
598
#       $io         io printer class
599
#
600
#       $target     Name of the target
601
#
602
#       $lib        Library specification
603
#
604
###############################################################################
605
 
606
sub ToolsetLibRecipe
607
{
608
    my ($io, $target, $lib) = @_;
609
 
610
    $io->Cmd( "${target}_lib += @(vglob2,$lib.$::a,LIB)" );
611
}
612
 
613
#.. Successful termination
614
1;
615