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