Subversion Repositories DevTools

Rev

Rev 3839 | Blame | Compare with Previous | Last modification | View Log | RSS feed

########################################################################
# Copyright (C) 1998-2013 Vix Technology, All rights reserved
#
# Module name   : MakePax.pl
# Module type   : Makefile system
# Compiler(s)   : Perl
# Environment(s): jats
#
# Description   : Build Wrpper for the MakePax directive
#                 This script is invoked at 'make' time
#                 A perl script is used to provide a little bit of flexability
#
# Usage:        : Invoked by JAT make system
#
#......................................................................#

require 5.008_002;
use strict;
use warnings;

use Pod::Usage;
use Getopt::Long;
use File::Path;

use JatsError;
use JatsSystem;
use FileUtils;

#
#   Globals
#

#
#   Command line options
#
my $opt_debug   = $ENV{'GBE_DEBUG'};        # Allow global debug
my $opt_verbose = $ENV{'GBE_VERBOSE'};      # Allow global verbose
my $opt_vargs;                              # Verbose arg
my $opt_help = 0;
my $opt_manual = 0;
my $opt_clean = 0;
my $opt_platform;
my $opt_buildname;
my $opt_buildversion;
my $opt_interfacedir;
my $opt_pkgdir;
my $opt_component;
my $opt_src;

#-------------------------------------------------------------------------------
# Function        : Main Entry point
#
# Description     : This function will be called when the package is initialised
#                   Extract arguments from the users environment
#
#                   Done here to greatly simplify the user script
#                   There should be no junk in the user script - keep it simple
#
# Inputs          :
#
# Returns         : 
#
main();

sub main
{
    my $dist_tree;
    my @make_args;

    my $result = GetOptions (
                "verbose:s"         => \$opt_vargs,
                "clean"             => \$opt_clean,
                "BuildName=s"       => \$opt_buildname,
                "BuildVersion=s"    => \$opt_buildversion,
                "Platform=s"        => \$opt_platform,
                "InterfaceDir=s"    => \$opt_interfacedir,
                "PackageDir=s"      => \$opt_pkgdir,
                "Component=s"       => \$opt_component,
                "Src=s"             => \$opt_src,
    );

    ErrorConfig( 'name'    => 'MakePax',
                 'verbose' => $opt_verbose,
                 'debug'   => $opt_debug );

    #
    #   Init the FileSystem Uiltity interface
    #
    InitFileUtils();

    #
    #   Ensure that we have all required options
    #
    Error ("BuildName not set")                 unless ( $opt_buildname );
    Error ("BuildVersion not set")              unless ( $opt_buildversion );
    Error ("InterfaceDir not set")              unless ( $opt_interfacedir );
    Error ("Package Dir not set")               unless ( $opt_pkgdir );
    Error ("Component not set")                 unless ( $opt_component );
    Error ("Source not set")                    unless ( $opt_src );

    #
    #   A few sanity checks
    #
    Error ("Cannot find 'intellect.bat'. This file was generated by JATS")
        unless ( -f 'intellect.bat' );


    Error ("Source does not contain a 'makefile'", 'Src:' . $opt_src)
        unless ( -f join('/', $opt_src, 'makefile') );

    #
    #   Define some global values
    #
    push @make_args, '-c', $opt_src;
    push @make_args, "-DDIST_PLATFORM=$opt_platform" if ( $opt_platform );
    push @make_args, '-DMAKE_VERBOSE=1' if $opt_vargs;

    $dist_tree = FullPath(join('/', $opt_pkgdir, 'pkg', $opt_component));

    #
    #   Clean package
    #
    if ( $opt_clean )
    {
        Message ("Clean Pax Build");
        runMake( @make_args, 'very_clean' );
        exit 0;
    }


    #
    #   Build Package
    #       Remove packageing output
    #       Make install - in tree
    #       Make install - - for packaging
    #
    RmDirTree($dist_tree);
    mkpath($dist_tree, 0, 0775);
    Message ("Build Software");
    runMake( @make_args, 'install' );

    Message ("Package Software");
    runMake( @make_args, '-DDIST_TREE=' . $dist_tree, 'install' );
}

#-------------------------------------------------------------------------------
# Function        : runMake
#
# Description     : Run the PAX Builder Make command in the PAX Builder
#                   environment - as setup by intellect.bat
#
# Inputs          : Array of make arguments
#
# Returns         : Will not return on error
#
sub runMake
{
    my (@args) = @_;
    System ('--Exit','--NoShell','intellect.bat', 'make', @args );
}