Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
5708 dpurdie 1
##############################################################################
6177 dpurdie 2
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
227 dpurdie 3
#
4
# Module name   : makelib.pl2
5
# Module type   : Makefile system
6
#
7
# Description:
8
#       This modules builds the platform definition makefiles(s)
9
#
10
# Notes:                *** DO NOT DETAB ***
11
#       Beware the use of space v's tab characters within the
12
#       makefile generation sessions.
13
#
14
##############################################################################
15
# Globals:
16
#  $ScmVersion          Makelib.pl2 version
17
#  $ScmRoot             Command line parameter that gives the root directory
18
#                       location for this directory tree.
19
#  $ScmMakelib          Command line parameter that points to the location
20
#                       of THIS script.  ie. location of makelib.pl.
21
#  $ScmPlatform         Current platform
22
#  $ScmProduct          Current product (if any)
23
#  $ScmTarget           Resulting target (derived from Platform)
24
#  @ScmPlatformArgs     Platform arguments
25
#  $ScmToolset          Toolset
26
#  @ScmToolsetArgs      Toolset arguments
27
#  $ScmDebug            Debug level
28
#  $ScmVerbose          Verbose setting
29
#  $ScmSourceTypes      Source types, aliasing for C, C++ and assembler
30
#                       source.
31
#  @CFLAGS              List containing all of the defined C flags
32
#  @CXXFLAGS            List containing all of the defined C++ flags
33
#  @ASFLAGS             List containing all of the defined assembler flags
34
#  @CLINTFLAGS          List containing all of the defined C lint flags
35
#  @CXXLINTFLAGS        List containing all of the defined C++ lint flags
36
#  @{G|L}_INCDIRS       List containing all of include paths
37
#  @{G|L}_SRCDIRS       List containing all of source search paths
38
#  @{G|L}_LIBDIRS       List containing all of library search paths
39
#  @LDFLAGS             List containing all of the defined linker flags
40
#  @SRCS                List of ALL source files. ie. C/C++ and other (eg .x)
41
#                       Key is source file, value is source path
42
#  @OBJS                List of ALL (non-shared) object files.
289 dpurdie 43
#  %SHOBJ_LIB           List of ALL shared library object files and associated library.
227 dpurdie 44
#  %OBJSOURCE           List of ALL object files
45
#                       from that should result from later makes.
46
#                       Key is objectfile, value is source file
47
#  %OBJREFS             List of ALL object files, built options.
48
#  @PROGOBJS            List of ALL application object files.
49
#  %SRC_ARGS            List of arguments that are to be used when making the
50
#                       nominated source.  Key is the source name, the
51
#                       value is a string of arguments to apply.  The
52
#                       arguments are '$;' separated.
53
#  %SRC_TYPE            Source file type (user override).
54
#  @CHDRS               List of C header files.
55
#  @CSRCS               List of C files
56
#                       Key is objectfile, value is source file
57
#  @CXXSRCS             List of C++ files
58
#  @ASHDRS              List of assembler include files (.inc)
59
#  @ASSRCS              List of assembler source files
60
#  @GENERATED           List of files that should result from a 'generate'
61
#                       make rule.  The programmer is expected to provide
62
#                       the necessary rule(s).
63
#  @RULES               List of additional make rules the programmer
64
#                       has specified to be included in the make.
65
#  %INSTALL_HDRS        List of headers that are to be installed for later
66
#                       "public" consumption.
67
#  %INSTALL_CLSS        List of Java classes or JAR files that are to be installed
68
#                       for later "public" consumption.
69
#  @LIBS                List of libraries that are to be built.
289 dpurdie 70
#  $LIBS                Ref to a collection of static library descriptors
71
#                       Indexed by lib name
227 dpurdie 72
#  %INSTALL_LIBS        List of libraries that are to be installed for later
73
#                       public consumption.
74
#  @MLIBS               List of libraries that are to be built via merging
289 dpurdie 75
#  $MLIBS               Ref to a collection of merged lib descriptors
227 dpurdie 76
#  @SHLIBS              List of shared libraries that are to be built.
289 dpurdie 77
#  $SHLIBS              Ref to collection of shared library information
227 dpurdie 78
#  %INSTALL_SHLIBS      List of libraries that are to be installed for later
79
#                       public consumption.
80
#  @PROGS               List of programs (binary executables) that are
81
#                       to be built
289 dpurdie 82
#  $PROGS               Ref to collection of program information
227 dpurdie 83
#  %SCRIPTS             List of scripts to 'create' (key) and whether they
84
#                       should be made executable or not (value).  Script
85
#                       set to executable is denoted by the value being
86
#                       defined AND true.
87
#  %INSTALL_PROGS       List of programs for "public" cosumption to install
88
#                       where (key) is the file and where to install it
89
#                       to vs. (value) which is composed of the original
90
#                       location of the file, the destination directory
91
#                       and a list of service providers this file applies to.
92
# $ProjectBase          Base of the user's project. This variable is designed to
93
#                       be used by the user.
94
#....
95
 
255 dpurdie 96
require 5.006_001;
227 dpurdie 97
use strict;
98
use warnings;
261 dpurdie 99
use Getopt::Long;
227 dpurdie 100
use Data::Dumper;
271 dpurdie 101
use JatsError;
227 dpurdie 102
use JatsEnv;
103
use MakeEntry;
104
use JatsLocateFiles;
105
use JatsDPackage;
271 dpurdie 106
use MakeIf;
289 dpurdie 107
use ToolsetPrinter;
108
use MakeObject;
339 dpurdie 109
use JatsVersionUtils;
6133 dpurdie 110
use ToolsetFiles;
227 dpurdie 111
 
112
 
113
our $ScmVersion             = "2.34";
114
our $ScmGlobal              = 0;
115
our $ScmExpert              = 0;
116
our $ScmInterface           = "interface";      # default 'interface'
117
our $ScmPackage             = 1;                # package active by default.
118
our $ScmProcessingRootMake  = 0;                # Processing root makefile.pl
119
our $ScmPlatformSeen        = 0;                # Platform directive has been seen
6133 dpurdie 120
my  $ScmNotGeneric          = 1;                # Not a generic build
227 dpurdie 121
 
122
our $ScmToolsetVersion      = "";               # version of toolset
123
our $ScmToolsetGenerate     = 1;                # generate active by default.
124
our $ScmToolsetProgDependancies = 1;            # 1: Write program dependancies
125
                                                # 0: Don't write progdeps. Prog is Phony
289 dpurdie 126
our $ScmToolsetSingleType   = 0;                # Toolset does not support Debug and Production
227 dpurdie 127
our $ScmToolsetProgSource   = ();               # Toolset Program Source
339 dpurdie 128
our $ScmToolsetSoName       = 0;                # 1: Shared library supports SoName
363 dpurdie 129
our $ScmToolsetNillLibSrc   = 0;                # 1: Librarys created without source specified
5411 dpurdie 130
our %ScmToolsetProperties   = ();               # Toolset specific features and limitations
131
                                                # Known values: UnitTests, AutoUnitTests
6415 dpurdie 132
our %ScmGlobalOptions       = ();               # Hash of Global(platform) options. Access via functions
133
our %ScmRecipeTags          = ();               # Hash of exposed recipe names
363 dpurdie 134
 
227 dpurdie 135
our $ScmRoot                = "";
136
our $ScmMakelib             = "";
137
our $ScmPlatform            = "";
138
our $ScmMachType            = "";
139
our $ScmSrcDir              = "";
140
our @ScmPlatformDirs        = ();
141
our @ScmPlatformArgs        = ();
289 dpurdie 142
our $ScmBuildType           = 0;                # 0, P, D. 0 == P and D
227 dpurdie 143
our $ScmProduct             = "";
144
our $ScmTarget              = "";
145
our $ScmTargetHost          = "";
146
our $ScmToolset             = "";
147
our @ScmToolsetArgs         = ();
148
our @ScmDepends             = ();
149
our %ScmSourceTypes         = ();
150
our $ScmDeploymentPatch     = "";
151
our $ProjectBase            = "";               # Base of the user's project
152
our $ScmNoToolsTest         = "";               # Supress compiler tests
153
our $ScmDependTags          = 0;                # Create dependancy scanning tag
4781 dpurdie 154
our $ScmMakeUid;                                # Unique makefile id (number 1 .. )
227 dpurdie 155
 
156
our @CFLAGS                 = ();
157
our @CFLAGS_DEBUG           = ();
158
our @CFLAGS_PROD            = ();
159
our @CLINTFLAGS             = ();
160
our @CLINTFLAGS_DEBUG       = ();
161
our @CLINTFLAGS_PROD        = ();
162
our @CXXFLAGS               = ();
163
our @CXXFLAGS_DEBUG         = ();
164
our @CXXFLAGS_PROD          = ();
165
our @CXXLINTFLAGS           = ();
166
our @CXXLINTFLAGS_DEBUG     = ();
167
our @CXXLINTFLAGS_PROD      = ();
168
our @ASFLAGS                = ();
267 dpurdie 169
our @ASFLAGS_DEBUG          = ();
170
our @ASFLAGS_PROD           = ();
227 dpurdie 171
our @LDFLAGS                = ();
267 dpurdie 172
our @LDFLAGS_DEBUG          = ();
173
our @LDFLAGS_PROD           = ();
227 dpurdie 174
 
175
our @INCDIRS                = ();
176
our @NODEPDIRS              = ();
177
our @S_INCDIRS              = ();
178
our @G_INCDIRS              = ();
179
our @L_INCDIRS              = ();
180
our @SRCDIRS                = ();
181
our @S_SRCDIRS              = ();
182
our @G_SRCDIRS              = ();
183
our @L_SRCDIRS              = ();
184
our @LIBDIRS                = ();
185
our @S_LIBDIRS              = ();
186
our @G_LIBDIRS              = ();
187
our @L_LIBDIRS              = ();
188
 
189
our %SRCS                   = ();
190
our %SRC_ARGS               = ();
191
our %SRC_TYPE               = ();
192
our %SRC_DEPEND             = ();
193
our %SCRIPTS                = ();
194
our @COPYIN                 = ();
195
our @INITS                  = ();
196
our @DEFINES                = ();
197
our @OBJS                   = ();
198
our %SHOBJ_LIB              = ();
199
our @PROGOBJS               = ();
289 dpurdie 200
our @TESTPROGOBJS           = ();
227 dpurdie 201
our %OBJSOURCE              = ();
202
our @CHDRS                  = ();
203
our @CSRCS                  = ();
204
our @CXXSRCS                = ();
205
our @ASHDRS                 = ();
206
our @ASSRCS                 = ();
207
our @GENERATED              = ();
208
our @GENERATED_NOTSRC       = ();
209
our @RULES                  = ();
210
our @TOOLSETRULES           = ();
211
our @TOOLSETDIRS            = ();
212
our @TOOLSETDIRTREES        = ();
213
our @TOOLSETGENERATED       = ();
214
our @USERGENERATED          = ();
215
our @TOOLSETOBJS            = ();
216
our @TOOLSETLIBS            = ();
217
our @TOOLSETPROGS           = ();
218
our %INSTALL_HDRS           = ();
219
our %INSTALL_CLSS           = ();
6898 dpurdie 220
our @CLOBBERFILES           = ();
221
our @CLOBBERDIRS            = ();
227 dpurdie 222
 
4778 dpurdie 223
our @TOOLSET_UTF_PRE        = ();       # Toolsets can extend rules run before all unit tests
224
our @TOOLSET_UTF_POST       = ();       # Toolsets can extend rules run after all unit tests
225
our @TOOLSET_UTF_COLLATE    = ();       # Toolsets can extend rules run to collate unit tests results
226
 
227 dpurdie 227
our @LIBS                   = ();
289 dpurdie 228
our $LIBS                   = ();
227 dpurdie 229
our %LIB_PKG                = ();
230
our %LIB_INS                = ();
231
our %INSTALL_LIBS           = ();
232
 
233
our @MLIBS                  = ();
289 dpurdie 234
our $MLIBS                  = ();
227 dpurdie 235
 
236
our @SHLIBS                 = ();
289 dpurdie 237
our $SHLIBS                 = ();
227 dpurdie 238
our @SHLIB_TARGETS          = ();
239
our %SHLIB_PKG              = ();
240
our %SHLIB_INS              = ();
241
our %INSTALL_SHLIBS         = ();
6387 dpurdie 242
our @INSTALL_DIRS           = ();
227 dpurdie 243
 
289 dpurdie 244
our $TESTPROGS              = ();
245
our @TESTPROGS              = ();
227 dpurdie 246
 
289 dpurdie 247
our $PROGS                  = ();           # Simplify tracking of progs
227 dpurdie 248
our @PROGS                  = ();
289 dpurdie 249
our @PROGS_EXTRA            = ();           # Look at doing better !!
227 dpurdie 250
our %PROG_PKG               = ();
251
our %PROG_INS               = ();
252
our %INSTALL_PROGS          = ();
253
 
254
our %PACKAGE_DIST           = ();
255
our %PACKAGE_SETS           = ();
256
our %PACKAGE_HDRS           = ();
257
our %PACKAGE_LIBS           = ();
258
our %PACKAGE_CLSS           = ();
259
our %PACKAGE_SHLIBS         = ();
260
our %PACKAGE_PROGS          = ();
261
our %PACKAGE_FILES          = ();
6387 dpurdie 262
our @PACKAGE_DIRS           = ();
227 dpurdie 263
 
264
our @LINTLIBS               = ();
265
our @LINTSHLIBS             = ();
266
 
4501 dpurdie 267
our @TESTS_TO_RUN           = ();                           # Info from 'RunTest' directives
227 dpurdie 268
 
4996 dpurdie 269
our @TESTPROJECT_TO_URUN    = ();                           # List of Unit Tests and Projects names (Auto and Non Auto in order defined in makefile)
270
our @TESTPROJECT_TO_ARUN    = ();                           # List of Auto Tests and Projects names in order defined in makefile
4501 dpurdie 271
my  $TESTS_TO_AUTORUN       = undef;                        # Flag - Auto Test found
272
my  $TESTS_TO_RUN           = undef;                        # Flag - Unit Test found
273
 
227 dpurdie 274
#our $CurrentTime           = "";
275
#our $CurrentDate           = "";
276
#our $Cwd                   = "";
277
 
278
our @GENERATE_FILES         = ();
279
our %DEPLOYPACKAGE          = ();
267 dpurdie 280
our $DEPLOYPACKAGE          = 0;
261 dpurdie 281
our %MakeTags;
227 dpurdie 282
 
283
#
284
#   Some toolset options that affect the generation of the makefile
285
#
286
our $UseAbsObjects          = 0;                # Default is relative paths to objects
287
our $UseRelativeRoot        = 0;                # Default is absolute paths to build root
299 dpurdie 288
our $DPackageDirective      = 0;
227 dpurdie 289
 
271 dpurdie 290
#
291
#   Arrays of hook functions
292
#
293
our %MF_RegisterSrcHooks;                       # Hook source file discovery
294
 
227 dpurdie 295
###############################################################################
296
#
297
#   Packaging and Installation Information
298
#   Held in a structure as its used in a few places
299
#   Items
300
#       PBase   - Package Base directory. Used for user overrides
301
#       IBase   - Local Install Base directory
302
#       Dir     - Default directory suffix for components. Added to Pbase and IBase
303
#
304
#
305
our %PackageInfo = (
306
    'File' => { 'PBase' => '$(PKGDIR)'       ,'IBase' => '$(LOCALDIR)'       , 'Dir' => '' },
307
    'Hdr'  => { 'PBase' => '$(INCDIR_PKG)'   ,'IBase' => '$(INCDIR_LOCAL)'   , 'Dir' => ''},
308
    'Lib'  => { 'PBase' => '$(LIBDIR_PKG)'   ,'IBase' => '$(LIBDIR_LOCAL)'   , 'Dir' => '/$(GBE_PLATFORM)'},
309
    'Prog' => { 'PBase' => '$(BINDIR_PKG)'   ,'IBase' => '$(BINDIR_LOCAL)'   , 'Dir' => '/$(GBE_PLATFORM)$(GBE_TYPE)'},
310
    'Jar'  => { 'PBase' => '$(CLSDIR_PKG)'   ,'IBase' => '$(CLSDIR_LOCAL)'   , 'Dir' => ''},
241 dpurdie 311
    'Tool' => { 'PBase' => '$(PKGDIR)'       ,'IBase' => '$(LOCALDIR)'       , 'Dir' => '/tools/bin/$(GBE_HOSTMACH)'},
227 dpurdie 312
    );
313
 
4778 dpurdie 314
###############################################################################
315
#
316
#   An array of reserved names
317
#   Used to attempt to prevent developers from naming toolset targets with names reserved
318
#   within the build system
319
our @reservedMakeTargets = qw (
320
    preprocess_tests postprocess_tests collate_test_results
321
);
322
 
227 dpurdie 323
MakeLib2Init();                                 # Runtime initialisation
324
 
325
sub MakeLib2Init
326
{
327
#.. Test environment
328
#
329
    EnvImport( "GBE_CORE" );
330
    EnvImport( "GBE_BIN" );
331
    EnvImport( "GBE_PERL" );
332
    EnvImport( "GBE_TOOLS" );
333
    EnvImport( "GBE_CONFIG" );
334
    EnvImport( "GBE_MACHTYPE" );
335
 
336
#.. Common stuff
337
#
338
    require "$::GBE_TOOLS/common.pl";           # Common stuff
339
    push( @ScmDepends, "$::GBE_TOOLS/common.pl" );
340
 
341
    CommonInit( "makelib2" );
342
    Debug( "version:   $ScmVersion" );
343
 
344
#.. Cache arguments
345
#
346
    CommandLine();
347
 
348
#.. Build defaults
349
#
350
    $ScmSourceTypes{ ".h" }     = ".h";
351
    $ScmSourceTypes{ ".hpp" }   = ".h";
352
    $ScmSourceTypes{ ".c" }     = ".c";
353
    $ScmSourceTypes{ ".C" }     = ".c";
354
    $ScmSourceTypes{ ".cpp" }   = ".cc";
355
    $ScmSourceTypes{ ".cc" }    = ".cc";
356
    $ScmSourceTypes{ ".asm" }   = ".asm";
357
    $ScmSourceTypes{ ".x" }     = "--Ignore";
358
    $ScmSourceTypes{ ".ini" }   = "--Ignore";
359
    $ScmSourceTypes{ ".sh" }    = "--Ignore";
360
    $ScmSourceTypes{ ".pl" }    = "--Ignore";
361
    $ScmSourceTypes{ ".awk" }   = "--Ignore";
362
 
363
#.. Get the stuff from the build configuration file
364
#
365
    ConfigLoad();
4781 dpurdie 366
    $ScmMakeUid = GetMakfilefileUid();
367
    Debug("ScmMakeUid: $ScmMakeUid");
227 dpurdie 368
 
369 dpurdie 369
    if ( (%::ScmBuildPlatforms) )        # Interface/build.cfg
227 dpurdie 370
    {
371
        AddPlatformArg( split( /$;/, $::ScmBuildPlatforms{ $ScmPlatform } ));
372
    }
373
 
369 dpurdie 374
    if ( (%::ScmBuildIncludes) )         # Interface/build.cfg
227 dpurdie 375
    {
376
        my( @includes ) = split( ',', $::ScmBuildIncludes{ $ScmPlatform } );
377
        my( $global ) = $ScmGlobal;
378
 
379
        $ScmGlobal = 1;                         # Follow defs are "global's" ...
380
        foreach my $elem ( @includes )
381
        {
382
            AddIncDir( "*", $elem ) if ($elem);
383
        }
384
        $ScmGlobal = $global;                   # Restore global status ...
385
    }
386
 
369 dpurdie 387
    if ( (%::ScmBuildLibraries) )        # Interface/build.cfg
227 dpurdie 388
    {
389
        my( @libraries ) = split( ',', $::ScmBuildLibraries{ $ScmPlatform } );
390
        my( $global ) = $ScmGlobal;
391
 
392
        $ScmGlobal = 1;                         # Follow defs are "global's" ...
393
        foreach my $elem ( @libraries )
394
        {
395
            AddLibDir( "*", $elem ) if ($elem);
396
        }
397
        $ScmGlobal = $global;                   # Restore global status ...
398
    }
399
 
400
#.. Determine the value of $ScmMachType
401
#   In the makefile GBE_MACHTYPE will be set to $ScmMachType.
402
#
403
#   There is an compatibility issue here.
404
#   A lot of (legacy) package.pl files use GBE_MACHTYPE to specify platform
405
#   specfic directories and names. This is not to be encouraged.
406
#
407
#   Allow for a platformm specific override
408
#
409
    if ( exists( $::BUILDINFO{$ScmPlatform}{'SCMMACHTYPE'} ))
410
    {
411
        $ScmMachType = $::BUILDINFO{$ScmPlatform}{'SCMMACHTYPE'};
412
        Verbose("Override ScmMachType: $ScmMachType");
413
    }
414
    else
415
    {
416
        $ScmMachType = $ScmPlatform;
417
    }
418
 
419
 
420
#.. Get the stuff from the Package definition file
421
#   A convention is that package.pl provide a package name via $Pbase
422
#   This may be different to the BUILDNAME. Generate a default $Pbase
423
#   to allow the package.pl to use the package name part of the buildname
424
#
425
    $::Pbase = $::ScmBuildPackage;
426
    if ( -f "$ScmRoot/package.pl" )
427
    {
428
        Warning ("package.pl file used. Use is being deprecated");
429
 
430
        my( $global ) = $ScmGlobal;             # Follow defs are "global's" ...
431
        $ScmGlobal = 1;
432
        require "$ScmRoot/package.pl";
433
        $ScmGlobal = $global;                   # Restore global status ...
434
 
435
        if ( defined ($::ScmBuildPackage) && defined ($::Pbase) )
436
        {
437
            #   Special case.
438
            #   $Pbase is set to ".". Set $Pbase to the Build Name to force
439
            #   construction of a well formatted package.
440
            #
441
            $::Pbase = $::ScmBuildPackage
442
                if ( $::Pbase eq "." );
443
 
444
            #
445
            #   Error if Pbase has changed
446
            #
447
            Error ("Pbase is not the same as the BuildName (Check package.pl)",
448
                   "Pbase    : $::Pbase",
449
                   "BuildName: $::ScmBuildPackage")
450
                if ( $::Pbase ne $::ScmBuildPackage );
451
        }
452
    }
289 dpurdie 453
 
454
    #
455
    #   Create objects to keep track of Libraies and Programs
456
    #
457
    $LIBS       = MakeObject::NewType( 'Library',       \@LIBS,     '$(LIBDIR)/', \&GenLibName);
458
    $MLIBS      = MakeObject::NewType( 'MergedLibrary', \@MLIBS,    '$(LIBDIR)/', \&GenLibName);
459
    $SHLIBS     = MakeObject::NewType( 'SharedLibrary', \@SHLIBS,   '$(LIBDIR)/', \&GenLibName);
460
    $PROGS      = MakeObject::NewType( 'Program',       \@PROGS,    '$(BINDIR)/', \&GenProgName);
461
    $TESTPROGS  = MakeObject::NewType( 'TestProgram',   \@TESTPROGS,'$(BINDIR)/', \&GenProgName);
227 dpurdie 462
}
463
 
261 dpurdie 464
#-------------------------------------------------------------------------------
289 dpurdie 465
# Function        : GenLibName
466
#
467
# Description     : Helper function to generate a (static) library name
468
#                   Used by MakeObject::NewType
469
#
470
#                   If the toolset doesn't support Debug and Prod, then
471
#                   The library name will not have the suffix
472
#
473
# Inputs          : arg0        - Base name of the library
343 dpurdie 474
#                   arg1        - Mode: 1 == Plain. No P or D
289 dpurdie 475
#
476
# Returns         : Name of the library as used in the makefiles
477
#                   Does not include base directory
478
#
479
sub GenLibName
480
{
343 dpurdie 481
    if ( $ScmToolsetSingleType || $_[1] ) {
289 dpurdie 482
        return "$_[0].$::a"
483
    } else {
484
        return "$_[0]\$(GBE_TYPE).$::a"
485
    }
486
}
487
 
488
#-------------------------------------------------------------------------------
489
# Function        : GenProgName
490
#
491
# Description     : Helper function to generate a program name
492
#                   Used by MakeObject::NewType
493
#
494
# Inputs          : arg0        - Base name of the library
495
#
496
# Returns         : Name of the program as used in the makefiles
497
#                   Does not include base directory
498
#
499
sub GenProgName
500
{
501
    return "$_[0]$::exe"
502
}
503
 
504
 
505
#-------------------------------------------------------------------------------
261 dpurdie 506
# Function        : CommandLine
507
#
508
# Description     : Process the command line.
509
#                   Arguments describes below
510
#
511
# Arguments       : ARG0        - Root of the project
512
#                   ARG1        - Path to this script
513
#                   ARG2        - Target Platform
514
#
515
#                   Options follow
516
#                       --interface=name    - Name of interface dir
517
#                       --arg=xxx           - Platform argument
518
#
519
#                   Otherwise display a usage message
520
#
521
# Returns         : Nothing
522
#
227 dpurdie 523
sub CommandLine
524
{
261 dpurdie 525
    Verbose ("Command Line: @ARGV");
227 dpurdie 526
 
261 dpurdie 527
    #
528
    #   Extract options first
529
    #
530
    my $opt_help = 0;
531
    my $result = GetOptions (
532
                "help+"         => \$opt_help,
533
                "interface=s"   => \$::ScmInterface,
534
                "arg=s"         => sub{ AddPlatformArg( "--$_[1]") }
535
                );
536
    Usage() if ( $opt_help || !$result );
537
 
538
    #
539
    # Need 3 Arguments
540
    #
227 dpurdie 541
    $ScmRoot     = ${ARGV[0]};
261 dpurdie 542
    $ScmRoot     = RelPath( $ScmRoot );
227 dpurdie 543
    $ProjectBase = $ScmRoot;
544
 
545
    $ScmMakelib  = ${ARGV[1]};
546
    $ScmPlatform = ${ARGV[2]};
547
    $ScmTarget   = $ScmPlatform;
548
 
549
    Message ("[$ScmPlatform] Generate Makefile");
550
    Debug( "root\t=$ScmRoot" );
551
    Debug( "makelib\t=$ScmMakelib" );
552
    Debug( "platform\t=$ScmPlatform" );
553
}
554
 
555
#   Usage ---
556
#       Command line usage help.
557
#..
558
 
559
sub Usage
560
{
261 dpurdie 561
    Error ( "Usage: perl makefile.pl2 <ROOTDIR> <makelib.pl2> <PLATFORM> [options ...]",
562
            "Valid options:",
563
            "    --interface=name  Set interface directory",
564
            "    --arg=text        Specify platform argument",
565
            );
227 dpurdie 566
}
567
 
568
 
569
#-------------------------------------------------------------------------------
570
# Function        : SubDir
571
#
572
# Description     : Include a sub-makefile
573
#                   When called when processing by this script this directive
574
#                   does nothing. The processing will be done by makelib.pl
575
#
576
#                   This directive MUST occur before the Platform directive
577
#
578
# Inputs          : None that are used
579
#
580
# Returns         : Nothing
581
#
582
 
583
sub SubDir
584
{
585
    Error ("SubDir directive not allowed after the Platform directive")
586
        if ( $ScmPlatformSeen );
587
}
588
 
589
 
590
###############################################################################
591
#   Platform support
592
###############################################################################
593
 
594
sub Platform
595
{
596
    my( $global, $file );
597
 
598
    Debug( "Platform( $ScmPlatform, @ScmPlatformArgs )" );
599
 
600
#.. Sanity test
601
#
602
    Error ("Platform directive is not allowed in common makefile.pl")
603
        if ( $ScmProcessingRootMake );
604
 
605
    Error ("Only one Platform directive is allowed")
606
        if ( $ScmPlatformSeen );
607
    $ScmPlatformSeen = 1;
608
 
609
#.. Arguments
610
#
611
    $ScmTargetHost = $::ScmHost;                # default
612
 
613
#.. Common configuration
614
#
615
    $global = $ScmGlobal;                       # Follow defs are "global's" ...
616
    $ScmGlobal = 1;
617
 
618
#.. Common rules (ScmHost specific)
619
#
620
    push( @ScmDepends, "$ScmMakelib" );         # parent
621
 
622
    $file = Require( "$::GBE_CONFIG", "Rules", "Common rules " );
623
    push( @ScmDepends, "$file" );
624
 
625
#.. Platform (defines ScmToolset)
626
#
369 dpurdie 627
    if ( ( %::ScmBuildProducts ) &&      # interface/build.cfg
4551 dpurdie 628
           $::ScmBuildProducts{ $ScmPlatform } )
227 dpurdie 629
    {
630
        my( @args ) = split( ',', $::ScmBuildProducts{ $ScmPlatform } );
631
 
632
        $ScmProduct = $args[0];
633
        $ScmTarget = $args[1];
634
 
635
        Debug( " mapping to product $ScmProduct" );
636
 
637
                                                # Platform/target specific
638
        MakeIf::PackageDirs( \@ScmPlatformDirs, $ScmPlatform, $ScmTarget );
639
        push @ScmPlatformDirs, "$::GBE_CONFIG"; # .. plus default
640
 
641
        @ScmPlatformArgs = ( "--product=$ScmProduct", @ScmPlatformArgs );
642
        $file = Require( "PLATFORM", $ScmTarget,
643
                    "Platform definition ", @ScmPlatformDirs );
644
    }
645
    else                                        # standard
646
    {
647
        Debug( " native platform" );
648
 
649
                                                # Platform specific
650
        MakeIf::PackageDirs( \@ScmPlatformDirs, $ScmPlatform );
651
        push @ScmPlatformDirs, "$::GBE_CONFIG"; # .. plus default
652
 
6133 dpurdie 653
        #   Map all GENERIC builds onto the one platform definition
4551 dpurdie 654
        my $platformDefs = $ScmPlatform;
6133 dpurdie 655
        if ($::BUILDINFO{$ScmPlatform}{IS_GENERIC})
656
        {
657
            $ScmNotGeneric = 0;
658
            $platformDefs = 'GENERIC' ;
659
        }
4551 dpurdie 660
 
661
        $file = Require( "PLATFORM", $platformDefs,
227 dpurdie 662
                    "Platform definition ", @ScmPlatformDirs );
663
    }
664
    push( @ScmDepends, "$file" );
665
 
666
    Error( "Toolset undefined for platform $ScmPlatform ...")
667
        unless( $ScmToolset );
668
 
669
#.. Toolset
670
#
671
    $file = Require( "$::GBE_CONFIG/TOOLSET", $ScmToolset, "Toolset definition " );
672
    push( @ScmDepends, "$file" );
673
 
674
#.. Package definitions
675
#
367 dpurdie 676
#   Global DPACKAGE definitions, which may pull in $ScmTarget specific definitions.
227 dpurdie 677
#
678
 
679
    MakeIf::PackageLoad( $ScmPlatform );        # DPACKAGE's (if any)
680
 
681
 
682
#.. Package extensions
683
#   Import, into the current package, files of the form gbe/DIRECTIVES
684
#   These allow the JATS directives to be extended by the contents of a package
685
#   without the need to update the core JATS release.
686
#
687
#   Intended use: Associate a directive with a tool script, such that the
688
#   new directive simplifies the use of the tool script.
689
#
690
#
691
#   First: Extend the Perl Search Space to include the toolset extensions
692
#          Although the directives are in gbe/DIRECTIVES/*.pm, they may need
693
#          to reference other packages that are not.
694
#
311 dpurdie 695
#           Look in the 'interface' and 'link' packages
696
#           The 'build' packages are duplicated into the 'interface'
697
#
227 dpurdie 698
    for my $path ( ToolExtensionPaths() )
699
    {
700
        UniquePush (\@INC, $path)
701
            if (glob( "$path/*.pm") || glob( "$path/*/*.pm"));
702
    }
703
 
704
    for my $entry (@{$::ScmBuildPkgRules{$ScmPlatform} })
705
    {
311 dpurdie 706
        next if ( $entry->{'TYPE'} eq 'build' );
227 dpurdie 707
        my $cfgdir = $entry->{'CFGDIR'};
708
        next unless ( $cfgdir );
709
        my $base_dir = $entry->{'ROOT'} . $cfgdir . '/DIRECTIVES';
710
        next unless ( -d $base_dir );
711
        foreach my $file  ( glob ("$base_dir/*.pm") )
712
        {
713
            push( @ScmDepends, "$file" );
714
            require $file;
715
        }
716
    }
717
 
718
    #
271 dpurdie 719
    #   Include local toolset extensions
720
    #   These are rooted in the build directory and are not to be confused with
721
    #   extensions that may be packaged
6387 dpurdie 722
    #   Simplify life - add the directory to the BUILDTOOLSPATH
271 dpurdie 723
    #
724
    my $local_base_dir = "$ScmRoot/gbe/DIRECTIVES";
725
    if ( -d $local_base_dir )
726
    {
6387 dpurdie 727
        unshift @::BUILDTOOLSPATH, AbsPath($local_base_dir); 
271 dpurdie 728
        foreach my $file  ( glob ("$local_base_dir/*.pm") )
729
        {
730
            push( @ScmDepends, "$file" );
731
            require $file;
732
        }
733
    }
734
 
735
    #
227 dpurdie 736
    #   All makefile.pl's will include a makefile.pl found in the build
737
    #   root directory ( The same directory as build.pl ). This makefile.pl
738
    #   is a little bit different - It should not "require "$ARGV[1]", nor
739
    #   should it use a Platform directive.
740
    #
741
    #   Note: This makefile is processed AFTER the toolset has been initialised
742
    #         so that toolset extensions are available to the directives
743
    #
744
    $file = "$ScmRoot/makefile.pl";
745
    if ( -e $file ) {
746
        $ScmProcessingRootMake = 1;
747
        require "$file";
748
        $ScmProcessingRootMake = 0;
749
        push( @ScmDepends, "$file" );
750
    }
751
 
752
    #
289 dpurdie 753
    #   Sanity Test for platforms that do not support both debug and production
754
    #   builds at the same time. This information is flagged by the toolset
755
    #   which we have now loaded.
756
    #
757
    if ( $ScmToolsetSingleType  )
758
    {
759
        unless ( $ScmBuildType )
760
        {
761
            Error ("The toolset used by the \"$ScmPlatform\" platform does not support",
762
                   "both Production and Debug Builds" );
763
        }
764
    }
765
 
766
    #
227 dpurdie 767
    #   Restore global status ...
768
    #
769
    $ScmGlobal = $global;
770
}
771
 
772
 
773
sub PlatformRequire
774
{
775
    my( $script, @arguments ) = @_;
776
    my( $file );
777
 
778
    Debug( "PlatformRequire($script, @arguments)" );
779
 
780
    push( @ScmPlatformArgs, @arguments );       # additional arguments
781
 
782
    $file = Require( "PLATFORM", $script,
783
                "PlatformRequire ", @ScmPlatformDirs );
784
 
785
    push( @ScmDepends, "$file" );
786
}
787
 
788
 
789
sub PlatformInclude
790
{
791
    my( $script, @arguments ) = @_;
792
    my( $file );
793
 
794
    Debug( "PlatformInclude( @_ )" );
795
 
796
    $file = Require2( \@arguments, "PLATFORM", $script,
797
                "PlatformInclude ", @ScmPlatformDirs );
798
 
799
    push( @ScmDepends, "$file" );
800
}
801
 
802
 
803
sub PlatformDefine
804
{
805
    Debug2( "PlatformDefine(@_)" );
806
 
807
    Define( @_ );
808
}
809
 
810
 
811
sub PlatformDefines
812
{
813
    my( $script ) = @_;
814
    my( $line );
815
 
816
    Debug2( "PlatformDefine(@_)" );
817
 
818
    $script = Exists( "PLATFORM", $script,      # locate image
819
                "PlatformDefines", @ScmPlatformDirs );
820
 
271 dpurdie 821
    push( @DEFINES, "# PlatformDefines from: $script" );
285 dpurdie 822
    open( my $fh, '<', $script ) || Error( "Opening $script" );
823
    while (<$fh>) {
227 dpurdie 824
        $_ =~ s/\s*(\n|$)//;                    # kill trailing whitespace & nl
825
        push( @DEFINES, $_ );
826
    }
827
    push( @ScmDepends, "$script" );             # makefile dependencies
285 dpurdie 828
    close( $fh );
227 dpurdie 829
}
830
 
831
 
832
sub PlatformEntry
833
{
834
    my( $prelim, $postlim, $prefix, $postfix, @elements ) = @_;
835
 
285 dpurdie 836
    my $str = "$prelim";
837
    foreach my $element ( @elements )
227 dpurdie 838
    {
839
        $str .= "${prefix}${element}${postfix}";
840
    }
841
    $str .= "$postlim";
842
    PlatformDefine( $str );
843
}
844
 
845
 
846
#
847
#   Add arguments to the ScmPlatformArgs, but remove "Global" arguments
848
#       --OnlyDebug
849
#       --OnlyProduction
343 dpurdie 850
#       --NoToolSet
227 dpurdie 851
#
289 dpurdie 852
#   Capture OnlyDebug and OnlyProd information
853
#   Will be sanitized by caller.
854
#
227 dpurdie 855
sub AddPlatformArg
856
{
857
    Debug("AddPlatformArg: @_" );
289 dpurdie 858
    foreach  ( @_ )
859
    {
860
        if ( m~^--OnlyDebug~ ) {
861
            $ScmBuildType = 'D';
862
        } elsif ( m~--OnlyProd~ ) {
863
            $ScmBuildType = 'P';
343 dpurdie 864
        } elsif ( m~--NoToolSet~ ) {
865
            $ScmNoToolsTest = 1;
289 dpurdie 866
        } else {
343 dpurdie 867
            UniquePush( \@::ScmPlatformArgs, $_ );
289 dpurdie 868
        }
869
    }
227 dpurdie 870
 
871
    Debug("AddPlatformArg: Result: @::ScmPlatformArgs" );
872
    1;
873
}
874
 
875
###############################################################################
876
# Toolset support
877
#
878
#   Toolset( 'platform [, ... ]', name, [arg, ... ] )
879
#       Specify the toolset for a platform
880
#
881
#   ToolDefine( )
882
#   ToolDefines( )
883
#       Specifies toolset defines for insertion into the target makefile.
884
#
885
#   ToolsetDir
886
#       Define toolset created directory(s) for removal during
887
#       'clean' operations.
888
#
889
#   ToolsetGenerate
890
#       Define toolset created file(s) for removal during
891
#       'clean' operations.
892
#
893
#   ToolsetObj
894
#       Define toolset created object(s) for removal during
895
#       'clean' operations.
896
#
897
#   ToolsetLib
898
#       Define toolset created library(s) for removal during
899
#       'clean' operations.
900
#
901
#   ToolsetProg
902
#       Define toolset created prog(s) for removal during
903
#       'clean' operations.
904
#
905
#   ToolsetRule( )
906
#   ToolsetRules( )
907
#       Specifies toolset rules for insertion into the target makefile.
908
#
909
##############################################################################
910
 
911
sub Toolset
912
{
913
    my( $platforms, $toolset, @arguments ) = @_;
914
 
915
    Debug2( "Toolset(@_)" );
916
 
4309 dpurdie 917
    return 1 if ( ! ActivePlatform($platforms) );
227 dpurdie 918
 
919
    $ScmToolset = $toolset;
920
    @ScmToolsetArgs = @arguments;
4309 dpurdie 921
    return 1;
227 dpurdie 922
}
923
 
924
 
925
sub ToolsetRequire
926
{
927
    my( $script, @arguments ) = @_;
928
    my( $file );
929
 
930
    Debug2( "ToolsetRequire(@_)" );
931
 
932
    @ScmToolsetArgs = @arguments;
933
    $file = Require( "",
934
                     $script,
935
                     "ToolsetRequire",
936
                     "$::GBE_CONFIG/TOOLSET", @::BUILDTOOLSPATH );
937
    push( @ScmDepends, "$file" );
938
}
939
 
940
 
941
sub ToolsetDefine
942
{
943
    Debug2( "ToolsetDefine(@_)" );
944
 
945
    Define( @_ );
946
}
947
 
948
 
949
sub ToolsetDefines
950
{
951
    Debug2( "ToolsetDefines(@_)" );
952
 
261 dpurdie 953
    Defines( "$::GBE_CONFIG/TOOLSET", @_ );
227 dpurdie 954
}
955
 
956
 
957
sub ToolsetDir
958
{
959
    Debug2( "ToolsetDir(@_)" );
960
 
261 dpurdie 961
    UniquePush ( \@TOOLSETDIRS, @_ );
227 dpurdie 962
}
963
 
964
 
965
sub ToolsetDirTree
966
{
967
    Debug2( "ToolsetDirTree(@_)" );
968
 
261 dpurdie 969
    UniquePush ( \@TOOLSETDIRTREES, @_);
227 dpurdie 970
}
971
 
972
 
973
sub ToolsetGenerate
974
{
975
    Debug2( "ToolsetGenerate(@_)" );
976
 
977
    UniquePush( \@TOOLSETGENERATED, @_ );
978
}
979
 
6898 dpurdie 980
sub ToolsetClobberFile
981
{
982
    Debug( "ToolsetClobberFile(@_)" );
983
    UniquePush( \@CLOBBERFILES, @_ );
984
}
227 dpurdie 985
 
6898 dpurdie 986
sub ToolsetClobberDir
987
{
988
    Debug( "ToolsetClobberDir(@_)" );
989
    UniquePush( \@CLOBBERDIRS, @_ );
990
}
991
 
227 dpurdie 992
sub ToolsetObj
993
{
994
    Debug2( "ToolsetObj(@_)" );
995
 
261 dpurdie 996
    foreach my $obj ( @_ )
227 dpurdie 997
    {
261 dpurdie 998
        UniquePush( \@TOOLSETOBJS, "$obj.$::o"  );
227 dpurdie 999
    }
1000
}
1001
 
1002
 
1003
sub ToolsetLib
1004
{
1005
    Debug2( "ToolsetLib(@_)" );
1006
 
261 dpurdie 1007
    foreach my $lib ( @_ )
227 dpurdie 1008
    {
289 dpurdie 1009
        UniquePush( \@TOOLSETLIBS, GenLibName( $lib ) );
227 dpurdie 1010
    }
1011
}
1012
 
1013
 
1014
sub ToolsetProg
1015
{
1016
    Debug2( "ToolsetProg(@_)" );
1017
 
261 dpurdie 1018
    foreach my $prog ( @_ )
227 dpurdie 1019
    {
289 dpurdie 1020
        UniquePush( \@TOOLSETPROGS, GenProgName( $prog ) );
227 dpurdie 1021
    }
1022
}
1023
 
1024
 
1025
sub ToolsetRule
1026
{
1027
    Debug2( "ToolsetRule(@_)" );
1028
 
1029
    push( @TOOLSETRULES, @_ );
1030
}
1031
 
1032
 
1033
sub ToolsetRules
1034
{
1035
    my( $script ) = @_;
1036
    my( $line );
1037
 
1038
    Debug2( "ToolsetRules(@_)" );
1039
 
1040
    $script = Exists( "$::GBE_CONFIG/TOOLSET", $script, "ToolsetRules" );
271 dpurdie 1041
    push( @TOOLSETRULES, "# ToolsetRules from: $script" );
285 dpurdie 1042
    open( my $fh, '<', $script ) || Error( "Opening $script" );
1043
    while (<$fh>) {
227 dpurdie 1044
        $_ =~ s/\s*(\n|$)//;                    # kill trailing whitespace & newline
1045
        push( @TOOLSETRULES, $_ );
1046
    }
1047
    push( @ScmDepends, "$script" );             # makefile dependencies
285 dpurdie 1048
    close( $fh );
227 dpurdie 1049
}
1050
 
4778 dpurdie 1051
#-------------------------------------------------------------------------------
4902 dpurdie 1052
# Function        : SetGlobalOption  
1053
#
1054
# Description     : Set a global toolset option
1055
#                   The global options are intended to allow platform-specific
1056
#                   operation of various tools and utilities. The scope is wider than 
1057
#                   just the underlying tooolset 
1058
#
1059
# Inputs          : $name           - Name of the option
1060
#                   $value          - Value to save            
1061
#
1062
# Returns         : Nothing
1063
#
1064
 
1065
sub SetGlobalOption
1066
{
1067
    my ($name, $value) = @_;
4928 dpurdie 1068
    Debug( "SetGlobalOption.", $name, $value );
4902 dpurdie 1069
    $ScmGlobalOptions{$name} = $value;
1070
}
1071
 
1072
#-------------------------------------------------------------------------------
1073
# Function        : GetGlobalOption   
1074
#
1075
# Description     : Get a global toolset option
1076
#
1077
# Inputs          : $name           - Name of the option to fetch
1078
#                   $default        - Default value to return, if the option
1079
#                                     is not present.
1080
#
1081
# Returns         : The value of the option, or the default value
1082
#
1083
 
1084
sub GetGlobalOption 
1085
{
1086
    my ($name, $default) = @_;
1087
    if (exists $ScmGlobalOptions{$name})
1088
    {
1089
        $default = $ScmGlobalOptions{$name};
1090
    }
4928 dpurdie 1091
    Debug( "GetGlobalOption .", $name, $default  );
4902 dpurdie 1092
    return $default;
1093
}
1094
 
1095
 
1096
#-------------------------------------------------------------------------------
4778 dpurdie 1097
# Function        : ToolsetAddUnitTestPreProcess
1098
#                   ToolsetAddUnitTestPostProcess
1099
#                   ToolsetAddUnitTestCollateProcess
1100
#
1101
# Description     : Functions to allow toolsets to add recipes to be run before
1102
#                   and after Unit Tests are run.    
1103
#
1104
# Inputs          : $target         - Name of the recipe to be run 
1105
#
1106
# Returns         : Nothing
1107
#
1108
sub ToolsetAddUnitTestPreProcess
1109
{
1110
    _ToolsetAddUnitTest(\@TOOLSET_UTF_PRE, @_ );
1111
}
227 dpurdie 1112
 
4778 dpurdie 1113
sub ToolsetAddUnitTestPostProcess
1114
{
1115
    _ToolsetAddUnitTest(\@TOOLSET_UTF_POST, @_ );
1116
}
1117
 
1118
sub ToolsetAddUnitTestCollateProcess
1119
{
1120
    _ToolsetAddUnitTest(\@TOOLSET_UTF_COLLATE, @_ );
1121
}
1122
 
1123
#-------------------------------------------------------------------------------
1124
# Function        : _ToolsetAddUnitTest  
1125
#
1126
# Description     : Internal helper function used by ToolsetAddUnitTest*
1127
#
1128
# Inputs          : $aref           - Ref to an array of names to extend
1129
#                   $target         - Name of recipe to run 
1130
#
1131
# Returns         : Nothing
1132
#
1133
sub _ToolsetAddUnitTest
1134
{
1135
    my ($aref, $target ) = @_;
1136
 
1137
    #   Determine name of parent function
1138
    my $fname = (caller(1))[3];
1139
    $fname =~ s~.*::~~;
1140
    Debug2( "$fname ($target)" );
1141
 
1142
    #
1143
    #   Ensure user is not using a reserved target
1144
    #
1145
    if (grep {$_ eq $target} @reservedMakeTargets) {
1146
        Error("Internal: $fname uses reserved make taget: $target");
1147
    }
1148
 
1149
    push @$aref, $target;
1150
 
1151
}
1152
 
227 dpurdie 1153
###############################################################################
1154
# User interface:
1155
#
1156
#   AddFlags( 'platform [, ... ]', 'flags' [, 'flag' ... ] )
1157
#       This subroutine takes the C and C++ compiler flags
1158
#       specified adding them to a global list for later
1159
#       inclusion in the built makefile.
1160
#
1161
#   AddCFlags( 'platform [, ... ]', 'flags' [, 'flag' ... ] )
1162
#       This subroutine takes the C compiler flags
1163
#       specified adding them to a global list for later
1164
#       inclusion in the built makefile.
1165
#
1166
#   AddCXXFlags( 'platform [, ... ]', 'flags' [, 'flag' ... ] )
1167
#       This subroutine takes the C++ compiler flags
1168
#       specified adding them to a global list for later
1169
#       inclusion in the built makefile.
1170
#
1171
#   AddLintFlags( 'platform [, ... ]', 'flags' [, ... ] )
1172
#       This subroutine takes the Lint flags specified
1173
#       adding them to a global list for later inclusion
1174
#       in the built makefile.
1175
#
1176
#   AddASFlags( 'platform [, ... ]', 'flags' [, ... ] )
1177
#       This subroutine takes the Assemler flags specified
1178
#       adding them to a global list for later inclusion
1179
#       in the built makefile.
1180
#
1181
#   AddLDFlags( 'platform [, ... ]', 'flags' [, ... ] )
1182
#       This subroutine takes the Linker flags specified
1183
#       adding them to a global list for later inclusion
1184
#       in the built makefile.
1185
#
1186
#   AddDir
1187
#       This subroutine takes the directories specified adding
1188
#       them to a global include and source directory list for
1189
#       later inclusion in the built makefile.
1190
#
1191
#   AddIncDir( 'platform [, ... ]', 'dir' [, ... ] )
1192
#       This subroutine takes the include file directories
1193
#       specified adding them to a global list for later
1194
#       inclusion in the built makefile.
1195
#
1196
#   AddSrcDir( 'platform [, ... ]', 'dir' [, ... ] )
1197
#       This subroutine takes the source file directories
1198
#       specified adding them to a global list used to resolve
1199
#       Src() definitions.
1200
#
1201
#   AddLibDir( 'platform [, ... ]', 'dir' [, ... ] )
1202
#       This subroutine takes the library directories
1203
#       specified adding them to a global list for later
1204
#       inclusion in the built makefile.
1205
#
1206
#   AddSourceType( 'ext', '.c|.cc|.asm' )
1207
#       This subroutine takes the extension(s) specified by the
1208
#       programmer and adds them to a global list for later
1209
#       inclusion in the built makefile.  This list contains
1210
#       the extensions to be recognised as 'C', 'C++' or
1211
#       assembler file types.
1212
#
1213
#   AddSourceFile( 'platform [, ... ]', 'file' [, ... ] )
1214
#       This subroutine takes the non-standard source file(s)
1215
#       and adds them add it to either C, C++ or assembler
1216
#       sources and the object list.
1217
#
1218
#   Init( 'platform [, ... ]', 'rule' )
1219
#       Initialisation rule
1220
#
1221
#   Generate( 'platform [, ... ]', 'file' [, ... ] )
1222
#       This subroutine is used to add the list of given
1223
#       source files to the generate sources list, and if
1224
#       the generated source is of type C, C++ or assember
1225
#       also adds it to either C, C++ or assembler sources and
1226
#       the object lists.
1227
#
1228
#       --c             Treat as a C source file.
1229
#       --cpp           Treat as a C++ source file.
1230
#       --asm           Treat as a assembler source file.
1231
#
1232
#   Rule( 'platform [, ... ]', definition )
1233
#       This subroutine is used to add the non-standard make
1234
#       rules required to build the system.  eg. any rules
1235
#       necessary to produce a .cc & .h file from a .x file.
1236
#
1237
#   Src( 'platform [, ... ]', 'file' [, ... ], [ 'arg' [, ...]] )
1238
#       This subroutine is used to add the list of given source
1239
#       files to the sources list, and if the source is of type
1240
#       C, C++ or assember also adds it to either C, C++ or
1241
#       assembler sources and the object lists.  The optional
1242
#       list of arguments is assigned to all source files.
1243
#
1244
#       --c             Treat as a C source file.
1245
#       --cpp           Treat as a C++ source file.
1246
#       --asm           Treat as a assembler source file.
1247
#       --Shared        Shared, produces position-independent
1248
#                       code (on targets where required).
1249
#
1250
#   Lib( 'platform [, ... ]', 'name', 'obj' [, ... ] [, '-arg' [, ... ]] )
1251
#       This subroutine takes a library definition list and adds
1252
#       the  entries to the 3 libraries definition lists. 'name'
1253
#       of the library to be created.  List of the object files
1254
#       'obj' that make up this library.  List of special
1255
#       arguments 'arg' to pass to the librarian.
1256
#
1257
#   MergeLibrary( 'platform [, ... ]', 'name', 'lib' [, ... ] )
1258
#       This subroutine takes a library merge list and adds
1259
#       the  entries to the 2 merge libraries definition lists. 'name'
1260
#       of the library to be created.  List of the libraries to be merged
1261
#
1262
#   LocalScript( 'platform [, ... ]', name, ['1'] )
1263
#   Script( 'platform [, ... ]', name, ['1'] )
1264
#       This subroutine takes a list that defines the name of
1265
#       the script to be placed in the platform 'bin' directory,
1266
#       and an optional second element that defines whether the
1267
#       script should be made executable or not.
1268
#
1269
#   Prog( 'platform [, ... ]', 'name', ['obj', ... ],
1270
#               ['-llib', ... ], ['options'] )
1271
#       This subroutine takes a list that defines which program
1272
#       (binary) is to be made, what libraries and object it is
1273
#       made from, and any special commands required to perform
1274
#       the program creation.
1275
#
1276
#       @PROGS          Updated list of programs to create
1277
#
1278
#   TestProg( 'platform [, ... ]', 'name', ['obj', ... ],
1279
#               ['-llib', ... ], ['options'] )
1280
#       This subroutine takes a list that defines which test program
1281
#       (binary) is to be made, what libraries and object it is
1282
#       made from, and any special commands required to perform
1283
#       the program creation.
1284
#
1285
#       @TESTPROGS      Updated list of programs to create
1286
#
1287
#   InstallHdr( 'platform [, ... ]', 'file' [, ...], ['-arg'] )
1288
#       This subroutine takes the given list of files and adds them
1289
#       to the install header files list.  Files in this list will be
1290
#       installed into the 'local header directory' area for public
1291
#       consumption.  This is generally API files for other modules
1292
#       to use.
1293
#
1294
#       --Strip         Strip directory from source
6276 dpurdie 1295
#       --Strip=n       Strip part of directory from source
227 dpurdie 1296
#       --Full          Install using full path
1297
#       --Subdir=subdir Install within the specified sub-directory
1298
#       --Prefix=subdir   "       "     "      "      "     "
1299
#
1300
#   InstallLib( 'platform [, ... ]', 'file', ['subdir'] )
1301
#       This subroutine takes the given list of files and adds them
1302
#       to the install libraries files list.  Files in this list will
1303
#       be installed into the 'local library directory' area for
1304
#       public consumption.
1305
#
1306
#   InstallProg( 'platform [, ... ]', 'file', ['subdir'] ) )
1307
#       This subroutine takes a list that defines the executable file
1308
#       that is to be installed.  The file in this list will be
1309
#       installed into the 'local executable directory' specified for
1310
#       public consumption.
1311
#
1312
###############################################################################
1313
 
1314
 
1315
sub Include                                     # User include
1316
{
1317
    my( $path, $name ) = @_;
1318
    my( $file );
1319
 
1320
    $file = Require( $path, $name, "Include" );
1321
    push( @ScmDepends, "$file" );
1322
}
1323
 
1324
sub ForceCCompile
1325
{
1326
    CompileOptions( $_[0], 'compile_as_c' );            # Backward compatability
1327
}
1328
 
1329
#-------------------------------------------------------------------------------
1330
#   Create a data structure to define the global compiler options
1331
#    The hash is keyed by compiler option
1332
#    The value contains another hash.
1333
#       The key is a makefile variable to set ( or remove )
1334
#       The value is the value to assign to the makefile variable
1335
#       If the value is 'undef' then the variable will be deleted
1336
#
1337
#   Keys of the form key=value are also supported
1338
#
1339
#   If the value is a CODE reference, then routine will be called with the key
1340
#   and value as arguments. The return value will be utilised.
1341
#
1342
our %ScmCompilerOptions =
1343
    (
1344
        'strict_ansi'           => { 'USE_STRICT_ANSI'    => '1' },
1345
        'no_strict_ansi'        => { 'USE_STRICT_ANSI'    => '' },      # Default
1346
 
1347
        'profile'               => { 'USE_PROFILE'        => '1' },
1348
        'no_profile'            => { 'USE_PROFILE'        => '' },       # Default
1349
 
1350
 
1351
        'prod_no_optimise'      => { 'PROD_USE_OPTIMISE'   => '' },
1352
        'prod_no_debuginfo'     => { 'PROD_USE_DEBUGINFO'  => '' },     # Default
1353
        'prod_optimise'         => { 'PROD_USE_OPTIMISE'   => '1' },    # Default
1354
        'prod_debuginfo'        => { 'PROD_USE_DEBUGINFO'  => '1' },
1355
 
1356
        'debug_no_optimise'     => { 'DEBUG_USE_OPTIMISE'  => '' },     # Default
1357
        'debug_no_debuginfo'    => { 'DEBUG_USE_DEBUGINFO' => '' },
1358
        'debug_optimise'        => { 'DEBUG_USE_OPTIMISE'  => '1' },
1359
        'debug_debuginfo'       => { 'DEBUG_USE_DEBUGINFO' => '1' },    # Default
1360
 
1361
        'compile_as_cpp'        => { 'FORCE_CC_COMPILE'    => '1',
1362
                                     'FORCE_C_COMPILE'     => undef },
1363
        'compile_as_c'          => { 'FORCE_C_COMPILE'     => '1',
1364
                                     'FORCE_CC_COMPILE'    => undef },
267 dpurdie 1365
 
1366
        'no_define_source_file' => { 'DISABLE__SOURCE__' => '1' },
4928 dpurdie 1367
        'define_source_file'    => { 'DISABLE__SOURCE__' => undef },        # Default
267 dpurdie 1368
 
4928 dpurdie 1369
        'warnings_as_errors'    => { 'WARNINGS_AS_ERRORS'        => '1' },
1370
        'no_warnings_as_errors' => { 'WARNINGS_AS_ERRORS'        => undef },       # Default
1371
 
227 dpurdie 1372
    );
1373
 
1374
#
1375
#   The toolset can extend the options by setting the following hash
1376
#
1377
our %ScmToolsetCompilerOptions = ();
1378
 
1379
#
1380
#   Define default compiler options
1381
#   These are makefile variables that will be assigned
1382
#
1383
our %ScmCompilerOpts =
1384
    (
1385
        'USE_STRICT_ANSI'       => '',
1386
        'USE_PROFILE'           => '',
1387
        'PROD_USE_DEBUGINFO'    => '',
1388
        'PROD_USE_OPTIMISE'     => '1',
1389
        'DEBUG_USE_OPTIMISE'    => '',
1390
        'DEBUG_USE_DEBUGINFO'   => '1',
1391
    );
1392
 
1393
 
1394
sub CompileOptions
1395
{
1396
    my( $platforms, @elements ) = @_;
1397
    return if ( ! ActivePlatform($platforms) );
1398
 
1399
    for (@elements)
1400
    {
1401
        my $oref;
1402
 
1403
        #
1404
        #   The toolset option may be a text string or a definition
1405
        #       Name        - A text string
1406
        #       Name=Value  - A value
1407
        #
1408
        my $value;
1409
        my $key = $_;
1410
        if ( $key =~ m~(.*=)(.*)~ )
1411
        {
1412
            $key = $1;
1413
            $value = $2 || '';
1414
        }
247 dpurdie 1415
        $key = lc( $key );
227 dpurdie 1416
 
1417
        #
1418
        #   Examine the global flags
1419
        #   Then the toolset extensions
1420
        #   Then just drop it
1421
        #
1422
        unless ( $oref = ($ScmCompilerOptions{$key} || $ScmToolsetCompilerOptions{$key}) )
1423
        {
1424
            Warning ("Compile Option ignored: $_");
1425
            next;
1426
        }
1427
 
1428
        #
1429
        #   Parse the definition and adjust makefile variables as required
1430
        #   Set the value of a make variable or remove the definition
1431
        #
1432
        #   If the user value is a code reference, then call the code
1433
        #   and use the returned value as the value.
1434
        #
1435
        while ( (my($ukey, $uvalue)) = each %{$oref} )
1436
        {
1437
            if ( defined( $uvalue) )
1438
            {
1439
                if ( ref($uvalue) eq "CODE" )
1440
                {
255 dpurdie 1441
                    $uvalue = &$uvalue( $key, $value, $ukey);
227 dpurdie 1442
                    unless ( defined $uvalue )
1443
                    {
1444
                        Warning ("Compile Option ignored: $_");
1445
                        next;
1446
                    }
1447
                }
247 dpurdie 1448
                elsif ( defined $value )
1449
                {
1450
                    $uvalue = $value;
1451
                }
227 dpurdie 1452
 
1453
                $ScmCompilerOpts{$ukey} = $uvalue;
1454
            }
1455
            else
1456
            {
1457
                delete $ScmCompilerOpts{$ukey};
1458
            }
1459
        }
1460
    }
1461
}
1462
 
1463
#-------------------------------------------------------------------------------
1464
# Function        : AddFlags
1465
#                   AddCFlags
1466
#                   AddCXXFlags
1467
#                   AddASFlags
1468
#                   AddLDFlags
1469
#                   AddLintFlags
1470
#
1471
# Description     : Add target specfic flags to the C compiler
1472
#                   This SHOULD only be used to add Defines to the compiler
1473
#                   but it can be absued.
1474
#
1475
# Inputs          : $platform       - Platforms for which the directive is active
1476
#                   ...             - list of flags to add
1477
#
1478
#                   Embedded options include:
1479
#                       --Debug     - Following options are added to the debug build
1480
#                       --Prod      - Following options are added to the production build
1481
#
1482
# Returns         : Nothing
1483
#
1484
 
1485
sub AddFlags
1486
{
1487
    my( $platforms, @elements ) = @_;
1488
 
1489
    AddCFlags( $platforms, @elements );
1490
    AddCXXFlags( $platforms, @elements );
1491
}
1492
 
1493
sub AddCFlags
1494
{
1495
    my( $platforms, @elements ) = @_;
1496
 
1497
    Debug2( "AddCFlags($platforms, @elements)" );
1498
    return if ( ! ActivePlatform($platforms) );
1499
 
1500
    WarnIfNastyFlag( @elements );
1501
    __AddFlags( "CFLAGS", \@elements,
1502
                \@CFLAGS, \@CLINTFLAGS,
1503
                \@CFLAGS_DEBUG, \@CLINTFLAGS_DEBUG,
1504
                \@CFLAGS_PROD,  \@CLINTFLAGS_PROD );
1505
}
1506
 
1507
sub AddCXXFlags
1508
{
1509
    my( $platforms, @elements ) = @_;
1510
 
1511
    Debug2( "AddCXXFlags($platforms, @elements)" );
1512
    return if ( ! ActivePlatform($platforms) );
1513
 
1514
    WarnIfNastyFlag( @elements );
1515
    __AddFlags( "CXXFLAGS", \@elements,
1516
               \@CXXFLAGS, \@CXXLINTFLAGS,
1517
               \@CXXFLAGS_DEBUG, \@CXXLINTFLAGS_DEBUG,
1518
               \@CXXFLAGS_PROD,  \@CXXLINTFLAGS_PROD );
1519
}
1520
 
1521
sub AddASFlags
1522
{
1523
    my( $platforms, @elements ) = @_;
1524
 
1525
    Debug2( "AddASFlags($platforms, @elements)" );
1526
 
1527
    return if ( ! ActivePlatform($platforms) );
1528
 
267 dpurdie 1529
    __AddFlags( "ASFLAGS", \@elements,
1530
                \@ASFLAGS, undef,
1531
                \@ASFLAGS_DEBUG, undef,
1532
                \@ASFLAGS_PROD, undef );
227 dpurdie 1533
}
1534
 
1535
sub AddLDFlags
1536
{
1537
    my( $platforms, @elements ) = @_;
1538
 
1539
    Debug2( "AddLDFlags($platforms, @elements)" );
1540
 
1541
    return if ( ! ActivePlatform($platforms) );
1542
 
1543
    foreach  ( @elements )
1544
    {
267 dpurdie 1545
        next if ( m~^--(Debug|Prod)~ );
227 dpurdie 1546
        Warning("Use of linker flag discouraged (will be used): $_");
1547
    }
267 dpurdie 1548
    __AddFlags( "LDFLAGS", \@elements,
1549
                \@LDFLAGS, undef,
1550
                \@LDFLAGS_DEBUG, undef,
1551
                \@LDFLAGS_PROD, undef );
227 dpurdie 1552
 
1553
}
1554
 
1555
sub AddLintFlags
1556
{
1557
    my( $platforms, @elements ) = @_;
1558
 
1559
    return if ( ! ActivePlatform($platforms) );
1560
 
1561
    Debug2( "AddLintFlags($platforms, @elements)" );
1562
 
1563
    __AddFlags( "LINTFLAG", \@elements,
1564
                \@CLINTFLAGS, \@CXXLINTFLAGS,
1565
                \@CLINTFLAGS_DEBUG, \@CXXLINTFLAGS_DEBUG,
1566
                \@CLINTFLAGS_PROD, \@CXXLINTFLAGS_PROD  );
1567
}
1568
 
1569
 
1570
#-------------------------------------------------------------------------------
1571
# Function        : __AddFlags
1572
#
1573
# Description     : Generic flag adding to lists routine
1574
#                   Internal use only
1575
#
1576
#                   Supports --Debug and --Prod options
1577
#                   if the appropriate list is present.
1578
#
1579
# Inputs          : Lots
1580
#                   References to compiler and lint flags for
1581
#                   common, debug and product builds.
1582
#
1583
#                   Not all the lists are needed.
1584
#
1585
# Returns         : Nothing
1586
#
1587
sub __AddFlags
1588
{
1589
    my ($textname, $eref,
1590
                   $f_all,      $flint_all,
1591
                   $f_debug,    $flint_debug,
1592
                   $f_prod,     $flint_prod ) = @_;
1593
 
1594
    #
1595
    #   Start added flags to the ALL lists
1596
    #
1597
    my $list = $f_all;
1598
    my $lintlist = $flint_all;
1599
    my $nowarn = 0;
1600
 
1601
    #
1602
    #   Process flags up front
1603
    #
1604
    $nowarn = 1 if ( grep (/^--NoWarn$/, @$eref) );
1605
 
1606
    #
1607
    #   Process all the user arguments
1608
    #
1609
    ADD:
1610
    foreach my $element ( @$eref )
1611
    {
1612
        #
1613
        #   Skip flags
1614
        #
1615
        if ( $element eq '--NoWarn' )
1616
        {
1617
            next;
1618
        }
1619
 
1620
        #
1621
        #   Detect --Debug and --Prod options and swap
1622
        #   lists accordingly.
1623
        #
1624
        if ( $element eq '--Debug' )
1625
        {
1626
            Error ("--Debug not supported for $textname") unless ( $f_debug );
1627
            $list = $f_debug;
1628
            $lintlist = $flint_debug;
1629
            next;
1630
        }
1631
 
1632
        if ( $element eq '--Prod' )
1633
        {
1634
            Error ("--Prod not supported for $textname") unless ( $f_prod );
1635
            $list = $f_prod;
1636
            $lintlist = $flint_prod;
1637
            next;
1638
        }
1639
 
1640
        #
1641
        #   Scan all the lists for a possible duplicates
1642
        #
1643
        foreach my $temp ( @$f_all, @$f_debug, @$f_prod ) {
1644
            if ($temp eq $element) {
1645
                Warning( "Duplicate $textname ignored '$element'") unless $nowarn;
1646
                next ADD;
1647
            }
1648
        }
1649
 
1650
        #
1651
        #   Add the flag to the compiler and lint lists
1652
        #
1653
        push( @$list, $element ) if $list;
1654
        push( @$lintlist, $element ) if $lintlist;
1655
    }
1656
}
1657
 
1658
sub WarnIfNastyFlag
1659
{
1660
    foreach  ( @_ )
1661
    {
1662
        Warning("Use of compiler flags discouraged (will be used): $_")
1663
            unless ( m/^-[DU]/ || m/^--Debug/ || m/^--Prod/ || /^--NoWarn/ );
1664
    }
1665
}
1666
 
1667
 
1668
sub AddDir
1669
{
1670
    AddIncDir( @_);
1671
    AddSrcDir( @_ );
1672
}
1673
 
1674
 
1675
sub AddIncDir
1676
{
1677
    _AddDir( 'AddIncDir', 'INCDIR', \@INCDIRS, \@S_INCDIRS, \@G_INCDIRS, \@L_INCDIRS, @_ );
1678
}                                                           
1679
 
1680
sub AddSrcDir                                               
1681
{                                                           
1682
    _AddDir( 'AddSrcDir', 'SRCDIR', \@SRCDIRS, \@S_SRCDIRS, \@G_SRCDIRS, \@L_SRCDIRS, @_ );
1683
}                                                           
1684
 
1685
sub AddLibDir                                               
1686
{                                                           
1687
    _AddDir( 'AddLibDir', 'LIBDIR', \@LIBDIRS, \@S_LIBDIRS, \@G_LIBDIRS, \@L_LIBDIRS, @_ );
1688
}
1689
 
1690
#-------------------------------------------------------------------------------
1691
# Function        : _AddDir
1692
#
1693
# Description     : Internal routine to add a directory to list of directories
1694
#                   Common code to simplify implementation of other directives
1695
#
1696
# Inputs          : $name           - Name of function
1697
#                   $udir           - User name of dir list
1698
#                   $dirref         - Reference to directory array
1699
#                   $s_dirref       - Reference to system directory array
1700
#                   $g_dirref       - Reference to global directory array
1701
#                   $l_dirref       - Reference to local directory array
1702
#                   @args           - User arguments
1703
#                                       - platforms
1704
#                                       - Directories and --Options
1705
#
1706
sub _AddDir
1707
{
1708
    my( $name, $udir, $dirref, $s_dirref, $g_dirref, $l_dirref, $platforms, @elements ) = @_;
1709
 
1710
    Debug ( "$name($platforms, @elements)" );
1711
    Error ( "$name: Insufficient arguments") unless ( @elements );
1712
    return if ( ! ActivePlatform($platforms) );
1713
 
1714
    #
1715
    #   Cleanup user parameters
1716
    #
1717
    foreach ( @elements )
1718
    {
1719
        s/^\s+//;                               # Remove leading space
1720
        s/\s+$//;                               # Remove trailing spaces
1721
        s~/$~~;                                 # Remove trailing /
1722
        s~//~/~g;                               # Remove multiple /
1723
    }
1724
 
1725
#.. Collect arguments
1726
    my $tlist_ref = $ScmGlobal ? $g_dirref : $l_dirref; # "current" scope ....
1727
    my $nowarn = 0;
1728
    my $nodepend = 0;
1729
    my @dirs;
1730
 
1731
    foreach ( @elements )
1732
    {
1733
        if ( ! /^--/ ) {                        # Collect directories
1734
            push @dirs, $_;
1735
 
1736
        } elsif (/^--Local$/) {                 # "local" scope ....
1737
            $tlist_ref = $l_dirref;
1738
 
1739
        } elsif (/^--Global$/) {                # "global" scope ...
1740
            $tlist_ref = $g_dirref;
1741
 
1742
        } elsif (/^--System$/) {                # "system" scope ...
1743
            $tlist_ref = $s_dirref;
1744
 
1745
        } elsif (/^--NoDepend$/) {              # Split from dependency list
1746
            if ( $udir eq 'INCDIR' ) {          # AddIncDir only
1747
                $nodepend = 1;
1748
            }
1749
 
1750
        } elsif (/^--NoWarn$/) {                # Disable warnings
1751
            $nowarn = 1;
1752
 
1753
        } elsif (/^--(.*)/) {
1754
            Message( "$name: unknown option $_ -- ignored\n" );
1755
 
1756
        }
1757
    }
1758
 
1759
    Error ( "$name: No directory specified: ($platforms, @elements)" )
1760
        unless ( @dirs );
1761
 
1762
 
1763
#.. Push source path(s)
1764
    foreach ( @dirs )
1765
    {
1766
        #
1767
        #   Add to complete list of directories
1768
        #   Warn on duplicates
1769
        #
1770
        unless ( UniquePush( $dirref, $_) )
1771
        {
1772
            Warning( "Duplicate $udir ignored '$_'" )
1773
                unless ( $nowarn );
1774
            next;
1775
        }
1776
 
1777
        #
1778
        #   Check that the directory actually exists
1779
        #   If the path contains a $(XXXXX) then it can't be checked
1780
        #
1781
        if ( index( $_, '$' ) == -1 )
1782
        {
1783
            Warning( "$name. Directory not found: $_",
1784
                     "Current directory         : $::Cwd",
2450 dpurdie 1785
                     "Cannot resolved Directory : " . AbsPath($_, $::Cwd, 1),
227 dpurdie 1786
                       )
1787
                unless ( $nowarn || -d $_ );
1788
        }
1789
 
1790
        #
1791
        #   Add to suitable list
1792
        #
1793
        push @{$tlist_ref}, $_;
6133 dpurdie 1794
        ToolsetFiles::AddDir($_, 'Include');
227 dpurdie 1795
 
1796
        #
1797
        #   Add to the no dependancy list (ie generated depend file)
1798
        #   Only used by AddIncDir, accepted by AddSrcDir
1799
        #
1800
        push( @NODEPDIRS, $_ )
1801
            if ($nodepend);
1802
    }
1803
}
1804
 
6177 dpurdie 1805
#-------------------------------------------------------------------------------
1806
# Function        : ExtendIncDir 
1807
#
1808
# Description     : Allow the directory search paths to be extended into sub
1809
#                   directories.
1810
#                   
1811
#                   Limit use, but ...
1812
#
1813
# Inputs          : $platform       - Active platforms
1814
#                   ...             - Path extensions
1815
#
1816
# Returns         : 
1817
#
1818
my  %ExtendIncDirSeen;
1819
sub ExtendIncDir
1820
{
1821
    my( $platforms, @paths ) = @_;
1822
    Debug2( "ExtendIncDir($platforms, @paths)" );
1823
    return if ( ! ActivePlatform($platforms) );
1824
    Error ('ExtendIncDir. No extensions listed') unless @paths;
1825
    #
1826
    #   Ensure the user only extends the paths once.
1827
    #   Could silently discard excess - better to force the user to get it right
1828
    #
1829
    foreach my $path ( @paths) {
1830
        ReportError ('ExtendIncDir. Multiple defintions for: ' . $path) if exists $ExtendIncDirSeen{$path}; 
1831
        $ExtendIncDirSeen{$path} = 0;
1832
    }
1833
    ErrorDoExit();
227 dpurdie 1834
 
6177 dpurdie 1835
    #
1836
    #   Zip though all the packages and extend the search paths
1837
    #   Also gets those in the interface directory
1838
    #
1839
    for my $package (@{$::ScmBuildPkgRules{$ScmPlatform} })
1840
    {
1841
        #DebugDumpData("package", $package);
1842
        foreach my $path ( @paths)
1843
        {
1844
            if ( $package->{PINCDIRS})
1845
            {
1846
                my @output;
1847
                foreach my $pdir ( @{$package->{PINCDIRS}})
1848
                {
1849
                    my $tdir = catdir ($pdir, $path);
1850
                    my $adir = catdir ($package->{ROOT}, $tdir);
1851
                    if ( -d $adir) {
1852
                        Verbose("Extending $package->{DNAME} $package->{VERSION}: $tdir");
1853
                        push @output, $tdir;
1854
                        $ExtendIncDirSeen{$path}++;
1855
                    }
1856
                    push @output, $pdir;
1857
                }
1858
              @{$package->{PINCDIRS}} = @output;
1859
            }
1860
        }
1861
    }
1862
 
1863
    #
1864
    #   Report extensions that have not been used
1865
    #
1866
    foreach my $path ( @paths) {
1867
        ReportError ('ExtendIncDir. Search path not extendable: ' . $path) unless $ExtendIncDirSeen{$path}; 
1868
    }
1869
 
1870
    ErrorDoExit();
1871
}
1872
 
1873
 
227 dpurdie 1874
sub AddProg
1875
{
1876
    my( $platforms, @progs ) = @_;
1877
 
1878
    Debug2( "AddProg($platforms, @progs)" );
1879
 
1880
    return if ( ! ActivePlatform($platforms) );
1881
 
285 dpurdie 1882
    foreach my $prog (@progs)
227 dpurdie 1883
    {
289 dpurdie 1884
        my $pProg = $PROGS->Get($prog);
227 dpurdie 1885
        Warning( "Duplicate prog ignored '$prog'" )
289 dpurdie 1886
            if ( $pProg );
1887
        $pProg = $PROGS->NewAdd($prog)
227 dpurdie 1888
    }
1889
}
1890
 
1891
 
1892
sub AddSourceType
1893
{
1894
    my( $ext, $type ) = @_;
1895
 
1896
    Debug2( "AddSourceType(@_)" );
1897
 
1898
    #
1899
    #   Default Source Type (C)
1900
    #
1901
    $type = ".c" unless ( $type );
1902
 
1903
    Error ("Source type '$ext' not allowed")
1904
        if ( $ext !~ /^\.\w+$/ );
1905
 
1906
    $type = lc($type)
1907
        if ( $::ScmHost ne "Unix" );
1908
    $ScmSourceTypes{ $ext } = $type;
1909
}
1910
 
1911
 
1912
sub AddSourceFile
1913
{
1914
    my( $platforms, @elements ) = @_;
1915
 
1916
    Debug2( "AddSourceFile($platforms, @elements)" );
1917
    return if ( ! ActivePlatform($platforms) );
1918
 
285 dpurdie 1919
    foreach my $path ( @elements )
227 dpurdie 1920
    {
1921
        __AddSourceFile( 1, $path );
1922
    }
1923
}
1924
 
1925
 
1926
#-------------------------------------------------------------------------------
1927
# Function        : __AddSourceFile
1928
#
1929
# Description     : Internal function
1930
#                   Add a source file to internal lists
1931
#
1932
#                   Assumes that the current platform is ACTIVE
1933
#
1934
# Inputs          : push    0: Don't push onto OBJS (non-shared objfiles)
1935
#                   path    Filename.extension
1936
#                   obj     object file name (optional)
1937
#                   type    Type of file. "" -> auto detect
1938
#
1939
# Returns         : True        - File is a 'known' source file
1940
#                   False       - File is not a 'known' source file
1941
#
1942
sub __AddSourceFile
1943
{
1944
    my( $push, $path, $obj, $type ) = @_;
271 dpurdie 1945
    my( $filename, $ext, $srcfile, $is_obj, $ext_type, $result );
227 dpurdie 1946
 
271 dpurdie 1947
    $filename = StripDir($path);                # file name
227 dpurdie 1948
 
1949
    $ext  = StripFile($path);                   # extension
1950
    $ext = lc($ext)
1951
        if ( $::ScmHost ne "Unix" );
1952
 
271 dpurdie 1953
    if (! ($srcfile = $SRCS{$filename})) {
227 dpurdie 1954
        $srcfile = $path;                       # generated
1955
    }
1956
 
271 dpurdie 1957
    $obj  = StripExt( $filename )               # Base name of object file
227 dpurdie 1958
        if ( ! defined($obj) || $obj eq "" );
1959
 
1960
    $type = ""                                  # optional type
1961
        if ( ! defined( $type ) );
1962
 
1963
    #
1964
    #   Push file onto a suitable source file list
1965
    #
1966
    $result = 0;
1967
    $ext_type = "";                             # map extension
1968
    $ext_type = $ScmSourceTypes{ $ext }
1969
        if ( exists( $ScmSourceTypes{ $ext } ) );
1970
    $result = 1 if ( $ext_type );
1971
 
1972
    if ( $type eq "" && defined $::ScmToolsetProgSource{$ext} )
1973
    {
1974
        Debug( "SourceFile: $path is ToolsetProgSource   -> $srcfile" );
1975
        push( @CSRCS, $srcfile );
1976
        $result = 1;
1977
    }
1978
    elsif ( ($type eq "" && $ext_type eq ".h") || ($type eq ".h") )
1979
    {
1980
        Debug( "SourceFile: $path is .h   -> $srcfile" );
1981
        push( @CHDRS, $srcfile );
1982
    }
1983
    elsif ( ($type eq "" && $ext_type eq ".inc") || ($type eq ".inc") )
1984
    {
1985
        Debug( "SourceFile: $path is .inc -> $srcfile" );
1986
        push( @ASHDRS, $srcfile );
1987
    }
1988
    elsif ( ($type eq "" && $ext_type eq ".c") || ($type eq ".c") )
1989
    {
1990
        Debug( "SourceFile: $path is .c   -> $srcfile=$obj" );
1991
        push( @CSRCS, $srcfile );
1992
        $is_obj = 1;
1993
    }
1994
    elsif ( ($type eq "" && $ext_type eq ".cc") || ($type eq ".cc") )
1995
    {
1996
        Debug( "SourceFile: $path is .cc  -> $srcfile=$obj" );
1997
        push( @CXXSRCS, $srcfile );
1998
        $is_obj = 1;
1999
    }
2000
    elsif ( ($type eq "" && $ext_type eq ".asm") || ($type eq ".asm") )
2001
    {
2002
        Debug( "SourceFile: $path is .asm -> $srcfile=$obj" );
2003
        push( @ASSRCS, $srcfile );
2004
        $is_obj = 1;
2005
    }
2006
    elsif ( $ext_type eq "--Ignore" )
2007
    {   # ignored ...
2008
        #   .x      "rpcgen" source files
2009
        #   .ini    Configuration
2010
        #   .sh     Shell script
2011
    }
2012
    else
2013
    {
2014
        Debug( "SourceFile: $path is unknown file type" );
2015
 
2016
        #
2017
        #   Insert source files with unknown extensions onto lists
2018
        #   of there own type
2019
        #
2020
        if ( $ext )
2021
        {
2022
            (my $varname = uc ( $ext . 'SRCS')) =~ s~\.~~g;
2023
            no strict 'refs';
2024
            push @$varname, $srcfile;
2025
            use strict 'refs';
2026
        }
2027
    }
2028
 
2029
    #
271 dpurdie 2030
    #   See if there is a hook function for this type of source file
2031
    #   Invoke user function to perform additional processing on the file
2032
    #
2033
    if ( %MF_RegisterSrcHooks )
2034
    {
2035
        my @listeners;
2036
        push @listeners, @{$MF_RegisterSrcHooks{$ext}} if ( exists $MF_RegisterSrcHooks{$ext} );
2037
        push @listeners, @{$MF_RegisterSrcHooks{'*'}}  if ( exists $MF_RegisterSrcHooks{'*'} );
2038
        while ( @listeners )
2039
        {
2040
            Debug( "RegisterSrcHook: Invoke SrcHook function" );
2041
            my ($fname, @args) = @{shift @listeners};
2042
            &$fname ( $srcfile ,$filename, $obj, $ext ,@args );
2043
        }
2044
    }
2045
 
2046
    #
227 dpurdie 2047
    #   Object files are saved in
2048
    #       OBJSOURCE   - Generate a recipe to create the object
2049
    #       OBJS        - A list of ALL non-shared object files
2050
    #
6133 dpurdie 2051
    if ( $is_obj && $::o && $ScmNotGeneric )
227 dpurdie 2052
    {
2053
        $OBJSOURCE{ "$obj" } = $srcfile;
2054
        push( @OBJS, $obj )
2055
            if ($push);
2056
    }
2057
 
2058
    #
2059
    #   Indicate to the user that the file is a 'known' source file
2060
    #   This implies that the file is required early in the build process
2061
    #   and may need to be generated early.
2062
    #
2063
    return $result;
2064
}
2065
 
2066
#-------------------------------------------------------------------------------
2067
# Function        : SetValue
2068
#
2069
# Description     : Defines a variable that can be used within the makefile.pl
2070
#                   Use sparingly
2071
#                   An attempt to formalise a mechanism that is used anyway, but
2072
#                   with correct platform detection
2073
#
2074
# Inputs          : $platform       - Platform selector
2075
#                   $name           - Name to set
2076
#                   $value          - Value to set
2077
#                   options         - Options
2078
#                                       --NoWarn
2079
#                                       --Project=xxxx[,xxxx]+
2080
#                                       --
2081
#
2082
sub SetValue
2083
{
2084
    my( $platforms, @elements ) = @_;
2085
    my $name;
2086
    my $value;
2087
    my $nowarn;
2088
    my $nomoreswicthes = 0;
2089
 
2090
    Debug2( "SetValue($platforms, @elements)" );
2091
 
2092
    return if ( ! ActivePlatform($platforms) );
2093
 
2094
    #
2095
    #   Process elements extracting values and options
2096
    #
2097
    foreach ( @elements )
2098
    {
2099
        if ( m/^--$/ ) {
2100
            $nomoreswicthes = ! $nomoreswicthes;
2101
            next;
2102
        }
2103
 
2104
        if ( m/^--/ && ! $nomoreswicthes )
2105
        {
2106
 
2107
            if ( m/^--NoWarn/ ) {
2108
                $nowarn = 1;
2109
 
2110
            } elsif ( m/^--Project=(.*)/ ) {
2111
                return unless ( ActiveProject( $1) );
2112
 
2113
            } else {
2114
                Error ("SetValue: Unknown option: $_");
2115
 
2116
            }
2117
 
2118
        } elsif ( ! defined $name ) {
2119
            $name = $_;
2120
 
2121
        } elsif ( ! defined $value ) {
2122
            $value = $_;
2123
 
2124
        } else {
2125
            Error ("SetValue: $name. Too many parameters" );
2126
 
2127
        }
2128
    }
2129
 
2130
    #
2131
    #   Warn if the named variable already exists
2132
    #   It may be a JATS internal or it may be a user.
2133
    #
2134
    unless ( $nowarn )
2135
    {
2136
        no strict 'refs';
2137
        Warning("SetValue: $name. Redefined") if defined ( $$name );
2138
        use strict 'refs';
2139
    }
2140
 
2141
    #
2142
    #   Set the value
2143
    #
2144
    no strict 'refs';
2145
    $$name = $value;
2146
    use strict 'refs';
2147
}
2148
 
2149
#-------------------------------------------------------------------------------
2150
# Function        : SetList
2151
#
2152
# Description     : Defines a list variable that can be used within the makefile.pl
2153
#                   Use sparingly
2154
#                   An attempt to formalise a mechanism that is used anyway, but
2155
#                   with correct platform detection
2156
#
2157
# Inputs          : $platform       - Platform selector
2158
#                   $name           - Name to set
2159
#                   $value,...      - Values to set
2160
#                   options         - Options
2161
#                                       --NoWarn
2162
#                                       --Project=xxxx[,xxxx]+
2163
#                                       --Unique
2164
#                                       --Clear
2165
#                                       --Append
2166
#                                       --
2167
#
2168
my %SetList_names;
2169
sub SetList
2170
{
2171
    my( $platforms, @elements ) = @_;
2172
    my $name;
2173
    my @value;
2174
    my $nowarn;
2175
    my $unique;
2176
    my $clear;
2177
    my $nomoreswicthes = 0;
2178
 
2179
    Debug2( "SetList($platforms, @elements)" );
2180
 
2181
    return if ( ! ActivePlatform($platforms) );
2182
 
2183
    #
2184
    #   Process elements extracting values and options
2185
    #
2186
    foreach ( @elements )
2187
    {
2188
        if ( m/^--$/ ) {
2189
            $nomoreswicthes = ! $nomoreswicthes;
2190
            next;
2191
        }
2192
 
2193
        if ( m/^--/ && ! $nomoreswicthes )
2194
        {
2195
            if ( m/^--NoWarn/ ) {
2196
                $nowarn = 1;
2197
 
2198
            } elsif ( m/^--Project=(.*)/ ) {
2199
                return unless ( ActiveProject( $1) );
2200
 
2201
            } elsif ( m/^--Unique/ ) {
2202
                $unique = 1;
2203
 
2204
            } elsif ( m/^--Clear/ ) {
2205
                $clear = 1;
2206
 
2207
            } elsif ( m/^--Append/ ) {
2208
                $clear = 0;
2209
 
2210
            } else {
2211
                Error ("SetList: Unknown option: $_");
2212
            }
2213
        } elsif ( ! defined $name ) {
2214
            $name = $_;
2215
 
2216
        } else {
2217
            push @value, $_;
2218
 
2219
        }
2220
    }
2221
 
2222
    Error ("SetList: No name specified") unless ( $name );
2223
 
2224
    #
2225
    #   Warn if the named variable already exists
2226
    #   It may be a JATS internal or it may be a user.
2227
    #
2228
    #   Only do this iff the name is not known to this function
2229
    #   Keep a list a names that have been set.
2230
    #
2231
    if ( ! $SetList_names{$name} && ! $nowarn )
2232
    {
2233
        no strict 'refs';
4455 dpurdie 2234
        Warning("SetList: $name. Defined outside the ScanList/SetList directive","May clash with Jats internals") if ( @$name );
227 dpurdie 2235
        use strict 'refs';
2236
    }
2237
    $SetList_names{$name} = 1;
2238
 
2239
    #
2240
    #   Clear list
2241
    #
2242
    if ( $clear )
2243
    {
2244
        no strict 'refs';
2245
        @$name = ();
2246
        use strict 'refs';
2247
    }
2248
 
2249
    #
2250
    #   Set the value
2251
    #
2252
    no strict 'refs';
2253
    if ( $unique ) {
2254
        UniquePush( \@$name, @value);
2255
    } else {
2256
        push @$name, @value;
2257
    }
2258
    use strict 'refs';
2259
}
2260
 
2261
#-------------------------------------------------------------------------------
2262
# Function        : ScanList
2263
#
2264
# Description     : Create a list by scanning for files in a directory
2265
#                   The files may be in a local directory or within a package
2266
#                   Care must be taken when using a package as the results
2267
#                   may differ bewteen BuildPkgArchive and LinkPkgArchive
2268
#
2269
#                   Interworks with SetList
2270
#
2271
# Inputs          : $platform       - Platform selector
2272
#                   $name           - Name to set
2273
#                   $value,...      - Values to set
2274
#                   options         - Options
2275
#                                       --NoWarn
2276
#                                       --Project=xxxx[,xxxx]+
2277
#                                       --Unique
2278
#                                       --Clear
2279
#                                       --Append
2280
#
2281
#                                       --Package=xxxx[,ext]
2282
#                                       --Dir=xxx
2283
#
2284
#                                       --Subdir=yyy
2285
#                                       --DirListOnly
2286
#                                       --FileListOnly
335 dpurdie 2287
#                                       --Recurse (default)
227 dpurdie 2288
#                                       --NoRecurse
335 dpurdie 2289
#                                       --FullPath (default)
2290
#                                       --NoFullPath
227 dpurdie 2291
#
2292
#                                       --FilterIn=xxx
2293
#                                       --FilterInRe=xxx
2294
#                                       --FilterOut=xxx
2295
#                                       --FilterOutRe=xxx
2296
#
2297
# Returns         :
2298
#
2299
sub ScanList
2300
{
2301
    my( $platforms, @elements ) = @_;
2302
    my $name;
2303
    my $package;
2304
    my $dir;
2305
    my $subdir;
2306
    my @set_args;
2307
    my $search = JatsLocateFiles->new('Recurse','FullPath' );
2308
 
2309
    Debug2( "ScanList($platforms, @elements)" );
2310
 
2311
    return if ( ! ActivePlatform($platforms) );
2312
 
2313
    #
2314
    #   Process elements extracting values and options
2315
    #
2316
    foreach ( @elements )
2317
    {
2318
        if ( m/^--Unique|--Clear|--Append|--NoWarn/ ) {
2319
            push @set_args, $_;
2320
 
2321
        } elsif ( m/^--Project=(.*)/ ) {
2322
            return unless ( ActiveProject( $1) );
2323
 
2324
        } elsif ( m/^--Package=(.*)/ ) {
2325
            $package = $1;
2326
 
2327
        } elsif ( m/^--Dir=(.*)/ ) {
2328
            $dir = $1;
2329
 
2330
        } elsif ( m/^--Subdir=(.*)/ ) {
2331
            $subdir = $1;
2332
 
2333
        } elsif ( $search->option( $_ ) ) {
2334
            Verbose ("Search Option: $_" );
2335
 
2336
        } elsif ( m/^--/ ) {
2337
            Error ("ScanList: Unknown option: $_");
2338
 
2339
        } elsif ( ! defined $name ) {
2340
            $name = $_;
2341
 
2342
        } else {
2343
                Error ("ScanList $name: Unknown option: $_");
2344
 
2345
        }
2346
    }
2347
 
2348
    Error ("ScanList: No variable name specified") unless ( $name );
2349
    Error ("ScanList: Must Specify --Dir or --Package") unless ( $dir || $package );
2350
    Error ("ScanList: --Dir and --Package are mutually exclusive") if ( $dir && $package );
2351
 
2352
    #
2353
    #   Locate the base of the scan
2354
    #   This may be either a package name or a local directory
2355
    #
2356
    #   Its no use allowing the user to use OBJ/LIB/BIN directories as the
2357
    #   directories MUST exist at build time. Don't really want the user doing
2358
    #   that level of poking out of a package
2359
    #
2360
    if ( $package )
2361
    {
2362
        $dir = GetPackageBase( "ScanList", $package );
2363
        Error ("ScanList: Package not found: $package") unless ( $dir );
2364
    }
2365
    else
2366
    {
2367
        Error ("ScanList: Root directory not found: $dir") unless ( -d $dir );
2368
    }
2369
    if ( $subdir )
2370
    {
2371
        $dir .= "/" . $subdir;
2372
        Error ("ScanList: Sub directory not found: $subdir") unless ( -d $dir );
2373
    }
2374
 
2375
    #
2376
    #   Use SetList to do the rest of the work
2377
    #
2378
    SetList( $platforms, $name, @set_args, '--', $search->search($dir) );
2379
}
2380
 
2381
 
2382
sub Init
2383
{
2384
    push( @INITS, @_ );
2385
}
2386
 
2387
#-------------------------------------------------------------------------------
2388
# Function        : Generate
2389
#
2390
# Description     : Legacy Function - don't use unless you have too.
2391
#                   Flags files that are to be generated during the
2392
#                   early 'generate' make phase. Will also add named files
2393
#                   to various internal lists
2394
#
2395
#                   Intended to be used in conjunction with the 'Rule' directive
2396
#                   to flag header and source files that need to be created early
2397
#                   in the build process.
2398
#
2399
# Inputs          : See GenerateSrcFile
2400
#
2401
# Returns         : 
2402
#
2403
sub Generate
2404
{
2405
    my( $platforms, @elements ) = @_;
2406
 
2407
    Debug2( "Generate($platforms, @elements)" );
2408
 
2409
    return if ( ! ActivePlatform($platforms) );
2410
    Message("Generate directive used. Consider replacing with GenerateFiles");
2411
 
2412
    #
2413
    #   Use Non-warning version to do the hard work
2414
    #
2415
    GenerateSrcFile( 1, @elements );
2416
}
2417
 
2418
#-------------------------------------------------------------------------------
2419
# Function        : Generated
2420
#
2421
# Description     : Legacy Function - don't use unless you have too.
2422
#                   Flags files that are generated by misc Rules
2423
#
2424
#                   Intended to be used in conjunction with the 'Rule' directive
2425
#                   to mark files that have been generated, so that they can be
2426
#                   cleaned up.
2427
#
2428
#                   Note the difference to the 'Generate' directive which will
2429
#                   ensure that the Rule will be run in the 'generate' phase,
2430
#                   this directive doesn't.
2431
#
2432
# Inputs          : Files with internal Makefile Paths and codes
2433
#                   Eg: Generated( '*', "\$(LIBDIR)/libcsf\$(GBE_TYPE).\${a}" );
2434
#                   See why its YUK!
2435
#
2436
# Returns         : 
2437
#
2438
sub Generated
2439
{
2440
    my( $platforms, @elements ) = @_;
2441
    my( @args );
2442
 
2443
    return if ( ! ActivePlatform($platforms) );
2444
    Debug2( "Generated($platforms, @elements)" );
2445
 
2446
    #.. Collect arguments
2447
    #
2448
    foreach ( @elements )
2449
    {
2450
        if ( /^-(.*)/ )
2451
        {
2452
            Debug( "Gen: arg $_" );
2453
            push ( @args, $_);
2454
        }
2455
    }
2456
 
2457
    #.. Push source file(s)
2458
    #
2459
    foreach ( @elements )
2460
    {
2461
        if ( ! /^-(.*)/ )
2462
        {
2463
            Debug( "Generated: $_ (@args)" );
2464
            push (@USERGENERATED, $_);
2465
 
2466
            #
2467
            #   Add the file to the list of known source files
2468
            #   This will allow them to be packaged
2469
            #
2470
            GenerateSrcFile (0, $_ );
2471
        }
2472
    }
2473
}
2474
 
2475
 
2476
#-------------------------------------------------------------------------------
2477
# Function        : GenerateSrcFile
2478
#
2479
# Description     : Internal Function (No $platform)
2480
#                   Determine how to handle a 'Generated' file
2481
#
2482
#
2483
# Inputs          : $generated          - 0: Don't add to GENERATED List
2484
#                                         1: Add to GENERATED List
2485
#                                         2: Add to GENERATED List, if a source file
2486
#                   FileName(s)         - Name of one or more files to process
2487
#                                         All files are processed in the same way
2488
#                                         These file may contain Makefile prefixes
2489
#                                         ie: $(OBJDIR)/file.obj
2490
#                   Options:
2491
#                       --c             - Hint: Its a "C" file
2492
#                       --cpp           - Hint: Its a C++ file
2493
#                       --asm           - Hint: Its an ASM file
2494
#                       -*              - Save as argument attached to the file
2495
#
303 dpurdie 2496
# Returns         : Number of 'source' file
227 dpurdie 2497
#
2498
sub GenerateSrcFile                             # Internal Function - no $platform
2499
{
2500
    my( $generated, @elements ) = @_;
2501
    my( $type, @args );
303 dpurdie 2502
    my $result = 0;
227 dpurdie 2503
 
2504
    Debug2( "GenerateSrcFile($generated,@elements)" );
2505
 
2506
    #.. Collect arguments
2507
    #
2508
    $type = "";
2509
    foreach ( @elements )
2510
    {
2511
        if ( /^--c$/ ) {
2512
            Debug( "Gen: --c" );
2513
            $type = ".c";
2514
 
2515
        } elsif ( /^--cpp$/ ) {
2516
            Debug( "Gen: --cpp" );
2517
            $type = ".cc";
2518
 
2519
        } elsif ( /^--asm$/ ) {
2520
            Debug( "Gen: --asm" );
2521
            $type = ".asm";
2522
 
2523
        } elsif ( /^-(.*)/ ) {
2524
            Debug( "Src: arg $_" );
2525
            push @args, $_;
2526
        }
2527
    }
2528
 
2529
    #.. Process source file(s)
2530
    #
2531
    #   Determine if file is already a known SRCS file - skip if already known
2532
    #   Update SRCS data
2533
    #   Update SRC_TYPE data
2534
    #   Update SRC_ARGS data
2535
    #   Add the file to a suitable source file list ie: @CHDRS,...
2536
    #   Flag as a GENERATED file - These will be processed during the 'generate' phase
2537
    #
2538
    foreach my $source ( @elements )
2539
    {
2540
        next if ( $source =~ /^-(.*)/ );                # Not a source file
2541
 
2542
        my $basename = StripDir( $source );
2543
        Debug( "Generate: $source=$basename (@args)" );
2544
 
2545
        if ($SRCS{ $basename }) {
2546
            Warning( "Duplicate src ignored '$source'" );
2547
            next;
2548
        }
2549
        $SRCS{ $basename } = $source;
2550
 
2551
        HashJoin( \%SRC_ARGS, $;, $basename, @args )
2552
            if (@args);
2553
 
2554
        $SRC_TYPE{ $basename } = $type
2555
            if ($type);
2556
 
2557
        #
5867 dpurdie 2558
        #   Add the file to any source file lists that may like to know
227 dpurdie 2559
        #   about this file.
2560
        #
2561
        #   If the file was a known source file, then it may need to be generated
2562
        #   very early in the build process.
2563
        #
2564
        my $src_file_type = __AddSourceFile( 1, $basename );
285 dpurdie 2565
        if ($generated == 1 || ($src_file_type && $generated > 1) )
227 dpurdie 2566
        {
2567
            push(@GENERATED, $source);
303 dpurdie 2568
            $result++;
227 dpurdie 2569
        }
2570
        else
2571
        {
2572
            push(@GENERATED_NOTSRC, $source);
2573
        }
2574
    }
303 dpurdie 2575
 
2576
    return $result;
227 dpurdie 2577
}
2578
 
2579
#-------------------------------------------------------------------------------
2580
# Function        : GenerateFiles
2581
#
2582
# Description     : Generate files in a controlled manner using a specified
2583
#                   tool to perform the task
2584
#
2585
# Inputs          : $1      - platform specifier '*' (comma delemitered)
2586
#                   $2      - Tool Name
2587
#                   $3...   - Command line argument to generate files with embedded information
2588
#                           - or options. Multiple command line arguments will be joind with
2589
#                             a single space
2590
#
2591
#                   The generated files will be placed in the OBJ directory for
2592
#                   the current target platform. This allows different files to
2593
#                   be generated for each platform, without collision.
2594
#
2595
#                   The full name of the generated files will be added to the list of
2596
#                   source files. Thus the user does not need to know the
2597
#                   full name of the file - it will be tracked by JATS.
2598
#
2599
#                   If a generated file is a header file, then the OBJ directory
2600
#                   will be added as AddIncDir() so that the header files can be
2601
#                   extracted
2602
#
2603
#                   If a generated file is a "C"/"C++" source file, then it will
2604
#                   compiled and the object file made available
2605
#
2606
#                   The tool name may be:
2607
#                       --Tool=name  or "name"
2608
#                               Look in the tool paths in Packages
2609
#                               Look in the JATS tool directory for named script
2610
#                               Look in the JATS bin directory for the named exe
2611
#                               Look in the users path ( and generate a warning )
2612
#                               Give up and hope magic happens later
2613
#                       --Script=name
2614
#                               Resolve the name using known Src paths
2615
#                               The script may be generated and need not exist
2616
#                               at the time the makefile is created.
2617
#                       --Shell
2618
#                               The command line argument is a shell script that
2619
#                               will be passed to a simple shell.
263 dpurdie 2620
#                       --Prog=name
2621
#                               Resolve to a program generated within this makefile
227 dpurdie 2622
#
2623
#
2624
#                   The command line argument contains keywords to allow
2625
#                   information to be extracted from the line. Keywords are:
2626
#
2627
#                       --Generated(xxx)        - xxx is a generated file
2628
#                                                 It will be placed in the OBJDIR
2629
#                       --GeneratedCommon(xxx)  - xxx is a generated file
2630
#                                                 File will be placed in the local directory
2631
#                                                 and will be shared by by all platforms
2632
#                       --GeneratedObject(xxx)  - xxx is a generated object file
2633
#                                                 It will be placed in the OBJDIR and will
2634
#                                                 have a suitable object suffix appended
2635
#                       --GeneratedProg(xxx)    - xxx is a generated program file
2636
#                                                 It will be placed in the BINDIR
2637
#                       --Prerequisite(xxx)     - xxx is a prerequisite file
2638
#                                                 The full name of the file will be located
2639
#                                                 and used within the command. The file will
2640
#                                                 be added to the list of recipe prerequisites
2641
#                       --GeneratedDirectory(xxx)
2642
#                       --GeneratedCommonDirectory(xxx)
2643
#                       --GeneratedObjectDirectory(xxx)
2644
#                       --GeneratedProgDirectory(xxx)
6177 dpurdie 2645
#                                               - xxx is a generated file
2646
#                                                 The containing directory will be placed on the command line
227 dpurdie 2647
#                       --PackageBase(xxx)      - xxx is a package. The keyword will be replaced
2648
#                                                 with the pathname to the package. If the package
2649
#                                                 has been copied in the the interface directory
2650
#                                                 then the interface directory will be used.
2651
#                       --PackageInfo(xxx,--opt)- xxx is a package. The keyword will be replaced
2652
#                                                 with the information requested.
2653
#                                                 Options are:
2654
#                                                   --path
2655
#                                                   --version
2656
#                                                   --fullversion
2657
#                                                   --project
2658
#
2659
#                       Where "xxx" may be of the form:
2660
#                           name,option[,option]
2661
#
2662
#                       Flag options are:
2663
#                           --file             - The file part of the full name
2664
#                           --dir              - The directory part of the full name
2665
#                           --abspath          - Abs path
2666
#                           --absdrive         - Abs path with drive letter
2667
#
2668
#                       --Var(Name,opt)         - Name is the name of a recognised varable
2669
#                                                 Refer to ExpandGenVar function for details
2670
#                                                 of Name and available options
2671
#                                                 The expanded text will be replaced with an
2672
#                                                 suitable makefile variables that will be
2673
#                                                 replaced at run-time.
6504 dpurdie 2674
#                                                 
2675
#                       --Tool(Name,opt)        - Name is the name of a 'tool' found withnin a package
2676
#                                                 The argument is replaced with the full path of the
2677
#                                                 tool. opt may be
2678
#                                                   --dir
2679
#                                                   --file
2680
#                                                   --abspath
2681
#                                                   --absdrive
227 dpurdie 2682
#
2683
#                   The keyword will be replaced with the resolved name. This may be a file,
2684
#                   a directory or other text.
2685
#
2686
#                   Options do not alter command line text. They do affect the way the command is
2687
#                   processed.
2688
#                   Options include:
2689
#                       --Prereq=name           - The name of a file to add as a prerequisite
2690
#                                                 The file does not form part of the command line
2691
#                       --Created=name          - The name of a file to treat as a generated file
2692
#                       --CreatedCommon=name      The file does not form part of the command line 
2693
#                       --CreatedObject=name
2694
#                       --CreatedProg=name
2695
#
2696
#                       --NoVarTag              - Modifes --Var operation to suppress tags
2697
#                       --NoWarn                - Don't warn if no prerequistes found
2698
#                       --NoGenerate            - Don't warn if no generated files are found
2699
#                                                 Will create a dummy rule name and the recipe will
2700
#                                                 always be executed during the 'GenerateFiles' phase
2701
#                       --UnknownPreq           - Prerequisites are not fully known.
2702
#                                                 Rebuild the target whenever it is required.
2703
#                       --AutoGenerate          - Examine the generated file to determine when the
2704
#                                                 tools is to be run.
261 dpurdie 2705
#                                                 Must be before any options that declare
2706
#                                                 creation of files.
227 dpurdie 2707
#                       --Text=<text>           - Display text for command
2708
#
263 dpurdie 2709
#                       --Clean[=arg]           - Call script with arg[-clean] for cleaning.
2710
#                       --PreDelete             - Delete generated files before running the command
6415 dpurdie 2711
#                       --RecipeTag=Name        - Name the recipe
2712
#                                                 Allows recipe to be called by Name and clean_Name
6898 dpurdie 2713
#                                                 
2714
#                       --UtfFormat=name        - Flags the program as a 'test' to be run in the Test Phase
6906 dpurdie 2715
#                                                 Intended to support things like Gradle that run tests in there own world
6898 dpurdie 2716
#                                                 Enables support for (Must occur first)
2717
#                           --AutoUtf           - Non interactive unit test
2718
#                           --NoAutoUtf         - Interactive unit Test
2719
#                           --UtfArg=nnn        - Argument passed into the UTF formatter
2720
#                           --UtfDir=path       - SUbdir in which the Unit Tests will be run    
2721
#                       
227 dpurdie 2722
#
2723
#               Eg: GenerateFiles ( '*', "--Tool=mod_if.pl",
2724
#                                        "-src --Prerequisite(udh_module.cfg)",
2725
#                                        "-direct -hdr --Generated(udp.h) -quiet" );
2726
#
2727
my $NoGenIndex = 0;
6415 dpurdie 2728
my %recipeTags;
227 dpurdie 2729
sub GenerateFiles
2730
{
6415 dpurdie 2731
    #
2732
    #   Remove undfined arguments
2733
    #   Simplifies programatic construction of argument lists
2734
    #
2735
    my ( $platforms, $tool, @args) = grep defined, @_;
227 dpurdie 2736
 
2737
    return if ( ! ActivePlatform($platforms) );
2738
 
6504 dpurdie 2739
    Debug( "GenerateFiles:($platforms, $tool, @args)" );
227 dpurdie 2740
 
2741
    my @preq_files;
2742
    my $preq_unknown;
2743
    my @gen_files;
2744
    my $shell_script;
2745
    my $shell_cmds;
2746
    my @tool_args;
2747
    my $no_warn;
2748
    my $clean_tag;
2749
    my $text;
2750
    my $gtype = 1;
303 dpurdie 2751
    my @has_source;
227 dpurdie 2752
    my @var_opts;
261 dpurdie 2753
    my @genreq_seen;
263 dpurdie 2754
    my $predelete;
6415 dpurdie 2755
    my $recipeTag;
6898 dpurdie 2756
    my $utfAuto;
2757
    my $utfFormat;
2758
    my $utfDir;
2759
    my @utfArgs;
2760
    my $isaUtf;
2761
    my $noGenerate;
227 dpurdie 2762
 
2763
    #
2764
    #   Process the first argument - this describes the program that will be used
2765
    #   to generate the files. It may be:
2766
    #       --Tool          - A Jats Tool or Plugin
2767
    #       --Script        - A shell script file
2768
    #       --Shell         - Raw shell commands
2769
    #       --Prog          - A program created within the Makefile
2770
    #
2771
    #
2772
    if ( $tool =~ /^--Tool=(.*)/ || $tool =~ /^([^-].*)/)
2773
    {
2774
        $tool = $1;
2775
        my $tool_no_prereq = 0;
2776
 
2777
        #
2778
        #   Process the Tool name and determine the location of the tool
2779
        #   Support --Tool=name and "name"
2780
        #   Locate the tool one of the many well known locations
2781
        #       1) Tool paths from Package Archives
2782
        #       2) JATS tool and binaries
2783
        #       3) User PATH (!YUK)
2784
        #
2785
 
2786
        #
2787
        #   Create a list of known extensions to scan
2788
        #   Basically present so that we can use .exe files without the .exe name
2789
        #
2790
        my @extension_list;
2791
        push @extension_list, '.exe' if ( $::ScmHost ne "Unix" );
2792
        push @extension_list, '.pl', '.sh', '.ksh', '';
2793
        TOOL_SEARCH:
2794
        {
2795
            #
2796
            #   Locate tool with package
2797
            #
2798
            if ( my $fname = ToolExtensionProgram( $tool, @extension_list ))
2799
            {
2800
                $tool = $fname;
2801
                last TOOL_SEARCH;
2802
            }
2803
 
2804
            #
2805
            #   Search the JATS tools and Bin directory
2806
            #   Retain the symbolic name of the JATS directory
2807
            #
2808
            for my $ext ( @extension_list )
2809
            {
2810
                foreach my $jdir ( qw( / /DEPLOY/ /LOCAL/ ) )
2811
                {
2812
                    if ( -f "$::GBE_TOOLS$jdir$tool$ext" )
2813
                    {
2814
                        $tool = "\$(GBE_TOOLS)$jdir$tool$ext";
2815
                        last TOOL_SEARCH;
2816
                    }
2817
                }
2818
 
2819
                if ( -f "$::GBE_BIN/$tool$ext" )
2820
                {
2821
                    $tool = "\$(GBE_BIN)/$tool$ext";
2822
                    last TOOL_SEARCH;
2823
                }
2824
            }
2825
 
2826
            #
2827
            #   Has the user provided an absolute PATH
2828
            #   This is not good, but for testing we can use it
2829
            #
2830
            if ( $tool =~ m~^/~ || $tool =~ m~^.:~ )
2831
            {
2832
                Warning("Absolute path program specified. Uncontrolled tool: $tool");
2833
                for my $ext ( @extension_list )
2834
                {
2835
                    if ( -f "$tool$ext" )
2836
                    {
2837
                        $tool = "$tool$ext";
2838
                        last TOOL_SEARCH;
2839
                    }
2840
                }
2841
            }
2842
 
2843
            #
2844
            #   May have a relative path to a local tool
2845
            #
2846
            if ( -f $tool )
2847
            {
2848
                UniquePush (\@preq_files, $tool);
2849
                last TOOL_SEARCH;
2850
            }
2851
 
2852
            #
2853
            #   Search the users PATH
2854
            #   Generate a warning if the program is found. These programs are
2855
            #   not nice as they are not really controlled.
2856
            #
2857
            for my $dir (split( $::ScmPathSep, $ENV{'PATH'} ) )
2858
            {
2859
                for my $ext ( @extension_list )
2860
                {
2861
                    if ( -f "$dir/$tool$ext" )
2862
                    {
2863
                        Warning("External program found in the user's PATH. Uncontrolled tool: $tool");
2864
                        $tool = "$dir/$tool$ext";
2865
 
2866
                        #
2867
                        #   Do not make the program a pre-requisite if we are running
2868
                        #   under Windows. This avoids two problems:
2869
                        #       1) May have spaces in pathname
2870
                        #       2) May have driver letter in pathname
2871
                        #
2872
                        $tool_no_prereq = 1 if ( $::ScmHost eq "WIN" );
2873
                        last TOOL_SEARCH;
2874
                    }
2875
                }
2876
            }
2877
 
2878
            #
2879
            #   Specified progrom not found
2880
            #   Generate a warning and use the raw name
2881
            #
2882
            Warning("Tool not found: $tool");
2883
            $tool_no_prereq = 1;
2884
        }
2885
        UniquePush (\@preq_files, $tool) unless ($tool_no_prereq);
2886
 
2887
    } elsif ( $tool =~ /^--Script=(.*)/ ) {
2888
 
2889
        #
2890
        #   Locate the script in a known source directory and make
2891
        #   the script a prerequisite of the target files, since the
2892
        #   script may be generated.
2893
        #
2894
        $tool = MakeSrcResolve ( $1 );
2895
        UniquePush (\@preq_files, $tool);
2896
 
2897
    } elsif ( $tool =~ /^--Shell$/ ) {
2898
        #
2899
        #   The user has provided a shell script within the command body
2900
        #   This will be executed directly by a shell
2901
        #   directores will need to use a "/" separator
2902
        #
2903
        $tool = "InternalShell";
2904
        $shell_script = 1;
2905
        $shell_cmds = 1;
2906
 
2907
 
2908
    } elsif ( $tool =~ /^--Prog=(.*)$/ ) {
2909
        #
2910
        #   Using a program that has been created within this script
2911
        #
2912
        my $prog = $1;
289 dpurdie 2913
        if ( my $pProg = $PROGS->Get($prog) )
227 dpurdie 2914
        {
289 dpurdie 2915
            $tool = $pProg->getPath()
227 dpurdie 2916
                unless ( $tool = $SRCS{$prog} );
2917
        UniquePush (\@preq_files, $tool);
2918
        }
2919
        else
2920
        {
2921
            Error ("Unknown program: $prog");
2922
        }
2923
 
2924
    } else {
2925
 
2926
        #
2927
        #   Currently generate a warning and then use the raw tool name
2928
        #
2929
        Error ("Unknown TOOL syntax: $tool");
2930
    }
2931
 
2932
    #
2933
    #   May need to quote the path
2934
    #   If the toolpath contains spaces then ugliness can occur - so quote the program
2935
    #
2936
    $tool = '"' . $tool . '"'
2937
        if ( (! $shell_script ) && $tool =~ m~\s~ );
2938
 
2939
    #
2940
    #   Determine special startup for various programs
2941
    #       Perl  - use known implemenatation
2942
    #       Shell - use known implemenatation
2943
    #       Otherwise - simply run it
2944
    #
2945
    #   Windows: Shell and Perl don't need '\' in paths
2946
    #
2947
    if ( $tool =~ /\.pl$/ )
2948
    {
2949
        $tool = "\$(GBE_PERL) $tool";
2950
        $shell_script = 1;
2951
    }
2952
    elsif ( $tool =~ /\.k?sh$/ )
2953
    {
2954
        $tool = "\$(GBE_BIN)/sh $tool";
2955
        $shell_script = 1;
2956
    }
2957
    Debug( "GenerateFiles: Tool: $tool" );
2958
 
2959
 
2960
    #
2961
    #   Process the remaining arguments
2962
    #   These will be command line arguments or options/flags
2963
    #   Command line arguments are concatenated together
2964
    #
2965
    for my $arg (@args)
2966
    {
263 dpurdie 2967
        if ( $arg =~ /^--PreDelete$/ )
2968
        {
2969
            #
2970
            #   Delete generated files before running the generation process
2971
            #   Some programs refuse to overwrite existing files
2972
            #
2973
            $predelete = 1;
2974
            next;
6898 dpurdie 2975
 
2976
        } elsif ( $arg =~ /^--NoVarTag$/ ) {
227 dpurdie 2977
            #
2978
            #   Modify the operation of --Var to supress the tags
6387 dpurdie 2979
            #   Should be used early as will only affect following --Var usage
227 dpurdie 2980
            #
2981
            push @var_opts, "--notag";
2982
            next;
2983
 
6898 dpurdie 2984
        } elsif ( $arg =~ /^--NoWarn$/ ) {
227 dpurdie 2985
            #
2986
            #   Supress warnings - No prequisites found
2987
            #   This is acceptable, but normally a tool should take an input
2988
            #   and create some output from it.
2989
            #
2990
            $no_warn = 1;
2991
            next;
2992
 
6898 dpurdie 2993
        } elsif ( $arg =~ /^--NoGenerate$/ ) {
227 dpurdie 2994
            #
2995
            #   Tool does generate a definable output
6898 dpurdie 2996
            #       Should only be used internally
227 dpurdie 2997
            #
6898 dpurdie 2998
            $noGenerate = 1;
227 dpurdie 2999
            next;
3000
 
6898 dpurdie 3001
        } elsif ( $arg =~ /^--UnknownPreq/ ) {
227 dpurdie 3002
            #
3003
            #   Indicate that the prequisites are not known, or too complex to
3004
            #   describe. ie: All files in a directory. May be used by packaging
3005
            #   tools.
3006
            #   The recipe will be run EVERY time we want to use the target.
3007
            #
3008
            $preq_unknown = 1;
3009
            $no_warn = 1;
3010
            next;
3011
 
6898 dpurdie 3012
        } elsif ( $arg =~ /^--AutoGenerate/ ) {
227 dpurdie 3013
            #
3014
            #   Determine when to run the tool based on the types of files that
3015
            #   are generated. Existance of a source file will force the tool
3016
            #   to be run during the 'generate' phase, othewise the tool will be run
3017
            #   when the generated components are required.
3018
            #
3019
            $gtype = 2;
261 dpurdie 3020
            Warning ("AutoGenerate MUST occur before options that declare generation of files",
3021
                     "Have seen:", @genreq_seen)
3022
                if (@genreq_seen);
227 dpurdie 3023
            next;
6898 dpurdie 3024
 
3025
        } elsif ( $arg =~ /^--Prereq=(.*)/ ) {
227 dpurdie 3026
            #
3027
            #   Specify a prerequisite file, that is not a part of the command line
3028
            #   Simply add the files to the list of preq files
3029
            #
3030
            my $fn = LocatePreReq ($1);
3031
            UniquePush ( \@preq_files, $fn );
3032
            Debug( "GenerateFiles: ExtraPrereq: $fn" );
3033
            next;
3034
 
6898 dpurdie 3035
        } elsif ( $arg =~ /^--Created(.*)=(.*)/ ) {
227 dpurdie 3036
            #
3037
            #   Specify a generated file, that is not a part of the command line
3038
            #   Add the files to the list of generated files
3039
            #
3040
            my $type = $1;
3041
            my $fn = $2;
3042
 
343 dpurdie 3043
            #
3044
            #   Append object suffix to CreatedObject
3045
            #
227 dpurdie 3046
            $fn .= '.' . $::o
3047
                if ( $type =~ m/Object/ );
3048
 
343 dpurdie 3049
            #
3050
            #   If the files is 'created' in a subdir, then add the dir
3051
            #   as a prerequisite.
3052
            #
3053
            if ( $type =~ m/Prog/ ) {
3054
                $fn = "\$(BINDIR)/$fn";
3055
                UniquePush (\@preq_files, '$(GBE_BINDIR)');
3056
 
3057
            } elsif ( $type !~ m/Common/ ) {
3058
                $fn = "\$(OBJDIR)/$fn";
3059
                UniquePush (\@preq_files, '$(GBE_OBJDIR)');
3060
            }
227 dpurdie 3061
 
3062
            #
3063
            #   Examine the file and see if it needs to be compiled
3064
            #   Add to the list of source files
3065
            #
261 dpurdie 3066
            push @genreq_seen, $arg;
303 dpurdie 3067
            if ( UniquePush (\@gen_files, $fn) )
3068
            {
3069
                if ( GenerateSrcFile ( $gtype, $fn  ) && $gtype == 2 )
3070
                {
3071
                    push @has_source, $fn;
3072
                }
3073
            }
227 dpurdie 3074
            Debug( "GenerateFiles: ExtraCreated: $fn" );
3075
            next;
3076
 
6898 dpurdie 3077
        } elsif ( $arg =~ /^--Clean($|=(.*))/ ) {
227 dpurdie 3078
            #
3079
            #   Detect Clean option
3080
            #
3081
            $clean_tag = $2 ? $2 : '-clean';
3082
 
3083
            #
3084
            #   Shell command with a --Clean will only
3085
            #   be run during a clean phase. They should not have any prereq
3086
            #   and should not generate any files, so simplify the interface.
3087
            #
3088
            push @args, '--NoWarn', '--NoGenerate'
3089
                if ( $shell_cmds );
3090
            next;
3091
 
6898 dpurdie 3092
        } elsif ( $arg =~ /^--Text=(.*)/ ) {
227 dpurdie 3093
            #
3094
            #   Display this text when executing commands
3095
            #
3096
            $text = $1;
3097
            next;
3098
 
6898 dpurdie 3099
        } elsif ( $arg =~ /^--RecipeTag=(.*)/ ) {
6415 dpurdie 3100
            #
3101
            #   Tag the generated Recipe
3102
            #   Only use the last tag - allow users to overwrite system tags
3103
            #
3104
            $recipeTag = $1;
3105
            Error ("Duplicate RecipeTag - $recipeTag") if ($recipeTags{$recipeTag}++ > 1);
3106
            next;
6898 dpurdie 3107
 
3108
        } elsif ( $arg =~ m/^--AutoUtf$/i) {
3109
            $utfAuto = 1;
3110
            $isaUtf = 1;
3111
            next;
3112
 
3113
        } elsif ( $arg =~ m/^--NoAutoUtf$/i ) {
3114
            $utfAuto = 0;
3115
            $isaUtf = 1;
3116
            next;
3117
 
3118
        } elsif ( $arg =~ m/^--UtfFormat=(.*)/i) {
3119
            $utfFormat = $1;
3120
            $isaUtf = 1;
3121
            next;
3122
 
3123
        } elsif ( $arg =~ m/^--UtfDir=(.*)/i) {
3124
            $utfDir = $1;
3125
            $isaUtf = 1;
3126
            next;
3127
 
3128
        } elsif ( $arg =~ m/^--UtfArg=(.*)/i) {
3129
            push @utfArgs, $1;
3130
            $isaUtf = 1;
3131
            next;
6415 dpurdie 3132
        }
3133
 
6898 dpurdie 3134
 
227 dpurdie 3135
        #   Not an option. Must be an argument to the tool/program
3136
        #   Process the tool arguments and extract file information
3137
        #   Extract all fields of the form:
3138
        #           --xxxxx(yyyyyy[,zzzzz])
3139
        #           --xxxxx{yyyyyyy}
3140
        #           --xxxxx[yyyyyyy] to allow embedded brackets
3141
        #
3142
        while ( $arg =~ m/--(\w+)               # --CommandWord         $1
3143
                                (               # Just for grouping
3144
                                \((.*?)\)   |   # Stuff like (yyyyy)    $3
3145
                                {(.*?)}     |   # or    like {yyyyy}    $4
3146
                                \[(.*?)\]       # or    like [yyyyy]    $5
3147
                                )/x )           # Allow comments and whitespace
3148
        {
3149
            my $cmd = $1;                       # The command
3150
            my $ufn = $3 || $4 || $5;           # User filename + options
3151
            my $mb = $-[0];                     # Match begin offset
3152
            my $me = $+[0];                     # Match end
3153
            my $flags = '';                     # Optional flags ( --dir or --file )
3154
            my $raw_arg = $ufn;                 # Raw arguments
6387 dpurdie 3155
            my $all = substr( $arg, $mb, $me - $mb ); # All of match. Avoid use of $&
343 dpurdie 3156
            my $is_path = 1;
285 dpurdie 3157
 
227 dpurdie 3158
 
3159
            Error ("GenerateFiles. Empty element not allowed: $all")
3160
                unless ( defined($ufn) );
3161
 
3162
            $ufn =~ s/\s+$//;
3163
            $ufn =~ s/^\s+//;
3164
            $ufn =~ s~//~/~g;                   # Remove multiple /
3165
            if ( $ufn =~ m/(.*?),(.*)/ )        # Extract out any flags
3166
            {
3167
                $ufn = $1;
3168
                $flags = $2;
3169
            }
3170
 
3171
            my $fn = $ufn ;                     # Replacement filename
343 dpurdie 3172
            my $fnp = '';                       # Prefix to $fn
227 dpurdie 3173
            Error ("GenerateFiles. Empty element not allowed: $all" )
3174
                if ( length ($ufn) <= 0 );
3175
 
3176
            #
3177
            #   Process found user command
3178
            #
3179
            if ( $cmd =~ /^Generated/ )
3180
            {
3181
                my $use_dir = "";
343 dpurdie 3182
 
227 dpurdie 3183
                #
3184
                #   Generated filename
3185
                #       Determine the target directory
3186
                #       Determine the full name of the file.
3187
                #       Flag the file as generated
3188
                #
3189
                if ( $cmd =~ /Prog/ )
3190
                {
3191
                    #
3192
                    #   Generated Prog are generated in the BIN directory
3193
                    #   Ensure the directory exists by using its symbolic name
3194
                    #   as a prerequisite.
3195
                    #
343 dpurdie 3196
                    $use_dir = '$(BINDIR)';
3197
                    UniquePush (\@preq_files, '$(GBE_BINDIR)');
227 dpurdie 3198
                }
3199
                elsif ( $cmd !~ /Common/ )
3200
                {
3201
                    #
3202
                    #   Files that are not Common are generated in the
3203
                    #   object directory. This directory must exist, so it
3204
                    #   symbolic name GBE_OBJDIR is made a prerequisite too.
3205
                    #
3206
                    #   If the file is a header file, then add the directory
3207
                    #   to the include search path too.
3208
                    #
343 dpurdie 3209
                    $use_dir = '$(OBJDIR)';
3210
                    UniquePush (\@preq_files, '$(GBE_OBJDIR)');
3211
                    AddIncDir( $platforms , '$(OBJDIR)', '--NoWarn' )
227 dpurdie 3212
                        if ( $ScmSourceTypes{ StripFile($fn) } && $ScmSourceTypes{ StripFile($fn) } eq ".h" );
3213
                }
3214
 
3215
 
3216
                #
3217
                #   Append a toolset specfic object file name suffix
3218
                #   for Object files only
3219
                #
3220
                $fn .= ".$::o"
3221
                    if ( $cmd =~ /Object/ );
3222
 
3223
                #
3224
                #   Merge directory and filename parts
3225
                #
3226
                $fn = $use_dir . ( $use_dir ? "/" : ""  ) . $fn;
3227
 
3228
                #
3229
                #   Save for later user
3230
                #   Flag the file as a generated file
3231
                #
261 dpurdie 3232
                push @genreq_seen, $cmd;
303 dpurdie 3233
                if ( UniquePush (\@gen_files, $fn) )
3234
                {
5878 dpurdie 3235
                    if ($SRCS{ StripDir( $fn ) })
303 dpurdie 3236
                    {
5878 dpurdie 3237
                        abtWarning(1,"GenerateFiles. Generated File also a Src file: $fn");
303 dpurdie 3238
                    }
5878 dpurdie 3239
                    elsif ( GenerateSrcFile ( $gtype, $fn  ) )
3240
                    {
3241
                        push ( @has_source, $fn ) if ($gtype == 2);
3242
                    }
303 dpurdie 3243
                }
227 dpurdie 3244
 
3245
                #
3246
                #   Use the directory or the full name
3247
                #   If using the directory then ensure that we have a name
3248
                #   even if its "."
3249
                #
3250
                $fn = ($use_dir) ? "$use_dir" : "."
3251
                    if ( $cmd =~ /Directory/ );
3252
 
3253
                Debug( "GenerateFiles: Generate: $fn" );
3254
 
3255
            }
3256
            elsif ( $cmd =~ /^Prereq/ )
3257
            {
3258
                #
3259
                #   Prerequisite filename
3260
                #       Resolve the full name of the file. It may be known
3261
                #       as a source file (possibly generated) or it may be
3262
                #       located in a known source directory
3263
                #
3264
                $fn = LocatePreReq ($ufn);
3265
                UniquePush (\@preq_files, $fn);
3266
 
3267
                Debug( "GenerateFiles: Prereq: $fn" );
3268
 
3269
            }
3270
            elsif ( $cmd =~ /^PackageBase/ )
3271
            {
3272
                $fn = GetPackageBase( "GenerateFiles", $raw_arg );
3273
                UniquePush (\@preq_files, $fn);
3274
            }
3275
            elsif ( $cmd =~ /^PackageInfo/ )
3276
            {
3277
                $fn = GetPackageInfo( "GenerateFiles", $raw_arg );
3278
            }
3279
            elsif ( $cmd =~ /^Var/ )
3280
            {
6504 dpurdie 3281
                # --Var(...)
343 dpurdie 3282
                ($fnp, $fn, $is_path) = ExpandGenVar( "GenerateFiles", $raw_arg, @var_opts );
227 dpurdie 3283
                $flags = '';
343 dpurdie 3284
                if ( $raw_arg eq 'ObjDir' ) {
3285
                    UniquePush (\@preq_files, '$(GBE_OBJDIR)');
3286
                } elsif ( $raw_arg eq 'BinDir' ) {
3287
                    UniquePush (\@preq_files, '$(GBE_BINDIR)');
3288
                } elsif ( $raw_arg eq 'LibDir' ) {
3289
                    UniquePush (\@preq_files, '$(GBE_LIBDIR)');
3290
                }
227 dpurdie 3291
            }
6504 dpurdie 3292
            elsif ( $cmd =~ /^Tool/ ) {
3293
                # --Tool(toolName)
3294
                ($fn, $is_path) = ExpandTool( "GenerateFiles", $raw_arg );
3295
            }
227 dpurdie 3296
            else
3297
            {
3298
                Warning ("GenerateFiles: Unknown replacement command: $cmd");
3299
                $fn = $ufn;
3300
            }
3301
 
3302
            #
3303
            #   Process path modification flags
3304
            #
3305
            $fn = ProcessPathName( $fn, $flags );
3306
 
3307
            #
3308
            #   Minor kludge under windows. Ensure directores have a "\" sep
3309
            #   Unless the user has specified a straight shell command
3310
            #
5986 dpurdie 3311
            $fn = "\$(subst /,\$(dirsep),$fn)"
343 dpurdie 3312
                if ( $is_path && $::ScmHost eq "WIN" && ! defined($shell_script) );
227 dpurdie 3313
 
3314
            #
343 dpurdie 3315
            #   Prepend any $fn Prefix
3316
            #   This will be a tag and is not subject to path processing
3317
            #
3318
            $fn = $fnp . $fn;
3319
 
3320
            #
227 dpurdie 3321
            #   Replace the found string with the real name of the file
3322
            #   Note: 4 argument version of substr is not always available
3323
            #         so we must do it the hard way
3324
            #               substr( $arg, $mb, $me - $mb, $fn);
3325
            #
3326
            $arg = substr( $arg, 0, $mb ) . $fn . substr( $arg, $me );
3327
 
3328
            Debug2( "GenerateFiles: subs: $all -> $fn" );
3329
        }
3330
 
3331
        #
3332
        #   Save the tool arguments in an array
3333
        #
3334
        push @tool_args, $arg;
3335
    }
3336
 
3337
    #
5867 dpurdie 3338
    #   Sanity test. Ensure that some file have been marked as generated
227 dpurdie 3339
    #                Warn if no prerequisites found
3340
    #
303 dpurdie 3341
    Warning( "GenerateFiles. --AutoGenerate option has no effect",
3342
             "The following files are 'source' files",  @has_source ) if ( @has_source );
6898 dpurdie 3343
    Warning( "No Prerequisite files found in $tool",@tool_args) unless ( $isaUtf || $no_warn || $#preq_files >= 0 );
227 dpurdie 3344
 
6423 dpurdie 3345
    #
6906 dpurdie 3346
    #   These would be nice tests - but break too much
3347
    #   
3348
    #    ReportError("Mixed use of --NoGenerate and generated files") if (@gen_files && $noGenerate);
3349
    #    ReportError  ( "No generated files found in $tool",@tool_args) unless ($isaUtf || $noGenerate || $#gen_files > 0);
3350
 
3351
    #
6898 dpurdie 3352
    #   Sanity test. If a UTF then we shouldn't generate files
3353
    #   
3354
    if ($isaUtf ) {
3355
        ReportError('In UTF mode generated files are not supported:', @gen_files) if @gen_files;
3356
    }
3357
 
3358
    #   Invocation does not generate and files
3359
    #       Need to create a dummy name for the rule
3360
    #       Use a base name and a number
3361
    #       
3362
    if ($noGenerate)
3363
    {
3364
        my $dummy_target = 'generate_files_' . $NoGenIndex;
3365
        UniquePush (\@gen_files, $dummy_target );
3366
        UniquePush (\@GENERATED, $dummy_target) unless $isaUtf;
3367
    }
3368
 
3369
    ErrorDoExit();
3370
 
3371
    #
6423 dpurdie 3372
    #   Determine the text to display while generating files
3373
    #   Will be either user-text or the first target file (default)
3374
    #   Suffix with RecipeTag, if provided
3375
    #   
3376
    my $txtSuffix = '';
3377
    $txtSuffix = "($recipeTag)" if defined $recipeTag;
3378
    $text = $gen_files[0] unless defined $text;
3379
    $text .= $txtSuffix;
227 dpurdie 3380
 
3381
    #
3382
    #   Save information
3383
    #   Will be used to create makefile statements later
3384
    #
3385
    my %gen_data;
3386
 
3387
    $gen_data{'index'}      = $NoGenIndex++;
6415 dpurdie 3388
    $gen_data{'recipeTag'}  = $recipeTag if defined $recipeTag;
227 dpurdie 3389
    $gen_data{'shell'}      = $shell_cmds;
3390
    $gen_data{'gen'}        = \@gen_files;
3391
    $gen_data{'preq'}       = \@preq_files;
3392
    $gen_data{'tool'}       = $tool;
3393
    $gen_data{'toolargs'}   = \@tool_args;
3394
    $gen_data{'clean'}      = $clean_tag;
6423 dpurdie 3395
    $gen_data{'text'}       = $text;
227 dpurdie 3396
    $gen_data{'preq_sus'}   = 1 if ( $preq_unknown );
263 dpurdie 3397
    $gen_data{'predelete'}  = 1 if ( $predelete );
227 dpurdie 3398
 
6898 dpurdie 3399
    if ($isaUtf)
3400
    {
3401
        $gen_data{'isautf'}     = 1;
3402
        $gen_data{'utfauto'}    = $utfAuto if ( $utfAuto );
3403
        $gen_data{'utfformat'}  = $utfFormat if ( $utfFormat );
3404
        $gen_data{'utfdir'}     = $utfDir if ( $utfDir );
3405
        $gen_data{'utfargs'}    = \@utfArgs;
3406
 
3407
        $TESTS_TO_RUN = 1;
3408
        $TESTS_TO_AUTORUN = 1 if ( $utfAuto );
3409
    }
3410
 
227 dpurdie 3411
    push(@GENERATE_FILES, \%gen_data);
6387 dpurdie 3412
#DebugDumpData("GenerateFiles", \%gen_data);
227 dpurdie 3413
    Debug2( "GenerateFiles: cmd: $tool @tool_args" );
3414
}
3415
 
3416
#-------------------------------------------------------------------------------
3417
# Function        : MakePerlModule
3418
#
3419
# Description     : Build Perl Module(s) using the Perl Build System
3420
#                   This is a thin wrapper around a specialised script
3421
#
3422
#                   The user can do the same job with correct use of
3423
#                   a GenerateFiles, but this is a lot tidier.
3424
#
3425
# Inputs          : $1      - platform specifier '*' (comma delemitered)
3426
#                   $*      - Paths to Perl Modules[,command options]
3427
#                             Options to the BuildPerl script
3428
#
3429
# Returns         :
3430
#
3431
sub MakePerlModule
3432
{
3433
    my ( $platforms, @args) = @_;
3434
 
3435
    return if ( ! ActivePlatform($platforms) );
3436
 
3437
    Debug2( "MakePerlModule:($platforms, @args)" );
3438
    my @opts;
3439
 
3440
    #
3441
    #   Extract options from paths to Perl Packages
3442
    #   Package names do not start with a '-'
3443
    #
3444
    foreach my $arg ( @args )
3445
    {
3446
        if ( $arg =~ /^-/ ) {
3447
            push @opts, $arg;
3448
 
3449
        } else {
3450
            #
3451
            #   Perl Package Directory Name
3452
            #   This may also contain embedded command to the Make command
3453
            #   These will be seperated with a comma
3454
            #       ie: module,-options=fred
3455
            #
3456
            my ($name,$options) = split( ',', $arg );
3457
            push @opts, "-PerlPackage=$arg";
3458
            push @opts, "--Prereq=$name/Makefile.PL";
3459
        }
3460
    }
3461
 
3462
    #
3463
    #   Invoke GenerateFiles with a bunch of additional arguments
3464
    #
3465
    GenerateFiles ($platforms, "--Tool=jats_buildperl.pl",
3466
                          '--Var(MachType)',                        # Build Machine type
3467
                          '--Var(PackageDir)',                      # Package dir
3468
                          '--NoGenerate',                           # Don't know the output
3469
                          '--Text=Make Perl Module',                # Pretty print
3470
                          '--NoWarn',
3471
                          '--Clean=-clean_build',                   # Jats clean support
3472
                          '--NoVarTag',                             # No more Tags
3473
                          @opts,
3474
                          );
3475
}
3476
 
3477
#-------------------------------------------------------------------------------
3478
# Function        : MakeLinuxDriver
3479
#
3480
# Description     : Build a Linux Device Driver using the Linux Device Driver
3481
#                   Build System
3482
#                   This is a thin wrapper around a specialised script
3483
#
3484
#                   The user can do the same job with correct use of
3485
#                   a GenerateFiles, but this is a lot tidier.
3486
#
3487
# Inputs          : $1      - platform specifier '*' (comma delemitered)
3488
#                   $2      - name of the driver. No extension
3489
#                   $*      - Driver sources
3490
#                             Options to the script
3491
#
3492
# Returns         :
3493
#
3494
sub MakeLinuxDriver
3495
{
3496
    my ( $platforms, $driver_name, @args) = @_;
3497
 
3498
    return if ( ! ActivePlatform($platforms) );
3499
 
285 dpurdie 3500
    Error ("No driver name specified") unless ( $driver_name );
227 dpurdie 3501
    Debug2( "MakeLinuxDriver:($platforms, $driver_name ,@args)" );
3502
    my @srcs;
3503
    my @opts;
3504
 
3505
    #
3506
    #   Extract options from source files
3507
    #   Package names do not start with a '-'
3508
    #
3509
    foreach my $arg ( @args )
3510
    {
3511
         if ( $arg =~ /^--Define=(.)/ ) {
3512
            push @opts, $arg;
5672 dpurdie 3513
 
3514
         } elsif ( $arg =~ /^--ExternalModule=(.)/ ) {
3515
               push @opts, $arg;
227 dpurdie 3516
 
3517
         } elsif ( $arg =~ /^-/ ) {
3518
            push @opts, $arg;
3519
            Warning ("MakeLinuxDriver: Unknown option: $arg. Passed to script");
3520
 
3521
        } else {
3522
            push @srcs, $arg;
3523
            push @opts, "--Prereq=$arg";
3524
        }
3525
    }
3526
 
3527
    #
3528
    #   Cleanup the drive name
3529
    #
3530
    $driver_name =~ s~\.ko$~~;
3531
 
3532
    #
3533
    #   Remove the specified sources from the list of object files
3534
    #   that will be build. This will ensure that some internal rules are
3535
    #   not generated.
3536
    #
3537
    foreach ( @srcs )
3538
    {
3539
        my $file = StripExt(StripDir( $_ ));
3540
        delete $OBJSOURCE{ $file };
3541
        @OBJS = grep(!/^$file$/, @OBJS);
3542
    }
3543
 
3544
    #
3545
    #   Invoke GenerateFiles with a bunch of additional arguments
3546
    #   At runtime the include directories will be added as
3547
    #   absolute paths
3548
    #
3549
    GenerateFiles ($platforms, "--Tool=jats_buildlinux.pl",
3550
                    "-Output=--GeneratedProg($driver_name.ko)",
3551
                    "-Driver=$driver_name",
3552
                    "-GccPath=\$(GCC_CC)",
3553
                    "-Arch=\$(HOST_CPU)",
3554
                    "-LeaveTmp=\$(LEAVETMP)",
3555
                    "-Verbose=\$(CC_PRE)",
3556
                    "-Type=\$(GBE_TYPE)",
3557
                    "-Platform=\$(GBE_PLATFORM)",
5672 dpurdie 3558
                    "--Var(LocalBinDir)",
227 dpurdie 3559
                    '$(patsubst %,-Incdir=%,$(INCDIRS))',
5672 dpurdie 3560
                    '--Clean',
227 dpurdie 3561
                    @opts,
3562
                    @srcs
3563
                    );
3564
}
3565
 
3566
#-------------------------------------------------------------------------------
3567
# Function        : GetPackageBase
3568
#
3569
# Description     : Helper routine
3570
#                   Given a package name, determine the base address of the
3571
#                   package
3572
#
3573
# Inputs          : $dname         - Directive name     (Reporting)
3574
#                   $name          - Required package
3575
#                                    Allows two forms:
3576
#                                       package_name
3577
#                                       package_name,ext
3578
#
3579
# Returns         : Path to the directory in which the files are installed
3580
#                   This may be the interface directory
3581
#
3582
sub GetPackageBase
3583
{
3584
    my ($dname, $fname) = @_;
3585
    my $pkg;
3586
    my ($name, $ext) = split(',', $fname);
3587
 
3588
    $pkg = GetPackageEntry( $name, $ext );
3589
    Error ("$dname: Package not found: $fname") unless ( $pkg );
3590
 
3591
    #
3592
    #   If a BuildPkgArchive then use the interface directory
3593
    #
3594
    return ( $pkg->{'TYPE'} eq 'link' ) ? $pkg->{'ROOT'} : '$(INTERFACEDIR)';
3595
}
3596
 
3597
#-------------------------------------------------------------------------------
3598
# Function        : GetPackageInfo
3599
#
3600
# Description     : Helper routine
3601
#                   Given a package name, return some information about the package
3602
#                   Only one information item is allowed with each call
3603
#
3604
# Inputs          : $dname         - Directive name     (Reporting)
3605
#                   $name          - Required package
3606
#                                    Allows two forms:
3607
#                                       package_name
3608
#                                       package_name,ext
3609
#                                    Selector
3610
#                                       --path
3611
#                                       --version
3612
#                                       --fullversion
3613
#                                       --project
3614
#
3615
# Returns         : Package information
3616
my %GetPackageInfo = qw(path ROOT
3617
                        version DVERSION
3618
                        fullversion VERSION
3619
                        project DPROJ);
3620
sub GetPackageInfo
3621
{
3622
    my ($dname, $args) = @_;
3623
    my $pkg;
3624
    my $name;
3625
    my $ext;
3626
    my $info;
3627
 
363 dpurdie 3628
    #
3629
    #   Split up the arguments
3630
    #       Options start with '--'
3631
    #   First non-option is the package name
3632
    #   2nd non-option is the packag extension
3633
    #
3634
    #   Only one option allowed
3635
    #       Convert it into a known package info item
3636
    #
3637
    #
227 dpurdie 3638
    foreach ( split(',', $args) )
3639
    {
3640
        if ( m/^--(.*)/ ) {
3641
            Error( "$dname: Too many info requests: $args") if ( $info );
3642
            $info = $GetPackageInfo{$1};
3643
            Error( "$dname: Unknown info type: $_") unless ($info);
363 dpurdie 3644
 
227 dpurdie 3645
        } elsif ( $ext ) {
3646
            Error("$dname: Too many names: $args");
363 dpurdie 3647
 
227 dpurdie 3648
        } elsif ( $name ) {
3649
            $ext = $_;
363 dpurdie 3650
 
227 dpurdie 3651
        } else {
3652
            $name = $_;
3653
        }
3654
    }
3655
 
3656
    $pkg = GetPackageEntry( $name, $ext );
3657
    Error ("$dname: Package not found: $args") unless ( $pkg );
3658
 
3659
    #
3660
    #   If a BuildPkgArchive then use the interface directory
363 dpurdie 3661
    #   Default data item - path to the package
227 dpurdie 3662
    #
363 dpurdie 3663
    $info = 'ROOT' unless ( $info );
3664
    if ( $info eq 'ROOT' &&  $pkg->{'TYPE'} ne 'link' )
227 dpurdie 3665
    {
3666
        return ( '$(INTERFACEDIR)');
3667
    }
363 dpurdie 3668
 
227 dpurdie 3669
    return ( $pkg->{$info} );
3670
}
3671
 
3672
#-------------------------------------------------------------------------------
3673
# Function        : GetPackageEntry
3674
#
3675
# Description     : Return the package class pointer given a package name
3676
#
3677
# Inputs          : $name          - Required package
3678
#                   $ext           - Option package extension
3679
#
3680
# Returns         : Class pointer
3681
#
3682
sub GetPackageEntry
3683
{
3684
    my ($name, $ext) = @_;
3685
    $ext = '' unless ( $ext );
3686
 
3687
    for my $entry (@{$::ScmBuildPkgRules{$ScmPlatform} })
3688
    {
3689
        next unless ( $entry->{'NAME'} eq $name );
3690
        next if ( $ext && $entry->{'DPROJ'} ne $ext );
3691
        return $entry;
3692
    }
285 dpurdie 3693
    return;
227 dpurdie 3694
}
3695
 
3696
#-------------------------------------------------------------------------------
3697
# Function        : ExpandGenVar
3698
#
3699
# Description     : Expand a known variable for the Generate Files option
3700
#
3701
# Inputs          : $dname         - Directive name     (Reporting)
3702
#                   $arg           - Raw argument
3703
#                                    This of the form of
3704
#                                       Tag[,--option]+
3705
#                                    Tags are specified in %ExpandGenVarConvert
3706
#
3707
#                                   Options are:
3708
#                                       --tag
3709
#                                       --notag
3710
#                                       --tag=<SomeTag>
3711
#                                       --absdrive
3712
#                                       --abspath
285 dpurdie 3713
#                                       --default=text
343 dpurdie 3714
#                                       --allownone
227 dpurdie 3715
#                                   Not all options are avalaible on all variables
3716
#                   @opts           - Options
3717
#                                       --notag     - Default is --notag
3718
#
343 dpurdie 3719
# Returns         : Tag             - Any tag component of the expansion
3720
#                   Path/Value      - Path/Value of the component
3721
#                   is_path         - Above is a path
3722
#                   is_abs          - Path is absolute
227 dpurdie 3723
#
3724
 
3725
#
3726
#   Create a Hash to simplify the process of converting Var names
343 dpurdie 3727
#   into makefile variables. There are two data items, separated by a comma.
3728
#       The first is the runtime expansion value
3729
#       The second describes the first:
3730
#           NotPresent  - Expansion is not a path
3731
#           '-'         - Expansion is a path and is relative to CWD
3732
#           '+'         - Expansion is a path and is absolute
227 dpurdie 3733
#
3734
my %ExpandGenVarConvert = (
3735
    'BuildName'         => '$(GBE_PBASE)',
3736
    'BuildVersion'      => '$(BUILDVER)',
3737
    'BuildVersionNum'   => '$(BUILDVERNUM)',
3738
 
3739
    'PackageDir'        => '$(PKGDIR),+',
3740
    'PackagePkgDir'     => '$(PKGDIR)/pkg/pkg.$(GBE_PLATFORM),+',
3741
    'PackageIncDir'     => '$(INCDIR_PKG),+',
6133 dpurdie 3742
    'PackageIncPlatDir' => '$(INCDIR_PKG)/$(GBE_PLATFORM),+',
227 dpurdie 3743
    'PackageLibDir'     => '$(LIBDIR_PKG)/$(GBE_PLATFORM),+',
3744
    'PackageBinDir'     => '$(BINDIR_PKG)/$(GBE_PLATFORM)$(GBE_TYPE),+',
3745
 
3746
    'PackageToolDir'    => '$(PKGDIR)/tools,+',
3747
    'PackageToolBin'    => '$(PKGDIR)/tools/bin/$(GBE_HOSTMACH),+',
3748
    'PackageToolScript' => '$(PKGDIR)/tools/scripts,+',
3749
 
3750
    'LibDir'            => '$(LIBDIR),+',
3751
    'BinDir'            => '$(BINDIR),+',
3752
    'ObjDir'            => '$(OBJDIR),+',
3753
 
3754
    'InterfaceDir'      => '$(INTERFACEDIR),+',
3755
    'InterfaceIncDir'   => '$(INCDIR_INTERFACE),+',
3756
    'InterfaceLibDir'   => '$(LIBDIR_INTERFACE)/$(GBE_PLATFORM),+',
3757
    'InterfaceBinDir'   => '$(BINDIR_INTERFACE)/$(GBE_PLATFORM)$(GBE_TYPE),+',
3758
 
3759
    'LocalDir'          => '$(LOCALDIR),+',
3760
    'LocalIncDir'       => '$(INCDIR_LOCAL),+',
3761
    'LocalLibDir'       => '$(LIBDIR_LOCAL)/$(GBE_PLATFORM),+',
3762
    'LocalBinDir'       => '$(BINDIR_LOCAL)/$(GBE_PLATFORM)$(GBE_TYPE),+',
3763
 
3764
    'Platform'          => '$(GBE_PLATFORM)',
3765
    'Product'           => '$(GBE_PRODUCT)',
3766
    'Target'            => '$(GBE_TARGET)',
3767
 
3768
    'Type'              => '$(GBE_TYPE)',
3769
    'Arch'              => '$(HOST_CPU)',
3770
    'Architecture'      => '$(HOST_CPU)',
3771
    'MachType'          => '$(GBE_HOSTMACH)',
3772
    'BuildRoot'         => '$(GBE_ROOT),+',
3773
 
3774
 
3775
    'Verbose'           => '$(CC_PRE)',
3776
    'LeaveTmp'          => '$(LEAVETMP)',
329 dpurdie 3777
    'Cwd'               => '$(CURDIR),-',
227 dpurdie 3778
 
6133 dpurdie 3779
    # Generated when used
227 dpurdie 3780
    'CompilerPath'      => '$(SCM_COMPILERPATH)',
3967 dpurdie 3781
    'PkgArch'           => '$(PACKAGE_ARCH)',
6133 dpurdie 3782
 
3783
    'Native'            => '0',
3784
    'Toolset'           => '0',
3785
 
227 dpurdie 3786
    );
3787
 
3788
sub ExpandGenVar
3789
{
3790
    my ($dname, $args, @uopts) = @_;
3791
    my $expansion;
3792
    my $prefix='';
3793
    my ($tag, @opts) = split('\s*,\s*', $args);
3794
    my $no_prefix;
285 dpurdie 3795
    my $default_value;
3796
    my $allow_none;
329 dpurdie 3797
    my $is_abs = 0;
227 dpurdie 3798
 
285 dpurdie 3799
    #
3800
    #   Parse options lists
3801
    #       Options provided by the caller
3802
    #       Options embedded in the argument
227 dpurdie 3803
    foreach ( @uopts )
3804
    {
3805
        if ( m/^--notag$/ ) {
3806
            $no_prefix = 1;
3807
        } else{
3808
            Error ("$dname: Unknown option: $_")
3809
        }
3810
    }
3811
 
285 dpurdie 3812
    foreach ( @opts )
3813
    {
3814
        if ( m/^--default=(.+)/i ) {
3815
            $default_value = $1;
3816
        } elsif ( m/^--allownone$/i ) {
3817
            $allow_none = 1;
3818
        }
3819
    }
3820
 
227 dpurdie 3821
    #
3822
    #   Perform run-time update on the %ExpandGenVarConvert
3823
    #   Most of it can be initialised at startup - but not all of it.
3824
    #
3825
    $ExpandGenVarConvert{CompilerPath} = undef unless $::ScmToolsetCompilerPath;
3826
    $ExpandGenVarConvert{Product}      = '$(GBE_PLATFORM)' unless $ScmProduct;
3827
 
6133 dpurdie 3828
    $ExpandGenVarConvert{Native}      = '1'  if isAnAlias ('NATIVE');
3829
    $ExpandGenVarConvert{Toolset}     = '1'  if isAnAlias ('TOOLSET');
3830
 
3831
 
227 dpurdie 3832
    #
3833
    #   Look up a hash of conversions
3834
    #   Could allow for a code ref, but not needed yet
3835
    #
3836
    Error ("$dname: Unknown expansion --Var($tag)")
3837
        unless ( exists $ExpandGenVarConvert{$tag} );
3838
 
285 dpurdie 3839
    #
3840
    #   Handle undefined expansions
3841
    #   Only 'CompilerPath', but it can be a pain in user land
3842
    #
3843
    $expansion = $ExpandGenVarConvert{$tag};
3844
    unless ( defined $expansion  )
3845
    {
6798 dpurdie 3846
        return '','',0,0 if ( $allow_none );
285 dpurdie 3847
        $expansion = $default_value;
3848
        Error ("$dname: Expansion --Var($tag) not be supported by toolset: $ScmToolset")
3849
            unless ( $expansion );
3850
    }
227 dpurdie 3851
 
285 dpurdie 3852
 
227 dpurdie 3853
    ($expansion,my $is_path) = split (',', $expansion );
329 dpurdie 3854
    $is_abs = 1
3855
        if ($is_path && $is_path eq '-' );
227 dpurdie 3856
 
3857
    #
3858
    #   Process options
3859
    #   Assume that a tag will be provided
3860
    #
3861
    $prefix =  $no_prefix ? '' : "-$tag=";
3862
    foreach my $opt ( @opts )
3863
    {
3864
        if ( $opt =~ /^--tag=(.*)/i ) {
3865
            $prefix = "$1=";
3866
 
3867
        } elsif ( $opt =~ m/^--tag$/i ) {
3868
            $prefix = "-$tag=";
3869
 
3870
        } elsif ( $opt =~ m/^--notag/i ) {
3871
            $prefix = '';
3872
 
329 dpurdie 3873
        } elsif ( $is_path && !$is_abs && $opt =~ /--abspath|--absdrive/i ) {
227 dpurdie 3874
            $expansion = '$(CURDIR)/' . $expansion;
329 dpurdie 3875
            $is_abs = 1;
227 dpurdie 3876
 
285 dpurdie 3877
        } elsif ( $opt =~ m/^--default=(.+)/i ) {
3878
            # Already processed
3879
        } elsif ( $opt =~ m/^--allownone$/i ) {
3880
            # Already processed
227 dpurdie 3881
        } else {
3882
            Error ("$dname: Unsupported option($opt) for --Var(@_)");
3883
        }
3884
    }
3885
 
3886
    Debug ("ExpandGenVar: args $args --> $prefix$expansion");
343 dpurdie 3887
    return $prefix , $expansion, $is_path ? 1 : 0, $is_abs;
227 dpurdie 3888
 
3889
}
3890
 
3891
#-------------------------------------------------------------------------------
6504 dpurdie 3892
# Function        : ExpandTool
3893
#
3894
# Description     : Locate a 'tool' and provide the complete path
3895
#
3896
# Inputs          : $dname         - Directive name     (Reporting)
3897
#                   $arg           - Name of the tool to locate (no extension) with 
3898
#                                    embedded options. Options are:
3899
#                                       --dir
3900
#                                       --file
3901
#                                       --abspath
3902
#                                       --absdrive
3903
#
3904
#                                    
3905
# Returns         : Path/Value      - Path/Value of the component
3906
#                   is_path         - Above is a path
3907
#                   is_abs          - Path is absolute
3908
#
3909
 
3910
sub ExpandTool
3911
{
3912
    my ($dname, $args) = @_;
3913
    my ($toolName, @opts) = split('\s*,\s*', $args);
3914
    my $is_abs = 1;
3915
    my $is_path = 1;
3916
 
3917
    #
3918
    #   Locate the tool in one of the dependent packages
3919
    #
3920
    my @extension_list; 
3921
    push @extension_list, '.exe' if ( $::ScmHost ne "Unix" );
3922
    my $toolFullPath =  ToolExtensionProgram( $toolName, @extension_list );
3923
    if ($toolFullPath) {
3924
        $toolName = $toolFullPath;
3925
    } else {
3926
            Warning("$dname. Tool not found: $toolName", "Searched:", ToolExtensionPaths());
3927
    }
3928
 
3929
    #
3930
    #   Process options
3931
    #
3932
    foreach my $opt ( @opts )
3933
    {
3934
        if ( $opt =~ m/^--dir/i ) {
3935
            $toolName = StripFileExt($toolName);
3936
 
3937
        } elsif ( $opt =~ m/^--file/i ) {
3938
            $toolName = StripDir($toolName);
3939
            $is_abs = 0;
3940
            $is_path = 0;
3941
 
3942
        } elsif ( $opt =~ m/^--abspath/i ) {
3943
            $toolName = AbsPath($toolName);
3944
 
3945
        } elsif ( $opt =~ m/^--absdrive/i ) {
3946
            $toolName = FullPath($toolName);
3947
 
3948
        } else {
3949
            Error ("$dname: Unsupported option($opt) for --Tool(@_)");
3950
        }
3951
    }
3952
 
3953
    Debug ("ExpandTool: $args --> $toolName");
3954
    return $toolName, $is_path ? 1 : 0, $is_abs;
3955
}
3956
 
3957
#-------------------------------------------------------------------------------
6133 dpurdie 3958
# Function        : isAnAlias 
3959
#
3960
# Description     : Internal Helper
3961
#                   Determine if this platform is an alias for ...
3962
#
3963
# Inputs          :  $target    - Test against this target
3964
#
3965
# Returns         :  True - Is an alais for $target.
3966
#
3967
sub isAnAlias
3968
{
3969
    my ($target) = @_;
3970
    if (exists ($::BUILDINFO{$ScmPlatform}{'USERALIAS'}) )
3971
    {
3972
        if ( grep /^$target$/, @{$::BUILDINFO{$ScmPlatform}{'USERALIAS'}} )
3973
        {
3974
                return 1;    
3975
        }
3976
 
3977
    }
3978
    if (exists ($::BUILDINFO{$ScmPlatform}{'ALIAS'}) )
3979
    {
3980
        if ( $target eq $::BUILDINFO{$ScmPlatform}{'ALIAS'} )
3981
        {
3982
                return 1;    
3983
        }
3984
    }
3985
 
3986
    return 0;
3987
}
3988
 
3989
#-------------------------------------------------------------------------------
227 dpurdie 3990
# Function        : ProcessPathName
3991
#
3992
# Description     : Massage a pathname according to a set of flags
3993
#
3994
# Inputs          : $fn         - Patchname to massage
3995
#                   $flags      - Flags in a string
3996
#                                   --dir       - only the directory part ( or a "." )
3997
#                                   --file      - only the file part
3998
#                                   --abspath   - Absolute path
3999
#                                   --absdrive  - Absolute path with drive letter(WIN)
4000
#
4001
# Returns         : Massaged pathname
4002
#
4003
sub ProcessPathName
4004
{
4005
    my ( $fn, $flags ) = @_;
4006
    #
4007
    #   Process flags
4008
    #       --dir           - only the directory part ( or a "." )
4009
    #       --file          - only the file part
4010
    #       --abspath       - Absolute path
4011
    #       --absdrive      - Absolute path with drive letter(WIN)
4012
    #
4013
    if ( $flags =~ /--dir/ )
4014
    {
4015
        $fn = '.'
4016
            unless ( $fn =~ s~/[^/]*$~~);
4017
    }
4018
 
4019
    if ( $flags =~ /--file/ )
4020
    {
4021
        $fn =~ s~.*/~~;
4022
    }
4023
 
4024
    if ( $flags =~ /--abspath/ )
4025
    {
4026
        $fn = AbsPath( $fn );
4027
    }
4028
    elsif ( $flags =~ /--absdrive/ )
4029
    {
4030
        $fn = AbsPath( $fn );
4031
        if ( $::ScmHost eq "WIN" )
4032
        {
4033
            $fn = $::CwdDrive . '/' . $fn
4034
                unless ( $fn =~ m~^\w:/~  );
4035
            $fn =~ s~//~/~g;
4036
        }
4037
    }
4038
 
4039
  return $fn;
4040
}
4041
 
4042
#-------------------------------------------------------------------------------
4043
# Function        : LocatePreReq
4044
#
4045
# Description     : Locate a file known to JATS
4046
#                   There are many places to search
4047
#                       1) Src files - specified with a Src directive
4048
#                       2) Scripts - specified with a script directive
4049
#                       3) Search - Files in the specified search path
4050
#                       4) Programs specified with a 'Prog' directive
4051
#
4052
#                   Should also look in other locations (Libs, SharedLibs)
4053
#                   Not done yet. May be issues of a name clash if a program
4054
#                   and a library have the same name.
4055
#
4056
# Inputs          : Name to locate
4057
#
4058
# Returns         : Full pathname of file
4059
#
4060
sub LocatePreReq
4061
{
4062
    my ( $name ) = @_;
4063
    Debug ("LocatePreReq:Looking for $name");
4064
    #
4065
    #   Try a Src file first
4066
    #
4067
    if ( exists $SRCS{ $name } )
4068
    {
4069
        return $SRCS{ $name };
4070
    }
4071
 
4072
    #
4073
    #   Try a script
4074
    #
4075
    if ( exists $SCRIPTS{ $name } )
4076
    {
4077
        return $SCRIPTS{ $name };
4078
    }
4079
 
4080
    #
4081
    #   Try a PROG
4082
    #
289 dpurdie 4083
    if ( my $pProg = $PROGS->Get($name) )
227 dpurdie 4084
    {
289 dpurdie 4085
        return $pProg->getPath();
227 dpurdie 4086
    }
4087
 
4088
    #
4089
    #   Try searching for the file
4090
    #   Uses Data from AddSrcDir
4091
    #
4092
    #   Done: last because it generates warning messages
4093
    #
4094
    return MakeSrcResolve( $name );
4095
}
4096
 
4097
#-------------------------------------------------------------------------------
4098
# Function        : ToolExtensionPaths
4099
#
4100
# Description     : Return a list of toolset extension directories
4101
#                   The data will have been discovered by the build process
4102
#                   and will have been saved for the makefile creation phase
4103
#
4104
# Inputs          : None
4105
#
4106
# Returns         : Return an ordered unique list
4107
#
4108
sub ToolExtensionPaths
4109
{
4110
    Debug( "ToolExtensionPaths:", @::BUILDTOOLSPATH );
4111
    return @::BUILDTOOLSPATH;
4112
}
4113
 
4114
#-------------------------------------------------------------------------------
4115
# Function        : ToolExtensionProgram
4116
#
4117
# Description     : Determine if the named program exists within the PATH
4118
#                   that also includes the toolset extension
4119
#
4120
# Inputs          : program             - Name of program
4121
#                   elist               - An array of possible program extensions
4122
#
6504 dpurdie 4123
# Returns         : Full path the to program or an empty element (not undef)
227 dpurdie 4124
#
4125
sub ToolExtensionProgram
4126
{
4127
    my ($program, @elist ) = @_;
4128
 
4129
    #
4130
    #   If elist is empty then insert a defined entry
4131
    #
4132
    push @elist, '' unless ( @elist );
4133
 
4134
    #
4135
    #   Scan all toolset directories
4136
    #   for the program
4137
    #
4138
    for my $dir ( ToolExtensionPaths() )
4139
    {
4140
        for my $ext ( @elist )
4141
        {
4142
            my $tool = "$dir/$program$ext";
4324 dpurdie 4143
            Debug( "ToolsetExtensionProgram: Look for: $tool" );
227 dpurdie 4144
 
4145
            return $tool if ( -f $tool );
4146
        }
4147
    }
4148
}
4149
 
4150
sub Define
4151
{
4152
    Debug2( "Define(@_)" );
4153
 
4154
    push( @DEFINES, @_ );
4155
}
4156
 
4157
 
4158
sub Defines
4159
{
4160
    my( $path, $script ) = @_;
4161
    my( $line );
4162
 
4163
    Debug2( "Defines($path, $script)" );
4164
 
4165
    $script = Exists( $path, $script, "Defines" );
271 dpurdie 4166
    push( @DEFINES, "# Defines from: $script" );
285 dpurdie 4167
    open( my $fh, '<', $script ) || Error( "Opening $script" );
4168
    while (<$fh>) {
227 dpurdie 4169
        $_ =~ s/\s*(\n|$)//;                    # kill trailing whitespace & nl
4170
        push( @DEFINES, $_ );
4171
    }
4172
    push( @ScmDepends, "$script" );             # makefile dependencies
285 dpurdie 4173
    close( $fh );
227 dpurdie 4174
}
271 dpurdie 4175
#-------------------------------------------------------------------------------
4176
# Function        : Rule
4177
#
4178
# Description     : Add a Rule and Recipe to the generated makefile
4179
#                   This is not encouraged as it has been misused to create
4180
#                   unreadable and unmaintainable makefiles.
4181
#
4182
#                   Rules will be added to the makefile after the rules and
4183
#                   recipes created by JATS directives
4184
#
4185
# Inputs          : $platform               - Platform predicate
4186
#                   @rule                   - Array of rules to add
4187
#
4188
# Returns         : 
4189
#
227 dpurdie 4190
sub Rule
4191
{
4192
    my( $platforms, @rule ) = @_;
4193
 
4194
    return if ( ! ActivePlatform($platforms) );
4195
 
4196
    push( @RULES, @rule );
4197
    Message("Rule directive used. Consider replacing with GenerateFiles");
4198
}
4199
 
271 dpurdie 4200
#-------------------------------------------------------------------------------
4201
# Function        : Rules
4202
#
4203
# Description     : Add a file of Rules and Recipes to the generated makefile
4204
#                   Used internally ONLY as there is no platform predicate
4205
#                   Similar to 'Rule()'
4206
#
4207
# Inputs          : $path                   - path to script
4208
#                   $script                 - File fo Rules
4209
#
4210
# Returns         : 
4211
#
227 dpurdie 4212
sub Rules
4213
{
4214
    my( $path, $script ) = @_;
4215
    my( $line );
4216
 
4217
    $script = Exists( $path, $script, "Rules" );
271 dpurdie 4218
    push( @RULES, "# Rules from: $script" );
285 dpurdie 4219
    open( my $fh, '<', $script ) || Error( "Opening $script" );
4220
    while (<$fh>) {
227 dpurdie 4221
        $_ =~ s/\s*(\n|$)//;                    # kill trailing whitespace & nl
4222
        push( @RULES, $_ );
4223
    }
4224
    push( @ScmDepends, "$script" );             # makefile dependencies
285 dpurdie 4225
    close( $fh );
227 dpurdie 4226
}
4227
 
271 dpurdie 4228
#-------------------------------------------------------------------------------
4229
# Function        : AddRule
4230
#
4231
# Description     : Inernal function
4232
#                   Add a line to the Rules area
4233
#
4234
# Inputs          : @elements                   - Array of lines to add
4235
#
4236
# Returns         : Nothing
4237
#
4238
sub AddRule
4239
{
4240
    push( @RULES, @_ );
4241
}
227 dpurdie 4242
 
271 dpurdie 4243
#-------------------------------------------------------------------------------
4244
# Function        : Src
4245
#
4246
# Description     : This directive is used to identify files to JATS
4247
#                   Once a file has been identified as a 'Source' file, then it
4248
#                   can be used by name, without the need to locate the file again.
4249
#                   This implies that filenames must be unique.
4250
#                   The directories cannot be used to make files of the same name
4251
#                   unqiue - this is not the JATS way
4252
#
4253
#                   Source files will be classified as one of:
4254
#                       c, c++, header, assembler or other
4255
#
4256
#
4257
# Inputs          : $platform               - Active Platform Predicate
4258
#                   @elements               - A list of files and options
4259
#
4260
#                   Valid options are:
4261
#                       --c                 - Specifies the type of file
4262
#                       --cpp
4263
#                       --h, --headers
4264
#                       --asm
4265
#                       --FromPackage       - Search packages for the file
4266
#                       --List=xxx          - Append file to a named list
4267
#                       --Depends=xxx       - Manually name a dependency
6387 dpurdie 4268
#                       --IgnoreDuplicates  - Ignore duplicates (mostly internal use)
271 dpurdie 4269
#
4270
#                   Options are processed before file elements
4271
#                   Thus options apply to all files in the list
4272
#
4273
# Returns         : Nothing
4274
#
227 dpurdie 4275
sub Src
4276
{
4277
    my( $platforms, @elements ) = @_;
6387 dpurdie 4278
    my( $type, @args, $source, $basename, $from_package, @lists, $ignoreDups );
227 dpurdie 4279
    my( @depends, @srcs );
4280
 
4281
    $platforms = '' unless ( $platforms );
4282
    Debug2( "Src($platforms, @elements)" );
4283
 
4284
    #
4285
    #   Ensure that there is a file within the list
4286
    #
4287
    Warning( "Src directive does not specify any files: Src($platforms, @elements)" )
4288
        unless (grep( /^[^-]/, @elements ) );
4289
 
4290
    return if ( ! ActivePlatform($platforms) );
4291
 
4292
    #
4293
    #   Remove spaces from both ends of the arguments.
4294
    #   It is easier to remove spaces now than to detect them later
4295
    #
4296
    foreach ( @elements )
4297
    {
4298
        s/^\s+//;
4299
        s/\s+$//;
4300
        s~//~/~g;                               # Remove multiple /
4301
    }
4302
 
4303
    #.. Collect arguments
4304
    #
4305
    $type = "";
4306
    foreach ( @elements )
4307
    {
4308
        if ( /^--c$/ )
4309
        {
4310
            Debug( "Src: --c" );
4311
            $type = ".c";
4312
        }
4313
        elsif ( /^--cpp$/ )
4314
        {
4315
            Debug( "Src: --cpp" );
4316
            $type = ".cc";
4317
        }
4318
        elsif ( /^--h$/ || /^--header$/ )
4319
        {
4320
            Debug( "Src: --h" );
4321
            $type = ".h";
4322
        }
4323
        elsif ( /^--asm$/ )
4324
        {
4325
            Debug( "Src: --asm" );
4326
            $type = ".asm";
4327
        }
6387 dpurdie 4328
        elsif ( /^--IgnoreDup/ )
4329
        {
4330
            $ignoreDups = 1;
4331
        }
227 dpurdie 4332
        elsif ( /^--FromPackage$/ )
4333
        {
4334
            $from_package = 1;
4335
        }
4336
        elsif ( /^--List=(.*)/ )
4337
        {
4338
            my $list_name = $1;
4339
            Error( "Bad list name: $list_name" )
4340
                unless ( $list_name =~ m/^[A-Za-z]\w+/ );
4341
            push @lists, $list_name;
4342
        }
4343
        elsif ( /^--Depends=(.*)/ )
4344
        {
4345
            foreach ( split( ',', $1) )
4346
            {
4347
                my $full = MakeSrcResolveExtended( $from_package, $_ );
4348
                push @depends, $full;
4349
            }
4350
        }
4351
        elsif ( /^-(.*)/ )
4352
        {
4353
            Debug( "Src: arg $_" );
4354
            push @args, $_;
4355
        }
4356
        else
4357
        {
4358
            push @srcs, $_;
4359
            Warning ("Src files contains a '\\' character: $_" ) if (m~\\~);
4360
        }
4361
    }
4362
 
4363
    #.. Push source file(s)
4364
    foreach ( @srcs )
4365
    {
4366
        if ( ! /^-(.*)/ )
4367
        {
4368
            $source = MakeSrcResolveExtended( $from_package, $_ );
4369
            $basename = StripDir( $source );
4370
            Debug( "Src: $_ -> $source=$basename (@args),(@depends)" );
4371
 
4372
            if ( $SRCS{ $basename } ) {
6387 dpurdie 4373
                Warning( "Duplicate src ignored '$source'") unless $ignoreDups;
227 dpurdie 4374
                next;
4375
            }
4376
            $SRCS{ $basename } = $source;
4377
 
4378
            HashJoin( \%SRC_ARGS, $;, $basename, @args )
4379
                if (@args);
4380
 
4381
            HashJoin( \%SRC_DEPEND, $;, $basename, @depends )
4382
                if ( @depends );
4383
 
4384
            $SRC_TYPE{ $basename } = $type
4385
                if ($type);
4386
 
4387
 
4388
            foreach (@lists) {
4389
                my $lname_short = "LIST_$_";
4390
                my $lname_full = "LIST_FULL_$_";
4391
 
4392
                no strict 'refs';
4393
 
4394
                push @$lname_short,$basename;
4395
                push @$lname_full ,$source;
4396
 
4397
                use strict 'refs';
4398
            }
4399
 
4400
            __AddSourceFile( 1, $source, "", $type );
4401
        }
4402
    }
4403
}
4404
 
6387 dpurdie 4405
#-------------------------------------------------------------------------------
4406
# Function        : AddToSrc 
4407
#
4408
# Description     : Internal function
4409
#                   Used by plugins and tools
4410
#                   
4411
#                   Will test if specified file is known to JATS, before
4412
#                   adding to the the list of known (Src) files 
4413
#
4414
# Inputs          : $platform
4415
#                   $file           - Only one file
4416
#                   @srcOpts        - Same as Src
4417
#
4418
# Returns         : True if any file can be found
4419
#                   Returns full path to the file    
4420
#
4421
sub AddToSrc
4422
{
4423
    my( $platforms, $file, @args ) = @_;
4424
    Debug2( "AddToSrc($platforms, $file, @args)" );
227 dpurdie 4425
 
6387 dpurdie 4426
    #
4427
    #   Process files
4428
    #
4429
    my $basename = StripDir( $file );
4430
    unless (exists $SRCS{$file} || exists  $SRCS{$basename} ) {
4431
        Src ('*', $file, @args);
4432
    }
4433
 
4434
    return $SRCS{$basename};
4435
}
4436
 
4437
 
227 dpurdie 4438
###############################################################################
4439
#  sub LibNameSplit
4440
#      Just a little help to deal with major/minor stuff for shared libs -
4441
#      given the name of the library as the argument, split out major and minor
4442
#      parts and return the basename, i.e name without major and minor and
4443
#      the pair of major and minor.
4444
###############################################################################
4445
 
4446
sub LibNameSplit
4447
{
4448
    my ( @bits ) = split('\.', $_[0]);
4449
    my ( $major, $minor );
4450
 
4451
    if ($#bits >= 1) {
4452
        $major = $bits[0]; $minor = $bits[1];
4453
    } elsif ($#bits >= 0) {
4454
        $major = $bits[0]; $minor = 0;
4455
    } else {
4456
        $major = 1; $minor = 0;
4457
    }
4458
    Debug( "LibName: $@_[0] ($major.$minor)" );
4459
    return ($major, $minor);
4460
}
4461
 
4462
#-------------------------------------------------------------------------------
4463
# Function        : Lib
4464
#
4465
# Description     : Generate a static library
4466
#
4467
# Inputs          : Platform specifier
4468
#                   Name of the library
4469
#                   Arguemnts ...
4470
#
4471
# Returns         :
4472
#
4473
sub Lib
4474
{
4475
    my( $platforms, $lib, @args ) = @_;
4476
    return if ( ! ActivePlatform($platforms) );
4477
 
4478
    Error ("Lib: Library name not defined") unless ( $lib );
4479
 
4480
    #
4481
    #   May be a shared library or a static library - for historic reasons
4482
    #   If the user has specified a --Shared then its a shared library
4483
    #
4484
    return SharedLib( @_ )
4485
        if ( grep (/^--Shared/, @args) );
4486
 
4487
    #
4488
    #   Does this toolset support libraries
4489
    #
4490
    Error ("Libraries are not supported") unless ( defined $::a );
4491
 
4492
    #.. Fully qualify library path for addition to library list.
4493
    $lib = "lib$lib"
4494
       if ( $ScmTargetHost eq "Unix" && $lib !~ m/^lib/);
4495
    Debug( "Lib: $lib" );
4496
 
4497
    #
289 dpurdie 4498
    #   Create a new object to describe the library
227 dpurdie 4499
    #   Ensure that only one such lib exists
289 dpurdie 4500
    #   Add the library to the list of static libraries
227 dpurdie 4501
    #
4502
    Error( "Library of the same name already defined: $lib" )
289 dpurdie 4503
        if ( $LIBS->Get($lib) );
4504
    $LIBS->NewAdd($lib);
227 dpurdie 4505
 
4506
    #
4507
    #   Process arguments
4508
    #
4509
    push( @LINTLIBS, $lib );
4510
    _LibArgs( $lib, @args );
4511
}
4512
 
4513
 
4514
#-------------------------------------------------------------------------------
4515
# Function        : SharedLib
4516
#
4517
# Description     : Generate a shared library
4518
#
4519
# Inputs          : Platform specifier
4520
#                   Name of the library
4521
#                   Arguemnts ...
4522
#
4523
# Returns         :
4524
#
4525
sub SharedLib
4526
{
4527
    my( $platforms, $lib, @args ) = @_;
4528
 
4529
    return if ( ! ActivePlatform($platforms) );
4530
 
4531
    Error ("SharedLib: Library name not defined") unless ( $lib );
4532
    Error ("Shared Libraries are not supported") unless ( defined $::so );
4533
 
4534
#.. Fully qualify library path for addition to library list.
4535
    $lib = "lib$lib"
4536
       if ( $ScmTargetHost eq "Unix" && $lib !~ m/^lib/);
4537
    Debug( "ShLib: $lib" );
4538
 
4539
    #
4540
    #   Ensure that only one such lib exists
4541
    #
289 dpurdie 4542
    Error( "Library of the same name already defined: $lib" )
4543
        if ( $SHLIBS->Get($lib) );
4544
    $SHLIBS->NewAdd($lib);
293 dpurdie 4545
 
227 dpurdie 4546
    #
4547
    #   If the user has not specified a --Shared parameter then provide one
4548
    #
4549
    push @args, "--Shared=Current"
4550
        unless ( grep (/^--Shared/, @args) );
4551
 
4552
    #
4553
    #   Process arguments
4554
    #
4555
    push( @LINTSHLIBS, $lib );
4556
    _SharedLibArgs( $lib, @args );
4557
}
4558
 
4559
 
4560
#-------------------------------------------------------------------------------
4561
# Function        : LibArgs
4562
#
4563
# Description     : Add arguments to an existing library directive
4564
#
4565
# Inputs          : Platform specifier
4566
#                   Name of the library
4567
#                   Arguemnts ...
4568
#
4569
# Returns         :
4570
#
4571
sub LibArgs
4572
{
4573
    my( $platforms, $lib, @args ) = @_;
4574
    return if ( ! ActivePlatform($platforms) );
4575
 
4576
#.. Fully qualify library path for addition to library list.
4577
    $lib = "lib$lib"
4578
       if ( $ScmTargetHost eq "Unix" && $lib !~ m/^lib/);
4579
    Debug( "LibArgs: $lib" );
4580
 
4581
    #
4582
    #   Process the arguments
4583
    #
4584
    _LibArgs( $lib, @args );
4585
}
4586
 
4587
 
4588
#-------------------------------------------------------------------------------
4589
# Function        : _LibArgs
4590
#
4591
# Description     : Process static library arguments
4592
#                   Internal use only
4593
#
4594
# Inputs          : Name of the library
4595
#                   Arguments to process
4596
#
4597
sub _LibArgs
4598
{
4599
    my( $lib, @elements) = @_;
4600
    my $obj;
4601
 
4602
    #
289 dpurdie 4603
    #   Ensure that only one such lib exists
4604
    #
4605
    my $libp = $LIBS->Get($lib);
4606
    Error("Library name not defined: $lib")
4607
        unless ( $libp );
4608
 
4609
    #
227 dpurdie 4610
    #   Process each element
4611
    #
4612
    foreach (@elements)
4613
    {
371 dpurdie 4614
        if ( /^\s+/ )
4615
        {
4616
            Error ("Argument cannot start with a space: '$_'");
4617
        }
227 dpurdie 4618
        if ( /^--Shared/ )
4619
        {
4620
            Error( "--Shared not valid for a static library" );
4621
        }
4622
 
4623
        if ( /^-l(.*)/ || /^--l(.*)/ || /^-L(.*)/ || /^--L(.*)/ )
4624
        {
4625
        #.. Target library specified - add to library list.
4626
        #
4627
            Warning( "$_ within non shared library specification" );
4628
            next;
4629
        }
4630
 
4631
        if ( /^--if(.*)/ )
4632
        {
4633
            Warning( "$_ within non shared library specification" );
4634
            next;
4635
        }
4636
 
4637
        if ( /^--(.*)/ )
4638
        {
4639
            Debug( "LibArgs: arg $_" );
4640
 
4641
            #.. Argument specified - add to argument list
4642
            #
289 dpurdie 4643
            $libp->addItem('ARGS', $_);
4644
 
227 dpurdie 4645
            next;
4646
        }
4647
 
369 dpurdie 4648
        if ( %::ScmToolsetProgSource )
227 dpurdie 4649
        {
4650
            #
4651
            #   Toolset provides support for some file types
4652
            #   to be passed directly to the librarian builder
4653
            #
4654
            my $ext  = StripFile($_);
4655
            if ( exists ($::ScmToolsetProgSource{$ext}) )
4656
            {
4657
                my $full_path = MakeSrcResolve ( $_ );
4658
                my $flag = $::ScmToolsetProgSource{$ext};
4659
                Debug( "LibArgs: src $_" );
289 dpurdie 4660
                $libp->addItem('ARGS', "$flag$full_path" );
227 dpurdie 4661
                next;
4662
            }
4663
        }
4664
 
4665
        if ( $::o )
4666
        {
4667
        #.. Object specified - add to object list.
4668
        #
4669
            $obj = _LibObject( "", $_ );
4670
 
4671
        #.. Add to object list.
4672
        #   Note:   Object path must be explicit as several
4673
        #           toolsets add additional objects.
4674
        #
289 dpurdie 4675
            $libp->addItem('OBJS', "\$(OBJDIR)/$obj" );
227 dpurdie 4676
            next;
4677
        }
4678
 
4679
        #
4680
        #   Don't know how to handle this type of argument
4681
        #
4682
        Error ("LibArgs: Don't know how to handle: $_" );
4683
    }
4684
}
4685
 
4686
 
4687
#-------------------------------------------------------------------------------
4688
# Function        : SharedLibArgs
4689
#
4690
# Description     : Add arguments to an existing shared library directive
4691
#
4692
# Inputs          : Platform specifier
4693
#                   Name of the library
4694
#                   Arguemnts ...
4695
#
4696
# Returns         :
4697
#
4698
sub SharedLibArgs
4699
{
4700
    my( $platforms, $lib, @args ) = @_;
4701
    return if ( ! ActivePlatform($platforms) );
4702
 
4703
#.. Fully qualify library path for addition to library list.
4704
    $lib = "lib$lib"
4705
       if ( $ScmTargetHost eq "Unix" && $lib !~ m/^lib/);
4706
    Debug( "ShLibArgs: $lib" );
4707
 
4708
    _SharedLibArgs( $lib, @args );
4709
}
4710
 
4711
 
4712
#-------------------------------------------------------------------------------
4713
# Function        : _SharedLibArgs
4714
#
4715
# Description     : Process shared library arguments
4716
#                   Internal use only
4717
#
4718
# Inputs          : Name of the library
4719
#                   Arguments to process
4720
#
4721
sub _SharedLibArgs
4722
{
4723
    my ( $lib, @elements) = @_;
4724
 
289 dpurdie 4725
    my $libp = $SHLIBS->Get($lib);
4726
    Error("Library name not defined: $lib")
4727
        unless ( $libp );
4728
 
227 dpurdie 4729
    #
289 dpurdie 4730
    #.. Collect --Shared arguments
339 dpurdie 4731
    #   Need to process this one first so that we have a version number
227 dpurdie 4732
    #
4733
    foreach (@elements)
4734
    {
371 dpurdie 4735
        if ( /^\s+/ )
4736
        {
4737
            Error ("Argument cannot start with a space: '$_'");
4738
        }
289 dpurdie 4739
        next unless ( /^--Shared/ );
4740
 
4741
        my $shared;
227 dpurdie 4742
        if ( /^--Shared$/ )
4743
        {
4744
        #.. Shared library, default library version 1.0
4745
        #
4746
            $shared = "1.0";
4747
        }
4748
        elsif ( /^--Shared=Current$/ )
4749
        {
4750
        #.. Shared library, using 'current' build version
4751
        #
4752
            $shared = $::ScmBuildVersion;
289 dpurdie 4753
            $shared = "1.0" if ($shared eq "");
227 dpurdie 4754
        }
4755
        elsif ( /^--Shared=(.*)/ )
4756
        {
4757
        #.. Shared library, specific version
4758
        #
4759
            my($M, $m) = LibNameSplit($1);
289 dpurdie 4760
            $shared = "$M.$m";
4761
        }
227 dpurdie 4762
 
289 dpurdie 4763
        #
4764
        #   Update the shared Names
4765
        #
4766
        if ( defined $shared )
4767
        {
227 dpurdie 4768
            Warning( "multiple --Shared arguments" )
339 dpurdie 4769
                if (exists $libp->{ VERSION });
227 dpurdie 4770
            Debug( "ShLibArgs: shared $_ ($shared)" );
289 dpurdie 4771
            $libp->{ VERSION } = $shared;
227 dpurdie 4772
        }
289 dpurdie 4773
        else
4774
        {
4775
            Error ("ShLibArgs: --Shared argument not understood");
4776
        }
227 dpurdie 4777
    }
4778
 
4779
 
4780
#.. Parse all of the object and argument entries.
4781
#
4782
    foreach (@elements)
4783
    {
289 dpurdie 4784
        next if ( /^--Shared(.*)/ );
227 dpurdie 4785
 
4786
        if ( /^[-]{1,2}([lL])(.*)/ )
4787
        {
4788
        #.. Target library specified - add to library list.
339 dpurdie 4789
        #   Support --L and -L and --l and -l
227 dpurdie 4790
        #
4791
            Debug( "ShLibArgs: lib  -$1$2" );
289 dpurdie 4792
            $libp->addItem('LIBS', "-$1$2" );
227 dpurdie 4793
            next;
4794
        }
4795
 
4796
        if ( /^--if(.*)/ )
4797
        {
4798
        #.. Library conditional - add to library list.
4799
        #
4800
            Debug( "ShLibArgs: cond $_" );
289 dpurdie 4801
            $libp->addItem('LIBS', $_);
227 dpurdie 4802
            next;
4803
        }
4804
 
339 dpurdie 4805
        if ( /^--SoName=(.*)/i )
4806
        {
4807
        #.. Specify the SoName of the library
4808
        #   Not supported by all toolsets
4809
        #
4810
            my $soMode = $1;
4811
            if ( !$ScmToolsetSoName )
4812
            {
4813
                Warning ("Toolset does not support --SoName. Option ignored");
4814
                next;
4815
            }
4816
 
4817
            Error ("SharedLib: $lib. Multiple --SoName arguments not allowed")
4818
                if ( $libp->{ SONAME } );
4819
 
4820
            my ($major, $minor, $patch, $build, $raw_patch) = SplitVersion($::ScmBuildVersionFull);
4821
            my $soname = '.';
4822
            if ( $soMode =~ m/Major/i ) {
4823
                $soname .= $major;
4824
            } elsif ( $soMode =~ m/^Minor/i ) {
4825
                $soname .= "$major.$minor";
4826
            } elsif ( $soMode =~ m/^Patch/i ) {
4827
                $soname .= "$major.$minor.$patch";
4828
            } elsif ( $soMode =~ m/^Build/i ) {
4829
                $soname .= "$major.$minor.$patch.$build";
4830
            } elsif ( $soMode =~ m/^Full/i ) {
4831
                $soname .= $libp->{ VERSION };
4832
            } elsif ( $soMode =~ m/^None/i ) {
4833
                $soname = '';
4834
            } elsif ( $soMode =~ m/^[0-9.]+$/ ) {
4835
                $soname .= $soMode;
4836
            } else {
4837
                Error ("Unknown --SoName mode: $soMode");
4838
            }
4839
            $libp->addItem('ARGS', '--SoNameSuffix=' . $soname);
4840
            $libp->{ SONAME } = 1;
4841
            next;
4842
        }
4843
 
227 dpurdie 4844
        if ( /^-(.*)/ )
4845
        {                           
4846
        #.. Argument specified - add to argument list
4847
        #
4848
            Debug( "ShLibArgs: arg  $_" );
289 dpurdie 4849
            $libp->addItem('ARGS', $_);
227 dpurdie 4850
            next;
4851
        }
4852
 
369 dpurdie 4853
        if ( %::ScmToolsetProgSource )
227 dpurdie 4854
        {
4855
            #
4856
            #   Toolset provides support for some file types
4857
            #   to be passed directly to the program builder
4858
            #
4859
            my $ext  = StripFile($_);
4860
            if ( exists ($::ScmToolsetProgSource{$ext}) )
4861
            {
4862
                my $full_path = MakeSrcResolve ( $_ );
4863
                my $flag = $::ScmToolsetProgSource{$ext};
4864
                Debug( "ShLibArgs: src $_" );
289 dpurdie 4865
                $libp->addItem('ARGS', "$flag$full_path");
227 dpurdie 4866
                next;
4867
            }
4868
        }
4869
 
4870
        if ( $::o )
4871
        {
4872
        #.. Object specified - add to object list.
4873
        #
4874
            my ($obj) = _LibObject( $lib, $_ );
4875
 
4876
        #.. Add to object list.
4877
        #   Note:   Object path must be explicit as several
4878
        #           toolsets add additional objects.
4879
        #
4880
            $SHOBJ_LIB{ $obj } = $lib;
289 dpurdie 4881
            $libp->addItem('OBJS', "\$(OBJDIR)/$obj");
227 dpurdie 4882
            next;
4883
        }
4884
 
4885
        #
4886
        #   Don't know how to handle this type of argument
4887
        #
4888
        Error ("SharedLib: Don't know how to handle: $_" );
4889
    }
4890
}
4891
 
4892
 
4893
#-------------------------------------------------------------------------------
4894
# Function        : _LibObject
4895
#
4896
# Description     : Process library object file
4897
#                   Common processing routine for static and shared library
4898
#                   Internal use only
4899
#
4900
# Inputs          : shared  - Name of the shared library is shared, if defined
4901
#                   fname   - Name of file
4902
#
4903
# Returns         : Name of the object file
4904
#
4905
sub _LibObject
4906
{
4907
    my ($shared, $fname) = @_;
4908
    my ($file, $ext, $obj, $srcfile, $delete_obj);
4909
 
4910
    #.. Object specified - add to object list.
4911
    #
4424 dpurdie 4912
    #   Want to handle several cases
4913
    #       Normal - User has provided the name of an object file (without the obj suffix)
4914
    #       Other  - User has provided the name of a source file
4915
    #                Need to perform implicit source file processing
4916
    #
4917
    #   The hard part is detecting the difference
4918
    #   Just can't use the existence of a '.' 
4919
    #
4920
    if ($OBJSOURCE{$fname}) {
4921
        $file = $fname;                             # Already know about this file
4922
        $ext = '';                                  # Don't need to split it
4923
    } else {
4924
        $file = StripDirExt($fname);                # file name, without extension or Dir
4925
        $ext  = StripFile($fname);                  # extension
4926
    }
227 dpurdie 4927
 
4928
    if ($shared) {
4929
        $obj = "$shared/$file";                 # library specific subdir
4930
    } else {
4931
        $obj = "$file";
4932
    }
4933
 
4934
    Debug( "LibObjs: obj [$shared]$fname ($file$ext)" );
4935
 
4936
    #.. Unqualified object name
4937
    #
4424 dpurdie 4938
    if ( $ext eq '' ) {
227 dpurdie 4939
        #
4940
        #   Object file not covered by a "Src" statement
4941
        #   Assume that it will be created
4942
        #
4424 dpurdie 4943
        unless ( $srcfile = $OBJSOURCE{$file} )
227 dpurdie 4944
        {
4945
            #
4424 dpurdie 4946
            #   If the object is "generated" then it will be in the
227 dpurdie 4947
            #   SRCS list
4948
            #
4949
            unless ( $srcfile = $SRCS{"$file.$::o"} )
4950
            {
4951
                Warning( "No source for object '$fname' ($file)" );
4952
            }
4953
        }
4954
        $delete_obj = 1;
4955
    }
4956
 
4957
    #.. Qualified object name (ie has extension)
4958
    #       Strip extension and resolve ...
4959
    #       Assume that the named file can be built into an object file
4960
    #
4961
    else
4962
    {
4963
        #.. Resolve
4964
        #
4965
        if ( !($srcfile = $OBJSOURCE{ "$file" }) )
4966
        {
4967
            $srcfile = MakeSrcResolve( $fname );
4968
            $SRCS{ $fname } = $srcfile;
4969
            __AddSourceFile( 0, $fname, $obj );
4970
            $delete_obj = 1;
4971
        }
4972
    }
4973
 
4974
    #.. Delete generated object file
4975
    #   Ensure that the object file is added to the delete list
4976
    #   Add it to the ToolsetObj deletion list as the main OBJ deleltion
4977
    #   list will aready have been processed
4978
    #
4979
    ToolsetObj( "\$(OBJDIR)/$obj" )
4980
        if ( $delete_obj );
4981
 
4982
 
4983
    #.. Shared library objects,
4984
    #       Must explicitly relate source and object, as shared libraries
4985
    #       objects are built within a library specific subdirs.
4986
    #
4987
    $OBJSOURCE{ $obj } = $srcfile
371 dpurdie 4988
        if ( $shared && defined $srcfile );
227 dpurdie 4989
 
4990
    return $obj;
4991
}
4992
 
4993
 
4994
# MergeLibrary
4995
#   Merge a list of libraries into one library
4996
#
4997
sub MergeLibrary
4998
{
4999
    my( $platforms, $lib, @elements ) = @_;
5000
 
5001
    return if ( ! ActivePlatform($platforms) );
5002
 
5003
 
5004
#.. Fully qualify library path for addition to library list.
5005
    $lib = "lib$lib"
5006
       if ( $ScmTargetHost eq "Unix" && $lib !~ m/^lib/);
5007
    Debug( "MergeLibrary: $lib" );
5008
 
289 dpurdie 5009
    #
5010
    #   Create a new object to describe the library
5011
    #   Ensure that only one such lib exists
5012
    #   Add the library to the list of static libraries
5013
    #
5014
    Error( "Merged Library of the same name already defined: $lib" )
5015
        if ( $MLIBS->Get($lib) );
5016
    my $libp = $MLIBS->NewAdd($lib);
5017
 
227 dpurdie 5018
#.. Parse all of the object and argument entries.
5019
#
5020
    foreach (@elements)
5021
    {
5022
        if ( /^--(.*)/ )
5023
        {
289 dpurdie 5024
            $libp->addItem('ARGS', $_);
227 dpurdie 5025
        }
5026
        else
5027
        {
5028
            my ($llib);
5029
 
5030
            #
5031
            #   Collect the source libraries
5032
            #   These must have been installed and will be in a known area
5033
            #   Create full names for the libaries
5034
            #
5035
            if ( $ScmTargetHost eq "Unix" ) {
5036
                $llib = "lib$_";                # Prefix "lib" ....
5037
                $lib =~ s/^liblib/lib/;         # @LIBS already has lib added
5038
            } else {
5039
                $llib = $_;
5040
            }
5041
 
5042
            Debug( "MergeLibrary: merge $llib" );
289 dpurdie 5043
            $libp->addItem('LIBS', $llib);
227 dpurdie 5044
        }
5045
    }
5046
}
5047
 
5048
#-------------------------------------------------------------------------------
5049
# Function        : Script
5050
#
5051
# Description     : Locate a script for test purposes
5052
#
5053
# Inputs          : $platforms      - Platform selector
5054
#                   $script         - A single script name
5055
#                   $execute        - Flag to indicate that the script is to
5056
#                                     marked as executable when used in a TestProg
5057
#                                     This flag is NOT used as the script will
5058
#                                     be forced executable
5059
#
5060
# Returns         : Nothing
5061
#
5062
sub Script
5063
{
5064
    my( $platforms, $script, $execute ) = @_;
5065
 
5066
    Debug2( "Script(@_)" );
5067
 
5068
    return if ( ! ActivePlatform($platforms) );
5069
 
5070
    #
5071
    #   Locate the script as a source file
5072
    #
5073
    my $file = MakeSrcResolve ( $script );
5074
    $script = StripDir( $file );
5075
    $SCRIPTS{ $script } = $file;
5076
}
5077
 
5078
#-------------------------------------------------------------------------------
5079
# Function        : RunTest
5080
#
5081
# Description     : Define a test to be run with the 'run_tests' and 'run_unit_tests'
5082
#
5083
# Inputs          : $platform       - Enabled for these platforms
5084
#                   $prog           - Program to run
5085
#                                     This SHOULD return a non-zero exit status
5086
#                                     on error. The program may be a 'TestProg'
5087
#                                     or a 'Script'.
5088
#                   @elements       - Options and test arguments
5089
#                                     Options are:
4778 dpurdie 5090
#                                       --Auto              - Non interactive unit test
5091
#                                       --Unit              - Same and --Auto
5092
#                                       --UtfFormat=nnn     - Specifies Automated Unit Test, 
5093
#                                                             results post processed with formatter
4781 dpurdie 5094
#                                       --UtfArg=nnn        - Argument passed into the UTF formatter    
5095
#                                       --Name=nnn          - Test Name.
5695 dpurdie 5096
#                                       --CopyIn=file       - A file to be copied into the test directory.
5097
#                                       --MaxTime=fff.ff[smhd] - Max Test Time. Default 30m
227 dpurdie 5098
#
5099
#                                     Non Options are passed to the test program.
5100
#                                     --PackageBase(xxx)    - Base of package
5101
#                                     --PackageInfo(xxx)    - Package information
5102
#                                     --File(xxx)           - Resolved name of file
5103
#                                     --Var(xxx)            - Expanded variable
5104
#                                     --Local(xxx)          - File within the local directory
5105
#
4778 dpurdie 5106
#                                     Toolset Framework support (ie NUNIT in csharp.pl)
5107
#                                       --FrameWork=name    - Name of framework
5108
#                                       --xxxx              - Args passed to framework constructor
5109
#
227 dpurdie 5110
# Returns         : Nothing
5111
#
4781 dpurdie 5112
my %RunTestNames;                       # Unique Name Tests
227 dpurdie 5113
sub RunTest
5114
{
5115
    my( $platforms, $prog, @elements ) = @_;
5116
    my $command = './';                 # program prefix / command
5117
    my $winprog = 1;                    # 1: Convert / -> \ (WIN32 only)
5118
    my $framework;
5119
    my @framework_opts;
5120
    my @copy = ();
5121
    my $auto;
4778 dpurdie 5122
    my $utfFormat;
4781 dpurdie 5123
    my @utfArgs;
5124
    my $utfName;
5695 dpurdie 5125
    my $maxTime;
227 dpurdie 5126
 
5127
    return if ( ! ActivePlatform($platforms) );
5128
 
5129
    #
5130
    #   Scan @elements and extract useful information
5131
    #   Need to process twice as some args will modify the
5132
    #   processing done later
5133
    #
5134
    my @args;
5135
    foreach ( @elements )
5136
    {
5137
        if ( m/^--FrameWork=(.+)/ ) {
5138
            $framework = $1;
5139
 
5140
        } elsif ( m/^--Auto/ || m/^--Unit/) {
5141
            $auto = 1;
5142
 
4781 dpurdie 5143
        } elsif ( m/^--Name=(.*)/) {
5144
            $utfName = $1;
5145
 
5146
            Error("Duplicate Test Name: $utfName")
5147
                if (exists $RunTestNames{$utfName} );
5148
            $RunTestNames{$utfName} = 1;
5149
 
4778 dpurdie 5150
        } elsif ( m/^--UtfFormat=(.*)/) {
5151
            $utfFormat = $1;
5152
 
4781 dpurdie 5153
        } elsif ( m/^--UtfArg=(.*)/) {
5154
            push @utfArgs, $1;
5155
 
5695 dpurdie 5156
        } elsif ( m/^--MaxTime=(.*)/) {
5157
            $maxTime = $1;
5158
            unless ($maxTime =~ m~^[0-9]*\.?[0-9]+[smhd]?$~) {
5159
                Error("MaxTime invalid: $maxTime");
5160
            }
5161
 
227 dpurdie 5162
        } elsif ( m/^--CopyIn=(.*)/ ) {
5163
            push @copy, MakeSrcResolve ( $1 );
5164
 
5165
        } elsif ( $framework && m/^--\w+=(.+)/ ) {
5166
            push @framework_opts, $_;
5167
 
5168
        } else {
5169
            push @args, $_;
5170
        }
5171
    }
5172
    @elements = @args;
5173
    @args = ();
5174
 
5175
    #
5176
    #   Determine the source of the test prog
4612 dpurdie 5177
    #   If using a plug-in framework, then we don't know
227 dpurdie 5178
    #   If not, then may be a script or a TESTPROGS
5179
    #
5180
 
5181
    unless ( $framework )
5182
    {
289 dpurdie 5183
        if ( $TESTPROGS->Get($prog) || $PROGS->Get($prog)  ) {
227 dpurdie 5184
            #
5185
            #   Append a suitable EXE suffix
5186
            #
289 dpurdie 5187
            $prog = GenProgName( $prog );
227 dpurdie 5188
 
5189
        } elsif ( exists $SCRIPTS{$prog} ) {
5190
            #
5191
            #   Script names are raw
5192
            #   Perl script are invoked directly
5193
            #
5194
            $command = "\$(GBE_PERL) -w "
5195
                if ( $prog =~ /\.pl$/ );
5196
 
5197
            #
5198
            #   Pass / to shells
5199
            #
5200
            $winprog = 0
5201
                unless ( $prog =~ m~\.bat$~ )
5202
 
5203
        } else {
5204
            Warning("RunTest program not known: $prog",
261 dpurdie 5205
                  "It is not a TestProg, Prog or a Script",
5206
                  "The test may fail" );
227 dpurdie 5207
        }
5208
    }
5209
 
5210
    #
5211
    #   Extract and process options
5212
    #
5213
    my @uargs = ();
5214
    my @preq_files;
5215
 
5216
    foreach my $arg (@elements) {
5217
        #
5218
        #   Process the tool arguments and extract file information
5219
        #   Extract all fields of the form:
5220
        #           --xxxxx(yyyyyy[,zzzzz])
5221
        #           --xxxxx{yyyyyyy}
5222
        #           --xxxxx[yyyyyyy] to allow embedded brackets
5223
        #
5224
        while ( $arg =~ m/--(\w+)               # --CommandWord         $1
5225
                                (               # Just for grouping
5226
                                \((.*?)\)   |   # Stuff like (yyyyy)    $3
5227
                                {(.*?)}     |   # or    like {yyyyy}    $4
5228
                                \[(.*?)\]       # or    like [yyyyy]    $5
5229
                                )/x )           # Allow comments and whitespace
5230
        {
5231
            my $cmd = $1;                       # The command
5232
            my $ufn = $3 || $4 || $5;           # User filename + options
5233
            my $mb = $-[0];                     # Match begin offset
5234
            my $me = $+[0];                     # Match end
5235
            my $flags = '';                     # Optional flags ( --dir or --file )
5236
            my $raw_arg = $ufn;                 # Raw arguments
6387 dpurdie 5237
            my $all = substr( $arg, $mb, $me - $mb ); # All of match. Avoid use of $&
329 dpurdie 5238
            my $is_abs;
5239
            my $is_path = 1;
227 dpurdie 5240
 
5241
            Error ("RunTest. Empty element not allowed: $all")
5242
                unless ( defined($ufn) );
5243
 
5244
            $ufn =~ s/\s+$//;
5245
            $ufn =~ s~//~/~g;                   # Remove multiple /
5246
            if ( $ufn =~ m/(.*?),(.*)/ )        # Extract out any flags
5247
            {
5248
                $ufn = $1;
5249
                $flags = $2;
5250
            }
5251
 
5252
            my $fn = $ufn ;                     # Replacement filename
343 dpurdie 5253
            my $fnp = '';                       # Prefix to $fn
227 dpurdie 5254
            Error ("RunTest. Empty element not allowed: $all" )
5255
                if ( length ($ufn) <= 0 );
5256
 
5257
            #
5258
            #   Process found user command
5259
            #
5260
            if ( $cmd =~ /^File/ )
5261
            {
5262
                #
5263
                #   Prerequisite filename
5264
                #       Resolve the full name of the file. It may be known
5265
                #       as a source file (possibly generated) or it may be
5266
                #       located in a known source directory
5267
                #
5268
                $fn = MakeSrcResolve ( $ufn );
5269
                UniquePush (\@preq_files, $fn);
5270
 
5271
                Debug( "RunTest: Prereq: $fn" );
5272
 
5273
            }
5274
            elsif ( $cmd =~ /^PackageBase/ )
5275
            {
5276
                $fn = GetPackageBase( "RunTest", $raw_arg );
5277
                UniquePush (\@preq_files, $fn);
5278
            }
5279
            elsif ( $cmd =~ /^PackageInfo/ )
5280
            {
5281
                $fn = GetPackageInfo( "RunTest", $raw_arg );
5282
            }
5283
            elsif ( $cmd =~ /^Var/ )
5284
            {
343 dpurdie 5285
                ($fnp, $fn, $is_path, $is_abs) = ExpandGenVar( "RunTest", $raw_arg );
227 dpurdie 5286
                $flags = '';
5287
            }
6504 dpurdie 5288
            elsif ( $cmd =~ /^Tool/ )
5289
            {
5290
                ($fn, $is_path, $is_abs) = ExpandTool( "RunTest", $raw_arg );
5291
                $flags = '';
5292
            }
227 dpurdie 5293
            elsif ( $cmd =~ /^Local/ )
5294
            {
5295
                $fn = '$(LOCALDIR)/' . $ufn ;
5296
                UniquePush (\@preq_files, $fn);
5297
            }
6387 dpurdie 5298
            elsif ( $cmd =~ /^Dir/ )
5299
            {
5300
                # Item is a directory.
5301
                # Must be massaged so that it will be correct within the context
5302
                # Modified path is simply added to the command line
5303
                # 
5304
                $fn = $ufn;
5305
                unless (-d $fn) {
5306
                    if (-f $fn) {
5307
                        Warning ("Not a directory. Its a file: $arg") ;
5308
                    } else {
5309
                        Warning ("Directory not found: $arg");
5310
                    }
5311
                }
5312
            }
227 dpurdie 5313
            else
5314
            {
5315
                Warning ("RunTest: Unknown replacement command: $cmd");
5316
                $fn = $ufn;
5317
            }
5318
 
5319
            #
5320
            #   Process path modification flags
5321
            #       --dir           - only the directory part ( or a "." )
5322
            #       --file          - only the file part
5323
            #       --abspath       - Absolute path
5324
            #       --absdrive      - Absolute path with drive letter(WIN)
5325
            #
5326
            $fn = ProcessPathName( $fn, $flags );
5327
 
5328
            #
5329
            #   The program is going to be executed within a subdirectory
5330
            #   so add one more level of indirection to the path, but only if
5331
            #   the path is relative
5332
            #
329 dpurdie 5333
            if ( $is_path && ! $is_abs )
227 dpurdie 5334
            {
329 dpurdie 5335
                unless ( $fn =~ m~^/|^\w:/~  )
5336
                {
5337
                    $fn = '../' . $fn
5338
                        unless( $fn =~ s~=~=../~ );
5339
                    $fn =~ s~/.$~~;
5340
                }
227 dpurdie 5341
            }
5342
 
5343
            #
5344
            #   Minor kludge under windows. Ensure directores have a "\" sep
5345
            #   Unless the user has specified a straight shell command
5346
            #
5986 dpurdie 5347
            $fn = "\$(subst /,\$(dirsep),$fn)"
227 dpurdie 5348
                if ( $::ScmHost eq "WIN" && $winprog );
5349
 
5350
            #
343 dpurdie 5351
            #   Prepend any $fn Prefix
5352
            #   This will be a tag and is not subject to path processing
5353
            #
5354
            $fn = $fnp . $fn;
5355
 
5356
            #
227 dpurdie 5357
            #   Replace the found string with the real name of the file
5358
            #   Note: 4 argument version of substr is not always available
5359
            #         so we must do it the hard way
5360
            #               substr( $arg, $mb, $me - $mb, $fn);
5361
            #
5362
            $arg = substr( $arg, 0, $mb ) . $fn . substr( $arg, $me );
5363
 
5364
            Debug2( "RunTest: subs: $all -> $fn" );
5365
        }
5366
        push(@uargs, "'$arg'");
5367
    }
5368
 
5369
    #
5370
    #   Create the test entry
5371
    #   This is a structure that will be placed in an array
5372
    #   The array preserves order and uniqness
5373
    #
5374
    my %test_entry;
5375
    $test_entry{'framework'}= $framework if ( $framework );
5376
    $test_entry{'framework_opts'}= \@framework_opts if ( $framework );
5377
    $test_entry{'command'}  = $command . $prog unless ( $framework);
5378
 
5379
    $test_entry{'prog'}     = $prog;
5380
    $test_entry{'copyprog'} = 1;
5381
    $test_entry{'args'}     = \@uargs;
5382
    $test_entry{'auto'}     = $auto if ( $auto );
4778 dpurdie 5383
    $test_entry{'utfformat'}= $utfFormat if ( $utfFormat );
4781 dpurdie 5384
    $test_entry{'utfargs'}  = \@utfArgs;
5385
    $test_entry{'utfname'}  = $utfName;
5695 dpurdie 5386
    $test_entry{'maxtime'}  = $maxTime if ($maxTime);
227 dpurdie 5387
    $test_entry{'copyin'}   = \@copy;
5388
    $test_entry{'copyonce'} = ();
5389
    $test_entry{'preq'}     = \@preq_files;
5390
    $test_entry{'testdir'}  = 'BINDIR';
5391
 
5392
    push ( @TESTS_TO_RUN, \%test_entry );
5393
 
5394
    #
5395
    #   Flag Auto Run processing required
5396
    #
4501 dpurdie 5397
    $TESTS_TO_RUN = 1;
227 dpurdie 5398
    $TESTS_TO_AUTORUN = 1 if ( $auto );
5399
}
5400
 
5401
 
5402
sub TestProg
5403
{
5404
    my( $platforms, $prog, @elements ) = @_;
5405
 
5406
    Debug2( "TestProg($platforms, $prog, @elements)" );
5407
 
5408
    return if ( ! ActivePlatform($platforms) );
5409
 
5410
    Error ("TestProg: Program name not defined") unless ( $prog );
5411
    Error ("Programs are not supported") unless ( defined $::exe );
5412
 
289 dpurdie 5413
    #
5414
    #   Create a new Prog object, or retrieve any existing one
5415
    #
5416
    my $pProg = $TESTPROGS->Get($prog);
5417
    $pProg = $TESTPROGS->NewAdd($prog)
5418
        unless ( $pProg );
227 dpurdie 5419
 
5420
#.. Parse all of the object, library and argument entries
5421
    Debug( "TestProg: $prog" );
5422
    foreach (@elements)
5423
    {
5424
        if ( /^[-]{1,2}([lL])(.*)/ )
5425
        {
5426
        #.. Target Library specified - add to library list.
5427
        #  
5428
            Debug( "TestProg: lib  -$1$2" );
289 dpurdie 5429
            $pProg->addItem('LIBS', "-$1$2");
227 dpurdie 5430
            next;
5431
        }
5432
 
5433
        if ( /^--if(.*)/ )
5434
        {
5435
        #.. Library conditional - add to library list.
5436
        #
5437
            Debug( "TestProg: cond $_" );
289 dpurdie 5438
            $pProg->addItem('LIBS', $_);
227 dpurdie 5439
            next;
5440
        }
5441
 
5442
        if ( /^-(.*)/ )
5443
        {
5444
        #.. Argument specified - add to argument list
5445
        #
5446
            Debug( "TestProg: arg $_" );
289 dpurdie 5447
            $pProg->addItem('ARGS', $_);
227 dpurdie 5448
            next;
5449
        }
5450
 
369 dpurdie 5451
        if ( %::ScmToolsetProgSource )
227 dpurdie 5452
        {
5453
            #
5454
            #   Toolset provides support for some file types
5455
            #   to be passed directly to the program builder
5456
            #
5457
            my $ext  = StripFile($_);
5458
            if ( exists ($::ScmToolsetProgSource{$ext}) )
5459
            {
5460
                my $full_path = MakeSrcResolve ( $_ );
5461
                my $flag = $::ScmToolsetProgSource{$ext};
5462
                Debug( "TestProg: src $_" );
289 dpurdie 5463
                $pProg->addItem('ARGS', "$flag$full_path");
227 dpurdie 5464
                next;
5465
            }
5466
        }
5467
 
5468
        if ( $::o )
5469
        {
5470
        #.. Object specified - add to object list.
5471
        #
5472
            my $obj = _LibObject( "", $_ );
5473
 
5474
        #.. Add to program object list.
289 dpurdie 5475
            $pProg->addItem('OBJS', "\$(OBJDIR)/$obj");
227 dpurdie 5476
            next;
5477
        }
5478
 
5479
        #
5480
        #   Don't know how to handle this type of argument
5481
        #
5482
        Error ("TestProg: Don't know how to handle: $_" );
5483
    }
5484
}
5485
 
5486
 
5487
sub Prog
5488
{
5489
    my( $platforms, $prog, @elements ) = @_;
5490
 
5491
    Debug2( "Prog($platforms, $prog, @elements)" );
5492
 
5493
    return if ( ! ActivePlatform($platforms) );
5494
 
5495
    Error ("Prog: Program name not defined") unless ( $prog );
5496
    Error ("Programs are not supported") unless ( defined $::exe );
5497
 
289 dpurdie 5498
    #
5499
    #   Create a new Prog object, or retrieve any existing one
5500
    #
5501
    my $pProg = $PROGS->Get($prog);
5502
    $pProg = $PROGS->NewAdd($prog)
5503
        unless ( $pProg );
227 dpurdie 5504
 
5505
#.. Parse all of the object, library and argument entries
5506
    Debug( "Prog: $prog" );
5507
    foreach (@elements)
5508
    {
5509
        if ( /^[-]{1,2}([lL])(.*)/ )
5510
        {
5511
        #.. Target Library specified - add to library list.
5512
        #  
5513
            Debug( "Prog: lib  -$1$2" );
289 dpurdie 5514
            $pProg->addItem('LIBS', "-$1$2");
227 dpurdie 5515
            next;
5516
        }
5517
 
5518
        if ( /^--if(.*)/ )
5519
        {
5520
        #.. Library conditional - add to library list.
5521
        #
5522
            Debug( "Prog: cond $_" );
289 dpurdie 5523
            $pProg->addItem('LIBS', $_);
227 dpurdie 5524
            next;
5525
        }
5526
 
5527
        if ( /^-(.*)/ )
5528
        {
5529
        #.. Argument specified - add to argument list
5530
        #
5531
            Debug( "Prog: arg $_" );
289 dpurdie 5532
            $pProg->addItem('ARGS', $_);
227 dpurdie 5533
            next;
5534
        }
5535
 
369 dpurdie 5536
        if ( %::ScmToolsetProgSource )
227 dpurdie 5537
        {
5538
            #
5539
            #   Toolset provides support for some file types
5540
            #   to be passed directly to the program builder
5541
            #
5542
            my $ext  = StripFile($_);
5543
            if ( exists ($::ScmToolsetProgSource{$ext}) )
5544
            {
5545
                my $full_path = MakeSrcResolve ( $_ );
5546
                my $flag = $::ScmToolsetProgSource{$ext};
5547
                Debug( "Prog: src $_" );
289 dpurdie 5548
                $pProg->addItem('ARGS', "$flag$full_path");
227 dpurdie 5549
                next;
5550
            }
5551
        }
5552
 
5553
        if ( $::o )
5554
        {
5555
        #.. Object specified - add to object list.
5556
        #
5557
            my $obj = _LibObject( "", $_ );
5558
 
5559
        #.. Add to program object list.
289 dpurdie 5560
            $pProg->addItem('OBJS', "\$(OBJDIR)/$obj");
227 dpurdie 5561
            next;
5562
        }
5563
 
5564
        #
5565
        #   Don't know how to handle this type of argument
5566
        #
5567
        Error ("Prog: Don't know how to handle: $_" );
5568
    }
5569
}
5570
 
5571
#-------------------------------------------------------------------------------
5572
# Function        : ProgAddExtra
5573
#
5574
# Description     : This (internal) function allows a toolset to list additional
5575
#                   binaries as a part of a program. This will ensure that the
5576
#                   binaries are generated in the 'make_prog' phase with the main
5577
#                   program.
5578
#
5579
#                   The files are not listed for packaging, by this function
5580
#
5581
#                   The function does not ensure that the files are not already
5582
#                   listed as a @PROG ( as @PROGS is not fully resolved at this point )
5583
#
5584
# Inputs          :     $name               - Tag name of program being built
5585
#                                             Not used (yet)
5586
#                       $prog               - Fully resolved path to a file
5587
#
5588
# Returns         : Nothing
5589
#
5590
sub ProgAddExtra
5591
{
5592
    my ($name, $prog) = @_;
5593
    Debug2( "ProgAddExtra($name: $prog)" );
5594
 
5595
    UniquePush(\@PROGS_EXTRA, $prog);
5596
}
5597
 
4261 dpurdie 5598
our %PROJECTS;                          # Project information
5599
my  @PROJECTS_ORDER;
227 dpurdie 5600
#-------------------------------------------------------------------------------
4261 dpurdie 5601
# Function        : MakeProjectName 
5602
#
5603
# Description     : Create a uniq project name
5604
#
5605
# Inputs          : srcPath 
5606
#
5607
# Returns         : A unique project name 
5608
#
5609
sub MakeProjectName
5610
{
5611
    my ($srcPath) = @_;
5612
    my $suffix = "";
5613
    my $index = 1;
5614
 
5615
    my $proj = StripDir( $srcPath );
5616
    while (exists $PROJECTS{$proj . $suffix})
5617
    {
5618
        $suffix = '.' . $index++;
5619
    }
5620
    return $proj . $suffix; 
5621
}
5622
 
5623
#-------------------------------------------------------------------------------
227 dpurdie 5624
# Function        : MakeProject
5625
#
5626
# Description     : A nasty directive that is intended to build a Microsoft
5627
#                   project for WINCE, WIN32 and .NET builds.
5628
#
5629
#                   There are many constraints:
5630
#                       Cannot be mixed with multi-platform builds
5631
#                       Some parameters are tool specific
5632
#
267 dpurdie 5633
#                   Allow programs to be Installed as well as Packaged
5634
#                   The 'Progect' is treated' as a program and it doesn't work
5635
#                   to well if we Install libraries.
227 dpurdie 5636
#
267 dpurdie 5637
#                   Only Reason to Install Programs is to allow the Cab Maker
5638
#                   to locate them.
5639
#
227 dpurdie 5640
# Inputs          : Platform        - Active platform
5641
#                   Project         - Project Name with extension
5642
#                   Options         - Many options
5643
#
5644
# Returns         :
5645
#
5646
sub MakeProject
5647
{
5648
    my( $platforms, $proj, @elements ) = @_;
5649
 
5650
    Debug2( "MakeProject($platforms, $proj, @elements)" );
5651
 
5652
    return if ( ! ActivePlatform($platforms) );
5653
 
5654
    #
5655
    #   Sanity test
5656
    #
5657
    Error ("MakeProject: Project name not defined") unless ( $proj );
5658
 
5659
    #
5660
    #   Take the project name and convert it into a full path
4261 dpurdie 5661
    #   Need to create a uniq project name - allowing for multiple uses
227 dpurdie 5662
    #
5663
    my $project = MakeSrcResolve ( $proj );
4261 dpurdie 5664
    $proj = MakeProjectName($project);
5665
 
237 dpurdie 5666
    Error ("Project File Not found: $project") unless ( -f $project );
227 dpurdie 5667
 
5668
    my $basedir = StripFileExt( $project );
5669
 
5670
    #
5671
    #   Collect user arguments
5672
    #   They are all processed within the toolset
5673
    #
5674
    my @tool_options;
5411 dpurdie 5675
    my $unit_tests;
5676
    my $auto_tests;
227 dpurdie 5677
    foreach ( @elements )
5678
    {
5679
        if ( m/^--Debug/ ) {
5680
            $PROJECTS{$proj}{'Debug'} = 1;
5681
 
5682
        } elsif ( m/^--Prod/ ) {
5683
            $PROJECTS{$proj}{'Prod'} = 1;
5684
 
267 dpurdie 5685
        } elsif ( m/^--(Package|Install)ProgDebug=(.*)/ ) {
5686
            _PackageFromProject( $1, $proj, $basedir,'Prog', 'D', $2 );
227 dpurdie 5687
 
267 dpurdie 5688
        } elsif ( m/^--(Package|Install)Prog(Prod)*=(.*)/ ) {
5689
            _PackageFromProject( $1, $proj, $basedir, 'Prog', 'P', $3 );
227 dpurdie 5690
 
267 dpurdie 5691
        } elsif ( m/^--(Package)LibDebug=(.*)/ ) {
5692
            _PackageFromProject( $1, $proj, $basedir, 'Lib', 'D', $2 );
227 dpurdie 5693
 
267 dpurdie 5694
        } elsif ( m/^--(Package)Lib(Prod)*=(.*)/ ) {
5695
            _PackageFromProject( $1, $proj, $basedir, 'Lib', 'P', $3 );
227 dpurdie 5696
 
267 dpurdie 5697
        } elsif ( m/^--(Package)SharedLibDebug=(.*)/ ) {
5698
            _PackageFromProject( $1, $proj, $basedir, 'Lib', 'D', $2 );
227 dpurdie 5699
 
267 dpurdie 5700
        } elsif ( m/^--(Package)SharedLib(Prod)*=(.*)/ ) {
5701
            _PackageFromProject( $1, $proj, $basedir, 'Lib', 'P', $3 );
227 dpurdie 5702
 
267 dpurdie 5703
        } elsif ( m/^--(Package)Hdr=(.*)/ ) {
5704
            _PackageFromProject( $1, $proj, $basedir, 'Hdr', undef, $2 );
227 dpurdie 5705
 
267 dpurdie 5706
        } elsif ( m/^--(Package)File=(.*)/ ) {
5707
            _PackageFromProject( $1, $proj, $basedir, 'File', undef, $2 );
227 dpurdie 5708
 
267 dpurdie 5709
        } elsif ( m/^--(Package)Tool(Prod)*=(.*)/ ) {
5710
            _PackageFromProject( $1, $proj, $basedir, 'Tool', 'P', $3 );
241 dpurdie 5711
 
267 dpurdie 5712
        } elsif ( m/^--(Package)ToolDebug=(.*)/ ) {
5713
            _PackageFromProject( $1, $proj, $basedir, 'Tool', 'D', $2 );
241 dpurdie 5714
 
267 dpurdie 5715
        } elsif ( m/^--(Package|Install)/ ) {
5716
            Error("MakeProject. Unknown $1 option: $_");
227 dpurdie 5717
 
5411 dpurdie 5718
        } elsif ( m/^--UnitTest/ ) {
5719
            $unit_tests = 1;
5720
 
5721
        } elsif ( m/^--AutoTest/ ) {
5722
            $auto_tests = 1;
5723
 
227 dpurdie 5724
        } else {
5725
            push @tool_options, $_;
5726
        }
5727
    }
5728
 
5729
    #
6353 dpurdie 5730
    #   Validate some of the arguments
5731
    #   Ensure has not specified both --Prod and --Debug
5732
    #
5733
    Error ("Makeproject. Conflicting options --Debug and --Prod" )
5734
        if ( $PROJECTS{$proj}{'Debug'}  && $PROJECTS{$proj}{'Prod'} );
5735
 
5736
    #   Ensure that global --OnlyProd/Debug don't prevent builds
5737
    $PROJECTS{$proj}{'Debug'} = 1 if ($ScmBuildType eq 'D');
5738
    $PROJECTS{$proj}{'Prod'} = 1 if ($ScmBuildType eq 'P');
5739
    Error ("Makeproject. Global and Local options --Debug and --Prod prevent project being built" )
5740
        if ( $PROJECTS{$proj}{'Debug'}  && $PROJECTS{$proj}{'Prod'} );
5741
 
5742
    #
227 dpurdie 5743
    #   Save the information
5744
    #
5745
    $PROJECTS{$proj}{'options'} = \@tool_options;
5746
    $PROJECTS{$proj}{'name'} = $proj;
5747
    $PROJECTS{$proj}{'project'} = $project;
5748
    $PROJECTS{$proj}{'basedir'} = $basedir;
5411 dpurdie 5749
    $PROJECTS{$proj}{'unittest'} = $unit_tests if ( $unit_tests );
5750
    $PROJECTS{$proj}{'autotest'} = $auto_tests if ( $auto_tests );
227 dpurdie 5751
    UniquePush (\@PROJECTS_ORDER, $proj);
5752
 
5753
}
5754
 
5755
#-------------------------------------------------------------------------------
5756
# Function        : _PackageFromProject
5757
#
5758
# Description     : Save Packaged data from the project
5759
#
267 dpurdie 5760
# Inputs          : $tgt        - Install or Package
5761
#                   $proj       - Name of the project
227 dpurdie 5762
#                   $base       - Base directory of files
5763
#                   $etype      - Type of Package (Progs, Libs, ... )
5764
#                   $type       - Debug or Production or both
5765
#                   $items      - Item to add. It may be comma seperated
5766
#
267 dpurdie 5767
my %PackageToData = ( 'Package' =>
5768
                        { 'Hdr'   => \%PACKAGE_HDRS,
5769
                          'Lib'   => \%PACKAGE_LIBS,
5770
                          'Prog'  => \%PACKAGE_PROGS,
5771
                          'File'  => \%PACKAGE_FILES,
5772
                          'Tool'  => \%PACKAGE_FILES,
5773
                          '_BASE' => 'PBase',
5774
                        },
5775
                      'Install' =>
5776
                        { 'Hdr'   => \%INSTALL_HDRS,
5777
                          'Lib'   => \%INSTALL_LIBS,
5778
                          'Prog'  => \%INSTALL_PROGS,
5779
                          'File'  => undef,
5780
                          'Tool'  => undef,
5781
                          '_BASE' => 'IBase',
5782
                        },
227 dpurdie 5783
                    );
5784
 
5785
sub _PackageFromProject
5786
{
267 dpurdie 5787
    my( $tgt, $proj, $base, $etype, $type, $items ) = @_;
227 dpurdie 5788
    my $subdir = '';
5789
 
5790
    #
267 dpurdie 5791
    #   Sanity test
5792
    #
5793
    $type = '' unless ( $type );
5794
    Error ("INTERNAL. Bad packaging option: $tgt")   unless ( exists $PackageToData{$tgt} );
5795
    Error ("INTERNAL. Bad packaging option: $etype") unless ( exists $PackageToData{$tgt}{$etype} );
5796
    Error ("Unsupported packaging combination: $tgt$etype$type=$items") unless ( defined $PackageToData{$tgt}{$etype} );
5797
 
5798
    #
5799
    #   Determine the index into the 'PackageInfo' structure
5800
    #   This provides the symbolic name for the target package path
5801
    #   for Package or Install
5802
    #
5803
    #   The key '_BASE' is internal. Used only to provide this information
5804
    #
5805
    my $tbase = $PackageToData{$tgt}{'_BASE'};
5806
 
5807
    #
227 dpurdie 5808
    #   Process options
5809
    #
5810
    foreach my $item ( split (/,/, $items ) )
5811
    {
5812
        next unless ( $item =~ m/^--/ );
5813
        if ( $item =~ m/^--Subdir=(.*)/ )
5814
        {
5815
            $subdir = '/' . $1;
5816
            $subdir =~ s~//~/~g;
5817
            $subdir =~ s~/$~~g;
5818
        }
5819
        else
5820
        {
5821
            Warning( "MakeProject: Unknown packaging option ignored: $_" );
5822
        }
5823
    }
5824
 
5825
    #
5826
    #   Process files
5827
    #
5828
    foreach my $item ( split (/,/, $items ) )
5829
    {
5830
        next if ( $item =~ m/^--/ );
5831
 
267 dpurdie 5832
        my $tdir = $PackageInfo{$etype}{$tbase} . $PackageInfo{$etype}{'Dir'} . $subdir ;
227 dpurdie 5833
        my $fname = StripDir( $item );
5834
        my $target = $tdir . '/' . $fname;
5835
 
5836
        $item = "$base/$item" if ( $base );
5837
 
5838
        #
5839
        #   Do not use $(GBE_TYPE) in the target name
5840
        #   The existing package mechanism does not handle different
5841
        #   production and debug file naming mechanism, whereas the project
5842
        #   must. Convert $(GBE_TYPE) into P or D to ensure uniquness
5843
        #
5844
        $target =~ s~\$\(GBE_TYPE\)~$type~ if ($type);
5845
 
5846
        #
5847
        #   Create a PACKAGE entry suitable for processing by the normal packaging
5848
        #   routines. This is complicated because the Projects do not adhere to
267 dpurdie 5849
        #   the JATS file name conventions
227 dpurdie 5850
        #
5851
        my %package_entry;
5852
        $package_entry{'src'}   = $item;
5853
        $package_entry{'dir'}   = $tdir;
267 dpurdie 5854
        $package_entry{'set'}   = 'ALL' if ($tgt eq 'Package');
227 dpurdie 5855
        $package_entry{'type'}  = $type if ($type);
5856
 
267 dpurdie 5857
        $PackageToData{$tgt}{$etype}->{$target} = {%package_entry};
227 dpurdie 5858
    }
5859
}
5860
 
5861
#-------------------------------------------------------------------------------
5862
# Function        : MakeAnt
5863
#
5864
# Description     : A nasty directive to create JAR files via ANT
5865
#                   There are several limitations
5866
#                   This is closely related to the MakeProject directive
5867
#
5868
#
5869
# Inputs          : Platform            - Active platform
5870
#                   buildfile           - Name of the build.xml file
5871
#                   Options             - A few options
5872
#                                         --Jar=file
5873
#                                               Generated JAR file(s)
5874
#                                         --GeneratedFile=file
5875
#                                               Other generated files
5876
#                                               Used to flag JNI that must
5877
#                                               Occur early
5878
#                                          --AutoTest=<name>
5879
#                                               Supports unitAutomated unit test
5880
#                                               by calling build target <name>
5881
#                                          --UnitTest=<name>
5882
#                                               Supports unit test
5883
#                                               by calling build target <name>
5884
#                                          --PackageBase
5885
#                                               Provides path to base of all packages
6294 dpurdie 5886
#                                          --AllPackages
5887
#                                               Provide paths to both LinkPkgArchive and BuildPkgArchive
227 dpurdie 5888
#
5889
# Returns         :
5890
#
5891
our %JAR_FILES;
5892
sub MakeAnt
5893
{
5894
    my( $platforms, $proj, @elements ) = @_;
5895
 
5896
    Debug2( "MakeAnt($platforms, $proj, @elements)" );
5897
 
5898
    return if ( ! ActivePlatform($platforms) );
5899
 
5900
    #
5901
    #   Sanity test
5902
    #
5903
    Error ("MakeAnt: build.xml name not defined") unless ( $proj );
5904
 
5905
    #
5906
    #   Take the project name and convert it into a full path
5907
    #
5908
    my $project;
5909
    $project = MakeSrcResolve ( $proj );
4261 dpurdie 5910
    $proj = MakeProjectName($project);
237 dpurdie 5911
    Error ("Build File Not found: $project") unless ( -f $project );
227 dpurdie 5912
 
5913
    my $basedir = StripFileExt( $project );
5914
 
5915
    #
5916
    #   Collect user arguments
5917
    #   They are all processed within the toolset
5918
    #
5919
    my @tool_options;
5920
    my @generated;
5921
    my $unit_tests;
5922
    my $auto_tests;
5923
    my $package_base;
6294 dpurdie 5924
    my $allPackages;
227 dpurdie 5925
 
5926
    foreach ( @elements )
5927
    {
5928
        if ( m/^--Debug/ ) {
5929
            $PROJECTS{$proj}{'Debug'} = 1;
5930
 
5931
        } elsif ( m/^--Prod/ ) {
5932
            $PROJECTS{$proj}{'Prod'} = 1;
5933
 
5934
        } elsif ( m/^--Jar=(.*)/ ) {
5935
            my $tgt = $1;
5936
               $tgt = "$basedir/$tgt" if ( $basedir );
5937
            my $fn = StripDir( $1 );
5938
            $JAR_FILES{$fn} = $tgt;
5939
            GenerateSrcFile( 0, $tgt );
5940
 
5941
        } elsif ( m/^--GeneratedFile=(.*)/ ) {
5942
            my $tgt = $1;
5943
            $tgt = "$basedir/$tgt" if ( $basedir );
5944
            push @generated, $tgt;
5945
            GenerateSrcFile( 2, $tgt );
5946
 
5947
        } elsif ( m/^--UnitTest=(.*)/ ) {
5948
            $unit_tests = $1
5949
 
5950
        } elsif ( m/^--AutoTest=(.*)/ ) {
5951
            $auto_tests = $1
5952
 
5953
        } elsif ( m/^--PackageBase/ ) {
5954
            $package_base = 1;
5955
 
6294 dpurdie 5956
        } elsif ( m/^--AllPackages/i ) {
5957
            $allPackages = 1;
227 dpurdie 5958
 
5959
        } elsif ( m/^--/ ) {
5960
            Error("MakeAnt. Unknown option ignored: $_");
5961
 
5962
        } else {
5963
            push @tool_options, $_;
5964
        }
5965
    }
5966
 
5967
    #
5968
    #   Extend option arguments to include the base dir of packages
5969
    #   Create definitions of the form PACKAGE_<name>
5970
    #
6294 dpurdie 5971
    for my $entry (getPackageList())
227 dpurdie 5972
    {
6294 dpurdie 5973
        my $pkgType = $entry->getType();
5974
        next if $pkgType eq 'interface'  ;
5975
        next unless ( ( $pkgType eq 'link') || $allPackages);
5976
        my $dir = $entry->getBase(2);
5977
        my $name = $entry->getName();
227 dpurdie 5978
        unless ( $package_base )
5979
        {
5980
            $dir .= '/jar';
5981
            next unless ( -d $dir );
5982
        }
6294 dpurdie 5983
        push @tool_options, "-DPACKAGE_$name=\$(call myabspath,$dir)";
227 dpurdie 5984
    }
5985
    #
5986
    #   Extend options to include the base dir of the created package
5987
    #   Allows careful use for direct packaging of artifacts
5988
    #
6294 dpurdie 5989
    push @tool_options, '-DPACKAGEDIR=$(call myabspath,$(PKGDIR))';
227 dpurdie 5990
 
5991
    #
5992
    #   Save the information
5993
    #
5994
    $PROJECTS{$proj}{'options'} = \@tool_options;
5995
    $PROJECTS{$proj}{'generated'} = \@generated if ( @generated );
5996
    $PROJECTS{$proj}{'name'}    = $proj;
5997
    $PROJECTS{$proj}{'project'} = $project;
5998
    $PROJECTS{$proj}{'basedir'} = $basedir;
5999
    $PROJECTS{$proj}{'type'}    = 'ant';
6000
    $PROJECTS{$proj}{'unittest'} = $unit_tests if ( $unit_tests );
6001
    $PROJECTS{$proj}{'autotest'} = $auto_tests if ( $auto_tests );
6002
    UniquePush (\@PROJECTS_ORDER, $proj);
6003
 
6004
    $TESTS_TO_AUTORUN = 1 if ( $auto_tests );
4501 dpurdie 6005
    $TESTS_TO_RUN     = 1 if ( $unit_tests || $auto_tests );
227 dpurdie 6006
 
6007
    #
6008
    #   Validate some of the arguments
6009
    #
6010
    Error ("MakeAnt. Conflicting options --Debug and --Prod" )
6011
        if ( $PROJECTS{$proj}{'Debug'}  && $PROJECTS{$proj}{'Prod'} );
6012
}
6013
 
6014
###############################################################################
6015
#
6016
#   Installation/Packaging util functions
6017
#
6018
#-------------------------------------------------------------------------------
6019
# Function        : __TargetDir
6020
#
6021
# Description     : Internal function to process common arguments for
6022
#                   the PackageXxx directives
6023
#
6024
# Inputs          : flags           - Indicate how to handle this argument
6025
#                   base            - Base directory for this type of package
6026
#                   argument        - Argument to process
6027
#                   pdir            - Reference to resultant directory
6028
#                   ptype           - Reference to resultant type (P or D)(optional)
6029
#
6030
# Returns         : 0               - Agument not consumed
6031
#                   1               - Argument consumed
6032
#                   2               - Skip this directive
6033
#
6034
my $T_TYPE  = 0x0001;                           # Postfix GBE_TYPE
6035
my $T_PKG   = 0x0002;                           # Special --Dir handling
6036
my $T_MACH  = 0x0004;                           # Allow --Machine too
6037
my $T_GBE   = 0x0008;                           # Allow --Gbe too
6038
my $T_FILE  = 0x0010;                           # Suffix or prefix subdir
6039
 
6040
sub __TargetDir
6041
{
6042
    my( $flags, $base, $argument, $pdir, $ptype ) = @_;
6043
    my $dir  = "";
6044
    my $consumed = 0;
6045
 
6046
    #
6047
    #   Generate basic parts
6048
    #   Note Product will default to Platform
6049
    #
6050
    my $str_platform = '$(GBE_PLATFORM)';
6051
    my $str_product = $ScmProduct ? '$(GBE_PRODUCT)' : '$(GBE_PLATFORM)';
6052
    my $str_target = '$(GBE_TARGET)';
6053
    my $str_common = '$(GBE_OS_COMMON)';
6054
 
6055
    my $str_common_avail = 0;
6056
       $str_common_avail = 1 if ( exists( $::BUILDINFO{$ScmPlatform}{OS_COMMON} ));
6057
 
6058
 
6059
    #
6060
    #   Add requested suffix
6061
    #
6062
    if ($flags & $T_TYPE)
6063
    {
6064
        $str_platform .= '$(GBE_TYPE)';
6065
        $str_product  .= '$(GBE_TYPE)';
6066
        $str_target   .= '$(GBE_TYPE)';
6067
        $str_common   .= '$(GBE_TYPE)';
6068
    }
6069
 
6070
    #
6071
    #   Process the argument
6072
    #
6073
    $_ = $argument;
6074
    if ( /^--Debug/ ) {                         # In the Debug build only
6075
        if ( $ptype ) {
6076
            $$ptype = "D";
6077
            $consumed = 1;
6078
        }
6079
 
6080
    } elsif ( /^--Prod$/ || /^--Production$/ ) { # In the Production build only
6081
        if ( $ptype ) {
6082
            $$ptype = "P";
6083
            $consumed = 1;
6084
        }
6085
 
6086
    } elsif (/^--Prefix=(.*)/) {                # Prefix with subdir
6087
        $dir = "$base/$1";
6088
 
6089
    } elsif (/^--Subdir=(.*)/) {                # same as 'prefix'
6090
        $dir = "$base/$1";
6091
 
6092
    } elsif (/^--Platform$/) {                  # Platform installation
6093
        $dir = "$base/$str_platform";
6094
 
6095
    } elsif (/^--Platform=(.*?),(.*)/) {        # prefix and suffix with platform specific subdir
6096
        $dir = "$base/$1/$str_platform/$2";
6097
 
6098
    } elsif (/^--Platform=(.*)/) {              # prefix with platform specific subdir
6099
        if ($flags & $T_FILE) {
6100
            $dir = "$base/$1/$str_platform";
6101
        } else {
6102
            $dir = "$base/$str_platform/$1";
6103
        }
6104
 
6105
    } elsif (/^--Product$/) {                   # Product installation
6106
        $dir = "$base/$str_product";
6107
 
6108
    } elsif (/^--Product=(.*?),(.*)/) {         # prefix and suffix with product specific subdir
6109
        $dir = "$base/$1/$str_product/$2";
6110
 
6111
    } elsif (/^--Product=(.*)/) {               # prefix with product specific subdir
6112
        if ($flags & $T_FILE) {
6113
            $dir = "$base/$1/$str_product";
6114
        } else {
6115
            $dir = "$base/$str_product/$1";
6116
        }
6117
 
6118
    } elsif (/^--Target$/) {                    # Target installation
6119
        $dir = "$base/$str_target";
6120
 
6121
    } elsif (/^--Target=(.*?),(.*)/) {          # prefix and suffix with target specific subdir
6122
        $dir = "$base/$1/$str_target/$2";
6123
 
6124
    } elsif (/^--Target=(.*)/) {                # prefix with target specific subdir
6125
        if ($flags & $T_FILE) {
6126
            $dir = "$base/$1/$str_target";
6127
        } else {
6128
            $dir = "$base/$str_target/$1";
6129
        }
6130
 
6131
    } elsif (/^--OsCommon/) {
6132
 
6133
        unless ( $str_common_avail ) {
6134
            Warning("Packaging option --OsCommon not supported on this platform($ScmPlatform). Directive skipped");
6135
            $consumed = 2;
6136
 
6137
        } elsif (/^--OsCommon$/) {                  # OS installation
6138
            $dir = "$base/$str_common";
6139
 
6140
        } elsif (/^--OsCommon=(.*?),(.*)/) {        # prefix and suffix with target specific subdir
6141
            $dir = "$base/$1/$str_common/$2";
6142
 
6143
        } elsif (/^--OsCommon=(.*)/) {              # prefix with target specific subdir
6144
            if ($flags & $T_FILE) {
6145
                $dir = "$base/$1/$str_common";
6146
            } else {
6147
                $dir = "$base/$str_common/$1";
6148
            }
6149
        }
6150
 
6151
    } elsif (/^--Derived=(.*?),(.*?),(.*)/) {   # Derived target + prefix + subdir
6152
        $dir = "$base/$2/$1_$str_platform/$3";
6153
 
6154
    } elsif (/^--Derived=(.*?),(.*)/) {         # Derived target + subdir
6155
        if ($flags & $T_FILE) {
6156
            $dir = "$base/$2/$1_$str_platform";
6157
        } else {
6158
            $dir = "$base/$1_$str_platform/$2";
6159
        }
6160
 
6161
    } elsif (/^--Derived=(.*)/) {               # Derived target
6162
        $dir = "$base/$1_$str_platform";
6163
 
6164
    } elsif ($flags & $T_MACH && /^--Machine(([=])(.*))?$/) {   # Allow Machine and Machine=xxx specfic target
6165
        #
6166
        #   Special: Append machine type to user dir
6167
        #            Intended to create tools/bin/win32 and tools/bin/sparc directories
6168
        my $path = ( defined( $3) ) ? "/$3" : "";
6169
        $dir = "$base$path/\$(GBE_HOSTMACH)";
6170
 
6171
    } elsif ($flags & $T_GBE && /^--Gbe(([=])(.*))?$/) {   # Allow Gbe and Gbe=xxx specfic target
6172
        my $path = ( defined( $3) ) ? "/$3" : "";
6173
        $dir = "$base/gbe$path";
6174
 
6175
    } elsif (/^--Dir=(.*)/) {                   # prefix with target specific subdir
6176
        Error ('Packaging directive with --Dir option does not specify a directory.',
6177
               'Possible bad use of option of the form:--Dir=$xxx',
6178
               'Note: Use of package.pl and this construct is deprecated') unless ( $1 );
241 dpurdie 6179
        my $udir = $1;
6180
 
6181
        #
6182
        #   Remove leading ./
6183
        #   Check for leading ../
5568 dpurdie 6184
        #   
6185
        #   Remove any stupid path manipulation elements
6186
        #   
5827 dpurdie 6187
        if ($udir =~ s~^([./]*/)~~)
6188
        {
6189
            Warning("Packaging directive with --Dir option contains path manipulation elements (removed)", "Option: $_");
6190
        }
241 dpurdie 6191
 
227 dpurdie 6192
        if ($flags & $T_PKG) {
241 dpurdie 6193
            $dir = __PkgDir( $udir );
227 dpurdie 6194
        } else {
6387 dpurdie 6195
            $dir = $base . "/" . $udir;
227 dpurdie 6196
        }
6197
    }
6198
 
6199
    return ($consumed) if ($dir eq "");
6200
    $dir =~ s~//~/~g;
6201
    $dir =~ s~/$~~;
6202
    $$pdir = $dir;
6203
    return (1);
6204
}
6205
 
6206
 
6207
#   __PkgDir ---
6208
#       Convert --Dir Package directives, removing leading subdir if
6209
#       matching the global $Pbase value.
6210
#
6211
#       Required as PKGDIR has the value 'GBE_ROOT/pkg/$Pbase'.
6212
#       Required to maintain compatability with older (package.pl) constructs
6213
#..
6214
 
6215
sub __PkgDir
6216
{
6217
    my( $dir ) = @_;
6218
    my $org = $dir;
6219
 
245 dpurdie 6220
    $dir =~ s~^\Q$::Pbase\E[/]?~~;
227 dpurdie 6221
    Debug2( "  PkgDir: converted \"$org\" to \"$dir\"" );
6222
 
6223
    $dir = "\$(PKGDIR)/$dir";
6224
    return $dir;
6225
}
6226
 
6227
 
6228
#   getMajorMinor ---
6229
#       Just a little help to deal with major/minor stuff for shared libs -
6230
#       given the name of the library as the argument, split out major and
6231
#       minor parts and return the basename, i.e name without major and minor
6232
#       and the pair of major and minor.
6233
#..
6234
 
285 dpurdie 6235
sub getMajorMinor
227 dpurdie 6236
{
6237
    my @bits = split ('\.', $_[0]);
6238
    my $stop;
6239
    my $major;
6240
    my $minor;
6241
 
6242
    if ( $#bits > 2 )
6243
    {
6244
        $stop = $#bits - 2;
6245
        $major = $bits[$#bits-1];
6246
        $minor = $bits[$#bits];
6247
    }
6248
    elsif ($#bits > 1)
6249
    {
6250
        $stop = $#bits-1;
6251
        $major = $bits[$#bits];
6252
        $minor=0;
6253
    }
6254
    else
6255
    {
6256
        $stop = $#bits; $major = 1; $minor = 0;
6257
    }
6258
 
6259
    my $base = $bits[0];
6260
    for ( my $i=1; $i <= $stop; $i++ ) {
6261
        $base = join ('.', $base, $bits[$i]);
6262
    }
6263
 
6264
    return ($base, $major, $minor);
6265
}
6266
 
6267
###############################################################################
6268
#
6269
#   Installation
6270
#
6271
 
6272
sub InstallHdr
6273
{
6274
    my( $platforms, @elements ) = @_;
335 dpurdie 6275
    my( $base, $dir, $srcfile, $full, $strip, $package );
227 dpurdie 6276
    my( $len, $name, $basename );
6277
 
6278
    Debug2( "InstallHdr($platforms, @elements)" );
6279
 
6280
    return if ( ! ActivePlatform($platforms) );
6281
    Warning ("InstallHdr: Needs local directory specified in build.pl") unless ( $::ScmLocal );
6282
 
6283
#.. Arguments
6284
#
6285
    $base = $PackageInfo{'Hdr'}{'IBase'};       # Base of target
6286
    $dir = $base . $PackageInfo{'Hdr'}{'Dir'};  # Installation path (default)
335 dpurdie 6287
    $full = $strip = 0;
227 dpurdie 6288
 
285 dpurdie 6289
    foreach ( @elements )
227 dpurdie 6290
    {
6291
                                                # Standard targets
6292
        my $rv = __TargetDir(0, $base, $_, \$dir);
6293
        next if ( $rv == 1 );
6294
        return if ( $rv == 2 );
6295
 
6296
        if (/^--Full/) {                        # using full (resolved) path
6297
            $full = 1;
6298
 
6299
        } elsif (/^--Strip$/) {                 # Strip path from source files
6276 dpurdie 6300
            $strip = -1;
227 dpurdie 6301
 
6276 dpurdie 6302
        } elsif (/^--Strip=(\d+)$/) {           # Strip some f the path from source files
6303
            $strip = $1;
227 dpurdie 6304
                                                # Package
6305
        } elsif (/^--Package$/ || /^--Package=(.*)/) {
6306
            $package = 1;
6307
 
6308
        } elsif (/^--(.*)/) {
6309
            Message( "InstallHdr: unknown option $_ -- ignored\n" );
6310
        }
6311
    }
6312
 
6313
#.. Files
6314
#
285 dpurdie 6315
    foreach ( @elements )
227 dpurdie 6316
    {
6317
        my %package_entry;
6318
        if ( ! /^--(.*)/ )
6319
        {
6320
            $name = $_;
6321
            $basename = StripDir( $name );
335 dpurdie 6322
            if ( !($srcfile = $SRCS{ $basename }) ) {
6323
                $srcfile = $name;
6324
            }
6325
 
227 dpurdie 6326
            if ( $full )
6327
            {
335 dpurdie 6328
                my $subdir = StripFileExt($srcfile);
6329
                $subdir = $1
6330
                    if ( $subdir =~ m~^$ProjectBase/(.*)~ );
6331
                $dir .= '/' . $subdir;
6332
                $dir =~ s~//~/~g;
6333
                $dir =~ s~/./~/~g;
6334
                $dir =~ s~/$~~g;
6335
                $name = $basename;
227 dpurdie 6336
            }
6337
 
6276 dpurdie 6338
            $name = StripPath($name, $strip) if ($strip);
227 dpurdie 6339
 
6340
            Debug( "InstallHdr( $dir/$name, src: $srcfile, dest: $dir)" );
6341
 
6342
            $package_entry{'src'} = $srcfile;
6343
            $package_entry{'dir'} = StripFileExt( "$dir/$name" );
6344
            $INSTALL_HDRS{ "$dir/$name" } = {%package_entry};
6345
        }
6346
    }
6347
 
6348
#.. Package
6349
#
6350
    PackageHdr( @_ )                            # auto package
6351
        if ( $package );
6352
}
6353
 
6354
 
6355
sub InstallLib
6356
{
6357
    my( $platforms, @elements ) = @_;
6358
    my( $base, $dir, $package );
6359
    my( $lib, $strip );
289 dpurdie 6360
    my $org_lib;
227 dpurdie 6361
 
6362
    Debug2( "InstallLib($platforms, @elements)" );
6363
 
6364
    return if ( ! ActivePlatform($platforms) );
6365
    Warning ("InstallLib: Needs local directory specified in build.pl") unless ( $::ScmLocal );
6366
 
6367
#.. Arguments
6368
#
6369
    $base = $PackageInfo{'Lib'}{'IBase'};       # Base of target
6370
    $dir = $base . $PackageInfo{'Lib'}{'Dir'};  # Installation path (default)
6371
 
285 dpurdie 6372
    foreach ( @elements )
227 dpurdie 6373
    {
6374
                                                # Standard targets
6375
        my $rv = __TargetDir(0, $base, $_, \$dir);
6376
        next if ( $rv == 1 );
6377
        return if ( $rv == 2 );
6378
 
6379
        if (/^--Package$/ || /^--Package=(.*)/) {
6380
            $package = 1;
6381
 
6382
        } elsif (/^--Strip$/) {                 # Strip path from source files
6276 dpurdie 6383
            $strip = -1;
227 dpurdie 6384
 
6276 dpurdie 6385
        } elsif (/^--Strip=(\d+)$/) {           # Strip some f the path from source files
6386
            $strip = $1;
6387
 
227 dpurdie 6388
        } elsif (/^--(.*)/) {
6389
            Message( "InstallLib: unknown option $_ -- ignored\n" );
6390
        }
6391
    }
6392
 
6393
#.. Files
6394
#
285 dpurdie 6395
    foreach ( @elements )
227 dpurdie 6396
    {
6397
        my %package_entry;
6398
        if ( ! /^--(.*)/ )
6399
        {
6276 dpurdie 6400
            $_ = StripPath($_, $strip) if ($strip);
289 dpurdie 6401
            $org_lib = $_;                      # Original name
227 dpurdie 6402
 
6403
            if ( $ScmTargetHost eq "Unix" ) {
6404
                $lib = "lib$_";                 # Prefix "lib" ....
6405
                $lib =~ s/^liblib/lib/;         # @LIBS already has lib added
6406
            } else {
6407
                $lib = $_;
6408
            }
6409
 
289 dpurdie 6410
            if (  my $libp = $SHLIBS->Get($lib) )
227 dpurdie 6411
            {
6412
                Debug( "InstallLib( $dir/$lib\$(GBE_TYPE).$::so, " .
6413
                    "src: \$(LIBDIR)/$lib\$(GBE_TYPE).$::so, dest: $dir)" );
6414
 
6415
                #
6416
                #   Create a "placekeeper" entry within $INSTALL_SHLIBS
6417
                #   The exact format of the name of the shared library is
6418
                #   toolset specific. Create an entry to allow the toolset
6419
                #   to extend the packaging information when the shared library
6420
                #   recipe is constructed.
6421
                #
289 dpurdie 6422
                my $ver = $libp->{ VERSION };
227 dpurdie 6423
                my $name = "$dir/$lib.$ver.PlaceKeeper";
6424
 
6425
                $package_entry{'placekeeper'} = 1;
6426
                $package_entry{'version'} = $ver;
6427
                $package_entry{'lib'} = $lib;
6428
                $package_entry{'dir'} = $dir;
289 dpurdie 6429
 
6430
                push @{$SHLIB_INS{$lib}}, $name;
227 dpurdie 6431
                $INSTALL_SHLIBS{$name} = {%package_entry};
6432
            }
6433
 
289 dpurdie 6434
            #
6435
            #   Clean up the package_entry
6436
            #   Insert common items
6437
            #
6438
            %package_entry = ();
6439
            $package_entry{'lib'} = $lib;
6440
            $package_entry{'dir'} = $dir;
6441
 
321 dpurdie 6442
            if ( my $libfile = $SRCS{$org_lib} )
227 dpurdie 6443
            {
6444
                #
6445
                #   Allow the user to package a sourced file as a library
289 dpurdie 6446
                #   But must be the un-massaged name of the file.
227 dpurdie 6447
                #
289 dpurdie 6448
                $package_entry{'dst'} = "$dir/$org_lib";
6449
                $package_entry{'src'} = $libfile;
6450
            }
6451
            elsif ( $LIBS->Get($lib) )
6452
            {
6453
                #
6454
                #   Install a library known to the makefile
6455
                #
6456
                my $libp = $LIBS->Get($lib);
227 dpurdie 6457
 
289 dpurdie 6458
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
6459
                $package_entry{'src'}    = $libp->getPath();
227 dpurdie 6460
            }
289 dpurdie 6461
            elsif ( ! $SHLIBS->Get($lib) )
227 dpurdie 6462
            {
289 dpurdie 6463
                #
6464
                #   Not a known shared lib
6465
                #   Not a known static lib
6466
                #   Not a 'sourced' file
6467
                #   Assume the a static library has magically appeared
6468
                #   in the standard LIB directory. May have been placed there
6469
                #   by a 'rule'
6470
                #
6471
                my $libp = $LIBS->New($lib);
227 dpurdie 6472
 
289 dpurdie 6473
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
6474
                $package_entry{'src'}    = $libp->getPath();
6475
            }
227 dpurdie 6476
 
289 dpurdie 6477
            #
6478
            #   Add entry to various lists if required
6479
            #
6480
            PackageLib_AddEntry ('InstallLib', \%LIB_INS, \%INSTALL_LIBS, \%package_entry )
6481
                if ( exists $package_entry{'dst'} );
227 dpurdie 6482
        }
6483
    }
6484
 
6485
#.. Package
6486
#
6487
    PackageLib( @_ )                            # auto package
6488
        if ( $package );
6489
}
6490
 
6491
 
6492
sub InstallJar
6493
{
6494
    my( $platforms, @elements ) = @_;
6495
    my( $base, $dir, $package );
6496
    my( $jar );
6497
 
6498
    Debug2( "InstallJar($platforms, @elements)" );
6499
 
6500
    return if ( ! ActivePlatform($platforms) );
6501
    Warning ("InstallJar: Needs local directory specified in build.pl") unless ( $::ScmLocal );
6502
 
6503
#.. Arguments
6504
#
6505
    $base = $PackageInfo{'Jar'}{'IBase'};       # Base of target
6506
    $dir = $base . $PackageInfo{'Jar'}{'Dir'};  # Installation path (default)
6507
 
285 dpurdie 6508
    foreach ( @elements )
227 dpurdie 6509
    {
6510
                                                # Standard targets
6511
        my $rv = __TargetDir(0, $base, $_, \$dir);
6512
        next if ( $rv == 1 );
6513
        return if ( $rv == 2 );
6514
 
6515
        if (/^--Package$/ || /^--Package=(.*)/) {
6516
            $package = 1;
6517
 
6518
        } elsif (/^--(.*)/) {
6519
            Message( "InstallJar: unknown option $_ -- ignored\n" );
6520
        }
6521
    }
6522
 
6523
 
6524
#.. Files
6525
#
285 dpurdie 6526
    foreach ( @elements )
227 dpurdie 6527
    {
6528
        my %package_entry;
6529
        if ( ! /^--(.*)/ )
6530
        {
6531
            $jar = $_;
6532
            my $src;
6533
            my $dest;
6534
 
6535
            if ( $JAR_FILES{$jar} )
6536
            {
6537
                $src = $JAR_FILES{$jar};
6538
                $dest = $jar;
6539
            }
6540
            else
6541
            {
6542
                $src = "\$(CLSDIR)/$jar\$(GBE_TYPE).jar";
6543
                $dest = "$jar\$(GBE_TYPE).jar";
6544
            }
6545
 
6546
 
6547
            Debug( "InstallJar( $dir/$dest, " .
6548
                "src: $src, dest: $dir)" );
6549
 
6550
            $package_entry{'src'} = $src;
6551
            $package_entry{'dir'} = $dir;
6552
            $INSTALL_CLSS{ "$dir/$dest" } = {%package_entry};
6553
 
6554
        }
6555
    }
6556
 
6557
#.. Package
6558
#
6559
    PackageJar( @_ )                            # auto package
6560
        if ( $package );
6561
}
6562
 
6563
 
6564
sub InstallProg
6565
{
6566
    my( $platforms, @elements ) = @_;
6567
    my( $base, $dir, $package );
6568
    my( $prog );
6569
 
6570
    Debug2( "InstallProg($platforms, @elements)" );
6571
 
6572
    return if ( ! ActivePlatform($platforms) );
6573
    Warning ("InstallProg: Needs local directory specified in build.pl") unless ( $::ScmLocal );
6574
 
6575
#.. Arguments
6576
#
6577
    $base = $PackageInfo{'Prog'}{'IBase'};       # Base of target
6578
    $dir = $base . $PackageInfo{'Prog'}{'Dir'};  # Installation path (default)
6579
 
285 dpurdie 6580
    foreach ( @elements )
227 dpurdie 6581
    {
6582
                                                # Standard targets
6583
        my $rv = __TargetDir($T_TYPE, $base, $_, \$dir);
6584
        next if ( $rv == 1 );
6585
        return if ( $rv == 2 );
6586
 
6587
        if (/^--Package$/ || /^--Package=(.*)/) {
6588
            $package = 1;
6589
 
6590
        } elsif (/^--(.*)/) {
6591
            Message( "InstallProg: unknown option $_ -- ignored\n" );
6592
        }
6593
    }
6594
 
6595
#.. Files
6596
#
285 dpurdie 6597
    foreach ( @elements )
227 dpurdie 6598
    {
6599
        my %package_entry;
6600
        if ( ! /^--(.*)/ )
6601
        {
6602
            my $ext = "";
6603
            $prog = $_;
6604
 
6605
            #
6606
            #   If the named target is a program then append the correct
6607
            #   extension. Otherwise assume that the target is either a script
6608
            #   or a some other file - and don't append an extension
6609
            #
6610
            $ext = $::exe
289 dpurdie 6611
                if ( $PROGS->Get($prog) );
227 dpurdie 6612
 
6613
            #
6614
            #   A "file" that is specified with a "Src" directive may be
6615
            #   installed as though it were a program
6616
            #
6617
            my $progfile;
6618
            $progfile = "\$(BINDIR)/$prog$ext"
6619
                unless ( $progfile = $SRCS{$prog} );
6620
 
6621
            Debug( "InstallProg( $dir/$prog$ext, " .
6622
                 "src: $progfile, dest: $dir)" );
6623
 
6624
            push @{$PROG_INS{$prog}}, "$dir/$prog$ext";
6625
 
6626
            $package_entry{'src'} = $progfile;
6627
            $package_entry{'dir'} = $dir;
6628
            $INSTALL_PROGS{ "$dir/$prog$ext" } = {%package_entry};
6629
        }
6630
    }
6631
 
6632
#.. Package
6633
#
6634
    PackageProg( @_ )                           # auto package
6635
        if ( $package );
6636
}
6637
 
6276 dpurdie 6638
#-------------------------------------------------------------------------------
6639
# Function        : StripPath 
6640
#
6641
# Description     : Internal function to strip bits from a pathname
6642
#                   Will never strip the filename, even if asked to strip too much
6643
#
6644
# Inputs          : $name       - Name to process
6645
#                   $stripCount - Strip part
6646
#                                 <0 - strip all paths
6647
#                                 =0  - Do nothing
6648
#                                 >0 - Strip count
6649
#
6650
# Returns         : Processed name
6651
#
6652
sub StripPath
6653
{
6654
    my( $name, $stripCount) = @_;
227 dpurdie 6655
 
6276 dpurdie 6656
    if ($stripCount)
6657
    {
6658
        $name =~ s~\\~/~g;
6619 dpurdie 6659
        $name =~ s~//~/~g;
6276 dpurdie 6660
 
6661
        my @items = split('/', $name);
6662
        if ($stripCount > 0)
6663
        {
6664
            my $len = scalar @items;
6665
            my $remove = $stripCount; 
6666
            if ($stripCount >= $len ) {
6667
                $remove = $len - 1;
6668
            }
6669
            splice @items, 0, $remove;
6670
            $name = join('/', @items);
6671
        }
6672
        else
6673
        {
6674
            $name = pop @items;
6675
        }
6676
    }
6677
    return $name;
6678
}
6679
 
6680
 
227 dpurdie 6681
###############################################################################
6682
#
6683
#   Packaging
6684
#
6685
sub PackageDist
6686
{
6687
    my( $name, @elements ) = @_;
6688
 
6689
    Debug2( "PackageDist($name, @elements)" );
6690
 
6691
    foreach ( @elements )
6692
    {
6693
    #.. Distribution sets
6694
    #
6695
        HashJoin( \%PACKAGE_DIST, $;, $name, "$_" );
6696
 
6697
    #.. Summary of distribution sets
6698
    #
267 dpurdie 6699
        $PACKAGE_SETS{ $_ }{'TAG'} = 1
6700
            if ( ! exists $PACKAGE_SETS{ $_ }{'TAG'} );
227 dpurdie 6701
    }
6702
}
6703
 
311 dpurdie 6704
#-------------------------------------------------------------------------------
6387 dpurdie 6705
# Function        : PackageDir 
6706
#                   InstallDir
6707
#
6708
# Description     : Directive to package an entire directory tree
6709
#                   Will package the contents of the directory without regard as to there content
6710
#                   
6711
#                   Differs from PackageFile (... --DirTree ) in that the process is dynamic
6712
#                   It will support the packaging of files that are generated
6713
#                   
6714
#                   NOT intended to support the JATS BIN and LIB structure
6715
#                   It knows nothing of these types of files
6716
#
6717
# Inputs          : platforms   - Active platform list
6718
#                   Options:    - Many from PackageFile
6719
#                       --DirTree=xxx   Source Tree [Mandatory]
6720
#                       --Subdir=yyy    Target [ Mandatory]
6721
#
6722
sub PackageDir { 
6723
    return if ( !$ScmPackage );                 # Packaging enabled ?
6724
    _PackageInstallDir('PackageDir', 'PBase', \@PACKAGE_DIRS, @_);
6725
    }
6726
 
6727
sub InstallDir { 
6728
    Warning ("InstallDir: Needs local directory specified in build.pl") unless ( $::ScmLocal );
6729
    _PackageInstallDir('InstallDir', 'IBase', \@INSTALL_DIRS, @_);
6730
    }
6731
 
6732
sub _PackageInstallDir
6733
{
6734
    my( $cmdName, $tbase, $dirRef, $platforms, @elements ) = @_;
6735
    my( $base, $dir, $path, $type );
6736
    my %data;
6737
 
6738
    Debug2( "$cmdName($platforms, @elements)" );
6739
 
6740
    return if ( ! ActivePlatform($platforms) );
6741
 
6742
#.. Arguments
6743
#
6744
    $base = $PackageInfo{'File'}{$tbase};           # Base of target
6745
    $dir = $base . $PackageInfo{'File'}{'Dir'};     # Installation path (default)
6746
 
6747
    foreach ( @elements )
6748
    {
6749
        my $rv = __TargetDir($T_MACH|$T_GBE|$T_FILE, $base, $_, \$dir, \$type);
6750
        next if ( $rv == 1 );
6751
        return if ( $rv == 2 );
6752
 
6753
        if (/^--Executable$/) {                  # Mark the file as executable
6754
            $data{exefile} = "X";
6755
 
6756
        } elsif (/^--PreserveSymlink/i) {        # Preserve symlink to local file
6757
            delete $data{noPreserveSymlink};
6758
 
6759
        } elsif (/^--NoPreserveSymlink/i) {      # Preserve symlink to local file
6760
            $data{noPreserveSymlink} = 1;
6761
 
6762
        } elsif ( /^--DirTree=(.*)/ ) {
6763
            Error("DirTree. Multiple directories not allowed.") if ( $data{dirTree} );
6764
            $data{dirTree} =  $1;
6765
 
6766
        } elsif ( /^--FilterOut=(.*)/ ) {
6767
            push @{$data{exclude}}, $1;
6768
 
6769
        } elsif ( /^--FilterIn=(.*)/ ) {
6770
            push @{$data{include}}, $1;
6771
 
6772
        } elsif ( /^--FilterOutRe=(.*)/ ) {
6773
            push @{$data{excludeRe}}, $1;
6774
 
6775
        } elsif ( /^--FilterInRe=(.*)/ ) {
6776
            push @{$data{includeRe}}, $1;
6777
 
6778
        } elsif ( /^--StripDir/ ) {
6779
            $data{strip_base} = 1;
6780
 
6781
        } elsif ( m/^--Recurse/ ) {
6782
            delete $data{noRecurse};
6783
 
6784
        } elsif ( m/^--NoRecurse/ ) {
6785
            $data{noRecurse} = 1;
6786
 
6787
        } elsif (/^--(.*)/) {
6788
            Message( "$cmdName: unknown option $_ -- ignored\n" );
6789
        }
6790
    }
6791
    Error("DirTree. No path specified") unless ( defined($data{dirTree}) && $data{dirTree} ne "" );
6792
    Debug2( "$cmdName. Raw DirTree: $data{dirTree}" );
6793
 
6794
    # Prevent the user from escaping from the current directory
6795
    Error("$cmdName. Absolute paths are not allowed",
6796
          "Directory: $data{dirTree}") if ( $data{dirTree} =~ m~^/~ || $data{dirTree} =~ m~^.\:~ );
6797
 
6798
    #
6799
    #   Convert the relative path to one that is truely relative to the current
6800
    #   directory. This may occur when the user uses $ProjectBase
6801
    #
6802
    my $abs_dir_tree = AbsPath($data{dirTree});
6803
    $data{dirTree} = RelPath($abs_dir_tree);
6804
 
6805
    #
6806
    #   Ensure that the user is not trying to escape the package
6807
    #   Don't allow the user to attempt to package the entire package either
6808
    #
6809
    #   Calculate the relative path from $ProjectBase to the target directory
6810
    #   It must not be above the $ProjectBase 
6811
    #
6812
    if ( $data{dirTree} =~ m~^\.\.~)
6813
    {
6814
        my $dirFromBase = RelPath($abs_dir_tree, AbsPath($ProjectBase));
6815
        Error("$cmdName. DirTree cannot extend outside current package.",
6816
              "Directory: $dirFromBase") if ( $dirFromBase =~ m~\.\.~ );
6817
        Error("$cmdName. DirTree cannot package entire package.",
6818
            "Directory: $dirFromBase") if ( $dirFromBase eq '.' );
6819
    }
6820
 
6821
    Debug( "$cmdName( $data{dirTree}");
6822
    $data{dir} = $dir;
6823
    $data{type} = $type if defined $type;
6824
    #DebugDumpData("$cmdName", \%data);
6825
    push @{$dirRef}, \%data;
6826
}
6827
 
6828
#-------------------------------------------------------------------------------
311 dpurdie 6829
# Function        : PackageFile
6830
#
6831
# Description     : Directive to package files
6832
#                   Not to be used to package libraries, executables, headers
6833
#                   as this should be done by specialised directives
6834
#
6835
#                   Use to package other files
6836
#                   Can package an entire tree (ugly)
6837
#
6838
# Inputs          : 
6839
#
6840
#
227 dpurdie 6841
sub PackageFile
6842
{
6843
    my( $platforms, @elements ) = @_;
335 dpurdie 6844
    my( $base, $dir, $full, $path, $dist, $strip, $exefile, $type );
227 dpurdie 6845
    my( $name, $basename, $len, $srcfile );
4257 dpurdie 6846
    my( $dir_tree, @dir_tree_exclude, @dir_tree_include, $strip_base, $strip_dots );
335 dpurdie 6847
    my $recurse = 1;
6133 dpurdie 6848
    my $preserveSymlink = 0;
227 dpurdie 6849
 
6850
    Debug2( "PackageFile($platforms, @elements)" );
6851
 
6852
    return if ( !$ScmPackage );                 # Packaging enabled ?
6853
    return if ( ! ActivePlatform($platforms) );
6854
 
6855
#.. Arguments
6856
#
6857
    $dist = "ALL";                                  # Default set (ALL)
6858
    $base = $PackageInfo{'File'}{'PBase'};          # Base of target
6859
    $dir = $base . $PackageInfo{'File'}{'Dir'};     # Installation path (default)
335 dpurdie 6860
    $full = 0;
227 dpurdie 6861
    $strip = 0;
341 dpurdie 6862
    $strip_base = 0;
4257 dpurdie 6863
    $strip_dots = 0;
227 dpurdie 6864
    $exefile = 0;
6865
 
285 dpurdie 6866
    foreach ( @elements )
227 dpurdie 6867
    {
6868
        my $rv = __TargetDir($T_PKG|$T_MACH|$T_GBE|$T_FILE, $base, $_, \$dir, \$type);
6869
        next if ( $rv == 1 );
6870
        return if ( $rv == 2 );
6871
 
6872
        if (/^--Full/) {                        # Using full (resolved) path
6873
            $full = 1;
6874
 
6875
        } elsif (/^--Set=(.*)/) {               # Distribution set
6876
            $dist = "$1";
6877
 
6878
        } elsif (/^--Package$/) {               # Package .. call by InstallFile
6879
        } elsif (/^--Package=(.*)/) {
6880
            $dist = "$1";
6881
 
6882
        } elsif (/^--Strip$/) {                 # Strip path from source files
6276 dpurdie 6883
            $strip = -1;
227 dpurdie 6884
 
6294 dpurdie 6885
        } elsif (/^--Strip=(\d+)$/) {           # Strip path from source files
6276 dpurdie 6886
            $strip = $1;
6887
 
227 dpurdie 6888
        } elsif (/^--Executable$/) {            # Mark the file as executable
6889
            $exefile = "X";
6890
 
6133 dpurdie 6891
        } elsif (/^--PreserveSymlink/i) {       # Preserve symlink to local file
6892
            $preserveSymlink = 1;
6893
 
227 dpurdie 6894
        } elsif ( /^--DirTree=(.*)/ ) {
6895
            Error("DirTree. Multiple directories not allowed.") if ( $dir_tree );
4163 dpurdie 6896
            $dir_tree =  $1;
4257 dpurdie 6897
            Error("DirTree. No path specified") unless ( defined($dir_tree) && $dir_tree ne "" );
227 dpurdie 6898
 
4163 dpurdie 6899
            # Prevent the user from escaping from the current directory
6900
            Error("DirTree. Absolute paths are not allowed",
6901
                  "Directory: $dir_tree") if ( $dir_tree =~ m~^/~ || $dir_tree =~ m~^.\:~ );
6902
 
6903
            #
6904
            #   Convert the relative path to one that is truely relative to the current
6905
            #   directory. This may occur when the user uses $ProjectBase
6906
            #
4257 dpurdie 6907
            my $abs_dir_tree = AbsPath($dir_tree);
6908
            $dir_tree = RelPath($abs_dir_tree);
6909
 
6910
            #
6911
            #   Ensure that the user is not trying to escape the package
4265 dpurdie 6912
            #   Don't allow the user to attempt to package the entire package either
4257 dpurdie 6913
            #
6914
            #   Calculate the relative path from $ProjectBase to the target directory
6915
            #   It must not be above the $ProjectBase 
6916
            #
4265 dpurdie 6917
            if ( $dir_tree =~ m~^\.\.~)
6918
            {
6919
                my $dirFromBase = RelPath($abs_dir_tree, AbsPath($ProjectBase));
6920
                Error("DirTree cannot extend outside current package.",
6921
                      "Directory: $dirFromBase") if ( $dirFromBase =~ m~\.\.~ );
6922
                Error("DirTree cannot package entire package.",
6923
                    "Directory: $dirFromBase") if ( $dirFromBase eq '.' );
6924
            }
4257 dpurdie 6925
 
4163 dpurdie 6926
            Debug2( "PackageFile. DirTree: $dir_tree" );
6927
 
227 dpurdie 6928
            Error("DirTree. Directory not found",
6929
                  "Directory: $dir_tree") unless  ( -d $dir_tree );
6930
 
4257 dpurdie 6931
            # If packaging a parent directory then force dot_stripping of the base directory
6932
            # strip_base will have precedence if both are active
6933
            if ( $dir_tree =~ m~\.\.~ )
6934
            {
6935
                $dir_tree =~ m~(\.\./)+~;
6936
                $strip_dots = length($1);
6937
            }
6938
 
227 dpurdie 6939
        } elsif ( /^--FilterOut=(.*)/ ) {
6940
            push @dir_tree_exclude, $1;
6941
 
6942
        } elsif ( /^--FilterIn=(.*)/ ) {
6943
            push @dir_tree_include, $1;
6944
 
6945
        } elsif ( /^--StripDir/ ) {
341 dpurdie 6946
            $strip_base = 1;
227 dpurdie 6947
 
335 dpurdie 6948
        } elsif ( m/^--Recurse/ ) {
6949
            $recurse = 1;
6950
 
6951
        } elsif ( m/^--NoRecurse/ ) {
6952
            $recurse = 0;
6953
 
227 dpurdie 6954
        } elsif (/^--(.*)/) {
6955
            Message( "PackageFile: unknown option $_ -- ignored\n" );
6956
        }
6957
    }
6958
 
6959
 
6960
    #.. DirTree expansion
6961
    #   Note: Uses REs, not simple globs
6962
    #         Use JatsLocateFiles to do the hard work
6963
    if ( $dir_tree )
6964
    {
335 dpurdie 6965
        my $search = JatsLocateFiles->new('FullPath' );
6966
        $search->recurse($recurse);
227 dpurdie 6967
        $search->filter_in_re ( $_ ) foreach ( @dir_tree_include );
6968
        $search->filter_out_re( $_ ) foreach ( @dir_tree_exclude );
1431 dpurdie 6969
        $search->filter_out_re( '/\.svn/' );
5848 dpurdie 6970
        $search->filter_out_re( '/\.git/' );
227 dpurdie 6971
        @elements = $search->search ( $dir_tree );
4257 dpurdie 6972
        if ($strip_base){
6973
            $strip_base = length( $dir_tree ) if ( $strip_base );
6974
        } elsif ($strip_dots) {
6975
            $strip_base = $strip_dots;
6976
        }
6403 dpurdie 6977
    } else {
6978
        $strip_base = 0;
227 dpurdie 6979
    }
6980
 
6981
#.. Files
6982
#
285 dpurdie 6983
    foreach ( @elements )
227 dpurdie 6984
    {
6985
        my %package_entry;
299 dpurdie 6986
        $name = $_;
6133 dpurdie 6987
        my $symlink;
299 dpurdie 6988
 
227 dpurdie 6989
        #
299 dpurdie 6990
        #   Trap special files
6991
        #       DPACKAGE - but only if we have a DPackageLibrary directive
6992
        #                  in the same makefile.
6993
        #
6994
        if ( m~^DPACKAGE$~ && $DPackageDirective ) {
6995
            $name = 'DPACKAGE.' . $::GBE_MACHTYPE;
6996
        }
6997
 
227 dpurdie 6998
        if ( ! /^--(.*)/ )
6999
        {
7000
            $basename = StripDir( $name );
335 dpurdie 7001
            if ( !($srcfile = $SRCS{ $basename }) ) {
7002
                $srcfile = $name;
7003
            }
7004
 
227 dpurdie 7005
            if ( $full )
7006
            {
335 dpurdie 7007
                my $subdir = StripFileExt($srcfile);
7008
                $subdir = $1
7009
                    if ( $subdir =~ m~^$ProjectBase/(.*)~ );
7010
                $dir .= '/' . $subdir;
7011
                $dir =~ s~//~/~g;
7012
                $dir =~ s~/./~/~g;
7013
                $dir =~ s~/$~~g;
7014
                $name = $basename;
227 dpurdie 7015
            }
6276 dpurdie 7016
            $name = StripPath($name, $strip) if ($strip);
227 dpurdie 7017
 
341 dpurdie 7018
            if ( $strip_base )
7019
            {
7020
                $name = substr $name, $strip_base;
7021
                $name =~ s~^/~~;
7022
            }
7023
 
227 dpurdie 7024
            $dir =~ s~//~/~g;
7025
            $dir =~ s~/$~~;
7026
 
7027
            #
6133 dpurdie 7028
            #   Preserve Symlink
7029
            #
7030
            if ($preserveSymlink && -l $srcfile)
7031
            {
7032
                $symlink = 1;
7033
            }
7034
 
7035
            #
227 dpurdie 7036
            #   Sanity test the source filename
7037
            #   User may have misused an option
7038
            #
6387 dpurdie 7039
            if ( !$dir_tree && ( ( $srcfile =~ m/=/ ) || ( $srcfile =~ m/^-/ ) || ( $srcfile =~ m~/-~ ))  )
227 dpurdie 7040
            {
7041
               Warning ("PackageFile: Suspect source filename: $srcfile");
7042
            }
7043
 
7044
            Debug( "PackageFile( $dir/$name, " .
7045
                "src: $srcfile, dest: $dir, dist: $dist, exe: $exefile )" );
7046
 
7047
            $package_entry{'src'} = $srcfile;
7048
            $package_entry{'dir'} = StripFileExt( "$dir/$name" );
7049
            $package_entry{'set'} = $dist;
7050
            $package_entry{'exe'} = $exefile if $exefile;
7051
            $package_entry{'type'} = $type if ( $type );
6133 dpurdie 7052
            $package_entry{'symlink'} = 1 if ( $symlink );
227 dpurdie 7053
 
7054
            $PACKAGE_FILES{ "$dir/$name" } = {%package_entry};
7055
        }
7056
    }
7057
}
7058
 
7059
sub PackageHdr
7060
{
7061
    my( $platforms, @elements ) = @_;
335 dpurdie 7062
    my( $base, $dir, $full, $path, $dist, $strip );
227 dpurdie 7063
    my( $name, $basename, $len, $srcfile );
7064
 
7065
    Debug2( "PackageHdr($platforms, @elements)" );
7066
 
7067
    return if ( !$ScmPackage );                 # Packaging enabled ?
7068
    return if ( ! ActivePlatform($platforms) );
7069
 
7070
#.. Arguments
7071
#
7072
    $dist = "ALL";                                  # Default set (ALL)
7073
    $base = $PackageInfo{'Hdr'}{'PBase'};           # Base of target
7074
    $dir = $base . $PackageInfo{'Hdr'}{'Dir'};      # Installation path (default)
335 dpurdie 7075
    $full = 0;
227 dpurdie 7076
    $strip = 0;
7077
 
285 dpurdie 7078
    foreach ( @elements )
227 dpurdie 7079
    {
7080
        my $rv = __TargetDir($T_PKG, $base, $_, \$dir);
7081
        next if ( $rv == 1 );
7082
        return if ( $rv == 2 );
7083
 
7084
        if (/^--Full/) {                        # Using full (resolved) path
7085
            $full = 1;
7086
 
7087
        } elsif (/^--Set=(.*)/) {               # Distribution set
7088
            $dist = "$1";
7089
 
7090
        } elsif (/^--Package$/) {               # Package .. call by InstallHdr
7091
        } elsif (/^--Package=(.*)/) {
7092
            $dist = "$1";
7093
 
7094
        } elsif (/^--Strip$/) {                 # Strip path from source files
6276 dpurdie 7095
            $strip = -1;
227 dpurdie 7096
 
6276 dpurdie 7097
        } elsif (/^--Strip=(\d+)$/) {           # Strip some f the path from source files
7098
            $strip = $1;
7099
 
227 dpurdie 7100
        } elsif (/^--(.*)/) {
7101
            Message( "PackageHdr: unknown option $_ -- ignored\n" );
7102
        }
7103
    }
7104
 
7105
#.. Files
7106
#
285 dpurdie 7107
    foreach ( @elements )
227 dpurdie 7108
    {
7109
        my %package_entry;
7110
        if ( ! /^--(.*)/ )
7111
        {
5991 dpurdie 7112
            $name = $_;
227 dpurdie 7113
            $basename = StripDir( $name );
335 dpurdie 7114
            if ( !($srcfile = $SRCS{ $basename }) ) {
7115
                $srcfile = $name;
7116
            }
7117
 
227 dpurdie 7118
            if ( $full )
7119
            {
335 dpurdie 7120
                my $subdir = StripFileExt($srcfile);
7121
                $subdir = $1
7122
                    if ( $subdir =~ m~^$ProjectBase/(.*)~ );
7123
                $dir .= '/' . $subdir;
7124
                $dir =~ s~//~/~g;
7125
                $dir =~ s~/./~/~g;
7126
                $dir =~ s~/$~~g;
7127
                $name = $basename;
227 dpurdie 7128
            }
7129
 
6276 dpurdie 7130
            $name = StripPath($name, $strip) if ($strip);
227 dpurdie 7131
 
7132
            Debug( "PackageHdr( $dir/$name, " .
7133
                "src: $srcfile, dest: $dir, dist: $dist )" );
7134
 
7135
            $package_entry{'src'} = $srcfile;
7136
            $package_entry{'dir'} = StripFileExt( "$dir/$name" );
7137
            $package_entry{'set'} = $dist;
7138
 
7139
            $PACKAGE_HDRS{ "$dir/$name" } = {%package_entry};
7140
        }
7141
    }
7142
}
7143
 
7144
 
7145
sub PackageLib
7146
{
7147
    my( $platforms, @elements ) = @_;
7148
    my( $base, $dir, $dist, $type );
7149
    my( $lib, $org_lib, %extras, $strip );
7150
 
7151
    Debug2( "PackageLib($platforms, @elements)" );
7152
 
7153
    return if ( !$ScmPackage );                 # Packaging enabled ?
7154
    return if ( ! ActivePlatform($platforms) );
7155
 
7156
#.. Arguments
7157
#
7158
    $dist = "ALL";                              # Default set (ALL)
7159
    $base = $PackageInfo{'Lib'}{'PBase'};       # Base of target
7160
    $dir = $base . $PackageInfo{'Lib'}{'Dir'};  # Installation path (default)
7161
    $type = "";
7162
 
285 dpurdie 7163
    foreach ( @elements )
227 dpurdie 7164
    {
7165
                                                # Standard targets
7166
        my $rv = __TargetDir($T_PKG, $base, $_, \$dir, \$type);
7167
        next if ( $rv == 1 );
7168
        return if ( $rv == 2 );
7169
 
7170
        if (/^--Set=(.*)/) {                    # Distribution set(s)
7171
            $dist = "$1";
7172
 
7173
        } elsif (/^--Package$/) {               # Package .. call by PackageLib
7174
        } elsif (/^--Package=(.*)/) {
7175
            $dist = "$1";
7176
 
7177
        } elsif (/^--Extras=(.*)/) {            # Extras=[none, .. ,all]
7178
            foreach my $elem ( split( ',', $1 ) )
7179
            {
7180
                Error ("PackageLib: Unknown Extras mode: $elem")
7181
                    unless ( grep m/$elem/, qw(none stub map lint debug all) );
7182
                $extras{$elem} = 1;
7183
            }
7184
            %extras = () if ( $extras{'all'} );
7185
 
7186
        } elsif (/^--Strip$/) {                 # Strip path from source files
6276 dpurdie 7187
            $strip = -1;
227 dpurdie 7188
 
6276 dpurdie 7189
        } elsif (/^--Strip=(\d+)$/) {           # Strip some f the path from source files
7190
            $strip = $1;
7191
 
227 dpurdie 7192
        } elsif (/^--(.*)/) {
7193
            Message( "PackageLib: unknown option $_ -- ignored\n" );
7194
        }
7195
    }
7196
 
7197
#.. Files
7198
#
285 dpurdie 7199
    foreach ( @elements )
227 dpurdie 7200
    {
7201
        my %package_entry;
7202
        if ( ! /^--(.*)/ )
7203
        {
6276 dpurdie 7204
            $_ = StripPath($_, $strip) if ($strip);
227 dpurdie 7205
 
7206
            $org_lib = $_;                      # Original name
7207
            if ( $ScmTargetHost eq "Unix" ) {
7208
                $lib = "lib$_";                 # Prefix "lib" ....
7209
                $lib =~ s/^liblib/lib/;         # @LIBS already has lib added
7210
            } else {
7211
                $lib = $_;
7212
            }
7213
 
289 dpurdie 7214
            if (  my $libp = $SHLIBS->Get($lib) )
227 dpurdie 7215
            {
7216
                Debug( "PackageLib( $dir/$lib\$(GBE_TYPE).$::so, " .
7217
                    "src: \$(LIBDIR)/$lib\$(GBE_TYPE).$::so, dest: $dir, dist: $dist, type: $type )" );
7218
 
7219
                #
7220
                #   Create a "placekeeper" entry within $PACKAGE_SHLIBS
7221
                #   The exact format of the name of the shared library is
7222
                #   toolset specific. Create an entry to allow the toolset
7223
                #   to extend the packaging information when the shared library
7224
                #   recipe is constructed.
7225
                #
7226
                #
289 dpurdie 7227
                my $ver = $libp->{ VERSION };
227 dpurdie 7228
                my $name = "$dir/$lib.$ver.PlaceKeeper";
7229
 
7230
                $package_entry{'placekeeper'} = 1;
7231
                $package_entry{'version'} = $ver;
7232
                $package_entry{'lib'} = $lib;
7233
                $package_entry{'dir'} = $dir;
7234
                $package_entry{'set'} = $dist;
7235
                $package_entry{'type'} = $type if ( $type );
7236
                $package_entry{'extras'} = {%extras} if ( scalar %extras );
289 dpurdie 7237
 
7238
                push @{$SHLIB_PKG{$lib}}, $name;
227 dpurdie 7239
                $PACKAGE_SHLIBS{$name} = {%package_entry};
7240
            }
7241
 
289 dpurdie 7242
            #
7243
            #   Clean up the package_entry
7244
            #   Insert common items
7245
            #
7246
            %package_entry = ();
7247
            $package_entry{'lib'} = $lib;
7248
            $package_entry{'dir'} = $dir;
7249
            $package_entry{'set'} = $dist;
7250
            $package_entry{'extras'} = {%extras} if ( scalar %extras );
7251
            $package_entry{'type'} = $type if ( $type );
7252
 
227 dpurdie 7253
            if ( my $libfile = $SRCS{$org_lib} )
7254
            {
7255
                #
7256
                #   Allow the user to package a sourced file as a library
7257
                #   But must be the un-massaged name of the file.
7258
                #
5991 dpurdie 7259
                $package_entry{'dst'} = "$dir/$org_lib";
7260
                $package_entry{'src'} = $libfile;
289 dpurdie 7261
            }
7262
            elsif ( $LIBS->Get($lib) )
7263
            {
7264
                #
7265
                #   Package up a library known to the makefile
7266
                #
7267
                my $libp = $LIBS->Get($lib);
227 dpurdie 7268
 
289 dpurdie 7269
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
7270
                $package_entry{'src'}    = $libp->getPath();
227 dpurdie 7271
            }
289 dpurdie 7272
            elsif ( ! $SHLIBS->Get($lib) )
227 dpurdie 7273
            {
289 dpurdie 7274
                #
7275
                #   Not a known shared lib
7276
                #   Not a known static lib
7277
                #   Not a 'sourced' file
7278
                #   Assume the a static library has magically appeared
7279
                #   in the standard LIB directory. May have been placed there
7280
                #   by a 'rule'
7281
                #
7282
                my $libp = $LIBS->New($lib);
227 dpurdie 7283
 
289 dpurdie 7284
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
7285
                $package_entry{'src'}    = $libp->getPath();
7286
            }
227 dpurdie 7287
 
289 dpurdie 7288
            #
7289
            #   Add entry to various lists if required
7290
            #
7291
            PackageLib_AddEntry ('PackageLib', \%LIB_PKG, \%PACKAGE_LIBS, \%package_entry )
7292
                if ( exists $package_entry{'dst'} );
227 dpurdie 7293
        }
7294
    }
7295
}
7296
 
289 dpurdie 7297
#-------------------------------------------------------------------------------
7298
# Function        : PackageLib_AddEntry
7299
#
7300
# Description     : Helper function to add a package entry
7301
#                   to the lists
7302
#
7303
# Inputs          : $directive          - Directive name
7304
#                   $pList              - Ref to array list to maintain
7305
#                   $pHash              - Ref to hash to maintain
7306
#                   $pData              - Packaging Data
7307
#                                         Must Take a copy.
7308
#
7309
# Returns         : 
7310
#
227 dpurdie 7311
 
289 dpurdie 7312
sub PackageLib_AddEntry
7313
{
7314
    my ($directive, $pList, $pHash, $pData) = @_;
7315
 
7316
    my $lib = delete $pData->{'lib'};
7317
    my $dst = delete $pData->{'dst'};
7318
 
7319
    Error ("INTERNAL PackageLib_AddEntry: lib or dst not defined")
7320
        unless ( $lib && $dst );
7321
 
7322
    Debug( "$directive( ",$dst,
7323
            ", src: " ,$pData->{'src'},
7324
            ", dest: ",$pData->{'dir'},
7325
            ", dist: ",$pData->{'set'},
7326
            ", type: ",$pData->{'type'} || '',
7327
            " )" );
7328
 
7329
    push @{$pList->{$lib }}, $dst;
7330
    $pHash->{$dst } = {%$pData};
7331
}
7332
 
7333
 
227 dpurdie 7334
sub PackageProg
7335
{
7336
    my( $platforms, @elements ) = @_;
7337
    my( $base, $dir, $dist, $type );
7338
    my( $prog, %extras, $strip );
7339
 
7340
    Debug2( "PackageProg($platforms, @elements)" );
7341
 
7342
    return if ( !$ScmPackage );                 # Packaging enabled ?
7343
    return if ( ! ActivePlatform($platforms) );
7344
 
7345
#.. Arguments
7346
#
7347
    $dist = "ALL";                              # Default set (ALL)
7348
    $base = $PackageInfo{'Prog'}{'PBase'};       # Base of target
7349
    $dir = $base . $PackageInfo{'Prog'}{'Dir'};  # Installation path (default)
7350
    $type = "";
7351
 
285 dpurdie 7352
    foreach ( @elements )
227 dpurdie 7353
    {
7354
                                                # Standard targets
7355
        my $rv = __TargetDir($T_PKG|$T_TYPE, $base, $_, \$dir, \$type);
7356
        next if ( $rv == 1 );
7357
        return if ( $rv == 2 );
7358
 
7359
        if (/^--Set=(.*)/) {                    # Distribution set(s)
7360
            $dist = "$1";
7361
 
7362
        } elsif (/^--Package$/) {               # Package .. call by PackageLib
7363
        } elsif (/^--Package=(.*)/) {
7364
            $dist = "$1";
7365
 
7366
        } elsif (/^--Tool(([=])(.*))?$/) {      # Allow Tool and Tool=xxx specfic target
7367
            my $path = ( defined( $3) ) ? "/$3" : "";
261 dpurdie 7368
            $dir = "\$(PKGDIR)$path/\$(GBE_HOSTMACH)";
227 dpurdie 7369
 
7370
        } elsif (/^--Extras=(.*)/) {            # Extras=[none, .. ,all]
7371
            foreach my $elem ( split( ',', $1 ) )
7372
            {
7373
                Error ("PackageLib: Unknown Extras mode: $elem")
7374
                    unless ( grep m/$elem/, qw(none stub map lint debug all) );
7375
                $extras{$elem} = 1;
7376
            }
7377
            %extras = () if ( $extras{'all'} );
7378
 
7379
        } elsif (/^--Strip$/) {                 # Strip path from source files
6276 dpurdie 7380
            $strip = -1;
227 dpurdie 7381
 
6276 dpurdie 7382
        } elsif (/^--Strip=(\d+)$/) {           # Strip some f the path from source files
7383
            $strip = $1;
7384
 
227 dpurdie 7385
        } elsif (/^--(.*)/) {
7386
            Message( "PackageProg: unknown option $_ -- ignored\n" );
7387
        }
7388
    }
7389
 
7390
#.. Files
7391
#
285 dpurdie 7392
    foreach ( @elements )
227 dpurdie 7393
    {
7394
        my %package_entry;
7395
        if ( m~descpkg~ ) {
7396
            PackageFile($platforms, @elements);
7397
 
7398
        } elsif ( ! /^--(.*)/ ) {
6276 dpurdie 7399
            $_ = StripPath($_, $strip) if ($strip);
227 dpurdie 7400
 
7401
            my $ext = "";
7402
            $prog = $_;
7403
 
7404
            #
7405
            #   If the named target is a program then append the correct
7406
            #   extension. Otherwise assume that the target is either a script
7407
            #   or a some other file - and don't append an extension
7408
            #
7409
            #   A program may not have any object files, only libraries
7410
            #
7411
            $ext = $::exe
289 dpurdie 7412
                if ( $PROGS->Get($prog) );
227 dpurdie 7413
 
7414
            #
7415
            #   A "file" that is specified with a "Src" directive may be
7416
            #   installed as though it were a program
7417
            #
7418
            my $progfile;
387 dpurdie 7419
            if ( $progfile = $SRCS{$prog} )
7420
            {
5991 dpurdie 7421
                $progfile = $progfile;
7422
                $prog = $prog;
387 dpurdie 7423
            }
7424
            else
7425
            {
7426
                $progfile = "\$(BINDIR)/$prog$ext";
7427
            }
227 dpurdie 7428
 
7429
            Debug( "PackageProg( $dir/$prog$ext, " .
7430
                 "src: $progfile, dest: $dir, dist: $dist, type: $type )" );
7431
 
7432
            my $target = "$dir/$prog$ext";
7433
            push @{$PROG_PKG{$prog}}, $target;
7434
 
7435
            $package_entry{'src'}   = $progfile;
7436
            $package_entry{'dir'}   = $dir;
7437
            $package_entry{'set'}   = $dist;
7438
            $package_entry{'extras'}= {%extras} if ( scalar %extras );
7439
            $package_entry{'type'}  = $type if ( $type );
7440
 
7441
            $PACKAGE_PROGS{$target} = {%package_entry};
7442
        }
7443
    }
7444
}
7445
 
7446
 
7447
sub PackageJar
7448
{
7449
    my( $platforms, @elements ) = @_;
7450
    my( $base, $dir, $dist, $type );
7451
    my( $jar );
7452
 
7453
    Debug2( "PackageJar($platforms, @elements)" );
7454
 
7455
    return if ( !$ScmPackage );                 # Packaging enabled ?
7456
    return if ( ! ActivePlatform($platforms) );
7457
 
7458
#.. Arguments
7459
#
7460
    $dist = "ALL";                              # Default set (ALL)
7461
    $base = $PackageInfo{'Jar'}{'PBase'};       # Base of target
7462
    $dir = $base . $PackageInfo{'Jar'}{'Dir'};  # Installation path (default)
7463
    $type = "";
7464
 
285 dpurdie 7465
    foreach ( @elements )
227 dpurdie 7466
    {
7467
                                                # Standard targets
7468
        my $rv = __TargetDir($T_PKG, $base, $_, \$dir, \$type);
7469
        next if ( $rv == 1 );
7470
        return if ( $rv == 2 );
7471
 
7472
        if (/^--Set=(.*)/) {                    # Distribution set(s)
7473
            $dist = "$1";
7474
 
7475
        } elsif (/^--Package$/) {               # Package .. call by InstallJar
7476
        } elsif (/^--Package=(.*)/) {
7477
            $dist = "$1";
7478
 
7479
        } elsif (/^--(.*)/) {
7480
            Message( "PackageJar: unknown option $_ -- ignored\n" );
7481
        }
7482
    }
7483
 
7484
#.. Files
7485
#
285 dpurdie 7486
    foreach ( @elements )
227 dpurdie 7487
    {
7488
        my %package_entry;
7489
        if ( ! /^--(.*)/ )
7490
        {
7491
            $jar = $_;
7492
            my $src;
7493
            my $dest;
7494
 
7495
            if ( $JAR_FILES{$jar} )
7496
            {
7497
                $src = $JAR_FILES{$jar};
7498
                $dest = $jar;
7499
            }
7500
            else
7501
            {
7502
                $src = "\$(CLSDIR)/$jar\$(GBE_TYPE).jar";
7503
                $dest = "$jar\$(GBE_TYPE).jar";
7504
            }
7505
 
7506
 
7507
            Debug( "PackageJar( $dir/$dest, " .
7508
                "src: $src, dest: $dir, dist: $dist, type: $type )" );
7509
 
7510
            $package_entry{'src'} = $src;;
7511
            $package_entry{'dir'} = $dir;
7512
            $package_entry{'set'} = $dist;
7513
            $package_entry{'type'} = $type if ( $type );
7514
 
7515
            $PACKAGE_CLSS{ "$dir/$dest" } = {%package_entry};
7516
 
7517
        }
7518
    }
7519
}
7520
 
7521
#-------------------------------------------------------------------------------
7522
# Function        : PackageProgAddFiles         - Add files to a PackageProg
7523
#                   PackageLibAddFiles          - Add files to a PackageLib
7524
#                   PackageShlibAddFiles        - Add files to a PackageLib (shared lib)
7525
#                   PackageShlibAddLibFiles     - Add files to a PackageLib (shared lib)
7526
#                                                 Add static library files
7527
#
7528
# Description     : Add files to a Program package or installation
7529
#                   For use by Tool sets to allow additional files to be
7530
#                   packaged with a program.
7531
#
7532
#                   The files are only added if the named program is being
7533
#                   packaged and/or installed.
7534
#
7535
#
7536
# Inputs          : prog        - program identifier
7537
#                   file        - A file to be add
7538
#                   args        - Additional packageing arguments
7539
#
7540
# Returns         : Nothing
7541
#
7542
 
7543
sub PackageProgAddFiles
7544
{
7545
    Debug("PackageProgAddFiles");
7546
 
7547
    PackageAddFiles ( \%PACKAGE_PROGS, \%PACKAGE_PROGS, \%PROG_PKG, @_);
7548
    PackageAddFiles ( \%INSTALL_PROGS, \%INSTALL_PROGS, \%PROG_INS, @_);
7549
}
7550
 
7551
sub PackageLibAddFiles
7552
{
7553
    Debug("PackageLibAddFiles");
7554
 
7555
    PackageAddFiles ( \%PACKAGE_LIBS, \%PACKAGE_LIBS, \%LIB_PKG, @_ );
7556
    PackageAddFiles ( \%INSTALL_LIBS, \%INSTALL_LIBS, \%LIB_INS, @_ );
7557
}
7558
 
7559
sub PackageShlibAddFiles
7560
{
7561
    my ($prog, $file, @args) = @_;
7562
    Debug("PackageShlibAddFiles");
7563
 
7564
    PackageAddFiles ( \%INSTALL_SHLIBS, \%INSTALL_SHLIBS, \%SHLIB_INS, @_ );
7565
    PackageAddFiles ( \%PACKAGE_SHLIBS, \%PACKAGE_SHLIBS, \%SHLIB_PKG, @_ );
7566
 
7567
    #
7568
    #   These files become the target of the "make_install_shlib" operation unless:
7569
    #       Conditionally packaged files are not always created
7570
    #       RemoveOnly files are not always generated
7571
    #
7572
    my $no_add;
7573
    foreach ( @args )
7574
    {
4382 dpurdie 7575
        if ( m/^defined=/ or m/^RemoveOnly=/ or /NoTarget=/ )
227 dpurdie 7576
        {
7577
            $no_add = 1;
7578
            last;
7579
        }
7580
    }
7581
 
7582
    push (@SHLIB_TARGETS, $file ) unless $no_add;
7583
}
7584
 
7585
sub PackageShlibAddLibFiles
7586
{
7587
    Debug("PackageShlibAddLibFiles");
7588
 
7589
    PackageAddFiles ( \%PACKAGE_SHLIBS, \%PACKAGE_LIBS, \%SHLIB_PKG, @_ , 'Class=lib');
7590
    PackageAddFiles ( \%INSTALL_SHLIBS, \%INSTALL_LIBS, \%SHLIB_INS, @_ , 'Class=lib');
7591
}
7592
 
7593
#-------------------------------------------------------------------------------
7594
# Function        : PackageAddFiles
7595
#
7596
# Description     : Internal function to add files to the data structures that
7597
#                   describe a package or installation
7598
#
7599
#                   Use this function to package or install additional files with
7600
#                   the Progs and Libs
7601
#
7602
#                   ie: Add a LIB file to be packaged with a Shared Library
7603
#                   ie: Add a MAP file to be packaged with a program
7604
#
7605
# Inputs          : ref_spkg  - Reference to the hash that contains the package data
7606
#                   ref_dpkg  - Reference to the target package/install hash
7607
#                               Normally the same as ref_dpkg, but does allow
289 dpurdie 7608
#                               a static library to be added to a dynamic library
227 dpurdie 7609
#                               package.
7610
#                   ref_list  - Reference to a hash that may contain package keys to process
7611
#                   prog      - Key for index to above
7612
#                   file      - A file to be added
7613
#                   args      - Additional packaging arguments
7614
#
7615
# Returns         :
7616
#
7617
sub PackageAddFiles
7618
{
7619
    my ($ref_spkg, $ref_dpkg, $ref_list, $prog, $file, @args ) = @_;
7620
 
7621
    #
7622
    #   Process entry
7623
    #   The files may need to be added to multiple packages
7624
    #
7625
    Debug("PackageAddFiles: $file");
7626
 
7627
    return unless ( $ref_list->{$prog} );
7628
 
7629
    #
7630
    #   Parse arguments and extract the "Class=xxx" argument. This may be used
7631
    #   to limit the extra files piggybacked with the base file
7632
    #   All files without a class will be treated as base files
7633
    #
7634
    my $class;
7635
    foreach ( @args )
7636
    {
7637
        next unless ( m~^Class=(.*)$~ );
7638
        $class = $1 unless ( $1 eq 'none' );
7639
    }
7640
    Debug("PackageAddFiles: Class: ", $class || 'Default=None');
7641
 
7642
    foreach my $entry_key ( @{$ref_list->{$prog}} )
7643
    {
7644
        Debug("PackageAddFiles: Entry found: $entry_key");
7645
 
7646
        #
7647
        #   Copy of the template entry
7648
        #
7649
        my %package_entry = %{$ref_spkg->{$entry_key}};
7650
        Error ("INTERNAL: Expected entry in PACKAGE_ hash not found: $entry_key" )
7651
            unless ( %package_entry );
7652
 
7653
        #
7654
        #   Do not add the file if the user has limited the extra files added
7655
        #   to the packaging list and the current file is not in the class list
7656
        #
7657
        if ( $class && $package_entry{'extras'} )
7658
        {
7659
            next unless ( $package_entry{'extras'}{$class} );
7660
        }
7661
 
7662
        #
7663
        #   Create new entries for the file
7664
        #
7665
        $package_entry{'src'} = $file;
7666
        foreach ( @args )
7667
        {
7668
            m~^(.*)=(.*)$~;
7669
            $package_entry{$1} = $2;
7670
        }
7671
 
7672
        #
7673
        #   Clean out useless fields
7674
        #   Must remove the placekeeper marker to allow the entry to be visible
7675
        #
7676
        delete $package_entry{'placekeeper'};
7677
        delete $package_entry{'version'};
7678
        delete $package_entry{'lib'};
261 dpurdie 7679
#       delete $package_entry{'extras'};                   # Keep these
227 dpurdie 7680
        delete $package_entry{'Class'};
7681
 
7682
        #
7683
        #   Add the entry
7684
        #
7685
        #   Under some conditions is it possible to attempt to add the same named
7686
        #   file. This will result in a circular dependancy in the makefile
7687
        #
7688
        #   The condition is when merged libaries with PDBs (WINCE+WIN32) are merged
261 dpurdie 7689
        #   and the source for the merge is the "local directory.
227 dpurdie 7690
        #
7691
        #
7692
        my $dst = $package_entry{'dir'} ;
7693
        ( my $dfile = $file) =~ s~.*/~~;
7694
        Debug( "    added $dst/$dfile = $file" );
7695
 
7696
        $ref_dpkg->{"$dst/$dfile"} = {%package_entry}
7697
            unless ( "$dst/$dfile" eq "$file" );
7698
    }
7699
}
7700
 
7701
#-------------------------------------------------------------------------------
7702
# Function        : PackageProgRemoveFiles
7703
#
7704
# Description     : Flag a Packaged program to be not packaged
7705
#                   This mechanism is used to remove a program from packageing
7706
#                   under conditions where the toolset has generated a different
7707
#                   program.
7708
#
7709
#                   The entry is flagged as a placeholder
7710
#
7711
# Inputs          : prog        - Program to process
7712
#
7713
# Returns         : Nothing
7714
#
7715
sub PackageProgRemoveFiles
7716
{
7717
    my ($prog) = @_;
7718
    Verbose ("PackageProgRemoveFiles: $prog" );
7719
    return unless (exists($PROG_PKG{$prog}));
7720
 
7721
    #
7722
    #   Must lookup the TAG to locate the  required entry
7723
    #
7724
    my $tag = $PROG_PKG{$prog};
7725
    foreach my $entry ( @$tag )
7726
    {
7727
        Verbose("Do not package: $entry");
7728
        if ( exists $PACKAGE_PROGS{$entry} )
7729
        {
7730
            $PACKAGE_PROGS{$entry}{placekeeper} = 'ProgRemoved';
7731
        }
7732
    }
7733
}
7734
 
7735
#-------------------------------------------------------------------------------
7736
# Function        : DPackageLibrary
7737
#
7738
# Description     : Collect information to allow the generation of a DPACKAGE
299 dpurdie 7739
#                   file. This directive allows the generation of "Library"
227 dpurdie 7740
#                   directives within the final DPACKAGE
7741
#
7742
#                   This directive does generate the DPACKAGE file.
7743
#
7744
# Inputs          : platform    - This does not need to be an active platform
7745
#                                 it is simply passed to the DPACKAGE builder
7746
#
7747
#                   using       - The "using" target
7748
#
7749
#                   ...         - Arguments for the Library directive
7750
#
7751
# Returns         :
7752
#
7753
sub DPackageLibrary
7754
{
7755
    JatsDPackage::DPackageAdd ( @_ );
299 dpurdie 7756
    $DPackageDirective = 1;
227 dpurdie 7757
}
7758
 
7759
#-------------------------------------------------------------------------------
7760
# Function        : SetProjectBase
7761
#
7762
# Description     : Allows the user to modify the build's concept of the Base
7763
#                   of the build. By default the base is the same directory as
7764
#                   the build.pl file, but in some contorted environments it
7765
#                   is a great deal simpler to specify a differnt base.
7766
#
7767
#                   The use may use the variable $ProjectBase as a path
7768
#                   specifier to locate files and directories
7769
#
7770
#                   Both absolute and relative paths are supported
7771
#                   If the initial value of $ProjectBase is relative then
7772
#                   it will be maintained as a relative path.
7773
#
7774
# Inputs          : elements        path to base
7775
#                                   These may be:
7776
#                                       --Up=xx
7777
#                                       name
7778
#
7779
# Returns         : Nothing
7780
#
7781
 
7782
#
7783
#   Allow the user to modify the project base variable
7784
#
7785
sub SetProjectBase
7786
{
7787
    my $rip = 0;
7788
    my $path = "";
7789
    my $is_relative;
7790
 
7791
    Debug("ProjectBase Initial: $ProjectBase, @_");
7792
 
7793
    #
7794
    #   Ensure that the ProjectBase is in a "nice" form
7795
    #   1) No /./ bits
7796
    #   2) No trailing /
7797
    #   3) Not equal to .
7798
    #   4) No training /.
7799
    #   5) No //
7800
    #
7801
    $ProjectBase =~ s~/\./~/~g;
7802
    $ProjectBase =~ s~/$~~g;
7803
    $ProjectBase =~ s~^\.$~~g;
7804
    $ProjectBase =~ s~/\.$~~g;
7805
    $ProjectBase =~ s~//$~/~g;
7806
 
7807
    #
7808
    #   ProjectBase may be absolute or relative
7809
    #   Determine this before we mess with it
7810
    #
7811
    $is_relative = ($ProjectBase !~ m~^/~);
7812
 
7813
    #
7814
    #   Process each argument
7815
    #
7816
    foreach ( @_ )
7817
    {
7818
        if ( /^--Up=([0-9]*)/ ) {
7819
            $rip = $1;
7820
        } elsif ( /^--/ ) {
7821
            Warning( "SetProjectBase - unknown option \"$_\" - ignored" );
7822
        } else {
7823
            $path = $_;
7824
        }
7825
    }
7826
 
7827
    #
7828
    #   Process the UP requests
7829
    #   If the tail directory is a ".." then up is done by adding another ".."
7830
    #   If the tail directory is not a "..", then up is done by removing it
7831
    #
7832
    #   If we go past the start of the path then simply add ".."
7833
    #
7834
    while ( $rip-- > 0 )
7835
    {
7836
        Debug2("ProjectBase: $ProjectBase, Up: $rip, IsRel: $is_relative");
7837
 
7838
        #
7839
        #   If ending in a /.. or is exactly equal to ..
7840
        #   Then its a dot-dot and the way to go UP is to append another ..
7841
        #
7842
        if ( $ProjectBase =~ m~(/\.\.$)|(^\.\.$)~ )
7843
        {
7844
            $ProjectBase .= '/..';
7845
        }
7846
        else
7847
        {
7848
            #
7849
            #   Not a dot-dot ending
7850
            #   Attempt to remove the last directory of the form
7851
            #       /xxxxx
7852
            #   Where the leading / is optional
7853
            #   Note: Must have at least one character in the dirname
7854
            #         This prevents leading / from matching - which is needed
7855
            #
7856
            unless ($ProjectBase =~ s~/?[^/]+$~~)
7857
            {
7858
                #
7859
                #   Removal failed
7860
                #   If a relative path then we can keep on going up,
7861
                #   otherwise we are dead.
7862
                #
7863
                Error ("ProjectBase outside project") unless ($is_relative);
7864
                $ProjectBase = '..';
7865
            }
7866
 
7867
            #
7868
            #   Ensure that the leading / in an absolute path is not deleted
7869
            #
7870
            $ProjectBase = '/'
7871
                unless ( $is_relative || $ProjectBase );
7872
        }
7873
    }
7874
 
7875
    #
7876
    #   Append the user path
7877
    #
7878
    $ProjectBase .= '/' . $path if ( $path );
7879
    $ProjectBase = '.' unless ( $ProjectBase );
7880
    Debug("ProjectBase set to : $ProjectBase");
7881
 
7882
    #
7883
    #   Once upon a time I tried to convert paths that contained spaces into
7884
    #   short (mangled) names. This was not sucessful because:
7885
    #       1) Clearcase dynamic views do not support name mangling
7886
    #       2) Samba file system does not appear to support name mangling
7887
    #
7888
    #   Spaces in paths are not good for MAKE
7889
    #   Now I simple generate a message
7890
    #
7891
    Warning( "ProjectBase contains a space: $ProjectBase")
7892
        if ( $ProjectBase =~ m/ / );
7893
 
7894
    #
7895
    #   Sanity check
7896
    #   Absolute paths can be checked easily
7897
    #   Checking of relative paths does not appear to work
7898
    #   When I tested it chdir, opendir and stat would limit themselves
7899
    #   and drop into the root directory ( under windows )
7900
    #
7901
    #   Solution: Check the path does not extend beyond the file tree
7902
    #
7903
    my $distance = 1;
7904
    my $tpath = $ProjectBase;
7905
 
7906
    if ( $is_relative && $tpath ne '.' )
7907
    {
7908
        #
7909
        #   Build up the complete pathname by merging it with the
7910
        #   current directory. Then clean it up.
7911
        #
7912
        $tpath = $::Cwd . '/' . $ProjectBase;
7913
 
7914
        #
7915
        #   Scan the list of diretories and count the distance from the root
7916
        #   This should not be greater than zero for sanity
7917
        #   Note: Get an empty elemement from the split due to
7918
        #         the leading / of the ABS path
7919
        #
7920
        $distance = 0;
7921
        foreach (  split ('/', $tpath) )
7922
        {
7923
            if ( m~\.\.~ )
7924
            {
7925
                $distance--;
7926
            }
7927
            else
7928
            {
7929
                $distance++;
7930
            }
7931
        }
7932
    }
7933
 
7934
    #
7935
    #   Warn if not a valid directory
7936
    #
7937
    Warning( "ProjectBase is not a directory: $ProjectBase")
7938
        if ( $distance <= 0 || !  -d $tpath  );
7939
 
7940
    #
7941
    #   $ProjectBase will always be a valid directory, but if its the top
7942
    #   directory (/) and it is added to a path we will get //path
7943
    #   This is not good, so // will be removed later in the AddIncDir and
7944
    #   AddSrcDir commands where $ProjectBase is really used.
7945
    #
7946
    #   Alternatively we could set $ProjectBase to an empty string, but then
7947
    #   this may be confused with an empty relative directory
7948
    #
7949
    Debug("ProjectBase Final  : $ProjectBase");
7950
}
7951
 
7952
#-------------------------------------------------------------------------------
7953
# Function        : DeployPackage
7954
#
7955
# Description     : Generate a deployed package
7956
#                   This is a gateway to a different packaging system
7957
#
7958
#                  DeployPackage and PackageXxxxx directives are mutually
7959
#                  exclusive. Only one person can play in the package area.
7960
#
7961
# Inputs          : Platform Specifier
7962
#                   Package Name    (Optional)
7963
#                   Options
7964
#                       --Name : Base name of the package. The default is taken
7965
#                                from the build.pl file
7966
#                       --Dir  : Package directory
7967
#                                The default is based on the package name
7968
#
7969
# Returns         :
7970
#
7971
sub DeployPackage
7972
{
7973
    my( $platforms, @elements ) = @_;
7974
    my $dir;
7975
    my $name;
7976
 
267 dpurdie 7977
    #
7978
    #   Flag that this build creates a deployable package, even if its not
7979
    #   active on this platform.
7980
    #
7981
    $DEPLOYPACKAGE = 1;
7982
 
7983
 
227 dpurdie 7984
    Debug2( "DeployPackage($platforms, @elements)" );
7985
    return if ( ! ActivePlatform($platforms) );
7986
 
7987
    #
7988
    #   Only allow one use of this directive
7989
    #
7990
    Error("DeployPackage can only be used once" ) if ( %DEPLOYPACKAGE );
267 dpurdie 7991
    $DEPLOYPACKAGE = 2;
227 dpurdie 7992
 
7993
    #
7994
    #   Ensure that the deployment file is available
7995
    #
7996
    my $command_file = $ScmDeploymentPatch ? "deploypatch.pl" : "deployfile.pl";
7997
    Error("DeployPackage: $command_file not found") unless (-f "./$command_file");
7998
    #
7999
    #   Collect arguments
8000
    #
8001
    foreach (@elements )
8002
    {
8003
        if ( m/^--Dir=(.*)/ ) {
8004
            Error ("DeployPackage: Package directory defined multiple times") if $dir;
8005
            $dir = $1;
8006
 
8007
        } elsif ( m/^--Name=(.*)/ ) {
8008
            Error ("DeployPackage: Package name defined multiple times") if $name;
8009
            $name = $1;
8010
 
8011
        } elsif ( m/^--/ ) {
8012
            Warning( "DeployPackage: Unknown option ignored: $_");
8013
 
8014
        } else {
8015
            Error ("DeployPackage: Package name defined multiple times") if $name;
8016
            $name = $_;
8017
 
8018
        }
8019
    }
8020
 
8021
    $name = $::ScmBuildPackage unless ( $name );
8022
 
8023
    #
8024
    #   Save the deployment data
8025
    #
8026
    $dir = lc($name) unless ( $dir );
8027
    $DEPLOYPACKAGE{'name'} = $name;
8028
    $DEPLOYPACKAGE{'dir'} = $dir;
8029
    $DEPLOYPACKAGE{'cmdfile'} = $command_file;
8030
 
8031
    #
8032
    #   Flag that toolset tests should be supressed
8033
    #   The Deploy world does not really use the full makefiles and if the
8034
    #   compilers are not installed will not be able to create deployment
8035
    #   packages
8036
    #
8037
    $ScmNoToolsTest = 1;
8038
}
8039
 
8040
 
8041
###############################################################################
8042
###############################################################################
8043
# Private function section.
8044
#       The following functions are used INTERNALLY by makelib.pl2.
8045
###############################################################################
8046
 
8047
###############################################################################
8048
#   A collection of functions to write to the MAKEFILE handle
8049
#
8050
#   MakeHeader          - Write a nice section header
8051
#   MakeNewLine         - Print a new line
8052
#   MakePrint           - Print a line ( without trailing \n)
8053
#   MakeQuote           - Escape \ and " character, then print a line
8054
#   MakePrintList       - Print an array
8055
#   MakeEntry           - Complex line printer
8056
#   MakePadded          - Padded line printer (internal)
8057
#   PadToPosn           - Calc space+tabs to tabstop (internal)
8058
#   MakeEntry3          - Complex Line Printer
8059
#   MakeDefEntry        - Print a definition line (Production + Debug support)
8060
#   MakeIfDefEntry      - Print ifdef entry
261 dpurdie 8061
#   MakeIfnDefEntry     - Print ifndef entry
8062
#   MakeIfZeroEntry     - Print ifeq entry
227 dpurdie 8063
#
8064
###############################################################################
8065
 
8066
sub MakeHeader
8067
{
8068
    my ($text, @rest) = @_;
8069
    my $length = length ($text);
8070
 
8071
    print MAKEFILE "\n";
8072
    print MAKEFILE "#--------- $text ", '-' x (80 - 12 - $length)  ,"\n";
8073
    print MAKEFILE "#    $_\n" foreach  ( @rest ) ;
8074
    print MAKEFILE "#\n";
8075
}
8076
 
8077
sub MakeNewLine         # Print a newline to the current 'Makefile'
8078
{
8079
    print MAKEFILE "\n";
8080
}
8081
 
8082
sub MakePrint           # Print to the current 'Makefile'
8083
{
8084
    print MAKEFILE @_
8085
        if ( defined $_[0] );
8086
}
8087
 
8088
sub MakeQuote           # Quote a makefile text line
8089
{
8090
    my( $line ) = @_;
8091
    $line =~ s/\\/\\\\/g;                       # quote all '\' characters
8092
    $line =~ s/"/\\"/g;                         # Then quote '"' characters
255 dpurdie 8093
    $line =~ s/=#/=\\#/g;                       # Then quote '=#' sequence
227 dpurdie 8094
    print MAKEFILE $line;
8095
}
8096
 
8097
sub MakePrintList
8098
{
8099
    print MAKEFILE $_ . "\n" foreach (@{$_[0]});
8100
}
8101
 
2429 dpurdie 8102
sub QuoteArray
8103
{
8104
    my $quote = "'";
8105
    if ( @_ ) {
8106
        return ($quote . join("$quote $quote", @_) . $quote);
8107
    }
8108
    return '';
8109
}
227 dpurdie 8110
 
8111
#-------------------------------------------------------------------------------
8112
# Function        : MakeEntry
8113
#
8114
# Description     : Build a entry based on the element list
8115
#                   Creates text of the form
8116
#                       $(BINDIR)/prog.exe: object1.obj \
8117
#                                           object2.obj
8118
#
8119
#
8120
# Inputs          : $prelim         - Preamble (one-off)
8121
#                   $postlim        - Postamble (one-off)
8122
#                   $prefix         - Pefix (to each element of array)
8123
#                   $postfix        - Postfix (to each element of array )
8124
#                   @elements       - Array of element to wrap
8125
#
8126
# Returns         :   1 Always
8127
#
8128
# Notes:
8129
#       The above description means that the following entry format is
8130
#       produced:
8131
#
8132
#           <preliminary><prefix><variant1><prefix><variant2>...<final>
8133
#
8134
#       With judicious use of newline and tab characters, a target
8135
#       and dependency list along with the command(s) to build the
8136
#       target can be constructed.
8137
#
8138
sub MakeEntry
8139
{
8140
    my( $prelim, $postlim, $prefix, $postfix, @elements ) = @_;
8141
 
8142
    MakePrint $prelim;
8143
    MakePrint "${prefix}${_}${postfix}" foreach ( @elements );
8144
    MakePrint $postlim if ($postlim);
8145
    return 1;
8146
}
8147
 
8148
#-------------------------------------------------------------------------------
8149
# Function        : MakePadded
8150
#
8151
# Description     : Generate aligned output of the form
8152
#                       Prefix_text           Aligned_text
8153
#                   where the aligned text is at a specified TAB boundary
8154
#
8155
# Inputs          : $align      - Tab stop (One tab = 8 chars)
8156
#                   $prefix     - Text to print before alignment occurs
8157
#                   @line       - Remainder of the line
8158
#
8159
sub MakePadded          # Print to the current 'Makefile', tab aligning
8160
{
8161
    my( $align, $prefix, @line ) = @_;
8162
 
8163
    my $strlen = length( $prefix );
8164
    my $pad = PadToPosn( $strlen, $align * 8 );
8165
 
8166
    print MAKEFILE $prefix . $pad;
8167
    print MAKEFILE @line;
8168
}
8169
 
8170
#-------------------------------------------------------------------------------
8171
# Function        : PadToPosn
8172
#
8173
# Description     : Given that we are at $startposn return a tab and space
8174
#                   string to place us at $endposn
8175
#
8176
sub PadToPosn
8177
{
8178
    my ($startposn, $endposn ) = @_;
8179
 
8180
 
8181
    #
8182
    #   Case where we are already too far into the line
8183
    #
8184
    return ( ' ' )if ( $endposn <= $startposn );
8185
 
8186
    my $tcount = 0;
8187
    my $scount = 0;
8188
 
8189
    while ( $startposn < $endposn )
8190
    {
8191
        $tcount ++;
8192
        $startposn = ($startposn >> 3) * 8 + 8;
8193
 
8194
        my $delta = $endposn - $startposn;
8195
        if ( $delta < 8 )
8196
        {
8197
            $scount = $delta;
8198
            last;
8199
        }
8200
 
8201
    }
8202
    return ( "\t" x $tcount .  ' ' x $scount );
8203
}
8204
 
8205
#-------------------------------------------------------------------------------
8206
# Function        : MakeEntry3
8207
#
8208
# Description     : Build a makefile entry based on the element list, tab aligned
8209
#                   Can creat text of the form:
8210
#                       TAG = NAME0 \       TAG : NAME0 \ 
8211
#                             NAME1               NAME1
8212
#
8213
#
8214
# Inputs          : $prelim             - Preliminary text
8215
#                   $presep             - Preliminary seperator
8216
#                   $elem_ref           - Either a single name or a reference to
8217
#                                         and array of names, or a hash.
8218
#
8219
# Returns         : Writes directly to the Makefile
8220
#
8221
sub MakeEntry3
8222
{
8223
    my( $prelim, $presep, $elem_ref ) = @_;
8224
 
8225
    #
8226
    #   The prelim may have some "\n" characters at the start
8227
    #   These simplify formatting, but mess up the nice formatting
8228
    #
8229
    if ($prelim =~ m~(^\n+)(.*)~ )
8230
    {
8231
        MakePrint $1;
8232
        $prelim = $2;
8233
    }
8234
 
8235
    #
8236
    #   Print the definition and the sep with nice padding
8237
    #
8238
    MakePadded ( 3, $prelim, $presep );
8239
    my $leadin = ' ';
8240
 
8241
    #
8242
    #   If a HASH reference then use a sorted list of keys from the hash.
8243
    #
8244
    if ( ref ($elem_ref) eq "HASH" )
8245
    {
8246
        my @hash_list;
8247
        @hash_list = sort keys ( %{$elem_ref} );
8248
        $elem_ref = \@hash_list;
8249
    }
8250
 
8251
    #
8252
    #   If the list is only one element long, then create a simple form
8253
    #   If the list is not an array ref, then treat it as a single element
8254
    #
8255
    if ( ref ($elem_ref) eq "ARRAY" )
8256
    {
8257
        my $line = 0;
8258
        foreach my $element ( @$elem_ref )
8259
        {
8260
            print MAKEFILE $leadin . $element;
8261
            $leadin = " \\\n" . PadToPosn(0,24 + length( $presep ) + 1 ) unless ($line++);
8262
        }
8263
    }
8264
    elsif ( defined $elem_ref )
8265
    {
8266
            print MAKEFILE $leadin . $elem_ref;
8267
    }
8268
    MakeNewLine();
8269
    return 1;
8270
}
8271
 
8272
#-------------------------------------------------------------------------------
8273
# Function        : MakeDefEntry
8274
#
8275
# Description     : Make a definition entry of the form
8276
#
8277
#                       TAG = NAME0 \
8278
#                             NAME1
8279
#
8280
#                   Support a list of definitions that will always be created
8281
#                   as well as a production and a debug list.
8282
#
8283
#                   Will always generate the "TAG = " string, even if the list
8284
#                   is empty.
8285
#
8286
#                   Will supress the TAG if there is no data if the FIRST opr starts with a '+'
8287
#
8288
# Inputs          : TAG         - Text tag to create
8289
#                   FIRST       - First assignement opr. = or +=
8290
#                   ALL_LIST    - A reference to a list of names to assign
8291
#                                 or a single name.
8292
#                   PROD_LIST   - Optional list to extend the definition with for a production build
8293
#                   DEBUG_LIST  - Optional list to extend the definition with for a debug build
8294
#
8295
# Returns         : Nothing
8296
#
8297
 
8298
sub MakeDefEntry
8299
{
8300
    my( $tag, $assign, $all, $prod, $debug ) = @_;
8301
 
8302
    #
8303
    #   Do not generate anything if the $opr is "+=" and there is no data
8304
    #   to output. ie: Supress empty TAG += statements
8305
    #
8306
    return if ( $assign =~ m/\+/ && ( ref($all) && ! defined $all->[0] ) );
8307
 
8308
    #
8309
    #   TAG for all entries
8310
    #
8311
    MakeEntry3( $tag, $assign, $all );
8312
 
8313
 
8314
    #
8315
    #   TAGs for PROD build
8316
    #   TAGs for DEBUG build
8317
    #
8318
    if ( defined $prod && defined $prod->[0] )
8319
    {
8320
        print MAKEFILE 'ifeq "$(DEBUG)" "0"' . "\n";
8321
        MakeEntry3( $tag, "+=", $prod );
267 dpurdie 8322
        print MAKEFILE 'endif' . "\n";
227 dpurdie 8323
    }
8324
 
8325
    if ( defined $debug && defined $debug->[0] )
8326
    {
8327
        print MAKEFILE 'ifeq "$(DEBUG)" "1"' . "\n";
8328
        MakeEntry3( $tag, "+=", $debug );
267 dpurdie 8329
        print MAKEFILE 'endif' . "\n";
227 dpurdie 8330
    }
8331
 
8332
}
8333
 
8334
sub MakeIfDefEntry
8335
{
8336
    my( $iftag, @rest ) = @_;
8337
 
8338
    print MAKEFILE "ifdef $iftag\n";
8339
    MakeDefEntry (@rest);
8340
    print MAKEFILE "endif\n\n";
8341
}
8342
 
8343
sub MakeIfnDefEntry
8344
{
8345
    my( $iftag, @rest ) = @_;
8346
 
8347
    print MAKEFILE "ifndef $iftag\n";
8348
    MakeDefEntry (@rest);
8349
    print MAKEFILE "endif\n\n";
8350
}
8351
 
261 dpurdie 8352
sub MakeIfZeroEntry
8353
{
8354
    my( $iftag, @rest ) = @_;
8355
 
8356
    print MAKEFILE "ifeq (\$($iftag),0)\n";
8357
    MakeDefEntry (@rest);
8358
    print MAKEFILE "endif\n\n";
8359
}
8360
 
227 dpurdie 8361
#-------------------------------------------------------------------------------
8362
# Function        : CreateNameList
8363
#
8364
# Description     : Create a list of names by adding a prefix and suffix to a
8365
#                   list of items. This is used to add a directory prefix and a
8366
#                   file suffix to a list of files.
8367
#
8368
# Inputs          : $prefix             ie: '$(OBJDIR)/'
8369
#                   $suffix             ie: '.obj'
8370
#                   $elem_ref           ie: A list of files ( passed be ref )
8371
#                                           If a Hash then its sorted keys is used
8372
#
8373
# Returns         : A ref to the resulting list
8374
#
8375
sub CreateNameList
8376
{
8377
    my( $prefix, $suffix, $elem_ref ) = @_;
8378
    my @result;
8379
 
8380
    if ( ref ($elem_ref) eq "HASH" )
8381
    {
8382
        my @hash_list;
8383
        @hash_list = sort keys ( %{$elem_ref} );
8384
        $elem_ref = \@hash_list;
8385
    }
8386
 
8387
    foreach  ( @$elem_ref )
8388
    {
8389
        push @result, $prefix . $_ . $suffix;
8390
    }
8391
    return \@result;
8392
}
8393
 
8394
#-------------------------------------------------------------------------------
8395
# Function        : ListGeneratedProjects
8396
#
8397
# Description     : Return a list of generated/nongenerated projects
8398
#                   Used in conjunction with CreateNameList
8399
#
8400
# Inputs          : $type       - TRUE : Generated
8401
#                                 FALSE: Not Generated
8402
#
8403
# Returns         : A reference to a list of projects
8404
#                   undef will be retuend if there are no projects
8405
#
8406
sub ListGeneratedProjects
8407
{
8408
    my ($type) = @_;
8409
    my @list;
8410
    foreach my $project ( @PROJECTS_ORDER )
8411
    {
8412
        if ( exists($PROJECTS{$project}->{'generated'}) xor $type )
8413
        {
8414
            push @list, $project;
8415
        }
8416
    }
8417
    return @list ? \@list : undef;
8418
}
8419
 
8420
#-------------------------------------------------------------------------------
8421
# Function        : ListCleanGenerated
8422
#
8423
# Description     : return a list of generated targets that have 'clean'
8424
#                   operations. This is used in conjunction with CreateNameList
8425
#
8426
# Inputs          : None
8427
#
8428
# Returns         : A list of project indexes, that can be cleaned
8429
#
8430
sub ListCleanGenerated
8431
{
8432
    my @list;
8433
    foreach my $i ( @GENERATE_FILES )
8434
    {
8435
        push @list, $i->{'index'}
8436
            if ( $i->{'clean'} );
8437
    }
8438
    return \@list;
8439
}
8440
 
251 dpurdie 8441
#-------------------------------------------------------------------------------
8442
# Function        : MakeResolve
8443
#
8444
# Description     : Internal Function
8445
#                   Locate a source file by examining a list of directories
8446
#
8447
#                   Don't use directly
8448
#                   Use MakeSrcResolve or MakeSrcResolveExtended
8449
#
8450
# Inputs          : $dirs           - Ref to an array of directories to scan
8451
#                   $source         - File to locate
8452
#
8453
# Returns         : Resolved path to the file
8454
#                   Will warn if multiple instances of the file are found
8455
#
227 dpurdie 8456
sub MakeResolve
8457
{
8458
    my( $dirs, $source ) = @_;
285 dpurdie 8459
    my( $first, $count );
227 dpurdie 8460
 
237 dpurdie 8461
    #
8462
    #   If the path contains a '$' then its assumed to be
8463
    #   a variable name in the path. Just assume that it exists
8464
    #
8465
    return $source if ( $source =~ m#\$# );
8466
 
8467
    #
8468
    #   If the path is absolute or contains a leading ., then don't search
8469
    #   Warn if it can't be found
8470
    #
8471
    if ( $source =~ m#^(/|\.)# )
8472
    {
8473
        Warning( "Unable to resolve '$source' path" ) unless -f $source;
8474
        return $source;
227 dpurdie 8475
    }
8476
 
6276 dpurdie 8477
    my @found;
8478
    # Search the local path first
8479
    push (@found, $source ) if -f ($source);
237 dpurdie 8480
 
285 dpurdie 8481
    foreach my $dir (@$dirs)
227 dpurdie 8482
    {
331 dpurdie 8483
        next if ( $dir eq '.' );
6276 dpurdie 8484
        my $temp = $dir . '/' . $source;
227 dpurdie 8485
        Debug2( "MakeResolve: Looking in: $temp" );
6276 dpurdie 8486
        push (@found, $temp) if (-f $temp);
227 dpurdie 8487
    }
8488
 
6276 dpurdie 8489
    Warning( "Unable to resolve path to '$source'" ) unless $found[0];
8490
    if (scalar @found > 1)
8491
    {
8492
        Warning("Duplicates for '$source'. Using the first", @found);
227 dpurdie 8493
    }
6276 dpurdie 8494
 
6504 dpurdie 8495
    return $found[0] || $source;
227 dpurdie 8496
}
8497
 
251 dpurdie 8498
#-------------------------------------------------------------------------------
8499
# Function        : MakeSrcResolve
8500
#
8501
# Description     : Locate a source file by examining the list of source
8502
#                   directories. There are a few frills
8503
#
8504
#                   Look for a source file in
8505
#                       1) %::BUILD_KNOWNFILES
8506
#                       2) %SRCS
8507
#                       3) Dirs specified by the array @SRCSDIRS
8508
#
8509
# Inputs          : Name of a file to resolve
8510
#
8511
# Returns         : Resolved path.
283 dpurdie 8512
#                   Input file - if not found at all
251 dpurdie 8513
#
227 dpurdie 8514
sub MakeSrcResolve
8515
{
8516
    my ($name) = @_;
8517
    my $file;
8518
 
251 dpurdie 8519
    if ( exists ( $::BUILD_KNOWNFILES{$name} ) ) {
8520
        #
8521
        #   The Known Files list is relative to ScmRoot
8522
        #   This must be included in the full path
8523
        #
8524
        $file = $ScmRoot . '/' . $::BUILD_KNOWNFILES{$name};
8525
 
8526
    } elsif ( exists $SRCS{$name} ) {
8527
        $file = $SRCS{$name};
8528
 
8529
    } else {
6469 dpurdie 8530
        $file = MakeResolve( \@SRCDIRS, @_ );
251 dpurdie 8531
    }
227 dpurdie 8532
    return $file;
8533
}
8534
 
8535
 
8536
# MakeSrcResolveExtended
8537
#   from_global = 0 : Search user specified directories
8538
#               = 1 : Search LinkPkgArchive list
8539
#
8540
our @PkgSrcDirList;
8541
sub MakeSrcResolveExtended
8542
{
8543
    my ( $from_global, $file ) = @_;
8544
 
8545
    #
8546
    #   Simple Case. Resolve source from known source directories
8547
    #
8548
    #
8549
    return MakeSrcResolve( $file )
8550
        unless ( $from_global );
8551
 
8552
    #
8553
    #   Not so simple Case
8554
    #   Resolve the source from the imported packages
8555
    #
8556
    #   Create a list of directores to search, but only the first time
311 dpurdie 8557
    #       - Interface directories - from BuildPkgArchive
227 dpurdie 8558
    #       - LnkPkgArchive directories
8559
    #         Using target,product,platform include directories
8560
    #
8561
    unless ( @PkgSrcDirList )
8562
    {
8563
        for my $entry (@{$::ScmBuildPkgRules{$ScmPlatform} })
8564
        {
311 dpurdie 8565
            next if ( $entry->{'TYPE'} eq 'build' ); # Ignore BuildPkgArchives
8566
 
227 dpurdie 8567
            for (@{$entry->{'PINCDIRS'}}, @{$entry->{'THXDIRS'}}, '' )
8568
            {
8569
                my $dir = $entry->{'ROOT'} . "/" . $_ ;
8570
                $dir =~ s~//~/~g;
8571
                $dir =~ s~/$~~;
311 dpurdie 8572
                push ( @PkgSrcDirList, $dir );
227 dpurdie 8573
            }
8574
        }
311 dpurdie 8575
    }
227 dpurdie 8576
 
8577
    return MakeResolve( \@PkgSrcDirList, $file );
8578
}
8579
 
8580
#-------------------------------------------------------------------------------
8581
# Function        : GetPackageRoot
8582
#
8583
# Description     : Determine the root directory for a given package
8584
#                   This routine is intended for non-standard JATS scripts that
8585
#                   access package contents directly
8586
#
8587
#                   Note: This routine does not attempt to handle multiple
8588
#                         instances of a package ( sysbasetypes ).
8589
#
8590
# Inputs          : $pname          - Name of the package
8591
#
8592
# Returns         :
8593
#
8594
sub GetPackageRoot
8595
{
8596
    my( $pname ) = @_;
8597
    Debug( "GetPackageRoot(@_)" );
8598
 
8599
    my $result = undef;
8600
    my $pkg = GetPackageEntry( $pname );
8601
    if ( $pkg )
8602
    {
8603
        $result = $pkg->{'ROOT'};
8604
        Debug( "GetPackageRoot: $result" );
8605
    }
8606
 
8607
    return $result;
8608
}
8609
 
8610
#-------------------------------------------------------------------------------
8611
# Function        : ActiveProject
8612
#
8613
# Description     : Determine if the specified project is currenly 'active'
8614
#
345 dpurdie 8615
# Inputs          : $project            - one or more project names separated
8616
#                                         by either a comma or a colon
227 dpurdie 8617
#
8618
# Returns         : TRUE    if the project is active
8619
#
8620
sub ActiveProject
8621
{
8622
    my ($project) = @_;
345 dpurdie 8623
    foreach (  split( '\s*[:,]\s*', $project ) )
227 dpurdie 8624
    {
8625
        return 1
8626
            if ( $_ eq $::ScmBuildProject );
8627
    }
8628
    return 0;
8629
}
8630
 
345 dpurdie 8631
#-------------------------------------------------------------------------------
8632
# Function        : ActiveDefine
8633
#
8634
# Description     : Determine if the specified definition is currenly 'active'
8635
#
8636
# Inputs          : $defs               - one or more variable names separated
8637
#                                         by either a comma or a colon
8638
#
8639
# Returns         : TRUE    if any of the definitions are known
8640
#
8641
sub ActiveDefine
8642
{
8643
    my ($defs) = @_;
8644
    no strict 'refs';
8645
    foreach (  split( '\s*[:,]\s*', $defs ) )
8646
    {
8647
        return 1
4455 dpurdie 8648
            if ( defined( $$_ ) || ( @$_ ) );
345 dpurdie 8649
    }
8650
    use strict 'refs';
8651
    return 0;
8652
}
227 dpurdie 8653
 
8654
#-------------------------------------------------------------------------------
345 dpurdie 8655
# Function        : ActiveMachType
8656
#
8657
# Description     : Determine if the specified MachType is currenly 'active'
8658
#
8659
# Inputs          : $mtype              - one or more machine names separated
8660
#                                         by either a comma or a colon
8661
#
8662
# Returns         : TRUE    if any of the current MachType is in the list
8663
#
8664
sub ActiveMachType
8665
{
8666
    my ($mtype) = @_;
8667
    foreach (  split( '\s*[:,]\s*', $mtype ) )
8668
    {
8669
        return 1
8670
            if ( uc($_) eq uc($::GBE_MACHTYPE) );
8671
    }
8672
    return 0;
8673
}
8674
 
8675
#-------------------------------------------------------------------------------
6133 dpurdie 8676
# Function        : ActiveAlias
8677
#
8678
# Description     : Determine if the specified Alias is currenly 'active'
8679
#
8680
# Inputs          : $mtype              - one or more alias names separated
8681
#                                         by either a comma or a colon
8682
#
8683
# Returns         : TRUE    if any of the current Aliases is in the list
8684
#
8685
sub ActiveAlias
8686
{
8687
    my ($mtype) = @_;
8688
    foreach (  split( '\s*[:,]\s*', $mtype ) )
8689
    {
8690
        return 1
8691
            if ( isAnAlias( uc($_) ) );
8692
    }
8693
    return 0;
8694
}
8695
 
8696
 
8697
#-------------------------------------------------------------------------------
227 dpurdie 8698
# Function        : ActivePlatform
8699
#
8700
# Description     : Determine if the specified platform is currently 'active'
8701
#                   This is used by all user directives in order to determine
8702
#                   if the directive should be ignored for the current platform
8703
#
8704
# Inputs          : $platform_spec      - A platform specifier
8705
#                                         This is a bit complex.
8706
#
241 dpurdie 8707
#                   Format of platform_spec. One or more of
8708
#                       PlatformName
8709
#                       AliasName
6133 dpurdie 8710
#                       TargetName[,--Target]
345 dpurdie 8711
#                   Special Options (Must all be True)
8712
#                       --Project=ProjectName[:ProjectName]+
8713
#                       --Defined=SomeValue[:SomeValue]+
6133 dpurdie 8714
#                       --MachType=SomeMachType[:SomeMachType]+
8715
#                       --Alias=SomeAlias[:SomeAlias]+
8716
#                   Some shortcuts
8717
#                       '*'     ==> Always true
8718
#
345 dpurdie 8719
#                   Each can be prefixed with a '!' to negate the test
6133 dpurdie 8720
#                   
8721
#                   PlatformNames are either additive or negative(prefixed with !)
8722
#                       Order is not important                   
8723
#                       All additive names are accumulated before the negative items are considered.
8724
#                           ie: aa,!bb => !bb,aa
8725
#                       If only negative names are provided then JATS assumes a leading '*'
8726
#                           ie: !aaa => *,!aaa
8727
#                   
241 dpurdie 8728
#                   Valid options are:
271 dpurdie 8729
#                       --Target        - indicates that the platform is a 'target'
241 dpurdie 8730
#
8731
# Returns         : TRUE if the platform spec is satisfied
8732
#
227 dpurdie 8733
sub ActivePlatform
8734
{
8735
    my( $platform_spec ) = @_;
8736
    my( @platforms, $scmplatform, $platform );
6133 dpurdie 8737
    my( %arguments, @args );
241 dpurdie 8738
    my @plist;
227 dpurdie 8739
 
241 dpurdie 8740
    #
8741
    #   Short circuit check
6133 dpurdie 8742
    #       '*' is used so often that it pays to check it first
241 dpurdie 8743
    #
8744
    if ( $platform_spec eq '*' )
8745
    {
8746
        Debug3( " ActivePlatform(@_) = TRUE" );
8747
        return 1;
8748
    }
227 dpurdie 8749
 
241 dpurdie 8750
    #
8751
    #   Platform specifier may be a comma seperated list
8752
    #   ie:  WIN32,MOS,XXX
8753
    #   Extract non-platform arguments
279 dpurdie 8754
    #   Process to yield a dummy platform of '0' or '1' - these will be seen later
241 dpurdie 8755
    #
8756
    foreach ( split( '\s*,\s*', $platform_spec ) )
8757
    {
345 dpurdie 8758
        my ($result, $not);
8759
        if ( m~^(!?)--Project=(.+)~ ) {
325 dpurdie 8760
            $not = $1;
345 dpurdie 8761
            $result = ActiveProject($2);
277 dpurdie 8762
 
345 dpurdie 8763
        } elsif ( m~^(!?)--Defined=(.+)~ ) {
325 dpurdie 8764
            $not = $1;
345 dpurdie 8765
            $result = ActiveDefine($2);
241 dpurdie 8766
 
345 dpurdie 8767
        } elsif ( m~^(!?)--MachType=(.+)~ ) {
325 dpurdie 8768
            $not = $1;
345 dpurdie 8769
            $result = ActiveMachType($2);
8770
 
6133 dpurdie 8771
        } elsif ( m~^(!?)--Alias=(.+)~ ) {
8772
            $not = $1;
8773
            $result = ActiveAlias($2);
8774
 
325 dpurdie 8775
        } else {
8776
            #
8777
            #   Must be a platform argument
8778
            #   Add to a list
8779
            #
8780
            push @platforms, $_;
241 dpurdie 8781
            next;
8782
        }
8783
 
8784
        #
325 dpurdie 8785
        #   Continue processing non-platform arguments
345 dpurdie 8786
        #   Each one must be TRUE, allowing for negation.
241 dpurdie 8787
        #
325 dpurdie 8788
        $result = $result ? 1 : 0;
345 dpurdie 8789
        $result = ! $result if ( $not );
8790
        return 0 unless ( $result );
241 dpurdie 8791
    }
8792
 
4128 dpurdie 8793
    #
8794
    #   If we have no platforms then the test was purely non-platform arguments.
8795
    #
6133 dpurdie 8796
    if ($platform_spec ne '' && ! @platforms) {
8797
        Debug3( " ActivePlatform(@_ == $ScmPlatform) = TRUE" );
4128 dpurdie 8798
        return 1;
8799
    }
8800
 
6133 dpurdie 8801
    unless (@platforms) {
8802
        Debug3( " ActivePlatform(@_ == $ScmPlatform) = FALSE" );
8803
        return 0;
8804
    }
8805
 
8806
 
241 dpurdie 8807
    #   Platform specified may be an Alias
8808
    #   Perform alias expansion
8809
    #
8810
    @platforms = ExpandPlatforms( @platforms );         # aliasing
227 dpurdie 8811
    Debug3( " ActivePlatform(@_)" );
6198 dpurdie 8812
#    Debug0( " Platforms(@platforms)" );
227 dpurdie 8813
 
8814
#.. Arguments
241 dpurdie 8815
#   At this point we have a list of platforms and arguments
8816
#   Build up a hash of arguments for each platform being parsed
227 dpurdie 8817
#   Multiple arguments can follow a platform name
241 dpurdie 8818
#   Arguments apply to the preceeding platform name
227 dpurdie 8819
#
241 dpurdie 8820
    $platform = undef;
227 dpurdie 8821
    foreach ( @platforms )
8822
    {
241 dpurdie 8823
        if ( /^--Target/ ) {                     # Arguments
8824
            if ( $platform ) {
8825
                $arguments{$platform}{'Target'} = 1;
8826
            } else {
317 dpurdie 8827
                Warning ("No Platform preceding platform option: $_");
241 dpurdie 8828
            }
8829
 
305 dpurdie 8830
        } elsif ( /^--Only(Prod)|(Debug)/ || /--board=/ ) {
273 dpurdie 8831
            # Known arguments
305 dpurdie 8832
            # Bit of a kludge. Must be a better way
273 dpurdie 8833
 
241 dpurdie 8834
        } elsif ( /^--/ ) {
8835
            Warning ("Unknown platform option: $_");
8836
 
227 dpurdie 8837
        } else {                                # Target
8838
            $platform = $_;
241 dpurdie 8839
            push @plist, $platform;
227 dpurdie 8840
        }
8841
    }
8842
 
241 dpurdie 8843
#.. Scan the expression
227 dpurdie 8844
#
6198 dpurdie 8845
    $scmplatform = uc( $ScmPlatform );              # current platform
6133 dpurdie 8846
    my @add;
8847
    my @remove;
8848
    foreach ( @plist ) {
6198 dpurdie 8849
        my $platform = uc( Trim( $_ ) );            # trim white and convert case
6133 dpurdie 8850
        my $pname = $platform;
8851
        my $invert = 0;
8852
        if (substr($platform, 0, 1) eq '!') {
8853
            $invert = 1;
8854
            $pname = substr($platform, 1)
8855
        }
325 dpurdie 8856
 
227 dpurdie 8857
        #
241 dpurdie 8858
        #   Determine filter comparison
6133 dpurdie 8859
        #       Either a Platform or a Target
241 dpurdie 8860
        #
6133 dpurdie 8861
        if ( $arguments{$platform}{'Target'} ) {
8862
            $pname = $scmplatform if ($pname eq  uc( $ScmTarget ));
227 dpurdie 8863
        }
241 dpurdie 8864
 
6133 dpurdie 8865
        #
8866
        #   Catch some historically bad practices
8867
        #
8868
        $pname = $scmplatform if ( $pname eq '*'  || $pname eq '1' ); 
227 dpurdie 8869
 
6133 dpurdie 8870
        Debug3( "   Platform=$platform, PName=$pname" );
8871
 
227 dpurdie 8872
        #
8873
        #   Examine platform names
6133 dpurdie 8874
        #   Allow negation (removal) of the name
227 dpurdie 8875
        #
6133 dpurdie 8876
        if ( substr($platform, 0, 1) eq '!' )  {
8877
            push @remove, $pname; 
8878
        } else {
8879
            push @add, $pname; 
227 dpurdie 8880
        }
8881
    }
8882
 
241 dpurdie 8883
    #
6133 dpurdie 8884
    #   Build complete list of allowed platforms
8885
    #       Process additive rules before removal rules
8886
    #       If there are no additive rules, then assume all protaforms
241 dpurdie 8887
    #
6133 dpurdie 8888
    my %calcList;
8889
    @add = @::BUILDPLATFORMS unless @add;
6204 dpurdie 8890
    $calcList{uc $_} = 1 foreach (@add);
8891
    delete $calcList{uc $_} foreach (@remove);
6133 dpurdie 8892
#DebugDumpData("Add", \@add);
8893
#DebugDumpData("Remove", \@remove);
8894
#DebugDumpData("calcList", \%calcList);
241 dpurdie 8895
 
8896
    #
6133 dpurdie 8897
    #   If the current build target is left in the platform list, then we are building for it
8898
    #   
6198 dpurdie 8899
    if (exists $calcList{$scmplatform}) {
227 dpurdie 8900
        Debug3( " ActivePlatform(@_ == $ScmPlatform) = TRUE" );
8901
        return 1;
8902
    }
241 dpurdie 8903
 
227 dpurdie 8904
    Debug3( " ActivePlatform(@_ == $ScmPlatform) = FALSE" );
8905
    return 0;
8906
}
8907
 
8908
#-------------------------------------------------------------------------------
321 dpurdie 8909
# Function        : If
8910
#
8911
# Description     : Function for embedding arguments in directives
8912
#                   To be used within another directive
8913
#                   ie:
8914
#                       AnyDirective ('*',  arg1, arg2, ...
8915
#                                           If (SomePlatform, arg1, .. ,argn))
8916
#
8917
# Inputs          : $platform               - Active Platform speciifier
8918
#                   @args                   - Args
8919
#
8920
# Returns         : @args or nothing
8921
#
8922
sub  If
8923
{
8924
    my $platform = shift;
8925
    return @_
8926
        if ( ActivePlatform( $platform ));
8927
    return;
8928
}
8929
 
8930
#-------------------------------------------------------------------------------
227 dpurdie 8931
# Function        : RegisterMakefileGenerate
8932
#
8933
# Description     : Register a function to be called at the start of the
8934
#                   makefile generation process
8935
#
8936
# Inputs          : $fname      - Name of the function
8937
#                   $args       - Function Arguments
8938
#
8939
# Returns         : Nothing
8940
#
8941
our @MF_Generators;
8942
sub RegisterMakefileGenerate
8943
{
8944
   my ($fref) = @_;
8945
   my $rtype = ref($fref) || 'not a reference';
8946
 
8947
   Error ("RegisterMakefileGenerate called incorrectly",
8948
          "First argument MUST be a code reference",
8949
          "It is a $rtype"
8950
          ) unless ( $rtype eq 'CODE' );
8951
 
8952
   #
8953
   #    Save the arguments by reference in an array
8954
   #    The array will be processed later
8955
   #
8956
   push @MF_Generators, \@_;
8957
}
8958
 
8959
#-------------------------------------------------------------------------------
271 dpurdie 8960
# Function        : RegisterSrcHook
8961
#
8962
# Description     : Register a function to be called when a source file is
8963
#                   declared
8964
#
8965
# Inputs          : $ext        - Extension of interest
8966
#                                 '*' will be used by all
8967
#                   $fname      - Name of the function
8968
#                   $args       - Function Arguments
8969
#
8970
# Returns         : Nothing
8971
#
8972
sub RegisterSrcHook
8973
{
8974
    my $ext = shift;
8975
    my ($fref) = @_;
8976
    my $rtype = ref($fref) || 'not a reference';
8977
 
8978
    Error ("RegisterSrcHook called incorrectly",
8979
           "Second argument MUST be a code reference",
8980
           "It is a $rtype"
8981
           ) unless ( $rtype eq 'CODE' );
8982
 
8983
    #
8984
    #    Save the arguments by reference in an array
8985
    #    The array will be processed later
8986
    #
8987
    push @{$MF_RegisterSrcHooks{$ext}}, \@_;
8988
}
8989
 
8990
 
8991
#-------------------------------------------------------------------------------
227 dpurdie 8992
# Function        : MakefileHeader
8993
#
8994
# Description:    : Generate a "standard" makefile header.
8995
#
8996
#..
8997
 
8998
sub MakefileHeader
8999
{
9000
    my ($file, $desc, $by, @trailing) = @_;
9001
    my ($diff);
9002
 
9003
    $diff = 0 if (($diff = ((80-5) - length($desc))) < 0);
9004
    $desc .= ' ' . ('-' x $diff);
9005
 
9006
    print $file <<EOF;
9007
#-- $desc
9008
#
9009
#                   -- Please do not edit this file. --
9010
#
9011
#       To do so may result in a system failure, in additional to any
9012
#       changes made shall be overwritten.
9013
#
9014
# Created by $by
9015
#         on $::CurrentTime
9016
#
9017
EOF
9018
    #
9019
    #   Print out the trailer
9020
    #   This is an array. Place each entry on a new line
9021
    #
9022
    print $file $_ . "\n" for ( @trailing );
9023
}
9024
 
9025
###############################################################################
9026
# MakeFileGenerate:
9027
#       This subroutine does all of the actual make file generation based
9028
#       on information provided in the calls to the various public
9029
#       interface routines.
9030
#
9031
# Inputs:
9032
#
9033
# Returns:
9034
###############################################################################
9035
 
9036
my $MakefileGenerate_once = 0;
9037
sub MakefileGenerate
9038
{
9039
    my $Makefile = "$ScmPlatform.mk";
9040
    Debug( "MakefileGenerate: $Makefile" );
9041
 
9042
    #
9043
    #   Nasty things happen when we generate a makefile twice
9044
    #   Just warn the user and do nothing
9045
    #   If its in the common makefile.pl then just ignore it
9046
    #
9047
    if ( $ScmProcessingRootMake )
9048
    {
9049
        Warning ("MakefileGenerate directive is not allowed in common makefile.pl");
9050
        return;
9051
    }
9052
 
9053
    if ( $MakefileGenerate_once )
9054
    {
9055
        Warning ("MakefileGenerate should only be called once.",
9056
                 "Dir: $::Cwd");
9057
        return;
9058
    }
9059
    $MakefileGenerate_once = 1;
9060
 
9061
    #
9062
    #   Invoke all registered Makefile Generator functions
9063
    #   These allow clever directives to collect information to be
9064
    #   processed before the makefiles are created
9065
    #
9066
    while ( @MF_Generators )
9067
    {
9068
        Debug( "MakefileGenerate: Invoke RegisterMakefileGenerate function" );
9069
        my ($fname, @args) = @{shift @MF_Generators};
9070
        &$fname ( @args );
9071
    }
9072
 
9073
    #
9074
    #   Allow the toolset the opportunity to process all the collected data
9075
    #   before the makefile is created. This is optional
9076
    #
9077
    my( $if ) = MakeIf::Factory();              # build interface
9078
    $if->Preprocess();
9079
 
9080
    #
343 dpurdie 9081
    #   If we have supressed the Toolset use, then we need to sanity test
9082
    #   the use of the toolset
9083
    #
9084
    if ( $ScmNoToolsTest )
9085
    {
9086
        ReportError ("Building programs not supported with --NoToolset") if ( @PROGS || @TESTPROGS );
9087
        ReportError ("Building libraries not supported with --NoToolset") if ( @LIBS || @MLIBS || @SHLIBS );
9088
        ReportError ("Building projects not supported with --NoToolset") if ( %PROJECTS );
9089
        ErrorDoExit();
9090
    }
9091
 
9092
    #
227 dpurdie 9093
    #   Auto package the 'descpkg' file
9094
    #   If this makefile packages any files, then it can also package the descpkg file
9095
    #   The descpkg will be piggybacked into all makefiles that do a package
9096
    #
9097
    if ( %PACKAGE_FILES || %PACKAGE_HDRS || %PACKAGE_CLSS || %PACKAGE_LIBS
6387 dpurdie 9098
                        || %PACKAGE_SHLIBS || %PACKAGE_PROGS || @PACKAGE_DIRS )
227 dpurdie 9099
    {
251 dpurdie 9100
        Src ('*', 'descpkg') unless ($SRCS{ descpkg });
9101
        PackageFile ('*', 'descpkg');
227 dpurdie 9102
    }
9103
 
9104
    #
9105
    #   Some toolsets NEED a relative root
261 dpurdie 9106
    #   Note: At the moment ScmRoot is relative anyway, thus this code
9107
    #         does nothing
227 dpurdie 9108
    #
9109
    my $gbe_root = $::ScmRoot;
9110
    if ( $::UseRelativeRoot )
9111
    {
9112
        $gbe_root =  RelPath( $::ScmRoot );
9113
    }
9114
 
9115
    #
9116
    #   Now start to create the makefile
9117
    #
6133 dpurdie 9118
    ToolsetFiles::AddFile($Makefile);
285 dpurdie 9119
    open( MAKEFILE, '>', $Makefile ) || Error( "Cannot create $Makefile" );
227 dpurdie 9120
    ::MakefileHeader( *MAKEFILE,
9121
                      'Auto-generated Platform Dependent Makefile',
9122
                      "$ScmMakelib (version $ScmVersion)",
6177 dpurdie 9123
                      "# COPYRIGHT - VIX IP PTY LTD (\"VIX\"). ALL RIGHTS RESERVED.",
227 dpurdie 9124
                      '#',
9125
                      "# Located in $::Cwd",
9126
                      "# Platform $::ScmPlatform",
9127
                      '#' . ('-' x 79),
9128
                      );
9129
 
9130
    #
9131
    #   Ensure that some essential variables are set
9132
    #
9133
    print MAKEFILE <<EOF;
9134
#
9135
#   Validate essential environment variables
9136
#
9137
ifndef GBE_BIN
9138
    \$(error ERROR: GBE_BIN is not available)
9139
endif
9140
ifndef GBE_PERL
9141
    \$(error ERROR: GBE_PERL is not available)
9142
endif
9143
ifndef DEBUG
9144
    \$(error ERROR: DEBUG is not defined)
9145
endif
9146
EOF
9147
 
9148
 
9149
    print MAKEFILE <<EOF;
9150
 
9151
#
9152
#   Basic definitions
9153
#
343 dpurdie 9154
GBE_ROOT      := $gbe_root
9155
GBE_ROOT_ABS  := \$(abspath \$(GBE_ROOT))
9156
GBE_HOST      := $::ScmHost
9157
GBE_HOSTMACH  := $::GBE_MACHTYPE
9158
GBE_TARGET    := $::ScmTarget
9159
GBE_MACHTYPE  := $::ScmMachType
9160
GBE_PLATFORM  := $::ScmPlatform
9161
GBE_PBASE     := $::Pbase
9162
GBE_TYPE      := \$(if \$(findstring 1,\$(DEBUG)),D,P)
227 dpurdie 9163
EOF
9164
 
343 dpurdie 9165
MakePrint( "GBE_ARGS      := @ScmPlatformArgs\n" )
227 dpurdie 9166
    if ( scalar @ScmPlatformArgs );
9167
 
343 dpurdie 9168
MakePrint( "GBE_PRODUCT   := $ScmProduct\n" )
227 dpurdie 9169
    if ( $ScmProduct ne "" );
9170
 
343 dpurdie 9171
MakePrint( "GBE_OS_COMMON := $::BUILDINFO{$ScmPlatform}{OS_COMMON}\n" )
227 dpurdie 9172
    if ( exists($::BUILDINFO{$ScmPlatform}{OS_COMMON}) );
9173
 
9174
    print MAKEFILE <<EOF;
9175
 
9176
SHELL           := \$(GBE_BIN)/sh
9177
SHELLARGS       :=
9178
EXTENDED_LINE   := \$(GBE_BIN)/extend.lst
9179
export EXTENDED_LINE MAKE
9180
 
343 dpurdie 9181
MFLAGS           := --no-print --warn -r
9182
BUILDNAME        := $::ScmBuildName
9183
BUILDVER         := $::ScmBuildVersionFull
9184
BUILDVERNUM      := $::ScmBuildVersion
227 dpurdie 9185
BUILDPREVIOUSVER := $::ScmBuildPreviousVersion
343 dpurdie 9186
DEPLOYPATCH      := $ScmDeploymentPatch
9187
GBE_NOTOOLSTEST  := $ScmNoToolsTest
4781 dpurdie 9188
MAKEFILEUID      := $ScmMakeUid
9189
export MAKEFILEUID
227 dpurdie 9190
 
9191
#
9192
#   Ensure PWD is correctly set
9193
#
9194
PWD             := \$(CURDIR)
9195
export PWD
9196
 
261 dpurdie 9197
#
9198
#   NODEPEND    - Used to suppress generated dependency file checking
9199
#                 Mostly done in jmake.pl
9200
#   EXPERT      - Used to suppress dependency on this makefile
9201
#
9202
EOF
9203
 
285 dpurdie 9204
MakePrint( "EXPERT\t\t?= " . ($ScmExpert ? '1' : '0' ) . "\n" );
9205
MakePrint( "NODEPEND\t?= 0\n" );
261 dpurdie 9206
 
9207
print MAKEFILE <<EOF;
9208
 
9209
#
9210
#   SCM_MAKEFILE - The name of the file to depend upon
9211
#                  Supressed in EXPERT mode
9212
#
9213
ifneq (\$(EXPERT),0)
9214
SCM_MAKEFILE	:=
9215
else
9216
SCM_MAKEFILE	:= $Makefile
9217
endif
9218
EOF
9219
 
267 dpurdie 9220
#
9221
#   Setup the base directory for the packaging process
9222
#   When building a deployable package the base directory is changed to match
9223
#   that used by the deployment world. This is done so that the descpkg file
9224
#   can be created in the correct location
9225
#
9226
my  $PKGDIR = "pkg/$::Pbase";
9227
    $PKGDIR = "build/deploy" if ( $DEPLOYPACKAGE );
9228
Verbose("Setting PKGDIR: $PKGDIR");
9229
 
261 dpurdie 9230
print MAKEFILE <<EOF;
9231
 
227 dpurdie 9232
#--------- Targets -------------------------------------------------------------
9233
 
9234
.PHONY: 	default all build install package unpackage uninstall \\
9235
		clean unbuild clobber deploy
9236
 
373 dpurdie 9237
default:
227 dpurdie 9238
all:		install package deploy
9239
build:		make_init generate install_hdr depend make_lib \\
6387 dpurdie 9240
		install_lib make_install_shlib make_prog install_class install_dirs
227 dpurdie 9241
install:	build install_prog
6387 dpurdie 9242
package:	package_dirs package_files package_hdr package_lib package_shlib \\
9243
		package_prog package_class
227 dpurdie 9244
unpackage:	unpackage_class unpackage_prog unpackage_shlib \\
6387 dpurdie 9245
		unpackage_lib unpackage_hdr unpackage_files unpackage_dirs 
9246
uninstall:	uninstall_dirs uninstall_class uninstall_prog uninstall_shlib \\
227 dpurdie 9247
		uninstall_lib uninstall_hdr
9248
clean:		make_clean unmake_prog unmake_test unmake_lib unobj \\
261 dpurdie 9249
		undepend ungenerate rmlitter unmake_dir
227 dpurdie 9250
unbuild:	clean uninstall
6898 dpurdie 9251
clobber:	unpackage unbuild clobberfiles clobberdirs
227 dpurdie 9252
deploy:		install run_deploy
9253
 
9254
#--------- Macros --------------------------------------------------------------
9255
 
9256
OBJDIR		= \$(GBE_PLATFORM)\$(GBE_TYPE).OBJ
9257
LIBDIR		= \$(GBE_PLATFORM).LIB
9258
BINDIR		= \$(GBE_PLATFORM)\$(GBE_TYPE).BIN
9259
CLSDIR		= classes\$(GBE_TYPE)
9260
 
267 dpurdie 9261
PKGDIR		= \$(GBE_ROOT)/$PKGDIR
227 dpurdie 9262
INCDIR_PKG	= \$(PKGDIR)/include
9263
LIBDIR_PKG	= \$(PKGDIR)/lib
9264
BINDIR_PKG	= \$(PKGDIR)/bin
9265
CLSDIR_PKG	= \$(PKGDIR)/classes
4996 dpurdie 9266
UTFDIR_PKG	= \$(GBE_ROOT_ABS)/$PKGDIR/utfResults
227 dpurdie 9267
 
9268
LOCALDIR	= \$(GBE_ROOT)/local
9269
INCDIR_LOCAL	= \$(LOCALDIR)/inc
9270
LIBDIR_LOCAL	= \$(LOCALDIR)/lib
9271
BINDIR_LOCAL	= \$(LOCALDIR)/bin
9272
CLSDIR_LOCAL	= \$(LOCALDIR)/classes
9273
BINDIR_LOCAL_PATH = \$(GBE_ROOT_ABS)/local/bin/\$(GBE_PLATFORM)\$(GBE_TYPE)
9274
 
9275
INTERFACEDIR	= \$(GBE_ROOT)/$ScmInterface
9276
INCDIR_INTERFACE= \$(INTERFACEDIR)/include
9277
LIBDIR_INTERFACE= \$(INTERFACEDIR)/lib
9278
BINDIR_INTERFACE= \$(INTERFACEDIR)/bin
9279
CLSDIR_INTERFACE= \$(INTERFACEDIR)/classes
9280
 
9281
.SUFFIXES:		# Delete the default suffixes
9282
 
9283
EOF
9284
 
9285
    MakePrintList( \@DEFINES );
9286
    MakeNewLine();
9287
 
9288
#-------------------------------------------------------------------------------
9289
#
9290
#
261 dpurdie 9291
    MakeHeader ("Defines, flags and file sets");
227 dpurdie 9292
 
9293
    # Flags
6177 dpurdie 9294
    foreach my $opt ( sort keys %ScmCompilerOpts )
261 dpurdie 9295
    {
9296
        MakeDefEntry ( $opt, "=", $ScmCompilerOpts{$opt} );
9297
    }
227 dpurdie 9298
 
261 dpurdie 9299
    MakeDefEntry( "CFLAGS",         "=", \@CFLAGS, \@CFLAGS_PROD, \@CFLAGS_DEBUG );
9300
    MakeDefEntry( "CLINTFLAGS",     "=", \@CLINTFLAGS, \@CLINTFLAGS_PROD, \@CLINTFLAGS_DEBUG );
9301
    MakeDefEntry( "CDEPENDFLAGS",   "=", \@CFLAGS, \@CFLAGS_PROD, \@CFLAGS_DEBUG );
9302
    MakeDefEntry( "CXXFLAGS",       "=", \@CXXFLAGS, \@CXXFLAGS_PROD, \@CXXFLAGS_DEBUG );
9303
    MakeDefEntry( "CXXLINTFLAGS",   "=", \@CXXLINTFLAGS, \@CXXLINTFLAGS_PROD, \@CXXLINTFLAGS_DEBUG );
9304
    MakeDefEntry( "CXXDEPENDFLAG",  "=", \@CXXFLAGS, \@CXXFLAGS_PROD, \@CXXFLAGS_DEBUG );
267 dpurdie 9305
    MakeDefEntry( "ASFLAGS",        "=", \@ASFLAGS, \@ASFLAGS_PROD, \@ASFLAGS_DEBUG );
9306
    MakeDefEntry( "LDFLAGS",        "=", \@LDFLAGS, \@LDFLAGS_PROD, \@LDFLAGS_DEBUG );
227 dpurdie 9307
 
9308
 
9309
#-------------------------------------------------------------------------------
9310
#   
9311
#
261 dpurdie 9312
    MakeHeader ("Tool Search Path",
9313
                "Extend the PATH seen by all the tools to include",
9314
                "The tools/bin directories discovered in Packages" );
9315
    my $put_PATH;
9316
    my $put_LD_LIBRARY_PATH;
6504 dpurdie 9317
 
9318
    MakePrint( "PATH := \$(BINDIR_LOCAL_PATH)$::ScmPathSep\$(PATH)\n" );
9319
    $put_PATH = 1;
9320
 
261 dpurdie 9321
    for my $path ( ToolExtensionPaths() )
9322
    {
9323
        MakePrint( "PATH := $path$::ScmPathSep\$(PATH)\n" );
9324
        $put_PATH = 1;
227 dpurdie 9325
 
261 dpurdie 9326
        if ( $::ScmHost eq "Unix" )
9327
        {
227 dpurdie 9328
        MakePrint( "LD_LIBRARY_PATH ?= \n" );
9329
        MakePrint( "LD_LIBRARY_PATH := $path$::ScmPathSep\$(LD_LIBRARY_PATH)\n" );
261 dpurdie 9330
            $put_LD_LIBRARY_PATH =1;
9331
        }
227 dpurdie 9332
    }
9333
 
261 dpurdie 9334
    #   Export the appropriate environment variables
9335
    #   Note: Windows has an issue with PATH and Path
9336
    #         Haven't got to the bottom of it yet, but it would appear that DLL
9337
    #         searching uses Path and other stuff uses PATH. Not too sure how we
9338
    #         end up with two (or more in the environment)
9339
    #
9340
    #
9341
    if ( $put_LD_LIBRARY_PATH )
9342
    {
343 dpurdie 9343
        MakePrint( "export LD_LIBRARY_PATH\n" );
261 dpurdie 9344
    }
227 dpurdie 9345
 
261 dpurdie 9346
    if ( $put_PATH )
9347
    {
343 dpurdie 9348
        MakePrint( "Path := \$(PATH)\n" );
9349
        MakePrint( "export PATH Path\n" );
261 dpurdie 9350
    }
227 dpurdie 9351
 
9352
#-------------------------------------------------------------------------------
9353
#   
9354
#
261 dpurdie 9355
    MakeHeader ("Perl Module Search Path",
9356
                "Extend the PERL5LIB seen by invocations of perl");
227 dpurdie 9357
 
261 dpurdie 9358
    my $perl_module_found;
9359
    for my $path ( ToolExtensionPaths() )
227 dpurdie 9360
    {
6276 dpurdie 9361
        if (my @results =  glob( "$path/*.pm"))
261 dpurdie 9362
        {
6276 dpurdie 9363
            MakePrint( "PERL5LIB := $path$::ScmPathSep\$(PERL5LIB)\n" );
261 dpurdie 9364
            $perl_module_found = 1;
9365
        }
227 dpurdie 9366
    }
261 dpurdie 9367
    if ( $perl_module_found  )
9368
    {
227 dpurdie 9369
    MakePrint( "export PERL5LIB\n" );
261 dpurdie 9370
    }
227 dpurdie 9371
 
261 dpurdie 9372
#-------------------------------------------------------------------------------
227 dpurdie 9373
#   
9374
#
261 dpurdie 9375
    MakeHeader ("Include Search Paths",
367 dpurdie 9376
                "Package Include Paths for header files and libraries" );
227 dpurdie 9377
 
6177 dpurdie 9378
    MakeDefEntry( 'PINCDIRS'  , '=', '# includes');
9379
    MakeDefEntry( 'PINCDIRS_INTERFACE', '=', '# Interface includes');
9380
    MakeDefEntry( 'PINCDIRS_LOCAL', '=', '# Local includes');
9381
    MakeDefEntry( 'PLIBDIRS'  , '=', '# libraries');
9382
    MakeDefEntry( 'PLIBDIRS_INTERFACE', '=', '# Interface libraries');
9383
    MakeDefEntry( 'PLIBDIRS_LOCAL', '=', '# Local libraries');
367 dpurdie 9384
 
9385
    for my $package (@{$::ScmBuildPkgRules{$ScmPlatform} })
9386
    {
9387
        #
9388
        #   Skip the pseudo package that encapsulates the interface
9389
        #   directory. Currently the makefiles do this in a different
9390
        #   manner - to be resolved
9391
        #
9392
        #   Just comment out the lines so that the data is visible
9393
        #   Its a hint to make use of the data
9394
        #
9395
        my $prefix = '';
6177 dpurdie 9396
        my $suffix = '';
367 dpurdie 9397
        $prefix = '# ' if ( $package->{'TYPE'} eq 'build' );
9398
 
6177 dpurdie 9399
        #
9400
        #   The interface directory is a little bit different
9401
        #
9402
        my ($name,$base);
9403
        if ( $package->{'TYPE'} eq 'interface' ) {
9404
            $base = '$(INTERFACEDIR)';
9405
            $name = 'Interface Directory';
9406
            $suffix = '_INTERFACE';
9407
        } else {
9408
            $name = $package->{'NAME'} . '/' . $package->{'VERSION'};
9409
            $base = $package->{'ROOT'};
9410
        }
367 dpurdie 9411
 
1329 dpurdie 9412
        my @doc;
9413
        push (@doc, "From: $base");
9414
        push (@doc, 'BuildPkgArchive via Interface' )if $package->{'TYPE'} eq 'build' ;
367 dpurdie 9415
 
1329 dpurdie 9416
        MakeHeader ("Source: $name", @doc);
9417
 
367 dpurdie 9418
        #
9419
        #   List include and library directories
9420
        #   Note: Need the True Path for windows.
9421
        #       Some makefile functions (wildcard) only work as expected
9422
        #       if the case of the pathname is correct. Really only a problem
6177 dpurdie 9423
        #       with badly formed legacy packages where the Windows user
367 dpurdie 9424
        #       guessed at the package format.
9425
        #
9426
        #       The conversion to a TruePath is done when ScmBuildPkgRules
6177 dpurdie 9427
        #       is created. Create once, use many time.
367 dpurdie 9428
        #
6177 dpurdie 9429
        for my $type (qw (PINCDIRS PLIBDIRS) ) {
9430
            for my $path ( @{$package->{$type}} ) {
9431
                MakeDefEntry ( "$prefix$type$suffix", "+=", $base . $path);
367 dpurdie 9432
            }
9433
        }
9434
    }
9435
 
6177 dpurdie 9436
    #
9437
    #   Local Paths
9438
    #   These are a little bit special
9439
    #
9440
    MakeHeader ('Source: Local',  'From: Package Local');
9441
 
9442
    sub MakeLocalPaths 
9443
    {
9444
        my ($name, $root, $addRoot) = @_;
9445
        my @pathlist;
9446
 
9447
        foreach my $tag ( $ScmPlatform, $ScmProduct, $ScmTarget ) {
9448
            UniquePush( \@pathlist, "$root/$tag" ) if ( $tag );
9449
        }
9450
 
9451
        #   Add the root directory too
9452
        UniquePush( \@pathlist, $root) if $addRoot;
9453
 
9454
        MakeDefEntry ( $name , "+=", \@pathlist);
9455
    }
9456
 
9457
    MakeLocalPaths ( 'PINCDIRS_LOCAL', '$(INCDIR_LOCAL)', 1 );
9458
    MakeLocalPaths ( 'PLIBDIRS_LOCAL', '$(LIBDIR_LOCAL)', 0 );
9459
 
9460
 
367 dpurdie 9461
#-------------------------------------------------------------------------------
9462
#   
9463
#
9464
    MakeHeader ("Include Search Paths",
9465
                "Local Include Paths",
9466
                " LINKDIRS - Local include search path (short)",
9467
                " INCDIRS  - Include search path (complete)",
9468
                " NODEPDIRS - ",
9469
                " SRCDIRS - ",
9470
                " LIBDIRS - Library search path",
9471
 
9472
                );
9473
 
227 dpurdie 9474
    # Include search path
9475
    #
9476
    #   user-local
367 dpurdie 9477
    #   local
9478
    #   interface
9479
    #       BuildPkgArchive
9480
    #       LinkPkgArchive
227 dpurdie 9481
    #   user-global
9482
    #
9483
 
6177 dpurdie 9484
    MakeDefEntry ( "\nLINCDIRS",    "= ", \@L_INCDIRS );                    # .. Local
9485
    MakeDefEntry ( "LINCDIRS",      "+=", '$(PINCDIRS_LOCAL)');             # .. Sandbox local
9486
    MakeDefEntry ( "LINCDIRS",      "+=", '$(PINCDIRS_INTERFACE)');         # .. Sandbox interface
9487
    MakeDefEntry ( "LINCDIRS",      "+=", \@G_INCDIRS );                    # .. Global
227 dpurdie 9488
 
6177 dpurdie 9489
    MakeDefEntry ( "INCDIRS",  "= ", '$(LINCDIRS)' );                       # Local
9490
    MakeDefEntry ( "INCDIRS",  "+=", '$(PINCDIRS)' );                       # Package
9491
    MakeDefEntry ( "LINCDIRS", "+=", \@S_INCDIRS );                         # System
227 dpurdie 9492
 
9493
    # Source search path
9494
 
261 dpurdie 9495
    MakeDefEntry( "\nNODEPDIRS",        "=", \@NODEPDIRS );
227 dpurdie 9496
 
6177 dpurdie 9497
    MakeDefEntry( "\nSRCDIRS","= "  , [ @L_SRCDIRS, @G_SRCDIRS ] );         # Local
9498
    MakeDefEntry ( "SRCDIRS", "+=" , '$(PINCDIRS)' );                       # Package
9499
    MakeDefEntry ( "SRCDIRS", "+=" , \@S_INCDIRS );                         # System
227 dpurdie 9500
 
9501
    # Library search path
9502
    #
9503
    #   user-local
367 dpurdie 9504
    #   local
9505
    #   interface
9506
    #       BuildPkgArchive
9507
    #       LinkPkgArchive
227 dpurdie 9508
    #   user-global
6177 dpurdie 9509
    #   
9510
    #   Kludge Note:
9511
    #       The LIBDIRS path needs an element with a directory seperator in it
9512
    #       Needed by (broken) cmdfile o determine the file seperator to use
9513
    #       
227 dpurdie 9514
 
367 dpurdie 9515
    MakeDefEntry( "\nLIBDIRS",  "= ", '$(LIBDIR)' );                    # User Local
261 dpurdie 9516
    MakeDefEntry( "LIBDIRS",    "+=", \@L_LIBDIRS );                    # Local
6177 dpurdie 9517
    MakeDefEntry( "LIBDIRS",    "+=", '$(PLIBDIRS_LOCAL)' );            # Sandbox/local
9518
    MakeDefEntry( "LIBDIRS",    "+=", '$(PLIBDIRS_INTERFACE)' );        # Sandbox/interface
9519
    MakeDefEntry( "LIBDIRS",    "+=", '$(LIBDIR_INTERFACE)' );          # Kludge. See note above
261 dpurdie 9520
    MakeDefEntry( "LIBDIRS",    "+=", \@G_LIBDIRS );                    # Global
367 dpurdie 9521
    MakeDefEntry( "LIBDIRS",    "+=", '$(PLIBDIRS)' );                  # Package
261 dpurdie 9522
    MakeDefEntry( "LIBDIRS",    "+=", \@S_LIBDIRS );                    # System
227 dpurdie 9523
 
9524
#-------------------------------------------------------------------------------
9525
#
9526
#   Subdir creation and deletion
9527
#   Creation is done on the fly
9528
#   Deletion is done AFTER the toolset functions have been invoked to create the
9529
#   build artifacts so that the toolsets can create directories too
9530
 
9531
    MakeHeader ("Subdir creation");
9532
    CreateMkdirRules();
6177 dpurdie 9533
    MkdirRule( '$(OBJDIR)', 'OBJDIR', '--Extra=depend,depend.err' );    # Object build directory
2429 dpurdie 9534
    MkdirRule( '$(OBJDIR)/'.$_ ) foreach (@SHLIBS);                     # Shared library build directory
9535
    MkdirRule( '$(LIBDIR)', 'LIBDIR' );                                 # Library directory
9536
    MkdirRule( '$(BINDIR)', 'BINDIR' );                                 # Binary directory
227 dpurdie 9537
 
261 dpurdie 9538
    #
9539
    #   Create a directory for library merge tool to work within
9540
    #
9541
    MkdirRule( "\$(MLIBDIR)", 'MLIBDIR', '--Path=$(GBE_PLATFORM).MRG', '--RemoveAll' ) if (@MLIBS);
9542
 
227 dpurdie 9543
#-------------------------------------------------------------------------------
9544
#   Generate rules and recipes to create all the toolset specific parts
9545
#   This is done fairly early to allow the toolsets to extend various
9546
#   definitions that may be used later in the makefile construction
9547
#
9548
    MakeHeader ("Construct Programs");
9549
 
9550
    foreach my $i ( @PROGS )
9551
    {
289 dpurdie 9552
        my $pProg = $PROGS->Get($i);
9553
        my $pArgs = $pProg->getItems('ARGS');
9554
        my $pObjs = $pProg->getItems('OBJS');
9555
        my $pLibs = $pProg->getItems('LIBS');
227 dpurdie 9556
 
289 dpurdie 9557
        #
9558
        #   Create a list of program object files
9559
        #
9560
        push @PROGOBJS, @$pObjs;
227 dpurdie 9561
 
9562
        MakePrint( "#---- (${i})\n\n" );
9563
        if ( $ScmToolsetProgDependancies )
9564
        {
261 dpurdie 9565
            #
9566
            #   Original style Prog Interface
271 dpurdie 9567
            #   Write some dependency information here and some in the toolset
9568
            #   Problems:
9569
            #       1) Errors in library dependency generation will be
9570
            #          reported after all the object files have been created
9571
            #          Thus the error message and the make-stop are seperated
9572
            #          by many,many lines of output. This makes it difficult
9573
            #          to see the error.
261 dpurdie 9574
            #
271 dpurdie 9575
            #       2) Lack of Flexability
9576
            #
293 dpurdie 9577
            MakeEntry( "\$(BINDIR)/$i$::exe: ", "", "\\\n\t\t", ".$::o ", @$pObjs );
227 dpurdie 9578
        }
9579
        else
9580
        {
261 dpurdie 9581
            #
9582
            #   New Style Prog Interface
9583
            #   The toolset does it all
9584
            #
9585
            #   Flag the progam packaging as a placeholder.
9586
            #   The toolset will replace/update it.
9587
            #
227 dpurdie 9588
            PackageProgRemoveFiles( $i );
9589
        }
9590
 
289 dpurdie 9591
        $if->LD    ( $i, $pArgs, $pObjs, $pLibs );
9592
        $if->LDLINT( $i, $pArgs, $pObjs, $pLibs );
227 dpurdie 9593
    }
9594
 
9595
#-------------------------------------------------------------------------------
9596
#   
9597
#
9598
    MakeHeader ("Construct Test Programs");
289 dpurdie 9599
    foreach my $i ( @TESTPROGS )
227 dpurdie 9600
    {
289 dpurdie 9601
        my $pProg = $TESTPROGS->Get($i);
9602
        my $pArgs = $pProg->getItems('ARGS');
9603
        my $pObjs = $pProg->getItems('OBJS');
9604
        my $pLibs = $pProg->getItems('LIBS');
227 dpurdie 9605
 
289 dpurdie 9606
        #
9607
        #   Create a list of program object files
9608
        #
9609
        push @TESTPROGOBJS, @$pObjs;
9610
 
227 dpurdie 9611
        MakePrint( "#---- (${i})\n\n" );
9612
        if ( $ScmToolsetProgDependancies )
9613
        {
293 dpurdie 9614
            MakeEntry( "\$(BINDIR)/$i$::exe: ", "", "\\\n\t\t", ".$::o ", @$pObjs );
227 dpurdie 9615
        }
9616
        else
9617
        {
9618
            PackageProgRemoveFiles( $i );
9619
        }
9620
 
289 dpurdie 9621
        $if->LD    ( $i, $pArgs, $pObjs, $pLibs );
9622
        $if->LDLINT( $i, $pArgs, $pObjs, $pLibs );
227 dpurdie 9623
    }
9624
 
9625
#-------------------------------------------------------------------------------
9626
#
9627
#
9628
    MakeHeader ("Transfer Scripts to BINDIR");
9629
    foreach my $i ( sort ( values %SCRIPTS ))
9630
    {
9631
        my $tname = "\$(BINDIR)/" . StripDir( $i );
9632
 
9633
 
9634
        MakePrint( "$i:\t\tmakefile.pl\n" .
6177 dpurdie 9635
            "\t\$(XX_PRE)if [ ! -f \"$i\" ]; then echo 'Script [$i] not found'; exit 2; fi\n\n" );
227 dpurdie 9636
 
9637
        #
9638
        #   Create a rule to copy the script into the BIN directory
9639
        #   Mark the script as executable - It can't hurt and its there
9640
        #   to be run as part of a test.
9641
        #
9642
        MakePrint "$tname:\t\$(GBE_BINDIR) $i\n" .
9643
                  "\t\$(XX_PRE)\$(cp) -f $i $tname\n" .
9644
                  "\t\$(XX_PRE)\$(chmod) -f +wx $tname\n\n"
9645
    }
9646
 
9647
#-------------------------------------------------------------------------------
9648
#   
9649
#
9650
    MakeHeader ("Construct Libraries");
9651
    foreach my $i ( @LIBS )
9652
    {
289 dpurdie 9653
        my $pLib  = $LIBS->Get($i);
9654
        my $pArgs = $pLib->getItems('ARGS');
9655
        my $pObjs = $pLib->getItems('OBJS');
227 dpurdie 9656
 
363 dpurdie 9657
        unless ( $ScmToolsetNillLibSrc )
9658
        {
9659
            Error ("Library has no component objects: $i")
9660
                if ( scalar @$pObjs <= 0 );
9661
        }
299 dpurdie 9662
 
227 dpurdie 9663
        MakePrint "#---- (${i})\n\n";
289 dpurdie 9664
        $if->AR(     $i, $pArgs, $pObjs, $pLib);
9665
        $if->ARLINT( $i, $pArgs, $pObjs, $pLib );
227 dpurdie 9666
    }
9667
 
289 dpurdie 9668
#-------------------------------------------------------------------------------
9669
#   
9670
#
9671
    MakeHeader ("Construct Merged Libraries");
227 dpurdie 9672
    sub MlibEntry
9673
    {
289 dpurdie 9674
        my( $mlib, $plib, $pLibs ) = @_;
227 dpurdie 9675
        my @flib;
9676
 
289 dpurdie 9677
        MakePrint '$(LIBDIR)/' . GenLibName($mlib) . ":";
9678
        foreach my $lib ( @$pLibs )
227 dpurdie 9679
        {
289 dpurdie 9680
            #
9681
            #   Each library name may contains one embedded option which
9682
            #   specifies the source directory
9683
            #       libname[,--Option | BaseSubdir]
9684
            #
227 dpurdie 9685
            my ($slib, $sdir) = split( ',', $lib );
343 dpurdie 9686
            my $mode;
227 dpurdie 9687
 
9688
            #
283 dpurdie 9689
            #   By default the librares are pulled from LOCAL unless the
9690
            #   library is built in this directory, in which case it will
289 dpurdie 9691
            #   be used.
227 dpurdie 9692
            #
289 dpurdie 9693
            $sdir = ( $LIBS->Get($slib) ) ? '--Here' : '--Local'
9694
                unless ( $sdir );
227 dpurdie 9695
 
9696
            #
9697
            #   --Interface     - Pull library from the interface directory
9698
            #   --Local         - Pull library from the local directory
9699
            #   --SubDir=xxxx   - Pull library from specified subdirectory
283 dpurdie 9700
            #   --Here          - Pull from local directory if built locally
227 dpurdie 9701
            #   otherwise       - Pull library from specified subdirectory
9702
            #
9703
            if ($sdir eq '--Interface') {
9704
                $sdir = '$(LIBDIR_INTERFACE)/$(GBE_PLATFORM)';
9705
 
343 dpurdie 9706
 
9707
            } elsif ($sdir eq '--InterfacePlain') {
9708
                $sdir = '$(LIBDIR_INTERFACE)/$(GBE_PLATFORM)';
9709
                $mode = 1;
9710
 
227 dpurdie 9711
            } elsif ( $sdir eq '--Local') {
9712
                $sdir = $PackageInfo{'Lib'}{'IBase'} .  # Base of Installed libs
9713
                        $PackageInfo{'Lib'}{'Dir'};     # Default subdir
9714
 
9715
            } elsif ( $sdir =~ m~^--SubDir=(.*)~ ) {
9716
                $sdir = $1 . '/$(LIBDIR)';
9717
 
283 dpurdie 9718
            } elsif ( $sdir eq '--Here') {
9719
                $sdir = '$(LIBDIR)';
9720
 
227 dpurdie 9721
            } else {
9722
                $sdir .= '/$(LIBDIR)';
9723
            }
9724
 
343 dpurdie 9725
            MakePrint " \\\n\t\t${sdir}/" . GenLibName($slib, $mode);
227 dpurdie 9726
            push @flib, "${sdir}/${slib}";
9727
        }
289 dpurdie 9728
        return \@flib;
227 dpurdie 9729
    }
9730
 
9731
    foreach my $i ( @MLIBS )
9732
    {
289 dpurdie 9733
        my $pLib  = $MLIBS->Get($i);
9734
        my $pArgs = $pLib->getItems('ARGS');
9735
        my $pLibs = $pLib->getItems('LIBS');
227 dpurdie 9736
 
261 dpurdie 9737
        MakePrint "#---- (${i})\n\n";
9738
 
227 dpurdie 9739
        unless ( defined &ToolsetARMerge )
9740
        {
9741
            Warning( "Merging of libraries not supported in this toolset yet" );
9742
            Warning( "MergeLibrary: \"$i\" will not be created" );
9743
        }
9744
        else
9745
        {
9746
            #
9747
            #   Create the dependency rule
9748
            #       Target library : source library list
9749
            #           Recipe - generated by the toolset
9750
            #
289 dpurdie 9751
            foreach ( @$pArgs )
227 dpurdie 9752
            {
9753
                Warning( "Ignoring unknown argument to MergeLibrary. $_" );
9754
            }
289 dpurdie 9755
            $pLibs = MlibEntry( $i, $pLib, $pLibs );
9756
            $if->ARMerge( $i, $pArgs, $pLibs, $pLib );
227 dpurdie 9757
        }
9758
    }
9759
 
289 dpurdie 9760
#-------------------------------------------------------------------------------
9761
#   
9762
#
9763
    MakeHeader ("Construct Shared Libraries");
339 dpurdie 9764
 
227 dpurdie 9765
    foreach my $i ( @SHLIBS )
9766
    {
289 dpurdie 9767
        my $pShlib  = $SHLIBS->Get($i);
9768
        my $pArgs = $pShlib->getItems('ARGS');
9769
        my $pObjs = $pShlib->getItems('OBJS');
9770
        my $pLibs = $pShlib->getItems('LIBS');
9771
        my $version = $pShlib->{VERSION};
227 dpurdie 9772
 
289 dpurdie 9773
        $if->SHLD    ( $i, $pArgs, $pObjs, $pLibs, $version );
9774
        $if->SHLDLINT( $i, $pArgs, $pObjs, $pLibs, $version );
227 dpurdie 9775
    }
9776
 
9777
#-------------------------------------------------------------------------------
9778
#   Construct Objects
9779
#   For each object within OBJSOURCE construct the following:
9780
#
9781
#   $(OBJDIR)/object-name:     source-name [makefile]
9782
#       Toolset ...
9783
#
9784
#   
9785
#
9786
    MakeHeader ("Construct Objects");
371 dpurdie 9787
 
227 dpurdie 9788
    foreach my $i ( sort keys %OBJSOURCE )
9789
    {
9790
        my( $src, $sname, $ext, $type, @args );
9791
 
9792
        $src  = $OBJSOURCE{ $i };
9793
        $sname = StripDir( $src );
9794
        $ext  = StripFile( $src );
9795
        $ext = lc($ext)
9796
            if ( $::ScmHost ne "Unix" );
381 dpurdie 9797
        $type = ($ScmSourceTypes{ $ext } || '')
227 dpurdie 9798
            unless (( $type = $SRC_TYPE{ $sname }) );
9799
 
9800
        #
9801
        #   Object source is an object file
9802
        #   No need the generate the object, just create makefile rule
261 dpurdie 9803
        #   [ddp] Not too sure how we get here
227 dpurdie 9804
        #
9805
        if ( $ext eq ".$::o" )
9806
        {
9807
            MakePrint "$src:";
261 dpurdie 9808
            MakePrint " \$(SCM_MAKEFILE)";
227 dpurdie 9809
            MakeNewLine();
9810
            next;
9811
        }
9812
 
9813
        #
9814
        #   Need to create object file
9815
        #
9816
        @args = split( /$;/, $SRC_ARGS{ StripDir( $sname ) } )
9817
            if $SRC_ARGS{ $sname };
9818
 
9819
        push( @args, "--Shared" )
9820
            if ( exists $SHOBJ_LIB{$i} );
9821
 
9822
        #
9823
        #   Convert relative paths to absolute paths if required by the
9824
        #   toolset. Some compilers need ABS paths to generate nice debug
9825
        #   information.
9826
        #
9827
        $src = AbsPath($src)
9828
            if ( $UseAbsObjects );
9829
 
9830
        #
9831
        #   Extract any user specified dependancies
261 dpurdie 9832
        #   These will be added to the dependency list
227 dpurdie 9833
        #
9834
        my @dlist;
9835
        @dlist = split( /$;/, $SRC_DEPEND{$sname} )
9836
            if ( exists $SRC_DEPEND{$sname} );
9837
 
261 dpurdie 9838
        #
9839
        #   Create the dependency part of the object rule
9840
        #   The source file MUST be the first dependent recipes
9841
        #   may assume that $< is the name source file
9842
        #
9843
        MakeEntry( "\$(OBJDIR)/$i.$::o: $src \$(SCM_MAKEFILE)", "", " \\\n\t", "", @dlist );
227 dpurdie 9844
 
9845
        if ( $type eq ".c" ) {
9846
            $if->CC(  $src, $i, \@args );
261 dpurdie 9847
 
227 dpurdie 9848
        } elsif ( $type eq ".cc" ) {
9849
            $if->CXX( $src, $i, \@args );
261 dpurdie 9850
 
227 dpurdie 9851
        } elsif ( $type eq ".asm" ) {
9852
            $if->AS( $src, $i, \@args );
261 dpurdie 9853
 
227 dpurdie 9854
        } else {
9855
            $if->EXT( $src, $i, \@args ) ||
9856
                Warning( "Don't know how to build '$ext' images' for $src, $i" );
9857
            MakeNewLine();
9858
        }
9859
    }
9860
 
9861
#-------------------------------------------------------------------------------
9862
#   Construct Projects
9863
#   Construct toolset specific projects
9864
#
9865
    MakeHeader ("Construct Projects");
9866
    while ( my($project, $entry) = each %PROJECTS)
9867
    {
9868
        $if->PROJECT( $entry );
9869
    }
9870
 
9871
#-------------------------------------------------------------------------------
4761 dpurdie 9872
#   Automated tests
9873
#
9874
    MakeHeader ("Automated tests");
9875
 
9876
    my $idx = 0;
9877
    my @copy_set = ();
9878
 
227 dpurdie 9879
    foreach my $pEntry ( @TESTS_TO_RUN )
9880
    {                                           # Foreach test
9881
        $idx++;
9882
        $pEntry->{'index'} = $idx;
9883
        $pEntry->{'test_name'} = "run_test_$idx";
5708 dpurdie 9884
        $pEntry->{'echoname'} = $pEntry->{'utfname'} || '';  
4781 dpurdie 9885
        $pEntry->{'utfname'} = $pEntry->{'test_name'} unless defined $pEntry->{'utfname'};  
227 dpurdie 9886
 
9887
        #
9888
        #   If the test is being run within a 'FrameWork' then the underlying
9889
        #   toolset must instantiate the frame work.
9890
        #
9891
        #   This may change. Perhaps frameworks shouldn't be a part of the
9892
        #   toolset. Perhaps they should be standalone. May change
9893
        #
9894
        if ( $pEntry->{framework} )
9895
        {
9896
            $if->TESTFRAMEWORK( $pEntry );
9897
        }
9898
 
9899
        #
9900
        #   Create a rule to run the test
9901
        #
9902
 
9903
        my $tdir_alias = $pEntry->{'testdir'};
9904
        my $tdir = '$(' . $tdir_alias . ')';
9905
 
9906
        my $test_name = $pEntry->{'test_name'};
4996 dpurdie 9907
        push @TESTPROJECT_TO_URUN, $test_name;
4501 dpurdie 9908
        push @TESTPROJECT_TO_ARUN, $test_name if     ($pEntry->{'auto'} );
227 dpurdie 9909
 
9910
        my $tprog = $tdir . '/' . StripDir( $pEntry->{'prog'} );
5695 dpurdie 9911
 
9912
        #
9913
        #   Determine the maximum time that the automated test should run
9914
        #       Default is 30 minutes
9915
        #   Non-auto tests are not time limited
9916
        #       
9917
        my $timeout = '';
5848 dpurdie 9918
        if ($pEntry->{'auto'})
5695 dpurdie 9919
        {
5848 dpurdie 9920
            $timeout = 'timeout -Time:' . ($pEntry->{'maxtime'} || '30m') . ' ';
5695 dpurdie 9921
        }
227 dpurdie 9922
 
9923
        my $me = MakeEntry::New( *MAKEFILE, $test_name, '--Phony' );
4781 dpurdie 9924
 
9925
        #
4996 dpurdie 9926
        #   Export GBE_UTF... for the duration of the test
4781 dpurdie 9927
        #
9928
        $me->AddDefn('export GBE_UTFNAME', $pEntry->{'utfname'});
9929
        $me->AddDefn('export GBE_UTFUID', '$(MAKEFILEUID)' . '_' . $pEntry->{'index'});
4996 dpurdie 9930
        $me->AddDefn('export GBE_UTFFILE','$(UTFDIR_PKG)/$(GBE_PLATFORM)-$(GBE_TYPE)-$(GBE_UTFUID)' . '.xml');
6619 dpurdie 9931
        $me->AddDefn('export GBE_UTFTEST','TEST-$(GBE_UTFNAME)-$(GBE_TYPE)-$(GBE_UTFUID)' );
4781 dpurdie 9932
 
6619 dpurdie 9933
        #
9934
        #   A bit of a kludge for 'googletest'
9935
        #       If we have another kludge like then then consider placing this work into a module based on the filter name
9936
        #       with some sort of interface to allow the ENVvars and format and command line args to be massaged
9937
        #       
9938
        #   For googletest
6898 dpurdie 9939
        #       Set EnvVar and then post process with junit
6619 dpurdie 9940
        #
6628 dpurdie 9941
        if ($pEntry->{'utfformat'})
9942
        {
9943
            if ($pEntry->{'utfformat'} eq 'gtest') {
9944
                $pEntry->{'utfformat'} = 'junit';
9945
                $me->AddDefn('export GTEST_OUTPUT ', 'xml:${GBE_UTFTEST}.xml');
9946
            }
6619 dpurdie 9947
        }
9948
 
5986 dpurdie 9949
        # Workaround for dirsep under windows when being wrapped in a timeout
9950
        $me->AddDefn('dirsep', '$(dirsep)$(dirsep)') if ($timeout && ($::ScmHost ne "Unix"));
9951
 
227 dpurdie 9952
        $me->AddDependancy( "\$(GBE_$tdir_alias)" );
9953
        $me->AddDependancy( "\$(INTERFACEDIR)/set_$::ScmPlatform.sh" );
9954
        $me->AddDependancy( $tprog ) if $pEntry->{'copyprog'};
9955
        $me->AddDependancy( @{ $pEntry->{'copyin' } } );
9956
        $me->AddDependancy( map { $tdir . '/' . StripDir($_) } @{ $pEntry->{'copyonce' } } );
9957
        $me->AddDependancy( @{ $pEntry->{'preq'} } );
9958
        $me->RecipePrefix ('$(XX_PRE)');
5708 dpurdie 9959
        $me->RecipeWrapper( $timeout . 'sh -c \'', '\'') if $timeout;
9960
        $me->RecipeComment( "------ Running test [$idx] $pEntry->{'echoname'} ..." );
227 dpurdie 9961
 
9962
        #
4996 dpurdie 9963
        #   Create package utfResults directory
9964
        #       Simplify use of the file
9965
        #
9966
        $me->AddShellRecipe ( 'mkdir -p $(UTFDIR_PKG)' );
9967
 
9968
        #
227 dpurdie 9969
        #   Extend the PATH seen by the script to include the local/bin directory
9970
        #   Allows programs and tests that have been created elsewhere in the component
9971
        #   to be accessed within the script.
9972
        #
9973
        $me->AddShellRecipe ( ". \$(INTERFACEDIR)/set_$::ScmPlatform.sh" );
9974
 
9975
        #
9976
        #   Copy in the files that we need
9977
        #
9978
        foreach my $file ( @{$pEntry->{'copyin'}} )
9979
        {
9980
            my $dst = $tdir . '/' . StripDir( $file );
9981
            UniquePush( \@COPYIN, $dst );
9982
            UniquePush( \@copy_set, $file );
9983
            $me->AddShellRecipe ( "\$(cp) -f $file $dst" );
9984
            $me->AddShellRecipe ( "\$(chmod) -f +wx $dst" );
9985
        }
9986
 
9987
        #
4778 dpurdie 9988
        #   Insert any FrameWork Recipe bits
227 dpurdie 9989
        #
9990
        $me->AddShellRecipe ( @{$pEntry->{'ShellRecipe'}} );
9991
 
4781 dpurdie 9992
        #
9993
        #   Insert command
5035 dpurdie 9994
        #       Save result code to a known file
4781 dpurdie 9995
        #
227 dpurdie 9996
        $me->AddShellRecipe ( "cd $tdir" );
9997
        $me->AddShellRecipe ( ["GBE_TYPE=\$(GBE_TYPE)",
9998
                               "GBE_HOST=\$(GBE_HOST)",
9999
                               "GBE_ROOT=\$(GBE_ROOT_ABS)",
4095 dpurdie 10000
                               "PATH=.\\$::ScmPathSep\$(BINDIR_LOCAL_PATH)\\$::ScmPathSep\$\$PATH",
5708 dpurdie 10001
                               $pEntry->{'command'},
227 dpurdie 10002
                               @{$pEntry->{'args'}},
5035 dpurdie 10003
                               ] , 
10004
                               'echo $$? > utf.$${GBE_UTFUID}.rc' );
10005
 
10006
        #
10007
        #   Create the basic command line for 'jats_runutf'
10008
        #       Use the simplistic 'internal' filter unless the user has provided one
10009
        #
10010
        my @cmdline;
10011
        push @cmdline, '--';
10012
        push @cmdline, '$(VERBOSE_OPT)';
10013
        push @cmdline, '-filter=' . ($pEntry->{'utfformat'} || 'internal');
10014
        push @cmdline, '-root=$(GBE_ROOT_ABS)' ;
10015
        push @cmdline, "-dir=$tdir";
10016
        push @cmdline, '-target=$(GBE_PLATFORM)';
10017
        push @cmdline, '-pkgdir=$(PKGDIR)';
10018
        push @cmdline, '-local=$(LOCALDIR)';
10019
        push @cmdline, '-interface=$(INTERFACEDIR)';
6898 dpurdie 10020
        push @cmdline, '-rcfile=utf.$${GBE_UTFUID}.rc';
10021
        push @cmdline, map { '-arg='. $_ } @{$pEntry->{'utfargs' }};
5035 dpurdie 10022
 
10023
        #
10024
        #   Insert commands to post process the test results according to the specified formatter
10025
        #
10026
        $me->NewSection     ();
10027
        $me->SectionIfDef   ('UTF_POSTPROCESS');
10028
        $me->RecipePrefix   ('$(XX_PRE)');
6898 dpurdie 10029
        $me->AddOneRecipe   ( "\$(GBE_PERL) -Mjats_runutf -e processUtf", @cmdline );
4778 dpurdie 10030
 
227 dpurdie 10031
        $me->Print();
10032
 
10033
 
10034
        #
10035
        #   Create entries to handle the copy-once files
10036
        #
10037
        foreach my $file ( @{ $pEntry->{'copyonce' } } )
10038
        {
10039
            my $tname = $tdir . '/' . StripDir($file);
10040
            my $me = MakeEntry::New( *MAKEFILE, $tname  );
10041
            $me->AddDependancy( $file );
10042
            $me->AddRecipe ( "\$(call CopyFile,CopyIn,$tname,$file,$tdir,)"  );
10043
            $me->Print();
10044
 
10045
            UniquePush( \@COPYIN, $tname );
10046
            UniquePush( \@copy_set, $file );
10047
 
10048
        }
10049
    }
10050
 
10051
    #
10052
    #   Generate sanity test for each copyin script
10053
    #   Simply to provide a nice error message for generated scripts
10054
    #   that do not exist at run-time
10055
    #
10056
    test_copy_in:
10057
    foreach my $i ( @copy_set )
10058
    {
10059
        next if ( $SCRIPTS{$i} );
10060
        foreach (  @SHLIB_TARGETS )
10061
        {
10062
            next test_copy_in if ( $i eq $_ );
10063
        }
10064
        MakePrint( "\n$i:\t\tmakefile.pl\n" .
6177 dpurdie 10065
            "\t\@if [ ! -f \"$i\" ]; then echo 'ERROR: CopyIn Script [$i] not found'; exit 2; fi\n" );
227 dpurdie 10066
    }
10067
 
261 dpurdie 10068
#-------------------------------------------------------------------------------
10069
#   Deploy rules
10070
#
10071
MakeHeader ("Deploy Rules");
227 dpurdie 10072
 
261 dpurdie 10073
print MAKEFILE <<EOF;
10074
.PHONY:		run_deploy
10075
EOF
227 dpurdie 10076
 
261 dpurdie 10077
#
10078
#   Build up the deployfile.pl command line from the available pieces
10079
#
10080
my $command_file = "";
10081
my @command_line;
10082
 
10083
if ( %DEPLOYPACKAGE )
10084
{
10085
    $command_file = $DEPLOYPACKAGE{'cmdfile'};
10086
 
10087
    push @command_line, "\$(XX_PRE)\$(GBE_PERL) -w $command_file";
10088
    push @command_line, "-r \"\$(GBE_ROOT)\"";
10089
    push @command_line, "-n \"$DEPLOYPACKAGE{'name'}\"";
10090
    push @command_line, "-d \"$DEPLOYPACKAGE{'dir'}\"";
10091
    push @command_line, "-v \"\$(BUILDVER)\"";
10092
    push @command_line, "-t \"\$(GBE_TYPE)\"";
10093
    push @command_line, "-o \"\$(BUILDPREVIOUSVER)\"";
10094
    push @command_line, "-m \"\$(GBE_PLATFORM)\"";
10095
    push @command_line, "-g \"\$(GBE_TARGET)\"";
10096
    push @command_line, "-k \"\$(GBE_PRODUCT)\""        if ( $ScmProduct );
10097
    push @command_line, "-p \"\$(DEPLOYPATCH)\""        if ( $ScmDeploymentPatch );
10098
 
10099
}
10100
 
10101
MakeEntry( "run_deploy:\t$command_file\n", "\n", "\t\t", " \\\n", @command_line );
10102
 
227 dpurdie 10103
#-------------------------------------------------------------------------------
261 dpurdie 10104
#   Custom Rules
10105
#
10106
    MakeHeader ("Custom Rules");
10107
    MakePrintList ( \@RULES );
10108
 
10109
#-------------------------------------------------------------------------------
10110
#   Generated Files
10111
#
10112
    MakeHeader ("Generated Files");
10113
    MakePrint ("\n.PHONY: phony_generate\n\n" );
6898 dpurdie 10114
    my $generateMustAddTestPostProcess;
261 dpurdie 10115
    foreach my $i ( @GENERATE_FILES )
10116
    {
10117
        my $gen_tag = $i->{'index'};
6898 dpurdie 10118
        my $genName = 'generate_' . $gen_tag;
10119
 
10120
        my $me = MakeEntry::New( *MAKEFILE );
10121
        $me->AddComment    ('Generate Files');
10122
        $me->AddName(@{$i->{'gen'}});
10123
 
6415 dpurdie 10124
        #
10125
        #   Generate user-provided recipe names to allow the rule to be called by name.
10126
        #
10127
        my $recipeTag = $i->{'recipeTag'} || '';
10128
        my $recipeName = '';
10129
        my $recipeCleanName = '';
261 dpurdie 10130
 
6415 dpurdie 10131
        if ($recipeTag) {
10132
            $recipeName = $recipeTag;
10133
            $recipeCleanName = 'clean_' . $recipeTag;
10134
 
10135
            # for 'jats make help'
10136
            $ScmRecipeTags{$recipeTag} = defined $i->{'clean'} ? 1 : 0;
10137
 
6898 dpurdie 10138
            $me->Phony() ;
10139
            $me->AddName($recipeName);
6415 dpurdie 10140
        }
10141
 
261 dpurdie 10142
        #
263 dpurdie 10143
        #   If predelete is enabled, then create a list of files to delete
10144
        #
6898 dpurdie 10145
        if ( $i->{'predelete'}  ) {
10146
            $me->AddDefn("generate_gen_$gen_tag", join(' ', @{$i->{'gen'}} )  );
263 dpurdie 10147
        }
10148
 
6898 dpurdie 10149
        my $target = join (' ', @{$i->{'gen'}}, $recipeName);
263 dpurdie 10150
 
10151
        #
6898 dpurdie 10152
        #   If a UnitTest then insert runtime defs
10153
        #
10154
        if ($i->{'isautf'})
10155
        {
10156
            my $test_name = $i->{'gen'}[0];
10157
            $generateMustAddTestPostProcess = 1;
10158
 
10159
            push @TESTPROJECT_TO_URUN, $test_name;
10160
            push @TESTPROJECT_TO_ARUN, $test_name if ($i->{'utfauto'} );
10161
 
10162
            $me->AddComment    ('  This is a Unit Test');
10163
            $me->AddDefn('export GBE_UTFNAME', $test_name );
10164
            $me->AddDefn('export GBE_UTFUID', 'G$(MAKEFILEUID)' . '_' . $i->{'index'});
10165
            $me->AddDefn('export GBE_UTFFILE','$(UTFDIR_PKG)/$(GBE_PLATFORM)-$(GBE_TYPE)-$(GBE_UTFUID)' . '.xml');
10166
            $me->AddDefn('export GBE_UTFTEST','TEST-$(GBE_UTFNAME)-$(GBE_TYPE)-$(GBE_UTFUID)' );
10167
        }
10168
 
10169
        #
261 dpurdie 10170
        #   Generate the basic generate rule and recipe
10171
        #   together with the prerequisites
10172
        #
10173
        unless ( $i->{'clean'} && $i->{'shell'} )
10174
        {
6898 dpurdie 10175
            $me->AddDependancy(@{$i->{'preq'}});
10176
            $me->AddDependancy("phony_generate") if $i->{'preq_sus'};
10177
            $me->AddDependancy("\$(SCM_MAKEFILE)");
10178
            $me->RecipePrefix   ('$(AA_PRE)');
10179
            $me->AddRecipe("\$(echo) '[$i->{'text'}] generating..'");
10180
            $me->RecipePrefix   ('$(XX_PRE)');
10181
            $me->AddRecipe("\$(call RmFiles,generate_gen_$gen_tag)") if ( $i->{'predelete'}  );
261 dpurdie 10182
 
6898 dpurdie 10183
            if ($i->{'isautf'}) {
10184
                my $filter = $i->{'utfformat'} || 'internal';
10185
                my $uargs = join(' ', map { '-arg='. $_ } @{$i->{'utfargs' }});
10186
                my $tdir = $i->{'utfdir'} || '.';
10187
                $me->AddShellRecipe (  [
10188
                                       "PATH=.\\$::ScmPathSep\$(BINDIR_LOCAL_PATH)\\$::ScmPathSep\$\$PATH",
10189
                                       "\$(call $genName,)"
10190
                                       ] , 
10191
                                       'echo $$? > ${INTERFACEDIR}/utf.$${GBE_UTFUID}.rc',
10192
                                       "\$(call UtfPostProcess,$filter,$tdir,$uargs)" );
10193
 
10194
            } else {
10195
                $me->AddRecipe("\$(call $genName,)");
263 dpurdie 10196
            }
261 dpurdie 10197
        }
6898 dpurdie 10198
        $me->Print();
261 dpurdie 10199
 
10200
        #
10201
        #   Generate 'clean' rules and recipes
10202
        #
10203
        if ( $i->{'clean'} )
10204
        {
6898 dpurdie 10205
            my $me = MakeEntry::New( *MAKEFILE, "clean_$genName", '--Phony' );
10206
            $me->AddName($recipeCleanName) if $recipeCleanName;
10207
            $me->RecipePrefix('$(XX_PRE)');
10208
            $me->AddRecipe("-\$(call $genName,$i->{'clean'})");
10209
            $me->Print();
261 dpurdie 10210
        }
10211
 
10212
        #
10213
        #   Define a function to contain the body of the generation call
10214
        #   The first argument will be a 'clean' argument
10215
        #
6898 dpurdie 10216
        my $md = MakeEntry::New( *MAKEFILE, $genName, '--Define' );
10217
        if ( $i->{'shell'} ) {
10218
            $md->AddShellRecipe( @{$i->{'toolargs'}} );
10219
 
10220
        } else {
10221
            $md->AddOneRecipe( $i->{'tool'} . ' $1' ,@{$i->{'toolargs'}} );
261 dpurdie 10222
        }
6898 dpurdie 10223
        $md->Print();
261 dpurdie 10224
    }
10225
 
6898 dpurdie 10226
    if ($generateMustAddTestPostProcess)
10227
    {
10228
        #
10229
        #   Define the UTF post processing
10230
        #   Define amacro thattakes two arguments
10231
        #       $1 - name of the filter
10232
        #       $2 - Directory to process
10233
        #       $3 - additional arguments
10234
        #
10235
 
10236
        #
10237
        #   Create the basic command line for 'jats_runutf'
10238
        #       Use the simplistic 'internal' filter unless the user has provided one
10239
        #
10240
        my @cmdline;
10241
        push @cmdline, '--';
10242
        push @cmdline, '$(VERBOSE_OPT)';
10243
        push @cmdline, '-filter=$1';
10244
        push @cmdline, '-root=$(GBE_ROOT_ABS)' ;
10245
        push @cmdline, '-dir=$2';
10246
        push @cmdline, '-target=$(GBE_PLATFORM)';
10247
        push @cmdline, '-pkgdir=$(PKGDIR)';
10248
        push @cmdline, '-local=$(LOCALDIR)';
10249
        push @cmdline, '-interface=$(INTERFACEDIR)';
10250
        push @cmdline, '-rcfile=${INTERFACEDIR}/utf.$${GBE_UTFUID}.rc';
10251
        push @cmdline, '$3';
10252
 
10253
        #
10254
        #   Insert commands to post process the test results according to the specified formatter
10255
        #
10256
        my $me = MakeEntry::New( *MAKEFILE, 'UtfPostProcess', '--Define' );
10257
        $me->AddComment    ('Post Process a UNIT TEST');
10258
        $me->AddComment    ('  arg1 - utffile name');
10259
        $me->AddComment    ('  arg2 - Directory to start scan for Unit Test Results');
10260
        $me->AddComment    ('  arg3 - Additional arguments to the filter');
10261
        $me->SectionIfDef  ('UTF_POSTPROCESS');
10262
        $me->AddOneRecipe  ("\$(GBE_PERL) -Mjats_runutf -e processUtf", @cmdline );
10263
        $me->Print();
10264
    }
10265
 
10266
 
261 dpurdie 10267
#-------------------------------------------------------------------------------
10268
#   Toolset Post Processing
10269
#   Allow the toolset to perform any post processing, before we finally write
10270
#   out any definitions.
10271
#
10272
#   We will not interprete any more user directives, but new stuff may get added
10273
#
10274
#
10275
MakeHeader ("Toolset Post Processing");
10276
$if->Postprocess();
10277
 
10278
################################################################################
10279
#   All interactions with the toolset are now complete
10280
#   All lists are now complete
10281
#
10282
#   Can now create internal definitions
10283
#   
10284
################################################################################
10285
 
10286
    #
10287
    #   Would be nice if this would work
10288
    #   Unfortunatelty we still need $if for the CCDEPENDS and CTAGS work
10289
    #   These must be defined AFTER the definitions
10290
    #
10291
    #   Ideally we should construct our makefile in sections
10292
    #   and then we can order the sections when we write them out
10293
    #
10294
#$if = 0;                            # Ensure the MakeIf class is not called
10295
                                     # If this file is modified
10296
 
10297
#-------------------------------------------------------------------------------
227 dpurdie 10298
#   Sources
10299
#
10300
MakeHeader  ( "Sources");
10301
MakeDefEntry( "CSRCS",      "=",  \@CSRCS );
10302
MakeDefEntry( "CXXSRCS",    "=",  \@CXXSRCS );
10303
MakeDefEntry( "ASSRCS",     "=",  \@ASSRCS );
10304
 
10305
#-------------------------------------------------------------------------------
10306
#   Generated, Installed and Packaged components
10307
#
10308
MakeHeader  ("Generated, Installed and Packaged components");
10309
MakeDefEntry( "INITS",           "=",  \@INITS )   if ( @INITS );
10310
MakeDefEntry( "GENERATED",       "=",  \@GENERATED ) if ( @GENERATED );
10311
MakeDefEntry( "GENERATED_NOTSRC","=",  \@GENERATED_NOTSRC ) if ( @GENERATED_NOTSRC );
10312
MakeDefEntry( "GENERATEDCLEAN",  "=",  CreateNameList( 'clean_generate_', '', ListCleanGenerated() ));
10313
MakeDefEntry( "INSTALL_HDRS",    "=",  \%INSTALL_HDRS ) if ( %INSTALL_HDRS );
10314
MakeDefEntry( "INSTALL_CLSS",    "=",  \%INSTALL_CLSS ) if ( %INSTALL_CLSS );
10315
MakeDefEntry( "OBJS",            "=", CreateNameList( '$(OBJDIR)/', ".$::o", \@OBJS) );
10316
MakeDefEntry( "SHOBJS",          "=", CreateNameList( '$(OBJDIR)/', ".$::o", \%SHOBJ_LIB ));
289 dpurdie 10317
MakeDefEntry( "PROGOBJS",        "=", CreateNameList( '', ".$::o", \@PROGOBJS ));
10318
MakeDefEntry( "TESTPROGOBJS",    "=", CreateNameList( '', ".$::o", \@TESTPROGOBJS ));
10319
MakeDefEntry( "LIBS",            "=", $LIBS->AllTargets() ) if ($::a);
10320
MakeDefEntry( "MLIBS",           "=", $MLIBS->AllTargets() ) if ($::a);
227 dpurdie 10321
MakeDefEntry( "SHNAMES",         "=", \@SHLIBS );
10322
MakeDefEntry( "SHDIRS",          "=", CreateNameList( '$(OBJDIR)/', "", \@SHLIBS ));
10323
MakeDefEntry( "SHLIBS",          "=", \@SHLIB_TARGETS );
10324
MakeDefEntry( "SCRIPTS",         "=", CreateNameList( '$(BINDIR)/', "", \%SCRIPTS ));
10325
MakeDefEntry( "COPYIN",          "=", \@COPYIN );
289 dpurdie 10326
MakeDefEntry( "PROGS",           "=", $PROGS->AllTargets() );
227 dpurdie 10327
MakeDefEntry( "PROGS_EXTRA",     "=", \@PROGS_EXTRA );
289 dpurdie 10328
MakeDefEntry( "TESTPROGS",       "=", $TESTPROGS->AllTargets());
227 dpurdie 10329
MakeDefEntry( "LINTLIBS",        "=", CreateNameList( 'lib_', '_lint', \@LINTLIBS ));
10330
MakeDefEntry( "LINTSHLIBS",      "=", CreateNameList( 'shlib_', '_lint', \@LINTSHLIBS ));
10331
MakeDefEntry( "LINTPROGS",       "=", CreateNameList( 'prog_', '_lint', \@PROGS ));
289 dpurdie 10332
MakeDefEntry( "LINTPROGS",      "+=", CreateNameList( 'prog_', '_lint', \@TESTPROGS ));
227 dpurdie 10333
MakeDefEntry( "PROJECTS",        "=", CreateNameList( 'Project_', '', ListGeneratedProjects(1) ));
10334
MakeDefEntry( "PROJECTSGEN",     "=", CreateNameList( 'Project_', '', ListGeneratedProjects(0) ));
10335
MakeDefEntry( "PROJECTSCLEAN",   "=", CreateNameList( 'ProjectClean_', '', \%PROJECTS ));
10336
 
4501 dpurdie 10337
MakeDefEntry( "UNITTESTS",       "=", \@TESTPROJECT_TO_URUN );
10338
MakeDefEntry( "AUTOUNITTESTS",   "=", \@TESTPROJECT_TO_ARUN );
10339
 
4778 dpurdie 10340
MakeDefEntry( "AUTOUNITTESTS_PRE",    "=", \@TOOLSET_UTF_PRE );
10341
MakeDefEntry( "AUTOUNITTESTS_POST",   "=", \@TOOLSET_UTF_POST );
10342
MakeDefEntry( "AUTOUNITTESTS_COLLATE","=", \@TOOLSET_UTF_COLLATE );
10343
 
10344
 
261 dpurdie 10345
MakeHeader ("Toolset components");
10346
MakeDefEntry( "USERGENERATED",        "=", \@USERGENERATED )    if ( @USERGENERATED );
10347
MakeDefEntry( "TOOLSETGENERATED",     "=", \@TOOLSETGENERATED ) if ( @TOOLSETGENERATED );
10348
MakeDefEntry( "TOOLSETOBJS",          "=", \@TOOLSETOBJS )      if ( @TOOLSETOBJS );
10349
MakeDefEntry( "TOOLSETLIBS",          "=", \@TOOLSETLIBS )      if ( @TOOLSETLIBS );
10350
MakeDefEntry( "TOOLSETPROGS",         "=", \@TOOLSETPROGS )     if ( @TOOLSETPROGS );
10351
MakeDefEntry( "TOOLSETDIRS",          "=", \@TOOLSETDIRS )      if ( @TOOLSETDIRS );
10352
MakeDefEntry( "TOOLSETDIRTREES",      "=", \@TOOLSETDIRTREES )  if ( @TOOLSETDIRTREES );
6898 dpurdie 10353
MakeDefEntry( "TOOLSETCLOBFILES",      "=", \@CLOBBERFILES )    if ( @CLOBBERFILES );
10354
MakeDefEntry( "TOOLSETCLOBDIRS",       "=", \@CLOBBERDIRS )      if ( @CLOBBERDIRS );
227 dpurdie 10355
 
6898 dpurdie 10356
 
227 dpurdie 10357
#--------- Determine compiler flag groups to use ----------------------------
10358
#
10359
#   Allows the compiler options to be controlled for both the debug and
10360
#   the production builds. Allows control over
10361
#       1) Optimisations
10362
#       2) Debug Information
10363
#
10364
MakeHeader ("Determine compiler flag groups to use");
10365
 
10366
print MAKEFILE <<EOF;
10367
 
10368
ifneq "\$(DEBUG)" "1"
10369
USE_OPTIMISE	:= \$(PROD_USE_OPTIMISE)
10370
USE_DEBUGINFO	:= \$(PROD_USE_DEBUGINFO)
10371
else
10372
USE_OPTIMISE	:= \$(DEBUG_USE_OPTIMISE)
10373
USE_DEBUGINFO	:= \$(DEBUG_USE_DEBUGINFO)
10374
endif
10375
 
10376
EOF
10377
 
261 dpurdie 10378
#-------------------------------------------------------------------------------
10379
#   Source browsing tools
10380
#
10381
MakeHeader ("Source browsing tools");
10382
    print MAKEFILE <<EOF;
10383
.PHONY:			ctags
10384
ctags:
10385
EOF
10386
    $if->CTAGS()
10387
        if (@CSRCS || @CXXSRCS);
227 dpurdie 10388
 
261 dpurdie 10389
#-------------------------------------------------------------------------------
10390
#   Depend
10391
#   If we are build C or C++ source files then create rules and recipes
10392
#   to invoke a dependency generator.
227 dpurdie 10393
#
261 dpurdie 10394
#   NODEPEND is used to disable, at make-time, the dependency generation
10395
#   and inclusion process.
10396
#
10397
#
10398
MakeHeader ("Depend");
6133 dpurdie 10399
if ($::o && (@CSRCS || @CXXSRCS) && $ScmNotGeneric)
261 dpurdie 10400
{
10401
    $ScmDependTags = 1;
10402
    print MAKEFILE <<EOF;
10403
depend:			\$(OBJDIR)/depend
10404
 
10405
\$(OBJDIR)/depend:	\$(SCM_MAKEFILE) \$(GBE_OBJDIR)
10406
\$(OBJDIR)/depend:	\$(CSRCS) \$(CXXSRCS)
10407
ifeq (\$(NODEPEND),0)
6177 dpurdie 10408
	\@echo '[\$@] Doing a make depend..'
261 dpurdie 10409
	-\$(XX_PRE)\$(rm) -f \$(OBJDIR)/depend
10410
EOF
10411
    $if->CCDepend( "\$(OBJDIR)/depend", "\$(CSRCS)" )
10412
        if ( @CSRCS );
10413
    $if->CXXDepend( "\$(OBJDIR)/depend", "\$(CXXSRCS)" )
10414
        if ( @CXXSRCS );
10415
    MakePrint
10416
        "\t-\@\$(touch) -f \$(OBJDIR)/depend\n";
10417
    print MAKEFILE <<EOF;
10418
else
6177 dpurdie 10419
	\@echo '[\$@] Skipping make depend..'
261 dpurdie 10420
	-\$(XX_PRE)\$(rm) -f \$(OBJDIR)/depend
10421
endif
10422
EOF
10423
}
10424
else
10425
{
10426
    print MAKEFILE <<EOF;
10427
depend:
10428
EOF
10429
}
10430
 
10431
#
10432
#   Rule to unmake the depend file
2429 dpurdie 10433
#       No longer neeed.
10434
#       The file is deleted as a part of the OBJDIR cleanup
261 dpurdie 10435
#
10436
    print MAKEFILE <<EOF;
10437
 
10438
undepend:
10439
EOF
10440
 
10441
#--------- IFLAG Documentation -------------------------------------------------
10442
#
10443
#   IFLAG - iteration flag. This is setting by the calling process
10444
#                           and is a function of the phase being processed
227 dpurdie 10445
#       0   No external dependencies.
10446
#       1   Source dependency list.
261 dpurdie 10447
#       2   Shared library dependency list
10448
#       3   Application dependency list
227 dpurdie 10449
#
10450
#
261 dpurdie 10451
#--------- Dependencies --------------------------------------------------------
10452
#   Include the 'depend' file if required
10453
#
10454
    MakeHeader ("Dependency Inclusion");
10455
    print MAKEFILE <<EOF;
10456
ifeq (\$(NODEPEND),0)
10457
 ifdef IFLAG
10458
  ifneq "\$(IFLAG)" "0"
10459
-include	\$(OBJDIR)/depend
10460
  endif
227 dpurdie 10461
 endif
10462
endif
10463
 
10464
EOF
10465
 
10466
#-------------------------------------------------------------------------------
10467
#   Standard rules
10468
#
5991 dpurdie 10469
    MakeHeader ("Standard rules");
10470
    print MAKEFILE <<EOF;
373 dpurdie 10471
.PHONY:		make_clean
227 dpurdie 10472
make_clean:
10473
	-\@echo "Removing generated files (objects, libraries, binaries etc)";
10474
 
10475
.PHONY:		rmlitter
10476
rmlitter:
2429 dpurdie 10477
	-\$(AA_PRE)JatsFileUtil 'D0' 'Removing litter' '.' 'core' '*.bak' '*.tmp' '*.err'
227 dpurdie 10478
 
261 dpurdie 10479
.PHONY:		lint_init
10480
lint_init:
10481
 
227 dpurdie 10482
EOF
10483
 
261 dpurdie 10484
#
10485
#   Dependencies for 'make_init'
10486
#
10487
#
10488
my @initdep;
10489
push @initdep, '$(INITS)' if ( @INITS );
227 dpurdie 10490
 
261 dpurdie 10491
#
10492
#   Dependencies for 'make_dir'
10493
#
10494
my @mkdirdep;
289 dpurdie 10495
push @mkdirdep, '$(GBE_OBJDIR)' if ( @CSRCS || @CXXSRCS || @OBJS || @PROGOBJS || @TESTPROGOBJS );
261 dpurdie 10496
push @mkdirdep, '$(SHDIRS)'     if ( %SHOBJ_LIB || @SHLIBS);
10497
push @mkdirdep, '$(GBE_LIBDIR)' if ( @LIBS || @MLIBS || @SHLIBS || %INSTALL_LIBS || %PACKAGE_LIBS );
289 dpurdie 10498
push @mkdirdep, '$(GBE_BINDIR)' if ( @SHLIBS || %SCRIPTS || @PROGS || @TESTPROGS || %INSTALL_PROGS || %PACKAGE_PROGS );
227 dpurdie 10499
 
261 dpurdie 10500
#
10501
#   Actions for for 'unobj'
10502
#
10503
my @unobjact;
10504
push @unobjact, RmFilesCmd( 'OBJS' )            if ( @OBJS );
10505
push @unobjact, RmFilesCmd( 'SHOBJS' )          if ( %SHOBJ_LIB );
10506
push @unobjact, RmFilesCmd( 'PROGOBJS' )        if ( @PROGOBJS );
289 dpurdie 10507
push @unobjact, RmFilesCmd( 'TESTPROGOBJS' )    if ( @TESTPROGOBJS );
261 dpurdie 10508
push @unobjact, RmFilesCmd( 'TOOLSETOBJS' )     if ( @TOOLSETOBJS );
227 dpurdie 10509
 
261 dpurdie 10510
#
10511
#   Dependencies for 'make_lib'
10512
#
10513
my @libdep;
10514
push @libdep, '$(GBE_OBJDIR)', '$(GBE_LIBDIR)', '$(LIBS)' if ( @LIBS );
227 dpurdie 10515
 
261 dpurdie 10516
#
10517
#   Dependencies for 'lint_lib'
10518
#
10519
my @liblintdep;
10520
push @liblintdep, 'lint_init', '$(GBE_OBJDIR)', '$(GBE_LIBDIR)', '$(LINTLIBS)' if ( @LIBS );
227 dpurdie 10521
 
261 dpurdie 10522
#
10523
#   Dependencies for 'make_mlib'
10524
#
10525
my @mlibdep;
10526
push @mlibdep, '$(GBE_OBJDIR)', '$(GBE_LIBDIR)', '$(GBE_MLIBDIR)', '$(MLIBS)' if ( @MLIBS );
227 dpurdie 10527
 
261 dpurdie 10528
#
10529
#   Dependencies for 'make_install_shlib' (tag)
10530
#
10531
my @shlibdep;
10532
push @shlibdep, '$(SHDIRS)', '$(SHLIBS)' if ( @SHLIBS );
227 dpurdie 10533
 
261 dpurdie 10534
#
10535
#   Dependencies for 'lint_shlib'
10536
#
10537
my @shliblintdep;
10538
push @shliblintdep, 'lint_init', '$(GBE_LIBDIR)', '$(LINTSHLIBS)' if ( @SHLIBS );
227 dpurdie 10539
 
261 dpurdie 10540
#
10541
#   Actions for 'unmake_lib'
10542
#
10543
my @unlibact;
10544
push @unlibact, RmFilesCmd( 'SHLIBS' )      if ( @SHLIBS );
10545
push @unlibact, RmFilesCmd( 'MLIBS' )       if ( @MLIBS );
10546
push @unlibact, RmFilesCmd( 'LIBS' )        if ( @LIBS );
10547
push @unlibact, RmFilesCmd( 'TOOLSETLIBS' ) if ( @TOOLSETLIBS );
227 dpurdie 10548
 
261 dpurdie 10549
#
10550
#   Actions for 'unmake_mlib'
10551
#
10552
my @unmlibact;
10553
push @unmlibact, RmFilesCmd( 'MLIBS' ) if ( @MLIBS );
227 dpurdie 10554
 
261 dpurdie 10555
#
10556
#   Dependencies for 'make_script'
10557
#
10558
my @scriptdep;
10559
push @scriptdep, '$(GBE_BINDIR)', '$(SCRIPTS)' if ( %SCRIPTS );
227 dpurdie 10560
 
261 dpurdie 10561
#
10562
#   Actions for 'unmake_script'
10563
#
10564
my @unscriptact;
10565
push @unscriptact , RmFilesCmd( 'SCRIPTS' ) if ( %SCRIPTS );
10566
push @unscriptact , RmFilesCmd( 'COPYIN' )  if ( @COPYIN );
227 dpurdie 10567
 
261 dpurdie 10568
#
10569
#   Dependencies for 'make_prog'
10570
#
10571
my @progdep;
10572
push @progdep, '$(GBE_OBJDIR)', '$(GBE_BINDIR)', '$(PROGS)' if ( @PROGS );
10573
push @progdep, '$(PROGS_EXTRA)' if (@PROGS_EXTRA);
227 dpurdie 10574
 
261 dpurdie 10575
#
10576
#   Dependencies for 'make_prog' created for 'projects'
10577
#
10578
my @projectdep;
10579
push @projectdep, '$(PROJECTS)' if (ListGeneratedProjects(1) );
227 dpurdie 10580
 
261 dpurdie 10581
#
10582
#   Dependencies for 'generate' created for 'projects'
10583
#
10584
my @projectgendep;
10585
push @projectgendep, '$(PROJECTSGEN)' if (ListGeneratedProjects(0) );
227 dpurdie 10586
 
261 dpurdie 10587
#
10588
#   Dependencies for 'unmake_prog' created for 'projects'
10589
#
10590
my @projectcleandep;
10591
push @projectcleandep, '$(PROJECTSCLEAN)' if (%PROJECTS);
227 dpurdie 10592
 
261 dpurdie 10593
#
10594
#   Dependencies for 'lint_prog'
10595
#
10596
my @proglintdep;
289 dpurdie 10597
push @proglintdep, 'lint_init', '$(GBE_OBJDIR)', '$(GBE_BINDIR)', '$(LINTPROGS)' if ( @PROGS || @TESTPROGS );
227 dpurdie 10598
 
261 dpurdie 10599
#
10600
#   Actions for 'unmake_prog'
10601
#
10602
my @unprogact;
10603
push @unprogact, RmFilesCmd( 'PROGS' )        if ( @PROGS );
10604
push @unprogact, RmFilesCmd( 'TOOLSETPROGS' ) if ( @TOOLSETPROGS );
227 dpurdie 10605
 
261 dpurdie 10606
#
4728 dpurdie 10607
#   Dependencies for 'exec_tests'
261 dpurdie 10608
#
10609
my @testprogdep;
289 dpurdie 10610
push @testprogdep, '$(GBE_OBJDIR)', '$(GBE_BINDIR)', '$(TESTPROGS)' if ( @TESTPROGS );
227 dpurdie 10611
 
4501 dpurdie 10612
my @autoruntestdep;
10613
push @autoruntestdep, 'makefile.pl', '$(AUTOUNITTESTS)' if ( @TESTPROJECT_TO_ARUN );
10614
 
10615
my @runtestdep;
4996 dpurdie 10616
push @runtestdep    , 'makefile.pl', '$(UNITTESTS)' if ( @TESTPROJECT_TO_URUN );
4501 dpurdie 10617
 
227 dpurdie 10618
#
4728 dpurdie 10619
#   Dependencies for 'exec_tests' and friends
261 dpurdie 10620
#
10621
my @untestprogact;
289 dpurdie 10622
push @untestprogact ,RmFilesCmd( 'TESTPROGS' ) if ( @TESTPROGS );
227 dpurdie 10623
 
261 dpurdie 10624
#
10625
#   Dependencies for 'generated'
10626
#
10627
my @generatedep;
10628
push @generatedep, '$(GENERATED)' if ( @GENERATED );
10629
 
10630
#
10631
#   Actions for 'ungenerate'
10632
#
10633
my @ungenact;
10634
push @ungenact, RmFilesCmd( 'GENERATED' ) if ( @GENERATED );
10635
push @ungenact, RmFilesCmd( 'GENERATED_NOTSRC' ) if ( @GENERATED_NOTSRC );
10636
push @ungenact, RmFilesCmd( 'TOOLSETGENERATED' ) if ( @TOOLSETGENERATED );
10637
push @ungenact, RmFilesCmd( 'USERGENERATED' ) if ( @USERGENERATED );
10638
 
10639
#
10640
#   Dependencies for 'ungenerate'
10641
#
10642
my @ungeneratedep;
10643
push @ungeneratedep, '$(GENERATEDCLEAN)';
10644
 
6898 dpurdie 10645
#
10646
#   Actions for clobberfiles
10647
#   
10648
my @clobberfiles;
10649
push @clobberfiles, RmFilesCmd('TOOLSETCLOBFILES') if (@CLOBBERFILES); 
10650
 
227 dpurdie 10651
#-------------------------------------------------------------------------------
261 dpurdie 10652
# Function        : PrintPhonyRule
227 dpurdie 10653
#
261 dpurdie 10654
# Description     : Helper function to print some internal phony makefile targets
10655
#                   These are used to hold the basic makefile together
10656
#
10657
# Inputs          : $target         - Name of the phony target
10658
#                   $prereq         - Prerequisites
10659
#                                     Leading spaces removed
10660
#                   $recipe         - Optional Reference to an array of recipes
10661
#                                     Will be printed one per line
10662
#
10663
#
10664
sub PrintPhonyRule
227 dpurdie 10665
{
261 dpurdie 10666
    my ($target, $prereq, $recipe) = @_;
10667
    $prereq =~ s/^\s+//;
227 dpurdie 10668
 
261 dpurdie 10669
    MakePadded( 2, '.PHONY:', $target, "\n");
10670
    MakePadded( 2,"$target:", $prereq, "\n");
10671
    MakePrint ("\t\t" . $_ . "\n") foreach ( @{$recipe} );
10672
    MakePrint ("\n");
227 dpurdie 10673
}
10674
 
261 dpurdie 10675
#   make_init - Test toolset presence and sanity
10676
#   Will only be called ONCE for each platform in a recursive build
10677
#   Should be used to ensure that the required toolset is present
10678
#
4778 dpurdie 10679
PrintPhonyRule ('make_init',            "@initdep" );
227 dpurdie 10680
 
261 dpurdie 10681
#   make_dir    - Create required subdirectories
10682
#   Will be invoked as a part of most targets that create files
10683
#   Will be invoked by the calling wrappers
10684
#   Should not be invoked when cleaning
10685
#
4778 dpurdie 10686
PrintPhonyRule ('make_dir',             "@mkdirdep" );
261 dpurdie 10687
 
4778 dpurdie 10688
PrintPhonyRule ('generate',             "@generatedep @projectgendep" );
10689
PrintPhonyRule ('ungenerate',           "@ungeneratedep",  \@ungenact);
10690
PrintPhonyRule ('unobj',                "",  \@unobjact);
10691
PrintPhonyRule ('make_lib',             "@libdep" );
10692
PrintPhonyRule ('lint_lib',             "@liblintdep" );
10693
PrintPhonyRule ('make_mlib',            "@mlibdep" );
10694
PrintPhonyRule ('lint_shlib',           "@shliblintdep" );
10695
PrintPhonyRule ('unmake_lib',           "", \@unlibact );
10696
PrintPhonyRule ('unmake_mlib',          "", \@unmlibact );
10697
PrintPhonyRule ('make_script',          "@scriptdep" );
10698
PrintPhonyRule ('unmake_script',        "", \@unscriptact );
10699
PrintPhonyRule ('make_prog',            "make_script @progdep @projectdep" );
10700
PrintPhonyRule ('unmake_prog',          "unmake_script @projectcleandep", \@unprogact );
10701
PrintPhonyRule ('lint_prog',            "@proglintdep" );
10702
PrintPhonyRule ('exec_tests',           "make_script @testprogdep @runtestdep" );
10703
PrintPhonyRule ('exec_unit_tests',      "make_script @testprogdep @autoruntestdep" );
10704
PrintPhonyRule ('make_test',            "make_script @testprogdep" );
10705
PrintPhonyRule ('unmake_test',          "unmake_script", \@untestprogact );
10706
PrintPhonyRule ('preprocess_tests',     '$(AUTOUNITTESTS_PRE)' );
10707
PrintPhonyRule ('postprocess_tests',    '$(AUTOUNITTESTS_POST)' );
10708
PrintPhonyRule ('collate_test_results', '$(AUTOUNITTESTS_COLLATE)' );
6898 dpurdie 10709
PrintPhonyRule ('clobberfiles',         "",\@clobberfiles );
261 dpurdie 10710
 
227 dpurdie 10711
#-------------------------------------------------------------------------------
10712
#   Package and Installation Summary
10713
#
10714
    MakeHeader ("Package and Installation Summary");
10715
    sub InstallTarget
10716
    {
10717
        my( $target, $hashp, $prereq, $fprereq ) = @_;
10718
        my( $element );
10719
 
5991 dpurdie 10720
        my $me = MakeEntry::New( *MAKEFILE, $target, '--Phony' );
10721
        $me->AddDependancy( $fprereq ) if ($fprereq);
227 dpurdie 10722
        foreach my $element ( sort keys %{$hashp} )
10723
        {
10724
            #
10725
            #   Skip placekeepers
10726
            #
10727
            next if ( $hashp->{$element}{'placekeeper'} );
10728
 
10729
            #
10730
            #   Prepend any prerequisites (once)
10731
            #
5991 dpurdie 10732
            $me->AddDependancy( $prereq ) if ( $prereq );
10733
            $prereq = 0;
227 dpurdie 10734
 
5991 dpurdie 10735
            $me->AddDependancyEscaped( $element );
227 dpurdie 10736
        }
5991 dpurdie 10737
        $me->Print();
10738
 
227 dpurdie 10739
    }
10740
 
10741
InstallTarget( "install_hdr",       \%INSTALL_HDRS );
10742
InstallTarget( "install_lib",       \%INSTALL_LIBS,  'make_mlib' );
261 dpurdie 10743
InstallTarget( "make_install_shlib",\%INSTALL_SHLIBS, '', "@shlibdep" );
227 dpurdie 10744
InstallTarget( "install_prog",      \%INSTALL_PROGS, 'make_script' );
10745
InstallTarget( "install_class",     \%INSTALL_CLSS );
10746
 
10747
InstallTarget( "package_files",     \%PACKAGE_FILES );
10748
InstallTarget( "package_hdr",       \%PACKAGE_HDRS );
10749
InstallTarget( "package_lib",       \%PACKAGE_LIBS );
10750
InstallTarget( "package_shlib",     \%PACKAGE_SHLIBS );
10751
InstallTarget( "package_prog",      \%PACKAGE_PROGS, 'make_script' );
10752
InstallTarget( "package_class",     \%PACKAGE_CLSS );
10753
 
10754
#-------------------------------------------------------------------------------
10755
#   Installations
10756
 
10757
MakeHeader ("Installations");
6387 dpurdie 10758
PackageRule    ( \&InstallCmd, \%INSTALL_HDRS  );
10759
PackageRule    ( \&InstallCmd, \%INSTALL_CLSS  );
10760
PackageRule    ( \&InstallCmd, \%INSTALL_LIBS  );
10761
PackageRule    ( \&InstallCmd, \%INSTALL_SHLIBS  );
10762
PackageRule    ( \&InstallCmd, \%INSTALL_PROGS  );
10763
PackageDirRule ('install_dirs',    \@INSTALL_DIRS);
227 dpurdie 10764
 
10765
#-------------------------------------------------------------------------------
10766
#   Packaging
10767
#
10768
MakeHeader ("Packaging");
6387 dpurdie 10769
PackageRule    ( \&PackageCmd, \%PACKAGE_FILES );
10770
PackageRule    ( \&PackageCmd, \%PACKAGE_HDRS );
10771
PackageRule    ( \&PackageCmd, \%PACKAGE_CLSS );
10772
PackageRule    ( \&PackageCmd, \%PACKAGE_LIBS );
10773
PackageRule    ( \&PackageCmd, \%PACKAGE_SHLIBS );
10774
PackageRule    ( \&PackageCmd, \%PACKAGE_PROGS );
10775
PackageDirRule ('package_dirs', \@PACKAGE_DIRS);
227 dpurdie 10776
 
10777
#-------------------------------------------------------------------------------
10778
#   Uninstall/unpackaging
10779
#
10780
MakeHeader ("Uninstall/unpackaging");
10781
 
6387 dpurdie 10782
UnpackageRule  ( 'uninstall_hdr',         \&UninstallCmd, \%INSTALL_HDRS );
10783
UnpackageRule  ( 'uninstall_lib',         \&UninstallCmd, \%INSTALL_LIBS );
10784
UnpackageRule  ( 'uninstall_shlib',       \&UninstallCmd, \%INSTALL_SHLIBS );
10785
UnpackageRule  ( 'uninstall_prog',        \&UninstallCmd, \%INSTALL_PROGS );
10786
UnpackageRule  ( 'uninstall_class',       \&UninstallCmd, \%INSTALL_CLSS );
10787
PackageDirRule ( 'uninstall_dirs',        \@INSTALL_DIRS);
227 dpurdie 10788
 
6387 dpurdie 10789
UnpackageRule  ( 'unpackage_files',       \&UnpackageCmd, \%PACKAGE_FILES );
10790
UnpackageRule  ( 'unpackage_hdr',         \&UnpackageCmd, \%PACKAGE_HDRS );
10791
UnpackageRule  ( 'unpackage_lib',         \&UnpackageCmd, \%PACKAGE_LIBS );
10792
UnpackageRule  ( 'unpackage_shlib',       \&UnpackageCmd, \%PACKAGE_SHLIBS );
10793
UnpackageRule  ( 'unpackage_prog',        \&UnpackageCmd, \%PACKAGE_PROGS );
10794
UnpackageRule  ( 'unpackage_class',       \&UnpackageCmd, \%PACKAGE_CLSS );
10795
PackageDirRule ( 'unpackage_dirs',        \@PACKAGE_DIRS);
227 dpurdie 10796
 
261 dpurdie 10797
#-------------------------------------------------------------------------------
267 dpurdie 10798
#   Distribution Sets
261 dpurdie 10799
#
267 dpurdie 10800
MakeHeader ("Distribution Sets");
10801
PackageSetRules();
10802
 
10803
#-------------------------------------------------------------------------------
10804
#
261 dpurdie 10805
#   Subdir deletion
10806
#   This is done AFTER the toolset functions have been invoked to create the
10807
#   build artifacts so that the toolsets can create directories too
10808
#
10809
#   Note: Toolset directories are deleted first
10810
#   Note: User Directories are deleted in the reverse order of creation
10811
#
2429 dpurdie 10812
#   Add them into the directory data structure
10813
#
10814
    foreach my $path ( @TOOLSETDIRS )
10815
    {
10816
        MkdirRule( $path, '', '--NoCreate' );
10817
    }
10818
 
10819
    foreach my $path ( @TOOLSETDIRTREES )
10820
    {
10821
        MkdirRule( $path, '', '--NoCreate' , '--RemoveAll');
10822
    }
10823
 
261 dpurdie 10824
    MakeHeader ("Subdir deletion");
10825
    RmdirRules();
6898 dpurdie 10826
    ClobberDirsRule();
261 dpurdie 10827
    MakeNewLine();
227 dpurdie 10828
 
261 dpurdie 10829
#--------- Toolset Rules -------------------------------------------------------
10830
    MakeHeader ("Toolset Rules");
10831
    MakePrintList ( \@TOOLSETRULES );
10832
 
10833
#--------- Maketags ------------------------------------------------------------
227 dpurdie 10834
 
10835
    Maketag( "make_init",           @INITS );
261 dpurdie 10836
    Maketag( "make_dir",            @mkdirdep );
10837
    Maketag( "generate",            @generatedep || @projectgendep || @USERGENERATED || ($ScmToolsetGenerate != 0) );
227 dpurdie 10838
    Maketag( "depend",              $ScmDependTags != 0 );
261 dpurdie 10839
    Maketag( "make_lib",            @libdep );
10840
    Maketag( "make_mlib",           @mlibdep );
10841
    Maketag( "make_install_shlib",  %INSTALL_SHLIBS || @shlibdep);
10842
    Maketag( "make_script",         @scriptdep );
10843
    Maketag( "make_prog",           @progdep || @projectdep );
10844
    Maketag( "make_test",           @testprogdep );
4996 dpurdie 10845
    Maketag( "exec_tests",          $TESTS_TO_RUN     || @TESTPROJECT_TO_URUN );
4728 dpurdie 10846
    Maketag( "exec_unit_tests",     $TESTS_TO_AUTORUN || @TESTPROJECT_TO_ARUN );
4778 dpurdie 10847
    Maketag( "process_tests",       @TOOLSET_UTF_PRE || @TOOLSET_UTF_POST || @TOOLSET_UTF_COLLATE);
227 dpurdie 10848
    Maketag( "install_hdr",         %INSTALL_HDRS );
10849
    Maketag( "install_class",       %INSTALL_CLSS );
10850
    Maketag( "install_lib",         %INSTALL_LIBS );
10851
    Maketag( "install_prog",        %INSTALL_PROGS );
6387 dpurdie 10852
    Maketag( "install_dirs",        @INSTALL_DIRS );
227 dpurdie 10853
    Maketag( "deploy",              %DEPLOYPACKAGE );
10854
    Maketag( "package",             %PACKAGE_FILES || %PACKAGE_HDRS || %PACKAGE_CLSS ||
10855
                                    %PACKAGE_LIBS || %PACKAGE_SHLIBS || %PACKAGE_PROGS );
10856
 
261 dpurdie 10857
    #
10858
    #   Display tags in the MAKEFILE
4778 dpurdie 10859
    #       Not used here - just for show
261 dpurdie 10860
    #
10861
    MakeHeader ("Maketags");
10862
    foreach my $tag ( sort keys %MakeTags )
10863
    {
4778 dpurdie 10864
        MakePadded( 3, "#   $tag:", '1', "\n");
261 dpurdie 10865
    }
10866
 
227 dpurdie 10867
#-------------------------------------------------------------------------------
10868
#   End of Makefile
10869
#
10870
    MakeHeader ("End of Makefile");
10871
    close( MAKEFILE );
10872
 
10873
#
10874
#   Save all platform information
10875
#   Done after the makefile is written as toolsets can extend the data
10876
#
10877
    WriteParsedConfig();
10878
 
10879
#
10880
#   Write out any accumulated DPACKAGE data
10881
#
10882
    JatsDPackage::DPackageSave();
10883
 
10884
    return 0;
10885
}
10886
 
10887
#-------------------------------------------------------------------------------
387 dpurdie 10888
# Function        : QuoteForMake
10889
#
10890
# Description     : Escape/Quote a pathname for make
10891
#                       Allow files with a $ in the name
10892
#                       Allow files with a space in the name
10893
#                       Allow files with a comma in the name
10894
#                       Allow for paths that have make-varible prefixes
6423 dpurdie 10895
#                           $(GBE_...) or ${GBE_...} or $(OBJDIR) or $(BUILDVERNUM)
387 dpurdie 10896
#                           as these may be generated internally
5991 dpurdie 10897
#                       Allow for files with a colon in the name
10898
#                           Mode dependent
10899
#                               0 - No effect
10900
#                               T - \\\:
10901
#                               S = \:    
387 dpurdie 10902
#
399 dpurdie 10903
#                       Must also allow $(GBE_TYPE) in the remainder
10904
#
5991 dpurdie 10905
# Inputs          : uarg            - Arg to quote
10906
#                   mode            - Mode of operation
10907
#                                     T - Makefile target
10908
#                                     S - Makefile source
10909
#                                     0 - Neither
387 dpurdie 10910
#
10911
# Returns         : Quoted arg
10912
#
10913
 
5991 dpurdie 10914
sub QuoteForMake($;$)
387 dpurdie 10915
{
5991 dpurdie 10916
    my ($uarg, $mode) = @_;
10917
    $mode = '0' unless defined $mode;
387 dpurdie 10918
 
10919
    #
10920
    #   Split into two
10921
    #       $(xxx)/             - Makefile variables
10922
    #       Remainder           - Stuff to quote
10923
    #
10924
    $uarg =~ m~^((\$\(.*?\)/)*)(.*)~;
10925
    my $prefix = defined $1 ? $1 : '';
10926
    my $arg    = defined $3 ? $3 : '';
10927
 
6423 dpurdie 10928
    $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 10929
    $arg =~ s~ ~\\ ~g;
10930
    $arg =~ s~,~\$(comma)~g;
2764 dpurdie 10931
    $arg =~ s~%~\\%~g;
5999 dpurdie 10932
    $arg =~ s~:~\\\\\\:~g if ($mode eq 'T' &&  $::ScmHost eq "Unix");
10933
    $arg =~ s~:~\\:~g     if ($mode eq 'S' &&  $::ScmHost eq "Unix");
387 dpurdie 10934
    return $prefix . $arg;
10935
}
10936
 
10937
#-------------------------------------------------------------------------------
227 dpurdie 10938
# Function        : Maketag
10939
#
10940
# Description     : Create Makefile tags to speed up recursive makes
10941
#
10942
# Inputs          : tag_name
10943
#                   dep
10944
#
10945
# Returns         : 
10946
#
10947
sub Maketag
10948
{
10949
    my( $tag, $dep ) = @_;
10950
    $MakeTags{$tag} = 1 if ( defined($dep) && $dep );
10951
}
10952
 
10953
#-------------------------------------------------------------------------------
10954
#   Function to create and delete directories within the build system
10955
#
10956
#    To stop make regenerating directory dependent targets each time the
10957
#    directory content is modified, rule should only be dependent on a internally
10958
#    created alias file 'gbedir', which represents the time a dir was created not
10959
#    last modified.
10960
#
10961
#    Must use tags like GBE_BINDIR, GBE_LIBDIR and GBE_OBJDIR to ensure that the
10962
#    directories are created correctly.
10963
#
10964
my %MkdirRuleData;
10965
my @MkdirRuleOrder;
10966
my $MkdirRulePrinting = 0;
10967
my $MkdirRuleGbeFile = ( $::ScmHost eq "Unix" ) ? ".gbedir" : "_gbedir";
10968
 
10969
#-------------------------------------------------------------------------------
10970
# Function        : MkdirRule
10971
#
10972
# Description     : Create Rules and Recipes to create a directory at make-time
10973
#                   Mark the information for such that the directories will
10974
#                   be deleted in a 'clean'
10975
#
10976
#                   Can be called before we start writing the makefile
10977
#                   Such entries will be retained and dumped at a known time
10978
#
10979
# Inputs          : $subdir     - Symbolic name of the subdir $(OBJDIR)
10980
#                   $alias      - Optional script alias for the dir 'OBJDIR' --> GBE_OBJDIR
10981
#                   Options:
2429 dpurdie 10982
#                       --Path=path             Optional value of $subdir '$(GBE_PLATFORM)$(GBE_TYPE).OBJ'
10983
#                       --RemoveAll             Remove all files on clean
6177 dpurdie 10984
#                       --Extra=file[,file]     Additional files to remove
2429 dpurdie 10985
#                       --NoCreate              Do not Create the Directory, just delete it
227 dpurdie 10986
#
10987
# Returns         : Nothing
10988
#
10989
 
10990
sub MkdirRule
10991
{
10992
    my( $subdir, $alias, @opts ) = @_;
10993
 
10994
    #
10995
    #   Create data entry once
10996
    #
10997
    $alias =~ s~^GBE_~~ if $alias;
10998
    unless ( $MkdirRuleData{$subdir}  )
10999
    {
11000
        my %data;
11001
 
11002
        #
11003
        #   Parse options
11004
        #
11005
        foreach ( @opts )
11006
        {
11007
            if ( /^--Path=(.+)/ ) {
11008
                $data{path} = $1;
11009
            } elsif ( /^--RemoveAll/ ) {
11010
                $data{remove_all} = 1;
2429 dpurdie 11011
            } elsif ( /^--NoCreate/ ) {
11012
                $data{noCreate} = 1;
11013
            } elsif ( /^--Extra=(.+)/ ) {
11014
                @{$data{extraFiles}} = split(/,/, $1);
227 dpurdie 11015
            } else {
11016
                Error ("MkdirRule: Unknown option: $_");
11017
            }
11018
        }
11019
        $data{alias} = $alias if ( $alias );
11020
 
11021
        $MkdirRuleData{$subdir} = \%data;
11022
        push @MkdirRuleOrder, $subdir;
11023
    }
11024
 
11025
    #
11026
    #   Save or print
11027
    #
11028
    return unless ( $MkdirRulePrinting );
2429 dpurdie 11029
    return if ( $MkdirRuleData{$subdir}{noCreate} );
227 dpurdie 11030
 
11031
    #
11032
    #   Create a definition of the physical directory
11033
    #
11034
    my $path = $MkdirRuleData{$subdir}{path};
261 dpurdie 11035
    MakePadded (2, $alias, ":= $path\n") if ( $path && $alias );
227 dpurdie 11036
 
11037
    #   Create an alias to be used within rules
11038
    #   The defined aliase will be prefixed with 'GBE_'
11039
    #
261 dpurdie 11040
    MakePadded (2, "GBE_$alias", ":= $subdir/$MkdirRuleGbeFile\n") if ( $alias );
227 dpurdie 11041
 
11042
    #
11043
    #   Create a recipe to create the directory
11044
    #   This is not as simple as it sounds
11045
    #   The touch is required.
11046
    #       Had 'timestamp' issues on solaris'. The 'echo' did not appear
11047
    #       to be enough. Perhaps the output was not flushed
11048
    #
261 dpurdie 11049
    MakePadded (2, "$subdir", ": $subdir/$MkdirRuleGbeFile\n");
227 dpurdie 11050
    MakePrint
11051
        "$subdir/$MkdirRuleGbeFile:\n".
11052
        "\t\$(XX_PRE)if [ ! -d $subdir ]; then \$(mkdir) -p $subdir; fi; \\\n".
11053
        "\t\$(echo) '# DO NOT REMOVE.' > \$@; \\\n".
11054
        "\t\$(touch) \$@\n\n";
11055
}
11056
 
11057
#-------------------------------------------------------------------------------
11058
# Function        : RmdirRules
11059
#
2429 dpurdie 11060
# Description     : Create the body of a recipe to delete the directories that
227 dpurdie 11061
#                   have been created.
11062
#
2429 dpurdie 11063
#                   Use JatsFileUtil rather than shell script
11064
#                       Faster under windows (and others)
11065
#                       Solved long pathname issues
11066
#                       Simpler to use and control
227 dpurdie 11067
#
11068
# Inputs          : Uses $MkdirRuleData
11069
#
11070
# Returns         : Nothing.
11071
#                   Prints to the makefile
11072
#
11073
sub RmdirRules
11074
{
2429 dpurdie 11075
    MakePrint( ".PHONY:\tunmake_dir\n" );
11076
    MakePrint( "unmake_dir:\n" );
11077
 
227 dpurdie 11078
    #
11079
    #   Determine the list of directories to delete
2429 dpurdie 11080
    #   Sort such that subdirs are deleted first
227 dpurdie 11081
    #
2429 dpurdie 11082
    my $txt = 'Removing directories';
227 dpurdie 11083
    foreach my $subdir ( reverse sort keys %MkdirRuleData )
11084
    {
2429 dpurdie 11085
        my @args = $subdir;
11086
 
5816 dpurdie 11087
        push (@args, $MkdirRuleGbeFile, 'core', '*.bak', '*.tmp', '*.err', 'utf.*.rc')
2429 dpurdie 11088
            unless $MkdirRuleData{$subdir}{remove_all};
11089
 
11090
        push (@args, @{$MkdirRuleData{$subdir}{extraFiles}})
11091
            if ( $MkdirRuleData{$subdir}{extraFiles} );
11092
 
11093
        my $mode = $MkdirRuleData{$subdir}{remove_all} ? 'T0' : 'D0';
11094
 
11095
        MakePrint ("\t-\$(AA_PRE)JatsFileUtil ", QuoteArray( $mode, $txt, @args ), "\n");
11096
        $txt = '';
227 dpurdie 11097
    }
11098
}
11099
 
11100
#-------------------------------------------------------------------------------
6898 dpurdie 11101
# Function        : ClobberDirsRule 
11102
#
11103
# Description     : Create the body of a recipe to delete the directories that
11104
#                   will be removed in a clobber
11105
#
11106
#                   Use JatsFileUtil rather than shell script
11107
#                       Faster under windows (and others)
11108
#                       Solved long pathname issues
11109
#                       Simpler to use and control
11110
#
11111
# Inputs          : @CLOBBERDIRS
11112
#
11113
# Returns         : Nothing.
11114
#                   Prints to the makefile
11115
#
11116
sub ClobberDirsRule
11117
{
11118
    MakeNewLine();
11119
    MakePrint( ".PHONY:\tclobberdirs\n" );
11120
    MakePrint( "clobberdirs:\n" );
11121
 
11122
    #
11123
    #   Determine the list of directories to delete
11124
    #   Sort such that subdirs are deleted first
11125
    #
11126
    my $txt = 'Removing toolset directories';
11127
    foreach my $subdir ( reverse sort @CLOBBERDIRS )
11128
    {
11129
        my @args = $subdir;
11130
        MakePrint ("\t-\$(AA_PRE)JatsFileUtil ", QuoteArray( 'T0', $txt, @args ), "\n");
11131
        $txt = '';
11132
    }
11133
}
11134
 
11135
#-------------------------------------------------------------------------------
227 dpurdie 11136
# Function        : CreateMkdirRules
11137
#
11138
# Description     : Create Rules to make dirs at runtime
11139
#                   This function is called to instantiate those entries
11140
#                   That have been requested before the makefile has has
11141
#                   started to be created.
11142
#
11143
#                   Once this function has been called all new MkdirRule calls
11144
#                   will result in the recipes being created in-line.
11145
#
11146
# Inputs          : Nothing
11147
#
11148
# Returns         : Even Less
11149
#
11150
#
11151
sub CreateMkdirRules
11152
{
11153
    $MkdirRulePrinting = 1;
11154
    foreach my $subdir ( @MkdirRuleOrder )
11155
    {
11156
        my $data = $MkdirRuleData{$subdir};
11157
        MkdirRule($subdir, $data->{alias}, $data->{path} );
11158
    }
11159
}
11160
 
11161
#-------------------------------------------------------------------------------
11162
# Function        : PackageRule
11163
#
11164
# Description     : Generate rules and recipes to "install" and "package" files
11165
#
11166
# Inputs          : codecmd     - A code reference to the actual installer routine
11167
#                   hashp       - A reference to a INSTALL or PACKAGE hash
11168
#
299 dpurdie 11169
#                   hashp is a reference to a hash
227 dpurdie 11170
#                       The key is the full path of the install target
11171
#                       The value is (another) hash that describes the install options
11172
#
11173
#                   Valid keys are:
11174
#                       src                 - Path of the source file [Mandatory]
11175
#                       dir                 - Target directory [Mandatory]
11176
#
11177
#                       defined             - Copy the file only if value is defined
4382 dpurdie 11178
#                       Exists              - Copy the file only if it exists
227 dpurdie 11179
#                       exe                 - Mark the file as executable
11180
#                       Mode                - File modes. Default is -w
11181
#                       placekeeper         - Marks SHARED library placekeepers
11182
#                       set                 - Distribution sets
11183
#                       type                - Copy the file in DEBUG or PROD mode
11184
#                                             Valid values are "D" or "P"         
11185
#                       version             - Shared library version information
5882 dpurdie 11186
#                       symlink             - File is a symlink
227 dpurdie 11187
#                       RemoveOnly          - Do not install the file. Entries are
11188
#                                             created to allow the removal of the file
4382 dpurdie 11189
#                       NoTarget            - Reserved - Implemented elsewhere
227 dpurdie 11190
#
11191
# Returns         :
11192
#
11193
sub PackageRule
11194
{
11195
    my ($codecmd, $hashp) = @_;
11196
 
11197
    foreach my $dest ( keys %{$hashp} )
11198
    {
11199
 
11200
        my $entry = $hashp->{$dest};
5991 dpurdie 11201
        my $destText = QuoteForMake($dest,'T');
227 dpurdie 11202
        #
11203
        #   Skip placekeepers
11204
        #
11205
        next if ( $entry->{'placekeeper'} );
11206
 
11207
        #
11208
        #   Some entries are not installed via this mechanism, but can be removed
11209
        #   if they exist. Mark these as PHONY to keep targets happy
11210
        #
11211
        if ( $entry->{'RemoveOnly'} )
11212
        {
5991 dpurdie 11213
            MakePrint ".PHONY:\t$destText\n";
11214
            MakePrint "$destText:\n\n";
227 dpurdie 11215
            next;
11216
        }
11217
 
11218
        my $fname = $entry->{'src'};
5991 dpurdie 11219
        my $fnameText = QuoteForMake($fname,'S');
227 dpurdie 11220
        my $fmode = $entry->{'Mode'};
11221
        $fmode .= "+x" if ( $entry->{'exe'}  );
5882 dpurdie 11222
        $fmode .= "+l" if ( $entry->{'symlink'}  );
227 dpurdie 11223
 
11224
        #
11225
        #   User conditionional
11226
        #   Mark both the source and the target as PHONY if the condition is not met
11227
        #   This will ensure that the target need not be built.
11228
        #
11229
        my $udef = $entry->{'defined'};
11230
        if ( $udef )
11231
        {
11232
            MakePrint "ifndef $udef \n";
5991 dpurdie 11233
            MakePrint ".PHONY:\t\t$destText\n";
11234
            MakePrint ".PHONY:\t\t$fnameText\n";
11235
            MakePrint "$destText:\n";
227 dpurdie 11236
            MakePrint "else\n"
11237
        }
11238
 
11239
        #
4382 dpurdie 11240
        #   File exists
11241
        #   Only package the file if it has been generated. ie: .exe.manifest
11242
        #
11243
        my $fexist = $entry->{'Exists'};
11244
        if ($fexist)
11245
        {
5991 dpurdie 11246
            MakePrint "ifeq (\"\$(wildcard $fnameText)\",\"\")\n";
11247
            MakePrint ".PHONY:\t\t$destText\n";
11248
            MakePrint "$destText:\n";
4382 dpurdie 11249
            MakePrint "else\n"
11250
        }
11251
 
11252
        #
227 dpurdie 11253
        #   Conditional installation for DEBUG/PRODUCTION
11254
        #
11255
        my $type = $entry->{'type'};
11256
        if ( $type )
11257
        {
11258
            if ( $type eq "D" ) {
11259
                MakePrint 'ifeq "$(DEBUG)" "0"'."\n";
11260
            } elsif ( $type eq "P" ) {
11261
                MakePrint 'ifneq "$(DEBUG)" "0"'."\n";
11262
            } else {
11263
                Error("INTERNAL: Unexpected packaging type: $type");
11264
            }
5991 dpurdie 11265
            MakePrint ".PHONY:\t\t$destText\n";
11266
            MakePrint "$destText:\n";
227 dpurdie 11267
            MakePrint "else\n"
11268
        }
11269
 
11270
        #
11271
        #   The body of the copy
11272
        #
5991 dpurdie 11273
        MakePadded( 4, $destText . ':' );
11274
        MakePrint "\t" . $fnameText . "\n";
2429 dpurdie 11275
        MakePrint $codecmd->( $dest, $fname, $fmode );
227 dpurdie 11276
        MakeNewLine();
11277
 
11278
        #
11279
        #   Unwind conditionals
11280
        #
11281
        MakePrint "endif\n" if ( $type );
4382 dpurdie 11282
        MakePrint "endif\n" if ( $fexist );
227 dpurdie 11283
        MakePrint "endif\n" if ( $udef );
11284
 
11285
        #
11286
        #   Distribution sets
11287
        #
11288
        my $dist = $entry->{'set'};
11289
        if ( $dist )
11290
        {
267 dpurdie 11291
            foreach my $set ( split( ',', $dist ) )
11292
            {
11293
                push @{$PACKAGE_SETS{$set}{LIST}}, $dest;
227 dpurdie 11294
            }
11295
            MakeNewLine();
11296
        }
11297
    }
11298
}
11299
 
11300
#-------------------------------------------------------------------------------
6387 dpurdie 11301
# Function        : PackageDirRule 
11302
#
11303
# Description     : Generate special rules for dynamic packaging/installation of directories 
11304
#
11305
# Inputs          : $mode        - package_dirs/unpackage_dirs/install_dirs/uninstall_dirs
11306
#                   $dataRef     - Ref to package/install list
11307
#                       
11308
#
11309
# Returns         : 
11310
#
11311
sub PackageDirRule
11312
{
11313
    my ($mode, $dataRef) = @_;
11314
    my $me = MakeEntry::New( *MAKEFILE, $mode , '--Phony' );
11315
 
11316
    my $modeText = 'packaging';
11317
    my $cmdText = 'PackageDir';
11318
    if ($mode =~ m~install~) {
11319
        $modeText = 'installing';
11320
        $cmdText = 'InstallDir';
11321
    }
11322
    my $cmd = 'copyDir'; 
11323
    if ($mode =~ m~^un~) {
11324
        $cmd = 'unCopyDir';
11325
        $modeText = 'un' . $modeText;
11326
        $cmdText = 'Un' . $cmdText;
11327
    }
11328
 
11329
 
11330
    foreach my $entry ( @{$dataRef}) {
11331
        $me->NewSection();
11332
 
11333
        #
11334
        #   Conditional installation for DEBUG/PRODUCTION
11335
        #
11336
        my $type = $entry->{'type'};
11337
        if ( $type )
11338
        {
11339
           if ( $type eq "D" ) {
11340
               $me->SectionIfNeq('$(DEBUG)','0');
11341
           } elsif ( $type eq "P" ) {
11342
               $me->SectionIfEq('$(DEBUG)','0');
11343
           } else {
11344
               Error("INTERNAL: Unexpected packaging type: $type");
11345
           }
11346
        }
11347
 
11348
        #
11349
        #   Quote the REs so that they can be passed to a command line
11350
        #       Replace $ with $$
11351
        #
11352
        my $QuoteRe = sub {
11353
            my ($arg) = @_;
11354
            $arg=~ s~\$~\$\$~g;
11355
            return $arg;
11356
            };
11357
 
11358
        #
11359
        #   The body of the copy
11360
        #   Create a command line for run-time command
11361
        #   
11362
        my @cmd;
11363
        push @cmd, '$(JatsRunTime)', $cmd, '--', '-$(VERBOSE_OPT)', '--Name='. $cmdText, '--';
11364
        push @cmd, '-mode=' . $modeText;
11365
        push @cmd, "'" . '-src=' . $entry->{dirTree} . "'";
11366
        push @cmd, "'" . '-dst=' . $entry->{dir} . "'";
11367
        push (@cmd, '-execute' ) if $entry->{exefile};
11368
        push (@cmd, '-noSymlink' ) if $entry->{noPreserveSymlink};
11369
        push (@cmd, '-noRecurse' ) if $entry->{noRecurse};
11370
        push (@cmd, '-stripBase' ) if $entry->{strip_base};
11371
        push (@cmd, "'" . '-exclude+=' . $QuoteRe->($_) . "'" ) foreach @{$entry->{exclude}};
11372
        push (@cmd, "'" . '-include+=' . $QuoteRe->($_) . "'" ) foreach @{$entry->{include}};
11373
        push (@cmd, "'" . '-excludeRe+=' . $QuoteRe->($_) . "'" ) foreach @{$entry->{excludeRe}};
11374
        push (@cmd, "'" . '-includeRe+=' . $QuoteRe->($_) . "'" ) foreach @{$entry->{includeRe}};
11375
 
11376
        $me->AddRecipe(join(' ', @cmd ) );
11377
    }
11378
    $me->Print();
11379
}
11380
 
11381
#-------------------------------------------------------------------------------
267 dpurdie 11382
# Function        : PackageSetRules
11383
#
11384
# Description     : Generate the packageset rules
11385
#                   These appear to be a now-defuct feature
11386
#
11387
#                   By default all packaged files are a part of package_setALL
11388
#
11389
# Inputs          : None
11390
#                   Takes data from %PACKAGE_SET
11391
#
11392
# Returns         : Nothing
11393
#
11394
sub PackageSetRules
11395
{
11396
    foreach my $set ( sort keys %PACKAGE_SETS )
11397
    {
11398
        my $me = MakeEntry::New( *MAKEFILE, "package_set$set", '--Phony' );
5991 dpurdie 11399
        $me->AddDependancyEscaped( @{$PACKAGE_SETS{$set}{LIST}} );
267 dpurdie 11400
        $me->Print();
11401
    }
11402
}
11403
 
11404
#-------------------------------------------------------------------------------
227 dpurdie 11405
# Function        : UnPackageRule
11406
#
11407
# Description     : Generate rules and recipes to "uninstall" and "unpackage" files
11408
#
11409
# Inputs          : target      - Name of the target
11410
#                   codecmd     - A code reference to the actual installer routine
11411
#                   hashp       - A reference to a INSTALL or PACKAGE hash
11412
#
11413
# Returns         :
11414
#
11415
sub UnpackageRule
11416
{
11417
    my ($target, $codecmd, $hashp) = @_;
11418
 
11419
    MakePrint ".PHONY:\t\t"."$target\n";
11420
    MakePrint "$target:\t";
11421
 
11422
    foreach my $dest ( sort keys %{$hashp} )
11423
    {
11424
 
11425
        my $entry = $hashp->{$dest};
11426
 
11427
        #
11428
        #   Skip placekeepers
11429
        #
11430
        next if ( $entry->{'placekeeper'} );
11431
 
11432
        MakePrint "\n" . $codecmd->($dest);
11433
    }
11434
    MakePrint "\n\n";
11435
}
11436
 
11437
 
11438
#
11439
#   Internal macro interface, see RULE.STD for definitions:
11440
#
11441
sub RmFilesCmd
11442
{
11443
    my ( $list ) = @_;
261 dpurdie 11444
    return "\$(call RmFiles,$list)";
227 dpurdie 11445
}
11446
 
11447
sub InstallCmd
11448
{
2429 dpurdie 11449
    my( $dest, $file, $fmode ) = @_;
227 dpurdie 11450
 
11451
    $fmode = "-w"                           # default, read-only
11452
        if ( !defined( $fmode ) || $fmode eq "" );
11453
 
5991 dpurdie 11454
    $dest = QuoteForMake($dest);
11455
    $file = QuoteForMake($file);
2429 dpurdie 11456
    return "\t\$(call InstallFile,$dest,$file,$fmode)";
227 dpurdie 11457
}
11458
 
11459
sub UninstallCmd
11460
{
11461
    my( $file ) = @_;
5991 dpurdie 11462
    $file = QuoteForMake($file);
227 dpurdie 11463
    return "\t\$(call UninstallFile,$file)";
11464
}
11465
 
11466
sub PackageCmd
11467
{
2429 dpurdie 11468
    my( $dest, $file, $fmode ) = @_;
227 dpurdie 11469
 
11470
    $fmode = "-w"                           # default, read-only
11471
        if ( !defined( $fmode ) || $fmode eq "" );
11472
 
5991 dpurdie 11473
    $dest = QuoteForMake($dest);
11474
    $file = QuoteForMake($file);
2429 dpurdie 11475
    return "\t\$(call PackageFile,$dest,$file,$fmode)";
227 dpurdie 11476
}
11477
 
11478
sub UnpackageCmd
11479
{
11480
    my( $file ) = @_;
5991 dpurdie 11481
    $file = QuoteForMake($file);
227 dpurdie 11482
    return "\t\$(call UnpackageFile,$file)";
11483
}
11484
 
11485
1;
11486