Subversion Repositories DevTools

Rev

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

########################################################################
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
#
# Module name   : jats.sh
# Module type   : Makefile system
# Compiler(s)   : n/a
# Environment(s): jats
#
# Description   : This package extends the JATS toolset at build time
#                 It provides additional directives to the JATS makefiles
#                 to simplify the directives.
#
#                 The directive matches up with a run-time tool to
#                 do the bulk of the work.
#
# Operation     : This package adds the JATS directive MakeDebianPackage
#                 When used the directive will use GenerateFiles to invoke
#                 a script (DebianPackager.pl) to actually do the hard work.
#
# Syntax        : MakeDebianPackage (<platforms>, Options+);
#                 Where Options may be one of:
#                   --Script=PackagerScript             - Mandatory. Name of a the packaging script
#                   --Name=Name                         - Debian Package name(optional)
#                   --Variant=Text                      - Package Variant(optional)
#                   --DeployMode                        - Create Deployable packages(optional)
#                                                         Default for native targets
#                                                         These are:
#                                                           * Packaged into the root of target pkg
#                                                           * Have P or D in the name
#                   --NoDeployMode                      - Create packages that cannot be directly deployed
#                                                         Default for embedded devices
#                   --TarFile[=TemplateName]            - Create named .tgz file, of the data area [not Debian scripts]
#                   --TarFile                           - Same as --TarFile=PACKAGE_VERSION_PLATFORM_TYPE or PACKAGE_VERSION_PLATFORM
#                   --NoArch                            - Marks the package as having no specific architecture
#                   
#
#               Templates may contain:
#                   PACKAGE
#                   VARIANT
#                   VERSION
#                   PLATFORM
#                   TYPE
#                       
#......................................................................#

require 5.006_001;
#use strict;
use warnings;

#-------------------------------------------------------------------------------
# Function        : MakeDebianPackage
#
# Description     : Create a Debian Package
#
# Inputs          : See above
#
# Returns         : Nothing 
#
sub MakeDebianPackage
{
    my( $platforms, @elements ) = @_;
    Debug2( "MakeDebianPackage($platforms, @elements)" );
    return if ( ! ActivePlatform($platforms) );

    my $build_name =  $::ScmBuildPackage;
    my $build_version = $::ScmBuildVersionFull;
    my $build_variant = '';

    my $script_set=0;
    my $name_set=0;
    my $variant_set=0;
    my $deploy_mode = GetGlobalOption('DEBIAN_PACKAGE_DEPLOYABLE', 0);

    my $tarFileName = '';
    my @outputFiles;
    my @optArgs;
    my $noArch;

    #
    #   Take the project name and convert it into a full path
    #
    my $script;

    #
    #   Collect user arguments
    #   They are all processed within the toolset
    #
    foreach ( @elements )
    {
        if ( m/^--Script=(.+)/i ) {
            $script = $1;
            $script_set++;

        } elsif ( m/^--Name=(.+)/i ) {
            $build_name = $1;
            $name_set++;

        } elsif ( m/^--Variant=(.+)/i ) {
            $build_variant = $1;
            $variant_set++;

        } elsif ( m/^--(No)?DeployMode/i ) {
            $deploy_mode = ! defined($1);

        } elsif ( m/^--NoArch$/i ) {
            $noArch = 1;

        } elsif ( m/^--TarFile(=(.*))?/i ) {
            $tarFileName = defined($1) ? $2 : 'DEFAULT';
            
        } elsif ( m/^--/ ) {
            Error("MakeDebianPackage. Unknown option: $_");

        } else {
            Error("MakeDebianPackage. Unknown argument: $_");
        }
    }

    #
    #   Sanity test
    #
    Error ("MakeDebianPackage: Not supported on a GENERIC target") if ( $ScmPlatform eq 'GENERIC' );
    Error ("MakeDebianPackage: Script name not defined") unless ( $script );
    Error ("MakeDebianPackage: --Script option can only be used once") if ( $script_set > 1 );
    Error ("MakeDebianPackage: --Name option can only be used once") if ( $name_set > 1 );
    Error ("MakeDebianPackage: --Variant option can only be used once") if ( $variant_set > 1 );

    #
    #   Build up the build name
    #       Add variant to base name.
    #
    if ( $build_variant )
    {
        $build_name .= '-' . $build_variant;
    }

    #
    #   Sanity check the package name and version
    #   Debian has stricter requirements than JATS
    #       Name:    Lower case letters (a-z), digits (0-9), plus (+) and minus (-) signs, and periods (.).
    #                Release Manager does not allow '.'
    #       Version: alphanumerics and the characters . + - : (full stop, plus, hyphen, colon) and should start with a digit
    #
    #   Allow ( and cleanup )
    #       ERGxxxxx    -> erg-xxx
    #       VIXxxxxx    -> vix-xxx
    #       Whitespace   -> -
    #       _           -> -
    #       Remove multiple '-' characters
    #       Lowercase all text
    #
    my $cvt = 0;
    $cvt = 1 if ( $build_name =~ s/^ERG/erg-/ );
    $cvt = 2 if ( $build_name =~ s/^VIX/vix-/ );
    $cvt = 3 if ( $build_name =~ s~\s~-~g );
    $cvt = 4 if ( $build_name =~ s~_~-~g );
    $cvt = 5 if ( $build_name =~ s~--+~-~g );
    if ( $build_name =~ m/[A-Z]/ )
    {
        $cvt = 6;
        $build_name = lc $build_name;
    }

    Warning ("Package Name converted to debian friendly form: $build_name")
        if ( $cvt );

    unless ( $build_name =~ m/^[a-z][-+a-z0-9]+$/ )
    {
        Error ("Package Name does not conform to Debian Requirements",
               "Must be at least two characters long",
               "Must start with an alphabetic character",
               "Must only contain: (a-z) (0-9) and -",
               "Provided Name: $::ScmBuildPackage",
               "Massaged: $build_name");
    }

    unless ( $::ScmBuildVersionFull =~ m/^[0-9][-+:.A-Za-z0-9]+$/ )
    {
        Error ("Package Version does not conform to Debian Requirements",
               "Must only contain: (a-zA-Z) (0-9), - and .",
               "Must start with a number",
               );
    }

    #
    #   Create the name of the target package
    #   The form of the name is of a fixed form.
    #
    #   Note: "_" used since this is the format of dpkg-name
    #   Note: dpkg-name generates: Name _ Version _ Architecture [ _ Type ]
    #
    #
    my $PkgType = $deploy_mode ? ( '_' . '$(GBE_TYPE)' ) : '' ;
    my $PkgArch = GetGlobalOption('PACKAGE_ARCH', $::ScmPlatform);
        if ($noArch)
        {
            $PkgArch = 'all';
            $PkgType = '';
            push @optArgs, "-NoArch";
        }
    my $PkgName = "${build_name}_${::ScmBuildVersionFull}_${PkgArch}${PkgType}.deb";
    push @outputFiles,  $PkgName;
    push @optArgs, "-PkgArch=$PkgArch";

    #
    #   Create name for the optional TGZ file
    #       Allow user to specify parts of the name symbolically
    #
    if ($tarFileName)
    {
        if ($tarFileName eq 'DEFAULT')
        {
            $tarFileName = 'PACKAGE_VERSION_PLATFORM';
            if ($deploy_mode && ! $noArch)
            {
                $tarFileName .= '_TYPE';
            }
        }

        if ($noArch) {
            $PkgArch = 'all';
        }

        $tarFileName =~ s~PACKAGE~${build_name}~g;
        $tarFileName =~ s~VERSION~${::ScmBuildVersionFull}~g;
        $tarFileName =~ s~PLATFORM~${PkgArch}~g;
        $tarFileName =~ s~TYPE~\$(GBE_TYPE)~;
        $tarFileName .= '.tgz' unless $tarFileName =~ m~\.tgz$~;
        push @outputFiles,  $tarFileName;

        #push @optArgs, "-TarFile=--GeneratedProg{$tarFileName}";
        push @optArgs, "-TarFile=$tarFileName";
    }

    #
    #   Simply use Generate Files
    #       With lots of options
    #
    Src ( '*', $script );
    GenerateFiles ('*', "--Tool=DebianPackager.pl",               # Associated tool
                        "--AutoGenerate",                         # Build when needed
                        "--UnknownPreq",                          # Always build
                        "--Clean",                                # Script supports jats clean
                        "--Text=Debian Package",                  # Display when building
                        
                        '--Var(BuildName)',                       # Target Package
                        '--Var(BuildVersion)',                    # Target Version
                        '--Var(Platform)',                        # Target platform
                        '--Var(Product)',                         # Target product
                        '--Var(Target)',                          # Underlying Target
                        '--Var(Type)',                            # Build Type

                        '--Var(Verbose)',                         # Verbose operation

                        '--Var(InterfaceDir)',                    # Interface Directory
                        '--Var(InterfaceIncDir)',
                        '--Var(InterfaceLibDir)',
                        '--Var(InterfaceBinDir)',

                        '--Var(LibDir)',                          # My Artifacts
                        '--Var(BinDir)',

                        '--Var(PackageDir)',                      # My Package
                        '--Var(PackageLibDir)',                   # My Package Library
                        '--Var(PackageBinDir)',                   # My Package Bin
                        '--Var(PackagePkgDir)',                   # My Package/pkg.target

                        '--Var(LocalIncDir)',                     # Installed Artifacts
                        '--Var(LocalLibDir)',
                        '--Var(LocalBinDir)',

                        "-genDeb",                                # Type to generate
                        "-Script=--Prerequisite($script)",        # Packager script
                        "-Name=$build_name",                      # Massaged Package Name
                        "-Variant=$build_variant",                # Variant Name
                        "-Output=--GeneratedProg{$PkgName}",      # Specify output file
                        @optArgs,                                 # Optional args
                        );

    #
    #   The Packager has created a binary in the 'PROG' directory
    #   Lets package it as a program.
    #
    if ($deploy_mode) {
        PackageFile ('*', @outputFiles );
    }
    else {
        PackageProg ('*', @outputFiles );
    }
}

1;