Subversion Repositories DevTools

Rev

Rev 7372 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 dpurdie 1
########################################################################
6177 dpurdie 2
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
227 dpurdie 3
#
4
# Module name   : jats.sh
5
# Module type   : Makefile system
6
# Compiler(s)   : n/a
7
# Environment(s): jats
8
#
9
# Description   : Provide varions functions used by the BuildVersion
10
#                 directive.
11
#
12
#                 Use only within buildlib.pl as this package assumes
13
#                 a great deal about its environment.
14
#
15
#......................................................................#
16
 
255 dpurdie 17
require 5.006_001;
227 dpurdie 18
use strict;
19
use warnings;
20
 
21
our $Clobber;
22
our $CurrentYear;
23
our $CurrentTime;
24
our $Srcdir;
25
our $BuildVersion;
26
our $BUILDNAME;
27
our $BUILDNAME_PACKAGE;
28
our $BUILDNAME_VERSION;
29
our $BUILDNAME_PROJECT;
30
 
31
package BuildVersion;
32
use JatsError;
33
use JatsSystem;
34
use JatsVersionUtils;
267 dpurdie 35
use ConfigurationFile;
289 dpurdie 36
use FileUtils;
227 dpurdie 37
 
283 dpurdie 38
#
39
#   Package Interface
40
#
41
use base qw(Exporter);
42
our @EXPORT = qw( BuildVersionC
227 dpurdie 43
              BuildVersionCdefs
44
              BuildVersionCSharp
45
              BuildVersionWinRC
229 dpurdie 46
              BuildVersionProperties
289 dpurdie 47
              BuildVersionDelphi
315 dpurdie 48
              BuildVersionVB
227 dpurdie 49
            );
50
 
377 dpurdie 51
################################################################################
52
#   The following strings have been obtained from Simon Davey in an email
53
#   to David Purdie dated Monday, 16 January 2012 3:40 PM
54
#
55
#   Note: At 'init' time, the $CurrentDate is not valid
56
#         It must be injected later
57
#
58
my $CompanyName = 'Vix IP Pty Ltd';
59
my $Copyright = $CompanyName;                   # Will have $CurrentDate appended
60
my $Trademark = $CompanyName;
61
#
62
################################################################################
63
 
227 dpurdie 64
#-------------------------------------------------------------------------------
65
# Function        : BuildVersionCSharp
66
#
67
# Description     : Generate a C# versionn information file to allow
68
#                   insertion of data into an assembly
69
#
70
# Inputs          : $FileName           - Output filename (Optional)
71
#
72
# Returns         :
73
#
74
sub BuildVersionCSharp
75
{
76
    my ( $fname ) = @_;
77
    $fname = 'AssemblyVersionInfo.cs' unless $fname;
78
 
247 dpurdie 79
    #
80
    #   Store the files location for use at runtime
81
    #   It will be a file that is 'known' to JATS
82
    #
83
    $fname = ::BuildAddKnownFile ( $Srcdir, $fname );
84
    return if ( $Clobber );      # clobber mode ?
289 dpurdie 85
    Message ("Creating C# Version File: $fname" );
227 dpurdie 86
 
87
    #
88
    #   Determine the build version
89
    #
359 dpurdie 90
    my ($major, $minor, $patch, $build, $raw_patch) = SplitVersionClean($BUILDNAME_VERSION);
227 dpurdie 91
    my $vstring = "$major.$minor.$patch.$build";
92
 
93
 
247 dpurdie 94
    my $fh = ConfigurationFile::New( $fname, '--Type=CSharp' );
227 dpurdie 95
    $fh->HeaderSimple( "buildlib (Version $BuildVersion)",
96
                       "CSharp Assembly Version Definition" );
97
 
98
    $fh->Write( "\n" );
99
    $fh->Write( "using System.Reflection;\n" );
100
    $fh->Write( "using System.Runtime.CompilerServices;\n" );
101
    $fh->Write( "\n" );
377 dpurdie 102
    $fh->Write( "[assembly: AssemblyCompany(\"$CompanyName\")]\n" );
227 dpurdie 103
    $fh->Write( "[assembly: AssemblyProduct(\"$BUILDNAME_PACKAGE\")]\n" );
377 dpurdie 104
    $fh->Write( "[assembly: AssemblyCopyright(\"$Copyright $CurrentYear\")]\n" );
105
    $fh->Write( "[assembly: AssemblyTrademark(\"$Trademark\")]\n" );
227 dpurdie 106
    $fh->Write( "\n");
107
    $fh->Comment( "\n");
108
    $fh->Comment( "Version information for an assembly consists of the following four values:\n");
109
    $fh->Comment( "\n");
377 dpurdie 110
    $fh->Comment( "     Major Version   -VIX:Major\n");
111
    $fh->Comment( "     Minor Version  - VIX:Minor\n");
112
    $fh->Comment( "     Build Number   - VIX:Patch\n");
113
    $fh->Comment( "     Revision       - VIX:Build Number\n");
227 dpurdie 114
    $fh->Comment( "\n");
115
    $fh->Write( "\n");
116
    $fh->Write( "[assembly: AssemblyVersion(\"$vstring\")]\n" );
117
    $fh->Write( "\n");
118
 
119
    $fh->Close();
120
}
121
 
122
#-------------------------------------------------------------------------------
123
# Function        : BuildVersionWinRC
124
#
125
# Description     : Create a Windows RC file to describe the build version
126
#                   This file may be used directly
127
#
128
# Inputs          : $FileName           - Output filename (Optional)
267 dpurdie 129
#                   @opts               - Options
130
#                           --Definitions
131
#                           --Icon=path
132
#                           --Comment=text
133
#                           --Description=text
134
#                           --Product=text
135
#                           --Version=text          (Internal Use)
136
#                           --PkgName=text          (Internal Use)
137
#                           --ToolUse               (Internal Use)
138
# Returns         : Nothing
227 dpurdie 139
#
140
sub BuildVersionWinRC
141
{
267 dpurdie 142
    my ( $fname, @opts ) = @_;
143
    my $icon;
144
    my $defs;
145
    my $product = '';
146
    my $version = $BUILDNAME_VERSION || '';
147
    my $pkg_name = $BUILDNAME_PACKAGE || '';
148
    my $comment = "Build Date: $CurrentTime";
149
    my $description = '';
150
    my $used_by_tool = '';
151
 
152
    #
153
    #   Process options
154
    #
155
    foreach ( @opts )
156
    {
157
        if ( m~^--Icon=(.+)~ ) {
158
            $icon = $1;
159
        } elsif ( m~^--Definitions~ ) {
160
            $defs = 1;
161
        } elsif ( m~^--Comment=(.+)~ ) {
162
            $comment = $1;
163
        } elsif ( m~^--Description=(.+)~ ) {
164
            $description = $1;
165
        } elsif ( m~^--Product=(.+)~ ) {
166
            $product = $1;
167
        } elsif ( m~^--Version=(.+)~ ) {
168
            $version = $1;
169
        } elsif ( m~^--PkgName=(.+)~ ) {
170
            $pkg_name = $1;
171
        } elsif ( m~^--ToolUse~ ) {
172
            $used_by_tool = 1;
173
        } else {
174
            Error ("WinRC Style Version. Unknown option: $_");
175
        }
176
    }
177
 
178
    #
179
    #   Setup defaults
180
    #
227 dpurdie 181
    $fname = 'version.rc' unless $fname;
267 dpurdie 182
    Error ("WinRC: No Build Version provided") unless ( $version );
183
    Error ("WinRC: No Build Package Name provided") unless ( $pkg_name );
227 dpurdie 184
 
185
    #
247 dpurdie 186
    #   Store the files location for use at runtime
187
    #   It will be a file that is 'known' to JATS
188
    #
267 dpurdie 189
    unless ( $used_by_tool  )
190
    {
191
        $fname = ::BuildAddKnownFile ( $Srcdir, $fname );
192
        return if ( $Clobber );      # clobber mode ?
193
    }
194
 
247 dpurdie 195
    Message ("Creating Windows Resource File: $fname" );
267 dpurdie 196
 
247 dpurdie 197
    #
227 dpurdie 198
    #   Determine the build version
199
    #
359 dpurdie 200
    my ($major, $minor, $patch, $build, $raw_patch) = SplitVersionClean($version);
227 dpurdie 201
    my $product_version = "$major, $minor, $patch, $build";
202
 
203
 
204
    #
205
    #   Create the file
206
    #
247 dpurdie 207
    my $fh = ConfigurationFile::New( $fname, '--Type=C++' );
227 dpurdie 208
    $fh->HeaderSimple( "buildlib (Version $BuildVersion)",
209
                       "Windows Resource Version Definition" );
210
 
211
    sub prc
212
    {
213
        return "@_\n";
214
    }
215
 
216
    sub pdefs
217
    {
218
        my ($arg, $val) = @_;
267 dpurdie 219
        Error ("Undefined value for $arg") unless ( defined $val );
227 dpurdie 220
        return "#define $arg \"$val\\0\"\n";
221
    }
222
 
223
    sub pdef
224
    {
225
        my ($arg, $val) = @_;
267 dpurdie 226
        Error ("Undefined value for $arg") unless ( defined $val );
227 dpurdie 227
        return "#define $arg $val\n";
228
    }
229
 
230
    $fh->Write(prc     (""));
231
    $fh->Write(pdefs   ("RC_STR_EMPTY"         , "" ));
377 dpurdie 232
    $fh->Write(pdefs   ("RC_STR_COMPANY"       , $CompanyName ));
267 dpurdie 233
    $fh->Write(pdefs   ("RC_STR_PRODUCTNAME"   , $product ));
234
    $fh->Write(pdefs   ("RC_STR_COMMENT"       , $comment ));
235
    $fh->Write(pdefs   ("RC_STR_DESCRIPTION"   , $description ));
236
    $fh->Write(pdefs   ("RC_STR_NAME"          , $pkg_name ));
227 dpurdie 237
    $fh->Write(pdefs   ("RC_STR_VERSION"       , $product_version ));
238
    $fh->Write(pdef    ("RC_NUM_VERSION"       , $product_version ));
377 dpurdie 239
    $fh->Write(pdefs   ("RC_STR_COPYRIGHT"     , $Copyright . ' ' . $::CurrentYear ));
240
    $fh->Write(pdefs   ("RC_STR_TRADEMARK"     , $Trademark ));
227 dpurdie 241
    $fh->Write(prc     ('#ifdef _DEBUG'));
242
    $fh->Write(pdefs   ("RC_STR_SPECIAL"       , "Debug Version" ));
243
    $fh->Write(prc     ('#else'));
244
    $fh->Write(pdefs   ("RC_STR_SPECIAL"       , "Production Version" ));
245
    $fh->Write(prc     ('#endif'));
246
    $fh->Write(prc     (""));
247
 
263 dpurdie 248
    unless ( $defs )
249
    {
269 dpurdie 250
        $fh->Write(prc     ('#define VS_VERSION_INFO     1'));
263 dpurdie 251
        $fh->Write(prc     (''));
252
        $fh->Write(prc     ('VS_VERSION_INFO VERSIONINFO'));
253
        $fh->Write(prc     (' FILEVERSION      RC_NUM_VERSION'));
254
        $fh->Write(prc     (' PRODUCTVERSION   RC_NUM_VERSION'));
255
        $fh->Write(prc     (' FILEFLAGSMASK 0x3fL'));
256
        $fh->Write(prc     ('#ifdef _DEBUG'));
257
        $fh->Write(prc     (' FILEFLAGS 0x1L'));
258
        $fh->Write(prc     ('#else'));
259
        $fh->Write(prc     (' FILEFLAGS 0x0L'));
260
        $fh->Write(prc     ('#endif'));
261
        $fh->Write(prc     (' FILEOS 0x40004L'));
262
        $fh->Write(prc     (' FILETYPE 0x1L'));
263
        $fh->Write(prc     (' FILESUBTYPE 0x0L'));
264
        $fh->Write(prc     ('BEGIN'));
265
        $fh->Write(prc     ('    BLOCK "StringFileInfo"'));
266
        $fh->Write(prc     ('    BEGIN'));
267
        $fh->Write(prc     ('        BLOCK "0c0904b0"'));
268
        $fh->Write(prc     ('        BEGIN'));
269
        $fh->Write(prc     ('            VALUE "Comments",         RC_STR_COMMENT'));
270
        $fh->Write(prc     ('            VALUE "CompanyName",      RC_STR_COMPANY'));
271
        $fh->Write(prc     ('            VALUE "FileDescription",  RC_STR_DESCRIPTION'));
272
        $fh->Write(prc     ('            VALUE "FileVersion",      RC_STR_VERSION'));
273
        $fh->Write(prc     ('            VALUE "InternalName",     RC_STR_NAME'));
274
        $fh->Write(prc     ('            VALUE "LegalCopyright",   RC_STR_COPYRIGHT'));
377 dpurdie 275
        $fh->Write(prc     ('            VALUE "LegalTrademarks",  RC_STR_TRADEMARK'));
263 dpurdie 276
        $fh->Write(prc     ('            VALUE "OriginalFilename", RC_STR_NAME'));
277
        $fh->Write(prc     ('            VALUE "PrivateBuild",     RC_STR_EMPTY'));
278
        $fh->Write(prc     ('            VALUE "ProductName",      RC_STR_PRODUCTNAME'));
279
        $fh->Write(prc     ('            VALUE "ProductVersion",   RC_STR_VERSION'));
280
        $fh->Write(prc     ('            VALUE "SpecialBuild",     RC_STR_SPECIAL'));
281
        $fh->Write(prc     ('        END'));
282
        $fh->Write(prc     ('    END'));
283
        $fh->Write(prc     ('        BLOCK "VarFileInfo"'));
284
        $fh->Write(prc     ('        BEGIN'));
285
        $fh->Write(prc     ('            VALUE "Translation", 0xc09, 1200'));
286
        $fh->Write(prc     ('        END'));
287
        $fh->Write(prc     ('END'));
288
        $fh->Write(prc     (''));
227 dpurdie 289
 
263 dpurdie 290
        if ( $icon )
291
        {
292
        $fh->Write(prc     (''));
293
        $fh->Write(prc     ('/////////////////////////////////////////////////////////////////////////////'));
294
        $fh->Write(prc     ('//'));
295
        $fh->Write(prc     ('// Icon'));
296
        $fh->Write(prc     ('//'));
297
        $fh->Write(prc     ('// Icon with lowest ID value placed first to ensure application icon'));
298
        $fh->Write(prc     ('// remains consistent on all systems.'));
299
        $fh->Write(prc     ("101       ICON    DISCARDABLE     \"$icon\""));
300
        $fh->Write(prc     (''));
301
        }
235 dpurdie 302
    }
303
 
304
 
227 dpurdie 305
    $fh->Close();
306
}
307
 
308
#-------------------------------------------------------------------------------
309
# Function        : BuildVersionC
310
#
311
# Description     : Create a "C" style version.c and version.h file
312
#
289 dpurdie 313
# Inputs          : $FileName       - Output filename (Optional)
314
#                                     If provided it will be 'known' to all
315
#                                     of jats. Done for backward compatability
316
#                   $Prefix         - Text to prefix generated variables with
227 dpurdie 317
#                                     Used to avoid namespace conflicts
318
#                   $Type           - Type of version to create
319
#                                     Only allowed value is 'array'
320
#
321
# Returns         :
322
#
323
 
324
sub BuildVersionC
325
{
289 dpurdie 326
    my( $FileName, $Prefix, $Type ) = @_;
227 dpurdie 327
    my $ver;
328
 
289 dpurdie 329
    #
330
    #   Default name of the file
331
    #   Don't allow the user to play with the extension
332
    #   If the user provided a filename It will be a file that is 'known' to JATS
333
    #   
334
    my $bname = defined($FileName) ? StripExt($FileName) : 'version';
227 dpurdie 335
 
289 dpurdie 336
    my $fname_c = ::BuildAddKnownFile ( $Srcdir, $bname . '.c', !defined($FileName) );
337
    my $fname_h = ::BuildAddKnownFile ( $Srcdir, $bname . '.h', !defined($FileName) );
338
 
339
    return if ( $Clobber );      # clobber mode ?
340
    Message ("Creating C Version File: $fname_c" );
341
 
227 dpurdie 342
    #
343
    #   Default prefix is none
344
    #   Set to a defined, bet empty, string
345
    #
346
    $Prefix = "" if ( ! defined( $Prefix ) );
347
    $Type   = "" if ( ! defined( $Type ) );
348
 
349
    #   src/version.c
350
    #..
289 dpurdie 351
    open( VERSIONC, '>', $fname_c ) ||
352
        Error( "cannot create $fname_c" );
227 dpurdie 353
 
354
    print VERSIONC
355
        "/* Please do not edit this file.\n" .
356
        " * It was auto-generated by Buildlib ($BuildVersion) on $::CurrentTime\n" .
357
        " */\n" .
358
        "#include \"version.h\"\n";
359
 
360
    my @PACKAGEVERS = PackageEntry::GetPackageVersionList();
361
    if ( $Type eq "array" )
362
    {                                           # new style
363
        print VERSIONC
364
           "static const char *pkgarray[] = \n" .
365
           "{\n";
366
 
367
        foreach $ver ( @PACKAGEVERS   ) {
368
            print VERSIONC "    \"$ver\",\n";
369
        }
370
 
371
        print VERSIONC
372
           "    0\n",
373
           "};\n\n";
374
 
375
        print VERSIONC
376
           "\nconst char *\n$Prefix"."VersionString(void)\n" .
377
           "{\n".
378
           "    return \"$BUILDNAME\";\n" .
379
           "}\n" .
380
           "\nconst char **\n$Prefix"."PkgStrings(void)\n" .
381
           "{\n".
382
           "    return pkgarray;\n" .
383
           "}\n" .
384
           "\nconst char *\n$Prefix"."GetModuleInfo(void)\n" .
385
           "{\n" .
386
           "    return \"$BUILDNAME_PACKAGE ($BUILDNAME_VERSION.$BUILDNAME_PROJECT) @PACKAGEVERS\";\n" .
387
           "}\n";
388
    }
389
    else
390
    {                                           # old style
391
        print VERSIONC
392
           "\nconst char *\n$Prefix"."VersionString(void)\n" .
393
           "{\n".
394
           "    return \"$BUILDNAME @PACKAGEVERS\";\n" .
395
           "}\n" .
396
           "\nconst char *\n$Prefix"."GetModuleInfo(void)\n" .
397
           "{\n" .
398
           "    return \"$BUILDNAME_PACKAGE ($BUILDNAME_VERSION.$BUILDNAME_PROJECT) @PACKAGEVERS\";\n" .
399
           "}\n";
400
    }
401
    close VERSIONC;
402
 
403
#   src/version.h
404
#..
289 dpurdie 405
    open( VERSIONH, '>', $fname_h ) ||
406
        Error( "cannot create $fname_h" );
227 dpurdie 407
 
408
    print VERSIONH
409
        "#ifndef VERSION_H_INCLUDED\n" .
410
        "#define VERSION_H_INCLUDED\n" .
411
        "/* Please do not edit this file.\n" .
412
        " * It was auto-generated by Buildlib ($BuildVersion) on $::CurrentTime\n" .
413
        " */\n\n" .
414
        "#define BUILDNAME     \"$BUILDNAME\"\n" .
415
        "#define BUILDDATE     \"$::CurrentTime\"\n" .
416
        "\n";
417
 
418
    print VERSIONH
419
        "#ifdef __cplusplus\n" .
420
        "    extern \"C\" {           /* force C calling convention when using C++ */\n" .
421
        "#endif\n" .
422
        "\n";
423
 
424
    if ( $Type eq "array" )
425
    {                                           # extended interface
426
        print VERSIONH
427
        "extern const char **  $Prefix"."PkgStrings(void);\n";
428
    }
429
    print VERSIONH
430
        "extern const char *   $Prefix"."VersionString(void);\n".
431
        "extern const char *   $Prefix"."GetModuleInfo(void);\n";
432
 
433
    print VERSIONH
434
        "\n" .
435
        "#ifdef __cplusplus\n" .
436
        "    } /* extern \"C\" */\n" .
437
        "#endif\n" .
438
        "\n";
439
 
440
    print VERSIONH
441
        "\n#endif /*VERSION_H_INCLUDED*/\n";
442
    close VERSIONH;
443
}
444
 
445
#-------------------------------------------------------------------------------
446
# Function        : BuildVersionCdefs
447
#
448
# Description     : Generate a "C" style version definitions file
449
#                   This file simply contains definitions
450
#
289 dpurdie 451
# Inputs          : $FileName       - Output filename (Optional)
452
#                                     If provided it will be 'known' to all
453
#                                     of jats. Done for backward compatability
454
#                   $Mode           - File suffix
227 dpurdie 455
#                   $ModePrefix     - Tag for all generated definitions
456
#
457
# Returns         :
458
#
459
 
460
sub BuildVersionCdefs
461
{
289 dpurdie 462
    my ( $FileName, $Mode, $ModePrefix ) = @_;
227 dpurdie 463
 
289 dpurdie 464
    my $fname = defined($FileName) ? $FileName : "version_$Mode.h";
465
    $fname = ::BuildAddKnownFile ( $Srcdir, $fname , ! defined($FileName) );
466
    return if ( $Clobber );      # clobber mode ?
467
    Message ("Creating C Version Defs File: $fname" );
227 dpurdie 468
 
469
    #
470
    #   Generate version_defs.h
471
    #   This file contains ONLY definitions. It may be used by assembler
472
    #   programs (that support a preprocessor) to access version information
473
    #
474
    #   Allow for a user supplied filename fragment that will be used within
475
    #   all the definitions with in the file.
476
    #
359 dpurdie 477
    my ($major, $minor, $patch, $build, $raw_patch) = SplitVersionClean($BUILDNAME_VERSION);
227 dpurdie 478
    my @PACKAGEVERS = PackageEntry::GetPackageVersionList();
479
 
480
    #
481
    #   Base names on a user supplied value or a default
482
    #
483
    my $vtag = uc( "VERSION$ModePrefix" );
484
    my $guard_name = uc($fname);
289 dpurdie 485
       $guard_name =~ tr~\.\/\\~_~s;
227 dpurdie 486
 
289 dpurdie 487
    open( VERSIOND, '>', $fname ) ||
488
        Error( "cannot create $fname" );
227 dpurdie 489
 
490
    print VERSIOND
491
        "#ifndef $guard_name\n" .
492
        "#define $guard_name\n" .
493
        "/* Please do not edit this file.\n" .
494
        " * It was auto-generated by Buildlib ($BuildVersion) on $::CurrentTime\n" .
495
        " */\n\n" .
496
        "\n".
497
        "#define ${vtag}_BUILDNAME      \"$BUILDNAME\"\n".
498
        "#define ${vtag}_BUILDDATE      \"$::CurrentTime\"\n".
499
        "\n".
500
        "#define ${vtag}_PACKAGE        \"$BUILDNAME_PACKAGE\"\n".
501
        "#define ${vtag}_VERSION        \"$BUILDNAME_VERSION\"\n".
502
        "#define ${vtag}_MAJOR_STR      \"$major\"\n".
503
        "#define ${vtag}_MINOR_STR      \"$minor\"\n".
504
        "#define ${vtag}_PATCH_STR      \"$patch\"\n".
505
        "#define ${vtag}_BUILD_STR      \"$build\"\n".
506
        "#define ${vtag}_PATCHBUILD_STR \"$raw_patch\"\n".
507
        "#define ${vtag}_PROJECT        \"$BUILDNAME_PROJECT\"\n".
359 dpurdie 508
        "#define ${vtag}_MAJOR          $major\n".
509
        "#define ${vtag}_MINOR          $minor\n".
510
        "#define ${vtag}_PATCH          $patch\n".
511
        "#define ${vtag}_BUILD          $build\n".
512
        "#define ${vtag}_PATCHBUILD     $raw_patch\n".
227 dpurdie 513
        "#define ${vtag}_ALL            \"$BUILDNAME_PACKAGE ($BUILDNAME_VERSION.$BUILDNAME_PROJECT) @PACKAGEVERS\"\n".
514
        "#define ${vtag}_BUILDTIME      " . strip_zeros(time()) . "\n".
515
        "\n".
516
        "#endif /* $guard_name */\n";
517
 
518
    close VERSIOND;
519
}
520
 
521
#-------------------------------------------------------------------------------
229 dpurdie 522
# Function        : BuildVersionProperties
523
#
524
# Description     : Generate a "Java" style version definitions file
525
#                   This is a simple properties file
526
#
527
# Inputs          : $FileName       - Output filename (Optional)
528
#                   $Prefix         - Tag for all generated definitions
529
#
530
# Returns         :
531
#
532
sub BuildVersionProperties
533
{
534
    my ( $fname, $Prefix ) = @_;
535
 
536
    #
537
    #   Default name of the file
538
    #
539
    $fname = 'version.properties' unless $fname;
540
 
541
    #
247 dpurdie 542
    #   Store the files location for use at runtime
543
    #   It will be a file that is 'known' to JATS
544
    #
545
    $fname = ::BuildAddKnownFile ( $Srcdir, $fname );
546
    return if ( $Clobber );      # clobber mode ?
289 dpurdie 547
    Message ("Creating Properties Version File: $fname" );
247 dpurdie 548
 
549
    #
229 dpurdie 550
    #   Generate version properties file
551
    #
552
    #   This file contains ONLY definitions. It may be included by the ANT
553
    #   builds. Its not intended to be imported by the java code
554
 
555
 
556
    #
557
    #   Allow for a user supplied property prefix
558
    #   Not really needed as
559
    #
560
    my $vtag = '';
561
    $vtag = $Prefix . '.' if $Prefix;
562
 
563
 
359 dpurdie 564
    my ($major, $minor, $patch, $build, $raw_patch) = SplitVersionClean($BUILDNAME_VERSION);
229 dpurdie 565
    my @PACKAGEVERS = PackageEntry::GetPackageVersionList();
566
 
567
    #
568
    #   Create properties in the same form as for "C" definitions
569
    #   Note:
570
    #       The 'ALL' is in a format used by other software. Do not change
571
    #
247 dpurdie 572
    open( VERSIOND, ">$fname" ) ||
573
        Error( "cannot create $fname" );
229 dpurdie 574
 
575
    print VERSIOND
576
        "# Please do not edit this file.\n" .
577
        "# It was auto-generated by Buildlib ($BuildVersion) on $::CurrentTime\n" .
578
        "#\n" .
579
        "${vtag}BUILDNAME      = $BUILDNAME\n".
580
        "${vtag}BUILDDATE      = $::CurrentTime\n".
581
        "\n".
582
        "${vtag}PACKAGE        = $BUILDNAME_PACKAGE\n".
583
        "${vtag}VERSION        = $BUILDNAME_VERSION\n".
584
        "${vtag}MAJOR_STR      = $major\n".
585
        "${vtag}MINOR_STR      = $minor\n".
586
        "${vtag}PATCH_STR      = $patch\n".
587
        "${vtag}BUILD_STR      = $build\n".
588
        "${vtag}PATCHBUILD_STR = $raw_patch\n".
589
        "${vtag}PROJECT        = $BUILDNAME_PROJECT\n".
359 dpurdie 590
        "${vtag}MAJOR          = $major\n".
591
        "${vtag}MINOR          = $minor\n".
592
        "${vtag}PATCH          = $patch\n".
593
        "${vtag}BUILD          = $build\n".
594
        "${vtag}PATCHBUILD     = $raw_patch\n".
229 dpurdie 595
        "${vtag}ALL            = $BUILDNAME_PACKAGE ($BUILDNAME_VERSION.$BUILDNAME_PROJECT) @PACKAGEVERS\n".
596
        "${vtag}BUILDTIME      = " . strip_zeros(time()) . "\n".
597
        "\n";
598
    #
599
    #   Create a set of definitions for each dependent package
600
    #
601
    print VERSIOND "# Dependent Packages and Versions\n".
602
                   "#\n";
603
 
604
    foreach my $tag ( PackageEntry::GetPackageList() )
605
    {
606
        my ($name, $version, $type) = PackageEntry::GetPackageData($tag);
607
#        push @attributes, "build=\"true\"" if $type =~ /Build/i;
608
        print VERSIOND "${vtag}PACKAGE.$name=$version\n";
609
    }
610
    close VERSIOND;
611
}
612
 
613
#-------------------------------------------------------------------------------
289 dpurdie 614
# Function        : BuildVersionDelphi
615
#
616
# Description     : Create a pascal file in Delphi format
617
#
618
# Inputs          : $FileName       - Output filename (Optional)
619
#                   $Prefix         - Tag for all generated definitions
620
#
621
#
622
# Returns         : 
623
#
624
sub BuildVersionDelphi
625
{
626
    my ( $fname, $Prefix ) = @_;
627
 
628
    #
629
    #   Default name of the file
630
    #
631
    $fname = 'version_defs.pas' unless $fname;
632
    $fname .= '.pas'
633
        unless ( $fname =~ m~\.~ );
634
    my $unit_name = StripDirExt($fname);
635
    Error ("BuildVersion: Delphi Style. Filename \'$unit_name\. not allowed")
636
        if ( $unit_name =~ m~^version$~i );
637
 
638
    #
639
    #   Store the files location for use at runtime
640
    #   It will be a file that is 'known' to JATS
641
    #
642
    $fname = ::BuildAddKnownFile ( $Srcdir, $fname );
643
    return if ( $Clobber );      # clobber mode ?
644
    Message ("Creating Delpi Version File: $fname" );
645
 
646
    #
647
    #   Generate version source file
648
    #   This file contains ONLY constant definitions.
649
 
650
    #
651
    #   Allow for a user supplied property prefix
652
    #   Not really needed as
653
    #
654
    my $vtag = '';
655
    $vtag = $Prefix . '_' if $Prefix;
656
 
657
 
359 dpurdie 658
    my ($major, $minor, $patch, $build, $raw_patch) = SplitVersionClean($BUILDNAME_VERSION);
289 dpurdie 659
    my @PACKAGEVERS = PackageEntry::GetPackageVersionList();
660
 
661
    #
662
    #   Create properties in the same form as for "C" definitions
663
    #   Note:
664
    #       The 'ALL' is in a format used by other software. Do not change
665
    #
666
    sub pstring
667
    {
668
        my ($arg, $val) = @_;
669
        Error ("Undefined value for $arg") unless ( defined $val );
670
        return sprintf ( "%-24s = \'%s\';" , $arg, $val);
671
    }
672
    sub pnum
673
    {
674
        my ($arg, $val) = @_;
675
        Error ("Undefined value for $arg") unless ( defined $val );
359 dpurdie 676
        return sprintf ( "%-24s = %s;" , $arg, $val );
289 dpurdie 677
    }
678
 
679
    my $fh = ConfigurationFile::New( $fname, '--Type=Delphi' );
680
    $fh->HeaderSimple( "buildlib (Version $BuildVersion)",
681
                       "Delphi Unit Version Definition" );
682
 
683
    $fh->WriteLn(
684
        "unit $unit_name;",
685
        "interface",
686
        "const",
687
        pstring ("${vtag}BUILDNAME",$BUILDNAME),
688
        pstring ("${vtag}BUILDDATE",$::CurrentTime),
689
        '',
690
        pstring ("${vtag}PACKAGE",$BUILDNAME_PACKAGE),
691
        pstring ("${vtag}VERSION",$BUILDNAME_VERSION),
692
        pstring ("${vtag}MAJOR_STR",$major),
693
        pstring ("${vtag}MINOR_STR",$minor),
694
        pstring ("${vtag}PATCH_STR",$patch),
695
        pstring ("${vtag}BUILD_STR",$build),
696
        pstring ("${vtag}PATCHBUILD_STR",$raw_patch),
697
        pstring ("${vtag}PROJECT",$BUILDNAME_PROJECT),
698
        pnum ("${vtag}MAJOR",$major),
699
        pnum ("${vtag}MINOR",$minor),
700
        pnum ("${vtag}PATCH",$patch),
701
        pnum ("${vtag}BUILD",$build),
702
        pnum ("${vtag}PATCHBUILD",$raw_patch),
703
        pstring ("${vtag}ALL","$BUILDNAME_PACKAGE ($BUILDNAME_VERSION.$BUILDNAME_PROJECT) @PACKAGEVERS"),
359 dpurdie 704
        pnum ("${vtag}BUILDTIME",strip_zeros(time())),
289 dpurdie 705
        ''
706
        );
707
 
708
    #
709
    #   Create a set of definitions for each dependent package
710
    #
711
    $fh->Comment("Dependent Packages and Versions\n");
712
    $fh->Comment("\n");
713
 
714
    foreach my $tag ( PackageEntry::GetPackageList() )
715
    {
716
        my ($name, $version, $type) = PackageEntry::GetPackageData($tag);
717
        $fh->WriteLn(pstring ("${vtag}PACKAGE_$name", $version));
718
    }
719
    $fh->WriteLn( '',
720
        "implementation",
721
        "end.");
722
 
723
 
724
    $fh->WriteLn();
725
    $fh->Close();
726
}
727
 
315 dpurdie 728
#-------------------------------------------------------------------------------
729
# Function        : BuildVersionVB
730
#
731
# Description     : Create a VB6 file in Basic format
732
#
733
# Inputs          : $FileName       - Output filename (Optional)
734
#                   $Prefix         - Tag for all generated definitions
735
#
736
#
737
# Returns         : 
738
#
739
sub BuildVersionVB
740
{
741
    my ( $fname, $Prefix ) = @_;
289 dpurdie 742
 
315 dpurdie 743
    #
744
    #   Default name of the file
745
    #
746
    $fname = 'version.bas' unless $fname;
747
    $fname .= '.bas'
748
        unless ( $fname =~ m~\.~ );
749
 
750
    #
751
    #   Store the files location for use at runtime
752
    #   It will be a file that is 'known' to JATS
753
    #
754
    $fname = ::BuildAddKnownFile ( $Srcdir, $fname );
755
    return if ( $Clobber );      # clobber mode ?
756
    Message ("Creating Visual Basic Version File: $fname" );
757
 
758
    #
759
    #   Generate version source file
760
    #   This file contains ONLY constant definitions.
761
 
762
    #
763
    #   Allow for a user supplied property prefix
764
    #   Not really needed as
765
    #
766
    my $vtag = '';
767
    $vtag = $Prefix . '_' if $Prefix;
768
 
769
 
359 dpurdie 770
    my ($major, $minor, $patch, $build, $raw_patch) = SplitVersionClean($BUILDNAME_VERSION);
315 dpurdie 771
    my @PACKAGEVERS = PackageEntry::GetPackageVersionList();
772
 
773
    #
774
    #   Create properties in the same form as for "C" definitions
775
    #   Note:
776
    #       The 'ALL' is in a format used by other software. Do not change
777
    #
778
    sub pvbstring
779
    {
780
        my ($arg, $val) = @_;
781
        Error ("Undefined value for $arg") unless ( defined $val );
782
        return sprintf ( "Public Const %-24s = \"%s\"" , $arg, $val);
783
    }
784
    sub pvbnum
785
    {
786
        my ($arg, $val) = @_;
787
        Error ("Undefined value for $arg") unless ( defined $val );
359 dpurdie 788
        return sprintf ( "Public Const %-24s = %s" , $arg, $val );
315 dpurdie 789
    }
790
 
791
    my $fh = ConfigurationFile::New( $fname, '--Type=Basic' );
792
    $fh->HeaderSimple( "buildlib (Version $BuildVersion)",
793
                       "Visual Basic Version Definition" );
794
 
795
    $fh->WriteLn(
796
        "Attribute VB_Name = \"JatsVersion\"",
797
        '',
798
        pvbstring ("${vtag}BUILDNAME",      $BUILDNAME),
799
        pvbstring ("${vtag}BUILDDATE",      $::CurrentTime),
800
        '',
801
        pvbstring ("${vtag}PACKAGE",        $BUILDNAME_PACKAGE),
802
        pvbstring ("${vtag}VERSION",        $BUILDNAME_VERSION),
803
        pvbstring ("${vtag}MAJOR_STR",      $major),
804
        pvbstring ("${vtag}MINOR_STR",      $minor),
805
        pvbstring ("${vtag}PATCH_STR",      $patch),
806
        pvbstring ("${vtag}BUILD_STR",      $build),
807
        pvbstring ("${vtag}PATCHBUILD_STR", $raw_patch),
808
        pvbstring ("${vtag}PROJECT",        $BUILDNAME_PROJECT),
809
        pvbnum    ("${vtag}MAJOR",          $major),
810
        pvbnum    ("${vtag}MINOR",          $minor),
811
        pvbnum    ("${vtag}PATCH",          $patch),
812
        pvbnum    ("${vtag}BUILD",          $build),
813
        pvbnum    ("${vtag}PATCHBUILD",     $raw_patch),
814
        pvbstring ("${vtag}ALL",            "$BUILDNAME_PACKAGE ($BUILDNAME_VERSION.$BUILDNAME_PROJECT) @PACKAGEVERS"),
359 dpurdie 815
        pvbnum    ("${vtag}BUILDTIME",      strip_zeros(time())),
315 dpurdie 816
        ''
817
        );
818
 
819
    #
820
    #   Create a set of definitions for each dependent package
821
    #
822
    $fh->Comment("Dependent Packages and Versions\n");
823
    $fh->Comment("\n");
824
 
825
    foreach my $tag ( PackageEntry::GetPackageList() )
826
    {
827
        my ($name, $version, $type) = PackageEntry::GetPackageData($tag);
363 dpurdie 828
        $fh->WriteLn(pvbstring ("${vtag}PACKAGE_$name", $version));
315 dpurdie 829
    }
830
 
831
    $fh->WriteLn();
832
    $fh->Close();
833
}
834
 
359 dpurdie 835
#-------------------------------------------------------------------------------
836
# Function        : SplitVersionClean
837
#
838
# Description     : Pull apart the Version Number and clean it up
839
#                   Remove leading zeros from components
840
#
841
# Inputs          : $version    - Version Number
842
#
843
# Returns         : A list of:
844
#                       Major, Minor, Patch, Build, RawPatch
845
#                   with leading zeros removed
846
#
847
sub SplitVersionClean
848
{
849
    my ($version) = @_;
850
    my ($major, $minor, $patch, $build, $raw_patch) = SplitVersion($version);
315 dpurdie 851
 
359 dpurdie 852
    return (
853
        strip_zeros($major),
854
        strip_zeros($minor),
855
        strip_zeros($patch),
856
        strip_zeros($build),
857
        strip_zeros($raw_patch)
858
    );
859
}
860
 
289 dpurdie 861
#-------------------------------------------------------------------------------
227 dpurdie 862
# Function        : stip_zeros
863
#
864
# Description     : Remove leading 0's from a string
865
#
866
# Inputs          : A string
867
#
868
# Returns         : A string without leading zeros
869
#
870
sub strip_zeros
871
{
872
    my ($text) = @_;
873
 
874
    $text =~ s~^0*~~;
875
    $text = '0' unless ( $text );
876
    return $text;
877
}
878
 
879
1;