Subversion Repositories DevTools

Rev

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