Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 dpurdie 1
#! perl
2
########################################################################
315 dpurdie 3
# Copyright (C) 1998-2010 ERG Limited, All rights reserved
227 dpurdie 4
#
5
# Module name   : jats.sh
6
# Module type   : Makefile system
7
# Compiler(s)   : n/a
8
# Environment(s): jats
9
#
10
# Description:
11
#       This is a wrapper script to simplify access to the jats
12
#       build system
13
#
14
# Usage:        jats build | make | install | help | ...
15
#
229 dpurdie 16
# Package: PACKAGE_TAG
17
# Version: VERSION_TAG
227 dpurdie 18
#......................................................................#
19
 
261 dpurdie 20
require 5.008_002;
227 dpurdie 21
use strict;
22
use warnings;
23
 
24
use Cwd;
25
use File::Copy;
26
use Getopt::Long qw(:config require_order);     # Stop on non-option
27
use FindBin;                                    # Determine the current directory
28
use lib "$FindBin::Bin/LIB";                    # Allow JATS libraries
29
use Config;
30
use Sys::Hostname;                              # For hostname
31
 
315 dpurdie 32
use Pod::Usage;                                 # For help support
227 dpurdie 33
use JatsError;                                  # Common error reporting
34
use DescPkg;                                    # Package Descriptor processing
35
use JatsSystem;                                 # System call interface
245 dpurdie 36
use JatsBuildFiles;                             # Parse Build Files
227 dpurdie 37
 
229 dpurdie 38
my $GBE_VERSION = "VERSION_TAG";                # Will be re-written when released
245 dpurdie 39
my $GBE_NOT_RELEASED = "RELEASE_TAG";           # Will be re-written when released
227 dpurdie 40
my $opr_done;
41
my $opt_here = 0;
42
my $BUILD_FILE      = "build.pl";
43
my @BUILD_FILE_ALT  = qw(auto.pl build_test.pl);
44
my $BUILD_FILE_SET;
45
my $RESULT = 0;
46
my $PSPLIT = ':';                               # Win/Unix path splitter
47
my $TIMER = time;
48
my $opt_time = 0;
49
my $opt_help = 0;
50
my $opt_locate = 0;
51
my $opt_locate_file;
245 dpurdie 52
my $opt_locate_package;
227 dpurdie 53
my $opt_dir;
54
my $opt_java;
277 dpurdie 55
my $opt_export_vars = 1;
227 dpurdie 56
my $result;
57
 
58
#
59
#   Grab a copy of ALL the environment variable that will be used
60
#   This will simplify the script a great deal
61
#
62
 
279 dpurdie 63
our $GBE_JATS_VERSION   = $ENV{'GBE_JATS_VERSION'}   || '';
227 dpurdie 64
our $GBE_JATS_SANE      = $ENV{'GBE_JATS_SANE'}      || 0;
279 dpurdie 65
our $GBE_CORE           = $ENV{'GBE_CORE'}           || '';
66
our $GBE_BIN            = $ENV{'GBE_BIN'}            || '';
67
our $GBE_CONFIG         = $ENV{'GBE_CONFIG'}         || '';
68
our $GBE_DPLY           = $ENV{'GBE_DPLY'}           || '';
69
our $GBE_DPKG           = $ENV{'GBE_DPKG'}           || '';
70
our $GBE_DPKG_STORE     = $ENV{'GBE_DPKG_STORE'}     || '';
71
our $GBE_DPKG_LOCAL     = $ENV{'GBE_DPKG_LOCAL'}     || '';
72
our $GBE_DPKG_CACHE     = $ENV{'GBE_DPKG_CACHE'}     || '';
73
our $GBE_DPKG_SBOX      = $ENV{'GBE_DPKG_SBOX'}      || '';
74
our $GBE_SANDBOX        = $ENV{'GBE_SANDBOX'}        || '';
75
our $GBE_PERL           = $ENV{'GBE_PERL'}           || '';
76
our $GBE_TOOLS          = $ENV{'GBE_TOOLS'}          || '';
77
our $GBE_MACHTYPE       = $ENV{'GBE_MACHTYPE'}       || '';
273 dpurdie 78
our $GBE_HOSTMACH       = $ENV{'GBE_HOSTMACH'}       || $GBE_MACHTYPE;
279 dpurdie 79
our $GBE_PLATFORM       = $ENV{'GBE_PLATFORM'}       || '';
80
our $GBE_BUILDFILTER    = $ENV{'GBE_BUILDFILTER'}    || '';
227 dpurdie 81
our $GBE_DEBUG          = $ENV{'GBE_DEBUG'}          || 0;
82
our $GBE_VERBOSE        = $ENV{'GBE_VERBOSE'}        || 0;
279 dpurdie 83
our $GBE_DRV            = $ENV{'GBE_DRV'}            || '';
84
our $GBE_HOSTNAME       = $ENV{'GBE_HOSTNAME'}       || hostname || '';
85
our $USER               = $ENV{'USER'}               || '';
86
our $PERL5LIB           = $ENV{'PERL5LIB'}           || '';
87
our $JAVA_HOME          = $ENV{'JAVA_HOME'}          || '';
88
our $GBE_ABT            = $ENV{'GBE_ABT'}            || '';
227 dpurdie 89
our $GBE_UNIX           = 1;
90
our $CWD;
91
 
92
#-------------------------------------------------------------------------------
93
#   Clean up some environment variables
245 dpurdie 94
#       GBE_BUILDFILTER - may be space or comma separated list
95
#       GBE_PLATFORM - may be space or comma separated list
96
#       GBE_ABT - may be space or comma separated list
279 dpurdie 97
#       GBE_HOSTNAME - No whitespace
227 dpurdie 98
#
99
$GBE_BUILDFILTER = join (' ', split( /[,\s]+/, $GBE_BUILDFILTER));
100
$GBE_PLATFORM    = join (' ', split( /[,\s]+/, $GBE_PLATFORM));
101
$GBE_ABT         = join (' ', split( /[,\s]+/, $GBE_ABT));
279 dpurdie 102
$GBE_HOSTNAME    =~ s~\s+~~g;
227 dpurdie 103
 
104
#-------------------------------------------------------------------------------
105
#   Parse the user options
106
#   GetOptions has been configured so that it will stop parsing on the first
107
#   non-options. This allows the command syntax to the script to have options
108
#   that are directed to this script before the command keyword, and command
109
#   options to the subcommand to be after the keyword.
110
#
111
$result = GetOptions (
261 dpurdie 112
            "help|h:+"          => \$opt_help,
113
            "manual:3"          => \$opt_help,
114
            "verbose|v:+"       => \$GBE_VERBOSE,
115
            "debug:+"           => \$GBE_DEBUG,
227 dpurdie 116
            "cd|changedir=s"    => \$opt_dir,
117
            "locate"            => \$opt_locate,
118
            "locatefile=s"      => \$opt_locate_file,
245 dpurdie 119
            "locatepkg=s"       => \$opt_locate_package,
227 dpurdie 120
            "here"              => \$opt_here,
121
            "time"              => \$opt_time,
122
            "b|buildfile=s"     => \&opts_buildfile,
245 dpurdie 123
            "java=s"            => \$opt_java,
227 dpurdie 124
            "version=s",        => \&opts_version,
125
            "platform:s",       => sub{ opts_extend( \$GBE_PLATFORM, @_ )},
126
            "buildfilter:s"     => sub{ opts_extend( \$GBE_BUILDFILTER, @_ )},
127
            "abt:s"             => sub{ opts_extend( \$GBE_ABT, @_ )},
277 dpurdie 128
            "exportvars!"       => \$opt_export_vars,
227 dpurdie 129
            );
130
 
131
#
132
#   Configure the error reporting process now that we have the user options
133
#
134
ErrorConfig( 'name'    => 'JATS',
135
             'debug'   => $GBE_DEBUG,
136
             'verbose' => $GBE_VERBOSE );
137
#
138
#   Post process some of the options
139
#
140
Error ("Options not parsed. Use -help for help") unless $result;
263 dpurdie 141
Verbose3 ('ARGS', @ARGV);
227 dpurdie 142
 
143
#
144
#   Option Helper Routine
145
#   Save alternate buildfile. Flag that it has been set
146
#
147
sub opts_buildfile
148
{
283 dpurdie 149
    my ($junk, $bf) = @_;
150
    $BUILD_FILE = $bf;
227 dpurdie 151
    $BUILD_FILE_SET = 1;
152
    Verbose ("Use alternate buildfile: $BUILD_FILE");
283 dpurdie 153
    return;
227 dpurdie 154
}
155
 
156
#
157
#   Options Helper Routine
158
#   Collect a space/comma delimited list and replace/append to string
159
#   Allows the string to be reset
160
#   Use of a +" will append to existing value
161
#
162
#       arg1 - Ref to string to store data
163
#       arg2 - Option name
164
#       arg3 - Option value
165
#
166
sub opts_extend
167
{
168
    my( $ref, $name, $value) = @_;
169
    if ( $value )
170
    {
171
        $value =~ s/,/ /g;
172
        $value = ${$ref} . ' ' . $value
173
            if ( $value =~ s/\+/ /g );
174
        $value =~ s/^\s+//;
175
        $value =~ s/\s+/ /;
176
    }
177
    ${$ref} = $value;
283 dpurdie 178
    return;
227 dpurdie 179
}
180
 
181
#
182
#   Options Helper routine
183
#   Collect --version=version, then stop processing of the command line
184
#   This will simulate a '--'
185
#
186
sub opts_version
187
{
283 dpurdie 188
    my ($junk, $vn) = @_;
189
    $GBE_JATS_VERSION = $vn;
190
    die("!FINISH\n");
227 dpurdie 191
}
192
 
193
################################################################################
194
#
195
#   Ensure that essential environment variables are present and that they
196
#   do not contain spaces.
197
#
198
ReportError('Set env-var GBE_PERL (typically "/usr/bin/perl")')   unless ( $GBE_PERL );
229 dpurdie 199
ReportError('Set env-var GBE_DPKG (typically "/devl/dpkg_archive")') unless ( $GBE_DPKG );
200
ReportError('Set env-var GBE_CORE (typically "/devl/dpkg_archive/PACKAGE_TAG/VERSION_TAG")')  unless ( $GBE_CORE );
279 dpurdie 201
ReportError('Hostname cannot be determined') unless ( $GBE_HOSTNAME );
227 dpurdie 202
 
229 dpurdie 203
################################################################################
204
#
205
#   Warn if using a version of perl that is newer than expected
206
#   The 'require' does a lower limit test
207
#
283 dpurdie 208
if ( ! $GBE_JATS_SANE )
209
{
210
    Warning ("Perl Version may not be compatible",
211
             "Jats has been tested with: 5.8.8",
212
             "This version is: $]",
213
            ) if ( $] > 5.010000 );
227 dpurdie 214
 
283 dpurdie 215
    Warning ("The PDK, as used by some deployed packages does not work with this version of perl.",
216
             "ERG only has a licence for PDK V5 and this only works with Perl 5.6 and 5.8",
217
             "This version is: $]",
218
            ) if ( $] > 5.009000 );
219
}
229 dpurdie 220
 
221
#
222
#   Warn if this is not an active state release
223
#
224
#   Would be nice, but I can't figure out how to do it - yet
225
#   The following does not work on all platforms
226
#
227
#unless ( $ActivePerl::VERSION )
228
#{
229
#    Warning ("Perl does not appear to be an ActiveState Release", "Jats may not function as expected");
230
#}
231
#else
232
#{
233
#    Verbose ("ActiveState Version: $ActivePerl::VERSION");
234
#}
235
 
227 dpurdie 236
################################################################################
229 dpurdie 237
#
245 dpurdie 238
#   Warn if this version of JATS is not correctly versioned
229 dpurdie 239
#   Users should be using correctly versioned copies of JATS. These come
240
#   from dpkg_archive.
241
#
231 dpurdie 242
Warning ("*** Unofficial version of JATS ***")
243 dpurdie 243
    if ( ! $GBE_JATS_SANE && $GBE_NOT_RELEASED );
229 dpurdie 244
 
245
################################################################################
227 dpurdie 246
#   If running with cygwin then warn if the CYGWIN environment variable
247
#   contains "tty". tty mode causes some strange behaviour such as:
248
#       1) Non flushing of perl scripts under some conditions (eg:create_dpkg)
249
#
250
if ( $ENV{'CYGWIN'} && $ENV{'CYGWIN'} =~ m/tty/ )
251
{
252
    Warning ("The CYGWIN variable contains \"tty\".",
253
             "This can cause strange behaviour with interactive scripts");
254
}
255
 
256
#
257
#   Remove CDPATH - this breaks things when cygwin is running
258
#   even if we are not running under cygwin perl
259
#
260
delete $ENV{'CDPATH'};
261
 
262
 
263
################################################################################
264
#   Sanitize GBE_CORE and others for internal Perl use
265
#   It may contain \ to be added to PATH but within perl is needs /
266
#
267
$PERL5LIB =~ tr~\\/~/~s;
268
 
269
TestDirectoryConfig( 'GBE_CORE' );
270
TestDirectoryConfig( 'GBE_BIN' );
271
TestDirectoryConfig( 'GBE_PERL' );
272
TestDirectoryConfig( 'GBE_DPLY' );
273
TestDirectoryConfig( 'GBE_DPKG' );
274
TestDirectoryConfig( 'GBE_DPKG_CACHE' );
275
TestDirectoryConfig( 'GBE_DPKG_LOCAL' );
276
TestDirectoryConfig( 'GBE_DPKG_STORE' );
277
TestDirectoryConfig( 'GBE_DPKG_SBOX' );
278
TestDirectoryConfig( 'GBE_SANDBOX' );
279
 
280
################################################################################
281
#   Setup the Machine Type
282
#
283
#   GBE_MACHTYPE is used to determine the BIN directory from which JATS will
284
#   pull local binary executables from. The directory must exist.
285
#
286
#   We need GBE_MACHTYPE to be correctly defined by the user
287
#   This is machine specific and should be done in jats.sh/jats.bat
288
#
289
unless ( $GBE_MACHTYPE )
290
{
291
    $GBE_MACHTYPE = 'win32' if ( $^O eq "cygwin" );
292
    $GBE_MACHTYPE = 'win32' if ( $^O eq "MSWin32" );
293
    $GBE_MACHTYPE = 'win32' if ( $^O eq "win95" );
294
    Verbose ("Setting GBE_MACHTYPE: $GBE_MACHTYPE") ;
295
}
296
 
297
ReportError ('Set env-var GBE_MACHTYPE (typically "win32")') unless ( $GBE_MACHTYPE );
298
ErrorDoExit();
299
 
300
if ( $GBE_MACHTYPE eq 'win32' )
301
{
302
    $PSPLIT = ';';
303
    $GBE_UNIX = 0;
304
}
305
 
306
################################################################################
307
#   Windows: If the user is running JATS from within the development view
308
#   then they may not provide a drive letter in the full name of GBE_CORE
309
#   For correct operation GBE_CORE needs to be able to run programs and
310
#   scripts from any other drive
311
#
312
#   If GBE_CORE does not have a driver letter - then add one
313
#   Note: Use the CWD before any CD operations
314
#
315
if ( $GBE_MACHTYPE eq 'win32'  && $GBE_CORE !~ m/^\w\:/ )
316
{
317
        my $cwd = getcwd();
318
        $GBE_CORE = substr( $cwd, 0, 2 ) . '/' . $GBE_CORE;
319
        $GBE_CORE =~ s~//~/~g;
320
        Verbose2 ("Setting GBE_CORE drive: $GBE_CORE");
321
}
322
 
323
################################################################################
324
#   Attempt to run JATS from a local cache
325
#   This mechanism allows JATS to be a link to a desired version on a network
326
#   drive, but to have the version transferred locally if required
327
#
229 dpurdie 328
#   The transfer/check is only done on the first invocation of jats. If jats uses
245 dpurdie 329
#   jats to perform functions, then it will not be performed.
229 dpurdie 330
#
245 dpurdie 331
#   If we want to run an alternate version of JATS, then don't attempt to
229 dpurdie 332
#   cache the initial version of JATS.
333
#
227 dpurdie 334
if ( $ENV{GBE_CACHE_JATS} && ! $GBE_JATS_SANE && ! $GBE_JATS_VERSION)
335
{
336
    my $state = "Not Cached: Not running from dpkg_archive";
337
    #
338
    #   Must have the DPKG_ARCHIVE cache
229 dpurdie 339
    #   Must be running from DPKG_ARCHIVE - prevent messing with local copies
227 dpurdie 340
    #
341
    if ( $GBE_DPKG_CACHE )
342
    {
229 dpurdie 343
        #
344
        #   JATS must be running from an archive, otherwise we assume that its
345
        #   a local copy. Detected by:
346
        #       GBE_NOT_RELEASED being set
347
        #       Lack of descpkg file
348
        #
349
        if ( ! $GBE_NOT_RELEASED  && -f "$GBE_CORE/descpkg" )
227 dpurdie 350
        {
229 dpurdie 351
            my ($archive, $package) = LocateJatsVersion( $GBE_VERSION );
352
            if ( $archive )
353
            {
354
                Verbose ("Update cached version of JATS: $GBE_VERSION");
355
                #
356
                #   Attempt to cache the package
357
                #   Need enough JATS environment to run the cache_dpkg utility
358
                #
283 dpurdie 359
                {
360
                    local %ENV = %ENV;
227 dpurdie 361
 
283 dpurdie 362
                    $ENV{GBE_TOOLS} = "$GBE_CORE/TOOLS";
363
                    $ENV{PERL5LIB} = "$GBE_CORE/TOOLS/LIB" ;
364
                    $ENV{GBE_BIN}  = "$GBE_CORE/BIN.$GBE_MACHTYPE";
365
                    $ENV{GBE_VERBOSE}  = $GBE_VERBOSE;
227 dpurdie 366
 
283 dpurdie 367
                    etool ( 'cache_dpkg.pl', $package );
368
                }
227 dpurdie 369
 
229 dpurdie 370
                my $tgt = "$GBE_DPKG_CACHE/$package";
371
                if ( -d $tgt )
372
                {
373
                    Verbose ("Using cached version of JATS: $GBE_VERSION");
374
                    $GBE_CORE = $tgt;
375
                    $state = "Cached";
376
                }
377
                else
378
                {
379
                    $state = "Not Cached: Copy Failure";
380
                }
227 dpurdie 381
            }
382
            else
383
            {
229 dpurdie 384
                $state = "Not Cached: Not found in archives";
227 dpurdie 385
            }
386
        }
387
    }
388
    else
389
    {
390
        $state = "Not Cached: No GBE_DPKG_CACHE";
391
    }
392
 
393
    #
394
    #   Flag JATS having been cached on the machine
395
    #
396
    $ENV{GBE_CACHE_JATS} = $state;
397
}
398
 
399
 
400
################################################################################
401
#   Establish a relationship between GBE_BIN, GBE_TOOLS and GBE_CONFIG
402
#   unless the user has already provided one.
403
#
404
#   Only NEED GBE_CORE - the others will be derived
405
#
406
unless ( $GBE_BIN )
407
{
408
    $GBE_BIN = "$GBE_CORE/BIN.$GBE_MACHTYPE";
409
    Verbose2 ("Setting GBE_BIN: $GBE_BIN");
410
}
411
ReportError ('GBE_MACHTYPE is not valid.',
412
             'There must be a corresponding BIN directory in GBE_CORE',
413
             "GBE_BIN     : $GBE_BIN",
414
             "GBE_MACHTYPE: $GBE_MACHTYPE"
415
             ) unless ( -d $GBE_BIN );
416
 
417
ReportError ('Machine specific binary directory does not appear to setup',
418
             'After JATS is installed the PostInstall script must be run',
419
             "GBE_BIN     : $GBE_BIN"
420
             ) unless ( -x $GBE_BIN . '/sh' || -x $GBE_BIN . '/sh.exe'  );
421
 
422
unless ( $GBE_TOOLS )
423
{
424
    $GBE_TOOLS = "$GBE_CORE/TOOLS";
425
    Verbose2 ("Setting GBE_TOOLS: $GBE_TOOLS");
426
}
427
 
428
unless ( $GBE_CONFIG )
429
{
430
    $GBE_CONFIG = "$GBE_CORE/CFG";
431
    Verbose2 ("Setting GBE_CONFIG: $GBE_CONFIG");
432
}
433
 
434
#
435
#   Extend the PERL5 with our own Module Repository
436
#
437
$PERL5LIB = join( $PSPLIT, split( $PSPLIT, $PERL5LIB), "$GBE_CORE/TOOLS/LIB" );
438
 
439
 
440
################################################################################
441
#   Sanity Test
442
#   The ABT environment requires several parameters to specify the location
443
#   of the Release/Deployment Managers
444
#
445
#   GBE_DM_LOCATION will be set GBE_RM_LOCATION, if not set
446
#
447
#   Only perform the test:
448
#       - On the first invocation of JATS, not nested invocations
449
#       - Based on the EnvVar, not the user option. This will allow a user
450
#         to invoke ABT without the need for these values to be present
451
#
452
if ( ! $GBE_JATS_SANE && $ENV{GBE_RM_LOCATION} && ! $ENV{GBE_DM_LOCATION} )
453
{
454
    $ENV{GBE_DM_LOCATION} = $ENV{GBE_RM_LOCATION};
455
}
456
 
457
if ( ! $GBE_JATS_SANE && $ENV{GBE_ABT} )
458
{
459
    foreach my $var ( qw(GBE_DM_LOCATION GBE_DM_USERNAME GBE_DM_PASSWORD GBE_RM_URL))
460
    {
461
        Warning("Deployment Manager EnvVar may need to be defined: $var") unless ( $ENV{$var} );
462
    }
463
 
464
    foreach my $var ( qw(GBE_RM_LOCATION GBE_RM_USERNAME GBE_RM_PASSWORD GBE_DM_URL))
465
    {
466
        ReportError("Release Manager EnvVar needs to be defined: $var") unless ( $ENV{$var} );
467
    }
468
}
469
 
470
################################################################################
471
#
472
#   Change to the required root directory
473
#       The user may specify a start directory( -c )
474
#
475
change_dir ( $opt_dir );
245 dpurdie 476
 
477
################################################################################
478
#   Locate the root of the build - if required
479
#   This is used by the autobuild tools to:
480
#       1) Locate the build.pl file for JATS based builds
481
#          The name of the target package can be provided to resolve
482
#          cases of multiple build files.
483
#
484
#       2) Locate the <ProjectName>depends.xml file for ANT based builds
485
#          The name of the buildfile will be specified
486
#          There must be only one file of this name in the tree
487
#
488
#   Note: If only one build file is found, then it will be used
489
#         It will not be sanity tested. This is intentional
490
#         for backward compatability.
491
#
492
if ( $opt_locate || $opt_locate_file || $opt_locate_package )
227 dpurdie 493
{
245 dpurdie 494
    #
495
    #   Allow the user to specify the name of the build file
496
    #   This will be used in ANT builds as the name changes
497
    #   but it can be predetermined
498
    #
227 dpurdie 499
    $opt_locate_file = $BUILD_FILE unless ( $opt_locate_file );
500
 
245 dpurdie 501
    #
502
    #   Create a Build File Scanner object
503
    #   This will be used to locate a suitable build file
504
    #
227 dpurdie 505
    Verbose ("Autolocate the build file: $opt_locate_file");
506
 
245 dpurdie 507
    my $bscanner = BuildFileScanner ( '.', $opt_locate_file );
508
    my $count = $bscanner->locate();
509
 
510
    Error ("Autolocate. Build file not found: $opt_locate_file" )
511
        if ( $count <= 0 );
512
 
227 dpurdie 513
    #
245 dpurdie 514
    #   If multiple build files have been found
515
    #   If $opt_locate_package is set then we can attempt to resolve the package
227 dpurdie 516
    #
245 dpurdie 517
    #   Scan the buildfiles and determine the names of the packages that will
518
    #   be built. This can be used to generate nice error messages
519
    if ( $count > 1 )
520
    {
521
        $bscanner->scan();
522
        $count = $bscanner->match( $opt_locate_package );
523
#DebugDumpData ("Bscan", \$bscanner );
227 dpurdie 524
 
245 dpurdie 525
        my $errmess;
526
        unless ( $opt_locate_package ) {
527
            $errmess = "Use -locatepkg=pkg to resolve required package";
528
 
529
        } elsif ( $count <= 0 ) {
530
            $errmess = "None found that build package: $opt_locate_package";
531
 
532
        } elsif ( $count > 1 ) {
533
            $errmess = "Multiple build files build the required package: $opt_locate_package";
534
        }
535
 
536
        #
537
        #   Pretty error display
538
        #   Display build directory and the package name (mangled)
539
        #
540
        if ( $errmess )
541
        {
542
            Error ("Autolocate. Multiple build files found.",
543
                   $errmess,
544
                   "Build files found in:", $bscanner->formatData() );
545
        }
546
    }
547
 
227 dpurdie 548
    #
245 dpurdie 549
    #   Extract the required build file directory
227 dpurdie 550
    #
245 dpurdie 551
    my $dir = $bscanner->getMatchDir() || '';
552
    Verbose ("Autolocate. Found $count build files: $dir");
227 dpurdie 553
 
554
    #
555
    #   Select the one true build directory
556
    #
245 dpurdie 557
    change_dir ( $dir );
227 dpurdie 558
 
559
    #
560
    #   Kill location scan as we have already located the build file
561
    #
562
    $opt_here = 1;
563
}
564
 
565
################################################################################
566
#   Version redirection
567
#   JATS allows the version of JATS to be used to be specified
568
#   This mechanism operates on the assumption that the required version is
569
#   present in dpkg_archive. If a specific version is required then the bulk
570
#   of this script is bypassed and the arguments passed directly to the required
571
#   target
572
#
573
if ( $GBE_JATS_VERSION && $GBE_JATS_VERSION eq $GBE_VERSION )
574
{
575
    Message("Using current JATS version: $GBE_JATS_VERSION" );
576
    $GBE_JATS_VERSION = undef;
577
}
578
 
579
if ( $GBE_JATS_VERSION )
580
{
581
    #
582
    #   Report any errors detected
583
    #
584
    ErrorDoExit();
585
    Message("Using JATS version: $GBE_JATS_VERSION");
586
 
587
    #
245 dpurdie 588
    #   If we have a cache available, then attempt to transfer the required
589
    #   version into the cache. If we don't have a cache, then don't even try.
229 dpurdie 590
    #
245 dpurdie 591
    if ( $GBE_DPKG_CACHE )
592
    {
593
        #
594
        #   Attempt to locate the desired version in one of the well known
595
        #   package archives. This will give us its package name.
596
        #
597
        my ($archive, $package) = LocateJatsVersion ($GBE_JATS_VERSION);
598
        Error("Cannot find JATS version: $GBE_JATS_VERSION") unless $archive;
229 dpurdie 599
 
245 dpurdie 600
        #
601
        #   Do NOT propagate GBE_JATS_VERSION in the environment
602
        #   This will only cause problem in recursion
603
        #
604
        delete $ENV{GBE_JATS_VERSION};
227 dpurdie 605
 
245 dpurdie 606
        #
607
        #   Attempt to cache the package
608
        #   Need enough JATS environment to run the utility
609
        #
283 dpurdie 610
        {
611
            local %ENV = %ENV;
227 dpurdie 612
 
283 dpurdie 613
            $ENV{PERL5LIB} = $PERL5LIB;
614
            $ENV{GBE_BIN}  = $GBE_BIN;
615
            $ENV{GBE_VERBOSE}  = $GBE_VERBOSE;
616
            $ENV{GBE_TOOLS}  = $GBE_TOOLS;
227 dpurdie 617
 
283 dpurdie 618
            etool ( 'cache_dpkg.pl', $package );
619
        }
245 dpurdie 620
    }
227 dpurdie 621
 
622
    #
229 dpurdie 623
    #   Locate the version of JATS to be run (again)
227 dpurdie 624
    #   It should be in the cache, but it may not be
625
    #
245 dpurdie 626
    my ($archive, $package) = LocateJatsVersion ($GBE_JATS_VERSION);
229 dpurdie 627
    Error("Cannot find JATS version: $GBE_JATS_VERSION") unless $archive;
628
 
629
    $GBE_CORE = "$archive/$package";
227 dpurdie 630
    Verbose2 ("Using alternate version: $GBE_CORE");
631
 
632
    #
633
    #   Run the specified version of JATS
634
    #   Force the required version of GBE_CORE and invoke the wrapper script
635
    #
636
    $ENV{GBE_CORE} = $GBE_CORE;
637
 
638
    Verbose("Use ARGV: @ARGV");
639
    $RESULT = System ($GBE_PERL, "$GBE_CORE/TOOLS/jats.pl", @ARGV );
640
    do_exit();
641
}
642
 
643
################################################################################
644
#   Determine the current directory
645
#   Note: Don't use `pwd`. This sucks for so many reasons including
646
#         the fact that it may not be available until this wrapper
647
#         script has done it job.
648
#
649
$CWD = getcwd();
650
Verbose ("Current Working Directory: $CWD");
651
Warning ("Current working directory contains spaces") if ( $CWD =~ m/\s/ );
652
 
653
 
654
################################################################################
655
#   Setup drive
656
#   This is only required under windows
657
#   Purpose is unclear, but under windows it is required, so lets create one
658
#   if its not present
659
#
660
unless ( $GBE_UNIX )
661
{
662
    unless ( $GBE_DRV )
663
    {
664
        ($GBE_DRV = $CWD ) =~ s~[^:]*$~~;
665
        $GBE_DRV = "c:" if ( $GBE_DRV !~ m/:/ );
666
        Verbose2( "Setting GBE_DRV: $GBE_DRV" );
667
    }
668
}
669
 
670
################################################################################
671
#   Sanity test the main archive variable
672
#   This MUST address one archive
673
#
674
 
675
Error ("GBE_DPKG must not be a path list: $GBE_DPKG")
676
    if ( $GBE_DPKG =~ /$PSPLIT/ );
677
Error ("GBE_DPKG is not a directory : $GBE_DPKG")
678
    unless( -d $GBE_DPKG );
679
 
680
################################################################################
681
#   Sanity test the cache
682
#
683
Error ("GBE_DPKG_CACHE is not a directory : $GBE_DPKG_CACHE")
684
    if ( $GBE_DPKG_CACHE && ! -d $GBE_DPKG_CACHE );
685
 
686
################################################################################
687
#   Sanity test the global store
688
#
689
Error ("GBE_DPKG_STORE is not a directory : $GBE_DPKG_STORE")
690
    if ( $GBE_DPKG_STORE && ! -d $GBE_DPKG_STORE );
691
 
692
Error ("GBE_DPLY is not a directory : $GBE_DPLY")
693
    if ( $GBE_DPLY && ! -d $GBE_DPLY );
694
 
695
########################################################################
696
#
697
#       Locate a local_dpkg_archive directory, by searching from the CWD
698
#       to the root of the file system
699
#
700
unless ( $GBE_DPKG_LOCAL )
701
{
283 dpurdie 702
    ($GBE_DPKG_LOCAL) = scan_for_dir ('local_dpkg_archive');
227 dpurdie 703
}
704
else
705
{
706
    Error ("GBE_DPKG_LOCAL is not a directory : $GBE_DPKG_LOCAL")
707
        unless( -d $GBE_DPKG_LOCAL );
708
}
709
 
710
########################################################################
711
#
712
#       Locate a sandbox_dpkg_archive directory by searching from the CWD
713
#       to the root of the file system
714
#
241 dpurdie 715
#       sandbox_dpkg_archive is a dpkg_archive for packages that are being
716
#       co-developed. Package Versions within the sandbox are ignored
227 dpurdie 717
#
241 dpurdie 718
 
719
#
720
#   Ensure that the user does not set $GBE_SANDBOX or $GBE_DPKG_SBOX
721
#   $GBE_JATS_SANE will be set for multiple invocations, thus it is cleared
722
#   for the first one (unless the user messes with it).
723
#
724
unless ( $GBE_JATS_SANE )
227 dpurdie 725
{
241 dpurdie 726
    Error ("GBE_SANDBOX must not be set by the user") if ( $GBE_SANDBOX );
727
    Error ("GBE_DPKG_SBOX must not be set by the user") if ( $GBE_DPKG_SBOX );
728
 
729
    #
730
    #   The ABT does not use the sandbox
731
    #   It will never be found and will be ignored
732
    #
733
    unless ( $GBE_ABT )
734
    {
277 dpurdie 735
        ($GBE_DPKG_SBOX,$GBE_SANDBOX)  = scan_for_dir ('sandbox_dpkg_archive');
227 dpurdie 736
    }
737
}
738
 
739
########################################################################
740
#
741
#   Ensure that the user has been set
742
#   Under windows USER may not be set, but USERNAME may be
299 dpurdie 743
#   As a last resort, use getlogin data
227 dpurdie 744
#
745
$USER = $ENV{ 'USERNAME' } || '' unless ( $USER );
746
$USER = $ENV{ 'LOGNAME' }  || '' unless ( $USER );
299 dpurdie 747
$USER = getlogin()         || '' unless ( $USER );
301 dpurdie 748
ReportError ('Cannot determine USER name, via USER, USERNAME, LOGNAME or getlogin')
749
    unless ( $USER );
299 dpurdie 750
#Debug ("User: ", $USER, $ENV{ 'USERNAME'}, $ENV{ 'LOGNAME' }, getlogin() );
751
 
227 dpurdie 752
################################################################################
753
#   Sanitize the PATH variable
754
#   Some of the Win32 binary tools used by JATS cannot handle lower case Path
755
#   Force an upper case PATH
756
#
757
my $PATH = '';
758
$PATH .= delete( $ENV{ 'Path' } ) if (exists $ENV{ 'Path' });
759
$PATH .= delete( $ENV{ 'path' } ) if (exists $ENV{ 'path' });
760
$PATH .= delete( $ENV{ 'PATH' } ) if (exists $ENV{ 'PATH' });
277 dpurdie 761
$ENV{'PATH'} = $PATH;
227 dpurdie 762
 
763
#
764
#   Windows now defines ComSpec. This is only a problem when programs are
765
#   started up without the use of cmd.exe - like the JATS internal sh.exe
766
#   Correct by deleting the environment variable and forcing it to be uppercase
767
#
768
my $COMSPEC = '';
769
$COMSPEC = delete( $ENV{'COMSPEC'} ) if ( exists $ENV{'COMSPEC'} );
770
 
771
################################################################################
772
#   There is some really ugly interaction between Cygwin, ActiveState Perl 5.8.2
773
#   and xmake. Even if none of the cygwin bits are used within JATS the fact that
774
#   Cygwin is in the path causes problems.
775
#
776
#   Problems seen:
777
#       1) "jats build"     xmake fails with a segment fault. Possibly when
778
#                           displaying an error message
779
#       2) Warnings and messages generated from within Perl don't always appear
780
#          In particular. The output from a Message() within a PLATFORM/xxx file
781
#          does not get displayed.
782
#
783
#   Solution:
784
#       Remove cygwin from the PATH
785
#
786
$PATH =~ s~c:\\cygwin[^;]*;~~ig;
787
 
788
################################################################################
297 dpurdie 789
#   Setup the default JAVA_HOME
790
#   User should specify 1.4, 1.5,1.6 ....
791
#
792
$JAVA_HOME = get_java_home ($opt_java)
793
    if ( $opt_java );
794
PathPrepend ("$JAVA_HOME/bin")
795
    if ( -d $JAVA_HOME );
796
 
797
 
798
################################################################################
227 dpurdie 799
#   Ensure that the PATH contains the PERL executable
800
#   Need to true path to the PERL executable so that the user has access to some
801
#   of the perl utility programs such as pod2html
802
#
299 dpurdie 803
PathPrepend ($Config{'binexp'});
227 dpurdie 804
 
805
################################################################################
806
#   There is more ugliness if GBE_BIN is not in the users path
807
#   I suspect that it something within xmake (under win32) and that it needs
808
#   to be able to find sh within the path - even though its fully pathed
809
#
810
#   Add GBE_BIN to the start of the path to assist in searching
811
#   Also ensure that we pickup our version of utilities instead of random
812
#   versions.
813
#
297 dpurdie 814
PathPrepend ($GBE_BIN);
227 dpurdie 815
 
816
################################################################################
817
#   Clean PATH
818
#       Remove duplicates
819
#       Remove empty elements
820
#       Clean path endings
245 dpurdie 821
#       Place non-existent paths at the end. They will be seen, but not scanned
227 dpurdie 822
#
823
{
824
    my @new_path;
825
    my @non_exist;
826
    my %seen;
827
    foreach ( split $PSPLIT, $PATH )
828
    {
829
        s~[/\\]+$~~;                                # Remove trailing / or \
830
        my $name = ( $GBE_UNIX ) ? $_ : lc ($_);    # Windows is case insensitive
831
        next unless ( $_ );                         # Remove empty elements
832
        next if ( /^\.+$/ );                        # Remove . and ..
833
        next if ( exists $seen{$name} );            # Remove duplicates
834
        if ( -d $_ ) {
835
            push @new_path, $_;                     # Exists
836
        } else {
245 dpurdie 837
            push @non_exist, $_;                    # Place non existent paths at the end
227 dpurdie 838
        }
839
        $seen{$name} = 1;
840
    }
841
    $PATH = join( $PSPLIT, @new_path, @non_exist );
842
}
843
 
844
################################################################################
845
#   Windows: Ensure that cmd.exe is in the users PATH
846
#            If cmd.exe cannot be found then the 'system' command will not work
847
#
317 dpurdie 848
unless ( $GBE_JATS_SANE || $GBE_UNIX )
227 dpurdie 849
{
850
    my $cmd_found;
851
    foreach ( split $PSPLIT, $PATH )
852
    {
853
        my $file = $_ . "/cmd.exe";
854
        Verbose2 ("Look for: $file");
855
        if ( -x $file  )
856
        {
857
            $cmd_found = 1;
858
            Verbose ("Found: $file");
859
            last;
860
        }
861
    }
862
 
863
    Warning( "Users PATH does not contain \"cmd.exe\"",
864
             "System commands may not work" ) unless $cmd_found;
865
}
866
 
867
################################################################################
868
#   Sanitize the Microsoft Visual Studio environment variables LIB and INCLUDE.
869
#   If these have a trailing \ then the generated makefiles
870
#   will fail. This is impossible to detect and fix within make so do it here
871
#
872
#   Note: JATS no longer allows these environment variables through to the
873
#         makefiles.
874
#
317 dpurdie 875
unless ( $GBE_JATS_SANE || $GBE_UNIX )
227 dpurdie 876
{
877
    for my $var qw ( LIB INCLUDE )
878
    {
879
        my $evar = $ENV{$var};
880
        if ( $evar )
881
        {
882
            $evar =~ s~\\;~;~g;         # Remove trailing \ from components \; -> ;
883
            $evar =~ s~\\$~~;           # Remove trailing \
884
            $evar =~ s~;$~~;            # Remove trailing ;
885
            $evar =~ s~;;~;~g;          # Remove empty items ;;
886
            $ENV{$var} = $evar;
887
        }
888
    }
889
}
890
 
891
################################################################################
297 dpurdie 892
#   Update the environment variables used by JATS, unless requested otherwise.
227 dpurdie 893
#
277 dpurdie 894
#   If JATS is being used to startup build daemons, then we don't want to
895
#   export many of the calculated values into the environment. In particular
896
#   GBE_CORE, GBE_BIN, GBE_CONFIG and GBE_TOOLS must not be exported as it will
897
#   prevent the daemon from picking up the 'current' version of JATS
898
#
899
#
287 dpurdie 900
 
277 dpurdie 901
if ( $opt_export_vars )
902
{
903
    $ENV{'PATH'}              = $PATH;
904
    $ENV{'GBE_VERSION'}       = $GBE_VERSION;
905
    $ENV{'GBE_CORE'}          = $GBE_CORE;
906
    $ENV{'GBE_BIN'}           = $GBE_BIN;
907
    $ENV{'GBE_CONFIG'}        = $GBE_CONFIG;
908
    $ENV{'GBE_DPLY'}          = $GBE_DPLY;
909
    $ENV{'GBE_DPKG'}          = $GBE_DPKG;
910
    $ENV{'JATS_HOME'}         = $GBE_DPKG;
911
    $ENV{'GBE_DPKG_CACHE'}    = $GBE_DPKG_CACHE;
912
    $ENV{'GBE_DPKG_STORE'}    = $GBE_DPKG_STORE;
913
    $ENV{'GBE_DPKG_LOCAL'}    = $GBE_DPKG_LOCAL;
914
    $ENV{'GBE_SANDBOX'}       = $GBE_SANDBOX;
915
    $ENV{'GBE_DPKG_SBOX'}     = $GBE_DPKG_SBOX;
916
    $ENV{'GBE_PERL'}          = $GBE_PERL;
917
    $ENV{'GBE_TOOLS'}         = $GBE_TOOLS;
918
    $ENV{'GBE_MACHTYPE'}      = $GBE_MACHTYPE;
919
    $ENV{'GBE_HOSTMACH'}      = $GBE_HOSTMACH;
920
    $ENV{'GBE_PLATFORM'}      = $GBE_PLATFORM;
921
    $ENV{'GBE_DRV'}           = $GBE_DRV;
922
    $ENV{'PERL5LIB'}          = $PERL5LIB;
923
    $ENV{'JAVA_HOME'}         = $JAVA_HOME if ($JAVA_HOME);
924
    $ENV{'GBE_JATS_SANE'}     = 1;
925
}
287 dpurdie 926
else
927
{
928
    #
929
    #   Delete, from the environment, values that are related to selecting
930
    #   the version of JATS being used
931
    #
932
    foreach ( qw( GBE_VERSION GBE_CORE GBE_BIN GBE_CONFIG GBE_TOOLS GBE_DRV PERL5LIB GBE_DPKG_SBOX GBE_SANDBOX GBE_PLATFORM GBE_JATS_SANE ) )
933
    {
934
        delete $ENV{$_};
935
    }
936
}
277 dpurdie 937
 
938
#
939
#   The following don't affect the operation of the build daemons selecting
940
#   the current version of JATS. Some need to be passed through anyway
941
#
227 dpurdie 942
$ENV{'GBE_BUILDFILTER'}   = $GBE_BUILDFILTER;
277 dpurdie 943
$ENV{'GBE_ABT'}           = $GBE_ABT if ($GBE_ABT);
227 dpurdie 944
$ENV{'GBE_DEBUG'}         = $GBE_DEBUG;
945
$ENV{'GBE_VERBOSE'}       = $GBE_VERBOSE;
946
$ENV{'GBE_UNIX'}          = $GBE_UNIX;
947
$ENV{'USER'}              = $USER;
277 dpurdie 948
$ENV{'COMSPEC'}           = $COMSPEC;
279 dpurdie 949
$ENV{'GBE_HOSTNAME'}      = $GBE_HOSTNAME;
227 dpurdie 950
 
951
#-------------------------------------------------------------------------------
297 dpurdie 952
# Function        : PathPrepend
953
#
954
# Description     : Prepend stuff to the PATH
955
#
956
# Inputs          : Items to prepend
957
#
958
# Returns         : Nothing
959
#                   Modifies $PATH
960
#
961
sub PathPrepend
962
{
299 dpurdie 963
    foreach my $el ( @_ )
297 dpurdie 964
    {
299 dpurdie 965
        # Must NOT change the original argument, just a copy of it.
966
        # Don't use $_ as this messes up too
967
        my $item = $el;
297 dpurdie 968
        $item =~ s~/~\\~g unless ( $GBE_UNIX );
969
        $PATH = $item . $PSPLIT . $PATH;
970
    }
971
}
972
 
973
#-------------------------------------------------------------------------------
229 dpurdie 974
# Function        : LocateJatsVersion
975
#
245 dpurdie 976
# Description     : Scan archives looking for a specified version of JATS
229 dpurdie 977
#                   Complicated by the name change from core_devl to jats
245 dpurdie 978
#                   that occurred circa version 2.71.7.
229 dpurdie 979
#                   The required version may be in either of the packages
980
#
981
# Inputs          : $version            - Version to locate
982
#
983
# Returns         : undef               - if not found
984
#                   Array of:
985
#                       Repository
986
#                       package/version
987
#
988
sub LocateJatsVersion
989
{
990
    my ($version) = @_;
991
    my $package;
992
    my $path;
993
 
994
    foreach my $archive qw ( GBE_DPKG_LOCAL GBE_DPKG_CACHE GBE_DPKG GBE_DPKG_STORE )
995
    {
996
        no strict 'refs';
997
        $path = ${$archive};
998
        use strict 'refs';
999
        next unless ( $path );
1000
 
1001
        foreach my $package qw( jats core_devl )
1002
        {
1003
            Verbose2( "ExamineDir: $path/$package/$version" );
1004
            if ( -d "$path/$package/$version" )
1005
            {
283 dpurdie 1006
                return $path, "$package/$version";
229 dpurdie 1007
            }
1008
        }
1009
    }
283 dpurdie 1010
    return;
229 dpurdie 1011
}
1012
 
1013
 
1014
#-------------------------------------------------------------------------------
227 dpurdie 1015
# Function        : TestDirectoryConfig
1016
#
1017
# Description     : Sanity test a user configurable directory or file
1018
#                   Must not contain spaces
1019
#                   Must not be a network drive ie: //computer
1020
#
1021
# Inputs          :
1022
#
1023
# Returns         :
1024
#
1025
sub TestDirectoryConfig
1026
{
1027
    my ($dir) = @_;
1028
 
1029
    no strict 'refs';
1030
    my $val = ${$dir};
1031
 
1032
    if ( $val )
1033
    {
1034
        #
1035
        #   Cleanup the path
1036
        #
1037
        $val =~ tr~\\/~/~s;
1038
        $val =~ s~/+$~~;
255 dpurdie 1039
        $val = '' if ( $val eq '-' || $val eq 'none' );
227 dpurdie 1040
        ${$dir} = $val;
1041
 
1042
        ReportError("$dir path cannot contain spaces: $val") if ( $val =~ m/\s/ );
1043
        ReportError("$dir path cannot be a computer name: $val") if ( $val =~ m~^//~  );
1044
    }
1045
    use strict 'refs';
283 dpurdie 1046
    return;
227 dpurdie 1047
}
1048
 
1049
#-------------------------------------------------------------------------------
1050
# Function        : change_dir
1051
#
1052
# Description     : change directory to the specified directory
1053
#
1054
# Inputs          : $1      - Target directory
1055
#
1056
# Returns         :
1057
#
1058
sub change_dir
1059
{
1060
    my ($dir) = @_;
1061
 
1062
    if ( $dir && $dir !~ m/^\.$/ )
1063
    {
1064
        Verbose ("Changing to JATS build directory: $dir");
1065
        chdir $dir || Error ("Bad change directory: $dir");
1066
    }
1067
 
1068
    #
1069
    #   Reset the CWD
1070
    #   Note: Don't use `pwd`. This sucks for so many reasons including
1071
    #         the fact that it may not be available until this wrapper
1072
    #         script has done it job.
1073
    #
1074
    $CWD = getcwd();
1075
    $CWD =~tr~\\/~/~s;
1076
    Warning ("Current working directory contains spaces") if ( $CWD =~ m/\s/ );
283 dpurdie 1077
    return;
227 dpurdie 1078
}
1079
 
1080
#-------------------------------------------------------------------------------
277 dpurdie 1081
# Function        : scan_for_dir
1082
#
1083
# Description     : Scan from the current directory up to the root
1084
#                   of the current file system looking for a named
1085
#                   directory
1086
#
1087
# Inputs          : $target                 - Directory to locate
1088
#
1089
# Returns         : full_path               - Path of dir
1090
#                   full_dir                - Containng dir
1091
#
1092
 
1093
sub scan_for_dir
1094
{
1095
    my ($target) = @_;
1096
    Verbose2 ("Scan for $target");
1097
 
1098
    my $test_dir = $CWD;
1099
    {
1100
        do
1101
        {
1102
            #
1103
            #   Stop at /home to prevent unix automounter spitting
1104
            #   lots of error messages
1105
            #
1106
            last if ( $test_dir =~ m~/home$~ );
1107
            Verbose2 ("Testing: $test_dir");
1108
 
1109
            my $test_path = $test_dir . '/' . $target;
1110
            if ( -d $test_path )
1111
            {
1112
                Verbose ("Found $target: $test_path");
1113
                return $test_path, $test_dir;
1114
            }
1115
            #
1116
            #   Remove one directory
1117
            #   Terminate the loop when no more can be removed
1118
            #
1119
        } while ( $test_dir =~ s~[/][^/]*$~~ );
1120
    }
1121
    return '','';
1122
}
1123
 
1124
#-------------------------------------------------------------------------------
227 dpurdie 1125
# Function        : get_java_home
1126
#
1127
# Description     : Convert user java option into a full path,or die
1128
#
1129
# Inputs          : User option
1130
#
1131
# Returns         : Full path
1132
#
1133
sub get_java_home
1134
{
1135
    my ($java) = @_;
1136
    my $jv = "JAVA_HOME_$java";
1137
    $jv =~ s~\.~_~g;
1138
 
1139
    unless ( exists($ENV{$jv}) )
1140
    {
1141
        Error ("Unknown JAVA version: $java",
1142
               "Looking for EnvVar: $jv",
1143
               "Example Usage: -java=1.5");
1144
    }
1145
    my $rv = $ENV{$jv};
1146
    unless ( -d $rv )
1147
    {
1148
        Error ("Java home path not found: $jv",
1149
               "Looking for: $rv" );
1150
    }
1151
    return $rv;
1152
}
1153
 
1154
#-------------------------------------------------------------------------------
1155
# Function        : get_version
1156
#
1157
# Description     : Return the version of JATS being run
1158
#                   JATS should be run from a "package"
1159
#                   The package should have a descpkg file
1160
#                   Use this file
1161
#
1162
# Inputs          :
1163
#
1164
# Returns         : A string
1165
#
1166
sub get_version
1167
{
229 dpurdie 1168
    #
1169
    #   The version number is embedded into this script by the release process
1170
    #   The text [V]ERSION_TAG will be replaced by the real version number
245 dpurdie 1171
    #   If this has not occurred then we know that the release is not official
229 dpurdie 1172
    #   Need to be a little bit careful about the tag name
1173
    #
1174
    return ("Unreleased Version. Version tag has not been set")
1175
        if ( $GBE_NOT_RELEASED );
1176
 
227 dpurdie 1177
    return "$GBE_VERSION [ Internal. Not an installed package ]"
1178
        if ( ! -f "$GBE_CORE/descpkg" );
1179
 
1180
    my $rec;
1181
    return $rec->{'VERSION_FULL'}
1182
        if ($rec = ReadDescpkg ( "$GBE_CORE/descpkg" ) );
1183
 
1184
    return "ERROR";
1185
}
1186
 
1187
#-------------------------------------------------------------------------------
1188
# Function        : print_version
1189
#
1190
# Description     :
1191
#
1192
# Inputs          :
1193
#
1194
# Returns         :
1195
#
1196
sub print_version
1197
{
1198
    #
1199
    #   Allow user to specify verboseness as an argument
1200
    #
1201
    foreach  ( @_ )
1202
    {
1203
        $GBE_VERBOSE++ if ( m/^-v/ );
1204
    }
1205
 
1206
    Message get_version();
1207
    Message "Internal: $GBE_VERSION" if ($GBE_VERBOSE);
1208
    $opr_done = 1;
283 dpurdie 1209
    return;
227 dpurdie 1210
}
1211
 
1212
 
1213
#-------------------------------------------------------------------------------
1214
#
1215
#   Give the user a clue
1216
#
1217
sub help
1218
{
1219
    my ($level) = @_;
1220
    $level = $opt_help unless ( $level );
1221
 
1222
    pod2usage(-verbose => 0, -message => "Version: ". get_version())  if ($level == 1 );
261 dpurdie 1223
    pod2usage(-verbose => $level - 1 );
227 dpurdie 1224
}
1225
 
1226
#-------------------------------------------------------------------------------
309 dpurdie 1227
# Function        : find_jats_dir
227 dpurdie 1228
#
309 dpurdie 1229
# Description     : Find a JATS build directory
1230
#                   Can be supressed with JATS '-here' command line option
227 dpurdie 1231
#
309 dpurdie 1232
# Inputs          : files               - Files to look for
1233
#                   options
1234
#                       --Ant           - Allow Ant files too
295 dpurdie 1235
#
309 dpurdie 1236
# Returns         : Will not return if not found
1237
#                   Will 'cd' to the build directory
1238
#
227 dpurdie 1239
sub find_jats_dir
1240
{
309 dpurdie 1241
    my $allow_ant;
1242
    my @FILES;
1243
    my $DIR;
1244
    my $check_file;
1245
 
227 dpurdie 1246
    #
1247
    #   Autodetect suppressed ?
1248
    #
1249
    return if ( $opt_here );
1250
 
309 dpurdie 1251
    #
1252
    #   Collect options
1253
    #   Collect the rest of the arguments
1254
    #
1255
    foreach ( @_ )
1256
    {
1257
        if ( m/^--Ant/ ) {
1258
            $allow_ant = 1;
1259
        }
1260
        else {
1261
            push @FILES, $_;
1262
        }
1263
    }
1264
 
227 dpurdie 1265
    push @FILES, @BUILD_FILE_ALT;
309 dpurdie 1266
    push @FILES, 'build.xml' if ( $allow_ant );
1267
 
1268
    #
1269
    #   Parent directories to search
1270
    #   Child dirs to search
1271
    #
227 dpurdie 1272
    my @SEARCH = qw( . .. ../.. ../../.. );
309 dpurdie 1273
    my @CHILD  = ('', '/jats', '/build', '/build/jats' );
227 dpurdie 1274
 
1275
    #
1276
    #   Locate the JATS build files
1277
    #   Allow the user to be in a number of parent directories
1278
    #
309 dpurdie 1279
    scan:
227 dpurdie 1280
    for my $ROOTDIR (@SEARCH)
1281
    {
309 dpurdie 1282
        for my $SUBDIR (@CHILD)
227 dpurdie 1283
        {
309 dpurdie 1284
            $DIR = $ROOTDIR . $SUBDIR;
227 dpurdie 1285
            next unless -d $DIR;
1286
 
283 dpurdie 1287
            for my $FILE ( @FILES)
227 dpurdie 1288
            {
309 dpurdie 1289
                $check_file = $DIR . '/' . $FILE;
227 dpurdie 1290
                Verbose2 ("Check for: $check_file");
309 dpurdie 1291
                last scan if ( -f $check_file );
1292
            }
1293
 
1294
            next unless ( $allow_ant );
1295
            foreach ( glob($DIR . '/*depends.xml' ) )
1296
            {
1297
                Verbose2 ("Check for: $_");
1298
                if ( m/(.+)depends.xml/ )
227 dpurdie 1299
                {
309 dpurdie 1300
                    $check_file = "$1.xml";
1301
                    last scan if ( -f $check_file );
227 dpurdie 1302
                }
1303
            }
1304
        }
309 dpurdie 1305
        $DIR = '';
227 dpurdie 1306
    }
309 dpurdie 1307
 
1308
    #
1309
    #   Change to the build directory if one has been found
1310
    #
1311
    if ( $DIR )
1312
    {
1313
        Verbose2 ("Found check file: $check_file");
1314
        change_dir ( $DIR );
1315
    }
1316
    else
1317
    {
1318
        Error ( 'JATS build directory not found.',
1319
                "Cannot locate: @FILES",
1320
                $allow_ant ? 'or Ant <Package>.xml <Package>depends.xml pair' : undef,
1321
                'Use -here option to supress this test'
1322
                );
1323
    }
227 dpurdie 1324
}
1325
 
1326
#-------------------------------------------------------------------------------
1327
#
295 dpurdie 1328
#   Determine the real build file to use
1329
#   Will select from a list of known build files.
227 dpurdie 1330
#
295 dpurdie 1331
sub getBuildFile
227 dpurdie 1332
{
1333
    my $build_file = $BUILD_FILE;
1334
    #
1335
    #   Use an alternative buildfile - if it exists
1336
    #   Do not use this file if the user has specified a buildfile
1337
    #
1338
    unless ( $BUILD_FILE_SET )
1339
    {
1340
        Verbose ("Search for alternate build file");
1341
        foreach my $test_file ( @BUILD_FILE_ALT )
1342
        {
1343
            Verbose2 ("Search for alternate build file: $test_file");
1344
            if ( -f $test_file )
1345
            {
1346
                $build_file = $test_file;
1347
                Message ("=== USING ALTERNATE BUILDFILE: $build_file ===");
1348
                last;
1349
            }
1350
        }
1351
    }
295 dpurdie 1352
   return $build_file;
1353
}
227 dpurdie 1354
 
295 dpurdie 1355
#-------------------------------------------------------------------------------
1356
#
1357
#   Kick off the build process
1358
#
1359
sub build
1360
{
1361
    my $build_file = $BUILD_FILE;
1362
    (my $name = $CWD) =~ s~^.*/~~ ;
1363
    $opr_done = 1;
1364
 
1365
    find_jats_dir($build_file);
1366
    Message ("=== Building $name ===");
1367
    $build_file = getBuildFile();
1368
 
227 dpurdie 1369
    #
1370
    #   Jats/make does not handle file systems with spaces in the path names
1371
    #
1372
    Error('$CWD path cannot contain spaces') if ( $CWD =~ m/\s/ );
1373
 
1374
    $RESULT = System ($GBE_PERL, $build_file, $CWD, "$GBE_TOOLS/buildlib.pl", "--project", @_ );
1375
 
283 dpurdie 1376
    Message ("=== Build $name NOT complete ===") if     ( $RESULT  );
1377
    Message ("=== Build $name complete ===")     unless ( $RESULT );
227 dpurdie 1378
    return $RESULT
1379
}
1380
 
1381
#-------------------------------------------------------------------------------
1382
# Function        : bmake_it
1383
#
1384
# Description     : Combo build and make operations
1385
#
1386
# Inputs          : ...     - COMMANDS or Make arguments.
1387
#                             Key commands are BUILD and INSTALL
1388
#
1389
# Returns         : RESULT code
1390
#
1391
sub bmake_it
1392
{
1393
    my @make_args = @_;
1394
    my $all = 1;
1395
    my $msg;
1396
    $opr_done = 1;
1397
 
1398
    if ( $make_args[0] && $make_args[0] eq 'NOTALL' )
1399
    {
1400
        $all = 0;
1401
        shift @make_args;
1402
    }
1403
    elsif ( $make_args[0] && $make_args[0] eq 'BUILD' )
1404
    {
1405
        Verbose ("Makeit build") ;
1406
        $msg = "Component not built";
1407
        build();
1408
        shift @make_args;
1409
    }
1410
 
1411
    unless ( $RESULT )
1412
    {
1413
        push @make_args, '-default=all' if ( $all );
1414
        Verbose ("Makeit make @make_args") ;
1415
 
309 dpurdie 1416
        find_jats_dir( 'makefile.pl', 'Makefile.gbe', $BUILD_FILE );
227 dpurdie 1417
        Error ("No Makefile.gbe file found") unless ( -f 'Makefile.gbe' );
1418
 
1419
        etool ( 'jmake.pl', @make_args );
1420
        $msg = "Component not made";
1421
        @make_args = ();
1422
    }
1423
 
1424
 
1425
    Verbose ("Makeit Result: $RESULT") ;
1426
    Error ( $msg ) if ( $RESULT );
1427
    return  if ( $RESULT );
1428
}
1429
 
1430
#-------------------------------------------------------------------------------
1431
# Function        : dev_expand
1432
#
1433
# Description     : Expand the users arguments to the "debug/prod" command
1434
#                   "debug/prod" builds and packages debug stuff
1435
#
1436
#                   Ignore make options.
1437
#
1438
# Inputs          : target
1439
#                   Argument list
1440
#
1441
# Returns         : expanded argument list
1442
#
1443
sub dev_expand
1444
{
1445
    my @resultd;
1446
    my @resultp;
1447
    my @args;
1448
    my @opts;
1449
 
1450
    #
1451
    #   Remove options from the argument list
1452
    #
1453
    foreach ( @_ )
1454
    {
1455
        if ( m~=~ || m~^-~ ) {
1456
            push @opts, $_;
1457
        } else {
1458
            push @args, $_;
1459
        }
1460
    }
1461
 
1462
    my $target = shift @args;
1463
    my @cmd = $target;
1464
    if ( $#args < 0 )
1465
    {
1466
        push @cmd, "package_$target";
1467
    }
1468
    else
1469
    {
1470
        foreach ( @args )
1471
        {
1472
            push @resultd, $_ . "_$target";
1473
            push @resultp, $_ . "_package_$target";
1474
            @cmd = ();
1475
        }
1476
    }
1477
 
1478
    return (@cmd, @resultd, @resultp, @opts);
1479
}
1480
 
1481
#-------------------------------------------------------------------------------
1482
# Function        : install_pkg
1483
#
1484
# Description     : Install the built package into local_dpkg_archive
1485
#                   This will make it available for use, without populating the
1486
#                   global archive
1487
#
1488
#                   This is done through an external utility to maintain
1489
#                   consistent interface
1490
#
1491
sub install_pkg
1492
{
1493
 
309 dpurdie 1494
    find_jats_dir($BUILD_FILE, '--Ant');
227 dpurdie 1495
    etool ( 'create_dpkg.pl', '-archive=local', '-quiet', '-override',  @_ );
1496
}
1497
 
1498
#-------------------------------------------------------------------------------
1499
# Function        : create_dpkg
1500
#
1501
# Description     : Install a package into the main dpkg_archive
1502
#                   This is done through an external utility to maintain
1503
#                   consistent interface
1504
#
1505
#                   This function is simply an easy way to access the utility
1506
 
1507
sub create_dpkg
1508
{
309 dpurdie 1509
    find_jats_dir($BUILD_FILE, '--Ant');
227 dpurdie 1510
    etool ( 'create_dpkg.pl',  @_ );
1511
}
1512
 
1513
#-------------------------------------------------------------------------------
1514
# Function        : etool
1515
#
1516
# Description     : Invoke an external tool program written in PERL
1517
#
1518
# Arguments       : $1  Name of the program to run
1519
#                       With optional .pl suffix
1520
#                   $2+ Program arguments
1521
#
1522
sub etool
1523
{
1524
    my $command = shift;
1525
    my $cmd;
1526
    my @etool_path = ( "$ENV{'GBE_TOOLS'}",
1527
                       "$ENV{'GBE_TOOLS'}/DEPLOY",
1528
                       "$ENV{'GBE_TOOLS'}/LOCAL" );
1529
    if ( $command )
1530
    {
1531
        #
1532
        #   Locate a potential tool
1533
        #   These will have the user name or a .pl extension
1534
        #
1535
        ETOOL_SEARCH:
1536
        foreach my $ext ( '', '.pl' )
1537
        {
1538
            foreach my $dir ( @etool_path )
1539
            {
297 dpurdie 1540
                $cmd = "$dir/jats_$command$ext";
1541
                last ETOOL_SEARCH if ( -f $cmd );
1542
 
227 dpurdie 1543
                $cmd = "$dir/$command$ext";
1544
                last ETOOL_SEARCH if ( -f $cmd );
1545
            }
1546
            $cmd='';
1547
        }
1548
 
1549
        Error ("Tool not found: $command", "Search path:", @etool_path) unless $cmd;
1550
        $RESULT = System ( $GBE_PERL, $cmd, @_ );
1551
    }
1552
    else
1553
    {
1554
        #
1555
        #   Display on the .pl commands
1556
        #
1557
        display_commands("Available Tools", \@etool_path, ['*.pl'] );
1558
    }
1559
 
1560
    $opr_done = 1;
1561
}
1562
 
1563
#-------------------------------------------------------------------------------
1564
# Function        : ebin
1565
#
1566
# Description     : Invoke an external JATS provided binary
1567
#                   within the JATS toolset
1568
#
1569
# Arguments       : $1  Name of the program to run
1570
#                   $2+ Program arguments
1571
#
1572
sub ebin
1573
{
1574
    my $command = shift;
1575
    my $cmd;
1576
    my @ebin_path = ( "$GBE_BIN" );
1577
 
1578
    if ( $command )
1579
    {
1580
        #
1581
        #   Locate a potential executable
1582
        #   This
1583
        #
1584
        ETOOL_SEARCH:
1585
        foreach my $ext ( '', '.exe', '.sh' )
1586
        {
1587
            foreach my $dir ( @ebin_path )
1588
            {
1589
                $cmd = "$dir/$command$ext";
1590
                last ETOOL_SEARCH if ( -f $cmd );
1591
            }
1592
            $cmd='';
1593
        }
1594
 
1595
        Error ("Program not found: $command", "Search path:", @ebin_path) unless $cmd;
1596
        $RESULT = System ( $cmd, @_ );
1597
    }
1598
    else
1599
    {
1600
        #
1601
        #   Display a list of programs
1602
        #
1603
        display_commands("Available Programs", \@ebin_path, ['*'] );
1604
    }
1605
 
1606
    $opr_done = 1;
1607
}
1608
 
1609
#-------------------------------------------------------------------------------
1610
# Function        : eprog
1611
#
1612
# Description     : Invoke an external program
1613
#                   Will detect local .pl files and execute them
1614
#                   Will detect local .jar files and execute them
229 dpurdie 1615
#                   Will detect local .bat files and execute them
227 dpurdie 1616
#
1617
# Arguments       : $1  Name of the program to run
1618
#                   $2+ Program arguments
1619
#
1620
sub eprog
1621
{
229 dpurdie 1622
    Verbose ("eprog: @_");
315 dpurdie 1623
    my $name = fix_command_name (shift @_);
227 dpurdie 1624
    Error ("eprog. No program specified") unless ( $name );
1625
 
229 dpurdie 1626
    $name .= ".pl"     if ( -f "${name}.pl" );
1627
    $name .= ".jar"    if ( -f "${name}.jar" );
1628
    $name .= ".bat"    if ( -f "${name}.bat" );
227 dpurdie 1629
 
229 dpurdie 1630
    #
245 dpurdie 1631
    #   On Windows programs in the CWD will be found
1632
    #   Mimic this behaviour on Unix
229 dpurdie 1633
    #
1634
    $name = "./$name" if ( $name !~ m~/~ && -f "./$name");
1635
 
227 dpurdie 1636
    if ( $name =~ m~\.pl$~ ) {
1637
        $RESULT = System ( $GBE_PERL, $name, @_ );
1638
 
1639
    } elsif ( $name =~  m~\.jar$~ ) {
1640
        $RESULT = System ( "$JAVA_HOME/bin/java", '-jar', $name, @_);
1641
 
1642
    } else {
229 dpurdie 1643
        #
1644
        #   Ensure .bat files are pathed with \, and not / characters
1645
        #   The windows command interpreter does not like /
1646
        #
1647
        $name =~ s~/~\\~g if ( $name =~ m~\.bat$~ );
1648
 
227 dpurdie 1649
        $RESULT = System ( $name, @_ );
1650
    }
1651
 
1652
    $opr_done = 1;
1653
}
1654
 
1655
#-------------------------------------------------------------------------------
1656
# Function        : display_commands
1657
#
1658
# Description     : Display a list of commands from a specified list of dirs
1659
#                   Internal helper function
1660
#
1661
# Inputs          : $title      - Display header
1662
#                   $ref_path   - Ref to an array that contains the search path
1663
#                   $ref_ext    - Ref to an array of valid patterns
1664
#
1665
# Returns         : Nothing
1666
#
1667
sub display_commands
1668
{
1669
    my ( $title, $ref_path, $ref_ext ) = @_;
1670
 
1671
    #
1672
    #   Display a list of commands
1673
    #
1674
    my %list;
1675
    foreach ( @$ref_path )
1676
    {
1677
        foreach my $ext ( @$ref_ext )
1678
        {
1679
            foreach my $file (  glob( "$_/$ext") )
1680
            {
1681
                $file =~ s~.*/~~ unless $GBE_VERBOSE;
1682
                $list{$file} = 1;
1683
            }
1684
        }
1685
    }
1686
 
1687
    my $count = 0;
1688
    my $limit = $GBE_VERBOSE ? 1 : 3;
1689
    print "$title:\n";
1690
    foreach ( sort keys %list )
1691
    {
1692
        printf "%-26s", $_;
1693
        print "\n" if ( !( ++$count % $limit) );
1694
    }
1695
}
1696
 
1697
#-------------------------------------------------------------------------------
315 dpurdie 1698
# Function        : fix_command_name
1699
#
1700
# Description     : Fix a command name parameter
1701
#                   Simplify use of cygwin for some users by allowing
1702
#                   that path of external tools to be a cygwin path
1703
#
1704
# Inputs          : cmd             - command
1705
#
1706
# Returns         : cleaned up version of cmd
1707
#
1708
sub fix_command_name
1709
{
1710
    my ($cmd) = @_;
1711
 
1712
    unless ( $GBE_UNIX )
1713
    {
1714
        #
1715
        #   Cygwin kludge
1716
        #       Replace /cygdrive/DriveLetter/ - with DriveLetter:/
1717
        #       Replace /DriveLetter/          - With DriveLetter:/
1718
        #
1719
        $cmd =~ s~^/cygdrive/([A-Z])/(.*)~$1:/$2~i;
1720
        $cmd =~ s~^/([A-Z])/(.*)~$1:/$2~i;
1721
    }
1722
    return $cmd;
1723
}
1724
 
1725
 
1726
#-------------------------------------------------------------------------------
227 dpurdie 1727
# Function        : run_ant
1728
#
1729
# Description     : Invoke ant
1730
#                   If the current directory looks like an ERG build system, then
1731
#                   create and maintain an auto.xml file. Otherwise simply invoke ant
1732
#
1733
# Inputs          : $1+ program arguments
1734
#
1735
sub run_ant
1736
{
1737
    my $JAVA_HOME = $ENV{JAVA_HOME} || Error ("JAVA_HOME is not defined in the environment");
1738
    my $ANT_HOME  = $ENV{ANT_HOME}  || Error ("ANT_HOME is not defined in the environment" );
1739
 
1740
    #
1741
    #   Detect an ERG formatted build
1742
    #   This will have two files <projectname>.xml and <projectname>depends.xml
1743
    #   Create the 'auto.xml' file only if its not present
1744
    #
1745
    my @ant_arg;
1746
    my @flist;
1747
    my $basename = '';
235 dpurdie 1748
    my $scanner = '*depends.xml';
227 dpurdie 1749
 
1750
    #
1751
    #   Use specified build file to resolve multiple names
1752
    #   Strip any trailing depends.xml to make it user friendly
1753
    #
1754
    if ( $BUILD_FILE_SET )
1755
    {
1756
        $basename = $BUILD_FILE;
1757
        $basename =~ s~\.xml$~~;
1758
        $basename =~ s~depends$~~;
235 dpurdie 1759
        $scanner = "${basename}depends.xml";
227 dpurdie 1760
        Verbose ("Using buildfile: $basename");
1761
    }
1762
 
235 dpurdie 1763
    my @buildlist = glob($scanner);
227 dpurdie 1764
    foreach ( @buildlist )
1765
    {
1766
        if ( m/(.+)depends.xml/ )
1767
        {
1768
            my $pname = $1;
1769
            push @flist, $pname if ( -f "$pname.xml" );
1770
        }
1771
    }
1772
 
1773
    if ( $#flist >= 0 )
1774
    {
1775
        Error ("Multiple depends.xml files found:", @flist,
297 dpurdie 1776
               "Use 'jats -buildfile=name ant ...' to resolve") if ( $#flist > 0 );
227 dpurdie 1777
 
1778
        my $depend = "$flist[0]depends.xml";
1779
        @ant_arg = ('-f', "$flist[0].xml");
1780
 
1781
        Message ("Ant using projectfiles: $flist[0].xml");
1782
 
1783
        #
1784
        #   Check for depends.xml newer than auto.xml.
1785
        #
1786
        my $auto_timestamp   = (stat('auto.xml'))[9] || 0;
1787
        my $depend_timestamp = (stat($depend))[9];
1788
        if ( $depend_timestamp > $auto_timestamp )
1789
        {
1790
            Message ("Creating: auto.xml");
1791
            copy( $depend, 'auto.xml' );
1792
            chmod 0777, 'auto.xml';
1793
        }
1794
    }
1795
    elsif ( $BUILD_FILE_SET  )
1796
    {
1797
        Error ("Specified build file pair not found:", $basename, $basename . "depends.xml");
1798
    }
1799
 
1800
    #
1801
    #   The ant provided startup scripts don't return an exit code under
1802
    #   windows. Invoke ant directly
1803
    #
1804
    launch_ant ( $JAVA_HOME, $ANT_HOME, @ant_arg, @_ );
1805
    $opr_done = 1;
1806
}
1807
 
1808
#-------------------------------------------------------------------------------
1809
# Function        : run_abt
1810
#
1811
# Description     : Invoke auto build tool (older form)
1812
#                   Options for the ABT
1813
#                       --Java=x.x
1814
#                   Invoke ANT for the ABT using a specified version of Java
1815
#                   Do not play with the user environment.
297 dpurdie 1816
#                   Don't stick java path into environment
227 dpurdie 1817
#
1818
# Inputs          : $1+ program arguments
1819
#
1820
sub run_abt
1821
{
279 dpurdie 1822
    my $ABT_JAVA = 'JAVA_HOME_1_6';         # Default version for the ABT
227 dpurdie 1823
    my $JAVA_HOME = $ENV{$ABT_JAVA};
1824
    my $ANT_HOME  = $ENV{ANT_HOME};
1825
    my @abt_arg;
239 dpurdie 1826
    my $buildfile = 'build.xml';
227 dpurdie 1827
 
1828
    ErrorConfig( 'name'    => 'JATS ABT' );
1829
 
1830
    #
239 dpurdie 1831
    #   Use the user specified buildfile
1832
    #
1833
    $buildfile = $BUILD_FILE
1834
        if ( $BUILD_FILE_SET );
1835
 
1836
    #
227 dpurdie 1837
    #   Extract known options
1838
    #
1839
    foreach  ( @_ )
1840
    {
1841
        if ( m/-java=(.*)/ ) {
1842
            $JAVA_HOME = get_java_home($1);
239 dpurdie 1843
 
1844
        } elsif ( m/^-buildfile=(.+)/ ) {
1845
            $buildfile = $1;
1846
 
227 dpurdie 1847
        } else {
1848
            push @abt_arg, $_;
1849
        }
1850
    }
1851
 
1852
    Error ("$ABT_JAVA is not defined in the environment") unless $JAVA_HOME;
1853
    Error ("ANT_HOME is not defined in the environment" ) unless $ANT_HOME;
239 dpurdie 1854
    Error ("Ant buildfile not found: $buildfile" ) unless (-f $buildfile);
227 dpurdie 1855
 
1856
    #
239 dpurdie 1857
    #   Insert correct build file arguments
1858
    #
279 dpurdie 1859
    push @abt_arg, '-buildfile', $buildfile;
1860
 
1861
    #
1862
    #   Add current directory as java library directory, but only if
1863
    #   it contains JAR files.
1864
    #
1865
    push @abt_arg, '-lib', $CWD
1866
        if ( glob ('*.jar') );
239 dpurdie 1867
 
1868
    #
227 dpurdie 1869
    #   Use the ant-launcher to invoke ant directly
1870
    #
1871
    launch_ant ( $JAVA_HOME, $ANT_HOME, @abt_arg );
1872
    $opr_done = 1;
1873
}
1874
 
1875
#-------------------------------------------------------------------------------
1876
# Function        : launch_ant
1877
#
1878
# Description     : Start ANT - with sanity checking
1879
#
1880
# Inputs          : JAVA_HOME
1881
#                   ANT_HOME
1882
#                   @user_args
1883
#
1884
# Returns         : Result Code
1885
#
1886
sub launch_ant
1887
{
1888
    my ($JAVA_HOME, $ANT_HOME, @user_args ) = @_;
1889
 
1890
    Error ("Directory not found: $JAVA_HOME") unless ( -d "$JAVA_HOME" );
1891
    Error ("Program not found: $JAVA_HOME/bin/java") unless ( -e "$JAVA_HOME/bin/java" || -e "$JAVA_HOME/bin/java.exe" );
1892
    Error ("Jar not found: $ANT_HOME/lib/ant-launcher.jar") unless ( -e "$ANT_HOME/lib/ant-launcher.jar" );
1893
    Error ("Directory not found: $ANT_HOME") unless ( -d "$ANT_HOME" );
1894
    Error ("Directory not found: $ANT_HOME/lib") unless ( -d "$ANT_HOME/lib" );
1895
 
1896
    #
1897
    #   Use the ant-launcher to invoke ant directly
1898
    #
1899
    $RESULT = System ( "$JAVA_HOME/bin/java",
1900
                       "-classpath","$ANT_HOME/lib/ant-launcher.jar",
1901
                       "-Dant.home=$ANT_HOME",
1902
                       "org.apache.tools.ant.launch.Launcher",
1903
                       "-lib","$ANT_HOME/lib",
1904
                       @user_args
1905
                       );
1906
 
1907
   return $RESULT;
1908
}
1909
 
1910
 
1911
#-------------------------------------------------------------------------------
1912
#
1913
#   Cleanup the sandbox
1914
#   Perform a "make clobber" then a "build clobber"
1915
#
1916
sub clobber
1917
{
1918
    Message ("=== Removing ======");
1919
    find_jats_dir( $BUILD_FILE );
295 dpurdie 1920
    my $build_file = getBuildFile();
1921
 
227 dpurdie 1922
 
1923
    #
1924
    #   Run a "make clobber" to clean out "everything"
1925
    #
1926
    etool ( 'jmake.pl', 'clobber' )
1927
        if ( -f "Makefile.gbe" );
1928
 
295 dpurdie 1929
    if ( -f $build_file )
227 dpurdie 1930
    {
295 dpurdie 1931
        System ( $GBE_PERL, $build_file, $CWD, "$GBE_TOOLS/buildlib.pl", 'clobber' );
227 dpurdie 1932
    }
1933
    else
1934
    {
1935
        Error ("Cannot clobber. No buildfile found");
1936
    }
1937
 
1938
    Message ("=== Remove complete ===");
1939
    $opr_done = 1;
1940
}
1941
 
1942
#-------------------------------------------------------------------------------
1943
# Function        : do_exit
1944
#
1945
# Description     : Common exit point so that time information can be displayed
1946
#
1947
# Inputs          : Optional exit code
1948
#
1949
# Returns         :
1950
#
1951
sub do_exit
1952
{
1953
    my ($ecode) = @_;
1954
 
1955
    $RESULT = $ecode if ( $ecode );
1956
 
1957
    #..
1958
    #   Determine the runtime
1959
    #
1960
    if ( $opt_time )
1961
    {
1962
        my ($TIMEU, $TIMES) = times;
1963
        $TIMER = time - $TIMER;
1964
        my ($m, $s );
1965
 
1966
        $m = int($TIMER / 60);
1967
        $s = $TIMER - ($m * 60);
1968
 
1969
        Message ( "Times: Real: $m:$s, User: $TIMEU, System: $TIMES");
1970
    }
1971
    #.
1972
    #   Make sure that any important exit code is passed to the user
1973
    #
1974
    Verbose ("ExitCode: $RESULT");
1975
    exit $RESULT;
1976
}
1977
 
1978
########################################################################
1979
#
1980
#   Main body of the script
1981
#
1982
#   Process help and manual options
1983
#       Done after all the setup to ensure that the PATH is correct
1984
#       Done before bombout to give user a chance
1985
#
1986
help() if $opt_help;
1987
ErrorDoExit();  # Exit if any error in setup
1988
ErrorConfig( 'on_exit'    => \&do_exit );
1989
 
1990
#
231 dpurdie 1991
#   Reset operational flags.
1992
#   May have been used by setup
1993
#
1994
$opr_done = 0;
1995
$RESULT = 0;
1996
 
1997
#
227 dpurdie 1998
#   Process user commands
1999
#
263 dpurdie 2000
my $cmd = shift @ARGV || help(1);
227 dpurdie 2001
 
2002
print_version(@ARGV)                    if ( $cmd =~ m/^ver/ );
2003
 
2004
clobber                                 if ( $cmd =~ m/^clobber$/ );
2005
build    (@ARGV)                        if ( $cmd =~ m/^build$/ );
2006
 
2007
bmake_it ('NOTALL', @ARGV)              if ( $cmd =~ m/^[x]*make$/ );
2008
bmake_it (@ARGV)                        if ( $cmd =~ m/^go$/ );
2009
bmake_it (dev_expand('debug', @ARGV) )  if ( $cmd =~ m/^debug$/ );
2010
bmake_it (dev_expand('prod', @ARGV) )   if ( $cmd =~ m/^prod$/ );
2011
bmake_it ("clean", @ARGV)               if ( $cmd =~ m/^clean$/ );
2012
bmake_it ("rebuild", @ARGV)             if ( $cmd =~ m/^rebuild$/ );
2013
bmake_it ('BUILD', @ARGV)               if ( $cmd =~ m/^all$/ );
2014
bmake_it ($cmd, @ARGV )                 if ( $cmd =~ m/^run_unit_tests/ );
2015
 
2016
install_pkg(@ARGV)                      if ( $cmd =~ m/^install$/ );
2017
create_dpkg(@ARGV)                      if ( $cmd =~ m/^create_dpkg$/ );
2018
 
2019
ebin  (@ARGV)                           if ( $cmd =~ m/^ebin/ );
2020
etool (@ARGV)                           if ( $cmd =~ m/^etool/ );
2021
eprog (@ARGV)                           if ( $cmd =~ m/^eprog$/ );
2022
run_ant (@ARGV)                         if ( $cmd =~ m/^ant$/ );
2023
run_abt (@ARGV)                         if ( $cmd =~ m/^abt$/ );
2024
 
299 dpurdie 2025
etool ('cache_dpkg', @ARGV)                         if ( $cmd =~ m/^dpkg/ );
2026
etool ('gen_msprojects', @ARGV)                     if ( $cmd =~ m/^gen_msproject/ );
2027
etool ('jats_ccrelease.pl', @ARGV)                  if ( $cmd =~ m/^cbuild/ );
2028
etool ('jats_ccrelease.pl', @ARGV)                  if ( $cmd =~ m/^release/ );
2029
etool ('jats_ccrelease.pl', '-extractfiles' ,@ARGV) if ( $cmd =~ m/^extractf/ );
2030
etool ('jats_ccrelease.pl', '-extract' ,@ARGV)      if (!$opr_done && $cmd =~ m/^extract/ );
2031
etool ('jats_label', @ARGV)                         if ( $cmd =~ m/^label$/ );
2032
etool ('jats_sandbox', @ARGV)                       if ( $cmd =~ m/^sandbox$/ );
313 dpurdie 2033
etool ('jats_help', @ARGV)                          if ( $cmd =~ m/^help$/ );
315 dpurdie 2034
etool ('jats_vars.pl', @ARGV)                       if ( $cmd =~ m/^var/ );
227 dpurdie 2035
 
2036
etool ($cmd, @ARGV)                     unless ($opr_done); # Pass to etool if not known
2037
 
2038
do_exit();
2039
#.
2040
 
2041
#-------------------------------------------------------------------------------
2042
#   Documentation
2043
#
2044
 
2045
=pod
2046
 
2047
=head1 NAME
2048
 
2049
jats - JATS utility interface tool
2050
 
2051
=head1 SYNOPSIS
2052
 
277 dpurdie 2053
 Usage: jats [opts] command [cmd-options]
227 dpurdie 2054
 
2055
 Where opts:
261 dpurdie 2056
    -h, -h -h, -man=[n] - Help messages with increasing verbosity
227 dpurdie 2057
    -cd dir             - Change to specified directory
2058
    -b file             - Use alternate build file
261 dpurdie 2059
    -verbose[=n]        - Verbose operation
2060
    -debug[=n]          - Enable debug mode of JATS scripts
227 dpurdie 2061
    -here               - Disable JATS auto locate of build.pl
2062
    -locate             - Locate build.pl file and change to directory
245 dpurdie 2063
    -locatepkg=pkg      - Locate build.pl. Resolve multiple files via pkg
227 dpurdie 2064
    -locatefile=file    - Locate specified file and change to directory
2065
    -platform=[name]    - Set GBE_PLATFORM to name   (=+ to append)
2066
    -buildfilter=[xxx]  - Set GBE_BUILDFILTER to xxx (=+ to append)
2067
    -abt=[xxx]          - Set GBE_ABT to xxx (=+ to append)
2068
    -java=version       - Alters java version used (1.4, 1.5)
2069
    -time               - Time build and compile times
2070
    -version=xxx        - Use specified version of JATS
277 dpurdie 2071
    -[no]exportvars     - Export sanitised JATS EnvVars (default)
227 dpurdie 2072
 
2073
 Where command is one of:
2074
    build               - Rebuild the sandbox and makefiles
2075
    make                - Make one or more components
2076
    ant                 - Invoke an ant build
2077
    abt [-java=xxx]     - Invoke the auto build tool
2078
    install             - Install package into local_dpkg_archive
2079
    help                - Display help message
2080
    vars                - Display JATS related environment variables
2081
 
2082
    create_dpkg         - Install a package into main dpkg_archive
2083
    label               - Labelling functions
2084
    release             - Build a release from a clearcase label
2085
    extract             - Extract a release from a clearcase label
2086
    dpkg_cache          - Maintain a dpkg cache
2087
    gen_msproject       - Generate MSVC project files
299 dpurdie 2088
    sandbox             - Run Sanbox utility
2089
 
227 dpurdie 2090
    etool name          - Run internal tool
2091
    eprog name          - Run external tool
2092
    ebin name           - Run JATS binary tool
2093
 
2094
 Shortcut commands. Composites of basic commands
2095
    all [opt]           - Same as a "build" and "make all"
2096
    go  [opt]           - Same as a "make all"
2097
    debug [tgt]         - Same as "make debug package_debug"
2098
    prod  [tgt]         - Same as "make prod package_prod"
2099
    clean               - Same as "make clean"
2100
    clobber             - Same as "build clobber"
2101
    *                   - Unknown commands are treated as arguments to etool
2102
 
2103
 Where [cmd-options] are command specific.
2104
 Try "jats command -help" for details
2105
 
2106
=head1 OPTIONS
2107
 
2108
=over 8
2109
 
2110
=item B<-help>
2111
 
2112
Print a brief help message and exits.
2113
 
2114
=item B<-help -help>
2115
 
2116
Print a detailed help message with an explanation for each option.
2117
 
261 dpurdie 2118
=item B<-man[=n]>
227 dpurdie 2119
 
2120
Prints the manual page and exits.
2121
 
261 dpurdie 2122
If a numeric manual level is provide then it will be used to control the
2123
verbosity of help provided. This should be inthe range of 1 to 3.
2124
 
227 dpurdie 2125
=item B<-b file> B<-buildfile file>
2126
 
2127
This option modifies the operation of the "build" command. The command will
2128
use the specified file instead of the normal build.pl file.
2129
 
2130
=item B<-cd dir> B<-changedir dir>
2131
 
2132
This option will change to specified directory before the command is invoked.
2133
 
261 dpurdie 2134
=item B<--verbose[=n]>
227 dpurdie 2135
 
2136
This option will increase the level of verbosity of the JATS command and command
261 dpurdie 2137
invoked by the JATS shell.
227 dpurdie 2138
 
261 dpurdie 2139
If an argument is provided, then it will be used to set the level, otherwise the
2140
existing level will be incremented. This option may be specified multiple times.
227 dpurdie 2141
 
261 dpurdie 2142
=item B<-debug[=n]>
2143
 
227 dpurdie 2144
This option will increase the level of debug output of the JATS command and command
261 dpurdie 2145
invoked by the JATS shell.
227 dpurdie 2146
 
261 dpurdie 2147
If an argument is provided, then it will be used to set the level, otherwise the
2148
existing level will be incremented. This option may be specified multiple times.
2149
 
227 dpurdie 2150
=item B<-here>
2151
 
2152
This option will disable the "autolocate" mechanism of the JATS shell script.
2153
 
2154
By default JATS will "hunt" for a suitable "build.pl" or "makefile.pl" before
2155
executing a build or a make command. JATS will look in the following directories
2156
for a  suitable file. Under some conditions this mechanism is not useful.
2157
 
2158
By default JATS will hunt in the following directories: "." "jats" "build/
2159
jats" ".." "../.." and "../../..".
2160
 
2161
=item B<-locate>
2162
 
2163
This option will cause the JATS wrapper script to locate the build.pl file and
2164
then change to that directory. This allows users to locate the build root of
2165
a project and then issue other JATS commands.
2166
 
2167
If the B<-c> option is also specified then searching will start in the specified
2168
directory.
2169
 
2170
If an alternate build file is specified with the B<-b> option then that filename
2171
will be used in the location process.
2172
 
2173
This option implies a B<-here>. No further scanning will be done.
2174
 
2175
Exactly one build file must be located. If more than buildfile is located then
2176
the locations of the build files is displayed and JATS will terminate.
2177
 
245 dpurdie 2178
 
2179
=item B<-locatepkg=packagename>
2180
 
2181
This option is similar to the B<-locate> option, but it allows the required
2182
build files to be located by ensuring that the required buildfile builds the
2183
specified package.
2184
 
2185
There are two forms in which the B<packagename> can be specified. It can be
2186
specified as a full package name and vesrion, or as a package name and the
2187
project suffix. ie: jats-api.1.0.0000.cr or jats-api.cr
2188
 
227 dpurdie 2189
=item B<-locatefile=file>
2190
 
2191
This option is similar to the B<-locate> option, but it allows the name of the
2192
file to be located to be specified.
2193
 
2194
=item B<-platform=[name]>
2195
 
2196
This option will set the JATS specific environment variable GBE_PLATFORM to
2197
the specified name. The existing value of GBE_PLATFORM may be extended by
2198
using "=+".
2199
 
2200
In practice the GBE_PLATFORM variable is of little use. The same effect can be
2201
achieved directly with make targets or with GBE_BUILDFILTER.
2202
 
2203
=item B<-buildfilter=[xxx]>
2204
 
2205
This option will set the JATS specific environment variable GBE_BUILDFILTER to
2206
the specified name. The existing value of GBE_BUILDFILTER may be extended by
2207
using "=+".
2208
 
2209
This option may be used to limit the initial build, and subsequent "make" to a
2210
limited set of platforms.
2211
 
2212
=item B<-abt=[xxx]>
2213
 
2214
This option will set the JATS specific environment variable GBE_ABT to
2215
the specified name The existing value of GBE_ABT may be extended by
2216
using "=+"..
2217
 
2218
This option is used to pass arguments directly to some tools within the
2219
(ABT) Auto Build Tool framework, or to indicate that the build is being
2220
performed within the ABT framework.
2221
 
2222
=item B<-java=version>
2223
 
2224
This option will override the default java version used by the ant builds and
2225
passed to the underlying programs. The path to the Java SDK is determined from
2226
the environment using the version string replacing the '.' with '_'
2227
 
2228
eg: -java=1.5, will examine the environment for JAVA_HOME_1_5 and will set
2229
JAVA_HOME to that value. It will not setup the users PATH or classpath.
2230
 
2231
=item B<-time>
2232
 
2233
When this option is enabled the JATS script will report the runtime of the
2234
underlying, invoked, command.
2235
 
2236
=item B<-version=xxx>
2237
 
2238
When this option is invoked JATS will attempt to use the specified version to
2239
perform all processing. JATS will search the GBE_DPKG_LOCAL, GBE_DPKG_CACHE,
2240
GBE_DPKG, GBE_DPKG_STORE in order to locate the specified version of the package.
2241
 
2242
The entire command line will be passed to the JATS wrapper script within that
2243
version. This bypasses the jats.bat or jats.sh startup scripts.
2244
 
277 dpurdie 2245
JATS will attempt to transfer the target version to the local cache in an
2246
attempt to improve performance.
227 dpurdie 2247
 
277 dpurdie 2248
=item B<-[no]exportvars>
227 dpurdie 2249
 
277 dpurdie 2250
The default operation is to export sanitised and calculated values to the
2251
programs running under JATS. The use of NoExportVars will prevent JATS from
2252
exporting modified EnvVars into the environment. This may be required by
2253
processes, such as the build daemons that need to pick up the current version of
2254
JATS on the fly and not have it fixed when the daemon is started.
227 dpurdie 2255
 
2256
=back
2257
 
2258
=head1 ARGUMENTS
2259
 
2260
=head2 Basic Commands
2261
 
2262
The following commands are invoked directly by the JATS script to wrap the build
2263
tools in a controlled manner.
2264
 
2265
=over 8
2266
 
2267
=item B<build>
2268
 
2269
Build or rebuild the sandbox and makefiles.
2270
 
2271
This command must be used before the component can be "made" and when the
2272
contents of the "buildpl" file change. It is a common mistake to use the "build"
2273
command to much.
2274
 
2275
The script will hunt for a suitable build.pl file before running the build and
2276
make subcommands.
2277
 
2278
The build process has a large number of options. Use "JATS build help" to
2279
display the complete list.
2280
 
2281
=item B<make>
2282
 
2283
Make one or more components
2284
 
2285
This command will invoke a suitable "make" program on the makefile found in
2286
the current directory. This makefile should have been generated by JATS.
2287
 
2288
The make process has a large number of options. Use "JATS make help" to
2289
display the complete list.
2290
 
2291
=item B<ant>
2292
 
2293
This command will use ANT to build a component. JATS will determine the
2294
build.xml file to use with the following algorithm.
2295
 
2296
    If the files called <Project>depends.xml and <Project>.xml exist then JATS
2297
    will create an 'auto.xml' from the depends file, if one does not already
2298
    exist or is older than the depends.xml file and then use the <Project>.xml
2299
    file as the ant build file.
2300
 
2301
    Otherwise ant is invoked and it will expect a build.xml file.
2302
 
2303
If multiple <Project>depends.xml and <Project>.xml file pairs are found the
2304
command will fail. This can be resolved through the use of the -buildfile=name
2305
option.
2306
 
2307
Ant is invoked with the version of Java specified with the -Java=x.x option.
2308
 
2309
=item B<abt>
2310
 
2311
This command is used to invoke the Auto Build Tool. It will invoke ANT on the
2312
build.xml file in the current directory in such  manner as to not affect the
239 dpurdie 2313
environment of the programs running under ANT.
227 dpurdie 2314
 
245 dpurdie 2315
The remained of the command line is passed to the ABT, with the exception of
239 dpurdie 2316
the options:
2317
 
2318
=over 8
2319
 
2320
=item * -java=x.x. This is used to control the version of Java used by the
227 dpurdie 2321
ABT. The default is 1.5.
2322
 
239 dpurdie 2323
=item * -buildfile=name. This is used to provide a different build file to ant.
2324
The default build file is 'build.xml'.
2325
 
2326
=back
2327
 
227 dpurdie 2328
=item B<install>
2329
 
2330
This command will install a generated "package" into the local_dpkg_archive
2331
directory. This allows a group of packages to be tested before being published
2332
into the global dpkg_archive.
2333
 
2334
NOTE. This command is no longer needed. The "build" process will place a
2335
shortcut in the local_dpkg_archive to a components "pkg" directory. Other
2336
components will utilize this shortcut directly and pickup the package without
2337
the user needing to "install" the package - a step that can be forgotten.
2338
 
2339
=item B<help>
2340
 
2341
Display the basic help message.
2342
 
2343
=item B<vars [-v]>
2344
 
2345
This command will display all the JATS related environment variables in a
2346
readable form.
2347
 
2348
Additional information will be displayed if an argument of "-v" is provided.
2349
 
2350
=back
2351
 
2352
=head2 Extended Commands
2353
 
2354
The following commands support the build environment. They are supplemental to
2355
the build environment. They are implemented as extensions to the basic JATS
2356
command scripts.
2357
 
2358
=over 8
2359
 
2360
=item B<create_dpkg>
2361
 
2362
This command will install a generated package into main dpkg_archive. This
2363
command should not be used directly by a user as it does not ensure that package
2364
has been created in a repeatable manner - use "jats release".
2365
 
2366
=item B<label>
2367
 
2368
This command provides a number of useful labelling mechanisms to assist in the
2369
labeling of source code.
2370
 
2371
=item B<release>, B<cbuild>
2372
 
2373
This command allows a package to be built and released, given a Clearcase label.
2374
This is the desired release mechanism.
2375
 
2376
The command has two main uses:
2377
 
2378
=over 8
2379
 
2380
=item 1
2381
 
2382
Build a package for release. The process will ensure that the build is
2383
controlled and repeatable.
2384
 
2385
=item 2
2386
 
2387
Rebuild a package for test or debugging purposes.
2388
 
2389
=back
2390
 
2391
=item B<extract>
2392
 
2393
This is the same as "release -extract"
2394
 
2395
 
2396
=item B<dpkg_cache>
2397
 
2398
This utility provides a number of commands to maintain the local cache of
245 dpurdie 2399
dpkg_archive.
227 dpurdie 2400
 
2401
=item B<gen_msproject>
2402
 
2403
This utility will generate a set of Microsoft Studio (Version 6) project and
2404
workspace files to encapsulate the JATS build. The resultant project allows VS
2405
to be used as an editor, source browser, debugger and build tool. JATS is
2406
still used to perform the build.
2407
 
2408
=item B<etool name>
2409
 
2410
This command allows any JATS extension program to be run. The programs will by
2411
found in the JATS TOOLS directory.
2412
 
2413
=item B<eprog name>
2414
 
2415
This command allows any JATS extension program to be run.
2416
If the program end in .pl, then it will be run within a perl interpreter.
2417
If the program end in .jar, then it will be run under a java interpreter.
2418
 
2419
=item B<ebin name>
2420
 
2421
This command allows any JATS support program to be run. The programs will by
2422
found in the JATS BIN directory for the current platform. This command allows
2423
a user script to access many of the machine independent utilities in a simple
2424
manner.
2425
 
2426
Example: "JATS ebin ls" - will provide a "real" ls on all platforms.
2427
 
2428
Example: "JATS ebin sh" - will start up the shell used by make.
2429
 
2430
=back
2431
 
2432
=head2 Command Shortcuts
2433
 
2434
The following commands are user shortcuts to the basic commands. The are basic
2435
commands run in sequence.
2436
 
2437
=over 8
2438
 
2439
=item B<all [make_opts]>
2440
 
2441
This command is the same as running the command "build" and "make all".
2442
It will build a component with a single command.
2443
 
2444
If "make_opts" is not present then "make all" is used.
2445
 
2446
If "make_opts" is present then they are passed to the "make" command. In this
2447
manner is it possible to build a WIN32 component of package with a single
2448
command.
2449
 
2450
=item B<go [make_opts]>
2451
 
2452
This command is similar to the "all" shortcut, but it does not "build" the
2453
sandbox. It may be used where the sandbox has already been prepared.
2454
 
2455
=item B<debug [target]>
2456
 
2457
This command is the same as running "make debug package_debug". It will make and
2458
package all the debug components of a sandbox.
2459
 
2460
If any additional arguments are provided to the B<dev> command then they will be
2461
treated as make targets and the commands will be expanded to make and package
2462
the specified debug versions of the names platforms. Make options cannot be
2463
passed in this manner.
2464
 
2465
Example: "JATS dev GAK" will create and package the debug parts for the
2466
GAK_MOS68K and GAK_MOSCF.
2467
 
2468
=item B<prod [target]>
2469
 
2470
This command is the same as running "make prod package_prod". It will make and
2471
package all the debug components of a sandbox.
2472
 
2473
If any additional arguments are provided to the B<prod> command then they will be
2474
treated as make targets and the commands will be expanded to make and package
2475
the specified debug versions of the names platforms. Make options cannot be
2476
passed in this manner.
2477
 
2478
Example: "JATS prod GAK" will create and package the production parts for the
2479
GAK_MOS68K and GAK_MOSCF.
2480
 
2481
=item B<clean>
2482
 
2483
This is the same as "make clean".
2484
 
2485
=item B<clobber>
2486
 
2487
This is the same as "build clobber"
2488
 
2489
=item B<else>
2490
 
2491
Commands that are not known to the JATS wrapper script are passed to etool.
2492
 
2493
ie: "JATS xxxx" is is the same as "JATS etool xxxx".
2494
 
2495
=back
2496
 
2497
=head1 DESCRIPTION
2498
 
2499
JATS is a wrapper script. It provides:
2500
 
2501
=over 8
2502
 
2503
=item *
2504
 
315 dpurdie 2505
A controlled and sanitised environment to all the build tools.
227 dpurdie 2506
 
2507
=item *
2508
 
2509
The same command interface on all supported machines: Windows, Solaris and
2510
Linux.
2511
 
2512
=item *
2513
 
2514
Provides a framework for extending the build environment toolset.
2515
 
2516
=back
2517
 
315 dpurdie 2518
=head1 RELATED DOCUMENTATION
227 dpurdie 2519
 
315 dpurdie 2520
=over 0
227 dpurdie 2521
 
315 dpurdie 2522
=item   * InstallationNotes
227 dpurdie 2523
 
315 dpurdie 2524
=item   * OverView
227 dpurdie 2525
 
315 dpurdie 2526
=item   * EnvVars
255 dpurdie 2527
 
315 dpurdie 2528
=item   * PkgArchives
227 dpurdie 2529
 
2530
=back
2531
 
315 dpurdie 2532
Use C<jats help> to see the available internal documentation.
227 dpurdie 2533
 
315 dpurdie 2534
=head1 EXAMPLES
227 dpurdie 2535
 
315 dpurdie 2536
=over 8
227 dpurdie 2537
 
315 dpurdie 2538
=item   JATS help
227 dpurdie 2539
 
315 dpurdie 2540
This will display the available internal documentation.
227 dpurdie 2541
 
2542
=item   JATS build
2543
 
315 dpurdie 2544
This will prime the current package being built ready for "make". The command
2545
will locate the build.pl file and process it. This will locate all the external
2546
packages and generate the required makefiles.
227 dpurdie 2547
 
2548
=item   JATS make
2549
 
2550
This will run the GNU make program over the makefiles generated by the "build"
2551
command. This may be executed in a subdirectory in order to limit the targets
2552
that are "made".
2553
 
2554
B<NOTE:> Do not run "make" without using the JATS wrapper. It will not perform
2555
as expected as the environment will not have been set up correctly.
2556
 
2557
=back
2558
 
2559
=cut
2560