Subversion Repositories DevTools

Rev

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