Subversion Repositories DevTools

Rev

Rev 363 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 dpurdie 1
#..
5709 dpurdie 2
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
227 dpurdie 3
#
4
# Module name   : DAFBR
5
# Module type   : Makefile system
6
# Compiler(s)   : None
7
# Environment(s): All
8
#
9
# Description:
10
#       This file provides Toolset initialisation and plugin functions
11
#       to makelib.pl2
12
#
13
# Contents:
14
#
15
# Revision History:
16
#       15-Dec-04   DDP     Created
17
#............................................................................#
18
 
19
##############################################################################
20
#   ToolsetInit()
21
#       Runtime initialisation
22
#
23
##############################################################################
24
 
25
my $v2_compiler = '';
26
 
27
ToolsetInit();
28
 
29
sub ToolsetInit
30
{
31
    my( @args ) = @ScmToolsetArgs;             # Toolset arguments
32
    my( $version, $product, $endian );
33
 
34
    $endian = "little";
35
 
36
#.. Parse arguments
37
#
38
    Debug( "DAFBR(@args)\n" );
39
 
40
    foreach $_ ( @args ) {
41
        if ( m/Endian=Big/ ) {
42
            $endian = "big";
43
 
44
        } elsif ( m/Endian=Little/ ) {
45
            $endian = "little";
46
 
47
        } else {
48
            Message( "DAFBR: unknown toolset argument $_ -- ignored\n" );
49
        }
50
    }
51
 
52
#.. Parse Platform Arguments
53
#
261 dpurdie 54
    @args = @ScmPlatformArgs;                   # Platform arguments
227 dpurdie 55
    foreach $_ ( @args ) {
56
        if (/^--product=(.*)/) {                # GBE product
57
            $product = $1;
58
        } else {
59
            Message( "DAFBR: unknown platform argument $_ -- ignored\n" );
60
        }
61
    }
62
 
63
#.. Standard.rul requirements
64
#
65
    $s =   undef;           # Assembler source file - not supported
261 dpurdie 66
    $o =   'rul';           # Object files
227 dpurdie 67
    $a =   undef;           # Library file          - not supported
68
    $so =  undef;           # Shared library        - not supported
69
    $exe = '.bin';          # Linked binary images
70
 
71
#.. Toolset configuration
72
#
73
    $ScmToolsetVersion = "1.0.0";               # our version
74
    $ScmToolsetGenerate = 0;                    # generate optional
261 dpurdie 75
    $::ScmToolsetProgDependancies = 0;          # handle Prog dependancies myself
227 dpurdie 76
 
77
#.. Define the environment
78
#
79
    #
80
    #   Define initialisation targets
81
    #   These will be used to ensure that correct versions of the toolset are present
82
    #
83
    Init( "dafbr" );
84
 
85
    ToolsetDefine ( "#################################################" );
86
    ToolsetDefine ( "# DAF BR compiler" );
87
    ToolsetDefine ( "#" );
88
    ToolsetDefine ( "ENDIAN := $endian" );
89
 
90
    ToolsetDefines( "dafbr.def" );
91
    ToolsetRules  ( "dafbr.rul" );
92
    ToolsetRules  ( "standard.rul" );
93
 
94
 
95
#.. Locate the compiler
96
#   The compiler is contained within a package.
97
#   This will contol the package version
98
#
99
#   Ensure that the pakage has been attached to the build
100
#   Ensure that we can find a suitable binary
101
#
102
    my $compiler = ToolExtensionProgram( "compile.exe" );
103
    my $compiler_path = StripFileExt( $compiler );
104
 
105
    Error ("Cannot locate the BR Compiler", "Check that the daf_br_compiler package is being used" )
106
        unless ( $compiler_path );
107
    ToolsetDefine ( "DAFBRCOMPILER := $compiler" );
108
    ToolsetDefine ( "DAFBRCOMPILER_PATH := $compiler_path" );
109
 
110
 
111
#.. Locate the compiler opcode table
363 dpurdie 112
#   This SHOULD be in a different package, but a local version is allowed
113
#   to simplify testing of the compiler.
227 dpurdie 114
#
115
    my $opcode = MakeSrcResolveExtended ( 1, "opcodes.tbl" );
363 dpurdie 116
    if ( $opcode eq  "opcodes.tbl")
117
    {
118
        $opcode = "$::Cwd/opcodes.tbl";
119
        if ( -f $opcode )
120
        {
121
            #
122
            #   Local opcode table is only supported to simplify testing
123
            #   of the compiler suite. Users should not be encouraged
124
            #   to provide a local table;
125
            #
126
            Warning("*** Local opcode table found. ***",
127
                    "*** Usage not recommended     ***");
128
        }
129
        else
130
        {
131
            Error ("Cannot locate the BR Compiler opcodes", 
132
                   "Check that a daf_br_compiler_opcodes package is used" );
133
        }
134
    }
227 dpurdie 135
 
136
    ToolsetDefine ( "DAFBROPCODE := $opcode" );
137
    my $opcode_path = StripFileExt ( $opcode );
138
    ToolsetDefine ( "DAFBROPCODE_PATH := $opcode_path" );
139
 
140
 
141
#.. Determine the version of the compiler
142
#   Locate a package with the compiler. Sort of works against the use of
143
#   ToolExtensionProgram() above. Perhaps we need a call to determine both.
144
#
145
    version_scan:
146
    for my $entry (@{$::ScmBuildPkgRules{$ScmPlatform} })
147
    {
148
        for my $td ( @{$entry->{'TOOLDIRS'}} )
149
        {
150
            if ( -f "$td/compile.exe" )
151
            {
152
                my ($maj,$min,$patch) = split( '\.', $entry->{'DVERSION'} );
153
                $v2_compiler = 1 if ( $maj > 1 );
154
Message( "DAFBR: Compiler version: $maj.$min.$patch\n" );
155
                last version_scan;
156
            }
157
        }
158
    }
159
    Message( "DAFBR: Using pre-version-2 compiler\n" ) unless $v2_compiler;
160
 
161
#.. Extend the CompilerOption directive
162
#   Create a standard data structure
163
#   This is a hash of hashes
164
#       The first hash is keyed by CompileOption keyword
165
#       The second hash contains pairs of values to set or remove
166
#
167
    %::ScmToolsetCompilerOptions =
168
    (
169
        'usedef='       => { 'BRLD_DEF' , \&locate_PLDEF },
170
 
171
        'addcdheader'   => { 'BRLD_FLAGS' , "" },
172
        'nocdheader'    => { 'BRLD_FLAGS' , "noheader" },
173
    );
174
 
175
#
176
#   Install defaults
177
#
178
    $ScmCompilerOpts{'BRLD_FLAGS'} = "noheader";
179
    $ScmCompilerOpts{'DAFBR_V2'} = 1 if $v2_compiler;
180
 
181
}
182
 
183
#-------------------------------------------------------------------------------
184
# Function        : locate_PLDEF
185
#
186
# Description     : Called to validate the "UseDef" option
187
#                   This function will
188
#                       1) verify that user has passed in a name
189
#                       2) Save the name of the file for later use
190
#                          We cannot source the file at this point
191
#
192
# Inputs          : $0  - Key  ( With a "=" appended )
193
#                   $1  - Value
194
#
195
# Returns         : undef : Error detected
196
#                   Name of the file
197
#
198
 
199
sub locate_PLDEF
200
{
201
    my ($key, $file) = @_;
202
    return undef unless $file;
203
    return $file;
204
}
205
 
206
###############################################################################
207
#   ToolsetCC( $source, $obj, \@args )
208
#       This subroutine takes the user options and builds the rule(s)
209
#       required to compile the source file 'source' to 'obj'
210
#
211
###############################################################################
212
 
213
sub ToolsetCC
214
{
215
    my( $source, $obj, $pArgs ) = @_;
216
    foreach $_ ( @$pArgs ) {
217
        Message( "DAFBR: unknown compiler option $_ -- ignored\n" );
218
    }
219
 
220
    MakePrint( "\n\t\$(CC)\n" );
221
 
222
 
223
    #
224
    #   Add in the global DEF file if present
225
    #   This can only be used by Version-2+ of the compiler. Earlier versions
226
    #   MUST not use it as they will generate a payload in the first phase.
227
    #
228
    if ($v2_compiler)
229
    {
230
        my $def;
231
        my $def_name = $ScmCompilerOpts{'BRLD_DEF'};    # Start with global value
232
        if ( $def_name )
233
        {
234
            #
235
            #   Locate the true path of the provided REL file
236
            #   If it is a generate file so it will be in the SRCS hash
237
            #   Other wise the use will have to use Src to locate the file
238
            #
239
            $def = MakeSrcResolve ( $def_name );
240
            MakePadded( 4, "\$(OBJDIR)/$obj.$::o:", "\tBRCC_DEF = $def\n" );
241
        }
242
        else
243
        {
244
            Error("dafbr: Must have a global .def file, with the V2 compiler");
245
        }
246
    }
247
 
248
    #
249
    #   Cleanup files that may be generated
250
    #
251
    ToolsetGenerate( "\$(OBJDIR)/$obj.rul" );
252
    ToolsetGenerate( "\$(OBJDIR)/$obj.sym" );
253
    ToolsetGenerate( "\$(OBJDIR)/$obj.asm" );
254
    ToolsetGenerate( "\$(OBJDIR)/$obj.pre" );
255
    ToolsetGenerate( "\$(OBJDIR)/$obj.lnk" );
256
}
257
 
258
 
259
 
260
###############################################################################
261
#   ToolsetCCDepend( $depend, \@sources )
262
#       This subroutine takes the user options and builds the
263
#       rule(s) required to build the dependencies for the source
264
#       files 'sources' to 'depend'.
265
#
266
###############################################################################
267
 
268
sub ToolsetCCDepend
269
{
270
    MakePrint( "\t\$(CCDEPEND)\n" );
271
}
272
 
273
###############################################################################
274
#   ToolsetLD( $name, \@args, \@objs, \@libraries )
275
#       This subroutine takes the user options and builds the rules
276
#       required to link the program 'name'.
277
#
278
#   Implementation Notes:
279
#
280
#   The DAF BR Compiler does not support libraries
281
#   It can "link" .rul files into a .bin file with the help of a .def file
282
#
283
#   Within this paradigm the objects are .RUL files and the .DEF file is passed
284
#   in directly or it may be globally specified
285
#
286
#   The compiler cannot take the names of the .RUL files
287
#   It can search for them in a specified directory and since they have
288
#   been created in the OBJDIR directory this directory is used.
289
#
290
#   Supported options
291
#       --Def=name              - Name of the .DEF file
292
#                                 The global value will be used if none specified
293
#       --Header                - Add a 32 byte CD file header
294
#       --NoHeader              - Don't add a CD file header
295
#                                 Default is to take global value
296
#
297
#   Arguments:
298
#       (none)
299
#
300
###############################################################################
301
 
302
sub ToolsetLD
303
{
304
    my ( $name, $pArgs, $pObjs, $pLibs ) = @_;
261 dpurdie 305
    my ( $full ) = '$(BINDIR)/' . $name . $::exe;
227 dpurdie 306
    my ( @slist );
307
    my $def_name = $ScmCompilerOpts{'BRLD_DEF'};    # Start with global value
308
    my $opt_header;
309
 
310
#.. Parse arguments
311
#
312
    foreach $_ ( @$pArgs ) {
313
        if (/--Def=(.*)$/) {                        # Definition file
314
            $def_name = $1;
315
        } elsif (/--NoHeader/ ) {                   # No CD header
316
            $opt_header = "noheader";
317
        } elsif (/--Header/ ) {
318
            $opt_header = "";                       # Add CD Header
319
        } else {
320
            Message( "DAFBR LD: unknown option $_ -- ignored\n" );
321
        }
322
    }
323
 
324
    if ( $def_name )
325
    {
326
        #
327
        #   Locate the true path of the provided REL file
328
        #   If it is a generate file so it will be in the SRCS hash
329
        #   Other wise the use will have to use Src to locate the file
330
        #
331
        $def = MakeSrcResolve ( $def_name );
332
    }
333
 
334
#.. Sanity Check
335
#   Need a .def file
336
#   Need at least one object file
337
#   No libraries allowed
338
#
339
    Error ("dafbr LD: No .def file specified")
340
        unless ( $def );
341
 
342
    Error ("dafbr LD: No .rul files specified")
343
        unless ( scalar @$pObjs > 0 );
344
 
345
    Error ("dafbr LD: Libraries not supported")
346
        if ( scalar @$pLibs > 0 );
347
 
348
 
261 dpurdie 349
    #
350
    #   Rules and Recipes to create the Program
351
    #
352
    my $me = MakeEntry::New (*MAKEFILE, $full );
353
    $me->AddComment ("Build Program: $name" );
354
    $me->AddDependancy ( map ( "$_.$::o", @$pObjs) );
355
    $me->AddRecipe ( '$(LD)' );
356
    $me->AddDefn ( 'BRLD_DEF' => $def  );
357
    $me->AddDefn ( 'BRLD_FLAGS' => $opt_header  ) if defined($opt_header);
358
    $me->Print();
227 dpurdie 359
 
261 dpurdie 360
    #
361
    #   Package the file
362
    #
363
    PackageProgAddFiles ( $name, $full );
227 dpurdie 364
}
365
 
366
1;
367