Subversion Repositories DevTools

Rev

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

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