Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
227 dpurdie 1
#
2
# Module name   : CSHARP
3
# Module type   : Makefile system
4
# Compiler(s)   : ANSI C
5
# Environment(s): WIN32
6
#
7
# Description:
8
#       CSHARP for Windows
9
#
10
#............................................................................#
11
use strict;
12
use warnings;
13
use MakeEntry;
14
 
15
#
16
#   Global data
17
#
18
my %resource_files;
19
my $pdb_none;
20
 
343 dpurdie 21
my $toolset_name = 'csharp';                           # Toolset name : Error reporting
255 dpurdie 22
my $toolset_info;
23
my $toolset_version = '1.1';
24
my %ToolsetVersion =
25
    (
26
    '1.1' => { 'def'      => 'CSHARP.DEF',              # Def file to use
27
               'pragma'   => 0,                         # True: Compiler supports #pragma
28
               'warnings' => '',                        # Comma sep list of warnings to ignore
29
             },
30
 
31
    '2.0' => { 'def'      => 'CSHARP2005.DEF',
32
               'pragma'   => 1,
33
               'warnings' => '1668',
34
             },
291 dpurdie 35
 
36
    '3.5' => { 'def'      => 'CSHARP2008.DEF',
37
               'pragma'   => 1,
38
               'warnings' => '1668',
39
             },
347 dpurdie 40
 
41
    '4.0' => { 'def'      => 'CSHARP2010.DEF',
42
               'pragma'   => 1,
43
               'warnings' => '1668',
351 dpurdie 44
               'platform' => 'x86',
347 dpurdie 45
             },
46
 
255 dpurdie 47
    );
48
 
49
 
227 dpurdie 50
##############################################################################
51
#   ToolsetInit()
52
#       Runtime initialisation
53
#
54
##############################################################################
55
 
56
ToolsetInit();
57
 
58
sub ToolsetInit
59
{
60
 
61
    #.. Parse arguments (Toolset arguments)
62
    #
343 dpurdie 63
    Debug( "$toolset_name(@::ScmToolsetArgs)" );
227 dpurdie 64
 
65
    foreach $_ ( @::ScmToolsetArgs ) {
66
        if (/^--Version=(.*)/) {                # MS SDK Version
67
            $toolset_version = $1;
68
 
69
        } else {
343 dpurdie 70
            Message( "$toolset_name toolset: unknown option $_ -- ignored\n" );
227 dpurdie 71
        }
72
    }
73
 
74
    #.. Parse arguments (platform arguments)
75
    #
343 dpurdie 76
    Debug( "$toolset_name(@::ScmPlatformArgs)" );
227 dpurdie 77
 
78
    foreach $_ ( @::ScmPlatformArgs ) {
79
        if (/^--product=(.*)/) {                # GBE product
80
 
81
        } elsif (/^--Version=(.*)/) {           # MS SDK Version
82
            $toolset_version = $1;
83
 
84
        } else {
343 dpurdie 85
            Message( "$toolset_name toolset: unknown platform argument $_ -- ignored\n" );
227 dpurdie 86
        }
87
    }
88
 
255 dpurdie 89
    #.. Validate SDK version
90
    #   Currently supported versions are described in a HASH
227 dpurdie 91
    #
255 dpurdie 92
    $toolset_info = $ToolsetVersion{$toolset_version};
343 dpurdie 93
    Error( "$toolset_name toolset: Unknown version: $toolset_version" ) unless ( defined $toolset_info );
255 dpurdie 94
 
227 dpurdie 95
    #.. Standard.rul requirements
96
    #
97
    $::s    = undef;
98
    $::o    = '';
99
    $::a    = 'netmodule';
100
    $::so   = 'dll';
101
    $::exe  = '.exe';
102
 
103
    #.. Toolset configuration
104
    #
105
    $::ScmToolsetVersion = "1.0.0";             # our version
106
    $::ScmToolsetGenerate = 0;                  # generate optional
107
    $::ScmToolsetProgDependancies = 0;          # handle Prog dependancies myself
108
    %::ScmToolsetProgSource = (                 # handle these files directly
109
            '.cs'       => '',                  # Will be flagged as "CSRCS"
110
            '.resx'     => '--Resource=',       # Will be passed with prefix
111
            '.dtd'      => '--Dtd=',            # Will be passed with prefix
112
            );
113
 
114
    #.. define Visual C/C+ environment
115
    Init( "csharp" );
255 dpurdie 116
    ToolsetDefines( $toolset_info->{'def'} );
227 dpurdie 117
    ToolsetRules( "csharp.rul" );
118
#    ToolsetRules( "standard.rul" );
119
 
120
 
121
    #.. Extend the CompilerOption directive
122
    #   Create a standard data structure
123
    #   This is a hash of hashes
124
    #       The first hash is keyed by CompileOption keyword
125
    #       The second hash contains pairs of values to set or remove
126
    #
127
    %::ScmToolsetCompilerOptions =
128
    (
129
        #
130
        #   Control the thread model to use
131
        #   This will affect the compiler options and the linker options
132
        #
133
        'noaddlibs'          => { 'ADDLINKLIBS' , undef },      # Don't add link libs
134
        'addlibs'            => { 'ADDLINKLIBS' , '1' },        # default
135
        'nowarn='            => { 'NOWARNLIST'  ,\&NoWarns },   # Suppress warnings
136
        'nopdb'              => { 'PDB_NONE', 1 },              # Disable all PDB files
137
        'pdb'                => { 'PDB_NONE', undef },          # Enable PDB files: Default
138
        'subsystem:windows'  => { 'LDSUBSYSTEM' , 'winexe' },
139
        'subsystem:console'  => { 'LDSUBSYSTEM' , 'exe' },
351 dpurdie 140
        'platform:32'        => { 'NET_PLATFORM', 'x86' },
141
        'platform:64'        => { 'NET_PLATFORM', 'x64' },
142
        'platform:any'       => { 'NET_PLATFORM', undef },
227 dpurdie 143
    );
144
 
145
    #
146
    #   Set default options
147
    #
148
    $::ScmCompilerOpts{'ADDLINKLIBS'} = '1';
255 dpurdie 149
    $::ScmCompilerOpts{'NOWARNLIST'} = $toolset_info->{'warnings'};
227 dpurdie 150
    $::ScmCompilerOpts{'LDSUBSYSTEM'} = 'winexe';
351 dpurdie 151
    $::ScmCompilerOpts{'NET_PLATFORM'} = $toolset_info->{'platform'};
227 dpurdie 152
}
153
 
154
 
155
#-------------------------------------------------------------------------------
156
# Function        : NoWarns
157
#
158
# Description     : ScmToolsetCompilerOptions  extension function
255 dpurdie 159
#                   Accumulates the NoWarn options as a comma seperated list
227 dpurdie 160
#
161
# Inputs          : $key        - Name of the Option
162
#                   $value      - Option Value. Comma sep list of numbers
255 dpurdie 163
#                   $ukey       - User key (within $::ScmCompilerOpts)
227 dpurdie 164
#
165
# Returns         : New sting to save
166
#
167
sub NoWarns
168
{
255 dpurdie 169
    my ($key, $value, $ukey) = @_;
170
    my @NoWarnList =  split (',', $::ScmCompilerOpts{$ukey});
261 dpurdie 171
    UniquePush ( \@NoWarnList, split (',', $value) );
227 dpurdie 172
    return join ',', @NoWarnList;
173
}
174
 
175
##############################################################################
176
#   ToolsetPreprocess()
177
#       Process collected data before the makefile is generated
178
#       This, optional, routine is called from within MakefileGenerate()
179
#       It allows the toolset to massage any of the collected data before
180
#       the makefile is created
181
#
182
##############################################################################
183
sub ToolsetPreprocess
184
{
185
    #
186
    #   Extract the current state of PDB_NONE
187
    #   Are PDB files to be constructed.
188
    #
189
    $pdb_none = $::ScmCompilerOpts{'PDB_NONE'};
190
}
191
 
192
##############################################################################
193
#   ToolsetPostprocess
194
#       Process collected data as the makefile is generated
195
#       This, optional, routine is called from within MakefileGenerate()
196
#       It allows the toolset to massage any of the collected data before
197
#       the makefile is finally closed created
198
#
199
##############################################################################
200
 
201
sub ToolsetPostprocess
202
{
203
    #
204
    #   Generate Recipes to create Resource Files
205
    #   This is done outside of the Prog and Lib routines
206
    #   so that they can be agregated
207
    #
208
    #   Note: don't make the makefile a dependant as changes to the
209
    #         makefile won't affect the file
210
    #
211
    for my $resource ( sort keys %resource_files )
212
    {
213
        my $src  = $resource_files{$resource}{src};
214
        my $root = $resource_files{$resource}{root};
215
 
216
        my $me = MakeEntry::New (*MAKEFILE, $resource );
217
        $me->AddComment ("Build Resource: $root" );
261 dpurdie 218
#        $me->AddDependancy ( '$(SCM_MAKEFILE)' );
227 dpurdie 219
        $me->AddDependancy ( $src );
220
        $me->AddRecipe ( '$(RESGEN)' );
221
        $me->Print();
222
 
223
        #
224
        #   Add to the deletion list
225
        #
226
        ToolsetGenerate( $resource );
227
    }
228
}
229
 
230
#-------------------------------------------------------------------------------
231
# Function        : Toolset_genres
232
#
233
# Description     : Internal function to assist in the creation of a resource
234
#                   In many cases it will create an entry for later processing
235
#
236
# Inputs          : $subdir         - Root of the target directory for the generated
237
#                                     resource file
238
#                   $src            - Path to the sorce resource file
239
#
240
# Returns         : Path to the generated resource file
241
#                   This will be FQN named file
242
#                   Path to the associated .CS file
243
#
244
# Notes           : Create and maintain the %resource_files hash
245
#                   Key is the path to the compiled file
246
#                   Values are:
247
#                       {src}   - Path to the source file
248
#                       {root}  - Basic file name (Display Purposes Only)
249
#
250
#                   Need to create a '.resource' file with a FQN name
251
#                   This is not that simple. Need to
252
#                       1) Extract the (optional) ThisName from the .resx file
253
#                          If not specified then the ThisName is the rootfilename
254
#                          without any .as[pca]x extension.
255
#                       2) Extract the namespace from the associated .cs file
256
#                       3) FQN = NameSpace.ThisName
257
#
258
#
259
sub Toolset_genres
260
{
261
    my ($subdir, $src ) = @_;
262
 
263
    #
264
    #   Ensure that the .cs file also exists
265
    #
266
    (my $csfile = $src) =~ s~\.resx$~.cs~;
343 dpurdie 267
    Error ("$toolset_name toolset: Resx File without a .cs file",
227 dpurdie 268
           "File: $src") unless ( -f $src );
269
 
270
    #
271
    #   Scan the .resx file looking for the ThisName element
272
    #   A very simple and crude parser
273
    #
274
    my $ThisName;
275
    open ( SCAN, '<', $src ) || Error ("Cannot open file for reading: $!", "File: $src" );
276
    while ( <SCAN> )
277
    {
278
        if ( m~\<data name=\"\$this\.Name\"\>~ )
279
        {
280
            # Next line will contain the needed data item
281
            my $element = <SCAN>;
282
            $element =~ m~\<.+\>(.+)\</.+\>~;
283
            $ThisName = $1;
343 dpurdie 284
            Error ("$toolset_name toolset: Resx parsing: Bad this.Name", "File: $src") unless $ThisName;
227 dpurdie 285
            $ThisName =~ s~\s+~~g;
286
            last;
287
        }
288
    }
289
    close SCAN;
290
 
291
    #
292
    #   Name not found
293
    #   Use a default. Filename with any .aspx, .asax, .ascx removed
294
    #
295
    unless ( $ThisName )
296
    {
297
        $ThisName = StripDirExt($src);
298
        $ThisName =~ s~\.as[pac]x~~i;
299
    }
300
 
301
    #
302
    #   Scan the.cs file looking for the namespace
303
    #   A very simple and crude parser
304
    #
305
    my $NameSpace;
306
    open ( SCAN, '<', $csfile ) || Error ("Cannot open file for reading: $!", "File: $csfile" );
307
    while ( <SCAN> )
308
    {
309
        if ( m~namespace\s+(\S+)~ )
310
        {
311
            $NameSpace = $1;
312
            last;
313
        }
314
    }
315
    close SCAN;
343 dpurdie 316
    Error ("$toolset_name toolset: Resx parsing: NameSpace not found", "File: $csfile") unless $NameSpace;
227 dpurdie 317
 
318
    #
319
    #   Need to create an output file name that is a function of the FQN
320
    #
321
    my $root = "$NameSpace.$ThisName.resources";
322
    my $resource = $subdir . '/' . $root;
323
 
324
    $resource_files{$resource}{src} = $src;
325
    $resource_files{$resource}{root} = $root;
326
 
327
    return $resource, $csfile;
328
}
329
 
330
 
331
#-------------------------------------------------------------------------------
332
# Function        : Toolset_gensnk
333
#
334
# Description     : Function to create a wrapper file for the processing
335
#                   of a StrongNameKey file
336
#
337
#                   Create only one wrapper per SNK file
338
#
339
# Inputs          : $name       - Name of component
340
#                   $snk        - Path to the SNK file
341
#
342
# Returns         : Path to the wrapper file
343
#
344
my %snk_data;
345
sub Toolset_gensnk
346
{
347
    my ($name, $snk ) = @_;
348
    my $file = StripDirExt( $snk );
349
 
350
    #
351
    #   Only create the file once
352
    #   Otherwise we will get nasty make messages
353
    #
354
 
355
    if ( exists $snk_data{$snk} )
356
    {
357
        return $snk_data{$snk}{output};
358
    }
359
 
360
    #
361
    #   Determine the target name
362
    #   Create the source file in the currentt directory
363
    #   If we build it in the OBJ directory we get two files
364
    #
365
    my $snk_file = '$(OBJDIR)/' . "Jats_${file}.cs";
366
    $snk_data{$snk}{output} = $snk_file;
367
    ToolsetGenerate( $snk_file );
368
 
369
    #
370
    #   Determine the Tag Name
371
    #   Used to conatin information in the makefile
372
    #
373
    my $tag = "${file}_snk";
374
 
375
    #
376
    #   Create Rules and Recipes to create the SNK wrapper file
377
    #
378
    my $me = MakeEntry::New (*MAKEFILE, $snk_file );
379
    $me->AddComment ("Build Strong Name Key File Wrapper: $snk" );
380
    $me->AddDependancy ( $snk );
261 dpurdie 381
    $me->AddDependancy ( '$(SCM_MAKEFILE)' );
227 dpurdie 382
    $me->AddRecipe ( '$(call GenSnkWrapper,' . $tag .  ')' );
383
    $me->Print();
384
 
385
    #
386
    #   Create the data t be placed into the wrapper file
387
    #
388
    my ($io) = ToolsetPrinter::New();
389
 
390
    my $ms_snk = $snk;
391
 
392
    $io->Label( "SNK Wrapper file content", $tag );    # label
393
    $io->SetTag( $tag );                                # macro tag
255 dpurdie 394
    $io->Cmd( '// This is JATS GENERATED FILE' );
395
    $io->Cmd( '//    Do not edit' );
396
    $io->Cmd( '//    Do not version control' );
397
 
227 dpurdie 398
    $io->Cmd( 'using System.Reflection;' );
399
    $io->Cmd( 'using System.Runtime.CompilerServices;' );
400
 
401
    $io->Cmd( '//' );
402
    $io->Cmd( '// In order to sign your assembly you must specify a key to use. Refer to the' );
403
    $io->Cmd( '// Microsoft .NET Framework documentation for more information on assembly signing.' );
404
    $io->Cmd( '//' );
405
    $io->Cmd( '// Use the attributes below to control which key is used for signing.' );
406
    $io->Cmd( '//' );
407
    $io->Cmd( '// Notes:' );
408
    $io->Cmd( '//   (*) If no key is specified, the assembly is not signed.' );
409
    $io->Cmd( '//   (*) KeyName refers to a key that has been installed in the Crypto Service' );
410
    $io->Cmd( '//       Provider (CSP) on your machine. KeyFile refers to a file which contains' );
411
    $io->Cmd( '//       a key.' );
412
    $io->Cmd( '//   (*) If the KeyFile and the KeyName values are both specified, the' );
413
    $io->Cmd( '//       following processing occurs:' );
414
    $io->Cmd( '//       (1) If the KeyName can be found in the CSP, that key is used.' );
415
    $io->Cmd( '//       (2) If the KeyName does not exist and the KeyFile does exist, the key' );
416
    $io->Cmd( '//           in the KeyFile is installed into the CSP and used.' );
417
    $io->Cmd( '//   (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.' );
418
    $io->Cmd( '//       When specifying the KeyFile, the location of the KeyFile should be' );
419
    $io->Cmd( '//       relative to the project output directory which is' );
420
    $io->Cmd( '//       %Project Directory%\obj\<configuration>. For example, if your KeyFile is' );
421
    $io->Cmd( '//       located in the project directory, you would specify the AssemblyKeyFile' );
422
    $io->Cmd( '//       attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]' );
423
    $io->Cmd( '//   (*) Delay Signing is an advanced option - see the Microsoft .NET Framework' );
424
    $io->Cmd( '//       documentation for more information on this.' );
425
    $io->Cmd( '//' );
426
 
427
    $io->Cmd( '[assembly: AssemblyDelaySign(false)]' );
255 dpurdie 428
    $io->Cmd( '#pragma warning disable 1699' ) if ($toolset_info->{'pragma'});
227 dpurdie 429
    $io->Cmd( '[assembly: AssemblyKeyFile(@"'. $snk  .'")]' );
255 dpurdie 430
    $io->Cmd( '#pragma warning restore 1699' ) if ($toolset_info->{'pragma'});
227 dpurdie 431
    $io->Cmd( '[assembly: AssemblyKeyName("")]' );
432
    $io->Newline();
433
 
434
    #
435
    #   Return the path to where the file will be created
436
    #
437
    return $snk_file;
438
}
439
 
440
 
441
###############################################################################
442
#   ToolsetLD( $name, \@args, \@objs, \@libraries )
443
#       This subroutine takes the user options and builds the rules
444
#       required to link the program 'name'.
445
#
446
#   Arguments:
447
#       $name       - Name of the target program
448
#       $pArgs      - Ref to an array of argumennts
449
#       $pObjs      - Ref to an array of object files
450
#       $pLibs      - Ref to an array of libraries
451
#
452
#   Output:
453
#       Makefile recipes to create the Program
454
#
455
#   Notes:
456
#       This Program Builder will handle its own dependancies
457
#       It will also create rules and recipes to construct various
458
#       parts directly fromm source
459
#
460
#   Options:
461
#       --Resource=file.resx
462
#       --Dtd=file.dtd
463
#       --Icon=file
464
#       --Entry=xxxxx                   # Entry point
465
#       --Console                       # Console app
466
#       --Windows                       # Windows app (default)
467
#       --DLL                           # As a DLL (No P|D)
468
#       --Doc
469
#       --NoPDB
470
#       CSharpSourceFile
471
#
472
#
473
###############################################################################
474
 
475
sub ToolsetLD
476
{
477
    my ( $name, $pArgs, $pObjs, $pLibs ) = @_;
478
    my ( @reslist, @resources, @csource, @dtd );
479
    my $no_pdb = $pdb_none;
480
    my $entry;
481
    my $noaddlibs;
482
    my $icon;
483
    my $docFile;
484
    my ($base, $root, $full );
485
    my $link_target = $::ScmCompilerOpts{'LDSUBSYSTEM'};
486
    my $snk;
487
    my $is_a_dll;
488
 
489
    #.. Parse arguments
490
    #
491
    foreach ( @$pArgs ) {
492
        if (/^--Resource=(.+)/) {               # Resource definition
493
            push @reslist, MakeSrcResolve($1);
494
 
495
        } elsif (/^--Dtd=(.+)/) {               # dtd definition
496
            push @dtd, MakeSrcResolve($1);
497
 
498
        } elsif (/^--Icon=(.+)/) {
343 dpurdie 499
            Error ("$toolset_name LD: Only one Icon file allowed") if ( $icon );
227 dpurdie 500
            $icon = MakeSrcResolve($1);
501
 
502
        } elsif (/^--StrongNameKey=(.+)/) {
343 dpurdie 503
            Error ("$toolset_name LD: Only one SNK file allowed") if ( $snk );
227 dpurdie 504
            $snk = MakeSrcResolve($1);
505
 
506
        } elsif (/^--Entry=(.+)/) {
507
            $entry = $1;
508
 
509
        } elsif (/^--Doc/) {
510
            $docFile = 1;
511
 
512
        } elsif (/^--Windows/) {
513
            $link_target = 'winexe';
514
 
515
        } elsif (/^--Console/) {
516
            $link_target = 'exe';
517
 
518
        } elsif (/^--DLL/) {
519
            $is_a_dll = 1;
520
 
521
        } elsif (/^--NoPDB$/) {
522
            $no_pdb = 1;
523
 
524
        } elsif ( !/^-/ ) {
525
            push @csource, MakeSrcResolve($_);
526
 
527
        } else {
343 dpurdie 528
            Message( "$toolset_name LD: unknown option $_ -- ignored\n" );
227 dpurdie 529
 
530
        }
531
    }
532
 
533
    #
534
    #   Determine the target output name
535
    #
536
    $base = $name;
537
    $root = "\$(BINDIR)/$base";
538
    $full = $root . $::exe;
539
    $docFile = "$root.xml" if ( $docFile );
540
 
541
    #
542
    #   Special case for DLLs that need to be created without a D or P mangled
543
    #   into the name. Create them as Progs just to fool the system
544
    #   Used when creating specialised web services
545
    #
546
    if ( $is_a_dll )
547
    {
548
        #
549
        #   Create a phony target
550
        #   The EXE name is not actually created, but the EXE target needs to be retained
551
        #
552
        my $exe_name = $root . $::exe;
553
        my $dll_name = $root . '.' . $::so;
554
        $full = $dll_name;
555
        $link_target = 'library';
556
 
557
        my $me = MakeEntry::New (*MAKEFILE, $exe_name, '--Phony' );
558
        $me->AddComment ("Build Program: $name as a DLL" );
559
        $me->AddDependancy ( $dll_name );
560
        $me->Print();
255 dpurdie 561
 
562
        #
563
        #   Need to specifically clean this up, since we have fiddled with the
564
        #   name of the generated file
565
        #
566
        ToolsetGenerate( $dll_name );
227 dpurdie 567
    }
568
 
569
    #
570
    #   Create Rules and Recipes to convert the .resx files to .resource files
571
    #
572
    foreach my $res ( @reslist )
573
    {
574
        my ($res, $cs) = Toolset_genres ('$(OBJDIR)', $res );
575
 
576
        UniquePush ( \@resources, $res );
577
        UniquePush ( \@csource, $cs );
578
    }
579
 
580
    #
581
    #   Create Rules and Recipes to provide Assembly instructions
582
    #   for the creation of a StrongNameKey
583
    #
584
    if ( $snk )
585
    {
586
        UniquePush ( \@csource, Toolset_gensnk ($name, $snk ) );
587
    }
588
 
335 dpurdie 589
    my ($io) = ToolsetPrinter::New();
590
    my $dep = $io->SetLdTarget( $name );
591
 
227 dpurdie 592
    #
593
    #   Create Rules and Recipes to create the Program
594
    #   This will be a combination of source, libraries and resources
595
    #
596
    my $me = MakeEntry::New (*MAKEFILE, $full );
597
    $me->AddComment ("Build Program: $name" );
598
    $me->AddName    ( $docFile ) if ( $docFile );
335 dpurdie 599
    $me->AddDependancy ( $dep );
261 dpurdie 600
    $me->AddDependancy ( '$(SCM_MAKEFILE)' );
227 dpurdie 601
    $me->AddDependancy ( @resources );
602
    $me->AddDependancy ( @csource );
603
    $me->AddDependancy ( @dtd );
604
    $me->AddDependancy ( $icon );
605
    $me->AddRecipe ( '$(CSC)' );
606
    $me->Print();
607
 
608
 
609
    #
610
    #.. Compiler command file
611
    #       Now piece together a variable $(name_ld) which ends up in
612
    #       the command file linking the application.
613
    #
614
    $io->Label( "Linker commands", $name );     # label
615
    $io->SetTag( "${name}_ld" );                # macro tag
616
 
617
    $io->Label( "Linker Command File", $name ); # label
618
 
619
    #
620
    #   Basic options
621
    #
622
    $io->Cmd( "/target:$link_target" );
623
    $io->Cmd("/doc:$docFile") if ( $docFile ) ;
624
    $io->Cmd( "/win32icon:\$(subst /,\\\\,$icon)" ) if $icon;
625
    $io->Cmd( "/main:$entry" ) if $entry;
626
 
627
    #
628
    #   Add in the Resource Files
629
    #          the source files
630
    #          the libraries
631
    #
632
    $io->Cmd( "/res:\$(subst /,\\\\,$_)" ) foreach @resources;
633
    $io->Cmd( "/res:\$(subst /,\\\\,$_)" ) foreach @dtd;
634
    $io->Cmd( "\$(subst /,\\\\,$_)" ) foreach @csource;
635
    $io->LibList( $name, $pLibs, \&ToolsetLibRecipe );
335 dpurdie 636
    $io->Newline();
227 dpurdie 637
 
638
 
335 dpurdie 639
    #.. Dependency link,
640
    #   Create a library dependency file
641
    #       Create command file to build applicaton dependency list
642
    #       from the list of dependent libraries
227 dpurdie 643
    #
335 dpurdie 644
    #       Create makefile directives to include the dependency
645
    #       list into the makefile.
227 dpurdie 646
    #
335 dpurdie 647
    $io->DepRules( $pLibs, \&ToolsetLibRecipe, $full );
648
    $io->LDDEPEND();
227 dpurdie 649
 
650
    #
651
    #   Files to clean up
652
    #
653
    ToolsetGenerate( "$root.ld" );
654
    ToolsetGenerate( "$root.pdb" );
655
    ToolsetGenerate( $docFile ) if $docFile;
656
 
657
 
658
    #.. Package up files that are a part of the program
659
    #
660
    PackageProgAddFiles ( $name, $full );
661
    PackageProgAddFiles ( $name, "$root.pdb", "Class=debug" ) unless ( $no_pdb );
662
    PackageProgAddFiles ( $name, $docFile, "Class=map" ) if ( $docFile );
663
}
664
 
665
###############################################################################
289 dpurdie 666
#   ToolsetSHLD( $name, \@args, \@objs, \@libraries, $ver )
227 dpurdie 667
#       This subroutine takes the user options and builds the rules
668
#       required to link the program 'name'.
669
#
670
#   Arguments:
671
#       $name       - Name of the target program
672
#       $pArgs      - Ref to an array of argumennts
673
#       $pObjs      - Ref to an array of object files
674
#       $pLibs      - Ref to an array of libraries
289 dpurdie 675
#       $ver        - Library Version string
227 dpurdie 676
#
677
#   Output:
678
#       Makefile recipes to create the DLL
679
#       Will create both versioned and unversioned DLLs
680
#
681
#   Notes:
682
#       This Library Builder will handle its own dependancies
683
#       It will also create rules and recipes to construct various
684
#       parts directly from source
685
#
686
#       This is SO close to the ToolsetLD function that its not funny
687
#
688
#   Options:
689
#       --Resource=file.resx
690
#       --Icon=file
691
#       --StrongNameKey=file
692
#       --Doc
693
#       --NoPDB
694
#       CSharpSourceFile
695
#
696
#
697
###############################################################################
698
sub ToolsetSHLD
699
{
700
    #
701
    #   Note: Use globals to kill warnings from internal sub
702
    #         Use _ prefix so that they don't get saved in Makefile_x.cfg
703
    #         Init as they are global
704
    #
289 dpurdie 705
    our ( $_name, $_pArgs, $_pObjs, $_pLibs, $_ver ) = @_;
227 dpurdie 706
    our ( @_reslist, @_resources, @_csource, @_dtd ) = ();
707
    our $_no_pdb = $pdb_none;
708
    our $_noaddlibs = 0;
709
    our $_icon = undef;
710
    our $_docFile = undef;
711
    our $_snk = undef;
712
 
713
    #.. Parse arguments
714
    #
715
    foreach ( @$_pArgs ) {
716
        if (/^--Resource=(.+)/) {               # Resource definition
717
            push @_reslist, MakeSrcResolve($1);
718
 
719
        } elsif (/^--Dtd=(.+)/) {               # dtd definition
720
            push @_dtd, MakeSrcResolve($1);
721
 
722
        } elsif (/^--Icon=(.+)/) {
343 dpurdie 723
            Error ("$toolset_name SHLD: Only one Icon file allowed") if ( $_icon );
227 dpurdie 724
            $_icon = MakeSrcResolve($1);
725
 
726
        } elsif (/^--StrongNameKey=(.+)/) {
343 dpurdie 727
            Error ("$toolset_name SHLD: Only one SNK file allowed") if ( $_snk );
227 dpurdie 728
            $_snk = MakeSrcResolve($1);
729
 
730
        } elsif (/^--Doc/) {
731
            $_docFile = 1;
732
 
733
        } elsif (/^--NoPDB$/) {
734
            $_no_pdb = 1;
735
 
736
        } elsif ( !/^-/ ) {
737
            push @_csource, MakeSrcResolve($_);
738
 
739
        } else {
343 dpurdie 740
            Message( "$toolset_name SHLD: unknown option $_ -- ignored\n" );
227 dpurdie 741
 
742
        }
743
    }
744
 
745
    #
746
    #   Create Rules and Recipes to convert the .resx files to .resource files
747
    #
748
    foreach my $res ( @_reslist )
749
    {
750
        my ($res, $cs) = Toolset_genres ('$(OBJDIR)/' . $_name, $res );
751
 
752
        UniquePush ( \@_resources, $res );
753
        UniquePush ( \@_csource, $cs );
754
    }
755
 
756
    #
757
    #   Create Rules and Recipes to provide Assembly instructions
758
    #   for the creation of a StrongNameKey
759
    #
760
    if ( $_snk )
761
    {
762
        UniquePush ( \@_csource, Toolset_gensnk ($_name, $_snk ) );
763
    }
764
 
765
    #
766
    #   Build Rules
767
    #   $1  - Base Name
768
    #   $2  - Name of the output DLL
769
    #
770
    sub BuildSHLD
771
    {
772
        my ($name, $lib ) = @_;
773
        my ($root, $full, $link_target);
774
 
775
        #
776
        #   Determine the target output name
777
        #
778
        $root = "\$(LIBDIR)/$lib";
779
        $full = "$root.$::so";
780
        $link_target = "library";
781
        $_docFile = "$full.xml" if ($_docFile);
782
 
335 dpurdie 783
        my ($io) = ToolsetPrinter::New();
784
        my $dep = $io->SetShldTarget( $lib );
785
 
227 dpurdie 786
        #
787
        #   Create Rules and Recipes to create the Program
788
        #   This will be a combination of source, libraries and resources
789
        #
790
        my $me = MakeEntry::New (*MAKEFILE, $full );
791
        $me->AddComment ("Build Shared Library: $name" );
792
        $me->AddName    ( $_docFile ) if ( $_docFile );
261 dpurdie 793
        $me->AddDependancy ( '$(SCM_MAKEFILE)' );
335 dpurdie 794
        $me->AddDependancy ( $dep );
227 dpurdie 795
        $me->AddDependancy ( @_resources );
796
        $me->AddDependancy ( @_csource );
797
        $me->AddDependancy ( @_dtd );
798
        $me->AddDependancy ( $_icon );
799
        $me->AddRecipe ( '$(CSC)' );
800
        $me->Print();
801
 
802
 
803
        #
804
        #.. Compiler command file
805
        #       Now piece together a variable $(name_ld) which ends up in
806
        #       the command file linking the application.
807
        #
808
 
809
        $io->Label( "Linker commands", $name );     # label
810
        $io->SetTag( "${lib}_ld" );                 # macro tag
811
 
812
        $io->Label( "Linker Command File", $lib ); # label
813
 
814
        #
815
        #   Basic options
816
        #
817
        $io->Cmd( "/target:$link_target" );
818
        $io->Cmd( "/doc:$_docFile")                    if ( $_docFile ) ;
819
        $io->Cmd( "/win32icon:\$(subst /,\\\\,$_icon)" ) if $_icon;
820
 
821
        #
822
        #   Add in the Resource Files
823
        #          the source files
824
        #          the libraries
825
        #
826
        $io->Cmd( "/res:\$(subst /,\\\\,$_)" ) foreach @_resources;
827
        $io->Cmd( "/res:\$(subst /,\\\\,$_)" ) foreach @_dtd;
828
        $io->Cmd( "\$(subst /,\\\\,$_)" ) foreach @_csource;
829
        $io->LibList( $name, $_pLibs, \&ToolsetLibRecipe );
335 dpurdie 830
        $io->Newline();
227 dpurdie 831
 
335 dpurdie 832
        #.. Dependency link,
833
        #   Create a library dependency file
834
        #       Create command file to build applicaton dependency list
835
        #       from the list of dependent libraries
227 dpurdie 836
        #
335 dpurdie 837
        #       Create makefile directives to include the dependency
838
        #       list into the makefile.
227 dpurdie 839
        #
335 dpurdie 840
        $io->DepRules( $_pLibs, \&ToolsetLibRecipe, $full );
841
        $io->SHLDDEPEND( $name, $lib  );
227 dpurdie 842
 
843
        #
844
        #   Files to clean up
845
        #
846
        ToolsetGenerate( "$root.ld" );
847
        ToolsetGenerate( "$root.pdb" );
848
        ToolsetGenerate( $_docFile ) if $_docFile;
849
 
850
 
851
        #.. Package up files that are a part of the Library
852
        #
853
        PackageShlibAddFiles ( $name, $full );
854
        PackageShlibAddFiles ( $name, "$root.pdb", "Class=debug" ) unless ( $_no_pdb );
855
        PackageShlibAddFiles ( $name, $_docFile  , "Class=map" ) if ( $_docFile );
856
 
857
        #
858
        #   Return the full name of the created DLL.
859
        #
860
        return $full;
861
    }
862
 
863
    #
864
    #   Generate DLLs
865
    #
866
    #       a) Unversioned DLL  $_name$(GBE_TYPE).dll
867
    #       b) Versioned DLL    $_name$(GBE_TYPE).xx.xx.xx.dll
868
    #
289 dpurdie 869
    my $fver   = BuildSHLD( "$_name", "$_name\$(GBE_TYPE).$_ver" );
227 dpurdie 870
    my $funver = BuildSHLD( "$_name", "$_name\$(GBE_TYPE)" );
871
 
872
    #
873
    #   Create a dependancy between the version and unversioned DLLs
874
    #
875
    my $me = MakeEntry::New (*MAKEFILE, $fver );
876
    $me->AddComment ("Link Version and Unversioned Images: $_name" );
877
    $me->AddDependancy ( $funver );
878
    $me->Print();
879
 
880
}
881
 
882
########################################################################
883
#
884
#   Generate a linker/depend library recipe.  This is a helper function
885
#   used within this toolset.
886
#
887
#   Arguments:
888
#       $io         I/O stream
889
#
890
#       $target     Name of the target
891
#
892
#       $lib        Library specification
893
#
894
#       $dp         If building a depend list, the full target name.
895
#
896
########################################################################
897
 
898
sub ToolsetLibRecipe
899
{
900
    my ($io, $target, $lib, $dp) = @_;
901
 
902
    if ( !defined($dp) ) {                      # linker
903
        $io->Cmd( "/reference:\$(subst /,\\\\,\$(strip $lib)).$::so" );
904
 
905
    } else {                                    # depend
255 dpurdie 906
        $io->Cmd( "$dp:\t@(vglob2,$lib.$::so,CS_LIB)" );
227 dpurdie 907
    }
908
}
909
 
910
########################################################################
911
#
912
#   Generate a project from the provided project solution file
913
#   This is aimed at .NET work
914
#
915
#   Arguments   : $name             - Base name of the project
916
#                 $solution         - Path to the solutionn file
917
#                 $pArgs            - Project specific options
918
#
919
########################################################################
920
 
921
my $project_defines_done = 0;
922
sub ToolsetPROJECT
923
{
924
    my( $name, $solution ,$pArgs ) = @_;
925
    my $buildcmd = 'devenv =DSW= /build =TYPE= /useenv /out =LOG=';
926
    my $cleancmd = 'devenv =DSW= /clean =TYPE= /useenv';
343 dpurdie 927
    my $release = 'RELEASE';
928
    my $debug = 'DEBUG';
227 dpurdie 929
 
930
    #
931
    #   Process options
932
    #
933
    foreach ( @$pArgs ) {
343 dpurdie 934
        if ( m/^--TargetProd*=(.+)/ ) {
935
            $release = $1;
936
 
937
        } elsif ( m/^--TargetDebug=(.+)/ ) {
938
            $debug = $1;
939
 
940
        } else {
941
            Message( "$toolset_name PROJECT: unknown option $_ -- ignored\n" );
942
        }
227 dpurdie 943
    }
944
 
945
    my ($io) = ToolsetPrinter::New();
946
 
947
    #
343 dpurdie 948
    #   Setup toolset specific difinitions. Once
227 dpurdie 949
    #
950
    unless( $project_defines_done )
951
    {
952
        $project_defines_done = 1;
343 dpurdie 953
        $io->PrtLn( 'project_target = $(if $(findstring 1,$(DEBUG)),$2,$1)' );
227 dpurdie 954
        $io->Newline();
955
    }
956
 
957
    #
958
    #   Process the build and clean commands
959
    #       Substitute arguments
960
    #           =TYPE=
961
    #           =LOG=
962
    #           =DSW=
963
    #
343 dpurdie 964
    $buildcmd =~ s~=TYPE=~"\$(call project_target,$release,$debug)"~g;
227 dpurdie 965
    $buildcmd =~ s~=LOG=~$name\$(GBE_TYPE).log~g;
966
    $buildcmd =~ s~=DSW=~$solution~g;
967
 
343 dpurdie 968
    $cleancmd =~ s~=TYPE=~"\$(call project_target,$release,$debug)"~g;
227 dpurdie 969
    $cleancmd =~ s~=LOG=~$name\$(GBE_TYPE).log~g;
970
    $cleancmd =~ s~=DSW=~$solution~g;
971
 
972
    #
973
    #   Generate the recipe to create the project
974
    #   Use the set_<PLATFORM>.sh file to extend the DLL search path
975
    #
976
    $io->Label( "Build project", $name );
977
    $io->PrtLn( "Project_$name: $solution \$(INTERFACEDIR)/set_$::ScmPlatform.sh" );
978
 
979
    $io->PrtLn( "\t\$(XX_PRE)( \$(rm) -f $name\$(GBE_TYPE).log; \\" );
980
    $io->PrtLn( "\t. \$(INTERFACEDIR)/set_$::ScmPlatform.sh; \\" );
255 dpurdie 981
    $io->PrtLn( "\t\$(show_environment); \\" );
227 dpurdie 982
    $io->PrtLn( "\t$buildcmd; \\" );
983
    $io->PrtLn( "\tret=\$\$?; \\" );
984
    $io->PrtLn( "\t\$(GBE_BIN)/cat $name\$(GBE_TYPE).log; \\" );
985
    $io->PrtLn( "\texit \$\$ret )" );
986
    $io->Newline();
987
 
988
    #
989
    #   Generate the recipe to clean the project
990
    #
991
    $io->Label( "Clean project", $name );
992
    $io->PrtLn( "ProjectClean_$name: $solution" );
993
    $io->PrtLn( "\t-\$(XX_PRE)$cleancmd" );
994
    $io->PrtLn( "\t-\$(XX_PRE)\$(rm) -f $name\$(GBE_TYPE).log" );
995
    $io->Newline();
996
 
997
}
998
 
999
#-------------------------------------------------------------------------------
1000
# Function        : ToolsetTESTFRAMEWORK_NUNIT
1001
#
1002
# Description     : Toolset specfic support for the NUNIT Test FrameWork
1003
#                   Accessed with RunTest ('*', --FrameWork=nunit, ... );
1004
#
1005
#                   Manipulates the pEntry structure to allow JATS to
1006
#                   construct a test entry to run Nunit tests
1007
#
1008
# Inputs          : $pEntry                 - Unit Test Hash
1009
#
1010
# Returns         : Modified Hash
1011
#
1012
sub ToolsetTESTFRAMEWORK_NUNIT
1013
{
1014
    my ($pEntry) = @_;
1015
    my $test_dll_name;
1016
    my @copy_dlls;
1017
    my %copy_dll_flags;
1018
 
1019
    #
1020
    #   Extract base name of DLL under test
1021
    #   Thsi will not have any extension.
1022
    #
1023
    $test_dll_name = $pEntry->{'prog'};
1024
    Error ("Nunit Framework. No TestDLL specified") unless $test_dll_name;
1025
 
1026
    #
1027
    #   Process the FrameWork Options
1028
    #
1029
    foreach  ( @{$pEntry->{'framework_opts'}} )
1030
    {
1031
        if ( m/^--Uses=(.+)/ ) {
1032
            my ($dll, @opts) = split (',', $1 );
1033
            push @copy_dlls, $dll;
1034
            foreach  ( @opts )
1035
            {
1036
                if ( m~^--NonJats~i ) {
1037
                    $copy_dll_flags{$dll}{'NonJats'} = 1;
1038
                } elsif ( m~--Jats~ ) {
1039
                    $copy_dll_flags{$dll}{'NonJats'} = 0;
1040
                } else {
1041
                    Error ("Nunit Framework. Unknown sub option to --Uses: $_");
1042
                }
1043
            }
1044
        } else {
1045
            Error ("Nunit Framework. Unknown option: $_");
1046
        }
1047
    }
1048
 
1049
    #
1050
    #   Locate the Nunit essentials
261 dpurdie 1051
    #       This list may change with each version of nunit
1052
    #       Look for a known file and use its contents
1053
    #       Format:
1054
    #           One file name per line
1055
    #           Line comments only
1056
    #           Comment marker is a #
1057
    #           First one MUST be the executable
227 dpurdie 1058
    #
261 dpurdie 1059
    my @nunit_files;
227 dpurdie 1060
 
261 dpurdie 1061
    my $mfile = 'nunit-jats-manifest.txt';
1062
    my $nunit_file = ToolExtensionProgram ( $mfile );
1063
    Error ("Cannot find Nunit Jats Manifest: $mfile") unless ( $nunit_file );
1064
    open (JM, $nunit_file ) || Error( "Cannot open file: $nunit_file", "Reason: $!" );
1065
    while ( <JM> )
1066
    {
1067
        s~\s+$~~;                   # Remove trailing white space
1068
        s~^\s+~~;                   # Remove Leading whitespace
1069
        next unless ( $_ );         # Skip block lines
1070
        next if ( m~^#~ );          # Skip comments
1071
        Verbose ("Nunit File: $_");
1072
        push @nunit_files, $_;
1073
    }
1074
    close JM;
1075
 
1076
    #
1077
    #   Locate all the required files
1078
    #   The first one will be the console executable
1079
    #
227 dpurdie 1080
    my @nunit_framework;
1081
    foreach my $file ( @nunit_files )
1082
    {
1083
        my $path = ToolExtensionProgram ($file );
1084
        Error ("Cannot locate nunit file: $file") unless ( $path );
1085
        push @nunit_framework, $path;
1086
    }
261 dpurdie 1087
    my $nunit_console = $nunit_framework[0];
1088
    Error ("Nunit console executable not specified") unless ( $nunit_console );
227 dpurdie 1089
 
1090
    #
1091
    #   Locate the test DLL.
1092
    #   This will be created locally within this makefile
1093
    #   It will be a known shared library
1094
    #
1095
    Errror( "TestDLL does not appear to be locally created: $test_dll_name" )
289 dpurdie 1096
        unless ( $::SHLIBS->Get($test_dll_name) );
227 dpurdie 1097
 
1098
    #
1099
    #   Hard bit. Determine the name/path of the DLL under test
1100
    #   It will have been created within this makefile
1101
    #   This is not a physical file.
1102
    #
1103
    $test_dll_name = $test_dll_name . '$(GBE_TYPE).' . $::so;
1104
    my $test_dll = '$(LIBDIR)/' . $test_dll_name;
1105
 
1106
    #
1107
    #   Other hard bit
1108
    #   Locate the other dll's needed by this test
1109
    #   Need to use P in production and D in Debug unless otherwise specified
1110
    #   These might be in:
1111
    #       an external package
1112
    #       within the local directory
1113
    #       the current makefile
1114
    #   ie: We can only determine the location of the files at run-time
1115
    #
1116
    #   The mechanism used is:
1117
    #       Create makefile recipe entries to
1118
    #           Use cmdfile to create a command file with copy command
1119
    #           Execute the command file
1120
    #
1121
    #   Complications include:
1122
    #       The windows shell used does not honour 'set -e', so we need to
1123
    #       detect error conditions ourselves
1124
    #
1125
    my $ofile = "\$(TESTDIR)/$pEntry->{test_name}.cmd";
1126
    push @{$pEntry->{'ShellRecipe'}}, "rm -f $ofile";
1127
 
1128
    my @cmds;
363 dpurdie 1129
    push @cmds, "\$(cmdfile) -wk1W1o$ofile";
227 dpurdie 1130
    foreach my $dll ( @copy_dlls )
1131
    {
1132
        #
1133
        #   Generate in-line commands to locate and copy in the required
1134
        #   DLL's. The 'cmdfile' utility can be used to do this at runtime
1135
        #
1136
        my $dll_name = $dll;
1137
        $dll_name .= '$(GBE_TYPE)' unless ( $copy_dll_flags{$dll}{'NonJats'} );
1138
 
363 dpurdie 1139
        push @cmds, '"' . "cp -f @(vglob2,$dll_name.$::so,PATH,/) \$(TESTDIR) || exit 98" . '\n"';
227 dpurdie 1140
    }
1141
    push @cmds, "|| exit 99";
1142
    push @{$pEntry->{'ShellRecipe'}}, \@cmds;
1143
    push @{$pEntry->{'ShellRecipe'}}, ". $ofile";
1144
 
1145
 
1146
    #
1147
    #   Add items to the Unit Test Hash
1148
    #       command     - command to execute to run the test program
1149
    #       prog        - test command/script that must be in the test dir
1150
    #       copyprog    - Prog must be copied in
1151
    #       args        - Arguments to the test
1152
    #       copyin      - Array of files to copy into the test directory
1153
    #       copyonce    - Array of files to copy only once
1154
    #       prereq      - Prerequiste conditions
1155
    #       testdir     - Symbolic name of the test directory
1156
    #       ShellRecipe - Recipe Bits to add
1157
    #
1158
    $pEntry->{'command'}  = $nunit_console . ' ' . $test_dll_name;
1159
    unshift @{$pEntry->{args}}, "/xml=$pEntry->{test_name}.xml";
1160
    $pEntry->{'prog'} = $test_dll_name;
1161
    $pEntry->{'copyprog'} = 0;
1162
    push @{$pEntry->{'copyin'}}, $test_dll;
261 dpurdie 1163
    push @{$pEntry->{'copyonce'}}, @nunit_framework;
227 dpurdie 1164
    $pEntry->{'testdir'}  = 'TESTDIR';
1165
 
1166
    #   
1167
    #   Create the Test Directory
1168
    #   Tests will be done in a .NUNIT subdir
1169
    #
1170
    MkdirRule( "\$(TESTDIR)", 'TESTDIR', '--Path=$(GBE_PLATFORM)$(GBE_TYPE).NUNIT', '--RemoveAll' );
1171
 
1172
    #
1173
    #   Files created by the Unit Test
1174
    #
1175
    ToolsetGenerate ( "\$(TESTDIR)/$pEntry->{test_name}.xml"  );
1176
    ToolsetGenerate ( $ofile  );
1177
 
1178
}
1179
 
1180
#.. Successful termination
1181
1;
1182