Subversion Repositories DevTools

Rev

Rev 229 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#! perl
########################################################################
# Copyright (C) 2004 ERG Limited, All rights reserved
#
# Module name   : jats.sh
# Module type   : Makefile system
# Compiler(s)   : n/a
# Environment(s): jats
#
# Description:
#
# Usage:
#
# Version   Who      Date        Description
#     1.0   DDP      08-Sep-04   Created
#......................................................................#

require 5.6.1;
use strict;
use warnings;
use Cwd;
use Getopt::Long;

my $opt_help;
my $version;

#
#   Parse the user options
#
my $result = GetOptions (
                "help+"         => \$opt_help,
                );
help() if ( !$result || $opt_help );
help ("Expecting one command line argument" )
    if ( $#ARGV != 0);

$version = $ARGV[0];
$version =~ s~^JATS_~~;
help ("Bad format for package version. Need nn.nn.nn" )
    unless ( $version =~ m~^(\d+\.\d+\.\d+)$~ );

#
#   Ensure that the jats.pl file has the correct version information
#   The version number in this file is important as it is published as
#   the JATS version number
#
my $line = qx(grep \"my.*\$GBE_VERSION\" ../TOOLS/jats.pl);
Error ('Cannot locate GBE_VERSION in jats.pl' ) unless ( $line );

$line =~ s~['"](.*).cr['"]~~;
$line = $1;
Error ("GBE_VERSION definition in jats.pl Does not match released version.",
        "Expecting: $version",
        "Got      : $line") unless( $line eq $version );

#
#   Remove any existing package directory
#
if ( -d "./pkg" )
{
    print "Removing existing package image\n";
    system ("rm -rf ./pkg");
}

print "Create package image\n";
mkdir  ("./pkg");
mkdir  ("./pkg/core_devl");

#
#   Create a new format descpkg file
#
my $pkgfile = "./pkg/core_devl/descpkg";
my $BUILDNAME_PACKAGE = "core_devl";
my $BUILDNAME_VERSION = $version;
my $BUILDNAME_PROJECT= "cr",
my $CurrentTime = localtime;
my $USER = $ENV{'USER'};
my $Cwd = getcwd();


open( DESCPKG, ">$pkgfile" ) ||
    Error( "cannot create $pkgfile" );

print DESCPKG "Package Name: $BUILDNAME_PACKAGE\n";
print DESCPKG "Version:      $BUILDNAME_VERSION.$BUILDNAME_PROJECT\n";
print DESCPKG "Released By:  $USER\n";
print DESCPKG "Released On:  $CurrentTime\n";
print DESCPKG "Path:         $Cwd\n";
print DESCPKG "\n";
print DESCPKG "Build Dependencies:\n";
print DESCPKG "\n";
close DESCPKG;

for my $dir (glob ('../BIN.*' ))
{
    print "Copy in: $dir\n";
    system ("cp -r $dir ./pkg/core_devl")
}

for my $dir qw(CFG TEMPLATES TOOLS)
{
    print "Copy in: $dir\n";
    system ("cp -r ../$dir ./pkg/core_devl")
}

for my $dir qw(TOOLS/LOCAL)
{
    print "Remove in: $dir\n";
    system ("rm -rf ./pkg/core_devl/$dir")
}

for my $file qw(Readme.txt PostInstall.sh ChangeLog.txt)
{
    print "Copy in: $file\n";
    system ("cp -r ../$file ./pkg/core_devl")
}

#
#   Update version info in some files
#
foreach my $file qw( TOOLS/jats.sh TOOLS/jats.bat )
{
    print "Insert version into: $file\n";
    system "sed -i -e 's~VERSION_TAG~${version}.cr~' ./pkg/core_devl/$file";
    if ( $? )
    {
        Error("Failure in SED command. Result: $?");
    }
}

system ( "jats.bat -here create_dpkg" );

print "Removing existing package image\n";
system ("rm -rf ./pkg");
exit 0;

########################################################################
#
#   Give the user a clue
#
sub help
{
    if ( $#_ >= 0 )
    {
        print STDERR    '-' x 80 . "\n";
        print STDERR    "ERROR: @_\n";
        print STDERR    '-' x 80 . "\n\n";
    }

    print STDERR    "Package JATS ready for release\n";
    print STDERR    "\n";
    print STDERR    "Usage: perl MakePackage nn.nn.nn\n";
    print STDERR    "\n";
    print STDERR    "Where opts:\n";
    print STDERR    "   -h              - Help message\n";
    print STDERR    "\n";
    print STDERR    "Where arguments:\n";
    print STDERR    "   nn.nn.nn        - The version of the release\n";
    print STDERR    "                     This should be based on the \n";
    print STDERR    "                     label applied to the package\n";
    print STDERR    "\n";
    exit 1;
}

#-------------------------------------------------------------------------------
# Function        : Message
#                   Warning
#                   Error
#                   _Message ( Internal use only )
#
# Description     : Error, Warning and Message routines
#                   These routines will display a message to the user
#                   with the module name.
#
#                   Multiple arguments are displayed on their own line
#                   with suitable spacing.
#
# Inputs          : Lines of text to display
#
# Returns         : Error() does not return
#
sub _Message
{
    my $tag = shift;                # First argument is a tag

    my $prefix = "";
    my $count = 0;

    #
    #   Generate the message prefix
    #   This will only be used on the first line
    #   All other lines will have a space filled prefix
    #
    $prefix .= $tag;

    foreach my $nextline ( @_ )
    {
        chomp( my $line = $nextline );
        $prefix = ' ' x length($prefix)
            if ( $count eq 1 );

        print "$prefix $line\n";
        $count++;
    }
}

sub Error
{
    _Message '(E)', @_;
    exit 1;
}