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