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