Subversion Repositories DevTools

Rev

Rev 283 | Rev 315 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 283 Rev 289
Line 36... Line 36...
36
package BuildVersion;
36
package BuildVersion;
37
use JatsError;
37
use JatsError;
38
use JatsSystem;
38
use JatsSystem;
39
use JatsVersionUtils;
39
use JatsVersionUtils;
40
use ConfigurationFile;
40
use ConfigurationFile;
-
 
41
use FileUtils;
41
 
42
 
42
#
43
#
43
#   Package Interface
44
#   Package Interface
44
#
45
#
45
use base qw(Exporter);
46
use base qw(Exporter);
46
our @EXPORT = qw( BuildVersionC
47
our @EXPORT = qw( BuildVersionC
47
              BuildVersionCdefs
48
              BuildVersionCdefs
48
              BuildVersionCSharp
49
              BuildVersionCSharp
49
              BuildVersionWinRC
50
              BuildVersionWinRC
50
              BuildVersionProperties
51
              BuildVersionProperties
-
 
52
              BuildVersionDelphi
51
            );
53
            );
52
 
54
 
53
#-------------------------------------------------------------------------------
55
#-------------------------------------------------------------------------------
54
# Function        : BuildVersionCSharp
56
# Function        : BuildVersionCSharp
55
#
57
#
Line 69... Line 71...
69
    #   Store the files location for use at runtime
71
    #   Store the files location for use at runtime
70
    #   It will be a file that is 'known' to JATS
72
    #   It will be a file that is 'known' to JATS
71
    #
73
    #
72
    $fname = ::BuildAddKnownFile ( $Srcdir, $fname );
74
    $fname = ::BuildAddKnownFile ( $Srcdir, $fname );
73
    return if ( $Clobber );      # clobber mode ?
75
    return if ( $Clobber );      # clobber mode ?
-
 
76
    Message ("Creating C# Version File: $fname" );
74
 
77
 
75
    #
78
    #
76
    #   Determine the build version
79
    #   Determine the build version
77
    #
80
    #
78
    my ($major, $minor, $patch, $build, $raw_patch) = SplitVersion($BUILDNAME_VERSION);
81
    my ($major, $minor, $patch, $build, $raw_patch) = SplitVersion($BUILDNAME_VERSION);
Line 299... Line 302...
299
#-------------------------------------------------------------------------------
302
#-------------------------------------------------------------------------------
300
# Function        : BuildVersionC
303
# Function        : BuildVersionC
301
#
304
#
302
# Description     : Create a "C" style version.c and version.h file
305
# Description     : Create a "C" style version.c and version.h file
303
#
306
#
-
 
307
# Inputs          : $FileName       - Output filename (Optional)
-
 
308
#                                     If provided it will be 'known' to all
-
 
309
#                                     of jats. Done for backward compatability
304
# Inputs          : $Prefix         - Text to prefix generated variables with
310
#                   $Prefix         - Text to prefix generated variables with
305
#                                     Used to avoid namespace conflicts
311
#                                     Used to avoid namespace conflicts
306
#                   $Type           - Type of version to create
312
#                   $Type           - Type of version to create
307
#                                     Only allowed value is 'array'
313
#                                     Only allowed value is 'array'
308
#
314
#
309
# Returns         :
315
# Returns         :
310
#
316
#
311
 
317
 
312
sub BuildVersionC
318
sub BuildVersionC
313
{
319
{
314
    my( $Prefix, $Type ) = @_;
320
    my( $FileName, $Prefix, $Type ) = @_;
315
    my $ver;
321
    my $ver;
316
 
322
 
317
    if ( $Clobber )                             # clobber mode ?
-
 
318
    {
323
    #
319
        #
324
    #   Default name of the file
320
        #   Clobber common version.c and version.h
325
    #   Don't allow the user to play with the extension
-
 
326
    #   If the user provided a filename It will be a file that is 'known' to JATS
321
        #
327
    #   
-
 
328
    my $bname = defined($FileName) ? StripExt($FileName) : 'version';
-
 
329
 
322
        System( "$::GBE_BIN/rm -f $Srcdir/version.c $Srcdir/version.h" );
330
    my $fname_c = ::BuildAddKnownFile ( $Srcdir, $bname . '.c', !defined($FileName) );
323
        return;
331
    my $fname_h = ::BuildAddKnownFile ( $Srcdir, $bname . '.h', !defined($FileName) );
324
    }
332
 
-
 
333
    return if ( $Clobber );      # clobber mode ?
-
 
334
    Message ("Creating C Version File: $fname_c" );
325
 
335
 
326
    #
336
    #
327
    #   Default prefix is none
337
    #   Default prefix is none
328
    #   Set to a defined, bet empty, string
338
    #   Set to a defined, bet empty, string
329
    #
339
    #
330
    $Prefix = "" if ( ! defined( $Prefix ) );
340
    $Prefix = "" if ( ! defined( $Prefix ) );
331
    $Type   = "" if ( ! defined( $Type ) );
341
    $Type   = "" if ( ! defined( $Type ) );
332
 
342
 
333
    #   src/version.c
343
    #   src/version.c
334
    #..
344
    #..
335
    open( VERSIONC, ">$Srcdir/version.c" ) ||
345
    open( VERSIONC, '>', $fname_c ) ||
336
        Error( "cannot create $Srcdir/version.c" );
346
        Error( "cannot create $fname_c" );
337
 
347
 
338
    print VERSIONC
348
    print VERSIONC
339
        "/* Please do not edit this file.\n" .
349
        "/* Please do not edit this file.\n" .
340
        " * It was auto-generated by Buildlib ($BuildVersion) on $::CurrentTime\n" .
350
        " * It was auto-generated by Buildlib ($BuildVersion) on $::CurrentTime\n" .
341
        " */\n" .
351
        " */\n" .
Line 390... Line 400...
390
    }
400
    }
391
    close VERSIONC;
401
    close VERSIONC;
392
 
402
 
393
#   src/version.h
403
#   src/version.h
394
#..
404
#..
395
    open( VERSIONH, ">$Srcdir/version.h" ) ||
405
    open( VERSIONH, '>', $fname_h ) ||
396
        Error( "cannot create $Srcdir/version.h" );
406
        Error( "cannot create $fname_h" );
397
 
407
 
398
    print VERSIONH
408
    print VERSIONH
399
        "#ifndef VERSION_H_INCLUDED\n" .
409
        "#ifndef VERSION_H_INCLUDED\n" .
400
        "#define VERSION_H_INCLUDED\n" .
410
        "#define VERSION_H_INCLUDED\n" .
401
        "/* Please do not edit this file.\n" .
411
        "/* Please do not edit this file.\n" .
Line 436... Line 446...
436
# Function        : BuildVersionCdefs
446
# Function        : BuildVersionCdefs
437
#
447
#
438
# Description     : Generate a "C" style version definitions file
448
# Description     : Generate a "C" style version definitions file
439
#                   This file simply contains definitions
449
#                   This file simply contains definitions
440
#
450
#
-
 
451
# Inputs          : $FileName       - Output filename (Optional)
-
 
452
#                                     If provided it will be 'known' to all
-
 
453
#                                     of jats. Done for backward compatability
441
# Inputs          : $Mode           - File suffix
454
#                   $Mode           - File suffix
442
#                   $ModePrefix     - Tag for all generated definitions
455
#                   $ModePrefix     - Tag for all generated definitions
443
#
456
#
444
# Returns         :
457
# Returns         :
445
#
458
#
446
 
459
 
447
sub BuildVersionCdefs
460
sub BuildVersionCdefs
448
{
461
{
449
    my ( $Mode, $ModePrefix ) = @_;
462
    my ( $FileName, $Mode, $ModePrefix ) = @_;
450
    my $fname = "version_$Mode.h";
-
 
451
 
463
 
452
    if ( $Clobber )                             # clobber mode ?
464
    my $fname = defined($FileName) ? $FileName : "version_$Mode.h";
453
    {
-
 
-
 
465
    $fname = ::BuildAddKnownFile ( $Srcdir, $fname , ! defined($FileName) );
454
        System( "$::GBE_BIN/rm -f $Srcdir/$fname" );
466
    return if ( $Clobber );      # clobber mode ?
455
        return;
467
    Message ("Creating C Version Defs File: $fname" );
456
    }
-
 
457
 
468
 
458
    #
469
    #
459
    #   Generate version_defs.h
470
    #   Generate version_defs.h
460
    #   This file contains ONLY definitions. It may be used by assembler
471
    #   This file contains ONLY definitions. It may be used by assembler
461
    #   programs (that support a preprocessor) to access version information
472
    #   programs (that support a preprocessor) to access version information
Line 469... Line 480...
469
    #
480
    #
470
    #   Base names on a user supplied value or a default
481
    #   Base names on a user supplied value or a default
471
    #
482
    #
472
    my $vtag = uc( "VERSION$ModePrefix" );
483
    my $vtag = uc( "VERSION$ModePrefix" );
473
    my $guard_name = uc($fname);
484
    my $guard_name = uc($fname);
474
       $guard_name =~ s~\.~_~g;
485
       $guard_name =~ tr~\.\/\\~_~s;
475
 
486
 
476
    open( VERSIOND, ">$Srcdir/$fname" ) ||
487
    open( VERSIOND, '>', $fname ) ||
477
        Error( "cannot create $Srcdir/$fname" );
488
        Error( "cannot create $fname" );
478
 
489
 
479
    print VERSIOND
490
    print VERSIOND
480
        "#ifndef $guard_name\n" .
491
        "#ifndef $guard_name\n" .
481
        "#define $guard_name\n" .
492
        "#define $guard_name\n" .
482
        "/* Please do not edit this file.\n" .
493
        "/* Please do not edit this file.\n" .
Line 531... Line 542...
531
    #   Store the files location for use at runtime
542
    #   Store the files location for use at runtime
532
    #   It will be a file that is 'known' to JATS
543
    #   It will be a file that is 'known' to JATS
533
    #
544
    #
534
    $fname = ::BuildAddKnownFile ( $Srcdir, $fname );
545
    $fname = ::BuildAddKnownFile ( $Srcdir, $fname );
535
    return if ( $Clobber );      # clobber mode ?
546
    return if ( $Clobber );      # clobber mode ?
-
 
547
    Message ("Creating Properties Version File: $fname" );
536
 
548
 
537
    #
549
    #
538
    #   Generate version properties file
550
    #   Generate version properties file
539
    #
551
    #
540
    #   This file contains ONLY definitions. It may be included by the ANT
552
    #   This file contains ONLY definitions. It may be included by the ANT
Line 597... Line 609...
597
    }
609
    }
598
    close VERSIOND;
610
    close VERSIOND;
599
}
611
}
600
 
612
 
601
#-------------------------------------------------------------------------------
613
#-------------------------------------------------------------------------------
-
 
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
 
-
 
658
    my ($major, $minor, $patch, $build, $raw_patch) = SplitVersion($BUILDNAME_VERSION);
-
 
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 );
-
 
676
        return sprintf ( "%-24s = %s;" , $arg, strip_zeros($val) );
-
 
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"),
-
 
704
        pnum ("${vtag}BUILDTIME",time()),
-
 
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
 
-
 
728
 
-
 
729
#-------------------------------------------------------------------------------
602
# Function        : stip_zeros
730
# Function        : stip_zeros
603
#
731
#
604
# Description     : Remove leading 0's from a string
732
# Description     : Remove leading 0's from a string
605
#
733
#
606
# Inputs          : A string
734
# Inputs          : A string