Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
303 dpurdie 1
#
2
# Module name   : vcwce
3
# Module type   : Makefile system
4
# Compiler(s)   : ANSI C
5
# Environment(s): WCE
6
#
7
# Description:
8
#   Visual C/C++ for WCE
9
#
10
#............................................................................#
11
 
12
use strict;
13
use warnings;
14
 
15
#
16
#   Global data
17
#
18
my $pdb_file = "\$(GBE_PBASE)";
19
my $pdb_first_lib;
20
my $target_file_lib;
21
my $target_file_dll;
22
my $target_file_exe;
23
my $pdb_none;
343 dpurdie 24
my $toolset_name = 'vcwce';                           # Toolset name : Error reporting
303 dpurdie 25
 
26
##############################################################################
27
#   Toolchain information
335 dpurdie 28
#   Abstract out minor toolchain differences into a data structure
303 dpurdie 29
#
30
my $toolchain_info;
31
my %ToolChainData =
32
    (
33
        'EVC4'      =>  {  'def'        => 'vcwce.def' ,
34
                           'initDef'    => 'vcembedded',
35
                           'wceroot'    => 'Microsoft eMbedded C++ 4.0',
343 dpurdie 36
                           'buildcmd'   => 'evc =DSW= /make =TYPE= /use_env /CEConfig="=CEPLATFORM=" /out =LOG=',
37
                           'cleancmd'   => 'evc =DSW= /make =TYPE= /clean /use_env /CEConfig="=CEPLATFORM="',
303 dpurdie 38
                           'tmp'        => 'vc60',
39
                           'VSCOMPILER' => '1',
343 dpurdie 40
                           'def_targets' => [ 'ALL - RELEASE','ALL - DEBUG' ],
303 dpurdie 41
                           },
42
 
43
 
44
        'VS2005'    =>  {  'def'        => 'vcembedded2005.def' ,
45
                           'initDef'    => 'vcembedded',
46
                           'buildcmd'   => 'devenv =DSW= /build =TYPE= /useenv /out =LOG=' ,
47
                           'cleancmd'   => 'devenv =DSW= /clean =TYPE= /useenv' ,
48
                           'tmp'        => 'vc80',
49
                           'VSCOMPILER' => '2',
50
 
51
                           'wceroot'    => 'Microsoft Visual Studio 8/VC/ce',
52
                           'includes'   => [    '$(WCEROOT)/include',
53
                                                '$(WCEROOT)/atlmfc/include',
54
                                           ],
55
                           'libs'       => [    '$(WCEROOT)/lib/$(WCE_TARGETCPU)',
56
                                                '$(WCEROOT)/atlmfc/lib/$(WCE_TARGETCPU)',
57
                                           ],
357 dpurdie 58
                           'hex_WCEVersion' => 1,
303 dpurdie 59
                           },
60
 
6294 dpurdie 61
        'VS2008'    =>  {  'def'       => 'vcembedded2008.def' ,
62
                          'initDef'    => 'vcembedded',
63
                          'buildcmd'   => 'devenv =DSW= /build =TYPE= /useenv /out =LOG=' ,
64
                          'cleancmd'   => 'devenv =DSW= /clean =TYPE= /useenv' ,
65
                          'tmp'        => 'vc80',
66
                          'VSCOMPILER' => '2',
67
 
68
                          'wceroot'    => 'Microsoft Visual Studio 9.0/VC/ce',
69
                          'includes'   => [    '$(WCEROOT)/include',
70
                                               '$(WCEROOT)/atlmfc/include',
71
                                          ],
72
                          'libs'       => [    '$(WCEROOT)/lib/$(WCE_TARGETCPU)',
73
                                               '$(WCEROOT)/atlmfc/lib/$(WCE_TARGETCPU)',
74
                                          ],
75
                          'hex_WCEVersion' => 1,
76
                          'calcEntryPoint' => 1,
77
                          },
78
 
79
 
303 dpurdie 80
    );
81
 
82
 
83
##############################################################################
84
#   ToolsetInit()
85
#       Runtime initialisation
86
#
87
##############################################################################
88
 
357 dpurdie 89
my( $WCEVersion,$WCEVersionTool ) = "";
303 dpurdie 90
my( $WCESubsystem )             = "";
91
my( $WCEPlatform )              = "";
92
my( $WCEPlatformDefine )        = "";
93
my( $WCEPlatformClean )         = "";
94
my( $WCETargetCPU )             = "";
95
my( $WCEHostCPU )               = "";
96
my( $WCEToolchain )             = "";
399 dpurdie 97
my( $WCEPlatformBase )          = "";
303 dpurdie 98
 
99
ToolsetInit();
100
 
101
sub ToolsetInit
102
{
103
    my( $wceroot, $sdkroot );
104
    my( $compiler, $linker, $vstool );
105
    my( @defines ) = ();
106
    my( @cflags, @cflags_debug, @cflags_prod ) = ();
107
    my( @libflags, @ldflags, @ldflags_debug, @ldflags_prod ) = ();
108
    my $is_vs2005;
317 dpurdie 109
    my $default_ehandling = undef;
355 dpurdie 110
    my @pDefines;
6294 dpurdie 111
    my $stack = '0x10000,0x1000';
7009 dpurdie 112
    my $findRc;
303 dpurdie 113
 
114
#.. Standard.rul requirements
115
#
116
    $::s = "asm";
117
    $::o = "obj";
118
    $::a = "lib";
119
    $::so = "dll";
120
    $::exe = ".exe";
121
 
122
#.. Toolset configuration
123
#
124
    $::ScmToolsetVersion = "1.0.0";             # our version
125
    $::ScmToolsetGenerate = 0;                  # generate optional
335 dpurdie 126
    $::ScmToolsetProgDependancies = 0;          # handle Prog dependancies myself
7018 dpurdie 127
    $::ScmToolsetProperties{'LdFlagSpace'} = 1; # LdFlags support embedded spaces
303 dpurdie 128
 
129
#.. Parse arguments
130
#
343 dpurdie 131
    Debug( "$toolset_name(ToolsetArgs=@::ScmToolsetArgs)" );
303 dpurdie 132
 
133
    foreach ( @::ScmToolsetArgs ) {
343 dpurdie 134
        Message( "$toolset_name toolset: unknown option $_ -- ignored\n" );
303 dpurdie 135
    }
136
 
343 dpurdie 137
    Debug( "$toolset_name(PlatformArgs=@::ScmPlatformArgs)" );
303 dpurdie 138
 
139
    foreach ( @::ScmPlatformArgs ) {
140
        if (/^--Version=(.*)/) {                # OS Version
399 dpurdie 141
            $WCEVersion     = $1;
303 dpurdie 142
 
143
        } elsif (/^--SDK=(.*)/) {               # SDK
399 dpurdie 144
            $WCEPlatform    = $1;
303 dpurdie 145
 
399 dpurdie 146
        } elsif (/^--SdkBase=(.*)/) {           # SdkBase
147
            $WCEPlatformBase = $1;
148
 
303 dpurdie 149
        } elsif (/^--Target=(.*)/) {            # CPU
399 dpurdie 150
            $WCETargetCPU   = $1;
303 dpurdie 151
 
152
        } elsif (/^--Host=(.*)/) {              # Emulator host CPU
399 dpurdie 153
            $WCEHostCPU     = $1;
303 dpurdie 154
 
155
        } elsif (/^--Toolchain=(.*)/) {         # Toolchain
399 dpurdie 156
            $WCEToolchain   = $1;
303 dpurdie 157
 
158
        } elsif (/^--product=(.*)/) {           # GBE product
159
 
160
        } elsif (/^--NoDinkumware/) {           # Deprecated switch
355 dpurdie 161
 
162
        } elsif (/^--Define=(.*)/ ) {
163
            push @pDefines, '-D' . $1;
164
 
7009 dpurdie 165
        } elsif (/^--FindRc/i ) {
166
            $findRc = 1;
167
 
303 dpurdie 168
        } else {
343 dpurdie 169
            Message( "$toolset_name toolset: unknown platform argument $_ -- ignored\n" );
303 dpurdie 170
        }
171
    }
172
 
173
#.. Select toolchain, based on targetCPU
174
#       1) EVC            - As provided via Embedded Visual C++
175
#       2) VS2005         - As provided via VS2005
176
#
177
    $toolchain_info = $ToolChainData{$WCEToolchain};
178
    Error( "Unknown Toolchain: $WCEToolchain" ) unless ( defined $toolchain_info );
179
    $is_vs2005 = ($toolchain_info->{'VSCOMPILER'} == 2);
180
 
181
#
182
#   The following table shows the processors that eMbedded Visual C++
183
#   currently supports.
184
#
185
#   ARM         ARMV4, ARMV4I, ARMV4T
186
#   MIPS        MIPSII, MIPSII_FP, MIPSIV, MIPSIV_FP, MIPS16
187
#   Hitachi     SH3, SH4
188
#   x86         x86, x86 emulation
189
#..
343 dpurdie 190
    Error ("TOOLSET/$toolset_name - Version undefined")
303 dpurdie 191
        if ($WCEVersion eq "");
192
 
343 dpurdie 193
    Error ("TOOLSET/$toolset_name - SDK undefined")
303 dpurdie 194
        if ($WCEPlatform eq "");
195
 
343 dpurdie 196
    Error ("TOOLSET/$toolset_name - TargetCPU undefined")
303 dpurdie 197
        if ($WCETargetCPU eq "");
198
 
343 dpurdie 199
    Error ("TOOLSET/$toolset_name - HostCPU undefined")
303 dpurdie 200
        if ($WCEPlatform eq "emulator" && $WCEHostCPU eq "");
201
 
343 dpurdie 202
    Error ("TOOLSET/$toolset_name - Toolchain undefined")
303 dpurdie 203
        unless ( $WCEToolchain );
204
 
205
 
206
# .. Generate CE Platform definition based on the selected SDK
207
#    The following is a list of known defintions for some SDKs
208
#    In the EVC studio these are $(CePlatform)
209
#..
210
    my %PlatformSDKDefinitions =
211
    (
212
        'H/PC 2000'         => 'WIN32_PLATFORM_HPC2000',
213
        'H/PC Pro 2.11'     => 'WIN32_PLATFORM_HPCPRO',
214
        'Pocket PC'         => 'WIN32_PLATFORM_PSPC',
215
        'Pocket PC 2002'    => 'WIN32_PLATFORM_PSPC=310',
216
        'POCKET PC 2003'    => 'WIN32_PLATFORM_PSPC=400',
217
        'Smartphone 2002'   => 'WIN32_PLATFORM_WFSP=100',
218
        'IT-3000'           => 'WCE_PLATFORM_PX780J_ARMV4I',
219
        'PCM7220'           => 'WCE_PLATFORM_SOCERXS',
220
        'ADVANTECH_X86_420' => 'WCE_PLATFORM_ADVANTECH_X86_420',
221
        'SOM_4450_2'        => 'WCE_PLATFORM_SOM_4450_2',
222
        'adv_som_4455_wlan' => 'WCE_PLATFORM_adv_som_4455_wlan',
223
        'PsionTeklogixCE420'=> 'WCE_PLATFORM_STANDARDSDK',
224
        'PsionTeklogixCE500'=> 'WCE_PLATFORM_STANDARDSDK',
225
        'PA961'             => 'WCE_PLATFORM_PA961',
226
        'PA962'             => 'WCE_PLATFORM_PA962',
227
        'PA962 WINCE 500'   => 'WCE_PLATFORM_PA962',
6294 dpurdie 228
        'M81B_SDK'          => 'WCE_PLATFORM_M81B',                 # Just made this one up
229
        'VixArmv4iGeneric'  => 'WCE_PLATFORM_VIXARMV4I_GENERIC',    # Just made this one up
399 dpurdie 230
        'PocketPC'          => 'WIN32_PLATFORM_PSPC',
7009 dpurdie 231
        'dc5000_som_4466_sdk' => 'WCE_PLATFORM_som_4466_sdk',       # Just made this one up
303 dpurdie 232
    );
233
 
399 dpurdie 234
    unless ( $WCEPlatform eq 'NONE' )
235
    {
236
        $WCEPlatformDefine = $PlatformSDKDefinitions{$WCEPlatform};
303 dpurdie 237
 
399 dpurdie 238
        Error ("TOOLSET/$toolset_name - SDK not defined. Extend table",
239
               "SDK: $WCEPlatform" )
240
            unless ( defined $WCEPlatformDefine );
303 dpurdie 241
 
399 dpurdie 242
        $WCEPlatformClean = $WCEPlatform;
243
        $WCEPlatformClean =~ s/\s/_/g;
244
    }
245
    else
246
    {
247
        $WCEPlatform = '.';
248
    }
303 dpurdie 249
 
250
    $WCESubsystem = "windowsce," . int($WCEVersion/100) . "." . $WCEVersion%100
251
        if ( !defined($WCESubsystem) || $WCESubsystem eq "" );
252
 
253
        push( @ldflags,     '-debug:full' ) unless ($is_vs2005);
254
        push( @ldflags,     '-debug' )      if ($is_vs2005);
7009 dpurdie 255
 
256
#
257
#   VS2008 may nothave installed rc.exe correctly
258
#       May have to set up PATH to locate a copy
259
#       
260
if ($findRc) {
261
    my $rcPath;
262
    my $programFiles = $ENV{PROGRAMFILES};
263
    Error ('EnvVar PROGRAMFILES not defined') unless $programFiles;
264
    Error ('EnvVar PROGRAMFILES does not reference a directory') unless -d $programFiles;
265
 
266
    my @GuessList = (
267
        'Windows Kits/8.0/bin/x86',
268
        'Windows Kits/8.1/bin/x86/rc.exe',
269
        'Microsoft SDKs/Windows/v7.1A/Bin'
270
        );
271
 
272
    foreach my $testDir ( @GuessList) {
273
        my $testPath = CatPaths($programFiles, $testDir, 'rc.exe' );
274
        if (-f $testPath) {
275
            $rcPath = $testDir;
276
            last;
277
        }
278
    }
279
    Warning ('RC.EXE cannot be located') unless $rcPath;
7040 dpurdie 280
    PlatformDefine ('RCPATH := $(PROGRAMFILES)/' . ($rcPath || 'Unknown') )
7009 dpurdie 281
 
282
}
303 dpurdie 283
 
284
#.. Select toolchain info , based on targetCPU
285
 
286
    if ( $WCETargetCPU eq "armv4" ) {
287
        $compiler           = "clarm";
288
        $linker             = "link";
289
        $vstool             = "x86_arm";
317 dpurdie 290
        $default_ehandling  = 1;
303 dpurdie 291
 
292
        @defines            = ( '-DARM', '-D_ARM_', '-DARMV4' );
293
 
317 dpurdie 294
        @cflags             = ( '-QRarch4' );
303 dpurdie 295
        @cflags             = ( '/GS-' )           if ($is_vs2005);
296
        @cflags_debug       = ( '-M$(CECrtDebug)' )unless ($is_vs2005);
297
        @cflags_prod        = ( '-M$(CECrtMT)' )   unless ($is_vs2005);
298
 
299
        push( @ldflags,     '-base:0x00010000' );
6294 dpurdie 300
        push( @ldflags,     '-stack:' . $stack );
303 dpurdie 301
        push( @ldflags,     '-entry:WinMainCRTStartup' );
302
        push( @ldflags,     '$(CENoDefaultLib)' );
303
        push( @ldflags,     '-Subsystem:$(CESubsystem)' );
304
        push( @ldflags,     '-align:4096' );
305
        push( @ldflags,     '-MACHINE:ARM' );
306
        push( @ldflags,     'commctrl.lib' );
307
        push( @ldflags,     'coredll.lib' );
308
        push( @ldflags,     'aygshell.lib' );
309
        push( @ldflags,     '$(CEx86Corelibc)' ) if ($is_vs2005);
310
 
311
        push( @libflags,    '-MACHINE:ARM' );
312
 
313
    } elsif ( $WCETargetCPU eq "armv4i" ) {
314
        $compiler           = "clarm";
315
        $linker             = "link";
316
        $vstool             = "x86_arm";
317
 
318
        @defines            = ( '-DARM', '-D_ARM_', '-DARMV4I' );
319
 
320
        @cflags             = ( '/QRarch4T' );
321
        @cflags             = ( '/QRinterwork-return' );
322
        @cflags             = ( '/GS-' )           if ($is_vs2005);
323
        @cflags_debug       = ( '-M$(CECrtDebug)' )unless ($is_vs2005);
324
        @cflags_prod        = ( '-M$(CECrtMT)' )   unless ($is_vs2005);
325
 
326
        push( @ldflags,     '-base:0x00010000' );
6294 dpurdie 327
        push( @ldflags,     '-stack:' . $stack );
303 dpurdie 328
        push( @ldflags,     '-entry:WinMainCRTStartup' );
329
        push( @ldflags,     '$(CENoDefaultLib)' );
330
        push( @ldflags,     '-nodefaultlib:oldnames.lib' ) if (1);
331
        push( @ldflags,     '-Subsystem:$(CESubsystem)' );
332
        push( @ldflags,     '-MACHINE:THUMB' );
333
        push( @ldflags,     'commctrl.lib' );
334
        push( @ldflags,     'coredll.lib' );
335
        push( @ldflags,     '$(CEx86Corelibc)' ) if ($is_vs2005);
336
 
337
        push( @libflags,    '-MACHINE:THUMB' );
338
 
339
 
399 dpurdie 340
    } elsif ( $WCETargetCPU eq 'armv5t' ) {
341
        Error ('armv5t only supported under VS2005') unless ( $is_vs2005 );
342
        $compiler           = 'cl';
343
        $linker             = 'link';
344
        $vstool             = 'x86_arm';
345
        $WCETargetCPU       = 'armv4i';
346
 
347
        push  (@defines,    '-DARM', '-D_ARM_', '-DARMV5T');
348
 
349
        push (@cflags,      '/QRarch5t' );
350
        push (@cflags,      '/GS-' );
351
        push (@cflags,      '/Zl' );
352
 
353
        #push( @ldflags,     '-base:0x00010000' );
354
        push( @ldflags,     '/Manifest:no' );
6294 dpurdie 355
        push( @ldflags,     '-stack:' . $stack );
399 dpurdie 356
        push( @ldflags,     '-entry:WinMainCRTStartup' );
357
        push( @ldflags,     '$(CENoDefaultLib)' );
358
        push( @ldflags,     '-nodefaultlib:oldnames.lib' ) if (1);
359
        push( @ldflags,     '-Subsystem:$(CESubsystem)' );
360
        push( @ldflags,     '-MACHINE:THUMB' );
361
        push( @ldflags,     'commctrl.lib' );
362
        push( @ldflags,     'coredll.lib' );
363
        push( @ldflags,     '$(CEx86Corelibc)' );
364
 
365
        push( @libflags,    '-MACHINE:THUMB' );
366
 
367
 
368
 
303 dpurdie 369
    } elsif ( $WCETargetCPU eq "armv4t" ) {
370
        $compiler           = "clthumb";
371
        $linker             = "link";
372
        $vstool             = "x86_arm";
373
 
374
        @cflags             = ( '/QRarch4t' );
375
        @defines            = ( '-DARM', '-D_ARM_', '-DARMV4T' );
376
 
377
    } elsif ( $WCETargetCPU eq "mips16" ) {
378
        $compiler           = "clmips";
379
        $linker             = "link";
380
        $vstool             = "x86_mips";
381
 
382
        @cflags             = ( '/QMmips16' );
383
        @defines            = ( '-DMIPS', '-D_MIPS_' );
384
 
385
    } elsif ( $WCETargetCPU eq "mips16ii" ) {
386
        $compiler           = "clmips";
387
        $linker             = "link";
388
        $vstool             = "x86_mips";
389
 
390
        @cflags             = ( '/QMmips16' );
391
        @defines            = ( '-DMIPS', '-D_MIPS_' );
392
 
393
    } elsif ( $WCETargetCPU eq "mipsii_fp" ) {
394
        $compiler           = "clmips";
395
        $linker             = "link";
396
 
397
        @cflags             = ( '/QMFWCE' );
398
        @defines            = ( '-DMIPS', '-D_MIPS_' );
399
 
400
    } elsif ( $WCETargetCPU eq "mipsiv" ) {
401
        $compiler           = "clmips";
402
        $linker             = "link";
403
        $vstool             = "x86_mips";
404
 
405
        @defines            = ( '-DMIPS', '-D_MIPS_' );
406
 
407
    } elsif ( $WCETargetCPU eq "mipsiv_fp" ) {
408
        $compiler           = "clmips";
409
        $linker             = "link";
410
 
411
        @cflags             = ( '/QMFWCE' );
412
        @defines            = ( '-DMIPS', '-D_MIPS_' );
413
 
414
    } elsif ( $WCETargetCPU eq "sh3" ) {
415
        if ( $WCEVersion >= 400 ) {             # SDK specific
416
            $compiler       = "clsh";
417
        } else {
418
            $compiler       = "shcl";
419
        }
420
        $linker             = "link";
421
        $vstool             = "x86_sh";
422
 
423
        @cflags             = ( '-Qsh3' );
424
        @defines            = ( '-DSHx', '-DSH3', '-D_SH3_' );
425
 
426
    } elsif ( $WCETargetCPU eq "sh4" ) {
427
        if ( $WCEVersion >= 400 ) {             # SDK specific
428
            $compiler       = "clsh";
429
        } else {
430
            $compiler       = "shcl";
431
        }
432
        $linker             = "link";
433
        $vstool             = "x86_sh";
434
 
435
        @cflags             = ( '-Qsh4' );
436
        @defines            = ( '-DSHx', '-DSH4', '-D_SH4_' );
437
 
438
    } elsif ( $WCETargetCPU eq "x86" ) {
439
        $compiler           = "cl";
440
        $linker             = "link";
441
        $vstool             = "x86_cex86";
442
 
443
        @cflags             = ( '-Gs8192', '-GF' );
444
        @defines            = ( '-D_X86_', '-Dx86', '-D_i386_' );
445
 
446
        push( @ldflags, '-section:.shared,rws' );
447
        push( @ldflags, '-base:0x00100000' );
6294 dpurdie 448
        push( @ldflags, '-stack:' . $stack );
303 dpurdie 449
        push( @ldflags, '-entry:WinMainCRTStartup' );
450
        push( @ldflags, '-Subsystem:$(CESubsystem)' );
451
        push( @ldflags, '-MACHINE:IX86' );
452
        push( @ldflags, '$(CENoDefaultLib)' );
453
        push( @ldflags, '-nodefaultlib:oldnames.lib' );
454
        push( @ldflags, '$(CEx86Corelibc)' );
455
        push( @ldflags, 'coredll.lib' );
456
        push( @ldflags, 'commctrl.lib' );
457
        push( @ldflags, 'aygshell.lib' );
458
 
459
        push( @libflags,'-MACHINE:IX86' );
460
 
461
    } elsif ( $WCETargetCPU eq "emulator" ) {
462
 
463
        if ( $WCEHostCPU eq "x86" ) {
464
            $compiler       = "cl";
465
            $linker         = "link";
466
            $vstool         = "x86_cex86";
317 dpurdie 467
            $default_ehandling  = 1;
303 dpurdie 468
 
469
            @defines        = ( '-D_X86_', '-Dx86', '-D_i386_' );
470
 
317 dpurdie 471
            @cflags         = ( '-Gs8192', '-GF' );
303 dpurdie 472
 
473
            push( @ldflags, '-base:0x00010000' );
6294 dpurdie 474
            push( @ldflags, '-stack:' . $stack );
303 dpurdie 475
            push( @ldflags, '-entry:WinMainCRTStartup' );
476
            push( @ldflags, '-Subsystem:$(CESubsystem)' );
477
            push( @ldflags, '-MACHINE:IX86' );
478
            push( @ldflags, '$(CENoDefaultLib)' );
479
            push( @ldflags, '-nodefaultlib:oldnames.lib' );
480
            push( @ldflags, '$(CEx86Corelibc)' );
481
            push( @ldflags, 'commctrl.lib' );
482
            push( @ldflags, 'coredll.lib' );
483
            push( @ldflags, 'aygshell.lib' );
484
 
485
            push( @libflags,'-MACHINE:IX86' );
486
 
487
        } else {
343 dpurdie 488
            Error ("TOOLSET/$toolset_name - unknown HostCPU '$WCEHostCPU'");
303 dpurdie 489
        }
490
 
491
    } else {
343 dpurdie 492
        Error ("TOOLSET/$toolset_name - unknown TargetCPU '$WCETargetCPU'");
303 dpurdie 493
    }
494
 
355 dpurdie 495
    #
496
    #   Append any platform specific definitions
497
    #
6294 dpurdie 498
    push (@defines,     '-D "_WINDOWS"', '-D "_WINCE"' ) if ($is_vs2005);
355 dpurdie 499
    push @defines, @pDefines;
500
 
303 dpurdie 501
#.. Define eMebbed C/C+ environment
502
#
503
 
504
    #
505
    #   Determine the toolchain root
506
    #   Currently these are within ProgramFiles
507
    #
508
    $wceroot = $toolchain_info->{'wceroot'};
509
 
510
    #
357 dpurdie 511
    #   The VS2005 toolchain uses a hex value for WCEVersion
512
    #
513
    $WCEVersionTool = $WCEVersion;
514
    $WCEVersionTool = '0X' . $WCEVersion if ( $toolchain_info->{'hex_WCEVersion'} );
515
 
516
 
517
    #
303 dpurdie 518
    #   Determine SDK root
519
    #   Currently these are well known
520
    #
399 dpurdie 521
    if ( $WCEPlatformBase )
522
    {
523
        $sdkroot = $WCEPlatformBase.'/'.$WCEPlatform;
524
    }
525
    else
526
    {
527
        $sdkroot = 'Windows CE Tools/wce'.$WCEVersion.'/'.$WCEPlatform;
528
    }
303 dpurdie 529
 
530
    Debug( "\twceroot           = $wceroot" );
531
    Debug( "\tsdkroot           = $sdkroot" );
532
    Debug( "\tWCEVersion        = $WCEVersion" );
533
    Debug( "\tWCESubsystem      = $WCESubsystem" );
534
    Debug( "\tWCEPlatform       = $WCEPlatform" );
535
    Debug( "\tWCEPlatformDefine = $WCEPlatformDefine" );
536
    Debug( "\tWCEPlatformClean  = $WCEPlatformClean" );
537
    Debug( "\tWCETargetCPU      = $WCETargetCPU" );
538
    Debug( "\tWCEHostCPU        = $WCEHostCPU" );
539
    Debug( "\tWCEToolchain      = $WCEToolchain" );
540
 
541
    PlatformDefine( "
542
#################################################
543
# Default paths, toolchain and flags
544
#
545
#..
546
 
6294 dpurdie 547
PROGRAMFILES         ?= C:/Program Files
303 dpurdie 548
 
549
ifndef WCEROOT
6294 dpurdie 550
WCEROOT              := \$(PROGRAMFILES)/" . $wceroot ."
303 dpurdie 551
export WCEROOT
552
endif
553
 
554
ifndef SDKROOT
6294 dpurdie 555
SDKROOT              := \$(PROGRAMFILES)/" . $sdkroot ."
303 dpurdie 556
export SDKROOT
557
endif
558
 
559
WCE_VSTOOL           := $vstool
357 dpurdie 560
WCE_VERSION          := $WCEVersionTool
303 dpurdie 561
WCE_SUBSYSTEM        := $WCESubsystem
562
WCE_PLATFORM         := $WCEPlatform
563
WCE_PLATFORM_SDK_DEF := $WCEPlatformDefine
564
WCE_PLATFORM2        := $WCEPlatformClean
565
WCE_TARGETCPU        := $WCETargetCPU
6294 dpurdie 566
WCE_HOSTCPU          := $WCEHostCPU
303 dpurdie 567
 
568
CESubsystem          := \$(WCE_SUBSYSTEM)
569
CEVersion            := \$(WCE_VERSION)
570
CEPlatform           := \$(WCE_PLATFORM)
571
");
572
 
573
if ( $WCEVersion < 201 ) {
574
    PlatformDefine( '
575
CECrtDebug	:= Ld
576
CECrtMT		:= T
577
CENoDefaultLib	:= \
578
		-nodefaultlib:corelibc.lib
579
CEx86Corelibc	:=
580
');
581
} else {
582
    PlatformDefine( '
583
CECrtDebug	:= C
584
CECrtMT		:= C
585
CENoDefaultLib	:= \\
586
		-nodefaultlib:libc.lib\
587
		-nodefaultlib:libcd.lib\
588
		-nodefaultlib:libcmt.lib\
589
		-nodefaultlib:libcmtd.lib\
590
		-nodefaultlib:msvcrt.lib\
591
		-nodefaultlib:msvcrtd.lib
592
CEx86Corelibc	:= corelibc.lib
593
' );
594
}
595
 
307 dpurdie 596
if ( $is_vs2005 )
597
{
598
    PlatformDefine( '
599
CENoDefaultLib	+= \\
600
		-nodefaultlib:secchk.lib\
601
		-nodefaultlib:ccrtrtti.lib
602
' );
603
}
604
 
303 dpurdie 605
#
606
#   WinCe development platform specifics
607
#       Encode Toolset paths as they contain spaces
608
#       These will be decoded later
609
#
610
PlatformEntry( "vc_includes\t=", "\n", "\\\n\t" . '$(call encodepath,', ')', @{$toolchain_info->{'includes'}} );
611
PlatformEntry( "vc_libs\t="    , "\n", "\\\n\t" . '$(call encodepath,', ')', @{$toolchain_info->{'libs'}} );
612
 
613
    PlatformDefine( "WCE_EMULATOR\t".   ":= 1" )
614
        if ( $WCETargetCPU eq "emulator" );
615
 
616
    PlatformEntry( "WCE_DEFINES\t=",    "\n", "\\\n\t", "", @defines )
617
        if ( scalar @defines );
618
 
619
    PlatformEntry( "WCE_CFLAGS\t=",     "\n", "\\\n\t", "", @cflags )
620
        if ( scalar @cflags );
621
 
622
    PlatformEntry( "WCE_CFLAGSD\t=",    "\n", "\\\n\t", "", @cflags_debug )
623
        if ( scalar @cflags_debug );
624
 
625
    PlatformEntry( "WCE_CFLAGSP\t=",    "\n", "\\\n\t", "", @cflags_prod )
626
        if ( scalar @cflags_prod );
627
 
628
    PlatformEntry( "WCE_LDFLAGS\t=",    "\n", "\\\n\t", "", @ldflags )
629
        if ( scalar @ldflags );
630
 
631
    PlatformEntry( "WCE_LIBFLAGS\t=",    "\n", "\\\n\t", "", @libflags )
632
        if ( scalar @libflags );
633
 
634
    PlatformEntry( "WCE_LDFLAGSD\t=",   "\n", "\\\n\t", "", @ldflags_debug )
635
        if ( scalar @ldflags_debug );
636
 
637
    PlatformEntry( "WCE_LDFLAGSP\t=",   "\n", "\\\n\t", "", @ldflags_prod )
638
        if ( scalar @ldflags_prod );
639
 
640
if ( $is_vs2005 )
641
{
642
    $compiler = 'cl';
643
    $linker = 'link';
644
}
645
    PlatformDefine( "
646
WCE_CC		:= $compiler
647
WCE_LINK	:= $linker
648
" );
649
 
650
    Init( $toolchain_info->{'initDef'} );
651
    ToolsetDefines( $toolchain_info->{'def'} );
652
    PlatformDefine ("VSCOMPILER\t= $toolchain_info->{'VSCOMPILER'}" );
653
    ToolsetRules( "vcwce.rul" );
654
    ToolsetRules( "standard.rul" );
655
 
656
#.. define PCLint envrionment
657
    ToolsetRequire( "pclint" );                 # using pclint
658
    PlatformDefine ("LINT_COFILE\t= co-msc60.lnt");
659
    PlatformDefine ("LINT_PRJ_FILE\t=lint.vcembedded");
660
 
661
#.. Cleanup rules
662
#
663
    ToolsetGenerate( "\$(OBJDIR)/$toolchain_info->{'tmp'}.idb" );
664
    ToolsetGenerate( "\$(OBJDIR)/$toolchain_info->{'tmp'}.pch" );
665
    ToolsetGenerate( "\$(OBJDIR)/$toolchain_info->{'tmp'}.pdb" );
666
    ToolsetGenerate( "\$(PDB)" );
667
    ToolsetGenerate( "\$(PDB).tmp" );
668
 
669
 
670
#
671
#   The PDB files need to be compiled up with absolute paths to the source files
672
#   The easiest way to do this is with the makefile rules created with absolute
673
#   paths. Set a global flag to enable this option
674
#
675
    $::UseAbsObjects = 1;
676
 
677
 
678
#.. Extend the CompilerOption directive
679
#   Create a standard data structure
680
#   This is a hash of hashes
681
#       The first hash is keyed by CompileOption keyword
682
#       The second hash contains pairs of values to set or remove
683
#
684
    %::ScmToolsetCompilerOptions =
685
    (
686
        'rtti'               => { 'USE_RTTI', 1 },
687
        'nopdb'              => { 'PDB_NONE', 1 },
688
        'pdb'                => { 'PDB_NONE', undef },
317 dpurdie 689
        'exceptions'         => { 'USE_HANDLING', 1 },
690
        'noexceptions'       => { 'USE_HANDLING', undef },
6294 dpurdie 691
        'subsystem:windows'  => { 'ENTRYPOINT' , 'WinMainCRTStartup' },
692
        'subsystem:console'  => { 'ENTRYPOINT' , 'mainACRTStartup' },
303 dpurdie 693
    );
694
 
695
    #
696
    #   Set default options
317 dpurdie 697
    #       USE_HANDLING - not always the same default
303 dpurdie 698
    #
317 dpurdie 699
    $::ScmCompilerOpts{'USE_HANDLING'} = $default_ehandling;
303 dpurdie 700
}
701
 
702
##############################################################################
703
#   ToolsetPreprocess()
704
#       Process collected data before the makefile is generated
705
#       This, optional, routine is called from within MakefileGenerate()
706
#       It allows the toolset to massage any of the collected data before
707
#       the makefile is created
708
#
709
##############################################################################
710
sub ToolsetPreprocess
711
{
712
    #
713
    #   Extract the current state of PDB_NONE
714
    #   Are PDB files to be constructed.
715
    #
716
    $pdb_none = $::ScmCompilerOpts{'PDB_NONE'};
717
}
718
 
719
##############################################################################
720
#   ToolsetPostprocess
721
#       Process collected data as the makefile is generated
722
#       This, optional, routine is called from within MakefileGenerate()
723
#       It allows the toolset to massage any of the collected data before
724
#       the makefile is finally closed created
725
#
726
##############################################################################
727
 
728
sub ToolsetPostprocess
729
{
730
    MakeHeader('Toolset Postprocessed Information');
731
 
732
    #
733
    #   Specify the name of the global PDB file. This is used for all
734
    #   compiles other than those associated with building a DLL
735
    #
736
    #   The name of the PDB will be based on either
737
    #       The name of base package
738
    #       The name of the first static library created
739
    #
740
 
741
MakePrint("
742
#
743
#   Export the name of the common PDB file
744
#   All compiler information will be placed in this file
745
#   The name of the file MUST be the same as the name of the output library
746
#
747
PDB		= \$(OBJDIR)/$pdb_file\$(GBE_TYPE).pdb
748
" );
749
 
750
    #
751
    #   Add values to the perl environment
752
    #   May be used by post processing tools to create Visual Studio Projects
753
    #
754
    $::TS_pdb_file = "\$(OBJDIR)/$pdb_file\$(GBE_TYPE).pdb" unless( $pdb_none );
755
    $::TS_sbr_support = 1;
756
 
757
    #
758
    #   Prioritorise target: EXE, DLL, LIB
759
    #
760
    for my $tgt ( $target_file_exe, $target_file_dll, $target_file_lib  )
761
    {
762
        if ( $tgt )
763
        {
764
            $::TS_target_file = $tgt;
765
            last;
766
        }
767
    }
768
}
769
 
770
###############################################################################
771
#   ToolsetCC( $source, $obj, \@args )
772
#       This subroutine takes the user options and builds the rule(s)
773
#       required to compile the source file 'source' to 'obj'
774
#
775
###############################################################################
776
 
777
sub ToolsetCC
778
{
779
    ToolsetCC_common( "CC", @_ );
780
}
781
 
782
sub ToolsetCC_common
783
{
784
    my( $name, $source, $obj, $pArgs ) = @_;
785
    my( $cflags, $pdb );
786
 
787
    foreach $_ ( @$pArgs ) {
788
        if (/--Shared$/) {                      # Building a 'shared' object
789
            $cflags = "$cflags \$(SHCFLAGS)";
790
            $pdb = $::SHOBJ_LIB{$obj}
791
                if (exists $::SHOBJ_LIB{$obj} );
792
 
793
        } else {
343 dpurdie 794
            Message( "$toolset_name $name: unknown option $_ -- ignored\n" );
303 dpurdie 795
        }
796
    }
797
 
798
    MakePrint( "\n\t\$($name)\n" );
799
    MakePadded( 4, "\$(OBJDIR)/$obj.$::o:", "\tCFLAGS +=$cflags\n" )
800
        if ( $cflags );                         # object specific CFLAGS
801
 
802
    if ( $pdb && !$pdb_none )
803
    {
804
        #
805
        #   Determine the name of the PDB file
806
        #   If we are building a shared library then the name of the PDB
807
        #   MUST NOT be the same as the name of the library as there is
808
        #   some stange interaction with the linker ( 50% of the time )
809
        #   This is OK as the file will not be published
810
        #
811
        #   If building a static library then create a PDB of the same
812
        #   name as it may be published directly.
813
        #
814
        my $pdb_file;
815
        if ($cflags )
816
        {
817
            $pdb_file = "\$(OBJDIR)/${pdb}\$(GBE_TYPE)_shlib.pdb";
818
        }
819
        else
820
        {
821
            $pdb_file = "\$(OBJDIR)/${pdb}\$(GBE_TYPE).pdb";
822
        }    
823
 
824
        MakePadded( 4, "\$(OBJDIR)/$obj.$::o:", "\tPDB = $pdb_file\n" );
825
        ToolsetGenerate( $pdb_file );
826
        ToolsetGenerate( $pdb_file . ".tmp" );
827
    }
828
 
829
    #
830
    #   Remove possible Source Browser Files
831
    #
832
    ToolsetGenerate( "\$(OBJDIR)/$obj.sbr" );
833
    MakePrint( "\n" );
834
}
835
 
836
 
837
###############################################################################
838
#   ToolsetCCDepend( $depend, \@sources )
839
#       This subroutine takes the user options and builds the
840
#       rule(s) required to build the dependencies for the source
841
#       files 'sources' to 'depend'.
842
#
843
###############################################################################
844
 
845
sub ToolsetCCDepend
846
{
847
    MakePrint( "\t\$(CCDEPEND)\n" );
848
}
849
 
850
 
851
###############################################################################
852
#   ToolsetCXX( $source, $obj, \@args )
853
#       This subroutine takes the user options and builds the rule(s)
854
#       required to compile the source file 'source' to 'obj'
855
#
856
###############################################################################
857
 
858
sub ToolsetCXX
859
{
860
    ToolsetCC_common( "CXX", @_ );
861
}
862
 
863
###############################################################################
864
#   ToolsetCXXDepend( $depend, \@sources )
865
#       This subroutine takes the user options and builds the
866
#       rule(s) required to build the dependencies for the source
867
#       files 'sources' to 'depend'.
868
#
869
###############################################################################
870
 
871
sub ToolsetCXXDepend
872
{
335 dpurdie 873
    ToolsetCCDepend();
303 dpurdie 874
}
875
 
876
 
877
###############################################################################
878
#   ToolsetAS( $source, $obj, \@args )
879
#       This subroutine takes the user options and builds the rule(s)
880
#       required to compile the source file 'source' to 'obj'
881
#
882
###############################################################################
883
 
884
sub ToolsetAS
885
{
886
    MakePrint( "\n\t\$(AS)\n" );
887
}
888
 
889
sub ToolsetASDepend
890
{
891
}
892
 
893
###############################################################################
894
#   ToolsetAR( $name, \@args, \@objs )
895
#       This subroutine takes the user options and builds the rules
896
#       required to build the library 'name'.
897
#
898
#   Arguments:
899
#       --Def=name              Library definition module
900
#
901
#   Output:
902
#       [ $(LIBDIR)/name$.${a}:   .... ]
903
#           $(AR)
904
#
905
###############################################################################
906
 
907
sub ToolsetAR
908
{
909
    my( $name, $pArgs, $pObjs ) = @_;
910
    my( $def );
911
    my ( $res, @reslist );
912
    my $lib_base = "\$(LIBDIR)/${name}\$(GBE_TYPE)";
913
    my $lib_name = "$lib_base.${a}";
914
 
915
 
916
#.. Parse arguments
917
#
918
    $def = "";                                  # options
919
    $res = "";
920
 
921
    foreach $_ ( @$pArgs ) {
922
        if (/^--Def=(.*)/) {                    # library definition
923
            $def = "$1";
924
 
925
        } elsif (/^--Resource=(.*)/) {          # Resource definition
926
            ($res, @reslist) = ToolsetRClist( "$name", $1 );
927
 
928
        } else {                                # unknown
343 dpurdie 929
            Message( "$toolset_name AR: unknown option $_ -- ignored\n" );
303 dpurdie 930
        }
931
    }
932
 
933
#.. Resource Creation
934
#
935
    MakePrint( "#.. Library Resource ($name)\n\n" );
936
    ToolsetRCrecipe( $res, @reslist )
937
        if ( $res );
938
 
939
#.. Target
940
#
941
    MakePrint( "#.. Library ($name)\n\n" );     # label
942
 
943
    MakePrint( "$lib_name:\tLIBDEF=$def\n" ) if ($def);
944
    MakeEntry( "$lib_name:\t", "", "\\\n\t\t", ".$::o", @$pObjs );
945
    MakePrint( "\\\n\t\t$def" ) if ($def);
946
    MakePrint( "\\\n\t\t$res" ) if ($res);
947
    MakePrint( "\n\t\$(AR)" );
948
 
949
#
950
#   Track the name of the possible target file
951
#   Used when creating Visual Studio projects
952
#
953
    $target_file_lib = $lib_name;
954
 
955
#
956
#   To assist in debugging the static library it is nice to
957
#   keep the PDB file used to build the library, with the library.
958
#
959
#   If the library is being packaged or installed then add the PDB
960
#   file to the package / installation
961
#
962
#   NOTE: Due to the limitations of JATS/MicroSoft only one static
963
#   library can be built with a PDB file. The name of the PDB file
964
#   will be taken from the first static library encountered
965
#
966
    unless ( $pdb_first_lib )
967
    {
968
        $pdb_first_lib = $name;
969
        $pdb_file = $name;
970
    }
971
    else
972
    {
973
        Warning( "Multiple static libraries created with a common PDB file: $pdb_file, $name" )
974
            unless( $pdb_none );
975
    }
976
 
977
    PackageLibAddFiles( $name, "\$(OBJDIR)/$pdb_file\$(GBE_TYPE).pdb", "Class=debug" )
978
        unless( $pdb_none );
979
}
980
 
981
 
982
###############################################################################
983
#   ToolsetARLINT( $name, \@args, \@objs )
984
#       This subroutine takes the user options and builds the rules
985
#       required to build the library 'name'.
986
#
987
#   Arguments:
988
#       --xxx                   No arguments currently defined
989
#
990
#   Output:
991
#       [ $(LIBDIR)/name$_lint:   .... ]
992
#           $(ARLINT)
993
#
994
###############################################################################
995
 
996
sub ToolsetARLINT
997
{
998
    PCLintAR( @_ );
999
}
1000
 
1001
 
1002
###############################################################################
1003
#   ToolsetARMerge( $name, \@args, \@libs )
1004
#       This subroutine takes the user options and builds the rules
1005
#       required to build the library 'name' by merging the specified
1006
#       libaries
1007
#
1008
#   Arguments:
1009
#       --xxx                   No arguments currently defined
1010
#
1011
#   Output:
1012
#       [ $(LIBDIR)/name$.${a}:   .... ]
1013
#           ...
1014
#
1015
###############################################################################
1016
 
1017
sub ToolsetARMerge
1018
{
1019
    my ($name, $pArgs, $pLibs) = @_;
1020
    MakePrint( "\n\t\$(ARMERGE)\n\n" );
1021
 
1022
    #
1023
    #   Package up the PDB's with the library
1024
    #   Note: The PDBs will be found in the OBJDIR
1025
    #
1026
    unless( $pdb_none )
1027
    {
1028
        for ( @{$pLibs} )
1029
        {
1030
            s~\$\(LIBDIR\)~\$(OBJDIR)~;
1031
            PackageLibAddFiles( $name, "$_\$(GBE_TYPE).pdb", "Class=debug" );
1032
        }
1033
    }
1034
}
1035
 
1036
 
1037
###############################################################################
1038
#   ToolsetSHLD $name, \@args, \@objs, \@libraries, $ver )
1039
#       This subroutine takes the user options and builds the rules
1040
#       required to link a shared library
1041
#
1042
#   Arguments:
1043
#       --Def=xxxx.def[,opts]           # Definition file
1044
#           --MutualDll                 # SubOption: Generate a Mutual DLL
1045
#       --MutualDll                     # Generate a Mutual DLL (requires --Def=xxx)
1046
#       --StubOnly                      # Only generate the stub library (requires --Def=xxx)
1047
#       --Resource=xxxx.rc              # Resource file
1048
#       --ResourceOnly                  # Only resources in this DLL
1049
#       --Implib                        # Alternate ruleset
1050
#       --NoPDB                         # Do not package the PDB file
1051
#       --NoImplib                      # Do not package the import library
1052
#       --Entry=xxxxx                   # Entry point
1053
#       --NoAddLibs                     # Do not add libraries
1054
#
1055
#   Output:
1056
#
1057
#       There is two supported rule sets differentiated by --Implib
1058
#       The two are very similar and generated exportable files of:
1059
#
1060
#       --Implib
1061
#           ${name}.lib         - Stub lib adresses the versioned DLL
1062
#           ${name}.${ver}.dll
1063
#
1064
#       Default
1065
#           ${name}.lib         - Stub lib addresses UN-versioned DLL
1066
#           ${name}.dll
1067
#           ${name}.${ver}.dll
1068
#
1069
#       Note: Each DLL has an associated PDB file
1070
#
1071
#       Generation is identical for both rulesets. The default form does
1072
#       not export any stub library associated with the versioned DLL.
1073
#
1074
#   Implementation notes
1075
#   The process of creating a DLL and associated import library (LIB) is
1076
#
1077
#           ${name}.${ver}.dep
1078
#           ${name}.${ver}.pdb          - Exported
1079
#           ${name}.${ver}.ilk
1080
#           ${name}.${ver}.dll          - Exported
1081
#           ${name}.${ver}.map
1082
#           ${name}.lib                 - Exported + Optional
1083
#           ${name}.exp
1084
#
1085
#       Where:    lib = name
1086
#
1087
#       #.. Rules ($lib)
1088
#
1089
#       $(LIBDIR)/${lib}.lib:               $(LIBDIR)/${lib}.${ver}.dll
1090
#       $(LIBDIR)/${lib}.pdb:               $(LIBDIR)/${lib}.${ver}.dll
1091
#       $(LIBDIR)/${lib}.${ver}.pdb:        $(LIBDIR)/${lib}.${ver}.dll
1092
#
1093
#       $(LIBDIR)/${lib}.${ver}.dep:        SHBASE=${name}
1094
#       $(LIBDIR)/${lib}.${ver}.dep:        SHNAME=${lib}.${ver}
1095
#       $(LIBDIR)/${lib}.${ver}.dep:        \$(LIBDIR)
1096
#       $(LIBDIR)/${lib}.${ver}.dep:        Makefile
1097
#           $(SHLDDEPEND)
1098
#
1099
#       $(LIBDIR)/${lib}.${ver}.${so}:      SHBASE=${name}
1100
#       $(LIBDIR)/${lib}.${ver}.${so}:      SHNAME=${lib}.${ver}
1101
#       $(LIBDIR)/${lib}.${ver}.${so}:      CFLAGS+=$(SHCFLAGS)
1102
#       $(LIBDIR)/${lib}.${ver}.${so}:      CXXLAGS+=$(SHCXXFLAGS)
1103
#       $(LIBDIR)/${lib}.${ver}.${so}:      ${def}
1104
#       $(LIBDIR)/${lib}.${ver}.${so}:      $(OBJDIR)/${name} \
1105
#                       object list ... \
1106
#                       $(LIBDIR)/${lib}.${ver}.dep
1107
#           $(SHLD)
1108
#           @$(cp) -f $(LIBDIR)/${lib}.${ver}.pdb $(LIBDIR)/${lib}.pdb
1109
#
1110
#       ifneq "$(findstring $(IFLAG),23)" ""
1111
#       -include        "$(LIBDIR)/${lib}.${ver}.dep"
1112
#       endif
1113
#
1114
#       #.. Linker commands ($lib)
1115
#
1116
#       ${lib}_ld       += ...
1117
#               standard flags                          \
1118
#               -implib:$${lib}.lib
1119
#
1120
#       #.. Linker commands ($lib)
1121
#
1122
#       ${lib}_shdp     += ...
1123
#
1124
###############################################################################
1125
 
1126
sub ToolsetSHLD
1127
{
1128
    our( $name, $pArgs, $pObjs, $pLibs, $ver ) = @_;
1129
    our( $def, $mutual_dll, $res, @reslist, $doimplib, $stub_only );
1130
    our( $no_implib, $no_pdb, $resource_only );
6442 dpurdie 1131
    our( $entry, $entrySet, $noaddlibs );
303 dpurdie 1132
 
1133
#.. Parse arguments
1134
#
1135
    $def = "";                                  # options
1136
    $doimplib = 0;
1137
    $res = "";
1138
    $no_pdb = $pdb_none;
6294 dpurdie 1139
    $entry = '_DllMainCRTStartup';
303 dpurdie 1140
 
1141
    foreach $_ ( @$pArgs ) {
1142
        if (/^--Def=(.*?)(\,(.*))?$/) {         # Library definition
1143
            #
1144
            #   Locate the Def file.
1145
            #   If it is a generate file so it will be in the SRCS hash
1146
            #   Otherwise the user will have to use Src to locate the file
1147
            #
1148
            $def = MakeSrcResolve($1);
1149
 
1150
            #
1151
            #   Process sub options to --Def
1152
            #
1153
            next unless ($2);
1154
            if ( $3 =~ /^--MutualDll$/ ) {
1155
                $mutual_dll = 1;
1156
            } else {
343 dpurdie 1157
                Message( "$toolset_name SHLD: unknown option $_ -- ignored\n" );
303 dpurdie 1158
            }
1159
 
1160
        } elsif (/^--Resource=(.*)/) {          # Resource definition
1161
            ($res, @reslist) = ToolsetRClist( "$name/$name", $1 );
1162
 
1163
        } elsif (/^--ResourceOnly/) {          # Resource definition
1164
            $resource_only = 1;
1165
 
1166
        } elsif (/^--Implib$/) {
1167
            $doimplib = 1;
1168
 
1169
        } elsif (/^--NoImplib$/) {
1170
            $no_implib = 1;
1171
 
1172
        } elsif (/^--NoPDB$/) {
1173
            $no_pdb = 1;
1174
 
1175
        } elsif (/^--Entry=(.*)/) {
1176
            $entry = $1;
6442 dpurdie 1177
            $entrySet = 1;
303 dpurdie 1178
 
1179
        } elsif (/^--NoAddLib/) {
1180
            $noaddlibs = 1;
1181
 
1182
        } elsif (/^--MutualDll$/) {
1183
            $mutual_dll = 1;
1184
 
1185
        } elsif (/^--Stubonly/) {
1186
            $stub_only = 1;
1187
 
1188
        } else {                                # unknown
343 dpurdie 1189
            Message( "$toolset_name SHLD: unknown option $_ -- ignored\n" );
303 dpurdie 1190
        }
1191
    }
1192
 
1193
    #
1194
    #   Sanity test
1195
    #
343 dpurdie 1196
    Error ("$toolset_name SHLD:Stubonly option requires --Def=file ")
303 dpurdie 1197
        if ( $stub_only && ! $def );
1198
 
343 dpurdie 1199
    Error ("$toolset_name SHLD:MutualDll option requires --Def=file ")
303 dpurdie 1200
        if ( $mutual_dll && ! $def );
1201
 
6442 dpurdie 1202
    Error ("$toolset_name SHLD:--ResourceOnly and --Entry options are mutually exclusive")
1203
        if ($entrySet && $resource_only);
303 dpurdie 1204
 
1205
 
6442 dpurdie 1206
 
303 dpurdie 1207
#.. Build rules
1208
#
1209
#   base    -   Basic name of the DLL
1210
#   name    -   Name of the Export library (Optional)
1211
#   lib     -   Name of the DLL
1212
#
1213
    sub BuildSHLD
1214
    {
1215
        my ($base, $name, $lib) = @_;
1216
        my $full = $lib.".$::so";
1217
        my $link_with_def;
1218
 
1219
    #.. Cleanup rules
1220
    #
1221
    #   ld      Linker command file
1222
    #   map     Map file
1223
    #   pdb     Microsoft C/C++ program database
1224
    #   ilk     Microsoft Linker Database
1225
    #
1226
        ToolsetGenerate( "\$(LIBDIR)/${lib}.ld" );
1227
        ToolsetGenerate( "\$(LIBDIR)/${lib}.map" );
1228
        ToolsetGenerate( "\$(LIBDIR)/${lib}.exp" );
1229
        ToolsetGenerate( "\$(LIBDIR)/${lib}.ilk" );
1230
        ToolsetGenerate( "\$(LIBDIR)/${full}" );
1231
 
1232
    #.. Linker rules
1233
    #
1234
        my ($io) = ToolsetPrinter::New();
1235
 
1236
        my $import_lib;
1237
        my $export_file;
1238
 
1239
        if ( $name && $def && ($mutual_dll || $stub_only ) )
1240
        {
1241
            #
1242
            #   Creating an Export library from user .DEF file
1243
            #   It is possible to create the stub library in the LIB phase
1244
            #   which allows DLLs with mutual imports
1245
            #
1246
            $io->Label( "Import(stub) library for mutual exports", $name );
1247
            $export_file = "\$(LIBDIR)/${name}.exp";
1248
 
1249
            #
1250
            #   Rules and recipe to generate the stub library
1251
            #
1252
            $io->Prt( "\$(LIBDIR)/${name}.exp:\t\$(LIBDIR)/${name}.${a}\n" );
1253
            $io->Prt( "\$(LIBDIR)/${name}.${a}:\tLIBDEF=$def\n" );
1254
            $io->Prt( "\$(LIBDIR)/${name}.${a}:\tLIBNAME=$lib\n" );
1255
            $io->Entry( "\$(LIBDIR)/${name}.${a}: \\\n\t\t\$(OBJDIR)/${base}",
1256
                                            "", " \\\n\t\t", ".$::o", @$pObjs );
1257
            $io->Prt( " \\\n\t\t$def" );
1258
            $io->Prt( "\n\t\t\$(AR)\n" );
1259
            $io->Newline();
1260
 
1261
            #
1262
            #   Files to be cleanup up
1263
            #
1264
            ToolsetGenerate( "\$(LIBDIR)/${name}.exp" );
1265
            ToolsetGenerate( "\$(LIBDIR)/${name}.${a}" );
1266
 
1267
            #
1268
            #   If the DLL is being packaged/installed then add the static
1269
            #   stub library to the packaging lists as a static library
1270
            #   This will allow the stub library to be installed with the
1271
            #   static libraries and thus allow DLL's with mutual imports
1272
            #
1273
            PackageShlibAddLibFiles ($base, "\$(LIBDIR)/${name}.${a}" )
1274
                unless ($resource_only);
1275
 
1276
            #
1277
            #   Add the stub library to the list of libraries being created
1278
            #   Note: Don't do if not created with .DEF file
1279
            #
1280
            push @::LIBS, $base;
1281
 
1282
        }
1283
        else
1284
        {
1285
            #
1286
            #   The stub library is created as part of the DLL generation
1287
            #   Whether we like it or not - so we need to control the name
1288
            #   and location
1289
            #
1290
            my $slname = ($name) ? $name : $lib;
1291
            $import_lib = "\$(LIBDIR)/${slname}.${a}";
1292
 
1293
            $io->Label( "Import(stub) library", $slname );
1294
            $io->Prt( "$import_lib:\t\$(LIBDIR)/${full}\n" );
1295
            $io->Newline();
1296
 
1297
            ToolsetGenerate( $import_lib );
1298
            ToolsetGenerate( "\$(LIBDIR)/${slname}.exp" );
1299
 
1300
            #
1301
            #   Package the generated stub library, if it is being
1302
            #   created on request.
1303
            #
1304
            #   Package it with the shared libaries and not the static
1305
            #   libraries as it will be created with the shared library
1306
            #
1307
            PackageShlibAddFiles ($base, $import_lib, 'Class=lib' )
1308
                if ($name && ! $no_implib && ! $resource_only);
1309
 
1310
            #
1311
            #   Indicate that we will be linking with a DEF file
1312
            #
1313
            $link_with_def = 1 if ( $def );
1314
        }
1315
 
1316
        #
1317
        #   If we are only creating a stub library, then the hard work has been
1318
        #   done.
1319
        #
1320
        return
1321
            if ($stub_only);
1322
 
1323
        $io->Label( "Shared library", $name );
1324
 
1325
        #
1326
        #   The process of creating a DLL will generate PDB file
1327
        #   Control the name of the PDB file
1328
        #
1329
        my $pdb_file = "\$(LIBDIR)/${lib}.pdb";
1330
        unless( $no_pdb )
1331
        {
1332
            $io->Prt( "$pdb_file:\t\$(LIBDIR)/${full}\n" );
1333
            ToolsetGenerate( $pdb_file );
1334
        }
1335
 
1336
        #
1337
        #   Package the PDB file up with the DLL
1338
        #   Package the DLL - now that we know its proper name
1339
        #
1340
        PackageShlibAddFiles( $base, $pdb_file, 'Class=debug' ) unless $no_pdb ;
1341
        PackageShlibAddFiles( $base, "\$(LIBDIR)/${full}" );
1342
 
1343
        #
1344
        #   Generate Shared Library dependency information
1345
        #
335 dpurdie 1346
        my $dep = $io->SetShldTarget( $lib );
303 dpurdie 1347
 
1348
        #
1349
        #   Generate rules and recipes to create the body of the shared
1350
        #   library. Several build variables are overiden when creating
1351
        #   a shared library.
1352
        #
1353
        $io->Prt( "\$(LIBDIR)/${full}:\tSHBASE=${lib}\n" );
1354
        $io->Prt( "\$(LIBDIR)/${full}:\tSHNAME=${lib}\n" );
1355
        $io->Prt( "\$(LIBDIR)/${full}:\tCFLAGS+=\$(SHCFLAGS)\n" );
1356
        $io->Prt( "\$(LIBDIR)/${full}:\tCXXLAGS+=\$(SHCXXFLAGS)\n" );
1357
        $io->Prt( "\$(LIBDIR)/${full}:\t$export_file\n" ) if ($export_file );
1358
        $io->Prt( "\$(LIBDIR)/${full}:\t$res\n" ) if ( $res );
1359
 
335 dpurdie 1360
        $io->Entry( "\$(LIBDIR)/${full}: $dep \\\n\t\t\$(OBJDIR)/${base}",
303 dpurdie 1361
            "", " \\\n\t\t", ".$::o", @$pObjs );
1362
 
1363
        $io->Prt( " \\\n\t\t$def" ) if ( $link_with_def );
335 dpurdie 1364
        $io->Prt( "\n\t\$(SHLD)\n" );
303 dpurdie 1365
 
1366
        $io->Newline();
1367
 
1368
        #.. Linker command file
1369
        #
1370
        #       Now the fun part... piecing together a variable ${name}_shld
1371
        #       which ends up in the command file.
1372
        #
1373
        $io->SetTag( "${lib}_shld" );          # command tag
1374
 
1375
        $io->Label( "Linker commands", $name ); # label
1376
 
1377
        $io->Cmd( "-dll" );
1378
        $io->Cmd( "-noentry" )if ($resource_only);
1379
        $io->Cmd( "-def:$def" ) if ($link_with_def);
1380
        $io->Cmd( "-out:\$(subst /,\\\\,\$(LIBDIR)/${full})" );
1381
        $io->Cmd( "-implib:\$(subst /,\\\\,$import_lib)" ) if ($import_lib);
1382
        $io->Cmd( "-pdb:\$(subst /,\\\\,$pdb_file)" ) unless ( $no_pdb );
1383
        $io->Cmd( "-debug:none" )                     if ($no_pdb);
1384
        $io->Cmd( "-pdb:none" )                       if ($no_pdb);
6294 dpurdie 1385
        $io->Cmd( "-entry:$entry" )                   unless ($resource_only);
303 dpurdie 1386
        $io->Cmd( "-map:\$(subst /,\\\\,\$(LIBDIR)/${lib}).map" );
1387
        $io->Cmd( "\$(subst /,\\\\,$res)" ) if ( $res );
1388
        $io->Cmd( "\$(subst /,\\\\,$export_file)" ) if ( $export_file );
1389
 
1390
                                                # object list
1391
        $io->ObjList( $name, $pObjs, \&ToolsetObjRecipe );
1392
 
1393
                                                # library list
1394
        $io->LibList( $name, $pLibs, \&ToolsetLibRecipe );
1395
 
1396
        $io->Newline();
1397
 
1398
        #.. Dependency link,
335 dpurdie 1399
        #   Create a library dependency file
1400
        #       Create command file to build applicaton dependency list
1401
        #       from the list of dependent libraries
303 dpurdie 1402
        #
335 dpurdie 1403
        #       Create makefile directives to include the dependency
1404
        #       list into the makefile.
303 dpurdie 1405
        #
335 dpurdie 1406
        $io->DepRules( $pLibs, \&ToolsetLibRecipe, "\$(LIBDIR)/${full}" );
1407
        $io->SHLDDEPEND( $name, $lib );
303 dpurdie 1408
    }
1409
 
1410
    ToolsetLibStd( $pLibs )                    # push standard libraries
1411
        unless ( $noaddlibs );
1412
 
1413
    if ( $doimplib ) {
1414
        #
1415
        #   --Implib flavor will create
1416
        #       a) Import library   $name$(GBE_TYPE).lib
1417
        #       b) Versioned DLL    $name$(GBE_TYPE).xx.xx.xx.dll
1418
        #
1419
        $target_file_dll = "\$(LIBDIR)/$name\$(GBE_TYPE).$ver.$::so";
1420
        BuildSHLD(
1421
            "$name",                        # Base Name
1422
            "$name\$(GBE_TYPE)",            # Name of Export Lib
1423
            "$name\$(GBE_TYPE).$ver");      # Name of the DLL + PDB
1424
 
1425
    } else {
1426
        #
1427
        #   Original flavor will create
1428
        #       a) Import library   $name$(GBE_TYPE).lib    ---+
1429
        #       b) Unversioned DLL  $name$(GBE_TYPE).dll    <--+
1430
        #       c) Versioned DLL    $name$(GBE_TYPE).xx.xx.xx.dll
1431
        #
1432
        MakePrint(
1433
            "# .. Versioned image\n\n".
1434
            "\$(LIBDIR)/${name}\$(GBE_TYPE).$::so:\t".
1435
            "\$(LIBDIR)/${name}\$(GBE_TYPE).$ver.$::so\n".
1436
            "\n" );
1437
 
1438
        $target_file_dll = "\$(LIBDIR)/$name\$(GBE_TYPE).$::so";
1439
        BuildSHLD( "$name", "$name\$(GBE_TYPE)" , "$name\$(GBE_TYPE)" );
1440
        BuildSHLD( "$name", ""                  , "$name\$(GBE_TYPE).$ver" );
1441
    }
1442
 
1443
    #.. Resource File
1444
    #
1445
    ToolsetRCrecipe( $res, @reslist )
1446
        if ( $res );
1447
}
1448
 
1449
 
1450
###############################################################################
1451
#   ToolsetSHLDLINT $name, \@args, \@objs, \@libraries )
1452
#       This subroutine takes the user options and builds the rules
1453
#       required to lint the program 'name'.
1454
#
1455
#   Arguments:
1456
#       (none)
1457
#
1458
#   Output:
1459
#       [ $(LIBDIR)/$name_lint:   .... ]
1460
#           $(SHLIBLINT)
1461
#
1462
###############################################################################
1463
 
1464
sub ToolsetSHLDLINT
1465
{
1466
    PCLintSHLIB( @_ );
1467
}
1468
 
1469
 
1470
###############################################################################
335 dpurdie 1471
# Function        : ToolsetLD
303 dpurdie 1472
#
335 dpurdie 1473
# Description     : Takes the user options and builds the rules required to
1474
#                   link the program 'name'.
303 dpurdie 1475
#
335 dpurdie 1476
# Inputs          : $name           - base name of the program
1477
#                   $pArgs          - Ref to program arguments
1478
#                   $pObjs          - Ref to program objects
1479
#                   $pLibs          - Ref to program library list
303 dpurdie 1480
#
335 dpurdie 1481
# Returns         : Nothing
303 dpurdie 1482
#
335 dpurdie 1483
# Output:         : Rules and recipes to create a program
1484
#                       Create program rules and recipes
1485
#                       Create linker input script
1486
#                       Create library dependency list
1487
#                       Include library dependency information
303 dpurdie 1488
#
1489
sub ToolsetLD
1490
{
1491
    my ( $name, $pArgs, $pObjs, $pLibs ) = @_;
1492
    my ( $res, @reslist );
1493
    my $no_pdb =$pdb_none;
1494
    our( $entry, $noaddlibs );
6294 dpurdie 1495
    my $stack = '0x10000,0x1000';
303 dpurdie 1496
 
6294 dpurdie 1497
    #
1498
    #   Auto calc entry point - only in new WinCE
1499
    #   Default is for subsystem:windows
1500
    #   
1501
    if ($toolchain_info->{'calcEntryPoint'}) {
6619 dpurdie 1502
        if (exists $::ScmCompilerOpts{'ENTRYPOINT'}) {
1503
            $entry = $::ScmCompilerOpts{'ENTRYPOINT'}; 
6294 dpurdie 1504
        }
1505
    }
1506
 
303 dpurdie 1507
#.. Parse arguments
1508
#
1509
    foreach ( @$pArgs ) {
1510
        if (/^--Resource=(.*)/) {               # Resource definition
1511
            ($res, @reslist) = ToolsetRClist( $name, $1 );
1512
 
1513
        } elsif (/^--NoPDB$/) {
1514
            $no_pdb = 1;
1515
 
1516
        } elsif (/^--Entry=(.*)/) {
1517
            $entry = $1;
1518
 
1519
        } elsif (/^--NoAddLib/) {
1520
            $noaddlibs = 1;
1521
 
6294 dpurdie 1522
        } elsif (/^--Stack=(.*)/i) {            # Alternate stack.
1523
            $stack   = $1;
1524
 
303 dpurdie 1525
        } else {
343 dpurdie 1526
            Message( "$toolset_name LD: unknown option $_ -- ignored\n" );
303 dpurdie 1527
 
1528
        }
1529
    }
1530
 
335 dpurdie 1531
#.. Names of important files
1532
#
1533
    my $base = "\$(BINDIR)/${name}";
1534
    my $full = $base . $::exe;
1535
    my $map  = $base . '.map';
1536
    my $pdb  = $base . '.pdb';
1537
 
1538
 
303 dpurdie 1539
#.. Cleanup rules
1540
#
1541
#   ld      Linker command file
1542
#   map     Map file
1543
#   pdb     Microsoft C/C++ program database
1544
#   ilk     Microsoft Linker Database
1545
#   res     Compiled resource script
1546
#
335 dpurdie 1547
    ToolsetGenerate( $map );
1548
    ToolsetGenerate( $pdb );
1549
    ToolsetGenerate( $base . '.ld' );
1550
    ToolsetGenerate( $base . '.ilk' );
303 dpurdie 1551
 
335 dpurdie 1552
#.. Toolset Printer
303 dpurdie 1553
#
1554
    my ($io) = ToolsetPrinter::New();
335 dpurdie 1555
    my $dep = $io->SetLdTarget( $name );
303 dpurdie 1556
 
335 dpurdie 1557
#
1558
#.. Linker command
1559
#
1560
    $io->Prt( "$full : $dep " );
1561
    $io->Entry( "", "", "\\\n\t", ".$::o ", @$pObjs );
1562
    $io->Prt( "\\\n\t$res " ) if ( $res );
1563
    $io->Prt( "\n\t\$(LD)\n\n" );
303 dpurdie 1564
 
1565
#.. Linker command file
1566
#
1567
#       Now piece together a variable $(name_ld) which ends up in
1568
#       the command file linking the application.
1569
#
1570
    $io->SetTag( "${name}_ld" );                # macro tag
1571
 
1572
    $io->Label( "Linker commands", $name );     # label
1573
 
335 dpurdie 1574
    $io->Cmd( "-out:\$(subst /,\\\\,$full)" );
1575
    $io->Cmd( "-pdb:\$(subst /,\\\\,$pdb)" )        unless ($no_pdb);
2429 dpurdie 1576
    $io->Cmd( "-debug:none" )                       if ($no_pdb);
1577
    $io->Cmd( "-pdb:none" )                         if ($no_pdb);
1578
    $io->Cmd( "-entry:$entry" )                     if ($entry);
6294 dpurdie 1579
    $io->Cmd( "-stack:$stack" )                     if ($stack);
335 dpurdie 1580
    $io->Cmd( "-map:\$(subst /,\\\\,$map)" );
1581
    $io->Cmd( "\$(subst /,\\\\,$res)" )             if ( $res );
303 dpurdie 1582
 
335 dpurdie 1583
    ToolsetLibStd( $pLibs ) unless ( $noaddlibs );      # push standard libraries
1584
    $io->ObjList( $name, $pObjs, \&ToolsetObjRecipe );  # object list
1585
    $io->LibList( $name, $pLibs, \&ToolsetLibRecipe );  # library list
303 dpurdie 1586
    $io->Newline();
1587
 
335 dpurdie 1588
    #.. Dependency link,
1589
    #   Create a library dependency file
1590
    #       Create command file to build applicaton dependency list
1591
    #       from the list of dependent libraries
1592
    #
1593
    #       Create makefile directives to include the dependency
1594
    #       list into the makefile.
1595
    #
1596
    $io->DepRules( $pLibs, \&ToolsetLibRecipe, $full );
1597
    $io->LDDEPEND();
303 dpurdie 1598
 
1599
#.. Compile up the resource file
1600
#
1601
    ToolsetRCrecipe( $res, @reslist )
1602
        if ( $res );
1603
 
1604
#.. Package up the PDB file with the program
1605
#
335 dpurdie 1606
    PackageProgAddFiles ( $name, $full );
1607
    PackageProgAddFiles ( $name, $pdb, "Class=debug" ) unless ( $no_pdb );
303 dpurdie 1608
 
1609
#
1610
#   Track the name of the possible target file
1611
#   Used when creating Visual Studio projects
1612
#
335 dpurdie 1613
    $target_file_exe = $full;
303 dpurdie 1614
}
1615
 
1616
 
1617
###############################################################################
1618
#   ToolsetLD( $name, \@args, \@objs, \@libraries, \@csrc, \@cxxsrc )
1619
#       This subroutine takes the user options and builds the rules
1620
#       required to lint the program 'name'.
1621
#
1622
#   Arguments:
1623
#       (none)
1624
#
1625
#   Output:
1626
#       [ $(BINDIR)/$name_lint:   .... ]
1627
#           $(LDLINT)
1628
#
1629
###############################################################################
1630
 
1631
sub ToolsetLDLINT
1632
{
1633
    PCLintLD( @_ );
1634
}
1635
 
1636
 
1637
########################################################################
1638
#
1639
#   Push standard "system" libraries. This is a helper function
1640
#   used within this toolset.
1641
#
1642
#   Arguments:
1643
#       $plib       Reference to library array.
1644
#
1645
########################################################################
1646
 
1647
sub ToolsetLibStd
1648
{
1649
    my ($plib) = @_;
1650
 
1651
    #
1652
    #   Only add libraries if required
1653
    #
1654
    return unless( $::ScmCompilerOpts{'ADDLINKLIBS'} );
1655
 
1656
}
1657
 
1658
 
1659
########################################################################
1660
#
1661
#   Generate a linker object recipe.  This is a helper function used 
1662
#   within this toolset.
1663
#
1664
#   Arguments:
1665
#       $io         I/O stream
1666
#
1667
#       $target     Name of the target
1668
#
1669
#       $obj        Library specification
1670
#
1671
########################################################################
1672
 
1673
sub ToolsetObjRecipe
1674
{
1675
    my ($io, $target, $obj) = @_;
1676
 
1677
    $io->Cmd( "\$(subst /,\\\\,\$(strip $obj)).$::o" );
1678
}
1679
 
1680
 
1681
########################################################################
1682
#
1683
#   Generate a linker/depend library recipe.  This is a helper function
1684
#   used within this toolset.
1685
#
1686
#   Arguments:
1687
#       $io         I/O stream
1688
#
1689
#       $target     Name of the target
1690
#
1691
#       $lib        Library specification
1692
#
1693
#       $dp         If building a depend list, the full target name.
1694
#
1695
########################################################################
1696
 
1697
sub ToolsetLibRecipe
1698
{
1699
    my ($io, $target, $lib, $dp) = @_;
1700
 
1701
    return                                      # ignore (compat)
1702
        if ( $lib eq "rt" ||        $lib eq "thread" ||
1703
             $lib eq "pthread" ||   $lib eq "nsl" ||
1704
             $lib eq "socket" );
1705
 
1706
    if ( !defined($dp) ) {                      # linker
1707
        $io->Cmd( "\$(subst /,\\\\,\$(strip $lib)).$::a" );
1708
 
1709
    } else {                                    # depend
1710
        $io->Cmd( "$dp:\t@(vlib2,$lib,LIB)" );
1711
    }
1712
}
1713
 
1714
 
1715
########################################################################
1716
#
1717
#   Parse resource file data
1718
#   This is a helper function used within this toolset
1719
#
1720
#   Arguments   : $1  BaseName
1721
#                 $2  The users resource list
1722
#                     This is a list of comma seperated files
1723
#                     The first file is the main resource script
1724
#
1725
#   Returns     : An array of resource files with full pathnames
1726
#                 [0] = The output file
1727
#                 [1] = The input file
1728
#                 [..] = Other input files
1729
#
1730
########################################################################
1731
 
1732
sub ToolsetRClist
1733
{
1734
    my ($name, $files) = @_;
1735
    my @result;
1736
 
1737
    #
1738
    #   Generate the name of the output file
1739
    #
1740
    push @result, "\$(OBJDIR)/$name.res";
1741
 
1742
    #
1743
    #   Process each user file
1744
    #
335 dpurdie 1745
    for (split( '\s*,\s*', $files ))
303 dpurdie 1746
    {
1747
        #
1748
        #   Locate the file.
1749
        #   If it is a generate file so it will be in the SRCS hash
1750
        #   Other wise the use will have to use Src to locate the file
1751
        #
1752
        push @result, MakeSrcResolve($_);
1753
    }
1754
 
1755
    #
1756
    #   Return the array to the user
1757
    #
1758
    return @result;
1759
}
1760
 
1761
 
1762
########################################################################
1763
#
1764
#   Generate a resource file recipe
1765
#   This is a helper function used within this tool
1766
#
1767
#   Arguments   : $1  Output resource file
1768
#                 ..  Input resource files
1769
#
1770
########################################################################
1771
 
1772
sub ToolsetRCrecipe
1773
{
1774
    my ($out, @in) = @_;
1775
 
1776
    #
1777
    #   Cleanup
1778
    #
1779
    ToolsetGenerate( $out );
1780
 
1781
    #
1782
    #   Recipe
1783
    #
1784
    MakePrint( "\n#.. Compile Resource file: $out\n\n" );
1785
    MakePrint( "$out:\t\$(GBE_PLATFORM).mk\n" );
1786
    MakeEntry( "$out:\t", "", "\\\n\t\t", " ", @in );
1787
    MakePrint( "\n\t\$(RC)\n" );
1788
    MakePrint( "\n" );
1789
}
1790
 
1791
########################################################################
1792
#
1793
#   Generate a project from the provided project file
1794
#
1795
#   Arguments   : $name             - Base name of the project
1796
#                 $project          - Path to the project file
1797
#                 $pArgs            - Project specific options
1798
#
1799
########################################################################
1800
 
1801
my $project_defines_done = 0;
1802
sub ToolsetPROJECT
1803
{
1804
    my( $name, $project, $pArgs ) = @_;
1805
    my $buildcmd = $toolchain_info->{'buildcmd'};
1806
    my $cleancmd = $toolchain_info->{'cleancmd'};
343 dpurdie 1807
    my $release = ${$toolchain_info->{'def_targets'}}[0] || 'RELEASE';
1808
    my $debug =   ${$toolchain_info->{'def_targets'}}[1] || 'DEBUG';
303 dpurdie 1809
 
1810
    #
1811
    #   Process options
1812
    #
1813
    foreach ( @$pArgs ) {
343 dpurdie 1814
        if ( m/^--TargetProd*=(.+)/ ) {
1815
            $release = $1;
1816
 
1817
        } elsif ( m/^--TargetDebug=(.+)/ ) {
1818
            $debug = $1;
1819
 
1820
        } else {
1821
            Message( "$toolset_name PROJECT: unknown option $_ -- ignored\n" );
1822
        }
303 dpurdie 1823
    }
343 dpurdie 1824
 
303 dpurdie 1825
    my ($io) = ToolsetPrinter::New();
1826
 
1827
    #
343 dpurdie 1828
    #   Setup toolset specific difinitions. Once
303 dpurdie 1829
    #
1830
    unless( $project_defines_done )
1831
    {
1832
        $project_defines_done = 1;
343 dpurdie 1833
        $io->PrtLn( 'project_target = $(if $(findstring 1,$(DEBUG)),$2,$1)' );
303 dpurdie 1834
        $io->Newline();
1835
    }
1836
 
1837
    #
1838
    #   Process the build and clean commands
1839
    #       Substitute arguments
1840
    #           =TYPE=
1841
    #           =LOG=
1842
    #           =DSW=
1843
    #           =CEPLATFORM=
1844
    #
343 dpurdie 1845
    $buildcmd =~ s~=TYPE=~"\$(call project_target,$release,$debug)"~g;
303 dpurdie 1846
    $buildcmd =~ s~=LOG=~$name\$(GBE_TYPE).log~g;
1847
    $buildcmd =~ s~=DSW=~$project~g;
1848
    $buildcmd =~ s~=CEPLATFORM=~\$(WCE_PLATFORM)~g;
1849
 
343 dpurdie 1850
    $cleancmd =~ s~=TYPE=~"\$(call project_target,$release,$debug)"~g;
303 dpurdie 1851
    $cleancmd =~ s~=LOG=~$name\$(GBE_TYPE).log~g;
1852
    $cleancmd =~ s~=DSW=~$project~g;
1853
    $cleancmd =~ s~=CEPLATFORM=~\$(WCE_PLATFORM)~g;
1854
 
1855
    #
1856
    #   Generate the recipe to create the project
1857
    #
1858
    $io->Label( "Build project", $name );
1859
    $io->PrtLn( "Project_$name: $project" );
1860
    $io->PrtLn( "\t\$(XX_PRE)( \$(rm) -f $name\$(GBE_TYPE).log; \\" );
1861
    $io->PrtLn( "\t\$(show_environment); \\" );
1862
    $io->PrtLn( "\t$buildcmd; \\" );
1863
    $io->PrtLn( "\tret=\$\$?; \\" );
1864
    $io->PrtLn( "\t\$(GBE_BIN)/cat $name\$(GBE_TYPE).log; \\" );
1865
    $io->PrtLn( "\texit \$\$ret )" );
1866
    $io->Newline();
1867
 
1868
    #
1869
    #   Generate the recipe to clean the project
1870
    #
1871
    $io->Label( "Clean project", $name );
1872
    $io->PrtLn( "ProjectClean_$name: $project" );
1873
    $io->PrtLn( "\t-\$(XX_PRE)$cleancmd" );
1874
    $io->PrtLn( "\t-\$(XX_PRE)\$(rm) -f $name\$(GBE_TYPE).log" );
1875
    $io->Newline();
1876
 
1877
}
1878
 
1879
 
1880
#.. Successful termination
1881
1;
1882