Subversion Repositories DevTools

Rev

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

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