Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
369 dpurdie 1
########################################################################
2
# Copyright (C) 1998-2011 Vix Technology, All rights reserved
3
#
4
# Module name   : MSP430.PL
5
# Module type   : Makefile system
6
# Compiler(s)   : Perl
7
# Environment(s): jats
8
#
9
# Description   : Toolset for the Texas Instruments CC Studio
10
#
11
#......................................................................#
12
 
13
use strict;
14
use JatsVersionUtils;
15
 
16
our $s;
17
our $o;
18
our $so;
19
our $exe;
20
our $tool_vxp430img;
383 dpurdie 21
our $itp_mode;
369 dpurdie 22
 
23
##############################################################################
24
#   ToolsetInit()
25
#       Runtime initialisation
26
#
27
##############################################################################
28
 
29
ToolsetInit();
30
 
31
sub ToolsetInit
32
{
33
    my( $version, $product, @defines, @dirs, @flags, @asflags, @asdefines );
34
 
35
    #.. Parse Toolset Arguments
36
    #
37
    Debug( "msp430(@::ScmToolsetArgs)\n" );
38
 
39
    foreach $_ ( @::ScmToolsetArgs ) {
40
        if (/^--Version=(.*)/) {                # Compiler version
41
            $version = "$1";
383 dpurdie 42
        } elsif ( /^--itp/ ) {
43
            $itp_mode = 1;
369 dpurdie 44
        } else {
45
            Message( "msp430: unknown toolset argument $_ -- ignored\n" );
46
        }
47
    }
48
 
49
    #.. Parse Platform Arguments
50
    #
51
    foreach $_ ( @::ScmPlatformArgs ) {
52
        Message( "msp430: unknown platform argument $_ -- ignored\n" );
53
    }
54
 
55
 
56
    #.. Standard.rul requirements
57
    #
58
    $s = 'asm';             # Assembler source file
59
    $o = 'obj';             # Object file
60
    $a = 'lib';             # Library file
61
    $so = '';               # Shared library
62
    $exe = '.out';          # Linked binary images
63
 
64
    AddSourceType( ".$s", '.asm' );
65
 
66
 
67
    #.. Toolset configuration
68
    #
69
    $::ScmToolsetVersion = "1.0.0";               # our version
70
    $::ScmToolsetGenerate = 0;                    # generate optional
71
    $::ScmToolsetProgDependancies = 0;            # handle Prog dependancies myself
72
 
73
#.. Cleanup rules
74
#
75
#
76
#    ToolsetGenerate( "SomeFile" );
77
 
78
 
79
    #.. Define toolchain environment
80
    #
81
    #
82
    #   Define initialisation targets
83
    #   These will be used to ensure that correct versions of the toolset are present
84
    #
85
    Init( "msp430" );
86
 
87
    ToolsetDefine ( "#################################################" );
88
    ToolsetDefine ( "# MSP430 compiler version" );
89
    ToolsetDefine ( "#" );
90
    ToolsetDefine ( "msp430_ver         = $version" );
91
    ToolsetDefine ( "" );
92
    ToolsetDefine ( "#" );
93
    ToolsetDefines( "msp430.def" );
94
    ToolsetRules  ( "msp430.rul" );
95
    ToolsetRules  ( "standard.rul" );
96
 
383 dpurdie 97
    # Support for ITP
98
    ToolsetDefine ( "ITP_MODE = 1" )    if $itp_mode;
99
 
369 dpurdie 100
}
101
 
102
 
103
##############################################################################
104
#   ToolsetPreprocess()
105
#       Process collected data before the makefile is generated
106
#       This, optional, routine is called from within MakefileGenerate()
107
#       It allows the toolset to massage any of the collected data before
108
#       the makefile is created
109
#
110
##############################################################################
111
 
112
#sub ToolsetPreprocess
113
#{
114
#}
115
 
116
###############################################################################
117
#   ToolsetCC( $source, $obj, \@args )
118
#       This subroutine takes the user options and builds the rule(s)
119
#       required to compile the source file 'source' to 'obj'
120
#
121
###############################################################################
122
 
123
sub ToolsetCC
124
{
125
    MakePrint( "\n\t\$(CC)\n" );
126
 
127
    #
128
    #   Mark generated assembler files to be deleted
129
    #
130
    ToolsetGenerate( "\$(OBJDIR)/$_[1].asm" );
131
}
132
 
133
###############################################################################
134
#   ToolsetCCDepend( $depend, \@sources )
135
#       This subroutine takes the user options and builds the
136
#       rule(s) required to build the dependencies for the source
137
#       files 'sources' to 'depend'.
138
#
139
###############################################################################
140
 
141
sub ToolsetCCDepend
142
{
143
    MakePrint( "\t\$(CCDEPEND)\n" );
144
}
145
 
146
 
147
###############################################################################
148
#   ToolsetCXX( $source, $obj, \@args )
149
#       This subroutine takes the user options and builds the rule(s)
150
#       required to compile the source file 'source' to 'obj'
151
#
152
###############################################################################
153
 
154
sub ToolsetCXX
155
{
156
    MakePrint( "\n\t\$(CC)\n" );
157
}
158
 
159
###############################################################################
160
#   ToolsetCXXDepend( $depend, \@sources )
161
#       This subroutine takes the user options and builds the
162
#       rule(s) required to build the dependencies for the source
163
#       files 'sources' to 'depend'.
164
#
165
###############################################################################
166
 
167
sub ToolsetCXXDepend
168
{
169
    ToolsetCCDepend();
170
}
171
 
172
 
173
###############################################################################
174
#   ToolsetAS( $source, $obj, \@args )
175
#       This subroutine takes the user options and builds the rule(s)
176
#       required to compile the source file 'source' to 'obj'
177
#
178
###############################################################################
179
 
180
sub ToolsetAS
181
{
182
    MakePrint( "\n\t\$(CC)\n" );
183
}
184
 
185
sub ToolsetASDepend
186
{
187
}
188
 
189
###############################################################################
190
#   ToolsetAR( $name, \@args, \@objs )
191
#       This subroutine takes the user options and builds the rules
192
#       required to build the library 'name'.
193
 
194
#
195
#   Arguments:
196
#       --xxx                   No arguments currently defined
197
#
198
#   Output:
199
#       [ $(BINDIR)/name$.${a}:   .... ]
200
#           $(AR)
201
#
202
###############################################################################
203
 
204
sub ToolsetAR
205
{
206
    my( $name, $pArgs, $pObjs ) = @_;
207
 
208
    Debug("ToolsetAR");
209
 
210
#.. Parse arguments
211
#
212
    foreach $_ ( @$pArgs ) {
213
        if (/^--/) {
214
            Message( "AR: unknown option $_ -- ignored\n" );
215
        }
216
    }
217
 
218
#.. Target
219
#
220
    MakeEntry( "\$(LIBDIR)/$name\$(GBE_TYPE).${a}:\t", "", " \\\n\t\t", ".${o}", @$pObjs );
221
 
222
#.. Build library rule (just append to standard rule)
223
#
224
    MakePrint( "\n\t\$(AR)\n\n" );
225
}
226
 
227
 
228
###############################################################################
229
#   ToolsetARMerge()
230
#       Generate the recipe to merge libraries.
231
#       The dependency list is created by the caller.
232
#
233
###############################################################################
234
 
235
#sub ToolsetARMerge
236
#   Currently not supported
237
#   Add only if required
238
#
239
#{
240
#    MakePrint( "\n\t\$(ARMERGE)\n\n" );
241
#}
242
 
243
 
244
###############################################################################
245
#   ToolsetLD( $name, \@args, \@objs, \@libraries )
246
#       This subroutine takes the user options and builds the rules
247
#       required to link the program 'name'.
248
#
249
#   Arguments:
250
#       --xxx                   No Arguments currently specified
251
#
252
#       Linker specific:
253
#       --Script=filename   Specify the name of a linker script file
254
#       --NoImg             Do not create IMG file, only COFF
255
#
256
#   Output:
257
#
258
#       name.map                - Map file
259
#       name.???
260
#       name.???
261
#       name.???
262
#
263
###############################################################################
264
 
265
sub ToolsetLD
266
{
267
    my( $name, $pArgs, $pObjs, $pLibs ) = @_;
371 dpurdie 268
    my $progName = $name;
269
    my $script;
383 dpurdie 270
    my $img_file = 1 unless $itp_mode;
371 dpurdie 271
    my $noVersion;
369 dpurdie 272
 
273
 
274
#.. Parse arguments
275
#
276
    foreach $_ ( @$pArgs )
277
    {
278
    #.. Target specific
279
    #
280
 
281
    #.. Toolset specific
282
    #
283
        if (/^--Script=(.*)/) {           # External file
284
            $script = $1;
285
            $script .= ".cmd" unless ( $script =~ m~\.cmd$~ );
286
 
287
        } elsif (/^--NoImg/i ) {
288
            $img_file = undef;
289
 
371 dpurdie 290
        } elsif (/^--NoVersion/i ) {
291
            $noVersion = 1;
292
 
369 dpurdie 293
        } else {
294
            Message( "Prog: unknown option $_ -- ignored\n" );
295
        }
296
    }
297
 
298
#
299
#   Sanity check
300
#       - Ensure a linker script has been provided
301
#
302
unless ( $script )
303
{
383 dpurdie 304
    $script = "$name.cmd";
369 dpurdie 305
    Warning( "Prog: Linker Script file not provided. Using $script" );
306
}
307
 
308
#
309
#   Locate the true path of the provided script file
310
#   If it is a generate file so it will be in the SRCS hash
311
#   Other wise the use will have to use Src to locate the file
312
#
313
    $script = MakeSrcResolve ( $script );
314
 
315
#
316
#   If creating an IMG file, then ensure that the tools are available
317
#
318
if ( $img_file )
319
{
320
    unless ( defined $tool_vxp430img )
321
    {
322
        $tool_vxp430img = ToolExtensionProgram( 'vxp430img', '.exe', '' );
323
        if ( $tool_vxp430img )
324
        {
325
            MakePrint ( "#################################################\n" );
326
            MakePrint ( "#  The path to tools required to build programs\n" );
327
            MakePrint ( "#\n" );
328
            MakePrint ( "TOOL_VXP430IMG := $tool_vxp430img\n" );
329
            MakePrint ( "\n" );
330
        }
331
        else
332
        {
333
            Error( 'Tool program required by toolset not found:',
334
                   'vxp430img',
335
                   'Check that the vxp430img package is present' );
336
        }
337
    }
338
}
339
 
340
#
371 dpurdie 341
#   Insert version number into the output name
342
#
343
    unless ( $noVersion )
344
    {
345
        $name .= "_\$(BUILDVERNUM)";
346
    }
347
 
348
#
369 dpurdie 349
#   Create a ToolsetPrinter
350
#
351
    my ($io) = ToolsetPrinter::New();
352
    my $dep = $io->SetLdTarget( $name );
353
 
354
#
371 dpurdie 355
#   Determine the target output name(s)
369 dpurdie 356
#
371 dpurdie 357
    my $root = "\$(BINDIR)/${name}";
358
    my $phonyProgName = "\$(BINDIR)/${progName}" . $::exe;
369 dpurdie 359
    my $full = $root . $::exe;
360
    my $img = $img_file ? $root . '.img' : '';
371 dpurdie 361
    my $hex = $root . '.hex';
369 dpurdie 362
    my $map = $root . '.map';
363
 
364
#
365
#   Add runtime support libaries
366
#   These are transparent to the user
367
#
368
    push @$pLibs, 'libc.a';
369
 
370
########################################################################
371
#
372
#   Before this function was called, makelib.pl2 has generated a
373
#   partial rule consisting of:
374
#
375
#       $(BINDIR)/${name}${exe} :
376
#               All the specified object files
377
#
378
#   Add the names of all the other files required in the process
379
#   This will then serve as a target fo all things that need to be
380
#   created when a "program" is required
381
#
382
#       These are:
383
#               User linker script file
384
#               Library dependency file
371 dpurdie 385
#
386
    unless ( $noVersion )
387
    {
388
        $io->Label( "Program", $progName );                     # label
389
        $io->Prt( ".PHONY:\t$phonyProgName\n" );                # Mark as phony
390
        $io->Prt( "$phonyProgName: \t$full\n" );                # Dependencies
391
        $io->Newline();
392
    }
393
 
394
    #
395
    #   Rules to generate the program
396
    #
369 dpurdie 397
    $io->Label( "Program", $name );                     # label
398
    $io->Prt( "$full $img: \t$dep" );                   # Dependencies
399
    $io->Prt( "\\\n\t\t$script" );
400
    $io->Entry( "", "", "\\\n\t", ".$::o ", @$pObjs );  # Object Files
401
    $io->Prt( "\n\t\$(LD)" );
402
    $io->Prt( "\n\t\$(call COFF2IMG,$full,$img,\$(BUILDVER))\n" ) if ($img);
403
    $io->Newline();
404
 
405
    #
406
    #   Specify files created by the linker
407
    #   These will be added to the clean list
408
    #
371 dpurdie 409
    ToolsetGenerate( $full );
369 dpurdie 410
    ToolsetGenerate( $map );
411
    ToolsetGenerate( $root . '.ld' );
412
    if ( $img )
413
    {
414
        ToolsetGenerate( $img );
371 dpurdie 415
        ToolsetGenerate( $hex );
369 dpurdie 416
    }
417
 
418
    #
419
    #   Create a linker command file
420
    #   Piecing together a variable $(name_ld) which ends up in the command file.
421
    #   This bit of magic will be performed by the LD recipe
422
    #
423
    $io->SetTag( "${name}_ld" );                            # macro tag
424
    $io->Label( "Linker commands", $name );                 # label
425
    $io->Cmd("--stack_size=160");
426
    $io->Cmd("--heap_size=160");
427
    $io->Cmd("--use_hw_mpy=F5");
428
    $io->Cmd("-o $full" );                                  # Output file
429
    $io->Cmd("-m $map" );                                   # Map file
430
    $io->Cmd("--warn_sections" );                           # Warn if creating unused sections
431
    $io->Cmd("--entry_point=main" );                        # Fixed entry point
432
    $io->Cmd("--reread_libs" );                             # Multipass on lib files
433
    $io->Cmd("-l $script" );                                # User script file
434
 
435
    $io->ObjList( $name, $pObjs, \&ToolsetObjRecipe );      # Object files
436
 
437
    #
438
    #   Specify the library files
439
    #
440
    $io->LibList( $name, $pLibs, \&ToolsetLibRecipe );      # Specify the libraries too
441
    $io->Newline();
442
 
443
    #.. Dependency link,
444
    #   Create a library dependency file
445
    #       Create command file to build applicaton dependency list
446
    #       from the list of dependent libraries
447
    #
448
    #       Create makefile directives to include the dependency
449
    #       list into the makefile.
450
    #
451
    $io->DepRules( $pLibs, \&ToolsetLibRecipe, $full );
452
    $io->LDDEPEND(); 
453
 
454
    #
455
    #   Add the MAP file to the program package
456
    #
371 dpurdie 457
    PackageProgAddFiles ( $progName, $full );
458
    PackageProgAddFiles ( $progName, $img ) if ($img);
459
    PackageProgAddFiles ( $progName, $hex ) if ($img);
460
    PackageProgAddFiles ( $progName, $map , 'Class=map' );
369 dpurdie 461
}
462
 
463
########################################################################
464
#
465
#   Generate a linker object recipe.  This is a helper function used 
466
#   within this toolset.
467
#
468
#   Arguments:
469
#       $io         I/O stream
470
#
471
#       $target     Name of the target
472
#
473
#       $obj        Library specification
474
#
475
########################################################################
476
 
477
sub ToolsetObjRecipe
478
{
479
    my ($io, $target, $obj) = @_;
480
 
481
    $io->Cmd("$obj.$::o" );
482
}
483
 
484
########################################################################
485
#
486
#   Generate a linker/depend library recipe.  This is a helper function
487
#   used within this toolset.
488
#
489
#   Arguments:
490
#       $io         I/O stream
491
#
492
#       $target     Name of the target
493
#
494
#       $lib        Library specification
495
#
496
#       $dp         If building a depend list, the full target name.
497
#
498
########################################################################
499
 
500
sub ToolsetLibRecipe
501
{
502
    my ($io, $target, $lib, $dp) = @_;
503
 
504
    #
505
    #   Run time libraries will have a .a suffix
506
    #   Do not append .lib if this is the case
507
    #
508
    $lib .= '.' . $::a unless ( $lib =~ m~\.a$~ );
509
 
510
 
511
    if ( !defined($dp) ) {                      # linker
512
        $io->Cmd("\"@(vpath2,\"$lib\",LIB,\\)\"" );
513
    } else {                                    # depend
514
        $io->Cmd( "$dp:\t@(vlib2,\"$lib\",LIB)" );
515
    }
516
}
517
 
518
#.. Successful termination
519
1;
520