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