Subversion Repositories DevTools

Rev

Rev 363 | Rev 2931 | 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",
379 dpurdie 268
           "File: $src") unless ( -f $csfile );
227 dpurdie 269
 
379 dpurdie 270
 
227 dpurdie 271
    #
272
    #   Scan the .resx file looking for the ThisName element
273
    #   A very simple and crude parser
274
    #
275
    my $ThisName;
276
    open ( SCAN, '<', $src ) || Error ("Cannot open file for reading: $!", "File: $src" );
277
    while ( <SCAN> )
278
    {
279
        if ( m~\<data name=\"\$this\.Name\"\>~ )
280
        {
281
            # Next line will contain the needed data item
282
            my $element = <SCAN>;
283
            $element =~ m~\<.+\>(.+)\</.+\>~;
284
            $ThisName = $1;
343 dpurdie 285
            Error ("$toolset_name toolset: Resx parsing: Bad this.Name", "File: $src") unless $ThisName;
227 dpurdie 286
            $ThisName =~ s~\s+~~g;
287
            last;
288
        }
289
    }
290
    close SCAN;
291
 
292
    #
293
    #   Name not found
294
    #   Use a default. Filename with any .aspx, .asax, .ascx removed
295
    #
296
    unless ( $ThisName )
297
    {
298
        $ThisName = StripDirExt($src);
299
        $ThisName =~ s~\.as[pac]x~~i;
300
    }
301
 
302
    #
303
    #   Scan the.cs file looking for the namespace
304
    #   A very simple and crude parser
305
    #
306
    my $NameSpace;
307
    open ( SCAN, '<', $csfile ) || Error ("Cannot open file for reading: $!", "File: $csfile" );
308
    while ( <SCAN> )
309
    {
310
        if ( m~namespace\s+(\S+)~ )
311
        {
312
            $NameSpace = $1;
313
            last;
314
        }
315
    }
316
    close SCAN;
343 dpurdie 317
    Error ("$toolset_name toolset: Resx parsing: NameSpace not found", "File: $csfile") unless $NameSpace;
227 dpurdie 318
 
319
    #
320
    #   Need to create an output file name that is a function of the FQN
321
    #
322
    my $root = "$NameSpace.$ThisName.resources";
323
    my $resource = $subdir . '/' . $root;
324
 
325
    $resource_files{$resource}{src} = $src;
326
    $resource_files{$resource}{root} = $root;
327
 
328
    return $resource, $csfile;
329
}
330
 
331
 
332
#-------------------------------------------------------------------------------
333
# Function        : Toolset_gensnk
334
#
335
# Description     : Function to create a wrapper file for the processing
336
#                   of a StrongNameKey file
337
#
338
#                   Create only one wrapper per SNK file
339
#
340
# Inputs          : $name       - Name of component
341
#                   $snk        - Path to the SNK file
342
#
343
# Returns         : Path to the wrapper file
344
#
345
my %snk_data;
346
sub Toolset_gensnk
347
{
348
    my ($name, $snk ) = @_;
349
    my $file = StripDirExt( $snk );
350
 
351
    #
352
    #   Only create the file once
353
    #   Otherwise we will get nasty make messages
354
    #
355
 
356
    if ( exists $snk_data{$snk} )
357
    {
358
        return $snk_data{$snk}{output};
359
    }
360
 
361
    #
362
    #   Determine the target name
363
    #   Create the source file in the currentt directory
364
    #   If we build it in the OBJ directory we get two files
365
    #
366
    my $snk_file = '$(OBJDIR)/' . "Jats_${file}.cs";
367
    $snk_data{$snk}{output} = $snk_file;
368
    ToolsetGenerate( $snk_file );
369
 
370
    #
371
    #   Determine the Tag Name
372
    #   Used to conatin information in the makefile
373
    #
374
    my $tag = "${file}_snk";
375
 
376
    #
377
    #   Create Rules and Recipes to create the SNK wrapper file
378
    #
379
    my $me = MakeEntry::New (*MAKEFILE, $snk_file );
380
    $me->AddComment ("Build Strong Name Key File Wrapper: $snk" );
381
    $me->AddDependancy ( $snk );
261 dpurdie 382
    $me->AddDependancy ( '$(SCM_MAKEFILE)' );
227 dpurdie 383
    $me->AddRecipe ( '$(call GenSnkWrapper,' . $tag .  ')' );
384
    $me->Print();
385
 
386
    #
387
    #   Create the data t be placed into the wrapper file
388
    #
389
    my ($io) = ToolsetPrinter::New();
390
 
391
    my $ms_snk = $snk;
392
 
393
    $io->Label( "SNK Wrapper file content", $tag );    # label
394
    $io->SetTag( $tag );                                # macro tag
255 dpurdie 395
    $io->Cmd( '// This is JATS GENERATED FILE' );
396
    $io->Cmd( '//    Do not edit' );
397
    $io->Cmd( '//    Do not version control' );
398
 
227 dpurdie 399
    $io->Cmd( 'using System.Reflection;' );
400
    $io->Cmd( 'using System.Runtime.CompilerServices;' );
401
 
402
    $io->Cmd( '//' );
403
    $io->Cmd( '// In order to sign your assembly you must specify a key to use. Refer to the' );
404
    $io->Cmd( '// Microsoft .NET Framework documentation for more information on assembly signing.' );
405
    $io->Cmd( '//' );
406
    $io->Cmd( '// Use the attributes below to control which key is used for signing.' );
407
    $io->Cmd( '//' );
408
    $io->Cmd( '// Notes:' );
409
    $io->Cmd( '//   (*) If no key is specified, the assembly is not signed.' );
410
    $io->Cmd( '//   (*) KeyName refers to a key that has been installed in the Crypto Service' );
411
    $io->Cmd( '//       Provider (CSP) on your machine. KeyFile refers to a file which contains' );
412
    $io->Cmd( '//       a key.' );
413
    $io->Cmd( '//   (*) If the KeyFile and the KeyName values are both specified, the' );
414
    $io->Cmd( '//       following processing occurs:' );
415
    $io->Cmd( '//       (1) If the KeyName can be found in the CSP, that key is used.' );
416
    $io->Cmd( '//       (2) If the KeyName does not exist and the KeyFile does exist, the key' );
417
    $io->Cmd( '//           in the KeyFile is installed into the CSP and used.' );
418
    $io->Cmd( '//   (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.' );
419
    $io->Cmd( '//       When specifying the KeyFile, the location of the KeyFile should be' );
420
    $io->Cmd( '//       relative to the project output directory which is' );
421
    $io->Cmd( '//       %Project Directory%\obj\<configuration>. For example, if your KeyFile is' );
422
    $io->Cmd( '//       located in the project directory, you would specify the AssemblyKeyFile' );
423
    $io->Cmd( '//       attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]' );
424
    $io->Cmd( '//   (*) Delay Signing is an advanced option - see the Microsoft .NET Framework' );
425
    $io->Cmd( '//       documentation for more information on this.' );
426
    $io->Cmd( '//' );
427
 
428
    $io->Cmd( '[assembly: AssemblyDelaySign(false)]' );
255 dpurdie 429
    $io->Cmd( '#pragma warning disable 1699' ) if ($toolset_info->{'pragma'});
227 dpurdie 430
    $io->Cmd( '[assembly: AssemblyKeyFile(@"'. $snk  .'")]' );
255 dpurdie 431
    $io->Cmd( '#pragma warning restore 1699' ) if ($toolset_info->{'pragma'});
227 dpurdie 432
    $io->Cmd( '[assembly: AssemblyKeyName("")]' );
433
    $io->Newline();
434
 
435
    #
436
    #   Return the path to where the file will be created
437
    #
438
    return $snk_file;
439
}
440
 
441
 
442
###############################################################################
443
#   ToolsetLD( $name, \@args, \@objs, \@libraries )
444
#       This subroutine takes the user options and builds the rules
445
#       required to link the program 'name'.
446
#
447
#   Arguments:
448
#       $name       - Name of the target program
449
#       $pArgs      - Ref to an array of argumennts
450
#       $pObjs      - Ref to an array of object files
451
#       $pLibs      - Ref to an array of libraries
452
#
453
#   Output:
454
#       Makefile recipes to create the Program
455
#
456
#   Notes:
457
#       This Program Builder will handle its own dependancies
458
#       It will also create rules and recipes to construct various
459
#       parts directly fromm source
460
#
461
#   Options:
462
#       --Resource=file.resx
463
#       --Dtd=file.dtd
464
#       --Icon=file
465
#       --Entry=xxxxx                   # Entry point
466
#       --Console                       # Console app
467
#       --Windows                       # Windows app (default)
468
#       --DLL                           # As a DLL (No P|D)
469
#       --Doc
470
#       --NoPDB
471
#       CSharpSourceFile
472
#
473
#
474
###############################################################################
475
 
476
sub ToolsetLD
477
{
478
    my ( $name, $pArgs, $pObjs, $pLibs ) = @_;
479
    my ( @reslist, @resources, @csource, @dtd );
480
    my $no_pdb = $pdb_none;
481
    my $entry;
482
    my $noaddlibs;
483
    my $icon;
484
    my $docFile;
485
    my ($base, $root, $full );
486
    my $link_target = $::ScmCompilerOpts{'LDSUBSYSTEM'};
487
    my $snk;
488
    my $is_a_dll;
489
 
490
    #.. Parse arguments
491
    #
492
    foreach ( @$pArgs ) {
493
        if (/^--Resource=(.+)/) {               # Resource definition
494
            push @reslist, MakeSrcResolve($1);
495
 
496
        } elsif (/^--Dtd=(.+)/) {               # dtd definition
497
            push @dtd, MakeSrcResolve($1);
498
 
499
        } elsif (/^--Icon=(.+)/) {
343 dpurdie 500
            Error ("$toolset_name LD: Only one Icon file allowed") if ( $icon );
227 dpurdie 501
            $icon = MakeSrcResolve($1);
502
 
503
        } elsif (/^--StrongNameKey=(.+)/) {
343 dpurdie 504
            Error ("$toolset_name LD: Only one SNK file allowed") if ( $snk );
227 dpurdie 505
            $snk = MakeSrcResolve($1);
506
 
507
        } elsif (/^--Entry=(.+)/) {
508
            $entry = $1;
509
 
510
        } elsif (/^--Doc/) {
511
            $docFile = 1;
512
 
513
        } elsif (/^--Windows/) {
514
            $link_target = 'winexe';
515
 
516
        } elsif (/^--Console/) {
517
            $link_target = 'exe';
518
 
519
        } elsif (/^--DLL/) {
520
            $is_a_dll = 1;
521
 
522
        } elsif (/^--NoPDB$/) {
523
            $no_pdb = 1;
524
 
525
        } elsif ( !/^-/ ) {
526
            push @csource, MakeSrcResolve($_);
527
 
528
        } else {
343 dpurdie 529
            Message( "$toolset_name LD: unknown option $_ -- ignored\n" );
227 dpurdie 530
 
531
        }
532
    }
533
 
534
    #
535
    #   Determine the target output name
536
    #
537
    $base = $name;
538
    $root = "\$(BINDIR)/$base";
539
    $full = $root . $::exe;
540
    $docFile = "$root.xml" if ( $docFile );
541
 
542
    #
543
    #   Special case for DLLs that need to be created without a D or P mangled
544
    #   into the name. Create them as Progs just to fool the system
545
    #   Used when creating specialised web services
546
    #
547
    if ( $is_a_dll )
548
    {
549
        #
550
        #   Create a phony target
551
        #   The EXE name is not actually created, but the EXE target needs to be retained
552
        #
553
        my $exe_name = $root . $::exe;
554
        my $dll_name = $root . '.' . $::so;
555
        $full = $dll_name;
556
        $link_target = 'library';
557
 
558
        my $me = MakeEntry::New (*MAKEFILE, $exe_name, '--Phony' );
559
        $me->AddComment ("Build Program: $name as a DLL" );
560
        $me->AddDependancy ( $dll_name );
561
        $me->Print();
255 dpurdie 562
 
563
        #
564
        #   Need to specifically clean this up, since we have fiddled with the
565
        #   name of the generated file
566
        #
567
        ToolsetGenerate( $dll_name );
227 dpurdie 568
    }
569
 
570
    #
571
    #   Create Rules and Recipes to convert the .resx files to .resource files
572
    #
573
    foreach my $res ( @reslist )
574
    {
575
        my ($res, $cs) = Toolset_genres ('$(OBJDIR)', $res );
576
 
577
        UniquePush ( \@resources, $res );
578
        UniquePush ( \@csource, $cs );
579
    }
580
 
581
    #
582
    #   Create Rules and Recipes to provide Assembly instructions
583
    #   for the creation of a StrongNameKey
584
    #
585
    if ( $snk )
586
    {
587
        UniquePush ( \@csource, Toolset_gensnk ($name, $snk ) );
588
    }
589
 
335 dpurdie 590
    my ($io) = ToolsetPrinter::New();
591
    my $dep = $io->SetLdTarget( $name );
592
 
227 dpurdie 593
    #
594
    #   Create Rules and Recipes to create the Program
595
    #   This will be a combination of source, libraries and resources
596
    #
597
    my $me = MakeEntry::New (*MAKEFILE, $full );
598
    $me->AddComment ("Build Program: $name" );
599
    $me->AddName    ( $docFile ) if ( $docFile );
335 dpurdie 600
    $me->AddDependancy ( $dep );
261 dpurdie 601
    $me->AddDependancy ( '$(SCM_MAKEFILE)' );
227 dpurdie 602
    $me->AddDependancy ( @resources );
603
    $me->AddDependancy ( @csource );
604
    $me->AddDependancy ( @dtd );
605
    $me->AddDependancy ( $icon );
606
    $me->AddRecipe ( '$(CSC)' );
607
    $me->Print();
608
 
609
 
610
    #
611
    #.. Compiler command file
612
    #       Now piece together a variable $(name_ld) which ends up in
613
    #       the command file linking the application.
614
    #
615
    $io->Label( "Linker commands", $name );     # label
616
    $io->SetTag( "${name}_ld" );                # macro tag
617
 
618
    $io->Label( "Linker Command File", $name ); # label
619
 
620
    #
621
    #   Basic options
622
    #
623
    $io->Cmd( "/target:$link_target" );
624
    $io->Cmd("/doc:$docFile") if ( $docFile ) ;
625
    $io->Cmd( "/win32icon:\$(subst /,\\\\,$icon)" ) if $icon;
626
    $io->Cmd( "/main:$entry" ) if $entry;
627
 
628
    #
629
    #   Add in the Resource Files
630
    #          the source files
631
    #          the libraries
632
    #
633
    $io->Cmd( "/res:\$(subst /,\\\\,$_)" ) foreach @resources;
634
    $io->Cmd( "/res:\$(subst /,\\\\,$_)" ) foreach @dtd;
635
    $io->Cmd( "\$(subst /,\\\\,$_)" ) foreach @csource;
636
    $io->LibList( $name, $pLibs, \&ToolsetLibRecipe );
335 dpurdie 637
    $io->Newline();
227 dpurdie 638
 
639
 
335 dpurdie 640
    #.. Dependency link,
641
    #   Create a library dependency file
642
    #       Create command file to build applicaton dependency list
643
    #       from the list of dependent libraries
227 dpurdie 644
    #
335 dpurdie 645
    #       Create makefile directives to include the dependency
646
    #       list into the makefile.
227 dpurdie 647
    #
335 dpurdie 648
    $io->DepRules( $pLibs, \&ToolsetLibRecipe, $full );
649
    $io->LDDEPEND();
227 dpurdie 650
 
651
    #
652
    #   Files to clean up
653
    #
654
    ToolsetGenerate( "$root.ld" );
655
    ToolsetGenerate( "$root.pdb" );
656
    ToolsetGenerate( $docFile ) if $docFile;
657
 
658
 
659
    #.. Package up files that are a part of the program
660
    #
661
    PackageProgAddFiles ( $name, $full );
662
    PackageProgAddFiles ( $name, "$root.pdb", "Class=debug" ) unless ( $no_pdb );
663
    PackageProgAddFiles ( $name, $docFile, "Class=map" ) if ( $docFile );
664
}
665
 
666
###############################################################################
289 dpurdie 667
#   ToolsetSHLD( $name, \@args, \@objs, \@libraries, $ver )
227 dpurdie 668
#       This subroutine takes the user options and builds the rules
669
#       required to link the program 'name'.
670
#
671
#   Arguments:
672
#       $name       - Name of the target program
673
#       $pArgs      - Ref to an array of argumennts
674
#       $pObjs      - Ref to an array of object files
675
#       $pLibs      - Ref to an array of libraries
289 dpurdie 676
#       $ver        - Library Version string
227 dpurdie 677
#
678
#   Output:
679
#       Makefile recipes to create the DLL
680
#       Will create both versioned and unversioned DLLs
681
#
682
#   Notes:
683
#       This Library Builder will handle its own dependancies
684
#       It will also create rules and recipes to construct various
685
#       parts directly from source
686
#
687
#       This is SO close to the ToolsetLD function that its not funny
688
#
689
#   Options:
690
#       --Resource=file.resx
691
#       --Icon=file
692
#       --StrongNameKey=file
693
#       --Doc
694
#       --NoPDB
695
#       CSharpSourceFile
696
#
697
#
698
###############################################################################
699
sub ToolsetSHLD
700
{
701
    #
702
    #   Note: Use globals to kill warnings from internal sub
703
    #         Use _ prefix so that they don't get saved in Makefile_x.cfg
704
    #         Init as they are global
705
    #
289 dpurdie 706
    our ( $_name, $_pArgs, $_pObjs, $_pLibs, $_ver ) = @_;
227 dpurdie 707
    our ( @_reslist, @_resources, @_csource, @_dtd ) = ();
708
    our $_no_pdb = $pdb_none;
709
    our $_noaddlibs = 0;
710
    our $_icon = undef;
711
    our $_docFile = undef;
712
    our $_snk = undef;
713
 
714
    #.. Parse arguments
715
    #
716
    foreach ( @$_pArgs ) {
717
        if (/^--Resource=(.+)/) {               # Resource definition
718
            push @_reslist, MakeSrcResolve($1);
719
 
720
        } elsif (/^--Dtd=(.+)/) {               # dtd definition
721
            push @_dtd, MakeSrcResolve($1);
722
 
723
        } elsif (/^--Icon=(.+)/) {
343 dpurdie 724
            Error ("$toolset_name SHLD: Only one Icon file allowed") if ( $_icon );
227 dpurdie 725
            $_icon = MakeSrcResolve($1);
726
 
727
        } elsif (/^--StrongNameKey=(.+)/) {
343 dpurdie 728
            Error ("$toolset_name SHLD: Only one SNK file allowed") if ( $_snk );
227 dpurdie 729
            $_snk = MakeSrcResolve($1);
730
 
731
        } elsif (/^--Doc/) {
732
            $_docFile = 1;
733
 
734
        } elsif (/^--NoPDB$/) {
735
            $_no_pdb = 1;
736
 
737
        } elsif ( !/^-/ ) {
738
            push @_csource, MakeSrcResolve($_);
739
 
740
        } else {
343 dpurdie 741
            Message( "$toolset_name SHLD: unknown option $_ -- ignored\n" );
227 dpurdie 742
 
743
        }
744
    }
745
 
746
    #
747
    #   Create Rules and Recipes to convert the .resx files to .resource files
748
    #
749
    foreach my $res ( @_reslist )
750
    {
751
        my ($res, $cs) = Toolset_genres ('$(OBJDIR)/' . $_name, $res );
752
 
753
        UniquePush ( \@_resources, $res );
754
        UniquePush ( \@_csource, $cs );
755
    }
756
 
757
    #
758
    #   Create Rules and Recipes to provide Assembly instructions
759
    #   for the creation of a StrongNameKey
760
    #
761
    if ( $_snk )
762
    {
763
        UniquePush ( \@_csource, Toolset_gensnk ($_name, $_snk ) );
764
    }
765
 
766
    #
767
    #   Build Rules
768
    #   $1  - Base Name
769
    #   $2  - Name of the output DLL
770
    #
771
    sub BuildSHLD
772
    {
773
        my ($name, $lib ) = @_;
774
        my ($root, $full, $link_target);
775
 
776
        #
777
        #   Determine the target output name
778
        #
779
        $root = "\$(LIBDIR)/$lib";
780
        $full = "$root.$::so";
781
        $link_target = "library";
782
        $_docFile = "$full.xml" if ($_docFile);
783
 
335 dpurdie 784
        my ($io) = ToolsetPrinter::New();
785
        my $dep = $io->SetShldTarget( $lib );
786
 
227 dpurdie 787
        #
788
        #   Create Rules and Recipes to create the Program
789
        #   This will be a combination of source, libraries and resources
790
        #
791
        my $me = MakeEntry::New (*MAKEFILE, $full );
792
        $me->AddComment ("Build Shared Library: $name" );
793
        $me->AddName    ( $_docFile ) if ( $_docFile );
261 dpurdie 794
        $me->AddDependancy ( '$(SCM_MAKEFILE)' );
335 dpurdie 795
        $me->AddDependancy ( $dep );
227 dpurdie 796
        $me->AddDependancy ( @_resources );
797
        $me->AddDependancy ( @_csource );
798
        $me->AddDependancy ( @_dtd );
799
        $me->AddDependancy ( $_icon );
800
        $me->AddRecipe ( '$(CSC)' );
801
        $me->Print();
802
 
803
 
804
        #
805
        #.. Compiler command file
806
        #       Now piece together a variable $(name_ld) which ends up in
807
        #       the command file linking the application.
808
        #
809
 
810
        $io->Label( "Linker commands", $name );     # label
811
        $io->SetTag( "${lib}_ld" );                 # macro tag
812
 
813
        $io->Label( "Linker Command File", $lib ); # label
814
 
815
        #
816
        #   Basic options
817
        #
818
        $io->Cmd( "/target:$link_target" );
819
        $io->Cmd( "/doc:$_docFile")                    if ( $_docFile ) ;
820
        $io->Cmd( "/win32icon:\$(subst /,\\\\,$_icon)" ) if $_icon;
821
 
822
        #
823
        #   Add in the Resource Files
824
        #          the source files
825
        #          the libraries
826
        #
827
        $io->Cmd( "/res:\$(subst /,\\\\,$_)" ) foreach @_resources;
828
        $io->Cmd( "/res:\$(subst /,\\\\,$_)" ) foreach @_dtd;
829
        $io->Cmd( "\$(subst /,\\\\,$_)" ) foreach @_csource;
830
        $io->LibList( $name, $_pLibs, \&ToolsetLibRecipe );
335 dpurdie 831
        $io->Newline();
227 dpurdie 832
 
335 dpurdie 833
        #.. Dependency link,
834
        #   Create a library dependency file
835
        #       Create command file to build applicaton dependency list
836
        #       from the list of dependent libraries
227 dpurdie 837
        #
335 dpurdie 838
        #       Create makefile directives to include the dependency
839
        #       list into the makefile.
227 dpurdie 840
        #
335 dpurdie 841
        $io->DepRules( $_pLibs, \&ToolsetLibRecipe, $full );
842
        $io->SHLDDEPEND( $name, $lib  );
227 dpurdie 843
 
844
        #
845
        #   Files to clean up
846
        #
847
        ToolsetGenerate( "$root.ld" );
848
        ToolsetGenerate( "$root.pdb" );
849
        ToolsetGenerate( $_docFile ) if $_docFile;
850
 
851
 
852
        #.. Package up files that are a part of the Library
853
        #
854
        PackageShlibAddFiles ( $name, $full );
855
        PackageShlibAddFiles ( $name, "$root.pdb", "Class=debug" ) unless ( $_no_pdb );
856
        PackageShlibAddFiles ( $name, $_docFile  , "Class=map" ) if ( $_docFile );
857
 
858
        #
859
        #   Return the full name of the created DLL.
860
        #
861
        return $full;
862
    }
863
 
864
    #
865
    #   Generate DLLs
866
    #
867
    #       a) Unversioned DLL  $_name$(GBE_TYPE).dll
868
    #       b) Versioned DLL    $_name$(GBE_TYPE).xx.xx.xx.dll
869
    #
289 dpurdie 870
    my $fver   = BuildSHLD( "$_name", "$_name\$(GBE_TYPE).$_ver" );
227 dpurdie 871
    my $funver = BuildSHLD( "$_name", "$_name\$(GBE_TYPE)" );
872
 
873
    #
874
    #   Create a dependancy between the version and unversioned DLLs
875
    #
876
    my $me = MakeEntry::New (*MAKEFILE, $fver );
877
    $me->AddComment ("Link Version and Unversioned Images: $_name" );
878
    $me->AddDependancy ( $funver );
879
    $me->Print();
880
 
881
}
882
 
883
########################################################################
884
#
885
#   Generate a linker/depend library recipe.  This is a helper function
886
#   used within this toolset.
887
#
888
#   Arguments:
889
#       $io         I/O stream
890
#
891
#       $target     Name of the target
892
#
893
#       $lib        Library specification
894
#
895
#       $dp         If building a depend list, the full target name.
896
#
897
########################################################################
898
 
899
sub ToolsetLibRecipe
900
{
901
    my ($io, $target, $lib, $dp) = @_;
902
 
903
    if ( !defined($dp) ) {                      # linker
904
        $io->Cmd( "/reference:\$(subst /,\\\\,\$(strip $lib)).$::so" );
905
 
906
    } else {                                    # depend
255 dpurdie 907
        $io->Cmd( "$dp:\t@(vglob2,$lib.$::so,CS_LIB)" );
227 dpurdie 908
    }
909
}
910
 
911
########################################################################
912
#
913
#   Generate a project from the provided project solution file
914
#   This is aimed at .NET work
915
#
916
#   Arguments   : $name             - Base name of the project
917
#                 $solution         - Path to the solutionn file
918
#                 $pArgs            - Project specific options
919
#
920
########################################################################
921
 
922
my $project_defines_done = 0;
923
sub ToolsetPROJECT
924
{
925
    my( $name, $solution ,$pArgs ) = @_;
926
    my $buildcmd = 'devenv =DSW= /build =TYPE= /useenv /out =LOG=';
927
    my $cleancmd = 'devenv =DSW= /clean =TYPE= /useenv';
343 dpurdie 928
    my $release = 'RELEASE';
929
    my $debug = 'DEBUG';
227 dpurdie 930
 
931
    #
932
    #   Process options
933
    #
934
    foreach ( @$pArgs ) {
343 dpurdie 935
        if ( m/^--TargetProd*=(.+)/ ) {
936
            $release = $1;
937
 
938
        } elsif ( m/^--TargetDebug=(.+)/ ) {
939
            $debug = $1;
940
 
941
        } else {
942
            Message( "$toolset_name PROJECT: unknown option $_ -- ignored\n" );
943
        }
227 dpurdie 944
    }
945
 
946
    my ($io) = ToolsetPrinter::New();
947
 
948
    #
343 dpurdie 949
    #   Setup toolset specific difinitions. Once
227 dpurdie 950
    #
951
    unless( $project_defines_done )
952
    {
953
        $project_defines_done = 1;
343 dpurdie 954
        $io->PrtLn( 'project_target = $(if $(findstring 1,$(DEBUG)),$2,$1)' );
227 dpurdie 955
        $io->Newline();
956
    }
957
 
958
    #
959
    #   Process the build and clean commands
960
    #       Substitute arguments
961
    #           =TYPE=
962
    #           =LOG=
963
    #           =DSW=
964
    #
343 dpurdie 965
    $buildcmd =~ s~=TYPE=~"\$(call project_target,$release,$debug)"~g;
227 dpurdie 966
    $buildcmd =~ s~=LOG=~$name\$(GBE_TYPE).log~g;
967
    $buildcmd =~ s~=DSW=~$solution~g;
968
 
343 dpurdie 969
    $cleancmd =~ s~=TYPE=~"\$(call project_target,$release,$debug)"~g;
227 dpurdie 970
    $cleancmd =~ s~=LOG=~$name\$(GBE_TYPE).log~g;
971
    $cleancmd =~ s~=DSW=~$solution~g;
972
 
973
    #
974
    #   Generate the recipe to create the project
975
    #   Use the set_<PLATFORM>.sh file to extend the DLL search path
976
    #
977
    $io->Label( "Build project", $name );
978
    $io->PrtLn( "Project_$name: $solution \$(INTERFACEDIR)/set_$::ScmPlatform.sh" );
979
 
980
    $io->PrtLn( "\t\$(XX_PRE)( \$(rm) -f $name\$(GBE_TYPE).log; \\" );
981
    $io->PrtLn( "\t. \$(INTERFACEDIR)/set_$::ScmPlatform.sh; \\" );
255 dpurdie 982
    $io->PrtLn( "\t\$(show_environment); \\" );
227 dpurdie 983
    $io->PrtLn( "\t$buildcmd; \\" );
984
    $io->PrtLn( "\tret=\$\$?; \\" );
985
    $io->PrtLn( "\t\$(GBE_BIN)/cat $name\$(GBE_TYPE).log; \\" );
986
    $io->PrtLn( "\texit \$\$ret )" );
987
    $io->Newline();
988
 
989
    #
990
    #   Generate the recipe to clean the project
991
    #
992
    $io->Label( "Clean project", $name );
993
    $io->PrtLn( "ProjectClean_$name: $solution" );
994
    $io->PrtLn( "\t-\$(XX_PRE)$cleancmd" );
995
    $io->PrtLn( "\t-\$(XX_PRE)\$(rm) -f $name\$(GBE_TYPE).log" );
996
    $io->Newline();
997
 
998
}
999
 
1000
#-------------------------------------------------------------------------------
1001
# Function        : ToolsetTESTFRAMEWORK_NUNIT
1002
#
1003
# Description     : Toolset specfic support for the NUNIT Test FrameWork
1004
#                   Accessed with RunTest ('*', --FrameWork=nunit, ... );
1005
#
1006
#                   Manipulates the pEntry structure to allow JATS to
1007
#                   construct a test entry to run Nunit tests
1008
#
1009
# Inputs          : $pEntry                 - Unit Test Hash
1010
#
1011
# Returns         : Modified Hash
1012
#
1013
sub ToolsetTESTFRAMEWORK_NUNIT
1014
{
1015
    my ($pEntry) = @_;
1016
    my $test_dll_name;
1017
    my @copy_dlls;
1018
    my %copy_dll_flags;
1019
 
1020
    #
1021
    #   Extract base name of DLL under test
1022
    #   Thsi will not have any extension.
1023
    #
1024
    $test_dll_name = $pEntry->{'prog'};
1025
    Error ("Nunit Framework. No TestDLL specified") unless $test_dll_name;
1026
 
1027
    #
1028
    #   Process the FrameWork Options
1029
    #
1030
    foreach  ( @{$pEntry->{'framework_opts'}} )
1031
    {
1032
        if ( m/^--Uses=(.+)/ ) {
1033
            my ($dll, @opts) = split (',', $1 );
1034
            push @copy_dlls, $dll;
1035
            foreach  ( @opts )
1036
            {
1037
                if ( m~^--NonJats~i ) {
1038
                    $copy_dll_flags{$dll}{'NonJats'} = 1;
1039
                } elsif ( m~--Jats~ ) {
1040
                    $copy_dll_flags{$dll}{'NonJats'} = 0;
1041
                } else {
1042
                    Error ("Nunit Framework. Unknown sub option to --Uses: $_");
1043
                }
1044
            }
1045
        } else {
1046
            Error ("Nunit Framework. Unknown option: $_");
1047
        }
1048
    }
1049
 
1050
    #
1051
    #   Locate the Nunit essentials
261 dpurdie 1052
    #       This list may change with each version of nunit
1053
    #       Look for a known file and use its contents
1054
    #       Format:
1055
    #           One file name per line
1056
    #           Line comments only
1057
    #           Comment marker is a #
1058
    #           First one MUST be the executable
227 dpurdie 1059
    #
261 dpurdie 1060
    my @nunit_files;
227 dpurdie 1061
 
261 dpurdie 1062
    my $mfile = 'nunit-jats-manifest.txt';
1063
    my $nunit_file = ToolExtensionProgram ( $mfile );
1064
    Error ("Cannot find Nunit Jats Manifest: $mfile") unless ( $nunit_file );
1065
    open (JM, $nunit_file ) || Error( "Cannot open file: $nunit_file", "Reason: $!" );
1066
    while ( <JM> )
1067
    {
1068
        s~\s+$~~;                   # Remove trailing white space
1069
        s~^\s+~~;                   # Remove Leading whitespace
1070
        next unless ( $_ );         # Skip block lines
1071
        next if ( m~^#~ );          # Skip comments
1072
        Verbose ("Nunit File: $_");
1073
        push @nunit_files, $_;
1074
    }
1075
    close JM;
1076
 
1077
    #
1078
    #   Locate all the required files
1079
    #   The first one will be the console executable
1080
    #
227 dpurdie 1081
    my @nunit_framework;
1082
    foreach my $file ( @nunit_files )
1083
    {
1084
        my $path = ToolExtensionProgram ($file );
1085
        Error ("Cannot locate nunit file: $file") unless ( $path );
1086
        push @nunit_framework, $path;
1087
    }
261 dpurdie 1088
    my $nunit_console = $nunit_framework[0];
1089
    Error ("Nunit console executable not specified") unless ( $nunit_console );
227 dpurdie 1090
 
1091
    #
1092
    #   Locate the test DLL.
1093
    #   This will be created locally within this makefile
1094
    #   It will be a known shared library
1095
    #
1096
    Errror( "TestDLL does not appear to be locally created: $test_dll_name" )
289 dpurdie 1097
        unless ( $::SHLIBS->Get($test_dll_name) );
227 dpurdie 1098
 
1099
    #
1100
    #   Hard bit. Determine the name/path of the DLL under test
1101
    #   It will have been created within this makefile
1102
    #   This is not a physical file.
1103
    #
1104
    $test_dll_name = $test_dll_name . '$(GBE_TYPE).' . $::so;
1105
    my $test_dll = '$(LIBDIR)/' . $test_dll_name;
1106
 
1107
    #
1108
    #   Other hard bit
1109
    #   Locate the other dll's needed by this test
1110
    #   Need to use P in production and D in Debug unless otherwise specified
1111
    #   These might be in:
1112
    #       an external package
1113
    #       within the local directory
1114
    #       the current makefile
1115
    #   ie: We can only determine the location of the files at run-time
1116
    #
1117
    #   The mechanism used is:
1118
    #       Create makefile recipe entries to
1119
    #           Use cmdfile to create a command file with copy command
1120
    #           Execute the command file
1121
    #
1122
    #   Complications include:
1123
    #       The windows shell used does not honour 'set -e', so we need to
1124
    #       detect error conditions ourselves
1125
    #
1126
    my $ofile = "\$(TESTDIR)/$pEntry->{test_name}.cmd";
1127
    push @{$pEntry->{'ShellRecipe'}}, "rm -f $ofile";
1128
 
1129
    my @cmds;
363 dpurdie 1130
    push @cmds, "\$(cmdfile) -wk1W1o$ofile";
227 dpurdie 1131
    foreach my $dll ( @copy_dlls )
1132
    {
1133
        #
1134
        #   Generate in-line commands to locate and copy in the required
1135
        #   DLL's. The 'cmdfile' utility can be used to do this at runtime
1136
        #
1137
        my $dll_name = $dll;
1138
        $dll_name .= '$(GBE_TYPE)' unless ( $copy_dll_flags{$dll}{'NonJats'} );
1139
 
363 dpurdie 1140
        push @cmds, '"' . "cp -f @(vglob2,$dll_name.$::so,PATH,/) \$(TESTDIR) || exit 98" . '\n"';
227 dpurdie 1141
    }
1142
    push @cmds, "|| exit 99";
1143
    push @{$pEntry->{'ShellRecipe'}}, \@cmds;
1144
    push @{$pEntry->{'ShellRecipe'}}, ". $ofile";
1145
 
1146
 
1147
    #
1148
    #   Add items to the Unit Test Hash
1149
    #       command     - command to execute to run the test program
1150
    #       prog        - test command/script that must be in the test dir
1151
    #       copyprog    - Prog must be copied in
1152
    #       args        - Arguments to the test
1153
    #       copyin      - Array of files to copy into the test directory
1154
    #       copyonce    - Array of files to copy only once
1155
    #       prereq      - Prerequiste conditions
1156
    #       testdir     - Symbolic name of the test directory
1157
    #       ShellRecipe - Recipe Bits to add
1158
    #
1159
    $pEntry->{'command'}  = $nunit_console . ' ' . $test_dll_name;
1160
    unshift @{$pEntry->{args}}, "/xml=$pEntry->{test_name}.xml";
1161
    $pEntry->{'prog'} = $test_dll_name;
1162
    $pEntry->{'copyprog'} = 0;
1163
    push @{$pEntry->{'copyin'}}, $test_dll;
261 dpurdie 1164
    push @{$pEntry->{'copyonce'}}, @nunit_framework;
227 dpurdie 1165
    $pEntry->{'testdir'}  = 'TESTDIR';
1166
 
1167
    #   
1168
    #   Create the Test Directory
1169
    #   Tests will be done in a .NUNIT subdir
1170
    #
1171
    MkdirRule( "\$(TESTDIR)", 'TESTDIR', '--Path=$(GBE_PLATFORM)$(GBE_TYPE).NUNIT', '--RemoveAll' );
1172
 
1173
    #
1174
    #   Files created by the Unit Test
1175
    #
1176
    ToolsetGenerate ( "\$(TESTDIR)/$pEntry->{test_name}.xml"  );
1177
    ToolsetGenerate ( $ofile  );
1178
 
1179
}
1180
 
1181
#.. Successful termination
1182
1;
1183