Subversion Repositories DevTools

Rev

Rev 6276 | Rev 6353 | 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
    #
5502
    #   Save the information
5503
    #
5504
    $PROJECTS{$proj}{'options'} = \@tool_options;
5505
    $PROJECTS{$proj}{'name'} = $proj;
5506
    $PROJECTS{$proj}{'project'} = $project;
5507
    $PROJECTS{$proj}{'basedir'} = $basedir;
5411 dpurdie 5508
    $PROJECTS{$proj}{'unittest'} = $unit_tests if ( $unit_tests );
5509
    $PROJECTS{$proj}{'autotest'} = $auto_tests if ( $auto_tests );
227 dpurdie 5510
    UniquePush (\@PROJECTS_ORDER, $proj);
5511
 
5512
    #
5513
    #   Validate some of the arguments
5514
    #
5515
    Error ("Makeproject. Conflicting options --Debug and --Prod" )
5516
        if ( $PROJECTS{$proj}{'Debug'}  && $PROJECTS{$proj}{'Prod'} );
5517
}
5518
 
5519
#-------------------------------------------------------------------------------
5520
# Function        : _PackageFromProject
5521
#
5522
# Description     : Save Packaged data from the project
5523
#
267 dpurdie 5524
# Inputs          : $tgt        - Install or Package
5525
#                   $proj       - Name of the project
227 dpurdie 5526
#                   $base       - Base directory of files
5527
#                   $etype      - Type of Package (Progs, Libs, ... )
5528
#                   $type       - Debug or Production or both
5529
#                   $items      - Item to add. It may be comma seperated
5530
#
267 dpurdie 5531
my %PackageToData = ( 'Package' =>
5532
                        { 'Hdr'   => \%PACKAGE_HDRS,
5533
                          'Lib'   => \%PACKAGE_LIBS,
5534
                          'Prog'  => \%PACKAGE_PROGS,
5535
                          'File'  => \%PACKAGE_FILES,
5536
                          'Tool'  => \%PACKAGE_FILES,
5537
                          '_BASE' => 'PBase',
5538
                        },
5539
                      'Install' =>
5540
                        { 'Hdr'   => \%INSTALL_HDRS,
5541
                          'Lib'   => \%INSTALL_LIBS,
5542
                          'Prog'  => \%INSTALL_PROGS,
5543
                          'File'  => undef,
5544
                          'Tool'  => undef,
5545
                          '_BASE' => 'IBase',
5546
                        },
227 dpurdie 5547
                    );
5548
 
5549
sub _PackageFromProject
5550
{
267 dpurdie 5551
    my( $tgt, $proj, $base, $etype, $type, $items ) = @_;
227 dpurdie 5552
    my $subdir = '';
5553
 
5554
    #
267 dpurdie 5555
    #   Sanity test
5556
    #
5557
    $type = '' unless ( $type );
5558
    Error ("INTERNAL. Bad packaging option: $tgt")   unless ( exists $PackageToData{$tgt} );
5559
    Error ("INTERNAL. Bad packaging option: $etype") unless ( exists $PackageToData{$tgt}{$etype} );
5560
    Error ("Unsupported packaging combination: $tgt$etype$type=$items") unless ( defined $PackageToData{$tgt}{$etype} );
5561
 
5562
    #
5563
    #   Determine the index into the 'PackageInfo' structure
5564
    #   This provides the symbolic name for the target package path
5565
    #   for Package or Install
5566
    #
5567
    #   The key '_BASE' is internal. Used only to provide this information
5568
    #
5569
    my $tbase = $PackageToData{$tgt}{'_BASE'};
5570
 
5571
    #
227 dpurdie 5572
    #   Process options
5573
    #
5574
    foreach my $item ( split (/,/, $items ) )
5575
    {
5576
        next unless ( $item =~ m/^--/ );
5577
        if ( $item =~ m/^--Subdir=(.*)/ )
5578
        {
5579
            $subdir = '/' . $1;
5580
            $subdir =~ s~//~/~g;
5581
            $subdir =~ s~/$~~g;
5582
        }
5583
        else
5584
        {
5585
            Warning( "MakeProject: Unknown packaging option ignored: $_" );
5586
        }
5587
    }
5588
 
5589
    #
5590
    #   Process files
5591
    #
5592
    foreach my $item ( split (/,/, $items ) )
5593
    {
5594
        next if ( $item =~ m/^--/ );
5595
 
267 dpurdie 5596
        my $tdir = $PackageInfo{$etype}{$tbase} . $PackageInfo{$etype}{'Dir'} . $subdir ;
227 dpurdie 5597
        my $fname = StripDir( $item );
5598
        my $target = $tdir . '/' . $fname;
5599
 
5600
        $item = "$base/$item" if ( $base );
5601
 
5602
        #
5603
        #   Do not use $(GBE_TYPE) in the target name
5604
        #   The existing package mechanism does not handle different
5605
        #   production and debug file naming mechanism, whereas the project
5606
        #   must. Convert $(GBE_TYPE) into P or D to ensure uniquness
5607
        #
5608
        $target =~ s~\$\(GBE_TYPE\)~$type~ if ($type);
5609
 
5610
        #
5611
        #   Create a PACKAGE entry suitable for processing by the normal packaging
5612
        #   routines. This is complicated because the Projects do not adhere to
267 dpurdie 5613
        #   the JATS file name conventions
227 dpurdie 5614
        #
5615
        my %package_entry;
5616
        $package_entry{'src'}   = $item;
5617
        $package_entry{'dir'}   = $tdir;
267 dpurdie 5618
        $package_entry{'set'}   = 'ALL' if ($tgt eq 'Package');
227 dpurdie 5619
        $package_entry{'type'}  = $type if ($type);
5620
 
267 dpurdie 5621
        $PackageToData{$tgt}{$etype}->{$target} = {%package_entry};
227 dpurdie 5622
    }
5623
}
5624
 
5625
#-------------------------------------------------------------------------------
5626
# Function        : MakeAnt
5627
#
5628
# Description     : A nasty directive to create JAR files via ANT
5629
#                   There are several limitations
5630
#                   This is closely related to the MakeProject directive
5631
#
5632
#
5633
# Inputs          : Platform            - Active platform
5634
#                   buildfile           - Name of the build.xml file
5635
#                   Options             - A few options
5636
#                                         --Jar=file
5637
#                                               Generated JAR file(s)
5638
#                                         --GeneratedFile=file
5639
#                                               Other generated files
5640
#                                               Used to flag JNI that must
5641
#                                               Occur early
5642
#                                          --AutoTest=<name>
5643
#                                               Supports unitAutomated unit test
5644
#                                               by calling build target <name>
5645
#                                          --UnitTest=<name>
5646
#                                               Supports unit test
5647
#                                               by calling build target <name>
5648
#                                          --PackageBase
5649
#                                               Provides path to base of all packages
6294 dpurdie 5650
#                                          --AllPackages
5651
#                                               Provide paths to both LinkPkgArchive and BuildPkgArchive
227 dpurdie 5652
#
5653
# Returns         :
5654
#
5655
our %JAR_FILES;
5656
sub MakeAnt
5657
{
5658
    my( $platforms, $proj, @elements ) = @_;
5659
 
5660
    Debug2( "MakeAnt($platforms, $proj, @elements)" );
5661
 
5662
    return if ( ! ActivePlatform($platforms) );
5663
 
5664
    #
5665
    #   Sanity test
5666
    #
5667
    Error ("MakeAnt: build.xml name not defined") unless ( $proj );
5668
 
5669
    #
5670
    #   Take the project name and convert it into a full path
5671
    #
5672
    my $project;
5673
    $project = MakeSrcResolve ( $proj );
4261 dpurdie 5674
    $proj = MakeProjectName($project);
237 dpurdie 5675
    Error ("Build File Not found: $project") unless ( -f $project );
227 dpurdie 5676
 
5677
    my $basedir = StripFileExt( $project );
5678
 
5679
    #
5680
    #   Collect user arguments
5681
    #   They are all processed within the toolset
5682
    #
5683
    my @tool_options;
5684
    my @generated;
5685
    my $unit_tests;
5686
    my $auto_tests;
5687
    my $package_base;
6294 dpurdie 5688
    my $allPackages;
227 dpurdie 5689
 
5690
    foreach ( @elements )
5691
    {
5692
        if ( m/^--Debug/ ) {
5693
            $PROJECTS{$proj}{'Debug'} = 1;
5694
 
5695
        } elsif ( m/^--Prod/ ) {
5696
            $PROJECTS{$proj}{'Prod'} = 1;
5697
 
5698
        } elsif ( m/^--Jar=(.*)/ ) {
5699
            my $tgt = $1;
5700
               $tgt = "$basedir/$tgt" if ( $basedir );
5701
            my $fn = StripDir( $1 );
5702
            $JAR_FILES{$fn} = $tgt;
5703
            GenerateSrcFile( 0, $tgt );
5704
 
5705
        } elsif ( m/^--GeneratedFile=(.*)/ ) {
5706
            my $tgt = $1;
5707
            $tgt = "$basedir/$tgt" if ( $basedir );
5708
            push @generated, $tgt;
5709
            GenerateSrcFile( 2, $tgt );
5710
 
5711
        } elsif ( m/^--UnitTest=(.*)/ ) {
5712
            $unit_tests = $1
5713
 
5714
        } elsif ( m/^--AutoTest=(.*)/ ) {
5715
            $auto_tests = $1
5716
 
5717
        } elsif ( m/^--PackageBase/ ) {
5718
            $package_base = 1;
5719
 
6294 dpurdie 5720
        } elsif ( m/^--AllPackages/i ) {
5721
            $allPackages = 1;
227 dpurdie 5722
 
5723
        } elsif ( m/^--/ ) {
5724
            Error("MakeAnt. Unknown option ignored: $_");
5725
 
5726
        } else {
5727
            push @tool_options, $_;
5728
        }
5729
    }
5730
 
5731
    #
5732
    #   Extend option arguments to include the base dir of packages
5733
    #   Create definitions of the form PACKAGE_<name>
5734
    #
6294 dpurdie 5735
    for my $entry (getPackageList())
227 dpurdie 5736
    {
6294 dpurdie 5737
        my $pkgType = $entry->getType();
5738
        next if $pkgType eq 'interface'  ;
5739
        next unless ( ( $pkgType eq 'link') || $allPackages);
5740
        my $dir = $entry->getBase(2);
5741
        my $name = $entry->getName();
227 dpurdie 5742
        unless ( $package_base )
5743
        {
5744
            $dir .= '/jar';
5745
            next unless ( -d $dir );
5746
        }
6294 dpurdie 5747
        push @tool_options, "-DPACKAGE_$name=\$(call myabspath,$dir)";
227 dpurdie 5748
    }
5749
    #
5750
    #   Extend options to include the base dir of the created package
5751
    #   Allows careful use for direct packaging of artifacts
5752
    #
6294 dpurdie 5753
    push @tool_options, '-DPACKAGEDIR=$(call myabspath,$(PKGDIR))';
227 dpurdie 5754
 
5755
    #
5756
    #   Save the information
5757
    #
5758
    $PROJECTS{$proj}{'options'} = \@tool_options;
5759
    $PROJECTS{$proj}{'generated'} = \@generated if ( @generated );
5760
    $PROJECTS{$proj}{'name'}    = $proj;
5761
    $PROJECTS{$proj}{'project'} = $project;
5762
    $PROJECTS{$proj}{'basedir'} = $basedir;
5763
    $PROJECTS{$proj}{'type'}    = 'ant';
5764
    $PROJECTS{$proj}{'unittest'} = $unit_tests if ( $unit_tests );
5765
    $PROJECTS{$proj}{'autotest'} = $auto_tests if ( $auto_tests );
5766
    UniquePush (\@PROJECTS_ORDER, $proj);
5767
 
5768
    $TESTS_TO_AUTORUN = 1 if ( $auto_tests );
4501 dpurdie 5769
    $TESTS_TO_RUN     = 1 if ( $unit_tests || $auto_tests );
227 dpurdie 5770
 
5771
    #
5772
    #   Validate some of the arguments
5773
    #
5774
    Error ("MakeAnt. Conflicting options --Debug and --Prod" )
5775
        if ( $PROJECTS{$proj}{'Debug'}  && $PROJECTS{$proj}{'Prod'} );
5776
}
5777
 
5778
###############################################################################
5779
#
5780
#   Installation/Packaging util functions
5781
#
5782
#-------------------------------------------------------------------------------
5783
# Function        : __TargetDir
5784
#
5785
# Description     : Internal function to process common arguments for
5786
#                   the PackageXxx directives
5787
#
5788
# Inputs          : flags           - Indicate how to handle this argument
5789
#                   base            - Base directory for this type of package
5790
#                   argument        - Argument to process
5791
#                   pdir            - Reference to resultant directory
5792
#                   ptype           - Reference to resultant type (P or D)(optional)
5793
#
5794
# Returns         : 0               - Agument not consumed
5795
#                   1               - Argument consumed
5796
#                   2               - Skip this directive
5797
#
5798
my $T_TYPE  = 0x0001;                           # Postfix GBE_TYPE
5799
my $T_PKG   = 0x0002;                           # Special --Dir handling
5800
my $T_MACH  = 0x0004;                           # Allow --Machine too
5801
my $T_GBE   = 0x0008;                           # Allow --Gbe too
5802
my $T_FILE  = 0x0010;                           # Suffix or prefix subdir
5803
 
5804
sub __TargetDir
5805
{
5806
    my( $flags, $base, $argument, $pdir, $ptype ) = @_;
5807
    my $dir  = "";
5808
    my $consumed = 0;
5809
 
5810
    #
5811
    #   Generate basic parts
5812
    #   Note Product will default to Platform
5813
    #
5814
    my $str_platform = '$(GBE_PLATFORM)';
5815
    my $str_product = $ScmProduct ? '$(GBE_PRODUCT)' : '$(GBE_PLATFORM)';
5816
    my $str_target = '$(GBE_TARGET)';
5817
    my $str_common = '$(GBE_OS_COMMON)';
5818
 
5819
    my $str_common_avail = 0;
5820
       $str_common_avail = 1 if ( exists( $::BUILDINFO{$ScmPlatform}{OS_COMMON} ));
5821
 
5822
 
5823
    #
5824
    #   Add requested suffix
5825
    #
5826
    if ($flags & $T_TYPE)
5827
    {
5828
        $str_platform .= '$(GBE_TYPE)';
5829
        $str_product  .= '$(GBE_TYPE)';
5830
        $str_target   .= '$(GBE_TYPE)';
5831
        $str_common   .= '$(GBE_TYPE)';
5832
    }
5833
 
5834
    #
5835
    #   Process the argument
5836
    #
5837
    $_ = $argument;
5838
    if ( /^--Debug/ ) {                         # In the Debug build only
5839
        if ( $ptype ) {
5840
            $$ptype = "D";
5841
            $consumed = 1;
5842
        }
5843
 
5844
    } elsif ( /^--Prod$/ || /^--Production$/ ) { # In the Production build only
5845
        if ( $ptype ) {
5846
            $$ptype = "P";
5847
            $consumed = 1;
5848
        }
5849
 
5850
    } elsif (/^--Prefix=(.*)/) {                # Prefix with subdir
5851
        $dir = "$base/$1";
5852
 
5853
    } elsif (/^--Subdir=(.*)/) {                # same as 'prefix'
5854
        $dir = "$base/$1";
5855
 
5856
    } elsif (/^--Platform$/) {                  # Platform installation
5857
        $dir = "$base/$str_platform";
5858
 
5859
    } elsif (/^--Platform=(.*?),(.*)/) {        # prefix and suffix with platform specific subdir
5860
        $dir = "$base/$1/$str_platform/$2";
5861
 
5862
    } elsif (/^--Platform=(.*)/) {              # prefix with platform specific subdir
5863
        if ($flags & $T_FILE) {
5864
            $dir = "$base/$1/$str_platform";
5865
        } else {
5866
            $dir = "$base/$str_platform/$1";
5867
        }
5868
 
5869
    } elsif (/^--Product$/) {                   # Product installation
5870
        $dir = "$base/$str_product";
5871
 
5872
    } elsif (/^--Product=(.*?),(.*)/) {         # prefix and suffix with product specific subdir
5873
        $dir = "$base/$1/$str_product/$2";
5874
 
5875
    } elsif (/^--Product=(.*)/) {               # prefix with product specific subdir
5876
        if ($flags & $T_FILE) {
5877
            $dir = "$base/$1/$str_product";
5878
        } else {
5879
            $dir = "$base/$str_product/$1";
5880
        }
5881
 
5882
    } elsif (/^--Target$/) {                    # Target installation
5883
        $dir = "$base/$str_target";
5884
 
5885
    } elsif (/^--Target=(.*?),(.*)/) {          # prefix and suffix with target specific subdir
5886
        $dir = "$base/$1/$str_target/$2";
5887
 
5888
    } elsif (/^--Target=(.*)/) {                # prefix with target specific subdir
5889
        if ($flags & $T_FILE) {
5890
            $dir = "$base/$1/$str_target";
5891
        } else {
5892
            $dir = "$base/$str_target/$1";
5893
        }
5894
 
5895
    } elsif (/^--OsCommon/) {
5896
 
5897
        unless ( $str_common_avail ) {
5898
            Warning("Packaging option --OsCommon not supported on this platform($ScmPlatform). Directive skipped");
5899
            $consumed = 2;
5900
 
5901
        } elsif (/^--OsCommon$/) {                  # OS installation
5902
            $dir = "$base/$str_common";
5903
 
5904
        } elsif (/^--OsCommon=(.*?),(.*)/) {        # prefix and suffix with target specific subdir
5905
            $dir = "$base/$1/$str_common/$2";
5906
 
5907
        } elsif (/^--OsCommon=(.*)/) {              # prefix with target specific subdir
5908
            if ($flags & $T_FILE) {
5909
                $dir = "$base/$1/$str_common";
5910
            } else {
5911
                $dir = "$base/$str_common/$1";
5912
            }
5913
        }
5914
 
5915
    } elsif (/^--Derived=(.*?),(.*?),(.*)/) {   # Derived target + prefix + subdir
5916
        $dir = "$base/$2/$1_$str_platform/$3";
5917
 
5918
    } elsif (/^--Derived=(.*?),(.*)/) {         # Derived target + subdir
5919
        if ($flags & $T_FILE) {
5920
            $dir = "$base/$2/$1_$str_platform";
5921
        } else {
5922
            $dir = "$base/$1_$str_platform/$2";
5923
        }
5924
 
5925
    } elsif (/^--Derived=(.*)/) {               # Derived target
5926
        $dir = "$base/$1_$str_platform";
5927
 
5928
    } elsif ($flags & $T_MACH && /^--Machine(([=])(.*))?$/) {   # Allow Machine and Machine=xxx specfic target
5929
        #
5930
        #   Special: Append machine type to user dir
5931
        #            Intended to create tools/bin/win32 and tools/bin/sparc directories
5932
        my $path = ( defined( $3) ) ? "/$3" : "";
5933
        $dir = "$base$path/\$(GBE_HOSTMACH)";
5934
 
5935
    } elsif ($flags & $T_GBE && /^--Gbe(([=])(.*))?$/) {   # Allow Gbe and Gbe=xxx specfic target
5936
        my $path = ( defined( $3) ) ? "/$3" : "";
5937
        $dir = "$base/gbe$path";
5938
 
5939
    } elsif (/^--Dir=(.*)/) {                   # prefix with target specific subdir
5940
        Error ('Packaging directive with --Dir option does not specify a directory.',
5941
               'Possible bad use of option of the form:--Dir=$xxx',
5942
               'Note: Use of package.pl and this construct is deprecated') unless ( $1 );
241 dpurdie 5943
        my $udir = $1;
5944
 
5945
        #
5946
        #   Remove leading ./
5947
        #   Check for leading ../
5568 dpurdie 5948
        #   
5949
        #   Remove any stupid path manipulation elements
5950
        #   
5827 dpurdie 5951
        if ($udir =~ s~^([./]*/)~~)
5952
        {
5953
            Warning("Packaging directive with --Dir option contains path manipulation elements (removed)", "Option: $_");
5954
        }
241 dpurdie 5955
 
227 dpurdie 5956
        if ($flags & $T_PKG) {
241 dpurdie 5957
            $dir = __PkgDir( $udir );
227 dpurdie 5958
        } else {
241 dpurdie 5959
            $dir = "\$(LOCALDIR)/$udir";
227 dpurdie 5960
        }
5961
    }
5962
 
5963
    return ($consumed) if ($dir eq "");
5964
    $dir =~ s~//~/~g;
5965
    $dir =~ s~/$~~;
5966
    $$pdir = $dir;
5967
    return (1);
5968
}
5969
 
5970
 
5971
#   __PkgDir ---
5972
#       Convert --Dir Package directives, removing leading subdir if
5973
#       matching the global $Pbase value.
5974
#
5975
#       Required as PKGDIR has the value 'GBE_ROOT/pkg/$Pbase'.
5976
#       Required to maintain compatability with older (package.pl) constructs
5977
#..
5978
 
5979
sub __PkgDir
5980
{
5981
    my( $dir ) = @_;
5982
    my $org = $dir;
5983
 
245 dpurdie 5984
    $dir =~ s~^\Q$::Pbase\E[/]?~~;
227 dpurdie 5985
    Debug2( "  PkgDir: converted \"$org\" to \"$dir\"" );
5986
 
5987
    $dir = "\$(PKGDIR)/$dir";
5988
    return $dir;
5989
}
5990
 
5991
 
5992
#   getMajorMinor ---
5993
#       Just a little help to deal with major/minor stuff for shared libs -
5994
#       given the name of the library as the argument, split out major and
5995
#       minor parts and return the basename, i.e name without major and minor
5996
#       and the pair of major and minor.
5997
#..
5998
 
285 dpurdie 5999
sub getMajorMinor
227 dpurdie 6000
{
6001
    my @bits = split ('\.', $_[0]);
6002
    my $stop;
6003
    my $major;
6004
    my $minor;
6005
 
6006
    if ( $#bits > 2 )
6007
    {
6008
        $stop = $#bits - 2;
6009
        $major = $bits[$#bits-1];
6010
        $minor = $bits[$#bits];
6011
    }
6012
    elsif ($#bits > 1)
6013
    {
6014
        $stop = $#bits-1;
6015
        $major = $bits[$#bits];
6016
        $minor=0;
6017
    }
6018
    else
6019
    {
6020
        $stop = $#bits; $major = 1; $minor = 0;
6021
    }
6022
 
6023
    my $base = $bits[0];
6024
    for ( my $i=1; $i <= $stop; $i++ ) {
6025
        $base = join ('.', $base, $bits[$i]);
6026
    }
6027
 
6028
    return ($base, $major, $minor);
6029
}
6030
 
6031
###############################################################################
6032
#
6033
#   Installation
6034
#
6035
 
6036
sub InstallHdr
6037
{
6038
    my( $platforms, @elements ) = @_;
335 dpurdie 6039
    my( $base, $dir, $srcfile, $full, $strip, $package );
227 dpurdie 6040
    my( $len, $name, $basename );
6041
 
6042
    Debug2( "InstallHdr($platforms, @elements)" );
6043
 
6044
    return if ( ! ActivePlatform($platforms) );
6045
    Warning ("InstallHdr: Needs local directory specified in build.pl") unless ( $::ScmLocal );
6046
 
6047
#.. Arguments
6048
#
6049
    $base = $PackageInfo{'Hdr'}{'IBase'};       # Base of target
6050
    $dir = $base . $PackageInfo{'Hdr'}{'Dir'};  # Installation path (default)
335 dpurdie 6051
    $full = $strip = 0;
227 dpurdie 6052
 
285 dpurdie 6053
    foreach ( @elements )
227 dpurdie 6054
    {
6055
                                                # Standard targets
6056
        my $rv = __TargetDir(0, $base, $_, \$dir);
6057
        next if ( $rv == 1 );
6058
        return if ( $rv == 2 );
6059
 
6060
        if (/^--Full/) {                        # using full (resolved) path
6061
            $full = 1;
6062
 
6063
        } elsif (/^--Strip$/) {                 # Strip path from source files
6276 dpurdie 6064
            $strip = -1;
227 dpurdie 6065
 
6276 dpurdie 6066
        } elsif (/^--Strip=(\d+)$/) {           # Strip some f the path from source files
6067
            $strip = $1;
227 dpurdie 6068
                                                # Package
6069
        } elsif (/^--Package$/ || /^--Package=(.*)/) {
6070
            $package = 1;
6071
 
6072
        } elsif (/^--(.*)/) {
6073
            Message( "InstallHdr: unknown option $_ -- ignored\n" );
6074
        }
6075
    }
6076
 
6077
#.. Files
6078
#
285 dpurdie 6079
    foreach ( @elements )
227 dpurdie 6080
    {
6081
        my %package_entry;
6082
        if ( ! /^--(.*)/ )
6083
        {
6084
            $name = $_;
6085
            $basename = StripDir( $name );
335 dpurdie 6086
            if ( !($srcfile = $SRCS{ $basename }) ) {
6087
                $srcfile = $name;
6088
            }
6089
 
227 dpurdie 6090
            if ( $full )
6091
            {
335 dpurdie 6092
                my $subdir = StripFileExt($srcfile);
6093
                $subdir = $1
6094
                    if ( $subdir =~ m~^$ProjectBase/(.*)~ );
6095
                $dir .= '/' . $subdir;
6096
                $dir =~ s~//~/~g;
6097
                $dir =~ s~/./~/~g;
6098
                $dir =~ s~/$~~g;
6099
                $name = $basename;
227 dpurdie 6100
            }
6101
 
6276 dpurdie 6102
            $name = StripPath($name, $strip) if ($strip);
227 dpurdie 6103
 
6104
            Debug( "InstallHdr( $dir/$name, src: $srcfile, dest: $dir)" );
6105
 
6106
            $package_entry{'src'} = $srcfile;
6107
            $package_entry{'dir'} = StripFileExt( "$dir/$name" );
6108
            $INSTALL_HDRS{ "$dir/$name" } = {%package_entry};
6109
        }
6110
    }
6111
 
6112
#.. Package
6113
#
6114
    PackageHdr( @_ )                            # auto package
6115
        if ( $package );
6116
}
6117
 
6118
 
6119
sub InstallLib
6120
{
6121
    my( $platforms, @elements ) = @_;
6122
    my( $base, $dir, $package );
6123
    my( $lib, $strip );
289 dpurdie 6124
    my $org_lib;
227 dpurdie 6125
 
6126
    Debug2( "InstallLib($platforms, @elements)" );
6127
 
6128
    return if ( ! ActivePlatform($platforms) );
6129
    Warning ("InstallLib: Needs local directory specified in build.pl") unless ( $::ScmLocal );
6130
 
6131
#.. Arguments
6132
#
6133
    $base = $PackageInfo{'Lib'}{'IBase'};       # Base of target
6134
    $dir = $base . $PackageInfo{'Lib'}{'Dir'};  # Installation path (default)
6135
 
285 dpurdie 6136
    foreach ( @elements )
227 dpurdie 6137
    {
6138
                                                # Standard targets
6139
        my $rv = __TargetDir(0, $base, $_, \$dir);
6140
        next if ( $rv == 1 );
6141
        return if ( $rv == 2 );
6142
 
6143
        if (/^--Package$/ || /^--Package=(.*)/) {
6144
            $package = 1;
6145
 
6146
        } elsif (/^--Strip$/) {                 # Strip path from source files
6276 dpurdie 6147
            $strip = -1;
227 dpurdie 6148
 
6276 dpurdie 6149
        } elsif (/^--Strip=(\d+)$/) {           # Strip some f the path from source files
6150
            $strip = $1;
6151
 
227 dpurdie 6152
        } elsif (/^--(.*)/) {
6153
            Message( "InstallLib: unknown option $_ -- ignored\n" );
6154
        }
6155
    }
6156
 
6157
#.. Files
6158
#
285 dpurdie 6159
    foreach ( @elements )
227 dpurdie 6160
    {
6161
        my %package_entry;
6162
        if ( ! /^--(.*)/ )
6163
        {
6276 dpurdie 6164
            $_ = StripPath($_, $strip) if ($strip);
289 dpurdie 6165
            $org_lib = $_;                      # Original name
227 dpurdie 6166
 
6167
            if ( $ScmTargetHost eq "Unix" ) {
6168
                $lib = "lib$_";                 # Prefix "lib" ....
6169
                $lib =~ s/^liblib/lib/;         # @LIBS already has lib added
6170
            } else {
6171
                $lib = $_;
6172
            }
6173
 
289 dpurdie 6174
            if (  my $libp = $SHLIBS->Get($lib) )
227 dpurdie 6175
            {
6176
                Debug( "InstallLib( $dir/$lib\$(GBE_TYPE).$::so, " .
6177
                    "src: \$(LIBDIR)/$lib\$(GBE_TYPE).$::so, dest: $dir)" );
6178
 
6179
                #
6180
                #   Create a "placekeeper" entry within $INSTALL_SHLIBS
6181
                #   The exact format of the name of the shared library is
6182
                #   toolset specific. Create an entry to allow the toolset
6183
                #   to extend the packaging information when the shared library
6184
                #   recipe is constructed.
6185
                #
289 dpurdie 6186
                my $ver = $libp->{ VERSION };
227 dpurdie 6187
                my $name = "$dir/$lib.$ver.PlaceKeeper";
6188
 
6189
                $package_entry{'placekeeper'} = 1;
6190
                $package_entry{'version'} = $ver;
6191
                $package_entry{'lib'} = $lib;
6192
                $package_entry{'dir'} = $dir;
289 dpurdie 6193
 
6194
                push @{$SHLIB_INS{$lib}}, $name;
227 dpurdie 6195
                $INSTALL_SHLIBS{$name} = {%package_entry};
6196
            }
6197
 
289 dpurdie 6198
            #
6199
            #   Clean up the package_entry
6200
            #   Insert common items
6201
            #
6202
            %package_entry = ();
6203
            $package_entry{'lib'} = $lib;
6204
            $package_entry{'dir'} = $dir;
6205
 
321 dpurdie 6206
            if ( my $libfile = $SRCS{$org_lib} )
227 dpurdie 6207
            {
6208
                #
6209
                #   Allow the user to package a sourced file as a library
289 dpurdie 6210
                #   But must be the un-massaged name of the file.
227 dpurdie 6211
                #
289 dpurdie 6212
                $package_entry{'dst'} = "$dir/$org_lib";
6213
                $package_entry{'src'} = $libfile;
6214
            }
6215
            elsif ( $LIBS->Get($lib) )
6216
            {
6217
                #
6218
                #   Install a library known to the makefile
6219
                #
6220
                my $libp = $LIBS->Get($lib);
227 dpurdie 6221
 
289 dpurdie 6222
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
6223
                $package_entry{'src'}    = $libp->getPath();
227 dpurdie 6224
            }
289 dpurdie 6225
            elsif ( ! $SHLIBS->Get($lib) )
227 dpurdie 6226
            {
289 dpurdie 6227
                #
6228
                #   Not a known shared lib
6229
                #   Not a known static lib
6230
                #   Not a 'sourced' file
6231
                #   Assume the a static library has magically appeared
6232
                #   in the standard LIB directory. May have been placed there
6233
                #   by a 'rule'
6234
                #
6235
                my $libp = $LIBS->New($lib);
227 dpurdie 6236
 
289 dpurdie 6237
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
6238
                $package_entry{'src'}    = $libp->getPath();
6239
            }
227 dpurdie 6240
 
289 dpurdie 6241
            #
6242
            #   Add entry to various lists if required
6243
            #
6244
            PackageLib_AddEntry ('InstallLib', \%LIB_INS, \%INSTALL_LIBS, \%package_entry )
6245
                if ( exists $package_entry{'dst'} );
227 dpurdie 6246
        }
6247
    }
6248
 
6249
#.. Package
6250
#
6251
    PackageLib( @_ )                            # auto package
6252
        if ( $package );
6253
}
6254
 
6255
 
6256
sub InstallJar
6257
{
6258
    my( $platforms, @elements ) = @_;
6259
    my( $base, $dir, $package );
6260
    my( $jar );
6261
 
6262
    Debug2( "InstallJar($platforms, @elements)" );
6263
 
6264
    return if ( ! ActivePlatform($platforms) );
6265
    Warning ("InstallJar: Needs local directory specified in build.pl") unless ( $::ScmLocal );
6266
 
6267
#.. Arguments
6268
#
6269
    $base = $PackageInfo{'Jar'}{'IBase'};       # Base of target
6270
    $dir = $base . $PackageInfo{'Jar'}{'Dir'};  # Installation path (default)
6271
 
285 dpurdie 6272
    foreach ( @elements )
227 dpurdie 6273
    {
6274
                                                # Standard targets
6275
        my $rv = __TargetDir(0, $base, $_, \$dir);
6276
        next if ( $rv == 1 );
6277
        return if ( $rv == 2 );
6278
 
6279
        if (/^--Package$/ || /^--Package=(.*)/) {
6280
            $package = 1;
6281
 
6282
        } elsif (/^--(.*)/) {
6283
            Message( "InstallJar: unknown option $_ -- ignored\n" );
6284
        }
6285
    }
6286
 
6287
 
6288
#.. Files
6289
#
285 dpurdie 6290
    foreach ( @elements )
227 dpurdie 6291
    {
6292
        my %package_entry;
6293
        if ( ! /^--(.*)/ )
6294
        {
6295
            $jar = $_;
6296
            my $src;
6297
            my $dest;
6298
 
6299
            if ( $JAR_FILES{$jar} )
6300
            {
6301
                $src = $JAR_FILES{$jar};
6302
                $dest = $jar;
6303
            }
6304
            else
6305
            {
6306
                $src = "\$(CLSDIR)/$jar\$(GBE_TYPE).jar";
6307
                $dest = "$jar\$(GBE_TYPE).jar";
6308
            }
6309
 
6310
 
6311
            Debug( "InstallJar( $dir/$dest, " .
6312
                "src: $src, dest: $dir)" );
6313
 
6314
            $package_entry{'src'} = $src;
6315
            $package_entry{'dir'} = $dir;
6316
            $INSTALL_CLSS{ "$dir/$dest" } = {%package_entry};
6317
 
6318
        }
6319
    }
6320
 
6321
#.. Package
6322
#
6323
    PackageJar( @_ )                            # auto package
6324
        if ( $package );
6325
}
6326
 
6327
 
6328
sub InstallProg
6329
{
6330
    my( $platforms, @elements ) = @_;
6331
    my( $base, $dir, $package );
6332
    my( $prog );
6333
 
6334
    Debug2( "InstallProg($platforms, @elements)" );
6335
 
6336
    return if ( ! ActivePlatform($platforms) );
6337
    Warning ("InstallProg: Needs local directory specified in build.pl") unless ( $::ScmLocal );
6338
 
6339
#.. Arguments
6340
#
6341
    $base = $PackageInfo{'Prog'}{'IBase'};       # Base of target
6342
    $dir = $base . $PackageInfo{'Prog'}{'Dir'};  # Installation path (default)
6343
 
285 dpurdie 6344
    foreach ( @elements )
227 dpurdie 6345
    {
6346
                                                # Standard targets
6347
        my $rv = __TargetDir($T_TYPE, $base, $_, \$dir);
6348
        next if ( $rv == 1 );
6349
        return if ( $rv == 2 );
6350
 
6351
        if (/^--Package$/ || /^--Package=(.*)/) {
6352
            $package = 1;
6353
 
6354
        } elsif (/^--(.*)/) {
6355
            Message( "InstallProg: unknown option $_ -- ignored\n" );
6356
        }
6357
    }
6358
 
6359
#.. Files
6360
#
285 dpurdie 6361
    foreach ( @elements )
227 dpurdie 6362
    {
6363
        my %package_entry;
6364
        if ( ! /^--(.*)/ )
6365
        {
6366
            my $ext = "";
6367
            $prog = $_;
6368
 
6369
            #
6370
            #   If the named target is a program then append the correct
6371
            #   extension. Otherwise assume that the target is either a script
6372
            #   or a some other file - and don't append an extension
6373
            #
6374
            $ext = $::exe
289 dpurdie 6375
                if ( $PROGS->Get($prog) );
227 dpurdie 6376
 
6377
            #
6378
            #   A "file" that is specified with a "Src" directive may be
6379
            #   installed as though it were a program
6380
            #
6381
            my $progfile;
6382
            $progfile = "\$(BINDIR)/$prog$ext"
6383
                unless ( $progfile = $SRCS{$prog} );
6384
 
6385
            Debug( "InstallProg( $dir/$prog$ext, " .
6386
                 "src: $progfile, dest: $dir)" );
6387
 
6388
            push @{$PROG_INS{$prog}}, "$dir/$prog$ext";
6389
 
6390
            $package_entry{'src'} = $progfile;
6391
            $package_entry{'dir'} = $dir;
6392
            $INSTALL_PROGS{ "$dir/$prog$ext" } = {%package_entry};
6393
        }
6394
    }
6395
 
6396
#.. Package
6397
#
6398
    PackageProg( @_ )                           # auto package
6399
        if ( $package );
6400
}
6401
 
6276 dpurdie 6402
#-------------------------------------------------------------------------------
6403
# Function        : StripPath 
6404
#
6405
# Description     : Internal function to strip bits from a pathname
6406
#                   Will never strip the filename, even if asked to strip too much
6407
#
6408
# Inputs          : $name       - Name to process
6409
#                   $stripCount - Strip part
6410
#                                 <0 - strip all paths
6411
#                                 =0  - Do nothing
6412
#                                 >0 - Strip count
6413
#
6414
# Returns         : Processed name
6415
#
6416
sub StripPath
6417
{
6418
    my( $name, $stripCount) = @_;
227 dpurdie 6419
 
6276 dpurdie 6420
    if ($stripCount)
6421
    {
6422
        $name =~ s~\\~/~g;
6423
        $name =~ s~//~~g;
6424
 
6425
        my @items = split('/', $name);
6426
        if ($stripCount > 0)
6427
        {
6428
            my $len = scalar @items;
6429
            my $remove = $stripCount; 
6430
            if ($stripCount >= $len ) {
6431
                $remove = $len - 1;
6432
            }
6433
            splice @items, 0, $remove;
6434
            $name = join('/', @items);
6435
        }
6436
        else
6437
        {
6438
            $name = pop @items;
6439
        }
6440
    }
6441
    return $name;
6442
}
6443
 
6444
 
227 dpurdie 6445
###############################################################################
6446
#
6447
#   Packaging
6448
#
6449
sub PackageDist
6450
{
6451
    my( $name, @elements ) = @_;
6452
 
6453
    Debug2( "PackageDist($name, @elements)" );
6454
 
6455
    foreach ( @elements )
6456
    {
6457
    #.. Distribution sets
6458
    #
6459
        HashJoin( \%PACKAGE_DIST, $;, $name, "$_" );
6460
 
6461
    #.. Summary of distribution sets
6462
    #
267 dpurdie 6463
        $PACKAGE_SETS{ $_ }{'TAG'} = 1
6464
            if ( ! exists $PACKAGE_SETS{ $_ }{'TAG'} );
227 dpurdie 6465
    }
6466
}
6467
 
311 dpurdie 6468
#-------------------------------------------------------------------------------
6469
# Function        : PackageFile
6470
#
6471
# Description     : Directive to package files
6472
#                   Not to be used to package libraries, executables, headers
6473
#                   as this should be done by specialised directives
6474
#
6475
#                   Use to package other files
6476
#                   Can package an entire tree (ugly)
6477
#
6478
# Inputs          : 
6479
#
6480
#
227 dpurdie 6481
sub PackageFile
6482
{
6483
    my( $platforms, @elements ) = @_;
335 dpurdie 6484
    my( $base, $dir, $full, $path, $dist, $strip, $exefile, $type );
227 dpurdie 6485
    my( $name, $basename, $len, $srcfile );
4257 dpurdie 6486
    my( $dir_tree, @dir_tree_exclude, @dir_tree_include, $strip_base, $strip_dots );
335 dpurdie 6487
    my $recurse = 1;
6133 dpurdie 6488
    my $preserveSymlink = 0;
227 dpurdie 6489
 
6490
    Debug2( "PackageFile($platforms, @elements)" );
6491
 
6492
    return if ( !$ScmPackage );                 # Packaging enabled ?
6493
    return if ( ! ActivePlatform($platforms) );
6494
 
6495
#.. Arguments
6496
#
6497
    $dist = "ALL";                                  # Default set (ALL)
6498
    $base = $PackageInfo{'File'}{'PBase'};          # Base of target
6499
    $dir = $base . $PackageInfo{'File'}{'Dir'};     # Installation path (default)
335 dpurdie 6500
    $full = 0;
227 dpurdie 6501
    $strip = 0;
341 dpurdie 6502
    $strip_base = 0;
4257 dpurdie 6503
    $strip_dots = 0;
227 dpurdie 6504
    $exefile = 0;
6505
 
285 dpurdie 6506
    foreach ( @elements )
227 dpurdie 6507
    {
6508
        my $rv = __TargetDir($T_PKG|$T_MACH|$T_GBE|$T_FILE, $base, $_, \$dir, \$type);
6509
        next if ( $rv == 1 );
6510
        return if ( $rv == 2 );
6511
 
6512
        if (/^--Full/) {                        # Using full (resolved) path
6513
            $full = 1;
6514
 
6515
        } elsif (/^--Set=(.*)/) {               # Distribution set
6516
            $dist = "$1";
6517
 
6518
        } elsif (/^--Package$/) {               # Package .. call by InstallFile
6519
        } elsif (/^--Package=(.*)/) {
6520
            $dist = "$1";
6521
 
6522
        } elsif (/^--Strip$/) {                 # Strip path from source files
6276 dpurdie 6523
            $strip = -1;
227 dpurdie 6524
 
6294 dpurdie 6525
        } elsif (/^--Strip=(\d+)$/) {           # Strip path from source files
6276 dpurdie 6526
            $strip = $1;
6527
 
227 dpurdie 6528
        } elsif (/^--Executable$/) {            # Mark the file as executable
6529
            $exefile = "X";
6530
 
6133 dpurdie 6531
        } elsif (/^--PreserveSymlink/i) {       # Preserve symlink to local file
6532
            $preserveSymlink = 1;
6533
 
227 dpurdie 6534
        } elsif ( /^--DirTree=(.*)/ ) {
6535
            Error("DirTree. Multiple directories not allowed.") if ( $dir_tree );
4163 dpurdie 6536
            $dir_tree =  $1;
4257 dpurdie 6537
            Error("DirTree. No path specified") unless ( defined($dir_tree) && $dir_tree ne "" );
227 dpurdie 6538
 
4163 dpurdie 6539
            # Prevent the user from escaping from the current directory
6540
            Error("DirTree. Absolute paths are not allowed",
6541
                  "Directory: $dir_tree") if ( $dir_tree =~ m~^/~ || $dir_tree =~ m~^.\:~ );
6542
 
6543
            #
6544
            #   Convert the relative path to one that is truely relative to the current
6545
            #   directory. This may occur when the user uses $ProjectBase
6546
            #
4257 dpurdie 6547
            my $abs_dir_tree = AbsPath($dir_tree);
6548
            $dir_tree = RelPath($abs_dir_tree);
6549
 
6550
            #
6551
            #   Ensure that the user is not trying to escape the package
4265 dpurdie 6552
            #   Don't allow the user to attempt to package the entire package either
4257 dpurdie 6553
            #
6554
            #   Calculate the relative path from $ProjectBase to the target directory
6555
            #   It must not be above the $ProjectBase 
6556
            #
4265 dpurdie 6557
            if ( $dir_tree =~ m~^\.\.~)
6558
            {
6559
                my $dirFromBase = RelPath($abs_dir_tree, AbsPath($ProjectBase));
6560
                Error("DirTree cannot extend outside current package.",
6561
                      "Directory: $dirFromBase") if ( $dirFromBase =~ m~\.\.~ );
6562
                Error("DirTree cannot package entire package.",
6563
                    "Directory: $dirFromBase") if ( $dirFromBase eq '.' );
6564
            }
4257 dpurdie 6565
 
4163 dpurdie 6566
            Debug2( "PackageFile. DirTree: $dir_tree" );
6567
 
227 dpurdie 6568
            Error("DirTree. Directory not found",
6569
                  "Directory: $dir_tree") unless  ( -d $dir_tree );
6570
 
4257 dpurdie 6571
            # If packaging a parent directory then force dot_stripping of the base directory
6572
            # strip_base will have precedence if both are active
6573
            if ( $dir_tree =~ m~\.\.~ )
6574
            {
6575
                $dir_tree =~ m~(\.\./)+~;
6576
                $strip_dots = length($1);
6577
            }
6578
 
227 dpurdie 6579
        } elsif ( /^--FilterOut=(.*)/ ) {
6580
            push @dir_tree_exclude, $1;
6581
 
6582
        } elsif ( /^--FilterIn=(.*)/ ) {
6583
            push @dir_tree_include, $1;
6584
 
6585
        } elsif ( /^--StripDir/ ) {
341 dpurdie 6586
            $strip_base = 1;
227 dpurdie 6587
 
335 dpurdie 6588
        } elsif ( m/^--Recurse/ ) {
6589
            $recurse = 1;
6590
 
6591
        } elsif ( m/^--NoRecurse/ ) {
6592
            $recurse = 0;
6593
 
227 dpurdie 6594
        } elsif (/^--(.*)/) {
6595
            Message( "PackageFile: unknown option $_ -- ignored\n" );
6596
        }
6597
    }
6598
 
6599
 
6600
    #.. DirTree expansion
6601
    #   Note: Uses REs, not simple globs
6602
    #         Use JatsLocateFiles to do the hard work
6603
    if ( $dir_tree )
6604
    {
335 dpurdie 6605
        my $search = JatsLocateFiles->new('FullPath' );
6606
        $search->recurse($recurse);
227 dpurdie 6607
        $search->filter_in_re ( $_ ) foreach ( @dir_tree_include );
6608
        $search->filter_out_re( $_ ) foreach ( @dir_tree_exclude );
1431 dpurdie 6609
        $search->filter_out_re( '/\.svn/' );
5848 dpurdie 6610
        $search->filter_out_re( '/\.git/' );
227 dpurdie 6611
        @elements = $search->search ( $dir_tree );
4257 dpurdie 6612
        if ($strip_base){
6613
            $strip_base = length( $dir_tree ) if ( $strip_base );
6614
        } elsif ($strip_dots) {
6615
            $strip_base = $strip_dots;
6616
        }
227 dpurdie 6617
    }
6618
 
6619
#.. Files
6620
#
285 dpurdie 6621
    foreach ( @elements )
227 dpurdie 6622
    {
6623
        my %package_entry;
299 dpurdie 6624
        $name = $_;
6133 dpurdie 6625
        my $symlink;
299 dpurdie 6626
 
227 dpurdie 6627
        #
299 dpurdie 6628
        #   Trap special files
6629
        #       DPACKAGE - but only if we have a DPackageLibrary directive
6630
        #                  in the same makefile.
6631
        #
6632
        if ( m~^DPACKAGE$~ && $DPackageDirective ) {
6633
            $name = 'DPACKAGE.' . $::GBE_MACHTYPE;
6634
        }
6635
 
227 dpurdie 6636
        if ( ! /^--(.*)/ )
6637
        {
6638
            $basename = StripDir( $name );
335 dpurdie 6639
            if ( !($srcfile = $SRCS{ $basename }) ) {
6640
                $srcfile = $name;
6641
            }
6642
 
227 dpurdie 6643
            if ( $full )
6644
            {
335 dpurdie 6645
                my $subdir = StripFileExt($srcfile);
6646
                $subdir = $1
6647
                    if ( $subdir =~ m~^$ProjectBase/(.*)~ );
6648
                $dir .= '/' . $subdir;
6649
                $dir =~ s~//~/~g;
6650
                $dir =~ s~/./~/~g;
6651
                $dir =~ s~/$~~g;
6652
                $name = $basename;
227 dpurdie 6653
            }
6654
 
6276 dpurdie 6655
            $name = StripPath($name, $strip) if ($strip);
227 dpurdie 6656
 
341 dpurdie 6657
            if ( $strip_base )
6658
            {
6659
                $name = substr $name, $strip_base;
6660
                $name =~ s~^/~~;
6661
            }
6662
 
227 dpurdie 6663
            $dir =~ s~//~/~g;
6664
            $dir =~ s~/$~~;
6665
 
6666
            #
6133 dpurdie 6667
            #   Preserve Symlink
6668
            #
6669
            if ($preserveSymlink && -l $srcfile)
6670
            {
6671
                $symlink = 1;
6672
            }
6673
 
6674
            #
227 dpurdie 6675
            #   Sanity test the source filename
6676
            #   User may have misused an option
6677
            #
6678
            if ( ( $srcfile =~ m/=/ ) || ( $srcfile =~ m/^-/ ) || ( $srcfile =~ m~/-~ )  )
6679
            {
6680
               Warning ("PackageFile: Suspect source filename: $srcfile");
6681
            }
6682
 
6683
            Debug( "PackageFile( $dir/$name, " .
6684
                "src: $srcfile, dest: $dir, dist: $dist, exe: $exefile )" );
6685
 
6686
            $package_entry{'src'} = $srcfile;
6687
            $package_entry{'dir'} = StripFileExt( "$dir/$name" );
6688
            $package_entry{'set'} = $dist;
6689
            $package_entry{'exe'} = $exefile if $exefile;
6690
            $package_entry{'type'} = $type if ( $type );
6133 dpurdie 6691
            $package_entry{'symlink'} = 1 if ( $symlink );
227 dpurdie 6692
 
6693
            $PACKAGE_FILES{ "$dir/$name" } = {%package_entry};
6694
        }
6695
    }
6696
}
6697
 
6698
sub PackageHdr
6699
{
6700
    my( $platforms, @elements ) = @_;
335 dpurdie 6701
    my( $base, $dir, $full, $path, $dist, $strip );
227 dpurdie 6702
    my( $name, $basename, $len, $srcfile );
6703
 
6704
    Debug2( "PackageHdr($platforms, @elements)" );
6705
 
6706
    return if ( !$ScmPackage );                 # Packaging enabled ?
6707
    return if ( ! ActivePlatform($platforms) );
6708
 
6709
#.. Arguments
6710
#
6711
    $dist = "ALL";                                  # Default set (ALL)
6712
    $base = $PackageInfo{'Hdr'}{'PBase'};           # Base of target
6713
    $dir = $base . $PackageInfo{'Hdr'}{'Dir'};      # Installation path (default)
335 dpurdie 6714
    $full = 0;
227 dpurdie 6715
    $strip = 0;
6716
 
285 dpurdie 6717
    foreach ( @elements )
227 dpurdie 6718
    {
6719
        my $rv = __TargetDir($T_PKG, $base, $_, \$dir);
6720
        next if ( $rv == 1 );
6721
        return if ( $rv == 2 );
6722
 
6723
        if (/^--Full/) {                        # Using full (resolved) path
6724
            $full = 1;
6725
 
6726
        } elsif (/^--Set=(.*)/) {               # Distribution set
6727
            $dist = "$1";
6728
 
6729
        } elsif (/^--Package$/) {               # Package .. call by InstallHdr
6730
        } elsif (/^--Package=(.*)/) {
6731
            $dist = "$1";
6732
 
6733
        } elsif (/^--Strip$/) {                 # Strip path from source files
6276 dpurdie 6734
            $strip = -1;
227 dpurdie 6735
 
6276 dpurdie 6736
        } elsif (/^--Strip=(\d+)$/) {           # Strip some f the path from source files
6737
            $strip = $1;
6738
 
227 dpurdie 6739
        } elsif (/^--(.*)/) {
6740
            Message( "PackageHdr: unknown option $_ -- ignored\n" );
6741
        }
6742
    }
6743
 
6744
#.. Files
6745
#
285 dpurdie 6746
    foreach ( @elements )
227 dpurdie 6747
    {
6748
        my %package_entry;
6749
        if ( ! /^--(.*)/ )
6750
        {
5991 dpurdie 6751
            $name = $_;
227 dpurdie 6752
            $basename = StripDir( $name );
335 dpurdie 6753
            if ( !($srcfile = $SRCS{ $basename }) ) {
6754
                $srcfile = $name;
6755
            }
6756
 
227 dpurdie 6757
            if ( $full )
6758
            {
335 dpurdie 6759
                my $subdir = StripFileExt($srcfile);
6760
                $subdir = $1
6761
                    if ( $subdir =~ m~^$ProjectBase/(.*)~ );
6762
                $dir .= '/' . $subdir;
6763
                $dir =~ s~//~/~g;
6764
                $dir =~ s~/./~/~g;
6765
                $dir =~ s~/$~~g;
6766
                $name = $basename;
227 dpurdie 6767
            }
6768
 
6276 dpurdie 6769
            $name = StripPath($name, $strip) if ($strip);
227 dpurdie 6770
 
6771
            Debug( "PackageHdr( $dir/$name, " .
6772
                "src: $srcfile, dest: $dir, dist: $dist )" );
6773
 
6774
            $package_entry{'src'} = $srcfile;
6775
            $package_entry{'dir'} = StripFileExt( "$dir/$name" );
6776
            $package_entry{'set'} = $dist;
6777
 
6778
            $PACKAGE_HDRS{ "$dir/$name" } = {%package_entry};
6779
        }
6780
    }
6781
}
6782
 
6783
 
6784
sub PackageLib
6785
{
6786
    my( $platforms, @elements ) = @_;
6787
    my( $base, $dir, $dist, $type );
6788
    my( $lib, $org_lib, %extras, $strip );
6789
 
6790
    Debug2( "PackageLib($platforms, @elements)" );
6791
 
6792
    return if ( !$ScmPackage );                 # Packaging enabled ?
6793
    return if ( ! ActivePlatform($platforms) );
6794
 
6795
#.. Arguments
6796
#
6797
    $dist = "ALL";                              # Default set (ALL)
6798
    $base = $PackageInfo{'Lib'}{'PBase'};       # Base of target
6799
    $dir = $base . $PackageInfo{'Lib'}{'Dir'};  # Installation path (default)
6800
    $type = "";
6801
 
285 dpurdie 6802
    foreach ( @elements )
227 dpurdie 6803
    {
6804
                                                # Standard targets
6805
        my $rv = __TargetDir($T_PKG, $base, $_, \$dir, \$type);
6806
        next if ( $rv == 1 );
6807
        return if ( $rv == 2 );
6808
 
6809
        if (/^--Set=(.*)/) {                    # Distribution set(s)
6810
            $dist = "$1";
6811
 
6812
        } elsif (/^--Package$/) {               # Package .. call by PackageLib
6813
        } elsif (/^--Package=(.*)/) {
6814
            $dist = "$1";
6815
 
6816
        } elsif (/^--Extras=(.*)/) {            # Extras=[none, .. ,all]
6817
            foreach my $elem ( split( ',', $1 ) )
6818
            {
6819
                Error ("PackageLib: Unknown Extras mode: $elem")
6820
                    unless ( grep m/$elem/, qw(none stub map lint debug all) );
6821
                $extras{$elem} = 1;
6822
            }
6823
            %extras = () if ( $extras{'all'} );
6824
 
6825
        } elsif (/^--Strip$/) {                 # Strip path from source files
6276 dpurdie 6826
            $strip = -1;
227 dpurdie 6827
 
6276 dpurdie 6828
        } elsif (/^--Strip=(\d+)$/) {           # Strip some f the path from source files
6829
            $strip = $1;
6830
 
227 dpurdie 6831
        } elsif (/^--(.*)/) {
6832
            Message( "PackageLib: unknown option $_ -- ignored\n" );
6833
        }
6834
    }
6835
 
6836
#.. Files
6837
#
285 dpurdie 6838
    foreach ( @elements )
227 dpurdie 6839
    {
6840
        my %package_entry;
6841
        if ( ! /^--(.*)/ )
6842
        {
6276 dpurdie 6843
            $_ = StripPath($_, $strip) if ($strip);
227 dpurdie 6844
 
6845
            $org_lib = $_;                      # Original name
6846
            if ( $ScmTargetHost eq "Unix" ) {
6847
                $lib = "lib$_";                 # Prefix "lib" ....
6848
                $lib =~ s/^liblib/lib/;         # @LIBS already has lib added
6849
            } else {
6850
                $lib = $_;
6851
            }
6852
 
289 dpurdie 6853
            if (  my $libp = $SHLIBS->Get($lib) )
227 dpurdie 6854
            {
6855
                Debug( "PackageLib( $dir/$lib\$(GBE_TYPE).$::so, " .
6856
                    "src: \$(LIBDIR)/$lib\$(GBE_TYPE).$::so, dest: $dir, dist: $dist, type: $type )" );
6857
 
6858
                #
6859
                #   Create a "placekeeper" entry within $PACKAGE_SHLIBS
6860
                #   The exact format of the name of the shared library is
6861
                #   toolset specific. Create an entry to allow the toolset
6862
                #   to extend the packaging information when the shared library
6863
                #   recipe is constructed.
6864
                #
6865
                #
289 dpurdie 6866
                my $ver = $libp->{ VERSION };
227 dpurdie 6867
                my $name = "$dir/$lib.$ver.PlaceKeeper";
6868
 
6869
                $package_entry{'placekeeper'} = 1;
6870
                $package_entry{'version'} = $ver;
6871
                $package_entry{'lib'} = $lib;
6872
                $package_entry{'dir'} = $dir;
6873
                $package_entry{'set'} = $dist;
6874
                $package_entry{'type'} = $type if ( $type );
6875
                $package_entry{'extras'} = {%extras} if ( scalar %extras );
289 dpurdie 6876
 
6877
                push @{$SHLIB_PKG{$lib}}, $name;
227 dpurdie 6878
                $PACKAGE_SHLIBS{$name} = {%package_entry};
6879
            }
6880
 
289 dpurdie 6881
            #
6882
            #   Clean up the package_entry
6883
            #   Insert common items
6884
            #
6885
            %package_entry = ();
6886
            $package_entry{'lib'} = $lib;
6887
            $package_entry{'dir'} = $dir;
6888
            $package_entry{'set'} = $dist;
6889
            $package_entry{'extras'} = {%extras} if ( scalar %extras );
6890
            $package_entry{'type'} = $type if ( $type );
6891
 
227 dpurdie 6892
            if ( my $libfile = $SRCS{$org_lib} )
6893
            {
6894
                #
6895
                #   Allow the user to package a sourced file as a library
6896
                #   But must be the un-massaged name of the file.
6897
                #
5991 dpurdie 6898
                $package_entry{'dst'} = "$dir/$org_lib";
6899
                $package_entry{'src'} = $libfile;
289 dpurdie 6900
            }
6901
            elsif ( $LIBS->Get($lib) )
6902
            {
6903
                #
6904
                #   Package up a library known to the makefile
6905
                #
6906
                my $libp = $LIBS->Get($lib);
227 dpurdie 6907
 
289 dpurdie 6908
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
6909
                $package_entry{'src'}    = $libp->getPath();
227 dpurdie 6910
            }
289 dpurdie 6911
            elsif ( ! $SHLIBS->Get($lib) )
227 dpurdie 6912
            {
289 dpurdie 6913
                #
6914
                #   Not a known shared lib
6915
                #   Not a known static lib
6916
                #   Not a 'sourced' file
6917
                #   Assume the a static library has magically appeared
6918
                #   in the standard LIB directory. May have been placed there
6919
                #   by a 'rule'
6920
                #
6921
                my $libp = $LIBS->New($lib);
227 dpurdie 6922
 
289 dpurdie 6923
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
6924
                $package_entry{'src'}    = $libp->getPath();
6925
            }
227 dpurdie 6926
 
289 dpurdie 6927
            #
6928
            #   Add entry to various lists if required
6929
            #
6930
            PackageLib_AddEntry ('PackageLib', \%LIB_PKG, \%PACKAGE_LIBS, \%package_entry )
6931
                if ( exists $package_entry{'dst'} );
227 dpurdie 6932
        }
6933
    }
6934
}
6935
 
289 dpurdie 6936
#-------------------------------------------------------------------------------
6937
# Function        : PackageLib_AddEntry
6938
#
6939
# Description     : Helper function to add a package entry
6940
#                   to the lists
6941
#
6942
# Inputs          : $directive          - Directive name
6943
#                   $pList              - Ref to array list to maintain
6944
#                   $pHash              - Ref to hash to maintain
6945
#                   $pData              - Packaging Data
6946
#                                         Must Take a copy.
6947
#
6948
# Returns         : 
6949
#
227 dpurdie 6950
 
289 dpurdie 6951
sub PackageLib_AddEntry
6952
{
6953
    my ($directive, $pList, $pHash, $pData) = @_;
6954
 
6955
    my $lib = delete $pData->{'lib'};
6956
    my $dst = delete $pData->{'dst'};
6957
 
6958
    Error ("INTERNAL PackageLib_AddEntry: lib or dst not defined")
6959
        unless ( $lib && $dst );
6960
 
6961
    Debug( "$directive( ",$dst,
6962
            ", src: " ,$pData->{'src'},
6963
            ", dest: ",$pData->{'dir'},
6964
            ", dist: ",$pData->{'set'},
6965
            ", type: ",$pData->{'type'} || '',
6966
            " )" );
6967
 
6968
    push @{$pList->{$lib }}, $dst;
6969
    $pHash->{$dst } = {%$pData};
6970
}
6971
 
6972
 
227 dpurdie 6973
sub PackageProg
6974
{
6975
    my( $platforms, @elements ) = @_;
6976
    my( $base, $dir, $dist, $type );
6977
    my( $prog, %extras, $strip );
6978
 
6979
    Debug2( "PackageProg($platforms, @elements)" );
6980
 
6981
    return if ( !$ScmPackage );                 # Packaging enabled ?
6982
    return if ( ! ActivePlatform($platforms) );
6983
 
6984
#.. Arguments
6985
#
6986
    $dist = "ALL";                              # Default set (ALL)
6987
    $base = $PackageInfo{'Prog'}{'PBase'};       # Base of target
6988
    $dir = $base . $PackageInfo{'Prog'}{'Dir'};  # Installation path (default)
6989
    $type = "";
6990
 
285 dpurdie 6991
    foreach ( @elements )
227 dpurdie 6992
    {
6993
                                                # Standard targets
6994
        my $rv = __TargetDir($T_PKG|$T_TYPE, $base, $_, \$dir, \$type);
6995
        next if ( $rv == 1 );
6996
        return if ( $rv == 2 );
6997
 
6998
        if (/^--Set=(.*)/) {                    # Distribution set(s)
6999
            $dist = "$1";
7000
 
7001
        } elsif (/^--Package$/) {               # Package .. call by PackageLib
7002
        } elsif (/^--Package=(.*)/) {
7003
            $dist = "$1";
7004
 
7005
        } elsif (/^--Tool(([=])(.*))?$/) {      # Allow Tool and Tool=xxx specfic target
7006
            my $path = ( defined( $3) ) ? "/$3" : "";
261 dpurdie 7007
            $dir = "\$(PKGDIR)$path/\$(GBE_HOSTMACH)";
227 dpurdie 7008
 
7009
        } elsif (/^--Extras=(.*)/) {            # Extras=[none, .. ,all]
7010
            foreach my $elem ( split( ',', $1 ) )
7011
            {
7012
                Error ("PackageLib: Unknown Extras mode: $elem")
7013
                    unless ( grep m/$elem/, qw(none stub map lint debug all) );
7014
                $extras{$elem} = 1;
7015
            }
7016
            %extras = () if ( $extras{'all'} );
7017
 
7018
        } elsif (/^--Strip$/) {                 # Strip path from source files
6276 dpurdie 7019
            $strip = -1;
227 dpurdie 7020
 
6276 dpurdie 7021
        } elsif (/^--Strip=(\d+)$/) {           # Strip some f the path from source files
7022
            $strip = $1;
7023
 
227 dpurdie 7024
        } elsif (/^--(.*)/) {
7025
            Message( "PackageProg: unknown option $_ -- ignored\n" );
7026
        }
7027
    }
7028
 
7029
#.. Files
7030
#
285 dpurdie 7031
    foreach ( @elements )
227 dpurdie 7032
    {
7033
        my %package_entry;
7034
        if ( m~descpkg~ ) {
7035
            PackageFile($platforms, @elements);
7036
 
7037
        } elsif ( ! /^--(.*)/ ) {
6276 dpurdie 7038
            $_ = StripPath($_, $strip) if ($strip);
227 dpurdie 7039
 
7040
            my $ext = "";
7041
            $prog = $_;
7042
 
7043
            #
7044
            #   If the named target is a program then append the correct
7045
            #   extension. Otherwise assume that the target is either a script
7046
            #   or a some other file - and don't append an extension
7047
            #
7048
            #   A program may not have any object files, only libraries
7049
            #
7050
            $ext = $::exe
289 dpurdie 7051
                if ( $PROGS->Get($prog) );
227 dpurdie 7052
 
7053
            #
7054
            #   A "file" that is specified with a "Src" directive may be
7055
            #   installed as though it were a program
7056
            #
7057
            my $progfile;
387 dpurdie 7058
            if ( $progfile = $SRCS{$prog} )
7059
            {
5991 dpurdie 7060
                $progfile = $progfile;
7061
                $prog = $prog;
387 dpurdie 7062
            }
7063
            else
7064
            {
7065
                $progfile = "\$(BINDIR)/$prog$ext";
7066
            }
227 dpurdie 7067
 
7068
            Debug( "PackageProg( $dir/$prog$ext, " .
7069
                 "src: $progfile, dest: $dir, dist: $dist, type: $type )" );
7070
 
7071
            my $target = "$dir/$prog$ext";
7072
            push @{$PROG_PKG{$prog}}, $target;
7073
 
7074
            $package_entry{'src'}   = $progfile;
7075
            $package_entry{'dir'}   = $dir;
7076
            $package_entry{'set'}   = $dist;
7077
            $package_entry{'extras'}= {%extras} if ( scalar %extras );
7078
            $package_entry{'type'}  = $type if ( $type );
7079
 
7080
            $PACKAGE_PROGS{$target} = {%package_entry};
7081
        }
7082
    }
7083
}
7084
 
7085
 
7086
sub PackageJar
7087
{
7088
    my( $platforms, @elements ) = @_;
7089
    my( $base, $dir, $dist, $type );
7090
    my( $jar );
7091
 
7092
    Debug2( "PackageJar($platforms, @elements)" );
7093
 
7094
    return if ( !$ScmPackage );                 # Packaging enabled ?
7095
    return if ( ! ActivePlatform($platforms) );
7096
 
7097
#.. Arguments
7098
#
7099
    $dist = "ALL";                              # Default set (ALL)
7100
    $base = $PackageInfo{'Jar'}{'PBase'};       # Base of target
7101
    $dir = $base . $PackageInfo{'Jar'}{'Dir'};  # Installation path (default)
7102
    $type = "";
7103
 
285 dpurdie 7104
    foreach ( @elements )
227 dpurdie 7105
    {
7106
                                                # Standard targets
7107
        my $rv = __TargetDir($T_PKG, $base, $_, \$dir, \$type);
7108
        next if ( $rv == 1 );
7109
        return if ( $rv == 2 );
7110
 
7111
        if (/^--Set=(.*)/) {                    # Distribution set(s)
7112
            $dist = "$1";
7113
 
7114
        } elsif (/^--Package$/) {               # Package .. call by InstallJar
7115
        } elsif (/^--Package=(.*)/) {
7116
            $dist = "$1";
7117
 
7118
        } elsif (/^--(.*)/) {
7119
            Message( "PackageJar: unknown option $_ -- ignored\n" );
7120
        }
7121
    }
7122
 
7123
#.. Files
7124
#
285 dpurdie 7125
    foreach ( @elements )
227 dpurdie 7126
    {
7127
        my %package_entry;
7128
        if ( ! /^--(.*)/ )
7129
        {
7130
            $jar = $_;
7131
            my $src;
7132
            my $dest;
7133
 
7134
            if ( $JAR_FILES{$jar} )
7135
            {
7136
                $src = $JAR_FILES{$jar};
7137
                $dest = $jar;
7138
            }
7139
            else
7140
            {
7141
                $src = "\$(CLSDIR)/$jar\$(GBE_TYPE).jar";
7142
                $dest = "$jar\$(GBE_TYPE).jar";
7143
            }
7144
 
7145
 
7146
            Debug( "PackageJar( $dir/$dest, " .
7147
                "src: $src, dest: $dir, dist: $dist, type: $type )" );
7148
 
7149
            $package_entry{'src'} = $src;;
7150
            $package_entry{'dir'} = $dir;
7151
            $package_entry{'set'} = $dist;
7152
            $package_entry{'type'} = $type if ( $type );
7153
 
7154
            $PACKAGE_CLSS{ "$dir/$dest" } = {%package_entry};
7155
 
7156
        }
7157
    }
7158
}
7159
 
7160
#-------------------------------------------------------------------------------
7161
# Function        : PackageProgAddFiles         - Add files to a PackageProg
7162
#                   PackageLibAddFiles          - Add files to a PackageLib
7163
#                   PackageShlibAddFiles        - Add files to a PackageLib (shared lib)
7164
#                   PackageShlibAddLibFiles     - Add files to a PackageLib (shared lib)
7165
#                                                 Add static library files
7166
#
7167
# Description     : Add files to a Program package or installation
7168
#                   For use by Tool sets to allow additional files to be
7169
#                   packaged with a program.
7170
#
7171
#                   The files are only added if the named program is being
7172
#                   packaged and/or installed.
7173
#
7174
#
7175
# Inputs          : prog        - program identifier
7176
#                   file        - A file to be add
7177
#                   args        - Additional packageing arguments
7178
#
7179
# Returns         : Nothing
7180
#
7181
 
7182
sub PackageProgAddFiles
7183
{
7184
    Debug("PackageProgAddFiles");
7185
 
7186
    PackageAddFiles ( \%PACKAGE_PROGS, \%PACKAGE_PROGS, \%PROG_PKG, @_);
7187
    PackageAddFiles ( \%INSTALL_PROGS, \%INSTALL_PROGS, \%PROG_INS, @_);
7188
}
7189
 
7190
sub PackageLibAddFiles
7191
{
7192
    Debug("PackageLibAddFiles");
7193
 
7194
    PackageAddFiles ( \%PACKAGE_LIBS, \%PACKAGE_LIBS, \%LIB_PKG, @_ );
7195
    PackageAddFiles ( \%INSTALL_LIBS, \%INSTALL_LIBS, \%LIB_INS, @_ );
7196
}
7197
 
7198
sub PackageShlibAddFiles
7199
{
7200
    my ($prog, $file, @args) = @_;
7201
    Debug("PackageShlibAddFiles");
7202
 
7203
    PackageAddFiles ( \%INSTALL_SHLIBS, \%INSTALL_SHLIBS, \%SHLIB_INS, @_ );
7204
    PackageAddFiles ( \%PACKAGE_SHLIBS, \%PACKAGE_SHLIBS, \%SHLIB_PKG, @_ );
7205
 
7206
    #
7207
    #   These files become the target of the "make_install_shlib" operation unless:
7208
    #       Conditionally packaged files are not always created
7209
    #       RemoveOnly files are not always generated
7210
    #
7211
    my $no_add;
7212
    foreach ( @args )
7213
    {
4382 dpurdie 7214
        if ( m/^defined=/ or m/^RemoveOnly=/ or /NoTarget=/ )
227 dpurdie 7215
        {
7216
            $no_add = 1;
7217
            last;
7218
        }
7219
    }
7220
 
7221
    push (@SHLIB_TARGETS, $file ) unless $no_add;
7222
}
7223
 
7224
sub PackageShlibAddLibFiles
7225
{
7226
    Debug("PackageShlibAddLibFiles");
7227
 
7228
    PackageAddFiles ( \%PACKAGE_SHLIBS, \%PACKAGE_LIBS, \%SHLIB_PKG, @_ , 'Class=lib');
7229
    PackageAddFiles ( \%INSTALL_SHLIBS, \%INSTALL_LIBS, \%SHLIB_INS, @_ , 'Class=lib');
7230
}
7231
 
7232
#-------------------------------------------------------------------------------
7233
# Function        : PackageAddFiles
7234
#
7235
# Description     : Internal function to add files to the data structures that
7236
#                   describe a package or installation
7237
#
7238
#                   Use this function to package or install additional files with
7239
#                   the Progs and Libs
7240
#
7241
#                   ie: Add a LIB file to be packaged with a Shared Library
7242
#                   ie: Add a MAP file to be packaged with a program
7243
#
7244
# Inputs          : ref_spkg  - Reference to the hash that contains the package data
7245
#                   ref_dpkg  - Reference to the target package/install hash
7246
#                               Normally the same as ref_dpkg, but does allow
289 dpurdie 7247
#                               a static library to be added to a dynamic library
227 dpurdie 7248
#                               package.
7249
#                   ref_list  - Reference to a hash that may contain package keys to process
7250
#                   prog      - Key for index to above
7251
#                   file      - A file to be added
7252
#                   args      - Additional packaging arguments
7253
#
7254
# Returns         :
7255
#
7256
sub PackageAddFiles
7257
{
7258
    my ($ref_spkg, $ref_dpkg, $ref_list, $prog, $file, @args ) = @_;
7259
 
7260
    #
7261
    #   Process entry
7262
    #   The files may need to be added to multiple packages
7263
    #
7264
    Debug("PackageAddFiles: $file");
7265
 
7266
    return unless ( $ref_list->{$prog} );
7267
 
7268
    #
7269
    #   Parse arguments and extract the "Class=xxx" argument. This may be used
7270
    #   to limit the extra files piggybacked with the base file
7271
    #   All files without a class will be treated as base files
7272
    #
7273
    my $class;
7274
    foreach ( @args )
7275
    {
7276
        next unless ( m~^Class=(.*)$~ );
7277
        $class = $1 unless ( $1 eq 'none' );
7278
    }
7279
    Debug("PackageAddFiles: Class: ", $class || 'Default=None');
7280
 
7281
    foreach my $entry_key ( @{$ref_list->{$prog}} )
7282
    {
7283
        Debug("PackageAddFiles: Entry found: $entry_key");
7284
 
7285
        #
7286
        #   Copy of the template entry
7287
        #
7288
        my %package_entry = %{$ref_spkg->{$entry_key}};
7289
        Error ("INTERNAL: Expected entry in PACKAGE_ hash not found: $entry_key" )
7290
            unless ( %package_entry );
7291
 
7292
        #
7293
        #   Do not add the file if the user has limited the extra files added
7294
        #   to the packaging list and the current file is not in the class list
7295
        #
7296
        if ( $class && $package_entry{'extras'} )
7297
        {
7298
            next unless ( $package_entry{'extras'}{$class} );
7299
        }
7300
 
7301
        #
7302
        #   Create new entries for the file
7303
        #
7304
        $package_entry{'src'} = $file;
7305
        foreach ( @args )
7306
        {
7307
            m~^(.*)=(.*)$~;
7308
            $package_entry{$1} = $2;
7309
        }
7310
 
7311
        #
7312
        #   Clean out useless fields
7313
        #   Must remove the placekeeper marker to allow the entry to be visible
7314
        #
7315
        delete $package_entry{'placekeeper'};
7316
        delete $package_entry{'version'};
7317
        delete $package_entry{'lib'};
261 dpurdie 7318
#       delete $package_entry{'extras'};                   # Keep these
227 dpurdie 7319
        delete $package_entry{'Class'};
7320
 
7321
        #
7322
        #   Add the entry
7323
        #
7324
        #   Under some conditions is it possible to attempt to add the same named
7325
        #   file. This will result in a circular dependancy in the makefile
7326
        #
7327
        #   The condition is when merged libaries with PDBs (WINCE+WIN32) are merged
261 dpurdie 7328
        #   and the source for the merge is the "local directory.
227 dpurdie 7329
        #
7330
        #
7331
        my $dst = $package_entry{'dir'} ;
7332
        ( my $dfile = $file) =~ s~.*/~~;
7333
        Debug( "    added $dst/$dfile = $file" );
7334
 
7335
        $ref_dpkg->{"$dst/$dfile"} = {%package_entry}
7336
            unless ( "$dst/$dfile" eq "$file" );
7337
    }
7338
}
7339
 
7340
#-------------------------------------------------------------------------------
7341
# Function        : PackageProgRemoveFiles
7342
#
7343
# Description     : Flag a Packaged program to be not packaged
7344
#                   This mechanism is used to remove a program from packageing
7345
#                   under conditions where the toolset has generated a different
7346
#                   program.
7347
#
7348
#                   The entry is flagged as a placeholder
7349
#
7350
# Inputs          : prog        - Program to process
7351
#
7352
# Returns         : Nothing
7353
#
7354
sub PackageProgRemoveFiles
7355
{
7356
    my ($prog) = @_;
7357
    Verbose ("PackageProgRemoveFiles: $prog" );
7358
    return unless (exists($PROG_PKG{$prog}));
7359
 
7360
    #
7361
    #   Must lookup the TAG to locate the  required entry
7362
    #
7363
    my $tag = $PROG_PKG{$prog};
7364
    foreach my $entry ( @$tag )
7365
    {
7366
        Verbose("Do not package: $entry");
7367
        if ( exists $PACKAGE_PROGS{$entry} )
7368
        {
7369
            $PACKAGE_PROGS{$entry}{placekeeper} = 'ProgRemoved';
7370
        }
7371
    }
7372
}
7373
 
7374
#-------------------------------------------------------------------------------
7375
# Function        : DPackageLibrary
7376
#
7377
# Description     : Collect information to allow the generation of a DPACKAGE
299 dpurdie 7378
#                   file. This directive allows the generation of "Library"
227 dpurdie 7379
#                   directives within the final DPACKAGE
7380
#
7381
#                   This directive does generate the DPACKAGE file.
7382
#
7383
# Inputs          : platform    - This does not need to be an active platform
7384
#                                 it is simply passed to the DPACKAGE builder
7385
#
7386
#                   using       - The "using" target
7387
#
7388
#                   ...         - Arguments for the Library directive
7389
#
7390
# Returns         :
7391
#
7392
sub DPackageLibrary
7393
{
7394
    JatsDPackage::DPackageAdd ( @_ );
299 dpurdie 7395
    $DPackageDirective = 1;
227 dpurdie 7396
}
7397
 
7398
#-------------------------------------------------------------------------------
7399
# Function        : SetProjectBase
7400
#
7401
# Description     : Allows the user to modify the build's concept of the Base
7402
#                   of the build. By default the base is the same directory as
7403
#                   the build.pl file, but in some contorted environments it
7404
#                   is a great deal simpler to specify a differnt base.
7405
#
7406
#                   The use may use the variable $ProjectBase as a path
7407
#                   specifier to locate files and directories
7408
#
7409
#                   Both absolute and relative paths are supported
7410
#                   If the initial value of $ProjectBase is relative then
7411
#                   it will be maintained as a relative path.
7412
#
7413
# Inputs          : elements        path to base
7414
#                                   These may be:
7415
#                                       --Up=xx
7416
#                                       name
7417
#
7418
# Returns         : Nothing
7419
#
7420
 
7421
#
7422
#   Allow the user to modify the project base variable
7423
#
7424
sub SetProjectBase
7425
{
7426
    my $rip = 0;
7427
    my $path = "";
7428
    my $is_relative;
7429
 
7430
    Debug("ProjectBase Initial: $ProjectBase, @_");
7431
 
7432
    #
7433
    #   Ensure that the ProjectBase is in a "nice" form
7434
    #   1) No /./ bits
7435
    #   2) No trailing /
7436
    #   3) Not equal to .
7437
    #   4) No training /.
7438
    #   5) No //
7439
    #
7440
    $ProjectBase =~ s~/\./~/~g;
7441
    $ProjectBase =~ s~/$~~g;
7442
    $ProjectBase =~ s~^\.$~~g;
7443
    $ProjectBase =~ s~/\.$~~g;
7444
    $ProjectBase =~ s~//$~/~g;
7445
 
7446
    #
7447
    #   ProjectBase may be absolute or relative
7448
    #   Determine this before we mess with it
7449
    #
7450
    $is_relative = ($ProjectBase !~ m~^/~);
7451
 
7452
    #
7453
    #   Process each argument
7454
    #
7455
    foreach ( @_ )
7456
    {
7457
        if ( /^--Up=([0-9]*)/ ) {
7458
            $rip = $1;
7459
        } elsif ( /^--/ ) {
7460
            Warning( "SetProjectBase - unknown option \"$_\" - ignored" );
7461
        } else {
7462
            $path = $_;
7463
        }
7464
    }
7465
 
7466
    #
7467
    #   Process the UP requests
7468
    #   If the tail directory is a ".." then up is done by adding another ".."
7469
    #   If the tail directory is not a "..", then up is done by removing it
7470
    #
7471
    #   If we go past the start of the path then simply add ".."
7472
    #
7473
    while ( $rip-- > 0 )
7474
    {
7475
        Debug2("ProjectBase: $ProjectBase, Up: $rip, IsRel: $is_relative");
7476
 
7477
        #
7478
        #   If ending in a /.. or is exactly equal to ..
7479
        #   Then its a dot-dot and the way to go UP is to append another ..
7480
        #
7481
        if ( $ProjectBase =~ m~(/\.\.$)|(^\.\.$)~ )
7482
        {
7483
            $ProjectBase .= '/..';
7484
        }
7485
        else
7486
        {
7487
            #
7488
            #   Not a dot-dot ending
7489
            #   Attempt to remove the last directory of the form
7490
            #       /xxxxx
7491
            #   Where the leading / is optional
7492
            #   Note: Must have at least one character in the dirname
7493
            #         This prevents leading / from matching - which is needed
7494
            #
7495
            unless ($ProjectBase =~ s~/?[^/]+$~~)
7496
            {
7497
                #
7498
                #   Removal failed
7499
                #   If a relative path then we can keep on going up,
7500
                #   otherwise we are dead.
7501
                #
7502
                Error ("ProjectBase outside project") unless ($is_relative);
7503
                $ProjectBase = '..';
7504
            }
7505
 
7506
            #
7507
            #   Ensure that the leading / in an absolute path is not deleted
7508
            #
7509
            $ProjectBase = '/'
7510
                unless ( $is_relative || $ProjectBase );
7511
        }
7512
    }
7513
 
7514
    #
7515
    #   Append the user path
7516
    #
7517
    $ProjectBase .= '/' . $path if ( $path );
7518
    $ProjectBase = '.' unless ( $ProjectBase );
7519
    Debug("ProjectBase set to : $ProjectBase");
7520
 
7521
    #
7522
    #   Once upon a time I tried to convert paths that contained spaces into
7523
    #   short (mangled) names. This was not sucessful because:
7524
    #       1) Clearcase dynamic views do not support name mangling
7525
    #       2) Samba file system does not appear to support name mangling
7526
    #
7527
    #   Spaces in paths are not good for MAKE
7528
    #   Now I simple generate a message
7529
    #
7530
    Warning( "ProjectBase contains a space: $ProjectBase")
7531
        if ( $ProjectBase =~ m/ / );
7532
 
7533
    #
7534
    #   Sanity check
7535
    #   Absolute paths can be checked easily
7536
    #   Checking of relative paths does not appear to work
7537
    #   When I tested it chdir, opendir and stat would limit themselves
7538
    #   and drop into the root directory ( under windows )
7539
    #
7540
    #   Solution: Check the path does not extend beyond the file tree
7541
    #
7542
    my $distance = 1;
7543
    my $tpath = $ProjectBase;
7544
 
7545
    if ( $is_relative && $tpath ne '.' )
7546
    {
7547
        #
7548
        #   Build up the complete pathname by merging it with the
7549
        #   current directory. Then clean it up.
7550
        #
7551
        $tpath = $::Cwd . '/' . $ProjectBase;
7552
 
7553
        #
7554
        #   Scan the list of diretories and count the distance from the root
7555
        #   This should not be greater than zero for sanity
7556
        #   Note: Get an empty elemement from the split due to
7557
        #         the leading / of the ABS path
7558
        #
7559
        $distance = 0;
7560
        foreach (  split ('/', $tpath) )
7561
        {
7562
            if ( m~\.\.~ )
7563
            {
7564
                $distance--;
7565
            }
7566
            else
7567
            {
7568
                $distance++;
7569
            }
7570
        }
7571
    }
7572
 
7573
    #
7574
    #   Warn if not a valid directory
7575
    #
7576
    Warning( "ProjectBase is not a directory: $ProjectBase")
7577
        if ( $distance <= 0 || !  -d $tpath  );
7578
 
7579
    #
7580
    #   $ProjectBase will always be a valid directory, but if its the top
7581
    #   directory (/) and it is added to a path we will get //path
7582
    #   This is not good, so // will be removed later in the AddIncDir and
7583
    #   AddSrcDir commands where $ProjectBase is really used.
7584
    #
7585
    #   Alternatively we could set $ProjectBase to an empty string, but then
7586
    #   this may be confused with an empty relative directory
7587
    #
7588
    Debug("ProjectBase Final  : $ProjectBase");
7589
}
7590
 
7591
#-------------------------------------------------------------------------------
7592
# Function        : DeployPackage
7593
#
7594
# Description     : Generate a deployed package
7595
#                   This is a gateway to a different packaging system
7596
#
7597
#                  DeployPackage and PackageXxxxx directives are mutually
7598
#                  exclusive. Only one person can play in the package area.
7599
#
7600
# Inputs          : Platform Specifier
7601
#                   Package Name    (Optional)
7602
#                   Options
7603
#                       --Name : Base name of the package. The default is taken
7604
#                                from the build.pl file
7605
#                       --Dir  : Package directory
7606
#                                The default is based on the package name
7607
#
7608
# Returns         :
7609
#
7610
sub DeployPackage
7611
{
7612
    my( $platforms, @elements ) = @_;
7613
    my $dir;
7614
    my $name;
7615
 
267 dpurdie 7616
    #
7617
    #   Flag that this build creates a deployable package, even if its not
7618
    #   active on this platform.
7619
    #
7620
    $DEPLOYPACKAGE = 1;
7621
 
7622
 
227 dpurdie 7623
    Debug2( "DeployPackage($platforms, @elements)" );
7624
    return if ( ! ActivePlatform($platforms) );
7625
 
7626
    #
7627
    #   Only allow one use of this directive
7628
    #
7629
    Error("DeployPackage can only be used once" ) if ( %DEPLOYPACKAGE );
267 dpurdie 7630
    $DEPLOYPACKAGE = 2;
227 dpurdie 7631
 
7632
    #
7633
    #   Ensure that the deployment file is available
7634
    #
7635
    my $command_file = $ScmDeploymentPatch ? "deploypatch.pl" : "deployfile.pl";
7636
    Error("DeployPackage: $command_file not found") unless (-f "./$command_file");
7637
    #
7638
    #   Collect arguments
7639
    #
7640
    foreach (@elements )
7641
    {
7642
        if ( m/^--Dir=(.*)/ ) {
7643
            Error ("DeployPackage: Package directory defined multiple times") if $dir;
7644
            $dir = $1;
7645
 
7646
        } elsif ( m/^--Name=(.*)/ ) {
7647
            Error ("DeployPackage: Package name defined multiple times") if $name;
7648
            $name = $1;
7649
 
7650
        } elsif ( m/^--/ ) {
7651
            Warning( "DeployPackage: Unknown option ignored: $_");
7652
 
7653
        } else {
7654
            Error ("DeployPackage: Package name defined multiple times") if $name;
7655
            $name = $_;
7656
 
7657
        }
7658
    }
7659
 
7660
    $name = $::ScmBuildPackage unless ( $name );
7661
 
7662
    #
7663
    #   Save the deployment data
7664
    #
7665
    $dir = lc($name) unless ( $dir );
7666
    $DEPLOYPACKAGE{'name'} = $name;
7667
    $DEPLOYPACKAGE{'dir'} = $dir;
7668
    $DEPLOYPACKAGE{'cmdfile'} = $command_file;
7669
 
7670
    #
7671
    #   Flag that toolset tests should be supressed
7672
    #   The Deploy world does not really use the full makefiles and if the
7673
    #   compilers are not installed will not be able to create deployment
7674
    #   packages
7675
    #
7676
    $ScmNoToolsTest = 1;
7677
}
7678
 
7679
 
7680
###############################################################################
7681
###############################################################################
7682
# Private function section.
7683
#       The following functions are used INTERNALLY by makelib.pl2.
7684
###############################################################################
7685
 
7686
###############################################################################
7687
#   A collection of functions to write to the MAKEFILE handle
7688
#
7689
#   MakeHeader          - Write a nice section header
7690
#   MakeNewLine         - Print a new line
7691
#   MakePrint           - Print a line ( without trailing \n)
7692
#   MakeQuote           - Escape \ and " character, then print a line
7693
#   MakePrintList       - Print an array
7694
#   MakeEntry           - Complex line printer
7695
#   MakePadded          - Padded line printer (internal)
7696
#   PadToPosn           - Calc space+tabs to tabstop (internal)
7697
#   MakeEntry3          - Complex Line Printer
7698
#   MakeDefEntry        - Print a definition line (Production + Debug support)
7699
#   MakeIfDefEntry      - Print ifdef entry
261 dpurdie 7700
#   MakeIfnDefEntry     - Print ifndef entry
7701
#   MakeIfZeroEntry     - Print ifeq entry
227 dpurdie 7702
#
7703
###############################################################################
7704
 
7705
sub MakeHeader
7706
{
7707
    my ($text, @rest) = @_;
7708
    my $length = length ($text);
7709
 
7710
    print MAKEFILE "\n";
7711
    print MAKEFILE "#--------- $text ", '-' x (80 - 12 - $length)  ,"\n";
7712
    print MAKEFILE "#    $_\n" foreach  ( @rest ) ;
7713
    print MAKEFILE "#\n";
7714
}
7715
 
7716
sub MakeNewLine         # Print a newline to the current 'Makefile'
7717
{
7718
    print MAKEFILE "\n";
7719
}
7720
 
7721
sub MakePrint           # Print to the current 'Makefile'
7722
{
7723
    print MAKEFILE @_
7724
        if ( defined $_[0] );
7725
}
7726
 
7727
sub MakeQuote           # Quote a makefile text line
7728
{
7729
    my( $line ) = @_;
7730
    $line =~ s/\\/\\\\/g;                       # quote all '\' characters
7731
    $line =~ s/"/\\"/g;                         # Then quote '"' characters
255 dpurdie 7732
    $line =~ s/=#/=\\#/g;                       # Then quote '=#' sequence
227 dpurdie 7733
    print MAKEFILE $line;
7734
}
7735
 
7736
sub MakePrintList
7737
{
7738
    print MAKEFILE $_ . "\n" foreach (@{$_[0]});
7739
}
7740
 
2429 dpurdie 7741
sub QuoteArray
7742
{
7743
    my $quote = "'";
7744
    if ( @_ ) {
7745
        return ($quote . join("$quote $quote", @_) . $quote);
7746
    }
7747
    return '';
7748
}
227 dpurdie 7749
 
7750
#-------------------------------------------------------------------------------
7751
# Function        : MakeEntry
7752
#
7753
# Description     : Build a entry based on the element list
7754
#                   Creates text of the form
7755
#                       $(BINDIR)/prog.exe: object1.obj \
7756
#                                           object2.obj
7757
#
7758
#
7759
# Inputs          : $prelim         - Preamble (one-off)
7760
#                   $postlim        - Postamble (one-off)
7761
#                   $prefix         - Pefix (to each element of array)
7762
#                   $postfix        - Postfix (to each element of array )
7763
#                   @elements       - Array of element to wrap
7764
#
7765
# Returns         :   1 Always
7766
#
7767
# Notes:
7768
#       The above description means that the following entry format is
7769
#       produced:
7770
#
7771
#           <preliminary><prefix><variant1><prefix><variant2>...<final>
7772
#
7773
#       With judicious use of newline and tab characters, a target
7774
#       and dependency list along with the command(s) to build the
7775
#       target can be constructed.
7776
#
7777
sub MakeEntry
7778
{
7779
    my( $prelim, $postlim, $prefix, $postfix, @elements ) = @_;
7780
 
7781
    MakePrint $prelim;
7782
    MakePrint "${prefix}${_}${postfix}" foreach ( @elements );
7783
    MakePrint $postlim if ($postlim);
7784
    return 1;
7785
}
7786
 
7787
#-------------------------------------------------------------------------------
7788
# Function        : MakePadded
7789
#
7790
# Description     : Generate aligned output of the form
7791
#                       Prefix_text           Aligned_text
7792
#                   where the aligned text is at a specified TAB boundary
7793
#
7794
# Inputs          : $align      - Tab stop (One tab = 8 chars)
7795
#                   $prefix     - Text to print before alignment occurs
7796
#                   @line       - Remainder of the line
7797
#
7798
sub MakePadded          # Print to the current 'Makefile', tab aligning
7799
{
7800
    my( $align, $prefix, @line ) = @_;
7801
 
7802
    my $strlen = length( $prefix );
7803
    my $pad = PadToPosn( $strlen, $align * 8 );
7804
 
7805
    print MAKEFILE $prefix . $pad;
7806
    print MAKEFILE @line;
7807
}
7808
 
7809
#-------------------------------------------------------------------------------
7810
# Function        : PadToPosn
7811
#
7812
# Description     : Given that we are at $startposn return a tab and space
7813
#                   string to place us at $endposn
7814
#
7815
sub PadToPosn
7816
{
7817
    my ($startposn, $endposn ) = @_;
7818
 
7819
 
7820
    #
7821
    #   Case where we are already too far into the line
7822
    #
7823
    return ( ' ' )if ( $endposn <= $startposn );
7824
 
7825
    my $tcount = 0;
7826
    my $scount = 0;
7827
 
7828
    while ( $startposn < $endposn )
7829
    {
7830
        $tcount ++;
7831
        $startposn = ($startposn >> 3) * 8 + 8;
7832
 
7833
        my $delta = $endposn - $startposn;
7834
        if ( $delta < 8 )
7835
        {
7836
            $scount = $delta;
7837
            last;
7838
        }
7839
 
7840
    }
7841
    return ( "\t" x $tcount .  ' ' x $scount );
7842
}
7843
 
7844
#-------------------------------------------------------------------------------
7845
# Function        : MakeEntry3
7846
#
7847
# Description     : Build a makefile entry based on the element list, tab aligned
7848
#                   Can creat text of the form:
7849
#                       TAG = NAME0 \       TAG : NAME0 \ 
7850
#                             NAME1               NAME1
7851
#
7852
#
7853
# Inputs          : $prelim             - Preliminary text
7854
#                   $presep             - Preliminary seperator
7855
#                   $elem_ref           - Either a single name or a reference to
7856
#                                         and array of names, or a hash.
7857
#
7858
# Returns         : Writes directly to the Makefile
7859
#
7860
sub MakeEntry3
7861
{
7862
    my( $prelim, $presep, $elem_ref ) = @_;
7863
 
7864
    #
7865
    #   The prelim may have some "\n" characters at the start
7866
    #   These simplify formatting, but mess up the nice formatting
7867
    #
7868
    if ($prelim =~ m~(^\n+)(.*)~ )
7869
    {
7870
        MakePrint $1;
7871
        $prelim = $2;
7872
    }
7873
 
7874
    #
7875
    #   Print the definition and the sep with nice padding
7876
    #
7877
    MakePadded ( 3, $prelim, $presep );
7878
    my $leadin = ' ';
7879
 
7880
    #
7881
    #   If a HASH reference then use a sorted list of keys from the hash.
7882
    #
7883
    if ( ref ($elem_ref) eq "HASH" )
7884
    {
7885
        my @hash_list;
7886
        @hash_list = sort keys ( %{$elem_ref} );
7887
        $elem_ref = \@hash_list;
7888
    }
7889
 
7890
    #
7891
    #   If the list is only one element long, then create a simple form
7892
    #   If the list is not an array ref, then treat it as a single element
7893
    #
7894
    if ( ref ($elem_ref) eq "ARRAY" )
7895
    {
7896
        my $line = 0;
7897
        foreach my $element ( @$elem_ref )
7898
        {
7899
            print MAKEFILE $leadin . $element;
7900
            $leadin = " \\\n" . PadToPosn(0,24 + length( $presep ) + 1 ) unless ($line++);
7901
        }
7902
    }
7903
    elsif ( defined $elem_ref )
7904
    {
7905
            print MAKEFILE $leadin . $elem_ref;
7906
    }
7907
    MakeNewLine();
7908
    return 1;
7909
}
7910
 
7911
#-------------------------------------------------------------------------------
7912
# Function        : MakeDefEntry
7913
#
7914
# Description     : Make a definition entry of the form
7915
#
7916
#                       TAG = NAME0 \
7917
#                             NAME1
7918
#
7919
#                   Support a list of definitions that will always be created
7920
#                   as well as a production and a debug list.
7921
#
7922
#                   Will always generate the "TAG = " string, even if the list
7923
#                   is empty.
7924
#
7925
#                   Will supress the TAG if there is no data if the FIRST opr starts with a '+'
7926
#
7927
# Inputs          : TAG         - Text tag to create
7928
#                   FIRST       - First assignement opr. = or +=
7929
#                   ALL_LIST    - A reference to a list of names to assign
7930
#                                 or a single name.
7931
#                   PROD_LIST   - Optional list to extend the definition with for a production build
7932
#                   DEBUG_LIST  - Optional list to extend the definition with for a debug build
7933
#
7934
# Returns         : Nothing
7935
#
7936
 
7937
sub MakeDefEntry
7938
{
7939
    my( $tag, $assign, $all, $prod, $debug ) = @_;
7940
 
7941
    #
7942
    #   Do not generate anything if the $opr is "+=" and there is no data
7943
    #   to output. ie: Supress empty TAG += statements
7944
    #
7945
    return if ( $assign =~ m/\+/ && ( ref($all) && ! defined $all->[0] ) );
7946
 
7947
    #
7948
    #   TAG for all entries
7949
    #
7950
    MakeEntry3( $tag, $assign, $all );
7951
 
7952
 
7953
    #
7954
    #   TAGs for PROD build
7955
    #   TAGs for DEBUG build
7956
    #
7957
    if ( defined $prod && defined $prod->[0] )
7958
    {
7959
        print MAKEFILE 'ifeq "$(DEBUG)" "0"' . "\n";
7960
        MakeEntry3( $tag, "+=", $prod );
267 dpurdie 7961
        print MAKEFILE 'endif' . "\n";
227 dpurdie 7962
    }
7963
 
7964
    if ( defined $debug && defined $debug->[0] )
7965
    {
7966
        print MAKEFILE 'ifeq "$(DEBUG)" "1"' . "\n";
7967
        MakeEntry3( $tag, "+=", $debug );
267 dpurdie 7968
        print MAKEFILE 'endif' . "\n";
227 dpurdie 7969
    }
7970
 
7971
}
7972
 
7973
sub MakeIfDefEntry
7974
{
7975
    my( $iftag, @rest ) = @_;
7976
 
7977
    print MAKEFILE "ifdef $iftag\n";
7978
    MakeDefEntry (@rest);
7979
    print MAKEFILE "endif\n\n";
7980
}
7981
 
7982
sub MakeIfnDefEntry
7983
{
7984
    my( $iftag, @rest ) = @_;
7985
 
7986
    print MAKEFILE "ifndef $iftag\n";
7987
    MakeDefEntry (@rest);
7988
    print MAKEFILE "endif\n\n";
7989
}
7990
 
261 dpurdie 7991
sub MakeIfZeroEntry
7992
{
7993
    my( $iftag, @rest ) = @_;
7994
 
7995
    print MAKEFILE "ifeq (\$($iftag),0)\n";
7996
    MakeDefEntry (@rest);
7997
    print MAKEFILE "endif\n\n";
7998
}
7999
 
227 dpurdie 8000
#-------------------------------------------------------------------------------
8001
# Function        : CreateNameList
8002
#
8003
# Description     : Create a list of names by adding a prefix and suffix to a
8004
#                   list of items. This is used to add a directory prefix and a
8005
#                   file suffix to a list of files.
8006
#
8007
# Inputs          : $prefix             ie: '$(OBJDIR)/'
8008
#                   $suffix             ie: '.obj'
8009
#                   $elem_ref           ie: A list of files ( passed be ref )
8010
#                                           If a Hash then its sorted keys is used
8011
#
8012
# Returns         : A ref to the resulting list
8013
#
8014
sub CreateNameList
8015
{
8016
    my( $prefix, $suffix, $elem_ref ) = @_;
8017
    my @result;
8018
 
8019
    if ( ref ($elem_ref) eq "HASH" )
8020
    {
8021
        my @hash_list;
8022
        @hash_list = sort keys ( %{$elem_ref} );
8023
        $elem_ref = \@hash_list;
8024
    }
8025
 
8026
    foreach  ( @$elem_ref )
8027
    {
8028
        push @result, $prefix . $_ . $suffix;
8029
    }
8030
    return \@result;
8031
}
8032
 
8033
#-------------------------------------------------------------------------------
8034
# Function        : ListGeneratedProjects
8035
#
8036
# Description     : Return a list of generated/nongenerated projects
8037
#                   Used in conjunction with CreateNameList
8038
#
8039
# Inputs          : $type       - TRUE : Generated
8040
#                                 FALSE: Not Generated
8041
#
8042
# Returns         : A reference to a list of projects
8043
#                   undef will be retuend if there are no projects
8044
#
8045
sub ListGeneratedProjects
8046
{
8047
    my ($type) = @_;
8048
    my @list;
8049
    foreach my $project ( @PROJECTS_ORDER )
8050
    {
8051
        if ( exists($PROJECTS{$project}->{'generated'}) xor $type )
8052
        {
8053
            push @list, $project;
8054
        }
8055
    }
8056
    return @list ? \@list : undef;
8057
}
8058
 
8059
#-------------------------------------------------------------------------------
8060
# Function        : ListCleanGenerated
8061
#
8062
# Description     : return a list of generated targets that have 'clean'
8063
#                   operations. This is used in conjunction with CreateNameList
8064
#
8065
# Inputs          : None
8066
#
8067
# Returns         : A list of project indexes, that can be cleaned
8068
#
8069
sub ListCleanGenerated
8070
{
8071
    my @list;
8072
    foreach my $i ( @GENERATE_FILES )
8073
    {
8074
        push @list, $i->{'index'}
8075
            if ( $i->{'clean'} );
8076
    }
8077
    return \@list;
8078
}
8079
 
251 dpurdie 8080
#-------------------------------------------------------------------------------
8081
# Function        : MakeResolve
8082
#
8083
# Description     : Internal Function
8084
#                   Locate a source file by examining a list of directories
8085
#
8086
#                   Don't use directly
8087
#                   Use MakeSrcResolve or MakeSrcResolveExtended
8088
#
8089
# Inputs          : $dirs           - Ref to an array of directories to scan
8090
#                   $source         - File to locate
8091
#
8092
# Returns         : Resolved path to the file
8093
#                   Will warn if multiple instances of the file are found
8094
#
227 dpurdie 8095
sub MakeResolve
8096
{
8097
    my( $dirs, $source ) = @_;
285 dpurdie 8098
    my( $first, $count );
227 dpurdie 8099
 
237 dpurdie 8100
    #
8101
    #   If the path contains a '$' then its assumed to be
8102
    #   a variable name in the path. Just assume that it exists
8103
    #
8104
    return $source if ( $source =~ m#\$# );
8105
 
8106
    #
8107
    #   If the path is absolute or contains a leading ., then don't search
8108
    #   Warn if it can't be found
8109
    #
8110
    if ( $source =~ m#^(/|\.)# )
8111
    {
8112
        Warning( "Unable to resolve '$source' path" ) unless -f $source;
8113
        return $source;
227 dpurdie 8114
    }
8115
 
6276 dpurdie 8116
    my @found;
8117
    # Search the local path first
8118
    push (@found, $source ) if -f ($source);
237 dpurdie 8119
 
285 dpurdie 8120
    foreach my $dir (@$dirs)
227 dpurdie 8121
    {
331 dpurdie 8122
        next if ( $dir eq '.' );
6276 dpurdie 8123
        my $temp = $dir . '/' . $source;
227 dpurdie 8124
        Debug2( "MakeResolve: Looking in: $temp" );
6276 dpurdie 8125
        push (@found, $temp) if (-f $temp);
227 dpurdie 8126
    }
8127
 
6276 dpurdie 8128
    Warning( "Unable to resolve path to '$source'" ) unless $found[0];
8129
    if (scalar @found > 1)
8130
    {
8131
        Warning("Duplicates for '$source'. Using the first", @found);
227 dpurdie 8132
    }
6276 dpurdie 8133
 
8134
    return $found[0] || "";
227 dpurdie 8135
}
8136
 
251 dpurdie 8137
#-------------------------------------------------------------------------------
8138
# Function        : MakeSrcResolve
8139
#
8140
# Description     : Locate a source file by examining the list of source
8141
#                   directories. There are a few frills
8142
#
8143
#                   Look for a source file in
8144
#                       1) %::BUILD_KNOWNFILES
8145
#                       2) %SRCS
8146
#                       3) Dirs specified by the array @SRCSDIRS
8147
#
8148
# Inputs          : Name of a file to resolve
8149
#
8150
# Returns         : Resolved path.
283 dpurdie 8151
#                   Input file - if not found at all
251 dpurdie 8152
#
227 dpurdie 8153
sub MakeSrcResolve
8154
{
8155
    my ($name) = @_;
8156
    my $file;
8157
 
251 dpurdie 8158
    if ( exists ( $::BUILD_KNOWNFILES{$name} ) ) {
8159
        #
8160
        #   The Known Files list is relative to ScmRoot
8161
        #   This must be included in the full path
8162
        #
8163
        $file = $ScmRoot . '/' . $::BUILD_KNOWNFILES{$name};
8164
 
8165
    } elsif ( exists $SRCS{$name} ) {
8166
        $file = $SRCS{$name};
8167
 
8168
    } else {
8169
        $file = MakeResolve( \@SRCDIRS, @_ )
8170
    }
227 dpurdie 8171
    return $file;
8172
}
8173
 
8174
 
8175
# MakeSrcResolveExtended
8176
#   from_global = 0 : Search user specified directories
8177
#               = 1 : Search LinkPkgArchive list
8178
#
8179
our @PkgSrcDirList;
8180
sub MakeSrcResolveExtended
8181
{
8182
    my ( $from_global, $file ) = @_;
8183
 
8184
    #
8185
    #   Simple Case. Resolve source from known source directories
8186
    #
8187
    #
8188
    return MakeSrcResolve( $file )
8189
        unless ( $from_global );
8190
 
8191
    #
8192
    #   Not so simple Case
8193
    #   Resolve the source from the imported packages
8194
    #
8195
    #   Create a list of directores to search, but only the first time
311 dpurdie 8196
    #       - Interface directories - from BuildPkgArchive
227 dpurdie 8197
    #       - LnkPkgArchive directories
8198
    #         Using target,product,platform include directories
8199
    #
8200
    unless ( @PkgSrcDirList )
8201
    {
8202
        for my $entry (@{$::ScmBuildPkgRules{$ScmPlatform} })
8203
        {
311 dpurdie 8204
            next if ( $entry->{'TYPE'} eq 'build' ); # Ignore BuildPkgArchives
8205
 
227 dpurdie 8206
            for (@{$entry->{'PINCDIRS'}}, @{$entry->{'THXDIRS'}}, '' )
8207
            {
8208
                my $dir = $entry->{'ROOT'} . "/" . $_ ;
8209
                $dir =~ s~//~/~g;
8210
                $dir =~ s~/$~~;
311 dpurdie 8211
                push ( @PkgSrcDirList, $dir );
227 dpurdie 8212
            }
8213
        }
311 dpurdie 8214
    }
227 dpurdie 8215
 
8216
    return MakeResolve( \@PkgSrcDirList, $file );
8217
}
8218
 
8219
#-------------------------------------------------------------------------------
8220
# Function        : GetPackageRoot
8221
#
8222
# Description     : Determine the root directory for a given package
8223
#                   This routine is intended for non-standard JATS scripts that
8224
#                   access package contents directly
8225
#
8226
#                   Note: This routine does not attempt to handle multiple
8227
#                         instances of a package ( sysbasetypes ).
8228
#
8229
# Inputs          : $pname          - Name of the package
8230
#
8231
# Returns         :
8232
#
8233
sub GetPackageRoot
8234
{
8235
    my( $pname ) = @_;
8236
    Debug( "GetPackageRoot(@_)" );
8237
 
8238
    my $result = undef;
8239
    my $pkg = GetPackageEntry( $pname );
8240
    if ( $pkg )
8241
    {
8242
        $result = $pkg->{'ROOT'};
8243
        Debug( "GetPackageRoot: $result" );
8244
    }
8245
 
8246
    return $result;
8247
}
8248
 
8249
#-------------------------------------------------------------------------------
8250
# Function        : ActiveProject
8251
#
8252
# Description     : Determine if the specified project is currenly 'active'
8253
#
345 dpurdie 8254
# Inputs          : $project            - one or more project names separated
8255
#                                         by either a comma or a colon
227 dpurdie 8256
#
8257
# Returns         : TRUE    if the project is active
8258
#
8259
sub ActiveProject
8260
{
8261
    my ($project) = @_;
345 dpurdie 8262
    foreach (  split( '\s*[:,]\s*', $project ) )
227 dpurdie 8263
    {
8264
        return 1
8265
            if ( $_ eq $::ScmBuildProject );
8266
    }
8267
    return 0;
8268
}
8269
 
345 dpurdie 8270
#-------------------------------------------------------------------------------
8271
# Function        : ActiveDefine
8272
#
8273
# Description     : Determine if the specified definition is currenly 'active'
8274
#
8275
# Inputs          : $defs               - one or more variable names separated
8276
#                                         by either a comma or a colon
8277
#
8278
# Returns         : TRUE    if any of the definitions are known
8279
#
8280
sub ActiveDefine
8281
{
8282
    my ($defs) = @_;
8283
    no strict 'refs';
8284
    foreach (  split( '\s*[:,]\s*', $defs ) )
8285
    {
8286
        return 1
4455 dpurdie 8287
            if ( defined( $$_ ) || ( @$_ ) );
345 dpurdie 8288
    }
8289
    use strict 'refs';
8290
    return 0;
8291
}
227 dpurdie 8292
 
8293
#-------------------------------------------------------------------------------
345 dpurdie 8294
# Function        : ActiveMachType
8295
#
8296
# Description     : Determine if the specified MachType is currenly 'active'
8297
#
8298
# Inputs          : $mtype              - one or more machine names separated
8299
#                                         by either a comma or a colon
8300
#
8301
# Returns         : TRUE    if any of the current MachType is in the list
8302
#
8303
sub ActiveMachType
8304
{
8305
    my ($mtype) = @_;
8306
    foreach (  split( '\s*[:,]\s*', $mtype ) )
8307
    {
8308
        return 1
8309
            if ( uc($_) eq uc($::GBE_MACHTYPE) );
8310
    }
8311
    return 0;
8312
}
8313
 
8314
#-------------------------------------------------------------------------------
6133 dpurdie 8315
# Function        : ActiveAlias
8316
#
8317
# Description     : Determine if the specified Alias is currenly 'active'
8318
#
8319
# Inputs          : $mtype              - one or more alias names separated
8320
#                                         by either a comma or a colon
8321
#
8322
# Returns         : TRUE    if any of the current Aliases is in the list
8323
#
8324
sub ActiveAlias
8325
{
8326
    my ($mtype) = @_;
8327
    foreach (  split( '\s*[:,]\s*', $mtype ) )
8328
    {
8329
        return 1
8330
            if ( isAnAlias( uc($_) ) );
8331
    }
8332
    return 0;
8333
}
8334
 
8335
 
8336
#-------------------------------------------------------------------------------
227 dpurdie 8337
# Function        : ActivePlatform
8338
#
8339
# Description     : Determine if the specified platform is currently 'active'
8340
#                   This is used by all user directives in order to determine
8341
#                   if the directive should be ignored for the current platform
8342
#
8343
# Inputs          : $platform_spec      - A platform specifier
8344
#                                         This is a bit complex.
8345
#
241 dpurdie 8346
#                   Format of platform_spec. One or more of
8347
#                       PlatformName
8348
#                       AliasName
6133 dpurdie 8349
#                       TargetName[,--Target]
345 dpurdie 8350
#                   Special Options (Must all be True)
8351
#                       --Project=ProjectName[:ProjectName]+
8352
#                       --Defined=SomeValue[:SomeValue]+
6133 dpurdie 8353
#                       --MachType=SomeMachType[:SomeMachType]+
8354
#                       --Alias=SomeAlias[:SomeAlias]+
8355
#                   Some shortcuts
8356
#                       '*'     ==> Always true
8357
#
345 dpurdie 8358
#                   Each can be prefixed with a '!' to negate the test
6133 dpurdie 8359
#                   
8360
#                   PlatformNames are either additive or negative(prefixed with !)
8361
#                       Order is not important                   
8362
#                       All additive names are accumulated before the negative items are considered.
8363
#                           ie: aa,!bb => !bb,aa
8364
#                       If only negative names are provided then JATS assumes a leading '*'
8365
#                           ie: !aaa => *,!aaa
8366
#                   
241 dpurdie 8367
#                   Valid options are:
271 dpurdie 8368
#                       --Target        - indicates that the platform is a 'target'
241 dpurdie 8369
#
8370
# Returns         : TRUE if the platform spec is satisfied
8371
#
227 dpurdie 8372
sub ActivePlatform
8373
{
8374
    my( $platform_spec ) = @_;
8375
    my( @platforms, $scmplatform, $platform );
6133 dpurdie 8376
    my( %arguments, @args );
241 dpurdie 8377
    my @plist;
227 dpurdie 8378
 
241 dpurdie 8379
    #
8380
    #   Short circuit check
6133 dpurdie 8381
    #       '*' is used so often that it pays to check it first
241 dpurdie 8382
    #
8383
    if ( $platform_spec eq '*' )
8384
    {
8385
        Debug3( " ActivePlatform(@_) = TRUE" );
8386
        return 1;
8387
    }
227 dpurdie 8388
 
241 dpurdie 8389
    #
8390
    #   Platform specifier may be a comma seperated list
8391
    #   ie:  WIN32,MOS,XXX
8392
    #   Extract non-platform arguments
279 dpurdie 8393
    #   Process to yield a dummy platform of '0' or '1' - these will be seen later
241 dpurdie 8394
    #
8395
    foreach ( split( '\s*,\s*', $platform_spec ) )
8396
    {
345 dpurdie 8397
        my ($result, $not);
8398
        if ( m~^(!?)--Project=(.+)~ ) {
325 dpurdie 8399
            $not = $1;
345 dpurdie 8400
            $result = ActiveProject($2);
277 dpurdie 8401
 
345 dpurdie 8402
        } elsif ( m~^(!?)--Defined=(.+)~ ) {
325 dpurdie 8403
            $not = $1;
345 dpurdie 8404
            $result = ActiveDefine($2);
241 dpurdie 8405
 
345 dpurdie 8406
        } elsif ( m~^(!?)--MachType=(.+)~ ) {
325 dpurdie 8407
            $not = $1;
345 dpurdie 8408
            $result = ActiveMachType($2);
8409
 
6133 dpurdie 8410
        } elsif ( m~^(!?)--Alias=(.+)~ ) {
8411
            $not = $1;
8412
            $result = ActiveAlias($2);
8413
 
325 dpurdie 8414
        } else {
8415
            #
8416
            #   Must be a platform argument
8417
            #   Add to a list
8418
            #
8419
            push @platforms, $_;
241 dpurdie 8420
            next;
8421
        }
8422
 
8423
        #
325 dpurdie 8424
        #   Continue processing non-platform arguments
345 dpurdie 8425
        #   Each one must be TRUE, allowing for negation.
241 dpurdie 8426
        #
325 dpurdie 8427
        $result = $result ? 1 : 0;
345 dpurdie 8428
        $result = ! $result if ( $not );
8429
        return 0 unless ( $result );
241 dpurdie 8430
    }
8431
 
4128 dpurdie 8432
    #
8433
    #   If we have no platforms then the test was purely non-platform arguments.
8434
    #
6133 dpurdie 8435
    if ($platform_spec ne '' && ! @platforms) {
8436
        Debug3( " ActivePlatform(@_ == $ScmPlatform) = TRUE" );
4128 dpurdie 8437
        return 1;
8438
    }
8439
 
6133 dpurdie 8440
    unless (@platforms) {
8441
        Debug3( " ActivePlatform(@_ == $ScmPlatform) = FALSE" );
8442
        return 0;
8443
    }
8444
 
8445
 
241 dpurdie 8446
    #   Platform specified may be an Alias
8447
    #   Perform alias expansion
8448
    #
8449
    @platforms = ExpandPlatforms( @platforms );         # aliasing
227 dpurdie 8450
    Debug3( " ActivePlatform(@_)" );
6198 dpurdie 8451
#    Debug0( " Platforms(@platforms)" );
227 dpurdie 8452
 
8453
#.. Arguments
241 dpurdie 8454
#   At this point we have a list of platforms and arguments
8455
#   Build up a hash of arguments for each platform being parsed
227 dpurdie 8456
#   Multiple arguments can follow a platform name
241 dpurdie 8457
#   Arguments apply to the preceeding platform name
227 dpurdie 8458
#
241 dpurdie 8459
    $platform = undef;
227 dpurdie 8460
    foreach ( @platforms )
8461
    {
241 dpurdie 8462
        if ( /^--Target/ ) {                     # Arguments
8463
            if ( $platform ) {
8464
                $arguments{$platform}{'Target'} = 1;
8465
            } else {
317 dpurdie 8466
                Warning ("No Platform preceding platform option: $_");
241 dpurdie 8467
            }
8468
 
305 dpurdie 8469
        } elsif ( /^--Only(Prod)|(Debug)/ || /--board=/ ) {
273 dpurdie 8470
            # Known arguments
305 dpurdie 8471
            # Bit of a kludge. Must be a better way
273 dpurdie 8472
 
241 dpurdie 8473
        } elsif ( /^--/ ) {
8474
            Warning ("Unknown platform option: $_");
8475
 
227 dpurdie 8476
        } else {                                # Target
8477
            $platform = $_;
241 dpurdie 8478
            push @plist, $platform;
227 dpurdie 8479
        }
8480
    }
8481
 
241 dpurdie 8482
#.. Scan the expression
227 dpurdie 8483
#
6198 dpurdie 8484
    $scmplatform = uc( $ScmPlatform );              # current platform
6133 dpurdie 8485
    my @add;
8486
    my @remove;
8487
    foreach ( @plist ) {
6198 dpurdie 8488
        my $platform = uc( Trim( $_ ) );            # trim white and convert case
6133 dpurdie 8489
        my $pname = $platform;
8490
        my $invert = 0;
8491
        if (substr($platform, 0, 1) eq '!') {
8492
            $invert = 1;
8493
            $pname = substr($platform, 1)
8494
        }
325 dpurdie 8495
 
227 dpurdie 8496
        #
241 dpurdie 8497
        #   Determine filter comparison
6133 dpurdie 8498
        #       Either a Platform or a Target
241 dpurdie 8499
        #
6133 dpurdie 8500
        if ( $arguments{$platform}{'Target'} ) {
8501
            $pname = $scmplatform if ($pname eq  uc( $ScmTarget ));
227 dpurdie 8502
        }
241 dpurdie 8503
 
6133 dpurdie 8504
        #
8505
        #   Catch some historically bad practices
8506
        #
8507
        $pname = $scmplatform if ( $pname eq '*'  || $pname eq '1' ); 
227 dpurdie 8508
 
6133 dpurdie 8509
        Debug3( "   Platform=$platform, PName=$pname" );
8510
 
227 dpurdie 8511
        #
8512
        #   Examine platform names
6133 dpurdie 8513
        #   Allow negation (removal) of the name
227 dpurdie 8514
        #
6133 dpurdie 8515
        if ( substr($platform, 0, 1) eq '!' )  {
8516
            push @remove, $pname; 
8517
        } else {
8518
            push @add, $pname; 
227 dpurdie 8519
        }
8520
    }
8521
 
241 dpurdie 8522
    #
6133 dpurdie 8523
    #   Build complete list of allowed platforms
8524
    #       Process additive rules before removal rules
8525
    #       If there are no additive rules, then assume all protaforms
241 dpurdie 8526
    #
6133 dpurdie 8527
    my %calcList;
8528
    @add = @::BUILDPLATFORMS unless @add;
6204 dpurdie 8529
    $calcList{uc $_} = 1 foreach (@add);
8530
    delete $calcList{uc $_} foreach (@remove);
6133 dpurdie 8531
#DebugDumpData("Add", \@add);
8532
#DebugDumpData("Remove", \@remove);
8533
#DebugDumpData("calcList", \%calcList);
241 dpurdie 8534
 
8535
    #
6133 dpurdie 8536
    #   If the current build target is left in the platform list, then we are building for it
8537
    #   
6198 dpurdie 8538
    if (exists $calcList{$scmplatform}) {
227 dpurdie 8539
        Debug3( " ActivePlatform(@_ == $ScmPlatform) = TRUE" );
8540
        return 1;
8541
    }
241 dpurdie 8542
 
227 dpurdie 8543
    Debug3( " ActivePlatform(@_ == $ScmPlatform) = FALSE" );
8544
    return 0;
8545
}
8546
 
8547
#-------------------------------------------------------------------------------
321 dpurdie 8548
# Function        : If
8549
#
8550
# Description     : Function for embedding arguments in directives
8551
#                   To be used within another directive
8552
#                   ie:
8553
#                       AnyDirective ('*',  arg1, arg2, ...
8554
#                                           If (SomePlatform, arg1, .. ,argn))
8555
#
8556
# Inputs          : $platform               - Active Platform speciifier
8557
#                   @args                   - Args
8558
#
8559
# Returns         : @args or nothing
8560
#
8561
sub  If
8562
{
8563
    my $platform = shift;
8564
    return @_
8565
        if ( ActivePlatform( $platform ));
8566
    return;
8567
}
8568
 
8569
#-------------------------------------------------------------------------------
227 dpurdie 8570
# Function        : RegisterMakefileGenerate
8571
#
8572
# Description     : Register a function to be called at the start of the
8573
#                   makefile generation process
8574
#
8575
# Inputs          : $fname      - Name of the function
8576
#                   $args       - Function Arguments
8577
#
8578
# Returns         : Nothing
8579
#
8580
our @MF_Generators;
8581
sub RegisterMakefileGenerate
8582
{
8583
   my ($fref) = @_;
8584
   my $rtype = ref($fref) || 'not a reference';
8585
 
8586
   Error ("RegisterMakefileGenerate called incorrectly",
8587
          "First argument MUST be a code reference",
8588
          "It is a $rtype"
8589
          ) unless ( $rtype eq 'CODE' );
8590
 
8591
   #
8592
   #    Save the arguments by reference in an array
8593
   #    The array will be processed later
8594
   #
8595
   push @MF_Generators, \@_;
8596
}
8597
 
8598
#-------------------------------------------------------------------------------
271 dpurdie 8599
# Function        : RegisterSrcHook
8600
#
8601
# Description     : Register a function to be called when a source file is
8602
#                   declared
8603
#
8604
# Inputs          : $ext        - Extension of interest
8605
#                                 '*' will be used by all
8606
#                   $fname      - Name of the function
8607
#                   $args       - Function Arguments
8608
#
8609
# Returns         : Nothing
8610
#
8611
sub RegisterSrcHook
8612
{
8613
    my $ext = shift;
8614
    my ($fref) = @_;
8615
    my $rtype = ref($fref) || 'not a reference';
8616
 
8617
    Error ("RegisterSrcHook called incorrectly",
8618
           "Second argument MUST be a code reference",
8619
           "It is a $rtype"
8620
           ) unless ( $rtype eq 'CODE' );
8621
 
8622
    #
8623
    #    Save the arguments by reference in an array
8624
    #    The array will be processed later
8625
    #
8626
    push @{$MF_RegisterSrcHooks{$ext}}, \@_;
8627
}
8628
 
8629
 
8630
#-------------------------------------------------------------------------------
227 dpurdie 8631
# Function        : MakefileHeader
8632
#
8633
# Description:    : Generate a "standard" makefile header.
8634
#
8635
#..
8636
 
8637
sub MakefileHeader
8638
{
8639
    my ($file, $desc, $by, @trailing) = @_;
8640
    my ($diff);
8641
 
8642
    $diff = 0 if (($diff = ((80-5) - length($desc))) < 0);
8643
    $desc .= ' ' . ('-' x $diff);
8644
 
8645
    print $file <<EOF;
8646
#-- $desc
8647
#
8648
#                   -- Please do not edit this file. --
8649
#
8650
#       To do so may result in a system failure, in additional to any
8651
#       changes made shall be overwritten.
8652
#
8653
# Created by $by
8654
#         on $::CurrentTime
8655
#
8656
EOF
8657
    #
8658
    #   Print out the trailer
8659
    #   This is an array. Place each entry on a new line
8660
    #
8661
    print $file $_ . "\n" for ( @trailing );
8662
}
8663
 
8664
###############################################################################
8665
# MakeFileGenerate:
8666
#       This subroutine does all of the actual make file generation based
8667
#       on information provided in the calls to the various public
8668
#       interface routines.
8669
#
8670
# Inputs:
8671
#
8672
# Returns:
8673
###############################################################################
8674
 
8675
my $MakefileGenerate_once = 0;
8676
sub MakefileGenerate
8677
{
8678
    my $Makefile = "$ScmPlatform.mk";
8679
    Debug( "MakefileGenerate: $Makefile" );
8680
 
8681
    #
8682
    #   Nasty things happen when we generate a makefile twice
8683
    #   Just warn the user and do nothing
8684
    #   If its in the common makefile.pl then just ignore it
8685
    #
8686
    if ( $ScmProcessingRootMake )
8687
    {
8688
        Warning ("MakefileGenerate directive is not allowed in common makefile.pl");
8689
        return;
8690
    }
8691
 
8692
    if ( $MakefileGenerate_once )
8693
    {
8694
        Warning ("MakefileGenerate should only be called once.",
8695
                 "Dir: $::Cwd");
8696
        return;
8697
    }
8698
    $MakefileGenerate_once = 1;
8699
 
8700
    #
8701
    #   Invoke all registered Makefile Generator functions
8702
    #   These allow clever directives to collect information to be
8703
    #   processed before the makefiles are created
8704
    #
8705
    while ( @MF_Generators )
8706
    {
8707
        Debug( "MakefileGenerate: Invoke RegisterMakefileGenerate function" );
8708
        my ($fname, @args) = @{shift @MF_Generators};
8709
        &$fname ( @args );
8710
    }
8711
 
8712
    #
8713
    #   Allow the toolset the opportunity to process all the collected data
8714
    #   before the makefile is created. This is optional
8715
    #
8716
    my( $if ) = MakeIf::Factory();              # build interface
8717
    $if->Preprocess();
8718
 
8719
    #
343 dpurdie 8720
    #   If we have supressed the Toolset use, then we need to sanity test
8721
    #   the use of the toolset
8722
    #
8723
    if ( $ScmNoToolsTest )
8724
    {
8725
        ReportError ("Building programs not supported with --NoToolset") if ( @PROGS || @TESTPROGS );
8726
        ReportError ("Building libraries not supported with --NoToolset") if ( @LIBS || @MLIBS || @SHLIBS );
8727
        ReportError ("Building projects not supported with --NoToolset") if ( %PROJECTS );
8728
        ErrorDoExit();
8729
    }
8730
 
8731
    #
227 dpurdie 8732
    #   Auto package the 'descpkg' file
8733
    #   If this makefile packages any files, then it can also package the descpkg file
8734
    #   The descpkg will be piggybacked into all makefiles that do a package
8735
    #
8736
    if ( %PACKAGE_FILES || %PACKAGE_HDRS || %PACKAGE_CLSS || %PACKAGE_LIBS
8737
                        || %PACKAGE_SHLIBS || %PACKAGE_PROGS )
8738
    {
251 dpurdie 8739
        Src ('*', 'descpkg') unless ($SRCS{ descpkg });
8740
        PackageFile ('*', 'descpkg');
227 dpurdie 8741
    }
8742
 
8743
    #
8744
    #   Some toolsets NEED a relative root
261 dpurdie 8745
    #   Note: At the moment ScmRoot is relative anyway, thus this code
8746
    #         does nothing
227 dpurdie 8747
    #
8748
    my $gbe_root = $::ScmRoot;
8749
    if ( $::UseRelativeRoot )
8750
    {
8751
        $gbe_root =  RelPath( $::ScmRoot );
8752
    }
8753
 
8754
    #
8755
    #   Now start to create the makefile
8756
    #
6133 dpurdie 8757
    ToolsetFiles::AddFile($Makefile);
285 dpurdie 8758
    open( MAKEFILE, '>', $Makefile ) || Error( "Cannot create $Makefile" );
227 dpurdie 8759
    ::MakefileHeader( *MAKEFILE,
8760
                      'Auto-generated Platform Dependent Makefile',
8761
                      "$ScmMakelib (version $ScmVersion)",
6177 dpurdie 8762
                      "# COPYRIGHT - VIX IP PTY LTD (\"VIX\"). ALL RIGHTS RESERVED.",
227 dpurdie 8763
                      '#',
8764
                      "# Located in $::Cwd",
8765
                      "# Platform $::ScmPlatform",
8766
                      '#' . ('-' x 79),
8767
                      );
8768
 
8769
    #
8770
    #   Ensure that some essential variables are set
8771
    #
8772
    print MAKEFILE <<EOF;
8773
#
8774
#   Validate essential environment variables
8775
#
8776
ifndef GBE_BIN
8777
    \$(error ERROR: GBE_BIN is not available)
8778
endif
8779
ifndef GBE_PERL
8780
    \$(error ERROR: GBE_PERL is not available)
8781
endif
8782
ifndef DEBUG
8783
    \$(error ERROR: DEBUG is not defined)
8784
endif
8785
EOF
8786
 
8787
 
8788
    print MAKEFILE <<EOF;
8789
 
8790
#
8791
#   Basic definitions
8792
#
343 dpurdie 8793
GBE_ROOT      := $gbe_root
8794
GBE_ROOT_ABS  := \$(abspath \$(GBE_ROOT))
8795
GBE_HOST      := $::ScmHost
8796
GBE_HOSTMACH  := $::GBE_MACHTYPE
8797
GBE_TARGET    := $::ScmTarget
8798
GBE_MACHTYPE  := $::ScmMachType
8799
GBE_PLATFORM  := $::ScmPlatform
8800
GBE_PBASE     := $::Pbase
8801
GBE_TYPE      := \$(if \$(findstring 1,\$(DEBUG)),D,P)
227 dpurdie 8802
EOF
8803
 
343 dpurdie 8804
MakePrint( "GBE_ARGS      := @ScmPlatformArgs\n" )
227 dpurdie 8805
    if ( scalar @ScmPlatformArgs );
8806
 
343 dpurdie 8807
MakePrint( "GBE_PRODUCT   := $ScmProduct\n" )
227 dpurdie 8808
    if ( $ScmProduct ne "" );
8809
 
343 dpurdie 8810
MakePrint( "GBE_OS_COMMON := $::BUILDINFO{$ScmPlatform}{OS_COMMON}\n" )
227 dpurdie 8811
    if ( exists($::BUILDINFO{$ScmPlatform}{OS_COMMON}) );
8812
 
8813
    print MAKEFILE <<EOF;
8814
 
8815
SHELL           := \$(GBE_BIN)/sh
8816
SHELLARGS       :=
8817
EXTENDED_LINE   := \$(GBE_BIN)/extend.lst
8818
export EXTENDED_LINE MAKE
8819
 
343 dpurdie 8820
MFLAGS           := --no-print --warn -r
8821
BUILDNAME        := $::ScmBuildName
8822
BUILDVER         := $::ScmBuildVersionFull
8823
BUILDVERNUM      := $::ScmBuildVersion
227 dpurdie 8824
BUILDPREVIOUSVER := $::ScmBuildPreviousVersion
343 dpurdie 8825
DEPLOYPATCH      := $ScmDeploymentPatch
8826
GBE_NOTOOLSTEST  := $ScmNoToolsTest
4781 dpurdie 8827
MAKEFILEUID      := $ScmMakeUid
8828
export MAKEFILEUID
227 dpurdie 8829
 
8830
#
8831
#   Ensure PWD is correctly set
8832
#
8833
PWD             := \$(CURDIR)
8834
export PWD
8835
 
261 dpurdie 8836
#
8837
#   NODEPEND    - Used to suppress generated dependency file checking
8838
#                 Mostly done in jmake.pl
8839
#   EXPERT      - Used to suppress dependency on this makefile
8840
#
8841
EOF
8842
 
285 dpurdie 8843
MakePrint( "EXPERT\t\t?= " . ($ScmExpert ? '1' : '0' ) . "\n" );
8844
MakePrint( "NODEPEND\t?= 0\n" );
261 dpurdie 8845
 
8846
print MAKEFILE <<EOF;
8847
 
8848
#
8849
#   SCM_MAKEFILE - The name of the file to depend upon
8850
#                  Supressed in EXPERT mode
8851
#
8852
ifneq (\$(EXPERT),0)
8853
SCM_MAKEFILE	:=
8854
else
8855
SCM_MAKEFILE	:= $Makefile
8856
endif
8857
EOF
8858
 
267 dpurdie 8859
#
8860
#   Setup the base directory for the packaging process
8861
#   When building a deployable package the base directory is changed to match
8862
#   that used by the deployment world. This is done so that the descpkg file
8863
#   can be created in the correct location
8864
#
8865
my  $PKGDIR = "pkg/$::Pbase";
8866
    $PKGDIR = "build/deploy" if ( $DEPLOYPACKAGE );
8867
Verbose("Setting PKGDIR: $PKGDIR");
8868
 
261 dpurdie 8869
print MAKEFILE <<EOF;
8870
 
227 dpurdie 8871
#--------- Targets -------------------------------------------------------------
8872
 
8873
.PHONY: 	default all build install package unpackage uninstall \\
8874
		clean unbuild clobber deploy
8875
 
373 dpurdie 8876
default:
227 dpurdie 8877
all:		install package deploy
8878
build:		make_init generate install_hdr depend make_lib \\
8879
		install_lib make_install_shlib make_prog install_class
8880
install:	build install_prog
8881
package:	package_files package_hdr package_lib package_shlib package_prog \\
8882
		package_class
8883
unpackage:	unpackage_class unpackage_prog unpackage_shlib \\
8884
		unpackage_lib unpackage_hdr unpackage_files
8885
uninstall:	uninstall_class uninstall_prog uninstall_shlib \\
8886
		uninstall_lib uninstall_hdr
8887
clean:		make_clean unmake_prog unmake_test unmake_lib unobj \\
261 dpurdie 8888
		undepend ungenerate rmlitter unmake_dir
227 dpurdie 8889
unbuild:	clean uninstall
8890
clobber:	unpackage unbuild
8891
deploy:		install run_deploy
8892
 
8893
#--------- Macros --------------------------------------------------------------
8894
 
8895
OBJDIR		= \$(GBE_PLATFORM)\$(GBE_TYPE).OBJ
8896
LIBDIR		= \$(GBE_PLATFORM).LIB
8897
BINDIR		= \$(GBE_PLATFORM)\$(GBE_TYPE).BIN
8898
CLSDIR		= classes\$(GBE_TYPE)
8899
 
267 dpurdie 8900
PKGDIR		= \$(GBE_ROOT)/$PKGDIR
227 dpurdie 8901
INCDIR_PKG	= \$(PKGDIR)/include
8902
LIBDIR_PKG	= \$(PKGDIR)/lib
8903
BINDIR_PKG	= \$(PKGDIR)/bin
8904
CLSDIR_PKG	= \$(PKGDIR)/classes
4996 dpurdie 8905
UTFDIR_PKG	= \$(GBE_ROOT_ABS)/$PKGDIR/utfResults
227 dpurdie 8906
 
8907
LOCALDIR	= \$(GBE_ROOT)/local
8908
INCDIR_LOCAL	= \$(LOCALDIR)/inc
8909
LIBDIR_LOCAL	= \$(LOCALDIR)/lib
8910
BINDIR_LOCAL	= \$(LOCALDIR)/bin
8911
CLSDIR_LOCAL	= \$(LOCALDIR)/classes
8912
BINDIR_LOCAL_PATH = \$(GBE_ROOT_ABS)/local/bin/\$(GBE_PLATFORM)\$(GBE_TYPE)
8913
 
8914
INTERFACEDIR	= \$(GBE_ROOT)/$ScmInterface
8915
INCDIR_INTERFACE= \$(INTERFACEDIR)/include
8916
LIBDIR_INTERFACE= \$(INTERFACEDIR)/lib
8917
BINDIR_INTERFACE= \$(INTERFACEDIR)/bin
8918
CLSDIR_INTERFACE= \$(INTERFACEDIR)/classes
8919
 
8920
.SUFFIXES:		# Delete the default suffixes
8921
 
8922
EOF
8923
 
8924
    MakePrintList( \@DEFINES );
8925
    MakeNewLine();
8926
 
8927
#-------------------------------------------------------------------------------
8928
#
8929
#
261 dpurdie 8930
    MakeHeader ("Defines, flags and file sets");
227 dpurdie 8931
 
8932
    # Flags
6177 dpurdie 8933
    foreach my $opt ( sort keys %ScmCompilerOpts )
261 dpurdie 8934
    {
8935
        MakeDefEntry ( $opt, "=", $ScmCompilerOpts{$opt} );
8936
    }
227 dpurdie 8937
 
261 dpurdie 8938
    MakeDefEntry( "CFLAGS",         "=", \@CFLAGS, \@CFLAGS_PROD, \@CFLAGS_DEBUG );
8939
    MakeDefEntry( "CLINTFLAGS",     "=", \@CLINTFLAGS, \@CLINTFLAGS_PROD, \@CLINTFLAGS_DEBUG );
8940
    MakeDefEntry( "CDEPENDFLAGS",   "=", \@CFLAGS, \@CFLAGS_PROD, \@CFLAGS_DEBUG );
8941
    MakeDefEntry( "CXXFLAGS",       "=", \@CXXFLAGS, \@CXXFLAGS_PROD, \@CXXFLAGS_DEBUG );
8942
    MakeDefEntry( "CXXLINTFLAGS",   "=", \@CXXLINTFLAGS, \@CXXLINTFLAGS_PROD, \@CXXLINTFLAGS_DEBUG );
8943
    MakeDefEntry( "CXXDEPENDFLAG",  "=", \@CXXFLAGS, \@CXXFLAGS_PROD, \@CXXFLAGS_DEBUG );
267 dpurdie 8944
    MakeDefEntry( "ASFLAGS",        "=", \@ASFLAGS, \@ASFLAGS_PROD, \@ASFLAGS_DEBUG );
8945
    MakeDefEntry( "LDFLAGS",        "=", \@LDFLAGS, \@LDFLAGS_PROD, \@LDFLAGS_DEBUG );
227 dpurdie 8946
 
8947
 
8948
#-------------------------------------------------------------------------------
8949
#   
8950
#
261 dpurdie 8951
    MakeHeader ("Tool Search Path",
8952
                "Extend the PATH seen by all the tools to include",
8953
                "The tools/bin directories discovered in Packages" );
8954
    my $put_PATH;
8955
    my $put_LD_LIBRARY_PATH;
8956
    for my $path ( ToolExtensionPaths() )
8957
    {
8958
        MakePrint( "PATH := $path$::ScmPathSep\$(PATH)\n" );
8959
        $put_PATH = 1;
227 dpurdie 8960
 
261 dpurdie 8961
        if ( $::ScmHost eq "Unix" )
8962
        {
227 dpurdie 8963
        MakePrint( "LD_LIBRARY_PATH ?= \n" );
8964
        MakePrint( "LD_LIBRARY_PATH := $path$::ScmPathSep\$(LD_LIBRARY_PATH)\n" );
261 dpurdie 8965
            $put_LD_LIBRARY_PATH =1;
8966
        }
227 dpurdie 8967
    }
8968
 
261 dpurdie 8969
    #   Export the appropriate environment variables
8970
    #   Note: Windows has an issue with PATH and Path
8971
    #         Haven't got to the bottom of it yet, but it would appear that DLL
8972
    #         searching uses Path and other stuff uses PATH. Not too sure how we
8973
    #         end up with two (or more in the environment)
8974
    #
8975
    #
8976
    if ( $put_LD_LIBRARY_PATH )
8977
    {
343 dpurdie 8978
        MakePrint( "export LD_LIBRARY_PATH\n" );
261 dpurdie 8979
    }
227 dpurdie 8980
 
261 dpurdie 8981
    if ( $put_PATH )
8982
    {
343 dpurdie 8983
        MakePrint( "Path := \$(PATH)\n" );
8984
        MakePrint( "export PATH Path\n" );
261 dpurdie 8985
    }
227 dpurdie 8986
 
8987
#-------------------------------------------------------------------------------
8988
#   
8989
#
261 dpurdie 8990
    MakeHeader ("Perl Module Search Path",
8991
                "Extend the PERL5LIB seen by invocations of perl");
227 dpurdie 8992
 
261 dpurdie 8993
    my $perl_module_found;
8994
    for my $path ( ToolExtensionPaths() )
227 dpurdie 8995
    {
6276 dpurdie 8996
        if (my @results =  glob( "$path/*.pm"))
261 dpurdie 8997
        {
6276 dpurdie 8998
            MakePrint( "PERL5LIB := $path$::ScmPathSep\$(PERL5LIB)\n" );
261 dpurdie 8999
            $perl_module_found = 1;
9000
        }
227 dpurdie 9001
    }
261 dpurdie 9002
    if ( $perl_module_found  )
9003
    {
227 dpurdie 9004
    MakePrint( "export PERL5LIB\n" );
261 dpurdie 9005
    }
227 dpurdie 9006
 
261 dpurdie 9007
#-------------------------------------------------------------------------------
227 dpurdie 9008
#   
9009
#
261 dpurdie 9010
    MakeHeader ("Include Search Paths",
367 dpurdie 9011
                "Package Include Paths for header files and libraries" );
227 dpurdie 9012
 
6177 dpurdie 9013
    MakeDefEntry( 'PINCDIRS'  , '=', '# includes');
9014
    MakeDefEntry( 'PINCDIRS_INTERFACE', '=', '# Interface includes');
9015
    MakeDefEntry( 'PINCDIRS_LOCAL', '=', '# Local includes');
9016
    MakeDefEntry( 'PLIBDIRS'  , '=', '# libraries');
9017
    MakeDefEntry( 'PLIBDIRS_INTERFACE', '=', '# Interface libraries');
9018
    MakeDefEntry( 'PLIBDIRS_LOCAL', '=', '# Local libraries');
367 dpurdie 9019
 
9020
    for my $package (@{$::ScmBuildPkgRules{$ScmPlatform} })
9021
    {
9022
        #
9023
        #   Skip the pseudo package that encapsulates the interface
9024
        #   directory. Currently the makefiles do this in a different
9025
        #   manner - to be resolved
9026
        #
9027
        #   Just comment out the lines so that the data is visible
9028
        #   Its a hint to make use of the data
9029
        #
9030
        my $prefix = '';
6177 dpurdie 9031
        my $suffix = '';
367 dpurdie 9032
        $prefix = '# ' if ( $package->{'TYPE'} eq 'build' );
9033
 
6177 dpurdie 9034
        #
9035
        #   The interface directory is a little bit different
9036
        #
9037
        my ($name,$base);
9038
        if ( $package->{'TYPE'} eq 'interface' ) {
9039
            $base = '$(INTERFACEDIR)';
9040
            $name = 'Interface Directory';
9041
            $suffix = '_INTERFACE';
9042
        } else {
9043
            $name = $package->{'NAME'} . '/' . $package->{'VERSION'};
9044
            $base = $package->{'ROOT'};
9045
        }
367 dpurdie 9046
 
1329 dpurdie 9047
        my @doc;
9048
        push (@doc, "From: $base");
9049
        push (@doc, 'BuildPkgArchive via Interface' )if $package->{'TYPE'} eq 'build' ;
367 dpurdie 9050
 
1329 dpurdie 9051
        MakeHeader ("Source: $name", @doc);
9052
 
367 dpurdie 9053
        #
9054
        #   List include and library directories
9055
        #   Note: Need the True Path for windows.
9056
        #       Some makefile functions (wildcard) only work as expected
9057
        #       if the case of the pathname is correct. Really only a problem
6177 dpurdie 9058
        #       with badly formed legacy packages where the Windows user
367 dpurdie 9059
        #       guessed at the package format.
9060
        #
9061
        #       The conversion to a TruePath is done when ScmBuildPkgRules
6177 dpurdie 9062
        #       is created. Create once, use many time.
367 dpurdie 9063
        #
6177 dpurdie 9064
        for my $type (qw (PINCDIRS PLIBDIRS) ) {
9065
            for my $path ( @{$package->{$type}} ) {
9066
                MakeDefEntry ( "$prefix$type$suffix", "+=", $base . $path);
367 dpurdie 9067
            }
9068
        }
9069
    }
9070
 
6177 dpurdie 9071
    #
9072
    #   Local Paths
9073
    #   These are a little bit special
9074
    #
9075
    MakeHeader ('Source: Local',  'From: Package Local');
9076
 
9077
    sub MakeLocalPaths 
9078
    {
9079
        my ($name, $root, $addRoot) = @_;
9080
        my @pathlist;
9081
 
9082
        foreach my $tag ( $ScmPlatform, $ScmProduct, $ScmTarget ) {
9083
            UniquePush( \@pathlist, "$root/$tag" ) if ( $tag );
9084
        }
9085
 
9086
        #   Add the root directory too
9087
        UniquePush( \@pathlist, $root) if $addRoot;
9088
 
9089
        MakeDefEntry ( $name , "+=", \@pathlist);
9090
    }
9091
 
9092
    MakeLocalPaths ( 'PINCDIRS_LOCAL', '$(INCDIR_LOCAL)', 1 );
9093
    MakeLocalPaths ( 'PLIBDIRS_LOCAL', '$(LIBDIR_LOCAL)', 0 );
9094
 
9095
 
367 dpurdie 9096
#-------------------------------------------------------------------------------
9097
#   
9098
#
9099
    MakeHeader ("Include Search Paths",
9100
                "Local Include Paths",
9101
                " LINKDIRS - Local include search path (short)",
9102
                " INCDIRS  - Include search path (complete)",
9103
                " NODEPDIRS - ",
9104
                " SRCDIRS - ",
9105
                " LIBDIRS - Library search path",
9106
 
9107
                );
9108
 
227 dpurdie 9109
    # Include search path
9110
    #
9111
    #   user-local
367 dpurdie 9112
    #   local
9113
    #   interface
9114
    #       BuildPkgArchive
9115
    #       LinkPkgArchive
227 dpurdie 9116
    #   user-global
9117
    #
9118
 
6177 dpurdie 9119
    MakeDefEntry ( "\nLINCDIRS",    "= ", \@L_INCDIRS );                    # .. Local
9120
    MakeDefEntry ( "LINCDIRS",      "+=", '$(PINCDIRS_LOCAL)');             # .. Sandbox local
9121
    MakeDefEntry ( "LINCDIRS",      "+=", '$(PINCDIRS_INTERFACE)');         # .. Sandbox interface
9122
    MakeDefEntry ( "LINCDIRS",      "+=", \@G_INCDIRS );                    # .. Global
227 dpurdie 9123
 
6177 dpurdie 9124
    MakeDefEntry ( "INCDIRS",  "= ", '$(LINCDIRS)' );                       # Local
9125
    MakeDefEntry ( "INCDIRS",  "+=", '$(PINCDIRS)' );                       # Package
9126
    MakeDefEntry ( "LINCDIRS", "+=", \@S_INCDIRS );                         # System
227 dpurdie 9127
 
9128
    # Source search path
9129
 
261 dpurdie 9130
    MakeDefEntry( "\nNODEPDIRS",        "=", \@NODEPDIRS );
227 dpurdie 9131
 
6177 dpurdie 9132
    MakeDefEntry( "\nSRCDIRS","= "  , [ @L_SRCDIRS, @G_SRCDIRS ] );         # Local
9133
    MakeDefEntry ( "SRCDIRS", "+=" , '$(PINCDIRS)' );                       # Package
9134
    MakeDefEntry ( "SRCDIRS", "+=" , \@S_INCDIRS );                         # System
227 dpurdie 9135
 
9136
    # Library search path
9137
    #
9138
    #   user-local
367 dpurdie 9139
    #   local
9140
    #   interface
9141
    #       BuildPkgArchive
9142
    #       LinkPkgArchive
227 dpurdie 9143
    #   user-global
6177 dpurdie 9144
    #   
9145
    #   Kludge Note:
9146
    #       The LIBDIRS path needs an element with a directory seperator in it
9147
    #       Needed by (broken) cmdfile o determine the file seperator to use
9148
    #       
227 dpurdie 9149
 
367 dpurdie 9150
    MakeDefEntry( "\nLIBDIRS",  "= ", '$(LIBDIR)' );                    # User Local
261 dpurdie 9151
    MakeDefEntry( "LIBDIRS",    "+=", \@L_LIBDIRS );                    # Local
6177 dpurdie 9152
    MakeDefEntry( "LIBDIRS",    "+=", '$(PLIBDIRS_LOCAL)' );            # Sandbox/local
9153
    MakeDefEntry( "LIBDIRS",    "+=", '$(PLIBDIRS_INTERFACE)' );        # Sandbox/interface
9154
    MakeDefEntry( "LIBDIRS",    "+=", '$(LIBDIR_INTERFACE)' );          # Kludge. See note above
261 dpurdie 9155
    MakeDefEntry( "LIBDIRS",    "+=", \@G_LIBDIRS );                    # Global
367 dpurdie 9156
    MakeDefEntry( "LIBDIRS",    "+=", '$(PLIBDIRS)' );                  # Package
261 dpurdie 9157
    MakeDefEntry( "LIBDIRS",    "+=", \@S_LIBDIRS );                    # System
227 dpurdie 9158
 
9159
#-------------------------------------------------------------------------------
9160
#
9161
#   Subdir creation and deletion
9162
#   Creation is done on the fly
9163
#   Deletion is done AFTER the toolset functions have been invoked to create the
9164
#   build artifacts so that the toolsets can create directories too
9165
 
9166
    MakeHeader ("Subdir creation");
9167
    CreateMkdirRules();
6177 dpurdie 9168
    MkdirRule( '$(OBJDIR)', 'OBJDIR', '--Extra=depend,depend.err' );    # Object build directory
2429 dpurdie 9169
    MkdirRule( '$(OBJDIR)/'.$_ ) foreach (@SHLIBS);                     # Shared library build directory
9170
    MkdirRule( '$(LIBDIR)', 'LIBDIR' );                                 # Library directory
9171
    MkdirRule( '$(BINDIR)', 'BINDIR' );                                 # Binary directory
227 dpurdie 9172
 
261 dpurdie 9173
    #
9174
    #   Create a directory for library merge tool to work within
9175
    #
9176
    MkdirRule( "\$(MLIBDIR)", 'MLIBDIR', '--Path=$(GBE_PLATFORM).MRG', '--RemoveAll' ) if (@MLIBS);
9177
 
227 dpurdie 9178
#-------------------------------------------------------------------------------
9179
#   Generate rules and recipes to create all the toolset specific parts
9180
#   This is done fairly early to allow the toolsets to extend various
9181
#   definitions that may be used later in the makefile construction
9182
#
9183
    MakeHeader ("Construct Programs");
9184
 
9185
    foreach my $i ( @PROGS )
9186
    {
289 dpurdie 9187
        my $pProg = $PROGS->Get($i);
9188
        my $pArgs = $pProg->getItems('ARGS');
9189
        my $pObjs = $pProg->getItems('OBJS');
9190
        my $pLibs = $pProg->getItems('LIBS');
227 dpurdie 9191
 
289 dpurdie 9192
        #
9193
        #   Create a list of program object files
9194
        #
9195
        push @PROGOBJS, @$pObjs;
227 dpurdie 9196
 
9197
        MakePrint( "#---- (${i})\n\n" );
9198
        if ( $ScmToolsetProgDependancies )
9199
        {
261 dpurdie 9200
            #
9201
            #   Original style Prog Interface
271 dpurdie 9202
            #   Write some dependency information here and some in the toolset
9203
            #   Problems:
9204
            #       1) Errors in library dependency generation will be
9205
            #          reported after all the object files have been created
9206
            #          Thus the error message and the make-stop are seperated
9207
            #          by many,many lines of output. This makes it difficult
9208
            #          to see the error.
261 dpurdie 9209
            #
271 dpurdie 9210
            #       2) Lack of Flexability
9211
            #
293 dpurdie 9212
            MakeEntry( "\$(BINDIR)/$i$::exe: ", "", "\\\n\t\t", ".$::o ", @$pObjs );
227 dpurdie 9213
        }
9214
        else
9215
        {
261 dpurdie 9216
            #
9217
            #   New Style Prog Interface
9218
            #   The toolset does it all
9219
            #
9220
            #   Flag the progam packaging as a placeholder.
9221
            #   The toolset will replace/update it.
9222
            #
227 dpurdie 9223
            PackageProgRemoveFiles( $i );
9224
        }
9225
 
289 dpurdie 9226
        $if->LD    ( $i, $pArgs, $pObjs, $pLibs );
9227
        $if->LDLINT( $i, $pArgs, $pObjs, $pLibs );
227 dpurdie 9228
    }
9229
 
9230
#-------------------------------------------------------------------------------
9231
#   
9232
#
9233
    MakeHeader ("Construct Test Programs");
289 dpurdie 9234
    foreach my $i ( @TESTPROGS )
227 dpurdie 9235
    {
289 dpurdie 9236
        my $pProg = $TESTPROGS->Get($i);
9237
        my $pArgs = $pProg->getItems('ARGS');
9238
        my $pObjs = $pProg->getItems('OBJS');
9239
        my $pLibs = $pProg->getItems('LIBS');
227 dpurdie 9240
 
289 dpurdie 9241
        #
9242
        #   Create a list of program object files
9243
        #
9244
        push @TESTPROGOBJS, @$pObjs;
9245
 
227 dpurdie 9246
        MakePrint( "#---- (${i})\n\n" );
9247
        if ( $ScmToolsetProgDependancies )
9248
        {
293 dpurdie 9249
            MakeEntry( "\$(BINDIR)/$i$::exe: ", "", "\\\n\t\t", ".$::o ", @$pObjs );
227 dpurdie 9250
        }
9251
        else
9252
        {
9253
            PackageProgRemoveFiles( $i );
9254
        }
9255
 
289 dpurdie 9256
        $if->LD    ( $i, $pArgs, $pObjs, $pLibs );
9257
        $if->LDLINT( $i, $pArgs, $pObjs, $pLibs );
227 dpurdie 9258
    }
9259
 
9260
#-------------------------------------------------------------------------------
9261
#
9262
#
9263
    MakeHeader ("Transfer Scripts to BINDIR");
9264
    foreach my $i ( sort ( values %SCRIPTS ))
9265
    {
9266
        my $tname = "\$(BINDIR)/" . StripDir( $i );
9267
 
9268
 
9269
        MakePrint( "$i:\t\tmakefile.pl\n" .
6177 dpurdie 9270
            "\t\$(XX_PRE)if [ ! -f \"$i\" ]; then echo 'Script [$i] not found'; exit 2; fi\n\n" );
227 dpurdie 9271
 
9272
        #
9273
        #   Create a rule to copy the script into the BIN directory
9274
        #   Mark the script as executable - It can't hurt and its there
9275
        #   to be run as part of a test.
9276
        #
9277
        MakePrint "$tname:\t\$(GBE_BINDIR) $i\n" .
9278
                  "\t\$(XX_PRE)\$(cp) -f $i $tname\n" .
9279
                  "\t\$(XX_PRE)\$(chmod) -f +wx $tname\n\n"
9280
    }
9281
 
9282
#-------------------------------------------------------------------------------
9283
#   
9284
#
9285
    MakeHeader ("Construct Libraries");
9286
    foreach my $i ( @LIBS )
9287
    {
289 dpurdie 9288
        my $pLib  = $LIBS->Get($i);
9289
        my $pArgs = $pLib->getItems('ARGS');
9290
        my $pObjs = $pLib->getItems('OBJS');
227 dpurdie 9291
 
363 dpurdie 9292
        unless ( $ScmToolsetNillLibSrc )
9293
        {
9294
            Error ("Library has no component objects: $i")
9295
                if ( scalar @$pObjs <= 0 );
9296
        }
299 dpurdie 9297
 
227 dpurdie 9298
        MakePrint "#---- (${i})\n\n";
289 dpurdie 9299
        $if->AR(     $i, $pArgs, $pObjs, $pLib);
9300
        $if->ARLINT( $i, $pArgs, $pObjs, $pLib );
227 dpurdie 9301
    }
9302
 
289 dpurdie 9303
#-------------------------------------------------------------------------------
9304
#   
9305
#
9306
    MakeHeader ("Construct Merged Libraries");
227 dpurdie 9307
    sub MlibEntry
9308
    {
289 dpurdie 9309
        my( $mlib, $plib, $pLibs ) = @_;
227 dpurdie 9310
        my @flib;
9311
 
289 dpurdie 9312
        MakePrint '$(LIBDIR)/' . GenLibName($mlib) . ":";
9313
        foreach my $lib ( @$pLibs )
227 dpurdie 9314
        {
289 dpurdie 9315
            #
9316
            #   Each library name may contains one embedded option which
9317
            #   specifies the source directory
9318
            #       libname[,--Option | BaseSubdir]
9319
            #
227 dpurdie 9320
            my ($slib, $sdir) = split( ',', $lib );
343 dpurdie 9321
            my $mode;
227 dpurdie 9322
 
9323
            #
283 dpurdie 9324
            #   By default the librares are pulled from LOCAL unless the
9325
            #   library is built in this directory, in which case it will
289 dpurdie 9326
            #   be used.
227 dpurdie 9327
            #
289 dpurdie 9328
            $sdir = ( $LIBS->Get($slib) ) ? '--Here' : '--Local'
9329
                unless ( $sdir );
227 dpurdie 9330
 
9331
            #
9332
            #   --Interface     - Pull library from the interface directory
9333
            #   --Local         - Pull library from the local directory
9334
            #   --SubDir=xxxx   - Pull library from specified subdirectory
283 dpurdie 9335
            #   --Here          - Pull from local directory if built locally
227 dpurdie 9336
            #   otherwise       - Pull library from specified subdirectory
9337
            #
9338
            if ($sdir eq '--Interface') {
9339
                $sdir = '$(LIBDIR_INTERFACE)/$(GBE_PLATFORM)';
9340
 
343 dpurdie 9341
 
9342
            } elsif ($sdir eq '--InterfacePlain') {
9343
                $sdir = '$(LIBDIR_INTERFACE)/$(GBE_PLATFORM)';
9344
                $mode = 1;
9345
 
227 dpurdie 9346
            } elsif ( $sdir eq '--Local') {
9347
                $sdir = $PackageInfo{'Lib'}{'IBase'} .  # Base of Installed libs
9348
                        $PackageInfo{'Lib'}{'Dir'};     # Default subdir
9349
 
9350
            } elsif ( $sdir =~ m~^--SubDir=(.*)~ ) {
9351
                $sdir = $1 . '/$(LIBDIR)';
9352
 
283 dpurdie 9353
            } elsif ( $sdir eq '--Here') {
9354
                $sdir = '$(LIBDIR)';
9355
 
227 dpurdie 9356
            } else {
9357
                $sdir .= '/$(LIBDIR)';
9358
            }
9359
 
343 dpurdie 9360
            MakePrint " \\\n\t\t${sdir}/" . GenLibName($slib, $mode);
227 dpurdie 9361
            push @flib, "${sdir}/${slib}";
9362
        }
289 dpurdie 9363
        return \@flib;
227 dpurdie 9364
    }
9365
 
9366
    foreach my $i ( @MLIBS )
9367
    {
289 dpurdie 9368
        my $pLib  = $MLIBS->Get($i);
9369
        my $pArgs = $pLib->getItems('ARGS');
9370
        my $pLibs = $pLib->getItems('LIBS');
227 dpurdie 9371
 
261 dpurdie 9372
        MakePrint "#---- (${i})\n\n";
9373
 
227 dpurdie 9374
        unless ( defined &ToolsetARMerge )
9375
        {
9376
            Warning( "Merging of libraries not supported in this toolset yet" );
9377
            Warning( "MergeLibrary: \"$i\" will not be created" );
9378
        }
9379
        else
9380
        {
9381
            #
9382
            #   Create the dependency rule
9383
            #       Target library : source library list
9384
            #           Recipe - generated by the toolset
9385
            #
289 dpurdie 9386
            foreach ( @$pArgs )
227 dpurdie 9387
            {
9388
                Warning( "Ignoring unknown argument to MergeLibrary. $_" );
9389
            }
289 dpurdie 9390
            $pLibs = MlibEntry( $i, $pLib, $pLibs );
9391
            $if->ARMerge( $i, $pArgs, $pLibs, $pLib );
227 dpurdie 9392
        }
9393
    }
9394
 
289 dpurdie 9395
#-------------------------------------------------------------------------------
9396
#   
9397
#
9398
    MakeHeader ("Construct Shared Libraries");
339 dpurdie 9399
 
227 dpurdie 9400
    foreach my $i ( @SHLIBS )
9401
    {
289 dpurdie 9402
        my $pShlib  = $SHLIBS->Get($i);
9403
        my $pArgs = $pShlib->getItems('ARGS');
9404
        my $pObjs = $pShlib->getItems('OBJS');
9405
        my $pLibs = $pShlib->getItems('LIBS');
9406
        my $version = $pShlib->{VERSION};
227 dpurdie 9407
 
289 dpurdie 9408
        $if->SHLD    ( $i, $pArgs, $pObjs, $pLibs, $version );
9409
        $if->SHLDLINT( $i, $pArgs, $pObjs, $pLibs, $version );
227 dpurdie 9410
    }
9411
 
9412
#-------------------------------------------------------------------------------
9413
#   Construct Objects
9414
#   For each object within OBJSOURCE construct the following:
9415
#
9416
#   $(OBJDIR)/object-name:     source-name [makefile]
9417
#       Toolset ...
9418
#
9419
#   
9420
#
9421
    MakeHeader ("Construct Objects");
371 dpurdie 9422
 
227 dpurdie 9423
    foreach my $i ( sort keys %OBJSOURCE )
9424
    {
9425
        my( $src, $sname, $ext, $type, @args );
9426
 
9427
        $src  = $OBJSOURCE{ $i };
9428
        $sname = StripDir( $src );
9429
        $ext  = StripFile( $src );
9430
        $ext = lc($ext)
9431
            if ( $::ScmHost ne "Unix" );
381 dpurdie 9432
        $type = ($ScmSourceTypes{ $ext } || '')
227 dpurdie 9433
            unless (( $type = $SRC_TYPE{ $sname }) );
9434
 
9435
        #
9436
        #   Object source is an object file
9437
        #   No need the generate the object, just create makefile rule
261 dpurdie 9438
        #   [ddp] Not too sure how we get here
227 dpurdie 9439
        #
9440
        if ( $ext eq ".$::o" )
9441
        {
9442
            MakePrint "$src:";
261 dpurdie 9443
            MakePrint " \$(SCM_MAKEFILE)";
227 dpurdie 9444
            MakeNewLine();
9445
            next;
9446
        }
9447
 
9448
        #
9449
        #   Need to create object file
9450
        #
9451
        @args = split( /$;/, $SRC_ARGS{ StripDir( $sname ) } )
9452
            if $SRC_ARGS{ $sname };
9453
 
9454
        push( @args, "--Shared" )
9455
            if ( exists $SHOBJ_LIB{$i} );
9456
 
9457
        #
9458
        #   Convert relative paths to absolute paths if required by the
9459
        #   toolset. Some compilers need ABS paths to generate nice debug
9460
        #   information.
9461
        #
9462
        $src = AbsPath($src)
9463
            if ( $UseAbsObjects );
9464
 
9465
        #
9466
        #   Extract any user specified dependancies
261 dpurdie 9467
        #   These will be added to the dependency list
227 dpurdie 9468
        #
9469
        my @dlist;
9470
        @dlist = split( /$;/, $SRC_DEPEND{$sname} )
9471
            if ( exists $SRC_DEPEND{$sname} );
9472
 
261 dpurdie 9473
        #
9474
        #   Create the dependency part of the object rule
9475
        #   The source file MUST be the first dependent recipes
9476
        #   may assume that $< is the name source file
9477
        #
9478
        MakeEntry( "\$(OBJDIR)/$i.$::o: $src \$(SCM_MAKEFILE)", "", " \\\n\t", "", @dlist );
227 dpurdie 9479
 
9480
        if ( $type eq ".c" ) {
9481
            $if->CC(  $src, $i, \@args );
261 dpurdie 9482
 
227 dpurdie 9483
        } elsif ( $type eq ".cc" ) {
9484
            $if->CXX( $src, $i, \@args );
261 dpurdie 9485
 
227 dpurdie 9486
        } elsif ( $type eq ".asm" ) {
9487
            $if->AS( $src, $i, \@args );
261 dpurdie 9488
 
227 dpurdie 9489
        } else {
9490
            $if->EXT( $src, $i, \@args ) ||
9491
                Warning( "Don't know how to build '$ext' images' for $src, $i" );
9492
            MakeNewLine();
9493
        }
9494
    }
9495
 
9496
#-------------------------------------------------------------------------------
9497
#   Construct Projects
9498
#   Construct toolset specific projects
9499
#
9500
    MakeHeader ("Construct Projects");
9501
    while ( my($project, $entry) = each %PROJECTS)
9502
    {
9503
        $if->PROJECT( $entry );
9504
    }
9505
 
9506
#-------------------------------------------------------------------------------
4761 dpurdie 9507
#   Automated tests
9508
#
9509
    MakeHeader ("Automated tests");
9510
 
9511
    my $idx = 0;
9512
    my @copy_set = ();
9513
 
227 dpurdie 9514
    foreach my $pEntry ( @TESTS_TO_RUN )
9515
    {                                           # Foreach test
9516
        $idx++;
9517
        $pEntry->{'index'} = $idx;
9518
        $pEntry->{'test_name'} = "run_test_$idx";
5708 dpurdie 9519
        $pEntry->{'echoname'} = $pEntry->{'utfname'} || '';  
4781 dpurdie 9520
        $pEntry->{'utfname'} = $pEntry->{'test_name'} unless defined $pEntry->{'utfname'};  
227 dpurdie 9521
 
9522
        #
9523
        #   If the test is being run within a 'FrameWork' then the underlying
9524
        #   toolset must instantiate the frame work.
9525
        #
9526
        #   This may change. Perhaps frameworks shouldn't be a part of the
9527
        #   toolset. Perhaps they should be standalone. May change
9528
        #
9529
        if ( $pEntry->{framework} )
9530
        {
9531
            $if->TESTFRAMEWORK( $pEntry );
9532
        }
9533
 
9534
        #
9535
        #   Create a rule to run the test
9536
        #
9537
 
9538
        my $tdir_alias = $pEntry->{'testdir'};
9539
        my $tdir = '$(' . $tdir_alias . ')';
9540
 
9541
        my $test_name = $pEntry->{'test_name'};
4996 dpurdie 9542
        push @TESTPROJECT_TO_URUN, $test_name;
4501 dpurdie 9543
        push @TESTPROJECT_TO_ARUN, $test_name if     ($pEntry->{'auto'} );
227 dpurdie 9544
 
9545
        my $tprog = $tdir . '/' . StripDir( $pEntry->{'prog'} );
5695 dpurdie 9546
 
9547
        #
9548
        #   Determine the maximum time that the automated test should run
9549
        #       Default is 30 minutes
9550
        #   Non-auto tests are not time limited
9551
        #       
9552
        my $timeout = '';
5848 dpurdie 9553
        if ($pEntry->{'auto'})
5695 dpurdie 9554
        {
5848 dpurdie 9555
            $timeout = 'timeout -Time:' . ($pEntry->{'maxtime'} || '30m') . ' ';
5695 dpurdie 9556
        }
227 dpurdie 9557
 
9558
        my $me = MakeEntry::New( *MAKEFILE, $test_name, '--Phony' );
4781 dpurdie 9559
 
9560
        #
4996 dpurdie 9561
        #   Export GBE_UTF... for the duration of the test
4781 dpurdie 9562
        #
9563
        $me->AddDefn('export GBE_UTFNAME', $pEntry->{'utfname'});
9564
        $me->AddDefn('export GBE_UTFUID', '$(MAKEFILEUID)' . '_' . $pEntry->{'index'});
4996 dpurdie 9565
        $me->AddDefn('export GBE_UTFFILE','$(UTFDIR_PKG)/$(GBE_PLATFORM)-$(GBE_TYPE)-$(GBE_UTFUID)' . '.xml');
4781 dpurdie 9566
 
5986 dpurdie 9567
        # Workaround for dirsep under windows when being wrapped in a timeout
9568
        $me->AddDefn('dirsep', '$(dirsep)$(dirsep)') if ($timeout && ($::ScmHost ne "Unix"));
9569
 
227 dpurdie 9570
        $me->AddDependancy( "\$(GBE_$tdir_alias)" );
9571
        $me->AddDependancy( "\$(INTERFACEDIR)/set_$::ScmPlatform.sh" );
9572
        $me->AddDependancy( $tprog ) if $pEntry->{'copyprog'};
9573
        $me->AddDependancy( @{ $pEntry->{'copyin' } } );
9574
        $me->AddDependancy( map { $tdir . '/' . StripDir($_) } @{ $pEntry->{'copyonce' } } );
9575
        $me->AddDependancy( @{ $pEntry->{'preq'} } );
9576
        $me->RecipePrefix ('$(XX_PRE)');
5708 dpurdie 9577
        $me->RecipeWrapper( $timeout . 'sh -c \'', '\'') if $timeout;
9578
        $me->RecipeComment( "------ Running test [$idx] $pEntry->{'echoname'} ..." );
227 dpurdie 9579
 
9580
        #
4996 dpurdie 9581
        #   Create package utfResults directory
9582
        #       Simplify use of the file
9583
        #
9584
        $me->AddShellRecipe ( 'mkdir -p $(UTFDIR_PKG)' );
9585
 
9586
        #
227 dpurdie 9587
        #   Extend the PATH seen by the script to include the local/bin directory
9588
        #   Allows programs and tests that have been created elsewhere in the component
9589
        #   to be accessed within the script.
9590
        #
9591
        $me->AddShellRecipe ( ". \$(INTERFACEDIR)/set_$::ScmPlatform.sh" );
9592
 
9593
        #
9594
        #   Copy in the files that we need
9595
        #
9596
        foreach my $file ( @{$pEntry->{'copyin'}} )
9597
        {
9598
            my $dst = $tdir . '/' . StripDir( $file );
9599
            UniquePush( \@COPYIN, $dst );
9600
            UniquePush( \@copy_set, $file );
9601
            $me->AddShellRecipe ( "\$(cp) -f $file $dst" );
9602
            $me->AddShellRecipe ( "\$(chmod) -f +wx $dst" );
9603
        }
9604
 
9605
        #
4778 dpurdie 9606
        #   Insert any FrameWork Recipe bits
227 dpurdie 9607
        #
9608
        $me->AddShellRecipe ( @{$pEntry->{'ShellRecipe'}} );
9609
 
4781 dpurdie 9610
        #
9611
        #   Insert command
5035 dpurdie 9612
        #       Save result code to a known file
4781 dpurdie 9613
        #
227 dpurdie 9614
        $me->AddShellRecipe ( "cd $tdir" );
9615
        $me->AddShellRecipe ( ["GBE_TYPE=\$(GBE_TYPE)",
9616
                               "GBE_HOST=\$(GBE_HOST)",
9617
                               "GBE_ROOT=\$(GBE_ROOT_ABS)",
4095 dpurdie 9618
                               "PATH=.\\$::ScmPathSep\$(BINDIR_LOCAL_PATH)\\$::ScmPathSep\$\$PATH",
5708 dpurdie 9619
                               $pEntry->{'command'},
227 dpurdie 9620
                               @{$pEntry->{'args'}},
5035 dpurdie 9621
                               ] , 
9622
                               'echo $$? > utf.$${GBE_UTFUID}.rc' );
9623
 
9624
        #
9625
        #   Create the basic command line for 'jats_runutf'
9626
        #       Use the simplistic 'internal' filter unless the user has provided one
9627
        #
9628
        my @cmdline;
9629
        push @cmdline, '--';
9630
        push @cmdline, '$(VERBOSE_OPT)';
9631
        push @cmdline, '-filter=' . ($pEntry->{'utfformat'} || 'internal');
9632
        push @cmdline, '-root=$(GBE_ROOT_ABS)' ;
9633
        push @cmdline, "-dir=$tdir";
9634
        push @cmdline, '-target=$(GBE_PLATFORM)';
9635
        push @cmdline, '-pkgdir=$(PKGDIR)';
9636
        push @cmdline, '-local=$(LOCALDIR)';
9637
        push @cmdline, '-interface=$(INTERFACEDIR)';
9638
        foreach my $entry (@{$pEntry->{'utfargs' }})
4778 dpurdie 9639
        {
5035 dpurdie 9640
            push @cmdline, '-arg=' . $entry;
4778 dpurdie 9641
        }
5035 dpurdie 9642
 
9643
        #
9644
        #   Insert commands to post process the test results according to the specified formatter
9645
        #
9646
        $me->NewSection     ();
9647
        $me->SectionIfDef   ('UTF_POSTPROCESS');
9648
        $me->RecipePrefix   ('$(XX_PRE)');
9649
        $me->AddRecipe      ( "\$(GBE_PERL) -Mjats_runutf -e processUtf " . join(" \\\n\t\t\t", @cmdline)  );
4778 dpurdie 9650
 
227 dpurdie 9651
        $me->Print();
9652
 
9653
 
9654
        #
9655
        #   Create entries to handle the copy-once files
9656
        #
9657
        foreach my $file ( @{ $pEntry->{'copyonce' } } )
9658
        {
9659
            my $tname = $tdir . '/' . StripDir($file);
9660
            my $me = MakeEntry::New( *MAKEFILE, $tname  );
9661
            $me->AddDependancy( $file );
9662
            $me->AddRecipe ( "\$(call CopyFile,CopyIn,$tname,$file,$tdir,)"  );
9663
            $me->Print();
9664
 
9665
            UniquePush( \@COPYIN, $tname );
9666
            UniquePush( \@copy_set, $file );
9667
 
9668
        }
9669
    }
9670
 
9671
    #
9672
    #   Generate sanity test for each copyin script
9673
    #   Simply to provide a nice error message for generated scripts
9674
    #   that do not exist at run-time
9675
    #
9676
    test_copy_in:
9677
    foreach my $i ( @copy_set )
9678
    {
9679
        next if ( $SCRIPTS{$i} );
9680
        foreach (  @SHLIB_TARGETS )
9681
        {
9682
            next test_copy_in if ( $i eq $_ );
9683
        }
9684
        MakePrint( "\n$i:\t\tmakefile.pl\n" .
6177 dpurdie 9685
            "\t\@if [ ! -f \"$i\" ]; then echo 'ERROR: CopyIn Script [$i] not found'; exit 2; fi\n" );
227 dpurdie 9686
    }
9687
 
261 dpurdie 9688
#-------------------------------------------------------------------------------
9689
#   Deploy rules
9690
#
9691
MakeHeader ("Deploy Rules");
227 dpurdie 9692
 
261 dpurdie 9693
print MAKEFILE <<EOF;
9694
.PHONY:		run_deploy
9695
EOF
227 dpurdie 9696
 
261 dpurdie 9697
#
9698
#   Build up the deployfile.pl command line from the available pieces
9699
#
9700
my $command_file = "";
9701
my @command_line;
9702
 
9703
if ( %DEPLOYPACKAGE )
9704
{
9705
    $command_file = $DEPLOYPACKAGE{'cmdfile'};
9706
 
9707
    push @command_line, "\$(XX_PRE)\$(GBE_PERL) -w $command_file";
9708
    push @command_line, "-r \"\$(GBE_ROOT)\"";
9709
    push @command_line, "-n \"$DEPLOYPACKAGE{'name'}\"";
9710
    push @command_line, "-d \"$DEPLOYPACKAGE{'dir'}\"";
9711
    push @command_line, "-v \"\$(BUILDVER)\"";
9712
    push @command_line, "-t \"\$(GBE_TYPE)\"";
9713
    push @command_line, "-o \"\$(BUILDPREVIOUSVER)\"";
9714
    push @command_line, "-m \"\$(GBE_PLATFORM)\"";
9715
    push @command_line, "-g \"\$(GBE_TARGET)\"";
9716
    push @command_line, "-k \"\$(GBE_PRODUCT)\""        if ( $ScmProduct );
9717
    push @command_line, "-p \"\$(DEPLOYPATCH)\""        if ( $ScmDeploymentPatch );
9718
 
9719
}
9720
 
9721
MakeEntry( "run_deploy:\t$command_file\n", "\n", "\t\t", " \\\n", @command_line );
9722
 
227 dpurdie 9723
#-------------------------------------------------------------------------------
261 dpurdie 9724
#   Custom Rules
9725
#
9726
    MakeHeader ("Custom Rules");
9727
    MakePrintList ( \@RULES );
9728
 
9729
#-------------------------------------------------------------------------------
9730
#   Generated Files
9731
#
9732
    MakeHeader ("Generated Files");
9733
    MakePrint ("\n.PHONY: phony_generate\n\n" );
9734
 
9735
    foreach my $i ( @GENERATE_FILES )
9736
    {
9737
        my $gen_tag = $i->{'index'};
9738
 
9739
        #
263 dpurdie 9740
        #   If predelete is enabled, then create a list of files to delete
9741
        #
9742
        if ( $i->{'predelete'}  )
9743
        {
9744
            MakeDefEntry( "generate_gen_$gen_tag", "=",  $i->{'gen'} );
9745
            MakePrint("\n")
9746
        }
9747
 
9748
 
9749
        #
261 dpurdie 9750
        #   Generate the basic generate rule and recipe
9751
        #   together with the prerequisites
9752
        #
9753
        MakeEntry ( "", ":", "", " ", @{$i->{'gen'}} );
9754
 
9755
        unless ( $i->{'clean'} && $i->{'shell'} )
9756
        {
9757
            MakeEntry ( "", "", " \\\n\t\t", "", @{$i->{'preq'}} );
9758
            MakeEntry ( "", "", " \\\n\t\t", "", "phony_generate" ) if $i->{'preq_sus'};
9759
            MakeEntry ( "", "", " \\\n\t\t", "", "\$(SCM_MAKEFILE)" );
9760
 
6177 dpurdie 9761
            MakePrint ("\n\t" . "\@\$(echo) '[$i->{'text'}] generating..'" );
263 dpurdie 9762
            if ( $i->{'predelete'}  )
9763
            {
9764
                MakePrint ("\n\t" . "\$(XX_PRE)\$(call RmFiles,generate_gen_$gen_tag)" );
9765
            }
261 dpurdie 9766
            MakePrint ("\n\t" . "\$(XX_PRE)\$(call generate_$gen_tag,)" );
9767
        }
9768
 
9769
        #
9770
        #   Generate 'clean' rules and recipes
9771
        #
9772
        if ( $i->{'clean'} )
9773
        {
9774
            MakePrint ("\n\nPHONY: clean_generate_$gen_tag" );
9775
            MakePrint ("\nclean_generate_$gen_tag:" );
343 dpurdie 9776
            MakePrint ("\n\t" . "\$(XX_PRE)-\$(call generate_$gen_tag,$i->{'clean'})" );
261 dpurdie 9777
        }
9778
 
9779
        #
9780
        #   Define a function to contain the body of the generation call
9781
        #   The first argument will be a 'clean' argument
9782
        #
9783
        MakePrint ("\n\ndefine generate_$gen_tag" );
9784
        if ( $i->{'shell'} )
9785
        {
9786
            MakeEntry ("\n\t(" , "\\\n\t)\n", " \\\n\t", ";" , @{$i->{'toolargs'}} );
9787
        }
9788
        else
9789
        {
9790
            MakeEntry ("\n\t" . $i->{'tool'} . ' $1', "\n", " \\\n\t\t", "" , @{$i->{'toolargs'}} );
9791
        }
9792
        MakePrint ("endef\n\n" );
9793
    }
9794
 
9795
#-------------------------------------------------------------------------------
9796
#   Toolset Post Processing
9797
#   Allow the toolset to perform any post processing, before we finally write
9798
#   out any definitions.
9799
#
9800
#   We will not interprete any more user directives, but new stuff may get added
9801
#
9802
#
9803
MakeHeader ("Toolset Post Processing");
9804
$if->Postprocess();
9805
 
9806
################################################################################
9807
#   All interactions with the toolset are now complete
9808
#   All lists are now complete
9809
#
9810
#   Can now create internal definitions
9811
#   
9812
################################################################################
9813
 
9814
    #
9815
    #   Would be nice if this would work
9816
    #   Unfortunatelty we still need $if for the CCDEPENDS and CTAGS work
9817
    #   These must be defined AFTER the definitions
9818
    #
9819
    #   Ideally we should construct our makefile in sections
9820
    #   and then we can order the sections when we write them out
9821
    #
9822
#$if = 0;                            # Ensure the MakeIf class is not called
9823
                                     # If this file is modified
9824
 
9825
#-------------------------------------------------------------------------------
227 dpurdie 9826
#   Sources
9827
#
9828
MakeHeader  ( "Sources");
9829
MakeDefEntry( "CSRCS",      "=",  \@CSRCS );
9830
MakeDefEntry( "CXXSRCS",    "=",  \@CXXSRCS );
9831
MakeDefEntry( "ASSRCS",     "=",  \@ASSRCS );
9832
 
9833
#-------------------------------------------------------------------------------
9834
#   Generated, Installed and Packaged components
9835
#
9836
MakeHeader  ("Generated, Installed and Packaged components");
9837
MakeDefEntry( "INITS",           "=",  \@INITS )   if ( @INITS );
9838
MakeDefEntry( "GENERATED",       "=",  \@GENERATED ) if ( @GENERATED );
9839
MakeDefEntry( "GENERATED_NOTSRC","=",  \@GENERATED_NOTSRC ) if ( @GENERATED_NOTSRC );
9840
MakeDefEntry( "GENERATEDCLEAN",  "=",  CreateNameList( 'clean_generate_', '', ListCleanGenerated() ));
9841
MakeDefEntry( "INSTALL_HDRS",    "=",  \%INSTALL_HDRS ) if ( %INSTALL_HDRS );
9842
MakeDefEntry( "INSTALL_CLSS",    "=",  \%INSTALL_CLSS ) if ( %INSTALL_CLSS );
9843
MakeDefEntry( "OBJS",            "=", CreateNameList( '$(OBJDIR)/', ".$::o", \@OBJS) );
9844
MakeDefEntry( "SHOBJS",          "=", CreateNameList( '$(OBJDIR)/', ".$::o", \%SHOBJ_LIB ));
289 dpurdie 9845
MakeDefEntry( "PROGOBJS",        "=", CreateNameList( '', ".$::o", \@PROGOBJS ));
9846
MakeDefEntry( "TESTPROGOBJS",    "=", CreateNameList( '', ".$::o", \@TESTPROGOBJS ));
9847
MakeDefEntry( "LIBS",            "=", $LIBS->AllTargets() ) if ($::a);
9848
MakeDefEntry( "MLIBS",           "=", $MLIBS->AllTargets() ) if ($::a);
227 dpurdie 9849
MakeDefEntry( "SHNAMES",         "=", \@SHLIBS );
9850
MakeDefEntry( "SHDIRS",          "=", CreateNameList( '$(OBJDIR)/', "", \@SHLIBS ));
9851
MakeDefEntry( "SHLIBS",          "=", \@SHLIB_TARGETS );
9852
MakeDefEntry( "SCRIPTS",         "=", CreateNameList( '$(BINDIR)/', "", \%SCRIPTS ));
9853
MakeDefEntry( "COPYIN",          "=", \@COPYIN );
289 dpurdie 9854
MakeDefEntry( "PROGS",           "=", $PROGS->AllTargets() );
227 dpurdie 9855
MakeDefEntry( "PROGS_EXTRA",     "=", \@PROGS_EXTRA );
289 dpurdie 9856
MakeDefEntry( "TESTPROGS",       "=", $TESTPROGS->AllTargets());
227 dpurdie 9857
MakeDefEntry( "LINTLIBS",        "=", CreateNameList( 'lib_', '_lint', \@LINTLIBS ));
9858
MakeDefEntry( "LINTSHLIBS",      "=", CreateNameList( 'shlib_', '_lint', \@LINTSHLIBS ));
9859
MakeDefEntry( "LINTPROGS",       "=", CreateNameList( 'prog_', '_lint', \@PROGS ));
289 dpurdie 9860
MakeDefEntry( "LINTPROGS",      "+=", CreateNameList( 'prog_', '_lint', \@TESTPROGS ));
227 dpurdie 9861
MakeDefEntry( "PROJECTS",        "=", CreateNameList( 'Project_', '', ListGeneratedProjects(1) ));
9862
MakeDefEntry( "PROJECTSGEN",     "=", CreateNameList( 'Project_', '', ListGeneratedProjects(0) ));
9863
MakeDefEntry( "PROJECTSCLEAN",   "=", CreateNameList( 'ProjectClean_', '', \%PROJECTS ));
9864
 
4501 dpurdie 9865
MakeDefEntry( "UNITTESTS",       "=", \@TESTPROJECT_TO_URUN );
9866
MakeDefEntry( "AUTOUNITTESTS",   "=", \@TESTPROJECT_TO_ARUN );
9867
 
4778 dpurdie 9868
MakeDefEntry( "AUTOUNITTESTS_PRE",    "=", \@TOOLSET_UTF_PRE );
9869
MakeDefEntry( "AUTOUNITTESTS_POST",   "=", \@TOOLSET_UTF_POST );
9870
MakeDefEntry( "AUTOUNITTESTS_COLLATE","=", \@TOOLSET_UTF_COLLATE );
9871
 
9872
 
261 dpurdie 9873
MakeHeader ("Toolset components");
9874
MakeDefEntry( "USERGENERATED",        "=", \@USERGENERATED )    if ( @USERGENERATED );
9875
MakeDefEntry( "TOOLSETGENERATED",     "=", \@TOOLSETGENERATED ) if ( @TOOLSETGENERATED );
9876
MakeDefEntry( "TOOLSETOBJS",          "=", \@TOOLSETOBJS )      if ( @TOOLSETOBJS );
9877
MakeDefEntry( "TOOLSETLIBS",          "=", \@TOOLSETLIBS )      if ( @TOOLSETLIBS );
9878
MakeDefEntry( "TOOLSETPROGS",         "=", \@TOOLSETPROGS )     if ( @TOOLSETPROGS );
9879
MakeDefEntry( "TOOLSETDIRS",          "=", \@TOOLSETDIRS )      if ( @TOOLSETDIRS );
9880
MakeDefEntry( "TOOLSETDIRTREES",      "=", \@TOOLSETDIRTREES )  if ( @TOOLSETDIRTREES );
227 dpurdie 9881
 
9882
#--------- Determine compiler flag groups to use ----------------------------
9883
#
9884
#   Allows the compiler options to be controlled for both the debug and
9885
#   the production builds. Allows control over
9886
#       1) Optimisations
9887
#       2) Debug Information
9888
#
9889
MakeHeader ("Determine compiler flag groups to use");
9890
 
9891
print MAKEFILE <<EOF;
9892
 
9893
ifneq "\$(DEBUG)" "1"
9894
USE_OPTIMISE	:= \$(PROD_USE_OPTIMISE)
9895
USE_DEBUGINFO	:= \$(PROD_USE_DEBUGINFO)
9896
else
9897
USE_OPTIMISE	:= \$(DEBUG_USE_OPTIMISE)
9898
USE_DEBUGINFO	:= \$(DEBUG_USE_DEBUGINFO)
9899
endif
9900
 
9901
EOF
9902
 
261 dpurdie 9903
#-------------------------------------------------------------------------------
9904
#   Source browsing tools
9905
#
9906
MakeHeader ("Source browsing tools");
9907
    print MAKEFILE <<EOF;
9908
.PHONY:			ctags
9909
ctags:
9910
EOF
9911
    $if->CTAGS()
9912
        if (@CSRCS || @CXXSRCS);
227 dpurdie 9913
 
261 dpurdie 9914
#-------------------------------------------------------------------------------
9915
#   Depend
9916
#   If we are build C or C++ source files then create rules and recipes
9917
#   to invoke a dependency generator.
227 dpurdie 9918
#
261 dpurdie 9919
#   NODEPEND is used to disable, at make-time, the dependency generation
9920
#   and inclusion process.
9921
#
9922
#
9923
MakeHeader ("Depend");
6133 dpurdie 9924
if ($::o && (@CSRCS || @CXXSRCS) && $ScmNotGeneric)
261 dpurdie 9925
{
9926
    $ScmDependTags = 1;
9927
    print MAKEFILE <<EOF;
9928
depend:			\$(OBJDIR)/depend
9929
 
9930
\$(OBJDIR)/depend:	\$(SCM_MAKEFILE) \$(GBE_OBJDIR)
9931
\$(OBJDIR)/depend:	\$(CSRCS) \$(CXXSRCS)
9932
ifeq (\$(NODEPEND),0)
6177 dpurdie 9933
	\@echo '[\$@] Doing a make depend..'
261 dpurdie 9934
	-\$(XX_PRE)\$(rm) -f \$(OBJDIR)/depend
9935
EOF
9936
    $if->CCDepend( "\$(OBJDIR)/depend", "\$(CSRCS)" )
9937
        if ( @CSRCS );
9938
    $if->CXXDepend( "\$(OBJDIR)/depend", "\$(CXXSRCS)" )
9939
        if ( @CXXSRCS );
9940
    MakePrint
9941
        "\t-\@\$(touch) -f \$(OBJDIR)/depend\n";
9942
    print MAKEFILE <<EOF;
9943
else
6177 dpurdie 9944
	\@echo '[\$@] Skipping make depend..'
261 dpurdie 9945
	-\$(XX_PRE)\$(rm) -f \$(OBJDIR)/depend
9946
endif
9947
EOF
9948
}
9949
else
9950
{
9951
    print MAKEFILE <<EOF;
9952
depend:
9953
EOF
9954
}
9955
 
9956
#
9957
#   Rule to unmake the depend file
2429 dpurdie 9958
#       No longer neeed.
9959
#       The file is deleted as a part of the OBJDIR cleanup
261 dpurdie 9960
#
9961
    print MAKEFILE <<EOF;
9962
 
9963
undepend:
9964
EOF
9965
 
9966
#--------- IFLAG Documentation -------------------------------------------------
9967
#
9968
#   IFLAG - iteration flag. This is setting by the calling process
9969
#                           and is a function of the phase being processed
227 dpurdie 9970
#       0   No external dependencies.
9971
#       1   Source dependency list.
261 dpurdie 9972
#       2   Shared library dependency list
9973
#       3   Application dependency list
227 dpurdie 9974
#
9975
#
261 dpurdie 9976
#--------- Dependencies --------------------------------------------------------
9977
#   Include the 'depend' file if required
9978
#
9979
    MakeHeader ("Dependency Inclusion");
9980
    print MAKEFILE <<EOF;
9981
ifeq (\$(NODEPEND),0)
9982
 ifdef IFLAG
9983
  ifneq "\$(IFLAG)" "0"
9984
-include	\$(OBJDIR)/depend
9985
  endif
227 dpurdie 9986
 endif
9987
endif
9988
 
9989
EOF
9990
 
9991
#-------------------------------------------------------------------------------
9992
#   Standard rules
9993
#
5991 dpurdie 9994
    MakeHeader ("Standard rules");
9995
    print MAKEFILE <<EOF;
373 dpurdie 9996
.PHONY:		make_clean
227 dpurdie 9997
make_clean:
9998
	-\@echo "Removing generated files (objects, libraries, binaries etc)";
9999
 
10000
.PHONY:		rmlitter
10001
rmlitter:
2429 dpurdie 10002
	-\$(AA_PRE)JatsFileUtil 'D0' 'Removing litter' '.' 'core' '*.bak' '*.tmp' '*.err'
227 dpurdie 10003
 
261 dpurdie 10004
.PHONY:		lint_init
10005
lint_init:
10006
 
227 dpurdie 10007
EOF
10008
 
261 dpurdie 10009
#
10010
#   Dependencies for 'make_init'
10011
#
10012
#
10013
my @initdep;
10014
push @initdep, '$(INITS)' if ( @INITS );
227 dpurdie 10015
 
261 dpurdie 10016
#
10017
#   Dependencies for 'make_dir'
10018
#
10019
my @mkdirdep;
289 dpurdie 10020
push @mkdirdep, '$(GBE_OBJDIR)' if ( @CSRCS || @CXXSRCS || @OBJS || @PROGOBJS || @TESTPROGOBJS );
261 dpurdie 10021
push @mkdirdep, '$(SHDIRS)'     if ( %SHOBJ_LIB || @SHLIBS);
10022
push @mkdirdep, '$(GBE_LIBDIR)' if ( @LIBS || @MLIBS || @SHLIBS || %INSTALL_LIBS || %PACKAGE_LIBS );
289 dpurdie 10023
push @mkdirdep, '$(GBE_BINDIR)' if ( @SHLIBS || %SCRIPTS || @PROGS || @TESTPROGS || %INSTALL_PROGS || %PACKAGE_PROGS );
227 dpurdie 10024
 
261 dpurdie 10025
#
10026
#   Actions for for 'unobj'
10027
#
10028
my @unobjact;
10029
push @unobjact, RmFilesCmd( 'OBJS' )            if ( @OBJS );
10030
push @unobjact, RmFilesCmd( 'SHOBJS' )          if ( %SHOBJ_LIB );
10031
push @unobjact, RmFilesCmd( 'PROGOBJS' )        if ( @PROGOBJS );
289 dpurdie 10032
push @unobjact, RmFilesCmd( 'TESTPROGOBJS' )    if ( @TESTPROGOBJS );
261 dpurdie 10033
push @unobjact, RmFilesCmd( 'TOOLSETOBJS' )     if ( @TOOLSETOBJS );
227 dpurdie 10034
 
261 dpurdie 10035
#
10036
#   Dependencies for 'make_lib'
10037
#
10038
my @libdep;
10039
push @libdep, '$(GBE_OBJDIR)', '$(GBE_LIBDIR)', '$(LIBS)' if ( @LIBS );
227 dpurdie 10040
 
261 dpurdie 10041
#
10042
#   Dependencies for 'lint_lib'
10043
#
10044
my @liblintdep;
10045
push @liblintdep, 'lint_init', '$(GBE_OBJDIR)', '$(GBE_LIBDIR)', '$(LINTLIBS)' if ( @LIBS );
227 dpurdie 10046
 
261 dpurdie 10047
#
10048
#   Dependencies for 'make_mlib'
10049
#
10050
my @mlibdep;
10051
push @mlibdep, '$(GBE_OBJDIR)', '$(GBE_LIBDIR)', '$(GBE_MLIBDIR)', '$(MLIBS)' if ( @MLIBS );
227 dpurdie 10052
 
261 dpurdie 10053
#
10054
#   Dependencies for 'make_install_shlib' (tag)
10055
#
10056
my @shlibdep;
10057
push @shlibdep, '$(SHDIRS)', '$(SHLIBS)' if ( @SHLIBS );
227 dpurdie 10058
 
261 dpurdie 10059
#
10060
#   Dependencies for 'lint_shlib'
10061
#
10062
my @shliblintdep;
10063
push @shliblintdep, 'lint_init', '$(GBE_LIBDIR)', '$(LINTSHLIBS)' if ( @SHLIBS );
227 dpurdie 10064
 
261 dpurdie 10065
#
10066
#   Actions for 'unmake_lib'
10067
#
10068
my @unlibact;
10069
push @unlibact, RmFilesCmd( 'SHLIBS' )      if ( @SHLIBS );
10070
push @unlibact, RmFilesCmd( 'MLIBS' )       if ( @MLIBS );
10071
push @unlibact, RmFilesCmd( 'LIBS' )        if ( @LIBS );
10072
push @unlibact, RmFilesCmd( 'TOOLSETLIBS' ) if ( @TOOLSETLIBS );
227 dpurdie 10073
 
261 dpurdie 10074
#
10075
#   Actions for 'unmake_mlib'
10076
#
10077
my @unmlibact;
10078
push @unmlibact, RmFilesCmd( 'MLIBS' ) if ( @MLIBS );
227 dpurdie 10079
 
261 dpurdie 10080
#
10081
#   Dependencies for 'make_script'
10082
#
10083
my @scriptdep;
10084
push @scriptdep, '$(GBE_BINDIR)', '$(SCRIPTS)' if ( %SCRIPTS );
227 dpurdie 10085
 
261 dpurdie 10086
#
10087
#   Actions for 'unmake_script'
10088
#
10089
my @unscriptact;
10090
push @unscriptact , RmFilesCmd( 'SCRIPTS' ) if ( %SCRIPTS );
10091
push @unscriptact , RmFilesCmd( 'COPYIN' )  if ( @COPYIN );
227 dpurdie 10092
 
261 dpurdie 10093
#
10094
#   Dependencies for 'make_prog'
10095
#
10096
my @progdep;
10097
push @progdep, '$(GBE_OBJDIR)', '$(GBE_BINDIR)', '$(PROGS)' if ( @PROGS );
10098
push @progdep, '$(PROGS_EXTRA)' if (@PROGS_EXTRA);
227 dpurdie 10099
 
261 dpurdie 10100
#
10101
#   Dependencies for 'make_prog' created for 'projects'
10102
#
10103
my @projectdep;
10104
push @projectdep, '$(PROJECTS)' if (ListGeneratedProjects(1) );
227 dpurdie 10105
 
261 dpurdie 10106
#
10107
#   Dependencies for 'generate' created for 'projects'
10108
#
10109
my @projectgendep;
10110
push @projectgendep, '$(PROJECTSGEN)' if (ListGeneratedProjects(0) );
227 dpurdie 10111
 
261 dpurdie 10112
#
10113
#   Dependencies for 'unmake_prog' created for 'projects'
10114
#
10115
my @projectcleandep;
10116
push @projectcleandep, '$(PROJECTSCLEAN)' if (%PROJECTS);
227 dpurdie 10117
 
261 dpurdie 10118
#
10119
#   Dependencies for 'lint_prog'
10120
#
10121
my @proglintdep;
289 dpurdie 10122
push @proglintdep, 'lint_init', '$(GBE_OBJDIR)', '$(GBE_BINDIR)', '$(LINTPROGS)' if ( @PROGS || @TESTPROGS );
227 dpurdie 10123
 
261 dpurdie 10124
#
10125
#   Actions for 'unmake_prog'
10126
#
10127
my @unprogact;
10128
push @unprogact, RmFilesCmd( 'PROGS' )        if ( @PROGS );
10129
push @unprogact, RmFilesCmd( 'TOOLSETPROGS' ) if ( @TOOLSETPROGS );
227 dpurdie 10130
 
261 dpurdie 10131
#
4728 dpurdie 10132
#   Dependencies for 'exec_tests'
261 dpurdie 10133
#
10134
my @testprogdep;
289 dpurdie 10135
push @testprogdep, '$(GBE_OBJDIR)', '$(GBE_BINDIR)', '$(TESTPROGS)' if ( @TESTPROGS );
227 dpurdie 10136
 
4501 dpurdie 10137
my @autoruntestdep;
10138
push @autoruntestdep, 'makefile.pl', '$(AUTOUNITTESTS)' if ( @TESTPROJECT_TO_ARUN );
10139
 
10140
my @runtestdep;
4996 dpurdie 10141
push @runtestdep    , 'makefile.pl', '$(UNITTESTS)' if ( @TESTPROJECT_TO_URUN );
4501 dpurdie 10142
 
227 dpurdie 10143
#
4728 dpurdie 10144
#   Dependencies for 'exec_tests' and friends
261 dpurdie 10145
#
10146
my @untestprogact;
289 dpurdie 10147
push @untestprogact ,RmFilesCmd( 'TESTPROGS' ) if ( @TESTPROGS );
227 dpurdie 10148
 
261 dpurdie 10149
#
10150
#   Dependencies for 'generated'
10151
#
10152
my @generatedep;
10153
push @generatedep, '$(GENERATED)' if ( @GENERATED );
10154
 
10155
#
10156
#   Actions for 'ungenerate'
10157
#
10158
my @ungenact;
10159
push @ungenact, RmFilesCmd( 'GENERATED' ) if ( @GENERATED );
10160
push @ungenact, RmFilesCmd( 'GENERATED_NOTSRC' ) if ( @GENERATED_NOTSRC );
10161
push @ungenact, RmFilesCmd( 'TOOLSETGENERATED' ) if ( @TOOLSETGENERATED );
10162
push @ungenact, RmFilesCmd( 'USERGENERATED' ) if ( @USERGENERATED );
10163
 
10164
#
10165
#   Dependencies for 'ungenerate'
10166
#
10167
my @ungeneratedep;
10168
push @ungeneratedep, '$(GENERATEDCLEAN)';
10169
 
227 dpurdie 10170
#-------------------------------------------------------------------------------
261 dpurdie 10171
# Function        : PrintPhonyRule
227 dpurdie 10172
#
261 dpurdie 10173
# Description     : Helper function to print some internal phony makefile targets
10174
#                   These are used to hold the basic makefile together
10175
#
10176
# Inputs          : $target         - Name of the phony target
10177
#                   $prereq         - Prerequisites
10178
#                                     Leading spaces removed
10179
#                   $recipe         - Optional Reference to an array of recipes
10180
#                                     Will be printed one per line
10181
#
10182
#
10183
sub PrintPhonyRule
227 dpurdie 10184
{
261 dpurdie 10185
    my ($target, $prereq, $recipe) = @_;
10186
    $prereq =~ s/^\s+//;
227 dpurdie 10187
 
261 dpurdie 10188
    MakePadded( 2, '.PHONY:', $target, "\n");
10189
    MakePadded( 2,"$target:", $prereq, "\n");
10190
    MakePrint ("\t\t" . $_ . "\n") foreach ( @{$recipe} );
10191
    MakePrint ("\n");
227 dpurdie 10192
}
10193
 
261 dpurdie 10194
#   make_init - Test toolset presence and sanity
10195
#   Will only be called ONCE for each platform in a recursive build
10196
#   Should be used to ensure that the required toolset is present
10197
#
4778 dpurdie 10198
PrintPhonyRule ('make_init',            "@initdep" );
227 dpurdie 10199
 
261 dpurdie 10200
#   make_dir    - Create required subdirectories
10201
#   Will be invoked as a part of most targets that create files
10202
#   Will be invoked by the calling wrappers
10203
#   Should not be invoked when cleaning
10204
#
4778 dpurdie 10205
PrintPhonyRule ('make_dir',             "@mkdirdep" );
261 dpurdie 10206
 
4778 dpurdie 10207
PrintPhonyRule ('generate',             "@generatedep @projectgendep" );
10208
PrintPhonyRule ('ungenerate',           "@ungeneratedep",  \@ungenact);
10209
PrintPhonyRule ('unobj',                "",  \@unobjact);
10210
PrintPhonyRule ('make_lib',             "@libdep" );
10211
PrintPhonyRule ('lint_lib',             "@liblintdep" );
10212
PrintPhonyRule ('make_mlib',            "@mlibdep" );
10213
PrintPhonyRule ('lint_shlib',           "@shliblintdep" );
10214
PrintPhonyRule ('unmake_lib',           "", \@unlibact );
10215
PrintPhonyRule ('unmake_mlib',          "", \@unmlibact );
10216
PrintPhonyRule ('make_script',          "@scriptdep" );
10217
PrintPhonyRule ('unmake_script',        "", \@unscriptact );
10218
PrintPhonyRule ('make_prog',            "make_script @progdep @projectdep" );
10219
PrintPhonyRule ('unmake_prog',          "unmake_script @projectcleandep", \@unprogact );
10220
PrintPhonyRule ('lint_prog',            "@proglintdep" );
10221
PrintPhonyRule ('exec_tests',           "make_script @testprogdep @runtestdep" );
10222
PrintPhonyRule ('exec_unit_tests',      "make_script @testprogdep @autoruntestdep" );
10223
PrintPhonyRule ('make_test',            "make_script @testprogdep" );
10224
PrintPhonyRule ('unmake_test',          "unmake_script", \@untestprogact );
10225
PrintPhonyRule ('preprocess_tests',     '$(AUTOUNITTESTS_PRE)' );
10226
PrintPhonyRule ('postprocess_tests',    '$(AUTOUNITTESTS_POST)' );
10227
PrintPhonyRule ('collate_test_results', '$(AUTOUNITTESTS_COLLATE)' );
261 dpurdie 10228
 
227 dpurdie 10229
#-------------------------------------------------------------------------------
10230
#   Package and Installation Summary
10231
#
10232
    MakeHeader ("Package and Installation Summary");
10233
    sub InstallTarget
10234
    {
10235
        my( $target, $hashp, $prereq, $fprereq ) = @_;
10236
        my( $element );
10237
 
5991 dpurdie 10238
        my $me = MakeEntry::New( *MAKEFILE, $target, '--Phony' );
10239
        $me->AddDependancy( $fprereq ) if ($fprereq);
227 dpurdie 10240
        foreach my $element ( sort keys %{$hashp} )
10241
        {
10242
            #
10243
            #   Skip placekeepers
10244
            #
10245
            next if ( $hashp->{$element}{'placekeeper'} );
10246
 
10247
            #
10248
            #   Prepend any prerequisites (once)
10249
            #
5991 dpurdie 10250
            $me->AddDependancy( $prereq ) if ( $prereq );
10251
            $prereq = 0;
227 dpurdie 10252
 
5991 dpurdie 10253
            $me->AddDependancyEscaped( $element );
227 dpurdie 10254
        }
5991 dpurdie 10255
        $me->Print();
10256
 
227 dpurdie 10257
    }
10258
 
10259
InstallTarget( "install_hdr",       \%INSTALL_HDRS );
10260
InstallTarget( "install_lib",       \%INSTALL_LIBS,  'make_mlib' );
261 dpurdie 10261
InstallTarget( "make_install_shlib",\%INSTALL_SHLIBS, '', "@shlibdep" );
227 dpurdie 10262
InstallTarget( "install_prog",      \%INSTALL_PROGS, 'make_script' );
10263
InstallTarget( "install_class",     \%INSTALL_CLSS );
10264
 
10265
InstallTarget( "package_files",     \%PACKAGE_FILES );
10266
InstallTarget( "package_hdr",       \%PACKAGE_HDRS );
10267
InstallTarget( "package_lib",       \%PACKAGE_LIBS );
10268
InstallTarget( "package_shlib",     \%PACKAGE_SHLIBS );
10269
InstallTarget( "package_prog",      \%PACKAGE_PROGS, 'make_script' );
10270
InstallTarget( "package_class",     \%PACKAGE_CLSS );
10271
 
10272
#-------------------------------------------------------------------------------
10273
#   Installations
10274
 
10275
MakeHeader ("Installations");
10276
PackageRule ( \&InstallCmd, \%INSTALL_HDRS  );
10277
PackageRule ( \&InstallCmd, \%INSTALL_CLSS  );
10278
PackageRule ( \&InstallCmd, \%INSTALL_LIBS  );
10279
PackageRule ( \&InstallCmd, \%INSTALL_SHLIBS  );
10280
PackageRule ( \&InstallCmd, \%INSTALL_PROGS  );
10281
 
10282
 
10283
#-------------------------------------------------------------------------------
10284
#   Packaging
10285
#
10286
MakeHeader ("Packaging");
10287
PackageRule ( \&PackageCmd, \%PACKAGE_FILES );
10288
PackageRule ( \&PackageCmd, \%PACKAGE_HDRS );
10289
PackageRule ( \&PackageCmd, \%PACKAGE_CLSS );
10290
PackageRule ( \&PackageCmd, \%PACKAGE_LIBS );
10291
PackageRule ( \&PackageCmd, \%PACKAGE_SHLIBS );
10292
PackageRule ( \&PackageCmd, \%PACKAGE_PROGS );
10293
 
10294
#-------------------------------------------------------------------------------
10295
#   Uninstall/unpackaging
10296
#
10297
MakeHeader ("Uninstall/unpackaging");
10298
 
10299
UnpackageRule( "uninstall_hdr",         \&UninstallCmd, \%INSTALL_HDRS );
10300
UnpackageRule( "uninstall_lib",         \&UninstallCmd, \%INSTALL_LIBS );
10301
UnpackageRule( "uninstall_shlib",       \&UninstallCmd, \%INSTALL_SHLIBS );
10302
UnpackageRule( "uninstall_prog",        \&UninstallCmd, \%INSTALL_PROGS );
10303
UnpackageRule( "uninstall_class",       \&UninstallCmd, \%INSTALL_CLSS );
10304
 
10305
UnpackageRule( "unpackage_files",       \&UnpackageCmd, \%PACKAGE_FILES );
10306
UnpackageRule( "unpackage_hdr",         \&UnpackageCmd, \%PACKAGE_HDRS );
10307
UnpackageRule( "unpackage_lib",         \&UnpackageCmd, \%PACKAGE_LIBS );
10308
UnpackageRule( "unpackage_shlib",       \&UnpackageCmd, \%PACKAGE_SHLIBS );
10309
UnpackageRule( "unpackage_prog",        \&UnpackageCmd, \%PACKAGE_PROGS );
10310
UnpackageRule( "unpackage_class",       \&UnpackageCmd, \%PACKAGE_CLSS );
10311
 
261 dpurdie 10312
#-------------------------------------------------------------------------------
267 dpurdie 10313
#   Distribution Sets
261 dpurdie 10314
#
267 dpurdie 10315
MakeHeader ("Distribution Sets");
10316
PackageSetRules();
10317
 
10318
#-------------------------------------------------------------------------------
10319
#
261 dpurdie 10320
#   Subdir deletion
10321
#   This is done AFTER the toolset functions have been invoked to create the
10322
#   build artifacts so that the toolsets can create directories too
10323
#
10324
#   Note: Toolset directories are deleted first
10325
#   Note: User Directories are deleted in the reverse order of creation
10326
#
2429 dpurdie 10327
#   Add them into the directory data structure
10328
#
10329
    foreach my $path ( @TOOLSETDIRS )
10330
    {
10331
        MkdirRule( $path, '', '--NoCreate' );
10332
    }
10333
 
10334
    foreach my $path ( @TOOLSETDIRTREES )
10335
    {
10336
        MkdirRule( $path, '', '--NoCreate' , '--RemoveAll');
10337
    }
10338
 
261 dpurdie 10339
    MakeHeader ("Subdir deletion");
10340
    RmdirRules();
10341
    MakeNewLine();
227 dpurdie 10342
 
261 dpurdie 10343
#--------- Toolset Rules -------------------------------------------------------
10344
    MakeHeader ("Toolset Rules");
10345
    MakePrintList ( \@TOOLSETRULES );
10346
 
10347
#--------- Maketags ------------------------------------------------------------
227 dpurdie 10348
 
10349
    Maketag( "make_init",           @INITS );
261 dpurdie 10350
    Maketag( "make_dir",            @mkdirdep );
10351
    Maketag( "generate",            @generatedep || @projectgendep || @USERGENERATED || ($ScmToolsetGenerate != 0) );
227 dpurdie 10352
    Maketag( "depend",              $ScmDependTags != 0 );
261 dpurdie 10353
    Maketag( "make_lib",            @libdep );
10354
    Maketag( "make_mlib",           @mlibdep );
10355
    Maketag( "make_install_shlib",  %INSTALL_SHLIBS || @shlibdep);
10356
    Maketag( "make_script",         @scriptdep );
10357
    Maketag( "make_prog",           @progdep || @projectdep );
10358
    Maketag( "make_test",           @testprogdep );
4996 dpurdie 10359
    Maketag( "exec_tests",          $TESTS_TO_RUN     || @TESTPROJECT_TO_URUN );
4728 dpurdie 10360
    Maketag( "exec_unit_tests",     $TESTS_TO_AUTORUN || @TESTPROJECT_TO_ARUN );
4778 dpurdie 10361
    Maketag( "process_tests",       @TOOLSET_UTF_PRE || @TOOLSET_UTF_POST || @TOOLSET_UTF_COLLATE);
227 dpurdie 10362
    Maketag( "install_hdr",         %INSTALL_HDRS );
10363
    Maketag( "install_class",       %INSTALL_CLSS );
10364
    Maketag( "install_lib",         %INSTALL_LIBS );
10365
    Maketag( "install_prog",        %INSTALL_PROGS );
10366
    Maketag( "deploy",              %DEPLOYPACKAGE );
10367
    Maketag( "package",             %PACKAGE_FILES || %PACKAGE_HDRS || %PACKAGE_CLSS ||
10368
                                    %PACKAGE_LIBS || %PACKAGE_SHLIBS || %PACKAGE_PROGS );
10369
 
261 dpurdie 10370
    #
10371
    #   Display tags in the MAKEFILE
4778 dpurdie 10372
    #       Not used here - just for show
261 dpurdie 10373
    #
10374
    MakeHeader ("Maketags");
10375
    foreach my $tag ( sort keys %MakeTags )
10376
    {
4778 dpurdie 10377
        MakePadded( 3, "#   $tag:", '1', "\n");
261 dpurdie 10378
    }
10379
 
227 dpurdie 10380
#-------------------------------------------------------------------------------
10381
#   End of Makefile
10382
#
10383
    MakeHeader ("End of Makefile");
10384
    close( MAKEFILE );
10385
 
10386
#
10387
#   Save all platform information
10388
#   Done after the makefile is written as toolsets can extend the data
10389
#
10390
    WriteParsedConfig();
10391
 
10392
#
10393
#   Write out any accumulated DPACKAGE data
10394
#
10395
    JatsDPackage::DPackageSave();
10396
 
10397
    return 0;
10398
}
10399
 
10400
#-------------------------------------------------------------------------------
387 dpurdie 10401
# Function        : QuoteForMake
10402
#
10403
# Description     : Escape/Quote a pathname for make
10404
#                       Allow files with a $ in the name
10405
#                       Allow files with a space in the name
10406
#                       Allow files with a comma in the name
10407
#                       Allow for paths that have make-varible prefixes
6073 dpurdie 10408
#                           $(GBE_...) or ${GBE_...} or $(OBJDIR)
387 dpurdie 10409
#                           as these may be generated internally
5991 dpurdie 10410
#                       Allow for files with a colon in the name
10411
#                           Mode dependent
10412
#                               0 - No effect
10413
#                               T - \\\:
10414
#                               S = \:    
387 dpurdie 10415
#
399 dpurdie 10416
#                       Must also allow $(GBE_TYPE) in the remainder
10417
#
5991 dpurdie 10418
# Inputs          : uarg            - Arg to quote
10419
#                   mode            - Mode of operation
10420
#                                     T - Makefile target
10421
#                                     S - Makefile source
10422
#                                     0 - Neither
387 dpurdie 10423
#
10424
# Returns         : Quoted arg
10425
#
10426
 
5991 dpurdie 10427
sub QuoteForMake($;$)
387 dpurdie 10428
{
5991 dpurdie 10429
    my ($uarg, $mode) = @_;
10430
    $mode = '0' unless defined $mode;
387 dpurdie 10431
 
10432
    #
10433
    #   Split into two
10434
    #       $(xxx)/             - Makefile variables
10435
    #       Remainder           - Stuff to quote
10436
    #
10437
    $uarg =~ m~^((\$\(.*?\)/)*)(.*)~;
10438
    my $prefix = defined $1 ? $1 : '';
10439
    my $arg    = defined $3 ? $3 : '';
10440
 
6073 dpurdie 10441
    $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 10442
    $arg =~ s~ ~\\ ~g;
10443
    $arg =~ s~,~\$(comma)~g;
2764 dpurdie 10444
    $arg =~ s~%~\\%~g;
5999 dpurdie 10445
    $arg =~ s~:~\\\\\\:~g if ($mode eq 'T' &&  $::ScmHost eq "Unix");
10446
    $arg =~ s~:~\\:~g     if ($mode eq 'S' &&  $::ScmHost eq "Unix");
387 dpurdie 10447
    return $prefix . $arg;
10448
}
10449
 
10450
#-------------------------------------------------------------------------------
227 dpurdie 10451
# Function        : Maketag
10452
#
10453
# Description     : Create Makefile tags to speed up recursive makes
10454
#
10455
# Inputs          : tag_name
10456
#                   dep
10457
#
10458
# Returns         : 
10459
#
10460
sub Maketag
10461
{
10462
    my( $tag, $dep ) = @_;
10463
    $MakeTags{$tag} = 1 if ( defined($dep) && $dep );
10464
}
10465
 
10466
#-------------------------------------------------------------------------------
10467
#   Function to create and delete directories within the build system
10468
#
10469
#    To stop make regenerating directory dependent targets each time the
10470
#    directory content is modified, rule should only be dependent on a internally
10471
#    created alias file 'gbedir', which represents the time a dir was created not
10472
#    last modified.
10473
#
10474
#    Must use tags like GBE_BINDIR, GBE_LIBDIR and GBE_OBJDIR to ensure that the
10475
#    directories are created correctly.
10476
#
10477
my %MkdirRuleData;
10478
my @MkdirRuleOrder;
10479
my $MkdirRulePrinting = 0;
10480
my $MkdirRuleGbeFile = ( $::ScmHost eq "Unix" ) ? ".gbedir" : "_gbedir";
10481
 
10482
#-------------------------------------------------------------------------------
10483
# Function        : MkdirRule
10484
#
10485
# Description     : Create Rules and Recipes to create a directory at make-time
10486
#                   Mark the information for such that the directories will
10487
#                   be deleted in a 'clean'
10488
#
10489
#                   Can be called before we start writing the makefile
10490
#                   Such entries will be retained and dumped at a known time
10491
#
10492
# Inputs          : $subdir     - Symbolic name of the subdir $(OBJDIR)
10493
#                   $alias      - Optional script alias for the dir 'OBJDIR' --> GBE_OBJDIR
10494
#                   Options:
2429 dpurdie 10495
#                       --Path=path             Optional value of $subdir '$(GBE_PLATFORM)$(GBE_TYPE).OBJ'
10496
#                       --RemoveAll             Remove all files on clean
6177 dpurdie 10497
#                       --Extra=file[,file]     Additional files to remove
2429 dpurdie 10498
#                       --NoCreate              Do not Create the Directory, just delete it
227 dpurdie 10499
#
10500
# Returns         : Nothing
10501
#
10502
 
10503
sub MkdirRule
10504
{
10505
    my( $subdir, $alias, @opts ) = @_;
10506
 
10507
    #
10508
    #   Create data entry once
10509
    #
10510
    $alias =~ s~^GBE_~~ if $alias;
10511
    unless ( $MkdirRuleData{$subdir}  )
10512
    {
10513
        my %data;
10514
 
10515
        #
10516
        #   Parse options
10517
        #
10518
        foreach ( @opts )
10519
        {
10520
            if ( /^--Path=(.+)/ ) {
10521
                $data{path} = $1;
10522
            } elsif ( /^--RemoveAll/ ) {
10523
                $data{remove_all} = 1;
2429 dpurdie 10524
            } elsif ( /^--NoCreate/ ) {
10525
                $data{noCreate} = 1;
10526
            } elsif ( /^--Extra=(.+)/ ) {
10527
                @{$data{extraFiles}} = split(/,/, $1);
227 dpurdie 10528
            } else {
10529
                Error ("MkdirRule: Unknown option: $_");
10530
            }
10531
        }
10532
        $data{alias} = $alias if ( $alias );
10533
 
10534
        $MkdirRuleData{$subdir} = \%data;
10535
        push @MkdirRuleOrder, $subdir;
10536
    }
10537
 
10538
    #
10539
    #   Save or print
10540
    #
10541
    return unless ( $MkdirRulePrinting );
2429 dpurdie 10542
    return if ( $MkdirRuleData{$subdir}{noCreate} );
227 dpurdie 10543
 
10544
    #
10545
    #   Create a definition of the physical directory
10546
    #
10547
    my $path = $MkdirRuleData{$subdir}{path};
261 dpurdie 10548
    MakePadded (2, $alias, ":= $path\n") if ( $path && $alias );
227 dpurdie 10549
 
10550
    #   Create an alias to be used within rules
10551
    #   The defined aliase will be prefixed with 'GBE_'
10552
    #
261 dpurdie 10553
    MakePadded (2, "GBE_$alias", ":= $subdir/$MkdirRuleGbeFile\n") if ( $alias );
227 dpurdie 10554
 
10555
    #
10556
    #   Create a recipe to create the directory
10557
    #   This is not as simple as it sounds
10558
    #   The touch is required.
10559
    #       Had 'timestamp' issues on solaris'. The 'echo' did not appear
10560
    #       to be enough. Perhaps the output was not flushed
10561
    #
261 dpurdie 10562
    MakePadded (2, "$subdir", ": $subdir/$MkdirRuleGbeFile\n");
227 dpurdie 10563
    MakePrint
10564
        "$subdir/$MkdirRuleGbeFile:\n".
10565
        "\t\$(XX_PRE)if [ ! -d $subdir ]; then \$(mkdir) -p $subdir; fi; \\\n".
10566
        "\t\$(echo) '# DO NOT REMOVE.' > \$@; \\\n".
10567
        "\t\$(touch) \$@\n\n";
10568
}
10569
 
10570
#-------------------------------------------------------------------------------
10571
# Function        : RmdirRules
10572
#
2429 dpurdie 10573
# Description     : Create the body of a recipe to delete the directories that
227 dpurdie 10574
#                   have been created.
10575
#
2429 dpurdie 10576
#                   Use JatsFileUtil rather than shell script
10577
#                       Faster under windows (and others)
10578
#                       Solved long pathname issues
10579
#                       Simpler to use and control
227 dpurdie 10580
#
10581
# Inputs          : Uses $MkdirRuleData
10582
#
10583
# Returns         : Nothing.
10584
#                   Prints to the makefile
10585
#
10586
sub RmdirRules
10587
{
2429 dpurdie 10588
    MakePrint( ".PHONY:\tunmake_dir\n" );
10589
    MakePrint( "unmake_dir:\n" );
10590
 
227 dpurdie 10591
    #
10592
    #   Determine the list of directories to delete
2429 dpurdie 10593
    #   Sort such that subdirs are deleted first
227 dpurdie 10594
    #
2429 dpurdie 10595
    my $txt = 'Removing directories';
227 dpurdie 10596
    foreach my $subdir ( reverse sort keys %MkdirRuleData )
10597
    {
2429 dpurdie 10598
        my @args = $subdir;
10599
 
5816 dpurdie 10600
        push (@args, $MkdirRuleGbeFile, 'core', '*.bak', '*.tmp', '*.err', 'utf.*.rc')
2429 dpurdie 10601
            unless $MkdirRuleData{$subdir}{remove_all};
10602
 
10603
        push (@args, @{$MkdirRuleData{$subdir}{extraFiles}})
10604
            if ( $MkdirRuleData{$subdir}{extraFiles} );
10605
 
10606
        my $mode = $MkdirRuleData{$subdir}{remove_all} ? 'T0' : 'D0';
10607
 
10608
        MakePrint ("\t-\$(AA_PRE)JatsFileUtil ", QuoteArray( $mode, $txt, @args ), "\n");
10609
        $txt = '';
227 dpurdie 10610
    }
10611
}
10612
 
10613
#-------------------------------------------------------------------------------
10614
# Function        : CreateMkdirRules
10615
#
10616
# Description     : Create Rules to make dirs at runtime
10617
#                   This function is called to instantiate those entries
10618
#                   That have been requested before the makefile has has
10619
#                   started to be created.
10620
#
10621
#                   Once this function has been called all new MkdirRule calls
10622
#                   will result in the recipes being created in-line.
10623
#
10624
# Inputs          : Nothing
10625
#
10626
# Returns         : Even Less
10627
#
10628
#
10629
sub CreateMkdirRules
10630
{
10631
    $MkdirRulePrinting = 1;
10632
    foreach my $subdir ( @MkdirRuleOrder )
10633
    {
10634
        my $data = $MkdirRuleData{$subdir};
10635
        MkdirRule($subdir, $data->{alias}, $data->{path} );
10636
    }
10637
}
10638
 
10639
#-------------------------------------------------------------------------------
10640
# Function        : PackageRule
10641
#
10642
# Description     : Generate rules and recipes to "install" and "package" files
10643
#
10644
# Inputs          : codecmd     - A code reference to the actual installer routine
10645
#                   hashp       - A reference to a INSTALL or PACKAGE hash
10646
#
299 dpurdie 10647
#                   hashp is a reference to a hash
227 dpurdie 10648
#                       The key is the full path of the install target
10649
#                       The value is (another) hash that describes the install options
10650
#
10651
#                   Valid keys are:
10652
#                       src                 - Path of the source file [Mandatory]
10653
#                       dir                 - Target directory [Mandatory]
10654
#
10655
#                       defined             - Copy the file only if value is defined
4382 dpurdie 10656
#                       Exists              - Copy the file only if it exists
227 dpurdie 10657
#                       exe                 - Mark the file as executable
10658
#                       Mode                - File modes. Default is -w
10659
#                       placekeeper         - Marks SHARED library placekeepers
10660
#                       set                 - Distribution sets
10661
#                       type                - Copy the file in DEBUG or PROD mode
10662
#                                             Valid values are "D" or "P"         
10663
#                       version             - Shared library version information
5882 dpurdie 10664
#                       symlink             - File is a symlink
227 dpurdie 10665
#                       RemoveOnly          - Do not install the file. Entries are
10666
#                                             created to allow the removal of the file
4382 dpurdie 10667
#                       NoTarget            - Reserved - Implemented elsewhere
227 dpurdie 10668
#
10669
# Returns         :
10670
#
10671
sub PackageRule
10672
{
10673
    my ($codecmd, $hashp) = @_;
10674
 
10675
    foreach my $dest ( keys %{$hashp} )
10676
    {
10677
 
10678
        my $entry = $hashp->{$dest};
5991 dpurdie 10679
        my $destText = QuoteForMake($dest,'T');
227 dpurdie 10680
        #
10681
        #   Skip placekeepers
10682
        #
10683
        next if ( $entry->{'placekeeper'} );
10684
 
10685
        #
10686
        #   Some entries are not installed via this mechanism, but can be removed
10687
        #   if they exist. Mark these as PHONY to keep targets happy
10688
        #
10689
        if ( $entry->{'RemoveOnly'} )
10690
        {
5991 dpurdie 10691
            MakePrint ".PHONY:\t$destText\n";
10692
            MakePrint "$destText:\n\n";
227 dpurdie 10693
            next;
10694
        }
10695
 
10696
        my $fname = $entry->{'src'};
5991 dpurdie 10697
        my $fnameText = QuoteForMake($fname,'S');
227 dpurdie 10698
        my $fmode = $entry->{'Mode'};
10699
        $fmode .= "+x" if ( $entry->{'exe'}  );
5882 dpurdie 10700
        $fmode .= "+l" if ( $entry->{'symlink'}  );
227 dpurdie 10701
 
10702
        #
10703
        #   User conditionional
10704
        #   Mark both the source and the target as PHONY if the condition is not met
10705
        #   This will ensure that the target need not be built.
10706
        #
10707
        my $udef = $entry->{'defined'};
10708
        if ( $udef )
10709
        {
10710
            MakePrint "ifndef $udef \n";
5991 dpurdie 10711
            MakePrint ".PHONY:\t\t$destText\n";
10712
            MakePrint ".PHONY:\t\t$fnameText\n";
10713
            MakePrint "$destText:\n";
227 dpurdie 10714
            MakePrint "else\n"
10715
        }
10716
 
10717
        #
4382 dpurdie 10718
        #   File exists
10719
        #   Only package the file if it has been generated. ie: .exe.manifest
10720
        #
10721
        my $fexist = $entry->{'Exists'};
10722
        if ($fexist)
10723
        {
5991 dpurdie 10724
            MakePrint "ifeq (\"\$(wildcard $fnameText)\",\"\")\n";
10725
            MakePrint ".PHONY:\t\t$destText\n";
10726
            MakePrint "$destText:\n";
4382 dpurdie 10727
            MakePrint "else\n"
10728
        }
10729
 
10730
        #
227 dpurdie 10731
        #   Conditional installation for DEBUG/PRODUCTION
10732
        #
10733
        my $type = $entry->{'type'};
10734
        if ( $type )
10735
        {
10736
            if ( $type eq "D" ) {
10737
                MakePrint 'ifeq "$(DEBUG)" "0"'."\n";
10738
            } elsif ( $type eq "P" ) {
10739
                MakePrint 'ifneq "$(DEBUG)" "0"'."\n";
10740
            } else {
10741
                Error("INTERNAL: Unexpected packaging type: $type");
10742
            }
5991 dpurdie 10743
            MakePrint ".PHONY:\t\t$destText\n";
10744
            MakePrint "$destText:\n";
227 dpurdie 10745
            MakePrint "else\n"
10746
        }
10747
 
10748
        #
10749
        #   The body of the copy
10750
        #
5991 dpurdie 10751
        MakePadded( 4, $destText . ':' );
10752
        MakePrint "\t" . $fnameText . "\n";
2429 dpurdie 10753
        MakePrint $codecmd->( $dest, $fname, $fmode );
227 dpurdie 10754
        MakeNewLine();
10755
 
10756
        #
10757
        #   Unwind conditionals
10758
        #
10759
        MakePrint "endif\n" if ( $type );
4382 dpurdie 10760
        MakePrint "endif\n" if ( $fexist );
227 dpurdie 10761
        MakePrint "endif\n" if ( $udef );
10762
 
10763
        #
10764
        #   Distribution sets
10765
        #
10766
        my $dist = $entry->{'set'};
10767
        if ( $dist )
10768
        {
267 dpurdie 10769
            foreach my $set ( split( ',', $dist ) )
10770
            {
10771
                push @{$PACKAGE_SETS{$set}{LIST}}, $dest;
227 dpurdie 10772
            }
10773
            MakeNewLine();
10774
        }
10775
    }
10776
}
10777
 
10778
#-------------------------------------------------------------------------------
267 dpurdie 10779
# Function        : PackageSetRules
10780
#
10781
# Description     : Generate the packageset rules
10782
#                   These appear to be a now-defuct feature
10783
#
10784
#                   By default all packaged files are a part of package_setALL
10785
#
10786
# Inputs          : None
10787
#                   Takes data from %PACKAGE_SET
10788
#
10789
# Returns         : Nothing
10790
#
10791
sub PackageSetRules
10792
{
10793
    foreach my $set ( sort keys %PACKAGE_SETS )
10794
    {
10795
        my $me = MakeEntry::New( *MAKEFILE, "package_set$set", '--Phony' );
5991 dpurdie 10796
        $me->AddDependancyEscaped( @{$PACKAGE_SETS{$set}{LIST}} );
267 dpurdie 10797
        $me->Print();
10798
    }
10799
}
10800
 
10801
#-------------------------------------------------------------------------------
227 dpurdie 10802
# Function        : UnPackageRule
10803
#
10804
# Description     : Generate rules and recipes to "uninstall" and "unpackage" files
10805
#
10806
# Inputs          : target      - Name of the target
10807
#                   codecmd     - A code reference to the actual installer routine
10808
#                   hashp       - A reference to a INSTALL or PACKAGE hash
10809
#
10810
# Returns         :
10811
#
10812
sub UnpackageRule
10813
{
10814
    my ($target, $codecmd, $hashp) = @_;
10815
 
10816
    MakePrint ".PHONY:\t\t"."$target\n";
10817
    MakePrint "$target:\t";
10818
 
10819
    foreach my $dest ( sort keys %{$hashp} )
10820
    {
10821
 
10822
        my $entry = $hashp->{$dest};
10823
 
10824
        #
10825
        #   Skip placekeepers
10826
        #
10827
        next if ( $entry->{'placekeeper'} );
10828
 
10829
        MakePrint "\n" . $codecmd->($dest);
10830
    }
10831
    MakePrint "\n\n";
10832
}
10833
 
10834
 
10835
#
10836
#   Internal macro interface, see RULE.STD for definitions:
10837
#
10838
sub RmFilesCmd
10839
{
10840
    my ( $list ) = @_;
261 dpurdie 10841
    return "\$(call RmFiles,$list)";
227 dpurdie 10842
}
10843
 
10844
sub InstallCmd
10845
{
2429 dpurdie 10846
    my( $dest, $file, $fmode ) = @_;
227 dpurdie 10847
 
10848
    $fmode = "-w"                           # default, read-only
10849
        if ( !defined( $fmode ) || $fmode eq "" );
10850
 
5991 dpurdie 10851
    $dest = QuoteForMake($dest);
10852
    $file = QuoteForMake($file);
2429 dpurdie 10853
    return "\t\$(call InstallFile,$dest,$file,$fmode)";
227 dpurdie 10854
}
10855
 
10856
sub UninstallCmd
10857
{
10858
    my( $file ) = @_;
5991 dpurdie 10859
    $file = QuoteForMake($file);
227 dpurdie 10860
    return "\t\$(call UninstallFile,$file)";
10861
}
10862
 
10863
sub PackageCmd
10864
{
2429 dpurdie 10865
    my( $dest, $file, $fmode ) = @_;
227 dpurdie 10866
 
10867
    $fmode = "-w"                           # default, read-only
10868
        if ( !defined( $fmode ) || $fmode eq "" );
10869
 
5991 dpurdie 10870
    $dest = QuoteForMake($dest);
10871
    $file = QuoteForMake($file);
2429 dpurdie 10872
    return "\t\$(call PackageFile,$dest,$file,$fmode)";
227 dpurdie 10873
}
10874
 
10875
sub UnpackageCmd
10876
{
10877
    my( $file ) = @_;
5991 dpurdie 10878
    $file = QuoteForMake($file);
227 dpurdie 10879
    return "\t\$(call UnpackageFile,$file)";
10880
}
10881
 
10882
1;
10883