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