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; -*-
261 dpurdie 2
# Copyright (C) 1998-2008 ERG Transit Systems, All rights reserved
227 dpurdie 3
#
4
# Module name   : makelib.pl2
5
# Module type   : Makefile system
6
#
7
# Description:
8
#       This modules builds the platform definition makefiles(s)
9
#
10
# Notes:                *** DO NOT DETAB ***
11
#       Beware the use of space v's tab characters within the
12
#       makefile generation sessions.
13
#
14
##############################################################################
15
# Globals:
16
#  $ScmVersion          Makelib.pl2 version
17
#  $ScmRoot             Command line parameter that gives the root directory
18
#                       location for this directory tree.
19
#  $ScmMakelib          Command line parameter that points to the location
20
#                       of THIS script.  ie. location of makelib.pl.
21
#  $ScmPlatform         Current platform
22
#  $ScmProduct          Current product (if any)
23
#  $ScmTarget           Resulting target (derived from Platform)
24
#  @ScmPlatformArgs     Platform arguments
25
#  $ScmToolset          Toolset
26
#  @ScmToolsetArgs      Toolset arguments
27
#  $ScmDebug            Debug level
28
#  $ScmVerbose          Verbose setting
29
#  $ScmSourceTypes      Source types, aliasing for C, C++ and assembler
30
#                       source.
31
#  @CFLAGS              List containing all of the defined C flags
32
#  @CXXFLAGS            List containing all of the defined C++ flags
33
#  @ASFLAGS             List containing all of the defined assembler flags
34
#  @CLINTFLAGS          List containing all of the defined C lint flags
35
#  @CXXLINTFLAGS        List containing all of the defined C++ lint flags
36
#  @{G|L}_INCDIRS       List containing all of include paths
37
#  @{G|L}_SRCDIRS       List containing all of source search paths
38
#  @{G|L}_LIBDIRS       List containing all of library search paths
39
#  @LDFLAGS             List containing all of the defined linker flags
40
#  @SRCS                List of ALL source files. ie. C/C++ and other (eg .x)
41
#                       Key is source file, value is source path
42
#  @OBJS                List of ALL (non-shared) object files.
289 dpurdie 43
#  %SHOBJ_LIB           List of ALL shared library object files and associated library.
227 dpurdie 44
#  %OBJSOURCE           List of ALL object files
45
#                       from that should result from later makes.
46
#                       Key is objectfile, value is source file
47
#  %OBJREFS             List of ALL object files, built options.
48
#  @PROGOBJS            List of ALL application object files.
49
#  %SRC_ARGS            List of arguments that are to be used when making the
50
#                       nominated source.  Key is the source name, the
51
#                       value is a string of arguments to apply.  The
52
#                       arguments are '$;' separated.
53
#  %SRC_TYPE            Source file type (user override).
54
#  @CHDRS               List of C header files.
55
#  @CSRCS               List of C files
56
#                       Key is objectfile, value is source file
57
#  @CXXSRCS             List of C++ files
58
#  @ASHDRS              List of assembler include files (.inc)
59
#  @ASSRCS              List of assembler source files
60
#  @GENERATED           List of files that should result from a 'generate'
61
#                       make rule.  The programmer is expected to provide
62
#                       the necessary rule(s).
63
#  @RULES               List of additional make rules the programmer
64
#                       has specified to be included in the make.
65
#  %INSTALL_HDRS        List of headers that are to be installed for later
66
#                       "public" consumption.
67
#  %INSTALL_CLSS        List of Java classes or JAR files that are to be installed
68
#                       for later "public" consumption.
69
#  @LIBS                List of libraries that are to be built.
289 dpurdie 70
#  $LIBS                Ref to a collection of static library descriptors
71
#                       Indexed by lib name
227 dpurdie 72
#  %INSTALL_LIBS        List of libraries that are to be installed for later
73
#                       public consumption.
74
#  @MLIBS               List of libraries that are to be built via merging
289 dpurdie 75
#  $MLIBS               Ref to a collection of merged lib descriptors
227 dpurdie 76
#  @SHLIBS              List of shared libraries that are to be built.
289 dpurdie 77
#  $SHLIBS              Ref to collection of shared library information
227 dpurdie 78
#  %INSTALL_SHLIBS      List of libraries that are to be installed for later
79
#                       public consumption.
80
#  @PROGS               List of programs (binary executables) that are
81
#                       to be built
289 dpurdie 82
#  $PROGS               Ref to collection of program information
227 dpurdie 83
#  %SCRIPTS             List of scripts to 'create' (key) and whether they
84
#                       should be made executable or not (value).  Script
85
#                       set to executable is denoted by the value being
86
#                       defined AND true.
87
#  %INSTALL_PROGS       List of programs for "public" cosumption to install
88
#                       where (key) is the file and where to install it
89
#                       to vs. (value) which is composed of the original
90
#                       location of the file, the destination directory
91
#                       and a list of service providers this file applies to.
92
# $ProjectBase          Base of the user's project. This variable is designed to
93
#                       be used by the user.
94
#....
95
 
255 dpurdie 96
require 5.006_001;
227 dpurdie 97
use strict;
98
use warnings;
261 dpurdie 99
use Getopt::Long;
227 dpurdie 100
use Data::Dumper;
271 dpurdie 101
use JatsError;
227 dpurdie 102
use JatsEnv;
103
use MakeEntry;
104
use JatsLocateFiles;
105
use JatsDPackage;
271 dpurdie 106
use MakeIf;
289 dpurdie 107
use ToolsetPrinter;
108
use MakeObject;
339 dpurdie 109
use JatsVersionUtils;
227 dpurdie 110
 
111
 
112
our $ScmVersion             = "2.34";
113
our $ScmGlobal              = 0;
114
our $ScmExpert              = 0;
115
our $ScmInterface           = "interface";      # default 'interface'
116
our $ScmPackage             = 1;                # package active by default.
117
our $ScmProcessingRootMake  = 0;                # Processing root makefile.pl
118
our $ScmPlatformSeen        = 0;                # Platform directive has been seen
119
 
120
our $ScmToolsetVersion      = "";               # version of toolset
121
our $ScmToolsetGenerate     = 1;                # generate active by default.
122
our $ScmToolsetProgDependancies = 1;            # 1: Write program dependancies
123
                                                # 0: Don't write progdeps. Prog is Phony
289 dpurdie 124
our $ScmToolsetSingleType   = 0;                # Toolset does not support Debug and Production
227 dpurdie 125
our $ScmToolsetProgSource   = ();               # Toolset Program Source
339 dpurdie 126
our $ScmToolsetSoName       = 0;                # 1: Shared library supports SoName
363 dpurdie 127
our $ScmToolsetNillLibSrc   = 0;                # 1: Librarys created without source specified
128
 
227 dpurdie 129
our $ScmRoot                = "";
130
our $ScmMakelib             = "";
131
our $ScmPlatform            = "";
132
our $ScmMachType            = "";
133
our $ScmSrcDir              = "";
134
our @ScmPlatformDirs        = ();
135
our @ScmPlatformArgs        = ();
289 dpurdie 136
our $ScmBuildType           = 0;                # 0, P, D. 0 == P and D
227 dpurdie 137
our $ScmProduct             = "";
138
our $ScmTarget              = "";
139
our $ScmTargetHost          = "";
140
our $ScmToolset             = "";
141
our @ScmToolsetArgs         = ();
142
our @ScmDepends             = ();
143
our %ScmSourceTypes         = ();
144
our $ScmDeploymentPatch     = "";
145
our $ProjectBase            = "";               # Base of the user's project
146
our $ScmNoToolsTest         = "";               # Supress compiler tests
147
our $ScmDependTags          = 0;                # Create dependancy scanning tag
148
 
149
our @CFLAGS                 = ();
150
our @CFLAGS_DEBUG           = ();
151
our @CFLAGS_PROD            = ();
152
our @CLINTFLAGS             = ();
153
our @CLINTFLAGS_DEBUG       = ();
154
our @CLINTFLAGS_PROD        = ();
155
our @CXXFLAGS               = ();
156
our @CXXFLAGS_DEBUG         = ();
157
our @CXXFLAGS_PROD          = ();
158
our @CXXLINTFLAGS           = ();
159
our @CXXLINTFLAGS_DEBUG     = ();
160
our @CXXLINTFLAGS_PROD      = ();
161
our @ASFLAGS                = ();
267 dpurdie 162
our @ASFLAGS_DEBUG          = ();
163
our @ASFLAGS_PROD           = ();
227 dpurdie 164
our @LDFLAGS                = ();
267 dpurdie 165
our @LDFLAGS_DEBUG          = ();
166
our @LDFLAGS_PROD           = ();
227 dpurdie 167
 
168
our @INCDIRS                = ();
169
our @NODEPDIRS              = ();
170
our @S_INCDIRS              = ();
171
our @G_INCDIRS              = ();
172
our @L_INCDIRS              = ();
173
our @SRCDIRS                = ();
174
our @S_SRCDIRS              = ();
175
our @G_SRCDIRS              = ();
176
our @L_SRCDIRS              = ();
177
our @LIBDIRS                = ();
178
our @S_LIBDIRS              = ();
179
our @G_LIBDIRS              = ();
180
our @L_LIBDIRS              = ();
181
 
182
our %SRCS                   = ();
183
our %SRC_ARGS               = ();
184
our %SRC_TYPE               = ();
185
our %SRC_DEPEND             = ();
186
our %SCRIPTS                = ();
187
our @COPYIN                 = ();
188
our @INITS                  = ();
189
our @DEFINES                = ();
190
our @OBJS                   = ();
191
our %SHOBJ_LIB              = ();
192
our @PROGOBJS               = ();
289 dpurdie 193
our @TESTPROGOBJS           = ();
227 dpurdie 194
our %OBJSOURCE              = ();
195
our @CHDRS                  = ();
196
our @CSRCS                  = ();
197
our @CXXSRCS                = ();
198
our @ASHDRS                 = ();
199
our @ASSRCS                 = ();
200
our @GENERATED              = ();
201
our @GENERATED_NOTSRC       = ();
202
our @RULES                  = ();
203
our @TOOLSETRULES           = ();
204
our @TOOLSETDIRS            = ();
205
our @TOOLSETDIRTREES        = ();
206
our @TOOLSETGENERATED       = ();
207
our @USERGENERATED          = ();
208
our @TOOLSETOBJS            = ();
209
our @TOOLSETLIBS            = ();
210
our @TOOLSETPROGS           = ();
211
our %INSTALL_HDRS           = ();
212
our %INSTALL_CLSS           = ();
213
 
214
our @LIBS                   = ();
289 dpurdie 215
our $LIBS                   = ();
227 dpurdie 216
our %LIB_PKG                = ();
217
our %LIB_INS                = ();
218
our %INSTALL_LIBS           = ();
219
 
220
our @MLIBS                  = ();
289 dpurdie 221
our $MLIBS                  = ();
227 dpurdie 222
 
223
our @SHLIBS                 = ();
289 dpurdie 224
our $SHLIBS                 = ();
227 dpurdie 225
our @SHLIB_TARGETS          = ();
226
our %SHLIB_PKG              = ();
227
our %SHLIB_INS              = ();
228
our %INSTALL_SHLIBS         = ();
229
 
289 dpurdie 230
our $TESTPROGS              = ();
231
our @TESTPROGS              = ();
227 dpurdie 232
 
289 dpurdie 233
our $PROGS                  = ();           # Simplify tracking of progs
227 dpurdie 234
our @PROGS                  = ();
289 dpurdie 235
our @PROGS_EXTRA            = ();           # Look at doing better !!
227 dpurdie 236
our %PROG_PKG               = ();
237
our %PROG_INS               = ();
238
our %INSTALL_PROGS          = ();
239
 
240
our %PACKAGE_DIST           = ();
241
our %PACKAGE_SETS           = ();
242
our %PACKAGE_HDRS           = ();
243
our %PACKAGE_LIBS           = ();
244
our %PACKAGE_CLSS           = ();
245
our %PACKAGE_SHLIBS         = ();
246
our %PACKAGE_PROGS          = ();
247
our %PACKAGE_FILES          = ();
248
 
249
our @PACKAGE_VARS           = ( '%PACKAGE_CLSS',  '%PACKAGE_FILES', '%PACKAGE_HDRS',
250
                                '%PACKAGE_LIBS',  '%PACKAGE_PROGS', '%PACKAGE_SHLIBS' );
251
our @INSTALL_VARS           = ( '%INSTALL_CLSS',  '%INSTALL_HDRS',  '%INSTALL_LIBS',
252
                                '%INSTALL_PROGS', '%INSTALL_SHLIBS');
253
 
254
our @LINTLIBS               = ();
255
our @LINTSHLIBS             = ();
256
 
257
our @TESTS_TO_RUN           = ();
258
our @TESTPROJECT_TO_URUN    = ();
259
our @TESTPROJECT_TO_ARUN    = ();
260
my  $TESTS_TO_AUTORUN       = undef;
263 dpurdie 261
my  $TESTS_TO_RUN           = undef;
227 dpurdie 262
 
263
#our $CurrentTime           = "";
264
#our $CurrentDate           = "";
265
#our $Cwd                   = "";
266
 
267
our @GENERATE_FILES         = ();
268
our %DEPLOYPACKAGE          = ();
267 dpurdie 269
our $DEPLOYPACKAGE          = 0;
261 dpurdie 270
our %MakeTags;
227 dpurdie 271
 
272
#
273
#   Some toolset options that affect the generation of the makefile
274
#
275
our $UseAbsObjects          = 0;                # Default is relative paths to objects
276
our $UseRelativeRoot        = 0;                # Default is absolute paths to build root
299 dpurdie 277
our $DPackageDirective      = 0;
227 dpurdie 278
 
271 dpurdie 279
#
280
#   Arrays of hook functions
281
#
282
our %MF_RegisterSrcHooks;                       # Hook source file discovery
283
 
284
 
227 dpurdie 285
###############################################################################
286
#
287
#   Packaging and Installation Information
288
#   Held in a structure as its used in a few places
289
#   Items
290
#       PBase   - Package Base directory. Used for user overrides
291
#       IBase   - Local Install Base directory
292
#       Dir     - Default directory suffix for components. Added to Pbase and IBase
293
#
294
#
295
our %PackageInfo = (
296
    'File' => { 'PBase' => '$(PKGDIR)'       ,'IBase' => '$(LOCALDIR)'       , 'Dir' => '' },
297
    'Hdr'  => { 'PBase' => '$(INCDIR_PKG)'   ,'IBase' => '$(INCDIR_LOCAL)'   , 'Dir' => ''},
298
    'Lib'  => { 'PBase' => '$(LIBDIR_PKG)'   ,'IBase' => '$(LIBDIR_LOCAL)'   , 'Dir' => '/$(GBE_PLATFORM)'},
299
    'Prog' => { 'PBase' => '$(BINDIR_PKG)'   ,'IBase' => '$(BINDIR_LOCAL)'   , 'Dir' => '/$(GBE_PLATFORM)$(GBE_TYPE)'},
300
    'Jar'  => { 'PBase' => '$(CLSDIR_PKG)'   ,'IBase' => '$(CLSDIR_LOCAL)'   , 'Dir' => ''},
241 dpurdie 301
    'Tool' => { 'PBase' => '$(PKGDIR)'       ,'IBase' => '$(LOCALDIR)'       , 'Dir' => '/tools/bin/$(GBE_HOSTMACH)'},
227 dpurdie 302
    );
303
 
304
MakeLib2Init();                                 # Runtime initialisation
305
 
306
sub MakeLib2Init
307
{
308
#.. Test environment
309
#
310
    EnvImport( "GBE_CORE" );
311
    EnvImport( "GBE_BIN" );
312
    EnvImport( "GBE_PERL" );
313
    EnvImport( "GBE_TOOLS" );
314
    EnvImport( "GBE_CONFIG" );
315
    EnvImport( "GBE_MACHTYPE" );
316
 
317
#.. Common stuff
318
#
319
    require "$::GBE_TOOLS/common.pl";           # Common stuff
320
    push( @ScmDepends, "$::GBE_TOOLS/common.pl" );
321
 
322
    CommonInit( "makelib2" );
323
    Debug( "version:   $ScmVersion" );
324
 
325
#.. Cache arguments
326
#
327
    CommandLine();
328
 
329
#.. Build defaults
330
#
331
    $ScmSourceTypes{ ".h" }     = ".h";
332
    $ScmSourceTypes{ ".hpp" }   = ".h";
333
    $ScmSourceTypes{ ".c" }     = ".c";
334
    $ScmSourceTypes{ ".C" }     = ".c";
335
    $ScmSourceTypes{ ".cpp" }   = ".cc";
336
    $ScmSourceTypes{ ".cc" }    = ".cc";
337
    $ScmSourceTypes{ ".asm" }   = ".asm";
338
    $ScmSourceTypes{ ".x" }     = "--Ignore";
339
    $ScmSourceTypes{ ".ini" }   = "--Ignore";
340
    $ScmSourceTypes{ ".sh" }    = "--Ignore";
341
    $ScmSourceTypes{ ".pl" }    = "--Ignore";
342
    $ScmSourceTypes{ ".awk" }   = "--Ignore";
343
 
344
#.. Get the stuff from the build configuration file
345
#
346
    ConfigLoad();
347
 
348
    if ( defined(%::ScmBuildPlatforms) )        # Interface/build.cfg
349
    {
350
        AddPlatformArg( split( /$;/, $::ScmBuildPlatforms{ $ScmPlatform } ));
351
    }
352
 
353
    if ( defined(%::ScmBuildIncludes) )         # Interface/build.cfg
354
    {
355
        my( @includes ) = split( ',', $::ScmBuildIncludes{ $ScmPlatform } );
356
        my( $global ) = $ScmGlobal;
357
 
358
        $ScmGlobal = 1;                         # Follow defs are "global's" ...
359
        foreach my $elem ( @includes )
360
        {
361
            AddIncDir( "*", $elem ) if ($elem);
362
        }
363
        $ScmGlobal = $global;                   # Restore global status ...
364
    }
365
 
366
    if ( defined(%::ScmBuildLibraries) )        # Interface/build.cfg
367
    {
368
        my( @libraries ) = split( ',', $::ScmBuildLibraries{ $ScmPlatform } );
369
        my( $global ) = $ScmGlobal;
370
 
371
        $ScmGlobal = 1;                         # Follow defs are "global's" ...
372
        foreach my $elem ( @libraries )
373
        {
374
            AddLibDir( "*", $elem ) if ($elem);
375
        }
376
        $ScmGlobal = $global;                   # Restore global status ...
377
    }
378
 
379
#.. Determine the value of $ScmMachType
380
#   In the makefile GBE_MACHTYPE will be set to $ScmMachType.
381
#
382
#   There is an compatibility issue here.
383
#   A lot of (legacy) package.pl files use GBE_MACHTYPE to specify platform
384
#   specfic directories and names. This is not to be encouraged.
385
#
386
#   Allow for a platformm specific override
387
#
388
    if ( exists( $::BUILDINFO{$ScmPlatform}{'SCMMACHTYPE'} ))
389
    {
390
        $ScmMachType = $::BUILDINFO{$ScmPlatform}{'SCMMACHTYPE'};
391
        Verbose("Override ScmMachType: $ScmMachType");
392
    }
393
    else
394
    {
395
        $ScmMachType = $ScmPlatform;
396
    }
397
 
398
 
399
#.. Get the stuff from the Package definition file
400
#   A convention is that package.pl provide a package name via $Pbase
401
#   This may be different to the BUILDNAME. Generate a default $Pbase
402
#   to allow the package.pl to use the package name part of the buildname
403
#
404
    $::Pbase = $::ScmBuildPackage;
405
    if ( -f "$ScmRoot/package.pl" )
406
    {
407
        Warning ("package.pl file used. Use is being deprecated");
408
 
409
        my( $global ) = $ScmGlobal;             # Follow defs are "global's" ...
410
        $ScmGlobal = 1;
411
        require "$ScmRoot/package.pl";
412
        $ScmGlobal = $global;                   # Restore global status ...
413
 
414
        if ( defined ($::ScmBuildPackage) && defined ($::Pbase) )
415
        {
416
            #   Special case.
417
            #   $Pbase is set to ".". Set $Pbase to the Build Name to force
418
            #   construction of a well formatted package.
419
            #
420
            $::Pbase = $::ScmBuildPackage
421
                if ( $::Pbase eq "." );
422
 
423
            #
424
            #   Error if Pbase has changed
425
            #
426
            Error ("Pbase is not the same as the BuildName (Check package.pl)",
427
                   "Pbase    : $::Pbase",
428
                   "BuildName: $::ScmBuildPackage")
429
                if ( $::Pbase ne $::ScmBuildPackage );
430
        }
431
    }
289 dpurdie 432
 
433
    #
434
    #   Create objects to keep track of Libraies and Programs
435
    #
436
    $LIBS       = MakeObject::NewType( 'Library',       \@LIBS,     '$(LIBDIR)/', \&GenLibName);
437
    $MLIBS      = MakeObject::NewType( 'MergedLibrary', \@MLIBS,    '$(LIBDIR)/', \&GenLibName);
438
    $SHLIBS     = MakeObject::NewType( 'SharedLibrary', \@SHLIBS,   '$(LIBDIR)/', \&GenLibName);
439
    $PROGS      = MakeObject::NewType( 'Program',       \@PROGS,    '$(BINDIR)/', \&GenProgName);
440
    $TESTPROGS  = MakeObject::NewType( 'TestProgram',   \@TESTPROGS,'$(BINDIR)/', \&GenProgName);
227 dpurdie 441
}
442
 
261 dpurdie 443
#-------------------------------------------------------------------------------
289 dpurdie 444
# Function        : GenLibName
445
#
446
# Description     : Helper function to generate a (static) library name
447
#                   Used by MakeObject::NewType
448
#
449
#                   If the toolset doesn't support Debug and Prod, then
450
#                   The library name will not have the suffix
451
#
452
# Inputs          : arg0        - Base name of the library
343 dpurdie 453
#                   arg1        - Mode: 1 == Plain. No P or D
289 dpurdie 454
#
455
# Returns         : Name of the library as used in the makefiles
456
#                   Does not include base directory
457
#
458
sub GenLibName
459
{
343 dpurdie 460
    if ( $ScmToolsetSingleType || $_[1] ) {
289 dpurdie 461
        return "$_[0].$::a"
462
    } else {
463
        return "$_[0]\$(GBE_TYPE).$::a"
464
    }
465
}
466
 
467
#-------------------------------------------------------------------------------
468
# Function        : GenProgName
469
#
470
# Description     : Helper function to generate a program name
471
#                   Used by MakeObject::NewType
472
#
473
# Inputs          : arg0        - Base name of the library
474
#
475
# Returns         : Name of the program as used in the makefiles
476
#                   Does not include base directory
477
#
478
sub GenProgName
479
{
480
    return "$_[0]$::exe"
481
}
482
 
483
 
484
#-------------------------------------------------------------------------------
261 dpurdie 485
# Function        : CommandLine
486
#
487
# Description     : Process the command line.
488
#                   Arguments describes below
489
#
490
# Arguments       : ARG0        - Root of the project
491
#                   ARG1        - Path to this script
492
#                   ARG2        - Target Platform
493
#
494
#                   Options follow
495
#                       --interface=name    - Name of interface dir
496
#                       --arg=xxx           - Platform argument
497
#
498
#                   Otherwise display a usage message
499
#
500
# Returns         : Nothing
501
#
227 dpurdie 502
sub CommandLine
503
{
261 dpurdie 504
    Verbose ("Command Line: @ARGV");
227 dpurdie 505
 
261 dpurdie 506
    #
507
    #   Extract options first
508
    #
509
    my $opt_help = 0;
510
    my $result = GetOptions (
511
                "help+"         => \$opt_help,
512
                "interface=s"   => \$::ScmInterface,
513
                "arg=s"         => sub{ AddPlatformArg( "--$_[1]") }
514
                );
515
    Usage() if ( $opt_help || !$result );
516
 
517
    #
518
    # Need 3 Arguments
519
    #
227 dpurdie 520
    $ScmRoot     = ${ARGV[0]};
261 dpurdie 521
    $ScmRoot     = RelPath( $ScmRoot );
227 dpurdie 522
    $ProjectBase = $ScmRoot;
523
 
524
    $ScmMakelib  = ${ARGV[1]};
525
    $ScmPlatform = ${ARGV[2]};
526
    $ScmTarget   = $ScmPlatform;
527
 
528
    Message ("[$ScmPlatform] Generate Makefile");
529
    Debug( "root\t=$ScmRoot" );
530
    Debug( "makelib\t=$ScmMakelib" );
531
    Debug( "platform\t=$ScmPlatform" );
532
}
533
 
534
#   Usage ---
535
#       Command line usage help.
536
#..
537
 
538
sub Usage
539
{
261 dpurdie 540
    Error ( "Usage: perl makefile.pl2 <ROOTDIR> <makelib.pl2> <PLATFORM> [options ...]",
541
            "Valid options:",
542
            "    --interface=name  Set interface directory",
543
            "    --arg=text        Specify platform argument",
544
            );
227 dpurdie 545
}
546
 
547
 
548
#-------------------------------------------------------------------------------
549
# Function        : SubDir
550
#
551
# Description     : Include a sub-makefile
552
#                   When called when processing by this script this directive
553
#                   does nothing. The processing will be done by makelib.pl
554
#
555
#                   This directive MUST occur before the Platform directive
556
#
557
# Inputs          : None that are used
558
#
559
# Returns         : Nothing
560
#
561
 
562
sub SubDir
563
{
564
    Error ("SubDir directive not allowed after the Platform directive")
565
        if ( $ScmPlatformSeen );
566
}
567
 
568
 
569
###############################################################################
570
#   Platform support
571
###############################################################################
572
 
573
sub Platform
574
{
575
    my( $global, $file );
576
 
577
    Debug( "Platform( $ScmPlatform, @ScmPlatformArgs )" );
578
 
579
#.. Sanity test
580
#
581
    Error ("Platform directive is not allowed in common makefile.pl")
582
        if ( $ScmProcessingRootMake );
583
 
584
    Error ("Only one Platform directive is allowed")
585
        if ( $ScmPlatformSeen );
586
    $ScmPlatformSeen = 1;
587
 
588
#.. Arguments
589
#
590
    $ScmTargetHost = $::ScmHost;                # default
591
 
592
#.. Common configuration
593
#
594
    $global = $ScmGlobal;                       # Follow defs are "global's" ...
595
    $ScmGlobal = 1;
596
 
597
#.. Common rules (ScmHost specific)
598
#
599
    push( @ScmDepends, "$ScmMakelib" );         # parent
600
 
601
    $file = Require( "$::GBE_CONFIG", "Rules", "Common rules " );
602
    push( @ScmDepends, "$file" );
603
 
604
#.. Platform (defines ScmToolset)
605
#
606
    if ( defined( %::ScmBuildProducts ) &&      # interface/build.cfg
607
            $::ScmBuildProducts{ $ScmPlatform } )
608
    {
609
        my( @args ) = split( ',', $::ScmBuildProducts{ $ScmPlatform } );
610
 
611
        $ScmProduct = $args[0];
612
        $ScmTarget = $args[1];
613
 
614
        Debug( " mapping to product $ScmProduct" );
615
 
616
                                                # Platform/target specific
617
        MakeIf::PackageDirs( \@ScmPlatformDirs, $ScmPlatform, $ScmTarget );
618
        push @ScmPlatformDirs, "$::GBE_CONFIG"; # .. plus default
619
 
620
        @ScmPlatformArgs = ( "--product=$ScmProduct", @ScmPlatformArgs );
621
        $file = Require( "PLATFORM", $ScmTarget,
622
                    "Platform definition ", @ScmPlatformDirs );
623
    }
624
    else                                        # standard
625
    {
626
        Debug( " native platform" );
627
 
628
                                                # Platform specific
629
        MakeIf::PackageDirs( \@ScmPlatformDirs, $ScmPlatform );
630
        push @ScmPlatformDirs, "$::GBE_CONFIG"; # .. plus default
631
 
632
        $file = Require( "PLATFORM", $ScmPlatform,
633
                    "Platform definition ", @ScmPlatformDirs );
634
    }
635
    push( @ScmDepends, "$file" );
636
 
637
    Error( "Toolset undefined for platform $ScmPlatform ...")
638
        unless( $ScmToolset );
639
 
640
#.. Toolset
641
#
642
    $file = Require( "$::GBE_CONFIG/TOOLSET", $ScmToolset, "Toolset definition " );
643
    push( @ScmDepends, "$file" );
644
 
645
#.. Package definitions
646
#
367 dpurdie 647
#   Global DPACKAGE definitions, which may pull in $ScmTarget specific definitions.
227 dpurdie 648
#
649
 
650
    MakeIf::PackageLoad( $ScmPlatform );        # DPACKAGE's (if any)
651
 
652
 
653
#.. Package extensions
654
#   Import, into the current package, files of the form gbe/DIRECTIVES
655
#   These allow the JATS directives to be extended by the contents of a package
656
#   without the need to update the core JATS release.
657
#
658
#   Intended use: Associate a directive with a tool script, such that the
659
#   new directive simplifies the use of the tool script.
660
#
661
#
662
#   First: Extend the Perl Search Space to include the toolset extensions
663
#          Although the directives are in gbe/DIRECTIVES/*.pm, they may need
664
#          to reference other packages that are not.
665
#
311 dpurdie 666
#           Look in the 'interface' and 'link' packages
667
#           The 'build' packages are duplicated into the 'interface'
668
#
227 dpurdie 669
    for my $path ( ToolExtensionPaths() )
670
    {
671
        UniquePush (\@INC, $path)
672
            if (glob( "$path/*.pm") || glob( "$path/*/*.pm"));
673
    }
674
 
675
    for my $entry (@{$::ScmBuildPkgRules{$ScmPlatform} })
676
    {
311 dpurdie 677
        next if ( $entry->{'TYPE'} eq 'build' );
227 dpurdie 678
        my $cfgdir = $entry->{'CFGDIR'};
679
        next unless ( $cfgdir );
680
        my $base_dir = $entry->{'ROOT'} . $cfgdir . '/DIRECTIVES';
681
        next unless ( -d $base_dir );
682
        foreach my $file  ( glob ("$base_dir/*.pm") )
683
        {
684
            push( @ScmDepends, "$file" );
685
            require $file;
686
        }
687
    }
688
 
689
    #
271 dpurdie 690
    #   Include local toolset extensions
691
    #   These are rooted in the build directory and are not to be confused with
692
    #   extensions that may be packaged
693
    #
694
    my $local_base_dir = "$ScmRoot/gbe/DIRECTIVES";
695
    if ( -d $local_base_dir )
696
    {
697
        foreach my $file  ( glob ("$local_base_dir/*.pm") )
698
        {
699
            push( @ScmDepends, "$file" );
700
            require $file;
701
        }
702
    }
703
 
704
    #
227 dpurdie 705
    #   All makefile.pl's will include a makefile.pl found in the build
706
    #   root directory ( The same directory as build.pl ). This makefile.pl
707
    #   is a little bit different - It should not "require "$ARGV[1]", nor
708
    #   should it use a Platform directive.
709
    #
710
    #   Note: This makefile is processed AFTER the toolset has been initialised
711
    #         so that toolset extensions are available to the directives
712
    #
713
    $file = "$ScmRoot/makefile.pl";
714
    if ( -e $file ) {
715
        $ScmProcessingRootMake = 1;
716
        require "$file";
717
        $ScmProcessingRootMake = 0;
718
        push( @ScmDepends, "$file" );
719
    }
720
 
721
    #
289 dpurdie 722
    #   Sanity Test for platforms that do not support both debug and production
723
    #   builds at the same time. This information is flagged by the toolset
724
    #   which we have now loaded.
725
    #
726
    if ( $ScmToolsetSingleType  )
727
    {
728
        unless ( $ScmBuildType )
729
        {
730
            Error ("The toolset used by the \"$ScmPlatform\" platform does not support",
731
                   "both Production and Debug Builds" );
732
        }
733
    }
734
 
735
    #
227 dpurdie 736
    #   Restore global status ...
737
    #
738
    $ScmGlobal = $global;
739
}
740
 
741
 
742
sub PlatformRequire
743
{
744
    my( $script, @arguments ) = @_;
745
    my( $file );
746
 
747
    Debug( "PlatformRequire($script, @arguments)" );
748
 
749
    push( @ScmPlatformArgs, @arguments );       # additional arguments
750
 
751
    $file = Require( "PLATFORM", $script,
752
                "PlatformRequire ", @ScmPlatformDirs );
753
 
754
    push( @ScmDepends, "$file" );
755
}
756
 
757
 
758
sub PlatformInclude
759
{
760
    my( $script, @arguments ) = @_;
761
    my( $file );
762
 
763
    Debug( "PlatformInclude( @_ )" );
764
 
765
    $file = Require2( \@arguments, "PLATFORM", $script,
766
                "PlatformInclude ", @ScmPlatformDirs );
767
 
768
    push( @ScmDepends, "$file" );
769
}
770
 
771
 
772
sub PlatformDefine
773
{
774
    Debug2( "PlatformDefine(@_)" );
775
 
776
    Define( @_ );
777
}
778
 
779
 
780
sub PlatformDefines
781
{
782
    my( $script ) = @_;
783
    my( $line );
784
 
785
    Debug2( "PlatformDefine(@_)" );
786
 
787
    $script = Exists( "PLATFORM", $script,      # locate image
788
                "PlatformDefines", @ScmPlatformDirs );
789
 
271 dpurdie 790
    push( @DEFINES, "# PlatformDefines from: $script" );
285 dpurdie 791
    open( my $fh, '<', $script ) || Error( "Opening $script" );
792
    while (<$fh>) {
227 dpurdie 793
        $_ =~ s/\s*(\n|$)//;                    # kill trailing whitespace & nl
794
        push( @DEFINES, $_ );
795
    }
796
    push( @ScmDepends, "$script" );             # makefile dependencies
285 dpurdie 797
    close( $fh );
227 dpurdie 798
}
799
 
800
 
801
sub PlatformEntry
802
{
803
    my( $prelim, $postlim, $prefix, $postfix, @elements ) = @_;
804
 
285 dpurdie 805
    my $str = "$prelim";
806
    foreach my $element ( @elements )
227 dpurdie 807
    {
808
        $str .= "${prefix}${element}${postfix}";
809
    }
810
    $str .= "$postlim";
811
    PlatformDefine( $str );
812
}
813
 
814
 
815
#
816
#   Add arguments to the ScmPlatformArgs, but remove "Global" arguments
817
#       --OnlyDebug
818
#       --OnlyProduction
343 dpurdie 819
#       --NoToolSet
227 dpurdie 820
#
289 dpurdie 821
#   Capture OnlyDebug and OnlyProd information
822
#   Will be sanitized by caller.
823
#
227 dpurdie 824
sub AddPlatformArg
825
{
826
    Debug("AddPlatformArg: @_" );
289 dpurdie 827
    foreach  ( @_ )
828
    {
829
        if ( m~^--OnlyDebug~ ) {
830
            $ScmBuildType = 'D';
831
        } elsif ( m~--OnlyProd~ ) {
832
            $ScmBuildType = 'P';
343 dpurdie 833
        } elsif ( m~--NoToolSet~ ) {
834
            $ScmNoToolsTest = 1;
289 dpurdie 835
        } else {
343 dpurdie 836
            UniquePush( \@::ScmPlatformArgs, $_ );
289 dpurdie 837
        }
838
    }
227 dpurdie 839
 
840
    Debug("AddPlatformArg: Result: @::ScmPlatformArgs" );
841
    1;
842
}
843
 
844
###############################################################################
845
# Toolset support
846
#
847
#   Toolset( 'platform [, ... ]', name, [arg, ... ] )
848
#       Specify the toolset for a platform
849
#
850
#   ToolDefine( )
851
#   ToolDefines( )
852
#       Specifies toolset defines for insertion into the target makefile.
853
#
854
#   ToolsetDir
855
#       Define toolset created directory(s) for removal during
856
#       'clean' operations.
857
#
858
#   ToolsetGenerate
859
#       Define toolset created file(s) for removal during
860
#       'clean' operations.
861
#
862
#   ToolsetObj
863
#       Define toolset created object(s) for removal during
864
#       'clean' operations.
865
#
866
#   ToolsetLib
867
#       Define toolset created library(s) for removal during
868
#       'clean' operations.
869
#
870
#   ToolsetProg
871
#       Define toolset created prog(s) for removal during
872
#       'clean' operations.
873
#
874
#   ToolsetRule( )
875
#   ToolsetRules( )
876
#       Specifies toolset rules for insertion into the target makefile.
877
#
878
##############################################################################
879
 
880
sub Toolset
881
{
882
    my( $platforms, $toolset, @arguments ) = @_;
883
 
884
    Debug2( "Toolset(@_)" );
885
 
886
    return if ( ! ActivePlatform($platforms) );
887
 
888
    $ScmToolset = $toolset;
889
    @ScmToolsetArgs = @arguments;
890
}
891
 
892
 
893
sub ToolsetRequire
894
{
895
    my( $script, @arguments ) = @_;
896
    my( $file );
897
 
898
    Debug2( "ToolsetRequire(@_)" );
899
 
900
    @ScmToolsetArgs = @arguments;
901
    $file = Require( "",
902
                     $script,
903
                     "ToolsetRequire",
904
                     "$::GBE_CONFIG/TOOLSET", @::BUILDTOOLSPATH );
905
    push( @ScmDepends, "$file" );
906
}
907
 
908
 
909
sub ToolsetDefine
910
{
911
    Debug2( "ToolsetDefine(@_)" );
912
 
913
    Define( @_ );
914
}
915
 
916
 
917
sub ToolsetDefines
918
{
919
    Debug2( "ToolsetDefines(@_)" );
920
 
261 dpurdie 921
    Defines( "$::GBE_CONFIG/TOOLSET", @_ );
227 dpurdie 922
}
923
 
924
 
925
sub ToolsetDir
926
{
927
    Debug2( "ToolsetDir(@_)" );
928
 
261 dpurdie 929
    UniquePush ( \@TOOLSETDIRS, @_ );
227 dpurdie 930
}
931
 
932
 
933
sub ToolsetDirTree
934
{
935
    Debug2( "ToolsetDirTree(@_)" );
936
 
261 dpurdie 937
    UniquePush ( \@TOOLSETDIRTREES, @_);
227 dpurdie 938
}
939
 
940
 
941
sub ToolsetGenerate
942
{
943
    Debug2( "ToolsetGenerate(@_)" );
944
 
945
    UniquePush( \@TOOLSETGENERATED, @_ );
946
}
947
 
948
 
949
sub ToolsetObj
950
{
951
    Debug2( "ToolsetObj(@_)" );
952
 
261 dpurdie 953
    foreach my $obj ( @_ )
227 dpurdie 954
    {
261 dpurdie 955
        UniquePush( \@TOOLSETOBJS, "$obj.$::o"  );
227 dpurdie 956
    }
957
}
958
 
959
 
960
sub ToolsetLib
961
{
962
    Debug2( "ToolsetLib(@_)" );
963
 
261 dpurdie 964
    foreach my $lib ( @_ )
227 dpurdie 965
    {
289 dpurdie 966
        UniquePush( \@TOOLSETLIBS, GenLibName( $lib ) );
227 dpurdie 967
    }
968
}
969
 
970
 
971
sub ToolsetProg
972
{
973
    Debug2( "ToolsetProg(@_)" );
974
 
261 dpurdie 975
    foreach my $prog ( @_ )
227 dpurdie 976
    {
289 dpurdie 977
        UniquePush( \@TOOLSETPROGS, GenProgName( $prog ) );
227 dpurdie 978
    }
979
}
980
 
981
 
982
sub ToolsetRule
983
{
984
    Debug2( "ToolsetRule(@_)" );
985
 
986
    push( @TOOLSETRULES, @_ );
987
}
988
 
989
 
990
sub ToolsetRules
991
{
992
    my( $script ) = @_;
993
    my( $line );
994
 
995
    Debug2( "ToolsetRules(@_)" );
996
 
997
    $script = Exists( "$::GBE_CONFIG/TOOLSET", $script, "ToolsetRules" );
271 dpurdie 998
    push( @TOOLSETRULES, "# ToolsetRules from: $script" );
285 dpurdie 999
    open( my $fh, '<', $script ) || Error( "Opening $script" );
1000
    while (<$fh>) {
227 dpurdie 1001
        $_ =~ s/\s*(\n|$)//;                    # kill trailing whitespace & newline
1002
        push( @TOOLSETRULES, $_ );
1003
    }
1004
    push( @ScmDepends, "$script" );             # makefile dependencies
285 dpurdie 1005
    close( $fh );
227 dpurdie 1006
}
1007
 
1008
 
1009
###############################################################################
1010
# User interface:
1011
#
1012
#   AddFlags( 'platform [, ... ]', 'flags' [, 'flag' ... ] )
1013
#       This subroutine takes the C and C++ compiler flags
1014
#       specified adding them to a global list for later
1015
#       inclusion in the built makefile.
1016
#
1017
#   AddCFlags( 'platform [, ... ]', 'flags' [, 'flag' ... ] )
1018
#       This subroutine takes the C compiler flags
1019
#       specified adding them to a global list for later
1020
#       inclusion in the built makefile.
1021
#
1022
#   AddCXXFlags( 'platform [, ... ]', 'flags' [, 'flag' ... ] )
1023
#       This subroutine takes the C++ compiler flags
1024
#       specified adding them to a global list for later
1025
#       inclusion in the built makefile.
1026
#
1027
#   AddLintFlags( 'platform [, ... ]', 'flags' [, ... ] )
1028
#       This subroutine takes the Lint flags specified
1029
#       adding them to a global list for later inclusion
1030
#       in the built makefile.
1031
#
1032
#   AddASFlags( 'platform [, ... ]', 'flags' [, ... ] )
1033
#       This subroutine takes the Assemler flags specified
1034
#       adding them to a global list for later inclusion
1035
#       in the built makefile.
1036
#
1037
#   AddLDFlags( 'platform [, ... ]', 'flags' [, ... ] )
1038
#       This subroutine takes the Linker flags specified
1039
#       adding them to a global list for later inclusion
1040
#       in the built makefile.
1041
#
1042
#   AddDir
1043
#       This subroutine takes the directories specified adding
1044
#       them to a global include and source directory list for
1045
#       later inclusion in the built makefile.
1046
#
1047
#   AddIncDir( 'platform [, ... ]', 'dir' [, ... ] )
1048
#       This subroutine takes the include file directories
1049
#       specified adding them to a global list for later
1050
#       inclusion in the built makefile.
1051
#
1052
#   AddSrcDir( 'platform [, ... ]', 'dir' [, ... ] )
1053
#       This subroutine takes the source file directories
1054
#       specified adding them to a global list used to resolve
1055
#       Src() definitions.
1056
#
1057
#   AddLibDir( 'platform [, ... ]', 'dir' [, ... ] )
1058
#       This subroutine takes the library directories
1059
#       specified adding them to a global list for later
1060
#       inclusion in the built makefile.
1061
#
1062
#   AddSourceType( 'ext', '.c|.cc|.asm' )
1063
#       This subroutine takes the extension(s) specified by the
1064
#       programmer and adds them to a global list for later
1065
#       inclusion in the built makefile.  This list contains
1066
#       the extensions to be recognised as 'C', 'C++' or
1067
#       assembler file types.
1068
#
1069
#   AddSourceFile( 'platform [, ... ]', 'file' [, ... ] )
1070
#       This subroutine takes the non-standard source file(s)
1071
#       and adds them add it to either C, C++ or assembler
1072
#       sources and the object list.
1073
#
1074
#   Init( 'platform [, ... ]', 'rule' )
1075
#       Initialisation rule
1076
#
1077
#   Generate( 'platform [, ... ]', 'file' [, ... ] )
1078
#       This subroutine is used to add the list of given
1079
#       source files to the generate sources list, and if
1080
#       the generated source is of type C, C++ or assember
1081
#       also adds it to either C, C++ or assembler sources and
1082
#       the object lists.
1083
#
1084
#       --c             Treat as a C source file.
1085
#       --cpp           Treat as a C++ source file.
1086
#       --asm           Treat as a assembler source file.
1087
#
1088
#   Rule( 'platform [, ... ]', definition )
1089
#       This subroutine is used to add the non-standard make
1090
#       rules required to build the system.  eg. any rules
1091
#       necessary to produce a .cc & .h file from a .x file.
1092
#
1093
#   Src( 'platform [, ... ]', 'file' [, ... ], [ 'arg' [, ...]] )
1094
#       This subroutine is used to add the list of given source
1095
#       files to the sources list, and if the source is of type
1096
#       C, C++ or assember also adds it to either C, C++ or
1097
#       assembler sources and the object lists.  The optional
1098
#       list of arguments is assigned to all source files.
1099
#
1100
#       --c             Treat as a C source file.
1101
#       --cpp           Treat as a C++ source file.
1102
#       --asm           Treat as a assembler source file.
1103
#       --Shared        Shared, produces position-independent
1104
#                       code (on targets where required).
1105
#
1106
#   Lib( 'platform [, ... ]', 'name', 'obj' [, ... ] [, '-arg' [, ... ]] )
1107
#       This subroutine takes a library definition list and adds
1108
#       the  entries to the 3 libraries definition lists. 'name'
1109
#       of the library to be created.  List of the object files
1110
#       'obj' that make up this library.  List of special
1111
#       arguments 'arg' to pass to the librarian.
1112
#
1113
#   MergeLibrary( 'platform [, ... ]', 'name', 'lib' [, ... ] )
1114
#       This subroutine takes a library merge list and adds
1115
#       the  entries to the 2 merge libraries definition lists. 'name'
1116
#       of the library to be created.  List of the libraries to be merged
1117
#
1118
#   LocalScript( 'platform [, ... ]', name, ['1'] )
1119
#   Script( 'platform [, ... ]', name, ['1'] )
1120
#       This subroutine takes a list that defines the name of
1121
#       the script to be placed in the platform 'bin' directory,
1122
#       and an optional second element that defines whether the
1123
#       script should be made executable or not.
1124
#
1125
#   Prog( 'platform [, ... ]', 'name', ['obj', ... ],
1126
#               ['-llib', ... ], ['options'] )
1127
#       This subroutine takes a list that defines which program
1128
#       (binary) is to be made, what libraries and object it is
1129
#       made from, and any special commands required to perform
1130
#       the program creation.
1131
#
1132
#       @PROGS          Updated list of programs to create
1133
#
1134
#   TestProg( 'platform [, ... ]', 'name', ['obj', ... ],
1135
#               ['-llib', ... ], ['options'] )
1136
#       This subroutine takes a list that defines which test program
1137
#       (binary) is to be made, what libraries and object it is
1138
#       made from, and any special commands required to perform
1139
#       the program creation.
1140
#
1141
#       @TESTPROGS      Updated list of programs to create
1142
#
1143
#   InstallHdr( 'platform [, ... ]', 'file' [, ...], ['-arg'] )
1144
#       This subroutine takes the given list of files and adds them
1145
#       to the install header files list.  Files in this list will be
1146
#       installed into the 'local header directory' area for public
1147
#       consumption.  This is generally API files for other modules
1148
#       to use.
1149
#
1150
#       --Strip         Strip directory from source
1151
#       --Full          Install using full path
1152
#       --Subdir=subdir Install within the specified sub-directory
1153
#       --Prefix=subdir   "       "     "      "      "     "
1154
#
1155
#   InstallLib( 'platform [, ... ]', 'file', ['subdir'] )
1156
#       This subroutine takes the given list of files and adds them
1157
#       to the install libraries files list.  Files in this list will
1158
#       be installed into the 'local library directory' area for
1159
#       public consumption.
1160
#
1161
#   InstallProg( 'platform [, ... ]', 'file', ['subdir'] ) )
1162
#       This subroutine takes a list that defines the executable file
1163
#       that is to be installed.  The file in this list will be
1164
#       installed into the 'local executable directory' specified for
1165
#       public consumption.
1166
#
1167
###############################################################################
1168
 
1169
 
1170
sub Include                                     # User include
1171
{
1172
    my( $path, $name ) = @_;
1173
    my( $file );
1174
 
1175
    $file = Require( $path, $name, "Include" );
1176
    push( @ScmDepends, "$file" );
1177
}
1178
 
1179
sub ForceCCompile
1180
{
1181
    CompileOptions( $_[0], 'compile_as_c' );            # Backward compatability
1182
}
1183
 
1184
#-------------------------------------------------------------------------------
1185
#   Create a data structure to define the global compiler options
1186
#    The hash is keyed by compiler option
1187
#    The value contains another hash.
1188
#       The key is a makefile variable to set ( or remove )
1189
#       The value is the value to assign to the makefile variable
1190
#       If the value is 'undef' then the variable will be deleted
1191
#
1192
#   Keys of the form key=value are also supported
1193
#
1194
#   If the value is a CODE reference, then routine will be called with the key
1195
#   and value as arguments. The return value will be utilised.
1196
#
1197
our %ScmCompilerOptions =
1198
    (
1199
        'strict_ansi'           => { 'USE_STRICT_ANSI'    => '1' },
1200
        'no_strict_ansi'        => { 'USE_STRICT_ANSI'    => '' },      # Default
1201
 
1202
        'profile'               => { 'USE_PROFILE'        => '1' },
1203
        'no_profile'            => { 'USE_PROFILE'        => '' },       # Default
1204
 
1205
 
1206
        'prod_no_optimise'      => { 'PROD_USE_OPTIMISE'   => '' },
1207
        'prod_no_debuginfo'     => { 'PROD_USE_DEBUGINFO'  => '' },     # Default
1208
        'prod_optimise'         => { 'PROD_USE_OPTIMISE'   => '1' },    # Default
1209
        'prod_debuginfo'        => { 'PROD_USE_DEBUGINFO'  => '1' },
1210
 
1211
        'debug_no_optimise'     => { 'DEBUG_USE_OPTIMISE'  => '' },     # Default
1212
        'debug_no_debuginfo'    => { 'DEBUG_USE_DEBUGINFO' => '' },
1213
        'debug_optimise'        => { 'DEBUG_USE_OPTIMISE'  => '1' },
1214
        'debug_debuginfo'       => { 'DEBUG_USE_DEBUGINFO' => '1' },    # Default
1215
 
1216
        'compile_as_cpp'        => { 'FORCE_CC_COMPILE'    => '1',
1217
                                     'FORCE_C_COMPILE'     => undef },
1218
        'compile_as_c'          => { 'FORCE_C_COMPILE'     => '1',
1219
                                     'FORCE_CC_COMPILE'    => undef },
267 dpurdie 1220
 
1221
        'no_define_source_file' => { 'DISABLE__SOURCE__' => '1' },
1222
        'define_source_file'    => { 'DISABLE__SOURCE__' => undef },    # Default
1223
 
227 dpurdie 1224
    );
1225
 
1226
#
1227
#   The toolset can extend the options by setting the following hash
1228
#
1229
our %ScmToolsetCompilerOptions = ();
1230
 
1231
#
1232
#   Define default compiler options
1233
#   These are makefile variables that will be assigned
1234
#
1235
our %ScmCompilerOpts =
1236
    (
1237
        'USE_STRICT_ANSI'       => '',
1238
        'USE_PROFILE'           => '',
1239
        'PROD_USE_DEBUGINFO'    => '',
1240
        'PROD_USE_OPTIMISE'     => '1',
1241
        'DEBUG_USE_OPTIMISE'    => '',
1242
        'DEBUG_USE_DEBUGINFO'   => '1',
1243
    );
1244
 
1245
 
1246
sub CompileOptions
1247
{
1248
    my( $platforms, @elements ) = @_;
1249
    return if ( ! ActivePlatform($platforms) );
1250
 
1251
    for (@elements)
1252
    {
1253
        my $oref;
1254
 
1255
        #
1256
        #   The toolset option may be a text string or a definition
1257
        #       Name        - A text string
1258
        #       Name=Value  - A value
1259
        #
1260
        my $value;
1261
        my $key = $_;
1262
        if ( $key =~ m~(.*=)(.*)~ )
1263
        {
1264
            $key = $1;
1265
            $value = $2 || '';
1266
        }
247 dpurdie 1267
        $key = lc( $key );
227 dpurdie 1268
 
1269
        #
1270
        #   Examine the global flags
1271
        #   Then the toolset extensions
1272
        #   Then just drop it
1273
        #
1274
        unless ( $oref = ($ScmCompilerOptions{$key} || $ScmToolsetCompilerOptions{$key}) )
1275
        {
1276
            Warning ("Compile Option ignored: $_");
1277
            next;
1278
        }
1279
 
1280
        #
1281
        #   Parse the definition and adjust makefile variables as required
1282
        #   Set the value of a make variable or remove the definition
1283
        #
1284
        #   If the user value is a code reference, then call the code
1285
        #   and use the returned value as the value.
1286
        #
1287
        while ( (my($ukey, $uvalue)) = each %{$oref} )
1288
        {
1289
            if ( defined( $uvalue) )
1290
            {
1291
                if ( ref($uvalue) eq "CODE" )
1292
                {
255 dpurdie 1293
                    $uvalue = &$uvalue( $key, $value, $ukey);
227 dpurdie 1294
                    unless ( defined $uvalue )
1295
                    {
1296
                        Warning ("Compile Option ignored: $_");
1297
                        next;
1298
                    }
1299
                }
247 dpurdie 1300
                elsif ( defined $value )
1301
                {
1302
                    $uvalue = $value;
1303
                }
227 dpurdie 1304
 
1305
                $ScmCompilerOpts{$ukey} = $uvalue;
1306
            }
1307
            else
1308
            {
1309
                delete $ScmCompilerOpts{$ukey};
1310
            }
1311
        }
1312
    }
1313
}
1314
 
1315
#-------------------------------------------------------------------------------
1316
# Function        : AddFlags
1317
#                   AddCFlags
1318
#                   AddCXXFlags
1319
#                   AddASFlags
1320
#                   AddLDFlags
1321
#                   AddLintFlags
1322
#
1323
# Description     : Add target specfic flags to the C compiler
1324
#                   This SHOULD only be used to add Defines to the compiler
1325
#                   but it can be absued.
1326
#
1327
# Inputs          : $platform       - Platforms for which the directive is active
1328
#                   ...             - list of flags to add
1329
#
1330
#                   Embedded options include:
1331
#                       --Debug     - Following options are added to the debug build
1332
#                       --Prod      - Following options are added to the production build
1333
#
1334
# Returns         : Nothing
1335
#
1336
 
1337
sub AddFlags
1338
{
1339
    my( $platforms, @elements ) = @_;
1340
 
1341
    AddCFlags( $platforms, @elements );
1342
    AddCXXFlags( $platforms, @elements );
1343
}
1344
 
1345
sub AddCFlags
1346
{
1347
    my( $platforms, @elements ) = @_;
1348
 
1349
    Debug2( "AddCFlags($platforms, @elements)" );
1350
    return if ( ! ActivePlatform($platforms) );
1351
 
1352
    WarnIfNastyFlag( @elements );
1353
    __AddFlags( "CFLAGS", \@elements,
1354
                \@CFLAGS, \@CLINTFLAGS,
1355
                \@CFLAGS_DEBUG, \@CLINTFLAGS_DEBUG,
1356
                \@CFLAGS_PROD,  \@CLINTFLAGS_PROD );
1357
}
1358
 
1359
sub AddCXXFlags
1360
{
1361
    my( $platforms, @elements ) = @_;
1362
 
1363
    Debug2( "AddCXXFlags($platforms, @elements)" );
1364
    return if ( ! ActivePlatform($platforms) );
1365
 
1366
    WarnIfNastyFlag( @elements );
1367
    __AddFlags( "CXXFLAGS", \@elements,
1368
               \@CXXFLAGS, \@CXXLINTFLAGS,
1369
               \@CXXFLAGS_DEBUG, \@CXXLINTFLAGS_DEBUG,
1370
               \@CXXFLAGS_PROD,  \@CXXLINTFLAGS_PROD );
1371
}
1372
 
1373
sub AddASFlags
1374
{
1375
    my( $platforms, @elements ) = @_;
1376
 
1377
    Debug2( "AddASFlags($platforms, @elements)" );
1378
 
1379
    return if ( ! ActivePlatform($platforms) );
1380
 
267 dpurdie 1381
    __AddFlags( "ASFLAGS", \@elements,
1382
                \@ASFLAGS, undef,
1383
                \@ASFLAGS_DEBUG, undef,
1384
                \@ASFLAGS_PROD, undef );
227 dpurdie 1385
}
1386
 
1387
sub AddLDFlags
1388
{
1389
    my( $platforms, @elements ) = @_;
1390
 
1391
    Debug2( "AddLDFlags($platforms, @elements)" );
1392
 
1393
    return if ( ! ActivePlatform($platforms) );
1394
 
1395
    foreach  ( @elements )
1396
    {
267 dpurdie 1397
        next if ( m~^--(Debug|Prod)~ );
227 dpurdie 1398
        Warning("Use of linker flag discouraged (will be used): $_");
1399
    }
267 dpurdie 1400
    __AddFlags( "LDFLAGS", \@elements,
1401
                \@LDFLAGS, undef,
1402
                \@LDFLAGS_DEBUG, undef,
1403
                \@LDFLAGS_PROD, undef );
227 dpurdie 1404
 
1405
}
1406
 
1407
sub AddLintFlags
1408
{
1409
    my( $platforms, @elements ) = @_;
1410
 
1411
    return if ( ! ActivePlatform($platforms) );
1412
 
1413
    Debug2( "AddLintFlags($platforms, @elements)" );
1414
 
1415
    __AddFlags( "LINTFLAG", \@elements,
1416
                \@CLINTFLAGS, \@CXXLINTFLAGS,
1417
                \@CLINTFLAGS_DEBUG, \@CXXLINTFLAGS_DEBUG,
1418
                \@CLINTFLAGS_PROD, \@CXXLINTFLAGS_PROD  );
1419
}
1420
 
1421
 
1422
#-------------------------------------------------------------------------------
1423
# Function        : __AddFlags
1424
#
1425
# Description     : Generic flag adding to lists routine
1426
#                   Internal use only
1427
#
1428
#                   Supports --Debug and --Prod options
1429
#                   if the appropriate list is present.
1430
#
1431
# Inputs          : Lots
1432
#                   References to compiler and lint flags for
1433
#                   common, debug and product builds.
1434
#
1435
#                   Not all the lists are needed.
1436
#
1437
# Returns         : Nothing
1438
#
1439
sub __AddFlags
1440
{
1441
    my ($textname, $eref,
1442
                   $f_all,      $flint_all,
1443
                   $f_debug,    $flint_debug,
1444
                   $f_prod,     $flint_prod ) = @_;
1445
 
1446
    #
1447
    #   Start added flags to the ALL lists
1448
    #
1449
    my $list = $f_all;
1450
    my $lintlist = $flint_all;
1451
    my $nowarn = 0;
1452
 
1453
    #
1454
    #   Process flags up front
1455
    #
1456
    $nowarn = 1 if ( grep (/^--NoWarn$/, @$eref) );
1457
 
1458
    #
1459
    #   Process all the user arguments
1460
    #
1461
    ADD:
1462
    foreach my $element ( @$eref )
1463
    {
1464
        #
1465
        #   Skip flags
1466
        #
1467
        if ( $element eq '--NoWarn' )
1468
        {
1469
            next;
1470
        }
1471
 
1472
        #
1473
        #   Detect --Debug and --Prod options and swap
1474
        #   lists accordingly.
1475
        #
1476
        if ( $element eq '--Debug' )
1477
        {
1478
            Error ("--Debug not supported for $textname") unless ( $f_debug );
1479
            $list = $f_debug;
1480
            $lintlist = $flint_debug;
1481
            next;
1482
        }
1483
 
1484
        if ( $element eq '--Prod' )
1485
        {
1486
            Error ("--Prod not supported for $textname") unless ( $f_prod );
1487
            $list = $f_prod;
1488
            $lintlist = $flint_prod;
1489
            next;
1490
        }
1491
 
1492
        #
1493
        #   Scan all the lists for a possible duplicates
1494
        #
1495
        foreach my $temp ( @$f_all, @$f_debug, @$f_prod ) {
1496
            if ($temp eq $element) {
1497
                Warning( "Duplicate $textname ignored '$element'") unless $nowarn;
1498
                next ADD;
1499
            }
1500
        }
1501
 
1502
        #
1503
        #   Add the flag to the compiler and lint lists
1504
        #
1505
        push( @$list, $element ) if $list;
1506
        push( @$lintlist, $element ) if $lintlist;
1507
    }
1508
}
1509
 
1510
sub WarnIfNastyFlag
1511
{
1512
    foreach  ( @_ )
1513
    {
1514
        Warning("Use of compiler flags discouraged (will be used): $_")
1515
            unless ( m/^-[DU]/ || m/^--Debug/ || m/^--Prod/ || /^--NoWarn/ );
1516
    }
1517
}
1518
 
1519
 
1520
sub AddDir
1521
{
1522
    AddIncDir( @_);
1523
    AddSrcDir( @_ );
1524
}
1525
 
1526
 
1527
sub AddIncDir
1528
{
1529
    _AddDir( 'AddIncDir', 'INCDIR', \@INCDIRS, \@S_INCDIRS, \@G_INCDIRS, \@L_INCDIRS, @_ );
1530
}                                                           
1531
 
1532
sub AddSrcDir                                               
1533
{                                                           
1534
    _AddDir( 'AddSrcDir', 'SRCDIR', \@SRCDIRS, \@S_SRCDIRS, \@G_SRCDIRS, \@L_SRCDIRS, @_ );
1535
}                                                           
1536
 
1537
sub AddLibDir                                               
1538
{                                                           
1539
    _AddDir( 'AddLibDir', 'LIBDIR', \@LIBDIRS, \@S_LIBDIRS, \@G_LIBDIRS, \@L_LIBDIRS, @_ );
1540
}
1541
 
1542
#-------------------------------------------------------------------------------
1543
# Function        : _AddDir
1544
#
1545
# Description     : Internal routine to add a directory to list of directories
1546
#                   Common code to simplify implementation of other directives
1547
#
1548
# Inputs          : $name           - Name of function
1549
#                   $udir           - User name of dir list
1550
#                   $dirref         - Reference to directory array
1551
#                   $s_dirref       - Reference to system directory array
1552
#                   $g_dirref       - Reference to global directory array
1553
#                   $l_dirref       - Reference to local directory array
1554
#                   @args           - User arguments
1555
#                                       - platforms
1556
#                                       - Directories and --Options
1557
#
1558
sub _AddDir
1559
{
1560
    my( $name, $udir, $dirref, $s_dirref, $g_dirref, $l_dirref, $platforms, @elements ) = @_;
1561
 
1562
    Debug ( "$name($platforms, @elements)" );
1563
    Error ( "$name: Insufficient arguments") unless ( @elements );
1564
    return if ( ! ActivePlatform($platforms) );
1565
 
1566
    #
1567
    #   Cleanup user parameters
1568
    #
1569
    foreach ( @elements )
1570
    {
1571
        s/^\s+//;                               # Remove leading space
1572
        s/\s+$//;                               # Remove trailing spaces
1573
        s~/$~~;                                 # Remove trailing /
1574
        s~//~/~g;                               # Remove multiple /
1575
    }
1576
 
1577
#.. Collect arguments
1578
    my $tlist_ref = $ScmGlobal ? $g_dirref : $l_dirref; # "current" scope ....
1579
    my $nowarn = 0;
1580
    my $nodepend = 0;
1581
    my @dirs;
1582
 
1583
    foreach ( @elements )
1584
    {
1585
        if ( ! /^--/ ) {                        # Collect directories
1586
            push @dirs, $_;
1587
 
1588
        } elsif (/^--Local$/) {                 # "local" scope ....
1589
            $tlist_ref = $l_dirref;
1590
 
1591
        } elsif (/^--Global$/) {                # "global" scope ...
1592
            $tlist_ref = $g_dirref;
1593
 
1594
        } elsif (/^--System$/) {                # "system" scope ...
1595
            $tlist_ref = $s_dirref;
1596
 
1597
        } elsif (/^--NoDepend$/) {              # Split from dependency list
1598
            if ( $udir eq 'INCDIR' ) {          # AddIncDir only
1599
                $nodepend = 1;
1600
            }
1601
 
1602
        } elsif (/^--NoWarn$/) {                # Disable warnings
1603
            $nowarn = 1;
1604
 
1605
        } elsif (/^--(.*)/) {
1606
            Message( "$name: unknown option $_ -- ignored\n" );
1607
 
1608
        }
1609
    }
1610
 
1611
    Error ( "$name: No directory specified: ($platforms, @elements)" )
1612
        unless ( @dirs );
1613
 
1614
 
1615
#.. Push source path(s)
1616
    foreach ( @dirs )
1617
    {
1618
        #
1619
        #   Add to complete list of directories
1620
        #   Warn on duplicates
1621
        #
1622
        unless ( UniquePush( $dirref, $_) )
1623
        {
1624
            Warning( "Duplicate $udir ignored '$_'" )
1625
                unless ( $nowarn );
1626
            next;
1627
        }
1628
 
1629
        #
1630
        #   Check that the directory actually exists
1631
        #   If the path contains a $(XXXXX) then it can't be checked
1632
        #
1633
        if ( index( $_, '$' ) == -1 )
1634
        {
1635
            Warning( "$name. Directory not found: $_",
1636
                     "Current directory         : $::Cwd",
1637
                     "Cannot resolved Directory : " . AbsPath($_),
1638
                       )
1639
                unless ( $nowarn || -d $_ );
1640
        }
1641
 
1642
        #
1643
        #   Add to suitable list
1644
        #
1645
        push @{$tlist_ref}, $_;
1646
 
1647
        #
1648
        #   Add to the no dependancy list (ie generated depend file)
1649
        #   Only used by AddIncDir, accepted by AddSrcDir
1650
        #
1651
        push( @NODEPDIRS, $_ )
1652
            if ($nodepend);
1653
    }
1654
}
1655
 
1656
 
1657
sub AddProg
1658
{
1659
    my( $platforms, @progs ) = @_;
1660
 
1661
    Debug2( "AddProg($platforms, @progs)" );
1662
 
1663
    return if ( ! ActivePlatform($platforms) );
1664
 
285 dpurdie 1665
    foreach my $prog (@progs)
227 dpurdie 1666
    {
289 dpurdie 1667
        my $pProg = $PROGS->Get($prog);
227 dpurdie 1668
        Warning( "Duplicate prog ignored '$prog'" )
289 dpurdie 1669
            if ( $pProg );
1670
        $pProg = $PROGS->NewAdd($prog)
227 dpurdie 1671
    }
1672
}
1673
 
1674
 
1675
sub AddSourceType
1676
{
1677
    my( $ext, $type ) = @_;
1678
 
1679
    Debug2( "AddSourceType(@_)" );
1680
 
1681
    #
1682
    #   Default Source Type (C)
1683
    #
1684
    $type = ".c" unless ( $type );
1685
 
1686
    Error ("Source type '$ext' not allowed")
1687
        if ( $ext !~ /^\.\w+$/ );
1688
 
1689
    $type = lc($type)
1690
        if ( $::ScmHost ne "Unix" );
1691
    $ScmSourceTypes{ $ext } = $type;
1692
}
1693
 
1694
 
1695
sub AddSourceFile
1696
{
1697
    my( $platforms, @elements ) = @_;
1698
 
1699
    Debug2( "AddSourceFile($platforms, @elements)" );
1700
    return if ( ! ActivePlatform($platforms) );
1701
 
285 dpurdie 1702
    foreach my $path ( @elements )
227 dpurdie 1703
    {
1704
        __AddSourceFile( 1, $path );
1705
    }
1706
}
1707
 
1708
 
1709
#-------------------------------------------------------------------------------
1710
# Function        : __AddSourceFile
1711
#
1712
# Description     : Internal function
1713
#                   Add a source file to internal lists
1714
#
1715
#                   Assumes that the current platform is ACTIVE
1716
#
1717
# Inputs          : push    0: Don't push onto OBJS (non-shared objfiles)
1718
#                   path    Filename.extension
1719
#                   obj     object file name (optional)
1720
#                   type    Type of file. "" -> auto detect
1721
#
1722
# Returns         : True        - File is a 'known' source file
1723
#                   False       - File is not a 'known' source file
1724
#
1725
sub __AddSourceFile
1726
{
1727
    my( $push, $path, $obj, $type ) = @_;
271 dpurdie 1728
    my( $filename, $ext, $srcfile, $is_obj, $ext_type, $result );
227 dpurdie 1729
 
271 dpurdie 1730
    $filename = StripDir($path);                # file name
227 dpurdie 1731
 
1732
    $ext  = StripFile($path);                   # extension
1733
    $ext = lc($ext)
1734
        if ( $::ScmHost ne "Unix" );
1735
 
271 dpurdie 1736
    if (! ($srcfile = $SRCS{$filename})) {
227 dpurdie 1737
        $srcfile = $path;                       # generated
1738
    }
1739
 
271 dpurdie 1740
    $obj  = StripExt( $filename )               # Base name of object file
227 dpurdie 1741
        if ( ! defined($obj) || $obj eq "" );
1742
 
1743
    $type = ""                                  # optional type
1744
        if ( ! defined( $type ) );
1745
 
1746
    #
1747
    #   Push file onto a suitable source file list
1748
    #
1749
    $result = 0;
1750
    $ext_type = "";                             # map extension
1751
    $ext_type = $ScmSourceTypes{ $ext }
1752
        if ( exists( $ScmSourceTypes{ $ext } ) );
1753
    $result = 1 if ( $ext_type );
1754
 
1755
    if ( $type eq "" && defined $::ScmToolsetProgSource{$ext} )
1756
    {
1757
        Debug( "SourceFile: $path is ToolsetProgSource   -> $srcfile" );
1758
        push( @CSRCS, $srcfile );
1759
        $result = 1;
1760
    }
1761
    elsif ( ($type eq "" && $ext_type eq ".h") || ($type eq ".h") )
1762
    {
1763
        Debug( "SourceFile: $path is .h   -> $srcfile" );
1764
        push( @CHDRS, $srcfile );
1765
    }
1766
    elsif ( ($type eq "" && $ext_type eq ".inc") || ($type eq ".inc") )
1767
    {
1768
        Debug( "SourceFile: $path is .inc -> $srcfile" );
1769
        push( @ASHDRS, $srcfile );
1770
    }
1771
    elsif ( ($type eq "" && $ext_type eq ".c") || ($type eq ".c") )
1772
    {
1773
        Debug( "SourceFile: $path is .c   -> $srcfile=$obj" );
1774
        push( @CSRCS, $srcfile );
1775
        $is_obj = 1;
1776
    }
1777
    elsif ( ($type eq "" && $ext_type eq ".cc") || ($type eq ".cc") )
1778
    {
1779
        Debug( "SourceFile: $path is .cc  -> $srcfile=$obj" );
1780
        push( @CXXSRCS, $srcfile );
1781
        $is_obj = 1;
1782
    }
1783
    elsif ( ($type eq "" && $ext_type eq ".asm") || ($type eq ".asm") )
1784
    {
1785
        Debug( "SourceFile: $path is .asm -> $srcfile=$obj" );
1786
        push( @ASSRCS, $srcfile );
1787
        $is_obj = 1;
1788
    }
1789
    elsif ( $ext_type eq "--Ignore" )
1790
    {   # ignored ...
1791
        #   .x      "rpcgen" source files
1792
        #   .ini    Configuration
1793
        #   .sh     Shell script
1794
    }
1795
    else
1796
    {
1797
        Debug( "SourceFile: $path is unknown file type" );
1798
 
1799
        #
1800
        #   Insert source files with unknown extensions onto lists
1801
        #   of there own type
1802
        #
1803
        if ( $ext )
1804
        {
1805
            (my $varname = uc ( $ext . 'SRCS')) =~ s~\.~~g;
1806
            no strict 'refs';
1807
            push @$varname, $srcfile;
1808
            use strict 'refs';
1809
        }
1810
    }
1811
 
1812
    #
271 dpurdie 1813
    #   See if there is a hook function for this type of source file
1814
    #   Invoke user function to perform additional processing on the file
1815
    #
1816
    if ( %MF_RegisterSrcHooks )
1817
    {
1818
        my @listeners;
1819
        push @listeners, @{$MF_RegisterSrcHooks{$ext}} if ( exists $MF_RegisterSrcHooks{$ext} );
1820
        push @listeners, @{$MF_RegisterSrcHooks{'*'}}  if ( exists $MF_RegisterSrcHooks{'*'} );
1821
        while ( @listeners )
1822
        {
1823
            Debug( "RegisterSrcHook: Invoke SrcHook function" );
1824
            my ($fname, @args) = @{shift @listeners};
1825
            &$fname ( $srcfile ,$filename, $obj, $ext ,@args );
1826
        }
1827
    }
1828
 
1829
    #
227 dpurdie 1830
    #   Object files are saved in
1831
    #       OBJSOURCE   - Generate a recipe to create the object
1832
    #       OBJS        - A list of ALL non-shared object files
1833
    #
1834
    if ( $is_obj && $::o )
1835
    {
1836
        $OBJSOURCE{ "$obj" } = $srcfile;
1837
        push( @OBJS, $obj )
1838
            if ($push);
1839
    }
1840
 
1841
    #
1842
    #   Indicate to the user that the file is a 'known' source file
1843
    #   This implies that the file is required early in the build process
1844
    #   and may need to be generated early.
1845
    #
1846
    return $result;
1847
}
1848
 
1849
#-------------------------------------------------------------------------------
1850
# Function        : SetValue
1851
#
1852
# Description     : Defines a variable that can be used within the makefile.pl
1853
#                   Use sparingly
1854
#                   An attempt to formalise a mechanism that is used anyway, but
1855
#                   with correct platform detection
1856
#
1857
# Inputs          : $platform       - Platform selector
1858
#                   $name           - Name to set
1859
#                   $value          - Value to set
1860
#                   options         - Options
1861
#                                       --NoWarn
1862
#                                       --Project=xxxx[,xxxx]+
1863
#                                       --
1864
#
1865
sub SetValue
1866
{
1867
    my( $platforms, @elements ) = @_;
1868
    my $name;
1869
    my $value;
1870
    my $nowarn;
1871
    my $nomoreswicthes = 0;
1872
 
1873
    Debug2( "SetValue($platforms, @elements)" );
1874
 
1875
    return if ( ! ActivePlatform($platforms) );
1876
 
1877
    #
1878
    #   Process elements extracting values and options
1879
    #
1880
    foreach ( @elements )
1881
    {
1882
        if ( m/^--$/ ) {
1883
            $nomoreswicthes = ! $nomoreswicthes;
1884
            next;
1885
        }
1886
 
1887
        if ( m/^--/ && ! $nomoreswicthes )
1888
        {
1889
 
1890
            if ( m/^--NoWarn/ ) {
1891
                $nowarn = 1;
1892
 
1893
            } elsif ( m/^--Project=(.*)/ ) {
1894
                return unless ( ActiveProject( $1) );
1895
 
1896
            } else {
1897
                Error ("SetValue: Unknown option: $_");
1898
 
1899
            }
1900
 
1901
        } elsif ( ! defined $name ) {
1902
            $name = $_;
1903
 
1904
        } elsif ( ! defined $value ) {
1905
            $value = $_;
1906
 
1907
        } else {
1908
            Error ("SetValue: $name. Too many parameters" );
1909
 
1910
        }
1911
    }
1912
 
1913
    #
1914
    #   Warn if the named variable already exists
1915
    #   It may be a JATS internal or it may be a user.
1916
    #
1917
    unless ( $nowarn )
1918
    {
1919
        no strict 'refs';
1920
        Warning("SetValue: $name. Redefined") if defined ( $$name );
1921
        use strict 'refs';
1922
    }
1923
 
1924
    #
1925
    #   Set the value
1926
    #
1927
    no strict 'refs';
1928
    $$name = $value;
1929
    use strict 'refs';
1930
}
1931
 
1932
#-------------------------------------------------------------------------------
1933
# Function        : SetList
1934
#
1935
# Description     : Defines a list variable that can be used within the makefile.pl
1936
#                   Use sparingly
1937
#                   An attempt to formalise a mechanism that is used anyway, but
1938
#                   with correct platform detection
1939
#
1940
# Inputs          : $platform       - Platform selector
1941
#                   $name           - Name to set
1942
#                   $value,...      - Values to set
1943
#                   options         - Options
1944
#                                       --NoWarn
1945
#                                       --Project=xxxx[,xxxx]+
1946
#                                       --Unique
1947
#                                       --Clear
1948
#                                       --Append
1949
#                                       --
1950
#
1951
my %SetList_names;
1952
sub SetList
1953
{
1954
    my( $platforms, @elements ) = @_;
1955
    my $name;
1956
    my @value;
1957
    my $nowarn;
1958
    my $unique;
1959
    my $clear;
1960
    my $nomoreswicthes = 0;
1961
 
1962
    Debug2( "SetList($platforms, @elements)" );
1963
 
1964
    return if ( ! ActivePlatform($platforms) );
1965
 
1966
    #
1967
    #   Process elements extracting values and options
1968
    #
1969
    foreach ( @elements )
1970
    {
1971
        if ( m/^--$/ ) {
1972
            $nomoreswicthes = ! $nomoreswicthes;
1973
            next;
1974
        }
1975
 
1976
        if ( m/^--/ && ! $nomoreswicthes )
1977
        {
1978
            if ( m/^--NoWarn/ ) {
1979
                $nowarn = 1;
1980
 
1981
            } elsif ( m/^--Project=(.*)/ ) {
1982
                return unless ( ActiveProject( $1) );
1983
 
1984
            } elsif ( m/^--Unique/ ) {
1985
                $unique = 1;
1986
 
1987
            } elsif ( m/^--Clear/ ) {
1988
                $clear = 1;
1989
 
1990
            } elsif ( m/^--Append/ ) {
1991
                $clear = 0;
1992
 
1993
            } else {
1994
                Error ("SetList: Unknown option: $_");
1995
            }
1996
        } elsif ( ! defined $name ) {
1997
            $name = $_;
1998
 
1999
        } else {
2000
            push @value, $_;
2001
 
2002
        }
2003
    }
2004
 
2005
    Error ("SetList: No name specified") unless ( $name );
2006
 
2007
    #
2008
    #   Warn if the named variable already exists
2009
    #   It may be a JATS internal or it may be a user.
2010
    #
2011
    #   Only do this iff the name is not known to this function
2012
    #   Keep a list a names that have been set.
2013
    #
2014
    if ( ! $SetList_names{$name} && ! $nowarn )
2015
    {
2016
        no strict 'refs';
2017
        Warning("SetList: $name. Defined outside the ScanList/SetList directive","May clash with Jats internals") if defined ( @$name );
2018
        use strict 'refs';
2019
    }
2020
    $SetList_names{$name} = 1;
2021
 
2022
    #
2023
    #   Clear list
2024
    #
2025
    if ( $clear )
2026
    {
2027
        no strict 'refs';
2028
        @$name = ();
2029
        use strict 'refs';
2030
    }
2031
 
2032
    #
2033
    #   Set the value
2034
    #
2035
    no strict 'refs';
2036
    if ( $unique ) {
2037
        UniquePush( \@$name, @value);
2038
    } else {
2039
        push @$name, @value;
2040
    }
2041
    use strict 'refs';
2042
}
2043
 
2044
#-------------------------------------------------------------------------------
2045
# Function        : ScanList
2046
#
2047
# Description     : Create a list by scanning for files in a directory
2048
#                   The files may be in a local directory or within a package
2049
#                   Care must be taken when using a package as the results
2050
#                   may differ bewteen BuildPkgArchive and LinkPkgArchive
2051
#
2052
#                   Interworks with SetList
2053
#
2054
# Inputs          : $platform       - Platform selector
2055
#                   $name           - Name to set
2056
#                   $value,...      - Values to set
2057
#                   options         - Options
2058
#                                       --NoWarn
2059
#                                       --Project=xxxx[,xxxx]+
2060
#                                       --Unique
2061
#                                       --Clear
2062
#                                       --Append
2063
#
2064
#                                       --Package=xxxx[,ext]
2065
#                                       --Dir=xxx
2066
#
2067
#                                       --Subdir=yyy
2068
#                                       --DirListOnly
2069
#                                       --FileListOnly
335 dpurdie 2070
#                                       --Recurse (default)
227 dpurdie 2071
#                                       --NoRecurse
335 dpurdie 2072
#                                       --FullPath (default)
2073
#                                       --NoFullPath
227 dpurdie 2074
#
2075
#                                       --FilterIn=xxx
2076
#                                       --FilterInRe=xxx
2077
#                                       --FilterOut=xxx
2078
#                                       --FilterOutRe=xxx
2079
#
2080
# Returns         :
2081
#
2082
sub ScanList
2083
{
2084
    my( $platforms, @elements ) = @_;
2085
    my $name;
2086
    my $package;
2087
    my $dir;
2088
    my $subdir;
2089
    my @set_args;
2090
    my $search = JatsLocateFiles->new('Recurse','FullPath' );
2091
 
2092
    Debug2( "ScanList($platforms, @elements)" );
2093
 
2094
    return if ( ! ActivePlatform($platforms) );
2095
 
2096
    #
2097
    #   Process elements extracting values and options
2098
    #
2099
    foreach ( @elements )
2100
    {
2101
        if ( m/^--Unique|--Clear|--Append|--NoWarn/ ) {
2102
            push @set_args, $_;
2103
 
2104
        } elsif ( m/^--Project=(.*)/ ) {
2105
            return unless ( ActiveProject( $1) );
2106
 
2107
        } elsif ( m/^--Package=(.*)/ ) {
2108
            $package = $1;
2109
 
2110
        } elsif ( m/^--Dir=(.*)/ ) {
2111
            $dir = $1;
2112
 
2113
        } elsif ( m/^--Subdir=(.*)/ ) {
2114
            $subdir = $1;
2115
 
2116
        } elsif ( $search->option( $_ ) ) {
2117
            Verbose ("Search Option: $_" );
2118
 
2119
        } elsif ( m/^--/ ) {
2120
            Error ("ScanList: Unknown option: $_");
2121
 
2122
        } elsif ( ! defined $name ) {
2123
            $name = $_;
2124
 
2125
        } else {
2126
                Error ("ScanList $name: Unknown option: $_");
2127
 
2128
        }
2129
    }
2130
 
2131
    Error ("ScanList: No variable name specified") unless ( $name );
2132
    Error ("ScanList: Must Specify --Dir or --Package") unless ( $dir || $package );
2133
    Error ("ScanList: --Dir and --Package are mutually exclusive") if ( $dir && $package );
2134
 
2135
    #
2136
    #   Locate the base of the scan
2137
    #   This may be either a package name or a local directory
2138
    #
2139
    #   Its no use allowing the user to use OBJ/LIB/BIN directories as the
2140
    #   directories MUST exist at build time. Don't really want the user doing
2141
    #   that level of poking out of a package
2142
    #
2143
    if ( $package )
2144
    {
2145
        $dir = GetPackageBase( "ScanList", $package );
2146
        Error ("ScanList: Package not found: $package") unless ( $dir );
2147
    }
2148
    else
2149
    {
2150
        Error ("ScanList: Root directory not found: $dir") unless ( -d $dir );
2151
    }
2152
    if ( $subdir )
2153
    {
2154
        $dir .= "/" . $subdir;
2155
        Error ("ScanList: Sub directory not found: $subdir") unless ( -d $dir );
2156
    }
2157
 
2158
    #
2159
    #   Use SetList to do the rest of the work
2160
    #
2161
    SetList( $platforms, $name, @set_args, '--', $search->search($dir) );
2162
}
2163
 
2164
 
2165
sub Init
2166
{
2167
    push( @INITS, @_ );
2168
}
2169
 
2170
#-------------------------------------------------------------------------------
2171
# Function        : Generate
2172
#
2173
# Description     : Legacy Function - don't use unless you have too.
2174
#                   Flags files that are to be generated during the
2175
#                   early 'generate' make phase. Will also add named files
2176
#                   to various internal lists
2177
#
2178
#                   Intended to be used in conjunction with the 'Rule' directive
2179
#                   to flag header and source files that need to be created early
2180
#                   in the build process.
2181
#
2182
# Inputs          : See GenerateSrcFile
2183
#
2184
# Returns         : 
2185
#
2186
sub Generate
2187
{
2188
    my( $platforms, @elements ) = @_;
2189
 
2190
    Debug2( "Generate($platforms, @elements)" );
2191
 
2192
    return if ( ! ActivePlatform($platforms) );
2193
    Message("Generate directive used. Consider replacing with GenerateFiles");
2194
 
2195
    #
2196
    #   Use Non-warning version to do the hard work
2197
    #
2198
    GenerateSrcFile( 1, @elements );
2199
}
2200
 
2201
#-------------------------------------------------------------------------------
2202
# Function        : Generated
2203
#
2204
# Description     : Legacy Function - don't use unless you have too.
2205
#                   Flags files that are generated by misc Rules
2206
#
2207
#                   Intended to be used in conjunction with the 'Rule' directive
2208
#                   to mark files that have been generated, so that they can be
2209
#                   cleaned up.
2210
#
2211
#                   Note the difference to the 'Generate' directive which will
2212
#                   ensure that the Rule will be run in the 'generate' phase,
2213
#                   this directive doesn't.
2214
#
2215
# Inputs          : Files with internal Makefile Paths and codes
2216
#                   Eg: Generated( '*', "\$(LIBDIR)/libcsf\$(GBE_TYPE).\${a}" );
2217
#                   See why its YUK!
2218
#
2219
# Returns         : 
2220
#
2221
sub Generated
2222
{
2223
    my( $platforms, @elements ) = @_;
2224
    my( @args );
2225
 
2226
    return if ( ! ActivePlatform($platforms) );
2227
    Debug2( "Generated($platforms, @elements)" );
2228
 
2229
    #.. Collect arguments
2230
    #
2231
    foreach ( @elements )
2232
    {
2233
        if ( /^-(.*)/ )
2234
        {
2235
            Debug( "Gen: arg $_" );
2236
            push ( @args, $_);
2237
        }
2238
    }
2239
 
2240
    #.. Push source file(s)
2241
    #
2242
    foreach ( @elements )
2243
    {
2244
        if ( ! /^-(.*)/ )
2245
        {
2246
            Debug( "Generated: $_ (@args)" );
2247
            push (@USERGENERATED, $_);
2248
 
2249
            #
2250
            #   Add the file to the list of known source files
2251
            #   This will allow them to be packaged
2252
            #
2253
            GenerateSrcFile (0, $_ );
2254
        }
2255
    }
2256
}
2257
 
2258
 
2259
#-------------------------------------------------------------------------------
2260
# Function        : GenerateSrcFile
2261
#
2262
# Description     : Internal Function (No $platform)
2263
#                   Determine how to handle a 'Generated' file
2264
#
2265
#
2266
# Inputs          : $generated          - 0: Don't add to GENERATED List
2267
#                                         1: Add to GENERATED List
2268
#                                         2: Add to GENERATED List, if a source file
2269
#                   FileName(s)         - Name of one or more files to process
2270
#                                         All files are processed in the same way
2271
#                                         These file may contain Makefile prefixes
2272
#                                         ie: $(OBJDIR)/file.obj
2273
#                   Options:
2274
#                       --c             - Hint: Its a "C" file
2275
#                       --cpp           - Hint: Its a C++ file
2276
#                       --asm           - Hint: Its an ASM file
2277
#                       -*              - Save as argument attached to the file
2278
#
303 dpurdie 2279
# Returns         : Number of 'source' file
227 dpurdie 2280
#
2281
sub GenerateSrcFile                             # Internal Function - no $platform
2282
{
2283
    my( $generated, @elements ) = @_;
2284
    my( $type, @args );
303 dpurdie 2285
    my $result = 0;
227 dpurdie 2286
 
2287
    Debug2( "GenerateSrcFile($generated,@elements)" );
2288
 
2289
    #.. Collect arguments
2290
    #
2291
    $type = "";
2292
    foreach ( @elements )
2293
    {
2294
        if ( /^--c$/ ) {
2295
            Debug( "Gen: --c" );
2296
            $type = ".c";
2297
 
2298
        } elsif ( /^--cpp$/ ) {
2299
            Debug( "Gen: --cpp" );
2300
            $type = ".cc";
2301
 
2302
        } elsif ( /^--asm$/ ) {
2303
            Debug( "Gen: --asm" );
2304
            $type = ".asm";
2305
 
2306
        } elsif ( /^-(.*)/ ) {
2307
            Debug( "Src: arg $_" );
2308
            push @args, $_;
2309
        }
2310
    }
2311
 
2312
    #.. Process source file(s)
2313
    #
2314
    #   Determine if file is already a known SRCS file - skip if already known
2315
    #   Update SRCS data
2316
    #   Update SRC_TYPE data
2317
    #   Update SRC_ARGS data
2318
    #   Add the file to a suitable source file list ie: @CHDRS,...
2319
    #   Flag as a GENERATED file - These will be processed during the 'generate' phase
2320
    #
2321
    foreach my $source ( @elements )
2322
    {
2323
        next if ( $source =~ /^-(.*)/ );                # Not a source file
2324
 
2325
        my $basename = StripDir( $source );
2326
        Debug( "Generate: $source=$basename (@args)" );
2327
 
2328
        if ($SRCS{ $basename }) {
2329
            Warning( "Duplicate src ignored '$source'" );
2330
            next;
2331
        }
2332
        $SRCS{ $basename } = $source;
2333
 
2334
        HashJoin( \%SRC_ARGS, $;, $basename, @args )
2335
            if (@args);
2336
 
2337
        $SRC_TYPE{ $basename } = $type
2338
            if ($type);
2339
 
2340
        #
2341
        #   Add the file to any source file lists that it may like to know
2342
        #   about this file.
2343
        #
2344
        #   If the file was a known source file, then it may need to be generated
2345
        #   very early in the build process.
2346
        #
2347
        my $src_file_type = __AddSourceFile( 1, $basename );
285 dpurdie 2348
        if ($generated == 1 || ($src_file_type && $generated > 1) )
227 dpurdie 2349
        {
2350
            push(@GENERATED, $source);
303 dpurdie 2351
            $result++;
227 dpurdie 2352
        }
2353
        else
2354
        {
2355
            push(@GENERATED_NOTSRC, $source);
2356
        }
2357
    }
303 dpurdie 2358
 
2359
    return $result;
227 dpurdie 2360
}
2361
 
2362
#-------------------------------------------------------------------------------
2363
# Function        : GenerateFiles
2364
#
2365
# Description     : Generate files in a controlled manner using a specified
2366
#                   tool to perform the task
2367
#
2368
# Inputs          : $1      - platform specifier '*' (comma delemitered)
2369
#                   $2      - Tool Name
2370
#                   $3...   - Command line argument to generate files with embedded information
2371
#                           - or options. Multiple command line arguments will be joind with
2372
#                             a single space
2373
#
2374
#                   The generated files will be placed in the OBJ directory for
2375
#                   the current target platform. This allows different files to
2376
#                   be generated for each platform, without collision.
2377
#
2378
#                   The full name of the generated files will be added to the list of
2379
#                   source files. Thus the user does not need to know the
2380
#                   full name of the file - it will be tracked by JATS.
2381
#
2382
#                   If a generated file is a header file, then the OBJ directory
2383
#                   will be added as AddIncDir() so that the header files can be
2384
#                   extracted
2385
#
2386
#                   If a generated file is a "C"/"C++" source file, then it will
2387
#                   compiled and the object file made available
2388
#
2389
#                   The tool name may be:
2390
#                       --Tool=name  or "name"
2391
#                               Look in the tool paths in Packages
2392
#                               Look in the JATS tool directory for named script
2393
#                               Look in the JATS bin directory for the named exe
2394
#                               Look in the users path ( and generate a warning )
2395
#                               Give up and hope magic happens later
2396
#                       --Script=name
2397
#                               Resolve the name using known Src paths
2398
#                               The script may be generated and need not exist
2399
#                               at the time the makefile is created.
2400
#                       --Shell
2401
#                               The command line argument is a shell script that
2402
#                               will be passed to a simple shell.
263 dpurdie 2403
#                       --Prog=name
2404
#                               Resolve to a program generated within this makefile
227 dpurdie 2405
#
2406
#
2407
#                   The command line argument contains keywords to allow
2408
#                   information to be extracted from the line. Keywords are:
2409
#
2410
#                       --Generated(xxx)        - xxx is a generated file
2411
#                                                 It will be placed in the OBJDIR
2412
#                       --GeneratedCommon(xxx)  - xxx is a generated file
2413
#                                                 File will be placed in the local directory
2414
#                                                 and will be shared by by all platforms
2415
#                       --GeneratedObject(xxx)  - xxx is a generated object file
2416
#                                                 It will be placed in the OBJDIR and will
2417
#                                                 have a suitable object suffix appended
2418
#                       --GeneratedProg(xxx)    - xxx is a generated program file
2419
#                                                 It will be placed in the BINDIR
2420
#                       --Prerequisite(xxx)     - xxx is a prerequisite file
2421
#                                                 The full name of the file will be located
2422
#                                                 and used within the command. The file will
2423
#                                                 be added to the list of recipe prerequisites
2424
#                       --GeneratedDirectory(xxx)
2425
#                       --GeneratedCommonDirectory(xxx)
2426
#                       --GeneratedObjectDirectory(xxx)
2427
#                       --GeneratedProgDirectory(xxx)
2428
#                                               - xxx is a generated file, but is not placed
2429
#                                                 on the command line. It is flagged as
2430
#                                                 a generated files
2431
#                       --PackageBase(xxx)      - xxx is a package. The keyword will be replaced
2432
#                                                 with the pathname to the package. If the package
2433
#                                                 has been copied in the the interface directory
2434
#                                                 then the interface directory will be used.
2435
#                       --PackageInfo(xxx,--opt)- xxx is a package. The keyword will be replaced
2436
#                                                 with the information requested.
2437
#                                                 Options are:
2438
#                                                   --path
2439
#                                                   --version
2440
#                                                   --fullversion
2441
#                                                   --project
2442
#
2443
#                       Where "xxx" may be of the form:
2444
#                           name,option[,option]
2445
#
2446
#                       Flag options are:
2447
#                           --file             - The file part of the full name
2448
#                           --dir              - The directory part of the full name
2449
#                           --abspath          - Abs path
2450
#                           --absdrive         - Abs path with drive letter
2451
#
2452
#                       --Var(Name,opt)         - Name is the name of a recognised varable
2453
#                                                 Refer to ExpandGenVar function for details
2454
#                                                 of Name and available options
2455
#                                                 The expanded text will be replaced with an
2456
#                                                 suitable makefile variables that will be
2457
#                                                 replaced at run-time.
2458
#
2459
#                   The keyword will be replaced with the resolved name. This may be a file,
2460
#                   a directory or other text.
2461
#
2462
#                   Options do not alter command line text. They do affect the way the command is
2463
#                   processed.
2464
#                   Options include:
2465
#                       --Prereq=name           - The name of a file to add as a prerequisite
2466
#                                                 The file does not form part of the command line
2467
#                       --Created=name          - The name of a file to treat as a generated file
2468
#                       --CreatedCommon=name      The file does not form part of the command line 
2469
#                       --CreatedObject=name
2470
#                       --CreatedProg=name
2471
#
2472
#                       --NoVarTag              - Modifes --Var operation to suppress tags
2473
#                       --NoWarn                - Don't warn if no prerequistes found
2474
#                       --NoGenerate            - Don't warn if no generated files are found
2475
#                                                 Will create a dummy rule name and the recipe will
2476
#                                                 always be executed during the 'GenerateFiles' phase
2477
#                       --UnknownPreq           - Prerequisites are not fully known.
2478
#                                                 Rebuild the target whenever it is required.
2479
#                       --AutoGenerate          - Examine the generated file to determine when the
2480
#                                                 tools is to be run.
261 dpurdie 2481
#                                                 Must be before any options that declare
2482
#                                                 creation of files.
227 dpurdie 2483
#                       --Text=<text>           - Display text for command
2484
#
263 dpurdie 2485
#                       --Clean[=arg]           - Call script with arg[-clean] for cleaning.
2486
#                       --PreDelete             - Delete generated files before running the command
227 dpurdie 2487
#
2488
#               Eg: GenerateFiles ( '*', "--Tool=mod_if.pl",
2489
#                                        "-src --Prerequisite(udh_module.cfg)",
2490
#                                        "-direct -hdr --Generated(udp.h) -quiet" );
2491
#
2492
my $NoGenIndex = 0;
2493
sub GenerateFiles
2494
{
2495
    my ( $platforms, $tool, @args) = @_;
2496
 
2497
    return if ( ! ActivePlatform($platforms) );
2498
 
2499
    Debug2( "GenerateFiles:($platforms, $tool, @args)" );
2500
 
2501
    my @preq_files;
2502
    my $preq_unknown;
2503
    my @gen_files;
2504
    my $shell_script;
2505
    my $shell_cmds;
2506
    my @tool_args;
2507
    my $no_warn;
2508
    my $clean_tag;
2509
    my $text;
2510
    my $gtype = 1;
303 dpurdie 2511
    my @has_source;
227 dpurdie 2512
    my @var_opts;
261 dpurdie 2513
    my @genreq_seen;
263 dpurdie 2514
    my $predelete;
227 dpurdie 2515
 
2516
    #
2517
    #   Process the first argument - this describes the program that will be used
2518
    #   to generate the files. It may be:
2519
    #       --Tool          - A Jats Tool or Plugin
2520
    #       --Script        - A shell script file
2521
    #       --Shell         - Raw shell commands
2522
    #       --Prog          - A program created within the Makefile
2523
    #
2524
    #
2525
    if ( $tool =~ /^--Tool=(.*)/ || $tool =~ /^([^-].*)/)
2526
    {
2527
        $tool = $1;
2528
        my $tool_no_prereq = 0;
2529
 
2530
        #
2531
        #   Process the Tool name and determine the location of the tool
2532
        #   Support --Tool=name and "name"
2533
        #   Locate the tool one of the many well known locations
2534
        #       1) Tool paths from Package Archives
2535
        #       2) JATS tool and binaries
2536
        #       3) User PATH (!YUK)
2537
        #
2538
 
2539
        #
2540
        #   Create a list of known extensions to scan
2541
        #   Basically present so that we can use .exe files without the .exe name
2542
        #
2543
        my @extension_list;
2544
        push @extension_list, '.exe' if ( $::ScmHost ne "Unix" );
2545
        push @extension_list, '.pl', '.sh', '.ksh', '';
2546
 
2547
        TOOL_SEARCH:
2548
        {
2549
            #
2550
            #   Locate tool with package
2551
            #
2552
            if ( my $fname = ToolExtensionProgram( $tool, @extension_list ))
2553
            {
2554
                $tool = $fname;
2555
                last TOOL_SEARCH;
2556
            }
2557
 
2558
            #
2559
            #   Search the JATS tools and Bin directory
2560
            #   Retain the symbolic name of the JATS directory
2561
            #
2562
            for my $ext ( @extension_list )
2563
            {
2564
                foreach my $jdir ( qw( / /DEPLOY/ /LOCAL/ ) )
2565
                {
2566
                    if ( -f "$::GBE_TOOLS$jdir$tool$ext" )
2567
                    {
2568
                        $tool = "\$(GBE_TOOLS)$jdir$tool$ext";
2569
                        last TOOL_SEARCH;
2570
                    }
2571
                }
2572
 
2573
                if ( -f "$::GBE_BIN/$tool$ext" )
2574
                {
2575
                    $tool = "\$(GBE_BIN)/$tool$ext";
2576
                    last TOOL_SEARCH;
2577
                }
2578
            }
2579
 
2580
            #
2581
            #   Has the user provided an absolute PATH
2582
            #   This is not good, but for testing we can use it
2583
            #
2584
            if ( $tool =~ m~^/~ || $tool =~ m~^.:~ )
2585
            {
2586
                Warning("Absolute path program specified. Uncontrolled tool: $tool");
2587
                for my $ext ( @extension_list )
2588
                {
2589
                    if ( -f "$tool$ext" )
2590
                    {
2591
                        $tool = "$tool$ext";
2592
                        last TOOL_SEARCH;
2593
                    }
2594
                }
2595
            }
2596
 
2597
            #
2598
            #   May have a relative path to a local tool
2599
            #
2600
            if ( -f $tool )
2601
            {
2602
                UniquePush (\@preq_files, $tool);
2603
                last TOOL_SEARCH;
2604
            }
2605
 
2606
            #
2607
            #   Search the users PATH
2608
            #   Generate a warning if the program is found. These programs are
2609
            #   not nice as they are not really controlled.
2610
            #
2611
            for my $dir (split( $::ScmPathSep, $ENV{'PATH'} ) )
2612
            {
2613
                for my $ext ( @extension_list )
2614
                {
2615
                    if ( -f "$dir/$tool$ext" )
2616
                    {
2617
                        Warning("External program found in the user's PATH. Uncontrolled tool: $tool");
2618
                        $tool = "$dir/$tool$ext";
2619
 
2620
                        #
2621
                        #   Do not make the program a pre-requisite if we are running
2622
                        #   under Windows. This avoids two problems:
2623
                        #       1) May have spaces in pathname
2624
                        #       2) May have driver letter in pathname
2625
                        #
2626
                        $tool_no_prereq = 1 if ( $::ScmHost eq "WIN" );
2627
                        last TOOL_SEARCH;
2628
                    }
2629
                }
2630
            }
2631
 
2632
            #
2633
            #   Specified progrom not found
2634
            #   Generate a warning and use the raw name
2635
            #
2636
            Warning("Tool not found: $tool");
2637
            $tool_no_prereq = 1;
2638
        }
2639
        UniquePush (\@preq_files, $tool) unless ($tool_no_prereq);
2640
 
2641
    } elsif ( $tool =~ /^--Script=(.*)/ ) {
2642
 
2643
        #
2644
        #   Locate the script in a known source directory and make
2645
        #   the script a prerequisite of the target files, since the
2646
        #   script may be generated.
2647
        #
2648
        $tool = MakeSrcResolve ( $1 );
2649
        UniquePush (\@preq_files, $tool);
2650
 
2651
    } elsif ( $tool =~ /^--Shell$/ ) {
2652
        #
2653
        #   The user has provided a shell script within the command body
2654
        #   This will be executed directly by a shell
2655
        #   directores will need to use a "/" separator
2656
        #
2657
        $tool = "InternalShell";
2658
        $shell_script = 1;
2659
        $shell_cmds = 1;
2660
 
2661
 
2662
    } elsif ( $tool =~ /^--Prog=(.*)$/ ) {
2663
        #
2664
        #   Using a program that has been created within this script
2665
        #
2666
        my $prog = $1;
289 dpurdie 2667
        if ( my $pProg = $PROGS->Get($prog) )
227 dpurdie 2668
        {
289 dpurdie 2669
            $tool = $pProg->getPath()
227 dpurdie 2670
                unless ( $tool = $SRCS{$prog} );
2671
        UniquePush (\@preq_files, $tool);
2672
        }
2673
        else
2674
        {
2675
            Error ("Unknown program: $prog");
2676
        }
2677
 
2678
    } else {
2679
 
2680
        #
2681
        #   Currently generate a warning and then use the raw tool name
2682
        #
2683
        Error ("Unknown TOOL syntax: $tool");
2684
    }
2685
 
2686
    #
2687
    #   May need to quote the path
2688
    #   If the toolpath contains spaces then ugliness can occur - so quote the program
2689
    #
2690
    $tool = '"' . $tool . '"'
2691
        if ( (! $shell_script ) && $tool =~ m~\s~ );
2692
 
2693
    #
2694
    #   Determine special startup for various programs
2695
    #       Perl  - use known implemenatation
2696
    #       Shell - use known implemenatation
2697
    #       Otherwise - simply run it
2698
    #
2699
    #   Windows: Shell and Perl don't need '\' in paths
2700
    #
2701
    if ( $tool =~ /\.pl$/ )
2702
    {
2703
        $tool = "\$(GBE_PERL) $tool";
2704
        $shell_script = 1;
2705
    }
2706
    elsif ( $tool =~ /\.k?sh$/ )
2707
    {
2708
        $tool = "\$(GBE_BIN)/sh $tool";
2709
        $shell_script = 1;
2710
    }
2711
    Debug( "GenerateFiles: Tool: $tool" );
2712
 
2713
 
2714
    #
2715
    #   Process the remaining arguments
2716
    #   These will be command line arguments or options/flags
2717
    #   Command line arguments are concatenated together
2718
    #
2719
    for my $arg (@args)
2720
    {
263 dpurdie 2721
        if ( $arg =~ /^--PreDelete$/ )
2722
        {
2723
            #
2724
            #   Delete generated files before running the generation process
2725
            #   Some programs refuse to overwrite existing files
2726
            #
2727
            $predelete = 1;
2728
            next;
2729
        }
2730
 
227 dpurdie 2731
        if ( $arg =~ /^--NoVarTag$/ )
2732
        {
2733
            #
2734
            #   Modify the operation of --Var to supress the tags
2735
            #   Should be usd early as will only affect following --Var usage
2736
            #
2737
            push @var_opts, "--notag";
2738
            next;
2739
        }
2740
 
2741
        if ( $arg =~ /^--NoWarn$/ )
2742
        {
2743
            #
2744
            #   Supress warnings - No prequisites found
2745
            #   This is acceptable, but normally a tool should take an input
2746
            #   and create some output from it.
2747
            #
2748
            $no_warn = 1;
2749
            next;
2750
        }
2751
 
2752
        if ( $arg =~ /^--NoGenerate$/ )
2753
        {
2754
            #
2755
            #   Tool does generate a definable output
2756
            #   Should only be used internally
2757
            #
2758
            #   Need to create a dummy name for the rule
2759
            #   Use a base name and a number
2760
            #
2761
            my $dummy_target = 'generate_files_' . $NoGenIndex;
2762
            UniquePush (\@gen_files, $dummy_target );
2763
            UniquePush (\@GENERATED, $dummy_target);
2764
            next;
2765
        }
2766
 
2767
        if ( $arg =~ /^--UnknownPreq/ )
2768
        {
2769
            #
2770
            #   Indicate that the prequisites are not known, or too complex to
2771
            #   describe. ie: All files in a directory. May be used by packaging
2772
            #   tools.
2773
            #   The recipe will be run EVERY time we want to use the target.
2774
            #
2775
            $preq_unknown = 1;
2776
            $no_warn = 1;
2777
            next;
2778
        }
2779
 
2780
        if ( $arg =~ /^--AutoGenerate/ )
2781
        {
2782
            #
2783
            #   Determine when to run the tool based on the types of files that
2784
            #   are generated. Existance of a source file will force the tool
2785
            #   to be run during the 'generate' phase, othewise the tool will be run
2786
            #   when the generated components are required.
2787
            #
2788
            $gtype = 2;
261 dpurdie 2789
            Warning ("AutoGenerate MUST occur before options that declare generation of files",
2790
                     "Have seen:", @genreq_seen)
2791
                if (@genreq_seen);
227 dpurdie 2792
            next;
2793
        }
2794
 
2795
        if ( $arg =~ /^--Prereq=(.*)/ )
2796
        {
2797
            #
2798
            #   Specify a prerequisite file, that is not a part of the command line
2799
            #   Simply add the files to the list of preq files
2800
            #
2801
            my $fn = LocatePreReq ($1);
2802
            UniquePush ( \@preq_files, $fn );
2803
            Debug( "GenerateFiles: ExtraPrereq: $fn" );
2804
            next;
2805
        }
2806
 
2807
        if ( $arg =~ /^--Created(.*)=(.*)/ )
2808
        {
2809
            #
2810
            #   Specify a generated file, that is not a part of the command line
2811
            #   Add the files to the list of generated files
2812
            #
2813
            my $type = $1;
2814
            my $fn = $2;
2815
 
343 dpurdie 2816
            #
2817
            #   Append object suffix to CreatedObject
2818
            #
227 dpurdie 2819
            $fn .= '.' . $::o
2820
                if ( $type =~ m/Object/ );
2821
 
343 dpurdie 2822
            #
2823
            #   If the files is 'created' in a subdir, then add the dir
2824
            #   as a prerequisite.
2825
            #
2826
            if ( $type =~ m/Prog/ ) {
2827
                $fn = "\$(BINDIR)/$fn";
2828
                UniquePush (\@preq_files, '$(GBE_BINDIR)');
2829
 
2830
            } elsif ( $type !~ m/Common/ ) {
2831
                $fn = "\$(OBJDIR)/$fn";
2832
                UniquePush (\@preq_files, '$(GBE_OBJDIR)');
2833
            }
227 dpurdie 2834
 
2835
            #
2836
            #   Examine the file and see if it needs to be compiled
2837
            #   Add to the list of source files
2838
            #
261 dpurdie 2839
            push @genreq_seen, $arg;
303 dpurdie 2840
            if ( UniquePush (\@gen_files, $fn) )
2841
            {
2842
                if ( GenerateSrcFile ( $gtype, $fn  ) && $gtype == 2 )
2843
                {
2844
                    push @has_source, $fn;
2845
                }
2846
            }
227 dpurdie 2847
            Debug( "GenerateFiles: ExtraCreated: $fn" );
2848
            next;
2849
        }
2850
 
2851
        if ( $arg =~ /^--Clean($|=(.*))/ )
2852
        {
2853
            #
2854
            #   Detect Clean option
2855
            #
2856
            $clean_tag = $2 ? $2 : '-clean';
2857
 
2858
            #
2859
            #   Shell command with a --Clean will only
2860
            #   be run during a clean phase. They should not have any prereq
2861
            #   and should not generate any files, so simplify the interface.
2862
            #
2863
            push @args, '--NoWarn', '--NoGenerate'
2864
                if ( $shell_cmds );
2865
 
2866
            next;
2867
        }
2868
 
2869
        if ( $arg =~ /^--Text=(.*)/ )
2870
        {
2871
            #
2872
            #   Display this text when executing commands
2873
            #
2874
            $text = $1;
2875
            next;
2876
        }
2877
 
2878
 
2879
        #   Not an option. Must be an argument to the tool/program
2880
        #   Process the tool arguments and extract file information
2881
        #   Extract all fields of the form:
2882
        #           --xxxxx(yyyyyy[,zzzzz])
2883
        #           --xxxxx{yyyyyyy}
2884
        #           --xxxxx[yyyyyyy] to allow embedded brackets
2885
        #
2886
        while ( $arg =~ m/--(\w+)               # --CommandWord         $1
2887
                                (               # Just for grouping
2888
                                \((.*?)\)   |   # Stuff like (yyyyy)    $3
2889
                                {(.*?)}     |   # or    like {yyyyy}    $4
2890
                                \[(.*?)\]       # or    like [yyyyy]    $5
2891
                                )/x )           # Allow comments and whitespace
2892
        {
2893
            my $cmd = $1;                       # The command
2894
            my $ufn = $3 || $4 || $5;           # User filename + options
2895
            my $mb = $-[0];                     # Match begin offset
2896
            my $me = $+[0];                     # Match end
2897
            my $flags = '';                     # Optional flags ( --dir or --file )
2898
            my $raw_arg = $ufn;                 # Raw arguments
285 dpurdie 2899
            my $all = substr( $arg, $mb, $me ); # All of match. Avoid use of $&
343 dpurdie 2900
            my $is_path = 1;
285 dpurdie 2901
 
227 dpurdie 2902
 
2903
            Error ("GenerateFiles. Empty element not allowed: $all")
2904
                unless ( defined($ufn) );
2905
 
2906
            $ufn =~ s/\s+$//;
2907
            $ufn =~ s/^\s+//;
2908
            $ufn =~ s~//~/~g;                   # Remove multiple /
2909
            if ( $ufn =~ m/(.*?),(.*)/ )        # Extract out any flags
2910
            {
2911
                $ufn = $1;
2912
                $flags = $2;
2913
            }
2914
 
2915
            my $fn = $ufn ;                     # Replacement filename
343 dpurdie 2916
            my $fnp = '';                       # Prefix to $fn
227 dpurdie 2917
            Error ("GenerateFiles. Empty element not allowed: $all" )
2918
                if ( length ($ufn) <= 0 );
2919
 
2920
            #
2921
            #   Process found user command
2922
            #
2923
            if ( $cmd =~ /^Generated/ )
2924
            {
2925
                my $use_dir = "";
343 dpurdie 2926
 
227 dpurdie 2927
                #
2928
                #   Generated filename
2929
                #       Determine the target directory
2930
                #       Determine the full name of the file.
2931
                #       Flag the file as generated
2932
                #
2933
                if ( $cmd =~ /Prog/ )
2934
                {
2935
                    #
2936
                    #   Generated Prog are generated in the BIN directory
2937
                    #   Ensure the directory exists by using its symbolic name
2938
                    #   as a prerequisite.
2939
                    #
343 dpurdie 2940
                    $use_dir = '$(BINDIR)';
2941
                    UniquePush (\@preq_files, '$(GBE_BINDIR)');
227 dpurdie 2942
                }
2943
                elsif ( $cmd !~ /Common/ )
2944
                {
2945
                    #
2946
                    #   Files that are not Common are generated in the
2947
                    #   object directory. This directory must exist, so it
2948
                    #   symbolic name GBE_OBJDIR is made a prerequisite too.
2949
                    #
2950
                    #   If the file is a header file, then add the directory
2951
                    #   to the include search path too.
2952
                    #
343 dpurdie 2953
                    $use_dir = '$(OBJDIR)';
2954
                    UniquePush (\@preq_files, '$(GBE_OBJDIR)');
2955
                    AddIncDir( $platforms , '$(OBJDIR)', '--NoWarn' )
227 dpurdie 2956
                        if ( $ScmSourceTypes{ StripFile($fn) } && $ScmSourceTypes{ StripFile($fn) } eq ".h" );
2957
                }
2958
 
2959
 
2960
                #
2961
                #   Append a toolset specfic object file name suffix
2962
                #   for Object files only
2963
                #
2964
                $fn .= ".$::o"
2965
                    if ( $cmd =~ /Object/ );
2966
 
2967
                #
2968
                #   Merge directory and filename parts
2969
                #
2970
                $fn = $use_dir . ( $use_dir ? "/" : ""  ) . $fn;
2971
 
2972
                #
2973
                #   Save for later user
2974
                #   Flag the file as a generated file
2975
                #
261 dpurdie 2976
                push @genreq_seen, $cmd;
303 dpurdie 2977
                if ( UniquePush (\@gen_files, $fn) )
2978
                {
2979
                    if ( GenerateSrcFile ( $gtype, $fn  ) && $gtype == 2 )
2980
                    {
2981
                        push @has_source, $fn;
2982
                    }
2983
                }
227 dpurdie 2984
 
2985
                #
2986
                #   Use the directory or the full name
2987
                #   If using the directory then ensure that we have a name
2988
                #   even if its "."
2989
                #
2990
                $fn = ($use_dir) ? "$use_dir" : "."
2991
                    if ( $cmd =~ /Directory/ );
2992
 
2993
                Debug( "GenerateFiles: Generate: $fn" );
2994
 
2995
            }
2996
            elsif ( $cmd =~ /^Prereq/ )
2997
            {
2998
                #
2999
                #   Prerequisite filename
3000
                #       Resolve the full name of the file. It may be known
3001
                #       as a source file (possibly generated) or it may be
3002
                #       located in a known source directory
3003
                #
3004
                $fn = LocatePreReq ($ufn);
3005
                UniquePush (\@preq_files, $fn);
3006
 
3007
                Debug( "GenerateFiles: Prereq: $fn" );
3008
 
3009
            }
3010
            elsif ( $cmd =~ /^PackageBase/ )
3011
            {
3012
                $fn = GetPackageBase( "GenerateFiles", $raw_arg );
3013
                UniquePush (\@preq_files, $fn);
3014
            }
3015
            elsif ( $cmd =~ /^PackageInfo/ )
3016
            {
3017
                $fn = GetPackageInfo( "GenerateFiles", $raw_arg );
3018
            }
3019
            elsif ( $cmd =~ /^Var/ )
3020
            {
343 dpurdie 3021
                ($fnp, $fn, $is_path) = ExpandGenVar( "GenerateFiles", $raw_arg, @var_opts );
227 dpurdie 3022
                $flags = '';
343 dpurdie 3023
                if ( $raw_arg eq 'ObjDir' ) {
3024
                    UniquePush (\@preq_files, '$(GBE_OBJDIR)');
3025
                } elsif ( $raw_arg eq 'BinDir' ) {
3026
                    UniquePush (\@preq_files, '$(GBE_BINDIR)');
3027
                } elsif ( $raw_arg eq 'LibDir' ) {
3028
                    UniquePush (\@preq_files, '$(GBE_LIBDIR)');
3029
                }
227 dpurdie 3030
            }
3031
            else
3032
            {
3033
                Warning ("GenerateFiles: Unknown replacement command: $cmd");
3034
                $fn = $ufn;
3035
            }
3036
 
3037
            #
3038
            #   Process path modification flags
3039
            #
3040
            $fn = ProcessPathName( $fn, $flags );
3041
 
3042
            #
3043
            #   Minor kludge under windows. Ensure directores have a "\" sep
3044
            #   Unless the user has specified a straight shell command
3045
            #
303 dpurdie 3046
            $fn = "\$(subst /,\\,$fn)"
343 dpurdie 3047
                if ( $is_path && $::ScmHost eq "WIN" && ! defined($shell_script) );
227 dpurdie 3048
 
3049
            #
343 dpurdie 3050
            #   Prepend any $fn Prefix
3051
            #   This will be a tag and is not subject to path processing
3052
            #
3053
            $fn = $fnp . $fn;
3054
 
3055
            #
227 dpurdie 3056
            #   Replace the found string with the real name of the file
3057
            #   Note: 4 argument version of substr is not always available
3058
            #         so we must do it the hard way
3059
            #               substr( $arg, $mb, $me - $mb, $fn);
3060
            #
3061
            $arg = substr( $arg, 0, $mb ) . $fn . substr( $arg, $me );
3062
 
3063
            Debug2( "GenerateFiles: subs: $all -> $fn" );
3064
        }
3065
 
3066
        #
3067
        #   Save the tool arguments in an array
3068
        #
3069
        push @tool_args, $arg;
3070
    }
3071
 
3072
 
3073
    #
3074
    #   Sanity test. Ensure that some file have been marged as generated
3075
    #                Warn if no prerequisites found
3076
    #
303 dpurdie 3077
    Warning( "GenerateFiles. --AutoGenerate option has no effect",
3078
             "The following files are 'source' files",  @has_source ) if ( @has_source );
227 dpurdie 3079
    Warning( "No Prerequisite files found in $tool",@tool_args) unless ( $no_warn || $#preq_files >= 0 );
3080
    Error  ( "No generated files found in $tool",@tool_args) unless ($#gen_files >= 0);
3081
 
3082
 
3083
    #
3084
    #   Save information
3085
    #   Will be used to create makefile statements later
3086
    #
3087
    my %gen_data;
3088
 
3089
    $gen_data{'index'}      = $NoGenIndex++;
3090
    $gen_data{'shell'}      = $shell_cmds;
3091
    $gen_data{'gen'}        = \@gen_files;
3092
    $gen_data{'preq'}       = \@preq_files;
3093
    $gen_data{'tool'}       = $tool;
3094
    $gen_data{'toolargs'}   = \@tool_args;
3095
    $gen_data{'clean'}      = $clean_tag;
3096
    $gen_data{'text'}       = $text || $gen_files[0];
3097
    $gen_data{'preq_sus'}   = 1 if ( $preq_unknown );
263 dpurdie 3098
    $gen_data{'predelete'}  = 1 if ( $predelete );
227 dpurdie 3099
 
3100
    push(@GENERATE_FILES, \%gen_data);
3101
 
3102
    Debug2( "GenerateFiles: cmd: $tool @tool_args" );
3103
}
3104
 
3105
#-------------------------------------------------------------------------------
3106
# Function        : MakePerlModule
3107
#
3108
# Description     : Build Perl Module(s) using the Perl Build System
3109
#                   This is a thin wrapper around a specialised script
3110
#
3111
#                   The user can do the same job with correct use of
3112
#                   a GenerateFiles, but this is a lot tidier.
3113
#
3114
# Inputs          : $1      - platform specifier '*' (comma delemitered)
3115
#                   $*      - Paths to Perl Modules[,command options]
3116
#                             Options to the BuildPerl script
3117
#
3118
# Returns         :
3119
#
3120
sub MakePerlModule
3121
{
3122
    my ( $platforms, @args) = @_;
3123
 
3124
    return if ( ! ActivePlatform($platforms) );
3125
 
3126
    Debug2( "MakePerlModule:($platforms, @args)" );
3127
    my @opts;
3128
 
3129
    #
3130
    #   Extract options from paths to Perl Packages
3131
    #   Package names do not start with a '-'
3132
    #
3133
    foreach my $arg ( @args )
3134
    {
3135
        if ( $arg =~ /^-/ ) {
3136
            push @opts, $arg;
3137
 
3138
        } else {
3139
            #
3140
            #   Perl Package Directory Name
3141
            #   This may also contain embedded command to the Make command
3142
            #   These will be seperated with a comma
3143
            #       ie: module,-options=fred
3144
            #
3145
            my ($name,$options) = split( ',', $arg );
3146
            push @opts, "-PerlPackage=$arg";
3147
            push @opts, "--Prereq=$name/Makefile.PL";
3148
        }
3149
    }
3150
 
3151
    #
3152
    #   Invoke GenerateFiles with a bunch of additional arguments
3153
    #
3154
    GenerateFiles ($platforms, "--Tool=jats_buildperl.pl",
3155
                          '--Var(MachType)',                        # Build Machine type
3156
                          '--Var(PackageDir)',                      # Package dir
3157
                          '--NoGenerate',                           # Don't know the output
3158
                          '--Text=Make Perl Module',                # Pretty print
3159
                          '--NoWarn',
3160
                          '--Clean=-clean_build',                   # Jats clean support
3161
                          '--NoVarTag',                             # No more Tags
3162
                          @opts,
3163
                          );
3164
}
3165
 
3166
#-------------------------------------------------------------------------------
3167
# Function        : MakeLinuxDriver
3168
#
3169
# Description     : Build a Linux Device Driver using the Linux Device Driver
3170
#                   Build System
3171
#                   This is a thin wrapper around a specialised script
3172
#
3173
#                   The user can do the same job with correct use of
3174
#                   a GenerateFiles, but this is a lot tidier.
3175
#
3176
# Inputs          : $1      - platform specifier '*' (comma delemitered)
3177
#                   $2      - name of the driver. No extension
3178
#                   $*      - Driver sources
3179
#                             Options to the script
3180
#
3181
# Returns         :
3182
#
3183
sub MakeLinuxDriver
3184
{
3185
    my ( $platforms, $driver_name, @args) = @_;
3186
 
3187
    return if ( ! ActivePlatform($platforms) );
3188
 
285 dpurdie 3189
    Error ("No driver name specified") unless ( $driver_name );
227 dpurdie 3190
    Debug2( "MakeLinuxDriver:($platforms, $driver_name ,@args)" );
3191
    my @srcs;
3192
    my @opts;
3193
 
3194
    #
3195
    #   Extract options from source files
3196
    #   Package names do not start with a '-'
3197
    #
3198
    foreach my $arg ( @args )
3199
    {
3200
         if ( $arg =~ /^--Define=(.)/ ) {
3201
            push @opts, $arg;
3202
 
3203
         } elsif ( $arg =~ /^-/ ) {
3204
            push @opts, $arg;
3205
            Warning ("MakeLinuxDriver: Unknown option: $arg. Passed to script");
3206
 
3207
        } else {
3208
            push @srcs, $arg;
3209
            push @opts, "--Prereq=$arg";
3210
        }
3211
    }
3212
 
3213
    #
3214
    #   Cleanup the drive name
3215
    #
3216
    $driver_name =~ s~\.ko$~~;
3217
 
3218
    #
3219
    #   Remove the specified sources from the list of object files
3220
    #   that will be build. This will ensure that some internal rules are
3221
    #   not generated.
3222
    #
3223
    foreach ( @srcs )
3224
    {
3225
        my $file = StripExt(StripDir( $_ ));
3226
        delete $OBJSOURCE{ $file };
3227
        @OBJS = grep(!/^$file$/, @OBJS);
3228
    }
3229
 
3230
    #
3231
    #   Invoke GenerateFiles with a bunch of additional arguments
3232
    #   At runtime the include directories will be added as
3233
    #   absolute paths
3234
    #
3235
    GenerateFiles ($platforms, "--Tool=jats_buildlinux.pl",
3236
                    "-Output=--GeneratedProg($driver_name.ko)",
3237
                    "-Driver=$driver_name",
3238
                    "-GccPath=\$(GCC_CC)",
3239
                    "-Arch=\$(HOST_CPU)",
3240
                    "-LeaveTmp=\$(LEAVETMP)",
3241
                    "-Verbose=\$(CC_PRE)",
3242
                    "-Type=\$(GBE_TYPE)",
3243
                    "-Platform=\$(GBE_PLATFORM)",
3244
                    '$(patsubst %,-Incdir=%,$(INCDIRS))',
3245
                    @opts,
3246
                    @srcs
3247
                    );
3248
}
3249
 
3250
#-------------------------------------------------------------------------------
3251
# Function        : GetPackageBase
3252
#
3253
# Description     : Helper routine
3254
#                   Given a package name, determine the base address of the
3255
#                   package
3256
#
3257
# Inputs          : $dname         - Directive name     (Reporting)
3258
#                   $name          - Required package
3259
#                                    Allows two forms:
3260
#                                       package_name
3261
#                                       package_name,ext
3262
#
3263
# Returns         : Path to the directory in which the files are installed
3264
#                   This may be the interface directory
3265
#
3266
sub GetPackageBase
3267
{
3268
    my ($dname, $fname) = @_;
3269
    my $pkg;
3270
    my ($name, $ext) = split(',', $fname);
3271
 
3272
    $pkg = GetPackageEntry( $name, $ext );
3273
    Error ("$dname: Package not found: $fname") unless ( $pkg );
3274
 
3275
    #
3276
    #   If a BuildPkgArchive then use the interface directory
3277
    #
3278
    return ( $pkg->{'TYPE'} eq 'link' ) ? $pkg->{'ROOT'} : '$(INTERFACEDIR)';
3279
}
3280
 
3281
#-------------------------------------------------------------------------------
3282
# Function        : GetPackageInfo
3283
#
3284
# Description     : Helper routine
3285
#                   Given a package name, return some information about the package
3286
#                   Only one information item is allowed with each call
3287
#
3288
# Inputs          : $dname         - Directive name     (Reporting)
3289
#                   $name          - Required package
3290
#                                    Allows two forms:
3291
#                                       package_name
3292
#                                       package_name,ext
3293
#                                    Selector
3294
#                                       --path
3295
#                                       --version
3296
#                                       --fullversion
3297
#                                       --project
3298
#
3299
# Returns         : Package information
3300
my %GetPackageInfo = qw(path ROOT
3301
                        version DVERSION
3302
                        fullversion VERSION
3303
                        project DPROJ);
3304
sub GetPackageInfo
3305
{
3306
    my ($dname, $args) = @_;
3307
    my $pkg;
3308
    my $name;
3309
    my $ext;
3310
    my $info;
3311
 
363 dpurdie 3312
    #
3313
    #   Split up the arguments
3314
    #       Options start with '--'
3315
    #   First non-option is the package name
3316
    #   2nd non-option is the packag extension
3317
    #
3318
    #   Only one option allowed
3319
    #       Convert it into a known package info item
3320
    #
3321
    #
227 dpurdie 3322
    foreach ( split(',', $args) )
3323
    {
3324
        if ( m/^--(.*)/ ) {
3325
            Error( "$dname: Too many info requests: $args") if ( $info );
3326
            $info = $GetPackageInfo{$1};
3327
            Error( "$dname: Unknown info type: $_") unless ($info);
363 dpurdie 3328
 
227 dpurdie 3329
        } elsif ( $ext ) {
3330
            Error("$dname: Too many names: $args");
363 dpurdie 3331
 
227 dpurdie 3332
        } elsif ( $name ) {
3333
            $ext = $_;
363 dpurdie 3334
 
227 dpurdie 3335
        } else {
3336
            $name = $_;
3337
        }
3338
    }
3339
 
3340
    $pkg = GetPackageEntry( $name, $ext );
3341
    Error ("$dname: Package not found: $args") unless ( $pkg );
3342
 
3343
    #
3344
    #   If a BuildPkgArchive then use the interface directory
363 dpurdie 3345
    #   Default data item - path to the package
227 dpurdie 3346
    #
363 dpurdie 3347
    $info = 'ROOT' unless ( $info );
3348
    if ( $info eq 'ROOT' &&  $pkg->{'TYPE'} ne 'link' )
227 dpurdie 3349
    {
3350
        return ( '$(INTERFACEDIR)');
3351
    }
363 dpurdie 3352
 
227 dpurdie 3353
    return ( $pkg->{$info} );
3354
}
3355
 
3356
#-------------------------------------------------------------------------------
3357
# Function        : GetPackageEntry
3358
#
3359
# Description     : Return the package class pointer given a package name
3360
#
3361
# Inputs          : $name          - Required package
3362
#                   $ext           - Option package extension
3363
#
3364
# Returns         : Class pointer
3365
#
3366
sub GetPackageEntry
3367
{
3368
    my ($name, $ext) = @_;
3369
    $ext = '' unless ( $ext );
3370
 
3371
    for my $entry (@{$::ScmBuildPkgRules{$ScmPlatform} })
3372
    {
3373
        next unless ( $entry->{'NAME'} eq $name );
3374
        next if ( $ext && $entry->{'DPROJ'} ne $ext );
3375
        return $entry;
3376
    }
285 dpurdie 3377
    return;
227 dpurdie 3378
}
3379
 
3380
#-------------------------------------------------------------------------------
3381
# Function        : ExpandGenVar
3382
#
3383
# Description     : Expand a known variable for the Generate Files option
3384
#
3385
# Inputs          : $dname         - Directive name     (Reporting)
3386
#                   $arg           - Raw argument
3387
#                                    This of the form of
3388
#                                       Tag[,--option]+
3389
#                                    Tags are specified in %ExpandGenVarConvert
3390
#
3391
#                                   Options are:
3392
#                                       --tag
3393
#                                       --notag
3394
#                                       --tag=<SomeTag>
3395
#                                       --absdrive
3396
#                                       --abspath
285 dpurdie 3397
#                                       --default=text
343 dpurdie 3398
#                                       --allownone
227 dpurdie 3399
#                                   Not all options are avalaible on all variables
3400
#                   @opts           - Options
3401
#                                       --notag     - Default is --notag
3402
#
343 dpurdie 3403
# Returns         : Tag             - Any tag component of the expansion
3404
#                   Path/Value      - Path/Value of the component
3405
#                   is_path         - Above is a path
3406
#                   is_abs          - Path is absolute
227 dpurdie 3407
#
3408
 
3409
#
3410
#   Create a Hash to simplify the process of converting Var names
343 dpurdie 3411
#   into makefile variables. There are two data items, separated by a comma.
3412
#       The first is the runtime expansion value
3413
#       The second describes the first:
3414
#           NotPresent  - Expansion is not a path
3415
#           '-'         - Expansion is a path and is relative to CWD
3416
#           '+'         - Expansion is a path and is absolute
227 dpurdie 3417
#
3418
my %ExpandGenVarConvert = (
3419
    'BuildName'         => '$(GBE_PBASE)',
3420
    'BuildVersion'      => '$(BUILDVER)',
3421
    'BuildVersionNum'   => '$(BUILDVERNUM)',
3422
 
3423
    'PackageDir'        => '$(PKGDIR),+',
3424
    'PackagePkgDir'     => '$(PKGDIR)/pkg/pkg.$(GBE_PLATFORM),+',
3425
    'PackageIncDir'     => '$(INCDIR_PKG),+',
3426
    'PackageLibDir'     => '$(LIBDIR_PKG)/$(GBE_PLATFORM),+',
3427
    'PackageBinDir'     => '$(BINDIR_PKG)/$(GBE_PLATFORM)$(GBE_TYPE),+',
3428
 
3429
    'PackageToolDir'    => '$(PKGDIR)/tools,+',
3430
    'PackageToolBin'    => '$(PKGDIR)/tools/bin/$(GBE_HOSTMACH),+',
3431
    'PackageToolScript' => '$(PKGDIR)/tools/scripts,+',
3432
 
3433
    'LibDir'            => '$(LIBDIR),+',
3434
    'BinDir'            => '$(BINDIR),+',
3435
    'ObjDir'            => '$(OBJDIR),+',
3436
 
3437
    'InterfaceDir'      => '$(INTERFACEDIR),+',
3438
    'InterfaceIncDir'   => '$(INCDIR_INTERFACE),+',
3439
    'InterfaceLibDir'   => '$(LIBDIR_INTERFACE)/$(GBE_PLATFORM),+',
3440
    'InterfaceBinDir'   => '$(BINDIR_INTERFACE)/$(GBE_PLATFORM)$(GBE_TYPE),+',
3441
 
3442
    'LocalDir'          => '$(LOCALDIR),+',
3443
    'LocalIncDir'       => '$(INCDIR_LOCAL),+',
3444
    'LocalLibDir'       => '$(LIBDIR_LOCAL)/$(GBE_PLATFORM),+',
3445
    'LocalBinDir'       => '$(BINDIR_LOCAL)/$(GBE_PLATFORM)$(GBE_TYPE),+',
3446
 
3447
    'Platform'          => '$(GBE_PLATFORM)',
3448
    'Product'           => '$(GBE_PRODUCT)',
3449
    'Target'            => '$(GBE_TARGET)',
3450
 
3451
    'Type'              => '$(GBE_TYPE)',
3452
    'Arch'              => '$(HOST_CPU)',
3453
    'Architecture'      => '$(HOST_CPU)',
3454
    'MachType'          => '$(GBE_HOSTMACH)',
3455
    'BuildRoot'         => '$(GBE_ROOT),+',
3456
 
3457
 
3458
    'Verbose'           => '$(CC_PRE)',
3459
    'LeaveTmp'          => '$(LEAVETMP)',
329 dpurdie 3460
    'Cwd'               => '$(CURDIR),-',
227 dpurdie 3461
 
3462
    'CompilerPath'      => '$(SCM_COMPILERPATH)',
3463
    );
3464
 
3465
sub ExpandGenVar
3466
{
3467
    my ($dname, $args, @uopts) = @_;
3468
    my $expansion;
3469
    my $prefix='';
3470
    my ($tag, @opts) = split('\s*,\s*', $args);
3471
    my $no_prefix;
285 dpurdie 3472
    my $default_value;
3473
    my $allow_none;
329 dpurdie 3474
    my $is_abs = 0;
227 dpurdie 3475
 
285 dpurdie 3476
    #
3477
    #   Parse options lists
3478
    #       Options provided by the caller
3479
    #       Options embedded in the argument
227 dpurdie 3480
    foreach ( @uopts )
3481
    {
3482
        if ( m/^--notag$/ ) {
3483
            $no_prefix = 1;
3484
        } else{
3485
            Error ("$dname: Unknown option: $_")
3486
        }
3487
    }
3488
 
285 dpurdie 3489
    foreach ( @opts )
3490
    {
3491
        if ( m/^--default=(.+)/i ) {
3492
            $default_value = $1;
3493
        } elsif ( m/^--allownone$/i ) {
3494
            $allow_none = 1;
3495
        }
3496
    }
3497
 
227 dpurdie 3498
    #
3499
    #   Perform run-time update on the %ExpandGenVarConvert
3500
    #   Most of it can be initialised at startup - but not all of it.
3501
    #
3502
    $ExpandGenVarConvert{CompilerPath} = undef unless $::ScmToolsetCompilerPath;
3503
    $ExpandGenVarConvert{Product}      = '$(GBE_PLATFORM)' unless $ScmProduct;
3504
 
3505
    #
3506
    #   Look up a hash of conversions
3507
    #   Could allow for a code ref, but not needed yet
3508
    #
3509
    Error ("$dname: Unknown expansion --Var($tag)")
3510
        unless ( exists $ExpandGenVarConvert{$tag} );
3511
 
285 dpurdie 3512
    #
3513
    #   Handle undefined expansions
3514
    #   Only 'CompilerPath', but it can be a pain in user land
3515
    #
3516
    $expansion = $ExpandGenVarConvert{$tag};
3517
    unless ( defined $expansion  )
3518
    {
3519
        return '' if ( $allow_none );
3520
        $expansion = $default_value;
3521
        Error ("$dname: Expansion --Var($tag) not be supported by toolset: $ScmToolset")
3522
            unless ( $expansion );
3523
    }
227 dpurdie 3524
 
285 dpurdie 3525
 
227 dpurdie 3526
    ($expansion,my $is_path) = split (',', $expansion );
329 dpurdie 3527
    $is_abs = 1
3528
        if ($is_path && $is_path eq '-' );
227 dpurdie 3529
 
3530
    #
3531
    #   Process options
3532
    #   Assume that a tag will be provided
3533
    #
3534
    $prefix =  $no_prefix ? '' : "-$tag=";
3535
    foreach my $opt ( @opts )
3536
    {
3537
        if ( $opt =~ /^--tag=(.*)/i ) {
3538
            $prefix = "$1=";
3539
 
3540
        } elsif ( $opt =~ m/^--tag$/i ) {
3541
            $prefix = "-$tag=";
3542
 
3543
        } elsif ( $opt =~ m/^--notag/i ) {
3544
            $prefix = '';
3545
 
329 dpurdie 3546
        } elsif ( $is_path && !$is_abs && $opt =~ /--abspath|--absdrive/i ) {
227 dpurdie 3547
            $expansion = '$(CURDIR)/' . $expansion;
329 dpurdie 3548
            $is_abs = 1;
227 dpurdie 3549
 
285 dpurdie 3550
        } elsif ( $opt =~ m/^--default=(.+)/i ) {
3551
            # Already processed
3552
        } elsif ( $opt =~ m/^--allownone$/i ) {
3553
            # Already processed
227 dpurdie 3554
        } else {
3555
            Error ("$dname: Unsupported option($opt) for --Var(@_)");
3556
        }
3557
    }
3558
 
3559
    Debug ("ExpandGenVar: args $args --> $prefix$expansion");
343 dpurdie 3560
    return $prefix , $expansion, $is_path ? 1 : 0, $is_abs;
227 dpurdie 3561
 
3562
}
3563
 
3564
#-------------------------------------------------------------------------------
3565
# Function        : ProcessPathName
3566
#
3567
# Description     : Massage a pathname according to a set of flags
3568
#
3569
# Inputs          : $fn         - Patchname to massage
3570
#                   $flags      - Flags in a string
3571
#                                   --dir       - only the directory part ( or a "." )
3572
#                                   --file      - only the file part
3573
#                                   --abspath   - Absolute path
3574
#                                   --absdrive  - Absolute path with drive letter(WIN)
3575
#
3576
# Returns         : Massaged pathname
3577
#
3578
sub ProcessPathName
3579
{
3580
    my ( $fn, $flags ) = @_;
3581
    #
3582
    #   Process flags
3583
    #       --dir           - only the directory part ( or a "." )
3584
    #       --file          - only the file part
3585
    #       --abspath       - Absolute path
3586
    #       --absdrive      - Absolute path with drive letter(WIN)
3587
    #
3588
    if ( $flags =~ /--dir/ )
3589
    {
3590
        $fn = '.'
3591
            unless ( $fn =~ s~/[^/]*$~~);
3592
    }
3593
 
3594
    if ( $flags =~ /--file/ )
3595
    {
3596
        $fn =~ s~.*/~~;
3597
    }
3598
 
3599
    if ( $flags =~ /--abspath/ )
3600
    {
3601
        $fn = AbsPath( $fn );
3602
    }
3603
    elsif ( $flags =~ /--absdrive/ )
3604
    {
3605
        $fn = AbsPath( $fn );
3606
        if ( $::ScmHost eq "WIN" )
3607
        {
3608
            $fn = $::CwdDrive . '/' . $fn
3609
                unless ( $fn =~ m~^\w:/~  );
3610
            $fn =~ s~//~/~g;
3611
        }
3612
    }
3613
 
3614
  return $fn;
3615
}
3616
 
3617
#-------------------------------------------------------------------------------
3618
# Function        : LocatePreReq
3619
#
3620
# Description     : Locate a file known to JATS
3621
#                   There are many places to search
3622
#                       1) Src files - specified with a Src directive
3623
#                       2) Scripts - specified with a script directive
3624
#                       3) Search - Files in the specified search path
3625
#                       4) Programs specified with a 'Prog' directive
3626
#
3627
#                   Should also look in other locations (Libs, SharedLibs)
3628
#                   Not done yet. May be issues of a name clash if a program
3629
#                   and a library have the same name.
3630
#
3631
# Inputs          : Name to locate
3632
#
3633
# Returns         : Full pathname of file
3634
#
3635
sub LocatePreReq
3636
{
3637
    my ( $name ) = @_;
3638
    Debug ("LocatePreReq:Looking for $name");
3639
    #
3640
    #   Try a Src file first
3641
    #
3642
    if ( exists $SRCS{ $name } )
3643
    {
3644
        return $SRCS{ $name };
3645
    }
3646
 
3647
    #
3648
    #   Try a script
3649
    #
3650
    if ( exists $SCRIPTS{ $name } )
3651
    {
3652
        return $SCRIPTS{ $name };
3653
    }
3654
 
3655
    #
3656
    #   Try a PROG
3657
    #
289 dpurdie 3658
    if ( my $pProg = $PROGS->Get($name) )
227 dpurdie 3659
    {
289 dpurdie 3660
        return $pProg->getPath();
227 dpurdie 3661
    }
3662
 
3663
    #
3664
    #   Try searching for the file
3665
    #   Uses Data from AddSrcDir
3666
    #
3667
    #   Done: last because it generates warning messages
3668
    #
3669
    return MakeSrcResolve( $name );
3670
}
3671
 
3672
#-------------------------------------------------------------------------------
3673
# Function        : ToolExtensionPaths
3674
#
3675
# Description     : Return a list of toolset extension directories
3676
#                   The data will have been discovered by the build process
3677
#                   and will have been saved for the makefile creation phase
3678
#
3679
# Inputs          : None
3680
#
3681
# Returns         : Return an ordered unique list
3682
#
3683
sub ToolExtensionPaths
3684
{
3685
    Debug( "ToolExtensionPaths:", @::BUILDTOOLSPATH );
3686
    return @::BUILDTOOLSPATH;
3687
}
3688
 
3689
#-------------------------------------------------------------------------------
3690
# Function        : ToolExtensionProgram
3691
#
3692
# Description     : Determine if the named program exists within the PATH
3693
#                   that also includes the toolset extension
3694
#
3695
# Inputs          : program             - Name of program
3696
#                   elist               - An array of possible program extensions
3697
#
3698
# Returns         : Full path the to program or undef
3699
#
3700
sub ToolExtensionProgram
3701
{
3702
    my ($program, @elist ) = @_;
3703
 
3704
    #
3705
    #   If elist is empty then insert a defined entry
3706
    #
3707
    push @elist, '' unless ( @elist );
3708
 
3709
    #
3710
    #   Scan all toolset directories
3711
    #   for the program
3712
    #
3713
    for my $dir ( ToolExtensionPaths() )
3714
    {
3715
        for my $ext ( @elist )
3716
        {
3717
            my $tool = "$dir/$program$ext";
3718
            Debug2( "ToolsetExtensionProgram: Look for: $tool" );
3719
 
3720
            return $tool if ( -f $tool );
3721
        }
3722
    }
3723
}
3724
 
3725
sub Define
3726
{
3727
    Debug2( "Define(@_)" );
3728
 
3729
    push( @DEFINES, @_ );
3730
}
3731
 
3732
 
3733
sub Defines
3734
{
3735
    my( $path, $script ) = @_;
3736
    my( $line );
3737
 
3738
    Debug2( "Defines($path, $script)" );
3739
 
3740
    $script = Exists( $path, $script, "Defines" );
271 dpurdie 3741
    push( @DEFINES, "# Defines from: $script" );
285 dpurdie 3742
    open( my $fh, '<', $script ) || Error( "Opening $script" );
3743
    while (<$fh>) {
227 dpurdie 3744
        $_ =~ s/\s*(\n|$)//;                    # kill trailing whitespace & nl
3745
        push( @DEFINES, $_ );
3746
    }
3747
    push( @ScmDepends, "$script" );             # makefile dependencies
285 dpurdie 3748
    close( $fh );
227 dpurdie 3749
}
271 dpurdie 3750
#-------------------------------------------------------------------------------
3751
# Function        : Rule
3752
#
3753
# Description     : Add a Rule and Recipe to the generated makefile
3754
#                   This is not encouraged as it has been misused to create
3755
#                   unreadable and unmaintainable makefiles.
3756
#
3757
#                   Rules will be added to the makefile after the rules and
3758
#                   recipes created by JATS directives
3759
#
3760
# Inputs          : $platform               - Platform predicate
3761
#                   @rule                   - Array of rules to add
3762
#
3763
# Returns         : 
3764
#
227 dpurdie 3765
sub Rule
3766
{
3767
    my( $platforms, @rule ) = @_;
3768
 
3769
    return if ( ! ActivePlatform($platforms) );
3770
 
3771
    push( @RULES, @rule );
3772
    Message("Rule directive used. Consider replacing with GenerateFiles");
3773
}
3774
 
271 dpurdie 3775
#-------------------------------------------------------------------------------
3776
# Function        : Rules
3777
#
3778
# Description     : Add a file of Rules and Recipes to the generated makefile
3779
#                   Used internally ONLY as there is no platform predicate
3780
#                   Similar to 'Rule()'
3781
#
3782
# Inputs          : $path                   - path to script
3783
#                   $script                 - File fo Rules
3784
#
3785
# Returns         : 
3786
#
227 dpurdie 3787
sub Rules
3788
{
3789
    my( $path, $script ) = @_;
3790
    my( $line );
3791
 
3792
    $script = Exists( $path, $script, "Rules" );
271 dpurdie 3793
    push( @RULES, "# Rules from: $script" );
285 dpurdie 3794
    open( my $fh, '<', $script ) || Error( "Opening $script" );
3795
    while (<$fh>) {
227 dpurdie 3796
        $_ =~ s/\s*(\n|$)//;                    # kill trailing whitespace & nl
3797
        push( @RULES, $_ );
3798
    }
3799
    push( @ScmDepends, "$script" );             # makefile dependencies
285 dpurdie 3800
    close( $fh );
227 dpurdie 3801
}
3802
 
271 dpurdie 3803
#-------------------------------------------------------------------------------
3804
# Function        : AddRule
3805
#
3806
# Description     : Inernal function
3807
#                   Add a line to the Rules area
3808
#
3809
# Inputs          : @elements                   - Array of lines to add
3810
#
3811
# Returns         : Nothing
3812
#
3813
sub AddRule
3814
{
3815
    push( @RULES, @_ );
3816
}
227 dpurdie 3817
 
271 dpurdie 3818
#-------------------------------------------------------------------------------
3819
# Function        : Src
3820
#
3821
# Description     : This directive is used to identify files to JATS
3822
#                   Once a file has been identified as a 'Source' file, then it
3823
#                   can be used by name, without the need to locate the file again.
3824
#                   This implies that filenames must be unique.
3825
#                   The directories cannot be used to make files of the same name
3826
#                   unqiue - this is not the JATS way
3827
#
3828
#                   Source files will be classified as one of:
3829
#                       c, c++, header, assembler or other
3830
#
3831
#
3832
# Inputs          : $platform               - Active Platform Predicate
3833
#                   @elements               - A list of files and options
3834
#
3835
#                   Valid options are:
3836
#                       --c                 - Specifies the type of file
3837
#                       --cpp
3838
#                       --h, --headers
3839
#                       --asm
3840
#                       --FromPackage       - Search packages for the file
3841
#                       --List=xxx          - Append file to a named list
3842
#                       --Depends=xxx       - Manually name a dependency
3843
#
3844
#                   Options are processed before file elements
3845
#                   Thus options apply to all files in the list
3846
#
3847
# Returns         : Nothing
3848
#
227 dpurdie 3849
sub Src
3850
{
3851
    my( $platforms, @elements ) = @_;
3852
    my( $type, @args, $source, $basename, $from_package, @lists );
3853
    my( @depends, @srcs );
3854
 
3855
    $platforms = '' unless ( $platforms );
3856
    Debug2( "Src($platforms, @elements)" );
3857
 
3858
    #
3859
    #   Ensure that there is a file within the list
3860
    #
3861
    Warning( "Src directive does not specify any files: Src($platforms, @elements)" )
3862
        unless (grep( /^[^-]/, @elements ) );
3863
 
3864
    return if ( ! ActivePlatform($platforms) );
3865
 
3866
    #
3867
    #   Remove spaces from both ends of the arguments.
3868
    #   It is easier to remove spaces now than to detect them later
3869
    #
3870
    foreach ( @elements )
3871
    {
3872
        s/^\s+//;
3873
        s/\s+$//;
3874
        s~//~/~g;                               # Remove multiple /
3875
    }
3876
 
3877
    #.. Collect arguments
3878
    #
3879
    $type = "";
3880
    foreach ( @elements )
3881
    {
3882
        if ( /^--c$/ )
3883
        {
3884
            Debug( "Src: --c" );
3885
            $type = ".c";
3886
        }
3887
        elsif ( /^--cpp$/ )
3888
        {
3889
            Debug( "Src: --cpp" );
3890
            $type = ".cc";
3891
        }
3892
        elsif ( /^--h$/ || /^--header$/ )
3893
        {
3894
            Debug( "Src: --h" );
3895
            $type = ".h";
3896
        }
3897
        elsif ( /^--asm$/ )
3898
        {
3899
            Debug( "Src: --asm" );
3900
            $type = ".asm";
3901
        }
3902
        elsif ( /^--FromPackage$/ )
3903
        {
3904
            $from_package = 1;
3905
        }
3906
        elsif ( /^--List=(.*)/ )
3907
        {
3908
            my $list_name = $1;
3909
            Error( "Bad list name: $list_name" )
3910
                unless ( $list_name =~ m/^[A-Za-z]\w+/ );
3911
            push @lists, $list_name;
3912
        }
3913
        elsif ( /^--Depends=(.*)/ )
3914
        {
3915
            foreach ( split( ',', $1) )
3916
            {
3917
                my $full = MakeSrcResolveExtended( $from_package, $_ );
3918
                push @depends, $full;
3919
            }
3920
        }
3921
        elsif ( /^-(.*)/ )
3922
        {
3923
            Debug( "Src: arg $_" );
3924
            push @args, $_;
3925
        }
3926
        else
3927
        {
3928
            push @srcs, $_;
3929
            Warning ("Src files contains a '\\' character: $_" ) if (m~\\~);
3930
        }
3931
    }
3932
 
3933
    #.. Push source file(s)
3934
    foreach ( @srcs )
3935
    {
3936
        if ( ! /^-(.*)/ )
3937
        {
3938
            $source = MakeSrcResolveExtended( $from_package, $_ );
3939
            $basename = StripDir( $source );
3940
            Debug( "Src: $_ -> $source=$basename (@args),(@depends)" );
3941
 
3942
            if ( $SRCS{ $basename } ) {
3943
                Warning( "Duplicate src ignored '$source'");
3944
                next;
3945
            }
3946
            $SRCS{ $basename } = $source;
3947
 
3948
            HashJoin( \%SRC_ARGS, $;, $basename, @args )
3949
                if (@args);
3950
 
3951
            HashJoin( \%SRC_DEPEND, $;, $basename, @depends )
3952
                if ( @depends );
3953
 
3954
            $SRC_TYPE{ $basename } = $type
3955
                if ($type);
3956
 
3957
 
3958
            foreach (@lists) {
3959
                my $lname_short = "LIST_$_";
3960
                my $lname_full = "LIST_FULL_$_";
3961
 
3962
                no strict 'refs';
3963
 
3964
                push @$lname_short,$basename;
3965
                push @$lname_full ,$source;
3966
 
3967
                use strict 'refs';
3968
            }
3969
 
3970
            __AddSourceFile( 1, $source, "", $type );
3971
        }
3972
    }
3973
}
3974
 
3975
 
3976
###############################################################################
3977
#  sub LibNameSplit
3978
#      Just a little help to deal with major/minor stuff for shared libs -
3979
#      given the name of the library as the argument, split out major and minor
3980
#      parts and return the basename, i.e name without major and minor and
3981
#      the pair of major and minor.
3982
###############################################################################
3983
 
3984
sub LibNameSplit
3985
{
3986
    my ( @bits ) = split('\.', $_[0]);
3987
    my ( $major, $minor );
3988
 
3989
    if ($#bits >= 1) {
3990
        $major = $bits[0]; $minor = $bits[1];
3991
    } elsif ($#bits >= 0) {
3992
        $major = $bits[0]; $minor = 0;
3993
    } else {
3994
        $major = 1; $minor = 0;
3995
    }
3996
    Debug( "LibName: $@_[0] ($major.$minor)" );
3997
    return ($major, $minor);
3998
}
3999
 
4000
#-------------------------------------------------------------------------------
4001
# Function        : Lib
4002
#
4003
# Description     : Generate a static library
4004
#
4005
# Inputs          : Platform specifier
4006
#                   Name of the library
4007
#                   Arguemnts ...
4008
#
4009
# Returns         :
4010
#
4011
sub Lib
4012
{
4013
    my( $platforms, $lib, @args ) = @_;
4014
    return if ( ! ActivePlatform($platforms) );
4015
 
4016
    Error ("Lib: Library name not defined") unless ( $lib );
4017
 
4018
    #
4019
    #   May be a shared library or a static library - for historic reasons
4020
    #   If the user has specified a --Shared then its a shared library
4021
    #
4022
    return SharedLib( @_ )
4023
        if ( grep (/^--Shared/, @args) );
4024
 
4025
    #
4026
    #   Does this toolset support libraries
4027
    #
4028
    Error ("Libraries are not supported") unless ( defined $::a );
4029
 
4030
    #.. Fully qualify library path for addition to library list.
4031
    $lib = "lib$lib"
4032
       if ( $ScmTargetHost eq "Unix" && $lib !~ m/^lib/);
4033
    Debug( "Lib: $lib" );
4034
 
4035
    #
289 dpurdie 4036
    #   Create a new object to describe the library
227 dpurdie 4037
    #   Ensure that only one such lib exists
289 dpurdie 4038
    #   Add the library to the list of static libraries
227 dpurdie 4039
    #
4040
    Error( "Library of the same name already defined: $lib" )
289 dpurdie 4041
        if ( $LIBS->Get($lib) );
4042
    $LIBS->NewAdd($lib);
227 dpurdie 4043
 
4044
    #
4045
    #   Process arguments
4046
    #
4047
    push( @LINTLIBS, $lib );
4048
    _LibArgs( $lib, @args );
4049
}
4050
 
4051
 
4052
#-------------------------------------------------------------------------------
4053
# Function        : SharedLib
4054
#
4055
# Description     : Generate a shared library
4056
#
4057
# Inputs          : Platform specifier
4058
#                   Name of the library
4059
#                   Arguemnts ...
4060
#
4061
# Returns         :
4062
#
4063
sub SharedLib
4064
{
4065
    my( $platforms, $lib, @args ) = @_;
4066
 
4067
    return if ( ! ActivePlatform($platforms) );
4068
 
4069
    Error ("SharedLib: Library name not defined") unless ( $lib );
4070
    Error ("Shared Libraries are not supported") unless ( defined $::so );
4071
 
4072
#.. Fully qualify library path for addition to library list.
4073
    $lib = "lib$lib"
4074
       if ( $ScmTargetHost eq "Unix" && $lib !~ m/^lib/);
4075
    Debug( "ShLib: $lib" );
4076
 
4077
    #
4078
    #   Ensure that only one such lib exists
4079
    #
289 dpurdie 4080
    Error( "Library of the same name already defined: $lib" )
4081
        if ( $SHLIBS->Get($lib) );
4082
    $SHLIBS->NewAdd($lib);
293 dpurdie 4083
 
227 dpurdie 4084
    #
4085
    #   If the user has not specified a --Shared parameter then provide one
4086
    #
4087
    push @args, "--Shared=Current"
4088
        unless ( grep (/^--Shared/, @args) );
4089
 
4090
    #
4091
    #   Process arguments
4092
    #
4093
    push( @LINTSHLIBS, $lib );
4094
    _SharedLibArgs( $lib, @args );
4095
}
4096
 
4097
 
4098
#-------------------------------------------------------------------------------
4099
# Function        : LibArgs
4100
#
4101
# Description     : Add arguments to an existing library directive
4102
#
4103
# Inputs          : Platform specifier
4104
#                   Name of the library
4105
#                   Arguemnts ...
4106
#
4107
# Returns         :
4108
#
4109
sub LibArgs
4110
{
4111
    my( $platforms, $lib, @args ) = @_;
4112
    return if ( ! ActivePlatform($platforms) );
4113
 
4114
#.. Fully qualify library path for addition to library list.
4115
    $lib = "lib$lib"
4116
       if ( $ScmTargetHost eq "Unix" && $lib !~ m/^lib/);
4117
    Debug( "LibArgs: $lib" );
4118
 
4119
    #
4120
    #   Process the arguments
4121
    #
4122
    _LibArgs( $lib, @args );
4123
}
4124
 
4125
 
4126
#-------------------------------------------------------------------------------
4127
# Function        : _LibArgs
4128
#
4129
# Description     : Process static library arguments
4130
#                   Internal use only
4131
#
4132
# Inputs          : Name of the library
4133
#                   Arguments to process
4134
#
4135
sub _LibArgs
4136
{
4137
    my( $lib, @elements) = @_;
4138
    my $obj;
4139
 
4140
    #
289 dpurdie 4141
    #   Ensure that only one such lib exists
4142
    #
4143
    my $libp = $LIBS->Get($lib);
4144
    Error("Library name not defined: $lib")
4145
        unless ( $libp );
4146
 
4147
    #
227 dpurdie 4148
    #   Process each element
4149
    #
4150
    foreach (@elements)
4151
    {
4152
        if ( /^--Shared/ )
4153
        {
4154
            Error( "--Shared not valid for a static library" );
4155
        }
4156
 
4157
        if ( /^-l(.*)/ || /^--l(.*)/ || /^-L(.*)/ || /^--L(.*)/ )
4158
        {
4159
        #.. Target library specified - add to library list.
4160
        #
4161
            Warning( "$_ within non shared library specification" );
4162
            next;
4163
        }
4164
 
4165
        if ( /^--if(.*)/ )
4166
        {
4167
            Warning( "$_ within non shared library specification" );
4168
            next;
4169
        }
4170
 
4171
        if ( /^--(.*)/ )
4172
        {
4173
            Debug( "LibArgs: arg $_" );
4174
 
4175
            #.. Argument specified - add to argument list
4176
            #
289 dpurdie 4177
            $libp->addItem('ARGS', $_);
4178
 
227 dpurdie 4179
            next;
4180
        }
4181
 
4182
        if ( defined %::ScmToolsetProgSource )
4183
        {
4184
            #
4185
            #   Toolset provides support for some file types
4186
            #   to be passed directly to the librarian builder
4187
            #
4188
            my $ext  = StripFile($_);
4189
            if ( exists ($::ScmToolsetProgSource{$ext}) )
4190
            {
4191
                my $full_path = MakeSrcResolve ( $_ );
4192
                my $flag = $::ScmToolsetProgSource{$ext};
4193
                Debug( "LibArgs: src $_" );
289 dpurdie 4194
                $libp->addItem('ARGS', "$flag$full_path" );
227 dpurdie 4195
                next;
4196
            }
4197
        }
4198
 
4199
        if ( $::o )
4200
        {
4201
        #.. Object specified - add to object list.
4202
        #
4203
            $obj = _LibObject( "", $_ );
4204
 
4205
        #.. Add to object list.
4206
        #   Note:   Object path must be explicit as several
4207
        #           toolsets add additional objects.
4208
        #
289 dpurdie 4209
            $libp->addItem('OBJS', "\$(OBJDIR)/$obj" );
227 dpurdie 4210
            next;
4211
        }
4212
 
4213
        #
4214
        #   Don't know how to handle this type of argument
4215
        #
4216
        Error ("LibArgs: Don't know how to handle: $_" );
4217
    }
4218
}
4219
 
4220
 
4221
#-------------------------------------------------------------------------------
4222
# Function        : SharedLibArgs
4223
#
4224
# Description     : Add arguments to an existing shared library directive
4225
#
4226
# Inputs          : Platform specifier
4227
#                   Name of the library
4228
#                   Arguemnts ...
4229
#
4230
# Returns         :
4231
#
4232
sub SharedLibArgs
4233
{
4234
    my( $platforms, $lib, @args ) = @_;
4235
    return if ( ! ActivePlatform($platforms) );
4236
 
4237
#.. Fully qualify library path for addition to library list.
4238
    $lib = "lib$lib"
4239
       if ( $ScmTargetHost eq "Unix" && $lib !~ m/^lib/);
4240
    Debug( "ShLibArgs: $lib" );
4241
 
4242
    _SharedLibArgs( $lib, @args );
4243
}
4244
 
4245
 
4246
#-------------------------------------------------------------------------------
4247
# Function        : _SharedLibArgs
4248
#
4249
# Description     : Process shared library arguments
4250
#                   Internal use only
4251
#
4252
# Inputs          : Name of the library
4253
#                   Arguments to process
4254
#
4255
sub _SharedLibArgs
4256
{
4257
    my ( $lib, @elements) = @_;
4258
 
289 dpurdie 4259
    my $libp = $SHLIBS->Get($lib);
4260
    Error("Library name not defined: $lib")
4261
        unless ( $libp );
4262
 
227 dpurdie 4263
    #
289 dpurdie 4264
    #.. Collect --Shared arguments
339 dpurdie 4265
    #   Need to process this one first so that we have a version number
227 dpurdie 4266
    #
4267
    foreach (@elements)
4268
    {
289 dpurdie 4269
        next unless ( /^--Shared/ );
4270
 
4271
        my $shared;
227 dpurdie 4272
        if ( /^--Shared$/ )
4273
        {
4274
        #.. Shared library, default library version 1.0
4275
        #
4276
            $shared = "1.0";
4277
        }
4278
        elsif ( /^--Shared=Current$/ )
4279
        {
4280
        #.. Shared library, using 'current' build version
4281
        #
4282
            $shared = $::ScmBuildVersion;
289 dpurdie 4283
            $shared = "1.0" if ($shared eq "");
227 dpurdie 4284
        }
4285
        elsif ( /^--Shared=(.*)/ )
4286
        {
4287
        #.. Shared library, specific version
4288
        #
4289
            my($M, $m) = LibNameSplit($1);
289 dpurdie 4290
            $shared = "$M.$m";
4291
        }
227 dpurdie 4292
 
289 dpurdie 4293
        #
4294
        #   Update the shared Names
4295
        #
4296
        if ( defined $shared )
4297
        {
227 dpurdie 4298
            Warning( "multiple --Shared arguments" )
339 dpurdie 4299
                if (exists $libp->{ VERSION });
227 dpurdie 4300
            Debug( "ShLibArgs: shared $_ ($shared)" );
289 dpurdie 4301
            $libp->{ VERSION } = $shared;
227 dpurdie 4302
        }
289 dpurdie 4303
        else
4304
        {
4305
            Error ("ShLibArgs: --Shared argument not understood");
4306
        }
227 dpurdie 4307
    }
4308
 
4309
 
4310
#.. Parse all of the object and argument entries.
4311
#
4312
    foreach (@elements)
4313
    {
289 dpurdie 4314
        next if ( /^--Shared(.*)/ );
227 dpurdie 4315
 
4316
        if ( /^[-]{1,2}([lL])(.*)/ )
4317
        {
4318
        #.. Target library specified - add to library list.
339 dpurdie 4319
        #   Support --L and -L and --l and -l
227 dpurdie 4320
        #
4321
            Debug( "ShLibArgs: lib  -$1$2" );
289 dpurdie 4322
            $libp->addItem('LIBS', "-$1$2" );
227 dpurdie 4323
            next;
4324
        }
4325
 
4326
        if ( /^--if(.*)/ )
4327
        {
4328
        #.. Library conditional - add to library list.
4329
        #
4330
            Debug( "ShLibArgs: cond $_" );
289 dpurdie 4331
            $libp->addItem('LIBS', $_);
227 dpurdie 4332
            next;
4333
        }
4334
 
339 dpurdie 4335
        if ( /^--SoName=(.*)/i )
4336
        {
4337
        #.. Specify the SoName of the library
4338
        #   Not supported by all toolsets
4339
        #
4340
            my $soMode = $1;
4341
            if ( !$ScmToolsetSoName )
4342
            {
4343
                Warning ("Toolset does not support --SoName. Option ignored");
4344
                next;
4345
            }
4346
 
4347
            Error ("SharedLib: $lib. Multiple --SoName arguments not allowed")
4348
                if ( $libp->{ SONAME } );
4349
 
4350
            my ($major, $minor, $patch, $build, $raw_patch) = SplitVersion($::ScmBuildVersionFull);
4351
            my $soname = '.';
4352
            if ( $soMode =~ m/Major/i ) {
4353
                $soname .= $major;
4354
            } elsif ( $soMode =~ m/^Minor/i ) {
4355
                $soname .= "$major.$minor";
4356
            } elsif ( $soMode =~ m/^Patch/i ) {
4357
                $soname .= "$major.$minor.$patch";
4358
            } elsif ( $soMode =~ m/^Build/i ) {
4359
                $soname .= "$major.$minor.$patch.$build";
4360
            } elsif ( $soMode =~ m/^Full/i ) {
4361
                $soname .= $libp->{ VERSION };
4362
            } elsif ( $soMode =~ m/^None/i ) {
4363
                $soname = '';
4364
            } elsif ( $soMode =~ m/^[0-9.]+$/ ) {
4365
                $soname .= $soMode;
4366
            } else {
4367
                Error ("Unknown --SoName mode: $soMode");
4368
            }
4369
            $libp->addItem('ARGS', '--SoNameSuffix=' . $soname);
4370
            $libp->{ SONAME } = 1;
4371
            next;
4372
        }
4373
 
227 dpurdie 4374
        if ( /^-(.*)/ )
4375
        {                           
4376
        #.. Argument specified - add to argument list
4377
        #
4378
            Debug( "ShLibArgs: arg  $_" );
289 dpurdie 4379
            $libp->addItem('ARGS', $_);
227 dpurdie 4380
            next;
4381
        }
4382
 
4383
        if ( defined %::ScmToolsetProgSource )
4384
        {
4385
            #
4386
            #   Toolset provides support for some file types
4387
            #   to be passed directly to the program builder
4388
            #
4389
            my $ext  = StripFile($_);
4390
            if ( exists ($::ScmToolsetProgSource{$ext}) )
4391
            {
4392
                my $full_path = MakeSrcResolve ( $_ );
4393
                my $flag = $::ScmToolsetProgSource{$ext};
4394
                Debug( "ShLibArgs: src $_" );
289 dpurdie 4395
                $libp->addItem('ARGS', "$flag$full_path");
227 dpurdie 4396
                next;
4397
            }
4398
        }
4399
 
4400
        if ( $::o )
4401
        {
4402
        #.. Object specified - add to object list.
4403
        #
4404
            my ($obj) = _LibObject( $lib, $_ );
4405
 
4406
        #.. Add to object list.
4407
        #   Note:   Object path must be explicit as several
4408
        #           toolsets add additional objects.
4409
        #
4410
            $SHOBJ_LIB{ $obj } = $lib;
289 dpurdie 4411
            $libp->addItem('OBJS', "\$(OBJDIR)/$obj");
227 dpurdie 4412
            next;
4413
        }
4414
 
4415
        #
4416
        #   Don't know how to handle this type of argument
4417
        #
4418
        Error ("SharedLib: Don't know how to handle: $_" );
4419
    }
4420
}
4421
 
4422
 
4423
#-------------------------------------------------------------------------------
4424
# Function        : _LibObject
4425
#
4426
# Description     : Process library object file
4427
#                   Common processing routine for static and shared library
4428
#                   Internal use only
4429
#
4430
# Inputs          : shared  - Name of the shared library is shared, if defined
4431
#                   fname   - Name of file
4432
#
4433
# Returns         : Name of the object file
4434
#
4435
sub _LibObject
4436
{
4437
    my ($shared, $fname) = @_;
4438
    my ($file, $ext, $obj, $srcfile, $delete_obj);
4439
 
4440
    #.. Object specified - add to object list.
4441
    #
4442
    $file = StripExt($fname);                   # file name, without extension
4443
    $ext  = StripFile($fname);                  # extension
4444
 
4445
    if ($shared) {
4446
        $obj = "$shared/$file";                 # library specific subdir
4447
    } else {
4448
        $obj = "$file";
4449
    }
4450
 
4451
    Debug( "LibObjs: obj [$shared]$fname ($file$ext)" );
4452
 
4453
    #.. Unqualified object name
4454
    #
4455
    if ( $ext eq "" )
4456
    {
4457
        #
4458
        #   Object file not covered by a "Src" statement
4459
        #   Assume that it will be created
4460
        #
4461
        unless ( $srcfile = $OBJSOURCE{ "$file" } )
4462
        {
4463
            #
4464
            #   If the object is "generated" then it will be is the
4465
            #   SRCS list
4466
            #
4467
            unless ( $srcfile = $SRCS{"$file.$::o"} )
4468
            {
4469
                Warning( "No source for object '$fname' ($file)" );
4470
            }
4471
        }
4472
        $delete_obj = 1;
4473
    }
4474
 
4475
    #.. Qualified object name (ie has extension)
4476
    #       Strip extension and resolve ...
4477
    #       Assume that the named file can be built into an object file
4478
    #
4479
    else
4480
    {
4481
        #.. Resolve
4482
        #
4483
        if ( !($srcfile = $OBJSOURCE{ "$file" }) )
4484
        {
4485
            $srcfile = MakeSrcResolve( $fname );
4486
            $SRCS{ $fname } = $srcfile;
4487
            __AddSourceFile( 0, $fname, $obj );
4488
            $delete_obj = 1;
4489
        }
4490
    }
4491
 
4492
    #.. Delete generated object file
4493
    #   Ensure that the object file is added to the delete list
4494
    #   Add it to the ToolsetObj deletion list as the main OBJ deleltion
4495
    #   list will aready have been processed
4496
    #
4497
    ToolsetObj( "\$(OBJDIR)/$obj" )
4498
        if ( $delete_obj );
4499
 
4500
 
4501
    #.. Shared library objects,
4502
    #       Must explicitly relate source and object, as shared libraries
4503
    #       objects are built within a library specific subdirs.
4504
    #
4505
    $OBJSOURCE{ $obj } = $srcfile
4506
        if ( $shared );
4507
 
4508
    return $obj;
4509
}
4510
 
4511
 
4512
# MergeLibrary
4513
#   Merge a list of libraries into one library
4514
#
4515
sub MergeLibrary
4516
{
4517
    my( $platforms, $lib, @elements ) = @_;
4518
 
4519
    return if ( ! ActivePlatform($platforms) );
4520
 
4521
 
4522
#.. Fully qualify library path for addition to library list.
4523
    $lib = "lib$lib"
4524
       if ( $ScmTargetHost eq "Unix" && $lib !~ m/^lib/);
4525
    Debug( "MergeLibrary: $lib" );
4526
 
289 dpurdie 4527
    #
4528
    #   Create a new object to describe the library
4529
    #   Ensure that only one such lib exists
4530
    #   Add the library to the list of static libraries
4531
    #
4532
    Error( "Merged Library of the same name already defined: $lib" )
4533
        if ( $MLIBS->Get($lib) );
4534
    my $libp = $MLIBS->NewAdd($lib);
4535
 
227 dpurdie 4536
#.. Parse all of the object and argument entries.
4537
#
4538
    foreach (@elements)
4539
    {
4540
        if ( /^--(.*)/ )
4541
        {
289 dpurdie 4542
            $libp->addItem('ARGS', $_);
227 dpurdie 4543
        }
4544
        else
4545
        {
4546
            my ($llib);
4547
 
4548
            #
4549
            #   Collect the source libraries
4550
            #   These must have been installed and will be in a known area
4551
            #   Create full names for the libaries
4552
            #
4553
            if ( $ScmTargetHost eq "Unix" ) {
4554
                $llib = "lib$_";                # Prefix "lib" ....
4555
                $lib =~ s/^liblib/lib/;         # @LIBS already has lib added
4556
            } else {
4557
                $llib = $_;
4558
            }
4559
 
4560
            Debug( "MergeLibrary: merge $llib" );
289 dpurdie 4561
            $libp->addItem('LIBS', $llib);
227 dpurdie 4562
        }
4563
    }
4564
}
4565
 
4566
#-------------------------------------------------------------------------------
4567
# Function        : Script
4568
#
4569
# Description     : Locate a script for test purposes
4570
#
4571
# Inputs          : $platforms      - Platform selector
4572
#                   $script         - A single script name
4573
#                   $execute        - Flag to indicate that the script is to
4574
#                                     marked as executable when used in a TestProg
4575
#                                     This flag is NOT used as the script will
4576
#                                     be forced executable
4577
#
4578
# Returns         : Nothing
4579
#
4580
sub Script
4581
{
4582
    my( $platforms, $script, $execute ) = @_;
4583
 
4584
    Debug2( "Script(@_)" );
4585
 
4586
    return if ( ! ActivePlatform($platforms) );
4587
 
4588
    #
4589
    #   Locate the script as a source file
4590
    #
4591
    my $file = MakeSrcResolve ( $script );
4592
    $script = StripDir( $file );
4593
    $SCRIPTS{ $script } = $file;
4594
}
4595
 
4596
#-------------------------------------------------------------------------------
4597
# Function        : RunTest
4598
#
4599
# Description     : Define a test to be run with the 'run_tests' and 'run_unit_tests'
4600
#
4601
# Inputs          : $platform       - Enabled for these platforms
4602
#                   $prog           - Program to run
4603
#                                     This SHOULD return a non-zero exit status
4604
#                                     on error. The program may be a 'TestProg'
4605
#                                     or a 'Script'.
4606
#                   @elements       - Options and test arguments
4607
#                                     Options are:
4608
#                                       --Auto          - Non interactive unit test
4609
#                                       --Unit          - Same and --Auto
4610
#                                       --CopyIn=file   - A file to be copied into
4611
#                                                         The test directory.
4612
#
4613
#                                     Non Options are passed to the test program.
4614
#                                     --PackageBase(xxx)    - Base of package
4615
#                                     --PackageInfo(xxx)    - Package information
4616
#                                     --File(xxx)           - Resolved name of file
4617
#                                     --Var(xxx)            - Expanded variable
4618
#                                     --Local(xxx)          - File within the local directory
4619
#
4620
# Returns         : Nothing
4621
#
4622
 
4623
sub RunTest
4624
{
4625
    my( $platforms, $prog, @elements ) = @_;
4626
    my $command = './';                 # program prefix / command
4627
    my $winprog = 1;                    # 1: Convert / -> \ (WIN32 only)
4628
    my $framework;
4629
    my @framework_opts;
4630
    my @copy = ();
4631
    my $auto;
4632
 
4633
    return if ( ! ActivePlatform($platforms) );
4634
 
4635
    #
4636
    #   Scan @elements and extract useful information
4637
    #   Need to process twice as some args will modify the
4638
    #   processing done later
4639
    #
4640
    my @args;
4641
    foreach ( @elements )
4642
    {
4643
        if ( m/^--FrameWork=(.+)/ ) {
4644
            $framework = $1;
4645
 
4646
        } elsif ( m/^--Auto/ || m/^--Unit/) {
4647
            $auto = 1;
4648
 
4649
        } elsif ( m/^--CopyIn=(.*)/ ) {
4650
            push @copy, MakeSrcResolve ( $1 );
4651
 
4652
 
4653
        } elsif ( $framework && m/^--\w+=(.+)/ ) {
4654
            push @framework_opts, $_;
4655
 
4656
        } else {
4657
            push @args, $_;
4658
        }
4659
    }
4660
    @elements = @args;
4661
    @args = ();
4662
 
4663
    #
4664
    #   Determine the source of the test prog
4665
    #   If using a plug-in framework, then we don;'t know
4666
    #   If not, then may be a script or a TESTPROGS
4667
    #
4668
 
4669
    unless ( $framework )
4670
    {
289 dpurdie 4671
        if ( $TESTPROGS->Get($prog) || $PROGS->Get($prog)  ) {
227 dpurdie 4672
            #
4673
            #   Append a suitable EXE suffix
4674
            #
289 dpurdie 4675
            $prog = GenProgName( $prog );
227 dpurdie 4676
 
4677
        } elsif ( exists $SCRIPTS{$prog} ) {
4678
            #
4679
            #   Script names are raw
4680
            #   Perl script are invoked directly
4681
            #
4682
            $command = "\$(GBE_PERL) -w "
4683
                if ( $prog =~ /\.pl$/ );
4684
 
4685
            #
4686
            #   Pass / to shells
4687
            #
4688
            $winprog = 0
4689
                unless ( $prog =~ m~\.bat$~ )
4690
 
4691
        } else {
4692
            Warning("RunTest program not known: $prog",
261 dpurdie 4693
                  "It is not a TestProg, Prog or a Script",
4694
                  "The test may fail" );
227 dpurdie 4695
        }
4696
    }
4697
 
4698
    #
4699
    #   Extract and process options
4700
    #
4701
    my @uargs = ();
4702
    my @preq_files;
4703
 
4704
    foreach my $arg (@elements) {
4705
        #
4706
        #   Process the tool arguments and extract file information
4707
        #   Extract all fields of the form:
4708
        #           --xxxxx(yyyyyy[,zzzzz])
4709
        #           --xxxxx{yyyyyyy}
4710
        #           --xxxxx[yyyyyyy] to allow embedded brackets
4711
        #
4712
        while ( $arg =~ m/--(\w+)               # --CommandWord         $1
4713
                                (               # Just for grouping
4714
                                \((.*?)\)   |   # Stuff like (yyyyy)    $3
4715
                                {(.*?)}     |   # or    like {yyyyy}    $4
4716
                                \[(.*?)\]       # or    like [yyyyy]    $5
4717
                                )/x )           # Allow comments and whitespace
4718
        {
4719
            my $cmd = $1;                       # The command
4720
            my $ufn = $3 || $4 || $5;           # User filename + options
4721
            my $mb = $-[0];                     # Match begin offset
4722
            my $me = $+[0];                     # Match end
4723
            my $flags = '';                     # Optional flags ( --dir or --file )
4724
            my $raw_arg = $ufn;                 # Raw arguments
285 dpurdie 4725
            my $all = substr( $arg, $mb, $me ); # All of match. Avoid use of $&
329 dpurdie 4726
            my $is_abs;
4727
            my $is_path = 1;
227 dpurdie 4728
 
4729
            Error ("RunTest. Empty element not allowed: $all")
4730
                unless ( defined($ufn) );
4731
 
4732
            $ufn =~ s/\s+$//;
4733
            $ufn =~ s~//~/~g;                   # Remove multiple /
4734
            if ( $ufn =~ m/(.*?),(.*)/ )        # Extract out any flags
4735
            {
4736
                $ufn = $1;
4737
                $flags = $2;
4738
            }
4739
 
4740
            my $fn = $ufn ;                     # Replacement filename
343 dpurdie 4741
            my $fnp = '';                       # Prefix to $fn
227 dpurdie 4742
            Error ("RunTest. Empty element not allowed: $all" )
4743
                if ( length ($ufn) <= 0 );
4744
 
4745
            #
4746
            #   Process found user command
4747
            #
4748
            if ( $cmd =~ /^File/ )
4749
            {
4750
                #
4751
                #   Prerequisite filename
4752
                #       Resolve the full name of the file. It may be known
4753
                #       as a source file (possibly generated) or it may be
4754
                #       located in a known source directory
4755
                #
4756
                $fn = MakeSrcResolve ( $ufn );
4757
                UniquePush (\@preq_files, $fn);
4758
 
4759
                Debug( "RunTest: Prereq: $fn" );
4760
 
4761
            }
4762
            elsif ( $cmd =~ /^PackageBase/ )
4763
            {
4764
                $fn = GetPackageBase( "RunTest", $raw_arg );
4765
                UniquePush (\@preq_files, $fn);
4766
            }
4767
            elsif ( $cmd =~ /^PackageInfo/ )
4768
            {
4769
                $fn = GetPackageInfo( "RunTest", $raw_arg );
4770
            }
4771
            elsif ( $cmd =~ /^Var/ )
4772
            {
343 dpurdie 4773
                ($fnp, $fn, $is_path, $is_abs) = ExpandGenVar( "RunTest", $raw_arg );
227 dpurdie 4774
                $flags = '';
4775
            }
4776
            elsif ( $cmd =~ /^Local/ )
4777
            {
4778
                $fn = '$(LOCALDIR)/' . $ufn ;
4779
                UniquePush (\@preq_files, $fn);
4780
            }
4781
            else
4782
            {
4783
                Warning ("RunTest: Unknown replacement command: $cmd");
4784
                $fn = $ufn;
4785
            }
4786
 
4787
            #
4788
            #   Process path modification flags
4789
            #       --dir           - only the directory part ( or a "." )
4790
            #       --file          - only the file part
4791
            #       --abspath       - Absolute path
4792
            #       --absdrive      - Absolute path with drive letter(WIN)
4793
            #
4794
            $fn = ProcessPathName( $fn, $flags );
4795
 
4796
            #
4797
            #   The program is going to be executed within a subdirectory
4798
            #   so add one more level of indirection to the path, but only if
4799
            #   the path is relative
4800
            #
329 dpurdie 4801
            if ( $is_path && ! $is_abs )
227 dpurdie 4802
            {
329 dpurdie 4803
                unless ( $fn =~ m~^/|^\w:/~  )
4804
                {
4805
                    $fn = '../' . $fn
4806
                        unless( $fn =~ s~=~=../~ );
4807
                    $fn =~ s~/.$~~;
4808
                }
227 dpurdie 4809
            }
4810
 
4811
            #
4812
            #   Minor kludge under windows. Ensure directores have a "\" sep
4813
            #   Unless the user has specified a straight shell command
4814
            #
303 dpurdie 4815
            $fn = "\$(subst /,\\,$fn)"
227 dpurdie 4816
                if ( $::ScmHost eq "WIN" && $winprog );
4817
 
4818
            #
343 dpurdie 4819
            #   Prepend any $fn Prefix
4820
            #   This will be a tag and is not subject to path processing
4821
            #
4822
            $fn = $fnp . $fn;
4823
 
4824
            #
227 dpurdie 4825
            #   Replace the found string with the real name of the file
4826
            #   Note: 4 argument version of substr is not always available
4827
            #         so we must do it the hard way
4828
            #               substr( $arg, $mb, $me - $mb, $fn);
4829
            #
4830
            $arg = substr( $arg, 0, $mb ) . $fn . substr( $arg, $me );
4831
 
4832
            Debug2( "RunTest: subs: $all -> $fn" );
4833
        }
4834
        push(@uargs, "'$arg'");
4835
    }
4836
 
4837
    #
4838
    #   Create the test entry
4839
    #   This is a structure that will be placed in an array
4840
    #   The array preserves order and uniqness
4841
    #
4842
    my %test_entry;
4843
    $test_entry{'framework'}= $framework if ( $framework );
4844
    $test_entry{'framework_opts'}= \@framework_opts if ( $framework );
4845
    $test_entry{'command'}  = $command . $prog unless ( $framework);
4846
 
4847
    $test_entry{'prog'}     = $prog;
4848
    $test_entry{'copyprog'} = 1;
4849
    $test_entry{'args'}     = \@uargs;
4850
    $test_entry{'auto'}     = $auto if ( $auto );
4851
    $test_entry{'copyin'}   = \@copy;
4852
    $test_entry{'copyonce'} = ();
4853
    $test_entry{'preq'}     = \@preq_files;
4854
    $test_entry{'testdir'}  = 'BINDIR';
4855
 
4856
    push ( @TESTS_TO_RUN, \%test_entry );
4857
 
4858
    #
4859
    #   Flag Auto Run processing required
4860
    #
4861
    $TESTS_TO_AUTORUN = 1 if ( $auto );
4862
}
4863
 
4864
 
4865
sub TestProg
4866
{
4867
    my( $platforms, $prog, @elements ) = @_;
4868
 
4869
    Debug2( "TestProg($platforms, $prog, @elements)" );
4870
 
4871
    return if ( ! ActivePlatform($platforms) );
4872
 
4873
    Error ("TestProg: Program name not defined") unless ( $prog );
4874
    Error ("Programs are not supported") unless ( defined $::exe );
4875
 
289 dpurdie 4876
    #
4877
    #   Create a new Prog object, or retrieve any existing one
4878
    #
4879
    my $pProg = $TESTPROGS->Get($prog);
4880
    $pProg = $TESTPROGS->NewAdd($prog)
4881
        unless ( $pProg );
227 dpurdie 4882
 
4883
#.. Parse all of the object, library and argument entries
4884
    Debug( "TestProg: $prog" );
4885
    foreach (@elements)
4886
    {
4887
        if ( /^[-]{1,2}([lL])(.*)/ )
4888
        {
4889
        #.. Target Library specified - add to library list.
4890
        #  
4891
            Debug( "TestProg: lib  -$1$2" );
289 dpurdie 4892
            $pProg->addItem('LIBS', "-$1$2");
227 dpurdie 4893
            next;
4894
        }
4895
 
4896
        if ( /^--if(.*)/ )
4897
        {
4898
        #.. Library conditional - add to library list.
4899
        #
4900
            Debug( "TestProg: cond $_" );
289 dpurdie 4901
            $pProg->addItem('LIBS', $_);
227 dpurdie 4902
            next;
4903
        }
4904
 
4905
        if ( /^-(.*)/ )
4906
        {
4907
        #.. Argument specified - add to argument list
4908
        #
4909
            Debug( "TestProg: arg $_" );
289 dpurdie 4910
            $pProg->addItem('ARGS', $_);
227 dpurdie 4911
            next;
4912
        }
4913
 
4914
        if ( defined %::ScmToolsetProgSource )
4915
        {
4916
            #
4917
            #   Toolset provides support for some file types
4918
            #   to be passed directly to the program builder
4919
            #
4920
            my $ext  = StripFile($_);
4921
            if ( exists ($::ScmToolsetProgSource{$ext}) )
4922
            {
4923
                my $full_path = MakeSrcResolve ( $_ );
4924
                my $flag = $::ScmToolsetProgSource{$ext};
4925
                Debug( "TestProg: src $_" );
289 dpurdie 4926
                $pProg->addItem('ARGS', "$flag$full_path");
227 dpurdie 4927
                next;
4928
            }
4929
        }
4930
 
4931
        if ( $::o )
4932
        {
4933
        #.. Object specified - add to object list.
4934
        #
4935
            my $obj = _LibObject( "", $_ );
4936
 
4937
        #.. Add to program object list.
289 dpurdie 4938
            $pProg->addItem('OBJS', "\$(OBJDIR)/$obj");
227 dpurdie 4939
            next;
4940
        }
4941
 
4942
        #
4943
        #   Don't know how to handle this type of argument
4944
        #
4945
        Error ("TestProg: Don't know how to handle: $_" );
4946
    }
4947
}
4948
 
4949
 
4950
sub Prog
4951
{
4952
    my( $platforms, $prog, @elements ) = @_;
4953
 
4954
    Debug2( "Prog($platforms, $prog, @elements)" );
4955
 
4956
    return if ( ! ActivePlatform($platforms) );
4957
 
4958
    Error ("Prog: Program name not defined") unless ( $prog );
4959
    Error ("Programs are not supported") unless ( defined $::exe );
4960
 
289 dpurdie 4961
    #
4962
    #   Create a new Prog object, or retrieve any existing one
4963
    #
4964
    my $pProg = $PROGS->Get($prog);
4965
    $pProg = $PROGS->NewAdd($prog)
4966
        unless ( $pProg );
227 dpurdie 4967
 
4968
#.. Parse all of the object, library and argument entries
4969
    Debug( "Prog: $prog" );
4970
    foreach (@elements)
4971
    {
4972
        if ( /^[-]{1,2}([lL])(.*)/ )
4973
        {
4974
        #.. Target Library specified - add to library list.
4975
        #  
4976
            Debug( "Prog: lib  -$1$2" );
289 dpurdie 4977
            $pProg->addItem('LIBS', "-$1$2");
227 dpurdie 4978
            next;
4979
        }
4980
 
4981
        if ( /^--if(.*)/ )
4982
        {
4983
        #.. Library conditional - add to library list.
4984
        #
4985
            Debug( "Prog: cond $_" );
289 dpurdie 4986
            $pProg->addItem('LIBS', $_);
227 dpurdie 4987
            next;
4988
        }
4989
 
4990
        if ( /^-(.*)/ )
4991
        {
4992
        #.. Argument specified - add to argument list
4993
        #
4994
            Debug( "Prog: arg $_" );
289 dpurdie 4995
            $pProg->addItem('ARGS', $_);
227 dpurdie 4996
            next;
4997
        }
4998
 
4999
        if ( defined %::ScmToolsetProgSource )
5000
        {
5001
            #
5002
            #   Toolset provides support for some file types
5003
            #   to be passed directly to the program builder
5004
            #
5005
            my $ext  = StripFile($_);
5006
            if ( exists ($::ScmToolsetProgSource{$ext}) )
5007
            {
5008
                my $full_path = MakeSrcResolve ( $_ );
5009
                my $flag = $::ScmToolsetProgSource{$ext};
5010
                Debug( "Prog: src $_" );
289 dpurdie 5011
                $pProg->addItem('ARGS', "$flag$full_path");
227 dpurdie 5012
                next;
5013
            }
5014
        }
5015
 
5016
        if ( $::o )
5017
        {
5018
        #.. Object specified - add to object list.
5019
        #
5020
            my $obj = _LibObject( "", $_ );
5021
 
5022
        #.. Add to program object list.
289 dpurdie 5023
            $pProg->addItem('OBJS', "\$(OBJDIR)/$obj");
227 dpurdie 5024
            next;
5025
        }
5026
 
5027
        #
5028
        #   Don't know how to handle this type of argument
5029
        #
5030
        Error ("Prog: Don't know how to handle: $_" );
5031
    }
5032
}
5033
 
5034
#-------------------------------------------------------------------------------
5035
# Function        : ProgAddExtra
5036
#
5037
# Description     : This (internal) function allows a toolset to list additional
5038
#                   binaries as a part of a program. This will ensure that the
5039
#                   binaries are generated in the 'make_prog' phase with the main
5040
#                   program.
5041
#
5042
#                   The files are not listed for packaging, by this function
5043
#
5044
#                   The function does not ensure that the files are not already
5045
#                   listed as a @PROG ( as @PROGS is not fully resolved at this point )
5046
#
5047
# Inputs          :     $name               - Tag name of program being built
5048
#                                             Not used (yet)
5049
#                       $prog               - Fully resolved path to a file
5050
#
5051
# Returns         : Nothing
5052
#
5053
sub ProgAddExtra
5054
{
5055
    my ($name, $prog) = @_;
5056
    Debug2( "ProgAddExtra($name: $prog)" );
5057
 
5058
    UniquePush(\@PROGS_EXTRA, $prog);
5059
}
5060
 
5061
#-------------------------------------------------------------------------------
5062
# Function        : MakeProject
5063
#
5064
# Description     : A nasty directive that is intended to build a Microsoft
5065
#                   project for WINCE, WIN32 and .NET builds.
5066
#
5067
#                   There are many constraints:
5068
#                       Cannot be mixed with multi-platform builds
5069
#                       Some parameters are tool specific
5070
#
267 dpurdie 5071
#                   Allow programs to be Installed as well as Packaged
5072
#                   The 'Progect' is treated' as a program and it doesn't work
5073
#                   to well if we Install libraries.
227 dpurdie 5074
#
267 dpurdie 5075
#                   Only Reason to Install Programs is to allow the Cab Maker
5076
#                   to locate them.
5077
#
227 dpurdie 5078
# Inputs          : Platform        - Active platform
5079
#                   Project         - Project Name with extension
5080
#                   Options         - Many options
5081
#
5082
# Returns         :
5083
#
5084
our %PROJECTS;                          # Project information
5085
my  @PROJECTS_ORDER;
5086
sub MakeProject
5087
{
5088
    my( $platforms, $proj, @elements ) = @_;
5089
 
5090
    Debug2( "MakeProject($platforms, $proj, @elements)" );
5091
 
5092
    return if ( ! ActivePlatform($platforms) );
5093
 
5094
    #
5095
    #   Sanity test
5096
    #
5097
    Error ("MakeProject: Project name not defined") unless ( $proj );
5098
 
5099
    #
5100
    #   Take the project name and convert it into a full path
5101
    #
5102
    my $project = MakeSrcResolve ( $proj );
5103
    $proj = StripDir( $project );
237 dpurdie 5104
    Error ("Project File Not found: $project") unless ( -f $project );
227 dpurdie 5105
 
5106
    my $basedir = StripFileExt( $project );
5107
 
5108
    #
5109
    #   Collect user arguments
5110
    #   They are all processed within the toolset
5111
    #
5112
    my @tool_options;
5113
    foreach ( @elements )
5114
    {
5115
        if ( m/^--Debug/ ) {
5116
            $PROJECTS{$proj}{'Debug'} = 1;
5117
 
5118
        } elsif ( m/^--Prod/ ) {
5119
            $PROJECTS{$proj}{'Prod'} = 1;
5120
 
267 dpurdie 5121
        } elsif ( m/^--(Package|Install)ProgDebug=(.*)/ ) {
5122
            _PackageFromProject( $1, $proj, $basedir,'Prog', 'D', $2 );
227 dpurdie 5123
 
267 dpurdie 5124
        } elsif ( m/^--(Package|Install)Prog(Prod)*=(.*)/ ) {
5125
            _PackageFromProject( $1, $proj, $basedir, 'Prog', 'P', $3 );
227 dpurdie 5126
 
267 dpurdie 5127
        } elsif ( m/^--(Package)LibDebug=(.*)/ ) {
5128
            _PackageFromProject( $1, $proj, $basedir, 'Lib', 'D', $2 );
227 dpurdie 5129
 
267 dpurdie 5130
        } elsif ( m/^--(Package)Lib(Prod)*=(.*)/ ) {
5131
            _PackageFromProject( $1, $proj, $basedir, 'Lib', 'P', $3 );
227 dpurdie 5132
 
267 dpurdie 5133
        } elsif ( m/^--(Package)SharedLibDebug=(.*)/ ) {
5134
            _PackageFromProject( $1, $proj, $basedir, 'Lib', 'D', $2 );
227 dpurdie 5135
 
267 dpurdie 5136
        } elsif ( m/^--(Package)SharedLib(Prod)*=(.*)/ ) {
5137
            _PackageFromProject( $1, $proj, $basedir, 'Lib', 'P', $3 );
227 dpurdie 5138
 
267 dpurdie 5139
        } elsif ( m/^--(Package)Hdr=(.*)/ ) {
5140
            _PackageFromProject( $1, $proj, $basedir, 'Hdr', undef, $2 );
227 dpurdie 5141
 
267 dpurdie 5142
        } elsif ( m/^--(Package)File=(.*)/ ) {
5143
            _PackageFromProject( $1, $proj, $basedir, 'File', undef, $2 );
227 dpurdie 5144
 
267 dpurdie 5145
        } elsif ( m/^--(Package)Tool(Prod)*=(.*)/ ) {
5146
            _PackageFromProject( $1, $proj, $basedir, 'Tool', 'P', $3 );
241 dpurdie 5147
 
267 dpurdie 5148
        } elsif ( m/^--(Package)ToolDebug=(.*)/ ) {
5149
            _PackageFromProject( $1, $proj, $basedir, 'Tool', 'D', $2 );
241 dpurdie 5150
 
267 dpurdie 5151
        } elsif ( m/^--(Package|Install)/ ) {
5152
            Error("MakeProject. Unknown $1 option: $_");
227 dpurdie 5153
 
5154
        } else {
5155
            push @tool_options, $_;
5156
        }
5157
    }
5158
 
5159
    #
5160
    #   Save the information
5161
    #
5162
    $PROJECTS{$proj}{'options'} = \@tool_options;
5163
    $PROJECTS{$proj}{'name'} = $proj;
5164
    $PROJECTS{$proj}{'project'} = $project;
5165
    $PROJECTS{$proj}{'basedir'} = $basedir;
5166
    UniquePush (\@PROJECTS_ORDER, $proj);
5167
 
5168
    #
5169
    #   Validate some of the arguments
5170
    #
5171
    Error ("Makeproject. Conflicting options --Debug and --Prod" )
5172
        if ( $PROJECTS{$proj}{'Debug'}  && $PROJECTS{$proj}{'Prod'} );
5173
}
5174
 
5175
#-------------------------------------------------------------------------------
5176
# Function        : _PackageFromProject
5177
#
5178
# Description     : Save Packaged data from the project
5179
#
267 dpurdie 5180
# Inputs          : $tgt        - Install or Package
5181
#                   $proj       - Name of the project
227 dpurdie 5182
#                   $base       - Base directory of files
5183
#                   $etype      - Type of Package (Progs, Libs, ... )
5184
#                   $type       - Debug or Production or both
5185
#                   $items      - Item to add. It may be comma seperated
5186
#
267 dpurdie 5187
my %PackageToData = ( 'Package' =>
5188
                        { 'Hdr'   => \%PACKAGE_HDRS,
5189
                          'Lib'   => \%PACKAGE_LIBS,
5190
                          'Prog'  => \%PACKAGE_PROGS,
5191
                          'File'  => \%PACKAGE_FILES,
5192
                          'Tool'  => \%PACKAGE_FILES,
5193
                          '_BASE' => 'PBase',
5194
                        },
5195
                      'Install' =>
5196
                        { 'Hdr'   => \%INSTALL_HDRS,
5197
                          'Lib'   => \%INSTALL_LIBS,
5198
                          'Prog'  => \%INSTALL_PROGS,
5199
                          'File'  => undef,
5200
                          'Tool'  => undef,
5201
                          '_BASE' => 'IBase',
5202
                        },
227 dpurdie 5203
                    );
5204
 
5205
sub _PackageFromProject
5206
{
267 dpurdie 5207
    my( $tgt, $proj, $base, $etype, $type, $items ) = @_;
227 dpurdie 5208
    my $subdir = '';
5209
 
5210
    #
267 dpurdie 5211
    #   Sanity test
5212
    #
5213
    $type = '' unless ( $type );
5214
    Error ("INTERNAL. Bad packaging option: $tgt")   unless ( exists $PackageToData{$tgt} );
5215
    Error ("INTERNAL. Bad packaging option: $etype") unless ( exists $PackageToData{$tgt}{$etype} );
5216
    Error ("Unsupported packaging combination: $tgt$etype$type=$items") unless ( defined $PackageToData{$tgt}{$etype} );
5217
 
5218
    #
5219
    #   Determine the index into the 'PackageInfo' structure
5220
    #   This provides the symbolic name for the target package path
5221
    #   for Package or Install
5222
    #
5223
    #   The key '_BASE' is internal. Used only to provide this information
5224
    #
5225
    my $tbase = $PackageToData{$tgt}{'_BASE'};
5226
 
5227
    #
227 dpurdie 5228
    #   Process options
5229
    #
5230
    foreach my $item ( split (/,/, $items ) )
5231
    {
5232
        next unless ( $item =~ m/^--/ );
5233
        if ( $item =~ m/^--Subdir=(.*)/ )
5234
        {
5235
            $subdir = '/' . $1;
5236
            $subdir =~ s~//~/~g;
5237
            $subdir =~ s~/$~~g;
5238
        }
5239
        else
5240
        {
5241
            Warning( "MakeProject: Unknown packaging option ignored: $_" );
5242
        }
5243
    }
5244
 
5245
    #
5246
    #   Process files
5247
    #
5248
    foreach my $item ( split (/,/, $items ) )
5249
    {
5250
        next if ( $item =~ m/^--/ );
5251
 
267 dpurdie 5252
        my $tdir = $PackageInfo{$etype}{$tbase} . $PackageInfo{$etype}{'Dir'} . $subdir ;
227 dpurdie 5253
        my $fname = StripDir( $item );
5254
        my $target = $tdir . '/' . $fname;
5255
 
5256
        $item = "$base/$item" if ( $base );
5257
 
5258
        #
5259
        #   Do not use $(GBE_TYPE) in the target name
5260
        #   The existing package mechanism does not handle different
5261
        #   production and debug file naming mechanism, whereas the project
5262
        #   must. Convert $(GBE_TYPE) into P or D to ensure uniquness
5263
        #
5264
        $target =~ s~\$\(GBE_TYPE\)~$type~ if ($type);
5265
 
5266
        #
5267
        #   Create a PACKAGE entry suitable for processing by the normal packaging
5268
        #   routines. This is complicated because the Projects do not adhere to
267 dpurdie 5269
        #   the JATS file name conventions
227 dpurdie 5270
        #
5271
        my %package_entry;
5272
        $package_entry{'src'}   = $item;
5273
        $package_entry{'dir'}   = $tdir;
267 dpurdie 5274
        $package_entry{'set'}   = 'ALL' if ($tgt eq 'Package');
227 dpurdie 5275
        $package_entry{'type'}  = $type if ($type);
5276
 
267 dpurdie 5277
        $PackageToData{$tgt}{$etype}->{$target} = {%package_entry};
227 dpurdie 5278
    }
5279
}
5280
 
5281
#-------------------------------------------------------------------------------
5282
# Function        : MakeAnt
5283
#
5284
# Description     : A nasty directive to create JAR files via ANT
5285
#                   There are several limitations
5286
#                   This is closely related to the MakeProject directive
5287
#
5288
#
5289
# Inputs          : Platform            - Active platform
5290
#                   buildfile           - Name of the build.xml file
5291
#                   Options             - A few options
5292
#                                         --Jar=file
5293
#                                               Generated JAR file(s)
5294
#                                         --GeneratedFile=file
5295
#                                               Other generated files
5296
#                                               Used to flag JNI that must
5297
#                                               Occur early
5298
#                                          --AutoTest=<name>
5299
#                                               Supports unitAutomated unit test
5300
#                                               by calling build target <name>
5301
#                                          --UnitTest=<name>
5302
#                                               Supports unit test
5303
#                                               by calling build target <name>
5304
#                                          --PackageBase
5305
#                                               Provides path to base of all packages
5306
#
5307
# Returns         :
5308
#
5309
our %JAR_FILES;
5310
sub MakeAnt
5311
{
5312
    my( $platforms, $proj, @elements ) = @_;
5313
 
5314
    Debug2( "MakeAnt($platforms, $proj, @elements)" );
5315
 
5316
    return if ( ! ActivePlatform($platforms) );
5317
 
5318
    #
5319
    #   Sanity test
5320
    #
5321
    Error ("MakeAnt: build.xml name not defined") unless ( $proj );
5322
 
5323
    #
5324
    #   Take the project name and convert it into a full path
5325
    #
5326
    my $project;
5327
    $project = MakeSrcResolve ( $proj );
5328
    $proj = StripDir( $project );
237 dpurdie 5329
    Error ("Build File Not found: $project") unless ( -f $project );
227 dpurdie 5330
 
5331
    my $basedir = StripFileExt( $project );
5332
 
5333
    #
5334
    #   Collect user arguments
5335
    #   They are all processed within the toolset
5336
    #
5337
    my @tool_options;
5338
    my @generated;
5339
    my $unit_tests;
5340
    my $auto_tests;
5341
    my $package_base;
5342
 
5343
    foreach ( @elements )
5344
    {
5345
        if ( m/^--Debug/ ) {
5346
            $PROJECTS{$proj}{'Debug'} = 1;
5347
 
5348
        } elsif ( m/^--Prod/ ) {
5349
            $PROJECTS{$proj}{'Prod'} = 1;
5350
 
5351
        } elsif ( m/^--Jar=(.*)/ ) {
5352
            my $tgt = $1;
5353
               $tgt = "$basedir/$tgt" if ( $basedir );
5354
            my $fn = StripDir( $1 );
5355
            $JAR_FILES{$fn} = $tgt;
5356
            GenerateSrcFile( 0, $tgt );
5357
 
5358
        } elsif ( m/^--GeneratedFile=(.*)/ ) {
5359
            my $tgt = $1;
5360
            $tgt = "$basedir/$tgt" if ( $basedir );
5361
            push @generated, $tgt;
5362
            GenerateSrcFile( 2, $tgt );
5363
 
5364
        } elsif ( m/^--UnitTest=(.*)/ ) {
5365
            $unit_tests = $1
5366
 
5367
        } elsif ( m/^--AutoTest=(.*)/ ) {
5368
            $auto_tests = $1
5369
 
5370
        } elsif ( m/^--PackageBase/ ) {
5371
            $package_base = 1;
5372
 
5373
 
5374
        } elsif ( m/^--/ ) {
5375
            Error("MakeAnt. Unknown option ignored: $_");
5376
 
5377
        } else {
5378
            push @tool_options, $_;
5379
        }
5380
    }
5381
 
5382
    #
5383
    #   Extend option arguments to include the base dir of packages
5384
    #   Create definitions of the form PACKAGE_<name>
5385
    #
5386
    for my $entry (@{$::ScmBuildPkgRules{$ScmPlatform} })
5387
    {
5388
        next unless ( $entry->{'TYPE'} eq 'link' );
5389
        my $dir = $entry->{'ROOT'};
5390
        my $name = $entry->{'NAME'};
5391
        unless ( $package_base )
5392
        {
5393
            $dir .= '/jar';
5394
            next unless ( -d $dir );
5395
        }
5396
        push @tool_options, "-DPACKAGE_$name=$dir";
5397
    }
5398
    #
5399
    #   Extend options to include the base dir of the created package
5400
    #   Allows careful use for direct packaging of artifacts
5401
    #
5402
    push @tool_options, '-DPACKAGEDIR=$(PWD)/$(PKGDIR)';
5403
 
5404
    #
5405
    #   Save the information
5406
    #
5407
    $PROJECTS{$proj}{'options'} = \@tool_options;
5408
    $PROJECTS{$proj}{'generated'} = \@generated if ( @generated );
5409
    $PROJECTS{$proj}{'name'}    = $proj;
5410
    $PROJECTS{$proj}{'project'} = $project;
5411
    $PROJECTS{$proj}{'basedir'} = $basedir;
5412
    $PROJECTS{$proj}{'type'}    = 'ant';
5413
    $PROJECTS{$proj}{'unittest'} = $unit_tests if ( $unit_tests );
5414
    $PROJECTS{$proj}{'autotest'} = $auto_tests if ( $auto_tests );
5415
    UniquePush (\@PROJECTS_ORDER, $proj);
5416
 
5417
    $TESTS_TO_AUTORUN = 1 if ( $auto_tests );
263 dpurdie 5418
    $TESTS_TO_RUN = 1 if ( $unit_tests || $auto_tests );
227 dpurdie 5419
 
5420
    #
5421
    #   Validate some of the arguments
5422
    #
5423
    Error ("MakeAnt. Conflicting options --Debug and --Prod" )
5424
        if ( $PROJECTS{$proj}{'Debug'}  && $PROJECTS{$proj}{'Prod'} );
5425
}
5426
 
5427
###############################################################################
5428
#
5429
#   Installation/Packaging util functions
5430
#
5431
#-------------------------------------------------------------------------------
5432
# Function        : __TargetDir
5433
#
5434
# Description     : Internal function to process common arguments for
5435
#                   the PackageXxx directives
5436
#
5437
# Inputs          : flags           - Indicate how to handle this argument
5438
#                   base            - Base directory for this type of package
5439
#                   argument        - Argument to process
5440
#                   pdir            - Reference to resultant directory
5441
#                   ptype           - Reference to resultant type (P or D)(optional)
5442
#
5443
# Returns         : 0               - Agument not consumed
5444
#                   1               - Argument consumed
5445
#                   2               - Skip this directive
5446
#
5447
my $T_TYPE  = 0x0001;                           # Postfix GBE_TYPE
5448
my $T_PKG   = 0x0002;                           # Special --Dir handling
5449
my $T_MACH  = 0x0004;                           # Allow --Machine too
5450
my $T_GBE   = 0x0008;                           # Allow --Gbe too
5451
my $T_FILE  = 0x0010;                           # Suffix or prefix subdir
5452
 
5453
sub __TargetDir
5454
{
5455
    my( $flags, $base, $argument, $pdir, $ptype ) = @_;
5456
    my $dir  = "";
5457
    my $consumed = 0;
5458
 
5459
    #
5460
    #   Generate basic parts
5461
    #   Note Product will default to Platform
5462
    #
5463
    my $str_platform = '$(GBE_PLATFORM)';
5464
    my $str_product = $ScmProduct ? '$(GBE_PRODUCT)' : '$(GBE_PLATFORM)';
5465
    my $str_target = '$(GBE_TARGET)';
5466
    my $str_common = '$(GBE_OS_COMMON)';
5467
 
5468
    my $str_common_avail = 0;
5469
       $str_common_avail = 1 if ( exists( $::BUILDINFO{$ScmPlatform}{OS_COMMON} ));
5470
 
5471
 
5472
    #
5473
    #   Add requested suffix
5474
    #
5475
    if ($flags & $T_TYPE)
5476
    {
5477
        $str_platform .= '$(GBE_TYPE)';
5478
        $str_product  .= '$(GBE_TYPE)';
5479
        $str_target   .= '$(GBE_TYPE)';
5480
        $str_common   .= '$(GBE_TYPE)';
5481
    }
5482
 
5483
    #
5484
    #   Process the argument
5485
    #
5486
    $_ = $argument;
5487
    if ( /^--Debug/ ) {                         # In the Debug build only
5488
        if ( $ptype ) {
5489
            $$ptype = "D";
5490
            $consumed = 1;
5491
        }
5492
 
5493
    } elsif ( /^--Prod$/ || /^--Production$/ ) { # In the Production build only
5494
        if ( $ptype ) {
5495
            $$ptype = "P";
5496
            $consumed = 1;
5497
        }
5498
 
5499
    } elsif (/^--Prefix=(.*)/) {                # Prefix with subdir
5500
        $dir = "$base/$1";
5501
 
5502
    } elsif (/^--Subdir=(.*)/) {                # same as 'prefix'
5503
        $dir = "$base/$1";
5504
 
5505
    } elsif (/^--Platform$/) {                  # Platform installation
5506
        $dir = "$base/$str_platform";
5507
 
5508
    } elsif (/^--Platform=(.*?),(.*)/) {        # prefix and suffix with platform specific subdir
5509
        $dir = "$base/$1/$str_platform/$2";
5510
 
5511
    } elsif (/^--Platform=(.*)/) {              # prefix with platform specific subdir
5512
        if ($flags & $T_FILE) {
5513
            $dir = "$base/$1/$str_platform";
5514
        } else {
5515
            $dir = "$base/$str_platform/$1";
5516
        }
5517
 
5518
    } elsif (/^--Product$/) {                   # Product installation
5519
        $dir = "$base/$str_product";
5520
 
5521
    } elsif (/^--Product=(.*?),(.*)/) {         # prefix and suffix with product specific subdir
5522
        $dir = "$base/$1/$str_product/$2";
5523
 
5524
    } elsif (/^--Product=(.*)/) {               # prefix with product specific subdir
5525
        if ($flags & $T_FILE) {
5526
            $dir = "$base/$1/$str_product";
5527
        } else {
5528
            $dir = "$base/$str_product/$1";
5529
        }
5530
 
5531
    } elsif (/^--Target$/) {                    # Target installation
5532
        $dir = "$base/$str_target";
5533
 
5534
    } elsif (/^--Target=(.*?),(.*)/) {          # prefix and suffix with target specific subdir
5535
        $dir = "$base/$1/$str_target/$2";
5536
 
5537
    } elsif (/^--Target=(.*)/) {                # prefix with target specific subdir
5538
        if ($flags & $T_FILE) {
5539
            $dir = "$base/$1/$str_target";
5540
        } else {
5541
            $dir = "$base/$str_target/$1";
5542
        }
5543
 
5544
    } elsif (/^--OsCommon/) {
5545
 
5546
        unless ( $str_common_avail ) {
5547
            Warning("Packaging option --OsCommon not supported on this platform($ScmPlatform). Directive skipped");
5548
            $consumed = 2;
5549
 
5550
        } elsif (/^--OsCommon$/) {                  # OS installation
5551
            $dir = "$base/$str_common";
5552
 
5553
        } elsif (/^--OsCommon=(.*?),(.*)/) {        # prefix and suffix with target specific subdir
5554
            $dir = "$base/$1/$str_common/$2";
5555
 
5556
        } elsif (/^--OsCommon=(.*)/) {              # prefix with target specific subdir
5557
            if ($flags & $T_FILE) {
5558
                $dir = "$base/$1/$str_common";
5559
            } else {
5560
                $dir = "$base/$str_common/$1";
5561
            }
5562
        }
5563
 
5564
    } elsif (/^--Derived=(.*?),(.*?),(.*)/) {   # Derived target + prefix + subdir
5565
        $dir = "$base/$2/$1_$str_platform/$3";
5566
 
5567
    } elsif (/^--Derived=(.*?),(.*)/) {         # Derived target + subdir
5568
        if ($flags & $T_FILE) {
5569
            $dir = "$base/$2/$1_$str_platform";
5570
        } else {
5571
            $dir = "$base/$1_$str_platform/$2";
5572
        }
5573
 
5574
    } elsif (/^--Derived=(.*)/) {               # Derived target
5575
        $dir = "$base/$1_$str_platform";
5576
 
5577
    } elsif ($flags & $T_MACH && /^--Machine(([=])(.*))?$/) {   # Allow Machine and Machine=xxx specfic target
5578
        #
5579
        #   Special: Append machine type to user dir
5580
        #            Intended to create tools/bin/win32 and tools/bin/sparc directories
5581
        my $path = ( defined( $3) ) ? "/$3" : "";
5582
        $dir = "$base$path/\$(GBE_HOSTMACH)";
5583
 
5584
    } elsif ($flags & $T_GBE && /^--Gbe(([=])(.*))?$/) {   # Allow Gbe and Gbe=xxx specfic target
5585
        my $path = ( defined( $3) ) ? "/$3" : "";
5586
        $dir = "$base/gbe$path";
5587
 
5588
    } elsif (/^--Dir=(.*)/) {                   # prefix with target specific subdir
5589
        Error ('Packaging directive with --Dir option does not specify a directory.',
5590
               'Possible bad use of option of the form:--Dir=$xxx',
5591
               'Note: Use of package.pl and this construct is deprecated') unless ( $1 );
241 dpurdie 5592
        my $udir = $1;
5593
 
5594
        #
5595
        #   Remove leading ./
5596
        #   Check for leading ../
5597
        while ( $udir =~ s{^\./}{} ){};
5598
 
5599
        if ( $udir =~ m~^\.\./~ )
5600
        {
5601
            Warning("Packaging directive with --Dir option contains relative path (removed)", "Option: $_");
5602
            while ( $udir =~ s{^\.\./}{} ){};
5603
        }
227 dpurdie 5604
        if ($flags & $T_PKG) {
241 dpurdie 5605
            $dir = __PkgDir( $udir );
227 dpurdie 5606
        } else {
241 dpurdie 5607
            $dir = "\$(LOCALDIR)/$udir";
227 dpurdie 5608
        }
5609
    }
5610
 
5611
    return ($consumed) if ($dir eq "");
5612
    $dir =~ s~//~/~g;
5613
    $dir =~ s~/$~~;
5614
    $$pdir = $dir;
5615
    return (1);
5616
}
5617
 
5618
 
5619
#   __PkgDir ---
5620
#       Convert --Dir Package directives, removing leading subdir if
5621
#       matching the global $Pbase value.
5622
#
5623
#       Required as PKGDIR has the value 'GBE_ROOT/pkg/$Pbase'.
5624
#       Required to maintain compatability with older (package.pl) constructs
5625
#..
5626
 
5627
sub __PkgDir
5628
{
5629
    my( $dir ) = @_;
5630
    my $org = $dir;
5631
 
245 dpurdie 5632
    $dir =~ s~^\Q$::Pbase\E[/]?~~;
227 dpurdie 5633
    Debug2( "  PkgDir: converted \"$org\" to \"$dir\"" );
5634
 
5635
    $dir = "\$(PKGDIR)/$dir";
5636
    return $dir;
5637
}
5638
 
5639
 
5640
#   getMajorMinor ---
5641
#       Just a little help to deal with major/minor stuff for shared libs -
5642
#       given the name of the library as the argument, split out major and
5643
#       minor parts and return the basename, i.e name without major and minor
5644
#       and the pair of major and minor.
5645
#..
5646
 
285 dpurdie 5647
sub getMajorMinor
227 dpurdie 5648
{
5649
    my @bits = split ('\.', $_[0]);
5650
    my $stop;
5651
    my $major;
5652
    my $minor;
5653
 
5654
    if ( $#bits > 2 )
5655
    {
5656
        $stop = $#bits - 2;
5657
        $major = $bits[$#bits-1];
5658
        $minor = $bits[$#bits];
5659
    }
5660
    elsif ($#bits > 1)
5661
    {
5662
        $stop = $#bits-1;
5663
        $major = $bits[$#bits];
5664
        $minor=0;
5665
    }
5666
    else
5667
    {
5668
        $stop = $#bits; $major = 1; $minor = 0;
5669
    }
5670
 
5671
    my $base = $bits[0];
5672
    for ( my $i=1; $i <= $stop; $i++ ) {
5673
        $base = join ('.', $base, $bits[$i]);
5674
    }
5675
 
5676
    return ($base, $major, $minor);
5677
}
5678
 
5679
###############################################################################
5680
#
5681
#   Installation
5682
#
5683
 
5684
sub InstallHdr
5685
{
5686
    my( $platforms, @elements ) = @_;
335 dpurdie 5687
    my( $base, $dir, $srcfile, $full, $strip, $package );
227 dpurdie 5688
    my( $len, $name, $basename );
5689
 
5690
    Debug2( "InstallHdr($platforms, @elements)" );
5691
 
5692
    return if ( ! ActivePlatform($platforms) );
5693
    Warning ("InstallHdr: Needs local directory specified in build.pl") unless ( $::ScmLocal );
5694
 
5695
#.. Arguments
5696
#
5697
    $base = $PackageInfo{'Hdr'}{'IBase'};       # Base of target
5698
    $dir = $base . $PackageInfo{'Hdr'}{'Dir'};  # Installation path (default)
335 dpurdie 5699
    $full = $strip = 0;
227 dpurdie 5700
 
285 dpurdie 5701
    foreach ( @elements )
227 dpurdie 5702
    {
5703
                                                # Standard targets
5704
        my $rv = __TargetDir(0, $base, $_, \$dir);
5705
        next if ( $rv == 1 );
5706
        return if ( $rv == 2 );
5707
 
5708
        if (/^--Full/) {                        # using full (resolved) path
5709
            $full = 1;
5710
 
5711
        } elsif (/^--Strip$/) {                 # Strip path from source files
5712
            $strip = 1;
5713
 
5714
                                                # Package
5715
        } elsif (/^--Package$/ || /^--Package=(.*)/) {
5716
            $package = 1;
5717
 
5718
        } elsif (/^--(.*)/) {
5719
            Message( "InstallHdr: unknown option $_ -- ignored\n" );
5720
        }
5721
    }
5722
 
5723
#.. Files
5724
#
285 dpurdie 5725
    foreach ( @elements )
227 dpurdie 5726
    {
5727
        my %package_entry;
5728
        if ( ! /^--(.*)/ )
5729
        {
5730
            $name = $_;
5731
            $basename = StripDir( $name );
335 dpurdie 5732
            if ( !($srcfile = $SRCS{ $basename }) ) {
5733
                $srcfile = $name;
5734
            }
5735
 
227 dpurdie 5736
            if ( $full )
5737
            {
335 dpurdie 5738
                my $subdir = StripFileExt($srcfile);
5739
                $subdir = $1
5740
                    if ( $subdir =~ m~^$ProjectBase/(.*)~ );
5741
                $dir .= '/' . $subdir;
5742
                $dir =~ s~//~/~g;
5743
                $dir =~ s~/./~/~g;
5744
                $dir =~ s~/$~~g;
5745
                $name = $basename;
227 dpurdie 5746
            }
5747
 
5748
            $name = $basename
5749
                if ( $strip );
5750
 
5751
            Debug( "InstallHdr( $dir/$name, src: $srcfile, dest: $dir)" );
5752
 
5753
            $package_entry{'src'} = $srcfile;
5754
            $package_entry{'dir'} = StripFileExt( "$dir/$name" );
5755
            $INSTALL_HDRS{ "$dir/$name" } = {%package_entry};
5756
        }
5757
    }
5758
 
5759
#.. Package
5760
#
5761
    PackageHdr( @_ )                            # auto package
5762
        if ( $package );
5763
}
5764
 
5765
 
5766
sub InstallLib
5767
{
5768
    my( $platforms, @elements ) = @_;
5769
    my( $base, $dir, $package );
5770
    my( $lib, $strip );
289 dpurdie 5771
    my $org_lib;
227 dpurdie 5772
 
5773
    Debug2( "InstallLib($platforms, @elements)" );
5774
 
5775
    return if ( ! ActivePlatform($platforms) );
5776
    Warning ("InstallLib: Needs local directory specified in build.pl") unless ( $::ScmLocal );
5777
 
5778
#.. Arguments
5779
#
5780
    $base = $PackageInfo{'Lib'}{'IBase'};       # Base of target
5781
    $dir = $base . $PackageInfo{'Lib'}{'Dir'};  # Installation path (default)
5782
 
285 dpurdie 5783
    foreach ( @elements )
227 dpurdie 5784
    {
5785
                                                # Standard targets
5786
        my $rv = __TargetDir(0, $base, $_, \$dir);
5787
        next if ( $rv == 1 );
5788
        return if ( $rv == 2 );
5789
 
5790
        if (/^--Package$/ || /^--Package=(.*)/) {
5791
            $package = 1;
5792
 
5793
        } elsif (/^--Strip$/) {                 # Strip path from source files
5794
            $strip = 1;
5795
 
5796
        } elsif (/^--(.*)/) {
5797
            Message( "InstallLib: unknown option $_ -- ignored\n" );
5798
        }
5799
    }
5800
 
5801
#.. Files
5802
#
285 dpurdie 5803
    foreach ( @elements )
227 dpurdie 5804
    {
5805
        my %package_entry;
5806
        if ( ! /^--(.*)/ )
5807
        {
5808
            $_ = basename ($_)
5809
                if ( $strip );
289 dpurdie 5810
            $org_lib = $_;                      # Original name
227 dpurdie 5811
 
5812
            if ( $ScmTargetHost eq "Unix" ) {
5813
                $lib = "lib$_";                 # Prefix "lib" ....
5814
                $lib =~ s/^liblib/lib/;         # @LIBS already has lib added
5815
            } else {
5816
                $lib = $_;
5817
            }
5818
 
289 dpurdie 5819
            if (  my $libp = $SHLIBS->Get($lib) )
227 dpurdie 5820
            {
5821
                Debug( "InstallLib( $dir/$lib\$(GBE_TYPE).$::so, " .
5822
                    "src: \$(LIBDIR)/$lib\$(GBE_TYPE).$::so, dest: $dir)" );
5823
 
5824
                #
5825
                #   Create a "placekeeper" entry within $INSTALL_SHLIBS
5826
                #   The exact format of the name of the shared library is
5827
                #   toolset specific. Create an entry to allow the toolset
5828
                #   to extend the packaging information when the shared library
5829
                #   recipe is constructed.
5830
                #
289 dpurdie 5831
                my $ver = $libp->{ VERSION };
227 dpurdie 5832
                my $name = "$dir/$lib.$ver.PlaceKeeper";
5833
 
5834
                $package_entry{'placekeeper'} = 1;
5835
                $package_entry{'version'} = $ver;
5836
                $package_entry{'lib'} = $lib;
5837
                $package_entry{'dir'} = $dir;
289 dpurdie 5838
 
5839
                push @{$SHLIB_INS{$lib}}, $name;
227 dpurdie 5840
                $INSTALL_SHLIBS{$name} = {%package_entry};
5841
            }
5842
 
289 dpurdie 5843
            #
5844
            #   Clean up the package_entry
5845
            #   Insert common items
5846
            #
5847
            %package_entry = ();
5848
            $package_entry{'lib'} = $lib;
5849
            $package_entry{'dir'} = $dir;
5850
 
321 dpurdie 5851
            if ( my $libfile = $SRCS{$org_lib} )
227 dpurdie 5852
            {
5853
                #
5854
                #   Allow the user to package a sourced file as a library
289 dpurdie 5855
                #   But must be the un-massaged name of the file.
227 dpurdie 5856
                #
289 dpurdie 5857
                $package_entry{'dst'} = "$dir/$org_lib";
5858
                $package_entry{'src'} = $libfile;
5859
            }
5860
            elsif ( $LIBS->Get($lib) )
5861
            {
5862
                #
5863
                #   Install a library known to the makefile
5864
                #
5865
                my $libp = $LIBS->Get($lib);
227 dpurdie 5866
 
289 dpurdie 5867
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
5868
                $package_entry{'src'}    = $libp->getPath();
227 dpurdie 5869
            }
289 dpurdie 5870
            elsif ( ! $SHLIBS->Get($lib) )
227 dpurdie 5871
            {
289 dpurdie 5872
                #
5873
                #   Not a known shared lib
5874
                #   Not a known static lib
5875
                #   Not a 'sourced' file
5876
                #   Assume the a static library has magically appeared
5877
                #   in the standard LIB directory. May have been placed there
5878
                #   by a 'rule'
5879
                #
5880
                my $libp = $LIBS->New($lib);
227 dpurdie 5881
 
289 dpurdie 5882
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
5883
                $package_entry{'src'}    = $libp->getPath();
5884
            }
227 dpurdie 5885
 
289 dpurdie 5886
            #
5887
            #   Add entry to various lists if required
5888
            #
5889
            PackageLib_AddEntry ('InstallLib', \%LIB_INS, \%INSTALL_LIBS, \%package_entry )
5890
                if ( exists $package_entry{'dst'} );
227 dpurdie 5891
        }
5892
    }
5893
 
5894
#.. Package
5895
#
5896
    PackageLib( @_ )                            # auto package
5897
        if ( $package );
5898
}
5899
 
5900
 
5901
sub InstallJar
5902
{
5903
    my( $platforms, @elements ) = @_;
5904
    my( $base, $dir, $package );
5905
    my( $jar );
5906
 
5907
    Debug2( "InstallJar($platforms, @elements)" );
5908
 
5909
    return if ( ! ActivePlatform($platforms) );
5910
    Warning ("InstallJar: Needs local directory specified in build.pl") unless ( $::ScmLocal );
5911
 
5912
#.. Arguments
5913
#
5914
    $base = $PackageInfo{'Jar'}{'IBase'};       # Base of target
5915
    $dir = $base . $PackageInfo{'Jar'}{'Dir'};  # Installation path (default)
5916
 
285 dpurdie 5917
    foreach ( @elements )
227 dpurdie 5918
    {
5919
                                                # Standard targets
5920
        my $rv = __TargetDir(0, $base, $_, \$dir);
5921
        next if ( $rv == 1 );
5922
        return if ( $rv == 2 );
5923
 
5924
        if (/^--Package$/ || /^--Package=(.*)/) {
5925
            $package = 1;
5926
 
5927
        } elsif (/^--(.*)/) {
5928
            Message( "InstallJar: unknown option $_ -- ignored\n" );
5929
        }
5930
    }
5931
 
5932
 
5933
#.. Files
5934
#
285 dpurdie 5935
    foreach ( @elements )
227 dpurdie 5936
    {
5937
        my %package_entry;
5938
        if ( ! /^--(.*)/ )
5939
        {
5940
            $jar = $_;
5941
            my $src;
5942
            my $dest;
5943
 
5944
            if ( $JAR_FILES{$jar} )
5945
            {
5946
                $src = $JAR_FILES{$jar};
5947
                $dest = $jar;
5948
            }
5949
            else
5950
            {
5951
                $src = "\$(CLSDIR)/$jar\$(GBE_TYPE).jar";
5952
                $dest = "$jar\$(GBE_TYPE).jar";
5953
            }
5954
 
5955
 
5956
            Debug( "InstallJar( $dir/$dest, " .
5957
                "src: $src, dest: $dir)" );
5958
 
5959
            $package_entry{'src'} = $src;
5960
            $package_entry{'dir'} = $dir;
5961
            $INSTALL_CLSS{ "$dir/$dest" } = {%package_entry};
5962
 
5963
        }
5964
    }
5965
 
5966
#.. Package
5967
#
5968
    PackageJar( @_ )                            # auto package
5969
        if ( $package );
5970
}
5971
 
5972
 
5973
sub InstallProg
5974
{
5975
    my( $platforms, @elements ) = @_;
5976
    my( $base, $dir, $package );
5977
    my( $prog );
5978
 
5979
    Debug2( "InstallProg($platforms, @elements)" );
5980
 
5981
    return if ( ! ActivePlatform($platforms) );
5982
    Warning ("InstallProg: Needs local directory specified in build.pl") unless ( $::ScmLocal );
5983
 
5984
#.. Arguments
5985
#
5986
    $base = $PackageInfo{'Prog'}{'IBase'};       # Base of target
5987
    $dir = $base . $PackageInfo{'Prog'}{'Dir'};  # Installation path (default)
5988
 
285 dpurdie 5989
    foreach ( @elements )
227 dpurdie 5990
    {
5991
                                                # Standard targets
5992
        my $rv = __TargetDir($T_TYPE, $base, $_, \$dir);
5993
        next if ( $rv == 1 );
5994
        return if ( $rv == 2 );
5995
 
5996
        if (/^--Package$/ || /^--Package=(.*)/) {
5997
            $package = 1;
5998
 
5999
        } elsif (/^--(.*)/) {
6000
            Message( "InstallProg: unknown option $_ -- ignored\n" );
6001
        }
6002
    }
6003
 
6004
#.. Files
6005
#
285 dpurdie 6006
    foreach ( @elements )
227 dpurdie 6007
    {
6008
        my %package_entry;
6009
        if ( ! /^--(.*)/ )
6010
        {
6011
            my $ext = "";
6012
            $prog = $_;
6013
 
6014
            #
6015
            #   If the named target is a program then append the correct
6016
            #   extension. Otherwise assume that the target is either a script
6017
            #   or a some other file - and don't append an extension
6018
            #
6019
            $ext = $::exe
289 dpurdie 6020
                if ( $PROGS->Get($prog) );
227 dpurdie 6021
 
6022
            #
6023
            #   A "file" that is specified with a "Src" directive may be
6024
            #   installed as though it were a program
6025
            #
6026
            my $progfile;
6027
            $progfile = "\$(BINDIR)/$prog$ext"
6028
                unless ( $progfile = $SRCS{$prog} );
6029
 
6030
            Debug( "InstallProg( $dir/$prog$ext, " .
6031
                 "src: $progfile, dest: $dir)" );
6032
 
6033
            push @{$PROG_INS{$prog}}, "$dir/$prog$ext";
6034
 
6035
            $package_entry{'src'} = $progfile;
6036
            $package_entry{'dir'} = $dir;
6037
            $INSTALL_PROGS{ "$dir/$prog$ext" } = {%package_entry};
6038
        }
6039
    }
6040
 
6041
#.. Package
6042
#
6043
    PackageProg( @_ )                           # auto package
6044
        if ( $package );
6045
}
6046
 
6047
 
6048
###############################################################################
6049
#
6050
#   Packaging
6051
#
6052
sub PackageDist
6053
{
6054
    my( $name, @elements ) = @_;
6055
 
6056
    Debug2( "PackageDist($name, @elements)" );
6057
 
6058
    foreach ( @elements )
6059
    {
6060
    #.. Distribution sets
6061
    #
6062
        HashJoin( \%PACKAGE_DIST, $;, $name, "$_" );
6063
 
6064
    #.. Summary of distribution sets
6065
    #
267 dpurdie 6066
        $PACKAGE_SETS{ $_ }{'TAG'} = 1
6067
            if ( ! exists $PACKAGE_SETS{ $_ }{'TAG'} );
227 dpurdie 6068
    }
6069
}
6070
 
311 dpurdie 6071
#-------------------------------------------------------------------------------
6072
# Function        : PackageFile
6073
#
6074
# Description     : Directive to package files
6075
#                   Not to be used to package libraries, executables, headers
6076
#                   as this should be done by specialised directives
6077
#
6078
#                   Use to package other files
6079
#                   Can package an entire tree (ugly)
6080
#
6081
# Inputs          : 
6082
#
6083
#
227 dpurdie 6084
sub PackageFile
6085
{
6086
    my( $platforms, @elements ) = @_;
335 dpurdie 6087
    my( $base, $dir, $full, $path, $dist, $strip, $exefile, $type );
227 dpurdie 6088
    my( $name, $basename, $len, $srcfile );
341 dpurdie 6089
    my( $dir_tree, @dir_tree_exclude, @dir_tree_include, $strip_base );
335 dpurdie 6090
    my $recurse = 1;
227 dpurdie 6091
 
6092
    Debug2( "PackageFile($platforms, @elements)" );
6093
 
6094
    return if ( !$ScmPackage );                 # Packaging enabled ?
6095
    return if ( ! ActivePlatform($platforms) );
6096
 
6097
#.. Arguments
6098
#
6099
    $dist = "ALL";                                  # Default set (ALL)
6100
    $base = $PackageInfo{'File'}{'PBase'};          # Base of target
6101
    $dir = $base . $PackageInfo{'File'}{'Dir'};     # Installation path (default)
335 dpurdie 6102
    $full = 0;
227 dpurdie 6103
    $strip = 0;
341 dpurdie 6104
    $strip_base = 0;
227 dpurdie 6105
    $exefile = 0;
6106
 
285 dpurdie 6107
    foreach ( @elements )
227 dpurdie 6108
    {
6109
        my $rv = __TargetDir($T_PKG|$T_MACH|$T_GBE|$T_FILE, $base, $_, \$dir, \$type);
6110
        next if ( $rv == 1 );
6111
        return if ( $rv == 2 );
6112
 
6113
        if (/^--Full/) {                        # Using full (resolved) path
6114
            $full = 1;
6115
 
6116
        } elsif (/^--Set=(.*)/) {               # Distribution set
6117
            $dist = "$1";
6118
 
6119
        } elsif (/^--Package$/) {               # Package .. call by InstallFile
6120
        } elsif (/^--Package=(.*)/) {
6121
            $dist = "$1";
6122
 
6123
        } elsif (/^--Strip$/) {                 # Strip path from source files
6124
            $strip = 1;
6125
 
6126
        } elsif (/^--Executable$/) {            # Mark the file as executable
6127
            $exefile = "X";
6128
 
6129
        } elsif ( /^--DirTree=(.*)/ ) {
6130
            Error("DirTree. Multiple directories not allowed.") if ( $dir_tree );
6131
            $dir_tree = $1;
6132
 
6133
            Error("DirTree cannot extend outside current subtree. '..' not allowed.",
6134
                  "Directory: $dir_tree") if ( $dir_tree =~ m~\.\.~ );
6135
            Error("DirTree. Absolute paths are not allowed",
6136
                  "Directory: $dir_tree") if ( $dir_tree =~ m~^/~ || $dir_tree =~ m~^.\:~ );
6137
            Error("DirTree. Directory not found",
6138
                  "Directory: $dir_tree") unless  ( -d $dir_tree );
6139
 
6140
        } elsif ( /^--FilterOut=(.*)/ ) {
6141
            push @dir_tree_exclude, $1;
6142
 
6143
        } elsif ( /^--FilterIn=(.*)/ ) {
6144
            push @dir_tree_include, $1;
6145
 
6146
        } elsif ( /^--StripDir/ ) {
341 dpurdie 6147
            $strip_base = 1;
227 dpurdie 6148
 
335 dpurdie 6149
        } elsif ( m/^--Recurse/ ) {
6150
            $recurse = 1;
6151
 
6152
        } elsif ( m/^--NoRecurse/ ) {
6153
            $recurse = 0;
6154
 
227 dpurdie 6155
        } elsif (/^--(.*)/) {
6156
            Message( "PackageFile: unknown option $_ -- ignored\n" );
6157
        }
6158
    }
6159
 
6160
 
6161
    #.. DirTree expansion
6162
    #   Note: Uses REs, not simple globs
6163
    #         Use JatsLocateFiles to do the hard work
6164
    if ( $dir_tree )
6165
    {
335 dpurdie 6166
        my $search = JatsLocateFiles->new('FullPath' );
6167
        $search->recurse($recurse);
227 dpurdie 6168
        $search->filter_in_re ( $_ ) foreach ( @dir_tree_include );
6169
        $search->filter_out_re( $_ ) foreach ( @dir_tree_exclude );
6170
        @elements = $search->search ( $dir_tree );
341 dpurdie 6171
        $strip_base = length( $dir_tree ) if ( $strip_base );
227 dpurdie 6172
    }
6173
 
6174
#.. Files
6175
#
285 dpurdie 6176
    foreach ( @elements )
227 dpurdie 6177
    {
6178
        my %package_entry;
299 dpurdie 6179
        $name = $_;
6180
 
227 dpurdie 6181
        #
299 dpurdie 6182
        #   Trap special files
6183
        #       DPACKAGE - but only if we have a DPackageLibrary directive
6184
        #                  in the same makefile.
6185
        #
6186
        if ( m~^DPACKAGE$~ && $DPackageDirective ) {
6187
            $name = 'DPACKAGE.' . $::GBE_MACHTYPE;
6188
        }
6189
 
6190
        #
227 dpurdie 6191
        #   Special cases: Provide make-style $ escape processing.
6192
        #       Allow files with a $ in the name
6193
        #       Allow files with a space in the name
263 dpurdie 6194
        #   Only for file names that don't look like $(GBE_...) as these
6195
        #   may be generated internally
227 dpurdie 6196
        #
301 dpurdie 6197
        unless ( $name =~ m~\$\(GBE_.+\)~ )
263 dpurdie 6198
        {
301 dpurdie 6199
            $name =~ s~\$~\$\$~g;
6200
            $name =~ s~ ~\\ ~g;
361 dpurdie 6201
            $name =~ s~,~\$(comma)~g;
263 dpurdie 6202
        }
227 dpurdie 6203
 
6204
        if ( ! /^--(.*)/ )
6205
        {
6206
            $basename = StripDir( $name );
335 dpurdie 6207
            if ( !($srcfile = $SRCS{ $basename }) ) {
6208
                $srcfile = $name;
6209
            }
6210
 
227 dpurdie 6211
            if ( $full )
6212
            {
335 dpurdie 6213
                my $subdir = StripFileExt($srcfile);
6214
                $subdir = $1
6215
                    if ( $subdir =~ m~^$ProjectBase/(.*)~ );
6216
                $dir .= '/' . $subdir;
6217
                $dir =~ s~//~/~g;
6218
                $dir =~ s~/./~/~g;
6219
                $dir =~ s~/$~~g;
6220
                $name = $basename;
227 dpurdie 6221
            }
6222
 
6223
            $name = $basename
6224
                if ( $strip );
6225
 
341 dpurdie 6226
            if ( $strip_base )
6227
            {
6228
                $name = substr $name, $strip_base;
6229
                $name =~ s~^/~~;
6230
            }
6231
 
227 dpurdie 6232
            $dir =~ s~//~/~g;
6233
            $dir =~ s~/$~~;
6234
 
6235
            #
6236
            #   Sanity test the source filename
6237
            #   User may have misused an option
6238
            #
6239
            if ( ( $srcfile =~ m/=/ ) || ( $srcfile =~ m/^-/ ) || ( $srcfile =~ m~/-~ )  )
6240
            {
6241
               Warning ("PackageFile: Suspect source filename: $srcfile");
6242
            }
6243
 
6244
            Debug( "PackageFile( $dir/$name, " .
6245
                "src: $srcfile, dest: $dir, dist: $dist, exe: $exefile )" );
6246
 
6247
            $package_entry{'src'} = $srcfile;
6248
            $package_entry{'dir'} = StripFileExt( "$dir/$name" );
6249
            $package_entry{'set'} = $dist;
6250
            $package_entry{'exe'} = $exefile if $exefile;
6251
            $package_entry{'type'} = $type if ( $type );
6252
 
6253
            $PACKAGE_FILES{ "$dir/$name" } = {%package_entry};
6254
        }
6255
    }
6256
}
6257
 
6258
sub PackageHdr
6259
{
6260
    my( $platforms, @elements ) = @_;
335 dpurdie 6261
    my( $base, $dir, $full, $path, $dist, $strip );
227 dpurdie 6262
    my( $name, $basename, $len, $srcfile );
6263
 
6264
    Debug2( "PackageHdr($platforms, @elements)" );
6265
 
6266
    return if ( !$ScmPackage );                 # Packaging enabled ?
6267
    return if ( ! ActivePlatform($platforms) );
6268
 
6269
#.. Arguments
6270
#
6271
    $dist = "ALL";                                  # Default set (ALL)
6272
    $base = $PackageInfo{'Hdr'}{'PBase'};           # Base of target
6273
    $dir = $base . $PackageInfo{'Hdr'}{'Dir'};      # Installation path (default)
335 dpurdie 6274
    $full = 0;
227 dpurdie 6275
    $strip = 0;
6276
 
285 dpurdie 6277
    foreach ( @elements )
227 dpurdie 6278
    {
6279
        my $rv = __TargetDir($T_PKG, $base, $_, \$dir);
6280
        next if ( $rv == 1 );
6281
        return if ( $rv == 2 );
6282
 
6283
        if (/^--Full/) {                        # Using full (resolved) path
6284
            $full = 1;
6285
 
6286
        } elsif (/^--Set=(.*)/) {               # Distribution set
6287
            $dist = "$1";
6288
 
6289
        } elsif (/^--Package$/) {               # Package .. call by InstallHdr
6290
        } elsif (/^--Package=(.*)/) {
6291
            $dist = "$1";
6292
 
6293
        } elsif (/^--Strip$/) {                 # Strip path from source files
6294
            $strip = 1;
6295
 
6296
        } elsif (/^--(.*)/) {
6297
            Message( "PackageHdr: unknown option $_ -- ignored\n" );
6298
        }
6299
    }
6300
 
6301
#.. Files
6302
#
285 dpurdie 6303
    foreach ( @elements )
227 dpurdie 6304
    {
6305
        my %package_entry;
6306
        if ( ! /^--(.*)/ )
6307
        {
6308
            $name = $_;
6309
            $basename = StripDir( $name );
335 dpurdie 6310
            if ( !($srcfile = $SRCS{ $basename }) ) {
6311
                $srcfile = $name;
6312
            }
6313
 
227 dpurdie 6314
            if ( $full )
6315
            {
335 dpurdie 6316
                my $subdir = StripFileExt($srcfile);
6317
                $subdir = $1
6318
                    if ( $subdir =~ m~^$ProjectBase/(.*)~ );
6319
                $dir .= '/' . $subdir;
6320
                $dir =~ s~//~/~g;
6321
                $dir =~ s~/./~/~g;
6322
                $dir =~ s~/$~~g;
6323
                $name = $basename;
227 dpurdie 6324
            }
6325
 
6326
            $name = $basename
6327
                if ( $strip );
6328
 
6329
            Debug( "PackageHdr( $dir/$name, " .
6330
                "src: $srcfile, dest: $dir, dist: $dist )" );
6331
 
6332
            $package_entry{'src'} = $srcfile;
6333
            $package_entry{'dir'} = StripFileExt( "$dir/$name" );
6334
            $package_entry{'set'} = $dist;
6335
 
6336
            $PACKAGE_HDRS{ "$dir/$name" } = {%package_entry};
6337
        }
6338
    }
6339
}
6340
 
6341
 
6342
sub PackageLib
6343
{
6344
    my( $platforms, @elements ) = @_;
6345
    my( $base, $dir, $dist, $type );
6346
    my( $lib, $org_lib, %extras, $strip );
6347
 
6348
    Debug2( "PackageLib($platforms, @elements)" );
6349
 
6350
    return if ( !$ScmPackage );                 # Packaging enabled ?
6351
    return if ( ! ActivePlatform($platforms) );
6352
 
6353
#.. Arguments
6354
#
6355
    $dist = "ALL";                              # Default set (ALL)
6356
    $base = $PackageInfo{'Lib'}{'PBase'};       # Base of target
6357
    $dir = $base . $PackageInfo{'Lib'}{'Dir'};  # Installation path (default)
6358
    $type = "";
6359
 
285 dpurdie 6360
    foreach ( @elements )
227 dpurdie 6361
    {
6362
                                                # Standard targets
6363
        my $rv = __TargetDir($T_PKG, $base, $_, \$dir, \$type);
6364
        next if ( $rv == 1 );
6365
        return if ( $rv == 2 );
6366
 
6367
        if (/^--Set=(.*)/) {                    # Distribution set(s)
6368
            $dist = "$1";
6369
 
6370
        } elsif (/^--Package$/) {               # Package .. call by PackageLib
6371
        } elsif (/^--Package=(.*)/) {
6372
            $dist = "$1";
6373
 
6374
        } elsif (/^--Extras=(.*)/) {            # Extras=[none, .. ,all]
6375
            foreach my $elem ( split( ',', $1 ) )
6376
            {
6377
                Error ("PackageLib: Unknown Extras mode: $elem")
6378
                    unless ( grep m/$elem/, qw(none stub map lint debug all) );
6379
                $extras{$elem} = 1;
6380
            }
6381
            %extras = () if ( $extras{'all'} );
6382
 
6383
        } elsif (/^--Strip$/) {                 # Strip path from source files
6384
            $strip = 1;
6385
 
6386
        } elsif (/^--(.*)/) {
6387
            Message( "PackageLib: unknown option $_ -- ignored\n" );
6388
        }
6389
    }
6390
 
6391
#.. Files
6392
#
285 dpurdie 6393
    foreach ( @elements )
227 dpurdie 6394
    {
6395
        my %package_entry;
6396
        if ( ! /^--(.*)/ )
6397
        {
6398
            $_ = StripDir( $_ )
6399
                if ( $strip );
6400
 
6401
            $org_lib = $_;                      # Original name
6402
            if ( $ScmTargetHost eq "Unix" ) {
6403
                $lib = "lib$_";                 # Prefix "lib" ....
6404
                $lib =~ s/^liblib/lib/;         # @LIBS already has lib added
6405
            } else {
6406
                $lib = $_;
6407
            }
6408
 
289 dpurdie 6409
            if (  my $libp = $SHLIBS->Get($lib) )
227 dpurdie 6410
            {
6411
                Debug( "PackageLib( $dir/$lib\$(GBE_TYPE).$::so, " .
6412
                    "src: \$(LIBDIR)/$lib\$(GBE_TYPE).$::so, dest: $dir, dist: $dist, type: $type )" );
6413
 
6414
                #
6415
                #   Create a "placekeeper" entry within $PACKAGE_SHLIBS
6416
                #   The exact format of the name of the shared library is
6417
                #   toolset specific. Create an entry to allow the toolset
6418
                #   to extend the packaging information when the shared library
6419
                #   recipe is constructed.
6420
                #
6421
                #
289 dpurdie 6422
                my $ver = $libp->{ VERSION };
227 dpurdie 6423
                my $name = "$dir/$lib.$ver.PlaceKeeper";
6424
 
6425
                $package_entry{'placekeeper'} = 1;
6426
                $package_entry{'version'} = $ver;
6427
                $package_entry{'lib'} = $lib;
6428
                $package_entry{'dir'} = $dir;
6429
                $package_entry{'set'} = $dist;
6430
                $package_entry{'type'} = $type if ( $type );
6431
                $package_entry{'extras'} = {%extras} if ( scalar %extras );
289 dpurdie 6432
 
6433
                push @{$SHLIB_PKG{$lib}}, $name;
227 dpurdie 6434
                $PACKAGE_SHLIBS{$name} = {%package_entry};
6435
            }
6436
 
289 dpurdie 6437
            #
6438
            #   Clean up the package_entry
6439
            #   Insert common items
6440
            #
6441
            %package_entry = ();
6442
            $package_entry{'lib'} = $lib;
6443
            $package_entry{'dir'} = $dir;
6444
            $package_entry{'set'} = $dist;
6445
            $package_entry{'extras'} = {%extras} if ( scalar %extras );
6446
            $package_entry{'type'} = $type if ( $type );
6447
 
227 dpurdie 6448
            if ( my $libfile = $SRCS{$org_lib} )
6449
            {
6450
                #
6451
                #   Allow the user to package a sourced file as a library
6452
                #   But must be the un-massaged name of the file.
6453
                #
289 dpurdie 6454
                $package_entry{'dst'} = "$dir/$org_lib";
6455
                $package_entry{'src'} = $libfile;
6456
            }
6457
            elsif ( $LIBS->Get($lib) )
6458
            {
6459
                #
6460
                #   Package up a library known to the makefile
6461
                #
6462
                my $libp = $LIBS->Get($lib);
227 dpurdie 6463
 
289 dpurdie 6464
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
6465
                $package_entry{'src'}    = $libp->getPath();
227 dpurdie 6466
            }
289 dpurdie 6467
            elsif ( ! $SHLIBS->Get($lib) )
227 dpurdie 6468
            {
289 dpurdie 6469
                #
6470
                #   Not a known shared lib
6471
                #   Not a known static lib
6472
                #   Not a 'sourced' file
6473
                #   Assume the a static library has magically appeared
6474
                #   in the standard LIB directory. May have been placed there
6475
                #   by a 'rule'
6476
                #
6477
                my $libp = $LIBS->New($lib);
227 dpurdie 6478
 
289 dpurdie 6479
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
6480
                $package_entry{'src'}    = $libp->getPath();
6481
            }
227 dpurdie 6482
 
289 dpurdie 6483
            #
6484
            #   Add entry to various lists if required
6485
            #
6486
            PackageLib_AddEntry ('PackageLib', \%LIB_PKG, \%PACKAGE_LIBS, \%package_entry )
6487
                if ( exists $package_entry{'dst'} );
227 dpurdie 6488
        }
6489
    }
6490
}
6491
 
289 dpurdie 6492
#-------------------------------------------------------------------------------
6493
# Function        : PackageLib_AddEntry
6494
#
6495
# Description     : Helper function to add a package entry
6496
#                   to the lists
6497
#
6498
# Inputs          : $directive          - Directive name
6499
#                   $pList              - Ref to array list to maintain
6500
#                   $pHash              - Ref to hash to maintain
6501
#                   $pData              - Packaging Data
6502
#                                         Must Take a copy.
6503
#
6504
# Returns         : 
6505
#
227 dpurdie 6506
 
289 dpurdie 6507
sub PackageLib_AddEntry
6508
{
6509
    my ($directive, $pList, $pHash, $pData) = @_;
6510
 
6511
    my $lib = delete $pData->{'lib'};
6512
    my $dst = delete $pData->{'dst'};
6513
 
6514
    Error ("INTERNAL PackageLib_AddEntry: lib or dst not defined")
6515
        unless ( $lib && $dst );
6516
 
6517
    Debug( "$directive( ",$dst,
6518
            ", src: " ,$pData->{'src'},
6519
            ", dest: ",$pData->{'dir'},
6520
            ", dist: ",$pData->{'set'},
6521
            ", type: ",$pData->{'type'} || '',
6522
            " )" );
6523
 
6524
    push @{$pList->{$lib }}, $dst;
6525
    $pHash->{$dst } = {%$pData};
6526
}
6527
 
6528
 
227 dpurdie 6529
sub PackageProg
6530
{
6531
    my( $platforms, @elements ) = @_;
6532
    my( $base, $dir, $dist, $type );
6533
    my( $prog, %extras, $strip );
6534
 
6535
    Debug2( "PackageProg($platforms, @elements)" );
6536
 
6537
    return if ( !$ScmPackage );                 # Packaging enabled ?
6538
    return if ( ! ActivePlatform($platforms) );
6539
 
6540
#.. Arguments
6541
#
6542
    $dist = "ALL";                              # Default set (ALL)
6543
    $base = $PackageInfo{'Prog'}{'PBase'};       # Base of target
6544
    $dir = $base . $PackageInfo{'Prog'}{'Dir'};  # Installation path (default)
6545
    $type = "";
6546
 
285 dpurdie 6547
    foreach ( @elements )
227 dpurdie 6548
    {
6549
                                                # Standard targets
6550
        my $rv = __TargetDir($T_PKG|$T_TYPE, $base, $_, \$dir, \$type);
6551
        next if ( $rv == 1 );
6552
        return if ( $rv == 2 );
6553
 
6554
        if (/^--Set=(.*)/) {                    # Distribution set(s)
6555
            $dist = "$1";
6556
 
6557
        } elsif (/^--Package$/) {               # Package .. call by PackageLib
6558
        } elsif (/^--Package=(.*)/) {
6559
            $dist = "$1";
6560
 
6561
        } elsif (/^--Tool(([=])(.*))?$/) {      # Allow Tool and Tool=xxx specfic target
6562
            my $path = ( defined( $3) ) ? "/$3" : "";
261 dpurdie 6563
            $dir = "\$(PKGDIR)$path/\$(GBE_HOSTMACH)";
227 dpurdie 6564
 
6565
        } elsif (/^--Extras=(.*)/) {            # Extras=[none, .. ,all]
6566
            foreach my $elem ( split( ',', $1 ) )
6567
            {
6568
                Error ("PackageLib: Unknown Extras mode: $elem")
6569
                    unless ( grep m/$elem/, qw(none stub map lint debug all) );
6570
                $extras{$elem} = 1;
6571
            }
6572
            %extras = () if ( $extras{'all'} );
6573
 
6574
        } elsif (/^--Strip$/) {                 # Strip path from source files
6575
            $strip = 1;
6576
 
6577
        } elsif (/^--(.*)/) {
6578
            Message( "PackageProg: unknown option $_ -- ignored\n" );
6579
        }
6580
    }
6581
 
6582
#.. Files
6583
#
285 dpurdie 6584
    foreach ( @elements )
227 dpurdie 6585
    {
6586
        my %package_entry;
6587
        if ( m~descpkg~ ) {
6588
            PackageFile($platforms, @elements);
6589
 
6590
        } elsif ( ! /^--(.*)/ ) {
6591
            $_ = StripDir( $_ )
6592
                if ( $strip );
6593
 
6594
            my $ext = "";
6595
            $prog = $_;
6596
 
6597
            #
6598
            #   If the named target is a program then append the correct
6599
            #   extension. Otherwise assume that the target is either a script
6600
            #   or a some other file - and don't append an extension
6601
            #
6602
            #   A program may not have any object files, only libraries
6603
            #
6604
            $ext = $::exe
289 dpurdie 6605
                if ( $PROGS->Get($prog) );
227 dpurdie 6606
 
6607
            #
6608
            #   A "file" that is specified with a "Src" directive may be
6609
            #   installed as though it were a program
6610
            #
6611
            my $progfile;
6612
            $progfile = "\$(BINDIR)/$prog$ext"
6613
                unless ( $progfile = $SRCS{$prog} );
6614
 
6615
            Debug( "PackageProg( $dir/$prog$ext, " .
6616
                 "src: $progfile, dest: $dir, dist: $dist, type: $type )" );
6617
 
6618
            my $target = "$dir/$prog$ext";
6619
            push @{$PROG_PKG{$prog}}, $target;
6620
 
6621
            $package_entry{'src'}   = $progfile;
6622
            $package_entry{'dir'}   = $dir;
6623
            $package_entry{'set'}   = $dist;
6624
            $package_entry{'extras'}= {%extras} if ( scalar %extras );
6625
            $package_entry{'type'}  = $type if ( $type );
6626
 
6627
            $PACKAGE_PROGS{$target} = {%package_entry};
6628
        }
6629
    }
6630
}
6631
 
6632
 
6633
sub PackageJar
6634
{
6635
    my( $platforms, @elements ) = @_;
6636
    my( $base, $dir, $dist, $type );
6637
    my( $jar );
6638
 
6639
    Debug2( "PackageJar($platforms, @elements)" );
6640
 
6641
    return if ( !$ScmPackage );                 # Packaging enabled ?
6642
    return if ( ! ActivePlatform($platforms) );
6643
 
6644
#.. Arguments
6645
#
6646
    $dist = "ALL";                              # Default set (ALL)
6647
    $base = $PackageInfo{'Jar'}{'PBase'};       # Base of target
6648
    $dir = $base . $PackageInfo{'Jar'}{'Dir'};  # Installation path (default)
6649
    $type = "";
6650
 
285 dpurdie 6651
    foreach ( @elements )
227 dpurdie 6652
    {
6653
                                                # Standard targets
6654
        my $rv = __TargetDir($T_PKG, $base, $_, \$dir, \$type);
6655
        next if ( $rv == 1 );
6656
        return if ( $rv == 2 );
6657
 
6658
        if (/^--Set=(.*)/) {                    # Distribution set(s)
6659
            $dist = "$1";
6660
 
6661
        } elsif (/^--Package$/) {               # Package .. call by InstallJar
6662
        } elsif (/^--Package=(.*)/) {
6663
            $dist = "$1";
6664
 
6665
        } elsif (/^--(.*)/) {
6666
            Message( "PackageJar: unknown option $_ -- ignored\n" );
6667
        }
6668
    }
6669
 
6670
#.. Files
6671
#
285 dpurdie 6672
    foreach ( @elements )
227 dpurdie 6673
    {
6674
        my %package_entry;
6675
        if ( ! /^--(.*)/ )
6676
        {
6677
            $jar = $_;
6678
            my $src;
6679
            my $dest;
6680
 
6681
            if ( $JAR_FILES{$jar} )
6682
            {
6683
                $src = $JAR_FILES{$jar};
6684
                $dest = $jar;
6685
            }
6686
            else
6687
            {
6688
                $src = "\$(CLSDIR)/$jar\$(GBE_TYPE).jar";
6689
                $dest = "$jar\$(GBE_TYPE).jar";
6690
            }
6691
 
6692
 
6693
            Debug( "PackageJar( $dir/$dest, " .
6694
                "src: $src, dest: $dir, dist: $dist, type: $type )" );
6695
 
6696
            $package_entry{'src'} = $src;;
6697
            $package_entry{'dir'} = $dir;
6698
            $package_entry{'set'} = $dist;
6699
            $package_entry{'type'} = $type if ( $type );
6700
 
6701
            $PACKAGE_CLSS{ "$dir/$dest" } = {%package_entry};
6702
 
6703
        }
6704
    }
6705
}
6706
 
6707
#-------------------------------------------------------------------------------
6708
# Function        : PackageProgAddFiles         - Add files to a PackageProg
6709
#                   PackageLibAddFiles          - Add files to a PackageLib
6710
#                   PackageShlibAddFiles        - Add files to a PackageLib (shared lib)
6711
#                   PackageShlibAddLibFiles     - Add files to a PackageLib (shared lib)
6712
#                                                 Add static library files
6713
#
6714
# Description     : Add files to a Program package or installation
6715
#                   For use by Tool sets to allow additional files to be
6716
#                   packaged with a program.
6717
#
6718
#                   The files are only added if the named program is being
6719
#                   packaged and/or installed.
6720
#
6721
#
6722
# Inputs          : prog        - program identifier
6723
#                   file        - A file to be add
6724
#                   args        - Additional packageing arguments
6725
#
6726
# Returns         : Nothing
6727
#
6728
 
6729
sub PackageProgAddFiles
6730
{
6731
    Debug("PackageProgAddFiles");
6732
 
6733
    PackageAddFiles ( \%PACKAGE_PROGS, \%PACKAGE_PROGS, \%PROG_PKG, @_);
6734
    PackageAddFiles ( \%INSTALL_PROGS, \%INSTALL_PROGS, \%PROG_INS, @_);
6735
}
6736
 
6737
sub PackageLibAddFiles
6738
{
6739
    Debug("PackageLibAddFiles");
6740
 
6741
    PackageAddFiles ( \%PACKAGE_LIBS, \%PACKAGE_LIBS, \%LIB_PKG, @_ );
6742
    PackageAddFiles ( \%INSTALL_LIBS, \%INSTALL_LIBS, \%LIB_INS, @_ );
6743
}
6744
 
6745
sub PackageShlibAddFiles
6746
{
6747
    my ($prog, $file, @args) = @_;
6748
    Debug("PackageShlibAddFiles");
6749
 
6750
    PackageAddFiles ( \%INSTALL_SHLIBS, \%INSTALL_SHLIBS, \%SHLIB_INS, @_ );
6751
    PackageAddFiles ( \%PACKAGE_SHLIBS, \%PACKAGE_SHLIBS, \%SHLIB_PKG, @_ );
6752
 
6753
    #
6754
    #   These files become the target of the "make_install_shlib" operation unless:
6755
    #       Conditionally packaged files are not always created
6756
    #       RemoveOnly files are not always generated
6757
    #
6758
    my $no_add;
6759
    foreach ( @args )
6760
    {
6761
        if ( m/^defined=/ or m/^RemoveOnly=/ )
6762
        {
6763
            $no_add = 1;
6764
            last;
6765
        }
6766
    }
6767
 
6768
    push (@SHLIB_TARGETS, $file ) unless $no_add;
6769
}
6770
 
6771
sub PackageShlibAddLibFiles
6772
{
6773
    Debug("PackageShlibAddLibFiles");
6774
 
6775
    PackageAddFiles ( \%PACKAGE_SHLIBS, \%PACKAGE_LIBS, \%SHLIB_PKG, @_ , 'Class=lib');
6776
    PackageAddFiles ( \%INSTALL_SHLIBS, \%INSTALL_LIBS, \%SHLIB_INS, @_ , 'Class=lib');
6777
}
6778
 
6779
#-------------------------------------------------------------------------------
6780
# Function        : PackageAddFiles
6781
#
6782
# Description     : Internal function to add files to the data structures that
6783
#                   describe a package or installation
6784
#
6785
#                   Use this function to package or install additional files with
6786
#                   the Progs and Libs
6787
#
6788
#                   ie: Add a LIB file to be packaged with a Shared Library
6789
#                   ie: Add a MAP file to be packaged with a program
6790
#
6791
# Inputs          : ref_spkg  - Reference to the hash that contains the package data
6792
#                   ref_dpkg  - Reference to the target package/install hash
6793
#                               Normally the same as ref_dpkg, but does allow
289 dpurdie 6794
#                               a static library to be added to a dynamic library
227 dpurdie 6795
#                               package.
6796
#                   ref_list  - Reference to a hash that may contain package keys to process
6797
#                   prog      - Key for index to above
6798
#                   file      - A file to be added
6799
#                   args      - Additional packaging arguments
6800
#
6801
# Returns         :
6802
#
6803
sub PackageAddFiles
6804
{
6805
    my ($ref_spkg, $ref_dpkg, $ref_list, $prog, $file, @args ) = @_;
6806
 
6807
    #
6808
    #   Process entry
6809
    #   The files may need to be added to multiple packages
6810
    #
6811
    Debug("PackageAddFiles: $file");
6812
 
6813
    return unless ( $ref_list->{$prog} );
6814
 
6815
    #
6816
    #   Parse arguments and extract the "Class=xxx" argument. This may be used
6817
    #   to limit the extra files piggybacked with the base file
6818
    #   All files without a class will be treated as base files
6819
    #
6820
    my $class;
6821
    foreach ( @args )
6822
    {
6823
        next unless ( m~^Class=(.*)$~ );
6824
        $class = $1 unless ( $1 eq 'none' );
6825
    }
6826
    Debug("PackageAddFiles: Class: ", $class || 'Default=None');
6827
 
6828
    foreach my $entry_key ( @{$ref_list->{$prog}} )
6829
    {
6830
        Debug("PackageAddFiles: Entry found: $entry_key");
6831
 
6832
        #
6833
        #   Copy of the template entry
6834
        #
6835
        my %package_entry = %{$ref_spkg->{$entry_key}};
6836
        Error ("INTERNAL: Expected entry in PACKAGE_ hash not found: $entry_key" )
6837
            unless ( %package_entry );
6838
 
6839
        #
6840
        #   Do not add the file if the user has limited the extra files added
6841
        #   to the packaging list and the current file is not in the class list
6842
        #
6843
        if ( $class && $package_entry{'extras'} )
6844
        {
6845
            next unless ( $package_entry{'extras'}{$class} );
6846
        }
6847
 
6848
        #
6849
        #   Create new entries for the file
6850
        #
6851
        $package_entry{'src'} = $file;
6852
        foreach ( @args )
6853
        {
6854
            m~^(.*)=(.*)$~;
6855
            $package_entry{$1} = $2;
6856
        }
6857
 
6858
        #
6859
        #   Clean out useless fields
6860
        #   Must remove the placekeeper marker to allow the entry to be visible
6861
        #
6862
        delete $package_entry{'placekeeper'};
6863
        delete $package_entry{'version'};
6864
        delete $package_entry{'lib'};
261 dpurdie 6865
#       delete $package_entry{'extras'};                   # Keep these
227 dpurdie 6866
        delete $package_entry{'Class'};
6867
 
6868
        #
6869
        #   Add the entry
6870
        #
6871
        #   Under some conditions is it possible to attempt to add the same named
6872
        #   file. This will result in a circular dependancy in the makefile
6873
        #
6874
        #   The condition is when merged libaries with PDBs (WINCE+WIN32) are merged
261 dpurdie 6875
        #   and the source for the merge is the "local directory.
227 dpurdie 6876
        #
6877
        #
6878
        my $dst = $package_entry{'dir'} ;
6879
        ( my $dfile = $file) =~ s~.*/~~;
6880
        Debug( "    added $dst/$dfile = $file" );
6881
 
6882
        $ref_dpkg->{"$dst/$dfile"} = {%package_entry}
6883
            unless ( "$dst/$dfile" eq "$file" );
6884
    }
6885
}
6886
 
6887
#-------------------------------------------------------------------------------
6888
# Function        : PackageProgRemoveFiles
6889
#
6890
# Description     : Flag a Packaged program to be not packaged
6891
#                   This mechanism is used to remove a program from packageing
6892
#                   under conditions where the toolset has generated a different
6893
#                   program.
6894
#
6895
#                   The entry is flagged as a placeholder
6896
#
6897
# Inputs          : prog        - Program to process
6898
#
6899
# Returns         : Nothing
6900
#
6901
sub PackageProgRemoveFiles
6902
{
6903
    my ($prog) = @_;
6904
    Verbose ("PackageProgRemoveFiles: $prog" );
6905
    return unless (exists($PROG_PKG{$prog}));
6906
 
6907
    #
6908
    #   Must lookup the TAG to locate the  required entry
6909
    #
6910
    my $tag = $PROG_PKG{$prog};
6911
    foreach my $entry ( @$tag )
6912
    {
6913
        Verbose("Do not package: $entry");
6914
        if ( exists $PACKAGE_PROGS{$entry} )
6915
        {
6916
            $PACKAGE_PROGS{$entry}{placekeeper} = 'ProgRemoved';
6917
        }
6918
    }
6919
}
6920
 
6921
#-------------------------------------------------------------------------------
6922
# Function        : DPackageLibrary
6923
#
6924
# Description     : Collect information to allow the generation of a DPACKAGE
299 dpurdie 6925
#                   file. This directive allows the generation of "Library"
227 dpurdie 6926
#                   directives within the final DPACKAGE
6927
#
6928
#                   This directive does generate the DPACKAGE file.
6929
#
6930
# Inputs          : platform    - This does not need to be an active platform
6931
#                                 it is simply passed to the DPACKAGE builder
6932
#
6933
#                   using       - The "using" target
6934
#
6935
#                   ...         - Arguments for the Library directive
6936
#
6937
# Returns         :
6938
#
6939
sub DPackageLibrary
6940
{
6941
    JatsDPackage::DPackageAdd ( @_ );
299 dpurdie 6942
    $DPackageDirective = 1;
227 dpurdie 6943
}
6944
 
6945
#-------------------------------------------------------------------------------
6946
# Function        : SetProjectBase
6947
#
6948
# Description     : Allows the user to modify the build's concept of the Base
6949
#                   of the build. By default the base is the same directory as
6950
#                   the build.pl file, but in some contorted environments it
6951
#                   is a great deal simpler to specify a differnt base.
6952
#
6953
#                   The use may use the variable $ProjectBase as a path
6954
#                   specifier to locate files and directories
6955
#
6956
#                   Both absolute and relative paths are supported
6957
#                   If the initial value of $ProjectBase is relative then
6958
#                   it will be maintained as a relative path.
6959
#
6960
# Inputs          : elements        path to base
6961
#                                   These may be:
6962
#                                       --Up=xx
6963
#                                       name
6964
#
6965
# Returns         : Nothing
6966
#
6967
 
6968
#
6969
#   Allow the user to modify the project base variable
6970
#
6971
sub SetProjectBase
6972
{
6973
    my $rip = 0;
6974
    my $path = "";
6975
    my $is_relative;
6976
 
6977
    Debug("ProjectBase Initial: $ProjectBase, @_");
6978
 
6979
    #
6980
    #   Ensure that the ProjectBase is in a "nice" form
6981
    #   1) No /./ bits
6982
    #   2) No trailing /
6983
    #   3) Not equal to .
6984
    #   4) No training /.
6985
    #   5) No //
6986
    #
6987
    $ProjectBase =~ s~/\./~/~g;
6988
    $ProjectBase =~ s~/$~~g;
6989
    $ProjectBase =~ s~^\.$~~g;
6990
    $ProjectBase =~ s~/\.$~~g;
6991
    $ProjectBase =~ s~//$~/~g;
6992
 
6993
    #
6994
    #   ProjectBase may be absolute or relative
6995
    #   Determine this before we mess with it
6996
    #
6997
    $is_relative = ($ProjectBase !~ m~^/~);
6998
 
6999
    #
7000
    #   Process each argument
7001
    #
7002
    foreach ( @_ )
7003
    {
7004
        if ( /^--Up=([0-9]*)/ ) {
7005
            $rip = $1;
7006
        } elsif ( /^--/ ) {
7007
            Warning( "SetProjectBase - unknown option \"$_\" - ignored" );
7008
        } else {
7009
            $path = $_;
7010
        }
7011
    }
7012
 
7013
    #
7014
    #   Process the UP requests
7015
    #   If the tail directory is a ".." then up is done by adding another ".."
7016
    #   If the tail directory is not a "..", then up is done by removing it
7017
    #
7018
    #   If we go past the start of the path then simply add ".."
7019
    #
7020
    while ( $rip-- > 0 )
7021
    {
7022
        Debug2("ProjectBase: $ProjectBase, Up: $rip, IsRel: $is_relative");
7023
 
7024
        #
7025
        #   If ending in a /.. or is exactly equal to ..
7026
        #   Then its a dot-dot and the way to go UP is to append another ..
7027
        #
7028
        if ( $ProjectBase =~ m~(/\.\.$)|(^\.\.$)~ )
7029
        {
7030
            $ProjectBase .= '/..';
7031
        }
7032
        else
7033
        {
7034
            #
7035
            #   Not a dot-dot ending
7036
            #   Attempt to remove the last directory of the form
7037
            #       /xxxxx
7038
            #   Where the leading / is optional
7039
            #   Note: Must have at least one character in the dirname
7040
            #         This prevents leading / from matching - which is needed
7041
            #
7042
            unless ($ProjectBase =~ s~/?[^/]+$~~)
7043
            {
7044
                #
7045
                #   Removal failed
7046
                #   If a relative path then we can keep on going up,
7047
                #   otherwise we are dead.
7048
                #
7049
                Error ("ProjectBase outside project") unless ($is_relative);
7050
                $ProjectBase = '..';
7051
            }
7052
 
7053
            #
7054
            #   Ensure that the leading / in an absolute path is not deleted
7055
            #
7056
            $ProjectBase = '/'
7057
                unless ( $is_relative || $ProjectBase );
7058
        }
7059
    }
7060
 
7061
    #
7062
    #   Append the user path
7063
    #
7064
    $ProjectBase .= '/' . $path if ( $path );
7065
    $ProjectBase = '.' unless ( $ProjectBase );
7066
    Debug("ProjectBase set to : $ProjectBase");
7067
 
7068
    #
7069
    #   Once upon a time I tried to convert paths that contained spaces into
7070
    #   short (mangled) names. This was not sucessful because:
7071
    #       1) Clearcase dynamic views do not support name mangling
7072
    #       2) Samba file system does not appear to support name mangling
7073
    #
7074
    #   Spaces in paths are not good for MAKE
7075
    #   Now I simple generate a message
7076
    #
7077
    Warning( "ProjectBase contains a space: $ProjectBase")
7078
        if ( $ProjectBase =~ m/ / );
7079
 
7080
    #
7081
    #   Sanity check
7082
    #   Absolute paths can be checked easily
7083
    #   Checking of relative paths does not appear to work
7084
    #   When I tested it chdir, opendir and stat would limit themselves
7085
    #   and drop into the root directory ( under windows )
7086
    #
7087
    #   Solution: Check the path does not extend beyond the file tree
7088
    #
7089
    my $distance = 1;
7090
    my $tpath = $ProjectBase;
7091
 
7092
    if ( $is_relative && $tpath ne '.' )
7093
    {
7094
        #
7095
        #   Build up the complete pathname by merging it with the
7096
        #   current directory. Then clean it up.
7097
        #
7098
        $tpath = $::Cwd . '/' . $ProjectBase;
7099
 
7100
        #
7101
        #   Scan the list of diretories and count the distance from the root
7102
        #   This should not be greater than zero for sanity
7103
        #   Note: Get an empty elemement from the split due to
7104
        #         the leading / of the ABS path
7105
        #
7106
        $distance = 0;
7107
        foreach (  split ('/', $tpath) )
7108
        {
7109
            if ( m~\.\.~ )
7110
            {
7111
                $distance--;
7112
            }
7113
            else
7114
            {
7115
                $distance++;
7116
            }
7117
        }
7118
    }
7119
 
7120
    #
7121
    #   Warn if not a valid directory
7122
    #
7123
    Warning( "ProjectBase is not a directory: $ProjectBase")
7124
        if ( $distance <= 0 || !  -d $tpath  );
7125
 
7126
    #
7127
    #   $ProjectBase will always be a valid directory, but if its the top
7128
    #   directory (/) and it is added to a path we will get //path
7129
    #   This is not good, so // will be removed later in the AddIncDir and
7130
    #   AddSrcDir commands where $ProjectBase is really used.
7131
    #
7132
    #   Alternatively we could set $ProjectBase to an empty string, but then
7133
    #   this may be confused with an empty relative directory
7134
    #
7135
    Debug("ProjectBase Final  : $ProjectBase");
7136
}
7137
 
7138
#-------------------------------------------------------------------------------
7139
# Function        : DeployPackage
7140
#
7141
# Description     : Generate a deployed package
7142
#                   This is a gateway to a different packaging system
7143
#
7144
#                  DeployPackage and PackageXxxxx directives are mutually
7145
#                  exclusive. Only one person can play in the package area.
7146
#
7147
# Inputs          : Platform Specifier
7148
#                   Package Name    (Optional)
7149
#                   Options
7150
#                       --Name : Base name of the package. The default is taken
7151
#                                from the build.pl file
7152
#                       --Dir  : Package directory
7153
#                                The default is based on the package name
7154
#
7155
# Returns         :
7156
#
7157
sub DeployPackage
7158
{
7159
    my( $platforms, @elements ) = @_;
7160
    my $dir;
7161
    my $name;
7162
 
267 dpurdie 7163
    #
7164
    #   Flag that this build creates a deployable package, even if its not
7165
    #   active on this platform.
7166
    #
7167
    $DEPLOYPACKAGE = 1;
7168
 
7169
 
227 dpurdie 7170
    Debug2( "DeployPackage($platforms, @elements)" );
7171
    return if ( ! ActivePlatform($platforms) );
7172
 
7173
    #
7174
    #   Only allow one use of this directive
7175
    #
7176
    Error("DeployPackage can only be used once" ) if ( %DEPLOYPACKAGE );
267 dpurdie 7177
    $DEPLOYPACKAGE = 2;
227 dpurdie 7178
 
7179
    #
7180
    #   Ensure that the deployment file is available
7181
    #
7182
    my $command_file = $ScmDeploymentPatch ? "deploypatch.pl" : "deployfile.pl";
7183
    Error("DeployPackage: $command_file not found") unless (-f "./$command_file");
7184
    #
7185
    #   Collect arguments
7186
    #
7187
    foreach (@elements )
7188
    {
7189
        if ( m/^--Dir=(.*)/ ) {
7190
            Error ("DeployPackage: Package directory defined multiple times") if $dir;
7191
            $dir = $1;
7192
 
7193
        } elsif ( m/^--Name=(.*)/ ) {
7194
            Error ("DeployPackage: Package name defined multiple times") if $name;
7195
            $name = $1;
7196
 
7197
        } elsif ( m/^--/ ) {
7198
            Warning( "DeployPackage: Unknown option ignored: $_");
7199
 
7200
        } else {
7201
            Error ("DeployPackage: Package name defined multiple times") if $name;
7202
            $name = $_;
7203
 
7204
        }
7205
    }
7206
 
7207
    $name = $::ScmBuildPackage unless ( $name );
7208
 
7209
    #
7210
    #   Save the deployment data
7211
    #
7212
    $dir = lc($name) unless ( $dir );
7213
    $DEPLOYPACKAGE{'name'} = $name;
7214
    $DEPLOYPACKAGE{'dir'} = $dir;
7215
    $DEPLOYPACKAGE{'cmdfile'} = $command_file;
7216
 
7217
    #
7218
    #   Flag that toolset tests should be supressed
7219
    #   The Deploy world does not really use the full makefiles and if the
7220
    #   compilers are not installed will not be able to create deployment
7221
    #   packages
7222
    #
7223
    $ScmNoToolsTest = 1;
7224
}
7225
 
7226
 
7227
###############################################################################
7228
###############################################################################
7229
# Private function section.
7230
#       The following functions are used INTERNALLY by makelib.pl2.
7231
###############################################################################
7232
 
7233
###############################################################################
7234
#   A collection of functions to write to the MAKEFILE handle
7235
#
7236
#   MakeHeader          - Write a nice section header
7237
#   MakeNewLine         - Print a new line
7238
#   MakePrint           - Print a line ( without trailing \n)
7239
#   MakeQuote           - Escape \ and " character, then print a line
7240
#   MakePrintList       - Print an array
7241
#   MakeEntry           - Complex line printer
7242
#   MakePadded          - Padded line printer (internal)
7243
#   PadToPosn           - Calc space+tabs to tabstop (internal)
7244
#   MakeEntry3          - Complex Line Printer
7245
#   MakeDefEntry        - Print a definition line (Production + Debug support)
7246
#   MakeIfDefEntry      - Print ifdef entry
261 dpurdie 7247
#   MakeIfnDefEntry     - Print ifndef entry
7248
#   MakeIfZeroEntry     - Print ifeq entry
227 dpurdie 7249
#
7250
###############################################################################
7251
 
7252
sub MakeHeader
7253
{
7254
    my ($text, @rest) = @_;
7255
    my $length = length ($text);
7256
 
7257
    print MAKEFILE "\n";
7258
    print MAKEFILE "#--------- $text ", '-' x (80 - 12 - $length)  ,"\n";
7259
    print MAKEFILE "#    $_\n" foreach  ( @rest ) ;
7260
    print MAKEFILE "#\n";
7261
}
7262
 
7263
sub MakeNewLine         # Print a newline to the current 'Makefile'
7264
{
7265
    print MAKEFILE "\n";
7266
}
7267
 
7268
sub MakePrint           # Print to the current 'Makefile'
7269
{
7270
    print MAKEFILE @_
7271
        if ( defined $_[0] );
7272
}
7273
 
7274
sub MakeQuote           # Quote a makefile text line
7275
{
7276
    my( $line ) = @_;
7277
    $line =~ s/\\/\\\\/g;                       # quote all '\' characters
7278
    $line =~ s/"/\\"/g;                         # Then quote '"' characters
255 dpurdie 7279
    $line =~ s/=#/=\\#/g;                       # Then quote '=#' sequence
227 dpurdie 7280
    print MAKEFILE $line;
7281
}
7282
 
7283
sub MakePrintList
7284
{
7285
    print MAKEFILE $_ . "\n" foreach (@{$_[0]});
7286
}
7287
 
7288
 
7289
#-------------------------------------------------------------------------------
7290
# Function        : MakeEntry
7291
#
7292
# Description     : Build a entry based on the element list
7293
#                   Creates text of the form
7294
#                       $(BINDIR)/prog.exe: object1.obj \
7295
#                                           object2.obj
7296
#
7297
#
7298
# Inputs          : $prelim         - Preamble (one-off)
7299
#                   $postlim        - Postamble (one-off)
7300
#                   $prefix         - Pefix (to each element of array)
7301
#                   $postfix        - Postfix (to each element of array )
7302
#                   @elements       - Array of element to wrap
7303
#
7304
# Returns         :   1 Always
7305
#
7306
# Notes:
7307
#       The above description means that the following entry format is
7308
#       produced:
7309
#
7310
#           <preliminary><prefix><variant1><prefix><variant2>...<final>
7311
#
7312
#       With judicious use of newline and tab characters, a target
7313
#       and dependency list along with the command(s) to build the
7314
#       target can be constructed.
7315
#
7316
sub MakeEntry
7317
{
7318
    my( $prelim, $postlim, $prefix, $postfix, @elements ) = @_;
7319
 
7320
    MakePrint $prelim;
7321
    MakePrint "${prefix}${_}${postfix}" foreach ( @elements );
7322
    MakePrint $postlim if ($postlim);
7323
    return 1;
7324
}
7325
 
7326
#-------------------------------------------------------------------------------
7327
# Function        : MakePadded
7328
#
7329
# Description     : Generate aligned output of the form
7330
#                       Prefix_text           Aligned_text
7331
#                   where the aligned text is at a specified TAB boundary
7332
#
7333
# Inputs          : $align      - Tab stop (One tab = 8 chars)
7334
#                   $prefix     - Text to print before alignment occurs
7335
#                   @line       - Remainder of the line
7336
#
7337
sub MakePadded          # Print to the current 'Makefile', tab aligning
7338
{
7339
    my( $align, $prefix, @line ) = @_;
7340
 
7341
    my $strlen = length( $prefix );
7342
    my $pad = PadToPosn( $strlen, $align * 8 );
7343
 
7344
    print MAKEFILE $prefix . $pad;
7345
    print MAKEFILE @line;
7346
}
7347
 
7348
#-------------------------------------------------------------------------------
7349
# Function        : PadToPosn
7350
#
7351
# Description     : Given that we are at $startposn return a tab and space
7352
#                   string to place us at $endposn
7353
#
7354
sub PadToPosn
7355
{
7356
    my ($startposn, $endposn ) = @_;
7357
 
7358
 
7359
    #
7360
    #   Case where we are already too far into the line
7361
    #
7362
    return ( ' ' )if ( $endposn <= $startposn );
7363
 
7364
    my $tcount = 0;
7365
    my $scount = 0;
7366
 
7367
    while ( $startposn < $endposn )
7368
    {
7369
        $tcount ++;
7370
        $startposn = ($startposn >> 3) * 8 + 8;
7371
 
7372
        my $delta = $endposn - $startposn;
7373
        if ( $delta < 8 )
7374
        {
7375
            $scount = $delta;
7376
            last;
7377
        }
7378
 
7379
    }
7380
    return ( "\t" x $tcount .  ' ' x $scount );
7381
}
7382
 
7383
#-------------------------------------------------------------------------------
7384
# Function        : MakeEntry3
7385
#
7386
# Description     : Build a makefile entry based on the element list, tab aligned
7387
#                   Can creat text of the form:
7388
#                       TAG = NAME0 \       TAG : NAME0 \ 
7389
#                             NAME1               NAME1
7390
#
7391
#
7392
# Inputs          : $prelim             - Preliminary text
7393
#                   $presep             - Preliminary seperator
7394
#                   $elem_ref           - Either a single name or a reference to
7395
#                                         and array of names, or a hash.
7396
#
7397
# Returns         : Writes directly to the Makefile
7398
#
7399
sub MakeEntry3
7400
{
7401
    my( $prelim, $presep, $elem_ref ) = @_;
7402
 
7403
    #
7404
    #   The prelim may have some "\n" characters at the start
7405
    #   These simplify formatting, but mess up the nice formatting
7406
    #
7407
    if ($prelim =~ m~(^\n+)(.*)~ )
7408
    {
7409
        MakePrint $1;
7410
        $prelim = $2;
7411
    }
7412
 
7413
    #
7414
    #   Print the definition and the sep with nice padding
7415
    #
7416
    MakePadded ( 3, $prelim, $presep );
7417
    my $leadin = ' ';
7418
 
7419
    #
7420
    #   If a HASH reference then use a sorted list of keys from the hash.
7421
    #
7422
    if ( ref ($elem_ref) eq "HASH" )
7423
    {
7424
        my @hash_list;
7425
        @hash_list = sort keys ( %{$elem_ref} );
7426
        $elem_ref = \@hash_list;
7427
    }
7428
 
7429
    #
7430
    #   If the list is only one element long, then create a simple form
7431
    #   If the list is not an array ref, then treat it as a single element
7432
    #
7433
    if ( ref ($elem_ref) eq "ARRAY" )
7434
    {
7435
        my $line = 0;
7436
        foreach my $element ( @$elem_ref )
7437
        {
7438
            print MAKEFILE $leadin . $element;
7439
            $leadin = " \\\n" . PadToPosn(0,24 + length( $presep ) + 1 ) unless ($line++);
7440
        }
7441
    }
7442
    elsif ( defined $elem_ref )
7443
    {
7444
            print MAKEFILE $leadin . $elem_ref;
7445
    }
7446
    MakeNewLine();
7447
    return 1;
7448
}
7449
 
7450
#-------------------------------------------------------------------------------
7451
# Function        : MakeDefEntry
7452
#
7453
# Description     : Make a definition entry of the form
7454
#
7455
#                       TAG = NAME0 \
7456
#                             NAME1
7457
#
7458
#                   Support a list of definitions that will always be created
7459
#                   as well as a production and a debug list.
7460
#
7461
#                   Will always generate the "TAG = " string, even if the list
7462
#                   is empty.
7463
#
7464
#                   Will supress the TAG if there is no data if the FIRST opr starts with a '+'
7465
#
7466
# Inputs          : TAG         - Text tag to create
7467
#                   FIRST       - First assignement opr. = or +=
7468
#                   ALL_LIST    - A reference to a list of names to assign
7469
#                                 or a single name.
7470
#                   PROD_LIST   - Optional list to extend the definition with for a production build
7471
#                   DEBUG_LIST  - Optional list to extend the definition with for a debug build
7472
#
7473
# Returns         : Nothing
7474
#
7475
 
7476
sub MakeDefEntry
7477
{
7478
    my( $tag, $assign, $all, $prod, $debug ) = @_;
7479
 
7480
    #
7481
    #   Do not generate anything if the $opr is "+=" and there is no data
7482
    #   to output. ie: Supress empty TAG += statements
7483
    #
7484
    return if ( $assign =~ m/\+/ && ( ref($all) && ! defined $all->[0] ) );
7485
 
7486
    #
7487
    #   TAG for all entries
7488
    #
7489
    MakeEntry3( $tag, $assign, $all );
7490
 
7491
 
7492
    #
7493
    #   TAGs for PROD build
7494
    #   TAGs for DEBUG build
7495
    #
7496
    if ( defined $prod && defined $prod->[0] )
7497
    {
7498
        print MAKEFILE 'ifeq "$(DEBUG)" "0"' . "\n";
7499
        MakeEntry3( $tag, "+=", $prod );
267 dpurdie 7500
        print MAKEFILE 'endif' . "\n";
227 dpurdie 7501
    }
7502
 
7503
    if ( defined $debug && defined $debug->[0] )
7504
    {
7505
        print MAKEFILE 'ifeq "$(DEBUG)" "1"' . "\n";
7506
        MakeEntry3( $tag, "+=", $debug );
267 dpurdie 7507
        print MAKEFILE 'endif' . "\n";
227 dpurdie 7508
    }
7509
 
7510
}
7511
 
7512
sub MakeIfDefEntry
7513
{
7514
    my( $iftag, @rest ) = @_;
7515
 
7516
    print MAKEFILE "ifdef $iftag\n";
7517
    MakeDefEntry (@rest);
7518
    print MAKEFILE "endif\n\n";
7519
}
7520
 
7521
sub MakeIfnDefEntry
7522
{
7523
    my( $iftag, @rest ) = @_;
7524
 
7525
    print MAKEFILE "ifndef $iftag\n";
7526
    MakeDefEntry (@rest);
7527
    print MAKEFILE "endif\n\n";
7528
}
7529
 
261 dpurdie 7530
sub MakeIfZeroEntry
7531
{
7532
    my( $iftag, @rest ) = @_;
7533
 
7534
    print MAKEFILE "ifeq (\$($iftag),0)\n";
7535
    MakeDefEntry (@rest);
7536
    print MAKEFILE "endif\n\n";
7537
}
7538
 
227 dpurdie 7539
#-------------------------------------------------------------------------------
7540
# Function        : CreateNameList
7541
#
7542
# Description     : Create a list of names by adding a prefix and suffix to a
7543
#                   list of items. This is used to add a directory prefix and a
7544
#                   file suffix to a list of files.
7545
#
7546
# Inputs          : $prefix             ie: '$(OBJDIR)/'
7547
#                   $suffix             ie: '.obj'
7548
#                   $elem_ref           ie: A list of files ( passed be ref )
7549
#                                           If a Hash then its sorted keys is used
7550
#
7551
# Returns         : A ref to the resulting list
7552
#
7553
sub CreateNameList
7554
{
7555
    my( $prefix, $suffix, $elem_ref ) = @_;
7556
    my @result;
7557
 
7558
    if ( ref ($elem_ref) eq "HASH" )
7559
    {
7560
        my @hash_list;
7561
        @hash_list = sort keys ( %{$elem_ref} );
7562
        $elem_ref = \@hash_list;
7563
    }
7564
 
7565
    foreach  ( @$elem_ref )
7566
    {
7567
        push @result, $prefix . $_ . $suffix;
7568
    }
7569
    return \@result;
7570
}
7571
 
7572
#-------------------------------------------------------------------------------
7573
# Function        : ListGeneratedProjects
7574
#
7575
# Description     : Return a list of generated/nongenerated projects
7576
#                   Used in conjunction with CreateNameList
7577
#
7578
# Inputs          : $type       - TRUE : Generated
7579
#                                 FALSE: Not Generated
7580
#
7581
# Returns         : A reference to a list of projects
7582
#                   undef will be retuend if there are no projects
7583
#
7584
sub ListGeneratedProjects
7585
{
7586
    my ($type) = @_;
7587
    my @list;
7588
    foreach my $project ( @PROJECTS_ORDER )
7589
    {
7590
        if ( exists($PROJECTS{$project}->{'generated'}) xor $type )
7591
        {
7592
            push @list, $project;
7593
        }
7594
    }
7595
    return @list ? \@list : undef;
7596
}
7597
 
7598
#-------------------------------------------------------------------------------
7599
# Function        : ListCleanGenerated
7600
#
7601
# Description     : return a list of generated targets that have 'clean'
7602
#                   operations. This is used in conjunction with CreateNameList
7603
#
7604
# Inputs          : None
7605
#
7606
# Returns         : A list of project indexes, that can be cleaned
7607
#
7608
sub ListCleanGenerated
7609
{
7610
    my @list;
7611
    foreach my $i ( @GENERATE_FILES )
7612
    {
7613
        push @list, $i->{'index'}
7614
            if ( $i->{'clean'} );
7615
    }
7616
    return \@list;
7617
}
7618
 
251 dpurdie 7619
#-------------------------------------------------------------------------------
7620
# Function        : MakeResolve
7621
#
7622
# Description     : Internal Function
7623
#                   Locate a source file by examining a list of directories
7624
#
7625
#                   Don't use directly
7626
#                   Use MakeSrcResolve or MakeSrcResolveExtended
7627
#
7628
# Inputs          : $dirs           - Ref to an array of directories to scan
7629
#                   $source         - File to locate
7630
#
7631
# Returns         : Resolved path to the file
7632
#                   Will warn if multiple instances of the file are found
7633
#
227 dpurdie 7634
sub MakeResolve
7635
{
7636
    my( $dirs, $source ) = @_;
285 dpurdie 7637
    my( $first, $count );
227 dpurdie 7638
 
237 dpurdie 7639
    #
7640
    #   If the path contains a '$' then its assumed to be
7641
    #   a variable name in the path. Just assume that it exists
7642
    #
7643
    return $source if ( $source =~ m#\$# );
7644
 
7645
    #
7646
    #   If the path is absolute or contains a leading ., then don't search
7647
    #   Warn if it can't be found
7648
    #
7649
    if ( $source =~ m#^(/|\.)# )
7650
    {
7651
        Warning( "Unable to resolve '$source' path" ) unless -f $source;
7652
        return $source;
227 dpurdie 7653
    }
7654
 
237 dpurdie 7655
 
227 dpurdie 7656
#.. search local path first
7657
#
7658
    $count = 0;
7659
    $first = "";
331 dpurdie 7660
    $first = "$source"                              # was ./$source
227 dpurdie 7661
        if (-r "$source");
7662
 
7663
#.. search directory paths
7664
#
285 dpurdie 7665
    foreach my $dir (@$dirs)
227 dpurdie 7666
    {
331 dpurdie 7667
        next if ( $dir eq '.' );
7668
        my $temp = "$dir/$source";                  # was ./$dir/$source
227 dpurdie 7669
        Debug2( "MakeResolve: Looking in: $temp" );
7670
        if (-r "$temp")
7671
        {
7672
            if ($first eq "") {
7673
                $first = $temp;
7674
            } else {
7675
                Warning( "Duplicate '$source' image - '$temp'" );
7676
                $count++;
7677
            }
7678
        }
7679
        Debug3( "MakeResolve: $count, $temp" );
7680
    }
7681
 
7682
    if ($first eq "") {
7683
        $first = $source;
7684
        Warning( "Unable to resolve '$source' path" );
7685
    } else {
7686
        Warning( "          using '$first'" )
7687
            if ($count);
7688
    }
7689
    return $first;
7690
}
7691
 
251 dpurdie 7692
#-------------------------------------------------------------------------------
7693
# Function        : MakeSrcResolve
7694
#
7695
# Description     : Locate a source file by examining the list of source
7696
#                   directories. There are a few frills
7697
#
7698
#                   Look for a source file in
7699
#                       1) %::BUILD_KNOWNFILES
7700
#                       2) %SRCS
7701
#                       3) Dirs specified by the array @SRCSDIRS
7702
#
7703
# Inputs          : Name of a file to resolve
7704
#
7705
# Returns         : Resolved path.
283 dpurdie 7706
#                   Input file - if not found at all
251 dpurdie 7707
#
227 dpurdie 7708
sub MakeSrcResolve
7709
{
7710
    my ($name) = @_;
7711
    my $file;
7712
 
251 dpurdie 7713
    if ( exists ( $::BUILD_KNOWNFILES{$name} ) ) {
7714
        #
7715
        #   The Known Files list is relative to ScmRoot
7716
        #   This must be included in the full path
7717
        #
7718
        $file = $ScmRoot . '/' . $::BUILD_KNOWNFILES{$name};
7719
 
7720
    } elsif ( exists $SRCS{$name} ) {
7721
        $file = $SRCS{$name};
7722
 
7723
    } else {
7724
        $file = MakeResolve( \@SRCDIRS, @_ )
7725
    }
227 dpurdie 7726
    return $file;
7727
}
7728
 
7729
 
7730
# MakeSrcResolveExtended
7731
#   from_global = 0 : Search user specified directories
7732
#               = 1 : Search LinkPkgArchive list
7733
#
7734
our @PkgSrcDirList;
7735
sub MakeSrcResolveExtended
7736
{
7737
    my ( $from_global, $file ) = @_;
7738
 
7739
    #
7740
    #   Simple Case. Resolve source from known source directories
7741
    #
7742
    #
7743
    return MakeSrcResolve( $file )
7744
        unless ( $from_global );
7745
 
7746
    #
7747
    #   Not so simple Case
7748
    #   Resolve the source from the imported packages
7749
    #
7750
    #   Create a list of directores to search, but only the first time
311 dpurdie 7751
    #       - Interface directories - from BuildPkgArchive
227 dpurdie 7752
    #       - LnkPkgArchive directories
7753
    #         Using target,product,platform include directories
7754
    #
7755
    unless ( @PkgSrcDirList )
7756
    {
7757
        for my $entry (@{$::ScmBuildPkgRules{$ScmPlatform} })
7758
        {
311 dpurdie 7759
            next if ( $entry->{'TYPE'} eq 'build' ); # Ignore BuildPkgArchives
7760
 
227 dpurdie 7761
            for (@{$entry->{'PINCDIRS'}}, @{$entry->{'THXDIRS'}}, '' )
7762
            {
7763
                my $dir = $entry->{'ROOT'} . "/" . $_ ;
7764
                $dir =~ s~//~/~g;
7765
                $dir =~ s~/$~~;
311 dpurdie 7766
                push ( @PkgSrcDirList, $dir );
227 dpurdie 7767
            }
7768
        }
311 dpurdie 7769
    }
227 dpurdie 7770
 
7771
    return MakeResolve( \@PkgSrcDirList, $file );
7772
}
7773
 
7774
#-------------------------------------------------------------------------------
7775
# Function        : GetPackageRoot
7776
#
7777
# Description     : Determine the root directory for a given package
7778
#                   This routine is intended for non-standard JATS scripts that
7779
#                   access package contents directly
7780
#
7781
#                   Note: This routine does not attempt to handle multiple
7782
#                         instances of a package ( sysbasetypes ).
7783
#
7784
# Inputs          : $pname          - Name of the package
7785
#
7786
# Returns         :
7787
#
7788
sub GetPackageRoot
7789
{
7790
    my( $pname ) = @_;
7791
    Debug( "GetPackageRoot(@_)" );
7792
 
7793
    my $result = undef;
7794
    my $pkg = GetPackageEntry( $pname );
7795
    if ( $pkg )
7796
    {
7797
        $result = $pkg->{'ROOT'};
7798
        Debug( "GetPackageRoot: $result" );
7799
    }
7800
 
7801
    return $result;
7802
}
7803
 
7804
#-------------------------------------------------------------------------------
7805
# Function        : ActiveProject
7806
#
7807
# Description     : Determine if the specified project is currenly 'active'
7808
#
345 dpurdie 7809
# Inputs          : $project            - one or more project names separated
7810
#                                         by either a comma or a colon
227 dpurdie 7811
#
7812
# Returns         : TRUE    if the project is active
7813
#
7814
sub ActiveProject
7815
{
7816
    my ($project) = @_;
345 dpurdie 7817
    foreach (  split( '\s*[:,]\s*', $project ) )
227 dpurdie 7818
    {
7819
        return 1
7820
            if ( $_ eq $::ScmBuildProject );
7821
    }
7822
    return 0;
7823
}
7824
 
345 dpurdie 7825
#-------------------------------------------------------------------------------
7826
# Function        : ActiveDefine
7827
#
7828
# Description     : Determine if the specified definition is currenly 'active'
7829
#
7830
# Inputs          : $defs               - one or more variable names separated
7831
#                                         by either a comma or a colon
7832
#
7833
# Returns         : TRUE    if any of the definitions are known
7834
#
7835
sub ActiveDefine
7836
{
7837
    my ($defs) = @_;
7838
    no strict 'refs';
7839
    foreach (  split( '\s*[:,]\s*', $defs ) )
7840
    {
7841
        return 1
7842
            if ( defined( $$_ ) || defined( @$_ ) );
7843
    }
7844
    use strict 'refs';
7845
    return 0;
7846
}
227 dpurdie 7847
 
7848
#-------------------------------------------------------------------------------
345 dpurdie 7849
# Function        : ActiveMachType
7850
#
7851
# Description     : Determine if the specified MachType is currenly 'active'
7852
#
7853
# Inputs          : $mtype              - one or more machine names separated
7854
#                                         by either a comma or a colon
7855
#
7856
# Returns         : TRUE    if any of the current MachType is in the list
7857
#
7858
sub ActiveMachType
7859
{
7860
    my ($mtype) = @_;
7861
    foreach (  split( '\s*[:,]\s*', $mtype ) )
7862
    {
7863
        return 1
7864
            if ( uc($_) eq uc($::GBE_MACHTYPE) );
7865
    }
7866
    return 0;
7867
}
7868
 
7869
#-------------------------------------------------------------------------------
227 dpurdie 7870
# Function        : ActivePlatform
7871
#
7872
# Description     : Determine if the specified platform is currently 'active'
7873
#                   This is used by all user directives in order to determine
7874
#                   if the directive should be ignored for the current platform
7875
#
7876
# Inputs          : $platform_spec      - A platform specifier
7877
#                                         This is a bit complex.
7878
#
241 dpurdie 7879
#                   Format of platform_spec. One or more of
7880
#                       PlatformName
7881
#                       AliasName
7882
#                       TargetName,--Target
345 dpurdie 7883
#                   Special Options (Must all be True)
7884
#                       --Project=ProjectName[:ProjectName]+
7885
#                       --Defined=SomeValue[:SomeValue]+
7886
#                       --MachType=SomeValue[:SomeValue]+
7887
 
7888
#                   Each can be prefixed with a '!' to negate the test
227 dpurdie 7889
#
241 dpurdie 7890
#                   Valid options are:
271 dpurdie 7891
#                       --Target        - indicates that the platform is a 'target'
241 dpurdie 7892
#
7893
# Returns         : TRUE if the platform spec is satisfied
7894
#
227 dpurdie 7895
sub ActivePlatform
7896
{
7897
    my( $platform_spec ) = @_;
7898
    my( @platforms, $scmplatform, $platform );
7899
    my( %arguments, @args, $filter );
241 dpurdie 7900
    my @plist;
7901
    my ($match_count, $count_invert, $count_vert) = (0,0,0);
227 dpurdie 7902
 
241 dpurdie 7903
    #
7904
    #   Short circuit check
7905
    #   '*' is used so often that it pays to check it first
7906
    #
7907
    if ( $platform_spec eq '*' )
7908
    {
7909
        Debug3( " ActivePlatform(@_) = TRUE" );
7910
        return 1;
7911
    }
227 dpurdie 7912
 
241 dpurdie 7913
    #
7914
    #   Platform specifier may be a comma seperated list
7915
    #   ie:  WIN32,MOS,XXX
7916
    #   Extract non-platform arguments
279 dpurdie 7917
    #   Process to yield a dummy platform of '0' or '1' - these will be seen later
241 dpurdie 7918
    #
7919
    foreach ( split( '\s*,\s*', $platform_spec ) )
7920
    {
345 dpurdie 7921
        my ($result, $not);
7922
        if ( m~^(!?)--Project=(.+)~ ) {
325 dpurdie 7923
            $not = $1;
345 dpurdie 7924
            $result = ActiveProject($2);
277 dpurdie 7925
 
345 dpurdie 7926
        } elsif ( m~^(!?)--Defined=(.+)~ ) {
325 dpurdie 7927
            $not = $1;
345 dpurdie 7928
            $result = ActiveDefine($2);
241 dpurdie 7929
 
345 dpurdie 7930
        } elsif ( m~^(!?)--MachType=(.+)~ ) {
325 dpurdie 7931
            $not = $1;
345 dpurdie 7932
            $result = ActiveMachType($2);
7933
 
325 dpurdie 7934
        } else {
7935
            #
7936
            #   Must be a platform argument
7937
            #   Add to a list
7938
            #
7939
            push @platforms, $_;
241 dpurdie 7940
            next;
7941
        }
7942
 
7943
        #
325 dpurdie 7944
        #   Continue processing non-platform arguments
345 dpurdie 7945
        #   Each one must be TRUE, allowing for negation.
241 dpurdie 7946
        #
325 dpurdie 7947
        $result = $result ? 1 : 0;
345 dpurdie 7948
        $result = ! $result if ( $not );
7949
        return 0 unless ( $result );
241 dpurdie 7950
    }
7951
 
7952
    #   Platform specified may be an Alias
7953
    #   Perform alias expansion
7954
    #
7955
    @platforms = ExpandPlatforms( @platforms );         # aliasing
227 dpurdie 7956
    Debug3( " ActivePlatform(@_)" );
325 dpurdie 7957
#    Debug0( " Platforms(@platforms)", "PLIST(@plist)" );
227 dpurdie 7958
 
7959
#.. Arguments
241 dpurdie 7960
#   At this point we have a list of platforms and arguments
7961
#   Build up a hash of arguments for each platform being parsed
227 dpurdie 7962
#   Multiple arguments can follow a platform name
241 dpurdie 7963
#   Arguments apply to the preceeding platform name
227 dpurdie 7964
#
241 dpurdie 7965
    $platform = undef;
227 dpurdie 7966
    foreach ( @platforms )
7967
    {
241 dpurdie 7968
        if ( /^--Target/ ) {                     # Arguments
7969
            if ( $platform ) {
7970
                $arguments{$platform}{'Target'} = 1;
7971
            } else {
317 dpurdie 7972
                Warning ("No Platform preceding platform option: $_");
241 dpurdie 7973
            }
7974
 
305 dpurdie 7975
        } elsif ( /^--Only(Prod)|(Debug)/ || /--board=/ ) {
273 dpurdie 7976
            # Known arguments
305 dpurdie 7977
            # Bit of a kludge. Must be a better way
273 dpurdie 7978
 
241 dpurdie 7979
        } elsif ( /^--/ ) {
7980
            Warning ("Unknown platform option: $_");
7981
 
227 dpurdie 7982
        } else {                                # Target
7983
            $platform = $_;
241 dpurdie 7984
            push @plist, $platform;
227 dpurdie 7985
        }
7986
    }
7987
 
241 dpurdie 7988
#.. Scan the expression
227 dpurdie 7989
#
7990
    $scmplatform = uc( $ScmPlatform );          # current platform
325 dpurdie 7991
 
241 dpurdie 7992
    foreach ( @plist )
227 dpurdie 7993
    {
7994
        $platform = uc( Trim( $_ ) );           # trim white and convert case
7995
 
7996
        #
241 dpurdie 7997
        #   Determine filter comparison
7998
        #   Either a Platform or a Target
7999
        #
8000
        if ( $arguments{$platform}{'Target'} )
227 dpurdie 8001
        {
241 dpurdie 8002
            $filter = uc( $ScmTarget );
227 dpurdie 8003
        }
241 dpurdie 8004
        else
8005
        {
8006
            $filter = $scmplatform;             # filter specification
8007
        }
8008
 
227 dpurdie 8009
        Debug3( "   Platform=$platform, Filter=$filter" );
8010
 
8011
        #
8012
        #   Examine platform names
8013
        #   Allow negation of name (!), but all the names must be negated
8014
        #   as a mix does not make sense.
8015
        #   ie:     !P1,!P2,!P3     - All except P1,P2 or P3
8016
        #            P1,P2,P2       - Only P1,P2,P3
8017
        #
241 dpurdie 8018
        my $invert = 0;
8019
        if ( substr($platform, 0, 1) eq '!' )
8020
        {
8021
            $count_invert++;
8022
            $platform = substr($platform, 1);
227 dpurdie 8023
        }
8024
        else
241 dpurdie 8025
        {
8026
            $count_vert++;
8027
        }
227 dpurdie 8028
 
241 dpurdie 8029
        $match_count++ if ( $platform eq ''  ||
8030
                            $platform eq '*' ||
8031
                            $platform eq '1' ||
8032
                            $platform eq $filter );
227 dpurdie 8033
    }
8034
 
241 dpurdie 8035
    #
8036
    #   Sanity test
8037
    #   Force failure on bad sanity
8038
    #
8039
    if ( $count_vert && $count_invert )
8040
    {
8041
        Warning( "Platform expression makes no sense. Mixed use of '!' operator",
8042
                 "Expression: @_" );
8043
        return 0;
8044
    }
8045
 
8046
    #
8047
    #   Test for pass
8048
    #   If not using '!', then any match passes : P1 or P2 or P3
8049
    #   If are using '!', then any match is bad : !P1 and !P2 and !P3 == !(P1 or P2 or P3)
8050
    #
8051
    if ( ( $count_vert && $match_count ) || ( $count_invert && ( not $match_count) )   )
8052
    {
227 dpurdie 8053
        Debug3( " ActivePlatform(@_ == $ScmPlatform) = TRUE" );
8054
        return 1;
8055
    }
241 dpurdie 8056
 
227 dpurdie 8057
    Debug3( " ActivePlatform(@_ == $ScmPlatform) = FALSE" );
8058
    return 0;
8059
}
8060
 
8061
#-------------------------------------------------------------------------------
321 dpurdie 8062
# Function        : If
8063
#
8064
# Description     : Function for embedding arguments in directives
8065
#                   To be used within another directive
8066
#                   ie:
8067
#                       AnyDirective ('*',  arg1, arg2, ...
8068
#                                           If (SomePlatform, arg1, .. ,argn))
8069
#
8070
# Inputs          : $platform               - Active Platform speciifier
8071
#                   @args                   - Args
8072
#
8073
# Returns         : @args or nothing
8074
#
8075
sub  If
8076
{
8077
    my $platform = shift;
8078
    return @_
8079
        if ( ActivePlatform( $platform ));
8080
    return;
8081
}
8082
 
8083
#-------------------------------------------------------------------------------
227 dpurdie 8084
# Function        : RegisterMakefileGenerate
8085
#
8086
# Description     : Register a function to be called at the start of the
8087
#                   makefile generation process
8088
#
8089
# Inputs          : $fname      - Name of the function
8090
#                   $args       - Function Arguments
8091
#
8092
# Returns         : Nothing
8093
#
8094
our @MF_Generators;
8095
sub RegisterMakefileGenerate
8096
{
8097
   my ($fref) = @_;
8098
   my $rtype = ref($fref) || 'not a reference';
8099
 
8100
   Error ("RegisterMakefileGenerate called incorrectly",
8101
          "First argument MUST be a code reference",
8102
          "It is a $rtype"
8103
          ) unless ( $rtype eq 'CODE' );
8104
 
8105
   #
8106
   #    Save the arguments by reference in an array
8107
   #    The array will be processed later
8108
   #
8109
   push @MF_Generators, \@_;
8110
}
8111
 
8112
#-------------------------------------------------------------------------------
271 dpurdie 8113
# Function        : RegisterSrcHook
8114
#
8115
# Description     : Register a function to be called when a source file is
8116
#                   declared
8117
#
8118
# Inputs          : $ext        - Extension of interest
8119
#                                 '*' will be used by all
8120
#                   $fname      - Name of the function
8121
#                   $args       - Function Arguments
8122
#
8123
# Returns         : Nothing
8124
#
8125
sub RegisterSrcHook
8126
{
8127
    my $ext = shift;
8128
    my ($fref) = @_;
8129
    my $rtype = ref($fref) || 'not a reference';
8130
 
8131
    Error ("RegisterSrcHook called incorrectly",
8132
           "Second argument MUST be a code reference",
8133
           "It is a $rtype"
8134
           ) unless ( $rtype eq 'CODE' );
8135
 
8136
    #
8137
    #    Save the arguments by reference in an array
8138
    #    The array will be processed later
8139
    #
8140
    push @{$MF_RegisterSrcHooks{$ext}}, \@_;
8141
}
8142
 
8143
 
8144
#-------------------------------------------------------------------------------
227 dpurdie 8145
# Function        : MakefileHeader
8146
#
8147
# Description:    : Generate a "standard" makefile header.
8148
#
8149
#..
8150
 
8151
sub MakefileHeader
8152
{
8153
    my ($file, $desc, $by, @trailing) = @_;
8154
    my ($diff);
8155
 
8156
    $diff = 0 if (($diff = ((80-5) - length($desc))) < 0);
8157
    $desc .= ' ' . ('-' x $diff);
8158
 
8159
    print $file <<EOF;
8160
# -*- mode: mak; -*-
8161
#-- $desc
8162
#
8163
#                   -- Please do not edit this file. --
8164
#
8165
#       To do so may result in a system failure, in additional to any
8166
#       changes made shall be overwritten.
8167
#
8168
# Created by $by
8169
#         on $::CurrentTime
8170
#
8171
EOF
8172
    #
8173
    #   Print out the trailer
8174
    #   This is an array. Place each entry on a new line
8175
    #
8176
    print $file $_ . "\n" for ( @trailing );
8177
}
8178
 
8179
###############################################################################
8180
# MakeFileGenerate:
8181
#       This subroutine does all of the actual make file generation based
8182
#       on information provided in the calls to the various public
8183
#       interface routines.
8184
#
8185
# Inputs:
8186
#
8187
# Returns:
8188
###############################################################################
8189
 
8190
my $MakefileGenerate_once = 0;
8191
sub MakefileGenerate
8192
{
8193
    my $Makefile = "$ScmPlatform.mk";
8194
    Debug( "MakefileGenerate: $Makefile" );
8195
 
8196
    #
8197
    #   Nasty things happen when we generate a makefile twice
8198
    #   Just warn the user and do nothing
8199
    #   If its in the common makefile.pl then just ignore it
8200
    #
8201
    if ( $ScmProcessingRootMake )
8202
    {
8203
        Warning ("MakefileGenerate directive is not allowed in common makefile.pl");
8204
        return;
8205
    }
8206
 
8207
    if ( $MakefileGenerate_once )
8208
    {
8209
        Warning ("MakefileGenerate should only be called once.",
8210
                 "Dir: $::Cwd");
8211
        return;
8212
    }
8213
    $MakefileGenerate_once = 1;
8214
 
8215
    #
8216
    #   Invoke all registered Makefile Generator functions
8217
    #   These allow clever directives to collect information to be
8218
    #   processed before the makefiles are created
8219
    #
8220
    while ( @MF_Generators )
8221
    {
8222
        Debug( "MakefileGenerate: Invoke RegisterMakefileGenerate function" );
8223
        my ($fname, @args) = @{shift @MF_Generators};
8224
        &$fname ( @args );
8225
    }
8226
 
8227
    #
8228
    #   Allow the toolset the opportunity to process all the collected data
8229
    #   before the makefile is created. This is optional
8230
    #
8231
    my( $if ) = MakeIf::Factory();              # build interface
8232
    $if->Preprocess();
8233
 
8234
    #
343 dpurdie 8235
    #   If we have supressed the Toolset use, then we need to sanity test
8236
    #   the use of the toolset
8237
    #
8238
    if ( $ScmNoToolsTest )
8239
    {
8240
        ReportError ("Building programs not supported with --NoToolset") if ( @PROGS || @TESTPROGS );
8241
        ReportError ("Building libraries not supported with --NoToolset") if ( @LIBS || @MLIBS || @SHLIBS );
8242
        ReportError ("Building projects not supported with --NoToolset") if ( %PROJECTS );
8243
        ErrorDoExit();
8244
    }
8245
 
8246
    #
227 dpurdie 8247
    #   Auto package the 'descpkg' file
8248
    #   If this makefile packages any files, then it can also package the descpkg file
8249
    #   The descpkg will be piggybacked into all makefiles that do a package
8250
    #
8251
    if ( %PACKAGE_FILES || %PACKAGE_HDRS || %PACKAGE_CLSS || %PACKAGE_LIBS
8252
                        || %PACKAGE_SHLIBS || %PACKAGE_PROGS )
8253
    {
251 dpurdie 8254
        Src ('*', 'descpkg') unless ($SRCS{ descpkg });
8255
        PackageFile ('*', 'descpkg');
227 dpurdie 8256
    }
8257
 
8258
    #
8259
    #   Some toolsets NEED a relative root
261 dpurdie 8260
    #   Note: At the moment ScmRoot is relative anyway, thus this code
8261
    #         does nothing
227 dpurdie 8262
    #
8263
    my $gbe_root = $::ScmRoot;
8264
    if ( $::UseRelativeRoot )
8265
    {
8266
        $gbe_root =  RelPath( $::ScmRoot );
8267
    }
8268
 
8269
    #
8270
    #   Now start to create the makefile
8271
    #
285 dpurdie 8272
    open( MAKEFILE, '>', $Makefile ) || Error( "Cannot create $Makefile" );
227 dpurdie 8273
    ::MakefileHeader( *MAKEFILE,
8274
                      'Auto-generated Platform Dependent Makefile',
8275
                      "$ScmMakelib (version $ScmVersion)",
343 dpurdie 8276
                      "# Copyright (C) 1995-$::CurrentYear Vix-ERG, All rights reserved",
227 dpurdie 8277
                      '#',
8278
                      "# Located in $::Cwd",
8279
                      "# Platform $::ScmPlatform",
8280
                      '#' . ('-' x 79),
8281
                      );
8282
 
8283
    #
8284
    #   Ensure that some essential variables are set
8285
    #
8286
    print MAKEFILE <<EOF;
8287
#
8288
#   Validate essential environment variables
8289
#
8290
ifndef GBE_BIN
8291
    \$(error ERROR: GBE_BIN is not available)
8292
endif
8293
ifndef GBE_PERL
8294
    \$(error ERROR: GBE_PERL is not available)
8295
endif
8296
ifndef DEBUG
8297
    \$(error ERROR: DEBUG is not defined)
8298
endif
8299
EOF
8300
 
8301
 
8302
    print MAKEFILE <<EOF;
8303
 
8304
#
8305
#   Basic definitions
8306
#
343 dpurdie 8307
GBE_ROOT      := $gbe_root
8308
GBE_ROOT_ABS  := \$(abspath \$(GBE_ROOT))
8309
GBE_HOST      := $::ScmHost
8310
GBE_HOSTMACH  := $::GBE_MACHTYPE
8311
GBE_TARGET    := $::ScmTarget
8312
GBE_MACHTYPE  := $::ScmMachType
8313
GBE_PLATFORM  := $::ScmPlatform
8314
GBE_PBASE     := $::Pbase
8315
GBE_TYPE      := \$(if \$(findstring 1,\$(DEBUG)),D,P)
227 dpurdie 8316
EOF
8317
 
343 dpurdie 8318
MakePrint( "GBE_ARGS      := @ScmPlatformArgs\n" )
227 dpurdie 8319
    if ( scalar @ScmPlatformArgs );
8320
 
343 dpurdie 8321
MakePrint( "GBE_PRODUCT   := $ScmProduct\n" )
227 dpurdie 8322
    if ( $ScmProduct ne "" );
8323
 
343 dpurdie 8324
MakePrint( "GBE_OS_COMMON := $::BUILDINFO{$ScmPlatform}{OS_COMMON}\n" )
227 dpurdie 8325
    if ( exists($::BUILDINFO{$ScmPlatform}{OS_COMMON}) );
8326
 
8327
 
8328
    print MAKEFILE <<EOF;
8329
 
8330
SHELL           := \$(GBE_BIN)/sh
8331
SHELLARGS       :=
8332
EXTENDED_LINE   := \$(GBE_BIN)/extend.lst
8333
export EXTENDED_LINE MAKE
8334
 
343 dpurdie 8335
MFLAGS           := --no-print --warn -r
8336
BUILDNAME        := $::ScmBuildName
8337
BUILDVER         := $::ScmBuildVersionFull
8338
BUILDVERNUM      := $::ScmBuildVersion
227 dpurdie 8339
BUILDPREVIOUSVER := $::ScmBuildPreviousVersion
343 dpurdie 8340
DEPLOYPATCH      := $ScmDeploymentPatch
8341
GBE_NOTOOLSTEST  := $ScmNoToolsTest
227 dpurdie 8342
 
8343
#
8344
#   Ensure PWD is correctly set
8345
#
8346
PWD             := \$(CURDIR)
8347
export PWD
8348
 
261 dpurdie 8349
#
8350
#   NODEPEND    - Used to suppress generated dependency file checking
8351
#                 Mostly done in jmake.pl
8352
#   EXPERT      - Used to suppress dependency on this makefile
8353
#
8354
EOF
8355
 
285 dpurdie 8356
MakePrint( "EXPERT\t\t?= " . ($ScmExpert ? '1' : '0' ) . "\n" );
8357
MakePrint( "NODEPEND\t?= 0\n" );
261 dpurdie 8358
 
8359
print MAKEFILE <<EOF;
8360
 
8361
#
8362
#   SCM_MAKEFILE - The name of the file to depend upon
8363
#                  Supressed in EXPERT mode
8364
#
8365
ifneq (\$(EXPERT),0)
8366
SCM_MAKEFILE	:=
8367
else
8368
SCM_MAKEFILE	:= $Makefile
8369
endif
8370
EOF
8371
 
267 dpurdie 8372
#
8373
#   Setup the base directory for the packaging process
8374
#   When building a deployable package the base directory is changed to match
8375
#   that used by the deployment world. This is done so that the descpkg file
8376
#   can be created in the correct location
8377
#
8378
my  $PKGDIR = "pkg/$::Pbase";
8379
    $PKGDIR = "build/deploy" if ( $DEPLOYPACKAGE );
8380
Verbose("Setting PKGDIR: $PKGDIR");
8381
 
261 dpurdie 8382
print MAKEFILE <<EOF;
8383
 
227 dpurdie 8384
#--------- Targets -------------------------------------------------------------
8385
 
8386
.PHONY: 	default all build install package unpackage uninstall \\
8387
		clean unbuild clobber deploy
8388
 
8389
default:	make_usage
8390
all:		install package deploy
8391
build:		make_init generate install_hdr depend make_lib \\
8392
		install_lib make_install_shlib make_prog install_class
8393
install:	build install_prog
8394
package:	package_files package_hdr package_lib package_shlib package_prog \\
8395
		package_class
8396
unpackage:	unpackage_class unpackage_prog unpackage_shlib \\
8397
		unpackage_lib unpackage_hdr unpackage_files
8398
uninstall:	uninstall_class uninstall_prog uninstall_shlib \\
8399
		uninstall_lib uninstall_hdr
8400
clean:		make_clean unmake_prog unmake_test unmake_lib unobj \\
261 dpurdie 8401
		undepend ungenerate rmlitter unmake_dir
227 dpurdie 8402
unbuild:	clean uninstall
8403
clobber:	unpackage unbuild
8404
deploy:		install run_deploy
8405
 
8406
#--------- Macros --------------------------------------------------------------
8407
 
8408
OBJDIR		= \$(GBE_PLATFORM)\$(GBE_TYPE).OBJ
8409
LIBDIR		= \$(GBE_PLATFORM).LIB
8410
BINDIR		= \$(GBE_PLATFORM)\$(GBE_TYPE).BIN
8411
CLSDIR		= classes\$(GBE_TYPE)
8412
 
267 dpurdie 8413
PKGDIR		= \$(GBE_ROOT)/$PKGDIR
227 dpurdie 8414
INCDIR_PKG	= \$(PKGDIR)/include
8415
LIBDIR_PKG	= \$(PKGDIR)/lib
8416
BINDIR_PKG	= \$(PKGDIR)/bin
8417
CLSDIR_PKG	= \$(PKGDIR)/classes
8418
 
8419
LOCALDIR	= \$(GBE_ROOT)/local
8420
INCDIR_LOCAL	= \$(LOCALDIR)/inc
8421
LIBDIR_LOCAL	= \$(LOCALDIR)/lib
8422
BINDIR_LOCAL	= \$(LOCALDIR)/bin
8423
CLSDIR_LOCAL	= \$(LOCALDIR)/classes
8424
BINDIR_LOCAL_PATH = \$(GBE_ROOT_ABS)/local/bin/\$(GBE_PLATFORM)\$(GBE_TYPE)
8425
 
8426
INTERFACEDIR	= \$(GBE_ROOT)/$ScmInterface
8427
INCDIR_INTERFACE= \$(INTERFACEDIR)/include
8428
LIBDIR_INTERFACE= \$(INTERFACEDIR)/lib
8429
BINDIR_INTERFACE= \$(INTERFACEDIR)/bin
8430
CLSDIR_INTERFACE= \$(INTERFACEDIR)/classes
8431
 
8432
.SUFFIXES:		# Delete the default suffixes
8433
 
8434
EOF
8435
 
8436
    MakePrintList( \@DEFINES );
8437
    MakeNewLine();
8438
 
8439
#-------------------------------------------------------------------------------
8440
#
8441
#
261 dpurdie 8442
    MakeHeader ("Defines, flags and file sets");
227 dpurdie 8443
 
8444
    # Flags
261 dpurdie 8445
    foreach my $opt ( keys %ScmCompilerOpts )
8446
    {
8447
        MakeDefEntry ( $opt, "=", $ScmCompilerOpts{$opt} );
8448
    }
227 dpurdie 8449
 
261 dpurdie 8450
    MakeDefEntry( "CFLAGS",         "=", \@CFLAGS, \@CFLAGS_PROD, \@CFLAGS_DEBUG );
8451
    MakeDefEntry( "CLINTFLAGS",     "=", \@CLINTFLAGS, \@CLINTFLAGS_PROD, \@CLINTFLAGS_DEBUG );
8452
    MakeDefEntry( "CDEPENDFLAGS",   "=", \@CFLAGS, \@CFLAGS_PROD, \@CFLAGS_DEBUG );
8453
    MakeDefEntry( "CXXFLAGS",       "=", \@CXXFLAGS, \@CXXFLAGS_PROD, \@CXXFLAGS_DEBUG );
8454
    MakeDefEntry( "CXXLINTFLAGS",   "=", \@CXXLINTFLAGS, \@CXXLINTFLAGS_PROD, \@CXXLINTFLAGS_DEBUG );
8455
    MakeDefEntry( "CXXDEPENDFLAG",  "=", \@CXXFLAGS, \@CXXFLAGS_PROD, \@CXXFLAGS_DEBUG );
267 dpurdie 8456
    MakeDefEntry( "ASFLAGS",        "=", \@ASFLAGS, \@ASFLAGS_PROD, \@ASFLAGS_DEBUG );
8457
    MakeDefEntry( "LDFLAGS",        "=", \@LDFLAGS, \@LDFLAGS_PROD, \@LDFLAGS_DEBUG );
227 dpurdie 8458
 
8459
 
8460
#-------------------------------------------------------------------------------
8461
#   
8462
#
261 dpurdie 8463
    MakeHeader ("Tool Search Path",
8464
                "Extend the PATH seen by all the tools to include",
8465
                "The tools/bin directories discovered in Packages" );
8466
    my $put_PATH;
8467
    my $put_LD_LIBRARY_PATH;
8468
    for my $path ( ToolExtensionPaths() )
8469
    {
8470
        MakePrint( "PATH := $path$::ScmPathSep\$(PATH)\n" );
8471
        $put_PATH = 1;
227 dpurdie 8472
 
261 dpurdie 8473
        if ( $::ScmHost eq "Unix" )
8474
        {
227 dpurdie 8475
        MakePrint( "LD_LIBRARY_PATH ?= \n" );
8476
        MakePrint( "LD_LIBRARY_PATH := $path$::ScmPathSep\$(LD_LIBRARY_PATH)\n" );
261 dpurdie 8477
            $put_LD_LIBRARY_PATH =1;
8478
        }
227 dpurdie 8479
    }
8480
 
261 dpurdie 8481
    #   Export the appropriate environment variables
8482
    #   Note: Windows has an issue with PATH and Path
8483
    #         Haven't got to the bottom of it yet, but it would appear that DLL
8484
    #         searching uses Path and other stuff uses PATH. Not too sure how we
8485
    #         end up with two (or more in the environment)
8486
    #
8487
    #
8488
    if ( $put_LD_LIBRARY_PATH )
8489
    {
343 dpurdie 8490
        MakePrint( "export LD_LIBRARY_PATH\n" );
261 dpurdie 8491
    }
227 dpurdie 8492
 
261 dpurdie 8493
    if ( $put_PATH )
8494
    {
343 dpurdie 8495
        MakePrint( "Path := \$(PATH)\n" );
8496
        MakePrint( "export PATH Path\n" );
261 dpurdie 8497
    }
227 dpurdie 8498
 
8499
#-------------------------------------------------------------------------------
8500
#   
8501
#
261 dpurdie 8502
    MakeHeader ("Perl Module Search Path",
8503
                "Extend the PERL5LIB seen by invocations of perl");
227 dpurdie 8504
 
261 dpurdie 8505
    my $perl_module_found;
8506
    for my $path ( ToolExtensionPaths() )
227 dpurdie 8507
    {
261 dpurdie 8508
        if (glob( "$path/*.pm"))
8509
        {
227 dpurdie 8510
        MakePrint( "PERL5LIB := $path$::ScmPathSep\$(PERL5LIB)\n" );
261 dpurdie 8511
            $perl_module_found = 1;
8512
        }
227 dpurdie 8513
    }
261 dpurdie 8514
    if ( $perl_module_found  )
8515
    {
227 dpurdie 8516
    MakePrint( "export PERL5LIB\n" );
261 dpurdie 8517
    }
227 dpurdie 8518
 
261 dpurdie 8519
#-------------------------------------------------------------------------------
8520
#   Internal Helper Functions
8521
#   Creating INCLUDE and LIBRARY paths
8522
#
8523
 
8524
# Assist in creating a list paths
8525
#   $pList  - Reference to an array to which $data will be added
8526
#   $pSeen  - Hash Ref to track tags that have been seen
8527
#   $data   - Data item to add, if tag is defined, but not seen
8528
#   $tag    - Resolved name for item
8529
#
227 dpurdie 8530
    sub PushPath
8531
    {
8532
        my ($pList, $pSeen, $data, $tag) = @_;
8533
        if ( $tag )
8534
        {
8535
            unless ( exists $pSeen->{$tag} )
8536
            {
8537
                $pSeen->{$tag} = 1;
8538
                push @{$pList}, $data;
8539
            }
8540
        }
8541
    }
8542
 
8543
    #
8544
    # Search paths for include files and libraries
8545
    # Currently symbolic paths are created, but there is very little need for this
8546
    #
8547
    sub MakePaths
8548
    {
8549
        my( $root ) = @_;
8550
        my @pathlist;
8551
        my %seen;
8552
 
8553
 
8554
        #   eg. SCA_WIN32   and SCA_WIN32       and SCA_SOLARIS
8555
        #       SCA             WIN32_i386          SPARC
8556
        #       WIN32           SCA                 SCA
8557
        #       .               WIN32               SOLARIS
8558
        #                       .                   .
8559
        #..
8560
        PushPath( \@pathlist, \%seen, "$root/\$(GBE_PLATFORM)",   $ScmPlatform );
8561
        PushPath( \@pathlist, \%seen, "$root/\$(GBE_PRODUCT)",    $ScmProduct );
8562
 
8563
        #
8564
        #   Insert extra path elements found in BUILDPLATFORM_PARTS
8565
        #   These will be present for BuildProduct (XXXX,-Uses=YYYY)
8566
        #   Note: Don't do for LOCAL paths, only INTERFACE
8567
        #
8568
        if ( $root =~ /INTERFACE/ ) {
8569
            my @parts = @{$::BUILDINFO{$ScmPlatform}{PARTS}};
8570
            foreach ( @parts ) {
8571
                PushPath( \@pathlist, \%seen, "$root/$_",   $_ );
8572
            }
8573
        }
8574
 
8575
        PushPath( \@pathlist, \%seen, "$root/\$(GBE_TARGET)",     $ScmTarget );
8576
 
8577
        push @pathlist, "$root";
8578
 
8579
        return \@pathlist;
8580
    }
8581
 
8582
#-------------------------------------------------------------------------------
8583
#   
8584
#
261 dpurdie 8585
    MakeHeader ("Include Search Paths",
367 dpurdie 8586
                "Package Include Paths for header files and libraries" );
227 dpurdie 8587
 
367 dpurdie 8588
    MakeDefEntry( 'PINCDIRS', '=', '# includes');
8589
    MakeDefEntry( 'PLIBDIRS', '=', '# libraries');
8590
 
8591
    for my $package (@{$::ScmBuildPkgRules{$ScmPlatform} })
8592
    {
8593
        #
8594
        #   Skip the pseudo package that encapsulates the interface
8595
        #   directory. Currently the makefiles do this in a different
8596
        #   manner - to be resolved
8597
        #
8598
        #   Just comment out the lines so that the data is visible
8599
        #   Its a hint to make use of the data
8600
        #
8601
        my $prefix = '';
8602
        $prefix = '# ' if ( $package->{'TYPE'} eq 'interface' );
8603
        $prefix = '# ' if ( $package->{'TYPE'} eq 'build' );
8604
 
8605
 
8606
        my $name = $package->{'NAME'} . '/' . $package->{'VERSION'};
8607
        my $base = $package->{'ROOT'};
8608
 
8609
        MakeHeader ("Source: $name");
8610
 
8611
        #
8612
        #   List include and library directories
8613
        #   Note: Need the True Path for windows.
8614
        #       Some makefile functions (wildcard) only work as expected
8615
        #       if the case of the pathname is correct. Really only a problem
8616
        #       with badly formed legecy packages where the Windows user
8617
        #       guessed at the package format.
8618
        #
8619
        #       The conversion to a TruePath is done when ScmBuildPkgRules
8620
        #       is created. Create one, use many time.
8621
        #
8622
        #
8623
        for my $type (qw (PINCDIRS PLIBDIRS) )
8624
        {
8625
            for my $path ( @{$package->{$type}} )
8626
            {
8627
                MakeDefEntry ( "$prefix$type", "+=", $base . $path);
8628
            }
8629
        }
8630
    }
8631
 
8632
#-------------------------------------------------------------------------------
8633
#   
8634
#
8635
    MakeHeader ("Include Search Paths",
8636
                "Local Include Paths",
8637
                " LINKDIRS - Local include search path (short)",
8638
                " INCDIRS  - Include search path (complete)",
8639
                " NODEPDIRS - ",
8640
                " SRCDIRS - ",
8641
                " LIBDIRS - Library search path",
8642
 
8643
                );
8644
 
227 dpurdie 8645
    # Include search path
8646
    #
8647
    #   user-local
367 dpurdie 8648
    #   local
8649
    #   interface
8650
    #       BuildPkgArchive
8651
    #       LinkPkgArchive
227 dpurdie 8652
    #   user-global
8653
    #
8654
 
367 dpurdie 8655
    MakeDefEntry ( "\nLINCDIRS",    "= ", \@L_INCDIRS );     # .. Local
261 dpurdie 8656
    MakeDefEntry ( "LINCDIRS",      "+=", MakePaths( '$(INCDIR_LOCAL)' ));     # .. Sandbox interface
8657
    MakeDefEntry ( "LINCDIRS",      "+=", MakePaths( '$(INCDIR_INTERFACE)' )); # .. Sandbox interface
8658
    MakeDefEntry ( "LINCDIRS",      "+=", \@G_INCDIRS );    # .. Global
227 dpurdie 8659
 
367 dpurdie 8660
    MakeDefEntry ( "INCDIRS",  "= ", '$(LINCDIRS)' );               # Local
8661
    MakeDefEntry ( "INCDIRS",  "+=", '$(PINCDIRS)' );               # Package
8662
    MakeDefEntry ( "LINCDIRS", "+=", \@S_INCDIRS );                 # System
227 dpurdie 8663
 
8664
    # Source search path
8665
 
261 dpurdie 8666
    MakeDefEntry( "\nNODEPDIRS",        "=", \@NODEPDIRS );
227 dpurdie 8667
 
367 dpurdie 8668
    MakeDefEntry( "\nSRCDIRS","= "  , [ @L_SRCDIRS, @G_SRCDIRS ] ); # Local
8669
    MakeDefEntry ( "SRCDIRS", "+=" , '$(PINCDIRS)' );               # Package
8670
    MakeDefEntry ( "SRCDIRS", "+=" , \@S_INCDIRS );                 # System
227 dpurdie 8671
 
8672
    # Library search path
8673
    #
8674
    #   user-local
367 dpurdie 8675
    #   local
8676
    #   interface
8677
    #       BuildPkgArchive
8678
    #       LinkPkgArchive
227 dpurdie 8679
    #   user-global
8680
 
367 dpurdie 8681
    MakeDefEntry( "\nLIBDIRS",  "= ", '$(LIBDIR)' );                    # User Local
261 dpurdie 8682
    MakeDefEntry( "LIBDIRS",    "+=", \@L_LIBDIRS );                    # Local
8683
    MakeDefEntry( "LIBDIRS",    "+=", MakePaths( '$(LIBDIR_LOCAL)' ));  # Sandbox/interface
8684
    MakeDefEntry( "LIBDIRS",    "+=", MakePaths( '$(LIBDIR_INTERFACE)' ));
8685
    MakeDefEntry( "LIBDIRS",    "+=", \@G_LIBDIRS );                    # Global
367 dpurdie 8686
    MakeDefEntry( "LIBDIRS",    "+=", '$(PLIBDIRS)' );                  # Package
261 dpurdie 8687
    MakeDefEntry( "LIBDIRS",    "+=", \@S_LIBDIRS );                    # System
227 dpurdie 8688
 
8689
#-------------------------------------------------------------------------------
8690
#
8691
#   Subdir creation and deletion
8692
#   Creation is done on the fly
8693
#   Deletion is done AFTER the toolset functions have been invoked to create the
8694
#   build artifacts so that the toolsets can create directories too
8695
 
8696
    MakeHeader ("Subdir creation");
8697
    CreateMkdirRules();
343 dpurdie 8698
    MkdirRule( '$(OBJDIR)', 'OBJDIR' );                # Object build directory
8699
    MkdirRule( '$(OBJDIR)/'.$_ ) foreach (@SHLIBS);    # Shared library build directory
8700
    MkdirRule( '$(LIBDIR)', 'LIBDIR' );                # Library directory
8701
    MkdirRule( '$(BINDIR)', 'BINDIR' );                # Binary directory
227 dpurdie 8702
 
261 dpurdie 8703
    #
8704
    #   Create a directory for library merge tool to work within
8705
    #
8706
    MkdirRule( "\$(MLIBDIR)", 'MLIBDIR', '--Path=$(GBE_PLATFORM).MRG', '--RemoveAll' ) if (@MLIBS);
8707
 
227 dpurdie 8708
#-------------------------------------------------------------------------------
8709
#   Generate rules and recipes to create all the toolset specific parts
8710
#   This is done fairly early to allow the toolsets to extend various
8711
#   definitions that may be used later in the makefile construction
8712
#
8713
    MakeHeader ("Construct Programs");
8714
 
8715
    foreach my $i ( @PROGS )
8716
    {
289 dpurdie 8717
        my $pProg = $PROGS->Get($i);
8718
        my $pArgs = $pProg->getItems('ARGS');
8719
        my $pObjs = $pProg->getItems('OBJS');
8720
        my $pLibs = $pProg->getItems('LIBS');
227 dpurdie 8721
 
289 dpurdie 8722
        #
8723
        #   Create a list of program object files
8724
        #
8725
        push @PROGOBJS, @$pObjs;
227 dpurdie 8726
 
8727
        MakePrint( "#---- (${i})\n\n" );
8728
        if ( $ScmToolsetProgDependancies )
8729
        {
261 dpurdie 8730
            #
8731
            #   Original style Prog Interface
271 dpurdie 8732
            #   Write some dependency information here and some in the toolset
8733
            #   Problems:
8734
            #       1) Errors in library dependency generation will be
8735
            #          reported after all the object files have been created
8736
            #          Thus the error message and the make-stop are seperated
8737
            #          by many,many lines of output. This makes it difficult
8738
            #          to see the error.
261 dpurdie 8739
            #
271 dpurdie 8740
            #       2) Lack of Flexability
8741
            #
293 dpurdie 8742
            MakeEntry( "\$(BINDIR)/$i$::exe: ", "", "\\\n\t\t", ".$::o ", @$pObjs );
227 dpurdie 8743
        }
8744
        else
8745
        {
261 dpurdie 8746
            #
8747
            #   New Style Prog Interface
8748
            #   The toolset does it all
8749
            #
8750
            #   Flag the progam packaging as a placeholder.
8751
            #   The toolset will replace/update it.
8752
            #
227 dpurdie 8753
            PackageProgRemoveFiles( $i );
8754
        }
8755
 
289 dpurdie 8756
        $if->LD    ( $i, $pArgs, $pObjs, $pLibs );
8757
        $if->LDLINT( $i, $pArgs, $pObjs, $pLibs );
227 dpurdie 8758
    }
8759
 
8760
#-------------------------------------------------------------------------------
8761
#   
8762
#
8763
    MakeHeader ("Construct Test Programs");
289 dpurdie 8764
    foreach my $i ( @TESTPROGS )
227 dpurdie 8765
    {
289 dpurdie 8766
        my $pProg = $TESTPROGS->Get($i);
8767
        my $pArgs = $pProg->getItems('ARGS');
8768
        my $pObjs = $pProg->getItems('OBJS');
8769
        my $pLibs = $pProg->getItems('LIBS');
227 dpurdie 8770
 
289 dpurdie 8771
        #
8772
        #   Create a list of program object files
8773
        #
8774
        push @TESTPROGOBJS, @$pObjs;
8775
 
227 dpurdie 8776
        MakePrint( "#---- (${i})\n\n" );
8777
        if ( $ScmToolsetProgDependancies )
8778
        {
293 dpurdie 8779
            MakeEntry( "\$(BINDIR)/$i$::exe: ", "", "\\\n\t\t", ".$::o ", @$pObjs );
227 dpurdie 8780
        }
8781
        else
8782
        {
8783
            PackageProgRemoveFiles( $i );
8784
        }
8785
 
289 dpurdie 8786
        $if->LD    ( $i, $pArgs, $pObjs, $pLibs );
8787
        $if->LDLINT( $i, $pArgs, $pObjs, $pLibs );
227 dpurdie 8788
    }
8789
 
8790
#-------------------------------------------------------------------------------
8791
#
8792
#
8793
    MakeHeader ("Transfer Scripts to BINDIR");
8794
    foreach my $i ( sort ( values %SCRIPTS ))
8795
    {
8796
        my $tname = "\$(BINDIR)/" . StripDir( $i );
8797
 
8798
 
8799
        MakePrint( "$i:\t\tmakefile.pl\n" .
261 dpurdie 8800
            "\t\$(XX_PRE)if [ ! -f \"$i\" ]; then echo Script [$i] not found; exit 2; fi\n\n" );
227 dpurdie 8801
 
8802
        #
8803
        #   Create a rule to copy the script into the BIN directory
8804
        #   Mark the script as executable - It can't hurt and its there
8805
        #   to be run as part of a test.
8806
        #
8807
        MakePrint "$tname:\t\$(GBE_BINDIR) $i\n" .
8808
                  "\t\$(XX_PRE)\$(cp) -f $i $tname\n" .
8809
                  "\t\$(XX_PRE)\$(chmod) -f +wx $tname\n\n"
8810
    }
8811
 
8812
#-------------------------------------------------------------------------------
8813
#   
8814
#
8815
    MakeHeader ("Construct Libraries");
8816
    foreach my $i ( @LIBS )
8817
    {
289 dpurdie 8818
        my $pLib  = $LIBS->Get($i);
8819
        my $pArgs = $pLib->getItems('ARGS');
8820
        my $pObjs = $pLib->getItems('OBJS');
227 dpurdie 8821
 
363 dpurdie 8822
        unless ( $ScmToolsetNillLibSrc )
8823
        {
8824
            Error ("Library has no component objects: $i")
8825
                if ( scalar @$pObjs <= 0 );
8826
        }
299 dpurdie 8827
 
227 dpurdie 8828
        MakePrint "#---- (${i})\n\n";
289 dpurdie 8829
        $if->AR(     $i, $pArgs, $pObjs, $pLib);
8830
        $if->ARLINT( $i, $pArgs, $pObjs, $pLib );
227 dpurdie 8831
    }
8832
 
289 dpurdie 8833
#-------------------------------------------------------------------------------
8834
#   
8835
#
8836
    MakeHeader ("Construct Merged Libraries");
227 dpurdie 8837
    sub MlibEntry
8838
    {
289 dpurdie 8839
        my( $mlib, $plib, $pLibs ) = @_;
227 dpurdie 8840
        my @flib;
8841
 
289 dpurdie 8842
        MakePrint '$(LIBDIR)/' . GenLibName($mlib) . ":";
8843
        foreach my $lib ( @$pLibs )
227 dpurdie 8844
        {
289 dpurdie 8845
            #
8846
            #   Each library name may contains one embedded option which
8847
            #   specifies the source directory
8848
            #       libname[,--Option | BaseSubdir]
8849
            #
227 dpurdie 8850
            my ($slib, $sdir) = split( ',', $lib );
343 dpurdie 8851
            my $mode;
227 dpurdie 8852
 
8853
            #
283 dpurdie 8854
            #   By default the librares are pulled from LOCAL unless the
8855
            #   library is built in this directory, in which case it will
289 dpurdie 8856
            #   be used.
227 dpurdie 8857
            #
289 dpurdie 8858
            $sdir = ( $LIBS->Get($slib) ) ? '--Here' : '--Local'
8859
                unless ( $sdir );
227 dpurdie 8860
 
8861
            #
8862
            #   --Interface     - Pull library from the interface directory
8863
            #   --Local         - Pull library from the local directory
8864
            #   --SubDir=xxxx   - Pull library from specified subdirectory
283 dpurdie 8865
            #   --Here          - Pull from local directory if built locally
227 dpurdie 8866
            #   otherwise       - Pull library from specified subdirectory
8867
            #
8868
            if ($sdir eq '--Interface') {
8869
                $sdir = '$(LIBDIR_INTERFACE)/$(GBE_PLATFORM)';
8870
 
343 dpurdie 8871
 
8872
            } elsif ($sdir eq '--InterfacePlain') {
8873
                $sdir = '$(LIBDIR_INTERFACE)/$(GBE_PLATFORM)';
8874
                $mode = 1;
8875
 
227 dpurdie 8876
            } elsif ( $sdir eq '--Local') {
8877
                $sdir = $PackageInfo{'Lib'}{'IBase'} .  # Base of Installed libs
8878
                        $PackageInfo{'Lib'}{'Dir'};     # Default subdir
8879
 
8880
            } elsif ( $sdir =~ m~^--SubDir=(.*)~ ) {
8881
                $sdir = $1 . '/$(LIBDIR)';
8882
 
283 dpurdie 8883
            } elsif ( $sdir eq '--Here') {
8884
                $sdir = '$(LIBDIR)';
8885
 
227 dpurdie 8886
            } else {
8887
                $sdir .= '/$(LIBDIR)';
8888
            }
8889
 
343 dpurdie 8890
            MakePrint " \\\n\t\t${sdir}/" . GenLibName($slib, $mode);
227 dpurdie 8891
            push @flib, "${sdir}/${slib}";
8892
        }
289 dpurdie 8893
        return \@flib;
227 dpurdie 8894
    }
8895
 
8896
    foreach my $i ( @MLIBS )
8897
    {
289 dpurdie 8898
        my $pLib  = $MLIBS->Get($i);
8899
        my $pArgs = $pLib->getItems('ARGS');
8900
        my $pLibs = $pLib->getItems('LIBS');
227 dpurdie 8901
 
261 dpurdie 8902
        MakePrint "#---- (${i})\n\n";
8903
 
227 dpurdie 8904
        unless ( defined &ToolsetARMerge )
8905
        {
8906
            Warning( "Merging of libraries not supported in this toolset yet" );
8907
            Warning( "MergeLibrary: \"$i\" will not be created" );
8908
        }
8909
        else
8910
        {
8911
            #
8912
            #   Create the dependency rule
8913
            #       Target library : source library list
8914
            #           Recipe - generated by the toolset
8915
            #
289 dpurdie 8916
            foreach ( @$pArgs )
227 dpurdie 8917
            {
8918
                Warning( "Ignoring unknown argument to MergeLibrary. $_" );
8919
            }
289 dpurdie 8920
            $pLibs = MlibEntry( $i, $pLib, $pLibs );
8921
            $if->ARMerge( $i, $pArgs, $pLibs, $pLib );
227 dpurdie 8922
        }
8923
    }
8924
 
289 dpurdie 8925
#-------------------------------------------------------------------------------
8926
#   
8927
#
8928
    MakeHeader ("Construct Shared Libraries");
339 dpurdie 8929
 
227 dpurdie 8930
    foreach my $i ( @SHLIBS )
8931
    {
289 dpurdie 8932
        my $pShlib  = $SHLIBS->Get($i);
8933
        my $pArgs = $pShlib->getItems('ARGS');
8934
        my $pObjs = $pShlib->getItems('OBJS');
8935
        my $pLibs = $pShlib->getItems('LIBS');
8936
        my $version = $pShlib->{VERSION};
227 dpurdie 8937
 
289 dpurdie 8938
        $if->SHLD    ( $i, $pArgs, $pObjs, $pLibs, $version );
8939
        $if->SHLDLINT( $i, $pArgs, $pObjs, $pLibs, $version );
227 dpurdie 8940
    }
8941
 
8942
#-------------------------------------------------------------------------------
8943
#   Construct Objects
8944
#   For each object within OBJSOURCE construct the following:
8945
#
8946
#   $(OBJDIR)/object-name:     source-name [makefile]
8947
#       Toolset ...
8948
#
8949
#   
8950
#
8951
    MakeHeader ("Construct Objects");
8952
    foreach my $i ( sort keys %OBJSOURCE )
8953
    {
8954
        my( $src, $sname, $ext, $type, @args );
8955
 
8956
        $src  = $OBJSOURCE{ $i };
8957
        $sname = StripDir( $src );
8958
        $ext  = StripFile( $src );
8959
        $ext = lc($ext)
8960
            if ( $::ScmHost ne "Unix" );
8961
        $type = $ScmSourceTypes{ $ext }
8962
            unless (( $type = $SRC_TYPE{ $sname }) );
8963
 
8964
        #
8965
        #   Object source is an object file
8966
        #   No need the generate the object, just create makefile rule
261 dpurdie 8967
        #   [ddp] Not too sure how we get here
227 dpurdie 8968
        #
8969
        if ( $ext eq ".$::o" )
8970
        {
8971
            MakePrint "$src:";
261 dpurdie 8972
            MakePrint " \$(SCM_MAKEFILE)";
227 dpurdie 8973
            MakeNewLine();
8974
            next;
8975
        }
8976
 
8977
        #
8978
        #   Need to create object file
8979
        #
8980
        @args = split( /$;/, $SRC_ARGS{ StripDir( $sname ) } )
8981
            if $SRC_ARGS{ $sname };
8982
 
8983
        push( @args, "--Shared" )
8984
            if ( exists $SHOBJ_LIB{$i} );
8985
 
8986
        #
8987
        #   Convert relative paths to absolute paths if required by the
8988
        #   toolset. Some compilers need ABS paths to generate nice debug
8989
        #   information.
8990
        #
8991
        $src = AbsPath($src)
8992
            if ( $UseAbsObjects );
8993
 
8994
        #
8995
        #   Extract any user specified dependancies
261 dpurdie 8996
        #   These will be added to the dependency list
227 dpurdie 8997
        #
8998
        my @dlist;
8999
        @dlist = split( /$;/, $SRC_DEPEND{$sname} )
9000
            if ( exists $SRC_DEPEND{$sname} );
9001
 
261 dpurdie 9002
        #
9003
        #   Create the dependency part of the object rule
9004
        #   The source file MUST be the first dependent recipes
9005
        #   may assume that $< is the name source file
9006
        #
9007
        MakeEntry( "\$(OBJDIR)/$i.$::o: $src \$(SCM_MAKEFILE)", "", " \\\n\t", "", @dlist );
227 dpurdie 9008
 
9009
        if ( $type eq ".c" ) {
9010
            $if->CC(  $src, $i, \@args );
261 dpurdie 9011
 
227 dpurdie 9012
        } elsif ( $type eq ".cc" ) {
9013
            $if->CXX( $src, $i, \@args );
261 dpurdie 9014
 
227 dpurdie 9015
        } elsif ( $type eq ".asm" ) {
9016
            $if->AS( $src, $i, \@args );
261 dpurdie 9017
 
227 dpurdie 9018
        } else {
9019
            $if->EXT( $src, $i, \@args ) ||
9020
                Warning( "Don't know how to build '$ext' images' for $src, $i" );
9021
            MakeNewLine();
9022
        }
9023
    }
9024
 
9025
#-------------------------------------------------------------------------------
9026
#   Construct Projects
9027
#   Construct toolset specific projects
9028
#
9029
    MakeHeader ("Construct Projects");
9030
    while ( my($project, $entry) = each %PROJECTS)
9031
    {
9032
        $if->PROJECT( $entry );
9033
    }
9034
 
9035
#-------------------------------------------------------------------------------
9036
#   Automated tests
9037
#
9038
    MakeHeader ("Automated tests");
9039
 
9040
    my $idx = 0;
9041
    my @test_set = ("makefile.pl");
9042
    my @test_set_auto = ("makefile.pl");
9043
    my @copy_set = ();
9044
 
9045
    foreach my $pEntry ( @TESTS_TO_RUN )
9046
    {                                           # Foreach test
9047
        $idx++;
9048
        $pEntry->{'index'} = $idx;
9049
        $pEntry->{'test_name'} = "run_test_$idx";
9050
 
9051
        #
9052
        #   If the test is being run within a 'FrameWork' then the underlying
9053
        #   toolset must instantiate the frame work.
9054
        #
9055
        #   This may change. Perhaps frameworks shouldn't be a part of the
9056
        #   toolset. Perhaps they should be standalone. May change
9057
        #
9058
        if ( $pEntry->{framework} )
9059
        {
9060
            $if->TESTFRAMEWORK( $pEntry );
9061
        }
9062
 
9063
        #
9064
        #   Create a rule to run the test
9065
        #
9066
 
9067
        my $tdir_alias = $pEntry->{'testdir'};
9068
        my $tdir = '$(' . $tdir_alias . ')';
9069
 
9070
        my $test_name = $pEntry->{'test_name'};
9071
        push @test_set, $test_name;
9072
        push @test_set_auto, $test_name if ($pEntry->{'auto'} );
9073
 
9074
        my $tprog = $tdir . '/' . StripDir( $pEntry->{'prog'} );
9075
 
9076
        my $me = MakeEntry::New( *MAKEFILE, $test_name, '--Phony' );
9077
        $me->AddDependancy( "\$(GBE_$tdir_alias)" );
9078
        $me->AddDependancy( "\$(INTERFACEDIR)/set_$::ScmPlatform.sh" );
9079
        $me->AddDependancy( $tprog ) if $pEntry->{'copyprog'};
9080
        $me->AddDependancy( @{ $pEntry->{'copyin' } } );
9081
        $me->AddDependancy( map { $tdir . '/' . StripDir($_) } @{ $pEntry->{'copyonce' } } );
9082
        $me->AddDependancy( @{ $pEntry->{'preq'} } );
9083
        $me->RecipePrefix ('$(XX_PRE)');
9084
        $me->RecipeComment( "------ Running test [$idx] ..." );
9085
 
9086
        #
9087
        #   Extend the PATH seen by the script to include the local/bin directory
9088
        #   Allows programs and tests that have been created elsewhere in the component
9089
        #   to be accessed within the script.
9090
        #
9091
        $me->AddShellRecipe ( ". \$(INTERFACEDIR)/set_$::ScmPlatform.sh" );
9092
 
9093
        #
9094
        #   Copy in the files that we need
9095
        #
9096
        foreach my $file ( @{$pEntry->{'copyin'}} )
9097
        {
9098
            my $dst = $tdir . '/' . StripDir( $file );
9099
            UniquePush( \@COPYIN, $dst );
9100
            UniquePush( \@copy_set, $file );
9101
            $me->AddShellRecipe ( "\$(cp) -f $file $dst" );
9102
            $me->AddShellRecipe ( "\$(chmod) -f +wx $dst" );
9103
        }
9104
 
9105
        #
9106
        #   Insert and FrameWork Recipe bits
9107
        #
9108
        $me->AddShellRecipe ( @{$pEntry->{'ShellRecipe'}} );
9109
 
9110
        $me->AddShellRecipe ( "cd $tdir" );
9111
        $me->AddShellRecipe ( ["GBE_TYPE=\$(GBE_TYPE)",
9112
                               "GBE_HOST=\$(GBE_HOST)",
9113
                               "GBE_ROOT=\$(GBE_ROOT_ABS)",
9114
                    		   "PATH=.\\$::ScmPathSep\$(BINDIR_LOCAL_PATH)\\$::ScmPathSep\$\$PATH",
9115
                               $pEntry->{'command'},
9116
                               @{$pEntry->{'args'}},
9117
                               ] );
9118
        $me->Print();
9119
 
9120
 
9121
        #
9122
        #   Create entries to handle the copy-once files
9123
        #
9124
        foreach my $file ( @{ $pEntry->{'copyonce' } } )
9125
        {
9126
            my $tname = $tdir . '/' . StripDir($file);
9127
            my $me = MakeEntry::New( *MAKEFILE, $tname  );
9128
            $me->AddDependancy( $file );
9129
            $me->AddRecipe ( "\$(call CopyFile,CopyIn,$tname,$file,$tdir,)"  );
9130
            $me->Print();
9131
 
9132
            UniquePush( \@COPYIN, $tname );
9133
            UniquePush( \@copy_set, $file );
9134
 
9135
        }
9136
    }
9137
 
9138
    #
9139
    #   Generate a target that specifies the tests to be run
9140
    #   Each test is provided with a dummy name
9141
    #
9142
    push @test_set, @TESTPROJECT_TO_ARUN;
9143
    push @test_set, @TESTPROJECT_TO_URUN;
9144
    MakeEntry3("\nrun_tests", ":", \@test_set )
9145
        if (@test_set);
9146
 
9147
    push @test_set_auto, @TESTPROJECT_TO_ARUN;
9148
    MakeEntry3("\nrun_unit_tests", ":", \@test_set_auto )
9149
        if (@test_set_auto);
9150
 
9151
    #
9152
    #   Generate sanity test for each copyin script
9153
    #   Simply to provide a nice error message for generated scripts
9154
    #   that do not exist at run-time
9155
    #
9156
    test_copy_in:
9157
    foreach my $i ( @copy_set )
9158
    {
9159
        next if ( $SCRIPTS{$i} );
9160
        foreach (  @SHLIB_TARGETS )
9161
        {
9162
            next test_copy_in if ( $i eq $_ );
9163
        }
9164
        MakePrint( "\n$i:\t\tmakefile.pl\n" .
9165
            "\t\@if [ ! -f \"$i\" ]; then echo ERROR: CopyIn Script [$i] not found; exit 2; fi\n" );
9166
    }
9167
 
261 dpurdie 9168
#-------------------------------------------------------------------------------
9169
#   Deploy rules
9170
#
9171
MakeHeader ("Deploy Rules");
227 dpurdie 9172
 
261 dpurdie 9173
print MAKEFILE <<EOF;
9174
.PHONY:		run_deploy
9175
EOF
227 dpurdie 9176
 
261 dpurdie 9177
#
9178
#   Build up the deployfile.pl command line from the available pieces
9179
#
9180
my $command_file = "";
9181
my @command_line;
9182
 
9183
if ( %DEPLOYPACKAGE )
9184
{
9185
    $command_file = $DEPLOYPACKAGE{'cmdfile'};
9186
 
9187
    push @command_line, "\$(XX_PRE)\$(GBE_PERL) -w $command_file";
9188
    push @command_line, "-r \"\$(GBE_ROOT)\"";
9189
    push @command_line, "-n \"$DEPLOYPACKAGE{'name'}\"";
9190
    push @command_line, "-d \"$DEPLOYPACKAGE{'dir'}\"";
9191
    push @command_line, "-v \"\$(BUILDVER)\"";
9192
    push @command_line, "-t \"\$(GBE_TYPE)\"";
9193
    push @command_line, "-o \"\$(BUILDPREVIOUSVER)\"";
9194
    push @command_line, "-m \"\$(GBE_PLATFORM)\"";
9195
    push @command_line, "-g \"\$(GBE_TARGET)\"";
9196
    push @command_line, "-k \"\$(GBE_PRODUCT)\""        if ( $ScmProduct );
9197
    push @command_line, "-p \"\$(DEPLOYPATCH)\""        if ( $ScmDeploymentPatch );
9198
 
9199
}
9200
 
9201
MakeEntry( "run_deploy:\t$command_file\n", "\n", "\t\t", " \\\n", @command_line );
9202
 
227 dpurdie 9203
#-------------------------------------------------------------------------------
261 dpurdie 9204
#   Custom Rules
9205
#
9206
    MakeHeader ("Custom Rules");
9207
    MakePrintList ( \@RULES );
9208
 
9209
#-------------------------------------------------------------------------------
9210
#   Generated Files
9211
#
9212
    MakeHeader ("Generated Files");
9213
    MakePrint ("\n.PHONY: phony_generate\n\n" );
9214
 
9215
    foreach my $i ( @GENERATE_FILES )
9216
    {
9217
        my $gen_tag = $i->{'index'};
9218
 
9219
        #
263 dpurdie 9220
        #   If predelete is enabled, then create a list of files to delete
9221
        #
9222
        if ( $i->{'predelete'}  )
9223
        {
9224
            MakeDefEntry( "generate_gen_$gen_tag", "=",  $i->{'gen'} );
9225
            MakePrint("\n")
9226
        }
9227
 
9228
 
9229
        #
261 dpurdie 9230
        #   Generate the basic generate rule and recipe
9231
        #   together with the prerequisites
9232
        #
9233
        MakeEntry ( "", ":", "", " ", @{$i->{'gen'}} );
9234
 
9235
        unless ( $i->{'clean'} && $i->{'shell'} )
9236
        {
9237
            MakeEntry ( "", "", " \\\n\t\t", "", @{$i->{'preq'}} );
9238
            MakeEntry ( "", "", " \\\n\t\t", "", "phony_generate" ) if $i->{'preq_sus'};
9239
            MakeEntry ( "", "", " \\\n\t\t", "", "\$(SCM_MAKEFILE)" );
9240
 
9241
            MakePrint ("\n\t" . "\@\$(echo) [$i->{'text'}] generating.." );
263 dpurdie 9242
            if ( $i->{'predelete'}  )
9243
            {
9244
                MakePrint ("\n\t" . "\$(XX_PRE)\$(call RmFiles,generate_gen_$gen_tag)" );
9245
            }
261 dpurdie 9246
            MakePrint ("\n\t" . "\$(XX_PRE)\$(call generate_$gen_tag,)" );
9247
        }
9248
 
9249
        #
9250
        #   Generate 'clean' rules and recipes
9251
        #
9252
        if ( $i->{'clean'} )
9253
        {
9254
            MakePrint ("\n\nPHONY: clean_generate_$gen_tag" );
9255
            MakePrint ("\nclean_generate_$gen_tag:" );
343 dpurdie 9256
            MakePrint ("\n\t" . "\$(XX_PRE)-\$(call generate_$gen_tag,$i->{'clean'})" );
261 dpurdie 9257
        }
9258
 
9259
        #
9260
        #   Define a function to contain the body of the generation call
9261
        #   The first argument will be a 'clean' argument
9262
        #
9263
        MakePrint ("\n\ndefine generate_$gen_tag" );
9264
        if ( $i->{'shell'} )
9265
        {
9266
            MakeEntry ("\n\t(" , "\\\n\t)\n", " \\\n\t", ";" , @{$i->{'toolargs'}} );
9267
        }
9268
        else
9269
        {
9270
            MakeEntry ("\n\t" . $i->{'tool'} . ' $1', "\n", " \\\n\t\t", "" , @{$i->{'toolargs'}} );
9271
        }
9272
        MakePrint ("endef\n\n" );
9273
    }
9274
 
9275
#-------------------------------------------------------------------------------
9276
#   Toolset Post Processing
9277
#   Allow the toolset to perform any post processing, before we finally write
9278
#   out any definitions.
9279
#
9280
#   We will not interprete any more user directives, but new stuff may get added
9281
#
9282
#
9283
MakeHeader ("Toolset Post Processing");
9284
$if->Postprocess();
9285
 
9286
################################################################################
9287
#   All interactions with the toolset are now complete
9288
#   All lists are now complete
9289
#
9290
#   Can now create internal definitions
9291
#   
9292
################################################################################
9293
 
9294
    #
9295
    #   Would be nice if this would work
9296
    #   Unfortunatelty we still need $if for the CCDEPENDS and CTAGS work
9297
    #   These must be defined AFTER the definitions
9298
    #
9299
    #   Ideally we should construct our makefile in sections
9300
    #   and then we can order the sections when we write them out
9301
    #
9302
#$if = 0;                            # Ensure the MakeIf class is not called
9303
                                     # If this file is modified
9304
 
9305
#-------------------------------------------------------------------------------
227 dpurdie 9306
#   Sources
9307
#
9308
MakeHeader  ( "Sources");
9309
MakeDefEntry( "CSRCS",      "=",  \@CSRCS );
9310
MakeDefEntry( "CXXSRCS",    "=",  \@CXXSRCS );
9311
MakeDefEntry( "ASSRCS",     "=",  \@ASSRCS );
9312
 
9313
#-------------------------------------------------------------------------------
9314
#   Generated, Installed and Packaged components
9315
#
9316
MakeHeader  ("Generated, Installed and Packaged components");
9317
MakeDefEntry( "INITS",           "=",  \@INITS )   if ( @INITS );
9318
MakeDefEntry( "GENERATED",       "=",  \@GENERATED ) if ( @GENERATED );
9319
MakeDefEntry( "GENERATED_NOTSRC","=",  \@GENERATED_NOTSRC ) if ( @GENERATED_NOTSRC );
9320
MakeDefEntry( "GENERATEDCLEAN",  "=",  CreateNameList( 'clean_generate_', '', ListCleanGenerated() ));
9321
MakeDefEntry( "INSTALL_HDRS",    "=",  \%INSTALL_HDRS ) if ( %INSTALL_HDRS );
9322
MakeDefEntry( "INSTALL_CLSS",    "=",  \%INSTALL_CLSS ) if ( %INSTALL_CLSS );
9323
MakeDefEntry( "OBJS",            "=", CreateNameList( '$(OBJDIR)/', ".$::o", \@OBJS) );
9324
MakeDefEntry( "SHOBJS",          "=", CreateNameList( '$(OBJDIR)/', ".$::o", \%SHOBJ_LIB ));
289 dpurdie 9325
MakeDefEntry( "PROGOBJS",        "=", CreateNameList( '', ".$::o", \@PROGOBJS ));
9326
MakeDefEntry( "TESTPROGOBJS",    "=", CreateNameList( '', ".$::o", \@TESTPROGOBJS ));
9327
MakeDefEntry( "LIBS",            "=", $LIBS->AllTargets() ) if ($::a);
9328
MakeDefEntry( "MLIBS",           "=", $MLIBS->AllTargets() ) if ($::a);
227 dpurdie 9329
MakeDefEntry( "SHNAMES",         "=", \@SHLIBS );
9330
MakeDefEntry( "SHDIRS",          "=", CreateNameList( '$(OBJDIR)/', "", \@SHLIBS ));
9331
MakeDefEntry( "SHLIBS",          "=", \@SHLIB_TARGETS );
9332
MakeDefEntry( "SCRIPTS",         "=", CreateNameList( '$(BINDIR)/', "", \%SCRIPTS ));
9333
MakeDefEntry( "COPYIN",          "=", \@COPYIN );
289 dpurdie 9334
MakeDefEntry( "PROGS",           "=", $PROGS->AllTargets() );
227 dpurdie 9335
MakeDefEntry( "PROGS_EXTRA",     "=", \@PROGS_EXTRA );
289 dpurdie 9336
MakeDefEntry( "TESTPROGS",       "=", $TESTPROGS->AllTargets());
227 dpurdie 9337
MakeDefEntry( "LINTLIBS",        "=", CreateNameList( 'lib_', '_lint', \@LINTLIBS ));
9338
MakeDefEntry( "LINTSHLIBS",      "=", CreateNameList( 'shlib_', '_lint', \@LINTSHLIBS ));
9339
MakeDefEntry( "LINTPROGS",       "=", CreateNameList( 'prog_', '_lint', \@PROGS ));
289 dpurdie 9340
MakeDefEntry( "LINTPROGS",      "+=", CreateNameList( 'prog_', '_lint', \@TESTPROGS ));
227 dpurdie 9341
MakeDefEntry( "PROJECTS",        "=", CreateNameList( 'Project_', '', ListGeneratedProjects(1) ));
9342
MakeDefEntry( "PROJECTSGEN",     "=", CreateNameList( 'Project_', '', ListGeneratedProjects(0) ));
9343
MakeDefEntry( "PROJECTSCLEAN",   "=", CreateNameList( 'ProjectClean_', '', \%PROJECTS ));
9344
 
261 dpurdie 9345
MakeHeader ("Toolset components");
9346
MakeDefEntry( "USERGENERATED",        "=", \@USERGENERATED )    if ( @USERGENERATED );
9347
MakeDefEntry( "TOOLSETGENERATED",     "=", \@TOOLSETGENERATED ) if ( @TOOLSETGENERATED );
9348
MakeDefEntry( "TOOLSETOBJS",          "=", \@TOOLSETOBJS )      if ( @TOOLSETOBJS );
9349
MakeDefEntry( "TOOLSETLIBS",          "=", \@TOOLSETLIBS )      if ( @TOOLSETLIBS );
9350
MakeDefEntry( "TOOLSETPROGS",         "=", \@TOOLSETPROGS )     if ( @TOOLSETPROGS );
9351
MakeDefEntry( "TOOLSETDIRS",          "=", \@TOOLSETDIRS )      if ( @TOOLSETDIRS );
9352
MakeDefEntry( "TOOLSETDIRTREES",      "=", \@TOOLSETDIRTREES )  if ( @TOOLSETDIRTREES );
227 dpurdie 9353
 
9354
#--------- Determine compiler flag groups to use ----------------------------
9355
#
9356
#   Allows the compiler options to be controlled for both the debug and
9357
#   the production builds. Allows control over
9358
#       1) Optimisations
9359
#       2) Debug Information
9360
#
9361
MakeHeader ("Determine compiler flag groups to use");
9362
 
9363
print MAKEFILE <<EOF;
9364
 
9365
ifneq "\$(DEBUG)" "1"
9366
USE_OPTIMISE	:= \$(PROD_USE_OPTIMISE)
9367
USE_DEBUGINFO	:= \$(PROD_USE_DEBUGINFO)
9368
else
9369
USE_OPTIMISE	:= \$(DEBUG_USE_OPTIMISE)
9370
USE_DEBUGINFO	:= \$(DEBUG_USE_DEBUGINFO)
9371
endif
9372
 
9373
EOF
9374
 
261 dpurdie 9375
#-------------------------------------------------------------------------------
9376
#   Source browsing tools
9377
#
9378
MakeHeader ("Source browsing tools");
9379
    print MAKEFILE <<EOF;
9380
.PHONY:			ctags
9381
ctags:
9382
EOF
9383
    $if->CTAGS()
9384
        if (@CSRCS || @CXXSRCS);
227 dpurdie 9385
 
261 dpurdie 9386
#-------------------------------------------------------------------------------
9387
#   Depend
9388
#   If we are build C or C++ source files then create rules and recipes
9389
#   to invoke a dependency generator.
227 dpurdie 9390
#
261 dpurdie 9391
#   NODEPEND is used to disable, at make-time, the dependency generation
9392
#   and inclusion process.
9393
#
9394
#
9395
MakeHeader ("Depend");
9396
if ($::o && (@CSRCS || @CXXSRCS))
9397
{
9398
    $ScmDependTags = 1;
9399
    print MAKEFILE <<EOF;
9400
depend:			\$(OBJDIR)/depend
9401
 
9402
\$(OBJDIR)/depend:	\$(SCM_MAKEFILE) \$(GBE_OBJDIR)
9403
\$(OBJDIR)/depend:	\$(CSRCS) \$(CXXSRCS)
9404
ifeq (\$(NODEPEND),0)
9405
	\@echo [\$@] Doing a make depend..
9406
	-\$(XX_PRE)\$(rm) -f \$(OBJDIR)/depend
9407
EOF
9408
    $if->CCDepend( "\$(OBJDIR)/depend", "\$(CSRCS)" )
9409
        if ( @CSRCS );
9410
    $if->CXXDepend( "\$(OBJDIR)/depend", "\$(CXXSRCS)" )
9411
        if ( @CXXSRCS );
9412
    MakePrint
9413
        "\t-\@\$(touch) -f \$(OBJDIR)/depend\n";
9414
    print MAKEFILE <<EOF;
9415
else
9416
	\@echo [\$@] Skipping make depend..
9417
	-\$(XX_PRE)\$(rm) -f \$(OBJDIR)/depend
9418
endif
9419
EOF
9420
}
9421
else
9422
{
9423
    print MAKEFILE <<EOF;
9424
depend:
9425
EOF
9426
}
9427
 
9428
#
9429
#   Rule to unmake the depend file
9430
#
9431
    print MAKEFILE <<EOF;
9432
 
9433
undepend:
9434
	-\$(XX_PRE)\$(rm) -f \$(OBJDIR)/depend
9435
EOF
9436
 
9437
#--------- IFLAG Documentation -------------------------------------------------
9438
#
9439
#   IFLAG - iteration flag. This is setting by the calling process
9440
#                           and is a function of the phase being processed
227 dpurdie 9441
#       0   No external dependencies.
9442
#       1   Source dependency list.
261 dpurdie 9443
#       2   Shared library dependency list
9444
#       3   Application dependency list
227 dpurdie 9445
#
9446
#
261 dpurdie 9447
#--------- Dependencies --------------------------------------------------------
9448
#   Include the 'depend' file if required
9449
#
9450
    MakeHeader ("Dependency Inclusion");
9451
    print MAKEFILE <<EOF;
9452
ifeq (\$(NODEPEND),0)
9453
 ifdef IFLAG
9454
  ifneq "\$(IFLAG)" "0"
9455
-include	\$(OBJDIR)/depend
9456
  endif
227 dpurdie 9457
 endif
9458
endif
9459
 
9460
EOF
9461
 
9462
#-------------------------------------------------------------------------------
9463
#   Standard rules
9464
#
9465
MakeHeader ("Standard rules");
9466
 
9467
    print MAKEFILE <<EOF;
9468
.PHONY:		make_usage
9469
make_usage:
9470
	\@echo -e \\
9471
	" make [SHOWENV=1] [LEAVETMP=1] [OPTIONS=[opt][,...]] {DEBUG=0|1} target(s)\\n"\\
9472
	"\\n"\\
9473
	"Build one or more of the following targets for the platform\\n"\\
9474
	"$ScmPlatform, recursively checking each configured sub directories.\\n"\\
9475
	"\\n"\\
9476
	"Valid targets include:\\n"\\
9477
	"  all:             build, install and package\\n"\\
9478
	"  build:           build everything\\n"\\
9479
	"  debug:           build all things for debug\\n"\\
9480
	"  prod:            build all things for production\\n"\\
9481
	"  install:         install of public usage\\n"\\
9482
	"  depend:          construct the dependencies\\n"\\
9483
	"  lint:            lints C and C++ source\\n"\\
9484
	"  package:         build all packages\\n"\\
9485
	"  package-{set}:   build specific package\\n"\\
9486
	"  unpackage:       remove all packages\\n"\\
9487
	"  run_tests:       Run the tests specified in the makefile\\n"\\
9488
	"  run_unit_tests:  Run the automatic unit tests specified in the makefile\\n"\\
9489
	"  deploy:          Run the deployment scripts\\n"\\
9490
	"  rmlitter:        remove litter (core, bak, tmp, err and cmd files)\\n"\\
9491
	"  clean:           delete generate, obj, libraries and programs\\n"\\
9492
	"  unbuild:         delete everything which can be remade\\n"\\
9493
	"  clobber:         unbuilds and deletes packages\\n"\\
9494
EOF
9495
 
9496
    print MAKEFILE <<EOF;
9497
	"\\n"
9498
 
9499
make_clean:
9500
	-\@echo "Removing generated files (objects, libraries, binaries etc)";
9501
 
9502
#
9503
#   Under windows/cygwin, there is a problem with the rm being used
9504
#   The expansion of wildcards will terminate the command if:
9505
#       1) No files exist to expand  : Solution : touch a file of that type
9506
#       2) A directory is involved   : Solution : cd to directory
9507
#
9508
#   Cannot use make's wildcard function as this only operates in the current directory
9509
#
9510
.PHONY:		rmlitter
9511
rmlitter:
315 dpurdie 9512
	-\$(AA_PRE)( echo "Removing litter";\\
227 dpurdie 9513
		\$(touch) _delete.bak _delete.tmp _delete.err ;\\
9514
		\$(rm) -f core *.bak *.tmp *.err ;\\
293 dpurdie 9515
		for subdir in \$(SHDIRS) '' ; do \\
9516
			if [ -d "\$\$subdir" ] ; then \\
227 dpurdie 9517
				( cd \$\$subdir ;\\
9518
				\$(touch) _delete.err _delete.cmd ;\\
289 dpurdie 9519
				\$(rm) -r * ; );\\
9520
			fi ;\\
9521
		done;\\
293 dpurdie 9522
		for subdir in \$(OBJDIR) '' ; do \\
9523
			if [ -d "\$\$subdir" ] ; then \\
289 dpurdie 9524
				( cd \$\$subdir ;\\
9525
				\$(touch) _delete.err _delete.cmd ;\\
227 dpurdie 9526
				\$(rm) -r *.err *.cmd ; );\\
9527
			fi ;\\
9528
		done;\\
9529
	)
9530
 
261 dpurdie 9531
.PHONY:		lint_init
9532
lint_init:
9533
 
227 dpurdie 9534
EOF
9535
 
261 dpurdie 9536
#
9537
#   Dependencies for 'make_init'
9538
#
9539
#
9540
my @initdep;
9541
push @initdep, '$(INITS)' if ( @INITS );
227 dpurdie 9542
 
261 dpurdie 9543
#
9544
#   Dependencies for 'make_dir'
9545
#
9546
my @mkdirdep;
289 dpurdie 9547
push @mkdirdep, '$(GBE_OBJDIR)' if ( @CSRCS || @CXXSRCS || @OBJS || @PROGOBJS || @TESTPROGOBJS );
261 dpurdie 9548
push @mkdirdep, '$(SHDIRS)'     if ( %SHOBJ_LIB || @SHLIBS);
9549
push @mkdirdep, '$(GBE_LIBDIR)' if ( @LIBS || @MLIBS || @SHLIBS || %INSTALL_LIBS || %PACKAGE_LIBS );
289 dpurdie 9550
push @mkdirdep, '$(GBE_BINDIR)' if ( @SHLIBS || %SCRIPTS || @PROGS || @TESTPROGS || %INSTALL_PROGS || %PACKAGE_PROGS );
227 dpurdie 9551
 
261 dpurdie 9552
#
9553
#   Actions for for 'unobj'
9554
#
9555
my @unobjact;
9556
push @unobjact, RmFilesCmd( 'OBJS' )            if ( @OBJS );
9557
push @unobjact, RmFilesCmd( 'SHOBJS' )          if ( %SHOBJ_LIB );
9558
push @unobjact, RmFilesCmd( 'PROGOBJS' )        if ( @PROGOBJS );
289 dpurdie 9559
push @unobjact, RmFilesCmd( 'TESTPROGOBJS' )    if ( @TESTPROGOBJS );
261 dpurdie 9560
push @unobjact, RmFilesCmd( 'TOOLSETOBJS' )     if ( @TOOLSETOBJS );
227 dpurdie 9561
 
261 dpurdie 9562
#
9563
#   Dependencies for 'make_lib'
9564
#
9565
my @libdep;
9566
push @libdep, '$(GBE_OBJDIR)', '$(GBE_LIBDIR)', '$(LIBS)' if ( @LIBS );
227 dpurdie 9567
 
261 dpurdie 9568
#
9569
#   Dependencies for 'lint_lib'
9570
#
9571
my @liblintdep;
9572
push @liblintdep, 'lint_init', '$(GBE_OBJDIR)', '$(GBE_LIBDIR)', '$(LINTLIBS)' if ( @LIBS );
227 dpurdie 9573
 
261 dpurdie 9574
#
9575
#   Dependencies for 'make_mlib'
9576
#
9577
my @mlibdep;
9578
push @mlibdep, '$(GBE_OBJDIR)', '$(GBE_LIBDIR)', '$(GBE_MLIBDIR)', '$(MLIBS)' if ( @MLIBS );
227 dpurdie 9579
 
261 dpurdie 9580
#
9581
#   Dependencies for 'make_install_shlib' (tag)
9582
#
9583
my @shlibdep;
9584
push @shlibdep, '$(SHDIRS)', '$(SHLIBS)' if ( @SHLIBS );
227 dpurdie 9585
 
261 dpurdie 9586
#
9587
#   Dependencies for 'lint_shlib'
9588
#
9589
my @shliblintdep;
9590
push @shliblintdep, 'lint_init', '$(GBE_LIBDIR)', '$(LINTSHLIBS)' if ( @SHLIBS );
227 dpurdie 9591
 
261 dpurdie 9592
#
9593
#   Actions for 'unmake_lib'
9594
#
9595
my @unlibact;
9596
push @unlibact, RmFilesCmd( 'SHLIBS' )      if ( @SHLIBS );
9597
push @unlibact, RmFilesCmd( 'MLIBS' )       if ( @MLIBS );
9598
push @unlibact, RmFilesCmd( 'LIBS' )        if ( @LIBS );
9599
push @unlibact, RmFilesCmd( 'TOOLSETLIBS' ) if ( @TOOLSETLIBS );
227 dpurdie 9600
 
261 dpurdie 9601
#
9602
#   Actions for 'unmake_mlib'
9603
#
9604
my @unmlibact;
9605
push @unmlibact, RmFilesCmd( 'MLIBS' ) if ( @MLIBS );
227 dpurdie 9606
 
261 dpurdie 9607
#
9608
#   Dependencies for 'make_script'
9609
#
9610
my @scriptdep;
9611
push @scriptdep, '$(GBE_BINDIR)', '$(SCRIPTS)' if ( %SCRIPTS );
227 dpurdie 9612
 
261 dpurdie 9613
#
9614
#   Actions for 'unmake_script'
9615
#
9616
my @unscriptact;
9617
push @unscriptact , RmFilesCmd( 'SCRIPTS' ) if ( %SCRIPTS );
9618
push @unscriptact , RmFilesCmd( 'COPYIN' )  if ( @COPYIN );
227 dpurdie 9619
 
261 dpurdie 9620
#
9621
#   Dependencies for 'make_prog'
9622
#
9623
my @progdep;
9624
push @progdep, '$(GBE_OBJDIR)', '$(GBE_BINDIR)', '$(PROGS)' if ( @PROGS );
9625
push @progdep, '$(PROGS_EXTRA)' if (@PROGS_EXTRA);
227 dpurdie 9626
 
261 dpurdie 9627
#
9628
#   Dependencies for 'make_prog' created for 'projects'
9629
#
9630
my @projectdep;
9631
push @projectdep, '$(PROJECTS)' if (ListGeneratedProjects(1) );
227 dpurdie 9632
 
261 dpurdie 9633
#
9634
#   Dependencies for 'generate' created for 'projects'
9635
#
9636
my @projectgendep;
9637
push @projectgendep, '$(PROJECTSGEN)' if (ListGeneratedProjects(0) );
227 dpurdie 9638
 
261 dpurdie 9639
#
9640
#   Dependencies for 'unmake_prog' created for 'projects'
9641
#
9642
my @projectcleandep;
9643
push @projectcleandep, '$(PROJECTSCLEAN)' if (%PROJECTS);
227 dpurdie 9644
 
261 dpurdie 9645
#
9646
#   Dependencies for 'lint_prog'
9647
#
9648
my @proglintdep;
289 dpurdie 9649
push @proglintdep, 'lint_init', '$(GBE_OBJDIR)', '$(GBE_BINDIR)', '$(LINTPROGS)' if ( @PROGS || @TESTPROGS );
227 dpurdie 9650
 
261 dpurdie 9651
#
9652
#   Actions for 'unmake_prog'
9653
#
9654
my @unprogact;
9655
push @unprogact, RmFilesCmd( 'PROGS' )        if ( @PROGS );
9656
push @unprogact, RmFilesCmd( 'TOOLSETPROGS' ) if ( @TOOLSETPROGS );
227 dpurdie 9657
 
261 dpurdie 9658
#
9659
#   Dependencies for 'lint_prog'
9660
#
9661
my @testprogdep;
289 dpurdie 9662
push @testprogdep, '$(GBE_OBJDIR)', '$(GBE_BINDIR)', '$(TESTPROGS)' if ( @TESTPROGS );
227 dpurdie 9663
 
9664
#
261 dpurdie 9665
#   Dependencies for 'run_tests' and friends
9666
#
9667
my @untestprogact;
289 dpurdie 9668
push @untestprogact ,RmFilesCmd( 'TESTPROGS' ) if ( @TESTPROGS );
227 dpurdie 9669
 
261 dpurdie 9670
#
9671
#   Dependencies for 'generated'
9672
#
9673
my @generatedep;
9674
push @generatedep, '$(GENERATED)' if ( @GENERATED );
9675
 
9676
#
9677
#   Actions for 'ungenerate'
9678
#
9679
my @ungenact;
9680
push @ungenact, RmFilesCmd( 'GENERATED' ) if ( @GENERATED );
9681
push @ungenact, RmFilesCmd( 'GENERATED_NOTSRC' ) if ( @GENERATED_NOTSRC );
9682
push @ungenact, RmFilesCmd( 'TOOLSETGENERATED' ) if ( @TOOLSETGENERATED );
9683
push @ungenact, RmFilesCmd( 'USERGENERATED' ) if ( @USERGENERATED );
9684
 
9685
#
9686
#   Dependencies for 'ungenerate'
9687
#
9688
my @ungeneratedep;
9689
push @ungeneratedep, '$(GENERATEDCLEAN)';
9690
 
227 dpurdie 9691
#-------------------------------------------------------------------------------
261 dpurdie 9692
# Function        : PrintPhonyRule
227 dpurdie 9693
#
261 dpurdie 9694
# Description     : Helper function to print some internal phony makefile targets
9695
#                   These are used to hold the basic makefile together
9696
#
9697
# Inputs          : $target         - Name of the phony target
9698
#                   $prereq         - Prerequisites
9699
#                                     Leading spaces removed
9700
#                   $recipe         - Optional Reference to an array of recipes
9701
#                                     Will be printed one per line
9702
#
9703
#
9704
sub PrintPhonyRule
227 dpurdie 9705
{
261 dpurdie 9706
    my ($target, $prereq, $recipe) = @_;
9707
    $prereq =~ s/^\s+//;
227 dpurdie 9708
 
261 dpurdie 9709
    MakePadded( 2, '.PHONY:', $target, "\n");
9710
    MakePadded( 2,"$target:", $prereq, "\n");
9711
    MakePrint ("\t\t" . $_ . "\n") foreach ( @{$recipe} );
9712
    MakePrint ("\n");
227 dpurdie 9713
}
9714
 
261 dpurdie 9715
#   make_init - Test toolset presence and sanity
9716
#   Will only be called ONCE for each platform in a recursive build
9717
#   Should be used to ensure that the required toolset is present
9718
#
9719
PrintPhonyRule ('make_init',       "@initdep" );
227 dpurdie 9720
 
261 dpurdie 9721
#   make_dir    - Create required subdirectories
9722
#   Will be invoked as a part of most targets that create files
9723
#   Will be invoked by the calling wrappers
9724
#   Should not be invoked when cleaning
9725
#
9726
PrintPhonyRule ('make_dir',       "@mkdirdep" );
9727
 
9728
 
9729
PrintPhonyRule ('generate',       "@generatedep @projectgendep" );
9730
PrintPhonyRule ('ungenerate',     "@ungeneratedep",  \@ungenact);
9731
PrintPhonyRule ('unobj',          "",  \@unobjact);
9732
PrintPhonyRule ('make_lib',       "@libdep" );
9733
PrintPhonyRule ('lint_lib',       "@liblintdep" );
9734
PrintPhonyRule ('make_mlib',      "@mlibdep" );
9735
PrintPhonyRule ('lint_shlib',     "@shliblintdep" );
9736
PrintPhonyRule ('unmake_lib',     "", \@unlibact );
9737
PrintPhonyRule ('unmake_mlib',    "", \@unmlibact );
9738
PrintPhonyRule ('make_script',    "@scriptdep" );
9739
PrintPhonyRule ('unmake_script',  "", \@unscriptact );
9740
PrintPhonyRule ('make_prog',      "@scriptdep @progdep @projectdep" );
9741
PrintPhonyRule ('lint_prog',      "@proglintdep" );
9742
PrintPhonyRule ('run_tests',      "@scriptdep @testprogdep" );
9743
PrintPhonyRule ('run_unit_tests', "@scriptdep @testprogdep" );
9744
PrintPhonyRule ('unmake_prog',    "unmake_script @projectcleandep", \@unprogact );
9745
PrintPhonyRule ('make_test',      "@scriptdep @testprogdep" );
9746
PrintPhonyRule ('unmake_test',    "unmake_script", \@untestprogact );
9747
 
227 dpurdie 9748
#-------------------------------------------------------------------------------
9749
#   Package and Installation Summary
9750
#
9751
    MakeHeader ("Package and Installation Summary");
9752
    sub InstallTarget
9753
    {
9754
        my( $target, $hashp, $prereq, $fprereq ) = @_;
9755
        my( $element );
9756
 
343 dpurdie 9757
        MakePrint ".PHONY:\t\t"."$target\n";
227 dpurdie 9758
        MakePrint "$target:";
9759
        MakePrint "\t$fprereq" if ($fprereq);
9760
 
9761
        foreach my $element ( sort keys %{$hashp} )
9762
        {
9763
            #
9764
            #   Skip placekeepers
9765
            #
9766
            next if ( $hashp->{$element}{'placekeeper'} );
9767
 
9768
            #
9769
            #   Prepend any prerequisites (once)
9770
            #
9771
            if ( $prereq )
9772
            {
9773
                MakePrint " \\\n\t${prereq}";
9774
                $prereq = 0;
9775
            }
9776
 
9777
            MakePrint " \\\n\t${element}";
9778
        }
9779
        MakePrint "\n\n";
9780
    }
9781
 
9782
InstallTarget( "install_hdr",       \%INSTALL_HDRS );
9783
InstallTarget( "install_lib",       \%INSTALL_LIBS,  'make_mlib' );
261 dpurdie 9784
InstallTarget( "make_install_shlib",\%INSTALL_SHLIBS, '', "@shlibdep" );
227 dpurdie 9785
InstallTarget( "install_prog",      \%INSTALL_PROGS, 'make_script' );
9786
InstallTarget( "install_class",     \%INSTALL_CLSS );
9787
 
9788
InstallTarget( "package_files",     \%PACKAGE_FILES );
9789
InstallTarget( "package_hdr",       \%PACKAGE_HDRS );
9790
InstallTarget( "package_lib",       \%PACKAGE_LIBS );
9791
InstallTarget( "package_shlib",     \%PACKAGE_SHLIBS );
9792
InstallTarget( "package_prog",      \%PACKAGE_PROGS, 'make_script' );
9793
InstallTarget( "package_class",     \%PACKAGE_CLSS );
9794
 
9795
#-------------------------------------------------------------------------------
9796
#   Installations
9797
 
9798
MakeHeader ("Installations");
9799
PackageRule ( \&InstallCmd, \%INSTALL_HDRS  );
9800
PackageRule ( \&InstallCmd, \%INSTALL_CLSS  );
9801
PackageRule ( \&InstallCmd, \%INSTALL_LIBS  );
9802
PackageRule ( \&InstallCmd, \%INSTALL_SHLIBS  );
9803
PackageRule ( \&InstallCmd, \%INSTALL_PROGS  );
9804
 
9805
 
9806
#-------------------------------------------------------------------------------
9807
#   Packaging
9808
#
9809
MakeHeader ("Packaging");
9810
PackageRule ( \&PackageCmd, \%PACKAGE_FILES );
9811
PackageRule ( \&PackageCmd, \%PACKAGE_HDRS );
9812
PackageRule ( \&PackageCmd, \%PACKAGE_CLSS );
9813
PackageRule ( \&PackageCmd, \%PACKAGE_LIBS );
9814
PackageRule ( \&PackageCmd, \%PACKAGE_SHLIBS );
9815
PackageRule ( \&PackageCmd, \%PACKAGE_PROGS );
9816
 
9817
#-------------------------------------------------------------------------------
9818
#   Uninstall/unpackaging
9819
#
9820
MakeHeader ("Uninstall/unpackaging");
9821
 
9822
UnpackageRule( "uninstall_hdr",         \&UninstallCmd, \%INSTALL_HDRS );
9823
UnpackageRule( "uninstall_lib",         \&UninstallCmd, \%INSTALL_LIBS );
9824
UnpackageRule( "uninstall_shlib",       \&UninstallCmd, \%INSTALL_SHLIBS );
9825
UnpackageRule( "uninstall_prog",        \&UninstallCmd, \%INSTALL_PROGS );
9826
UnpackageRule( "uninstall_class",       \&UninstallCmd, \%INSTALL_CLSS );
9827
 
9828
UnpackageRule( "unpackage_files",       \&UnpackageCmd, \%PACKAGE_FILES );
9829
UnpackageRule( "unpackage_hdr",         \&UnpackageCmd, \%PACKAGE_HDRS );
9830
UnpackageRule( "unpackage_lib",         \&UnpackageCmd, \%PACKAGE_LIBS );
9831
UnpackageRule( "unpackage_shlib",       \&UnpackageCmd, \%PACKAGE_SHLIBS );
9832
UnpackageRule( "unpackage_prog",        \&UnpackageCmd, \%PACKAGE_PROGS );
9833
UnpackageRule( "unpackage_class",       \&UnpackageCmd, \%PACKAGE_CLSS );
9834
 
261 dpurdie 9835
#-------------------------------------------------------------------------------
267 dpurdie 9836
#   Distribution Sets
261 dpurdie 9837
#
267 dpurdie 9838
MakeHeader ("Distribution Sets");
9839
PackageSetRules();
9840
 
9841
#-------------------------------------------------------------------------------
9842
#
261 dpurdie 9843
#   Subdir deletion
9844
#   This is done AFTER the toolset functions have been invoked to create the
9845
#   build artifacts so that the toolsets can create directories too
9846
#
9847
#   Note: Toolset directories are deleted first
9848
#   Note: User Directories are deleted in the reverse order of creation
9849
#
9850
    MakeHeader ("Subdir deletion");
285 dpurdie 9851
    MakePrint( ".PHONY:\t\tunmake_dir\n" );
261 dpurdie 9852
    MakePrint( "unmake_dir:\n" );
9853
    MakePrint( "\t-\$(AA_PRE)echo Removing directories;" );
9854
    MakePrint( " \\\n\t\$(rmdir) \$(TOOLSETDIRS);" )            if ( @TOOLSETDIRS );
9855
    MakePrint( " \\\n\t\$(rm) -rf \$(TOOLSETDIRTREES);" )       if ( @TOOLSETDIRTREES );
9856
    RmdirRules();
9857
    MakeNewLine();
227 dpurdie 9858
 
261 dpurdie 9859
#--------- Toolset Rules -------------------------------------------------------
9860
    MakeHeader ("Toolset Rules");
9861
    MakePrintList ( \@TOOLSETRULES );
9862
 
9863
#--------- Maketags ------------------------------------------------------------
227 dpurdie 9864
 
9865
    Maketag( "make_init",           @INITS );
261 dpurdie 9866
    Maketag( "make_dir",            @mkdirdep );
9867
    Maketag( "generate",            @generatedep || @projectgendep || @USERGENERATED || ($ScmToolsetGenerate != 0) );
227 dpurdie 9868
    Maketag( "depend",              $ScmDependTags != 0 );
261 dpurdie 9869
    Maketag( "make_lib",            @libdep );
9870
    Maketag( "make_mlib",           @mlibdep );
9871
    Maketag( "make_install_shlib",  %INSTALL_SHLIBS || @shlibdep);
9872
    Maketag( "make_script",         @scriptdep );
9873
    Maketag( "make_prog",           @progdep || @projectdep );
9874
    Maketag( "make_test",           @testprogdep );
263 dpurdie 9875
    Maketag( "run_tests",           @TESTS_TO_RUN || @TESTPROJECT_TO_URUN || $TESTS_TO_RUN);
227 dpurdie 9876
    Maketag( "run_unit_tests",      $TESTS_TO_AUTORUN || @TESTPROJECT_TO_ARUN);
9877
    Maketag( "install_hdr",         %INSTALL_HDRS );
9878
    Maketag( "install_class",       %INSTALL_CLSS );
9879
    Maketag( "install_lib",         %INSTALL_LIBS );
9880
    Maketag( "install_prog",        %INSTALL_PROGS );
9881
    Maketag( "deploy",              %DEPLOYPACKAGE );
9882
    Maketag( "package",             %PACKAGE_FILES || %PACKAGE_HDRS || %PACKAGE_CLSS ||
9883
                                    %PACKAGE_LIBS || %PACKAGE_SHLIBS || %PACKAGE_PROGS );
9884
 
261 dpurdie 9885
    #
9886
    #   Display tags in the MAKEFILE
9887
    #   Not used here - just for show
9888
    #
9889
    MakeHeader ("Maketags");
9890
    foreach my $tag ( sort keys %MakeTags )
9891
    {
9892
        MakePadded( 2, "#   $tag:", defined ($MakeTags{$tag}) ? 1 : 0, "\n");
9893
    }
9894
 
227 dpurdie 9895
#-------------------------------------------------------------------------------
9896
#   End of Makefile
9897
#
9898
    MakeHeader ("End of Makefile");
9899
    close( MAKEFILE );
9900
 
9901
#
9902
#   Save all platform information
9903
#   Done after the makefile is written as toolsets can extend the data
9904
#
9905
    WriteParsedConfig();
9906
 
9907
#
9908
#   Write out any accumulated DPACKAGE data
9909
#
9910
    JatsDPackage::DPackageSave();
9911
 
9912
    return 0;
9913
}
9914
 
9915
#-------------------------------------------------------------------------------
9916
# Function        : Maketag
9917
#
9918
# Description     : Create Makefile tags to speed up recursive makes
9919
#
9920
# Inputs          : tag_name
9921
#                   dep
9922
#
9923
# Returns         : 
9924
#
9925
sub Maketag
9926
{
9927
    my( $tag, $dep ) = @_;
9928
    $MakeTags{$tag} = 1 if ( defined($dep) && $dep );
9929
}
9930
 
9931
#-------------------------------------------------------------------------------
9932
#   Function to create and delete directories within the build system
9933
#
9934
#    To stop make regenerating directory dependent targets each time the
9935
#    directory content is modified, rule should only be dependent on a internally
9936
#    created alias file 'gbedir', which represents the time a dir was created not
9937
#    last modified.
9938
#
9939
#    Must use tags like GBE_BINDIR, GBE_LIBDIR and GBE_OBJDIR to ensure that the
9940
#    directories are created correctly.
9941
#
9942
my %MkdirRuleData;
9943
my @MkdirRuleOrder;
9944
my $MkdirRulePrinting = 0;
9945
my $MkdirRuleGbeFile = ( $::ScmHost eq "Unix" ) ? ".gbedir" : "_gbedir";
9946
 
9947
#-------------------------------------------------------------------------------
9948
# Function        : MkdirRule
9949
#
9950
# Description     : Create Rules and Recipes to create a directory at make-time
9951
#                   Mark the information for such that the directories will
9952
#                   be deleted in a 'clean'
9953
#
9954
#                   Can be called before we start writing the makefile
9955
#                   Such entries will be retained and dumped at a known time
9956
#
9957
# Inputs          : $subdir     - Symbolic name of the subdir $(OBJDIR)
9958
#                   $alias      - Optional script alias for the dir 'OBJDIR' --> GBE_OBJDIR
9959
#                   Options:
9960
#                       --Path=path     Optional value of $subdir '$(GBE_PLATFORM)$(GBE_TYPE).OBJ'
9961
#                       --RemoveAll     Remove all files on clean
9962
#
9963
# Returns         : Nothing
9964
#
9965
 
9966
sub MkdirRule
9967
{
9968
    my( $subdir, $alias, @opts ) = @_;
9969
 
9970
    #
9971
    #   Create data entry once
9972
    #
9973
    $alias =~ s~^GBE_~~ if $alias;
9974
    unless ( $MkdirRuleData{$subdir}  )
9975
    {
9976
        my %data;
9977
 
9978
        #
9979
        #   Parse options
9980
        #
9981
        foreach ( @opts )
9982
        {
9983
            if ( /^--Path=(.+)/ ) {
9984
                $data{path} = $1;
9985
            } elsif ( /^--RemoveAll/ ) {
9986
                $data{remove_all} = 1;
9987
            } else {
9988
                Error ("MkdirRule: Unknown option: $_");
9989
            }
9990
        }
9991
        $data{alias} = $alias if ( $alias );
9992
 
9993
        $MkdirRuleData{$subdir} = \%data;
9994
        push @MkdirRuleOrder, $subdir;
9995
    }
9996
 
9997
    #
9998
    #   Save or print
9999
    #
10000
    return unless ( $MkdirRulePrinting );
10001
 
10002
    #
10003
    #   Create a definition of the physical directory
10004
    #
10005
    my $path = $MkdirRuleData{$subdir}{path};
261 dpurdie 10006
    MakePadded (2, $alias, ":= $path\n") if ( $path && $alias );
227 dpurdie 10007
 
10008
    #   Create an alias to be used within rules
10009
    #   The defined aliase will be prefixed with 'GBE_'
10010
    #
261 dpurdie 10011
    MakePadded (2, "GBE_$alias", ":= $subdir/$MkdirRuleGbeFile\n") if ( $alias );
227 dpurdie 10012
 
10013
    #
10014
    #   Create a recipe to create the directory
10015
    #   This is not as simple as it sounds
10016
    #   The touch is required.
10017
    #       Had 'timestamp' issues on solaris'. The 'echo' did not appear
10018
    #       to be enough. Perhaps the output was not flushed
10019
    #
261 dpurdie 10020
    MakePadded (2, "$subdir", ": $subdir/$MkdirRuleGbeFile\n");
227 dpurdie 10021
    MakePrint
10022
        "$subdir/$MkdirRuleGbeFile:\n".
10023
        "\t\$(XX_PRE)if [ ! -d $subdir ]; then \$(mkdir) -p $subdir; fi; \\\n".
10024
        "\t\$(echo) '# DO NOT REMOVE.' > \$@; \\\n".
10025
        "\t\$(touch) \$@\n\n";
10026
}
10027
 
10028
#-------------------------------------------------------------------------------
10029
# Function        : RmdirRules
10030
#
10031
# Description     : Create the body of a recipe to delete the directoeis that
10032
#                   have been created.
10033
#
10034
#                   The rule header will have been written to the makefile
10035
#
10036
# Inputs          : Uses $MkdirRuleData
10037
#
10038
# Returns         : Nothing.
10039
#                   Prints to the makefile
10040
#
10041
sub RmdirRules
10042
{
10043
    #
10044
    #   Determine the list of directories to delete
10045
    #   Sort such that subdirs are deleted files
10046
    #
10047
    foreach my $subdir ( reverse sort keys %MkdirRuleData )
10048
    {
10049
        MakePrint "\\\n";                       # join to previous line
261 dpurdie 10050
        MakePrint "\tif [ -d $subdir ]; then \\\n";
10051
        unless ( $MkdirRuleData{$subdir}{remove_all} )
10052
        {
10053
            MakePrint "\t\t\$(rm) -f $subdir/$MkdirRuleGbeFile; \\\n";
10054
            MakePrint "\t\t\$(rmdir) $subdir; \\\n";
10055
        }
10056
        else
10057
        {
10058
            MakePrint "\t\t\$(rm) -rf $subdir; \\\n";
10059
        }
227 dpurdie 10060
        MakePrint "\tfi;";
10061
    }
10062
}
10063
 
10064
#-------------------------------------------------------------------------------
10065
# Function        : CreateMkdirRules
10066
#
10067
# Description     : Create Rules to make dirs at runtime
10068
#                   This function is called to instantiate those entries
10069
#                   That have been requested before the makefile has has
10070
#                   started to be created.
10071
#
10072
#                   Once this function has been called all new MkdirRule calls
10073
#                   will result in the recipes being created in-line.
10074
#
10075
# Inputs          : Nothing
10076
#
10077
# Returns         : Even Less
10078
#
10079
#
10080
sub CreateMkdirRules
10081
{
10082
    $MkdirRulePrinting = 1;
10083
    foreach my $subdir ( @MkdirRuleOrder )
10084
    {
10085
        my $data = $MkdirRuleData{$subdir};
10086
        MkdirRule($subdir, $data->{alias}, $data->{path} );
10087
    }
10088
}
10089
 
10090
#-------------------------------------------------------------------------------
10091
# Function        : PackageRule
10092
#
10093
# Description     : Generate rules and recipes to "install" and "package" files
10094
#
10095
# Inputs          : codecmd     - A code reference to the actual installer routine
10096
#                   hashp       - A reference to a INSTALL or PACKAGE hash
10097
#
299 dpurdie 10098
#                   hashp is a reference to a hash
227 dpurdie 10099
#                       The key is the full path of the install target
10100
#                       The value is (another) hash that describes the install options
10101
#
10102
#                   Valid keys are:
10103
#                       src                 - Path of the source file [Mandatory]
10104
#                       dir                 - Target directory [Mandatory]
10105
#
10106
#                       defined             - Copy the file only if value is defined
10107
#                       exe                 - Mark the file as executable
10108
#                       Mode                - File modes. Default is -w
10109
#                       placekeeper         - Marks SHARED library placekeepers
10110
#                       set                 - Distribution sets
10111
#                       type                - Copy the file in DEBUG or PROD mode
10112
#                                             Valid values are "D" or "P"         
10113
#                       version             - Shared library version information
10114
#                       RemoveOnly          - Do not install the file. Entries are
10115
#                                             created to allow the removal of the file
10116
#
10117
# Returns         :
10118
#
10119
sub PackageRule
10120
{
10121
    my ($codecmd, $hashp) = @_;
10122
 
10123
    foreach my $dest ( keys %{$hashp} )
10124
    {
10125
 
10126
        my $entry = $hashp->{$dest};
10127
 
10128
        #
10129
        #   Skip placekeepers
10130
        #
10131
        next if ( $entry->{'placekeeper'} );
10132
 
10133
        #
10134
        #   Some entries are not installed via this mechanism, but can be removed
10135
        #   if they exist. Mark these as PHONY to keep targets happy
10136
        #
10137
        if ( $entry->{'RemoveOnly'} )
10138
        {
10139
            MakePrint ".PHONY:\t$dest\n";
10140
            MakePrint "$dest:\n\n";
10141
            next;
10142
        }
10143
 
10144
        my $fname = $entry->{'src'};
10145
        my $fmode = $entry->{'Mode'};
10146
        $fmode .= "+x" if ( $entry->{'exe'}  );
10147
 
10148
        #
10149
        #   User conditionional
10150
        #   Mark both the source and the target as PHONY if the condition is not met
10151
        #   This will ensure that the target need not be built.
10152
        #
10153
        my $udef = $entry->{'defined'};
10154
        if ( $udef )
10155
        {
10156
            MakePrint "ifndef $udef \n";
10157
            MakePrint ".PHONY:\t\t$dest\n";
10158
            MakePrint ".PHONY:\t\t$fname\n";
10159
            MakePrint "$dest:\n";
10160
            MakePrint "else\n"
10161
        }
10162
 
10163
        #
10164
        #   Conditional installation for DEBUG/PRODUCTION
10165
        #
10166
        my $type = $entry->{'type'};
10167
        if ( $type )
10168
        {
10169
            if ( $type eq "D" ) {
10170
                MakePrint 'ifeq "$(DEBUG)" "0"'."\n";
10171
            } elsif ( $type eq "P" ) {
10172
                MakePrint 'ifneq "$(DEBUG)" "0"'."\n";
10173
            } else {
10174
                Error("INTERNAL: Unexpected packaging type: $type");
10175
            }
10176
            MakePrint ".PHONY:\t\t$dest\n";
10177
            MakePrint "$dest:\n";
10178
            MakePrint "else\n"
10179
        }
10180
 
10181
        #
10182
        #   The body of the copy
10183
        #
10184
        MakePadded( 4, "$dest:" );
10185
        MakePrint "\t$fname\n";
10186
        MakePrint $codecmd->( $dest, $fname, $entry->{'dir'}, $fmode );
10187
        MakeNewLine();
10188
 
10189
 
10190
        #
10191
        #   Unwind conditionals
10192
        #
10193
        MakePrint "endif\n" if ( $type );
10194
        MakePrint "endif\n" if ( $udef );
10195
 
10196
        #
10197
        #   Distribution sets
10198
        #
10199
        my $dist = $entry->{'set'};
10200
        if ( $dist )
10201
        {
267 dpurdie 10202
            foreach my $set ( split( ',', $dist ) )
10203
            {
10204
                push @{$PACKAGE_SETS{$set}{LIST}}, $dest;
227 dpurdie 10205
            }
10206
            MakeNewLine();
10207
        }
10208
    }
10209
}
10210
 
10211
#-------------------------------------------------------------------------------
267 dpurdie 10212
# Function        : PackageSetRules
10213
#
10214
# Description     : Generate the packageset rules
10215
#                   These appear to be a now-defuct feature
10216
#
10217
#                   By default all packaged files are a part of package_setALL
10218
#
10219
# Inputs          : None
10220
#                   Takes data from %PACKAGE_SET
10221
#
10222
# Returns         : Nothing
10223
#
10224
sub PackageSetRules
10225
{
10226
    foreach my $set ( sort keys %PACKAGE_SETS )
10227
    {
10228
        my $me = MakeEntry::New( *MAKEFILE, "package_set$set", '--Phony' );
10229
        $me->AddDependancy( @{$PACKAGE_SETS{$set}{LIST}} );
10230
        $me->Print();
10231
    }
10232
}
10233
 
10234
#-------------------------------------------------------------------------------
227 dpurdie 10235
# Function        : UnPackageRule
10236
#
10237
# Description     : Generate rules and recipes to "uninstall" and "unpackage" files
10238
#
10239
# Inputs          : target      - Name of the target
10240
#                   codecmd     - A code reference to the actual installer routine
10241
#                   hashp       - A reference to a INSTALL or PACKAGE hash
10242
#
10243
# Returns         :
10244
#
10245
sub UnpackageRule
10246
{
10247
    my ($target, $codecmd, $hashp) = @_;
10248
 
10249
    MakePrint ".PHONY:\t\t"."$target\n";
10250
    MakePrint "$target:\t";
10251
 
10252
    foreach my $dest ( sort keys %{$hashp} )
10253
    {
10254
 
10255
        my $entry = $hashp->{$dest};
10256
 
10257
        #
10258
        #   Skip placekeepers
10259
        #
10260
        next if ( $entry->{'placekeeper'} );
10261
 
10262
        MakePrint "\n" . $codecmd->($dest);
10263
    }
10264
    MakePrint "\n\n";
10265
}
10266
 
10267
 
10268
#
10269
#   Internal macro interface, see RULE.STD for definitions:
10270
#
10271
sub RmFilesCmd
10272
{
10273
    my ( $list ) = @_;
261 dpurdie 10274
    return "\$(call RmFiles,$list)";
227 dpurdie 10275
}
10276
 
10277
sub InstallCmd
10278
{
10279
    my( $dest, $file, $path, $fmode ) = @_;
10280
 
10281
    $path =~ s~/$~~;                        # remove trailing "/"
10282
    $fmode = "-w"                           # default, read-only
10283
        if ( !defined( $fmode ) || $fmode eq "" );
10284
 
10285
    return "\t\$(call InstallFile,$dest,$file,$path,$fmode)";
10286
}
10287
 
10288
sub UninstallCmd
10289
{
10290
    my( $file ) = @_;
10291
 
10292
    return "\t\$(call UninstallFile,$file)";
10293
}
10294
 
10295
sub PackageCmd
10296
{
10297
    my( $dest, $file, $path, $fmode ) = @_;
10298
 
10299
    $path =~ s~/$~~;                        # remove trailing "/"
10300
    $fmode = "-w"                           # default, read-only
10301
        if ( !defined( $fmode ) || $fmode eq "" );
10302
 
10303
    return "\t\$(call PackageFile,$dest,$file,$path,$fmode)";
10304
}
10305
 
10306
sub UnpackageCmd
10307
{
10308
    my( $file ) = @_;
10309
    return "\t\$(call UnpackageFile,$file)";
10310
}
10311
 
10312
1;
10313