Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
227 dpurdie 1
########################################################################
7300 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
    print VERSIONC
361
        "\n" .
377 dpurdie 362
        "static char what[] = \"@(#) $BUILDNAME $::CurrentDate $CompanyName\";\n" .
227 dpurdie 363
        "\n";
364
 
365
 
366
    my @PACKAGEVERS = PackageEntry::GetPackageVersionList();
367
    if ( $Type eq "array" )
368
    {                                           # new style
369
        print VERSIONC
370
           "static const char *pkgarray[] = \n" .
371
           "{\n";
372
 
373
        foreach $ver ( @PACKAGEVERS   ) {
374
            print VERSIONC "    \"$ver\",\n";
375
        }
376
 
377
        print VERSIONC
378
           "    0\n",
379
           "};\n\n";
380
 
381
        print VERSIONC
382
           "\nconst char *\n$Prefix"."VersionString(void)\n" .
383
           "{\n".
384
           "    return \"$BUILDNAME\";\n" .
385
           "}\n" .
386
           "\nconst char **\n$Prefix"."PkgStrings(void)\n" .
387
           "{\n".
388
           "    return pkgarray;\n" .
389
           "}\n" .
390
           "\nconst char *\n$Prefix"."GetModuleInfo(void)\n" .
391
           "{\n" .
392
           "    return \"$BUILDNAME_PACKAGE ($BUILDNAME_VERSION.$BUILDNAME_PROJECT) @PACKAGEVERS\";\n" .
393
           "}\n";
394
    }
395
    else
396
    {                                           # old style
397
        print VERSIONC
398
           "\nconst char *\n$Prefix"."VersionString(void)\n" .
399
           "{\n".
400
           "    return \"$BUILDNAME @PACKAGEVERS\";\n" .
401
           "}\n" .
402
           "\nconst char *\n$Prefix"."GetModuleInfo(void)\n" .
403
           "{\n" .
404
           "    return \"$BUILDNAME_PACKAGE ($BUILDNAME_VERSION.$BUILDNAME_PROJECT) @PACKAGEVERS\";\n" .
405
           "}\n";
406
    }
407
    close VERSIONC;
408
 
409
#   src/version.h
410
#..
289 dpurdie 411
    open( VERSIONH, '>', $fname_h ) ||
412
        Error( "cannot create $fname_h" );
227 dpurdie 413
 
414
    print VERSIONH
415
        "#ifndef VERSION_H_INCLUDED\n" .
416
        "#define VERSION_H_INCLUDED\n" .
417
        "/* Please do not edit this file.\n" .
418
        " * It was auto-generated by Buildlib ($BuildVersion) on $::CurrentTime\n" .
419
        " */\n\n" .
420
        "#define BUILDNAME     \"$BUILDNAME\"\n" .
421
        "#define BUILDDATE     \"$::CurrentTime\"\n" .
422
        "\n";
423
 
424
    print VERSIONH
425
        "#ifdef __cplusplus\n" .
426
        "    extern \"C\" {           /* force C calling convention when using C++ */\n" .
427
        "#endif\n" .
428
        "\n";
429
 
430
    if ( $Type eq "array" )
431
    {                                           # extended interface
432
        print VERSIONH
433
        "extern const char **  $Prefix"."PkgStrings(void);\n";
434
    }
435
    print VERSIONH
436
        "extern const char *   $Prefix"."VersionString(void);\n".
437
        "extern const char *   $Prefix"."GetModuleInfo(void);\n";
438
 
439
    print VERSIONH
440
        "\n" .
441
        "#ifdef __cplusplus\n" .
442
        "    } /* extern \"C\" */\n" .
443
        "#endif\n" .
444
        "\n";
445
 
446
    print VERSIONH
447
        "\n#endif /*VERSION_H_INCLUDED*/\n";
448
    close VERSIONH;
449
}
450
 
451
#-------------------------------------------------------------------------------
452
# Function        : BuildVersionCdefs
453
#
454
# Description     : Generate a "C" style version definitions file
455
#                   This file simply contains definitions
456
#
289 dpurdie 457
# Inputs          : $FileName       - Output filename (Optional)
458
#                                     If provided it will be 'known' to all
459
#                                     of jats. Done for backward compatability
460
#                   $Mode           - File suffix
227 dpurdie 461
#                   $ModePrefix     - Tag for all generated definitions
462
#
463
# Returns         :
464
#
465
 
466
sub BuildVersionCdefs
467
{
289 dpurdie 468
    my ( $FileName, $Mode, $ModePrefix ) = @_;
227 dpurdie 469
 
289 dpurdie 470
    my $fname = defined($FileName) ? $FileName : "version_$Mode.h";
471
    $fname = ::BuildAddKnownFile ( $Srcdir, $fname , ! defined($FileName) );
472
    return if ( $Clobber );      # clobber mode ?
473
    Message ("Creating C Version Defs File: $fname" );
227 dpurdie 474
 
475
    #
476
    #   Generate version_defs.h
477
    #   This file contains ONLY definitions. It may be used by assembler
478
    #   programs (that support a preprocessor) to access version information
479
    #
480
    #   Allow for a user supplied filename fragment that will be used within
481
    #   all the definitions with in the file.
482
    #
359 dpurdie 483
    my ($major, $minor, $patch, $build, $raw_patch) = SplitVersionClean($BUILDNAME_VERSION);
227 dpurdie 484
    my @PACKAGEVERS = PackageEntry::GetPackageVersionList();
485
 
486
    #
487
    #   Base names on a user supplied value or a default
488
    #
489
    my $vtag = uc( "VERSION$ModePrefix" );
490
    my $guard_name = uc($fname);
289 dpurdie 491
       $guard_name =~ tr~\.\/\\~_~s;
227 dpurdie 492
 
289 dpurdie 493
    open( VERSIOND, '>', $fname ) ||
494
        Error( "cannot create $fname" );
227 dpurdie 495
 
496
    print VERSIOND
497
        "#ifndef $guard_name\n" .
498
        "#define $guard_name\n" .
499
        "/* Please do not edit this file.\n" .
500
        " * It was auto-generated by Buildlib ($BuildVersion) on $::CurrentTime\n" .
501
        " */\n\n" .
502
        "\n".
503
        "#define ${vtag}_BUILDNAME      \"$BUILDNAME\"\n".
504
        "#define ${vtag}_BUILDDATE      \"$::CurrentTime\"\n".
505
        "\n".
506
        "#define ${vtag}_PACKAGE        \"$BUILDNAME_PACKAGE\"\n".
507
        "#define ${vtag}_VERSION        \"$BUILDNAME_VERSION\"\n".
508
        "#define ${vtag}_MAJOR_STR      \"$major\"\n".
509
        "#define ${vtag}_MINOR_STR      \"$minor\"\n".
510
        "#define ${vtag}_PATCH_STR      \"$patch\"\n".
511
        "#define ${vtag}_BUILD_STR      \"$build\"\n".
512
        "#define ${vtag}_PATCHBUILD_STR \"$raw_patch\"\n".
513
        "#define ${vtag}_PROJECT        \"$BUILDNAME_PROJECT\"\n".
359 dpurdie 514
        "#define ${vtag}_MAJOR          $major\n".
515
        "#define ${vtag}_MINOR          $minor\n".
516
        "#define ${vtag}_PATCH          $patch\n".
517
        "#define ${vtag}_BUILD          $build\n".
518
        "#define ${vtag}_PATCHBUILD     $raw_patch\n".
227 dpurdie 519
        "#define ${vtag}_ALL            \"$BUILDNAME_PACKAGE ($BUILDNAME_VERSION.$BUILDNAME_PROJECT) @PACKAGEVERS\"\n".
520
        "#define ${vtag}_BUILDTIME      " . strip_zeros(time()) . "\n".
521
        "\n".
522
        "#endif /* $guard_name */\n";
523
 
524
    close VERSIOND;
525
}
526
 
527
#-------------------------------------------------------------------------------
229 dpurdie 528
# Function        : BuildVersionProperties
529
#
530
# Description     : Generate a "Java" style version definitions file
531
#                   This is a simple properties file
532
#
533
# Inputs          : $FileName       - Output filename (Optional)
534
#                   $Prefix         - Tag for all generated definitions
535
#
536
# Returns         :
537
#
538
sub BuildVersionProperties
539
{
540
    my ( $fname, $Prefix ) = @_;
541
 
542
    #
543
    #   Default name of the file
544
    #
545
    $fname = 'version.properties' unless $fname;
546
 
547
    #
247 dpurdie 548
    #   Store the files location for use at runtime
549
    #   It will be a file that is 'known' to JATS
550
    #
551
    $fname = ::BuildAddKnownFile ( $Srcdir, $fname );
552
    return if ( $Clobber );      # clobber mode ?
289 dpurdie 553
    Message ("Creating Properties Version File: $fname" );
247 dpurdie 554
 
555
    #
229 dpurdie 556
    #   Generate version properties file
557
    #
558
    #   This file contains ONLY definitions. It may be included by the ANT
559
    #   builds. Its not intended to be imported by the java code
560
 
561
 
562
    #
563
    #   Allow for a user supplied property prefix
564
    #   Not really needed as
565
    #
566
    my $vtag = '';
567
    $vtag = $Prefix . '.' if $Prefix;
568
 
569
 
359 dpurdie 570
    my ($major, $minor, $patch, $build, $raw_patch) = SplitVersionClean($BUILDNAME_VERSION);
229 dpurdie 571
    my @PACKAGEVERS = PackageEntry::GetPackageVersionList();
572
 
573
    #
574
    #   Create properties in the same form as for "C" definitions
575
    #   Note:
576
    #       The 'ALL' is in a format used by other software. Do not change
577
    #
247 dpurdie 578
    open( VERSIOND, ">$fname" ) ||
579
        Error( "cannot create $fname" );
229 dpurdie 580
 
581
    print VERSIOND
582
        "# Please do not edit this file.\n" .
583
        "# It was auto-generated by Buildlib ($BuildVersion) on $::CurrentTime\n" .
584
        "#\n" .
585
        "${vtag}BUILDNAME      = $BUILDNAME\n".
586
        "${vtag}BUILDDATE      = $::CurrentTime\n".
587
        "\n".
588
        "${vtag}PACKAGE        = $BUILDNAME_PACKAGE\n".
589
        "${vtag}VERSION        = $BUILDNAME_VERSION\n".
590
        "${vtag}MAJOR_STR      = $major\n".
591
        "${vtag}MINOR_STR      = $minor\n".
592
        "${vtag}PATCH_STR      = $patch\n".
593
        "${vtag}BUILD_STR      = $build\n".
594
        "${vtag}PATCHBUILD_STR = $raw_patch\n".
595
        "${vtag}PROJECT        = $BUILDNAME_PROJECT\n".
359 dpurdie 596
        "${vtag}MAJOR          = $major\n".
597
        "${vtag}MINOR          = $minor\n".
598
        "${vtag}PATCH          = $patch\n".
599
        "${vtag}BUILD          = $build\n".
600
        "${vtag}PATCHBUILD     = $raw_patch\n".
229 dpurdie 601
        "${vtag}ALL            = $BUILDNAME_PACKAGE ($BUILDNAME_VERSION.$BUILDNAME_PROJECT) @PACKAGEVERS\n".
602
        "${vtag}BUILDTIME      = " . strip_zeros(time()) . "\n".
603
        "\n";
604
    #
605
    #   Create a set of definitions for each dependent package
606
    #
607
    print VERSIOND "# Dependent Packages and Versions\n".
608
                   "#\n";
609
 
610
    foreach my $tag ( PackageEntry::GetPackageList() )
611
    {
612
        my ($name, $version, $type) = PackageEntry::GetPackageData($tag);
613
#        push @attributes, "build=\"true\"" if $type =~ /Build/i;
614
        print VERSIOND "${vtag}PACKAGE.$name=$version\n";
615
    }
616
    close VERSIOND;
617
}
618
 
619
#-------------------------------------------------------------------------------
289 dpurdie 620
# Function        : BuildVersionDelphi
621
#
622
# Description     : Create a pascal file in Delphi format
623
#
624
# Inputs          : $FileName       - Output filename (Optional)
625
#                   $Prefix         - Tag for all generated definitions
626
#
627
#
628
# Returns         : 
629
#
630
sub BuildVersionDelphi
631
{
632
    my ( $fname, $Prefix ) = @_;
633
 
634
    #
635
    #   Default name of the file
636
    #
637
    $fname = 'version_defs.pas' unless $fname;
638
    $fname .= '.pas'
639
        unless ( $fname =~ m~\.~ );
640
    my $unit_name = StripDirExt($fname);
641
    Error ("BuildVersion: Delphi Style. Filename \'$unit_name\. not allowed")
642
        if ( $unit_name =~ m~^version$~i );
643
 
644
    #
645
    #   Store the files location for use at runtime
646
    #   It will be a file that is 'known' to JATS
647
    #
648
    $fname = ::BuildAddKnownFile ( $Srcdir, $fname );
649
    return if ( $Clobber );      # clobber mode ?
650
    Message ("Creating Delpi Version File: $fname" );
651
 
652
    #
653
    #   Generate version source file
654
    #   This file contains ONLY constant definitions.
655
 
656
    #
657
    #   Allow for a user supplied property prefix
658
    #   Not really needed as
659
    #
660
    my $vtag = '';
661
    $vtag = $Prefix . '_' if $Prefix;
662
 
663
 
359 dpurdie 664
    my ($major, $minor, $patch, $build, $raw_patch) = SplitVersionClean($BUILDNAME_VERSION);
289 dpurdie 665
    my @PACKAGEVERS = PackageEntry::GetPackageVersionList();
666
 
667
    #
668
    #   Create properties in the same form as for "C" definitions
669
    #   Note:
670
    #       The 'ALL' is in a format used by other software. Do not change
671
    #
672
    sub pstring
673
    {
674
        my ($arg, $val) = @_;
675
        Error ("Undefined value for $arg") unless ( defined $val );
676
        return sprintf ( "%-24s = \'%s\';" , $arg, $val);
677
    }
678
    sub pnum
679
    {
680
        my ($arg, $val) = @_;
681
        Error ("Undefined value for $arg") unless ( defined $val );
359 dpurdie 682
        return sprintf ( "%-24s = %s;" , $arg, $val );
289 dpurdie 683
    }
684
 
685
    my $fh = ConfigurationFile::New( $fname, '--Type=Delphi' );
686
    $fh->HeaderSimple( "buildlib (Version $BuildVersion)",
687
                       "Delphi Unit Version Definition" );
688
 
689
    $fh->WriteLn(
690
        "unit $unit_name;",
691
        "interface",
692
        "const",
693
        pstring ("${vtag}BUILDNAME",$BUILDNAME),
694
        pstring ("${vtag}BUILDDATE",$::CurrentTime),
695
        '',
696
        pstring ("${vtag}PACKAGE",$BUILDNAME_PACKAGE),
697
        pstring ("${vtag}VERSION",$BUILDNAME_VERSION),
698
        pstring ("${vtag}MAJOR_STR",$major),
699
        pstring ("${vtag}MINOR_STR",$minor),
700
        pstring ("${vtag}PATCH_STR",$patch),
701
        pstring ("${vtag}BUILD_STR",$build),
702
        pstring ("${vtag}PATCHBUILD_STR",$raw_patch),
703
        pstring ("${vtag}PROJECT",$BUILDNAME_PROJECT),
704
        pnum ("${vtag}MAJOR",$major),
705
        pnum ("${vtag}MINOR",$minor),
706
        pnum ("${vtag}PATCH",$patch),
707
        pnum ("${vtag}BUILD",$build),
708
        pnum ("${vtag}PATCHBUILD",$raw_patch),
709
        pstring ("${vtag}ALL","$BUILDNAME_PACKAGE ($BUILDNAME_VERSION.$BUILDNAME_PROJECT) @PACKAGEVERS"),
359 dpurdie 710
        pnum ("${vtag}BUILDTIME",strip_zeros(time())),
289 dpurdie 711
        ''
712
        );
713
 
714
    #
715
    #   Create a set of definitions for each dependent package
716
    #
717
    $fh->Comment("Dependent Packages and Versions\n");
718
    $fh->Comment("\n");
719
 
720
    foreach my $tag ( PackageEntry::GetPackageList() )
721
    {
722
        my ($name, $version, $type) = PackageEntry::GetPackageData($tag);
723
        $fh->WriteLn(pstring ("${vtag}PACKAGE_$name", $version));
724
    }
725
    $fh->WriteLn( '',
726
        "implementation",
727
        "end.");
728
 
729
 
730
    $fh->WriteLn();
731
    $fh->Close();
732
}
733
 
315 dpurdie 734
#-------------------------------------------------------------------------------
735
# Function        : BuildVersionVB
736
#
737
# Description     : Create a VB6 file in Basic format
738
#
739
# Inputs          : $FileName       - Output filename (Optional)
740
#                   $Prefix         - Tag for all generated definitions
741
#
742
#
743
# Returns         : 
744
#
745
sub BuildVersionVB
746
{
747
    my ( $fname, $Prefix ) = @_;
289 dpurdie 748
 
315 dpurdie 749
    #
750
    #   Default name of the file
751
    #
752
    $fname = 'version.bas' unless $fname;
753
    $fname .= '.bas'
754
        unless ( $fname =~ m~\.~ );
755
 
756
    #
757
    #   Store the files location for use at runtime
758
    #   It will be a file that is 'known' to JATS
759
    #
760
    $fname = ::BuildAddKnownFile ( $Srcdir, $fname );
761
    return if ( $Clobber );      # clobber mode ?
762
    Message ("Creating Visual Basic Version File: $fname" );
763
 
764
    #
765
    #   Generate version source file
766
    #   This file contains ONLY constant definitions.
767
 
768
    #
769
    #   Allow for a user supplied property prefix
770
    #   Not really needed as
771
    #
772
    my $vtag = '';
773
    $vtag = $Prefix . '_' if $Prefix;
774
 
775
 
359 dpurdie 776
    my ($major, $minor, $patch, $build, $raw_patch) = SplitVersionClean($BUILDNAME_VERSION);
315 dpurdie 777
    my @PACKAGEVERS = PackageEntry::GetPackageVersionList();
778
 
779
    #
780
    #   Create properties in the same form as for "C" definitions
781
    #   Note:
782
    #       The 'ALL' is in a format used by other software. Do not change
783
    #
784
    sub pvbstring
785
    {
786
        my ($arg, $val) = @_;
787
        Error ("Undefined value for $arg") unless ( defined $val );
788
        return sprintf ( "Public Const %-24s = \"%s\"" , $arg, $val);
789
    }
790
    sub pvbnum
791
    {
792
        my ($arg, $val) = @_;
793
        Error ("Undefined value for $arg") unless ( defined $val );
359 dpurdie 794
        return sprintf ( "Public Const %-24s = %s" , $arg, $val );
315 dpurdie 795
    }
796
 
797
    my $fh = ConfigurationFile::New( $fname, '--Type=Basic' );
798
    $fh->HeaderSimple( "buildlib (Version $BuildVersion)",
799
                       "Visual Basic Version Definition" );
800
 
801
    $fh->WriteLn(
802
        "Attribute VB_Name = \"JatsVersion\"",
803
        '',
804
        pvbstring ("${vtag}BUILDNAME",      $BUILDNAME),
805
        pvbstring ("${vtag}BUILDDATE",      $::CurrentTime),
806
        '',
807
        pvbstring ("${vtag}PACKAGE",        $BUILDNAME_PACKAGE),
808
        pvbstring ("${vtag}VERSION",        $BUILDNAME_VERSION),
809
        pvbstring ("${vtag}MAJOR_STR",      $major),
810
        pvbstring ("${vtag}MINOR_STR",      $minor),
811
        pvbstring ("${vtag}PATCH_STR",      $patch),
812
        pvbstring ("${vtag}BUILD_STR",      $build),
813
        pvbstring ("${vtag}PATCHBUILD_STR", $raw_patch),
814
        pvbstring ("${vtag}PROJECT",        $BUILDNAME_PROJECT),
815
        pvbnum    ("${vtag}MAJOR",          $major),
816
        pvbnum    ("${vtag}MINOR",          $minor),
817
        pvbnum    ("${vtag}PATCH",          $patch),
818
        pvbnum    ("${vtag}BUILD",          $build),
819
        pvbnum    ("${vtag}PATCHBUILD",     $raw_patch),
820
        pvbstring ("${vtag}ALL",            "$BUILDNAME_PACKAGE ($BUILDNAME_VERSION.$BUILDNAME_PROJECT) @PACKAGEVERS"),
359 dpurdie 821
        pvbnum    ("${vtag}BUILDTIME",      strip_zeros(time())),
315 dpurdie 822
        ''
823
        );
824
 
825
    #
826
    #   Create a set of definitions for each dependent package
827
    #
828
    $fh->Comment("Dependent Packages and Versions\n");
829
    $fh->Comment("\n");
830
 
831
    foreach my $tag ( PackageEntry::GetPackageList() )
832
    {
833
        my ($name, $version, $type) = PackageEntry::GetPackageData($tag);
363 dpurdie 834
        $fh->WriteLn(pvbstring ("${vtag}PACKAGE_$name", $version));
315 dpurdie 835
    }
836
 
837
    $fh->WriteLn();
838
    $fh->Close();
839
}
840
 
359 dpurdie 841
#-------------------------------------------------------------------------------
842
# Function        : SplitVersionClean
843
#
844
# Description     : Pull apart the Version Number and clean it up
845
#                   Remove leading zeros from components
846
#
847
# Inputs          : $version    - Version Number
848
#
849
# Returns         : A list of:
850
#                       Major, Minor, Patch, Build, RawPatch
851
#                   with leading zeros removed
852
#
853
sub SplitVersionClean
854
{
855
    my ($version) = @_;
856
    my ($major, $minor, $patch, $build, $raw_patch) = SplitVersion($version);
315 dpurdie 857
 
359 dpurdie 858
    return (
859
        strip_zeros($major),
860
        strip_zeros($minor),
861
        strip_zeros($patch),
862
        strip_zeros($build),
863
        strip_zeros($raw_patch)
864
    );
865
}
866
 
289 dpurdie 867
#-------------------------------------------------------------------------------
227 dpurdie 868
# Function        : stip_zeros
869
#
870
# Description     : Remove leading 0's from a string
871
#
872
# Inputs          : A string
873
#
874
# Returns         : A string without leading zeros
875
#
876
sub strip_zeros
877
{
878
    my ($text) = @_;
879
 
880
    $text =~ s~^0*~~;
881
    $text = '0' unless ( $text );
882
    return $text;
883
}
884
 
885
1;