Subversion Repositories DevTools

Rev

Rev 227 | 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
#..
2
# Copyright (C) 1998-2004 ERG Transit Systems, All rights reserved
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
112
#   This will be in a different package
113
#   Cannot detect a warning, thus we must ensure that the filename not
114
#   in the local directory.
115
#
116
    my $opcode = MakeSrcResolveExtended ( 1, "opcodes.tbl" );
117
 
118
    Error ("Cannot locate the BR Compiler opcodes", "Check that a daf_br_compiler_opcodes package is being used" )
119
        unless ( $opcode ne  "opcodes.tbl");
120
    ToolsetDefine ( "DAFBROPCODE := $opcode" );
121
 
122
    my $opcode_path = StripFileExt ( $opcode );
123
    ToolsetDefine ( "DAFBROPCODE_PATH := $opcode_path" );
124
 
125
 
126
#.. Determine the version of the compiler
127
#   Locate a package with the compiler. Sort of works against the use of
128
#   ToolExtensionProgram() above. Perhaps we need a call to determine both.
129
#
130
    version_scan:
131
    for my $entry (@{$::ScmBuildPkgRules{$ScmPlatform} })
132
    {
133
        for my $td ( @{$entry->{'TOOLDIRS'}} )
134
        {
135
            if ( -f "$td/compile.exe" )
136
            {
137
                my ($maj,$min,$patch) = split( '\.', $entry->{'DVERSION'} );
138
                $v2_compiler = 1 if ( $maj > 1 );
139
Message( "DAFBR: Compiler version: $maj.$min.$patch\n" );
140
                last version_scan;
141
            }
142
        }
143
    }
144
    Message( "DAFBR: Using pre-version-2 compiler\n" ) unless $v2_compiler;
145
 
146
#.. Extend the CompilerOption directive
147
#   Create a standard data structure
148
#   This is a hash of hashes
149
#       The first hash is keyed by CompileOption keyword
150
#       The second hash contains pairs of values to set or remove
151
#
152
    %::ScmToolsetCompilerOptions =
153
    (
154
        'usedef='       => { 'BRLD_DEF' , \&locate_PLDEF },
155
 
156
        'addcdheader'   => { 'BRLD_FLAGS' , "" },
157
        'nocdheader'    => { 'BRLD_FLAGS' , "noheader" },
158
    );
159
 
160
#
161
#   Install defaults
162
#
163
    $ScmCompilerOpts{'BRLD_FLAGS'} = "noheader";
164
    $ScmCompilerOpts{'DAFBR_V2'} = 1 if $v2_compiler;
165
 
166
}
167
 
168
#-------------------------------------------------------------------------------
169
# Function        : locate_PLDEF
170
#
171
# Description     : Called to validate the "UseDef" option
172
#                   This function will
173
#                       1) verify that user has passed in a name
174
#                       2) Save the name of the file for later use
175
#                          We cannot source the file at this point
176
#
177
# Inputs          : $0  - Key  ( With a "=" appended )
178
#                   $1  - Value
179
#
180
# Returns         : undef : Error detected
181
#                   Name of the file
182
#
183
 
184
sub locate_PLDEF
185
{
186
    my ($key, $file) = @_;
187
    return undef unless $file;
188
    return $file;
189
}
190
 
191
###############################################################################
192
#   ToolsetCC( $source, $obj, \@args )
193
#       This subroutine takes the user options and builds the rule(s)
194
#       required to compile the source file 'source' to 'obj'
195
#
196
###############################################################################
197
 
198
sub ToolsetCC
199
{
200
    my( $source, $obj, $pArgs ) = @_;
201
    foreach $_ ( @$pArgs ) {
202
        Message( "DAFBR: unknown compiler option $_ -- ignored\n" );
203
    }
204
 
205
    MakePrint( "\n\t\$(CC)\n" );
206
 
207
 
208
    #
209
    #   Add in the global DEF file if present
210
    #   This can only be used by Version-2+ of the compiler. Earlier versions
211
    #   MUST not use it as they will generate a payload in the first phase.
212
    #
213
    if ($v2_compiler)
214
    {
215
        my $def;
216
        my $def_name = $ScmCompilerOpts{'BRLD_DEF'};    # Start with global value
217
        if ( $def_name )
218
        {
219
            #
220
            #   Locate the true path of the provided REL file
221
            #   If it is a generate file so it will be in the SRCS hash
222
            #   Other wise the use will have to use Src to locate the file
223
            #
224
            $def = MakeSrcResolve ( $def_name );
225
            MakePadded( 4, "\$(OBJDIR)/$obj.$::o:", "\tBRCC_DEF = $def\n" );
226
        }
227
        else
228
        {
229
            Error("dafbr: Must have a global .def file, with the V2 compiler");
230
        }
231
    }
232
 
233
    #
234
    #   Cleanup files that may be generated
235
    #
236
    ToolsetGenerate( "\$(OBJDIR)/$obj.rul" );
237
    ToolsetGenerate( "\$(OBJDIR)/$obj.sym" );
238
    ToolsetGenerate( "\$(OBJDIR)/$obj.asm" );
239
    ToolsetGenerate( "\$(OBJDIR)/$obj.pre" );
240
    ToolsetGenerate( "\$(OBJDIR)/$obj.lnk" );
241
}
242
 
243
 
244
 
245
###############################################################################
246
#   ToolsetCCDepend( $depend, \@sources )
247
#       This subroutine takes the user options and builds the
248
#       rule(s) required to build the dependencies for the source
249
#       files 'sources' to 'depend'.
250
#
251
###############################################################################
252
 
253
sub ToolsetCCDepend
254
{
255
    MakePrint( "\t\$(CCDEPEND)\n" );
256
}
257
 
258
###############################################################################
259
#   ToolsetLD( $name, \@args, \@objs, \@libraries )
260
#       This subroutine takes the user options and builds the rules
261
#       required to link the program 'name'.
262
#
263
#   Implementation Notes:
264
#
265
#   The DAF BR Compiler does not support libraries
266
#   It can "link" .rul files into a .bin file with the help of a .def file
267
#
268
#   Within this paradigm the objects are .RUL files and the .DEF file is passed
269
#   in directly or it may be globally specified
270
#
271
#   The compiler cannot take the names of the .RUL files
272
#   It can search for them in a specified directory and since they have
273
#   been created in the OBJDIR directory this directory is used.
274
#
275
#   Supported options
276
#       --Def=name              - Name of the .DEF file
277
#                                 The global value will be used if none specified
278
#       --Header                - Add a 32 byte CD file header
279
#       --NoHeader              - Don't add a CD file header
280
#                                 Default is to take global value
281
#
282
#   Arguments:
283
#       (none)
284
#
285
###############################################################################
286
 
287
sub ToolsetLD
288
{
289
    my ( $name, $pArgs, $pObjs, $pLibs ) = @_;
261 dpurdie 290
    my ( $full ) = '$(BINDIR)/' . $name . $::exe;
227 dpurdie 291
    my ( @slist );
292
    my $def_name = $ScmCompilerOpts{'BRLD_DEF'};    # Start with global value
293
    my $opt_header;
294
 
295
#.. Parse arguments
296
#
297
    foreach $_ ( @$pArgs ) {
298
        if (/--Def=(.*)$/) {                        # Definition file
299
            $def_name = $1;
300
        } elsif (/--NoHeader/ ) {                   # No CD header
301
            $opt_header = "noheader";
302
        } elsif (/--Header/ ) {
303
            $opt_header = "";                       # Add CD Header
304
        } else {
305
            Message( "DAFBR LD: unknown option $_ -- ignored\n" );
306
        }
307
    }
308
 
309
    if ( $def_name )
310
    {
311
        #
312
        #   Locate the true path of the provided REL file
313
        #   If it is a generate file so it will be in the SRCS hash
314
        #   Other wise the use will have to use Src to locate the file
315
        #
316
        $def = MakeSrcResolve ( $def_name );
317
    }
318
 
319
#.. Sanity Check
320
#   Need a .def file
321
#   Need at least one object file
322
#   No libraries allowed
323
#
324
    Error ("dafbr LD: No .def file specified")
325
        unless ( $def );
326
 
327
    Error ("dafbr LD: No .rul files specified")
328
        unless ( scalar @$pObjs > 0 );
329
 
330
    Error ("dafbr LD: Libraries not supported")
331
        if ( scalar @$pLibs > 0 );
332
 
333
 
261 dpurdie 334
    #
335
    #   Rules and Recipes to create the Program
336
    #
337
    my $me = MakeEntry::New (*MAKEFILE, $full );
338
    $me->AddComment ("Build Program: $name" );
339
    $me->AddDependancy ( map ( "$_.$::o", @$pObjs) );
340
    $me->AddRecipe ( '$(LD)' );
341
    $me->AddDefn ( 'BRLD_DEF' => $def  );
342
    $me->AddDefn ( 'BRLD_FLAGS' => $opt_header  ) if defined($opt_header);
343
    $me->Print();
227 dpurdie 344
 
261 dpurdie 345
    #
346
    #   Package the file
347
    #
348
    PackageProgAddFiles ( $name, $full );
227 dpurdie 349
}
350
 
351
1;
352