Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
363 dpurdie 1
########################################################################
5709 dpurdie 2
# Copyright (c) VIX TECHNOLOGY (AUST) LTD
227 dpurdie 3
#
4
# Module name   : buildlib.pl
5
# Module type   : Makefile system
363 dpurdie 6
# Compiler(s)   : Perl
7
# Environment(s): jats
227 dpurdie 8
#
363 dpurdie 9
# Description   : Process build.pl file and create the build environment
227 dpurdie 10
#
363 dpurdie 11
# Usage         : Refer to documentation at the end of the file
227 dpurdie 12
#
363 dpurdie 13
#......................................................................#
227 dpurdie 14
 
15
use strict;
16
use warnings;
17
 
363 dpurdie 18
use JatsError;
227 dpurdie 19
use BuildVersion;
20
use BuildName;
21
use PackageEntry;
22
use JatsEnv;
23
use JatsSystem;
24
use JatsVersionUtils;
25
use FileUtils;
26
use Pod::Usage;
261 dpurdie 27
use Getopt::Long;
305 dpurdie 28
use File::Path;
227 dpurdie 29
 
30
our $BuildVersion           = "2.1.0";
31
 
32
#.. Switchs
33
#
34
our $ScmBuildlib            = 0;
35
our $ScmBuildSrc            = "";
36
 
37
our $CmdSwitch              = "";
38
our $Clobber                = 0;
39
our $Archive                = 0;
40
our $Interface              = 0;
41
our $RootOnly               = 0;
42
our $Perms                  = 0;
43
our $Expert                 = 0;
44
our $All                    = 0;
45
our $Nolog                  = 0;
5109 dpurdie 46
our $Cache                  = $ENV{GBE_DPKG_CACHE_CTL} || 0;
261 dpurdie 47
our $NoPackageError         = 0;
227 dpurdie 48
our $ForceBuildPkg          = 0;
49
our $Srcdir                 = "";               # default source root
331 dpurdie 50
our $ForceBuild             = 1;
2078 dpurdie 51
our $IgnorePkgs             = 0;
4778 dpurdie 52
our $GenericBuild           = undef;            # Build System Generic Build Test
227 dpurdie 53
 
54
#.. Public symbols, referenced by many build.pl implementations
55
#
56
our $BUILDPREVIOUSVERSION   = "0.0.0";          # BuildPreviousVersion()
57
our @BUILDPLATFORMS         = ();               # BuildPlatforms()
58
our %BUILDINFO              = ();               # BuildInfo
59
our @DEFBUILDPLATFORMS      = ();
60
our %BUILDPLATFORMARGS      = ();
61
our @BUILD_ACTIVEPLATFORMS  = ();
62
our @BUILDSUBDIRS           = ();               # BuildSubDir()
63
our @BUILDSETENV            = ();               # BuildSetenv()
64
our $BUILDINTERFACE         = "";               # BuildInterface()
65
our $BUILDLOCAL             = "";               # BuildInterface()
66
our $BUILDDIRTREE           = "";               # BuildDirTree()
241 dpurdie 67
our @BUILD_BADNAME          = ();               # Unknown platforms
4551 dpurdie 68
our @GENERIC_TARGETS        = ();               # Generic targets - only one allowed    
227 dpurdie 69
 
70
our $BUILDNAME              = "";               # BuildName()
71
our $BUILDVERSION           = "";               # BuildName()
72
our $BUILDNAME_PACKAGE;                         # Name
73
our $BUILDNAME_VERSION;                         # Version
74
our $BUILDNAME_PROJECT;                         # Project(optional)
359 dpurdie 75
our $BUILDNAME_SUFFIX;                          # Project (available)
227 dpurdie 76
our $DEPLOY_PATCH           = 0;                # Deplyment patch number
77
 
78
our %BUILDALIAS_DELAY       = ();               # Delayed aliases
79
our %BUILDALIAS_TARGETS     = ();               # BuildAlias from --Targets
80
our %BUILDALIAS             = ();               # BuildAlias
81
our %BUILDPRODUCT           = ();               # BuildProduct
82
our %BUILDPRODUCT_PARTS     = ();               # BuildProduct parts
83
our %PKGRULES               = ();               # Package include and link rules
84
our @BUILDTOOLS             = ();               # Extended tool path
85
our $BUILDPHASE             = 0;                # In Build Phase
86
our @CLOBBERDIRS            = ();               # Directories to clobber
375 dpurdie 87
our @REMOVEDIRS             = ();               # Directories to remove - if empty
247 dpurdie 88
our %BUILD_KNOWNFILES       = ();               # Files that will be known
5679 dpurdie 89
our @BUILDEXCLUDE           = ();               # Platforms to be excluded
227 dpurdie 90
 
333 dpurdie 91
our $Makelib                = "";
263 dpurdie 92
our $GBE_CORE;                                  # Root of JATS
93
our $InterfaceVersion;                          # Interface directory format version
3967 dpurdie 94
our $ScmRoot;                                   # Package Root
263 dpurdie 95
our $ScmInterface;                              # Interface directory
363 dpurdie 96
our $ScmBuildFilter;                            # Build Filter when build was created
4003 dpurdie 97
our $NoBuild                = 0;                # Dummy Build under ABT only
227 dpurdie 98
 
263 dpurdie 99
 
227 dpurdie 100
my  $DeleteDPACKAGE         = 0;                # Must clobber DPACKAGE
305 dpurdie 101
my  $build_source_pkg       = 0;                # Flag to build source package
227 dpurdie 102
my  $opt_help               = 0;
359 dpurdie 103
my  $sandbox_exact          = 0;                # Exact or in-exact sandbox
227 dpurdie 104
 
105
BuildLibInit();
106
 
107
sub BuildLibInit
108
{
109
 
110
#.. Set environment
111
#
331 dpurdie 112
    EnvImport( 'GBE_VERSION' );
113
    EnvImport( 'GBE_BIN' );
114
    EnvImport( 'GBE_CORE' );
115
    EnvImport( 'GBE_PERL' );
116
    EnvImport( 'GBE_TOOLS' );
117
    EnvImport( 'GBE_CONFIG' );
118
    EnvImport( 'GBE_DPKG' );
119
    EnvImport( 'GBE_MACHTYPE' );
120
    EnvImport( 'USER' );
121
    EnvImport( 'GBE_HOSTNAME');
122
    EnvImport( 'GBE_DRV' )
123
        if ( $ScmHost ne 'Unix' );            # DOS or WIN special
227 dpurdie 124
 
4688 dpurdie 125
    EnvImportOptional ( 'GBE_DPKG_REPLICA','' );
227 dpurdie 126
    EnvImportOptional ( 'GBE_DPKG_STORE','' );
127
    EnvImportOptional ( 'GBE_DPKG_CACHE','' );
128
    EnvImportOptional ( 'GBE_DPKG_LOCAL','' );
129
    EnvImportOptional ( 'GBE_DPKG_SBOX' ,'' );
313 dpurdie 130
    EnvImportOptional ( 'GBE_DPLY'      ,'' );
341 dpurdie 131
    EnvImportOptional ( 'GBE_SANDBOX'   ,'' );
227 dpurdie 132
 
133
    EnvImportOptional ( 'GBE_PLATFORM' );           # optional PLATFORM filter
134
    EnvImportOptional ( 'GBE_BUILDFILTER' );        # optional BUILD filter       
135
    EnvImportOptional ( 'GBE_ABT' );                # optional ABT flags          
136
 
137
#.. Common stuff
138
#
139
    require "$::GBE_TOOLS/common.pl";
331 dpurdie 140
    CommonInit( 'buildlib' );
227 dpurdie 141
    Debug( "Version:   $BuildVersion" );
279 dpurdie 142
    Require( "$::GBE_CONFIG/PLATFORM", "PLATFORM_CFG.PM"  );
227 dpurdie 143
 
144
#.. Parse command line
145
#
146
    $ScmBuildSrc = $0;                          # Name of the build file
331 dpurdie 147
    $Cwd = shift @ARGV;
227 dpurdie 148
    $Cwd =~ tr~\\/~/~s;;                        # Need / in path, Remove doubles
3967 dpurdie 149
    $::ScmRoot = StripDrive($Cwd);
333 dpurdie 150
    $Makelib = shift @ARGV;                     # Only for legacy build.pl files
227 dpurdie 151
 
261 dpurdie 152
    Verbose ("Command Line: @ARGV");
313 dpurdie 153
    my $result = GetOptions( "help|h:+"      => \$opt_help,
154
                             "man:3"         => \$opt_help,
155
                             "debug:+"       => \$::ScmDebug,
156
                             "verbose:+"     => \$::ScmVerbose,
157
                             "expert:1"      => \$Expert,
158
                             "all"           => \$All,
159
                             "nolog"         => \$Nolog,
331 dpurdie 160
                             "cache:+"       => \$Cache,
313 dpurdie 161
                             "package"       => \$NoPackageError,
2078 dpurdie 162
                             "nopackages"    => \$IgnorePkgs,
313 dpurdie 163
                             "forcebuildpkg" => \$ForceBuildPkg,
331 dpurdie 164
                             "force!"        => \$ForceBuild,
4778 dpurdie 165
                             "generic!"      => \$GenericBuild,
313 dpurdie 166
                             );
261 dpurdie 167
    Usage() if ( $opt_help || !$result );
227 dpurdie 168
 
331 dpurdie 169
    Debug( "Host:          ", $ScmHost );
170
    Debug( "Cwd:           ", $Cwd );
333 dpurdie 171
    Debug( "Makelib:       ", $Makelib );
331 dpurdie 172
    Debug( "BuildFile:     ", $ScmBuildSrc );
173
    Debug( "Debug:         ", $::ScmDebug );
174
    Debug( "Verbose:       ", $::ScmVerbose );
175
    Debug( "Expert:        ", $Expert );
176
    Debug( "All:           ", $All );
177
    Debug( "Nolog:         ", $Nolog );
178
    Debug( "Cache:         ", $Cache );
179
    Debug( "package:       ", $NoPackageError );
180
    Debug( "ForcePkg  :    ", $ForceBuildPkg );
181
    Debug( "ForceBuild :   ", $ForceBuild );
4778 dpurdie 182
    Debug( "IgnorePkgs :   ", $IgnorePkgs );
183
    Debug( "GenericTest :  ", $GenericBuild );
227 dpurdie 184
 
185
#.. Command
186
#
3967 dpurdie 187
 
188
    $CmdSwitch = (lc shift @ARGV) if @ARGV;
331 dpurdie 189
    Debug( "CmdSwitch:     ", $CmdSwitch );
227 dpurdie 190
 
331 dpurdie 191
    if ( $CmdSwitch )
192
    {
193
        if ( $CmdSwitch eq "interface" ) {
194
            $Interface      = 1;
227 dpurdie 195
 
331 dpurdie 196
        } elsif ( $CmdSwitch eq "rootonly" ) {
197
            $RootOnly       = 1;
227 dpurdie 198
 
331 dpurdie 199
        } elsif ( $CmdSwitch eq "clobber" ) {
200
            $Clobber        = 1;
227 dpurdie 201
 
331 dpurdie 202
        } elsif ( $CmdSwitch eq "help" || $CmdSwitch eq "usage" ) {
203
            $opt_help = 1;
204
            Usage();
227 dpurdie 205
 
331 dpurdie 206
        } elsif ( $CmdSwitch eq "changelog" ) {
207
            if ( -d "CVS" )                         # CVS support subdir
208
            {
209
                System( "$::GBE_PERL $::GBE_TOOLS/cvs2cl.pl --tags --branches --revisions --day-of-week" )
210
            }
211
            exit(1);
227 dpurdie 212
 
331 dpurdie 213
        } else {
214
            Usage( "(E) build. Unknown command \"$CmdSwitch\"" );
215
        }
216
    }
227 dpurdie 217
 
331 dpurdie 218
    #
341 dpurdie 219
    #   If we are not performing a ForceBuild, then we don't need to continue
220
    #   We have updated the interface directory with BuildPkgArchive
221
    #   information.
331 dpurdie 222
    #
341 dpurdie 223
    unless ( $::GBE_SANDBOX )
331 dpurdie 224
    {
341 dpurdie 225
        TestForForcedBuild();
227 dpurdie 226
    }
227
 
228
    #
229
    #   Must inform makelib that its running under buildlib
230
    #
231
    $ScmBuildlib = 1;
232
 
233
    #
234
    #   In clobber mode System commands will not force termination
235
    #   otherwise, within build.pl, a failed system command will die.
236
    #
237
    SystemConfig ('UseShell' => 1,
283 dpurdie 238
                  'ExitOnError' => ($Clobber == 0) );
5109 dpurdie 239
 
240
    #
241
    #   Capture messages while processing directives
242
    # 
243
    StartCapture(1) 
244
        unless ($Clobber);
227 dpurdie 245
}
246
 
247
 
248
#-------------------------------------------------------------------------------
249
# Function        : Log
250
#
251
# Description     : Internal function to generate a log file of the build process
341 dpurdie 252
#                   The function will print its arguments to the screen and a log file
227 dpurdie 253
#
254
# Inputs          : Arguments will be printed
255
#
256
# Returns         : Nothing
257
#
258
sub Log
259
{
260
    if ( ! $Clobber )
261
    {
261 dpurdie 262
        print "@_\n";
263
        FileAppend ('build.log', \@_ );
227 dpurdie 264
    }
265
}
266
 
267
#-------------------------------------------------------------------------------
268
# Function        : BuildSubDir
269
#
270
# Description     : Specify one or more directories in which makefile.pl's can be
271
#                   found to be processed.
272
#
273
#                   This function will flag the build 'src' dir.
274
#                   This will be the first directory specified UNLESS there
275
#                   is a 'src' directory in the list
276
#
277
#                   The function may be called multiple times.
278
#
279
# Inputs          : NewDirs             - An array of directories
280
#
281
# Returns         : Nothing
282
#
283
 
284
sub BuildSubDir
285
{
286
    my( @NewDirs );
287
 
288
    @NewDirs = map { split /\s+/ } @_;
289
    @NewDirs = grep { defined $_ } @NewDirs;
290
 
291
    Debug( "BuildSubDir(@NewDirs)" );
292
 
293
    foreach my $ThisDir ( @NewDirs )
294
    {
295
        unless ( $Clobber )
296
        {
2450 dpurdie 297
            $ThisDir =~ s~/+$~~;
227 dpurdie 298
            if ( $ThisDir eq "." )
299
            {
300
                Error( "BuildSubDir() cannot specify the current directory (.)",
301
                       "The makefile.pl in the root directory is included in all makefile.pl's" );
302
            }
303
 
304
            if ( $ThisDir =~ m~\\~)
305
            {
306
                Warning ("BuildSubDir contains a '\\' character: $ThisDir" );
307
            }
308
            if ( grep /^$ThisDir$/, @BUILDSUBDIRS )
309
            {
310
                Warning( "BuildSubDir() duplicate subdirectory ignored '$ThisDir'." );
311
                next;
312
            }
313
            if ( ! ( -e $ThisDir and -d $ThisDir ) )
314
            {
315
                Error( "BuildSubDir() non-existent subdirectory: '$ThisDir'." );
316
            }
317
            if ( ! -f $ThisDir . '/makefile.pl' )
318
            {
319
                Error( "BuildSubDir() makefile.pl not found in subdirectory: '$ThisDir'." );
320
            }
321
 
322
            push( @BUILDSUBDIRS, $ThisDir );
323
        }
324
 
325
        #
326
        #   Capture the first source directory mentioned
327
        #   This will be used as the root of the build
328
        #
329
        #   If there is a Src directory then use this
330
        #
331
        $Srcdir = $ThisDir
332
            if ( $ThisDir =~ m/^src$/i );
333
        $Srcdir = $ThisDir
334
            unless ( $Srcdir );
335
    }
336
}
337
 
338
#-------------------------------------------------------------------------------
339
# Function        : BuildAlias
340
#
341
# Description     : Create an alias for multiple targets
342
#                   The default operations will:
343
#                       Add the alias as a default platform (* in the makefile.pl)
344
#                       Perform an implicit BuildPlatform for the alias targets
345
#
346
#                   In hindsight this was not good. Options modify the behaviour
347
#                   Options:
348
#                       --NotDefault    The alias will not be a part of the default
349
#                                       platform for the makefile.pls
350
#                       --Define        Simply define text substitution
351
#                                       Do not implicitly create platforms
352
#                       --Target        Accumulate platforms with specified targets
353
#                                       Complete alias determination is delayed
354
#                                       The named targets are specified as an alias
355
#                                       until the calculation is done
356
#
357
# Inputs          : alias[,--options]   comma seperated options
358
#                   arguments           alias arguments; platforms or targets
359
#
360
# Returns         : Nothing
361
#
362
sub BuildAlias
363
{
364
    my( $alias, @arguments ) = @_;
365
    my $notdefault;
366
    my $define;
367
    my $target_mode;
368
 
369
    Debug( "BuildAlias($alias, @arguments)" );
370
    Error ("BuildAlias: No platforms specified") unless ( @arguments );
371
    Error( "BuildAlias() must appear before BuildName()..." ) if ( $BUILDNAME );
372
 
373
    #   Parse attributes
374
    #
375
    my ( @attrs ) = split( ',', $alias );
376
 
377
    $alias = "";
378
    foreach ( @attrs ) {
379
        if ( /^--/ ) {
380
            if ( /^--NotDefault$/ ) {
381
                $notdefault = 1;
382
 
383
            } elsif ( /^--Define$/ ) {
384
                $define = 1;
385
 
386
            } elsif ( /^--Target$/ ) {
387
                $target_mode = 1;
388
 
389
            } else {
390
                Warning( "BuildAlias() unknown attribute: $_ -- ignored" );
391
            }
392
 
393
        } else {
5262 dpurdie 394
            Error( "BuildAlias() multiple alias specifications", "First: $alias and now $_" )
227 dpurdie 395
                if ( $alias ne "" );
396
            $alias = $_;
397
        }
398
    }
399
    Error( "BuildAlias() missing alias specifications" )
400
        if ( $alias eq "" );
401
 
402
 
403
    #
404
    #   If we need to recalculate the alias based on targets, then tag the alias
405
    #   to be processed
406
    #
407
    $BUILDALIAS_TARGETS{ $alias } = ''
408
        if ( $target_mode );
409
 
410
    #   Define alias
411
    #
4551 dpurdie 412
    if ( PlatformConfig::checkBuildAvailability($alias) == 2 )
227 dpurdie 413
    {
4551 dpurdie 414
        Error( "BuildAlias() cannot create an alias named $alias", "That name is reserved for generic targets" );
227 dpurdie 415
    }
416
    elsif ( $alias ne quotemeta( $alias ) )
417
    {
418
        Warning( "BuildAlias() alias '$alias' contains invalid characters -- ignored" );
419
    }
420
    elsif ( $BUILDALIAS{ $alias } )
421
    {
422
        Warning( "BuildAlias() duplicate alias '$alias' -- alias ignored" );
423
    }
424
    else
425
    {
426
        #
427
        #   Expand alias UNLESS using --Target.
428
        #   The --Target is a real target and not a subject to alias expansion
429
        #   This solves order dependancy problems.
430
        #
431
        @arguments = ExpandPlatforms( @arguments )
432
            unless $target_mode;
433
 
434
        my $platform = "";                   # current platform
435
        my @pargs = ();                      # current args
436
 
437
        #
438
        #   Process the expanded arguments
439
        #   Collect arguments and process when a new platform is discovered
440
        #
441
        foreach my $arg ( @arguments, '++' )
442
        {
443
            if ( $arg =~ /^--/ )
444
            {
445
                push @pargs, $arg;
446
                next;
447
            }
448
            else
449
            {
450
                #
451
                #   Start of a platform
452
                #   Process previous data, once a platform has been seen
453
                #
454
                if ( $platform )
455
                {
456
                    #   Add arguments to BUILDALIAS as we see them
457
                    #
458
                    HashJoin( \%BUILDALIAS, ' ', $alias, $platform );
459
                    HashJoin( \%BUILDALIAS, ' ', $alias, grep(!/^--Uses=/, @pargs) );
460
 
461
                    #
462
                    #   The BuildAlias can also define a platform.
463
                    #   (Sounded like a good idea at the time!)
464
                    #
465
                    unless ( $define || $target_mode )
466
                    {
467
                        push @pargs, '--NotDefault' if ( $notdefault );
468
                        push @pargs, '--FunctionName=BuildAlias';
469
                        BuildPlatforms( $platform, @pargs );
470
                    }
471
                }
472
 
473
                #
474
                #   Start collecting args for the next platform
475
                #
476
                @pargs = ();
477
                $platform = $arg;
478
            }
479
        }
480
    }
481
}
482
 
483
 
484
#-------------------------------------------------------------------------------
485
# Function        : Process_TargetAlias
486
#
487
# Description     : Post Process the --Target option for the build alias
488
#                   Filter all platforms and extract those with a matching targets
489
#
490
# Inputs          : None
491
#
492
# Returns         : Nothing
493
#
494
sub Process_TargetAlias
495
{
496
 
497
    #
498
    #   Merge any delayed aliases with the complete set of alias
499
    #   Delayed alias are not used in expansions during the processing
5410 dpurdie 500
    #   of platforms and targets, but can be used to pick up errors
227 dpurdie 501
    #
502
    while ( my($key,$value) = each(%BUILDALIAS_DELAY) )
503
    {
504
        if ( exists($BUILDALIAS{$key}) )
505
        {
5867 dpurdie 506
            abtWarning(0,"BuildAlias() duplicates internal alias '$key'");
227 dpurdie 507
            next;
508
        }
509
        $BUILDALIAS{$key} = $value;
510
    }
5410 dpurdie 511
    ErrorDoExit();
227 dpurdie 512
 
513
    foreach my $alias ( keys %BUILDALIAS_TARGETS )
514
    {
515
        Debug( "BuildTargetAlias($alias)" );
516
 
517
        #
518
        #   Replace the existing alias - it has done its JOB
519
        #
520
        my $arguments = delete $BUILDALIAS{ $alias } ;
521
 
522
        foreach my $arg ( split / /, $arguments )
523
        {
524
            if ( $arg =~ /^--/ )                # argument
525
            {
526
                #   Add arguments to BUILDALIAS as we see them
527
                #
528
                HashJoin( \%BUILDALIAS, ' ', $alias, $arg );
529
                next;
530
            }
531
 
532
            foreach my $platform ( keys %BUILDINFO )
533
            {
534
                foreach my $element ( qw (TARGET BASE ) )
535
                {
536
                    my $target = $BUILDINFO{$platform}{$element};
537
                    if ( $target && $target eq $arg )
538
                    {
539
                        HashUniqueJoin( \%BUILDALIAS, ' ', $alias, $platform );
540
                        Debug( "BuildTargetAlias: $alias, $target -> $platform" );
541
                    }
542
                }
543
            }
544
        }
545
    }
546
}
547
 
548
#-------------------------------------------------------------------------------
549
# Function        : BuildProduct
550
#
551
# Description     : Create a family of Platforms with a common product line
552
#                   ie: Create two flavors of the TP5, one based on the MOSF and
553
#                   the othe based on the MOS68 toolset.
554
#
555
# Inputs          : $product[,opts]+    The name of the product
556
#                                       This will be the base name for the family
557
#                                       Allowed options are:
558
#                                           --NotDefault    : This is not a default build platform
559
#                                           --Uses=xxx      : All use another platform
5115 dpurdie 560
#                                           --Alias=yyy     : All alias to this name
227 dpurdie 561
#
562
#                   platforms           One or more root platforms, with options
563
#                                       The platform is macro expanded.
564
#                                       Options may be a part of the platform or
565
#                                       distinct.
566
#
567
# Returns         :
568
#
569
 
570
sub BuildProduct
571
{
572
    my( $product, @arguments ) = @_;
573
    my $notdefault = 0;
574
    my @uses = ();
5115 dpurdie 575
    my @alias = ();
227 dpurdie 576
 
577
    Debug( "BuildProduct($product, @arguments)" );
578
    Error( "BuildProduct must appear before BuildName()..." )
579
        if ( $BUILDNAME ne "" );
580
 
581
    #   Parse attributes
582
    #
583
    my( @attrs ) = split( ',', $product );
584
 
585
    $product = "";
586
    foreach ( @attrs ) {
587
        if ( /^--/ ) {
588
            if ( /^--NotDefault$/ ) {
589
                $notdefault++;
590
 
591
            } elsif ( /^--Uses=(.*)/ ) {
592
                UniquePush (\@uses, $1);
593
 
5115 dpurdie 594
            } elsif ( /^(--Alias=.*)/ ) {
595
                UniquePush (\@alias, $1);
596
 
227 dpurdie 597
            } else {
598
                Warning( "BuildProduct() unknown attribute: $_ -- ignored" );
599
            }
600
 
601
        } else {
602
            Error( "BuildProduct() multiple product specifications not allowed" )
603
                if ( $product ne "" );
604
            $product = $_;
605
        }
606
    }
607
 
608
    #
609
    #   Sanity test
610
    #
611
    Error( "BuildProduct() missing product specifications" )
612
        if ( $product eq "" );
613
 
614
    Error( "BuildProduct() product '$product' contains invalid characters" )
615
        if ( $product ne quotemeta( $product ) );
616
 
617
    Error( "BuildProduct() duplicate product '$product'" )
618
        if ( $BUILDPRODUCT{ $product } );
619
 
620
    Error( "BuildProduct() duplicate alias '$product'" )
621
        if ( $BUILDALIAS{ $product } );
622
 
623
    #
624
    #   Expand the user specified targets to allow the use of BuildAlias
625
    #   The (bad) side effect of this is that target options get reorganised
626
    #       PLATFORM,--Uses=ANOTHER  ==> PLATFORM --Uses=ANOTHER
627
    #
628
    #   Insert markers(++) into @aruments to mark when to process collected data
629
    #   Insert before each PLATFORM and at the end of the list
630
    #   platform specifier or the end of the list. Scan the arguments
631
    #
632
    @arguments = ExpandPlatforms( @arguments );
633
    my @new_args;
634
    foreach  ( @arguments )
635
    {
636
        push (@new_args, '++') unless ( m/^--/ );
637
        push (@new_args, $_ );
638
    }
639
    push (@new_args, '++');
640
    shift @new_args if $new_args[0] eq '++';
641
 
5115 dpurdie 642
    my @targs = @alias;
227 dpurdie 643
    my $target;
644
    my @tuses = @uses;
645
    foreach my $arg ( @new_args )
646
    {
647
        #
648
        #   Collect per-platform arguments
649
        #
650
        if ( $arg =~ /^--Uses=(.*)/ ) {
651
            UniquePush (\@tuses, $1);
652
            next;
653
 
654
        } elsif ( $arg =~ /^--/ ) {
655
            push @targs, $arg;
656
            next;
657
        }
658
 
659
        #
660
        #   Collect target(platform) name
661
        #
662
        unless ( $arg eq '++' )
663
        {
664
            $target = $arg;
665
            Error( "BuildProduct() cannot create a product based on a GENERIC platform" )
4551 dpurdie 666
                if ( PlatformConfig::checkBuildAvailability($target) == 2);
227 dpurdie 667
            next;
668
        }
669
 
670
        #
671
        #   Infer a BuildPlatform
672
        #   Do not provide a platform name. This will be created later when the
673
        #   full name is known - or can be calculated.
674
        #
675
        CreateBuildPlatformEntry('BuildProduct', $notdefault, $product, $target, \@tuses, \@targs );
676
 
5115 dpurdie 677
        @targs = @alias;
227 dpurdie 678
        @tuses = @uses;
679
        $target = undef;
680
    }
681
}
682
 
683
#-------------------------------------------------------------------------------
684
# Function        : CreateBuildPlatformEntry
685
#
686
# Description     : Internal routine to create the Build Entry
687
#                   Single point to create a platform, whatever one of those is
688
#
689
# Inputs          : $fname                  - Name of invoking directive
690
#                   $notdefault             - True if the platform is not to be added to the
691
#                                             list of default platforms
692
#                   $product                - Optional product name
693
#                   $target                 - Target platform name
694
#                   $pUses                  - Ref to an array of 'Uses'
695
#                   $pArgs                  - Ref to an array of platform arguments
696
#
697
# Returns         :
698
#
699
 
700
sub CreateBuildPlatformEntry
701
{
702
    my ($fname, $notdefault, $product, $target, $pUses, $pArgs ) = @_;
703
    my %buildentry;
704
    my $platform;
705
 
706
    #
707
    #   Create a basic BUILDINFO entry
708
    #
709
    $buildentry{FNAME} = $fname;
710
    $buildentry{NOT_DEFAULT} = $notdefault;
711
    $buildentry{PRODUCT} = $product;
712
    $buildentry{TARGET} = $target;
713
    $buildentry{BASE} = $target;
714
    $buildentry{USES} = [ @$pUses ] if $pUses;
363 dpurdie 715
    foreach ( @$pArgs )
716
    {
717
        if ( m~^--Alias=(.+)~ ) {
718
            push @{$buildentry{USERALIAS}}, split(',',$1);
719
        }
720
        else{
721
            push @{$buildentry{ARGS}}, $_;
722
        }
723
    }
227 dpurdie 724
 
4728 dpurdie 725
    #   Detect reserved words being misused as a platform name
726
    #   At the moment, the value of NATIVE is calculate towards the end of the
727
    #   build process so that it can be limited to platfroms that 
728
    #   are present.
729
    Error('Invalid use of the platform alias NATIVE','The NATIVE alias cannot be used to define build platforms')
730
        if (uc($target) eq 'NATIVE');
731
 
227 dpurdie 732
    #
733
    #   Allow per-platform processing to be alter the basic information
734
    #   Special processing may be perform to extend the information
735
    #   Allows special processing to be enabled on a per-target basis
736
    #
737
    #   There are three forms of processing that have been allowed for:
738
    #       1) None:        There is not platform specific extension
739
    #       2) Basic:       The extension will add or extend build information
740
    #       3) Advanced:    The extension will generate additional build information
741
    #                       structures.
742
    #
743
 
744
    #
745
    #   Locate the optional PLATFORM configuration file
746
    #   If it does exist then it can alter build-time information
747
    #
748
    if ( my $build_cfg = Require( "$::GBE_CONFIG/PLATFORM", "$target.cfg"  ) )
749
    {
750
        Verbose ("Processing(new) Platform Configuration file: $build_cfg");
751
 
297 dpurdie 752
        #
303 dpurdie 753
        #   Create package name with an uppercase target
754
        #   Target should be UC, but under windows its not detected
755
        #   at this time
756
        #
757
        my $package_name = uc($target) . '_Build';
758
 
759
        #
4551 dpurdie 760
        #   Ensure that the CFG is correctly formed
297 dpurdie 761
        #       Perhaps the package that it implements was misnamed
762
        #
303 dpurdie 763
        Error ("INTERNAL: $target.cfg does not satisfy API " )
297 dpurdie 764
            unless ( $package_name->can('new_platform') || $package_name->can('add_platform') );
765
 
227 dpurdie 766
        if ( $package_name->can('new_platform') )
767
        {
768
            Verbose ("Processing(new) Platform Configuration: $package_name");
769
            $package_name->new_platform( \%buildentry );
770
        }
771
        else
772
        {
773
            Debug ("Processing(new) Platform Configuration: $package_name. 'new_platform' function not found");
774
        }
775
    }
776
 
777
    #
778
    #   Add the basic entry into the build system, unless its been
779
    #   flagged as a TEMPLATE
780
    #
781
    AddBuildPlatformEntry (\%buildentry )
782
        unless ( $buildentry{TEMPLATE} );
783
}
784
 
785
 
786
#-------------------------------------------------------------------------------
787
# Function        : AddBuildPlatformEntry
788
#
789
# Description     : Internal routine to add a Build Entry into the build system
790
#                   This function MAY be called from the build extensions
791
#
792
#                   NOTES:
793
#                   No processing of the info structure is performed. This MUST
794
#                   have been done before now.
795
#
796
#                   Additional information may be added to the structure.
797
#
798
#
799
# Inputs          : $pInfo              - Reference to a BuildInfo structure
800
#
801
# Returns         : Nothing
802
#
803
sub AddBuildPlatformEntry
804
{
805
    my ($pInfo) = @_;
806
    my $fname = $pInfo->{FNAME};
807
 
808
    #
809
    #   Locate the optional PLATFORM configuration file
810
    #   If it does exist then it can extend build-time information
811
    #
812
    my $target = $pInfo->{TARGET};
241 dpurdie 813
 
279 dpurdie 814
    #
815
    #   Yukky Kludge
816
    #   JATS has a mechanism whereby packages can create new platforms
817
    #   Luckily this has only been done for LMOS - don't every do it again
818
    #   One problem is that we can't validate the target name at this point
819
    #   in time: as the packages are loaded much later.
820
    #
821
    #   Kludge. Assume that a leading LMOS_ can be removed when determing
822
    #           validity of the target platform.
823
    #
824
    my $base_target = $target;
825
    $base_target =~ s~^LMOS_~~;
241 dpurdie 826
 
279 dpurdie 827
    #
4551 dpurdie 828
    #   Detect GENERIC targets
829
    #       The Build file is only allowed to have one that can be built on any one machine
830
    #
831
    my $buildAvailability = PlatformConfig::checkBuildAvailability( $base_target );
832
    if ($buildAvailability == 2 )
833
    {
834
        UniquePush (\@GENERIC_TARGETS, $target );
835
        $pInfo->{IS_GENERIC} = 1;
836
    }
837
 
838
    #
279 dpurdie 839
    #   Ensure target is known to JATS
840
    #   Remove unknown targets from the build. Create a list of unknown
841
    #   targets and report them later.
842
    #
843
    #   If there are signs that the target has been processed, then it may be
844
    #   an alias that has not been expanded.
845
    #
846
    #   One result will be that alias platforms, such as DEVLINUX, that don't
847
    #   expand on WIN32 will be shown as DEVLINUX and not its components.
848
    #
4551 dpurdie 849
    unless ( $pInfo->{NOT_AVAILABLE} || exists $BUILDINFO{$target} || $pInfo->{IS_GENERIC} )
227 dpurdie 850
    {
279 dpurdie 851
        unless ( Exists( "$::GBE_CONFIG/PLATFORM", $base_target  ) )
852
        {
4551 dpurdie 853
            UniquePush (\@BUILD_BADNAME, $target ) 
854
                unless PlatformConfig::checkKnownSpecial($target);
279 dpurdie 855
            $pInfo->{NOT_AVAILABLE} = 1;
856
        }
857
    }
858
 
859
    #
4551 dpurdie 860
    #   Mark as NOT_AVAILABLE platforms that are not available on this machine
279 dpurdie 861
    #
862
    unless ($pInfo->{NOT_AVAILABLE} )
863
    {
864
        $pInfo->{NOT_AVAILABLE} = 1
4551 dpurdie 865
            if ($buildAvailability == 0 )
279 dpurdie 866
    }
867
 
868
    unless ($pInfo->{NOT_AVAILABLE} )
869
    {
4551 dpurdie 870
        my $target_cfg = $pInfo->{TARGET_CFG} || $target;
317 dpurdie 871
        if ( my $build_cfg = Require( "$::GBE_CONFIG/PLATFORM", "${target_cfg}.cfg"  ) )
227 dpurdie 872
        {
873
            Verbose ("Processing(add) Platform Configuration file: $build_cfg");
317 dpurdie 874
            my $package_name = "${target_cfg}_Build";
227 dpurdie 875
 
876
            if ( $package_name->can('add_platform') )
877
            {
878
                Verbose ("Processing(add) Platform Configuration: $package_name");
879
                $package_name->add_platform( $pInfo );
880
            }
881
            else
882
            {
883
                Debug ("Processing(add) Platform Configuration: $package_name. 'add_platform' function not found");
884
            }
885
        }
886
    }
887
 
888
    #
889
    #   If a product name has been provided then the platform is a product
890
    #   and will need additional processing
891
    #
892
    if ( $pInfo->{PRODUCT} )
893
    {
894
        #
895
        #   Create the platform name. Derived from the product and the target
896
        #
897
        $pInfo->{PLATFORM} = $pInfo->{PRODUCT} . '_' . $pInfo->{TARGET};
898
 
899
        #
900
        #   Remember the product name
901
        #
902
        $BUILDPRODUCT{ $pInfo->{PRODUCT} } = 1;
903
 
904
        #
905
        #   Add platform name to the alias explansion being created
906
        #   Allows the user to reference the entire FAMILY of platforms
907
        #
908
        HashJoin( \%BUILDALIAS, ' ', $pInfo->{PRODUCT}, $pInfo->{PLATFORM} );
909
 
910
        #
911
        #   Add arguments to the 'alias' based on the product
912
        #   Ensure they don't make it any further
913
        #
914
        HashJoin( \%BUILDALIAS, ' ', $pInfo->{PRODUCT}, @{$pInfo->{ARGS}} ) if ( $pInfo->{ARGS}  );
915
        $pInfo->{ARGS} = undef;
916
 
917
        #
918
        #   Create an element to assist in creating %ScmBuildProducts
919
        #
920
        $pInfo->{ISPRODUCT} = 1;
921
        $BUILDPRODUCT_PARTS{$pInfo->{PLATFORM}} = "$pInfo->{PRODUCT},$pInfo->{TARGET}";
922
    }
923
    else
924
    {
925
        $pInfo->{PRODUCT} = $pInfo->{TARGET};
926
        $pInfo->{PLATFORM} = $pInfo->{TARGET};
927
    }
928
 
929
    #---------------------------------------------------------------------------
930
    #   All the hard work has been done
931
    #   We now know the platforms full name
932
    #
933
    #   Ensure that the target platform has not been been specified
934
    #   Perhaps this should be an error
935
    #
936
    my $platform = $pInfo->{PLATFORM};
937
 
5109 dpurdie 938
    if ( defined ( $BUILDINFO{$platform}) && ! $Clobber)
227 dpurdie 939
    {
5867 dpurdie 940
        abtWarning(1,"$fname() duplicate platform '$platform'");
5429 dpurdie 941
        return;
227 dpurdie 942
    }
943
 
944
    #
945
    #   Add platform (tag) to various lists
946
    #
947
    UniquePush( \@BUILDPLATFORMS, $platform );
948
    UniquePush( \@DEFBUILDPLATFORMS, $platform ) unless ( $pInfo->{NOT_DEFAULT} );
949
 
950
    #
951
    #   Create a simple alias if requested
952
    #   Used if a platform creates multiple entires
953
    #
954
    if ( $pInfo->{ALIAS} )
955
    {
317 dpurdie 956
        HashJoin( \%BUILDALIAS_DELAY, ' ', $_, $platform )
957
            foreach ( ArrayList($pInfo->{ALIAS}) );
227 dpurdie 958
    }
959
 
363 dpurdie 960
    if ( $pInfo->{USERALIAS} )
961
    {
962
        HashJoin( \%BUILDALIAS_DELAY, ' ', $_, $platform )
963
            foreach ( ArrayList($pInfo->{USERALIAS}) );
964
    }
965
 
227 dpurdie 966
    #
967
    #   Create a HARDWARE type alias if requested
968
    #   ie: SOLARIS_SPARC or SOLARIS_X86
969
    #
970
    if ( $pInfo->{HARDWARE} )
971
    {
972
        HashJoin( \%BUILDALIAS_DELAY, ' ',  $pInfo->{BASE} . '_' . $pInfo->{HARDWARE}, $platform );
973
    }
974
 
975
    #
976
    #   Create the 'parts' of the platform. This is a list of unique
977
    #   bits to search. It will consist of:
978
    #       [0]     - platform
979
    #       [1]     - product
980
    #       ...     - Uses bits ...
981
    #       [last]  - target
982
    #
983
    my @parts;
984
 
379 dpurdie 985
    if ( $pInfo->{USES_FIRST} )
986
    {
987
        UniquePush (\@parts, @{$pInfo->{USES_FIRST}} );
988
    }
989
 
990
    UniquePush (\@parts, $platform);
991
 
227 dpurdie 992
    #
993
    #   Include all the product extensions
994
    #
995
    if ( $pInfo->{ISPRODUCT}  )
996
    {
997
        UniquePush (\@parts, map {+ "$pInfo->{PRODUCT}_${_}" } @{$pInfo->{USES}});
998
        UniquePush (\@parts, map {+ "$pInfo->{PRODUCT}_${_}" } @{$pInfo->{ALSO_USES}});
999
        UniquePush (\@parts, $pInfo->{PRODUCT} );
1000
    }
1001
 
1002
    #
1003
    #   Add in non-product expanded parts
1004
    #
1005
    UniquePush (\@parts, @{$pInfo->{EXTRA_USES}});
1006
 
1007
    #
1008
    #   Create a structure to assist in search path resolution
1009
    #   The order is important. It sets the include search order for include
1010
    #   files and libraries
1011
    #   If A uses B then search in A_B, A, B
1012
    #       ie: GAK uses MOS68K Search stuff in GAK_MOS68K, GAK, MOS68K
1013
    #
1014
    #       Usage:  OBFTP uses TP5 on MOSCF(target)       (BuildProduct)
1015
    #       Expansion: OBFTP, TP5_MOSCF, TP5
1016
    #
1017
    #       Usage: VS2003(target) also uses WIN32(uses)     (BuildPlatform)
1018
    #       Expansion: VS2003, VS2003_WIN32, WIN32
1019
    #
1020
    if ( $pInfo->{ISPRODUCT}  )
1021
    {
1022
        UniquePush (\@parts, map {+ "${_}_$pInfo->{TARGET}", $_, $pInfo->{TARGET}} @{$pInfo->{USES}});
1023
        UniquePush (\@parts, map {+ "${_}_$pInfo->{TARGET}", $_, $pInfo->{TARGET}} @{$pInfo->{ALSO_USES}});
1024
    }
1025
    else
1026
    {
1027
        UniquePush (\@parts, map {+ "$pInfo->{TARGET}_${_}", $pInfo->{TARGET}, $_} @{$pInfo->{USES}});
1028
        UniquePush (\@parts, map {+ "$pInfo->{TARGET}_${_}", $pInfo->{TARGET}, $_} @{$pInfo->{ALSO_USES}});
1029
    }
1030
 
1031
    #
1032
    #   Finally - the target
1033
    #
1034
    UniquePush (\@parts, $pInfo->{TARGET} );
1035
 
1036
    #
1037
    #   Save the PARTS
1038
    #   Also saved as BUILDPLATFORM_PARTS for interface with older versions
1039
    #   of the deployments scripts.
1040
    #
1041
    $pInfo->{PARTS} = \@parts;
1042
 
1043
    #
1044
    #   Add any arguments to the platforms argument list
1045
    #
1046
    PlatformArgument( $platform, @{$pInfo->{ARGS}} ) if ( $pInfo->{ARGS} );
1047
 
1048
    #
1049
    #   Clean up and save
1050
    #
1051
    delete $pInfo->{TEMPLATE};
1052
    delete $pInfo->{FNAME};
1053
    $BUILDINFO{$platform} = $pInfo;
1054
#    DebugDumpData("BUILDINFO", \%BUILDINFO );
1055
}
1056
 
1057
 
1058
sub BuildArgument
1059
{
1060
    my( $platform, @arguments ) = @_;
1061
    my( @platforms );
1062
 
1063
    Debug( "BuildArgument($platform, @arguments)" );
1064
 
1065
    Error( "BuildArgument must appear before BuildName()..." )
1066
        if ( $BUILDNAME ne "" );
1067
 
1068
    #
1069
    #   Allow a wildcard to apply a single argument to all platforms
1070
    #   Should only be used AFTER all the platforms have been specified
1071
    #
1072
    if ( $platform eq '*' )
1073
    {
1074
        @platforms = @BUILDPLATFORMS;          # Simple Wildcard
1075
    }
1076
    else
1077
    {
1078
        @platforms = ExpandPlatforms( $platform );  # aliasing
1079
    }
1080
 
283 dpurdie 1081
    foreach my $platform ( @platforms )
227 dpurdie 1082
    {
1083
        next if ( $platform =~ /^--/ );         # argument, ignore
1084
 
1085
        PlatformArgument( $platform, @arguments );
1086
    }
1087
}
1088
 
1089
 
1090
sub BuildPlatforms
1091
{
1092
    my( @arguments ) = @_;
1093
    my $fname = "BuildPlatforms";
1094
 
1095
    Debug( "BuildPlatforms(@arguments)" );
1096
 
1097
    Error( "BuildPlatforms must appear before BuildName()..." )
1098
        if ( $BUILDNAME ne "" );
1099
 
1100
    #
1101
    #   Expand the user specified platforms to allow the use of BuildAlias
1102
    #   The (bad) side effect of this is that platform options get reorganised
1103
    #       PLATFORM,--Uses=ANOTHER  ==> PLATFORM --Uses=ANOTHER
1104
    #
1105
    #   Insert markers(++) into @aruments to mark when to process collected data
1106
    #   Insert before each PLATFORM and at the end of the list
1107
    #   platform specifier or the end of the list. Scan the arguments
1108
    #
1109
    @arguments = ExpandPlatforms( @arguments );
1110
    my @new_args;
1111
    foreach  ( @arguments )
1112
    {
1113
        push (@new_args, '++') unless ( m/^--/ );
1114
        push (@new_args, $_ );
1115
    }
1116
    push (@new_args, '++');
1117
    shift @new_args if $new_args[0] eq '++';
1118
 
1119
 
1120
    my $platform  = "";                         # current platform
1121
    my $notdefault  = 0;
1122
    my @uses = ();
1123
    my @pargs = ();
1124
 
1125
    foreach my $arg ( @new_args )
1126
    {
1127
        #
1128
        #   Extract known options
1129
        #   Unknown options bind to the current platform
1130
        #
1131
        if ( $arg =~ /^--/ ) {
1132
            if ( $arg =~ /^--NotDefault$/ ) {
1133
                $notdefault = 1;
1134
 
1135
            } elsif ( $arg =~/^--Uses=(.*)/ ) {
1136
                UniquePush (\@uses, $1);
1137
 
1138
            } elsif ( $arg =~/^--FunctionName=(.*)/ ) {
1139
                $fname = $1;
1140
 
1141
            } else {
1142
                push @pargs, $arg;
1143
            }
1144
            next;
1145
        }
1146
 
1147
        #
1148
        #   New platform. Save name for later. Collect arguments first
1149
        #
1150
        unless ( $arg eq '++' )
1151
        {
1152
            $platform = $arg;
1153
 
1154
            Error( "$fname() missing platform specification" )
1155
                unless ( $platform );
1156
 
1157
            Error( "$fname() product '$platform' contains invalid characters" )
1158
                unless ( $platform eq quotemeta( $platform ) );
1159
 
1160
            next;
1161
        }
1162
 
1163
        #
1164
        #   Create new platform
1165
        #   Have collected name and arguments
1166
        #
1167
        CreateBuildPlatformEntry($fname, $notdefault, undef, $platform, \@uses, \@pargs  );
1168
 
1169
        #
1170
        #   Reset collection variables for next platform
1171
        #
1172
        $platform = "";
1173
        $notdefault  = 0;
1174
        @uses = ();
1175
        @pargs = ();
1176
    }
1177
}
1178
 
1179
 
1180
#   PlatformArgument ---
1181
#       Append an argument list to the specified platform argument list.
1182
#       Internal use only
1183
#..
1184
 
1185
sub PlatformArgument
1186
{
1187
    my( $platform, @arguments ) = @_;
1188
 
1189
    Debug( "  PlatformArguments($platform, @arguments)" );
1190
 
1191
    HashJoin( \%BUILDPLATFORMARGS, $;, $platform, @arguments )
1192
        if ( $platform );
1193
}
1194
 
279 dpurdie 1195
#-------------------------------------------------------------------------------
5679 dpurdie 1196
# Function        : BuildExclude 
1197
#
1198
# Description     : Allow specific platforms to be excluded from the Build
1199
#                   Intended use:
1200
#                       Allow the use if a platform alias, but not all elements of it
1201
#                       ie: Use DEVLINUX, but not ARM9TDMI as we no longer support it 
1202
#                           in this version.
1203
#                   Multiple BuildExclude directives are allowed
1204
#                   Order or location is not important        
1205
#
1206
# Inputs          : Platforms names and options
1207
#                   Format:
1208
#                       --PLATFORM=xxxxx    (Marginal use)
1209
#                       --PRODUCT=yyyy      (Not very useful)
1210
#                       --TARGET=zzzz       (Default)
1211
#                       zzzz                (Same as --TARGET=ZZZZ)
1212
#                       
1213
#
1214
# Returns         : Nothing 
1215
#
1216
sub BuildExclude
1217
{
1218
    my( @arguments ) = @_;
1219
    Debug( "BuildExclude(@arguments)" );
1220
 
1221
    Error( "BuildExclude must appear before BuildName()..." )
1222
        if ( $BUILDNAME ne "" );
1223
 
1224
    #
1225
    #   Simply save the arguments for later
1226
    #   Allow multiple specs in the one definition
1227
    #
1228
    foreach ( @arguments)
1229
    {
5680 dpurdie 1230
        Error ("Invalid format: $_") if m/[,\s]/;
5679 dpurdie 1231
        UniquePush (\@BUILDEXCLUDE, split(/\s*,\s*/,$_));
1232
    }
1233
}
1234
 
1235
#-------------------------------------------------------------------------------
279 dpurdie 1236
# Function        : BuildName
1237
#
1238
# Description     : Defines the package name and version
1239
#
1240
# Inputs          : build arguments
1241
#                   Various formats are allowed for backward compatability
1242
#                   Must support a number of different formats
1243
#                       "name nn.nn.nn prj"
1244
#                       "name nn.nn.nn.prj"
1245
#
1246
#                       "name nn.nn.nn prj", "nn.nn.nn"
1247
#                       "name nn.nn.nn.prj", "nn.nn.nn"
1248
#
1249
#                       "name", "nn.nn.nn.prj"
1250
#
1251
#                       "name", "nn.nn.nn", "prj", --RelaxedVersion
1252
#
1253
# Returns         : Nothing
1254
#
227 dpurdie 1255
sub BuildName
1256
{
1257
    my( @arguments ) = @_;
1258
    my $relaxed_version_name = 0;
1259
    my @args;
1260
 
1261
    Debug( "BuildName(@arguments)" );
1262
 
315 dpurdie 1263
    Error( "Platform(s) not defined.",
227 dpurdie 1264
            "BuildAlias, BuildProduct and BuildPlatform directives must be defined prior to BuildName()." )
1265
        unless( scalar @BUILDPLATFORMS );
1266
 
1267
#.. Parse arguments
1268
#.
1269
    my $build_info = parseBuildName( @arguments );
1270
 
1271
    $BUILDNAME_PACKAGE = $build_info->{BUILDNAME_PACKAGE};
1272
    $BUILDNAME_VERSION = $build_info->{BUILDNAME_VERSION};
1273
    $BUILDNAME_PROJECT = $build_info->{BUILDNAME_PROJECT};
359 dpurdie 1274
    $BUILDNAME_SUFFIX  = $BUILDNAME_PROJECT ? '.' . $BUILDNAME_PROJECT : '';
227 dpurdie 1275
 
1276
    $BUILDNAME         = $build_info->{BUILDNAME};
1277
    $BUILDVERSION      = $build_info->{BUILDVERSION};
1278
 
1279
    $DEPLOY_PATCH      = $build_info->{DEPLOY_PATCH} || 0;
1280
 
1281
    #
1282
    #   Clobber processing done after values have been accumulated
1283
    #   as they may be used later
1284
    #
1285
    return if ( $Clobber );
4003 dpurdie 1286
    ToolsetFile('build.log');
1287
    ToolsetFile('ChangeLog', 'ChangeLog.bak') if ( $ScmHost eq "Unix" );
1288
 
359 dpurdie 1289
    #
1290
    #   Determine type of sandbox
1291
    #
1292
    $sandbox_exact = ( -f $::GBE_DPKG_SBOX . '/.exact' )
1293
        if ( $::GBE_DPKG_SBOX );
1294
 
227 dpurdie 1295
#.. Create the ChangeLog
1296
#
1297
    if ( -d "CVS" )                             # CVS support subdir
1298
    {
1299
        System( "$::GBE_PERL $::GBE_TOOLS/cvs2cl.pl --tags --branches --revisions --day-of-week" )
1300
            if ( $Nolog == 0 && $ScmHost eq "Unix" );
1301
    }
1302
 
1303
 
1304
#.. Create build.log summary information
1305
#
261 dpurdie 1306
    my ($sep) = "\n".(" " x 11) . ". ";
227 dpurdie 1307
 
261 dpurdie 1308
    Log( "\nBuild configuration (version $::GBE_VERSION)" );
1309
    Log( "Name ....... $BUILDNAME ($ScmHost)" );
1310
    Log( "Version .... $BUILDNAME_VERSION" );
1311
    Log( "DeployPatch. $DEPLOY_PATCH" ) if ($DEPLOY_PATCH);
1312
    Log( "Project .... $BUILDNAME_PROJECT" )if ($BUILDNAME_PROJECT);
1313
    Log( "Project .... ****** Specifically supressed ******" )unless ($BUILDNAME_PROJECT);
1314
    Log( "DateTime ... $::CurrentTime" );
1315
    Log( "AutoBuild... Enabled:$::GBE_ABT" ) if defined($::GBE_ABT) ;
359 dpurdie 1316
    Log( "Build dir... $Cwd" ) if defined($::GBE_ABT) || $::GBE_DPKG_SBOX;
4161 dpurdie 1317
    Log( "Build Mach.. $::GBE_HOSTNAME" ) if defined($::GBE_ABT);
227 dpurdie 1318
 
359 dpurdie 1319
    Log( "PERL ....... $::GBE_PERL" );
261 dpurdie 1320
    Log( "BIN  ....... $::GBE_BIN" );
1321
    Log( "TOOLS ...... $::GBE_TOOLS" );
1322
    Log( "CONFIG ..... $::GBE_CONFIG" );
1323
    Log( "MACHTYPE ... $::GBE_MACHTYPE" );
227 dpurdie 1324
 
261 dpurdie 1325
    Log( "PLATFORM ... " . PrintList([split(' ', $::GBE_PLATFORM)], $sep) )    if defined ($::GBE_PLATFORM);
5708 dpurdie 1326
    Log( "EXCLUDE .... " . PrintList([@BUILDEXCLUDE], $sep) )    if (@BUILDEXCLUDE);
261 dpurdie 1327
    Log( "BUILDFILTER. " . PrintList([split(' ', $::GBE_BUILDFILTER)], $sep) ) if defined ($::GBE_BUILDFILTER);
227 dpurdie 1328
 
261 dpurdie 1329
    Log( "DPKG_STORE.. $::GBE_DPKG_STORE" );
1330
    Log( "DPKG ....... $::GBE_DPKG" );
4688 dpurdie 1331
    Log( "DPKG_REPLI . $::GBE_DPKG_REPLICA" );
261 dpurdie 1332
    Log( "DPKG_CACHE . $::GBE_DPKG_CACHE" );
1333
    Log( "DPKG_LOCAL . $::GBE_DPKG_LOCAL" );
1334
    Log( "DPKG_SBOX .. $::GBE_DPKG_SBOX" );
359 dpurdie 1335
    Log( "Sandbox .... " . ($sandbox_exact ? "Exact" : "Development") );
3559 dpurdie 1336
    Log( "LocalFilter. $::GBE_SANDBOX/buildfilter") if ( $::GBE_SANDBOX && -f $::GBE_SANDBOX . '/buildfilter' );
227 dpurdie 1337
 
261 dpurdie 1338
    Log( "Platforms .. " . PrintPlatforms(\@BUILDPLATFORMS, $sep) );
227 dpurdie 1339
 
1340
    #
241 dpurdie 1341
    #   Generate a list of platforms that are completely unknown to JATS
4003 dpurdie 1342
    #   May be the result of a user typo or a guess
241 dpurdie 1343
    #
1344
    if ( @BUILD_BADNAME )
1345
    {
281 dpurdie 1346
        Log( "Unknown Pl . " . PrintPlatforms(\@BUILD_BADNAME, $sep) );
4551 dpurdie 1347
        Warning ("The following platform names are not known to JATS", "@BUILD_BADNAME");
241 dpurdie 1348
    }
4551 dpurdie 1349
 
241 dpurdie 1350
    #
4551 dpurdie 1351
    #   Detect multiple GENERIC targets
1352
    #       Only one such target can be processed on any one machine
1353
    #
1354
    if ($#GENERIC_TARGETS > 0)
1355
    {
1356
        Error ("Multiple GENERIC targets detected", PrintPlatforms(\@GENERIC_TARGETS, $sep));
1357
    }
1358
    if ($#GENERIC_TARGETS >= 0 )
1359
    {
1360
        $All = 1;
1361
    }
1362
 
1363
    #
227 dpurdie 1364
    #   Generate a list of active platforms
1365
    #   Ensure that there are some active platforms
1366
    #
1367
    GeneratePlatformList();
4551 dpurdie 1368
 
1369
    #
1370
    #   Detect a mix of Generic and non Generic targets
1371
    #       Cannot mix generic and non-generic targets
1372
    #
1373
    if ($#GENERIC_TARGETS >= 0 && $#BUILD_ACTIVEPLATFORMS >= 0)
1374
    {
1375
        if ($#BUILD_ACTIVEPLATFORMS != $#GENERIC_TARGETS )
1376
        {
1377
            Verbose("Active:", @BUILD_ACTIVEPLATFORMS);
1378
            Verbose("Generic:", @GENERIC_TARGETS);
1379
            Error("Cannot mix GENERIC and non-GENERIC targets in the one build");
1380
        }
1381
    }
1382
 
4778 dpurdie 1383
    #
1384
    #   Build System Generic Saniy Test
1385
    #       If Generic   then MUST be a GENERIC build
1386
    #       If NoGeneric then MUST not be a GENERIC build
1387
    #
1388
    if (defined $GenericBuild)
1389
    {
1390
        if ( scalar(@GENERIC_TARGETS) ne $GenericBuild)
1391
        {
1392
            Error("Generic build inconsistency",
1393
                  "Release Manager entry indicates: $GenericBuild",
1394
                  "Build File indicates: " . scalar(@GENERIC_TARGETS)
1395
                  );
1396
        }
1397
    }
1398
 
4003 dpurdie 1399
    unless( @BUILD_ACTIVEPLATFORMS )
1400
    {
5109 dpurdie 1401
        my $msg = 'GBE_BUILDFILTER prevents any targets being built';
4003 dpurdie 1402
        if (defined($::GBE_ABT)) {
227 dpurdie 1403
 
4003 dpurdie 1404
            # Build filter on this machine prevents the package building
1405
            # On a Build System this is not an error
1406
            #   Create a dummy platform called NOBUILD
1407
            #   Do not populate the interface directory with package data
1408
            #   Flag for jmake to do very little
1409
            #
1410
            CreateBuildPlatformEntry('Internal', 0, undef, 'NOBUILD');
1411
            $IgnorePkgs = 1;
1412
            $NoBuild = 1;
5109 dpurdie 1413
            Log( "Build for .. ". PrintPlatforms(['NOBUILD - ' . $msg], $sep));
4003 dpurdie 1414
 
1415
        } else {
5109 dpurdie 1416
            Error( $msg );
4003 dpurdie 1417
        }
1418
    }
1419
    else
1420
    {
1421
        Log( "Build for .. ". PrintPlatforms(\@BUILD_ACTIVEPLATFORMS, $sep));
1422
    }
1423
 
227 dpurdie 1424
    #
1425
    #   Generate an error if nothing can be done because the GBE_PLATFORM
1426
    #   masks any useful operation.
1427
    #
1428
    if ( $::GBE_PLATFORM )
1429
    {
1430
        my @MAKE_PLATFORMS;
1431
        my %active_platforms;
1432
 
239 dpurdie 1433
        #
1434
        #   Create a hash of active platforms based on the array of
1435
        #   active platforms to simplify testing
1436
        #
1437
        $active_platforms{$_} = 1 foreach ( @BUILD_ACTIVEPLATFORMS  );
227 dpurdie 1438
 
4551 dpurdie 1439
        unless ( $#GENERIC_TARGETS >= 0 )
227 dpurdie 1440
        {
239 dpurdie 1441
            foreach  ( split( ' ', $::GBE_PLATFORM) )
1442
            {
1443
                push @MAKE_PLATFORMS, $_
1444
                    if ( $active_platforms{$_} );
1445
            }
227 dpurdie 1446
 
239 dpurdie 1447
            Error ("The GBE_PLATFORM filter prevents any targets being made",
1448
                   "GBE_PLATFORM: $::GBE_PLATFORM" ) unless ( @MAKE_PLATFORMS );
227 dpurdie 1449
 
261 dpurdie 1450
            Log( "Make for ... ". PrintPlatforms(\@MAKE_PLATFORMS, $sep));
239 dpurdie 1451
        }
227 dpurdie 1452
 
1453
    }
1454
 
1455
    return 1;
1456
}
1457
 
1458
 
1459
sub BuildPreviousVersion
1460
{
1461
    my( $version ) = shift;
1462
 
1463
    $BUILDPREVIOUSVERSION = $version;
261 dpurdie 1464
    Log( "Previous Version ... $BUILDPREVIOUSVERSION" );
227 dpurdie 1465
 
1466
    return 1;
1467
}
1468
 
1469
 
1470
sub BuildInterface
1471
{
1472
    my( $ifdirname ) = @_;
1473
 
1474
 
1475
    #
1476
    #   Clobber the directory - at the end.
1477
    #
1478
    if ( $Clobber )
1479
    {
1480
        #
1481
        #   If this Interface directory contains the Dpackage.cfg file
1482
        #   then JATS has created DPACKAGE and it needs to be clobbered
1483
        #   Flag that it needs to be done later - when we know where it is
1484
        #
1485
        $DeleteDPACKAGE = 1 if ( -f "$ifdirname/Dpackage.cfg" );
1486
 
1487
        push @CLOBBERDIRS, $ifdirname;
1488
        return;
1489
    }
1490
 
1491
    #
1492
    #   In AutoBuildTool mode the entire interface directory
1493
    #   will be deleted. This allows the build to be retried
1494
    #
1495
    if (  defined($::GBE_ABT) )   # clobber mode ?
1496
    {
361 dpurdie 1497
        if ( -d $ifdirname )
227 dpurdie 1498
        {
361 dpurdie 1499
                RmDirTree( $ifdirname );
227 dpurdie 1500
        }
1501
    }
1502
 
1503
    if ( $ifdirname eq "local" ) {
341 dpurdie 1504
        mkpath ( "$ifdirname/inc" );
227 dpurdie 1505
        $BUILDLOCAL = "local";
1506
 
1507
    } else {
341 dpurdie 1508
        mkpath ( "$ifdirname/include" );
227 dpurdie 1509
        $BUILDINTERFACE = $ifdirname;
1510
        $::ScmInterface = $ifdirname;
1511
    }
341 dpurdie 1512
    mkpath ( "$ifdirname/bin" );
1513
    mkpath ( "$ifdirname/lib" );
227 dpurdie 1514
 
261 dpurdie 1515
    Log( "Interface .. $ifdirname" );
227 dpurdie 1516
    return 1;
1517
}
1518
 
1519
 
1520
sub BuildDirTree
1521
{
1522
    my( $dirfile, $dirhead ) = @_;
1523
    my( $dirname, $c );
1524
 
1525
    $dirhead = '.'
1526
        unless defined( $dirhead );
1527
 
1528
    if ( $Clobber )                             # clobber mode ?
1529
    {
1530
        push @CLOBBERDIRS, $dirhead unless $dirhead eq '.';
1531
        return;
1532
    }
1533
 
1534
    #
1535
    #   Allow for an empty "dirfile". This will allow a directory to be created
1536
    #   without the overhead of the file
1537
    #
1538
    if ( ! $dirfile )
1539
    {
261 dpurdie 1540
        Log( "DirTree .... $dirhead" );
341 dpurdie 1541
        mkpath ( $dirhead );
227 dpurdie 1542
    }
1543
    else
1544
    {
261 dpurdie 1545
        Log( "DirTree .... $dirfile within $dirhead" );
341 dpurdie 1546
        mkpath ( $dirhead );
1547
 
283 dpurdie 1548
        open( DIRFILE, '<' ,$dirfile ) ||
227 dpurdie 1549
            Error( "cannot open '$dirfile'" );
1550
 
1551
        while( $dirname = <DIRFILE> )
1552
        {
1553
            chop $dirname;
1554
            $dirname =~ s/#.*//;
1555
            $c = $dirname =~ s/\s*(\S+).*/$1/g;
1556
 
1557
            next unless ( $c == 1 );
1558
 
1559
            if ( ! -d "$dirhead/$dirname" )
1560
            {
261 dpurdie 1561
                Log( "Dir ........ $dirhead/$dirname" );
341 dpurdie 1562
                mkpath ( "$dirhead/$dirname" );
227 dpurdie 1563
            }
1564
        }
1565
 
1566
        close( DIRFILE );
1567
    }
1568
    $BUILDDIRTREE = $dirhead;
1569
}
1570
 
1571
#-------------------------------------------------------------------------------
1572
# Function        : IncludePkg
1573
#
1574
# Description     : Examine a fully specified package directory for a file
1575
#                   that will specify packages to be included. This allows
1576
#                   a package to be simply a package of other packages
1577
#
1578
#                   Internal function. Not to be used by users
1579
#
1580
# Inputs          : Name of the package
1581
#                   Full directory path of the package to examine
1582
#
1583
# Returns         : Nothing
1584
#
1585
sub IncludePkg
1586
{
1587
    my ($name, $pkg) = @_;
1588
    my $file = "$pkg/incpkg";
1589
 
363 dpurdie 1590
    Debug ("IncludePkg: $name, $pkg" );
227 dpurdie 1591
 
1592
    #
1593
    #   Using a require will ensure that the package is only processed once
1594
    #   even though the function user may be called multiple times.
1595
    #   Also prevents recursion within included packages.
1596
    #
1597
    if ( -f $file  )
1598
    {
261 dpurdie 1599
        Log( "PackageIncludes. $name" ) unless ( $INC{$file} );
227 dpurdie 1600
        require $file;
1601
    }
1602
}
1603
 
1604
 
1605
sub LinkSandbox
1606
{
1607
    my( $name, $path, $platform ) = @_;
1608
    return if ( $Clobber );                     # clobber mode ?
2078 dpurdie 1609
 
371 dpurdie 1610
    Warning ("LinkSandbox() This directive is being deprecated.");       #Dec-2011
227 dpurdie 1611
 
1612
    Error ("LinkSandbox() expects three arguments:  @_")
1613
        unless ( $#_ == 2 );
1614
 
371 dpurdie 1615
    Error ("LinkSandbox not allowed in ABT build","It can only be used in a Development Environment")
299 dpurdie 1616
        if ( $::GBE_ABT );
1617
 
227 dpurdie 1618
    Debug( "LinkSandbox:" );
1619
    Debug( "Package:   $name" );
1620
    Debug( "Version:   $path" );
1621
 
1622
    DataDirective("LinkSandbox");               # This directive allowed here
1623
 
2078 dpurdie 1624
    if ( $IgnorePkgs )
1625
    {
1626
        Log( "LinkSandbox. $name ($path) - Ignored" );
1627
        return;
1628
    }
1629
 
227 dpurdie 1630
#
1631
#   If GBE_BUILDFILTER exists, Import 'user' platform
1632
#   specification and filter against the BUILD_ACTIVEPLATFORMS.
1633
#
261 dpurdie 1634
    Log( "LinkSandbox. $name ($path)" );
227 dpurdie 1635
 
1636
    if ( ! -d $path )                           # sandbox exists ?
1637
    {
261 dpurdie 1638
        Log( "WARNING .... Sandbox $path not available" );
227 dpurdie 1639
    }
1640
    else
1641
    {
363 dpurdie 1642
        my @platforms;
1643
        if ( !defined($platform) || $platform eq "*" ) {
1644
            @platforms = @BUILD_ACTIVEPLATFORMS;
1645
        } else {
1646
            @platforms = ExpandPlatforms( split( ',', $platform ) );
1647
        }
1648
 
227 dpurdie 1649
        $path = Realpath( $path );
363 dpurdie 1650
        IncludePkg ( $name, $path );
1651
        foreach my $platform ( @platforms )
227 dpurdie 1652
        {
363 dpurdie 1653
            LinkEntry( $platform, $path, $name, "!sandbox", 1, 1 );
227 dpurdie 1654
        }
1655
    }
1656
}
1657
 
1658
 
1659
#-------------------------------------------------------------------------------
1660
# Function        : LinkPkgArchive
1661
#
1662
# Description     : Include an external package into the build sandbox
1663
#                   by extending the compiler and linker search paths to
1664
#                   include suitable directories found in the package
1665
#
1666
# Inputs          : package name
1667
#                   package version
1668
#
1669
sub LinkPkgArchive
1670
{
1671
    my( $name, $version ) = @_;
1672
 
1673
    return BuildPkgArchive( @_ )
1674
        if ( $ForceBuildPkg );                  # Forcing interface directory
1675
    return if ( $Clobber );                     # clobber mode ?
1676
 
1677
    Debug( "LinkPkgArchive:" );
1678
    Debug( "Name:      $name" );
1679
    Debug( "Version:   $version" );
1680
 
1681
    DataDirective("LinkPkgArchive");            # This directive allowed here
1682
 
2078 dpurdie 1683
    if ( $IgnorePkgs )
1684
    {
1685
        Log( "LinkPkgArchive .. $name ($version) - Ignored" );
1686
        return;
1687
    }
1688
 
227 dpurdie 1689
    #
1690
    #   Ensure that we have do not have multiple definitions
1691
    #
1692
    if ( PackageEntry::Exists( $name, $version ) )
1693
    {
261 dpurdie 1694
        Log( "Duplicate Package: $name, $version. Duplicate entry ignored" );
227 dpurdie 1695
        return;
1696
    }
1697
 
1698
    if ( $Cache && $::GBE_DPKG_CACHE )
1699
    {
1700
        my $mode = ($Cache > 1) ? "-refresh" : "";
331 dpurdie 1701
        Log( "LinkPkgArchive .. $name ($version) Update Cache" );
5744 dpurdie 1702
        System('--NoExit', "$::GBE_PERL $::GBE_TOOLS/cache_dpkg.pl $mode -wait -quiet $name/$version" );
227 dpurdie 1703
    }
1704
 
1705
    #
1706
    #   Locate the package ONCE
1707
    #
331 dpurdie 1708
    Log( "LinkPkgArchive .. $name ($version)" );
227 dpurdie 1709
    my ($pkg, $local ) = PackageLocate( $name, $version );
1710
    if ( $pkg )
1711
    {
1712
        #
1713
        #   Generate package rules for each active platform
1714
        #
363 dpurdie 1715
        IncludePkg ( $name, $pkg );
1716
        foreach my $platform ( @BUILD_ACTIVEPLATFORMS, '--' )
227 dpurdie 1717
        {
331 dpurdie 1718
            LinkEntry( $platform, $pkg, $name, $version, 0, $local );
227 dpurdie 1719
        }
1720
    }
1721
}
1722
 
1723
#-------------------------------------------------------------------------------
1724
# Function        : PackageLocate
1725
#
1726
# Description     : Locate a package
1727
#                   Once located a package will be processed for each
1728
#                   platform, but it need only be located ONCE
1729
#
1730
# Inputs          : package name
1731
#                   package version
1732
#
1733
# Returns         : path to the package
1734
#                   local       1 - From local package repository
1735
#
1736
sub PackageLocate
1737
{
1738
    my ($name, $uversion ) = @_;
283 dpurdie 1739
    my $pkg;
227 dpurdie 1740
    my $local = 1;
359 dpurdie 1741
    my $sandbox = ! $sandbox_exact;
227 dpurdie 1742
    my $isa_cache = 0;
1743
    my $version;
1744
 
1745
    Debug( "PackageLocate: ($name/$uversion)" );
1746
 
1747
    #
1748
    #   Look in each package archive directory
1749
    #
1750
    foreach my $dpkg ( split( $::ScmPathSep, $::GBE_DPKG_SBOX),
1751
                       '--NotSandbox',
1752
                       split( $::ScmPathSep, $::GBE_DPKG_LOCAL),
1753
                       '--NotLocal',
1754
                       split( $::ScmPathSep, $::GBE_DPKG_CACHE),
1755
                       '--NotCache',
4688 dpurdie 1756
                       split( $::ScmPathSep, $::GBE_DPKG_REPLICA),
227 dpurdie 1757
                       split( $::ScmPathSep, $::GBE_DPKG),
313 dpurdie 1758
                       split( $::ScmPathSep, $::GBE_DPLY),
227 dpurdie 1759
                       split( $::ScmPathSep, $::GBE_DPKG_STORE) )
1760
    {
1761
 
1762
        #
1763
        #   Detect various tags that have been placed in the search list
1764
        #   to flag the end of the sandbox search and the end of the local
1765
        #   archive search
1766
        #
1767
        if ( $dpkg eq '--NotSandbox' )
1768
        {
1769
            $sandbox = 0;
1770
            next;
1771
        }
1772
        if ( $dpkg eq '--NotLocal' )
1773
        {
1774
            $local = 0;
1775
            $isa_cache = 1;
1776
            next;
1777
        }
1778
        if ( $dpkg eq '--NotCache' )
1779
        {
1780
            $isa_cache = 0;
1781
            next;
1782
        }
1783
 
1784
 
1785
        #
1786
        #   If we are playing in a sandbox, then the version number is
1787
        #   not used. The Package suffix is still used so that we can
1788
        #   differentiate sysbasetypes.xxxxx.mas and sysbasetypes.xxxxx.syd
1789
        #
1790
        if ( $sandbox )
1791
        {
359 dpurdie 1792
            my ($pn, $pv, $ps ) = SplitPackage ($name, $uversion );
227 dpurdie 1793
            $version = 'sandbox';
1794
            $version .= '.' . $ps if ( $ps );
1795
        }
1796
        else
1797
        {
1798
            $version = $uversion;
1799
        }
1800
 
1801
        #
1802
        #   Alias support
1803
        #   If the 'version' is '!current' then use a version of:
1804
        #       current
1805
        #       current_<USER_NAME>
1806
        #   This is an old mechanism whose use should not be encouraged
1807
        #
1808
        #..
1809
        if ( $version eq "!current" )
331 dpurdie 1810
        {
5819 dpurdie 1811
            Error ("Use of !current is not allowed in ABT build")
331 dpurdie 1812
                if ( $::GBE_ABT );
227 dpurdie 1813
 
331 dpurdie 1814
            $pkg = "$dpkg/$name/current";       # current
227 dpurdie 1815
            $pkg = "$dpkg/$name/current.lnk"
1816
                if ( -e "$dpkg/$name/current.lnk" );
1817
 
331 dpurdie 1818
                                                # USER specific current
1819
            EnvImport( "USER" );
227 dpurdie 1820
            $pkg = "$dpkg/$name/current_$::USER"
1821
                if ( -e "$dpkg/$name/current_$::USER" );
1822
 
1823
            $pkg = "$dpkg/$name/current_$::USER.lnk"
1824
                if ( -e "$dpkg/$name/current_$::USER.lnk" );
1825
        }
1826
        else
1827
        {                                       # standard
1828
            $pkg = "$dpkg/$name/$version";
1829
            $pkg = "$dpkg/$name/$version.lnk"
1830
                if ( -e "$dpkg/$name/$version.lnk" );
1831
        }
1832
 
1833
        #
1834
        #   Using a soft link
1835
        #   Emulate a link in software. The link file contains one line
1836
        #   which is the real pathname of the package
1837
        #
1838
        if ( $pkg =~ m~(.*)\.lnk$~  )
1839
        {
1840
            #
1841
            #   Warn the user if both a link and a real directory
1842
            #   are both present - the link may well be incorrect
1843
            #
1844
            my $non_link = $1;
1845
            Warning ("Suspect package link: $pkg",
1846
                     "Both a link and a package where found - using the link" )
1847
                                                            if ( -d $non_link );
1848
 
1849
            Debug( "           link found -> $pkg" );
1850
            my $link_src = $pkg;
283 dpurdie 1851
            open( LNKFILE, '<', "$pkg" ) || Error( "cannot open '$pkg'" );
227 dpurdie 1852
            $pkg = <LNKFILE>;                   # real path
1853
            close( LNKFILE );
1854
            $pkg = '' unless ( $pkg );
5819 dpurdie 1855
            $pkg =~ s~\s+$~~;
1856
            if ($pkg =~ s~^GBE_SANDBOX/~$::GBE_SANDBOX/~)
1857
            {
1858
                    # If the target sandbox is in the 'deploymode' then the package
1859
                    # will not be in the expected location. It will be in a 'build/deploy'
1860
                    # subdir. Remove the pkg/name dir to get to the root of the package
1861
                    my @dirs = File::Spec->splitdir( $pkg );
1862
                    splice(@dirs, -2);
1863
                    my $deployBox = catdir(@dirs, 'build', 'deploy');
1864
                    $pkg = $deployBox if ( -d $deployBox);
1865
            }
227 dpurdie 1866
 
2078 dpurdie 1867
            unless ( -d $pkg )
1868
            {
1869
                Error ("Broken link: $pkg",
1870
                       "Source link: $link_src",
1871
                       "Try deleting the .lnk file" ) unless ( $NoPackageError );
1872
 
1873
                Warning ("Package not available. Broken link: $pkg");
1874
            }
227 dpurdie 1875
        }
1876
 
1877
        Debug( "           searching $pkg" );
1878
 
1879
        #   Does the package directory exist?
1880
        #   Terminate the directory name with a "/" to detect hidden spaces
1881
        #..
1882
        $pkg =~ s~//~/~g;
1883
        next unless ( -d "$pkg/" );             # exists ?
1884
 
1885
        #
1886
        #   If the package exists within the dpkg_archive cache then mark the
1887
        #   version as having been used. Used by cache cleanup algorithms
1888
        #
1889
        if ( $isa_cache  )
1890
        {
1891
            TouchFile ( "$pkg/used.cache", "Marks the cache copy as being used");
1892
        }
1893
 
1894
        #
1895
        #   Use the first suitable package found
1896
        #..
1897
 
1898
        Debug( "           importing $pkg" );
1899
        return $pkg, $local;
1900
    }
1901
 
1902
    #
1903
    #   Package not found
1904
    #   This is an error, although it can be bypassed
1905
    #
261 dpurdie 1906
    Error ("Required package not found: '$name/$version'" ) unless ( $NoPackageError );
227 dpurdie 1907
 
261 dpurdie 1908
    Log( "WARNING .... Package not available: '$name/$version'" );
283 dpurdie 1909
    return;
227 dpurdie 1910
}
1911
 
1912
 
1913
#-------------------------------------------------------------------------------
1914
# Function        : LinkEntry
1915
#
1916
# Description     : Scan a package an locate platform specific directories
1917
#                   Create data structures to capture the information
1918
#                   This function is used by LinkPkgArchive and LinkSandbox
1919
#                   to perfom the bulk of package inclusion work.
1920
#
1921
# Inputs          : platform being processed
1922
#                   path to the package
1923
#                   name of the package
1924
#                   version of the package
1925
#                   sandbox support (non-zero)
331 dpurdie 1926
#                   local package
227 dpurdie 1927
#
1928
sub LinkEntry
1929
{
331 dpurdie 1930
    my( $platform, $pkg, $name, $version, $sandbox, $local ) = @_;
227 dpurdie 1931
    my( $entry );
1932
 
1933
    #   Create entry record
1934
    #
1935
    #..
331 dpurdie 1936
    $entry = PackageEntry::New( $pkg, $name, $version, $sandbox, 'link', $local );
227 dpurdie 1937
 
1938
    #   Populate includes:
1939
    #
1940
    #   - include/$platform                 (eg include/solaris)
1941
    #   - inc/$platform                     (eg inc/solaris)
1942
    #   - include.$platform                 (eg include.solaris)
1943
    #   - inc.$platform                     (eg inc.solaris)
1944
    #   - include                           (eg include)
1945
    #   - inc                               (eg inc)
1946
    #
1947
    #   plus, product specialisation directores
1948
    #
1949
    #   eg. BuildProduct( 'IDFC', 'WIN32' );
1950
    #
1951
    #   - inc/IDFC_WIN32                    <- derived platform
1952
    #   - inc/IDFC                          <- product
1953
    #   - inc/WIN32                         <- target
1954
    #..
1955
    my $parts = $BUILDINFO{$platform}{PARTS};
1956
 
1957
    foreach my $part ( @$parts )
1958
    {
1959
        $entry->RuleInc( "/include." . $part ) if ( !$sandbox );
1960
        $entry->RuleInc( "/inc." . $part )     if ( !$sandbox );
1961
        $entry->RuleInc( "/include/" . $part ) if ( !$sandbox );
1962
        $entry->RuleInc( "/inc/" . $part );
1963
    }
1964
 
1965
    #
1966
    #   Also search the root include directory - last
1967
    #
1968
    $entry->RuleInc( "/include" )               if ( !$sandbox );
1969
    $entry->RuleInc( "/inc" );
1970
 
1971
    #   Populate libraries:
1972
    #
1973
    #   - lib/lib.$platform[D|P]            (eg lib/lib.sparcD)
1974
    #   - lib/$platform[D|P]                (eg lib/lib.sparc)
1975
    #   - lib.$platform[D|P]                (eg lib.sparcD)
1976
    #
1977
    #   plus, product specialisation directores
1978
    #
1979
    #   eg. BuildProduct( 'IDFC', 'WIN32' );
1980
    #
1981
    #   - lib/IDFC_WIN32                    <- derived platform
1982
    #   - lib/IDFC                          <- product
1983
    #   - lib/WIN32                         <- target
1984
    #..
1985
    $parts = $BUILDINFO{$platform}{PARTS};
1986
 
1987
    foreach my $part ( @$parts )
1988
    {
1989
        $entry->RuleLib("/lib" . ".$part" )     if ( !$sandbox );
1990
        $entry->RuleLib("/lib" . "/lib.$part" ) if ( !$sandbox );
1991
        $entry->RuleLib("/lib" . "/$part" );
1992
    }
1993
 
1994
    #
1995
    #   Some extra places to search
1996
    #   None. This is good as it indicates that all locations are described in PARTS
1997
    #
1998
    #   Do NOT search in /lib. There are no libraries that work on all platforms
1999
    #   Libraries are binaries!
2000
    #
2001
    #    $entry->RuleLib( "/lib" );
2002
 
2003
    #   Tools:
2004
    #
2005
    #   Tools provide an extensible search path for tools and
2006
    #   utilities used to build programs. These are tools that
2007
    #   are executable on the current host machine and are
2008
    #   independent of the toolset.
2009
    #
2010
    #..
2011
    $entry->ExamineToolPath();
2012
    $entry->ExamineThxPath($platform);
2013
    $entry->Cleanup();                          # cleanup tables
2014
 
2015
    #
2016
    #   Add the package entry to the array of such entries for
2017
    #   the current platform. Maintain the discovery order
2018
    #
2019
    #..
2020
    push ( @{$PKGRULES{$platform}}, $entry );
2021
}
2022
 
2023
 
2024
#-------------------------------------------------------------------------------
2025
# Function        : BuildPkgArchive
2026
#
2027
# Description     : Include an external package into the build sandbox
2028
#                   by copying the packages files into the interface directory
2029
#
2030
# Inputs          : package name
2031
#                   package version
2032
#
2033
sub BuildPkgArchive
2034
{
2035
    my( $name, $version ) = @_;
2036
 
2037
    return if ( $Clobber );                     # clobber mode ?
2038
 
2039
    Debug( "BuildPkgArchive:" );
2040
    Debug( "Name:      $name" );
2041
    Debug( "Version:   $version" );
2042
 
2043
    DataDirective("BuildPkgArchive");           # This directive allowed here
2044
 
2078 dpurdie 2045
    if ( $IgnorePkgs )
2046
    {
2047
        Log( "BuildPkgArchive . $name ($version) - Ignored" );
2048
        return;
2049
    }
2050
 
227 dpurdie 2051
    #
2052
    #   Ensure that we have do not have multiple definitions
2053
    #
2054
    if ( PackageEntry::Exists( $name, $version ) )
2055
    {
261 dpurdie 2056
        Log( "Duplicate Package: $name, $version. Duplicate entry ignored" );
227 dpurdie 2057
        return;
2058
    }
2059
 
2060
    if ( $Cache && $::GBE_DPKG_CACHE )
2061
    {
2062
        my $mode = ($Cache > 1) ? "-refresh" : "";
261 dpurdie 2063
        Log( "BuildPkgArchive . $name ($version) Update Cache" );
5744 dpurdie 2064
        System('--NoExit', "$::GBE_PERL $::GBE_TOOLS/cache_dpkg.pl $mode -wait -quiet $name/$version" );
227 dpurdie 2065
    }
2066
 
2067
    #
2068
    #   Locate the package
2069
    #   Use the first instance of the package that it found
2070
    #
261 dpurdie 2071
    Log( "BuildPkgArchive . $name ($version)" );
227 dpurdie 2072
    my ( $pkg, $local ) = PackageLocate( $name, $version );
2073
    if ( $pkg )
2074
    {
2075
        #
2076
        #   Create a Package Entry
2077
        #
331 dpurdie 2078
        my $entry = PackageEntry::New( $pkg, $name, $version, 0, 'build', $local );
227 dpurdie 2079
 
2080
        #
2081
        #   Determine if the package needs to be installed:
2082
        #       If the package is a 'local' package then force transfer
2083
        #       If the user has specified --cache then force transfer
2084
        #       If package is newer that copy, then force transfer
2085
        #       If copy does not exist, then force a transfer
2086
        #
2087
        my $tag_dir = "$Cwd/$BUILDINTERFACE/BuildTags";
2088
        my $tag_file = "$tag_dir/${name}_${version}.tag";
2089
 
2090
        my $package_installed;
2091
        $package_installed = 1
2092
            if ( !$local &&
2093
                 !$Cache &&
2094
                 !FileIsNewer( $entry->GetBaseDir('descpkg'), $tag_file ) );
2095
 
2096
        #
2097
        #   Determine the package format and use the appropriate installer
2098
        #   Supported formats
2099
        #       1) Package has a descpkg file (new style)
2100
        #       2) Package has a InstallPkg.sh file (old style)
2101
        #       3) Package has a Install.sh file (old style is it used ??)
2102
        #
2103
        if ( $package_installed ) {
2104
            Verbose ("Package already installed: $name, $version");
2105
 
2106
        } else {
261 dpurdie 2107
            Log( "                . installing '$pkg'" );
2108
            Log( "                . -> " . readlink($pkg) ) if ( -l $pkg );
227 dpurdie 2109
 
2110
            if ( -e "$pkg/descpkg" )
2111
            {
2112
 
2113
                #
2114
                #   If forcing a BuildPkg, then don't use symlinks
2115
                #   to files in dpkg_archive
2116
                #
331 dpurdie 2117
                my @opts;
2118
                push @opts, "--NoSymlinks" if ( $ForceBuildPkg );
2119
                push @opts, "--AllowOverWrite" if ( $local );
227 dpurdie 2120
 
2121
                #
2122
                #   Determine all the Platforms, Products and Targets
2123
                #   that need to be installed
2124
                #
2125
                my $arglist = GenerateInstallArgumentList();
331 dpurdie 2126
                System( "cd $pkg; $::GBE_PERL $::GBE_TOOLS/installpkg.pl $Cwd/$BUILDINTERFACE $Cwd @opts $arglist");
227 dpurdie 2127
                Error( "Package installation error" ) if ( $? != 0 );
2128
            }
2129
            elsif ( -e "$pkg/InstallPkg.sh" )
2130
            {
2131
                System( "(cd $pkg; ./InstallPkg.sh $Cwd/$BUILDINTERFACE $Cwd)" );
2132
            }
2133
            elsif ( -e "$pkg/Install.sh" )
2134
            {
2135
                System( "(cd $pkg; ./Install.sh $Cwd/$BUILDINTERFACE $Cwd)" );
2136
            }
2137
            else
2138
            {
2139
                Error ("Unknown package format for package $name/$version found in $pkg");
2140
            }
2141
 
2142
            #
2143
            #   Tag the package as installed - after it has been transferred
2144
            #
2145
            mkdir ( $tag_dir );
2146
            TouchFile( $tag_file );
2147
        }
2148
 
2149
        #
2150
        #   Process package
2151
        #
2152
        IncludePkg ( $name, $pkg );
2153
 
2154
        #
2155
        #   Complete the creation of the package entry
2156
        #   Add the information for all platforms
2157
        #
2158
        $entry->Cleanup();
2159
        for my $platform (@BUILD_ACTIVEPLATFORMS)
2160
        {
2161
            $entry->ExamineToolPath();
2162
            $entry->ExamineThxPath($platform);
2163
            push ( @{$PKGRULES{$platform}}, $entry );
2164
        }
2165
    }
2166
}
2167
 
2168
#-------------------------------------------------------------------------------
311 dpurdie 2169
# Function        : CreateInterfacePackage
2170
#
2171
# Description     : Create a dummy package entry to describe the Interface
2172
#                   This is done AFTER all the BuildPkgArchive directives have
2173
#                   been processed so that the interface directory is fully
2174
#                   processed
2175
#
2176
# Inputs          : None
2177
#
2178
# Returns         : 
2179
#
2180
sub CreateInterfacePackage
2181
{
2182
    foreach my $platform ( @BUILD_ACTIVEPLATFORMS )
2183
    {
2184
        my $entry = PackageEntry::Interface( "$::Cwd/$BUILDINTERFACE" );
2185
 
2186
        #
2187
        #   Locate include and lib bits within the interface
2188
        #   This is much simpler than for a LinkPkgArchive as the form
2189
        #   has been sanitized
2190
        #
2191
        my $parts = $BUILDINFO{$platform}{PARTS};
2192
 
2193
        foreach my $part ( @$parts )
2194
        {
2195
            $entry->RuleInc( "/include/" . $part );
2196
        }
2197
        $entry->RuleInc( "/include" );
2198
 
2199
        foreach my $part ( @$parts )
2200
        {
2201
            $entry->RuleLib("/lib/" . $part );
2202
        }
2203
 
2204
        $entry->ExamineToolPath();
2205
        $entry->ExamineThxPath($platform);
2206
        $entry->Cleanup();
2207
 
2208
        #
2209
        #   Add the package entry to the array of such entries for
2210
        #   the current platform. Force it to be the first one as
2211
        #   the interface directory will be scanned first
2212
        #
2213
        unshift ( @{$PKGRULES{$platform}}, $entry );
2214
    }
2215
}
2216
 
2217
#-------------------------------------------------------------------------------
227 dpurdie 2218
# Function        : GenerateInstallArgumentList
2219
#
2220
# Description     : Generate an argument list for the installpkg.pl script
2221
#                   The argument list is of the form
2222
#                       --Platform:xx[:xx[:xx]] --Platform:yy[:yy[:yy]] ...
2223
#                   Where xx is:
2224
#                       * a 'part' of the target platform
2225
#                         Order is: platform, product, ...  target( in that order )
2226
#                       * --Option[=yyy]
2227
#                        An option to be passed to the script. These are bound only
2228
#                        to the enclosed platform.
2229
# Inputs          :
2230
#
2231
# Returns         : See above
2232
#
2233
sub GenerateInstallArgumentList
2234
{
2235
    my @arglist;
2236
 
2237
    #
2238
    #   Generate the argument list as an array
2239
    #
2240
    for (@BUILD_ACTIVEPLATFORMS)
2241
    {
2242
        my @args = '--Platform';
2243
        push @args, @{$BUILDINFO{$_}{PARTS}};
2244
        push @arglist, join (":" , @args );
2245
    }
2246
 
2247
    return "@arglist";
2248
}
2249
 
2250
#-------------------------------------------------------------------------------
2251
# Function        : GeneratePlatformList
2252
#
2253
# Description     : Return a list of platforms that should particiate in this
2254
#                   build. This is a function of
2255
#                       1) Platforms defined in the build.pl file
5679 dpurdie 2256
#                       2) Platforms excluded in the build.pl file
2257
#                       3) User filter defined in GBE_BUILDFILTER
227 dpurdie 2258
#
2259
#                   The primary use of this function is to limit the creation
2260
#                   of makefiles to those that have supported compilers on
2261
#                   the underlying machine.
2262
#
2263
#                   GBE_BUILDFILTER is a space seperated string of words
2264
#                   Each word may be one of
2265
#                       OPTION=TAG or OPTION=!TAG
2266
#                       TAG or !TAG. This is the same as --TARGET=TAG
2267
#
2268
#                   Bare tags are taken to be TARGETS.
2269
#
2270
#                   Where OPTION may be one of
2271
#                       --PLATFORM
2272
#                       --PRODUCT
2273
#                       --TARGET
5679 dpurdie 2274
#                   For a BuildProduct( AA,BB,CC)
2275
#                       Product     - AA
2276
#                       Targets     - BB, CC
2277
#                       Platforms   - AA_BB, AA_CC
227 dpurdie 2278
#
2279
#                   Special cases
2280
#                   1) If GBE_BUILDFILTER is empty, then all available platforms are used
2281
#                      The global $All is set, then all available platforms are used
2282
#                   2) If the first word of GBE_BUILDFILTER is a negative filter,
2283
#                      ie is used the !xxxx or yyy=!xxxx construct, then it is assumed
2284
#                      that the filter will start with all available platforms
2285
#                   3) The special word --ALL forces selection of ALL platforms
2286
#                      and may reset any existing scanning
2287
#                   4) GBE_BUILDFILTER is parsed left to right. It is possible to add and
2288
#                      subtract items from the list.
2289
#                   5) OPTIONS are case insensitive
2290
#                      TAGS are case sensitive
2291
#
2292
#
2293
# Inputs          : GBE_BUILDFILTER from the environment
2294
#
2295
# Returns         : An array of platforms to include in the build
2296
#                   Maintains @BUILD_ACTIVEPLATFORMS  - the last calculated result
2297
#                   Ensures that @DEFBUILDPLATFORMS is a subset of @BUILD_ACTIVEPLATFORMS
2298
#
2299
sub GeneratePlatformList
2300
{
2301
    #
2302
    #   Return the cached result for speed
2303
    #   The value need only be calculated once
2304
    #
2931 dpurdie 2305
    unless ( @BUILD_ACTIVEPLATFORMS )
227 dpurdie 2306
    {
2307
        my ($platform_filter);
2308
        my %result;
2309
        my %part_to_platform;
2310
 
2311
        #
2312
        #   Create a data structure to assist in the production of the platform list
2313
        #   The structure will be a hash of hashes of arrays
2314
        #
2315
        #   The first level hash will be keyed by the word TARGET, PRODUCT or PLATFORM
2316
        #   The second level of the hash will keyed by available targets, products or platforms
2317
        #   The value of the field will be an array of platforms that match the keyword
2318
        #
2319
        for my $platform (keys (%::BUILDINFO))
2320
        {
2321
            my $pParts = $::BUILDINFO{$platform};
2322
 
2323
            #
2324
            #   Skip platforms that are known to be unavailable on this build
2325
            #   machine. Self configure
2326
            #
2327
            next if ( $pParts->{NOT_AVAILABLE} );
2328
 
2329
            my $target  = $pParts->{TARGET};
2330
            my $product = $pParts->{PRODUCT};
2331
 
2332
            push @{$part_to_platform{'PLATFORM'}{$platform}}, $platform;
2333
            push @{$part_to_platform{'TARGET'}  {$target}}  , $platform;
2334
            push @{$part_to_platform{'PRODUCT'} {$product}} , $platform;
2335
        }
2336
        #
2337
        #   Determine the source of the filter
2338
        #   If the user provides one, then use it.
2339
        #   Otherwise its taken from the environment.
2340
        #
2341
        #   Global build all platforms - Kill any user filter
2342
        #
2343
        if ( $All )
2344
        {
2345
            $platform_filter = "";
2346
        }
2347
        else
2348
        {
2349
            $platform_filter = "";
2350
            $platform_filter = $::GBE_BUILDFILTER
2351
                if ( defined($::GBE_BUILDFILTER) );
2352
        }
2353
        Debug( "GeneratePlatformList: Filter:$platform_filter" );
2354
 
2355
        #
2356
        #   Detect the special cases
5679 dpurdie 2357
        #       1) No user definition
227 dpurdie 2358
        #       2) First word contains a subtractive element
5679 dpurdie 2359
        #   And assume all platforms    
227 dpurdie 2360
        #
2361
        my (@filter) = split( ' ', $platform_filter );
2362
 
2363
        if ( !scalar @filter || $filter[0] =~ m/^$/ || $filter[0] =~ m/!/ )
2364
        {
2365
            %result = %{$part_to_platform{'PLATFORM'}}
2366
                if exists $part_to_platform{'PLATFORM'} ;
2367
        }
5679 dpurdie 2368
 
227 dpurdie 2369
#DebugDumpData( "PartToPlatform", \%part_to_platform );
2370
 
2371
        #
2372
        #   Process each element in the user filter list
2373
        #   Expand platforms into known aliases
2374
        #
2375
        for my $word (@filter)
2376
        {
2377
            my $platform;
2378
 
2379
            if ( $word =~ m/^--ALL/i )
2380
            {
2381
                %result = %{$part_to_platform{'PLATFORM'}};
2382
            }
2383
            elsif ( $word =~ m/^--(TARGET)=(!?)(.*)/i ||
2384
                    $word =~ m/^--(PRODUCT)=(!?)(.*)/i ||
2385
                    $word =~ m/^--(PLATFORM)=(!?)(.*)/i ||
2386
                    ( $word !~ m/^-/ && $word =~ m/()(!?)(.*)/ )
2387
                )
2388
            {
2389
                my $table = uc($1);
2390
                $table = "TARGET"
2391
                    unless ( $1 );
2392
 
2393
                #
2394
                #   Expand PLATFORMs into known aliases
2395
                #   Alias will expand to PLATFORMs so it won't work unless we are
2396
                #   processing PALTFORMs.
2397
                #
2398
                my @taglist = ( $table eq "PLATFORM" ) ? ExpandPlatforms($3) : $3;
2399
 
2400
                #
2401
                #   Add / Remove items from the result
2402
                #
2403
                for my $item ( @taglist )
2404
                {
2405
                    my $plist = $part_to_platform{$table}{$item};
2406
                    for ( @{$plist})
2407
                    {
2408
                        if ( $2 )
2409
                        {
2410
                            delete $result{$_};
2411
                        }
2412
                        else
2413
                        {
2414
                            $result{$_} = 1;
2415
                        }
2416
                    }
2417
                }
2418
            }
2419
            else
2420
            {
2421
                print "GBE_BUILDFILTER filter term not understood: $word\n";
2422
            }
2423
        }
2424
 
2425
        #
5679 dpurdie 2426
        #   Process BuildExclude
2427
        #   A list of 
2428
        #
2429
        for my $word (@BUILDEXCLUDE)
2430
        {
2431
            my $platform;
2432
 
2433
            Error('BuildExclude: Unknown option: ' . $word) if ($word =~ m~^-~);
2434
            Error('BuildExclude: Invalid format: ' . $word) if ($word =~ m~^!~);
2435
 
2436
            #
2437
            #   Remove items from the result
2438
            #
2439
            my $table = "TARGET";
2440
            my $plist = $part_to_platform{$table}{$word};
2441
            Warning('BuildExclude: Unknown target:' . $word ) unless $plist;
2442
            for ( @{$plist})
2443
            {
2444
                delete $result{$_};
2445
            }
2446
        }
2447
 
2448
        #
227 dpurdie 2449
        #   Return an array of platforms to process
2450
        #
2451
        @BUILD_ACTIVEPLATFORMS = sort keys %result;
2452
 
2453
        #
2454
        #   Ensure that DEFBUILDPLATFORMS is a subset of build active platforms
2455
        #
2456
        my @NEW_DEFBUILDPLATFORMS;
2457
        foreach ( @DEFBUILDPLATFORMS )
2458
        {
2459
            push @NEW_DEFBUILDPLATFORMS, $_
2460
                if ( exists $result{$_} );
2461
        }
2462
        @DEFBUILDPLATFORMS = @NEW_DEFBUILDPLATFORMS;
2463
    }
2464
 
2465
    Debug("GeneratePlatformList: Result:@BUILD_ACTIVEPLATFORMS");
2466
    return @BUILD_ACTIVEPLATFORMS;
2467
}
2468
 
2469
#-------------------------------------------------------------------------------
2470
# Function        : PrintPlatforms
2471
#
2472
# Description     : Petty print the specified platform list, breaking line
2473
#                   on either a primary key change or length width >78.
2474
#
2475
# Returns         : Formated string
2476
#
2477
# Example Output :
2478
#
2479
#           DDU_LMOS_WIN32 DDU_LMOS_linux_armv4 DDU_LMOS_linux_i386
2480
#           IDFC_LMOS_WIN32 IDFC_LMOS_linux_armv4 IDFC_LMOS_linux_i386
2481
#           LMOS_WCEPSPC_ARM LMOS_WCEPSPC_EMU LMOS_WIN32 LMOS_linux_armv4
2482
#           LMOS_linux_i386
2483
#..
2484
sub PrintPlatforms
2485
{
2486
    my ($platforms, $nl) = @_;
2487
    my ($string) = "";                          # result
2488
 
2931 dpurdie 2489
    if ( @$platforms )
227 dpurdie 2490
    {
2491
        my ($key_run) = 0;
2492
        my ($pkey);                             # previous key
2493
 
2494
        #   Perform a simple formatting and determine if there is key 
2495
        #   change greater then 1 or whether the total length exceeds 78.
2496
        #
2497
        #   If the line exceeds 78, the printer shall then reformat 
2498
        #   breaking based on line length and possiblity keys.
2499
        #
2500
        $pkey = "";
2501
        for my $k (sort @$platforms) 
2502
        {
2503
            my ($d);                            # delimitor
2504
 
2505
            if (($d = index( $k, '_' )) != index( $pkey, '_' ) ||
2506
                    substr( $k, 0, $d ) ne substr( $pkey, 0, $d )) {
2507
                $key_run = 1
2508
                    if ($key_run <= 1);         # change, reset run if <= 1
2509
            } else {
2510
                $key_run++;                     # same primary key
2511
            }
2512
 
2513
            $string .= " " if ($pkey);
2514
            $string .= $k;
2515
            $pkey = $k;
2516
        }
2517
 
2518
        #   Reprint if required.
2519
        #
2520
        if (length($nl)+length($string) > 78)
2521
        {
2522
            my ($llen);                         # line length
2523
 
2524
            $llen = length($nl);
2525
 
2526
            $pkey = "";
2527
            $string = "";
2528
 
2529
            for my $k (sort @$platforms)
2530
            {
2531
                my ($klen, $d);                 # key length, delimitor
2532
 
2533
                $klen = length($k);
2534
                if ($pkey ne "")
2535
                {
2536
                    if ($llen + $klen > 78 ||
2537
                        ($key_run > 1 && (
2538
                            ($d = index( $k, '_' )) != index( $pkey, '_' ) ||
2539
                            substr( $k, 0, $d ) ne substr( $pkey, 0, $d ) )) )
2540
                    {                           # line >70 or key change
2541
                        $string .= $nl;
2542
                        $llen = length($nl);
2543
                    }
2544
                    else
2545
                    {
2546
                        $string .= " ";
2547
                        $llen++;
2548
                    }
2549
                }
2550
                $string .= $k;
2551
                $pkey = $k;
2552
                $llen += $klen;
2553
            }
2554
        }    
2555
    }
2556
    return $string;
2557
}
241 dpurdie 2558
#-------------------------------------------------------------------------------
2559
# Function        : PrintList
2560
#
2561
# Description     : Pretty format an array to fit within 80 char line
2562
#                   Perform wrapping as required
2563
#
2564
# Inputs          : $list           - Reference to an array
2565
#                   $nl             - New line stuff.
2566
#                                     Use to prefix new lines
2567
#
2568
# Returns         : string
2569
#
2570
sub PrintList
2571
{
2572
    my ($list, $nl) = @_;
2573
    my ($string) = '';                          # result
2574
    my $sep;
227 dpurdie 2575
 
241 dpurdie 2576
    if ( @$list )
2577
    {
2578
        my ($llen) = length($nl);
227 dpurdie 2579
 
241 dpurdie 2580
        for my $k (@$list)
2581
        {
2582
            my $klen = length($k);
2583
            if ($llen + $klen > 78 )
2584
            {
2585
                $string .= $nl;
2586
                $llen = length($nl);
2587
            }
2588
            else
2589
            {
2590
                if ( $sep )
2591
                {
2592
                    $string .= $sep;
2593
                    $llen++;
2594
                }
2595
                else
2596
                {
2597
                    $sep = ' ';
2598
                }
2599
            }
2600
            $string .= $k;
2601
            $llen += $klen;
2602
        }
2603
    }
2604
    return $string;
2605
}
2606
 
305 dpurdie 2607
#-------------------------------------------------------------------------------
2608
# Function        : BuildReleaseFile
2609
#
2610
# Description     : Legacy function
2611
#                   Don't know what it was meant to do
2612
#                   Unfortunately it is present in a lot of build.pl files
2613
#
2614
#                   Not well supported on all machine types
2615
#
331 dpurdie 2616
# Inputs          : None that are used
305 dpurdie 2617
#
331 dpurdie 2618
# Returns         : Undefined
305 dpurdie 2619
#
227 dpurdie 2620
sub BuildReleaseFile
2621
{
2622
}
2623
 
305 dpurdie 2624
#-------------------------------------------------------------------------------
2625
# Function        : BuildSnapshot
2626
#
2627
# Description     : Legacy function
2628
#                   Don't know what it was meant to do
2629
#                   Unfortunately it is present in a lot of build.pl files
2630
#
2631
# Inputs          : None that are used
2632
#
2633
# Returns         : Undefined
2634
#
227 dpurdie 2635
sub BuildSnapshot
2636
{
2637
}
2638
 
305 dpurdie 2639
#-------------------------------------------------------------------------------
2640
# Function        : BuildSrcArchive
2641
#
2642
# Description     : Create a source snapshot of the build source
2643
#                   Designed to provide a source image for packaging
2644
#                   examples
2645
#
2646
#                   Should be platform independent
2647
#
2648
#                   Creates an archive file and places it into the
2649
#                   interface directory. The archive will be packaged
2650
#                   automatically by the build process
2651
#
2652
#                   Use the 'pax' utility
2653
#                       1) Can massage the file path such that the stored
2654
#                          directory image contains the package name and version
2655
#
2656
#                   Directive can be used at any time before the BuildMake
2657
#
2658
#                   Will handle the existence of an auto.pl file by inserting
2659
#                   it as build.pl.
2660
#
2661
# Inputs          : Options
2662
#
2663
#
2664
# Returns         : 
2665
#
2666
sub BuildSrcArchive
2667
{
2668
    #
2669
    #   If we are clobbering, then there is nothing to do
2670
    #   The generated file is placed within the interface
2671
    #   directory and that directory will be deleted during the clobber
2672
    #
2673
    return if ( $Clobber );
2674
    DataDirective("BuildSrcArchive");
227 dpurdie 2675
 
305 dpurdie 2676
    #
2677
    #   Currently this operation is only supported of some platforms
2678
    #   Only supported on Unix platforms
2679
    #   Uses the 'pax' utility
2680
    #
2681
    unless ( LocateProgInPath ( 'pax', '--All' ) && ( $ScmHost eq "Unix" ) )
2682
    {
2683
        Log( "SrcPackage . Not supported" );
2684
        return;
2685
    }
2686
 
2687
    #
2688
    #   Only allow one instance of the directive
2689
    #
2690
    Error ("Multiple BuildSrcArchive directives not supported")
2691
        if ( $build_source_pkg );
2692
 
2693
    #
2694
    #   Create the name of the archive
2695
    #       Based on the package name and version
2696
    #       Has no spaces
2697
    #
2698
    my $build_name = $BUILDNAME;
2699
    $build_name =~ s~\s+~_~g;
2700
 
2701
    #
2702
    #   Create the archive in the interface directory
2703
    #   Don't need to clobber it as the entire interface directory
2704
    #   will be clobbered
2705
    #
2706
    $build_source_pkg = $build_name;
2707
}
2708
 
2709
#-------------------------------------------------------------------------------
2710
# Function        : BuildSrcArchiveBody
227 dpurdie 2711
#
305 dpurdie 2712
# Description     : Function to implement the body of the BuildSrcArchive
2713
#                   operation. Will be invoked during BuildMake
2714
#
2715
# Inputs          : None
2716
#
2717
# Returns         : 
2718
#
2719
sub BuildSrcArchiveBody
2720
{
2721
    return unless ( $build_source_pkg );
2722
 
2723
    my $archive_dir = "pkg/$BUILDNAME_PACKAGE/src";
2724
    my $archive_file = "$build_source_pkg" . '.tar';
2725
 
2726
    Log( "SrcPackage . $archive_file.gz" );
2727
    unlink "$archive_dir/$archive_file";
2728
    unlink "$archive_dir/$archive_file.gz";
2729
    mkpath($archive_dir, 0, 0775);
2730
 
2731
    #
2732
    #   Create a list of files and top-level dirs to add to source archive
2733
    #   Many files are ignored
2734
    #   Should only be executed on the first 'build' thus many internal
2735
    #   directories will not be present
2736
    #
2737
    my @flist;
2738
    my $auto_pl;
2739
    opendir (my $tp, '.' ) or Error ("Cannot read current directory");
2740
    while ( $_ = readdir($tp) )
2741
    {
2742
        next if ( m/^\.$/ );
2743
        next if ( m'^\.\.$' );
2744
        next if ( m'^build\.log$' );
2745
        next if ( m'\.gbe$' );
2746
        next if ( m'^local$' );
2747
        next if ( m'^pkg$' );
2748
        next if ( m/^$BUILDINTERFACE$/ );
2749
        $auto_pl = 1, next  if ( m'^auto\.pl$' );
2750
        next if (  m'^build\.pl$' );
2751
        next if ( m/^$build_source_pkg$/ );
2752
        push @flist, $_;
2753
    }
2754
    closedir $tp;
2755
 
2756
    #
2757
    #   If we don't have an auto.pl, then we add the build.pl file
2758
    #   If we do have a auto.pl - it gets tricky. Its don't after the
2759
    #   initial pax command
2760
    #
2761
    unless ( $auto_pl )
2762
    {
2763
        push @flist, 'build.pl';
2764
    }
2765
 
2766
    #
2767
    #   Create the command to be executed
2768
    #   Prefix archive paths with build_name
2769
    #
2770
    my @command = ( 'pax', '-w', '-f', "$archive_dir/$archive_file" );
2771
    System( '--NoShell' , @command, '-s', "~^~$build_source_pkg/~", @flist );
2772
 
2773
    #
2774
    #   If we have an auto.pl file, then we need to add it to the archive
2775
    #   but it needs to be called build.pl
2776
    #
2777
    if ( $auto_pl )
2778
    {
2779
        System( '--NoShell' , @command, '-a', '-s', "~^auto.pl~$build_source_pkg/build.pl~" , 'auto.pl' );
2780
    }
2781
 
2782
    #
2783
    #   Must now zip the file
2784
    #   Can't zip and append at the same time
2785
    #
2786
    System( '--NoShell' , 'gzip', "$archive_dir/$archive_file" );
2787
 
2788
    #
2789
    #   Display the results
2790
    #
2791
    System ('--NoShell', 'pax', '-z', "-f$archive_dir/$archive_file.gz")
2792
        if (IsVerbose (1));
2793
}
2794
 
2795
#-------------------------------------------------------------------------------
2796
# Function        : BuildAccessPerms
2797
#
2798
# Description     : Check if access/permissions setting requested...
2799
#                   Legacy
2800
#
331 dpurdie 2801
#                   Don't know what it was meant to do
2802
#                   Unfortunately it is present in a lot of build.pl files
305 dpurdie 2803
#
331 dpurdie 2804
# Inputs          : None that are used
305 dpurdie 2805
#
331 dpurdie 2806
# Returns         : Undefined
2807
#
227 dpurdie 2808
sub BuildAccessPerms
2809
{
2810
}
2811
 
2812
 
2813
sub BuildSetenv
2814
{
2815
    push( @BUILDSETENV, @_ );
2816
}
2817
 
2818
#-------------------------------------------------------------------------------
2819
# Function        : DataDirective
2820
#
2821
# Description     : Called by data collection directives to ensure that we are
2822
#                   still collecting data and that we have collected other data
2823
#
2824
# Inputs          : $dname              - Directive Name
2825
#
2826
# Returns         : Will error if we are not
2827
#
2828
sub DataDirective
2829
{
2830
    my ($dname) = @_;
2831
 
2832
    Error( "$dname() must appear after BuildName()...")
2833
        if ( $BUILDNAME eq "" );
2834
 
2835
    Error( "$dname() must appear after BuildInterface()...")
2836
        unless( $BUILDINTERFACE );
2837
 
2838
    Error( "$dname() not allowed after BuildDescpkg, BuildIncpkg, BuildVersion or BuildMake")
2839
        if( $BUILDPHASE);
2840
}
2841
 
2842
#-------------------------------------------------------------------------------
2843
# Function        : StartBuildPhase
2844
#
2845
# Description     : Called by directives that deal with the building phases
2846
#                   to perform common initialisation and to ensure that
2847
#                   directives that collect data are no longer called
2848
#
305 dpurdie 2849
# Inputs          : last                - True: Last directive expected
227 dpurdie 2850
#
2851
# Returns         : May generate an error
2852
#
2853
sub StartBuildPhase
2854
{
305 dpurdie 2855
    my ($last) = @_;
2856
 
227 dpurdie 2857
    #
305 dpurdie 2858
    #   Ensure directive is allowed
2859
    #       $BUILDPHASE >  1     - No more directives allowed
2860
    #       $BUILDPHASE == 1     - Allowed directive
2861
    #
2862
    if ( $BUILDPHASE > 1 )
2863
    {
2864
        my $function = (caller(1))[3];
2865
        $function =~ s~.*::~~;
2866
        Error ("Directive not allowed: $function","'BuildMake' must be the last directive in the build file");
2867
    }
2868
 
2869
    #
227 dpurdie 2870
    #   Only do it once
2871
    #
305 dpurdie 2872
    return if ( $BUILDPHASE  );
2873
    $BUILDPHASE = 1;
227 dpurdie 2874
 
2875
    #
341 dpurdie 2876
    #   If we are not performing a ForceBuild, then we don't need to continue
2877
    #   We have updated the interface directory with BuildPkgArchive
2878
    #   information.
2879
    #
2880
    TestForForcedBuild();
2881
 
2882
    #
227 dpurdie 2883
    #   Calcuate the aliases that are being extracted from targets
2884
    #
2885
    Process_TargetAlias();
2886
 
2887
    #
4728 dpurdie 2888
    #   Calculate NATIVE alaias
2889
    #   Limit the Native Alias to active platforms
2890
    #
2891
    if (exists $BUILDALIAS{NATIVE})
2892
    {
2893
        Warning('User has manually specified a NATIVE alias','Default alias will not be set.');
2894
    }
2895
    else
2896
    {
2897
        my %activePatformMap = map {$_ => 1} @BUILD_ACTIVEPLATFORMS;
2898
        my @activeNatives;
2899
        foreach my $item (PlatformConfig::getNativeTargets())
2900
        {
2901
            push (@activeNatives, $item) if exists($activePatformMap{$item});
2902
        }
2903
 
2904
        $BUILDALIAS{NATIVE} = join(' ', @activeNatives);
2905
    }
2906
 
2907
    #
311 dpurdie 2908
    #   Create dummy package to describe the Interface directory
2909
    #
2910
    CreateInterfacePackage();
2911
 
2912
    #
227 dpurdie 2913
    #   Sanity test the users packages
2914
    #
2915
    PackageEntry::SanityTest() unless $Clobber;
2916
 
2917
    #
2918
    #   Validate the $Srcdir before its first real use
2919
    #   This is calculated from the user directives
2920
    #
2921
 
2922
    #.. Determine default "source" root
2923
    #
2924
    if ( $Srcdir eq "" )
2925
    {
2926
        Warning( "Both the directories 'src' and 'SRC' exist ....." )
2927
            if ( $ScmHost eq "Unix" && -e "src" && -e "SRC" );
2928
 
2929
        if ( -e "src" ) {
2930
            $Srcdir = "src";
2931
        } else {
2932
            ( -e "SRC" ) ||
2933
                Error( "Neither the directory 'src' nor 'SRC' exist ....." );
2934
            $Srcdir = "SRC";
2935
        }
2936
    }
2937
 
2938
    #
2939
    #   Must have a valid Srcdir
2940
    #
2941
    Error ("Source directory not found: $Srcdir")
2942
        unless ( $Srcdir && -d $Srcdir );
2943
 
305 dpurdie 2944
    #
2945
    #   Create source package
2946
    #
2947
    BuildSrcArchiveBody();
2948
 
227 dpurdie 2949
    return $Srcdir;
2950
}
2951
 
2952
#-------------------------------------------------------------------------------
341 dpurdie 2953
# Function        : TestForForcedBuild
2954
#
2955
# Description     : If a non-forced build has been requested, then see
2956
#                   if a build is required ( ie: build.pl modified )
2957
#
2958
#
2959
# Inputs          : None
2960
#
2961
# Returns         : May not return
2962
#
2963
sub TestForForcedBuild
2964
{
2965
    #
2966
    #   Always return if in clobber mode
2967
    #
2968
    return if ( $Clobber );
2969
 
2970
    if ( ! $ForceBuild  )
2971
    {
2972
        my @build_warn;
2973
        my $bstamp = -M "$Cwd/$ScmBuildSrc";
2974
        my $tstamp = -M "$Cwd/Makefile.gbe";
2975
 
2976
        push @build_warn, "Missing: Makefile.gbe" unless ( defined $tstamp );
2977
        push @build_warn, "Modified build file ($ScmBuildSrc)" if ( $tstamp && $bstamp < $tstamp );
2978
 
363 dpurdie 2979
        #
2980
        #   Ensure that the build filter has not changed
2981
        #   If the user has changed the buildfilter, then we need to
2982
        #   force a build.
2983
        #
2984
        #   The root Makefile.bge will have a $ScmBuildFilter entry
2985
        #
2986
        unless ( @build_warn )
2987
        {
2988
            use JatsMakeInfo;
2989
            ReadMakeInfo();
5726 dpurdie 2990
            my $line = $::ScmBuildFilter || '';
2991
            $line =~ s~\s+~ ~g;
363 dpurdie 2992
 
5726 dpurdie 2993
            my $filter = $::GBE_BUILDFILTER || '';
2994
            $filter =~ s~\s+~ ~g;
2995
            if ( $line ne $filter )
2996
            {
2997
                push @build_warn, "Build filter has changed";
2998
                Verbose2 ("Buildfilter Test: Was:$line, Is:$::GBE_BUILDFILTER");
2999
            }
363 dpurdie 3000
        }
3001
 
341 dpurdie 3002
        if ( @build_warn )
3003
        {
363 dpurdie 3004
            Verbose ("Forcing Build.", @build_warn );
341 dpurdie 3005
        }
3006
        else
3007
        {
3008
            Verbose ("No build performed. Build files up to date");
3009
            Log ("Build files up to date") if $::GBE_SANDBOX;
3010
            exit 0;
3011
        }
3012
    }
3013
}
3014
 
3015
#-------------------------------------------------------------------------------
305 dpurdie 3016
# Function        : LastBuildDirective
3017
#
3018
# Description     : No more build directives allowed
3019
#
3020
# Inputs          : 
3021
#
3022
# Returns         : 
3023
#
3024
sub LastBuildDirective
3025
{
3026
    $BUILDPHASE = 2;
3027
}
3028
 
3029
#-------------------------------------------------------------------------------
227 dpurdie 3030
# Function        : BuildPackageLink
3031
#
3032
# Description     : Create a soft link from sandbox_dpkg_archive to the package
3033
#                   being created by this build
3034
#
3035
#                   For backward compatability.
3036
#                   If GBE_DPKG_SBOX is not defined, then use GBE_DPKG_LOCAL
3037
#
3038
#                   This will allow multiple components to work together
3039
#
3040
#                   Note: When called in Clobber-mode the link will be deleted
3041
#
3042
# Inputs          : $BUILDNAME              - The package name
3043
#                   $BUILDNAME_PROJECT      - Project extension
3044
#                   $::GBE_DPKG_SBOX        - Path of sandbox_dpkg_archive
3045
#                   $::GBE_DPKG_LOCAL       - Path of local_dpkg_archive
3046
#                   $::GBE_DPKG             - Main repository
3047
#
3048
# Returns         : Nothing
3049
#
3050
sub BuildPackageLink
3051
{
3052
    my $target_archive;
3053
    my $target_archive_name;
3054
    my $link_file;
3055
    my $tag;
371 dpurdie 3056
    my $root_path;
227 dpurdie 3057
 
3058
    #
3059
    #   Determine the path (and name) of the target archive
3060
    #   Use sandbox_dpkg_archive if it exists
3061
    #   Use local_dpkg_acrhive for backward compatability (should be removed after JATS 2.64.2+)
3062
    #
3063
    if ( $target_archive = $::GBE_DPKG_SBOX )
3064
    {
3065
        $target_archive_name = "sandbox_dpkg_archive";
3066
        $tag = "Sandbox";
359 dpurdie 3067
        if ( $sandbox_exact )
3068
        {
3069
            $link_file = "$BUILDVERSION.lnk";
3070
        }
3071
        else
3072
        {
3073
            $link_file  = 'sandbox' . ${BUILDNAME_SUFFIX} . '.lnk';
3074
        }
371 dpurdie 3075
        $root_path = 'GBE_SANDBOX' . substr($Cwd, length($::GBE_SANDBOX));
3076
        Verbose2("Root Path: $::GBE_SANDBOX, $root_path");
227 dpurdie 3077
    }
3078
    elsif ( $target_archive = $::GBE_DPKG_LOCAL )
3079
    {
3080
        $target_archive_name = "local_dpkg_archive";
3081
        $link_file = "$BUILDVERSION.lnk";
3082
        $tag = "Local";
371 dpurdie 3083
        $root_path = $Cwd;
227 dpurdie 3084
    }
3085
    else
3086
    {
3087
        Verbose("Cannot locate local or sandbox archive")
3088
            unless $Clobber;
3089
        return;
3090
    }
3091
 
3092
    #
3093
    #   Santity test
3094
    #   Target must be a directory
3095
    #
3096
    unless ( -d $target_archive )
3097
    {
241 dpurdie 3098
        Warning("$target_archive_name is not a directory: $target_archive")
227 dpurdie 3099
            unless $Clobber;
3100
        return;
3101
    }
3102
 
3103
    my $link_dir = "$target_archive/$BUILDNAME_PACKAGE";
3104
    my $link_path = "$link_dir/$link_file";
3105
 
3106
    if ( $Clobber )
3107
    {
3108
        unlink $link_path;          # Delete the link
3109
        rmdir $link_dir;            # Delete only if empty
3110
    }
3111
    else
3112
    {
261 dpurdie 3113
        Log( "Local Link . $BUILDNAME_PACKAGE/$link_file ($tag)");
3114
        mkdir $link_dir unless -d $link_dir;
371 dpurdie 3115
        FileCreate ( $link_path, "$root_path/pkg/$BUILDNAME_PACKAGE");
227 dpurdie 3116
    }
3117
}
3118
 
3119
#-------------------------------------------------------------------------------
3120
# Function        : BuildSandboxData
3121
#
3122
# Description     : Create data structures to allow this package to be built
3123
#                   within a multi-package sandbox.
3124
#
3125
#                   This will allow multiple components to work together
3126
#
3127
#                   Note: When called in Clobber-mode the link will be deleted
3128
#
3129
# Inputs          : $BUILDNAME              - The package name
3130
#                   $BUILDNAME_PROJECT      - Project extension
3131
#                   $::GBE_DPKG_SBOX        - Path of sandbox_dpkg_archive
3132
#                   $::GBE_DPKG             - Main repository
3133
#
3134
# Returns         : Nothing
3135
#
3136
sub BuildSandboxData
3137
{
3138
    my $sandbox_dpkg_archive = $::GBE_DPKG_SBOX;
3139
    return unless ( $sandbox_dpkg_archive );
3140
 
3141
    unless ( -d $sandbox_dpkg_archive )
3142
    {
241 dpurdie 3143
        Error("sandbox_dpkg_archive is not a directory: $sandbox_dpkg_archive")
227 dpurdie 3144
            unless $Clobber;
3145
        return;
3146
    }
3147
 
3148
    #
3149
    #   Create a name for this package in the sandbox
3150
    #   Must use the package name and extension. Don't use the version
3151
    #   information as this will not be correct
3152
    #
3153
    #   PACKAGE/sandbox.PRJ.cfg
3154
    #
3155
    my $link_dir = "$sandbox_dpkg_archive/$BUILDNAME_PACKAGE";
359 dpurdie 3156
    my $link_file;
3157
 
3158
    if ( $sandbox_exact )
3159
    {
3160
        $link_file = "$BUILDVERSION.cfg";
3161
    }
3162
    else
3163
    {
3164
        $link_file  = 'sandbox' . ${BUILDNAME_SUFFIX} . '.cfg';
3165
    }
227 dpurdie 3166
    my $link_path = "$link_dir/$link_file";
3167
 
3168
    if ( $Clobber )
3169
    {
3170
        unlink $link_path;          # Delete the link
3171
        rmdir $link_dir;            # Delete only if empty
3172
    }
3173
    else
3174
    {
261 dpurdie 3175
        Log( "Sandbox cfg. $link_file");
227 dpurdie 3176
        unlink $link_path;
3177
        mkdir $link_dir;
3178
 
3179
        #
3180
        #   Create the sandbox config data structure
3181
        #
3182
        my %sandbox_info = (
3183
            BUILDDIR     => $Cwd,
3184
            INTERFACEDIR => $BUILDINTERFACE,
3185
            );
3186
 
3187
        #
3188
        #   Write out the Parsed Config File with new information
3189
        #
3190
        my $fh = ConfigurationFile::New( $link_path );
3191
        $fh->Header( "buildlib (version $::BuildVersion)",
3192
                                  "Sandbox configuration" );
3193
 
3194
        #
3195
        #   Dump out the configuration information
3196
        #
3197
        $fh->Dump( [\%sandbox_info], [qw(*sandbox_info)] );
3198
        $fh->Close();
3199
    }
3200
}
3201
 
3202
 
3203
#-------------------------------------------------------------------------------
3204
# Function        : BuildMake
3205
#
3206
# Description     : Generate the makefiles
3207
#                   This directive MUST be the last directive in the build.pl
3208
#                   file. The directive triggers the processing of all the
3209
#                   information that has been collected
3210
#
3211
#
3212
# Inputs          : None
3213
#
3214
# Returns         : Nothing
3215
#
3216
 
3217
sub BuildMake
3218
{
3219
    my( $argc, $platform );
3220
 
3221
    #
3222
    #   Must have a valid $BUILDINTERFACE
3223
    #   Normally this is held in the interface directory, but this is not
3224
    #   always created. If there is no $BUILDINTERFACE, then use the
3225
    #   build directory
3226
    #
3227
    $BUILDINTERFACE = "." unless ( $BUILDINTERFACE );
3228
 
3229
    #.. Starting the build phase. No more data collection
3230
    #
305 dpurdie 3231
    StartBuildPhase();
3232
    LastBuildDirective();
227 dpurdie 3233
 
5109 dpurdie 3234
    #
3235
    #   Now that the bulk of the information has been displayed
3236
    #   we can display captured messages. These warnings will be 
3237
    #   at the end of the log so that users can see them.
3238
    DumpCapture();
3239
 
227 dpurdie 3240
    sub DeleteCfg
3241
    {
3242
        #
3243
        #   Delete files that will be re-created
3244
        #   Some of these files are read and written.
3245
        #   Errors in the files are solved by deleting the files now.
3246
        #
3247
        unlink "$BUILDINTERFACE/build.cfg";
3248
        unlink "$BUILDINTERFACE/Makefile.cfg";
3249
        unlink glob ("$BUILDINTERFACE/Makefile*.cfg");
3250
        unlink "$BUILDINTERFACE/Buildfile.cfg";
3251
        unlink "$BUILDINTERFACE/Dpackage.cfg";
3252
    }
3253
 
3254
    if ( $Clobber )                             # clobber mode ?
3255
    {
4003 dpurdie 3256
        #
3257
        #   Read in toolset files - a list of files collected during
3258
        #   previous builds
3259
        #
3260
        ToolsetFile();
227 dpurdie 3261
 
4003 dpurdie 3262
        #
3263
        #   Unmake all the makefiles
3264
        #   No longer needed as we track the file that are created
3265
        #
3266
        #if ( -e "Makefile.gbe" )
3267
        #{
3268
        #    JatsTool ( 'jmake.pl', 'unmakefiles');
3269
        #}
3270
 
3271
        #
3272
        #   Delete my own configuration files
3273
        #
227 dpurdie 3274
        DeleteCfg();
3275
 
3276
        #
3277
        #   JATS creates a 'pkg' directory for the target package
3278
        #
3279
        push @CLOBBERDIRS, "pkg";
3280
 
3281
        #
3282
        #   Deployment creates a 'build/deploy' directory
375 dpurdie 3283
        #   The 'build' directory may contain user files - only remove if empty
227 dpurdie 3284
        #
3285
        push @CLOBBERDIRS, "build/deploy";
375 dpurdie 3286
        push @REMOVEDIRS, "build";
227 dpurdie 3287
 
3288
        #
3289
        #   Delete interface directories and other directories that have been
375 dpurdie 3290
        #   marked to be clobbered
227 dpurdie 3291
        #
3292
        foreach my $dir ( @CLOBBERDIRS )
3293
        {
3294
            next if ( $dir eq '.' );
3295
            next if ( $dir eq '..' );
3296
            if ( -d $dir )
3297
            {
361 dpurdie 3298
                RmDirTree ( $dir );
227 dpurdie 3299
            }
3300
        }
3301
 
375 dpurdie 3302
        foreach my $dir ( @REMOVEDIRS )
3303
        {
3304
            next if ( $dir eq '.' );
3305
            next if ( $dir eq '..' );
3306
            if ( -d $dir )
3307
            {
3308
                rmdir ( $dir ); # Only if empty
3309
            }
3310
        }
3311
 
4003 dpurdie 3312
        if ( exists $::GBE_TOOLSETFiles{Files} )
227 dpurdie 3313
        {
4007 dpurdie 3314
            foreach my $file (keys %{$::GBE_TOOLSETFiles{Files}})
227 dpurdie 3315
            {
4003 dpurdie 3316
                if ( -f $file )
3317
                {
3318
                    RmDirTree ( $file );
3319
                }
227 dpurdie 3320
            }
3321
        }
3322
 
3323
        #
3324
        #   DPACKAGE may be a user file, Only delete it if we created it
3325
        #
299 dpurdie 3326
        unlink "$Srcdir/DPACKAGE.$::GBE_MACHTYPE" if $DeleteDPACKAGE;
227 dpurdie 3327
 
3328
        BuildPackageLink();
3329
        BuildSandboxData();
3330
        return;
3331
    }
3332
 
3333
    #.. Build support files
3334
    #
3335
    DeleteCfg();
3336
    BuildConfig();
3337
    BuildSharedLibFiles();
3338
    WriteParsedBuildConfig();
3339
    BuildPackageLink();
3340
    BuildSandboxData();
4003 dpurdie 3341
    NoBuildMarker();
227 dpurdie 3342
 
3343
    #
3344
    #  ONLY (re)building interface dir
3345
    #
3346
    return
3347
        if ( $Interface );
3348
 
3349
    #---------------------------------------------------------------------------
3350
    #
3351
    #.. Make bootstrap "makefile",
3352
    #   Simulate a top level makefile
3353
    #       Pass argumenst to makelib
3354
    #       Sumulate SubDir() operations
3355
    #       Sumulate a Platform(*);
3356
    #
3357
    #       Due to the normal way that makelib.pl is executed,
3358
    #       the following substitutions are done.
3359
    #
3360
    @ARGV = ();
3361
    $0 = "makefile.pl ";
3362
    push @ARGV, "$Cwd";                         # current working directory
331 dpurdie 3363
    push @ARGV, "$::GBE_TOOLS/makelib.pl";     # makelib.pl image
227 dpurdie 3364
    push @ARGV, "--interface=$BUILDINTERFACE"
261 dpurdie 3365
        if ($BUILDINTERFACE);
227 dpurdie 3366
 
3367
    Debug( "ARGV:      @ARGV" );
3368
 
3369
    #.. (re)Build root makefile
3370
    #
3371
    $ScmBuildlib = 0;                           # clear Buildlib flag for 'makelib.pl'
3372
    RootMakefile();                             # inform 'makelib.pl'
3373
    MakeLibInit();                              # run initialisation
3374
 
3375
    #.. Register subdir(s)
3376
    #
3377
    UniquePush (\@BUILDSUBDIRS, $Srcdir );
3378
    SubDir( @BUILDSUBDIRS );
3379
    Platform( @BUILD_ACTIVEPLATFORMS );
3380
 
3381
    #.. (re)build src makefiles and associated information
367 dpurdie 3382
    #   JatsTool will not return on error
227 dpurdie 3383
    #
263 dpurdie 3384
    my @cmds = ('jmake.pl', 'rebuild');
227 dpurdie 3385
    push @cmds, 'NORECURSE=1' if ( $RootOnly );
263 dpurdie 3386
    JatsTool ( @cmds);
305 dpurdie 3387
 
3388
    #
3389
    #   Generate some warnings that will be seen at the end of the build
3390
    #
3391
    Warning ("BuildSrcArchive Directive Present","Read JATS Manual for correct usage")
3392
        if ($build_source_pkg);
227 dpurdie 3393
}
3394
 
3395
 
3396
#-------------------------------------------------------------------------------
3397
# Function        : BuildVersion
3398
#
3399
# Description     : Generate version.c and version.h files
3400
#
3401
# Inputs          : Options
3402
#                       --Prefix=prefix         Text prepended to variables created
3403
#                                               as a part of the "C" versions
3404
#                       --Type=type             Type of "C" style data
3405
#                                               Allowed types are: array
3406
#                       --Defs=name             Generate a "C" definitions file.
3407
#                                               This file simply contains definitions
3408
#                       --Defs                  Same as --Defs=defs
3409
#                       --Style=style           Output file style
3410
#                                               Supported styles:
3411
#                                                   "C" - Default
3412
#                                                   "CSharp"
3413
#                                                   "WinRC"
289 dpurdie 3414
#                                                   "Delphi"
315 dpurdie 3415
#                                                   "VB"
227 dpurdie 3416
#                       --File=name             Specifies the output file name
3417
#                                               Default is determined by the style
3418
#
3419
#                   Also allows for an 'old' style format in which
3420
#                   the first three arguments are prefix,type and defs
3421
# Returns         :
3422
#
3423
 
3424
sub BuildVersion
3425
{
3426
    my ( $Prefix, $Type, $Mode ) = @_;
3427
    my $ModePrefix;
3428
    my $Style = "C";
3429
    my $FileName;
3430
    my $VersionFiles;
267 dpurdie 3431
    my @opts;
3432
    my $supports_opts;
227 dpurdie 3433
 
3434
    StartBuildPhase();                          # Starting the build phase. No more data collection
3435
 
279 dpurdie 3436
    if ( defined($Prefix) && $Prefix =~ /^-/ )
227 dpurdie 3437
    {
3438
        $Prefix = undef;
3439
        $Type = undef;
3440
        $Mode = undef;
3441
        foreach  ( @_ )
3442
        {
3443
            if (      /^--Prefix=(.*)/ ) {
3444
                $Prefix = $1;
3445
                $VersionFiles = 1;
3446
 
3447
            } elsif ( /^--Type=(.*)/ ) {
3448
                $Type = $1;
3449
                $VersionFiles = 1;
3450
 
3451
            } elsif ( /^--Defs=(.*)/ ) {
3452
                $Mode = $1;
3453
                $ModePrefix = "_$1";
3454
 
3455
            } elsif ( /^--Defs$/ ) {
3456
                $Mode = 'defs';
3457
                $ModePrefix = "";
3458
 
3459
            } elsif ( /^--Style=(.*)/ ) {
3460
                $Style = $1;
279 dpurdie 3461
                $VersionFiles = 1;
267 dpurdie 3462
                $supports_opts = 1 if ( $Style =~ /^WinRC/i );
227 dpurdie 3463
 
3464
            } elsif ( /^--File=(.*)/ ) {
3465
                $FileName = $1;
3466
 
267 dpurdie 3467
            } elsif ($supports_opts ) {
3468
                push @opts, $_;
235 dpurdie 3469
 
227 dpurdie 3470
            } else {
3471
                Error ("BuildVersion: Unknown option: $_");
3472
 
3473
            }
3474
        }
3475
    }
3476
    else
3477
    {
3478
        #
3479
        #   Old style positional arguments.
3480
        #
3481
        $VersionFiles = 1;
3482
        if ( defined( $Mode ) )
3483
        {
3484
            if ( $Mode =~ m/^defs(=(.*))?$/i )
3485
            {
3486
                $Mode       = $2 ? $2    : 'defs';
3487
                $ModePrefix = $2 ? "_$2" : "";
3488
            }
3489
            else
3490
            {
3491
                Error ("BuildVersion: Bad Mode argument. Need 'defs' or 'defs=name'");
3492
            }
3493
        }
3494
    }
3495
 
3496
    #
3497
    #   Determine the style of version file to create
3498
    #
3499
    if ( $Style =~ /^CSharp/i ) {
3500
        BuildVersionCSharp( $FileName );
3501
 
229 dpurdie 3502
    } elsif ( $Style =~ /^Properties/i ) {
3503
        BuildVersionProperties( $FileName, $Prefix );
3504
 
227 dpurdie 3505
    } elsif ( $Style =~ /^WinRC/i ) {
267 dpurdie 3506
        BuildVersionWinRC( $FileName, @opts );
227 dpurdie 3507
 
289 dpurdie 3508
    } elsif ( $Style =~ /^Delphi/i ) {
3509
        BuildVersionDelphi( $FileName, $Prefix );
315 dpurdie 3510
 
3511
    } elsif ( $Style =~ /^VB/i ) {
3512
        BuildVersionVB( $FileName, $Prefix );
289 dpurdie 3513
 
227 dpurdie 3514
    } elsif ( $Style eq "C" ) {
289 dpurdie 3515
        BuildVersionC    ( $FileName, $Prefix, $Type )     if ( $VersionFiles );
3516
        BuildVersionCdefs( $FileName, $Mode, $ModePrefix ) if ( $Mode );
227 dpurdie 3517
 
3518
    } else {
3519
        Error("BuildVersion: Unknown style: $Style");
3520
    }
3521
}
3522
 
3523
#-------------------------------------------------------------------------------
3524
# Function        : BuildDescpkg
3525
#
3526
# Description     : Create a package description file
3527
#                   The format of this file matches that generated by JANTS
3528
#                   Take care when extending the format
3529
#
3530
#                   NOTE: It turns out that JANTS is not a standard and the
3531
#                         implementors (of JANTS) kept on changing it.
3532
#
3533
# Inputs          :
3534
#
3535
# Returns         :
3536
#
3537
sub BuildDescpkg
3538
{
4003 dpurdie 3539
    StartBuildPhase();                      # Starting the build phase. No more data collection
3540
    return if ( $Clobber );                 # clobber mode ?
227 dpurdie 3541
 
247 dpurdie 3542
    #
3543
    #   Store the files location for use at runtime
3544
    #   It will be a file that is 'known' to JATS
3545
    #
4003 dpurdie 3546
    my $pkgfile = BuildAddKnownFile ( $NoBuild ? $Cwd : $Srcdir, 'descpkg' );
227 dpurdie 3547
 
261 dpurdie 3548
    my @desc;
279 dpurdie 3549
    push @desc, "Package Name:  $BUILDNAME_PACKAGE";
3550
    push @desc, "Version:       $BUILDVERSION";
3551
    push @desc, "Released By:   $::USER";
3552
    push @desc, "Released On:   $::CurrentTime";
3553
    push @desc, "Build Machine: $::GBE_HOSTNAME";
3554
    push @desc, "Path:          $Cwd";
3555
    push @desc, "Jats Version:  $::GBE_VERSION";
3556
    push @desc, "Jats Path:     $::GBE_CORE";
261 dpurdie 3557
    push @desc, "";
3558
    push @desc, "Build Dependencies:";
3559
    push @desc, "";
227 dpurdie 3560
 
3561
    foreach my $tag ( PackageEntry::GetPackageList )
3562
    {
3563
        my ($name, $version, $type) = PackageEntry::GetPackageData($tag);
3564
 
3565
        my @attributes;
3566
 
3567
        push @attributes, "name=\"$name\"";
3568
        push @attributes, "version=\"$version\"";
3569
        push @attributes, "build=\"true\"" if $type =~ /Build/i;
3570
 
261 dpurdie 3571
        push @desc, "<sandbox @attributes/>";
227 dpurdie 3572
    }
247 dpurdie 3573
 
261 dpurdie 3574
    FileCreate ($pkgfile, \@desc );
227 dpurdie 3575
}
3576
 
3577
#-------------------------------------------------------------------------------
4003 dpurdie 3578
# Function        : NoBuildMarker
3579
#
3580
# Description     : Maintain the nobuild marker
3581
#                   This is file placed in the interface directory simply
3582
#                   to indicate to the 'create_dpkg' utility that this build
3583
#                   does not do anything useful.
3584
#
3585
#                   It will only be used on a build machine by the buid daemon
3586
#
3587
#                   Its not placed in the interface directory as it would be
3588
#                   harder for create_dpkg to find it.
3589
#
3590
# Inputs          : None
3591
# Globals         : $NoBuild, $Clobber
3592
#
3593
# Returns         : Nothing
3594
#
3595
sub NoBuildMarker
3596
{
3597
    return if ( $Clobber );
3598
 
3599
    # Always delete the file - in case we toggle build forms
3600
    #
3601
    my $markerFile = BuildAddKnownFile( $Cwd, 'noBuild.gbe');
3602
    unlink($markerFile);
3603
 
3604
    TouchFile($markerFile)
3605
        if ($NoBuild);
3606
}
3607
 
3608
#-------------------------------------------------------------------------------
227 dpurdie 3609
# Function        : BuildIncpkg
3610
#
3611
# Description     : Create a package inclusion file
3612
#
3613
# Inputs          :
3614
#
3615
# Returns         :
3616
#
3617
sub BuildIncpkg
3618
{
3619
    StartBuildPhase();                          # Starting the build phase. No more data collection
3620
    if ( $Clobber )                             # clobber mode ?
3621
    {
361 dpurdie 3622
        RmDirTree( "$Srcdir/incpkg" );
227 dpurdie 3623
        return;
3624
    }
3625
 
3626
    my $fh = ConfigurationFile::New( "$Srcdir/incpkg" );
3627
    $fh->Header( "buildlib (Version $BuildVersion)",
3628
                              "Package inclusion list" );
3629
 
3630
    foreach my $tag ( PackageEntry::GetPackageList )
3631
    {
3632
        my ($name, $version, $type) = PackageEntry::GetPackageData($tag);
3633
        $type = ($type =~ /build/i) ? "Build" : "Link";
3634
 
3635
        $fh->Write( "${type}PkgArchive( '$name', '$version' );\n" );
3636
    }
3637
 
3638
    $fh->Close();
3639
}
3640
 
3641
#-------------------------------------------------------------------------------
3642
# Function        : BuildConfig
3643
#
3644
# Description     : Create the file interface/build.cfg
3645
#                   This file contains information gathered by the build process
3646
#                   that is to be used when makefiles are created and re-created
3647
#
3648
# Inputs          : None
3649
#
3650
# Returns         : Nothing
3651
#
283 dpurdie 3652
sub BuildConfig
227 dpurdie 3653
{
3654
    Error( "No BuildInterface directive encountered\n" )
3655
        unless ($BUILDINTERFACE);
3656
 
3657
    my $fh = ConfigurationFile::New( "$BUILDINTERFACE/build.cfg");
3658
    $fh->Header( "buildlib (Version $BuildVersion)",
3659
                              "Makelib configuration file", "
3660
\$ScmBuildMachType              = \"$::GBE_MACHTYPE\";
3661
\$ScmInterfaceVersion           = \"$::InterfaceVersion\";
3662
\$ScmBuildName                  = \"$BUILDNAME\";
3663
\$ScmBuildPackage               = \"$BUILDNAME_PACKAGE\";
3664
\$ScmBuildVersion               = \"$BUILDNAME_VERSION\";
3665
\$ScmBuildProject               = \"$BUILDNAME_PROJECT\";
3666
\$ScmBuildVersionFull           = \"$BUILDVERSION\";
3667
\$ScmBuildPreviousVersion       = \"$BUILDPREVIOUSVERSION\";
3668
\$ScmLocal                      = \"$BUILDLOCAL\";
3669
\$ScmDeploymentPatch            = \"$DEPLOY_PATCH\";
3670
\$ScmSrcDir                     = \"$Srcdir\";
3671
\$ScmBuildSrc                   = \"$ScmBuildSrc\";
3672
\$ScmExpert                     = \"$Expert\";
261 dpurdie 3673
\$ScmAll                        = \"$All\";
4003 dpurdie 3674
\$ScmNoBuild                    = \"$NoBuild\";
227 dpurdie 3675
");
3676
 
3677
#.. Alias
3678
#
3679
    $fh->DumpData(
3680
        "\n# Aliases.\n#\n",
3681
        "ScmBuildAliases", \%BUILDALIAS );
3682
 
3683
#.. Products
3684
#
3685
    $fh->DumpData(
3686
        "# Product mapping.\n#\n",
3687
        "ScmBuildProducts", \%BUILDPRODUCT_PARTS );
3688
 
3689
#.. Create ScmBuildPlatforms
3690
#
3691
    my( @platforms_merged, %platform_args ) = ();
3692
 
3693
    UniquePush ( \@platforms_merged, @BUILDPLATFORMS );
3694
 
3695
    foreach my $key ( keys %BUILDPRODUCT ) {
3696
        my( @list ) = split( ' ', $BUILDALIAS{ $key } || '' );
3697
        my( $platform );
3698
 
3699
        foreach my $elem ( @list ) {
3700
            if ( $elem =~ /^--/ ) {             # argument
3701
                HashJoin( \%platform_args, $;, $platform, $elem )
3702
                    if ( defined($platform) );
3703
                next;
3704
            }
3705
            $platform = $elem;                  # platform
3706
            UniquePush( \@platforms_merged, $elem );
3707
        }
3708
    }
3709
 
3710
#.. Create ScmBuildPlatforms
3711
#   Contains per platform options extracted from alias and platform args
3712
#
3713
    my %ScmBuildPlatforms;
3714
    foreach my $key ( @platforms_merged ) {
3715
 
3716
        my( @arguments ) = ();
3717
        UniquePush( \@arguments, split( /$;/, $BUILDPLATFORMARGS{ $key } ))
3718
            if ( exists $BUILDPLATFORMARGS{ $key } );
3719
 
3720
        UniquePush( \@arguments, split( /$;/, $platform_args{ $key } ))
3721
            if ( exists $platform_args{ $key } );
3722
 
3723
        $ScmBuildPlatforms{$key} = join "$;", @arguments;
3724
    }
3725
 
3726
    $fh->DumpData(
3727
        "# Platform and global argument list.\n#\n",
3728
        "ScmBuildPlatforms", \%ScmBuildPlatforms );
3729
 
3730
 
3731
# .. Create BuildPkgRules
3732
#
367 dpurdie 3733
#    This is most of the information contained within %PKGRULES, which
227 dpurdie 3734
#    requires additional processing within makelib.
3735
#
367 dpurdie 3736
#   Need the True Path for windows.
3737
#       Some makefile functions (wildcard) only work as expected
3738
#       if the case of the pathname is correct. Really only a problem
3739
#       with badly formed legecy packages where the Windows user
3740
#       guessed at the package format.
3741
#
227 dpurdie 3742
    my %ScmBuildPkgRules;
3743
    foreach my $platform ( keys %PKGRULES )
3744
    {
3745
        foreach my $package ( @{$PKGRULES{$platform}} )
3746
        {
3747
            my %entry;
3748
 
367 dpurdie 3749
            $entry{ROOT}     = TruePath( $package->{'base'} );
227 dpurdie 3750
            $entry{NAME}     = $package->{'name'};
3751
            $entry{VERSION}  = $package->{'version'};
3752
            $entry{DNAME}    = $package->{'dname'};
3753
            $entry{DVERSION} = $package->{'dversion'};
3754
            $entry{DPROJ}    = $package->{'dproj'};
3755
            $entry{TYPE}     = $package->{'type'};
3756
            $entry{CFGDIR}   = $package->{'cfgdir'} if ( defined( $package->{'cfgdir'} ) );
3757
 
367 dpurdie 3758
            foreach my $dir (qw (TOOLDIRS) )
227 dpurdie 3759
            {
3760
                $entry{$dir} = $package->{$dir} ;
3761
            }
3762
 
367 dpurdie 3763
            my $baselen = length($package->{'base'});
3764
            foreach my $dir (qw (PINCDIRS PLIBDIRS THXDIRS) )
3765
            {
3766
                $entry{$dir} = [];
3767
                foreach my $file ( @{$package->{$dir}} )
3768
                {
3769
                    push @{$entry{$dir}}, substr TruePath($package->{'base'} . $file ), $baselen;
3770
                }
3771
            }
3772
 
227 dpurdie 3773
            push @{$ScmBuildPkgRules{$platform}}, \%entry;
3774
        }
3775
    }
3776
 
3777
    $fh->DumpData(
3778
        "# Imported packages.\n#\n",
3779
        "ScmBuildPkgRules", \%ScmBuildPkgRules );
3780
 
3781
#
3782
#   BUILDPLATFORMS,
3783
#       The value that is saved only contains the active platforms
3784
#
3785
#   DEFBUILDPLATFORMS,
3786
#       The value that is matchs the wildcard specification for Platform 
3787
#       directives.
3788
#
3789
    $fh->DumpData(
3790
        "# A list of platforms active within the view.\n#\n",
3791
        "BUILDPLATFORMS", \@BUILD_ACTIVEPLATFORMS );
3792
 
3793
    $fh->DumpData(
3794
        "# A list of default platforms within the view.\n#\n",
3795
        "DEFBUILDPLATFORMS", \@DEFBUILDPLATFORMS );
3796
 
3797
#
3798
#   BUILDTOOLS
3799
#       A list of toolset extension paths
3800
#
3801
    $fh->DumpData(
3802
        "# A list of paths with toolset extension programs.\n#\n",
3803
        "BUILDTOOLSPATH", \@BUILDTOOLS );
3804
 
3805
#
3806
#   BUILDPLATFORM_PARTS
3807
#       A subset of BUILDINFO exported as BUILDPLATFORM_PARTS
3808
#       This exists only for backward compatability with existing code
3809
#       in external packages ( deployfiles).
3810
#
3811
#   Only save those parts that are part of the current build
3812
#   This will prevent users attempting to build for platforms that have not
3813
#   been correctly constructed.
3814
#
3815
    my %active =  map { ${_} => 1 } @BUILD_ACTIVEPLATFORMS;
3816
    my %active_buildplatform_parts;
3817
    my %active_build_info;
3818
    foreach ( keys %BUILDINFO )
3819
    {
3820
        next unless ( $active{$_} );
3821
        $active_buildplatform_parts{$_} = $BUILDINFO{$_}{PARTS};
3822
        $active_build_info{$_}          = $BUILDINFO{$_};
3823
    }
3824
 
3825
    $fh->DumpData(
3826
        "# Parts of all platforms.\n#\n",
3827
        "BUILDPLATFORM_PARTS", \%active_buildplatform_parts );
3828
#
3829
#   BUILDINFO
3830
#       Complete TARGET Information
3831
#
3832
    $fh->DumpData(
3833
        "# Extended build information.\n#\n",
3834
        "BUILDINFO", \%active_build_info );
3835
 
3836
#
247 dpurdie 3837
#   BUILD_KNOWNFILES
3838
#       All paths are relative to the project root directory
3839
#       ie: The directory that conatins the build.pl file
3840
#
3841
    $fh->DumpData(
3842
        "# Generated Files that may be known when used as Src files.\n#\n",
3843
        "BUILD_KNOWNFILES", \%BUILD_KNOWNFILES );
3844
 
3845
#
227 dpurdie 3846
#   Close out the file
3847
#
3848
    $fh->Close();
363 dpurdie 3849
 
227 dpurdie 3850
}
3851
 
3852
#-------------------------------------------------------------------------------
3853
# Function        : WriteParsedBuildConfig
3854
#
3855
# Description     : Write all the parsed build.pl data to a single file
3856
#                   Its all in there for use
3857
#
3858
# Inputs          : 
3859
#
3860
# Returns         : 
3861
#
3862
sub WriteParsedBuildConfig
3863
{
3864
    my $cfg_file = "$::BUILDINTERFACE/Buildfile.cfg";
3865
    my %cf_build_info = ();
3866
 
3867
    #
3868
    #   Examine the symbol table and capture most of the entries
3869
    #
3870
    foreach my $symname (keys %main::)
3871
    {
3872
        next if ( $symname =~ m/::/  );                 # No Typeglobs
3873
        next if ( $symname =~ m/^cf_build_info/  );     # Not myself
3874
        next unless ( $symname =~ m/^[A-Za-z]/  );      # No system type names
3875
        next if ( $symname =~ m/^SIG$/  );              # Useless
3876
        next if ( $symname =~ m/^ENV$/  );              # Don't keep the user ENV
3877
        next if ( $symname =~ m/^INC$/  );              # Don't keep the INC paths
3878
        next if ( $symname =~ m/^DEFINES/  );           # Don't keep
3879
        next if ( $symname =~ m/^TOOLSETRULES/  );      # Don't keep
3880
 
331 dpurdie 3881
        no strict 'vars';
227 dpurdie 3882
        local *sym = $main::{$symname};
3883
 
331 dpurdie 3884
        $cf_build_info{"\$$symname"} =  $sym if defined $sym;
369 dpurdie 3885
        $cf_build_info{"\@$symname"} = \@sym if @sym;
3886
        $cf_build_info{"\%$symname"} = \%sym if %sym;
331 dpurdie 3887
        use strict 'vars';
227 dpurdie 3888
    }
3889
 
3890
    #
3891
    #   Dump out the configuration information
3892
    #
3893
    my $fh = ConfigurationFile::New( "$cfg_file" );
3894
    $fh->Header( "buildlib (version $::BuildVersion)",
3895
                              "Buildfile configuration" );
3896
    $fh->Dump( [\%cf_build_info], [qw(*cf_build_info)] );
3897
    $fh->Close();
3898
}
3899
 
3900
 
3901
#-------------------------------------------------------------------------------
3902
# Function        : BuildSharedLibFiles
3903
#
3904
# Description     : Create a file in the interface directory that will specify
3905
#                   the locations of shared libraries.
3906
#
3907
#                   Note: Always create a file as makefile targets depend on it.
3908
#
3909
#                   This is a bit ugly.
3910
#
3911
#                   There needs be an association between the build machine and
3912
#                   the target platform. Need to know if the current target is
3913
#                   native to the current build machine. If it is then we can
3914
#                   run tests on the machine and we then need to extend the
3915
#                   search path for the target.
3916
#
3917
#                   The BUILDINFO{EXT_SHARED} is used to control the creation of
3918
#                   the files by specifying the extension of the file.
3919
#
3920
# Inputs          : None
3921
#
3922
# Returns         :
3923
#
3924
sub BuildSharedLibFiles
3925
{
3926
    if ( $ScmHost eq "DOS" || $ScmHost eq "WIN" ) {
3927
        BuildSharedLibFiles_WIN(@_);
3928
 
3929
    } elsif ( $ScmHost eq "Unix" ) {
3930
        BuildSharedLibFiles_Unix(@_);
3931
 
3932
    } else {
3933
        Error("Cannot build. Unknown machine type: $ScmHost",
3934
              "Need WIN, DOS or Unix" );
3935
    }
3936
}
3937
 
3938
#-------------------------------------------------------------------------------
3939
# Function        : BuildSharedLibFiles_WIN
3940
#
3941
# Description     : Implementation of BuildSharedLibFiles for Windows
3942
#
3943
# Inputs          : None
3944
#
3945
sub BuildSharedLibFiles_WIN
3946
{
3947
 
3948
    foreach my $platform ( @BUILD_ACTIVEPLATFORMS )
3949
    {
3950
        next unless ( exists $BUILDINFO{$platform}{EXT_SHARED} );
3951
        my @dos_paths = BuildSharedLibFiles_list( $platform, $BUILDINFO{$platform}{EXT_SHARED} );
3952
 
3953
        #
3954
        #   Create a .bat file for WIN32
3955
        #   This may be consumed by user wrapper programs
3956
        #
229 dpurdie 3957
        #   Features: No Echo
3958
        #             Use of SETLOCAL to prevent pollution of environment
3959
        #
227 dpurdie 3960
        my $fh = ::ConfigurationFile::New( "$BUILDINTERFACE/set_$platform.bat", '--NoEof', '--Type=bat' );
229 dpurdie 3961
        $fh->Write ( "\@echo off\n");
227 dpurdie 3962
        $fh->Header( "Buildlib ($BuildVersion)","Shared Library Paths" );
229 dpurdie 3963
        $fh->Write ( "\nSETLOCAL\n");
227 dpurdie 3964
        foreach ( reverse @dos_paths )
3965
        {
3966
            $_ =~ s~/~\\~g;
3967
            $fh->Write ( "PATH=$_;\%PATH\%\n" );
3968
        }
3969
        $fh->Write ( "\n%*\n" );
229 dpurdie 3970
        $fh->Write ( "\nENDLOCAL\n");
231 dpurdie 3971
        $fh->Write ( "EXIT /B %ERRORLEVEL%\n");
227 dpurdie 3972
        $fh->Close();
3973
 
3974
        #
3975
        #   Create a .sh file for WIN32
3976
        #   This may be consumed by a shell - as used within JATS
3977
        #
3978
        $fh = ::ConfigurationFile::New( "$BUILDINTERFACE/set_$platform.sh", '--NoEof', '--Type=sh' );
3979
        $fh->Header( "Buildlib ($BuildVersion)","Shared Library Paths" );
3980
        foreach ( reverse @dos_paths )
3981
        {
3982
            tr~\\/~/~s;
3983
            $fh->Write ( "PATH=$_\\;\$PATH\n" );
3984
        }
287 dpurdie 3985
        $fh->Write ( "\n" . '[ -n "$*" ] && "$@"'  ."\n" );
227 dpurdie 3986
        $fh->Close();
3987
    }
3988
}
3989
 
3990
#-------------------------------------------------------------------------------
3991
# Function        : BuildSharedLibFiles_Unix
3992
#
3993
# Description     : Implementation of BuildSharedLibFiles for Unix
3994
#                   Extend the Shared Library search path via LD_LIBRARY_PATH
3995
#
3996
# Inputs          : None
3997
#
3998
sub BuildSharedLibFiles_Unix
3999
{
4000
    foreach my $platform ( @BUILD_ACTIVEPLATFORMS )
4001
    {
4002
        next unless ( exists $BUILDINFO{$platform}{EXT_SHARED} );
4003
        my @unix_paths = BuildSharedLibFiles_list( $platform, $BUILDINFO{$platform}{EXT_SHARED} );
4004
 
4005
        #
4006
        #   Create a .sh file for Unix
4007
        #
229 dpurdie 4008
        my $file = "$BUILDINTERFACE/set_$platform.sh";
4009
        my $fh = ::ConfigurationFile::New( $file , '--NoEof', '--Type=sh' );
227 dpurdie 4010
        $fh->Header( "Buildlib ($BuildVersion)","Shared Library Paths" );
4011
        foreach ( reverse @unix_paths )
4012
        {
4013
            $fh->Write ( "export LD_LIBRARY_PATH=$_:\$LD_LIBRARY_PATH\n" );
4014
        }
275 dpurdie 4015
        $fh->Write ( "\n\"\$\@\"\n" );
227 dpurdie 4016
        $fh->Close();
229 dpurdie 4017
 
4018
        #
4019
        #   Make the file executable under unix
4020
        #
4021
        chmod 0755, $file;
227 dpurdie 4022
    }
4023
}
4024
 
4025
#-------------------------------------------------------------------------------
4026
# Function        : BuildSharedLibFiles_list
4027
#
4028
# Description     : Determine a list of Shared Library paths that can be used
4029
#                   by the current target
4030
#
4031
# Inputs          : $platform       - Current platform
4032
#                   $so             - Shared object extensions
4033
#
4034
# Returns         : List of search paths
4035
#
4036
sub BuildSharedLibFiles_list
4037
{
4038
    my ($platform, $so ) = @_;
4039
    my @paths;
4040
    my @parts = @{$BUILDINFO{$platform}{PARTS}};
4041
 
4042
    #
4043
    #   Paths from the current build
4044
    #       Local directory         - for installed components
4045
    #       Interface directory     - for BuildPkgArchives
4046
    #
4047
    if ( $BUILDLOCAL )
4048
    {
4049
        foreach ( @parts )
4050
        {
4051
            push @paths, AbsPath("$BUILDLOCAL/lib/$_");
4052
        }
4053
    }
4054
 
4055
    foreach ( @parts )
4056
    {
4057
            push @paths, AbsPath("$BUILDINTERFACE/lib/$_");
4058
    }
4059
 
4060
    #
4061
    #   For each LinkPkgArchive
4062
    #
4063
    foreach my $package ( @{$PKGRULES{$platform}} )
4064
    {
4065
        next unless ( $package->{'type'} eq 'link' );
4066
 
4067
        my $base = $package->{'base'};
4068
        for my $path ( @{$package->{'PLIBDIRS'}} )
4069
        {
289 dpurdie 4070
            my @so_libs;
317 dpurdie 4071
            push @so_libs, glob ( "$base$path/*$_") foreach ( ArrayList($so) );
227 dpurdie 4072
            next unless scalar @so_libs;
4073
            push @paths, $base . $path;;
4074
        }
4075
    }
4076
 
4077
    #
4078
    #   Returns paths found
4079
    #
4080
    return @paths;
4081
}
4082
 
4083
#-------------------------------------------------------------------------------
247 dpurdie 4084
# Function        : BuildAddKnownFile
4085
#
4086
# Description     : Save the file as a file that will be known  to the JATS
4087
#                   makefiles. It will be available SRCS, but will not be a
4088
#                   part of any object list.
4089
#
4090
#                   Known Files will be deleted on clobber
4091
#
4092
# Inputs          : $path
4093
#                   $file
289 dpurdie 4094
#                   $noadd                    - Don't add to known
247 dpurdie 4095
#
4096
# Returns         : Path and filename
4097
#
4098
 
4099
sub BuildAddKnownFile
4100
{
289 dpurdie 4101
    my ($path, $file, $noadd) = @_;
247 dpurdie 4102
    $path .= '/'. $file;
2450 dpurdie 4103
    $path =~ tr~/~/~s;
289 dpurdie 4104
    $BUILD_KNOWNFILES {$file} = $path
4105
        unless ( defined($noadd) && $noadd);
4003 dpurdie 4106
 
3967 dpurdie 4107
    ToolsetFile( $path )
4108
        unless ($Clobber);
4109
 
247 dpurdie 4110
    return $path;
4111
}
4112
 
4113
#-------------------------------------------------------------------------------
227 dpurdie 4114
# Function        : Usage
4115
#
4116
# Description     : Display program usage information
4117
#
4118
# Inputs          : args            - Text message to display
4119
#
4120
#                   $opt_help       - Level of verbose ness
4121
#
4122
# Returns         : Does not return
4123
#                   This function will exit
4124
#
4125
sub Usage
4126
{
4127
    my( $msg ) = @_;
4128
    my %usage_args;
4129
 
4130
    #
4131
    #   Create a hash of arguments for the pod2usage function
4132
    #
4133
    $usage_args{'-input'} = __FILE__;
4134
    $usage_args{'-exitval'} = 42;
4135
    $usage_args{'-message'} = "\nbuildlib $msg\n" if $msg;
4136
    $usage_args{'-verbose'} = $opt_help < 3 ? $opt_help - 1 : 3 if ( $opt_help );
4137
 
4138
    #
4139
    #   Generate nice help
4140
    #
4141
    pod2usage(\%usage_args);
4142
}
4143
 
4144
#-------------------------------------------------------------------------------
4145
#   Documentation
4146
#
4147
 
4148
=pod
4149
 
361 dpurdie 4150
=for htmltoc    JATS::build
4151
 
227 dpurdie 4152
=head1 NAME
4153
 
361 dpurdie 4154
build - Build Environment and Makefiles
227 dpurdie 4155
 
4156
=head1 SYNOPSIS
4157
 
4158
jats build [options] [command]
4159
 
4160
     [perl buildlib.pl [options] PWD [command]]
4161
 
4162
 Options:
331 dpurdie 4163
    -help          - Display terse usage
361 dpurdie 4164
    -help -help    - Display verbose usage
331 dpurdie 4165
    -man           - Display internal manual
4166
    -verbose[=n]   - Set level of progress verbosity
4167
    -debug[=n]     - Set the debug level
4168
    -nolog         - Do not generate/update Changelog
4169
    -cache         - Cache packages in the local dpkg_package cache
361 dpurdie 4170
    -cache -cache  - Forced refresh dependent packages in the local cache
331 dpurdie 4171
    -package       - Ignore packages that are not available and continue
2078 dpurdie 4172
    -nopackages    - Ignore package processing directives
331 dpurdie 4173
    -forcebuildpkg - Treat LinkPkgArchive directives as BuildPkgArchive
361 dpurdie 4174
                     Also suppress the use of symlinks so that the physical
4175
                     file will be copied locally.
331 dpurdie 4176
    -[no]force     - Force build even if build.pl is not newer
363 dpurdie 4177
                     Default: -force
4778 dpurdie 4178
    -[no]generic   - Build system sanity test
4179
                     Default: Do not test
227 dpurdie 4180
 
4181
 Sticky settings:
331 dpurdie 4182
    -all           - Build for all platforms ignoring GBE_BUILDFILTER
4183
    -expert[=n]    - Relaxing dependency checks on the user makefiles
227 dpurdie 4184
 
4185
 Commands:
361 dpurdie 4186
    changelog      - Only update ChangeLog.
2078 dpurdie 4187
    clobber        - Remove generated build system (eg Makefiles).
361 dpurdie 4188
    interface      - Only (re)build the interface tree, including ChangeLog.
4189
    rootonly       - Only (re)build the root directory.
227 dpurdie 4190
 
4191
=head1 OPTIONS
4192
 
4193
=over 8
4194
 
331 dpurdie 4195
=item B<-help>
227 dpurdie 4196
 
4197
Print a brief help message and exits.
4198
 
4199
=item B<-help -help>
4200
 
4201
Print a detailed help message with an explanation for each option.
4202
 
4203
=item B<-man>
4204
 
4205
Prints the manual page and exits.
4206
 
331 dpurdie 4207
=item B<-verbose[=n]>
227 dpurdie 4208
 
261 dpurdie 4209
Increases program output.
227 dpurdie 4210
 
261 dpurdie 4211
If an argument is provided, then it will be used to set the level, otherwise the
4212
existing level will be incremented. This option may be specified multiple times.
227 dpurdie 4213
 
261 dpurdie 4214
=item B<-debug>
4215
 
227 dpurdie 4216
Increases program output. Enable internal debugging messages to generate detailed
4217
progress information.
4218
 
261 dpurdie 4219
If an argument is provided, then it will be used to set the level, otherwise the
4220
existing level will be incremented. This option may be specified multiple times.
4221
 
331 dpurdie 4222
=item B<-nolog>
227 dpurdie 4223
 
4224
Do not generate or update the ChangeLog maintained when a CVS directory is detected
4225
in the build directory.
4226
 
331 dpurdie 4227
=item B<-cache>
227 dpurdie 4228
 
4229
This option will cause dependent packages to be cached in the local
4230
dpkg_archive cache.
4231
 
4232
If the option is used twice then the packages will be forcibly refreshed.
4233
 
331 dpurdie 4234
=item B<-package>
227 dpurdie 4235
 
4236
This option will cause the build process to ignore packages that cannot be
4237
located. The package build may fail at a later stage.
4238
 
4239
This option is used by the Auto Build Tool to handle packages that may not be
4240
needed in all builds.
4241
 
2078 dpurdie 4242
=item B<-nopackage>
4243
 
4244
This options will cause all the directives that process external packages to be
4245
ignored.
4246
 
4247
This directive has limited use. It can be used in conjunction with the
4248
'interface' build command in order to create Version Information files in a
4249
sandbox where the required packages do not yet exist.
4250
 
331 dpurdie 4251
=item B<-forcebuildpkg>
227 dpurdie 4252
 
4253
This option will force LinkPkgArchive directives to be treated as
4254
BuildPkgArchive directives. The result is that the 'interface' directory will be
4255
populated with the contents of all dependent packages. Moreover, on a Unix
4256
machine, the files will be copied and not referenced with a soft link.
4257
 
4258
This may be useful for:
4259
 
4260
=over 8
4261
 
361 dpurdie 4262
=item *
227 dpurdie 4263
 
361 dpurdie 4264
Remote Development
227 dpurdie 4265
 
361 dpurdie 4266
=item *
227 dpurdie 4267
 
361 dpurdie 4268
Collecting header files for scanning
4269
 
4270
=item *
4271
 
4272
Local modification of files for test/debug/development
4273
 
227 dpurdie 4274
=back
4275
 
331 dpurdie 4276
=item B<-[no]force>
227 dpurdie 4277
 
331 dpurdie 4278
The '-noforce' option will only perform a build, if the build.pl file
363 dpurdie 4279
has been modified, or the buildfilter has changed, since the last build.
331 dpurdie 4280
 
363 dpurdie 4281
The default operation will always force a build.
331 dpurdie 4282
 
4778 dpurdie 4283
=item B<-[no]generic>
4284
 
4285
If used, this option will perform a sanity test on the build type. If set to 
4286
Generic then the build must be a GENERIC build. If set to noGeneric then the build
4287
must not be a GENERIC build.
4288
 
4289
The default is to not perform the test.
4290
 
4291
This option is intended to be used by the automated build system.
4292
 
331 dpurdie 4293
=item B<-all>
4294
 
227 dpurdie 4295
This option will cause the build process to generate makefiles for all
4296
possible build targets ignoring the use of GBE_BUILDFILTER.
4297
 
4298
This option is sticky. Once used in a build it will be retained when makefiles
4299
are rebuilt.
4300
 
331 dpurdie 4301
=item B<-expert[=n]>
227 dpurdie 4302
 
4303
This option causes the generation of makefiles with relaxed dependancy checks.
4304
 
261 dpurdie 4305
If an argument is provided, then it will be used to set the level, otherwise a
4306
level of '1' will be set.
4307
 
227 dpurdie 4308
The makefiles will have no dependancy between the makefiles and the JATS build
4309
files or the users makefile. If the user's makefile.pl is changed then JATS
4310
will not detect the change and will not rebuild the makefiles. The user manually
4311
force the rebuild with the command 'jats rebuild'.
4312
 
4313
This option should be used with care and with full knowledge of its impact.
4314
 
4315
This option is sticky. Once used in a build it will be retained when makefiles
363 dpurdie 4316
are rebuilt. It will only be lost when the next 'jats build' is performed.
227 dpurdie 4317
 
261 dpurdie 4318
The effect of the option can be changed when the makefiles are processed. This
4319
option simply sets the default' mode of operation.
4320
 
227 dpurdie 4321
=item B<changelog>
4322
 
4323
This command will only update the CVS change log.
4324
 
4325
=item B<interface>
4326
 
4327
This command will only build, or rebuild, the 'interface' directory and the
4328
changelog ( if required ).
4329
 
261 dpurdie 4330
This command will not build, or rebuild, the root directory. The build
227 dpurdie 4331
process will not recurse through the subdirectories creating makefiles.
4332
 
261 dpurdie 4333
=item B<rootonly>
4334
 
4335
This command will only build, or rebuild, the 'interface' directory, the
4336
changelog (if required) and the root-level makefiles.
4337
 
4338
The build process will not recurse through the subdirectories creating
4339
makefiles. These can be made on-demand by jats if a 'make' command is issued.
4340
 
227 dpurdie 4341
=item B<clobber>
4342
 
4343
This command will remove generated build system files and directories.
4344
 
4345
=back
4346
 
4347
=head1 DESCRIPTION
4348
 
4349
The default build process will parse the user's build.pl file and create the
4350
'interface' directory before creating makefiles for each target platform.
4351
 
4352
The 'build' process simply generates the build sandbox. It does not invoke the
4353
generated makefiles. This must be done by the user in a different phase.
4354
 
4355
The 'build' process need only be invoked if the build.pl file has changed. The
4356
generated makefiles will detected changes to the makefile.pl's and cause them to
4357
be generated as required. The 'build' step sets up the sandboxes external
4358
environment.
4359
 
4360
=head1 INVOCATION
4361
 
4362
This perl library (buildlib.pl) is not designed to be invoked directly by the
4363
user. It should be invoked through a 'build.pl' file. Moreover, for historical
4364
reasons, the build.pl is not easily invoked. It is best to only invoke the
4365
'build' process via the JATS wrapper scripts : jats.bat or jats.sh.
4366
 
331 dpurdie 4367
The build.pl file must be invoked with one fixed arguments, followed by user
227 dpurdie 4368
options and subcommands
4369
 
4370
=over 8
4371
 
361 dpurdie 4372
=item   1
227 dpurdie 4373
 
361 dpurdie 4374
The current working directory
4375
 
227 dpurdie 4376
This could have been derived directly by the program, rather than having it
4377
passed in.
4378
 
361 dpurdie 4379
=item   2
227 dpurdie 4380
 
361 dpurdie 4381
Options and commands may follow the first two mandatory arguments.
4382
 
227 dpurdie 4383
=back
4384
 
4385
The build.pl file must 'require' the buildlib.pl and makelib.pl. The preferred
4386
code is:
4387
 
4388
=over 8
4389
 
4390
    build.pl: First statements
4391
    $MAKELIB_PL     = "$ENV{ GBE_TOOLS }/makelib.pl";
4392
    $BUILDLIB_PL    = "$ENV{ GBE_TOOLS }/buildlib.pl";
4393
 
4394
    require         "$BUILDLIB_PL";
4395
    require         "$MAKELIB_PL";
4396
 
4397
=back
4398
 
4399
=cut
4400
 
4401
1;