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;
385 dpurdie 271
    my $hex_file = 1 if $itp_mode;
371 dpurdie 272
    my $noVersion;
369 dpurdie 273
 
274
 
385 dpurdie 275
 
369 dpurdie 276
#.. Parse arguments
277
#
278
    foreach $_ ( @$pArgs )
279
    {
280
    #.. Target specific
281
    #
282
 
283
    #.. Toolset specific
284
    #
285
        if (/^--Script=(.*)/) {           # External file
286
            $script = $1;
287
            $script .= ".cmd" unless ( $script =~ m~\.cmd$~ );
288
 
289
        } elsif (/^--NoImg/i ) {
290
            $img_file = undef;
291
 
385 dpurdie 292
        } elsif (/^--NoHex/i ) {
293
            $hex_file = undef;
294
 
371 dpurdie 295
        } elsif (/^--NoVersion/i ) {
296
            $noVersion = 1;
297
 
369 dpurdie 298
        } else {
299
            Message( "Prog: unknown option $_ -- ignored\n" );
300
        }
301
    }
302
 
303
#
304
#   Sanity check
305
#       - Ensure a linker script has been provided
306
#
385 dpurdie 307
Error ("Cannot generate 'image' and 'hex' at the same time") if $hex_file and $img_file;
369 dpurdie 308
unless ( $script )
309
{
383 dpurdie 310
    $script = "$name.cmd";
369 dpurdie 311
    Warning( "Prog: Linker Script file not provided. Using $script" );
312
}
313
 
314
#
315
#   Locate the true path of the provided script file
316
#   If it is a generate file so it will be in the SRCS hash
317
#   Other wise the use will have to use Src to locate the file
318
#
319
    $script = MakeSrcResolve ( $script );
320
 
321
#
322
#   If creating an IMG file, then ensure that the tools are available
323
#
324
if ( $img_file )
325
{
326
    unless ( defined $tool_vxp430img )
327
    {
328
        $tool_vxp430img = ToolExtensionProgram( 'vxp430img', '.exe', '' );
329
        if ( $tool_vxp430img )
330
        {
331
            MakePrint ( "#################################################\n" );
332
            MakePrint ( "#  The path to tools required to build programs\n" );
333
            MakePrint ( "#\n" );
334
            MakePrint ( "TOOL_VXP430IMG := $tool_vxp430img\n" );
335
            MakePrint ( "\n" );
336
        }
337
        else
338
        {
339
            Error( 'Tool program required by toolset not found:',
340
                   'vxp430img',
341
                   'Check that the vxp430img package is present' );
342
        }
343
    }
344
}
345
 
346
#
371 dpurdie 347
#   Insert version number into the output name
348
#
349
    unless ( $noVersion )
350
    {
351
        $name .= "_\$(BUILDVERNUM)";
352
    }
353
 
354
#
369 dpurdie 355
#   Create a ToolsetPrinter
356
#
357
    my ($io) = ToolsetPrinter::New();
358
    my $dep = $io->SetLdTarget( $name );
359
 
360
#
371 dpurdie 361
#   Determine the target output name(s)
369 dpurdie 362
#
371 dpurdie 363
    my $root = "\$(BINDIR)/${name}";
364
    my $phonyProgName = "\$(BINDIR)/${progName}" . $::exe;
369 dpurdie 365
    my $full = $root . $::exe;
366
    my $img = $img_file ? $root . '.img' : '';
371 dpurdie 367
    my $hex = $root . '.hex';
369 dpurdie 368
    my $map = $root . '.map';
369
 
370
#
371
#   Add runtime support libaries
372
#   These are transparent to the user
373
#
374
    push @$pLibs, 'libc.a';
375
 
376
########################################################################
377
#
378
#   Before this function was called, makelib.pl2 has generated a
379
#   partial rule consisting of:
380
#
381
#       $(BINDIR)/${name}${exe} :
382
#               All the specified object files
383
#
384
#   Add the names of all the other files required in the process
385
#   This will then serve as a target fo all things that need to be
386
#   created when a "program" is required
387
#
388
#       These are:
389
#               User linker script file
390
#               Library dependency file
371 dpurdie 391
#
392
    unless ( $noVersion )
393
    {
394
        $io->Label( "Program", $progName );                     # label
395
        $io->Prt( ".PHONY:\t$phonyProgName\n" );                # Mark as phony
396
        $io->Prt( "$phonyProgName: \t$full\n" );                # Dependencies
397
        $io->Newline();
398
    }
399
 
400
    #
401
    #   Rules to generate the program
402
    #
369 dpurdie 403
    $io->Label( "Program", $name );                     # label
385 dpurdie 404
    $io->Prt( "$full $img $hex: \t$dep" );                   # Dependencies
369 dpurdie 405
    $io->Prt( "\\\n\t\t$script" );
406
    $io->Entry( "", "", "\\\n\t", ".$::o ", @$pObjs );  # Object Files
407
    $io->Prt( "\n\t\$(LD)" );
408
    $io->Prt( "\n\t\$(call COFF2IMG,$full,$img,\$(BUILDVER))\n" ) if ($img);
385 dpurdie 409
    $io->Prt( "\n\t\$(call COFF2HEX,$full,$hex)\n" ) if ($hex_file);
369 dpurdie 410
    $io->Newline();
411
 
412
    #
413
    #   Specify files created by the linker
414
    #   These will be added to the clean list
415
    #
371 dpurdie 416
    ToolsetGenerate( $full );
369 dpurdie 417
    ToolsetGenerate( $map );
418
    ToolsetGenerate( $root . '.ld' );
385 dpurdie 419
    ToolsetGenerate( $hex ) if ( $img || $hex_file) ;
420
    ToolsetGenerate( $img ) if ($img );
369 dpurdie 421
 
422
    #
423
    #   Create a linker command file
424
    #   Piecing together a variable $(name_ld) which ends up in the command file.
425
    #   This bit of magic will be performed by the LD recipe
426
    #
427
    $io->SetTag( "${name}_ld" );                            # macro tag
428
    $io->Label( "Linker commands", $name );                 # label
385 dpurdie 429
    unless ( $itp_mode )
430
    {
431
        $io->Cmd("--stack_size=160");
432
        $io->Cmd("--heap_size=160");
433
        $io->Cmd("--use_hw_mpy=F5");
434
        $io->Cmd("--entry_point=main" );                        # Fixed entry point
435
    }
436
    else
437
    {
438
        $io->Cmd("--stack_size=50");
439
        $io->Cmd("--heap_size=0");
440
#        $io->Cmd("--symdebug:dwarf");
441
        $io->Cmd("--rom_model");
369 dpurdie 442
 
385 dpurdie 443
    }
444
        $io->Cmd("--warn_sections" );                           # Warn if creating unused sections
445
        $io->Cmd("-o $full" );                                  # Output file
446
        $io->Cmd("-m $map" );                                   # Map file
447
        $io->Cmd("--reread_libs" );                             # Multipass on lib files
448
        $io->Cmd("-l $script" );                                # User script file
449
 
369 dpurdie 450
    $io->ObjList( $name, $pObjs, \&ToolsetObjRecipe );      # Object files
451
 
452
    #
453
    #   Specify the library files
454
    #
455
    $io->LibList( $name, $pLibs, \&ToolsetLibRecipe );      # Specify the libraries too
456
    $io->Newline();
457
 
458
    #.. Dependency link,
459
    #   Create a library dependency file
460
    #       Create command file to build applicaton dependency list
461
    #       from the list of dependent libraries
462
    #
463
    #       Create makefile directives to include the dependency
464
    #       list into the makefile.
465
    #
466
    $io->DepRules( $pLibs, \&ToolsetLibRecipe, $full );
467
    $io->LDDEPEND(); 
468
 
469
    #
470
    #   Add the MAP file to the program package
471
    #
371 dpurdie 472
    PackageProgAddFiles ( $progName, $full );
473
    PackageProgAddFiles ( $progName, $img ) if ($img);
385 dpurdie 474
    PackageProgAddFiles ( $progName, $hex ) if ($img || $hex_file );
371 dpurdie 475
    PackageProgAddFiles ( $progName, $map , 'Class=map' );
369 dpurdie 476
}
477
 
478
########################################################################
479
#
480
#   Generate a linker object recipe.  This is a helper function used 
481
#   within this toolset.
482
#
483
#   Arguments:
484
#       $io         I/O stream
485
#
486
#       $target     Name of the target
487
#
488
#       $obj        Library specification
489
#
490
########################################################################
491
 
492
sub ToolsetObjRecipe
493
{
494
    my ($io, $target, $obj) = @_;
495
 
496
    $io->Cmd("$obj.$::o" );
497
}
498
 
499
########################################################################
500
#
501
#   Generate a linker/depend library recipe.  This is a helper function
502
#   used within this toolset.
503
#
504
#   Arguments:
505
#       $io         I/O stream
506
#
507
#       $target     Name of the target
508
#
509
#       $lib        Library specification
510
#
511
#       $dp         If building a depend list, the full target name.
512
#
513
########################################################################
514
 
515
sub ToolsetLibRecipe
516
{
517
    my ($io, $target, $lib, $dp) = @_;
518
 
519
    #
520
    #   Run time libraries will have a .a suffix
521
    #   Do not append .lib if this is the case
522
    #
523
    $lib .= '.' . $::a unless ( $lib =~ m~\.a$~ );
524
 
525
 
526
    if ( !defined($dp) ) {                      # linker
527
        $io->Cmd("\"@(vpath2,\"$lib\",LIB,\\)\"" );
528
    } else {                                    # depend
529
        $io->Cmd( "$dp:\t@(vlib2,\"$lib\",LIB)" );
530
    }
531
}
532
 
533
#.. Successful termination
534
1;
535