Subversion Repositories DevTools

Rev

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