Subversion Repositories DevTools

Rev

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

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