Subversion Repositories DevTools

Rev

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