| 283 |
dpurdie |
1 |
##############################################################################
|
|
|
2 |
#
|
|
|
3 |
# Module name : TOOLSET/KeilArmV3
|
|
|
4 |
# Module type : Makefile system
|
|
|
5 |
# Environment(s):
|
|
|
6 |
#
|
|
|
7 |
# Description:
|
|
|
8 |
# Keil MDK Arm V4.3 toolset
|
|
|
9 |
# A very simple toolset to support
|
|
|
10 |
# 1) C compiliation
|
|
|
11 |
# 2) Generation of libaries
|
|
|
12 |
# 3) Merging of libraries
|
|
|
13 |
# 4) Executables
|
|
|
14 |
# 5) Assembler files
|
|
|
15 |
#
|
|
|
16 |
# Does not support ( because its not needed yet )
|
|
|
17 |
# a) Shared libraries
|
|
|
18 |
#
|
|
|
19 |
##############################################################################
|
|
|
20 |
|
|
|
21 |
our @ScmToolsetArgs;
|
|
|
22 |
|
|
|
23 |
##############################################################################
|
|
|
24 |
# ToolsetInit()
|
|
|
25 |
# Runtime initialisation
|
|
|
26 |
#
|
|
|
27 |
##############################################################################
|
|
|
28 |
|
|
|
29 |
ToolsetInit();
|
|
|
30 |
|
|
|
31 |
sub ToolsetInit
|
|
|
32 |
{
|
|
|
33 |
my $GenThumb;
|
|
|
34 |
my $GenDevice;
|
| 327 |
dpurdie |
35 |
#
|
|
|
36 |
# Version Specific
|
|
|
37 |
#
|
|
|
38 |
my $KeilVersion = "MDK Arm V4.3";
|
|
|
39 |
my $Version = '3.40';
|
|
|
40 |
my $DefFile = 'KeilArmV3.def';
|
| 283 |
dpurdie |
41 |
|
|
|
42 |
#.. Parse arguments
|
|
|
43 |
#
|
|
|
44 |
foreach $_ ( @ScmToolsetArgs ) {
|
|
|
45 |
if ( m~^--Thumb~ ) {
|
|
|
46 |
$GenThumb=1;
|
|
|
47 |
|
|
|
48 |
} elsif ( m~^--Device=(.*)~ ) {
|
|
|
49 |
$GenDevice = $1;
|
|
|
50 |
|
| 327 |
dpurdie |
51 |
} elsif ( m~^--Version=(.*)~ ) {
|
|
|
52 |
$Version = $1;
|
|
|
53 |
|
| 283 |
dpurdie |
54 |
} else {
|
|
|
55 |
Message( "KeilArmV3: unknown option $_ -- ignored\n" );
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
Error ("KeilArmV3: Toolset error. --Device must be specified")
|
|
|
59 |
unless ( $GenDevice );
|
|
|
60 |
|
| 327 |
dpurdie |
61 |
#
|
|
|
62 |
# If using a specified version, then ensure that the required
|
|
|
63 |
# def file is present. This is used to setup the environment
|
|
|
64 |
# for this family of compilers
|
|
|
65 |
#
|
|
|
66 |
if ( $Version =~ m/4.03a/i)
|
|
|
67 |
{
|
|
|
68 |
$DefFile = 'KeilArmV43a.def';
|
|
|
69 |
$KeilVersion = "MDK Arm V4.03a";
|
|
|
70 |
}
|
|
|
71 |
Error ("Unsupported compiler version: $Version")
|
|
|
72 |
unless (Exists( "$::GBE_CONFIG/TOOLSET", $DefFile));
|
|
|
73 |
|
| 283 |
dpurdie |
74 |
#.. Standard.rul requirements
|
|
|
75 |
#
|
|
|
76 |
$s = 's';
|
|
|
77 |
$o = 'o';
|
|
|
78 |
$a = 'lib';
|
|
|
79 |
$exe = '.bin';
|
|
|
80 |
|
|
|
81 |
AddSourceType( ".$s", '.asm' );
|
|
|
82 |
|
|
|
83 |
#.. Define environment
|
|
|
84 |
#
|
| 327 |
dpurdie |
85 |
Init( "KeilArm" );
|
| 283 |
dpurdie |
86 |
|
|
|
87 |
ToolsetDefine( "#################################################" );
|
|
|
88 |
ToolsetDefine( "# Compiler version" );
|
|
|
89 |
ToolsetDefine( "#" );
|
|
|
90 |
ToolsetDefine( "KeilC Version = \"$KeilVersion\"" );
|
|
|
91 |
ToolsetDefine( "USE_THUMB = 1" ) if $GenThumb;
|
|
|
92 |
ToolsetDefine( "USE_DEVICE = $GenDevice" );
|
|
|
93 |
ToolsetDefine( "" );
|
|
|
94 |
ToolsetDefine( "#" );
|
|
|
95 |
|
| 327 |
dpurdie |
96 |
ToolsetDefines( $DefFile );
|
| 283 |
dpurdie |
97 |
ToolsetRules ( "KeilArmV3.rul" );
|
|
|
98 |
ToolsetRules ( "standard.rul" );
|
|
|
99 |
|
|
|
100 |
#
|
|
|
101 |
# Extend the cleanup rule
|
|
|
102 |
#
|
|
|
103 |
ToolsetGenerate( '*.lst' );
|
|
|
104 |
|
|
|
105 |
#.. Extend the CompilerOption directive
|
|
|
106 |
# Create a standard data structure
|
|
|
107 |
# This is a hash of hashes
|
|
|
108 |
# The first hash is keyed by CompileOption keyword
|
|
|
109 |
# The second hash contains pairs of values to set or remove
|
|
|
110 |
#
|
|
|
111 |
%::ScmToolsetCompilerOptions =
|
|
|
112 |
(
|
|
|
113 |
'nowarn=' => { 'NOWARNLIST' ,\&NoWarns }, # Suppress warnings
|
|
|
114 |
'timeoptimization' => { 'OPT_MODE' , 'time' }, # Time optimize
|
|
|
115 |
'spaceoptimization' => { 'OPT_MODE' , 'space' }, # Space optimize
|
|
|
116 |
'defaultoptimization' => { 'OPT_MODE' , undef }, # Default (?space)
|
|
|
117 |
);
|
|
|
118 |
|
|
|
119 |
|
|
|
120 |
#
|
|
|
121 |
# Set default options
|
|
|
122 |
# $::ScmCompilerOpts{'xxxx'} = 'yyy';
|
|
|
123 |
#
|
|
|
124 |
$::ScmCompilerOpts{'NOWARNLIST'} = '';
|
|
|
125 |
$::ScmCompilerOpts{'OPT_MODE'} = 'space';
|
|
|
126 |
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
#-------------------------------------------------------------------------------
|
|
|
130 |
# Function : NoWarns
|
|
|
131 |
#
|
|
|
132 |
# Description : ScmToolsetCompilerOptions extension function
|
|
|
133 |
# Accumulates the NoWarn options as a comma seperated list
|
|
|
134 |
#
|
|
|
135 |
# Inputs : $key - Name of the Option
|
|
|
136 |
# $value - Option Value. Comma sep list of numbers
|
|
|
137 |
# $ukey - User key (within $::ScmCompilerOpts)
|
|
|
138 |
#
|
|
|
139 |
# Returns : New sting to save
|
|
|
140 |
#
|
|
|
141 |
sub NoWarns
|
|
|
142 |
{
|
|
|
143 |
my ($key, $value, $ukey) = @_;
|
|
|
144 |
my @NoWarnList = split (',', $::ScmCompilerOpts{$ukey});
|
|
|
145 |
UniquePush ( \@NoWarnList, split (',', $value) );
|
|
|
146 |
return join ',', @NoWarnList;
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
###############################################################################
|
|
|
151 |
# ToolsetAS( $source, $obj, \@args )
|
|
|
152 |
# This subroutine takes the user options and builds the rule(s)
|
|
|
153 |
# required to compile the source file 'source' to 'obj'
|
|
|
154 |
#
|
|
|
155 |
###############################################################################
|
|
|
156 |
|
|
|
157 |
sub ToolsetAS
|
|
|
158 |
{
|
|
|
159 |
MakePrint( "\n\t\$(AS)\n" );
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
sub ToolsetASDepend
|
|
|
163 |
{
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
###############################################################################
|
|
|
167 |
# ToolsetCC( $source, $obj, \@args )
|
|
|
168 |
# This subroutine takes the user options and builds the rule(s)
|
|
|
169 |
# required to compile the source file 'source' to 'obj'
|
|
|
170 |
#
|
|
|
171 |
###############################################################################
|
|
|
172 |
|
|
|
173 |
sub ToolsetCC
|
|
|
174 |
{
|
|
|
175 |
my( $source, $obj, $pArgs ) = @_;
|
|
|
176 |
|
|
|
177 |
Debug( "CC: $source -> $obj" );
|
|
|
178 |
foreach ( @$pArgs ) {
|
|
|
179 |
Debug( "option: $_" );
|
|
|
180 |
if ( /--Shared$/ ) { # Building a 'shared' object
|
|
|
181 |
$cflags = "$cflags \$(SHCFLAGS)";
|
|
|
182 |
Debug( "CC: as shared object" );
|
|
|
183 |
} else { # unknown option
|
|
|
184 |
Message( "CC: unknown option $_ -- ignored\n" );
|
|
|
185 |
}
|
|
|
186 |
}
|
|
|
187 |
|
|
|
188 |
MakePrint( "\n\t\$(CC)\n" );
|
|
|
189 |
MakePrint( "\$(OBJDIR)/$i.${o}:\tCFLAGS +=$cflags\n" )
|
|
|
190 |
if ( $cflags );
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
###############################################################################
|
|
|
194 |
# ToolsetCCDepend( $depend, \@sources )
|
|
|
195 |
# This subroutine takes the user options and builds the
|
|
|
196 |
# rule(s) required to build the dependencies for the source
|
|
|
197 |
# files 'sources' to 'depend'.
|
|
|
198 |
#
|
|
|
199 |
###############################################################################
|
|
|
200 |
|
|
|
201 |
sub ToolsetCCDepend
|
|
|
202 |
{
|
|
|
203 |
MakePrint( "\t\$(CCDEPEND)\n" );
|
|
|
204 |
}
|
|
|
205 |
|
|
|
206 |
###############################################################################
|
|
|
207 |
# ToolsetAR( $name, \@args, \@objs )
|
|
|
208 |
# This subroutine takes the user options and builds the rules
|
|
|
209 |
# required to build the library 'name'.
|
|
|
210 |
#
|
|
|
211 |
# Arguments:
|
|
|
212 |
# n/a
|
|
|
213 |
#
|
|
|
214 |
# Output:
|
|
|
215 |
# [ $(BINDIR)/name$.${a}: .... ]
|
|
|
216 |
# $(AR)
|
|
|
217 |
#
|
|
|
218 |
###############################################################################
|
|
|
219 |
|
|
|
220 |
sub ToolsetAR
|
|
|
221 |
{
|
|
|
222 |
my( $name, $pArgs, $pObjs ) = @_;
|
|
|
223 |
|
|
|
224 |
#.. Parse arguments
|
|
|
225 |
#
|
|
|
226 |
foreach $_ ( @$pArgs )
|
|
|
227 |
{
|
|
|
228 |
Message( "AR: unknown option $_ -- ignored\n" );
|
|
|
229 |
}
|
|
|
230 |
|
|
|
231 |
#
|
|
|
232 |
MakeEntry( "\$(LIBDIR)/$name\$(GBE_TYPE).${a}:\t", "", " \\\n\t\t", ".${o}", @$pObjs );
|
|
|
233 |
|
|
|
234 |
#.. Build library rule (just append to standard rule)
|
|
|
235 |
#
|
|
|
236 |
MakePrint( "\n\t\$(AR)\n\n" );
|
|
|
237 |
}
|
|
|
238 |
|
|
|
239 |
|
|
|
240 |
###############################################################################
|
|
|
241 |
# ToolsetARMerge()
|
|
|
242 |
# Generate the recipe to merge libraries.
|
|
|
243 |
# The dependency list is created by the caller.
|
|
|
244 |
#
|
|
|
245 |
###############################################################################
|
|
|
246 |
|
|
|
247 |
sub ToolsetARMerge
|
|
|
248 |
{
|
|
|
249 |
MakePrint( "\n\t\$(ARMERGE)\n\n" );
|
|
|
250 |
}
|
|
|
251 |
|
|
|
252 |
|
|
|
253 |
#-------------------------------------------------------------------------------
|
|
|
254 |
# ToolsetLD( $name, \@pArgs, \@pObjs, \@pLibs )
|
|
|
255 |
# This subroutine takes the user options and builds the rules
|
|
|
256 |
# required to link the program 'name'.
|
|
|
257 |
#
|
|
|
258 |
# Toolset is configured to suppress partial creation of the Package
|
|
|
259 |
# Rules. This function must create the complete rule and recipe set.
|
|
|
260 |
#
|
|
|
261 |
# Arguments:
|
|
|
262 |
# $name - Name of the output
|
|
|
263 |
# $pArgs - Ref to array of args
|
|
|
264 |
# $pObjs - Ref to array of objects
|
|
|
265 |
# $pLibs - Ref to array of libs
|
|
|
266 |
#
|
|
|
267 |
# Options:
|
|
|
268 |
# --Map - Create a MAP file
|
|
|
269 |
# --NoMap - Don't create a MAP file
|
|
|
270 |
# --Scatter=file - Names a scatter file to be used
|
|
|
271 |
# --ro-base=text - Names the ReadOnly base
|
|
|
272 |
# --rw-base=text - Names the ReadWrite base
|
|
|
273 |
# --Script=file - Additional Linker commands
|
|
|
274 |
#
|
|
|
275 |
# Output:
|
|
|
276 |
# Generates makefile rules and recipes to create a program
|
|
|
277 |
#
|
|
|
278 |
|
|
|
279 |
sub ToolsetLD
|
|
|
280 |
{
|
|
|
281 |
my( $name, $pArgs, $pObjs, $pLibs ) = @_;
|
|
|
282 |
my $map_file;
|
|
|
283 |
my $scatter_file;
|
|
|
284 |
my $ro_base;
|
|
|
285 |
my $rw_base;
|
|
|
286 |
my @script_files;
|
|
|
287 |
|
|
|
288 |
#.. Parse arguments
|
|
|
289 |
#
|
|
|
290 |
|
|
|
291 |
foreach ( @$pArgs )
|
|
|
292 |
{
|
|
|
293 |
if ( m~^--Map~i ) {
|
|
|
294 |
$map_file = 1;
|
|
|
295 |
|
|
|
296 |
} elsif ( m~^--NoMap~i ) {
|
|
|
297 |
$map_file = 0;
|
|
|
298 |
|
|
|
299 |
} elsif ( m~^--Scatter=(.+)~i ) {
|
|
|
300 |
Src ('*', $1 );
|
|
|
301 |
$scatter_file = MakeSrcResolve($1);
|
|
|
302 |
|
|
|
303 |
} elsif ( m~^--Script=(.+)~i ) {
|
|
|
304 |
Src ('*', $1 );
|
|
|
305 |
push @script_files, MakeSrcResolve($1);
|
|
|
306 |
|
|
|
307 |
} elsif ( /^--ro-base=(.+)/i ) {
|
|
|
308 |
$ro_base = $1;
|
|
|
309 |
|
|
|
310 |
} elsif ( m~^--rw-base=(.+)~i ) {
|
|
|
311 |
$rw_base = $1;
|
|
|
312 |
|
|
|
313 |
} else {
|
|
|
314 |
Error( "LD: unknown option $_ -- ignored\n" );
|
|
|
315 |
}
|
|
|
316 |
}
|
|
|
317 |
|
|
|
318 |
#
|
|
|
319 |
# Sanity test
|
|
|
320 |
#
|
|
|
321 |
Error ("Can't use --scatter in conjunction with -ro-base or -rw-base")
|
|
|
322 |
if ( $scatter_file && ( $ro_base || $rw_base) );
|
|
|
323 |
|
|
|
324 |
#
|
|
|
325 |
# Determine the target output name
|
|
|
326 |
#
|
|
|
327 |
my $root = "\$(BINDIR)/$name";
|
|
|
328 |
my $full = $root . $::exe;
|
|
|
329 |
my $axf = $root . '.axf';
|
|
|
330 |
my $dep = $root . '.dep';
|
|
|
331 |
my $map = $root . '.map';
|
|
|
332 |
my $call = $root . '.htm';
|
|
|
333 |
|
|
|
334 |
#.. Packageing
|
|
|
335 |
# Have supressed default Prog building
|
|
|
336 |
# Need to specify the files to Package
|
|
|
337 |
#
|
|
|
338 |
PackageProgAddFiles ( $name, $full );
|
|
|
339 |
PackageProgAddFiles ( $name, $map, 'Class=map' ) if $map_file;
|
|
|
340 |
|
|
|
341 |
|
|
|
342 |
#.. Cleanup rules
|
|
|
343 |
#
|
|
|
344 |
ToolsetGenerate( $dep );
|
|
|
345 |
ToolsetGenerate( $map );
|
|
|
346 |
ToolsetGenerate( $axf );
|
|
|
347 |
ToolsetGenerate( $call );
|
|
|
348 |
|
|
|
349 |
#.. Build rules
|
|
|
350 |
#
|
|
|
351 |
my ($io) = ToolsetPrinter::New();
|
|
|
352 |
|
|
|
353 |
#
|
|
|
354 |
# Standard Dependency rules
|
|
|
355 |
# Will generate rules to
|
|
|
356 |
# 1) Determine at make-time the full paths to the libraries
|
|
|
357 |
# 2) Include the above information
|
|
|
358 |
#
|
|
|
359 |
$io->LDDEPEND( $name ); # standard LDDEPEND rules
|
|
|
360 |
|
|
|
361 |
#.. Dependency link,
|
|
|
362 |
#
|
|
|
363 |
# Now piece together a variable $(name_dp) which ends up in
|
|
|
364 |
# the command file building the application dependency list.
|
|
|
365 |
#
|
|
|
366 |
$io->SetTag( "${name}_dp" ); # macro tag
|
|
|
367 |
$io->SetTerm();
|
|
|
368 |
$io->DepRules( $name, $pLibs, \&ToolsetLibRecipe ); # library depends rules
|
|
|
369 |
$io->Newline();
|
|
|
370 |
|
|
|
371 |
#
|
|
|
372 |
# List the object files
|
|
|
373 |
# Create a definition for the objects
|
|
|
374 |
#
|
|
|
375 |
$io->Label( "Object files", $name ); # label
|
|
|
376 |
$io->StartDef ("${name}_obj");
|
|
|
377 |
$io->ObjList( $name, $pObjs, \&ToolsetObjRecipe );
|
|
|
378 |
$io->EndDef ();
|
|
|
379 |
$io->Newline();
|
|
|
380 |
|
|
|
381 |
#
|
|
|
382 |
# Define the program and its dependencies
|
|
|
383 |
# Place the .dep file first - this will ensure that failure
|
|
|
384 |
# to create this file will create an error before the object
|
|
|
385 |
# files are compiled. This makes it obvious what the error is.
|
|
|
386 |
#
|
|
|
387 |
$io->Label( "Program", $name ); # label
|
|
|
388 |
$io->Prt( "$axf : \t$dep" ); # Dependencies
|
|
|
389 |
$io->Prt( " \\\n\t$scatter_file" ) if ($scatter_file);
|
|
|
390 |
$io->Prt( " \\\n\t$_" ) foreach (@script_files);
|
|
|
391 |
$io->Prt( " \\\n\t\$(${name}_obj)" .
|
|
|
392 |
" \\\n\t\$(${name}_lib)" );
|
|
|
393 |
$io->Newline();
|
|
|
394 |
|
|
|
395 |
#
|
|
|
396 |
# Recipe to build the program
|
|
|
397 |
#
|
|
|
398 |
$io->PrtLn( "\t\$(LD)" );
|
|
|
399 |
|
|
|
400 |
|
|
|
401 |
#.. Linker command file
|
|
|
402 |
#
|
|
|
403 |
# Create a variable $(name_ld) which will be the linker
|
|
|
404 |
# command line. Use previosly defined values
|
|
|
405 |
#
|
|
|
406 |
$io->Label( "Linker commands", $name ); # label
|
|
|
407 |
$io->StartDef ("${name}_ld");
|
|
|
408 |
$io->Def( "\$(${name}_obj)" ); # Object file list variable
|
|
|
409 |
$io->Def( "\$(${name}_lib)" ); # Library list variable
|
|
|
410 |
$io->Def( "--scatter=$scatter_file" ) if ($scatter_file);
|
|
|
411 |
$io->Def( "--ro-base=$ro_base" ) if defined ($ro_base);
|
|
|
412 |
$io->Def( "--rw-base=$rw_base" ) if defined ($rw_base);
|
|
|
413 |
$io->Def( "--list=$map" ) if ( $map_file );
|
|
|
414 |
$io->Def( "--via=$_" ) foreach (@script_files);
|
|
|
415 |
$io->EndDef ();
|
|
|
416 |
$io->Newline();
|
|
|
417 |
|
|
|
418 |
#
|
|
|
419 |
# Create rules to convert the .axf file into a bin file
|
|
|
420 |
# Done as a seperate step
|
|
|
421 |
#
|
|
|
422 |
#
|
|
|
423 |
$io->Label( "Elf Converion ", $name ); # label
|
|
|
424 |
$io->Prt( "$full : \t$axf\n" ); # Dependencies
|
|
|
425 |
|
|
|
426 |
#
|
|
|
427 |
# Recipe to build the program
|
|
|
428 |
#
|
|
|
429 |
$io->PrtLn( "\t\$(FROMELF)" );
|
|
|
430 |
|
|
|
431 |
}
|
|
|
432 |
|
|
|
433 |
|
|
|
434 |
########################################################################
|
|
|
435 |
#
|
|
|
436 |
# Generate a linker object recipe. This is a helper function used
|
|
|
437 |
# within this toolset.
|
|
|
438 |
#
|
|
|
439 |
# Arguments:
|
|
|
440 |
# $io I/O stream
|
|
|
441 |
#
|
|
|
442 |
# $target Name of the target
|
|
|
443 |
#
|
|
|
444 |
# $obj Library specification
|
|
|
445 |
#
|
|
|
446 |
########################################################################
|
|
|
447 |
|
|
|
448 |
sub ToolsetObjRecipe
|
|
|
449 |
{
|
|
|
450 |
my ($io, $target, $obj) = @_;
|
|
|
451 |
|
|
|
452 |
$io->Def( "$obj.$::o" );
|
|
|
453 |
}
|
|
|
454 |
|
|
|
455 |
|
|
|
456 |
###############################################################################
|
|
|
457 |
#
|
|
|
458 |
# Parse a linker lib list
|
|
|
459 |
# This is a helper function used within this toolset
|
|
|
460 |
#
|
|
|
461 |
# Used to create a variable that will be fedd into 'cmdfile'
|
|
|
462 |
# The output will then be included in the makefile
|
|
|
463 |
# The output extends the definitions of the program being built
|
|
|
464 |
# to contain the absolute pathnames to the libraries being consumed.
|
|
|
465 |
#
|
|
|
466 |
# Arguments:
|
|
|
467 |
# $io io printer class
|
|
|
468 |
#
|
|
|
469 |
# $target Name of the target
|
|
|
470 |
#
|
|
|
471 |
# $lib Library specification
|
|
|
472 |
#
|
|
|
473 |
###############################################################################
|
|
|
474 |
|
|
|
475 |
sub ToolsetLibRecipe
|
|
|
476 |
{
|
|
|
477 |
my ($io, $target, $lib) = @_;
|
|
|
478 |
|
|
|
479 |
$io->Cmd( "${target}_lib += @(vglob2,$lib.$::a,LIB)" );
|
|
|
480 |
}
|
|
|
481 |
|
|
|
482 |
#.. Successful termination
|
|
|
483 |
1;
|
|
|
484 |
|