Subversion Repositories DevTools

Rev

Rev 5709 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
363 dpurdie 1
##############################################################################
6177 dpurdie 2
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
363 dpurdie 3
#
4
# Module name   : TOOLSET/arm251
5
# Module type   : Makefile system
6
# Environment(s):
7
#
8
# Description:
9
#   Arm V2.51 toolset
10
#   A very simple toolset to support
11
#       1) C compiliation
12
#       2) Generation of libaries
13
#       3) Merging of libraries
14
#       4) Executables
15
#       5) Assembler files
16
#
17
#   Does not support
18
#       a) Shared libraries
19
#
20
#   Based on the KEILARM32 toolset
21
#
22
##############################################################################
23
 
24
our @ScmToolsetArgs;
25
 
26
##############################################################################
27
#   ToolsetInit()
28
#       Runtime initialisation
29
#
30
##############################################################################
31
 
32
ToolsetInit();
33
 
34
sub ToolsetInit
35
{
36
        $DefFile = 'ARM251.DEF';
37
        $Version = "Arm V2.51";
38
 
39
 
40
#.. Parse arguments
41
#
42
    foreach $_ ( @ScmToolsetArgs ) {
43
        Message( "arm251: unknown option $_ -- ignored\n" );
44
    }
45
 
46
    Error ("Unsupported compiler version: $Version")
47
        unless (Exists( "$::GBE_CONFIG/TOOLSET", $DefFile));
48
 
49
#.. Standard.rul requirements
50
#
51
    $s = 's';
52
    $o = 'o';
53
    $a = 'lib';
54
    $exe = '.axf';
55
 
56
    #
57
    #   Regsiter non standard files types
58
    #
59
    AddSourceType( ".$s", '.asm' );
60
 
61
#.. Toolset configuration
62
#
63
    $::ScmToolsetVersion = "1.0.0";             # our version
64
    $::ScmToolsetGenerate = 0;                  # generate optional
65
    $::ScmToolsetProgDependancies = 0;          # handle Prog dependancies myself
66
 
67
 
68
#.. Define environment
69
#
70
    Init( "arm251" );
71
 
72
    ToolsetDefine( "#################################################" );
73
    ToolsetDefine( "# Compiler version" );
74
    ToolsetDefine( "#" );
75
    ToolsetDefine( "Arm Compiler Version      = \"$Version\"" );
76
    ToolsetDefine( "" );
77
    ToolsetDefine( "#" );
78
 
79
    ToolsetDefines( $DefFile );
80
    ToolsetRules  ( "arm251.rul" );
81
    ToolsetRules  ( "standard.rul" );
82
 
83
    #
84
    #   Extend the cleanup rule
85
    #
86
    ToolsetGenerate( '*.lst' );
87
 
88
#.. Extend the CompilerOption directive
89
#   Create a standard data structure
90
#   This is a hash of hashes
91
#       The first hash is keyed by CompileOption keyword
92
#       The second hash contains pairs of values to set or remove
93
#
94
    %::ScmToolsetCompilerOptions =
95
    (
96
        'timeoptimization'    => { 'OPT_MODE' , 'time'  },      # Time optimize
97
        'spaceoptimization'   => { 'OPT_MODE' , 'space' },      # Space optimize
98
        'defaultoptimization' => { 'OPT_MODE' , undef },        # Default (?space)
99
    );
100
 
101
 
102
    #
103
    #   Set default options
104
    #       $::ScmCompilerOpts{'xxxx'} = 'yyy';
105
    #
106
    $::ScmCompilerOpts{'OPT_MODE'}    = undef;
107
 
108
}
109
 
110
###############################################################################
111
#   ToolsetAS( $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 ToolsetAS
118
{
119
    MakePrint( "\n\t\$(AS)\n" );
120
}
121
 
122
sub ToolsetASDepend
123
{
124
}
125
 
126
###############################################################################
127
#   ToolsetCC( $source, $obj, \@args )
128
#       This subroutine takes the user options and builds the rule(s)
129
#       required to compile the source file 'source' to 'obj'
130
#
131
###############################################################################
132
 
133
sub ToolsetCC
134
{
135
    my( $source, $obj, $pArgs ) = @_;
136
 
137
    Debug( "CC:  $source -> $obj" );
138
    foreach ( @$pArgs ) {
139
        Debug( "option:    $_" );
140
        if ( /--Shared$/ ) {                    # Building a 'shared' object
141
            $cflags = "$cflags \$(SHCFLAGS)";
142
            Debug( "CC:    as shared object" );
143
        } else {                                # unknown option
144
            Message( "CC: unknown option $_ -- ignored\n" );
145
        }
146
    }
147
 
148
    MakePrint( "\n\t\$(CC)\n" );
149
    MakePrint( "\$(OBJDIR)/$i.${o}:\tCFLAGS +=$cflags\n" )
150
        if ( $cflags );
151
}
152
 
153
###############################################################################
154
#   ToolsetCCDepend( $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 ToolsetCCDepend
162
{
163
    MakePrint( "\t\$(CCDEPEND)\n" );
164
}
165
 
166
###############################################################################
167
#   ToolsetAR( $name, \@args, \@objs )
168
#       This subroutine takes the user options and builds the rules
169
#       required to build the library 'name'.
170
#
171
#   Arguments:
172
#       n/a
173
#
174
#   Output:
175
#       [ $(BINDIR)/name$.${a}:   .... ]
176
#           $(AR)
177
#
178
###############################################################################
179
 
180
sub ToolsetAR
181
{
182
    my( $name, $pArgs, $pObjs ) = @_;
183
 
184
#.. Parse arguments
185
#
186
    foreach $_ ( @$pArgs ) 
187
    {
188
        Message( "AR: unknown option $_ -- ignored\n" );
189
    }
190
 
191
#
192
    MakeEntry( "\$(LIBDIR)/$name\$(GBE_TYPE).${a}:\t", "", " \\\n\t\t", ".${o}", @$pObjs );
193
 
194
#.. Build library rule (just append to standard rule)
195
#
196
    MakePrint( "\n\t\$(AR)\n\n" );
197
}
198
 
199
#-------------------------------------------------------------------------------
200
#   ToolsetLD( $name, \@pArgs, \@pObjs, \@pLibs )
201
#       This subroutine takes the user options and builds the rules
202
#       required to link the program 'name'.
203
#
204
#   Toolset is configured to suppress partial creation of the Package
205
#   Rules. This function must create the complete rule and recipe set.
206
#
207
#   Arguments:
208
#       $name           - Name of the output
209
#       $pArgs          - Ref to array of args
210
#       $pObjs          - Ref to array of objects
211
#       $pLibs          - Ref to array of libs
212
#
213
#  Options:
214
#       --Map           - Create a MAP file
215
#       --NoMap         - Don't create a MAP file
216
#       --Scatter=file  - Names a scatter file to be used
217
#       --ro-base=text  - Names the ReadOnly base
218
#       --rw-base=text  - Names the ReadWrite base
219
#       --Script=file   - Additional Linker commands
220
#       --NoAddLibs     - No special objects and libs
221
#       --Heap=nn       - Create Heap definition
222
#
223
#   Output:
224
#       Generates makefile rules and recipes to create a program
225
#
226
 
227
sub ToolsetLD
228
{
229
    my( $name, $pArgs, $pObjs, $pLibs ) = @_;
230
    my $map_file;
231
    my $scatter_file;
232
    my $ro_base;
233
    my $rw_base;
234
    my @script_files;
235
    my $addLibs = 1;
236
    my $heapSize = undef;
237
 
238
 
239
#.. Parse arguments
240
#
241
 
242
    foreach ( @$pArgs )
243
    {
244
        if ( m~^--Map~i ) {
245
            $map_file = 1;
246
 
247
        } elsif ( m~^--NoMap~i ) {
248
            $map_file = 0;
249
 
250
        } elsif ( m~^--Scatter=(.+)~i ) {
251
            Src ('*', $1 );
252
            $scatter_file = MakeSrcResolve($1);
253
 
254
        } elsif ( m~^--Script=(.+)~i ) {
255
            Src ('*', $1 );
256
            push @script_files, MakeSrcResolve($1);
257
 
258
        } elsif ( /^--ro-base=(.+)/i ) {
259
            $ro_base = $1;
260
 
261
        } elsif ( m~^--rw-base=(.+)~i ) {
262
            $rw_base = $1;
263
 
264
        } elsif ( m~^--NoAddLibs~i ) {
265
            $addLibs = 0;
266
 
267
        } elsif ( m~^--Heap=(\d+)~i ) {
268
            $heapSize = 1024 * $1;
269
 
270
        } else {
271
            Error( "LD: unknown option $_ -- ignored\n" );
272
        }
273
    }
274
 
275
    #
276
    #   Sanity test
277
    #
278
    Error ("Can't use --scatter in conjunction with -ro-base or -rw-base")
279
        if ( $scatter_file && ( $ro_base || $rw_base) );
280
 
281
    #
282
    #   Determine the target output name
283
    #
284
    my $root = "\$(BINDIR)/$name";
285
    my $full = $root . $::exe;
286
    my $axf  = $root . '.axf';
287
    my $map  = $root . '.map';
288
    my $symbols  = $root . '.sym';
289
    my $heapRootName = "\$(OBJDIR)/heap";
290
 
291
    #.. Packageing
292
    #   Have supressed default Prog building
293
    #   Need to specify the files to Package
294
    #
295
    PackageProgAddFiles ( $name, $full );
296
    PackageProgAddFiles ( $name, $map, 'Class=map' ) if $map_file;
297
 
298
 
299
    #.. Cleanup rules
300
    #
301
    ToolsetGenerate( $map );
302
    ToolsetGenerate( $axf );
303
    ToolsetGenerate( $symbols );
304
 
305
    #.. Build rules
306
    #
307
    my ($io) = ToolsetPrinter::New();
308
    my $dep = $io->SetLdTarget( $name );
309
 
310
    #.. Dependency link,
311
    #   Create a library dependency file
312
    #       Create command file to build applicaton dependency list
313
    #       from the list of dependent libraries
314
    #
315
    #       Create makefile directives to include the dependency
316
    #       list into the makefile.
317
    #
318
    $io->DepRules( $pLibs, \&ToolsetLibRecipe );
319
    $io->LDDEPEND();
320
 
321
    #
322
    #   List the object files
323
    #   Create a definition for the objects
324
    #   Extend the ObjList iff we are creating the heap file
325
    #
326
    $io->Label( "Object files", $name );            # label
327
    $io->StartDef ("${name}_obj");
328
    $io->ObjList( $name, [$heapRootName], \&ToolsetObjRecipe ) if($heapSize);
329
    $io->ObjList( $name, $pObjs, \&ToolsetObjRecipe );
330
    $io->EndDef ();
331
    $io->Newline();
332
 
333
    #
334
    #   Define the program and its dependencies
335
    #   Place the .dep file first - this will ensure that failure
336
    #   to create this file will create an error before the object
337
    #   files are compiled. This makes it obvious what the error is.
338
    #
339
    $io->Label( "Program", $name );                     # label
340
    $io->Prt( "$axf : \t$dep" );                        # Dependencies
341
    $io->Prt( " \\\n\t$scatter_file" ) if ($scatter_file);
342
    $io->Prt( " \\\n\t$_" ) foreach (@script_files);
343
    $io->Prt( " \\\n\t\$(${name}_obj)" .
344
              " \\\n\t\$(${name}_lib)" );
345
    $io->Newline();
346
 
347
    #
348
    #   Recipe to build the program
349
    #
350
    $io->PrtLn( "\t\$(LD)" );
351
 
352
 
353
    #.. Linker command file
354
    #
355
    #       Create a variable $(name_ld) which will be the linker
356
    #       command line. Use previously defined values
357
    #
358
    $io->Label( "Linker commands", $name );         # label
359
    $io->SetTag( "${name}_ld" );                    # macro tag
360
 
361
    $io->Cmd( "-noscanlib");
362
    $io->Cmd( "-info sizes,totals");
363
    $io->Cmd( "-nounusedareas");
364
    $io->Cmd( "-nozeropad");
365
    $io->Cmd( "-MAP");
366
    $io->Cmd( "-Symbols $symbols");
367
    $io->Cmd( "-xref");
368
    $io->Cmd( "-scatter $scatter_file" ) if ($scatter_file);
369
    $io->Cmd( "-ro-base $ro_base" ) if defined ($ro_base);
370
    $io->Cmd( "-rw-base $rw_base" ) if defined ($rw_base);
371
    $io->Cmd( "-list $map" ) if ( $map_file );
372
    $io->Cmd( "-via=$_" ) foreach (@script_files);
373
    $io->Cmd( '$(INGEDEV_LIBS)/AppHead.o' ) if ($addLibs);                  # Fixed entries
374
    $io->Cmd( '$(INGEDEV_LIBS)/AppEntry.o' ) if ($addLibs);                 # Fixed entries
375
    $io->Cmd( "\$(subst \$(space),\\n,\$(${name}_obj))" );                  # Object file list variable
376
    $io->Cmd( "\$(subst \$(space),\\n,\$(${name}_lib))" );                  # Library file list variable
377
    $io->Newline();
378
 
379
    if ( $heapSize )
380
    {
381
        #
382
        #   Create small assember file to provide the heap
383
        #
384
 
385
        #
386
        #   Create rules to create the source file
387
        #   Done as a seperate step
388
        #
389
        #
390
        $io->Label( "Create Heap Source ", $name );                     # label
391
        $io->Prt( "${heapRootName}.$::o : \t${heapRootName}.$::s\n" );  # Dependencies
392
        $io->Prt( "\t\$(AS)\n\n" );
393
 
394
        #
395
        #   Recipe to create heap source file
396
        #
397
        $io->Prt( "${heapRootName}.s : \$(SCM_MAKEFILE)\n" );           # Dependencies
398
        $io->Prt("\t\$(GBE_PERL) -Mjats_runtime_arm251 -e create_heap -- --Heap=$heapSize --OutFile=\$@\n");
399
 
400
        #
401
        #   Cleanup files
402
        #
403
        ToolsetGenerate( "${heapRootName}.$::o"  );
404
        ToolsetGenerate( "${heapRootName}.s"  );
405
    }
406
}
407
 
408
 
409
########################################################################
410
#
411
#   Generate a linker object recipe.  This is a helper function used 
412
#   within this toolset.
413
#
414
#   Arguments:
415
#       $io         I/O stream
416
#
417
#       $target     Name of the target
418
#
419
#       $obj        Library specification
420
#
421
########################################################################
422
 
423
sub ToolsetObjRecipe
424
{
425
    my ($io, $target, $obj) = @_;
426
 
427
    $io->Def( "$obj.$::o" );
428
}
429
 
430
 
431
###############################################################################
432
#
433
#   Parse a linker lib list
434
#   This is a helper function used within this toolset
435
#
436
#   Used to create a variable that will be fedd into 'cmdfile'
437
#   The output will then be included in the makefile
438
#   The output extends the definitions of the program being built
439
#   to contain the absolute pathnames to the libraries being consumed.
440
#
441
#   Arguments:
442
#       $io         io printer class
443
#
444
#       $target     Name of the target
445
#
446
#       $lib        Library specification
447
#
448
###############################################################################
449
 
450
sub ToolsetLibRecipe
451
{
452
    my ($io, $target, $lib) = @_;
453
 
454
    #
455
    #   System libraries will have a .16l extension
456
    #   If the user provides a .16l extension, then don't append
457
    #   an extension.
458
    #
459
    $lib .= ".$::a" unless ( $lib =~ m/.16l/ );
460
    $io->Cmd( "${target}_lib += @(vglob2,$lib,LIB)" );
461
}
462
 
463
#.. Successful termination
464
1;
465