Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4950 dpurdie 1
#..
2
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
3
#
4
# Module name   : AVR32-GNU
5
# Module type   : Makefile system
6
# Compiler(s)   : ANSI C
7
# Environment(s): Atmel AVR
8
#
9
# Description:
10
#       This file provides Toolset initialisation and plugin functions
11
#       to makelib.pl2
12
#
13
# Contents:     AVR32-GNU rules as used for the AVR
14
#
15
#............................................................................#
16
 
17
use strict;
18
 
19
our $s;
20
our $o;
21
our $so;
22
our $exe;
23
 
24
#   Toolset specific globals
25
my $avrPart;                                    # Device Part
26
 
27
##############################################################################
28
#   ToolsetInit()
29
#       Runtime initialisation
30
#
31
##############################################################################
32
 
33
ToolsetInit();
34
 
35
sub ToolsetInit
36
{
37
    my( @args ) = @::ScmToolsetArgs;             # Toolset arguments
38
    my $toolName = 'avr32_gnu';
39
 
40
    #.. Parse arguments
41
    #
42
    Debug( "$toolName(@args)\n" );
43
 
44
    foreach $_ ( @args ) {
45
        if ( m~^-part=(.*)~) {
46
            $avrPart = $1;
47
        } else {
48
            Message( "$toolName: unknown toolset argument $_ -- ignored\n" );
49
        }
50
    }
51
 
52
    #.. Parse Platform Arguments
53
    #
54
    foreach $_ ( @::ScmPlatformArgs ) {
55
        Message( "$toolName: unknown platform argument $_ -- ignored\n" );
56
    }
57
 
58
    #
59
    #   Sanity Test
60
    #   Platform definition MUST supply the Device Part
61
    #
62
    Error ('$toolName: No part specified') 
63
        unless defined $avrPart;
64
 
65
    #.. Standard.rul requirements
66
    #
67
    $s = 'asm';             # Assembler source file : Not supported
68
    $o = 'o';               # Object file
69
    $a = 'a';               # Library file
70
    $so = '';               # Shared library : Not supported
71
    $exe = '.bin';          # Linked binary images
72
 
73
    #.. Toolset configuration
74
    #
75
    $::ScmToolsetVersion = "1.0.0";               # our version
76
    $::ScmToolsetGenerate = 0;                    # generate optional
77
    $::ScmToolsetProgDependancies = 0;            # handle Prog dependancies myself
78
 
79
    #.. Compiler paths
80
    #   Based on an environment variable
81
    #
82
    my $GCCBin      = '${GBE_AVR32_GNU}' . '/bin/avr32-gcc';
83
    my $GCCAr       = '${GBE_AVR32_GNU}' . '/bin/avr32-ar';
84
    my $GCCObjCopy  = '${GBE_AVR32_GNU}' . '/bin/avr32-objcopy';
85
 
86
#.. Define GCC environment
87
#
88
    PlatformDefine( "
89
#################################################
90
# GCC toolchain definitions 
91
#
92
#..");
93
    PlatformDefine( "GCC_CC             = $GCCBin" );
94
    PlatformDefine( "GCC_AR             = $GCCAr" );
95
    PlatformDefine( "GCC_OBJCOPY        = $GCCObjCopy" );
96
 
97
    #
98
    #   Sanity checking
99
    #
100
    PlatformDefine( "GCC_EVERSION       := 4.4.7" );
101
    PlatformDefine( "GCC_EMACHINE       := avr32" );
102
 
103
 
104
    #.. Define AVR32 environment
105
    #
106
    #   Define initialisation targets
107
    #   These will be used to ensure that correct versions of the toolset are present
108
    #
109
    Init( "avr32" );
110
 
111
    ToolsetDefine ( "#################################################" );
112
    ToolsetDefine ( "# AVR32 GNU compiler version" );
113
    ToolsetDefine ( "#" );
114
    ToolsetDefines( "avr32_gnu.def" );
115
    ToolsetRules  ( "avr32_gnu.rul" );
116
    ToolsetRules  ( "standard.rul" );
117
 
118
    #.. AVR32 definitions
119
    PlatformDefine("AVR32_PART          := " . $avrPart);
120
 
121
    # Ctags support
122
    PlatformDefine( "CTAGS_EXE:= ctags" );
123
    ToolsetRequire( "exctags" );                # and Exuberant Ctags
124
 
125
}
126
 
127
###############################################################################
128
#   ToolsetCTAGS()
129
#       This subroutine takes the user options and builds the rules
130
#       required to build the CTAGS database.
131
#
132
#   Arguments:
133
#       --xxx                   No arguments currently defined
134
#
135
#   Output:
136
#       [ctags:]
137
#           $(EXCTAGS)
138
#
139
###############################################################################
140
 
141
sub ToolsetCTAGS
142
{
143
    EXCTAGS( @_ );
144
}
145
 
146
###############################################################################
147
#   ToolsetCC( $source, $obj, \@args )
148
#       This subroutine takes the user options and builds the rule(s)
149
#       required to compile the source file 'source' to 'obj'
150
#
151
###############################################################################
152
 
153
sub ToolsetCC
154
{
155
    MakePrint( "\n\t\$(CC)\n" );
156
}
157
 
158
###############################################################################
159
#   ToolsetCCDepend( $depend, \@sources )
160
#       This subroutine takes the user options and builds the
161
#       rule(s) required to build the dependencies for the source
162
#       files 'sources' to 'depend'.
163
#
164
###############################################################################
165
 
166
sub ToolsetCCDepend
167
{
168
    MakePrint( "\t\$(CCDEPEND)\n" );
169
}
170
 
171
 
172
###############################################################################
173
#   ToolsetCXX( $source, $obj, \@args )
174
#       This subroutine takes the user options and builds the rule(s)
175
#       required to compile the source file 'source' to 'obj'
176
#
177
###############################################################################
178
 
179
sub ToolsetCXX
180
{
181
    MakePrint( "\n\t\$(CXX)\n" );
182
}
183
 
184
###############################################################################
185
#   ToolsetCXXDepend( $depend, \@sources )
186
#       This subroutine takes the user options and builds the
187
#       rule(s) required to build the dependencies for the source
188
#       files 'sources' to 'depend'.
189
#
190
###############################################################################
191
 
192
sub ToolsetCXXDepend
193
{
194
    ToolsetCCDepend();
195
}
196
 
197
###############################################################################
198
#   ToolsetAR( $name, \@args, \@objs )
199
#       This subroutine takes the user options and builds the rules
200
#       required to build the library 'name'.
201
 
202
#
203
#   Arguments:
204
#       --xxx                   No arguments currently defined
205
#
206
#   Output:
207
#       [ $(BINDIR)/name$.${a}:   .... ]
208
#           $(AR)
209
#
210
###############################################################################
211
 
212
sub ToolsetAR
213
{
214
    my( $name, $pArgs, $pObjs ) = @_;
215
 
216
    Debug("ToolsetAR");
217
 
218
#.. Parse arguments
219
#
220
    foreach $_ ( @$pArgs ) {
221
        if (/^--/) {
222
            Message( "AR: unknown option $_ -- ignored\n" );
223
        }
224
    }
225
 
226
#.. Target
227
#
228
    MakeEntry( "\$(LIBDIR)/$name\$(GBE_TYPE).${a}:\t", "", " \\\n\t\t", ".${o}", @$pObjs );
229
 
230
#.. Build library rule (just append to standard rule)
231
#
232
    MakePrint( "\n\t\$(AR)\n\n" );
233
}
234
 
235
 
236
###############################################################################
237
#   ToolsetARMerge()
238
#       Generate the recipe to merge libraries.
239
#       The dependency list is created by the caller.
240
#
241
###############################################################################
242
 
243
sub ToolsetARMerge
244
{
245
    MakePrint( "\n\t\$(ARMERGE)\n\n" );
246
}
247
 
248
 
249
###############################################################################
250
#   ToolsetLD( $name, \@args, \@objs, \@libraries )
251
#       This subroutine takes the user options and builds the rules
252
#       required to link the program 'name'.
253
#
254
#   Arguments:
255
#       --xxx                   No Arguments currently specified
256
#
257
#       Linker specific:
258
#       --Script=filename       Specify the name of a linker script file
259
#
260
#   Output:
261
#
262
#       name.map                - Linker map
263
#       name.elf                - Linker Output
264
#       name.bin                - Generated Program
265
#
266
###############################################################################
267
 
268
sub ToolsetLD
269
{
270
    my( $name, $pArgs, $pObjs, $pLibs ) = @_;
271
    my( $script );
272
 
273
 
274
    #.. Parse arguments
275
    #
276
    foreach $_ ( @$pArgs )
277
    {
278
        if (/^--Script=(.*)/) {           # External file
279
            $script = $1;
280
            $script .= ".lds" unless ( $script =~ m~\.lds$~ );
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, or guess at a default one
290
    #       - Use name.lds. Iff it exists in the current directory
291
    #         Else try name based on the 'part'
292
    #
293
    unless ( $script )
294
    {
295
        $script = "$name.lds";
296
        unless (-f $script) {
297
            $script = 'link_'.$avrPart.'sdram.lds';
298
        }
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
    #   Create a ToolsetPrinter
311
    #
312
    my ($io) = ToolsetPrinter::New();
313
    my $dep = $io->SetLdTarget( $name );
314
 
315
    #
316
    #   Determine the target output name
317
    #
318
    my $root = "\$(BINDIR)/$name";
319
    my $full = $root . $::exe;
320
    my $map = $root . '.map';
321
    my $elf = $root . '.elf';
322
 
323
 
324
    ########################################################################
325
    #
326
    #   Create a makefile recipe to build an ELF file
327
    #       Depends upon
328
    #               Library dependency file
329
    #               User linker script file
330
    #               Objects
331
    # 
332
    $io->Label( "Program", $name );                     # label
333
    $io->Prt( "$elf : \t$dep" );                        # Dependencies
334
    $io->Prt( "\\\n\t\t$script" );
335
    $io->Entry( "", "", "\\\n\t", ".$::o ", @$pObjs );  # Object Files
336
    $io->Prt( "\n\t\$(LD)\n" );
337
    $io->Newline();
338
 
339
    #
340
    #   Specify files created by the linker
341
    #   These will be added to the clean list
342
    #
343
    ToolsetGenerate( $elf );
344
    ToolsetGenerate( $map );
345
 
346
    #
347
    #   Create a linker command file
348
    #   Piecing together a variable $(name_ld) which ends up in the command file.
349
    #   This bit of magic will be performed by the LD recipe
350
    #
351
    $io->SetTag( "${name}_ld" );                            # macro tag
352
    $io->Label( "Linker commands", $name );                 # label
353
    $io->SetTerm( "\n" );
354
 
355
    $io->Cmd('-nostartfiles' );
356
    $io->Cmd('-Wl,--gc-sections' );
357
    $io->Cmd('--rodata-writable' );
358
    $io->Cmd('-Wl,--direct-data' );
359
    $io->Cmd('-Wl,--relax' );
360
    $io->Cmd('-Wl,-e,_trampoline' );
361
    $io->Cmd('-mpart=$(AVR32_PART)' );
362
    $io->Cmd('-T ' . $script );                             # User script file
363
 
364
    $io->ObjList( $name, $pObjs, \&ToolsetObjRecipe );      # Object files
365
 
366
    #
367
    #   Specify the library files
368
    #
369
    $io->LibList( $name, $pLibs, \&ToolsetLibRecipe );      # Specify the libraries too
370
    $io->Newline();
371
 
372
    #.. Dependency link,
373
    #   Create a library dependency file
374
    #       Create command file to build applicaton dependency list
375
    #       from the list of dependent libraries
376
    #
377
    #       Create makefile directives to include the dependency
378
    #       list into the makefile.
379
    #
380
    $io->DepRules( $pLibs, \&ToolsetLibRecipe, $elf );
381
    $io->LDDEPEND(); 
382
 
383
    #
384
    #   Create a recipe to convert the ELF file to a BIN
385
    #   The BIN depends only on ELF file
386
    #
387
    $io->Label( "Program Bin", $name );                 # label
388
    $io->Prt( "$full : \t$elf" );                       # Dependencies
389
    $io->Prt( "\n\t\$(call ELF2BIN,$full,$elf)\n\n" );
390
 
391
    #
392
    #   Define the files to the packaged up as a part of the prog
393
    #       BIN file
394
    #       MAP file - but only if the user wants it
395
    #
396
    PackageProgAddFiles ( $name, $full );
397
    PackageProgAddFiles ( $name, $map , 'Class=map' );
398
}
399
 
400
########################################################################
401
#
402
#   Generate a linker object recipe.  This is a helper function used 
403
#   within this toolset.
404
#
405
#   Arguments:
406
#       $io         I/O stream
407
#
408
#       $target     Name of the target
409
#
410
#       $obj        Library specification
411
#
412
########################################################################
413
 
414
sub ToolsetObjRecipe
415
{
416
    my ($io, $target, $obj) = @_;
417
 
418
    $io->Cmd("$obj.$::o" );
419
}
420
 
421
########################################################################
422
#
423
#   Generate a linker/depend library recipe.  This is a helper function
424
#   used within this toolset.
425
#
426
#   Arguments:
427
#       $io         I/O stream
428
#
429
#       $target     Name of the target
430
#
431
#       $lib        Library specification
432
#
433
#       $dp         If building a depend list, the full target name.
434
#
435
########################################################################
436
 
437
sub ToolsetLibRecipe
438
{
439
    my ($io, $target, $lib, $dp) = @_;
440
 
441
    if ( ! defined($dp) ) {                     # linker
442
        $lib =~ s/^lib//;                       # .. remove leading 'lib'
443
        $io->Cmd( "-l$lib" );
444
 
445
    } else {                                    # depend
446
        $io->Cmd( "$dp:\t@(vlib2,$lib,GCC_LIB)" );
447
 
448
    }
449
}
450
 
451
#.. Successful termination
452
1;
453