Subversion Repositories DevTools

Rev

Rev 7299 | Rev 7310 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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