Subversion Repositories DevTools

Rev

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