Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
5708 dpurdie 1
##############################################################################
6177 dpurdie 2
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
227 dpurdie 3
#
4
# Module name   : makelib.pl2
5
# Module type   : Makefile system
6
#
7
# Description:
8
#       This modules builds the platform definition makefiles(s)
9
#
10
# Notes:                *** DO NOT DETAB ***
11
#       Beware the use of space v's tab characters within the
12
#       makefile generation sessions.
13
#
14
##############################################################################
15
# Globals:
16
#  $ScmVersion          Makelib.pl2 version
17
#  $ScmRoot             Command line parameter that gives the root directory
18
#                       location for this directory tree.
19
#  $ScmMakelib          Command line parameter that points to the location
20
#                       of THIS script.  ie. location of makelib.pl.
21
#  $ScmPlatform         Current platform
22
#  $ScmProduct          Current product (if any)
23
#  $ScmTarget           Resulting target (derived from Platform)
24
#  @ScmPlatformArgs     Platform arguments
25
#  $ScmToolset          Toolset
26
#  @ScmToolsetArgs      Toolset arguments
27
#  $ScmDebug            Debug level
28
#  $ScmVerbose          Verbose setting
29
#  $ScmSourceTypes      Source types, aliasing for C, C++ and assembler
30
#                       source.
31
#  @CFLAGS              List containing all of the defined C flags
32
#  @CXXFLAGS            List containing all of the defined C++ flags
33
#  @ASFLAGS             List containing all of the defined assembler flags
34
#  @CLINTFLAGS          List containing all of the defined C lint flags
35
#  @CXXLINTFLAGS        List containing all of the defined C++ lint flags
36
#  @{G|L}_INCDIRS       List containing all of include paths
37
#  @{G|L}_SRCDIRS       List containing all of source search paths
38
#  @{G|L}_LIBDIRS       List containing all of library search paths
39
#  @LDFLAGS             List containing all of the defined linker flags
40
#  @SRCS                List of ALL source files. ie. C/C++ and other (eg .x)
41
#                       Key is source file, value is source path
42
#  @OBJS                List of ALL (non-shared) object files.
289 dpurdie 43
#  %SHOBJ_LIB           List of ALL shared library object files and associated library.
227 dpurdie 44
#  %OBJSOURCE           List of ALL object files
45
#                       from that should result from later makes.
46
#                       Key is objectfile, value is source file
47
#  %OBJREFS             List of ALL object files, built options.
48
#  @PROGOBJS            List of ALL application object files.
49
#  %SRC_ARGS            List of arguments that are to be used when making the
50
#                       nominated source.  Key is the source name, the
51
#                       value is a string of arguments to apply.  The
52
#                       arguments are '$;' separated.
53
#  %SRC_TYPE            Source file type (user override).
54
#  @CHDRS               List of C header files.
55
#  @CSRCS               List of C files
56
#                       Key is objectfile, value is source file
57
#  @CXXSRCS             List of C++ files
58
#  @ASHDRS              List of assembler include files (.inc)
59
#  @ASSRCS              List of assembler source files
60
#  @GENERATED           List of files that should result from a 'generate'
61
#                       make rule.  The programmer is expected to provide
62
#                       the necessary rule(s).
63
#  @RULES               List of additional make rules the programmer
64
#                       has specified to be included in the make.
65
#  %INSTALL_HDRS        List of headers that are to be installed for later
66
#                       "public" consumption.
67
#  %INSTALL_CLSS        List of Java classes or JAR files that are to be installed
68
#                       for later "public" consumption.
69
#  @LIBS                List of libraries that are to be built.
289 dpurdie 70
#  $LIBS                Ref to a collection of static library descriptors
71
#                       Indexed by lib name
227 dpurdie 72
#  %INSTALL_LIBS        List of libraries that are to be installed for later
73
#                       public consumption.
74
#  @MLIBS               List of libraries that are to be built via merging
289 dpurdie 75
#  $MLIBS               Ref to a collection of merged lib descriptors
227 dpurdie 76
#  @SHLIBS              List of shared libraries that are to be built.
289 dpurdie 77
#  $SHLIBS              Ref to collection of shared library information
227 dpurdie 78
#  %INSTALL_SHLIBS      List of libraries that are to be installed for later
79
#                       public consumption.
80
#  @PROGS               List of programs (binary executables) that are
81
#                       to be built
289 dpurdie 82
#  $PROGS               Ref to collection of program information
227 dpurdie 83
#  %SCRIPTS             List of scripts to 'create' (key) and whether they
84
#                       should be made executable or not (value).  Script
85
#                       set to executable is denoted by the value being
86
#                       defined AND true.
87
#  %INSTALL_PROGS       List of programs for "public" cosumption to install
88
#                       where (key) is the file and where to install it
89
#                       to vs. (value) which is composed of the original
90
#                       location of the file, the destination directory
91
#                       and a list of service providers this file applies to.
92
# $ProjectBase          Base of the user's project. This variable is designed to
93
#                       be used by the user.
94
#....
95
 
255 dpurdie 96
require 5.006_001;
227 dpurdie 97
use strict;
98
use warnings;
261 dpurdie 99
use Getopt::Long;
227 dpurdie 100
use Data::Dumper;
271 dpurdie 101
use JatsError;
227 dpurdie 102
use JatsEnv;
103
use MakeEntry;
104
use JatsLocateFiles;
105
use JatsDPackage;
271 dpurdie 106
use MakeIf;
289 dpurdie 107
use ToolsetPrinter;
108
use MakeObject;
339 dpurdie 109
use JatsVersionUtils;
6133 dpurdie 110
use ToolsetFiles;
227 dpurdie 111
 
112
 
113
our $ScmVersion             = "2.34";
114
our $ScmGlobal              = 0;
115
our $ScmExpert              = 0;
116
our $ScmInterface           = "interface";      # default 'interface'
117
our $ScmPackage             = 1;                # package active by default.
118
our $ScmProcessingRootMake  = 0;                # Processing root makefile.pl
119
our $ScmPlatformSeen        = 0;                # Platform directive has been seen
6133 dpurdie 120
my  $ScmNotGeneric          = 1;                # Not a generic build
227 dpurdie 121
 
122
our $ScmToolsetVersion      = "";               # version of toolset
123
our $ScmToolsetGenerate     = 1;                # generate active by default.
124
our $ScmToolsetProgDependancies = 1;            # 1: Write program dependancies
125
                                                # 0: Don't write progdeps. Prog is Phony
289 dpurdie 126
our $ScmToolsetSingleType   = 0;                # Toolset does not support Debug and Production
227 dpurdie 127
our $ScmToolsetProgSource   = ();               # Toolset Program Source
339 dpurdie 128
our $ScmToolsetSoName       = 0;                # 1: Shared library supports SoName
363 dpurdie 129
our $ScmToolsetNillLibSrc   = 0;                # 1: Librarys created without source specified
5411 dpurdie 130
our %ScmToolsetProperties   = ();               # Toolset specific features and limitations
131
                                                # Known values: UnitTests, AutoUnitTests
6415 dpurdie 132
our %ScmGlobalOptions       = ();               # Hash of Global(platform) options. Access via functions
133
our %ScmRecipeTags          = ();               # Hash of exposed recipe names
363 dpurdie 134
 
227 dpurdie 135
our $ScmRoot                = "";
136
our $ScmMakelib             = "";
137
our $ScmPlatform            = "";
138
our $ScmMachType            = "";
139
our $ScmSrcDir              = "";
140
our @ScmPlatformDirs        = ();
141
our @ScmPlatformArgs        = ();
289 dpurdie 142
our $ScmBuildType           = 0;                # 0, P, D. 0 == P and D
227 dpurdie 143
our $ScmProduct             = "";
144
our $ScmTarget              = "";
145
our $ScmTargetHost          = "";
146
our $ScmToolset             = "";
147
our @ScmToolsetArgs         = ();
148
our @ScmDepends             = ();
149
our %ScmSourceTypes         = ();
150
our $ScmDeploymentPatch     = "";
151
our $ProjectBase            = "";               # Base of the user's project
152
our $ScmNoToolsTest         = "";               # Supress compiler tests
153
our $ScmDependTags          = 0;                # Create dependancy scanning tag
4781 dpurdie 154
our $ScmMakeUid;                                # Unique makefile id (number 1 .. )
227 dpurdie 155
 
156
our @CFLAGS                 = ();
157
our @CFLAGS_DEBUG           = ();
158
our @CFLAGS_PROD            = ();
159
our @CLINTFLAGS             = ();
160
our @CLINTFLAGS_DEBUG       = ();
161
our @CLINTFLAGS_PROD        = ();
162
our @CXXFLAGS               = ();
163
our @CXXFLAGS_DEBUG         = ();
164
our @CXXFLAGS_PROD          = ();
165
our @CXXLINTFLAGS           = ();
166
our @CXXLINTFLAGS_DEBUG     = ();
167
our @CXXLINTFLAGS_PROD      = ();
168
our @ASFLAGS                = ();
267 dpurdie 169
our @ASFLAGS_DEBUG          = ();
170
our @ASFLAGS_PROD           = ();
227 dpurdie 171
our @LDFLAGS                = ();
267 dpurdie 172
our @LDFLAGS_DEBUG          = ();
173
our @LDFLAGS_PROD           = ();
227 dpurdie 174
 
175
our @INCDIRS                = ();
176
our @NODEPDIRS              = ();
177
our @S_INCDIRS              = ();
178
our @G_INCDIRS              = ();
179
our @L_INCDIRS              = ();
180
our @SRCDIRS                = ();
181
our @S_SRCDIRS              = ();
182
our @G_SRCDIRS              = ();
183
our @L_SRCDIRS              = ();
184
our @LIBDIRS                = ();
185
our @S_LIBDIRS              = ();
186
our @G_LIBDIRS              = ();
187
our @L_LIBDIRS              = ();
188
 
189
our %SRCS                   = ();
190
our %SRC_ARGS               = ();
191
our %SRC_TYPE               = ();
192
our %SRC_DEPEND             = ();
193
our %SCRIPTS                = ();
194
our @COPYIN                 = ();
195
our @INITS                  = ();
196
our @DEFINES                = ();
197
our @OBJS                   = ();
198
our %SHOBJ_LIB              = ();
199
our @PROGOBJS               = ();
289 dpurdie 200
our @TESTPROGOBJS           = ();
227 dpurdie 201
our %OBJSOURCE              = ();
202
our @CHDRS                  = ();
203
our @CSRCS                  = ();
204
our @CXXSRCS                = ();
205
our @ASHDRS                 = ();
206
our @ASSRCS                 = ();
207
our @GENERATED              = ();
208
our @GENERATED_NOTSRC       = ();
209
our @RULES                  = ();
210
our @TOOLSETRULES           = ();
211
our @TOOLSETDIRS            = ();
212
our @TOOLSETDIRTREES        = ();
213
our @TOOLSETGENERATED       = ();
214
our @USERGENERATED          = ();
215
our @TOOLSETOBJS            = ();
216
our @TOOLSETLIBS            = ();
217
our @TOOLSETPROGS           = ();
218
our %INSTALL_HDRS           = ();
219
our %INSTALL_CLSS           = ();
220
 
4778 dpurdie 221
our @TOOLSET_UTF_PRE        = ();       # Toolsets can extend rules run before all unit tests
222
our @TOOLSET_UTF_POST       = ();       # Toolsets can extend rules run after all unit tests
223
our @TOOLSET_UTF_COLLATE    = ();       # Toolsets can extend rules run to collate unit tests results
224
 
227 dpurdie 225
our @LIBS                   = ();
289 dpurdie 226
our $LIBS                   = ();
227 dpurdie 227
our %LIB_PKG                = ();
228
our %LIB_INS                = ();
229
our %INSTALL_LIBS           = ();
230
 
231
our @MLIBS                  = ();
289 dpurdie 232
our $MLIBS                  = ();
227 dpurdie 233
 
234
our @SHLIBS                 = ();
289 dpurdie 235
our $SHLIBS                 = ();
227 dpurdie 236
our @SHLIB_TARGETS          = ();
237
our %SHLIB_PKG              = ();
238
our %SHLIB_INS              = ();
239
our %INSTALL_SHLIBS         = ();
6387 dpurdie 240
our @INSTALL_DIRS           = ();
227 dpurdie 241
 
289 dpurdie 242
our $TESTPROGS              = ();
243
our @TESTPROGS              = ();
227 dpurdie 244
 
289 dpurdie 245
our $PROGS                  = ();           # Simplify tracking of progs
227 dpurdie 246
our @PROGS                  = ();
289 dpurdie 247
our @PROGS_EXTRA            = ();           # Look at doing better !!
227 dpurdie 248
our %PROG_PKG               = ();
249
our %PROG_INS               = ();
250
our %INSTALL_PROGS          = ();
251
 
252
our %PACKAGE_DIST           = ();
253
our %PACKAGE_SETS           = ();
254
our %PACKAGE_HDRS           = ();
255
our %PACKAGE_LIBS           = ();
256
our %PACKAGE_CLSS           = ();
257
our %PACKAGE_SHLIBS         = ();
258
our %PACKAGE_PROGS          = ();
259
our %PACKAGE_FILES          = ();
6387 dpurdie 260
our @PACKAGE_DIRS           = ();
227 dpurdie 261
 
262
our @LINTLIBS               = ();
263
our @LINTSHLIBS             = ();
264
 
4501 dpurdie 265
our @TESTS_TO_RUN           = ();                           # Info from 'RunTest' directives
227 dpurdie 266
 
4996 dpurdie 267
our @TESTPROJECT_TO_URUN    = ();                           # List of Unit Tests and Projects names (Auto and Non Auto in order defined in makefile)
268
our @TESTPROJECT_TO_ARUN    = ();                           # List of Auto Tests and Projects names in order defined in makefile
4501 dpurdie 269
my  $TESTS_TO_AUTORUN       = undef;                        # Flag - Auto Test found
270
my  $TESTS_TO_RUN           = undef;                        # Flag - Unit Test found
271
 
227 dpurdie 272
#our $CurrentTime           = "";
273
#our $CurrentDate           = "";
274
#our $Cwd                   = "";
275
 
276
our @GENERATE_FILES         = ();
277
our %DEPLOYPACKAGE          = ();
267 dpurdie 278
our $DEPLOYPACKAGE          = 0;
261 dpurdie 279
our %MakeTags;
227 dpurdie 280
 
281
#
282
#   Some toolset options that affect the generation of the makefile
283
#
284
our $UseAbsObjects          = 0;                # Default is relative paths to objects
285
our $UseRelativeRoot        = 0;                # Default is absolute paths to build root
299 dpurdie 286
our $DPackageDirective      = 0;
227 dpurdie 287
 
271 dpurdie 288
#
289
#   Arrays of hook functions
290
#
291
our %MF_RegisterSrcHooks;                       # Hook source file discovery
292
 
227 dpurdie 293
###############################################################################
294
#
295
#   Packaging and Installation Information
296
#   Held in a structure as its used in a few places
297
#   Items
298
#       PBase   - Package Base directory. Used for user overrides
299
#       IBase   - Local Install Base directory
300
#       Dir     - Default directory suffix for components. Added to Pbase and IBase
301
#
302
#
303
our %PackageInfo = (
304
    'File' => { 'PBase' => '$(PKGDIR)'       ,'IBase' => '$(LOCALDIR)'       , 'Dir' => '' },
305
    'Hdr'  => { 'PBase' => '$(INCDIR_PKG)'   ,'IBase' => '$(INCDIR_LOCAL)'   , 'Dir' => ''},
306
    'Lib'  => { 'PBase' => '$(LIBDIR_PKG)'   ,'IBase' => '$(LIBDIR_LOCAL)'   , 'Dir' => '/$(GBE_PLATFORM)'},
307
    'Prog' => { 'PBase' => '$(BINDIR_PKG)'   ,'IBase' => '$(BINDIR_LOCAL)'   , 'Dir' => '/$(GBE_PLATFORM)$(GBE_TYPE)'},
308
    'Jar'  => { 'PBase' => '$(CLSDIR_PKG)'   ,'IBase' => '$(CLSDIR_LOCAL)'   , 'Dir' => ''},
241 dpurdie 309
    'Tool' => { 'PBase' => '$(PKGDIR)'       ,'IBase' => '$(LOCALDIR)'       , 'Dir' => '/tools/bin/$(GBE_HOSTMACH)'},
227 dpurdie 310
    );
311
 
4778 dpurdie 312
###############################################################################
313
#
314
#   An array of reserved names
315
#   Used to attempt to prevent developers from naming toolset targets with names reserved
316
#   within the build system
317
our @reservedMakeTargets = qw (
318
    preprocess_tests postprocess_tests collate_test_results
319
);
320
 
227 dpurdie 321
MakeLib2Init();                                 # Runtime initialisation
322
 
323
sub MakeLib2Init
324
{
325
#.. Test environment
326
#
327
    EnvImport( "GBE_CORE" );
328
    EnvImport( "GBE_BIN" );
329
    EnvImport( "GBE_PERL" );
330
    EnvImport( "GBE_TOOLS" );
331
    EnvImport( "GBE_CONFIG" );
332
    EnvImport( "GBE_MACHTYPE" );
333
 
334
#.. Common stuff
335
#
336
    require "$::GBE_TOOLS/common.pl";           # Common stuff
337
    push( @ScmDepends, "$::GBE_TOOLS/common.pl" );
338
 
339
    CommonInit( "makelib2" );
340
    Debug( "version:   $ScmVersion" );
341
 
342
#.. Cache arguments
343
#
344
    CommandLine();
345
 
346
#.. Build defaults
347
#
348
    $ScmSourceTypes{ ".h" }     = ".h";
349
    $ScmSourceTypes{ ".hpp" }   = ".h";
350
    $ScmSourceTypes{ ".c" }     = ".c";
351
    $ScmSourceTypes{ ".C" }     = ".c";
352
    $ScmSourceTypes{ ".cpp" }   = ".cc";
353
    $ScmSourceTypes{ ".cc" }    = ".cc";
354
    $ScmSourceTypes{ ".asm" }   = ".asm";
355
    $ScmSourceTypes{ ".x" }     = "--Ignore";
356
    $ScmSourceTypes{ ".ini" }   = "--Ignore";
357
    $ScmSourceTypes{ ".sh" }    = "--Ignore";
358
    $ScmSourceTypes{ ".pl" }    = "--Ignore";
359
    $ScmSourceTypes{ ".awk" }   = "--Ignore";
360
 
361
#.. Get the stuff from the build configuration file
362
#
363
    ConfigLoad();
4781 dpurdie 364
    $ScmMakeUid = GetMakfilefileUid();
365
    Debug("ScmMakeUid: $ScmMakeUid");
227 dpurdie 366
 
369 dpurdie 367
    if ( (%::ScmBuildPlatforms) )        # Interface/build.cfg
227 dpurdie 368
    {
369
        AddPlatformArg( split( /$;/, $::ScmBuildPlatforms{ $ScmPlatform } ));
370
    }
371
 
369 dpurdie 372
    if ( (%::ScmBuildIncludes) )         # Interface/build.cfg
227 dpurdie 373
    {
374
        my( @includes ) = split( ',', $::ScmBuildIncludes{ $ScmPlatform } );
375
        my( $global ) = $ScmGlobal;
376
 
377
        $ScmGlobal = 1;                         # Follow defs are "global's" ...
378
        foreach my $elem ( @includes )
379
        {
380
            AddIncDir( "*", $elem ) if ($elem);
381
        }
382
        $ScmGlobal = $global;                   # Restore global status ...
383
    }
384
 
369 dpurdie 385
    if ( (%::ScmBuildLibraries) )        # Interface/build.cfg
227 dpurdie 386
    {
387
        my( @libraries ) = split( ',', $::ScmBuildLibraries{ $ScmPlatform } );
388
        my( $global ) = $ScmGlobal;
389
 
390
        $ScmGlobal = 1;                         # Follow defs are "global's" ...
391
        foreach my $elem ( @libraries )
392
        {
393
            AddLibDir( "*", $elem ) if ($elem);
394
        }
395
        $ScmGlobal = $global;                   # Restore global status ...
396
    }
397
 
398
#.. Determine the value of $ScmMachType
399
#   In the makefile GBE_MACHTYPE will be set to $ScmMachType.
400
#
401
#   There is an compatibility issue here.
402
#   A lot of (legacy) package.pl files use GBE_MACHTYPE to specify platform
403
#   specfic directories and names. This is not to be encouraged.
404
#
405
#   Allow for a platformm specific override
406
#
407
    if ( exists( $::BUILDINFO{$ScmPlatform}{'SCMMACHTYPE'} ))
408
    {
409
        $ScmMachType = $::BUILDINFO{$ScmPlatform}{'SCMMACHTYPE'};
410
        Verbose("Override ScmMachType: $ScmMachType");
411
    }
412
    else
413
    {
414
        $ScmMachType = $ScmPlatform;
415
    }
416
 
417
 
418
#.. Get the stuff from the Package definition file
419
#   A convention is that package.pl provide a package name via $Pbase
420
#   This may be different to the BUILDNAME. Generate a default $Pbase
421
#   to allow the package.pl to use the package name part of the buildname
422
#
423
    $::Pbase = $::ScmBuildPackage;
424
    if ( -f "$ScmRoot/package.pl" )
425
    {
426
        Warning ("package.pl file used. Use is being deprecated");
427
 
428
        my( $global ) = $ScmGlobal;             # Follow defs are "global's" ...
429
        $ScmGlobal = 1;
430
        require "$ScmRoot/package.pl";
431
        $ScmGlobal = $global;                   # Restore global status ...
432
 
433
        if ( defined ($::ScmBuildPackage) && defined ($::Pbase) )
434
        {
435
            #   Special case.
436
            #   $Pbase is set to ".". Set $Pbase to the Build Name to force
437
            #   construction of a well formatted package.
438
            #
439
            $::Pbase = $::ScmBuildPackage
440
                if ( $::Pbase eq "." );
441
 
442
            #
443
            #   Error if Pbase has changed
444
            #
445
            Error ("Pbase is not the same as the BuildName (Check package.pl)",
446
                   "Pbase    : $::Pbase",
447
                   "BuildName: $::ScmBuildPackage")
448
                if ( $::Pbase ne $::ScmBuildPackage );
449
        }
450
    }
289 dpurdie 451
 
452
    #
453
    #   Create objects to keep track of Libraies and Programs
454
    #
455
    $LIBS       = MakeObject::NewType( 'Library',       \@LIBS,     '$(LIBDIR)/', \&GenLibName);
456
    $MLIBS      = MakeObject::NewType( 'MergedLibrary', \@MLIBS,    '$(LIBDIR)/', \&GenLibName);
457
    $SHLIBS     = MakeObject::NewType( 'SharedLibrary', \@SHLIBS,   '$(LIBDIR)/', \&GenLibName);
458
    $PROGS      = MakeObject::NewType( 'Program',       \@PROGS,    '$(BINDIR)/', \&GenProgName);
459
    $TESTPROGS  = MakeObject::NewType( 'TestProgram',   \@TESTPROGS,'$(BINDIR)/', \&GenProgName);
227 dpurdie 460
}
461
 
261 dpurdie 462
#-------------------------------------------------------------------------------
289 dpurdie 463
# Function        : GenLibName
464
#
465
# Description     : Helper function to generate a (static) library name
466
#                   Used by MakeObject::NewType
467
#
468
#                   If the toolset doesn't support Debug and Prod, then
469
#                   The library name will not have the suffix
470
#
471
# Inputs          : arg0        - Base name of the library
343 dpurdie 472
#                   arg1        - Mode: 1 == Plain. No P or D
289 dpurdie 473
#
474
# Returns         : Name of the library as used in the makefiles
475
#                   Does not include base directory
476
#
477
sub GenLibName
478
{
343 dpurdie 479
    if ( $ScmToolsetSingleType || $_[1] ) {
289 dpurdie 480
        return "$_[0].$::a"
481
    } else {
482
        return "$_[0]\$(GBE_TYPE).$::a"
483
    }
484
}
485
 
486
#-------------------------------------------------------------------------------
487
# Function        : GenProgName
488
#
489
# Description     : Helper function to generate a program name
490
#                   Used by MakeObject::NewType
491
#
492
# Inputs          : arg0        - Base name of the library
493
#
494
# Returns         : Name of the program as used in the makefiles
495
#                   Does not include base directory
496
#
497
sub GenProgName
498
{
499
    return "$_[0]$::exe"
500
}
501
 
502
 
503
#-------------------------------------------------------------------------------
261 dpurdie 504
# Function        : CommandLine
505
#
506
# Description     : Process the command line.
507
#                   Arguments describes below
508
#
509
# Arguments       : ARG0        - Root of the project
510
#                   ARG1        - Path to this script
511
#                   ARG2        - Target Platform
512
#
513
#                   Options follow
514
#                       --interface=name    - Name of interface dir
515
#                       --arg=xxx           - Platform argument
516
#
517
#                   Otherwise display a usage message
518
#
519
# Returns         : Nothing
520
#
227 dpurdie 521
sub CommandLine
522
{
261 dpurdie 523
    Verbose ("Command Line: @ARGV");
227 dpurdie 524
 
261 dpurdie 525
    #
526
    #   Extract options first
527
    #
528
    my $opt_help = 0;
529
    my $result = GetOptions (
530
                "help+"         => \$opt_help,
531
                "interface=s"   => \$::ScmInterface,
532
                "arg=s"         => sub{ AddPlatformArg( "--$_[1]") }
533
                );
534
    Usage() if ( $opt_help || !$result );
535
 
536
    #
537
    # Need 3 Arguments
538
    #
227 dpurdie 539
    $ScmRoot     = ${ARGV[0]};
261 dpurdie 540
    $ScmRoot     = RelPath( $ScmRoot );
227 dpurdie 541
    $ProjectBase = $ScmRoot;
542
 
543
    $ScmMakelib  = ${ARGV[1]};
544
    $ScmPlatform = ${ARGV[2]};
545
    $ScmTarget   = $ScmPlatform;
546
 
547
    Message ("[$ScmPlatform] Generate Makefile");
548
    Debug( "root\t=$ScmRoot" );
549
    Debug( "makelib\t=$ScmMakelib" );
550
    Debug( "platform\t=$ScmPlatform" );
551
}
552
 
553
#   Usage ---
554
#       Command line usage help.
555
#..
556
 
557
sub Usage
558
{
261 dpurdie 559
    Error ( "Usage: perl makefile.pl2 <ROOTDIR> <makelib.pl2> <PLATFORM> [options ...]",
560
            "Valid options:",
561
            "    --interface=name  Set interface directory",
562
            "    --arg=text        Specify platform argument",
563
            );
227 dpurdie 564
}
565
 
566
 
567
#-------------------------------------------------------------------------------
568
# Function        : SubDir
569
#
570
# Description     : Include a sub-makefile
571
#                   When called when processing by this script this directive
572
#                   does nothing. The processing will be done by makelib.pl
573
#
574
#                   This directive MUST occur before the Platform directive
575
#
576
# Inputs          : None that are used
577
#
578
# Returns         : Nothing
579
#
580
 
581
sub SubDir
582
{
583
    Error ("SubDir directive not allowed after the Platform directive")
584
        if ( $ScmPlatformSeen );
585
}
586
 
587
 
588
###############################################################################
589
#   Platform support
590
###############################################################################
591
 
592
sub Platform
593
{
594
    my( $global, $file );
595
 
596
    Debug( "Platform( $ScmPlatform, @ScmPlatformArgs )" );
597
 
598
#.. Sanity test
599
#
600
    Error ("Platform directive is not allowed in common makefile.pl")
601
        if ( $ScmProcessingRootMake );
602
 
603
    Error ("Only one Platform directive is allowed")
604
        if ( $ScmPlatformSeen );
605
    $ScmPlatformSeen = 1;
606
 
607
#.. Arguments
608
#
609
    $ScmTargetHost = $::ScmHost;                # default
610
 
611
#.. Common configuration
612
#
613
    $global = $ScmGlobal;                       # Follow defs are "global's" ...
614
    $ScmGlobal = 1;
615
 
616
#.. Common rules (ScmHost specific)
617
#
618
    push( @ScmDepends, "$ScmMakelib" );         # parent
619
 
620
    $file = Require( "$::GBE_CONFIG", "Rules", "Common rules " );
621
    push( @ScmDepends, "$file" );
622
 
623
#.. Platform (defines ScmToolset)
624
#
369 dpurdie 625
    if ( ( %::ScmBuildProducts ) &&      # interface/build.cfg
4551 dpurdie 626
           $::ScmBuildProducts{ $ScmPlatform } )
227 dpurdie 627
    {
628
        my( @args ) = split( ',', $::ScmBuildProducts{ $ScmPlatform } );
629
 
630
        $ScmProduct = $args[0];
631
        $ScmTarget = $args[1];
632
 
633
        Debug( " mapping to product $ScmProduct" );
634
 
635
                                                # Platform/target specific
636
        MakeIf::PackageDirs( \@ScmPlatformDirs, $ScmPlatform, $ScmTarget );
637
        push @ScmPlatformDirs, "$::GBE_CONFIG"; # .. plus default
638
 
639
        @ScmPlatformArgs = ( "--product=$ScmProduct", @ScmPlatformArgs );
640
        $file = Require( "PLATFORM", $ScmTarget,
641
                    "Platform definition ", @ScmPlatformDirs );
642
    }
643
    else                                        # standard
644
    {
645
        Debug( " native platform" );
646
 
647
                                                # Platform specific
648
        MakeIf::PackageDirs( \@ScmPlatformDirs, $ScmPlatform );
649
        push @ScmPlatformDirs, "$::GBE_CONFIG"; # .. plus default
650
 
6133 dpurdie 651
        #   Map all GENERIC builds onto the one platform definition
4551 dpurdie 652
        my $platformDefs = $ScmPlatform;
6133 dpurdie 653
        if ($::BUILDINFO{$ScmPlatform}{IS_GENERIC})
654
        {
655
            $ScmNotGeneric = 0;
656
            $platformDefs = 'GENERIC' ;
657
        }
4551 dpurdie 658
 
659
        $file = Require( "PLATFORM", $platformDefs,
227 dpurdie 660
                    "Platform definition ", @ScmPlatformDirs );
661
    }
662
    push( @ScmDepends, "$file" );
663
 
664
    Error( "Toolset undefined for platform $ScmPlatform ...")
665
        unless( $ScmToolset );
666
 
667
#.. Toolset
668
#
669
    $file = Require( "$::GBE_CONFIG/TOOLSET", $ScmToolset, "Toolset definition " );
670
    push( @ScmDepends, "$file" );
671
 
672
#.. Package definitions
673
#
367 dpurdie 674
#   Global DPACKAGE definitions, which may pull in $ScmTarget specific definitions.
227 dpurdie 675
#
676
 
677
    MakeIf::PackageLoad( $ScmPlatform );        # DPACKAGE's (if any)
678
 
679
 
680
#.. Package extensions
681
#   Import, into the current package, files of the form gbe/DIRECTIVES
682
#   These allow the JATS directives to be extended by the contents of a package
683
#   without the need to update the core JATS release.
684
#
685
#   Intended use: Associate a directive with a tool script, such that the
686
#   new directive simplifies the use of the tool script.
687
#
688
#
689
#   First: Extend the Perl Search Space to include the toolset extensions
690
#          Although the directives are in gbe/DIRECTIVES/*.pm, they may need
691
#          to reference other packages that are not.
692
#
311 dpurdie 693
#           Look in the 'interface' and 'link' packages
694
#           The 'build' packages are duplicated into the 'interface'
695
#
227 dpurdie 696
    for my $path ( ToolExtensionPaths() )
697
    {
698
        UniquePush (\@INC, $path)
699
            if (glob( "$path/*.pm") || glob( "$path/*/*.pm"));
700
    }
701
 
702
    for my $entry (@{$::ScmBuildPkgRules{$ScmPlatform} })
703
    {
311 dpurdie 704
        next if ( $entry->{'TYPE'} eq 'build' );
227 dpurdie 705
        my $cfgdir = $entry->{'CFGDIR'};
706
        next unless ( $cfgdir );
707
        my $base_dir = $entry->{'ROOT'} . $cfgdir . '/DIRECTIVES';
708
        next unless ( -d $base_dir );
709
        foreach my $file  ( glob ("$base_dir/*.pm") )
710
        {
711
            push( @ScmDepends, "$file" );
712
            require $file;
713
        }
714
    }
715
 
716
    #
271 dpurdie 717
    #   Include local toolset extensions
718
    #   These are rooted in the build directory and are not to be confused with
719
    #   extensions that may be packaged
6387 dpurdie 720
    #   Simplify life - add the directory to the BUILDTOOLSPATH
271 dpurdie 721
    #
722
    my $local_base_dir = "$ScmRoot/gbe/DIRECTIVES";
723
    if ( -d $local_base_dir )
724
    {
6387 dpurdie 725
        unshift @::BUILDTOOLSPATH, AbsPath($local_base_dir); 
271 dpurdie 726
        foreach my $file  ( glob ("$local_base_dir/*.pm") )
727
        {
728
            push( @ScmDepends, "$file" );
729
            require $file;
730
        }
731
    }
732
 
733
    #
227 dpurdie 734
    #   All makefile.pl's will include a makefile.pl found in the build
735
    #   root directory ( The same directory as build.pl ). This makefile.pl
736
    #   is a little bit different - It should not "require "$ARGV[1]", nor
737
    #   should it use a Platform directive.
738
    #
739
    #   Note: This makefile is processed AFTER the toolset has been initialised
740
    #         so that toolset extensions are available to the directives
741
    #
742
    $file = "$ScmRoot/makefile.pl";
743
    if ( -e $file ) {
744
        $ScmProcessingRootMake = 1;
745
        require "$file";
746
        $ScmProcessingRootMake = 0;
747
        push( @ScmDepends, "$file" );
748
    }
749
 
750
    #
289 dpurdie 751
    #   Sanity Test for platforms that do not support both debug and production
752
    #   builds at the same time. This information is flagged by the toolset
753
    #   which we have now loaded.
754
    #
755
    if ( $ScmToolsetSingleType  )
756
    {
757
        unless ( $ScmBuildType )
758
        {
759
            Error ("The toolset used by the \"$ScmPlatform\" platform does not support",
760
                   "both Production and Debug Builds" );
761
        }
762
    }
763
 
764
    #
227 dpurdie 765
    #   Restore global status ...
766
    #
767
    $ScmGlobal = $global;
768
}
769
 
770
 
771
sub PlatformRequire
772
{
773
    my( $script, @arguments ) = @_;
774
    my( $file );
775
 
776
    Debug( "PlatformRequire($script, @arguments)" );
777
 
778
    push( @ScmPlatformArgs, @arguments );       # additional arguments
779
 
780
    $file = Require( "PLATFORM", $script,
781
                "PlatformRequire ", @ScmPlatformDirs );
782
 
783
    push( @ScmDepends, "$file" );
784
}
785
 
786
 
787
sub PlatformInclude
788
{
789
    my( $script, @arguments ) = @_;
790
    my( $file );
791
 
792
    Debug( "PlatformInclude( @_ )" );
793
 
794
    $file = Require2( \@arguments, "PLATFORM", $script,
795
                "PlatformInclude ", @ScmPlatformDirs );
796
 
797
    push( @ScmDepends, "$file" );
798
}
799
 
800
 
801
sub PlatformDefine
802
{
803
    Debug2( "PlatformDefine(@_)" );
804
 
805
    Define( @_ );
806
}
807
 
808
 
809
sub PlatformDefines
810
{
811
    my( $script ) = @_;
812
    my( $line );
813
 
814
    Debug2( "PlatformDefine(@_)" );
815
 
816
    $script = Exists( "PLATFORM", $script,      # locate image
817
                "PlatformDefines", @ScmPlatformDirs );
818
 
271 dpurdie 819
    push( @DEFINES, "# PlatformDefines from: $script" );
285 dpurdie 820
    open( my $fh, '<', $script ) || Error( "Opening $script" );
821
    while (<$fh>) {
227 dpurdie 822
        $_ =~ s/\s*(\n|$)//;                    # kill trailing whitespace & nl
823
        push( @DEFINES, $_ );
824
    }
825
    push( @ScmDepends, "$script" );             # makefile dependencies
285 dpurdie 826
    close( $fh );
227 dpurdie 827
}
828
 
829
 
830
sub PlatformEntry
831
{
832
    my( $prelim, $postlim, $prefix, $postfix, @elements ) = @_;
833
 
285 dpurdie 834
    my $str = "$prelim";
835
    foreach my $element ( @elements )
227 dpurdie 836
    {
837
        $str .= "${prefix}${element}${postfix}";
838
    }
839
    $str .= "$postlim";
840
    PlatformDefine( $str );
841
}
842
 
843
 
844
#
845
#   Add arguments to the ScmPlatformArgs, but remove "Global" arguments
846
#       --OnlyDebug
847
#       --OnlyProduction
343 dpurdie 848
#       --NoToolSet
227 dpurdie 849
#
289 dpurdie 850
#   Capture OnlyDebug and OnlyProd information
851
#   Will be sanitized by caller.
852
#
227 dpurdie 853
sub AddPlatformArg
854
{
855
    Debug("AddPlatformArg: @_" );
289 dpurdie 856
    foreach  ( @_ )
857
    {
858
        if ( m~^--OnlyDebug~ ) {
859
            $ScmBuildType = 'D';
860
        } elsif ( m~--OnlyProd~ ) {
861
            $ScmBuildType = 'P';
343 dpurdie 862
        } elsif ( m~--NoToolSet~ ) {
863
            $ScmNoToolsTest = 1;
289 dpurdie 864
        } else {
343 dpurdie 865
            UniquePush( \@::ScmPlatformArgs, $_ );
289 dpurdie 866
        }
867
    }
227 dpurdie 868
 
869
    Debug("AddPlatformArg: Result: @::ScmPlatformArgs" );
870
    1;
871
}
872
 
873
###############################################################################
874
# Toolset support
875
#
876
#   Toolset( 'platform [, ... ]', name, [arg, ... ] )
877
#       Specify the toolset for a platform
878
#
879
#   ToolDefine( )
880
#   ToolDefines( )
881
#       Specifies toolset defines for insertion into the target makefile.
882
#
883
#   ToolsetDir
884
#       Define toolset created directory(s) for removal during
885
#       'clean' operations.
886
#
887
#   ToolsetGenerate
888
#       Define toolset created file(s) for removal during
889
#       'clean' operations.
890
#
891
#   ToolsetObj
892
#       Define toolset created object(s) for removal during
893
#       'clean' operations.
894
#
895
#   ToolsetLib
896
#       Define toolset created library(s) for removal during
897
#       'clean' operations.
898
#
899
#   ToolsetProg
900
#       Define toolset created prog(s) for removal during
901
#       'clean' operations.
902
#
903
#   ToolsetRule( )
904
#   ToolsetRules( )
905
#       Specifies toolset rules for insertion into the target makefile.
906
#
907
##############################################################################
908
 
909
sub Toolset
910
{
911
    my( $platforms, $toolset, @arguments ) = @_;
912
 
913
    Debug2( "Toolset(@_)" );
914
 
4309 dpurdie 915
    return 1 if ( ! ActivePlatform($platforms) );
227 dpurdie 916
 
917
    $ScmToolset = $toolset;
918
    @ScmToolsetArgs = @arguments;
4309 dpurdie 919
    return 1;
227 dpurdie 920
}
921
 
922
 
923
sub ToolsetRequire
924
{
925
    my( $script, @arguments ) = @_;
926
    my( $file );
927
 
928
    Debug2( "ToolsetRequire(@_)" );
929
 
930
    @ScmToolsetArgs = @arguments;
931
    $file = Require( "",
932
                     $script,
933
                     "ToolsetRequire",
934
                     "$::GBE_CONFIG/TOOLSET", @::BUILDTOOLSPATH );
935
    push( @ScmDepends, "$file" );
936
}
937
 
938
 
939
sub ToolsetDefine
940
{
941
    Debug2( "ToolsetDefine(@_)" );
942
 
943
    Define( @_ );
944
}
945
 
946
 
947
sub ToolsetDefines
948
{
949
    Debug2( "ToolsetDefines(@_)" );
950
 
261 dpurdie 951
    Defines( "$::GBE_CONFIG/TOOLSET", @_ );
227 dpurdie 952
}
953
 
954
 
955
sub ToolsetDir
956
{
957
    Debug2( "ToolsetDir(@_)" );
958
 
261 dpurdie 959
    UniquePush ( \@TOOLSETDIRS, @_ );
227 dpurdie 960
}
961
 
962
 
963
sub ToolsetDirTree
964
{
965
    Debug2( "ToolsetDirTree(@_)" );
966
 
261 dpurdie 967
    UniquePush ( \@TOOLSETDIRTREES, @_);
227 dpurdie 968
}
969
 
970
 
971
sub ToolsetGenerate
972
{
973
    Debug2( "ToolsetGenerate(@_)" );
974
 
975
    UniquePush( \@TOOLSETGENERATED, @_ );
976
}
977
 
978
 
979
sub ToolsetObj
980
{
981
    Debug2( "ToolsetObj(@_)" );
982
 
261 dpurdie 983
    foreach my $obj ( @_ )
227 dpurdie 984
    {
261 dpurdie 985
        UniquePush( \@TOOLSETOBJS, "$obj.$::o"  );
227 dpurdie 986
    }
987
}
988
 
989
 
990
sub ToolsetLib
991
{
992
    Debug2( "ToolsetLib(@_)" );
993
 
261 dpurdie 994
    foreach my $lib ( @_ )
227 dpurdie 995
    {
289 dpurdie 996
        UniquePush( \@TOOLSETLIBS, GenLibName( $lib ) );
227 dpurdie 997
    }
998
}
999
 
1000
 
1001
sub ToolsetProg
1002
{
1003
    Debug2( "ToolsetProg(@_)" );
1004
 
261 dpurdie 1005
    foreach my $prog ( @_ )
227 dpurdie 1006
    {
289 dpurdie 1007
        UniquePush( \@TOOLSETPROGS, GenProgName( $prog ) );
227 dpurdie 1008
    }
1009
}
1010
 
1011
 
1012
sub ToolsetRule
1013
{
1014
    Debug2( "ToolsetRule(@_)" );
1015
 
1016
    push( @TOOLSETRULES, @_ );
1017
}
1018
 
1019
 
1020
sub ToolsetRules
1021
{
1022
    my( $script ) = @_;
1023
    my( $line );
1024
 
1025
    Debug2( "ToolsetRules(@_)" );
1026
 
1027
    $script = Exists( "$::GBE_CONFIG/TOOLSET", $script, "ToolsetRules" );
271 dpurdie 1028
    push( @TOOLSETRULES, "# ToolsetRules from: $script" );
285 dpurdie 1029
    open( my $fh, '<', $script ) || Error( "Opening $script" );
1030
    while (<$fh>) {
227 dpurdie 1031
        $_ =~ s/\s*(\n|$)//;                    # kill trailing whitespace & newline
1032
        push( @TOOLSETRULES, $_ );
1033
    }
1034
    push( @ScmDepends, "$script" );             # makefile dependencies
285 dpurdie 1035
    close( $fh );
227 dpurdie 1036
}
1037
 
4778 dpurdie 1038
#-------------------------------------------------------------------------------
4902 dpurdie 1039
# Function        : SetGlobalOption  
1040
#
1041
# Description     : Set a global toolset option
1042
#                   The global options are intended to allow platform-specific
1043
#                   operation of various tools and utilities. The scope is wider than 
1044
#                   just the underlying tooolset 
1045
#
1046
# Inputs          : $name           - Name of the option
1047
#                   $value          - Value to save            
1048
#
1049
# Returns         : Nothing
1050
#
1051
 
1052
sub SetGlobalOption
1053
{
1054
    my ($name, $value) = @_;
4928 dpurdie 1055
    Debug( "SetGlobalOption.", $name, $value );
4902 dpurdie 1056
    $ScmGlobalOptions{$name} = $value;
1057
}
1058
 
1059
#-------------------------------------------------------------------------------
1060
# Function        : GetGlobalOption   
1061
#
1062
# Description     : Get a global toolset option
1063
#
1064
# Inputs          : $name           - Name of the option to fetch
1065
#                   $default        - Default value to return, if the option
1066
#                                     is not present.
1067
#
1068
# Returns         : The value of the option, or the default value
1069
#
1070
 
1071
sub GetGlobalOption 
1072
{
1073
    my ($name, $default) = @_;
1074
    if (exists $ScmGlobalOptions{$name})
1075
    {
1076
        $default = $ScmGlobalOptions{$name};
1077
    }
4928 dpurdie 1078
    Debug( "GetGlobalOption .", $name, $default  );
4902 dpurdie 1079
    return $default;
1080
}
1081
 
1082
 
1083
#-------------------------------------------------------------------------------
4778 dpurdie 1084
# Function        : ToolsetAddUnitTestPreProcess
1085
#                   ToolsetAddUnitTestPostProcess
1086
#                   ToolsetAddUnitTestCollateProcess
1087
#
1088
# Description     : Functions to allow toolsets to add recipes to be run before
1089
#                   and after Unit Tests are run.    
1090
#
1091
# Inputs          : $target         - Name of the recipe to be run 
1092
#
1093
# Returns         : Nothing
1094
#
1095
sub ToolsetAddUnitTestPreProcess
1096
{
1097
    _ToolsetAddUnitTest(\@TOOLSET_UTF_PRE, @_ );
1098
}
227 dpurdie 1099
 
4778 dpurdie 1100
sub ToolsetAddUnitTestPostProcess
1101
{
1102
    _ToolsetAddUnitTest(\@TOOLSET_UTF_POST, @_ );
1103
}
1104
 
1105
sub ToolsetAddUnitTestCollateProcess
1106
{
1107
    _ToolsetAddUnitTest(\@TOOLSET_UTF_COLLATE, @_ );
1108
}
1109
 
1110
#-------------------------------------------------------------------------------
1111
# Function        : _ToolsetAddUnitTest  
1112
#
1113
# Description     : Internal helper function used by ToolsetAddUnitTest*
1114
#
1115
# Inputs          : $aref           - Ref to an array of names to extend
1116
#                   $target         - Name of recipe to run 
1117
#
1118
# Returns         : Nothing
1119
#
1120
sub _ToolsetAddUnitTest
1121
{
1122
    my ($aref, $target ) = @_;
1123
 
1124
    #   Determine name of parent function
1125
    my $fname = (caller(1))[3];
1126
    $fname =~ s~.*::~~;
1127
    Debug2( "$fname ($target)" );
1128
 
1129
    #
1130
    #   Ensure user is not using a reserved target
1131
    #
1132
    if (grep {$_ eq $target} @reservedMakeTargets) {
1133
        Error("Internal: $fname uses reserved make taget: $target");
1134
    }
1135
 
1136
    push @$aref, $target;
1137
 
1138
}
1139
 
227 dpurdie 1140
###############################################################################
1141
# User interface:
1142
#
1143
#   AddFlags( 'platform [, ... ]', 'flags' [, 'flag' ... ] )
1144
#       This subroutine takes the C and C++ compiler flags
1145
#       specified adding them to a global list for later
1146
#       inclusion in the built makefile.
1147
#
1148
#   AddCFlags( 'platform [, ... ]', 'flags' [, 'flag' ... ] )
1149
#       This subroutine takes the C compiler flags
1150
#       specified adding them to a global list for later
1151
#       inclusion in the built makefile.
1152
#
1153
#   AddCXXFlags( 'platform [, ... ]', 'flags' [, 'flag' ... ] )
1154
#       This subroutine takes the C++ compiler flags
1155
#       specified adding them to a global list for later
1156
#       inclusion in the built makefile.
1157
#
1158
#   AddLintFlags( 'platform [, ... ]', 'flags' [, ... ] )
1159
#       This subroutine takes the Lint flags specified
1160
#       adding them to a global list for later inclusion
1161
#       in the built makefile.
1162
#
1163
#   AddASFlags( 'platform [, ... ]', 'flags' [, ... ] )
1164
#       This subroutine takes the Assemler flags specified
1165
#       adding them to a global list for later inclusion
1166
#       in the built makefile.
1167
#
1168
#   AddLDFlags( 'platform [, ... ]', 'flags' [, ... ] )
1169
#       This subroutine takes the Linker flags specified
1170
#       adding them to a global list for later inclusion
1171
#       in the built makefile.
1172
#
1173
#   AddDir
1174
#       This subroutine takes the directories specified adding
1175
#       them to a global include and source directory list for
1176
#       later inclusion in the built makefile.
1177
#
1178
#   AddIncDir( 'platform [, ... ]', 'dir' [, ... ] )
1179
#       This subroutine takes the include file directories
1180
#       specified adding them to a global list for later
1181
#       inclusion in the built makefile.
1182
#
1183
#   AddSrcDir( 'platform [, ... ]', 'dir' [, ... ] )
1184
#       This subroutine takes the source file directories
1185
#       specified adding them to a global list used to resolve
1186
#       Src() definitions.
1187
#
1188
#   AddLibDir( 'platform [, ... ]', 'dir' [, ... ] )
1189
#       This subroutine takes the library directories
1190
#       specified adding them to a global list for later
1191
#       inclusion in the built makefile.
1192
#
1193
#   AddSourceType( 'ext', '.c|.cc|.asm' )
1194
#       This subroutine takes the extension(s) specified by the
1195
#       programmer and adds them to a global list for later
1196
#       inclusion in the built makefile.  This list contains
1197
#       the extensions to be recognised as 'C', 'C++' or
1198
#       assembler file types.
1199
#
1200
#   AddSourceFile( 'platform [, ... ]', 'file' [, ... ] )
1201
#       This subroutine takes the non-standard source file(s)
1202
#       and adds them add it to either C, C++ or assembler
1203
#       sources and the object list.
1204
#
1205
#   Init( 'platform [, ... ]', 'rule' )
1206
#       Initialisation rule
1207
#
1208
#   Generate( 'platform [, ... ]', 'file' [, ... ] )
1209
#       This subroutine is used to add the list of given
1210
#       source files to the generate sources list, and if
1211
#       the generated source is of type C, C++ or assember
1212
#       also adds it to either C, C++ or assembler sources and
1213
#       the object lists.
1214
#
1215
#       --c             Treat as a C source file.
1216
#       --cpp           Treat as a C++ source file.
1217
#       --asm           Treat as a assembler source file.
1218
#
1219
#   Rule( 'platform [, ... ]', definition )
1220
#       This subroutine is used to add the non-standard make
1221
#       rules required to build the system.  eg. any rules
1222
#       necessary to produce a .cc & .h file from a .x file.
1223
#
1224
#   Src( 'platform [, ... ]', 'file' [, ... ], [ 'arg' [, ...]] )
1225
#       This subroutine is used to add the list of given source
1226
#       files to the sources list, and if the source is of type
1227
#       C, C++ or assember also adds it to either C, C++ or
1228
#       assembler sources and the object lists.  The optional
1229
#       list of arguments is assigned to all source files.
1230
#
1231
#       --c             Treat as a C source file.
1232
#       --cpp           Treat as a C++ source file.
1233
#       --asm           Treat as a assembler source file.
1234
#       --Shared        Shared, produces position-independent
1235
#                       code (on targets where required).
1236
#
1237
#   Lib( 'platform [, ... ]', 'name', 'obj' [, ... ] [, '-arg' [, ... ]] )
1238
#       This subroutine takes a library definition list and adds
1239
#       the  entries to the 3 libraries definition lists. 'name'
1240
#       of the library to be created.  List of the object files
1241
#       'obj' that make up this library.  List of special
1242
#       arguments 'arg' to pass to the librarian.
1243
#
1244
#   MergeLibrary( 'platform [, ... ]', 'name', 'lib' [, ... ] )
1245
#       This subroutine takes a library merge list and adds
1246
#       the  entries to the 2 merge libraries definition lists. 'name'
1247
#       of the library to be created.  List of the libraries to be merged
1248
#
1249
#   LocalScript( 'platform [, ... ]', name, ['1'] )
1250
#   Script( 'platform [, ... ]', name, ['1'] )
1251
#       This subroutine takes a list that defines the name of
1252
#       the script to be placed in the platform 'bin' directory,
1253
#       and an optional second element that defines whether the
1254
#       script should be made executable or not.
1255
#
1256
#   Prog( 'platform [, ... ]', 'name', ['obj', ... ],
1257
#               ['-llib', ... ], ['options'] )
1258
#       This subroutine takes a list that defines which program
1259
#       (binary) is to be made, what libraries and object it is
1260
#       made from, and any special commands required to perform
1261
#       the program creation.
1262
#
1263
#       @PROGS          Updated list of programs to create
1264
#
1265
#   TestProg( 'platform [, ... ]', 'name', ['obj', ... ],
1266
#               ['-llib', ... ], ['options'] )
1267
#       This subroutine takes a list that defines which test program
1268
#       (binary) is to be made, what libraries and object it is
1269
#       made from, and any special commands required to perform
1270
#       the program creation.
1271
#
1272
#       @TESTPROGS      Updated list of programs to create
1273
#
1274
#   InstallHdr( 'platform [, ... ]', 'file' [, ...], ['-arg'] )
1275
#       This subroutine takes the given list of files and adds them
1276
#       to the install header files list.  Files in this list will be
1277
#       installed into the 'local header directory' area for public
1278
#       consumption.  This is generally API files for other modules
1279
#       to use.
1280
#
1281
#       --Strip         Strip directory from source
6276 dpurdie 1282
#       --Strip=n       Strip part of directory from source
227 dpurdie 1283
#       --Full          Install using full path
1284
#       --Subdir=subdir Install within the specified sub-directory
1285
#       --Prefix=subdir   "       "     "      "      "     "
1286
#
1287
#   InstallLib( 'platform [, ... ]', 'file', ['subdir'] )
1288
#       This subroutine takes the given list of files and adds them
1289
#       to the install libraries files list.  Files in this list will
1290
#       be installed into the 'local library directory' area for
1291
#       public consumption.
1292
#
1293
#   InstallProg( 'platform [, ... ]', 'file', ['subdir'] ) )
1294
#       This subroutine takes a list that defines the executable file
1295
#       that is to be installed.  The file in this list will be
1296
#       installed into the 'local executable directory' specified for
1297
#       public consumption.
1298
#
1299
###############################################################################
1300
 
1301
 
1302
sub Include                                     # User include
1303
{
1304
    my( $path, $name ) = @_;
1305
    my( $file );
1306
 
1307
    $file = Require( $path, $name, "Include" );
1308
    push( @ScmDepends, "$file" );
1309
}
1310
 
1311
sub ForceCCompile
1312
{
1313
    CompileOptions( $_[0], 'compile_as_c' );            # Backward compatability
1314
}
1315
 
1316
#-------------------------------------------------------------------------------
1317
#   Create a data structure to define the global compiler options
1318
#    The hash is keyed by compiler option
1319
#    The value contains another hash.
1320
#       The key is a makefile variable to set ( or remove )
1321
#       The value is the value to assign to the makefile variable
1322
#       If the value is 'undef' then the variable will be deleted
1323
#
1324
#   Keys of the form key=value are also supported
1325
#
1326
#   If the value is a CODE reference, then routine will be called with the key
1327
#   and value as arguments. The return value will be utilised.
1328
#
1329
our %ScmCompilerOptions =
1330
    (
1331
        'strict_ansi'           => { 'USE_STRICT_ANSI'    => '1' },
1332
        'no_strict_ansi'        => { 'USE_STRICT_ANSI'    => '' },      # Default
1333
 
1334
        'profile'               => { 'USE_PROFILE'        => '1' },
1335
        'no_profile'            => { 'USE_PROFILE'        => '' },       # Default
1336
 
1337
 
1338
        'prod_no_optimise'      => { 'PROD_USE_OPTIMISE'   => '' },
1339
        'prod_no_debuginfo'     => { 'PROD_USE_DEBUGINFO'  => '' },     # Default
1340
        'prod_optimise'         => { 'PROD_USE_OPTIMISE'   => '1' },    # Default
1341
        'prod_debuginfo'        => { 'PROD_USE_DEBUGINFO'  => '1' },
1342
 
1343
        'debug_no_optimise'     => { 'DEBUG_USE_OPTIMISE'  => '' },     # Default
1344
        'debug_no_debuginfo'    => { 'DEBUG_USE_DEBUGINFO' => '' },
1345
        'debug_optimise'        => { 'DEBUG_USE_OPTIMISE'  => '1' },
1346
        'debug_debuginfo'       => { 'DEBUG_USE_DEBUGINFO' => '1' },    # Default
1347
 
1348
        'compile_as_cpp'        => { 'FORCE_CC_COMPILE'    => '1',
1349
                                     'FORCE_C_COMPILE'     => undef },
1350
        'compile_as_c'          => { 'FORCE_C_COMPILE'     => '1',
1351
                                     'FORCE_CC_COMPILE'    => undef },
267 dpurdie 1352
 
1353
        'no_define_source_file' => { 'DISABLE__SOURCE__' => '1' },
4928 dpurdie 1354
        'define_source_file'    => { 'DISABLE__SOURCE__' => undef },        # Default
267 dpurdie 1355
 
4928 dpurdie 1356
        'warnings_as_errors'    => { 'WARNINGS_AS_ERRORS'        => '1' },
1357
        'no_warnings_as_errors' => { 'WARNINGS_AS_ERRORS'        => undef },       # Default
1358
 
227 dpurdie 1359
    );
1360
 
1361
#
1362
#   The toolset can extend the options by setting the following hash
1363
#
1364
our %ScmToolsetCompilerOptions = ();
1365
 
1366
#
1367
#   Define default compiler options
1368
#   These are makefile variables that will be assigned
1369
#
1370
our %ScmCompilerOpts =
1371
    (
1372
        'USE_STRICT_ANSI'       => '',
1373
        'USE_PROFILE'           => '',
1374
        'PROD_USE_DEBUGINFO'    => '',
1375
        'PROD_USE_OPTIMISE'     => '1',
1376
        'DEBUG_USE_OPTIMISE'    => '',
1377
        'DEBUG_USE_DEBUGINFO'   => '1',
1378
    );
1379
 
1380
 
1381
sub CompileOptions
1382
{
1383
    my( $platforms, @elements ) = @_;
1384
    return if ( ! ActivePlatform($platforms) );
1385
 
1386
    for (@elements)
1387
    {
1388
        my $oref;
1389
 
1390
        #
1391
        #   The toolset option may be a text string or a definition
1392
        #       Name        - A text string
1393
        #       Name=Value  - A value
1394
        #
1395
        my $value;
1396
        my $key = $_;
1397
        if ( $key =~ m~(.*=)(.*)~ )
1398
        {
1399
            $key = $1;
1400
            $value = $2 || '';
1401
        }
247 dpurdie 1402
        $key = lc( $key );
227 dpurdie 1403
 
1404
        #
1405
        #   Examine the global flags
1406
        #   Then the toolset extensions
1407
        #   Then just drop it
1408
        #
1409
        unless ( $oref = ($ScmCompilerOptions{$key} || $ScmToolsetCompilerOptions{$key}) )
1410
        {
1411
            Warning ("Compile Option ignored: $_");
1412
            next;
1413
        }
1414
 
1415
        #
1416
        #   Parse the definition and adjust makefile variables as required
1417
        #   Set the value of a make variable or remove the definition
1418
        #
1419
        #   If the user value is a code reference, then call the code
1420
        #   and use the returned value as the value.
1421
        #
1422
        while ( (my($ukey, $uvalue)) = each %{$oref} )
1423
        {
1424
            if ( defined( $uvalue) )
1425
            {
1426
                if ( ref($uvalue) eq "CODE" )
1427
                {
255 dpurdie 1428
                    $uvalue = &$uvalue( $key, $value, $ukey);
227 dpurdie 1429
                    unless ( defined $uvalue )
1430
                    {
1431
                        Warning ("Compile Option ignored: $_");
1432
                        next;
1433
                    }
1434
                }
247 dpurdie 1435
                elsif ( defined $value )
1436
                {
1437
                    $uvalue = $value;
1438
                }
227 dpurdie 1439
 
1440
                $ScmCompilerOpts{$ukey} = $uvalue;
1441
            }
1442
            else
1443
            {
1444
                delete $ScmCompilerOpts{$ukey};
1445
            }
1446
        }
1447
    }
1448
}
1449
 
1450
#-------------------------------------------------------------------------------
1451
# Function        : AddFlags
1452
#                   AddCFlags
1453
#                   AddCXXFlags
1454
#                   AddASFlags
1455
#                   AddLDFlags
1456
#                   AddLintFlags
1457
#
1458
# Description     : Add target specfic flags to the C compiler
1459
#                   This SHOULD only be used to add Defines to the compiler
1460
#                   but it can be absued.
1461
#
1462
# Inputs          : $platform       - Platforms for which the directive is active
1463
#                   ...             - list of flags to add
1464
#
1465
#                   Embedded options include:
1466
#                       --Debug     - Following options are added to the debug build
1467
#                       --Prod      - Following options are added to the production build
1468
#
1469
# Returns         : Nothing
1470
#
1471
 
1472
sub AddFlags
1473
{
1474
    my( $platforms, @elements ) = @_;
1475
 
1476
    AddCFlags( $platforms, @elements );
1477
    AddCXXFlags( $platforms, @elements );
1478
}
1479
 
1480
sub AddCFlags
1481
{
1482
    my( $platforms, @elements ) = @_;
1483
 
1484
    Debug2( "AddCFlags($platforms, @elements)" );
1485
    return if ( ! ActivePlatform($platforms) );
1486
 
1487
    WarnIfNastyFlag( @elements );
1488
    __AddFlags( "CFLAGS", \@elements,
1489
                \@CFLAGS, \@CLINTFLAGS,
1490
                \@CFLAGS_DEBUG, \@CLINTFLAGS_DEBUG,
1491
                \@CFLAGS_PROD,  \@CLINTFLAGS_PROD );
1492
}
1493
 
1494
sub AddCXXFlags
1495
{
1496
    my( $platforms, @elements ) = @_;
1497
 
1498
    Debug2( "AddCXXFlags($platforms, @elements)" );
1499
    return if ( ! ActivePlatform($platforms) );
1500
 
1501
    WarnIfNastyFlag( @elements );
1502
    __AddFlags( "CXXFLAGS", \@elements,
1503
               \@CXXFLAGS, \@CXXLINTFLAGS,
1504
               \@CXXFLAGS_DEBUG, \@CXXLINTFLAGS_DEBUG,
1505
               \@CXXFLAGS_PROD,  \@CXXLINTFLAGS_PROD );
1506
}
1507
 
1508
sub AddASFlags
1509
{
1510
    my( $platforms, @elements ) = @_;
1511
 
1512
    Debug2( "AddASFlags($platforms, @elements)" );
1513
 
1514
    return if ( ! ActivePlatform($platforms) );
1515
 
267 dpurdie 1516
    __AddFlags( "ASFLAGS", \@elements,
1517
                \@ASFLAGS, undef,
1518
                \@ASFLAGS_DEBUG, undef,
1519
                \@ASFLAGS_PROD, undef );
227 dpurdie 1520
}
1521
 
1522
sub AddLDFlags
1523
{
1524
    my( $platforms, @elements ) = @_;
1525
 
1526
    Debug2( "AddLDFlags($platforms, @elements)" );
1527
 
1528
    return if ( ! ActivePlatform($platforms) );
1529
 
1530
    foreach  ( @elements )
1531
    {
267 dpurdie 1532
        next if ( m~^--(Debug|Prod)~ );
227 dpurdie 1533
        Warning("Use of linker flag discouraged (will be used): $_");
1534
    }
267 dpurdie 1535
    __AddFlags( "LDFLAGS", \@elements,
1536
                \@LDFLAGS, undef,
1537
                \@LDFLAGS_DEBUG, undef,
1538
                \@LDFLAGS_PROD, undef );
227 dpurdie 1539
 
1540
}
1541
 
1542
sub AddLintFlags
1543
{
1544
    my( $platforms, @elements ) = @_;
1545
 
1546
    return if ( ! ActivePlatform($platforms) );
1547
 
1548
    Debug2( "AddLintFlags($platforms, @elements)" );
1549
 
1550
    __AddFlags( "LINTFLAG", \@elements,
1551
                \@CLINTFLAGS, \@CXXLINTFLAGS,
1552
                \@CLINTFLAGS_DEBUG, \@CXXLINTFLAGS_DEBUG,
1553
                \@CLINTFLAGS_PROD, \@CXXLINTFLAGS_PROD  );
1554
}
1555
 
1556
 
1557
#-------------------------------------------------------------------------------
1558
# Function        : __AddFlags
1559
#
1560
# Description     : Generic flag adding to lists routine
1561
#                   Internal use only
1562
#
1563
#                   Supports --Debug and --Prod options
1564
#                   if the appropriate list is present.
1565
#
1566
# Inputs          : Lots
1567
#                   References to compiler and lint flags for
1568
#                   common, debug and product builds.
1569
#
1570
#                   Not all the lists are needed.
1571
#
1572
# Returns         : Nothing
1573
#
1574
sub __AddFlags
1575
{
1576
    my ($textname, $eref,
1577
                   $f_all,      $flint_all,
1578
                   $f_debug,    $flint_debug,
1579
                   $f_prod,     $flint_prod ) = @_;
1580
 
1581
    #
1582
    #   Start added flags to the ALL lists
1583
    #
1584
    my $list = $f_all;
1585
    my $lintlist = $flint_all;
1586
    my $nowarn = 0;
1587
 
1588
    #
1589
    #   Process flags up front
1590
    #
1591
    $nowarn = 1 if ( grep (/^--NoWarn$/, @$eref) );
1592
 
1593
    #
1594
    #   Process all the user arguments
1595
    #
1596
    ADD:
1597
    foreach my $element ( @$eref )
1598
    {
1599
        #
1600
        #   Skip flags
1601
        #
1602
        if ( $element eq '--NoWarn' )
1603
        {
1604
            next;
1605
        }
1606
 
1607
        #
1608
        #   Detect --Debug and --Prod options and swap
1609
        #   lists accordingly.
1610
        #
1611
        if ( $element eq '--Debug' )
1612
        {
1613
            Error ("--Debug not supported for $textname") unless ( $f_debug );
1614
            $list = $f_debug;
1615
            $lintlist = $flint_debug;
1616
            next;
1617
        }
1618
 
1619
        if ( $element eq '--Prod' )
1620
        {
1621
            Error ("--Prod not supported for $textname") unless ( $f_prod );
1622
            $list = $f_prod;
1623
            $lintlist = $flint_prod;
1624
            next;
1625
        }
1626
 
1627
        #
1628
        #   Scan all the lists for a possible duplicates
1629
        #
1630
        foreach my $temp ( @$f_all, @$f_debug, @$f_prod ) {
1631
            if ($temp eq $element) {
1632
                Warning( "Duplicate $textname ignored '$element'") unless $nowarn;
1633
                next ADD;
1634
            }
1635
        }
1636
 
1637
        #
1638
        #   Add the flag to the compiler and lint lists
1639
        #
1640
        push( @$list, $element ) if $list;
1641
        push( @$lintlist, $element ) if $lintlist;
1642
    }
1643
}
1644
 
1645
sub WarnIfNastyFlag
1646
{
1647
    foreach  ( @_ )
1648
    {
1649
        Warning("Use of compiler flags discouraged (will be used): $_")
1650
            unless ( m/^-[DU]/ || m/^--Debug/ || m/^--Prod/ || /^--NoWarn/ );
1651
    }
1652
}
1653
 
1654
 
1655
sub AddDir
1656
{
1657
    AddIncDir( @_);
1658
    AddSrcDir( @_ );
1659
}
1660
 
1661
 
1662
sub AddIncDir
1663
{
1664
    _AddDir( 'AddIncDir', 'INCDIR', \@INCDIRS, \@S_INCDIRS, \@G_INCDIRS, \@L_INCDIRS, @_ );
1665
}                                                           
1666
 
1667
sub AddSrcDir                                               
1668
{                                                           
1669
    _AddDir( 'AddSrcDir', 'SRCDIR', \@SRCDIRS, \@S_SRCDIRS, \@G_SRCDIRS, \@L_SRCDIRS, @_ );
1670
}                                                           
1671
 
1672
sub AddLibDir                                               
1673
{                                                           
1674
    _AddDir( 'AddLibDir', 'LIBDIR', \@LIBDIRS, \@S_LIBDIRS, \@G_LIBDIRS, \@L_LIBDIRS, @_ );
1675
}
1676
 
1677
#-------------------------------------------------------------------------------
1678
# Function        : _AddDir
1679
#
1680
# Description     : Internal routine to add a directory to list of directories
1681
#                   Common code to simplify implementation of other directives
1682
#
1683
# Inputs          : $name           - Name of function
1684
#                   $udir           - User name of dir list
1685
#                   $dirref         - Reference to directory array
1686
#                   $s_dirref       - Reference to system directory array
1687
#                   $g_dirref       - Reference to global directory array
1688
#                   $l_dirref       - Reference to local directory array
1689
#                   @args           - User arguments
1690
#                                       - platforms
1691
#                                       - Directories and --Options
1692
#
1693
sub _AddDir
1694
{
1695
    my( $name, $udir, $dirref, $s_dirref, $g_dirref, $l_dirref, $platforms, @elements ) = @_;
1696
 
1697
    Debug ( "$name($platforms, @elements)" );
1698
    Error ( "$name: Insufficient arguments") unless ( @elements );
1699
    return if ( ! ActivePlatform($platforms) );
1700
 
1701
    #
1702
    #   Cleanup user parameters
1703
    #
1704
    foreach ( @elements )
1705
    {
1706
        s/^\s+//;                               # Remove leading space
1707
        s/\s+$//;                               # Remove trailing spaces
1708
        s~/$~~;                                 # Remove trailing /
1709
        s~//~/~g;                               # Remove multiple /
1710
    }
1711
 
1712
#.. Collect arguments
1713
    my $tlist_ref = $ScmGlobal ? $g_dirref : $l_dirref; # "current" scope ....
1714
    my $nowarn = 0;
1715
    my $nodepend = 0;
1716
    my @dirs;
1717
 
1718
    foreach ( @elements )
1719
    {
1720
        if ( ! /^--/ ) {                        # Collect directories
1721
            push @dirs, $_;
1722
 
1723
        } elsif (/^--Local$/) {                 # "local" scope ....
1724
            $tlist_ref = $l_dirref;
1725
 
1726
        } elsif (/^--Global$/) {                # "global" scope ...
1727
            $tlist_ref = $g_dirref;
1728
 
1729
        } elsif (/^--System$/) {                # "system" scope ...
1730
            $tlist_ref = $s_dirref;
1731
 
1732
        } elsif (/^--NoDepend$/) {              # Split from dependency list
1733
            if ( $udir eq 'INCDIR' ) {          # AddIncDir only
1734
                $nodepend = 1;
1735
            }
1736
 
1737
        } elsif (/^--NoWarn$/) {                # Disable warnings
1738
            $nowarn = 1;
1739
 
1740
        } elsif (/^--(.*)/) {
1741
            Message( "$name: unknown option $_ -- ignored\n" );
1742
 
1743
        }
1744
    }
1745
 
1746
    Error ( "$name: No directory specified: ($platforms, @elements)" )
1747
        unless ( @dirs );
1748
 
1749
 
1750
#.. Push source path(s)
1751
    foreach ( @dirs )
1752
    {
1753
        #
1754
        #   Add to complete list of directories
1755
        #   Warn on duplicates
1756
        #
1757
        unless ( UniquePush( $dirref, $_) )
1758
        {
1759
            Warning( "Duplicate $udir ignored '$_'" )
1760
                unless ( $nowarn );
1761
            next;
1762
        }
1763
 
1764
        #
1765
        #   Check that the directory actually exists
1766
        #   If the path contains a $(XXXXX) then it can't be checked
1767
        #
1768
        if ( index( $_, '$' ) == -1 )
1769
        {
1770
            Warning( "$name. Directory not found: $_",
1771
                     "Current directory         : $::Cwd",
2450 dpurdie 1772
                     "Cannot resolved Directory : " . AbsPath($_, $::Cwd, 1),
227 dpurdie 1773
                       )
1774
                unless ( $nowarn || -d $_ );
1775
        }
1776
 
1777
        #
1778
        #   Add to suitable list
1779
        #
1780
        push @{$tlist_ref}, $_;
6133 dpurdie 1781
        ToolsetFiles::AddDir($_, 'Include');
227 dpurdie 1782
 
1783
        #
1784
        #   Add to the no dependancy list (ie generated depend file)
1785
        #   Only used by AddIncDir, accepted by AddSrcDir
1786
        #
1787
        push( @NODEPDIRS, $_ )
1788
            if ($nodepend);
1789
    }
1790
}
1791
 
6177 dpurdie 1792
#-------------------------------------------------------------------------------
1793
# Function        : ExtendIncDir 
1794
#
1795
# Description     : Allow the directory search paths to be extended into sub
1796
#                   directories.
1797
#                   
1798
#                   Limit use, but ...
1799
#
1800
# Inputs          : $platform       - Active platforms
1801
#                   ...             - Path extensions
1802
#
1803
# Returns         : 
1804
#
1805
my  %ExtendIncDirSeen;
1806
sub ExtendIncDir
1807
{
1808
    my( $platforms, @paths ) = @_;
1809
    Debug2( "ExtendIncDir($platforms, @paths)" );
1810
    return if ( ! ActivePlatform($platforms) );
1811
    Error ('ExtendIncDir. No extensions listed') unless @paths;
1812
    #
1813
    #   Ensure the user only extends the paths once.
1814
    #   Could silently discard excess - better to force the user to get it right
1815
    #
1816
    foreach my $path ( @paths) {
1817
        ReportError ('ExtendIncDir. Multiple defintions for: ' . $path) if exists $ExtendIncDirSeen{$path}; 
1818
        $ExtendIncDirSeen{$path} = 0;
1819
    }
1820
    ErrorDoExit();
227 dpurdie 1821
 
6177 dpurdie 1822
    #
1823
    #   Zip though all the packages and extend the search paths
1824
    #   Also gets those in the interface directory
1825
    #
1826
    for my $package (@{$::ScmBuildPkgRules{$ScmPlatform} })
1827
    {
1828
        #DebugDumpData("package", $package);
1829
        foreach my $path ( @paths)
1830
        {
1831
            if ( $package->{PINCDIRS})
1832
            {
1833
                my @output;
1834
                foreach my $pdir ( @{$package->{PINCDIRS}})
1835
                {
1836
                    my $tdir = catdir ($pdir, $path);
1837
                    my $adir = catdir ($package->{ROOT}, $tdir);
1838
                    if ( -d $adir) {
1839
                        Verbose("Extending $package->{DNAME} $package->{VERSION}: $tdir");
1840
                        push @output, $tdir;
1841
                        $ExtendIncDirSeen{$path}++;
1842
                    }
1843
                    push @output, $pdir;
1844
                }
1845
              @{$package->{PINCDIRS}} = @output;
1846
            }
1847
        }
1848
    }
1849
 
1850
    #
1851
    #   Report extensions that have not been used
1852
    #
1853
    foreach my $path ( @paths) {
1854
        ReportError ('ExtendIncDir. Search path not extendable: ' . $path) unless $ExtendIncDirSeen{$path}; 
1855
    }
1856
 
1857
    ErrorDoExit();
1858
}
1859
 
1860
 
227 dpurdie 1861
sub AddProg
1862
{
1863
    my( $platforms, @progs ) = @_;
1864
 
1865
    Debug2( "AddProg($platforms, @progs)" );
1866
 
1867
    return if ( ! ActivePlatform($platforms) );
1868
 
285 dpurdie 1869
    foreach my $prog (@progs)
227 dpurdie 1870
    {
289 dpurdie 1871
        my $pProg = $PROGS->Get($prog);
227 dpurdie 1872
        Warning( "Duplicate prog ignored '$prog'" )
289 dpurdie 1873
            if ( $pProg );
1874
        $pProg = $PROGS->NewAdd($prog)
227 dpurdie 1875
    }
1876
}
1877
 
1878
 
1879
sub AddSourceType
1880
{
1881
    my( $ext, $type ) = @_;
1882
 
1883
    Debug2( "AddSourceType(@_)" );
1884
 
1885
    #
1886
    #   Default Source Type (C)
1887
    #
1888
    $type = ".c" unless ( $type );
1889
 
1890
    Error ("Source type '$ext' not allowed")
1891
        if ( $ext !~ /^\.\w+$/ );
1892
 
1893
    $type = lc($type)
1894
        if ( $::ScmHost ne "Unix" );
1895
    $ScmSourceTypes{ $ext } = $type;
1896
}
1897
 
1898
 
1899
sub AddSourceFile
1900
{
1901
    my( $platforms, @elements ) = @_;
1902
 
1903
    Debug2( "AddSourceFile($platforms, @elements)" );
1904
    return if ( ! ActivePlatform($platforms) );
1905
 
285 dpurdie 1906
    foreach my $path ( @elements )
227 dpurdie 1907
    {
1908
        __AddSourceFile( 1, $path );
1909
    }
1910
}
1911
 
1912
 
1913
#-------------------------------------------------------------------------------
1914
# Function        : __AddSourceFile
1915
#
1916
# Description     : Internal function
1917
#                   Add a source file to internal lists
1918
#
1919
#                   Assumes that the current platform is ACTIVE
1920
#
1921
# Inputs          : push    0: Don't push onto OBJS (non-shared objfiles)
1922
#                   path    Filename.extension
1923
#                   obj     object file name (optional)
1924
#                   type    Type of file. "" -> auto detect
1925
#
1926
# Returns         : True        - File is a 'known' source file
1927
#                   False       - File is not a 'known' source file
1928
#
1929
sub __AddSourceFile
1930
{
1931
    my( $push, $path, $obj, $type ) = @_;
271 dpurdie 1932
    my( $filename, $ext, $srcfile, $is_obj, $ext_type, $result );
227 dpurdie 1933
 
271 dpurdie 1934
    $filename = StripDir($path);                # file name
227 dpurdie 1935
 
1936
    $ext  = StripFile($path);                   # extension
1937
    $ext = lc($ext)
1938
        if ( $::ScmHost ne "Unix" );
1939
 
271 dpurdie 1940
    if (! ($srcfile = $SRCS{$filename})) {
227 dpurdie 1941
        $srcfile = $path;                       # generated
1942
    }
1943
 
271 dpurdie 1944
    $obj  = StripExt( $filename )               # Base name of object file
227 dpurdie 1945
        if ( ! defined($obj) || $obj eq "" );
1946
 
1947
    $type = ""                                  # optional type
1948
        if ( ! defined( $type ) );
1949
 
1950
    #
1951
    #   Push file onto a suitable source file list
1952
    #
1953
    $result = 0;
1954
    $ext_type = "";                             # map extension
1955
    $ext_type = $ScmSourceTypes{ $ext }
1956
        if ( exists( $ScmSourceTypes{ $ext } ) );
1957
    $result = 1 if ( $ext_type );
1958
 
1959
    if ( $type eq "" && defined $::ScmToolsetProgSource{$ext} )
1960
    {
1961
        Debug( "SourceFile: $path is ToolsetProgSource   -> $srcfile" );
1962
        push( @CSRCS, $srcfile );
1963
        $result = 1;
1964
    }
1965
    elsif ( ($type eq "" && $ext_type eq ".h") || ($type eq ".h") )
1966
    {
1967
        Debug( "SourceFile: $path is .h   -> $srcfile" );
1968
        push( @CHDRS, $srcfile );
1969
    }
1970
    elsif ( ($type eq "" && $ext_type eq ".inc") || ($type eq ".inc") )
1971
    {
1972
        Debug( "SourceFile: $path is .inc -> $srcfile" );
1973
        push( @ASHDRS, $srcfile );
1974
    }
1975
    elsif ( ($type eq "" && $ext_type eq ".c") || ($type eq ".c") )
1976
    {
1977
        Debug( "SourceFile: $path is .c   -> $srcfile=$obj" );
1978
        push( @CSRCS, $srcfile );
1979
        $is_obj = 1;
1980
    }
1981
    elsif ( ($type eq "" && $ext_type eq ".cc") || ($type eq ".cc") )
1982
    {
1983
        Debug( "SourceFile: $path is .cc  -> $srcfile=$obj" );
1984
        push( @CXXSRCS, $srcfile );
1985
        $is_obj = 1;
1986
    }
1987
    elsif ( ($type eq "" && $ext_type eq ".asm") || ($type eq ".asm") )
1988
    {
1989
        Debug( "SourceFile: $path is .asm -> $srcfile=$obj" );
1990
        push( @ASSRCS, $srcfile );
1991
        $is_obj = 1;
1992
    }
1993
    elsif ( $ext_type eq "--Ignore" )
1994
    {   # ignored ...
1995
        #   .x      "rpcgen" source files
1996
        #   .ini    Configuration
1997
        #   .sh     Shell script
1998
    }
1999
    else
2000
    {
2001
        Debug( "SourceFile: $path is unknown file type" );
2002
 
2003
        #
2004
        #   Insert source files with unknown extensions onto lists
2005
        #   of there own type
2006
        #
2007
        if ( $ext )
2008
        {
2009
            (my $varname = uc ( $ext . 'SRCS')) =~ s~\.~~g;
2010
            no strict 'refs';
2011
            push @$varname, $srcfile;
2012
            use strict 'refs';
2013
        }
2014
    }
2015
 
2016
    #
271 dpurdie 2017
    #   See if there is a hook function for this type of source file
2018
    #   Invoke user function to perform additional processing on the file
2019
    #
2020
    if ( %MF_RegisterSrcHooks )
2021
    {
2022
        my @listeners;
2023
        push @listeners, @{$MF_RegisterSrcHooks{$ext}} if ( exists $MF_RegisterSrcHooks{$ext} );
2024
        push @listeners, @{$MF_RegisterSrcHooks{'*'}}  if ( exists $MF_RegisterSrcHooks{'*'} );
2025
        while ( @listeners )
2026
        {
2027
            Debug( "RegisterSrcHook: Invoke SrcHook function" );
2028
            my ($fname, @args) = @{shift @listeners};
2029
            &$fname ( $srcfile ,$filename, $obj, $ext ,@args );
2030
        }
2031
    }
2032
 
2033
    #
227 dpurdie 2034
    #   Object files are saved in
2035
    #       OBJSOURCE   - Generate a recipe to create the object
2036
    #       OBJS        - A list of ALL non-shared object files
2037
    #
6133 dpurdie 2038
    if ( $is_obj && $::o && $ScmNotGeneric )
227 dpurdie 2039
    {
2040
        $OBJSOURCE{ "$obj" } = $srcfile;
2041
        push( @OBJS, $obj )
2042
            if ($push);
2043
    }
2044
 
2045
    #
2046
    #   Indicate to the user that the file is a 'known' source file
2047
    #   This implies that the file is required early in the build process
2048
    #   and may need to be generated early.
2049
    #
2050
    return $result;
2051
}
2052
 
2053
#-------------------------------------------------------------------------------
2054
# Function        : SetValue
2055
#
2056
# Description     : Defines a variable that can be used within the makefile.pl
2057
#                   Use sparingly
2058
#                   An attempt to formalise a mechanism that is used anyway, but
2059
#                   with correct platform detection
2060
#
2061
# Inputs          : $platform       - Platform selector
2062
#                   $name           - Name to set
2063
#                   $value          - Value to set
2064
#                   options         - Options
2065
#                                       --NoWarn
2066
#                                       --Project=xxxx[,xxxx]+
2067
#                                       --
2068
#
2069
sub SetValue
2070
{
2071
    my( $platforms, @elements ) = @_;
2072
    my $name;
2073
    my $value;
2074
    my $nowarn;
2075
    my $nomoreswicthes = 0;
2076
 
2077
    Debug2( "SetValue($platforms, @elements)" );
2078
 
2079
    return if ( ! ActivePlatform($platforms) );
2080
 
2081
    #
2082
    #   Process elements extracting values and options
2083
    #
2084
    foreach ( @elements )
2085
    {
2086
        if ( m/^--$/ ) {
2087
            $nomoreswicthes = ! $nomoreswicthes;
2088
            next;
2089
        }
2090
 
2091
        if ( m/^--/ && ! $nomoreswicthes )
2092
        {
2093
 
2094
            if ( m/^--NoWarn/ ) {
2095
                $nowarn = 1;
2096
 
2097
            } elsif ( m/^--Project=(.*)/ ) {
2098
                return unless ( ActiveProject( $1) );
2099
 
2100
            } else {
2101
                Error ("SetValue: Unknown option: $_");
2102
 
2103
            }
2104
 
2105
        } elsif ( ! defined $name ) {
2106
            $name = $_;
2107
 
2108
        } elsif ( ! defined $value ) {
2109
            $value = $_;
2110
 
2111
        } else {
2112
            Error ("SetValue: $name. Too many parameters" );
2113
 
2114
        }
2115
    }
2116
 
2117
    #
2118
    #   Warn if the named variable already exists
2119
    #   It may be a JATS internal or it may be a user.
2120
    #
2121
    unless ( $nowarn )
2122
    {
2123
        no strict 'refs';
2124
        Warning("SetValue: $name. Redefined") if defined ( $$name );
2125
        use strict 'refs';
2126
    }
2127
 
2128
    #
2129
    #   Set the value
2130
    #
2131
    no strict 'refs';
2132
    $$name = $value;
2133
    use strict 'refs';
2134
}
2135
 
2136
#-------------------------------------------------------------------------------
2137
# Function        : SetList
2138
#
2139
# Description     : Defines a list variable that can be used within the makefile.pl
2140
#                   Use sparingly
2141
#                   An attempt to formalise a mechanism that is used anyway, but
2142
#                   with correct platform detection
2143
#
2144
# Inputs          : $platform       - Platform selector
2145
#                   $name           - Name to set
2146
#                   $value,...      - Values to set
2147
#                   options         - Options
2148
#                                       --NoWarn
2149
#                                       --Project=xxxx[,xxxx]+
2150
#                                       --Unique
2151
#                                       --Clear
2152
#                                       --Append
2153
#                                       --
2154
#
2155
my %SetList_names;
2156
sub SetList
2157
{
2158
    my( $platforms, @elements ) = @_;
2159
    my $name;
2160
    my @value;
2161
    my $nowarn;
2162
    my $unique;
2163
    my $clear;
2164
    my $nomoreswicthes = 0;
2165
 
2166
    Debug2( "SetList($platforms, @elements)" );
2167
 
2168
    return if ( ! ActivePlatform($platforms) );
2169
 
2170
    #
2171
    #   Process elements extracting values and options
2172
    #
2173
    foreach ( @elements )
2174
    {
2175
        if ( m/^--$/ ) {
2176
            $nomoreswicthes = ! $nomoreswicthes;
2177
            next;
2178
        }
2179
 
2180
        if ( m/^--/ && ! $nomoreswicthes )
2181
        {
2182
            if ( m/^--NoWarn/ ) {
2183
                $nowarn = 1;
2184
 
2185
            } elsif ( m/^--Project=(.*)/ ) {
2186
                return unless ( ActiveProject( $1) );
2187
 
2188
            } elsif ( m/^--Unique/ ) {
2189
                $unique = 1;
2190
 
2191
            } elsif ( m/^--Clear/ ) {
2192
                $clear = 1;
2193
 
2194
            } elsif ( m/^--Append/ ) {
2195
                $clear = 0;
2196
 
2197
            } else {
2198
                Error ("SetList: Unknown option: $_");
2199
            }
2200
        } elsif ( ! defined $name ) {
2201
            $name = $_;
2202
 
2203
        } else {
2204
            push @value, $_;
2205
 
2206
        }
2207
    }
2208
 
2209
    Error ("SetList: No name specified") unless ( $name );
2210
 
2211
    #
2212
    #   Warn if the named variable already exists
2213
    #   It may be a JATS internal or it may be a user.
2214
    #
2215
    #   Only do this iff the name is not known to this function
2216
    #   Keep a list a names that have been set.
2217
    #
2218
    if ( ! $SetList_names{$name} && ! $nowarn )
2219
    {
2220
        no strict 'refs';
4455 dpurdie 2221
        Warning("SetList: $name. Defined outside the ScanList/SetList directive","May clash with Jats internals") if ( @$name );
227 dpurdie 2222
        use strict 'refs';
2223
    }
2224
    $SetList_names{$name} = 1;
2225
 
2226
    #
2227
    #   Clear list
2228
    #
2229
    if ( $clear )
2230
    {
2231
        no strict 'refs';
2232
        @$name = ();
2233
        use strict 'refs';
2234
    }
2235
 
2236
    #
2237
    #   Set the value
2238
    #
2239
    no strict 'refs';
2240
    if ( $unique ) {
2241
        UniquePush( \@$name, @value);
2242
    } else {
2243
        push @$name, @value;
2244
    }
2245
    use strict 'refs';
2246
}
2247
 
2248
#-------------------------------------------------------------------------------
2249
# Function        : ScanList
2250
#
2251
# Description     : Create a list by scanning for files in a directory
2252
#                   The files may be in a local directory or within a package
2253
#                   Care must be taken when using a package as the results
2254
#                   may differ bewteen BuildPkgArchive and LinkPkgArchive
2255
#
2256
#                   Interworks with SetList
2257
#
2258
# Inputs          : $platform       - Platform selector
2259
#                   $name           - Name to set
2260
#                   $value,...      - Values to set
2261
#                   options         - Options
2262
#                                       --NoWarn
2263
#                                       --Project=xxxx[,xxxx]+
2264
#                                       --Unique
2265
#                                       --Clear
2266
#                                       --Append
2267
#
2268
#                                       --Package=xxxx[,ext]
2269
#                                       --Dir=xxx
2270
#
2271
#                                       --Subdir=yyy
2272
#                                       --DirListOnly
2273
#                                       --FileListOnly
335 dpurdie 2274
#                                       --Recurse (default)
227 dpurdie 2275
#                                       --NoRecurse
335 dpurdie 2276
#                                       --FullPath (default)
2277
#                                       --NoFullPath
227 dpurdie 2278
#
2279
#                                       --FilterIn=xxx
2280
#                                       --FilterInRe=xxx
2281
#                                       --FilterOut=xxx
2282
#                                       --FilterOutRe=xxx
2283
#
2284
# Returns         :
2285
#
2286
sub ScanList
2287
{
2288
    my( $platforms, @elements ) = @_;
2289
    my $name;
2290
    my $package;
2291
    my $dir;
2292
    my $subdir;
2293
    my @set_args;
2294
    my $search = JatsLocateFiles->new('Recurse','FullPath' );
2295
 
2296
    Debug2( "ScanList($platforms, @elements)" );
2297
 
2298
    return if ( ! ActivePlatform($platforms) );
2299
 
2300
    #
2301
    #   Process elements extracting values and options
2302
    #
2303
    foreach ( @elements )
2304
    {
2305
        if ( m/^--Unique|--Clear|--Append|--NoWarn/ ) {
2306
            push @set_args, $_;
2307
 
2308
        } elsif ( m/^--Project=(.*)/ ) {
2309
            return unless ( ActiveProject( $1) );
2310
 
2311
        } elsif ( m/^--Package=(.*)/ ) {
2312
            $package = $1;
2313
 
2314
        } elsif ( m/^--Dir=(.*)/ ) {
2315
            $dir = $1;
2316
 
2317
        } elsif ( m/^--Subdir=(.*)/ ) {
2318
            $subdir = $1;
2319
 
2320
        } elsif ( $search->option( $_ ) ) {
2321
            Verbose ("Search Option: $_" );
2322
 
2323
        } elsif ( m/^--/ ) {
2324
            Error ("ScanList: Unknown option: $_");
2325
 
2326
        } elsif ( ! defined $name ) {
2327
            $name = $_;
2328
 
2329
        } else {
2330
                Error ("ScanList $name: Unknown option: $_");
2331
 
2332
        }
2333
    }
2334
 
2335
    Error ("ScanList: No variable name specified") unless ( $name );
2336
    Error ("ScanList: Must Specify --Dir or --Package") unless ( $dir || $package );
2337
    Error ("ScanList: --Dir and --Package are mutually exclusive") if ( $dir && $package );
2338
 
2339
    #
2340
    #   Locate the base of the scan
2341
    #   This may be either a package name or a local directory
2342
    #
2343
    #   Its no use allowing the user to use OBJ/LIB/BIN directories as the
2344
    #   directories MUST exist at build time. Don't really want the user doing
2345
    #   that level of poking out of a package
2346
    #
2347
    if ( $package )
2348
    {
2349
        $dir = GetPackageBase( "ScanList", $package );
2350
        Error ("ScanList: Package not found: $package") unless ( $dir );
2351
    }
2352
    else
2353
    {
2354
        Error ("ScanList: Root directory not found: $dir") unless ( -d $dir );
2355
    }
2356
    if ( $subdir )
2357
    {
2358
        $dir .= "/" . $subdir;
2359
        Error ("ScanList: Sub directory not found: $subdir") unless ( -d $dir );
2360
    }
2361
 
2362
    #
2363
    #   Use SetList to do the rest of the work
2364
    #
2365
    SetList( $platforms, $name, @set_args, '--', $search->search($dir) );
2366
}
2367
 
2368
 
2369
sub Init
2370
{
2371
    push( @INITS, @_ );
2372
}
2373
 
2374
#-------------------------------------------------------------------------------
2375
# Function        : Generate
2376
#
2377
# Description     : Legacy Function - don't use unless you have too.
2378
#                   Flags files that are to be generated during the
2379
#                   early 'generate' make phase. Will also add named files
2380
#                   to various internal lists
2381
#
2382
#                   Intended to be used in conjunction with the 'Rule' directive
2383
#                   to flag header and source files that need to be created early
2384
#                   in the build process.
2385
#
2386
# Inputs          : See GenerateSrcFile
2387
#
2388
# Returns         : 
2389
#
2390
sub Generate
2391
{
2392
    my( $platforms, @elements ) = @_;
2393
 
2394
    Debug2( "Generate($platforms, @elements)" );
2395
 
2396
    return if ( ! ActivePlatform($platforms) );
2397
    Message("Generate directive used. Consider replacing with GenerateFiles");
2398
 
2399
    #
2400
    #   Use Non-warning version to do the hard work
2401
    #
2402
    GenerateSrcFile( 1, @elements );
2403
}
2404
 
2405
#-------------------------------------------------------------------------------
2406
# Function        : Generated
2407
#
2408
# Description     : Legacy Function - don't use unless you have too.
2409
#                   Flags files that are generated by misc Rules
2410
#
2411
#                   Intended to be used in conjunction with the 'Rule' directive
2412
#                   to mark files that have been generated, so that they can be
2413
#                   cleaned up.
2414
#
2415
#                   Note the difference to the 'Generate' directive which will
2416
#                   ensure that the Rule will be run in the 'generate' phase,
2417
#                   this directive doesn't.
2418
#
2419
# Inputs          : Files with internal Makefile Paths and codes
2420
#                   Eg: Generated( '*', "\$(LIBDIR)/libcsf\$(GBE_TYPE).\${a}" );
2421
#                   See why its YUK!
2422
#
2423
# Returns         : 
2424
#
2425
sub Generated
2426
{
2427
    my( $platforms, @elements ) = @_;
2428
    my( @args );
2429
 
2430
    return if ( ! ActivePlatform($platforms) );
2431
    Debug2( "Generated($platforms, @elements)" );
2432
 
2433
    #.. Collect arguments
2434
    #
2435
    foreach ( @elements )
2436
    {
2437
        if ( /^-(.*)/ )
2438
        {
2439
            Debug( "Gen: arg $_" );
2440
            push ( @args, $_);
2441
        }
2442
    }
2443
 
2444
    #.. Push source file(s)
2445
    #
2446
    foreach ( @elements )
2447
    {
2448
        if ( ! /^-(.*)/ )
2449
        {
2450
            Debug( "Generated: $_ (@args)" );
2451
            push (@USERGENERATED, $_);
2452
 
2453
            #
2454
            #   Add the file to the list of known source files
2455
            #   This will allow them to be packaged
2456
            #
2457
            GenerateSrcFile (0, $_ );
2458
        }
2459
    }
2460
}
2461
 
2462
 
2463
#-------------------------------------------------------------------------------
2464
# Function        : GenerateSrcFile
2465
#
2466
# Description     : Internal Function (No $platform)
2467
#                   Determine how to handle a 'Generated' file
2468
#
2469
#
2470
# Inputs          : $generated          - 0: Don't add to GENERATED List
2471
#                                         1: Add to GENERATED List
2472
#                                         2: Add to GENERATED List, if a source file
2473
#                   FileName(s)         - Name of one or more files to process
2474
#                                         All files are processed in the same way
2475
#                                         These file may contain Makefile prefixes
2476
#                                         ie: $(OBJDIR)/file.obj
2477
#                   Options:
2478
#                       --c             - Hint: Its a "C" file
2479
#                       --cpp           - Hint: Its a C++ file
2480
#                       --asm           - Hint: Its an ASM file
2481
#                       -*              - Save as argument attached to the file
2482
#
303 dpurdie 2483
# Returns         : Number of 'source' file
227 dpurdie 2484
#
2485
sub GenerateSrcFile                             # Internal Function - no $platform
2486
{
2487
    my( $generated, @elements ) = @_;
2488
    my( $type, @args );
303 dpurdie 2489
    my $result = 0;
227 dpurdie 2490
 
2491
    Debug2( "GenerateSrcFile($generated,@elements)" );
2492
 
2493
    #.. Collect arguments
2494
    #
2495
    $type = "";
2496
    foreach ( @elements )
2497
    {
2498
        if ( /^--c$/ ) {
2499
            Debug( "Gen: --c" );
2500
            $type = ".c";
2501
 
2502
        } elsif ( /^--cpp$/ ) {
2503
            Debug( "Gen: --cpp" );
2504
            $type = ".cc";
2505
 
2506
        } elsif ( /^--asm$/ ) {
2507
            Debug( "Gen: --asm" );
2508
            $type = ".asm";
2509
 
2510
        } elsif ( /^-(.*)/ ) {
2511
            Debug( "Src: arg $_" );
2512
            push @args, $_;
2513
        }
2514
    }
2515
 
2516
    #.. Process source file(s)
2517
    #
2518
    #   Determine if file is already a known SRCS file - skip if already known
2519
    #   Update SRCS data
2520
    #   Update SRC_TYPE data
2521
    #   Update SRC_ARGS data
2522
    #   Add the file to a suitable source file list ie: @CHDRS,...
2523
    #   Flag as a GENERATED file - These will be processed during the 'generate' phase
2524
    #
2525
    foreach my $source ( @elements )
2526
    {
2527
        next if ( $source =~ /^-(.*)/ );                # Not a source file
2528
 
2529
        my $basename = StripDir( $source );
2530
        Debug( "Generate: $source=$basename (@args)" );
2531
 
2532
        if ($SRCS{ $basename }) {
2533
            Warning( "Duplicate src ignored '$source'" );
2534
            next;
2535
        }
2536
        $SRCS{ $basename } = $source;
2537
 
2538
        HashJoin( \%SRC_ARGS, $;, $basename, @args )
2539
            if (@args);
2540
 
2541
        $SRC_TYPE{ $basename } = $type
2542
            if ($type);
2543
 
2544
        #
5867 dpurdie 2545
        #   Add the file to any source file lists that may like to know
227 dpurdie 2546
        #   about this file.
2547
        #
2548
        #   If the file was a known source file, then it may need to be generated
2549
        #   very early in the build process.
2550
        #
2551
        my $src_file_type = __AddSourceFile( 1, $basename );
285 dpurdie 2552
        if ($generated == 1 || ($src_file_type && $generated > 1) )
227 dpurdie 2553
        {
2554
            push(@GENERATED, $source);
303 dpurdie 2555
            $result++;
227 dpurdie 2556
        }
2557
        else
2558
        {
2559
            push(@GENERATED_NOTSRC, $source);
2560
        }
2561
    }
303 dpurdie 2562
 
2563
    return $result;
227 dpurdie 2564
}
2565
 
2566
#-------------------------------------------------------------------------------
2567
# Function        : GenerateFiles
2568
#
2569
# Description     : Generate files in a controlled manner using a specified
2570
#                   tool to perform the task
2571
#
2572
# Inputs          : $1      - platform specifier '*' (comma delemitered)
2573
#                   $2      - Tool Name
2574
#                   $3...   - Command line argument to generate files with embedded information
2575
#                           - or options. Multiple command line arguments will be joind with
2576
#                             a single space
2577
#
2578
#                   The generated files will be placed in the OBJ directory for
2579
#                   the current target platform. This allows different files to
2580
#                   be generated for each platform, without collision.
2581
#
2582
#                   The full name of the generated files will be added to the list of
2583
#                   source files. Thus the user does not need to know the
2584
#                   full name of the file - it will be tracked by JATS.
2585
#
2586
#                   If a generated file is a header file, then the OBJ directory
2587
#                   will be added as AddIncDir() so that the header files can be
2588
#                   extracted
2589
#
2590
#                   If a generated file is a "C"/"C++" source file, then it will
2591
#                   compiled and the object file made available
2592
#
2593
#                   The tool name may be:
2594
#                       --Tool=name  or "name"
2595
#                               Look in the tool paths in Packages
2596
#                               Look in the JATS tool directory for named script
2597
#                               Look in the JATS bin directory for the named exe
2598
#                               Look in the users path ( and generate a warning )
2599
#                               Give up and hope magic happens later
2600
#                       --Script=name
2601
#                               Resolve the name using known Src paths
2602
#                               The script may be generated and need not exist
2603
#                               at the time the makefile is created.
2604
#                       --Shell
2605
#                               The command line argument is a shell script that
2606
#                               will be passed to a simple shell.
263 dpurdie 2607
#                       --Prog=name
2608
#                               Resolve to a program generated within this makefile
227 dpurdie 2609
#
2610
#
2611
#                   The command line argument contains keywords to allow
2612
#                   information to be extracted from the line. Keywords are:
2613
#
2614
#                       --Generated(xxx)        - xxx is a generated file
2615
#                                                 It will be placed in the OBJDIR
2616
#                       --GeneratedCommon(xxx)  - xxx is a generated file
2617
#                                                 File will be placed in the local directory
2618
#                                                 and will be shared by by all platforms
2619
#                       --GeneratedObject(xxx)  - xxx is a generated object file
2620
#                                                 It will be placed in the OBJDIR and will
2621
#                                                 have a suitable object suffix appended
2622
#                       --GeneratedProg(xxx)    - xxx is a generated program file
2623
#                                                 It will be placed in the BINDIR
2624
#                       --Prerequisite(xxx)     - xxx is a prerequisite file
2625
#                                                 The full name of the file will be located
2626
#                                                 and used within the command. The file will
2627
#                                                 be added to the list of recipe prerequisites
2628
#                       --GeneratedDirectory(xxx)
2629
#                       --GeneratedCommonDirectory(xxx)
2630
#                       --GeneratedObjectDirectory(xxx)
2631
#                       --GeneratedProgDirectory(xxx)
6177 dpurdie 2632
#                                               - xxx is a generated file
2633
#                                                 The containing directory will be placed on the command line
227 dpurdie 2634
#                       --PackageBase(xxx)      - xxx is a package. The keyword will be replaced
2635
#                                                 with the pathname to the package. If the package
2636
#                                                 has been copied in the the interface directory
2637
#                                                 then the interface directory will be used.
2638
#                       --PackageInfo(xxx,--opt)- xxx is a package. The keyword will be replaced
2639
#                                                 with the information requested.
2640
#                                                 Options are:
2641
#                                                   --path
2642
#                                                   --version
2643
#                                                   --fullversion
2644
#                                                   --project
2645
#
2646
#                       Where "xxx" may be of the form:
2647
#                           name,option[,option]
2648
#
2649
#                       Flag options are:
2650
#                           --file             - The file part of the full name
2651
#                           --dir              - The directory part of the full name
2652
#                           --abspath          - Abs path
2653
#                           --absdrive         - Abs path with drive letter
2654
#
2655
#                       --Var(Name,opt)         - Name is the name of a recognised varable
2656
#                                                 Refer to ExpandGenVar function for details
2657
#                                                 of Name and available options
2658
#                                                 The expanded text will be replaced with an
2659
#                                                 suitable makefile variables that will be
2660
#                                                 replaced at run-time.
2661
#
2662
#                   The keyword will be replaced with the resolved name. This may be a file,
2663
#                   a directory or other text.
2664
#
2665
#                   Options do not alter command line text. They do affect the way the command is
2666
#                   processed.
2667
#                   Options include:
2668
#                       --Prereq=name           - The name of a file to add as a prerequisite
2669
#                                                 The file does not form part of the command line
2670
#                       --Created=name          - The name of a file to treat as a generated file
2671
#                       --CreatedCommon=name      The file does not form part of the command line 
2672
#                       --CreatedObject=name
2673
#                       --CreatedProg=name
2674
#
2675
#                       --NoVarTag              - Modifes --Var operation to suppress tags
2676
#                       --NoWarn                - Don't warn if no prerequistes found
2677
#                       --NoGenerate            - Don't warn if no generated files are found
2678
#                                                 Will create a dummy rule name and the recipe will
2679
#                                                 always be executed during the 'GenerateFiles' phase
2680
#                       --UnknownPreq           - Prerequisites are not fully known.
2681
#                                                 Rebuild the target whenever it is required.
2682
#                       --AutoGenerate          - Examine the generated file to determine when the
2683
#                                                 tools is to be run.
261 dpurdie 2684
#                                                 Must be before any options that declare
2685
#                                                 creation of files.
227 dpurdie 2686
#                       --Text=<text>           - Display text for command
2687
#
263 dpurdie 2688
#                       --Clean[=arg]           - Call script with arg[-clean] for cleaning.
2689
#                       --PreDelete             - Delete generated files before running the command
6415 dpurdie 2690
#                       --RecipeTag=Name        - Name the recipe
2691
#                                                 Allows recipe to be called by Name and clean_Name
227 dpurdie 2692
#
2693
#               Eg: GenerateFiles ( '*', "--Tool=mod_if.pl",
2694
#                                        "-src --Prerequisite(udh_module.cfg)",
2695
#                                        "-direct -hdr --Generated(udp.h) -quiet" );
2696
#
2697
my $NoGenIndex = 0;
6415 dpurdie 2698
my %recipeTags;
227 dpurdie 2699
sub GenerateFiles
2700
{
6415 dpurdie 2701
    #
2702
    #   Remove undfined arguments
2703
    #   Simplifies programatic construction of argument lists
2704
    #
2705
    my ( $platforms, $tool, @args) = grep defined, @_;
227 dpurdie 2706
 
2707
    return if ( ! ActivePlatform($platforms) );
2708
 
2709
    Debug2( "GenerateFiles:($platforms, $tool, @args)" );
2710
 
2711
    my @preq_files;
2712
    my $preq_unknown;
2713
    my @gen_files;
2714
    my $shell_script;
2715
    my $shell_cmds;
2716
    my @tool_args;
2717
    my $no_warn;
2718
    my $clean_tag;
2719
    my $text;
2720
    my $gtype = 1;
303 dpurdie 2721
    my @has_source;
227 dpurdie 2722
    my @var_opts;
261 dpurdie 2723
    my @genreq_seen;
263 dpurdie 2724
    my $predelete;
6415 dpurdie 2725
    my $recipeTag;
227 dpurdie 2726
 
2727
    #
2728
    #   Process the first argument - this describes the program that will be used
2729
    #   to generate the files. It may be:
2730
    #       --Tool          - A Jats Tool or Plugin
2731
    #       --Script        - A shell script file
2732
    #       --Shell         - Raw shell commands
2733
    #       --Prog          - A program created within the Makefile
2734
    #
2735
    #
2736
    if ( $tool =~ /^--Tool=(.*)/ || $tool =~ /^([^-].*)/)
2737
    {
2738
        $tool = $1;
2739
        my $tool_no_prereq = 0;
2740
 
2741
        #
2742
        #   Process the Tool name and determine the location of the tool
2743
        #   Support --Tool=name and "name"
2744
        #   Locate the tool one of the many well known locations
2745
        #       1) Tool paths from Package Archives
2746
        #       2) JATS tool and binaries
2747
        #       3) User PATH (!YUK)
2748
        #
2749
 
2750
        #
2751
        #   Create a list of known extensions to scan
2752
        #   Basically present so that we can use .exe files without the .exe name
2753
        #
2754
        my @extension_list;
2755
        push @extension_list, '.exe' if ( $::ScmHost ne "Unix" );
2756
        push @extension_list, '.pl', '.sh', '.ksh', '';
2757
        TOOL_SEARCH:
2758
        {
2759
            #
2760
            #   Locate tool with package
2761
            #
2762
            if ( my $fname = ToolExtensionProgram( $tool, @extension_list ))
2763
            {
2764
                $tool = $fname;
2765
                last TOOL_SEARCH;
2766
            }
2767
 
2768
            #
2769
            #   Search the JATS tools and Bin directory
2770
            #   Retain the symbolic name of the JATS directory
2771
            #
2772
            for my $ext ( @extension_list )
2773
            {
2774
                foreach my $jdir ( qw( / /DEPLOY/ /LOCAL/ ) )
2775
                {
2776
                    if ( -f "$::GBE_TOOLS$jdir$tool$ext" )
2777
                    {
2778
                        $tool = "\$(GBE_TOOLS)$jdir$tool$ext";
2779
                        last TOOL_SEARCH;
2780
                    }
2781
                }
2782
 
2783
                if ( -f "$::GBE_BIN/$tool$ext" )
2784
                {
2785
                    $tool = "\$(GBE_BIN)/$tool$ext";
2786
                    last TOOL_SEARCH;
2787
                }
2788
            }
2789
 
2790
            #
2791
            #   Has the user provided an absolute PATH
2792
            #   This is not good, but for testing we can use it
2793
            #
2794
            if ( $tool =~ m~^/~ || $tool =~ m~^.:~ )
2795
            {
2796
                Warning("Absolute path program specified. Uncontrolled tool: $tool");
2797
                for my $ext ( @extension_list )
2798
                {
2799
                    if ( -f "$tool$ext" )
2800
                    {
2801
                        $tool = "$tool$ext";
2802
                        last TOOL_SEARCH;
2803
                    }
2804
                }
2805
            }
2806
 
2807
            #
2808
            #   May have a relative path to a local tool
2809
            #
2810
            if ( -f $tool )
2811
            {
2812
                UniquePush (\@preq_files, $tool);
2813
                last TOOL_SEARCH;
2814
            }
2815
 
2816
            #
2817
            #   Search the users PATH
2818
            #   Generate a warning if the program is found. These programs are
2819
            #   not nice as they are not really controlled.
2820
            #
2821
            for my $dir (split( $::ScmPathSep, $ENV{'PATH'} ) )
2822
            {
2823
                for my $ext ( @extension_list )
2824
                {
2825
                    if ( -f "$dir/$tool$ext" )
2826
                    {
2827
                        Warning("External program found in the user's PATH. Uncontrolled tool: $tool");
2828
                        $tool = "$dir/$tool$ext";
2829
 
2830
                        #
2831
                        #   Do not make the program a pre-requisite if we are running
2832
                        #   under Windows. This avoids two problems:
2833
                        #       1) May have spaces in pathname
2834
                        #       2) May have driver letter in pathname
2835
                        #
2836
                        $tool_no_prereq = 1 if ( $::ScmHost eq "WIN" );
2837
                        last TOOL_SEARCH;
2838
                    }
2839
                }
2840
            }
2841
 
2842
            #
2843
            #   Specified progrom not found
2844
            #   Generate a warning and use the raw name
2845
            #
2846
            Warning("Tool not found: $tool");
2847
            $tool_no_prereq = 1;
2848
        }
2849
        UniquePush (\@preq_files, $tool) unless ($tool_no_prereq);
2850
 
2851
    } elsif ( $tool =~ /^--Script=(.*)/ ) {
2852
 
2853
        #
2854
        #   Locate the script in a known source directory and make
2855
        #   the script a prerequisite of the target files, since the
2856
        #   script may be generated.
2857
        #
2858
        $tool = MakeSrcResolve ( $1 );
2859
        UniquePush (\@preq_files, $tool);
2860
 
2861
    } elsif ( $tool =~ /^--Shell$/ ) {
2862
        #
2863
        #   The user has provided a shell script within the command body
2864
        #   This will be executed directly by a shell
2865
        #   directores will need to use a "/" separator
2866
        #
2867
        $tool = "InternalShell";
2868
        $shell_script = 1;
2869
        $shell_cmds = 1;
2870
 
2871
 
2872
    } elsif ( $tool =~ /^--Prog=(.*)$/ ) {
2873
        #
2874
        #   Using a program that has been created within this script
2875
        #
2876
        my $prog = $1;
289 dpurdie 2877
        if ( my $pProg = $PROGS->Get($prog) )
227 dpurdie 2878
        {
289 dpurdie 2879
            $tool = $pProg->getPath()
227 dpurdie 2880
                unless ( $tool = $SRCS{$prog} );
2881
        UniquePush (\@preq_files, $tool);
2882
        }
2883
        else
2884
        {
2885
            Error ("Unknown program: $prog");
2886
        }
2887
 
2888
    } else {
2889
 
2890
        #
2891
        #   Currently generate a warning and then use the raw tool name
2892
        #
2893
        Error ("Unknown TOOL syntax: $tool");
2894
    }
2895
 
2896
    #
2897
    #   May need to quote the path
2898
    #   If the toolpath contains spaces then ugliness can occur - so quote the program
2899
    #
2900
    $tool = '"' . $tool . '"'
2901
        if ( (! $shell_script ) && $tool =~ m~\s~ );
2902
 
2903
    #
2904
    #   Determine special startup for various programs
2905
    #       Perl  - use known implemenatation
2906
    #       Shell - use known implemenatation
2907
    #       Otherwise - simply run it
2908
    #
2909
    #   Windows: Shell and Perl don't need '\' in paths
2910
    #
2911
    if ( $tool =~ /\.pl$/ )
2912
    {
2913
        $tool = "\$(GBE_PERL) $tool";
2914
        $shell_script = 1;
2915
    }
2916
    elsif ( $tool =~ /\.k?sh$/ )
2917
    {
2918
        $tool = "\$(GBE_BIN)/sh $tool";
2919
        $shell_script = 1;
2920
    }
2921
    Debug( "GenerateFiles: Tool: $tool" );
2922
 
2923
 
2924
    #
2925
    #   Process the remaining arguments
2926
    #   These will be command line arguments or options/flags
2927
    #   Command line arguments are concatenated together
2928
    #
2929
    for my $arg (@args)
2930
    {
263 dpurdie 2931
        if ( $arg =~ /^--PreDelete$/ )
2932
        {
2933
            #
2934
            #   Delete generated files before running the generation process
2935
            #   Some programs refuse to overwrite existing files
2936
            #
2937
            $predelete = 1;
2938
            next;
2939
        }
2940
 
227 dpurdie 2941
        if ( $arg =~ /^--NoVarTag$/ )
2942
        {
2943
            #
2944
            #   Modify the operation of --Var to supress the tags
6387 dpurdie 2945
            #   Should be used early as will only affect following --Var usage
227 dpurdie 2946
            #
2947
            push @var_opts, "--notag";
2948
            next;
2949
        }
2950
 
2951
        if ( $arg =~ /^--NoWarn$/ )
2952
        {
2953
            #
2954
            #   Supress warnings - No prequisites found
2955
            #   This is acceptable, but normally a tool should take an input
2956
            #   and create some output from it.
2957
            #
2958
            $no_warn = 1;
2959
            next;
2960
        }
2961
 
2962
        if ( $arg =~ /^--NoGenerate$/ )
2963
        {
2964
            #
2965
            #   Tool does generate a definable output
2966
            #   Should only be used internally
2967
            #
2968
            #   Need to create a dummy name for the rule
2969
            #   Use a base name and a number
2970
            #
2971
            my $dummy_target = 'generate_files_' . $NoGenIndex;
2972
            UniquePush (\@gen_files, $dummy_target );
2973
            UniquePush (\@GENERATED, $dummy_target);
2974
            next;
2975
        }
2976
 
2977
        if ( $arg =~ /^--UnknownPreq/ )
2978
        {
2979
            #
2980
            #   Indicate that the prequisites are not known, or too complex to
2981
            #   describe. ie: All files in a directory. May be used by packaging
2982
            #   tools.
2983
            #   The recipe will be run EVERY time we want to use the target.
2984
            #
2985
            $preq_unknown = 1;
2986
            $no_warn = 1;
2987
            next;
2988
        }
2989
 
2990
        if ( $arg =~ /^--AutoGenerate/ )
2991
        {
2992
            #
2993
            #   Determine when to run the tool based on the types of files that
2994
            #   are generated. Existance of a source file will force the tool
2995
            #   to be run during the 'generate' phase, othewise the tool will be run
2996
            #   when the generated components are required.
2997
            #
2998
            $gtype = 2;
261 dpurdie 2999
            Warning ("AutoGenerate MUST occur before options that declare generation of files",
3000
                     "Have seen:", @genreq_seen)
3001
                if (@genreq_seen);
227 dpurdie 3002
            next;
3003
        }
3004
 
3005
        if ( $arg =~ /^--Prereq=(.*)/ )
3006
        {
3007
            #
3008
            #   Specify a prerequisite file, that is not a part of the command line
3009
            #   Simply add the files to the list of preq files
3010
            #
3011
            my $fn = LocatePreReq ($1);
3012
            UniquePush ( \@preq_files, $fn );
3013
            Debug( "GenerateFiles: ExtraPrereq: $fn" );
3014
            next;
3015
        }
3016
 
3017
        if ( $arg =~ /^--Created(.*)=(.*)/ )
3018
        {
3019
            #
3020
            #   Specify a generated file, that is not a part of the command line
3021
            #   Add the files to the list of generated files
3022
            #
3023
            my $type = $1;
3024
            my $fn = $2;
3025
 
343 dpurdie 3026
            #
3027
            #   Append object suffix to CreatedObject
3028
            #
227 dpurdie 3029
            $fn .= '.' . $::o
3030
                if ( $type =~ m/Object/ );
3031
 
343 dpurdie 3032
            #
3033
            #   If the files is 'created' in a subdir, then add the dir
3034
            #   as a prerequisite.
3035
            #
3036
            if ( $type =~ m/Prog/ ) {
3037
                $fn = "\$(BINDIR)/$fn";
3038
                UniquePush (\@preq_files, '$(GBE_BINDIR)');
3039
 
3040
            } elsif ( $type !~ m/Common/ ) {
3041
                $fn = "\$(OBJDIR)/$fn";
3042
                UniquePush (\@preq_files, '$(GBE_OBJDIR)');
3043
            }
227 dpurdie 3044
 
3045
            #
3046
            #   Examine the file and see if it needs to be compiled
3047
            #   Add to the list of source files
3048
            #
261 dpurdie 3049
            push @genreq_seen, $arg;
303 dpurdie 3050
            if ( UniquePush (\@gen_files, $fn) )
3051
            {
3052
                if ( GenerateSrcFile ( $gtype, $fn  ) && $gtype == 2 )
3053
                {
3054
                    push @has_source, $fn;
3055
                }
3056
            }
227 dpurdie 3057
            Debug( "GenerateFiles: ExtraCreated: $fn" );
3058
            next;
3059
        }
3060
 
3061
        if ( $arg =~ /^--Clean($|=(.*))/ )
3062
        {
3063
            #
3064
            #   Detect Clean option
3065
            #
3066
            $clean_tag = $2 ? $2 : '-clean';
3067
 
3068
            #
3069
            #   Shell command with a --Clean will only
3070
            #   be run during a clean phase. They should not have any prereq
3071
            #   and should not generate any files, so simplify the interface.
3072
            #
3073
            push @args, '--NoWarn', '--NoGenerate'
3074
                if ( $shell_cmds );
3075
 
3076
            next;
3077
        }
3078
 
3079
        if ( $arg =~ /^--Text=(.*)/ )
3080
        {
3081
            #
3082
            #   Display this text when executing commands
3083
            #
3084
            $text = $1;
3085
            next;
3086
        }
3087
 
6415 dpurdie 3088
        if ( $arg =~ /^--RecipeTag=(.*)/ )
3089
        {
3090
            #
3091
            #   Tag the generated Recipe
3092
            #   Only use the last tag - allow users to overwrite system tags
3093
            #
3094
            $recipeTag = $1;
3095
            Error ("Duplicate RecipeTag - $recipeTag") if ($recipeTags{$recipeTag}++ > 1);
3096
            next;
3097
        }
3098
 
227 dpurdie 3099
        #   Not an option. Must be an argument to the tool/program
3100
        #   Process the tool arguments and extract file information
3101
        #   Extract all fields of the form:
3102
        #           --xxxxx(yyyyyy[,zzzzz])
3103
        #           --xxxxx{yyyyyyy}
3104
        #           --xxxxx[yyyyyyy] to allow embedded brackets
3105
        #
3106
        while ( $arg =~ m/--(\w+)               # --CommandWord         $1
3107
                                (               # Just for grouping
3108
                                \((.*?)\)   |   # Stuff like (yyyyy)    $3
3109
                                {(.*?)}     |   # or    like {yyyyy}    $4
3110
                                \[(.*?)\]       # or    like [yyyyy]    $5
3111
                                )/x )           # Allow comments and whitespace
3112
        {
3113
            my $cmd = $1;                       # The command
3114
            my $ufn = $3 || $4 || $5;           # User filename + options
3115
            my $mb = $-[0];                     # Match begin offset
3116
            my $me = $+[0];                     # Match end
3117
            my $flags = '';                     # Optional flags ( --dir or --file )
3118
            my $raw_arg = $ufn;                 # Raw arguments
6387 dpurdie 3119
            my $all = substr( $arg, $mb, $me - $mb ); # All of match. Avoid use of $&
343 dpurdie 3120
            my $is_path = 1;
285 dpurdie 3121
 
227 dpurdie 3122
 
3123
            Error ("GenerateFiles. Empty element not allowed: $all")
3124
                unless ( defined($ufn) );
3125
 
3126
            $ufn =~ s/\s+$//;
3127
            $ufn =~ s/^\s+//;
3128
            $ufn =~ s~//~/~g;                   # Remove multiple /
3129
            if ( $ufn =~ m/(.*?),(.*)/ )        # Extract out any flags
3130
            {
3131
                $ufn = $1;
3132
                $flags = $2;
3133
            }
3134
 
3135
            my $fn = $ufn ;                     # Replacement filename
343 dpurdie 3136
            my $fnp = '';                       # Prefix to $fn
227 dpurdie 3137
            Error ("GenerateFiles. Empty element not allowed: $all" )
3138
                if ( length ($ufn) <= 0 );
3139
 
3140
            #
3141
            #   Process found user command
3142
            #
3143
            if ( $cmd =~ /^Generated/ )
3144
            {
3145
                my $use_dir = "";
343 dpurdie 3146
 
227 dpurdie 3147
                #
3148
                #   Generated filename
3149
                #       Determine the target directory
3150
                #       Determine the full name of the file.
3151
                #       Flag the file as generated
3152
                #
3153
                if ( $cmd =~ /Prog/ )
3154
                {
3155
                    #
3156
                    #   Generated Prog are generated in the BIN directory
3157
                    #   Ensure the directory exists by using its symbolic name
3158
                    #   as a prerequisite.
3159
                    #
343 dpurdie 3160
                    $use_dir = '$(BINDIR)';
3161
                    UniquePush (\@preq_files, '$(GBE_BINDIR)');
227 dpurdie 3162
                }
3163
                elsif ( $cmd !~ /Common/ )
3164
                {
3165
                    #
3166
                    #   Files that are not Common are generated in the
3167
                    #   object directory. This directory must exist, so it
3168
                    #   symbolic name GBE_OBJDIR is made a prerequisite too.
3169
                    #
3170
                    #   If the file is a header file, then add the directory
3171
                    #   to the include search path too.
3172
                    #
343 dpurdie 3173
                    $use_dir = '$(OBJDIR)';
3174
                    UniquePush (\@preq_files, '$(GBE_OBJDIR)');
3175
                    AddIncDir( $platforms , '$(OBJDIR)', '--NoWarn' )
227 dpurdie 3176
                        if ( $ScmSourceTypes{ StripFile($fn) } && $ScmSourceTypes{ StripFile($fn) } eq ".h" );
3177
                }
3178
 
3179
 
3180
                #
3181
                #   Append a toolset specfic object file name suffix
3182
                #   for Object files only
3183
                #
3184
                $fn .= ".$::o"
3185
                    if ( $cmd =~ /Object/ );
3186
 
3187
                #
3188
                #   Merge directory and filename parts
3189
                #
3190
                $fn = $use_dir . ( $use_dir ? "/" : ""  ) . $fn;
3191
 
3192
                #
3193
                #   Save for later user
3194
                #   Flag the file as a generated file
3195
                #
261 dpurdie 3196
                push @genreq_seen, $cmd;
303 dpurdie 3197
                if ( UniquePush (\@gen_files, $fn) )
3198
                {
5878 dpurdie 3199
                    if ($SRCS{ StripDir( $fn ) })
303 dpurdie 3200
                    {
5878 dpurdie 3201
                        abtWarning(1,"GenerateFiles. Generated File also a Src file: $fn");
303 dpurdie 3202
                    }
5878 dpurdie 3203
                    elsif ( GenerateSrcFile ( $gtype, $fn  ) )
3204
                    {
3205
                        push ( @has_source, $fn ) if ($gtype == 2);
3206
                    }
303 dpurdie 3207
                }
227 dpurdie 3208
 
3209
                #
3210
                #   Use the directory or the full name
3211
                #   If using the directory then ensure that we have a name
3212
                #   even if its "."
3213
                #
3214
                $fn = ($use_dir) ? "$use_dir" : "."
3215
                    if ( $cmd =~ /Directory/ );
3216
 
3217
                Debug( "GenerateFiles: Generate: $fn" );
3218
 
3219
            }
3220
            elsif ( $cmd =~ /^Prereq/ )
3221
            {
3222
                #
3223
                #   Prerequisite filename
3224
                #       Resolve the full name of the file. It may be known
3225
                #       as a source file (possibly generated) or it may be
3226
                #       located in a known source directory
3227
                #
3228
                $fn = LocatePreReq ($ufn);
3229
                UniquePush (\@preq_files, $fn);
3230
 
3231
                Debug( "GenerateFiles: Prereq: $fn" );
3232
 
3233
            }
3234
            elsif ( $cmd =~ /^PackageBase/ )
3235
            {
3236
                $fn = GetPackageBase( "GenerateFiles", $raw_arg );
3237
                UniquePush (\@preq_files, $fn);
3238
            }
3239
            elsif ( $cmd =~ /^PackageInfo/ )
3240
            {
3241
                $fn = GetPackageInfo( "GenerateFiles", $raw_arg );
3242
            }
3243
            elsif ( $cmd =~ /^Var/ )
3244
            {
343 dpurdie 3245
                ($fnp, $fn, $is_path) = ExpandGenVar( "GenerateFiles", $raw_arg, @var_opts );
227 dpurdie 3246
                $flags = '';
343 dpurdie 3247
                if ( $raw_arg eq 'ObjDir' ) {
3248
                    UniquePush (\@preq_files, '$(GBE_OBJDIR)');
3249
                } elsif ( $raw_arg eq 'BinDir' ) {
3250
                    UniquePush (\@preq_files, '$(GBE_BINDIR)');
3251
                } elsif ( $raw_arg eq 'LibDir' ) {
3252
                    UniquePush (\@preq_files, '$(GBE_LIBDIR)');
3253
                }
227 dpurdie 3254
            }
3255
            else
3256
            {
3257
                Warning ("GenerateFiles: Unknown replacement command: $cmd");
3258
                $fn = $ufn;
3259
            }
3260
 
3261
            #
3262
            #   Process path modification flags
3263
            #
3264
            $fn = ProcessPathName( $fn, $flags );
3265
 
3266
            #
3267
            #   Minor kludge under windows. Ensure directores have a "\" sep
3268
            #   Unless the user has specified a straight shell command
3269
            #
5986 dpurdie 3270
            $fn = "\$(subst /,\$(dirsep),$fn)"
343 dpurdie 3271
                if ( $is_path && $::ScmHost eq "WIN" && ! defined($shell_script) );
227 dpurdie 3272
 
3273
            #
343 dpurdie 3274
            #   Prepend any $fn Prefix
3275
            #   This will be a tag and is not subject to path processing
3276
            #
3277
            $fn = $fnp . $fn;
3278
 
3279
            #
227 dpurdie 3280
            #   Replace the found string with the real name of the file
3281
            #   Note: 4 argument version of substr is not always available
3282
            #         so we must do it the hard way
3283
            #               substr( $arg, $mb, $me - $mb, $fn);
3284
            #
3285
            $arg = substr( $arg, 0, $mb ) . $fn . substr( $arg, $me );
3286
 
3287
            Debug2( "GenerateFiles: subs: $all -> $fn" );
3288
        }
3289
 
3290
        #
3291
        #   Save the tool arguments in an array
3292
        #
3293
        push @tool_args, $arg;
3294
    }
3295
 
3296
 
3297
    #
5867 dpurdie 3298
    #   Sanity test. Ensure that some file have been marked as generated
227 dpurdie 3299
    #                Warn if no prerequisites found
3300
    #
303 dpurdie 3301
    Warning( "GenerateFiles. --AutoGenerate option has no effect",
3302
             "The following files are 'source' files",  @has_source ) if ( @has_source );
227 dpurdie 3303
    Warning( "No Prerequisite files found in $tool",@tool_args) unless ( $no_warn || $#preq_files >= 0 );
3304
    Error  ( "No generated files found in $tool",@tool_args) unless ($#gen_files >= 0);
3305
 
6423 dpurdie 3306
    #
3307
    #   Determine the text to display while generating files
3308
    #   Will be either user-text or the first target file (default)
3309
    #   Suffix with RecipeTag, if provided
3310
    #   
3311
    my $txtSuffix = '';
3312
    $txtSuffix = "($recipeTag)" if defined $recipeTag;
3313
    $text = $gen_files[0] unless defined $text;
3314
    $text .= $txtSuffix;
227 dpurdie 3315
 
3316
    #
3317
    #   Save information
3318
    #   Will be used to create makefile statements later
3319
    #
3320
    my %gen_data;
3321
 
3322
    $gen_data{'index'}      = $NoGenIndex++;
6415 dpurdie 3323
    $gen_data{'recipeTag'}  = $recipeTag if defined $recipeTag;
227 dpurdie 3324
    $gen_data{'shell'}      = $shell_cmds;
3325
    $gen_data{'gen'}        = \@gen_files;
3326
    $gen_data{'preq'}       = \@preq_files;
3327
    $gen_data{'tool'}       = $tool;
3328
    $gen_data{'toolargs'}   = \@tool_args;
3329
    $gen_data{'clean'}      = $clean_tag;
6423 dpurdie 3330
    $gen_data{'text'}       = $text;
227 dpurdie 3331
    $gen_data{'preq_sus'}   = 1 if ( $preq_unknown );
263 dpurdie 3332
    $gen_data{'predelete'}  = 1 if ( $predelete );
227 dpurdie 3333
 
3334
    push(@GENERATE_FILES, \%gen_data);
6387 dpurdie 3335
#DebugDumpData("GenerateFiles", \%gen_data);
227 dpurdie 3336
    Debug2( "GenerateFiles: cmd: $tool @tool_args" );
3337
}
3338
 
3339
#-------------------------------------------------------------------------------
3340
# Function        : MakePerlModule
3341
#
3342
# Description     : Build Perl Module(s) using the Perl Build System
3343
#                   This is a thin wrapper around a specialised script
3344
#
3345
#                   The user can do the same job with correct use of
3346
#                   a GenerateFiles, but this is a lot tidier.
3347
#
3348
# Inputs          : $1      - platform specifier '*' (comma delemitered)
3349
#                   $*      - Paths to Perl Modules[,command options]
3350
#                             Options to the BuildPerl script
3351
#
3352
# Returns         :
3353
#
3354
sub MakePerlModule
3355
{
3356
    my ( $platforms, @args) = @_;
3357
 
3358
    return if ( ! ActivePlatform($platforms) );
3359
 
3360
    Debug2( "MakePerlModule:($platforms, @args)" );
3361
    my @opts;
3362
 
3363
    #
3364
    #   Extract options from paths to Perl Packages
3365
    #   Package names do not start with a '-'
3366
    #
3367
    foreach my $arg ( @args )
3368
    {
3369
        if ( $arg =~ /^-/ ) {
3370
            push @opts, $arg;
3371
 
3372
        } else {
3373
            #
3374
            #   Perl Package Directory Name
3375
            #   This may also contain embedded command to the Make command
3376
            #   These will be seperated with a comma
3377
            #       ie: module,-options=fred
3378
            #
3379
            my ($name,$options) = split( ',', $arg );
3380
            push @opts, "-PerlPackage=$arg";
3381
            push @opts, "--Prereq=$name/Makefile.PL";
3382
        }
3383
    }
3384
 
3385
    #
3386
    #   Invoke GenerateFiles with a bunch of additional arguments
3387
    #
3388
    GenerateFiles ($platforms, "--Tool=jats_buildperl.pl",
3389
                          '--Var(MachType)',                        # Build Machine type
3390
                          '--Var(PackageDir)',                      # Package dir
3391
                          '--NoGenerate',                           # Don't know the output
3392
                          '--Text=Make Perl Module',                # Pretty print
3393
                          '--NoWarn',
3394
                          '--Clean=-clean_build',                   # Jats clean support
3395
                          '--NoVarTag',                             # No more Tags
3396
                          @opts,
3397
                          );
3398
}
3399
 
3400
#-------------------------------------------------------------------------------
3401
# Function        : MakeLinuxDriver
3402
#
3403
# Description     : Build a Linux Device Driver using the Linux Device Driver
3404
#                   Build System
3405
#                   This is a thin wrapper around a specialised script
3406
#
3407
#                   The user can do the same job with correct use of
3408
#                   a GenerateFiles, but this is a lot tidier.
3409
#
3410
# Inputs          : $1      - platform specifier '*' (comma delemitered)
3411
#                   $2      - name of the driver. No extension
3412
#                   $*      - Driver sources
3413
#                             Options to the script
3414
#
3415
# Returns         :
3416
#
3417
sub MakeLinuxDriver
3418
{
3419
    my ( $platforms, $driver_name, @args) = @_;
3420
 
3421
    return if ( ! ActivePlatform($platforms) );
3422
 
285 dpurdie 3423
    Error ("No driver name specified") unless ( $driver_name );
227 dpurdie 3424
    Debug2( "MakeLinuxDriver:($platforms, $driver_name ,@args)" );
3425
    my @srcs;
3426
    my @opts;
3427
 
3428
    #
3429
    #   Extract options from source files
3430
    #   Package names do not start with a '-'
3431
    #
3432
    foreach my $arg ( @args )
3433
    {
3434
         if ( $arg =~ /^--Define=(.)/ ) {
3435
            push @opts, $arg;
5672 dpurdie 3436
 
3437
         } elsif ( $arg =~ /^--ExternalModule=(.)/ ) {
3438
               push @opts, $arg;
227 dpurdie 3439
 
3440
         } elsif ( $arg =~ /^-/ ) {
3441
            push @opts, $arg;
3442
            Warning ("MakeLinuxDriver: Unknown option: $arg. Passed to script");
3443
 
3444
        } else {
3445
            push @srcs, $arg;
3446
            push @opts, "--Prereq=$arg";
3447
        }
3448
    }
3449
 
3450
    #
3451
    #   Cleanup the drive name
3452
    #
3453
    $driver_name =~ s~\.ko$~~;
3454
 
3455
    #
3456
    #   Remove the specified sources from the list of object files
3457
    #   that will be build. This will ensure that some internal rules are
3458
    #   not generated.
3459
    #
3460
    foreach ( @srcs )
3461
    {
3462
        my $file = StripExt(StripDir( $_ ));
3463
        delete $OBJSOURCE{ $file };
3464
        @OBJS = grep(!/^$file$/, @OBJS);
3465
    }
3466
 
3467
    #
3468
    #   Invoke GenerateFiles with a bunch of additional arguments
3469
    #   At runtime the include directories will be added as
3470
    #   absolute paths
3471
    #
3472
    GenerateFiles ($platforms, "--Tool=jats_buildlinux.pl",
3473
                    "-Output=--GeneratedProg($driver_name.ko)",
3474
                    "-Driver=$driver_name",
3475
                    "-GccPath=\$(GCC_CC)",
3476
                    "-Arch=\$(HOST_CPU)",
3477
                    "-LeaveTmp=\$(LEAVETMP)",
3478
                    "-Verbose=\$(CC_PRE)",
3479
                    "-Type=\$(GBE_TYPE)",
3480
                    "-Platform=\$(GBE_PLATFORM)",
5672 dpurdie 3481
                    "--Var(LocalBinDir)",
227 dpurdie 3482
                    '$(patsubst %,-Incdir=%,$(INCDIRS))',
5672 dpurdie 3483
                    '--Clean',
227 dpurdie 3484
                    @opts,
3485
                    @srcs
3486
                    );
3487
}
3488
 
3489
#-------------------------------------------------------------------------------
3490
# Function        : GetPackageBase
3491
#
3492
# Description     : Helper routine
3493
#                   Given a package name, determine the base address of the
3494
#                   package
3495
#
3496
# Inputs          : $dname         - Directive name     (Reporting)
3497
#                   $name          - Required package
3498
#                                    Allows two forms:
3499
#                                       package_name
3500
#                                       package_name,ext
3501
#
3502
# Returns         : Path to the directory in which the files are installed
3503
#                   This may be the interface directory
3504
#
3505
sub GetPackageBase
3506
{
3507
    my ($dname, $fname) = @_;
3508
    my $pkg;
3509
    my ($name, $ext) = split(',', $fname);
3510
 
3511
    $pkg = GetPackageEntry( $name, $ext );
3512
    Error ("$dname: Package not found: $fname") unless ( $pkg );
3513
 
3514
    #
3515
    #   If a BuildPkgArchive then use the interface directory
3516
    #
3517
    return ( $pkg->{'TYPE'} eq 'link' ) ? $pkg->{'ROOT'} : '$(INTERFACEDIR)';
3518
}
3519
 
3520
#-------------------------------------------------------------------------------
3521
# Function        : GetPackageInfo
3522
#
3523
# Description     : Helper routine
3524
#                   Given a package name, return some information about the package
3525
#                   Only one information item is allowed with each call
3526
#
3527
# Inputs          : $dname         - Directive name     (Reporting)
3528
#                   $name          - Required package
3529
#                                    Allows two forms:
3530
#                                       package_name
3531
#                                       package_name,ext
3532
#                                    Selector
3533
#                                       --path
3534
#                                       --version
3535
#                                       --fullversion
3536
#                                       --project
3537
#
3538
# Returns         : Package information
3539
my %GetPackageInfo = qw(path ROOT
3540
                        version DVERSION
3541
                        fullversion VERSION
3542
                        project DPROJ);
3543
sub GetPackageInfo
3544
{
3545
    my ($dname, $args) = @_;
3546
    my $pkg;
3547
    my $name;
3548
    my $ext;
3549
    my $info;
3550
 
363 dpurdie 3551
    #
3552
    #   Split up the arguments
3553
    #       Options start with '--'
3554
    #   First non-option is the package name
3555
    #   2nd non-option is the packag extension
3556
    #
3557
    #   Only one option allowed
3558
    #       Convert it into a known package info item
3559
    #
3560
    #
227 dpurdie 3561
    foreach ( split(',', $args) )
3562
    {
3563
        if ( m/^--(.*)/ ) {
3564
            Error( "$dname: Too many info requests: $args") if ( $info );
3565
            $info = $GetPackageInfo{$1};
3566
            Error( "$dname: Unknown info type: $_") unless ($info);
363 dpurdie 3567
 
227 dpurdie 3568
        } elsif ( $ext ) {
3569
            Error("$dname: Too many names: $args");
363 dpurdie 3570
 
227 dpurdie 3571
        } elsif ( $name ) {
3572
            $ext = $_;
363 dpurdie 3573
 
227 dpurdie 3574
        } else {
3575
            $name = $_;
3576
        }
3577
    }
3578
 
3579
    $pkg = GetPackageEntry( $name, $ext );
3580
    Error ("$dname: Package not found: $args") unless ( $pkg );
3581
 
3582
    #
3583
    #   If a BuildPkgArchive then use the interface directory
363 dpurdie 3584
    #   Default data item - path to the package
227 dpurdie 3585
    #
363 dpurdie 3586
    $info = 'ROOT' unless ( $info );
3587
    if ( $info eq 'ROOT' &&  $pkg->{'TYPE'} ne 'link' )
227 dpurdie 3588
    {
3589
        return ( '$(INTERFACEDIR)');
3590
    }
363 dpurdie 3591
 
227 dpurdie 3592
    return ( $pkg->{$info} );
3593
}
3594
 
3595
#-------------------------------------------------------------------------------
3596
# Function        : GetPackageEntry
3597
#
3598
# Description     : Return the package class pointer given a package name
3599
#
3600
# Inputs          : $name          - Required package
3601
#                   $ext           - Option package extension
3602
#
3603
# Returns         : Class pointer
3604
#
3605
sub GetPackageEntry
3606
{
3607
    my ($name, $ext) = @_;
3608
    $ext = '' unless ( $ext );
3609
 
3610
    for my $entry (@{$::ScmBuildPkgRules{$ScmPlatform} })
3611
    {
3612
        next unless ( $entry->{'NAME'} eq $name );
3613
        next if ( $ext && $entry->{'DPROJ'} ne $ext );
3614
        return $entry;
3615
    }
285 dpurdie 3616
    return;
227 dpurdie 3617
}
3618
 
3619
#-------------------------------------------------------------------------------
3620
# Function        : ExpandGenVar
3621
#
3622
# Description     : Expand a known variable for the Generate Files option
3623
#
3624
# Inputs          : $dname         - Directive name     (Reporting)
3625
#                   $arg           - Raw argument
3626
#                                    This of the form of
3627
#                                       Tag[,--option]+
3628
#                                    Tags are specified in %ExpandGenVarConvert
3629
#
3630
#                                   Options are:
3631
#                                       --tag
3632
#                                       --notag
3633
#                                       --tag=<SomeTag>
3634
#                                       --absdrive
3635
#                                       --abspath
285 dpurdie 3636
#                                       --default=text
343 dpurdie 3637
#                                       --allownone
227 dpurdie 3638
#                                   Not all options are avalaible on all variables
3639
#                   @opts           - Options
3640
#                                       --notag     - Default is --notag
3641
#
343 dpurdie 3642
# Returns         : Tag             - Any tag component of the expansion
3643
#                   Path/Value      - Path/Value of the component
3644
#                   is_path         - Above is a path
3645
#                   is_abs          - Path is absolute
227 dpurdie 3646
#
3647
 
3648
#
3649
#   Create a Hash to simplify the process of converting Var names
343 dpurdie 3650
#   into makefile variables. There are two data items, separated by a comma.
3651
#       The first is the runtime expansion value
3652
#       The second describes the first:
3653
#           NotPresent  - Expansion is not a path
3654
#           '-'         - Expansion is a path and is relative to CWD
3655
#           '+'         - Expansion is a path and is absolute
227 dpurdie 3656
#
3657
my %ExpandGenVarConvert = (
3658
    'BuildName'         => '$(GBE_PBASE)',
3659
    'BuildVersion'      => '$(BUILDVER)',
3660
    'BuildVersionNum'   => '$(BUILDVERNUM)',
3661
 
3662
    'PackageDir'        => '$(PKGDIR),+',
3663
    'PackagePkgDir'     => '$(PKGDIR)/pkg/pkg.$(GBE_PLATFORM),+',
3664
    'PackageIncDir'     => '$(INCDIR_PKG),+',
6133 dpurdie 3665
    'PackageIncPlatDir' => '$(INCDIR_PKG)/$(GBE_PLATFORM),+',
227 dpurdie 3666
    'PackageLibDir'     => '$(LIBDIR_PKG)/$(GBE_PLATFORM),+',
3667
    'PackageBinDir'     => '$(BINDIR_PKG)/$(GBE_PLATFORM)$(GBE_TYPE),+',
3668
 
3669
    'PackageToolDir'    => '$(PKGDIR)/tools,+',
3670
    'PackageToolBin'    => '$(PKGDIR)/tools/bin/$(GBE_HOSTMACH),+',
3671
    'PackageToolScript' => '$(PKGDIR)/tools/scripts,+',
3672
 
3673
    'LibDir'            => '$(LIBDIR),+',
3674
    'BinDir'            => '$(BINDIR),+',
3675
    'ObjDir'            => '$(OBJDIR),+',
3676
 
3677
    'InterfaceDir'      => '$(INTERFACEDIR),+',
3678
    'InterfaceIncDir'   => '$(INCDIR_INTERFACE),+',
3679
    'InterfaceLibDir'   => '$(LIBDIR_INTERFACE)/$(GBE_PLATFORM),+',
3680
    'InterfaceBinDir'   => '$(BINDIR_INTERFACE)/$(GBE_PLATFORM)$(GBE_TYPE),+',
3681
 
3682
    'LocalDir'          => '$(LOCALDIR),+',
3683
    'LocalIncDir'       => '$(INCDIR_LOCAL),+',
3684
    'LocalLibDir'       => '$(LIBDIR_LOCAL)/$(GBE_PLATFORM),+',
3685
    'LocalBinDir'       => '$(BINDIR_LOCAL)/$(GBE_PLATFORM)$(GBE_TYPE),+',
3686
 
3687
    'Platform'          => '$(GBE_PLATFORM)',
3688
    'Product'           => '$(GBE_PRODUCT)',
3689
    'Target'            => '$(GBE_TARGET)',
3690
 
3691
    'Type'              => '$(GBE_TYPE)',
3692
    'Arch'              => '$(HOST_CPU)',
3693
    'Architecture'      => '$(HOST_CPU)',
3694
    'MachType'          => '$(GBE_HOSTMACH)',
3695
    'BuildRoot'         => '$(GBE_ROOT),+',
3696
 
3697
 
3698
    'Verbose'           => '$(CC_PRE)',
3699
    'LeaveTmp'          => '$(LEAVETMP)',
329 dpurdie 3700
    'Cwd'               => '$(CURDIR),-',
227 dpurdie 3701
 
6133 dpurdie 3702
    # Generated when used
227 dpurdie 3703
    'CompilerPath'      => '$(SCM_COMPILERPATH)',
3967 dpurdie 3704
    'PkgArch'           => '$(PACKAGE_ARCH)',
6133 dpurdie 3705
 
3706
    'Native'            => '0',
3707
    'Toolset'           => '0',
3708
 
227 dpurdie 3709
    );
3710
 
3711
sub ExpandGenVar
3712
{
3713
    my ($dname, $args, @uopts) = @_;
3714
    my $expansion;
3715
    my $prefix='';
3716
    my ($tag, @opts) = split('\s*,\s*', $args);
3717
    my $no_prefix;
285 dpurdie 3718
    my $default_value;
3719
    my $allow_none;
329 dpurdie 3720
    my $is_abs = 0;
227 dpurdie 3721
 
285 dpurdie 3722
    #
3723
    #   Parse options lists
3724
    #       Options provided by the caller
3725
    #       Options embedded in the argument
227 dpurdie 3726
    foreach ( @uopts )
3727
    {
3728
        if ( m/^--notag$/ ) {
3729
            $no_prefix = 1;
3730
        } else{
3731
            Error ("$dname: Unknown option: $_")
3732
        }
3733
    }
3734
 
285 dpurdie 3735
    foreach ( @opts )
3736
    {
3737
        if ( m/^--default=(.+)/i ) {
3738
            $default_value = $1;
3739
        } elsif ( m/^--allownone$/i ) {
3740
            $allow_none = 1;
3741
        }
3742
    }
3743
 
227 dpurdie 3744
    #
3745
    #   Perform run-time update on the %ExpandGenVarConvert
3746
    #   Most of it can be initialised at startup - but not all of it.
3747
    #
3748
    $ExpandGenVarConvert{CompilerPath} = undef unless $::ScmToolsetCompilerPath;
3749
    $ExpandGenVarConvert{Product}      = '$(GBE_PLATFORM)' unless $ScmProduct;
3750
 
6133 dpurdie 3751
    $ExpandGenVarConvert{Native}      = '1'  if isAnAlias ('NATIVE');
3752
    $ExpandGenVarConvert{Toolset}     = '1'  if isAnAlias ('TOOLSET');
3753
 
3754
 
227 dpurdie 3755
    #
3756
    #   Look up a hash of conversions
3757
    #   Could allow for a code ref, but not needed yet
3758
    #
3759
    Error ("$dname: Unknown expansion --Var($tag)")
3760
        unless ( exists $ExpandGenVarConvert{$tag} );
3761
 
285 dpurdie 3762
    #
3763
    #   Handle undefined expansions
3764
    #   Only 'CompilerPath', but it can be a pain in user land
3765
    #
3766
    $expansion = $ExpandGenVarConvert{$tag};
3767
    unless ( defined $expansion  )
3768
    {
3769
        return '' if ( $allow_none );
3770
        $expansion = $default_value;
3771
        Error ("$dname: Expansion --Var($tag) not be supported by toolset: $ScmToolset")
3772
            unless ( $expansion );
3773
    }
227 dpurdie 3774
 
285 dpurdie 3775
 
227 dpurdie 3776
    ($expansion,my $is_path) = split (',', $expansion );
329 dpurdie 3777
    $is_abs = 1
3778
        if ($is_path && $is_path eq '-' );
227 dpurdie 3779
 
3780
    #
3781
    #   Process options
3782
    #   Assume that a tag will be provided
3783
    #
3784
    $prefix =  $no_prefix ? '' : "-$tag=";
3785
    foreach my $opt ( @opts )
3786
    {
3787
        if ( $opt =~ /^--tag=(.*)/i ) {
3788
            $prefix = "$1=";
3789
 
3790
        } elsif ( $opt =~ m/^--tag$/i ) {
3791
            $prefix = "-$tag=";
3792
 
3793
        } elsif ( $opt =~ m/^--notag/i ) {
3794
            $prefix = '';
3795
 
329 dpurdie 3796
        } elsif ( $is_path && !$is_abs && $opt =~ /--abspath|--absdrive/i ) {
227 dpurdie 3797
            $expansion = '$(CURDIR)/' . $expansion;
329 dpurdie 3798
            $is_abs = 1;
227 dpurdie 3799
 
285 dpurdie 3800
        } elsif ( $opt =~ m/^--default=(.+)/i ) {
3801
            # Already processed
3802
        } elsif ( $opt =~ m/^--allownone$/i ) {
3803
            # Already processed
227 dpurdie 3804
        } else {
3805
            Error ("$dname: Unsupported option($opt) for --Var(@_)");
3806
        }
3807
    }
3808
 
3809
    Debug ("ExpandGenVar: args $args --> $prefix$expansion");
343 dpurdie 3810
    return $prefix , $expansion, $is_path ? 1 : 0, $is_abs;
227 dpurdie 3811
 
3812
}
3813
 
3814
#-------------------------------------------------------------------------------
6133 dpurdie 3815
# Function        : isAnAlias 
3816
#
3817
# Description     : Internal Helper
3818
#                   Determine if this platform is an alias for ...
3819
#
3820
# Inputs          :  $target    - Test against this target
3821
#
3822
# Returns         :  True - Is an alais for $target.
3823
#
3824
sub isAnAlias
3825
{
3826
    my ($target) = @_;
3827
    if (exists ($::BUILDINFO{$ScmPlatform}{'USERALIAS'}) )
3828
    {
3829
        if ( grep /^$target$/, @{$::BUILDINFO{$ScmPlatform}{'USERALIAS'}} )
3830
        {
3831
                return 1;    
3832
        }
3833
 
3834
    }
3835
    if (exists ($::BUILDINFO{$ScmPlatform}{'ALIAS'}) )
3836
    {
3837
        if ( $target eq $::BUILDINFO{$ScmPlatform}{'ALIAS'} )
3838
        {
3839
                return 1;    
3840
        }
3841
    }
3842
 
3843
    return 0;
3844
}
3845
 
3846
#-------------------------------------------------------------------------------
227 dpurdie 3847
# Function        : ProcessPathName
3848
#
3849
# Description     : Massage a pathname according to a set of flags
3850
#
3851
# Inputs          : $fn         - Patchname to massage
3852
#                   $flags      - Flags in a string
3853
#                                   --dir       - only the directory part ( or a "." )
3854
#                                   --file      - only the file part
3855
#                                   --abspath   - Absolute path
3856
#                                   --absdrive  - Absolute path with drive letter(WIN)
3857
#
3858
# Returns         : Massaged pathname
3859
#
3860
sub ProcessPathName
3861
{
3862
    my ( $fn, $flags ) = @_;
3863
    #
3864
    #   Process flags
3865
    #       --dir           - only the directory part ( or a "." )
3866
    #       --file          - only the file part
3867
    #       --abspath       - Absolute path
3868
    #       --absdrive      - Absolute path with drive letter(WIN)
3869
    #
3870
    if ( $flags =~ /--dir/ )
3871
    {
3872
        $fn = '.'
3873
            unless ( $fn =~ s~/[^/]*$~~);
3874
    }
3875
 
3876
    if ( $flags =~ /--file/ )
3877
    {
3878
        $fn =~ s~.*/~~;
3879
    }
3880
 
3881
    if ( $flags =~ /--abspath/ )
3882
    {
3883
        $fn = AbsPath( $fn );
3884
    }
3885
    elsif ( $flags =~ /--absdrive/ )
3886
    {
3887
        $fn = AbsPath( $fn );
3888
        if ( $::ScmHost eq "WIN" )
3889
        {
3890
            $fn = $::CwdDrive . '/' . $fn
3891
                unless ( $fn =~ m~^\w:/~  );
3892
            $fn =~ s~//~/~g;
3893
        }
3894
    }
3895
 
3896
  return $fn;
3897
}
3898
 
3899
#-------------------------------------------------------------------------------
3900
# Function        : LocatePreReq
3901
#
3902
# Description     : Locate a file known to JATS
3903
#                   There are many places to search
3904
#                       1) Src files - specified with a Src directive
3905
#                       2) Scripts - specified with a script directive
3906
#                       3) Search - Files in the specified search path
3907
#                       4) Programs specified with a 'Prog' directive
3908
#
3909
#                   Should also look in other locations (Libs, SharedLibs)
3910
#                   Not done yet. May be issues of a name clash if a program
3911
#                   and a library have the same name.
3912
#
3913
# Inputs          : Name to locate
3914
#
3915
# Returns         : Full pathname of file
3916
#
3917
sub LocatePreReq
3918
{
3919
    my ( $name ) = @_;
3920
    Debug ("LocatePreReq:Looking for $name");
3921
    #
3922
    #   Try a Src file first
3923
    #
3924
    if ( exists $SRCS{ $name } )
3925
    {
3926
        return $SRCS{ $name };
3927
    }
3928
 
3929
    #
3930
    #   Try a script
3931
    #
3932
    if ( exists $SCRIPTS{ $name } )
3933
    {
3934
        return $SCRIPTS{ $name };
3935
    }
3936
 
3937
    #
3938
    #   Try a PROG
3939
    #
289 dpurdie 3940
    if ( my $pProg = $PROGS->Get($name) )
227 dpurdie 3941
    {
289 dpurdie 3942
        return $pProg->getPath();
227 dpurdie 3943
    }
3944
 
3945
    #
3946
    #   Try searching for the file
3947
    #   Uses Data from AddSrcDir
3948
    #
3949
    #   Done: last because it generates warning messages
3950
    #
3951
    return MakeSrcResolve( $name );
3952
}
3953
 
3954
#-------------------------------------------------------------------------------
3955
# Function        : ToolExtensionPaths
3956
#
3957
# Description     : Return a list of toolset extension directories
3958
#                   The data will have been discovered by the build process
3959
#                   and will have been saved for the makefile creation phase
3960
#
3961
# Inputs          : None
3962
#
3963
# Returns         : Return an ordered unique list
3964
#
3965
sub ToolExtensionPaths
3966
{
3967
    Debug( "ToolExtensionPaths:", @::BUILDTOOLSPATH );
3968
    return @::BUILDTOOLSPATH;
3969
}
3970
 
3971
#-------------------------------------------------------------------------------
3972
# Function        : ToolExtensionProgram
3973
#
3974
# Description     : Determine if the named program exists within the PATH
3975
#                   that also includes the toolset extension
3976
#
3977
# Inputs          : program             - Name of program
3978
#                   elist               - An array of possible program extensions
3979
#
4324 dpurdie 3980
# Returns         : Full path the to program or an empty elelent (not undef)
227 dpurdie 3981
#
3982
sub ToolExtensionProgram
3983
{
3984
    my ($program, @elist ) = @_;
3985
 
3986
    #
3987
    #   If elist is empty then insert a defined entry
3988
    #
3989
    push @elist, '' unless ( @elist );
3990
 
3991
    #
3992
    #   Scan all toolset directories
3993
    #   for the program
3994
    #
3995
    for my $dir ( ToolExtensionPaths() )
3996
    {
3997
        for my $ext ( @elist )
3998
        {
3999
            my $tool = "$dir/$program$ext";
4324 dpurdie 4000
            Debug( "ToolsetExtensionProgram: Look for: $tool" );
227 dpurdie 4001
 
4002
            return $tool if ( -f $tool );
4003
        }
4004
    }
4005
}
4006
 
4007
sub Define
4008
{
4009
    Debug2( "Define(@_)" );
4010
 
4011
    push( @DEFINES, @_ );
4012
}
4013
 
4014
 
4015
sub Defines
4016
{
4017
    my( $path, $script ) = @_;
4018
    my( $line );
4019
 
4020
    Debug2( "Defines($path, $script)" );
4021
 
4022
    $script = Exists( $path, $script, "Defines" );
271 dpurdie 4023
    push( @DEFINES, "# Defines from: $script" );
285 dpurdie 4024
    open( my $fh, '<', $script ) || Error( "Opening $script" );
4025
    while (<$fh>) {
227 dpurdie 4026
        $_ =~ s/\s*(\n|$)//;                    # kill trailing whitespace & nl
4027
        push( @DEFINES, $_ );
4028
    }
4029
    push( @ScmDepends, "$script" );             # makefile dependencies
285 dpurdie 4030
    close( $fh );
227 dpurdie 4031
}
271 dpurdie 4032
#-------------------------------------------------------------------------------
4033
# Function        : Rule
4034
#
4035
# Description     : Add a Rule and Recipe to the generated makefile
4036
#                   This is not encouraged as it has been misused to create
4037
#                   unreadable and unmaintainable makefiles.
4038
#
4039
#                   Rules will be added to the makefile after the rules and
4040
#                   recipes created by JATS directives
4041
#
4042
# Inputs          : $platform               - Platform predicate
4043
#                   @rule                   - Array of rules to add
4044
#
4045
# Returns         : 
4046
#
227 dpurdie 4047
sub Rule
4048
{
4049
    my( $platforms, @rule ) = @_;
4050
 
4051
    return if ( ! ActivePlatform($platforms) );
4052
 
4053
    push( @RULES, @rule );
4054
    Message("Rule directive used. Consider replacing with GenerateFiles");
4055
}
4056
 
271 dpurdie 4057
#-------------------------------------------------------------------------------
4058
# Function        : Rules
4059
#
4060
# Description     : Add a file of Rules and Recipes to the generated makefile
4061
#                   Used internally ONLY as there is no platform predicate
4062
#                   Similar to 'Rule()'
4063
#
4064
# Inputs          : $path                   - path to script
4065
#                   $script                 - File fo Rules
4066
#
4067
# Returns         : 
4068
#
227 dpurdie 4069
sub Rules
4070
{
4071
    my( $path, $script ) = @_;
4072
    my( $line );
4073
 
4074
    $script = Exists( $path, $script, "Rules" );
271 dpurdie 4075
    push( @RULES, "# Rules from: $script" );
285 dpurdie 4076
    open( my $fh, '<', $script ) || Error( "Opening $script" );
4077
    while (<$fh>) {
227 dpurdie 4078
        $_ =~ s/\s*(\n|$)//;                    # kill trailing whitespace & nl
4079
        push( @RULES, $_ );
4080
    }
4081
    push( @ScmDepends, "$script" );             # makefile dependencies
285 dpurdie 4082
    close( $fh );
227 dpurdie 4083
}
4084
 
271 dpurdie 4085
#-------------------------------------------------------------------------------
4086
# Function        : AddRule
4087
#
4088
# Description     : Inernal function
4089
#                   Add a line to the Rules area
4090
#
4091
# Inputs          : @elements                   - Array of lines to add
4092
#
4093
# Returns         : Nothing
4094
#
4095
sub AddRule
4096
{
4097
    push( @RULES, @_ );
4098
}
227 dpurdie 4099
 
271 dpurdie 4100
#-------------------------------------------------------------------------------
4101
# Function        : Src
4102
#
4103
# Description     : This directive is used to identify files to JATS
4104
#                   Once a file has been identified as a 'Source' file, then it
4105
#                   can be used by name, without the need to locate the file again.
4106
#                   This implies that filenames must be unique.
4107
#                   The directories cannot be used to make files of the same name
4108
#                   unqiue - this is not the JATS way
4109
#
4110
#                   Source files will be classified as one of:
4111
#                       c, c++, header, assembler or other
4112
#
4113
#
4114
# Inputs          : $platform               - Active Platform Predicate
4115
#                   @elements               - A list of files and options
4116
#
4117
#                   Valid options are:
4118
#                       --c                 - Specifies the type of file
4119
#                       --cpp
4120
#                       --h, --headers
4121
#                       --asm
4122
#                       --FromPackage       - Search packages for the file
4123
#                       --List=xxx          - Append file to a named list
4124
#                       --Depends=xxx       - Manually name a dependency
6387 dpurdie 4125
#                       --IgnoreDuplicates  - Ignore duplicates (mostly internal use)
271 dpurdie 4126
#
4127
#                   Options are processed before file elements
4128
#                   Thus options apply to all files in the list
4129
#
4130
# Returns         : Nothing
4131
#
227 dpurdie 4132
sub Src
4133
{
4134
    my( $platforms, @elements ) = @_;
6387 dpurdie 4135
    my( $type, @args, $source, $basename, $from_package, @lists, $ignoreDups );
227 dpurdie 4136
    my( @depends, @srcs );
4137
 
4138
    $platforms = '' unless ( $platforms );
4139
    Debug2( "Src($platforms, @elements)" );
4140
 
4141
    #
4142
    #   Ensure that there is a file within the list
4143
    #
4144
    Warning( "Src directive does not specify any files: Src($platforms, @elements)" )
4145
        unless (grep( /^[^-]/, @elements ) );
4146
 
4147
    return if ( ! ActivePlatform($platforms) );
4148
 
4149
    #
4150
    #   Remove spaces from both ends of the arguments.
4151
    #   It is easier to remove spaces now than to detect them later
4152
    #
4153
    foreach ( @elements )
4154
    {
4155
        s/^\s+//;
4156
        s/\s+$//;
4157
        s~//~/~g;                               # Remove multiple /
4158
    }
4159
 
4160
    #.. Collect arguments
4161
    #
4162
    $type = "";
4163
    foreach ( @elements )
4164
    {
4165
        if ( /^--c$/ )
4166
        {
4167
            Debug( "Src: --c" );
4168
            $type = ".c";
4169
        }
4170
        elsif ( /^--cpp$/ )
4171
        {
4172
            Debug( "Src: --cpp" );
4173
            $type = ".cc";
4174
        }
4175
        elsif ( /^--h$/ || /^--header$/ )
4176
        {
4177
            Debug( "Src: --h" );
4178
            $type = ".h";
4179
        }
4180
        elsif ( /^--asm$/ )
4181
        {
4182
            Debug( "Src: --asm" );
4183
            $type = ".asm";
4184
        }
6387 dpurdie 4185
        elsif ( /^--IgnoreDup/ )
4186
        {
4187
            $ignoreDups = 1;
4188
        }
227 dpurdie 4189
        elsif ( /^--FromPackage$/ )
4190
        {
4191
            $from_package = 1;
4192
        }
4193
        elsif ( /^--List=(.*)/ )
4194
        {
4195
            my $list_name = $1;
4196
            Error( "Bad list name: $list_name" )
4197
                unless ( $list_name =~ m/^[A-Za-z]\w+/ );
4198
            push @lists, $list_name;
4199
        }
4200
        elsif ( /^--Depends=(.*)/ )
4201
        {
4202
            foreach ( split( ',', $1) )
4203
            {
4204
                my $full = MakeSrcResolveExtended( $from_package, $_ );
4205
                push @depends, $full;
4206
            }
4207
        }
4208
        elsif ( /^-(.*)/ )
4209
        {
4210
            Debug( "Src: arg $_" );
4211
            push @args, $_;
4212
        }
4213
        else
4214
        {
4215
            push @srcs, $_;
4216
            Warning ("Src files contains a '\\' character: $_" ) if (m~\\~);
4217
        }
4218
    }
4219
 
4220
    #.. Push source file(s)
4221
    foreach ( @srcs )
4222
    {
4223
        if ( ! /^-(.*)/ )
4224
        {
4225
            $source = MakeSrcResolveExtended( $from_package, $_ );
4226
            $basename = StripDir( $source );
4227
            Debug( "Src: $_ -> $source=$basename (@args),(@depends)" );
4228
 
4229
            if ( $SRCS{ $basename } ) {
6387 dpurdie 4230
                Warning( "Duplicate src ignored '$source'") unless $ignoreDups;
227 dpurdie 4231
                next;
4232
            }
4233
            $SRCS{ $basename } = $source;
4234
 
4235
            HashJoin( \%SRC_ARGS, $;, $basename, @args )
4236
                if (@args);
4237
 
4238
            HashJoin( \%SRC_DEPEND, $;, $basename, @depends )
4239
                if ( @depends );
4240
 
4241
            $SRC_TYPE{ $basename } = $type
4242
                if ($type);
4243
 
4244
 
4245
            foreach (@lists) {
4246
                my $lname_short = "LIST_$_";
4247
                my $lname_full = "LIST_FULL_$_";
4248
 
4249
                no strict 'refs';
4250
 
4251
                push @$lname_short,$basename;
4252
                push @$lname_full ,$source;
4253
 
4254
                use strict 'refs';
4255
            }
4256
 
4257
            __AddSourceFile( 1, $source, "", $type );
4258
        }
4259
    }
4260
}
4261
 
6387 dpurdie 4262
#-------------------------------------------------------------------------------
4263
# Function        : AddToSrc 
4264
#
4265
# Description     : Internal function
4266
#                   Used by plugins and tools
4267
#                   
4268
#                   Will test if specified file is known to JATS, before
4269
#                   adding to the the list of known (Src) files 
4270
#
4271
# Inputs          : $platform
4272
#                   $file           - Only one file
4273
#                   @srcOpts        - Same as Src
4274
#
4275
# Returns         : True if any file can be found
4276
#                   Returns full path to the file    
4277
#
4278
sub AddToSrc
4279
{
4280
    my( $platforms, $file, @args ) = @_;
4281
    Debug2( "AddToSrc($platforms, $file, @args)" );
227 dpurdie 4282
 
6387 dpurdie 4283
    #
4284
    #   Process files
4285
    #
4286
    my $basename = StripDir( $file );
4287
    unless (exists $SRCS{$file} || exists  $SRCS{$basename} ) {
4288
        Src ('*', $file, @args);
4289
    }
4290
 
4291
    return $SRCS{$basename};
4292
}
4293
 
4294
 
227 dpurdie 4295
###############################################################################
4296
#  sub LibNameSplit
4297
#      Just a little help to deal with major/minor stuff for shared libs -
4298
#      given the name of the library as the argument, split out major and minor
4299
#      parts and return the basename, i.e name without major and minor and
4300
#      the pair of major and minor.
4301
###############################################################################
4302
 
4303
sub LibNameSplit
4304
{
4305
    my ( @bits ) = split('\.', $_[0]);
4306
    my ( $major, $minor );
4307
 
4308
    if ($#bits >= 1) {
4309
        $major = $bits[0]; $minor = $bits[1];
4310
    } elsif ($#bits >= 0) {
4311
        $major = $bits[0]; $minor = 0;
4312
    } else {
4313
        $major = 1; $minor = 0;
4314
    }
4315
    Debug( "LibName: $@_[0] ($major.$minor)" );
4316
    return ($major, $minor);
4317
}
4318
 
4319
#-------------------------------------------------------------------------------
4320
# Function        : Lib
4321
#
4322
# Description     : Generate a static library
4323
#
4324
# Inputs          : Platform specifier
4325
#                   Name of the library
4326
#                   Arguemnts ...
4327
#
4328
# Returns         :
4329
#
4330
sub Lib
4331
{
4332
    my( $platforms, $lib, @args ) = @_;
4333
    return if ( ! ActivePlatform($platforms) );
4334
 
4335
    Error ("Lib: Library name not defined") unless ( $lib );
4336
 
4337
    #
4338
    #   May be a shared library or a static library - for historic reasons
4339
    #   If the user has specified a --Shared then its a shared library
4340
    #
4341
    return SharedLib( @_ )
4342
        if ( grep (/^--Shared/, @args) );
4343
 
4344
    #
4345
    #   Does this toolset support libraries
4346
    #
4347
    Error ("Libraries are not supported") unless ( defined $::a );
4348
 
4349
    #.. Fully qualify library path for addition to library list.
4350
    $lib = "lib$lib"
4351
       if ( $ScmTargetHost eq "Unix" && $lib !~ m/^lib/);
4352
    Debug( "Lib: $lib" );
4353
 
4354
    #
289 dpurdie 4355
    #   Create a new object to describe the library
227 dpurdie 4356
    #   Ensure that only one such lib exists
289 dpurdie 4357
    #   Add the library to the list of static libraries
227 dpurdie 4358
    #
4359
    Error( "Library of the same name already defined: $lib" )
289 dpurdie 4360
        if ( $LIBS->Get($lib) );
4361
    $LIBS->NewAdd($lib);
227 dpurdie 4362
 
4363
    #
4364
    #   Process arguments
4365
    #
4366
    push( @LINTLIBS, $lib );
4367
    _LibArgs( $lib, @args );
4368
}
4369
 
4370
 
4371
#-------------------------------------------------------------------------------
4372
# Function        : SharedLib
4373
#
4374
# Description     : Generate a shared library
4375
#
4376
# Inputs          : Platform specifier
4377
#                   Name of the library
4378
#                   Arguemnts ...
4379
#
4380
# Returns         :
4381
#
4382
sub SharedLib
4383
{
4384
    my( $platforms, $lib, @args ) = @_;
4385
 
4386
    return if ( ! ActivePlatform($platforms) );
4387
 
4388
    Error ("SharedLib: Library name not defined") unless ( $lib );
4389
    Error ("Shared Libraries are not supported") unless ( defined $::so );
4390
 
4391
#.. Fully qualify library path for addition to library list.
4392
    $lib = "lib$lib"
4393
       if ( $ScmTargetHost eq "Unix" && $lib !~ m/^lib/);
4394
    Debug( "ShLib: $lib" );
4395
 
4396
    #
4397
    #   Ensure that only one such lib exists
4398
    #
289 dpurdie 4399
    Error( "Library of the same name already defined: $lib" )
4400
        if ( $SHLIBS->Get($lib) );
4401
    $SHLIBS->NewAdd($lib);
293 dpurdie 4402
 
227 dpurdie 4403
    #
4404
    #   If the user has not specified a --Shared parameter then provide one
4405
    #
4406
    push @args, "--Shared=Current"
4407
        unless ( grep (/^--Shared/, @args) );
4408
 
4409
    #
4410
    #   Process arguments
4411
    #
4412
    push( @LINTSHLIBS, $lib );
4413
    _SharedLibArgs( $lib, @args );
4414
}
4415
 
4416
 
4417
#-------------------------------------------------------------------------------
4418
# Function        : LibArgs
4419
#
4420
# Description     : Add arguments to an existing library directive
4421
#
4422
# Inputs          : Platform specifier
4423
#                   Name of the library
4424
#                   Arguemnts ...
4425
#
4426
# Returns         :
4427
#
4428
sub LibArgs
4429
{
4430
    my( $platforms, $lib, @args ) = @_;
4431
    return if ( ! ActivePlatform($platforms) );
4432
 
4433
#.. Fully qualify library path for addition to library list.
4434
    $lib = "lib$lib"
4435
       if ( $ScmTargetHost eq "Unix" && $lib !~ m/^lib/);
4436
    Debug( "LibArgs: $lib" );
4437
 
4438
    #
4439
    #   Process the arguments
4440
    #
4441
    _LibArgs( $lib, @args );
4442
}
4443
 
4444
 
4445
#-------------------------------------------------------------------------------
4446
# Function        : _LibArgs
4447
#
4448
# Description     : Process static library arguments
4449
#                   Internal use only
4450
#
4451
# Inputs          : Name of the library
4452
#                   Arguments to process
4453
#
4454
sub _LibArgs
4455
{
4456
    my( $lib, @elements) = @_;
4457
    my $obj;
4458
 
4459
    #
289 dpurdie 4460
    #   Ensure that only one such lib exists
4461
    #
4462
    my $libp = $LIBS->Get($lib);
4463
    Error("Library name not defined: $lib")
4464
        unless ( $libp );
4465
 
4466
    #
227 dpurdie 4467
    #   Process each element
4468
    #
4469
    foreach (@elements)
4470
    {
371 dpurdie 4471
        if ( /^\s+/ )
4472
        {
4473
            Error ("Argument cannot start with a space: '$_'");
4474
        }
227 dpurdie 4475
        if ( /^--Shared/ )
4476
        {
4477
            Error( "--Shared not valid for a static library" );
4478
        }
4479
 
4480
        if ( /^-l(.*)/ || /^--l(.*)/ || /^-L(.*)/ || /^--L(.*)/ )
4481
        {
4482
        #.. Target library specified - add to library list.
4483
        #
4484
            Warning( "$_ within non shared library specification" );
4485
            next;
4486
        }
4487
 
4488
        if ( /^--if(.*)/ )
4489
        {
4490
            Warning( "$_ within non shared library specification" );
4491
            next;
4492
        }
4493
 
4494
        if ( /^--(.*)/ )
4495
        {
4496
            Debug( "LibArgs: arg $_" );
4497
 
4498
            #.. Argument specified - add to argument list
4499
            #
289 dpurdie 4500
            $libp->addItem('ARGS', $_);
4501
 
227 dpurdie 4502
            next;
4503
        }
4504
 
369 dpurdie 4505
        if ( %::ScmToolsetProgSource )
227 dpurdie 4506
        {
4507
            #
4508
            #   Toolset provides support for some file types
4509
            #   to be passed directly to the librarian builder
4510
            #
4511
            my $ext  = StripFile($_);
4512
            if ( exists ($::ScmToolsetProgSource{$ext}) )
4513
            {
4514
                my $full_path = MakeSrcResolve ( $_ );
4515
                my $flag = $::ScmToolsetProgSource{$ext};
4516
                Debug( "LibArgs: src $_" );
289 dpurdie 4517
                $libp->addItem('ARGS', "$flag$full_path" );
227 dpurdie 4518
                next;
4519
            }
4520
        }
4521
 
4522
        if ( $::o )
4523
        {
4524
        #.. Object specified - add to object list.
4525
        #
4526
            $obj = _LibObject( "", $_ );
4527
 
4528
        #.. Add to object list.
4529
        #   Note:   Object path must be explicit as several
4530
        #           toolsets add additional objects.
4531
        #
289 dpurdie 4532
            $libp->addItem('OBJS', "\$(OBJDIR)/$obj" );
227 dpurdie 4533
            next;
4534
        }
4535
 
4536
        #
4537
        #   Don't know how to handle this type of argument
4538
        #
4539
        Error ("LibArgs: Don't know how to handle: $_" );
4540
    }
4541
}
4542
 
4543
 
4544
#-------------------------------------------------------------------------------
4545
# Function        : SharedLibArgs
4546
#
4547
# Description     : Add arguments to an existing shared library directive
4548
#
4549
# Inputs          : Platform specifier
4550
#                   Name of the library
4551
#                   Arguemnts ...
4552
#
4553
# Returns         :
4554
#
4555
sub SharedLibArgs
4556
{
4557
    my( $platforms, $lib, @args ) = @_;
4558
    return if ( ! ActivePlatform($platforms) );
4559
 
4560
#.. Fully qualify library path for addition to library list.
4561
    $lib = "lib$lib"
4562
       if ( $ScmTargetHost eq "Unix" && $lib !~ m/^lib/);
4563
    Debug( "ShLibArgs: $lib" );
4564
 
4565
    _SharedLibArgs( $lib, @args );
4566
}
4567
 
4568
 
4569
#-------------------------------------------------------------------------------
4570
# Function        : _SharedLibArgs
4571
#
4572
# Description     : Process shared library arguments
4573
#                   Internal use only
4574
#
4575
# Inputs          : Name of the library
4576
#                   Arguments to process
4577
#
4578
sub _SharedLibArgs
4579
{
4580
    my ( $lib, @elements) = @_;
4581
 
289 dpurdie 4582
    my $libp = $SHLIBS->Get($lib);
4583
    Error("Library name not defined: $lib")
4584
        unless ( $libp );
4585
 
227 dpurdie 4586
    #
289 dpurdie 4587
    #.. Collect --Shared arguments
339 dpurdie 4588
    #   Need to process this one first so that we have a version number
227 dpurdie 4589
    #
4590
    foreach (@elements)
4591
    {
371 dpurdie 4592
        if ( /^\s+/ )
4593
        {
4594
            Error ("Argument cannot start with a space: '$_'");
4595
        }
289 dpurdie 4596
        next unless ( /^--Shared/ );
4597
 
4598
        my $shared;
227 dpurdie 4599
        if ( /^--Shared$/ )
4600
        {
4601
        #.. Shared library, default library version 1.0
4602
        #
4603
            $shared = "1.0";
4604
        }
4605
        elsif ( /^--Shared=Current$/ )
4606
        {
4607
        #.. Shared library, using 'current' build version
4608
        #
4609
            $shared = $::ScmBuildVersion;
289 dpurdie 4610
            $shared = "1.0" if ($shared eq "");
227 dpurdie 4611
        }
4612
        elsif ( /^--Shared=(.*)/ )
4613
        {
4614
        #.. Shared library, specific version
4615
        #
4616
            my($M, $m) = LibNameSplit($1);
289 dpurdie 4617
            $shared = "$M.$m";
4618
        }
227 dpurdie 4619
 
289 dpurdie 4620
        #
4621
        #   Update the shared Names
4622
        #
4623
        if ( defined $shared )
4624
        {
227 dpurdie 4625
            Warning( "multiple --Shared arguments" )
339 dpurdie 4626
                if (exists $libp->{ VERSION });
227 dpurdie 4627
            Debug( "ShLibArgs: shared $_ ($shared)" );
289 dpurdie 4628
            $libp->{ VERSION } = $shared;
227 dpurdie 4629
        }
289 dpurdie 4630
        else
4631
        {
4632
            Error ("ShLibArgs: --Shared argument not understood");
4633
        }
227 dpurdie 4634
    }
4635
 
4636
 
4637
#.. Parse all of the object and argument entries.
4638
#
4639
    foreach (@elements)
4640
    {
289 dpurdie 4641
        next if ( /^--Shared(.*)/ );
227 dpurdie 4642
 
4643
        if ( /^[-]{1,2}([lL])(.*)/ )
4644
        {
4645
        #.. Target library specified - add to library list.
339 dpurdie 4646
        #   Support --L and -L and --l and -l
227 dpurdie 4647
        #
4648
            Debug( "ShLibArgs: lib  -$1$2" );
289 dpurdie 4649
            $libp->addItem('LIBS', "-$1$2" );
227 dpurdie 4650
            next;
4651
        }
4652
 
4653
        if ( /^--if(.*)/ )
4654
        {
4655
        #.. Library conditional - add to library list.
4656
        #
4657
            Debug( "ShLibArgs: cond $_" );
289 dpurdie 4658
            $libp->addItem('LIBS', $_);
227 dpurdie 4659
            next;
4660
        }
4661
 
339 dpurdie 4662
        if ( /^--SoName=(.*)/i )
4663
        {
4664
        #.. Specify the SoName of the library
4665
        #   Not supported by all toolsets
4666
        #
4667
            my $soMode = $1;
4668
            if ( !$ScmToolsetSoName )
4669
            {
4670
                Warning ("Toolset does not support --SoName. Option ignored");
4671
                next;
4672
            }
4673
 
4674
            Error ("SharedLib: $lib. Multiple --SoName arguments not allowed")
4675
                if ( $libp->{ SONAME } );
4676
 
4677
            my ($major, $minor, $patch, $build, $raw_patch) = SplitVersion($::ScmBuildVersionFull);
4678
            my $soname = '.';
4679
            if ( $soMode =~ m/Major/i ) {
4680
                $soname .= $major;
4681
            } elsif ( $soMode =~ m/^Minor/i ) {
4682
                $soname .= "$major.$minor";
4683
            } elsif ( $soMode =~ m/^Patch/i ) {
4684
                $soname .= "$major.$minor.$patch";
4685
            } elsif ( $soMode =~ m/^Build/i ) {
4686
                $soname .= "$major.$minor.$patch.$build";
4687
            } elsif ( $soMode =~ m/^Full/i ) {
4688
                $soname .= $libp->{ VERSION };
4689
            } elsif ( $soMode =~ m/^None/i ) {
4690
                $soname = '';
4691
            } elsif ( $soMode =~ m/^[0-9.]+$/ ) {
4692
                $soname .= $soMode;
4693
            } else {
4694
                Error ("Unknown --SoName mode: $soMode");
4695
            }
4696
            $libp->addItem('ARGS', '--SoNameSuffix=' . $soname);
4697
            $libp->{ SONAME } = 1;
4698
            next;
4699
        }
4700
 
227 dpurdie 4701
        if ( /^-(.*)/ )
4702
        {                           
4703
        #.. Argument specified - add to argument list
4704
        #
4705
            Debug( "ShLibArgs: arg  $_" );
289 dpurdie 4706
            $libp->addItem('ARGS', $_);
227 dpurdie 4707
            next;
4708
        }
4709
 
369 dpurdie 4710
        if ( %::ScmToolsetProgSource )
227 dpurdie 4711
        {
4712
            #
4713
            #   Toolset provides support for some file types
4714
            #   to be passed directly to the program builder
4715
            #
4716
            my $ext  = StripFile($_);
4717
            if ( exists ($::ScmToolsetProgSource{$ext}) )
4718
            {
4719
                my $full_path = MakeSrcResolve ( $_ );
4720
                my $flag = $::ScmToolsetProgSource{$ext};
4721
                Debug( "ShLibArgs: src $_" );
289 dpurdie 4722
                $libp->addItem('ARGS', "$flag$full_path");
227 dpurdie 4723
                next;
4724
            }
4725
        }
4726
 
4727
        if ( $::o )
4728
        {
4729
        #.. Object specified - add to object list.
4730
        #
4731
            my ($obj) = _LibObject( $lib, $_ );
4732
 
4733
        #.. Add to object list.
4734
        #   Note:   Object path must be explicit as several
4735
        #           toolsets add additional objects.
4736
        #
4737
            $SHOBJ_LIB{ $obj } = $lib;
289 dpurdie 4738
            $libp->addItem('OBJS', "\$(OBJDIR)/$obj");
227 dpurdie 4739
            next;
4740
        }
4741
 
4742
        #
4743
        #   Don't know how to handle this type of argument
4744
        #
4745
        Error ("SharedLib: Don't know how to handle: $_" );
4746
    }
4747
}
4748
 
4749
 
4750
#-------------------------------------------------------------------------------
4751
# Function        : _LibObject
4752
#
4753
# Description     : Process library object file
4754
#                   Common processing routine for static and shared library
4755
#                   Internal use only
4756
#
4757
# Inputs          : shared  - Name of the shared library is shared, if defined
4758
#                   fname   - Name of file
4759
#
4760
# Returns         : Name of the object file
4761
#
4762
sub _LibObject
4763
{
4764
    my ($shared, $fname) = @_;
4765
    my ($file, $ext, $obj, $srcfile, $delete_obj);
4766
 
4767
    #.. Object specified - add to object list.
4768
    #
4424 dpurdie 4769
    #   Want to handle several cases
4770
    #       Normal - User has provided the name of an object file (without the obj suffix)
4771
    #       Other  - User has provided the name of a source file
4772
    #                Need to perform implicit source file processing
4773
    #
4774
    #   The hard part is detecting the difference
4775
    #   Just can't use the existence of a '.' 
4776
    #
4777
    if ($OBJSOURCE{$fname}) {
4778
        $file = $fname;                             # Already know about this file
4779
        $ext = '';                                  # Don't need to split it
4780
    } else {
4781
        $file = StripDirExt($fname);                # file name, without extension or Dir
4782
        $ext  = StripFile($fname);                  # extension
4783
    }
227 dpurdie 4784
 
4785
    if ($shared) {
4786
        $obj = "$shared/$file";                 # library specific subdir
4787
    } else {
4788
        $obj = "$file";
4789
    }
4790
 
4791
    Debug( "LibObjs: obj [$shared]$fname ($file$ext)" );
4792
 
4793
    #.. Unqualified object name
4794
    #
4424 dpurdie 4795
    if ( $ext eq '' ) {
227 dpurdie 4796
        #
4797
        #   Object file not covered by a "Src" statement
4798
        #   Assume that it will be created
4799
        #
4424 dpurdie 4800
        unless ( $srcfile = $OBJSOURCE{$file} )
227 dpurdie 4801
        {
4802
            #
4424 dpurdie 4803
            #   If the object is "generated" then it will be in the
227 dpurdie 4804
            #   SRCS list
4805
            #
4806
            unless ( $srcfile = $SRCS{"$file.$::o"} )
4807
            {
4808
                Warning( "No source for object '$fname' ($file)" );
4809
            }
4810
        }
4811
        $delete_obj = 1;
4812
    }
4813
 
4814
    #.. Qualified object name (ie has extension)
4815
    #       Strip extension and resolve ...
4816
    #       Assume that the named file can be built into an object file
4817
    #
4818
    else
4819
    {
4820
        #.. Resolve
4821
        #
4822
        if ( !($srcfile = $OBJSOURCE{ "$file" }) )
4823
        {
4824
            $srcfile = MakeSrcResolve( $fname );
4825
            $SRCS{ $fname } = $srcfile;
4826
            __AddSourceFile( 0, $fname, $obj );
4827
            $delete_obj = 1;
4828
        }
4829
    }
4830
 
4831
    #.. Delete generated object file
4832
    #   Ensure that the object file is added to the delete list
4833
    #   Add it to the ToolsetObj deletion list as the main OBJ deleltion
4834
    #   list will aready have been processed
4835
    #
4836
    ToolsetObj( "\$(OBJDIR)/$obj" )
4837
        if ( $delete_obj );
4838
 
4839
 
4840
    #.. Shared library objects,
4841
    #       Must explicitly relate source and object, as shared libraries
4842
    #       objects are built within a library specific subdirs.
4843
    #
4844
    $OBJSOURCE{ $obj } = $srcfile
371 dpurdie 4845
        if ( $shared && defined $srcfile );
227 dpurdie 4846
 
4847
    return $obj;
4848
}
4849
 
4850
 
4851
# MergeLibrary
4852
#   Merge a list of libraries into one library
4853
#
4854
sub MergeLibrary
4855
{
4856
    my( $platforms, $lib, @elements ) = @_;
4857
 
4858
    return if ( ! ActivePlatform($platforms) );
4859
 
4860
 
4861
#.. Fully qualify library path for addition to library list.
4862
    $lib = "lib$lib"
4863
       if ( $ScmTargetHost eq "Unix" && $lib !~ m/^lib/);
4864
    Debug( "MergeLibrary: $lib" );
4865
 
289 dpurdie 4866
    #
4867
    #   Create a new object to describe the library
4868
    #   Ensure that only one such lib exists
4869
    #   Add the library to the list of static libraries
4870
    #
4871
    Error( "Merged Library of the same name already defined: $lib" )
4872
        if ( $MLIBS->Get($lib) );
4873
    my $libp = $MLIBS->NewAdd($lib);
4874
 
227 dpurdie 4875
#.. Parse all of the object and argument entries.
4876
#
4877
    foreach (@elements)
4878
    {
4879
        if ( /^--(.*)/ )
4880
        {
289 dpurdie 4881
            $libp->addItem('ARGS', $_);
227 dpurdie 4882
        }
4883
        else
4884
        {
4885
            my ($llib);
4886
 
4887
            #
4888
            #   Collect the source libraries
4889
            #   These must have been installed and will be in a known area
4890
            #   Create full names for the libaries
4891
            #
4892
            if ( $ScmTargetHost eq "Unix" ) {
4893
                $llib = "lib$_";                # Prefix "lib" ....
4894
                $lib =~ s/^liblib/lib/;         # @LIBS already has lib added
4895
            } else {
4896
                $llib = $_;
4897
            }
4898
 
4899
            Debug( "MergeLibrary: merge $llib" );
289 dpurdie 4900
            $libp->addItem('LIBS', $llib);
227 dpurdie 4901
        }
4902
    }
4903
}
4904
 
4905
#-------------------------------------------------------------------------------
4906
# Function        : Script
4907
#
4908
# Description     : Locate a script for test purposes
4909
#
4910
# Inputs          : $platforms      - Platform selector
4911
#                   $script         - A single script name
4912
#                   $execute        - Flag to indicate that the script is to
4913
#                                     marked as executable when used in a TestProg
4914
#                                     This flag is NOT used as the script will
4915
#                                     be forced executable
4916
#
4917
# Returns         : Nothing
4918
#
4919
sub Script
4920
{
4921
    my( $platforms, $script, $execute ) = @_;
4922
 
4923
    Debug2( "Script(@_)" );
4924
 
4925
    return if ( ! ActivePlatform($platforms) );
4926
 
4927
    #
4928
    #   Locate the script as a source file
4929
    #
4930
    my $file = MakeSrcResolve ( $script );
4931
    $script = StripDir( $file );
4932
    $SCRIPTS{ $script } = $file;
4933
}
4934
 
4935
#-------------------------------------------------------------------------------
4936
# Function        : RunTest
4937
#
4938
# Description     : Define a test to be run with the 'run_tests' and 'run_unit_tests'
4939
#
4940
# Inputs          : $platform       - Enabled for these platforms
4941
#                   $prog           - Program to run
4942
#                                     This SHOULD return a non-zero exit status
4943
#                                     on error. The program may be a 'TestProg'
4944
#                                     or a 'Script'.
4945
#                   @elements       - Options and test arguments
4946
#                                     Options are:
4778 dpurdie 4947
#                                       --Auto              - Non interactive unit test
4948
#                                       --Unit              - Same and --Auto
4949
#                                       --UtfFormat=nnn     - Specifies Automated Unit Test, 
4950
#                                                             results post processed with formatter
4781 dpurdie 4951
#                                       --UtfArg=nnn        - Argument passed into the UTF formatter    
4952
#                                       --Name=nnn          - Test Name.
5695 dpurdie 4953
#                                       --CopyIn=file       - A file to be copied into the test directory.
4954
#                                       --MaxTime=fff.ff[smhd] - Max Test Time. Default 30m
227 dpurdie 4955
#
4956
#                                     Non Options are passed to the test program.
4957
#                                     --PackageBase(xxx)    - Base of package
4958
#                                     --PackageInfo(xxx)    - Package information
4959
#                                     --File(xxx)           - Resolved name of file
4960
#                                     --Var(xxx)            - Expanded variable
4961
#                                     --Local(xxx)          - File within the local directory
4962
#
4778 dpurdie 4963
#                                     Toolset Framework support (ie NUNIT in csharp.pl)
4964
#                                       --FrameWork=name    - Name of framework
4965
#                                       --xxxx              - Args passed to framework constructor
4966
#
227 dpurdie 4967
# Returns         : Nothing
4968
#
4781 dpurdie 4969
my %RunTestNames;                       # Unique Name Tests
227 dpurdie 4970
sub RunTest
4971
{
4972
    my( $platforms, $prog, @elements ) = @_;
4973
    my $command = './';                 # program prefix / command
4974
    my $winprog = 1;                    # 1: Convert / -> \ (WIN32 only)
4975
    my $framework;
4976
    my @framework_opts;
4977
    my @copy = ();
4978
    my $auto;
4778 dpurdie 4979
    my $utfFormat;
4781 dpurdie 4980
    my @utfArgs;
4981
    my $utfName;
5695 dpurdie 4982
    my $maxTime;
227 dpurdie 4983
 
4984
    return if ( ! ActivePlatform($platforms) );
4985
 
4986
    #
4987
    #   Scan @elements and extract useful information
4988
    #   Need to process twice as some args will modify the
4989
    #   processing done later
4990
    #
4991
    my @args;
4992
    foreach ( @elements )
4993
    {
4994
        if ( m/^--FrameWork=(.+)/ ) {
4995
            $framework = $1;
4996
 
4997
        } elsif ( m/^--Auto/ || m/^--Unit/) {
4998
            $auto = 1;
4999
 
4781 dpurdie 5000
        } elsif ( m/^--Name=(.*)/) {
5001
            $utfName = $1;
5002
 
5003
            Error("Duplicate Test Name: $utfName")
5004
                if (exists $RunTestNames{$utfName} );
5005
            $RunTestNames{$utfName} = 1;
5006
 
4778 dpurdie 5007
        } elsif ( m/^--UtfFormat=(.*)/) {
5008
            $utfFormat = $1;
5009
 
4781 dpurdie 5010
        } elsif ( m/^--UtfArg=(.*)/) {
5011
            push @utfArgs, $1;
5012
 
5695 dpurdie 5013
        } elsif ( m/^--MaxTime=(.*)/) {
5014
            $maxTime = $1;
5015
            unless ($maxTime =~ m~^[0-9]*\.?[0-9]+[smhd]?$~) {
5016
                Error("MaxTime invalid: $maxTime");
5017
            }
5018
 
227 dpurdie 5019
        } elsif ( m/^--CopyIn=(.*)/ ) {
5020
            push @copy, MakeSrcResolve ( $1 );
5021
 
5022
        } elsif ( $framework && m/^--\w+=(.+)/ ) {
5023
            push @framework_opts, $_;
5024
 
5025
        } else {
5026
            push @args, $_;
5027
        }
5028
    }
5029
    @elements = @args;
5030
    @args = ();
5031
 
5032
    #
5033
    #   Determine the source of the test prog
4612 dpurdie 5034
    #   If using a plug-in framework, then we don't know
227 dpurdie 5035
    #   If not, then may be a script or a TESTPROGS
5036
    #
5037
 
5038
    unless ( $framework )
5039
    {
289 dpurdie 5040
        if ( $TESTPROGS->Get($prog) || $PROGS->Get($prog)  ) {
227 dpurdie 5041
            #
5042
            #   Append a suitable EXE suffix
5043
            #
289 dpurdie 5044
            $prog = GenProgName( $prog );
227 dpurdie 5045
 
5046
        } elsif ( exists $SCRIPTS{$prog} ) {
5047
            #
5048
            #   Script names are raw
5049
            #   Perl script are invoked directly
5050
            #
5051
            $command = "\$(GBE_PERL) -w "
5052
                if ( $prog =~ /\.pl$/ );
5053
 
5054
            #
5055
            #   Pass / to shells
5056
            #
5057
            $winprog = 0
5058
                unless ( $prog =~ m~\.bat$~ )
5059
 
5060
        } else {
5061
            Warning("RunTest program not known: $prog",
261 dpurdie 5062
                  "It is not a TestProg, Prog or a Script",
5063
                  "The test may fail" );
227 dpurdie 5064
        }
5065
    }
5066
 
5067
    #
5068
    #   Extract and process options
5069
    #
5070
    my @uargs = ();
5071
    my @preq_files;
5072
 
5073
    foreach my $arg (@elements) {
5074
        #
5075
        #   Process the tool arguments and extract file information
5076
        #   Extract all fields of the form:
5077
        #           --xxxxx(yyyyyy[,zzzzz])
5078
        #           --xxxxx{yyyyyyy}
5079
        #           --xxxxx[yyyyyyy] to allow embedded brackets
5080
        #
5081
        while ( $arg =~ m/--(\w+)               # --CommandWord         $1
5082
                                (               # Just for grouping
5083
                                \((.*?)\)   |   # Stuff like (yyyyy)    $3
5084
                                {(.*?)}     |   # or    like {yyyyy}    $4
5085
                                \[(.*?)\]       # or    like [yyyyy]    $5
5086
                                )/x )           # Allow comments and whitespace
5087
        {
5088
            my $cmd = $1;                       # The command
5089
            my $ufn = $3 || $4 || $5;           # User filename + options
5090
            my $mb = $-[0];                     # Match begin offset
5091
            my $me = $+[0];                     # Match end
5092
            my $flags = '';                     # Optional flags ( --dir or --file )
5093
            my $raw_arg = $ufn;                 # Raw arguments
6387 dpurdie 5094
            my $all = substr( $arg, $mb, $me - $mb ); # All of match. Avoid use of $&
329 dpurdie 5095
            my $is_abs;
5096
            my $is_path = 1;
227 dpurdie 5097
 
5098
            Error ("RunTest. Empty element not allowed: $all")
5099
                unless ( defined($ufn) );
5100
 
5101
            $ufn =~ s/\s+$//;
5102
            $ufn =~ s~//~/~g;                   # Remove multiple /
5103
            if ( $ufn =~ m/(.*?),(.*)/ )        # Extract out any flags
5104
            {
5105
                $ufn = $1;
5106
                $flags = $2;
5107
            }
5108
 
5109
            my $fn = $ufn ;                     # Replacement filename
343 dpurdie 5110
            my $fnp = '';                       # Prefix to $fn
227 dpurdie 5111
            Error ("RunTest. Empty element not allowed: $all" )
5112
                if ( length ($ufn) <= 0 );
5113
 
5114
            #
5115
            #   Process found user command
5116
            #
5117
            if ( $cmd =~ /^File/ )
5118
            {
5119
                #
5120
                #   Prerequisite filename
5121
                #       Resolve the full name of the file. It may be known
5122
                #       as a source file (possibly generated) or it may be
5123
                #       located in a known source directory
5124
                #
5125
                $fn = MakeSrcResolve ( $ufn );
5126
                UniquePush (\@preq_files, $fn);
5127
 
5128
                Debug( "RunTest: Prereq: $fn" );
5129
 
5130
            }
5131
            elsif ( $cmd =~ /^PackageBase/ )
5132
            {
5133
                $fn = GetPackageBase( "RunTest", $raw_arg );
5134
                UniquePush (\@preq_files, $fn);
5135
            }
5136
            elsif ( $cmd =~ /^PackageInfo/ )
5137
            {
5138
                $fn = GetPackageInfo( "RunTest", $raw_arg );
5139
            }
5140
            elsif ( $cmd =~ /^Var/ )
5141
            {
343 dpurdie 5142
                ($fnp, $fn, $is_path, $is_abs) = ExpandGenVar( "RunTest", $raw_arg );
227 dpurdie 5143
                $flags = '';
5144
            }
5145
            elsif ( $cmd =~ /^Local/ )
5146
            {
5147
                $fn = '$(LOCALDIR)/' . $ufn ;
5148
                UniquePush (\@preq_files, $fn);
5149
            }
6387 dpurdie 5150
            elsif ( $cmd =~ /^Dir/ )
5151
            {
5152
                # Item is a directory.
5153
                # Must be massaged so that it will be correct within the context
5154
                # Modified path is simply added to the command line
5155
                # 
5156
                $fn = $ufn;
5157
                unless (-d $fn) {
5158
                    if (-f $fn) {
5159
                        Warning ("Not a directory. Its a file: $arg") ;
5160
                    } else {
5161
                        Warning ("Directory not found: $arg");
5162
                    }
5163
                }
5164
            }
227 dpurdie 5165
            else
5166
            {
5167
                Warning ("RunTest: Unknown replacement command: $cmd");
5168
                $fn = $ufn;
5169
            }
5170
 
5171
            #
5172
            #   Process path modification flags
5173
            #       --dir           - only the directory part ( or a "." )
5174
            #       --file          - only the file part
5175
            #       --abspath       - Absolute path
5176
            #       --absdrive      - Absolute path with drive letter(WIN)
5177
            #
5178
            $fn = ProcessPathName( $fn, $flags );
5179
 
5180
            #
5181
            #   The program is going to be executed within a subdirectory
5182
            #   so add one more level of indirection to the path, but only if
5183
            #   the path is relative
5184
            #
329 dpurdie 5185
            if ( $is_path && ! $is_abs )
227 dpurdie 5186
            {
329 dpurdie 5187
                unless ( $fn =~ m~^/|^\w:/~  )
5188
                {
5189
                    $fn = '../' . $fn
5190
                        unless( $fn =~ s~=~=../~ );
5191
                    $fn =~ s~/.$~~;
5192
                }
227 dpurdie 5193
            }
5194
 
5195
            #
5196
            #   Minor kludge under windows. Ensure directores have a "\" sep
5197
            #   Unless the user has specified a straight shell command
5198
            #
5986 dpurdie 5199
            $fn = "\$(subst /,\$(dirsep),$fn)"
227 dpurdie 5200
                if ( $::ScmHost eq "WIN" && $winprog );
5201
 
5202
            #
343 dpurdie 5203
            #   Prepend any $fn Prefix
5204
            #   This will be a tag and is not subject to path processing
5205
            #
5206
            $fn = $fnp . $fn;
5207
 
5208
            #
227 dpurdie 5209
            #   Replace the found string with the real name of the file
5210
            #   Note: 4 argument version of substr is not always available
5211
            #         so we must do it the hard way
5212
            #               substr( $arg, $mb, $me - $mb, $fn);
5213
            #
5214
            $arg = substr( $arg, 0, $mb ) . $fn . substr( $arg, $me );
5215
 
5216
            Debug2( "RunTest: subs: $all -> $fn" );
5217
        }
5218
        push(@uargs, "'$arg'");
5219
    }
5220
 
5221
    #
5222
    #   Create the test entry
5223
    #   This is a structure that will be placed in an array
5224
    #   The array preserves order and uniqness
5225
    #
5226
    my %test_entry;
5227
    $test_entry{'framework'}= $framework if ( $framework );
5228
    $test_entry{'framework_opts'}= \@framework_opts if ( $framework );
5229
    $test_entry{'command'}  = $command . $prog unless ( $framework);
5230
 
5231
    $test_entry{'prog'}     = $prog;
5232
    $test_entry{'copyprog'} = 1;
5233
    $test_entry{'args'}     = \@uargs;
5234
    $test_entry{'auto'}     = $auto if ( $auto );
4778 dpurdie 5235
    $test_entry{'utfformat'}= $utfFormat if ( $utfFormat );
4781 dpurdie 5236
    $test_entry{'utfargs'}  = \@utfArgs;
5237
    $test_entry{'utfname'}  = $utfName;
5695 dpurdie 5238
    $test_entry{'maxtime'}  = $maxTime if ($maxTime);
227 dpurdie 5239
    $test_entry{'copyin'}   = \@copy;
5240
    $test_entry{'copyonce'} = ();
5241
    $test_entry{'preq'}     = \@preq_files;
5242
    $test_entry{'testdir'}  = 'BINDIR';
5243
 
5244
    push ( @TESTS_TO_RUN, \%test_entry );
5245
 
5246
    #
5247
    #   Flag Auto Run processing required
5248
    #
4501 dpurdie 5249
    $TESTS_TO_RUN = 1;
227 dpurdie 5250
    $TESTS_TO_AUTORUN = 1 if ( $auto );
5251
}
5252
 
5253
 
5254
sub TestProg
5255
{
5256
    my( $platforms, $prog, @elements ) = @_;
5257
 
5258
    Debug2( "TestProg($platforms, $prog, @elements)" );
5259
 
5260
    return if ( ! ActivePlatform($platforms) );
5261
 
5262
    Error ("TestProg: Program name not defined") unless ( $prog );
5263
    Error ("Programs are not supported") unless ( defined $::exe );
5264
 
289 dpurdie 5265
    #
5266
    #   Create a new Prog object, or retrieve any existing one
5267
    #
5268
    my $pProg = $TESTPROGS->Get($prog);
5269
    $pProg = $TESTPROGS->NewAdd($prog)
5270
        unless ( $pProg );
227 dpurdie 5271
 
5272
#.. Parse all of the object, library and argument entries
5273
    Debug( "TestProg: $prog" );
5274
    foreach (@elements)
5275
    {
5276
        if ( /^[-]{1,2}([lL])(.*)/ )
5277
        {
5278
        #.. Target Library specified - add to library list.
5279
        #  
5280
            Debug( "TestProg: lib  -$1$2" );
289 dpurdie 5281
            $pProg->addItem('LIBS', "-$1$2");
227 dpurdie 5282
            next;
5283
        }
5284
 
5285
        if ( /^--if(.*)/ )
5286
        {
5287
        #.. Library conditional - add to library list.
5288
        #
5289
            Debug( "TestProg: cond $_" );
289 dpurdie 5290
            $pProg->addItem('LIBS', $_);
227 dpurdie 5291
            next;
5292
        }
5293
 
5294
        if ( /^-(.*)/ )
5295
        {
5296
        #.. Argument specified - add to argument list
5297
        #
5298
            Debug( "TestProg: arg $_" );
289 dpurdie 5299
            $pProg->addItem('ARGS', $_);
227 dpurdie 5300
            next;
5301
        }
5302
 
369 dpurdie 5303
        if ( %::ScmToolsetProgSource )
227 dpurdie 5304
        {
5305
            #
5306
            #   Toolset provides support for some file types
5307
            #   to be passed directly to the program builder
5308
            #
5309
            my $ext  = StripFile($_);
5310
            if ( exists ($::ScmToolsetProgSource{$ext}) )
5311
            {
5312
                my $full_path = MakeSrcResolve ( $_ );
5313
                my $flag = $::ScmToolsetProgSource{$ext};
5314
                Debug( "TestProg: src $_" );
289 dpurdie 5315
                $pProg->addItem('ARGS', "$flag$full_path");
227 dpurdie 5316
                next;
5317
            }
5318
        }
5319
 
5320
        if ( $::o )
5321
        {
5322
        #.. Object specified - add to object list.
5323
        #
5324
            my $obj = _LibObject( "", $_ );
5325
 
5326
        #.. Add to program object list.
289 dpurdie 5327
            $pProg->addItem('OBJS', "\$(OBJDIR)/$obj");
227 dpurdie 5328
            next;
5329
        }
5330
 
5331
        #
5332
        #   Don't know how to handle this type of argument
5333
        #
5334
        Error ("TestProg: Don't know how to handle: $_" );
5335
    }
5336
}
5337
 
5338
 
5339
sub Prog
5340
{
5341
    my( $platforms, $prog, @elements ) = @_;
5342
 
5343
    Debug2( "Prog($platforms, $prog, @elements)" );
5344
 
5345
    return if ( ! ActivePlatform($platforms) );
5346
 
5347
    Error ("Prog: Program name not defined") unless ( $prog );
5348
    Error ("Programs are not supported") unless ( defined $::exe );
5349
 
289 dpurdie 5350
    #
5351
    #   Create a new Prog object, or retrieve any existing one
5352
    #
5353
    my $pProg = $PROGS->Get($prog);
5354
    $pProg = $PROGS->NewAdd($prog)
5355
        unless ( $pProg );
227 dpurdie 5356
 
5357
#.. Parse all of the object, library and argument entries
5358
    Debug( "Prog: $prog" );
5359
    foreach (@elements)
5360
    {
5361
        if ( /^[-]{1,2}([lL])(.*)/ )
5362
        {
5363
        #.. Target Library specified - add to library list.
5364
        #  
5365
            Debug( "Prog: lib  -$1$2" );
289 dpurdie 5366
            $pProg->addItem('LIBS', "-$1$2");
227 dpurdie 5367
            next;
5368
        }
5369
 
5370
        if ( /^--if(.*)/ )
5371
        {
5372
        #.. Library conditional - add to library list.
5373
        #
5374
            Debug( "Prog: cond $_" );
289 dpurdie 5375
            $pProg->addItem('LIBS', $_);
227 dpurdie 5376
            next;
5377
        }
5378
 
5379
        if ( /^-(.*)/ )
5380
        {
5381
        #.. Argument specified - add to argument list
5382
        #
5383
            Debug( "Prog: arg $_" );
289 dpurdie 5384
            $pProg->addItem('ARGS', $_);
227 dpurdie 5385
            next;
5386
        }
5387
 
369 dpurdie 5388
        if ( %::ScmToolsetProgSource )
227 dpurdie 5389
        {
5390
            #
5391
            #   Toolset provides support for some file types
5392
            #   to be passed directly to the program builder
5393
            #
5394
            my $ext  = StripFile($_);
5395
            if ( exists ($::ScmToolsetProgSource{$ext}) )
5396
            {
5397
                my $full_path = MakeSrcResolve ( $_ );
5398
                my $flag = $::ScmToolsetProgSource{$ext};
5399
                Debug( "Prog: src $_" );
289 dpurdie 5400
                $pProg->addItem('ARGS', "$flag$full_path");
227 dpurdie 5401
                next;
5402
            }
5403
        }
5404
 
5405
        if ( $::o )
5406
        {
5407
        #.. Object specified - add to object list.
5408
        #
5409
            my $obj = _LibObject( "", $_ );
5410
 
5411
        #.. Add to program object list.
289 dpurdie 5412
            $pProg->addItem('OBJS', "\$(OBJDIR)/$obj");
227 dpurdie 5413
            next;
5414
        }
5415
 
5416
        #
5417
        #   Don't know how to handle this type of argument
5418
        #
5419
        Error ("Prog: Don't know how to handle: $_" );
5420
    }
5421
}
5422
 
5423
#-------------------------------------------------------------------------------
5424
# Function        : ProgAddExtra
5425
#
5426
# Description     : This (internal) function allows a toolset to list additional
5427
#                   binaries as a part of a program. This will ensure that the
5428
#                   binaries are generated in the 'make_prog' phase with the main
5429
#                   program.
5430
#
5431
#                   The files are not listed for packaging, by this function
5432
#
5433
#                   The function does not ensure that the files are not already
5434
#                   listed as a @PROG ( as @PROGS is not fully resolved at this point )
5435
#
5436
# Inputs          :     $name               - Tag name of program being built
5437
#                                             Not used (yet)
5438
#                       $prog               - Fully resolved path to a file
5439
#
5440
# Returns         : Nothing
5441
#
5442
sub ProgAddExtra
5443
{
5444
    my ($name, $prog) = @_;
5445
    Debug2( "ProgAddExtra($name: $prog)" );
5446
 
5447
    UniquePush(\@PROGS_EXTRA, $prog);
5448
}
5449
 
4261 dpurdie 5450
our %PROJECTS;                          # Project information
5451
my  @PROJECTS_ORDER;
227 dpurdie 5452
#-------------------------------------------------------------------------------
4261 dpurdie 5453
# Function        : MakeProjectName 
5454
#
5455
# Description     : Create a uniq project name
5456
#
5457
# Inputs          : srcPath 
5458
#
5459
# Returns         : A unique project name 
5460
#
5461
sub MakeProjectName
5462
{
5463
    my ($srcPath) = @_;
5464
    my $suffix = "";
5465
    my $index = 1;
5466
 
5467
    my $proj = StripDir( $srcPath );
5468
    while (exists $PROJECTS{$proj . $suffix})
5469
    {
5470
        $suffix = '.' . $index++;
5471
    }
5472
    return $proj . $suffix; 
5473
}
5474
 
5475
#-------------------------------------------------------------------------------
227 dpurdie 5476
# Function        : MakeProject
5477
#
5478
# Description     : A nasty directive that is intended to build a Microsoft
5479
#                   project for WINCE, WIN32 and .NET builds.
5480
#
5481
#                   There are many constraints:
5482
#                       Cannot be mixed with multi-platform builds
5483
#                       Some parameters are tool specific
5484
#
267 dpurdie 5485
#                   Allow programs to be Installed as well as Packaged
5486
#                   The 'Progect' is treated' as a program and it doesn't work
5487
#                   to well if we Install libraries.
227 dpurdie 5488
#
267 dpurdie 5489
#                   Only Reason to Install Programs is to allow the Cab Maker
5490
#                   to locate them.
5491
#
227 dpurdie 5492
# Inputs          : Platform        - Active platform
5493
#                   Project         - Project Name with extension
5494
#                   Options         - Many options
5495
#
5496
# Returns         :
5497
#
5498
sub MakeProject
5499
{
5500
    my( $platforms, $proj, @elements ) = @_;
5501
 
5502
    Debug2( "MakeProject($platforms, $proj, @elements)" );
5503
 
5504
    return if ( ! ActivePlatform($platforms) );
5505
 
5506
    #
5507
    #   Sanity test
5508
    #
5509
    Error ("MakeProject: Project name not defined") unless ( $proj );
5510
 
5511
    #
5512
    #   Take the project name and convert it into a full path
4261 dpurdie 5513
    #   Need to create a uniq project name - allowing for multiple uses
227 dpurdie 5514
    #
5515
    my $project = MakeSrcResolve ( $proj );
4261 dpurdie 5516
    $proj = MakeProjectName($project);
5517
 
237 dpurdie 5518
    Error ("Project File Not found: $project") unless ( -f $project );
227 dpurdie 5519
 
5520
    my $basedir = StripFileExt( $project );
5521
 
5522
    #
5523
    #   Collect user arguments
5524
    #   They are all processed within the toolset
5525
    #
5526
    my @tool_options;
5411 dpurdie 5527
    my $unit_tests;
5528
    my $auto_tests;
227 dpurdie 5529
    foreach ( @elements )
5530
    {
5531
        if ( m/^--Debug/ ) {
5532
            $PROJECTS{$proj}{'Debug'} = 1;
5533
 
5534
        } elsif ( m/^--Prod/ ) {
5535
            $PROJECTS{$proj}{'Prod'} = 1;
5536
 
267 dpurdie 5537
        } elsif ( m/^--(Package|Install)ProgDebug=(.*)/ ) {
5538
            _PackageFromProject( $1, $proj, $basedir,'Prog', 'D', $2 );
227 dpurdie 5539
 
267 dpurdie 5540
        } elsif ( m/^--(Package|Install)Prog(Prod)*=(.*)/ ) {
5541
            _PackageFromProject( $1, $proj, $basedir, 'Prog', 'P', $3 );
227 dpurdie 5542
 
267 dpurdie 5543
        } elsif ( m/^--(Package)LibDebug=(.*)/ ) {
5544
            _PackageFromProject( $1, $proj, $basedir, 'Lib', 'D', $2 );
227 dpurdie 5545
 
267 dpurdie 5546
        } elsif ( m/^--(Package)Lib(Prod)*=(.*)/ ) {
5547
            _PackageFromProject( $1, $proj, $basedir, 'Lib', 'P', $3 );
227 dpurdie 5548
 
267 dpurdie 5549
        } elsif ( m/^--(Package)SharedLibDebug=(.*)/ ) {
5550
            _PackageFromProject( $1, $proj, $basedir, 'Lib', 'D', $2 );
227 dpurdie 5551
 
267 dpurdie 5552
        } elsif ( m/^--(Package)SharedLib(Prod)*=(.*)/ ) {
5553
            _PackageFromProject( $1, $proj, $basedir, 'Lib', 'P', $3 );
227 dpurdie 5554
 
267 dpurdie 5555
        } elsif ( m/^--(Package)Hdr=(.*)/ ) {
5556
            _PackageFromProject( $1, $proj, $basedir, 'Hdr', undef, $2 );
227 dpurdie 5557
 
267 dpurdie 5558
        } elsif ( m/^--(Package)File=(.*)/ ) {
5559
            _PackageFromProject( $1, $proj, $basedir, 'File', undef, $2 );
227 dpurdie 5560
 
267 dpurdie 5561
        } elsif ( m/^--(Package)Tool(Prod)*=(.*)/ ) {
5562
            _PackageFromProject( $1, $proj, $basedir, 'Tool', 'P', $3 );
241 dpurdie 5563
 
267 dpurdie 5564
        } elsif ( m/^--(Package)ToolDebug=(.*)/ ) {
5565
            _PackageFromProject( $1, $proj, $basedir, 'Tool', 'D', $2 );
241 dpurdie 5566
 
267 dpurdie 5567
        } elsif ( m/^--(Package|Install)/ ) {
5568
            Error("MakeProject. Unknown $1 option: $_");
227 dpurdie 5569
 
5411 dpurdie 5570
        } elsif ( m/^--UnitTest/ ) {
5571
            $unit_tests = 1;
5572
 
5573
        } elsif ( m/^--AutoTest/ ) {
5574
            $auto_tests = 1;
5575
 
227 dpurdie 5576
        } else {
5577
            push @tool_options, $_;
5578
        }
5579
    }
5580
 
5581
    #
6353 dpurdie 5582
    #   Validate some of the arguments
5583
    #   Ensure has not specified both --Prod and --Debug
5584
    #
5585
    Error ("Makeproject. Conflicting options --Debug and --Prod" )
5586
        if ( $PROJECTS{$proj}{'Debug'}  && $PROJECTS{$proj}{'Prod'} );
5587
 
5588
    #   Ensure that global --OnlyProd/Debug don't prevent builds
5589
    $PROJECTS{$proj}{'Debug'} = 1 if ($ScmBuildType eq 'D');
5590
    $PROJECTS{$proj}{'Prod'} = 1 if ($ScmBuildType eq 'P');
5591
    Error ("Makeproject. Global and Local options --Debug and --Prod prevent project being built" )
5592
        if ( $PROJECTS{$proj}{'Debug'}  && $PROJECTS{$proj}{'Prod'} );
5593
 
5594
    #
227 dpurdie 5595
    #   Save the information
5596
    #
5597
    $PROJECTS{$proj}{'options'} = \@tool_options;
5598
    $PROJECTS{$proj}{'name'} = $proj;
5599
    $PROJECTS{$proj}{'project'} = $project;
5600
    $PROJECTS{$proj}{'basedir'} = $basedir;
5411 dpurdie 5601
    $PROJECTS{$proj}{'unittest'} = $unit_tests if ( $unit_tests );
5602
    $PROJECTS{$proj}{'autotest'} = $auto_tests if ( $auto_tests );
227 dpurdie 5603
    UniquePush (\@PROJECTS_ORDER, $proj);
5604
 
5605
}
5606
 
5607
#-------------------------------------------------------------------------------
5608
# Function        : _PackageFromProject
5609
#
5610
# Description     : Save Packaged data from the project
5611
#
267 dpurdie 5612
# Inputs          : $tgt        - Install or Package
5613
#                   $proj       - Name of the project
227 dpurdie 5614
#                   $base       - Base directory of files
5615
#                   $etype      - Type of Package (Progs, Libs, ... )
5616
#                   $type       - Debug or Production or both
5617
#                   $items      - Item to add. It may be comma seperated
5618
#
267 dpurdie 5619
my %PackageToData = ( 'Package' =>
5620
                        { 'Hdr'   => \%PACKAGE_HDRS,
5621
                          'Lib'   => \%PACKAGE_LIBS,
5622
                          'Prog'  => \%PACKAGE_PROGS,
5623
                          'File'  => \%PACKAGE_FILES,
5624
                          'Tool'  => \%PACKAGE_FILES,
5625
                          '_BASE' => 'PBase',
5626
                        },
5627
                      'Install' =>
5628
                        { 'Hdr'   => \%INSTALL_HDRS,
5629
                          'Lib'   => \%INSTALL_LIBS,
5630
                          'Prog'  => \%INSTALL_PROGS,
5631
                          'File'  => undef,
5632
                          'Tool'  => undef,
5633
                          '_BASE' => 'IBase',
5634
                        },
227 dpurdie 5635
                    );
5636
 
5637
sub _PackageFromProject
5638
{
267 dpurdie 5639
    my( $tgt, $proj, $base, $etype, $type, $items ) = @_;
227 dpurdie 5640
    my $subdir = '';
5641
 
5642
    #
267 dpurdie 5643
    #   Sanity test
5644
    #
5645
    $type = '' unless ( $type );
5646
    Error ("INTERNAL. Bad packaging option: $tgt")   unless ( exists $PackageToData{$tgt} );
5647
    Error ("INTERNAL. Bad packaging option: $etype") unless ( exists $PackageToData{$tgt}{$etype} );
5648
    Error ("Unsupported packaging combination: $tgt$etype$type=$items") unless ( defined $PackageToData{$tgt}{$etype} );
5649
 
5650
    #
5651
    #   Determine the index into the 'PackageInfo' structure
5652
    #   This provides the symbolic name for the target package path
5653
    #   for Package or Install
5654
    #
5655
    #   The key '_BASE' is internal. Used only to provide this information
5656
    #
5657
    my $tbase = $PackageToData{$tgt}{'_BASE'};
5658
 
5659
    #
227 dpurdie 5660
    #   Process options
5661
    #
5662
    foreach my $item ( split (/,/, $items ) )
5663
    {
5664
        next unless ( $item =~ m/^--/ );
5665
        if ( $item =~ m/^--Subdir=(.*)/ )
5666
        {
5667
            $subdir = '/' . $1;
5668
            $subdir =~ s~//~/~g;
5669
            $subdir =~ s~/$~~g;
5670
        }
5671
        else
5672
        {
5673
            Warning( "MakeProject: Unknown packaging option ignored: $_" );
5674
        }
5675
    }
5676
 
5677
    #
5678
    #   Process files
5679
    #
5680
    foreach my $item ( split (/,/, $items ) )
5681
    {
5682
        next if ( $item =~ m/^--/ );
5683
 
267 dpurdie 5684
        my $tdir = $PackageInfo{$etype}{$tbase} . $PackageInfo{$etype}{'Dir'} . $subdir ;
227 dpurdie 5685
        my $fname = StripDir( $item );
5686
        my $target = $tdir . '/' . $fname;
5687
 
5688
        $item = "$base/$item" if ( $base );
5689
 
5690
        #
5691
        #   Do not use $(GBE_TYPE) in the target name
5692
        #   The existing package mechanism does not handle different
5693
        #   production and debug file naming mechanism, whereas the project
5694
        #   must. Convert $(GBE_TYPE) into P or D to ensure uniquness
5695
        #
5696
        $target =~ s~\$\(GBE_TYPE\)~$type~ if ($type);
5697
 
5698
        #
5699
        #   Create a PACKAGE entry suitable for processing by the normal packaging
5700
        #   routines. This is complicated because the Projects do not adhere to
267 dpurdie 5701
        #   the JATS file name conventions
227 dpurdie 5702
        #
5703
        my %package_entry;
5704
        $package_entry{'src'}   = $item;
5705
        $package_entry{'dir'}   = $tdir;
267 dpurdie 5706
        $package_entry{'set'}   = 'ALL' if ($tgt eq 'Package');
227 dpurdie 5707
        $package_entry{'type'}  = $type if ($type);
5708
 
267 dpurdie 5709
        $PackageToData{$tgt}{$etype}->{$target} = {%package_entry};
227 dpurdie 5710
    }
5711
}
5712
 
5713
#-------------------------------------------------------------------------------
5714
# Function        : MakeAnt
5715
#
5716
# Description     : A nasty directive to create JAR files via ANT
5717
#                   There are several limitations
5718
#                   This is closely related to the MakeProject directive
5719
#
5720
#
5721
# Inputs          : Platform            - Active platform
5722
#                   buildfile           - Name of the build.xml file
5723
#                   Options             - A few options
5724
#                                         --Jar=file
5725
#                                               Generated JAR file(s)
5726
#                                         --GeneratedFile=file
5727
#                                               Other generated files
5728
#                                               Used to flag JNI that must
5729
#                                               Occur early
5730
#                                          --AutoTest=<name>
5731
#                                               Supports unitAutomated unit test
5732
#                                               by calling build target <name>
5733
#                                          --UnitTest=<name>
5734
#                                               Supports unit test
5735
#                                               by calling build target <name>
5736
#                                          --PackageBase
5737
#                                               Provides path to base of all packages
6294 dpurdie 5738
#                                          --AllPackages
5739
#                                               Provide paths to both LinkPkgArchive and BuildPkgArchive
227 dpurdie 5740
#
5741
# Returns         :
5742
#
5743
our %JAR_FILES;
5744
sub MakeAnt
5745
{
5746
    my( $platforms, $proj, @elements ) = @_;
5747
 
5748
    Debug2( "MakeAnt($platforms, $proj, @elements)" );
5749
 
5750
    return if ( ! ActivePlatform($platforms) );
5751
 
5752
    #
5753
    #   Sanity test
5754
    #
5755
    Error ("MakeAnt: build.xml name not defined") unless ( $proj );
5756
 
5757
    #
5758
    #   Take the project name and convert it into a full path
5759
    #
5760
    my $project;
5761
    $project = MakeSrcResolve ( $proj );
4261 dpurdie 5762
    $proj = MakeProjectName($project);
237 dpurdie 5763
    Error ("Build File Not found: $project") unless ( -f $project );
227 dpurdie 5764
 
5765
    my $basedir = StripFileExt( $project );
5766
 
5767
    #
5768
    #   Collect user arguments
5769
    #   They are all processed within the toolset
5770
    #
5771
    my @tool_options;
5772
    my @generated;
5773
    my $unit_tests;
5774
    my $auto_tests;
5775
    my $package_base;
6294 dpurdie 5776
    my $allPackages;
227 dpurdie 5777
 
5778
    foreach ( @elements )
5779
    {
5780
        if ( m/^--Debug/ ) {
5781
            $PROJECTS{$proj}{'Debug'} = 1;
5782
 
5783
        } elsif ( m/^--Prod/ ) {
5784
            $PROJECTS{$proj}{'Prod'} = 1;
5785
 
5786
        } elsif ( m/^--Jar=(.*)/ ) {
5787
            my $tgt = $1;
5788
               $tgt = "$basedir/$tgt" if ( $basedir );
5789
            my $fn = StripDir( $1 );
5790
            $JAR_FILES{$fn} = $tgt;
5791
            GenerateSrcFile( 0, $tgt );
5792
 
5793
        } elsif ( m/^--GeneratedFile=(.*)/ ) {
5794
            my $tgt = $1;
5795
            $tgt = "$basedir/$tgt" if ( $basedir );
5796
            push @generated, $tgt;
5797
            GenerateSrcFile( 2, $tgt );
5798
 
5799
        } elsif ( m/^--UnitTest=(.*)/ ) {
5800
            $unit_tests = $1
5801
 
5802
        } elsif ( m/^--AutoTest=(.*)/ ) {
5803
            $auto_tests = $1
5804
 
5805
        } elsif ( m/^--PackageBase/ ) {
5806
            $package_base = 1;
5807
 
6294 dpurdie 5808
        } elsif ( m/^--AllPackages/i ) {
5809
            $allPackages = 1;
227 dpurdie 5810
 
5811
        } elsif ( m/^--/ ) {
5812
            Error("MakeAnt. Unknown option ignored: $_");
5813
 
5814
        } else {
5815
            push @tool_options, $_;
5816
        }
5817
    }
5818
 
5819
    #
5820
    #   Extend option arguments to include the base dir of packages
5821
    #   Create definitions of the form PACKAGE_<name>
5822
    #
6294 dpurdie 5823
    for my $entry (getPackageList())
227 dpurdie 5824
    {
6294 dpurdie 5825
        my $pkgType = $entry->getType();
5826
        next if $pkgType eq 'interface'  ;
5827
        next unless ( ( $pkgType eq 'link') || $allPackages);
5828
        my $dir = $entry->getBase(2);
5829
        my $name = $entry->getName();
227 dpurdie 5830
        unless ( $package_base )
5831
        {
5832
            $dir .= '/jar';
5833
            next unless ( -d $dir );
5834
        }
6294 dpurdie 5835
        push @tool_options, "-DPACKAGE_$name=\$(call myabspath,$dir)";
227 dpurdie 5836
    }
5837
    #
5838
    #   Extend options to include the base dir of the created package
5839
    #   Allows careful use for direct packaging of artifacts
5840
    #
6294 dpurdie 5841
    push @tool_options, '-DPACKAGEDIR=$(call myabspath,$(PKGDIR))';
227 dpurdie 5842
 
5843
    #
5844
    #   Save the information
5845
    #
5846
    $PROJECTS{$proj}{'options'} = \@tool_options;
5847
    $PROJECTS{$proj}{'generated'} = \@generated if ( @generated );
5848
    $PROJECTS{$proj}{'name'}    = $proj;
5849
    $PROJECTS{$proj}{'project'} = $project;
5850
    $PROJECTS{$proj}{'basedir'} = $basedir;
5851
    $PROJECTS{$proj}{'type'}    = 'ant';
5852
    $PROJECTS{$proj}{'unittest'} = $unit_tests if ( $unit_tests );
5853
    $PROJECTS{$proj}{'autotest'} = $auto_tests if ( $auto_tests );
5854
    UniquePush (\@PROJECTS_ORDER, $proj);
5855
 
5856
    $TESTS_TO_AUTORUN = 1 if ( $auto_tests );
4501 dpurdie 5857
    $TESTS_TO_RUN     = 1 if ( $unit_tests || $auto_tests );
227 dpurdie 5858
 
5859
    #
5860
    #   Validate some of the arguments
5861
    #
5862
    Error ("MakeAnt. Conflicting options --Debug and --Prod" )
5863
        if ( $PROJECTS{$proj}{'Debug'}  && $PROJECTS{$proj}{'Prod'} );
5864
}
5865
 
5866
###############################################################################
5867
#
5868
#   Installation/Packaging util functions
5869
#
5870
#-------------------------------------------------------------------------------
5871
# Function        : __TargetDir
5872
#
5873
# Description     : Internal function to process common arguments for
5874
#                   the PackageXxx directives
5875
#
5876
# Inputs          : flags           - Indicate how to handle this argument
5877
#                   base            - Base directory for this type of package
5878
#                   argument        - Argument to process
5879
#                   pdir            - Reference to resultant directory
5880
#                   ptype           - Reference to resultant type (P or D)(optional)
5881
#
5882
# Returns         : 0               - Agument not consumed
5883
#                   1               - Argument consumed
5884
#                   2               - Skip this directive
5885
#
5886
my $T_TYPE  = 0x0001;                           # Postfix GBE_TYPE
5887
my $T_PKG   = 0x0002;                           # Special --Dir handling
5888
my $T_MACH  = 0x0004;                           # Allow --Machine too
5889
my $T_GBE   = 0x0008;                           # Allow --Gbe too
5890
my $T_FILE  = 0x0010;                           # Suffix or prefix subdir
5891
 
5892
sub __TargetDir
5893
{
5894
    my( $flags, $base, $argument, $pdir, $ptype ) = @_;
5895
    my $dir  = "";
5896
    my $consumed = 0;
5897
 
5898
    #
5899
    #   Generate basic parts
5900
    #   Note Product will default to Platform
5901
    #
5902
    my $str_platform = '$(GBE_PLATFORM)';
5903
    my $str_product = $ScmProduct ? '$(GBE_PRODUCT)' : '$(GBE_PLATFORM)';
5904
    my $str_target = '$(GBE_TARGET)';
5905
    my $str_common = '$(GBE_OS_COMMON)';
5906
 
5907
    my $str_common_avail = 0;
5908
       $str_common_avail = 1 if ( exists( $::BUILDINFO{$ScmPlatform}{OS_COMMON} ));
5909
 
5910
 
5911
    #
5912
    #   Add requested suffix
5913
    #
5914
    if ($flags & $T_TYPE)
5915
    {
5916
        $str_platform .= '$(GBE_TYPE)';
5917
        $str_product  .= '$(GBE_TYPE)';
5918
        $str_target   .= '$(GBE_TYPE)';
5919
        $str_common   .= '$(GBE_TYPE)';
5920
    }
5921
 
5922
    #
5923
    #   Process the argument
5924
    #
5925
    $_ = $argument;
5926
    if ( /^--Debug/ ) {                         # In the Debug build only
5927
        if ( $ptype ) {
5928
            $$ptype = "D";
5929
            $consumed = 1;
5930
        }
5931
 
5932
    } elsif ( /^--Prod$/ || /^--Production$/ ) { # In the Production build only
5933
        if ( $ptype ) {
5934
            $$ptype = "P";
5935
            $consumed = 1;
5936
        }
5937
 
5938
    } elsif (/^--Prefix=(.*)/) {                # Prefix with subdir
5939
        $dir = "$base/$1";
5940
 
5941
    } elsif (/^--Subdir=(.*)/) {                # same as 'prefix'
5942
        $dir = "$base/$1";
5943
 
5944
    } elsif (/^--Platform$/) {                  # Platform installation
5945
        $dir = "$base/$str_platform";
5946
 
5947
    } elsif (/^--Platform=(.*?),(.*)/) {        # prefix and suffix with platform specific subdir
5948
        $dir = "$base/$1/$str_platform/$2";
5949
 
5950
    } elsif (/^--Platform=(.*)/) {              # prefix with platform specific subdir
5951
        if ($flags & $T_FILE) {
5952
            $dir = "$base/$1/$str_platform";
5953
        } else {
5954
            $dir = "$base/$str_platform/$1";
5955
        }
5956
 
5957
    } elsif (/^--Product$/) {                   # Product installation
5958
        $dir = "$base/$str_product";
5959
 
5960
    } elsif (/^--Product=(.*?),(.*)/) {         # prefix and suffix with product specific subdir
5961
        $dir = "$base/$1/$str_product/$2";
5962
 
5963
    } elsif (/^--Product=(.*)/) {               # prefix with product specific subdir
5964
        if ($flags & $T_FILE) {
5965
            $dir = "$base/$1/$str_product";
5966
        } else {
5967
            $dir = "$base/$str_product/$1";
5968
        }
5969
 
5970
    } elsif (/^--Target$/) {                    # Target installation
5971
        $dir = "$base/$str_target";
5972
 
5973
    } elsif (/^--Target=(.*?),(.*)/) {          # prefix and suffix with target specific subdir
5974
        $dir = "$base/$1/$str_target/$2";
5975
 
5976
    } elsif (/^--Target=(.*)/) {                # prefix with target specific subdir
5977
        if ($flags & $T_FILE) {
5978
            $dir = "$base/$1/$str_target";
5979
        } else {
5980
            $dir = "$base/$str_target/$1";
5981
        }
5982
 
5983
    } elsif (/^--OsCommon/) {
5984
 
5985
        unless ( $str_common_avail ) {
5986
            Warning("Packaging option --OsCommon not supported on this platform($ScmPlatform). Directive skipped");
5987
            $consumed = 2;
5988
 
5989
        } elsif (/^--OsCommon$/) {                  # OS installation
5990
            $dir = "$base/$str_common";
5991
 
5992
        } elsif (/^--OsCommon=(.*?),(.*)/) {        # prefix and suffix with target specific subdir
5993
            $dir = "$base/$1/$str_common/$2";
5994
 
5995
        } elsif (/^--OsCommon=(.*)/) {              # prefix with target specific subdir
5996
            if ($flags & $T_FILE) {
5997
                $dir = "$base/$1/$str_common";
5998
            } else {
5999
                $dir = "$base/$str_common/$1";
6000
            }
6001
        }
6002
 
6003
    } elsif (/^--Derived=(.*?),(.*?),(.*)/) {   # Derived target + prefix + subdir
6004
        $dir = "$base/$2/$1_$str_platform/$3";
6005
 
6006
    } elsif (/^--Derived=(.*?),(.*)/) {         # Derived target + subdir
6007
        if ($flags & $T_FILE) {
6008
            $dir = "$base/$2/$1_$str_platform";
6009
        } else {
6010
            $dir = "$base/$1_$str_platform/$2";
6011
        }
6012
 
6013
    } elsif (/^--Derived=(.*)/) {               # Derived target
6014
        $dir = "$base/$1_$str_platform";
6015
 
6016
    } elsif ($flags & $T_MACH && /^--Machine(([=])(.*))?$/) {   # Allow Machine and Machine=xxx specfic target
6017
        #
6018
        #   Special: Append machine type to user dir
6019
        #            Intended to create tools/bin/win32 and tools/bin/sparc directories
6020
        my $path = ( defined( $3) ) ? "/$3" : "";
6021
        $dir = "$base$path/\$(GBE_HOSTMACH)";
6022
 
6023
    } elsif ($flags & $T_GBE && /^--Gbe(([=])(.*))?$/) {   # Allow Gbe and Gbe=xxx specfic target
6024
        my $path = ( defined( $3) ) ? "/$3" : "";
6025
        $dir = "$base/gbe$path";
6026
 
6027
    } elsif (/^--Dir=(.*)/) {                   # prefix with target specific subdir
6028
        Error ('Packaging directive with --Dir option does not specify a directory.',
6029
               'Possible bad use of option of the form:--Dir=$xxx',
6030
               'Note: Use of package.pl and this construct is deprecated') unless ( $1 );
241 dpurdie 6031
        my $udir = $1;
6032
 
6033
        #
6034
        #   Remove leading ./
6035
        #   Check for leading ../
5568 dpurdie 6036
        #   
6037
        #   Remove any stupid path manipulation elements
6038
        #   
5827 dpurdie 6039
        if ($udir =~ s~^([./]*/)~~)
6040
        {
6041
            Warning("Packaging directive with --Dir option contains path manipulation elements (removed)", "Option: $_");
6042
        }
241 dpurdie 6043
 
227 dpurdie 6044
        if ($flags & $T_PKG) {
241 dpurdie 6045
            $dir = __PkgDir( $udir );
227 dpurdie 6046
        } else {
6387 dpurdie 6047
            $dir = $base . "/" . $udir;
227 dpurdie 6048
        }
6049
    }
6050
 
6051
    return ($consumed) if ($dir eq "");
6052
    $dir =~ s~//~/~g;
6053
    $dir =~ s~/$~~;
6054
    $$pdir = $dir;
6055
    return (1);
6056
}
6057
 
6058
 
6059
#   __PkgDir ---
6060
#       Convert --Dir Package directives, removing leading subdir if
6061
#       matching the global $Pbase value.
6062
#
6063
#       Required as PKGDIR has the value 'GBE_ROOT/pkg/$Pbase'.
6064
#       Required to maintain compatability with older (package.pl) constructs
6065
#..
6066
 
6067
sub __PkgDir
6068
{
6069
    my( $dir ) = @_;
6070
    my $org = $dir;
6071
 
245 dpurdie 6072
    $dir =~ s~^\Q$::Pbase\E[/]?~~;
227 dpurdie 6073
    Debug2( "  PkgDir: converted \"$org\" to \"$dir\"" );
6074
 
6075
    $dir = "\$(PKGDIR)/$dir";
6076
    return $dir;
6077
}
6078
 
6079
 
6080
#   getMajorMinor ---
6081
#       Just a little help to deal with major/minor stuff for shared libs -
6082
#       given the name of the library as the argument, split out major and
6083
#       minor parts and return the basename, i.e name without major and minor
6084
#       and the pair of major and minor.
6085
#..
6086
 
285 dpurdie 6087
sub getMajorMinor
227 dpurdie 6088
{
6089
    my @bits = split ('\.', $_[0]);
6090
    my $stop;
6091
    my $major;
6092
    my $minor;
6093
 
6094
    if ( $#bits > 2 )
6095
    {
6096
        $stop = $#bits - 2;
6097
        $major = $bits[$#bits-1];
6098
        $minor = $bits[$#bits];
6099
    }
6100
    elsif ($#bits > 1)
6101
    {
6102
        $stop = $#bits-1;
6103
        $major = $bits[$#bits];
6104
        $minor=0;
6105
    }
6106
    else
6107
    {
6108
        $stop = $#bits; $major = 1; $minor = 0;
6109
    }
6110
 
6111
    my $base = $bits[0];
6112
    for ( my $i=1; $i <= $stop; $i++ ) {
6113
        $base = join ('.', $base, $bits[$i]);
6114
    }
6115
 
6116
    return ($base, $major, $minor);
6117
}
6118
 
6119
###############################################################################
6120
#
6121
#   Installation
6122
#
6123
 
6124
sub InstallHdr
6125
{
6126
    my( $platforms, @elements ) = @_;
335 dpurdie 6127
    my( $base, $dir, $srcfile, $full, $strip, $package );
227 dpurdie 6128
    my( $len, $name, $basename );
6129
 
6130
    Debug2( "InstallHdr($platforms, @elements)" );
6131
 
6132
    return if ( ! ActivePlatform($platforms) );
6133
    Warning ("InstallHdr: Needs local directory specified in build.pl") unless ( $::ScmLocal );
6134
 
6135
#.. Arguments
6136
#
6137
    $base = $PackageInfo{'Hdr'}{'IBase'};       # Base of target
6138
    $dir = $base . $PackageInfo{'Hdr'}{'Dir'};  # Installation path (default)
335 dpurdie 6139
    $full = $strip = 0;
227 dpurdie 6140
 
285 dpurdie 6141
    foreach ( @elements )
227 dpurdie 6142
    {
6143
                                                # Standard targets
6144
        my $rv = __TargetDir(0, $base, $_, \$dir);
6145
        next if ( $rv == 1 );
6146
        return if ( $rv == 2 );
6147
 
6148
        if (/^--Full/) {                        # using full (resolved) path
6149
            $full = 1;
6150
 
6151
        } elsif (/^--Strip$/) {                 # Strip path from source files
6276 dpurdie 6152
            $strip = -1;
227 dpurdie 6153
 
6276 dpurdie 6154
        } elsif (/^--Strip=(\d+)$/) {           # Strip some f the path from source files
6155
            $strip = $1;
227 dpurdie 6156
                                                # Package
6157
        } elsif (/^--Package$/ || /^--Package=(.*)/) {
6158
            $package = 1;
6159
 
6160
        } elsif (/^--(.*)/) {
6161
            Message( "InstallHdr: unknown option $_ -- ignored\n" );
6162
        }
6163
    }
6164
 
6165
#.. Files
6166
#
285 dpurdie 6167
    foreach ( @elements )
227 dpurdie 6168
    {
6169
        my %package_entry;
6170
        if ( ! /^--(.*)/ )
6171
        {
6172
            $name = $_;
6173
            $basename = StripDir( $name );
335 dpurdie 6174
            if ( !($srcfile = $SRCS{ $basename }) ) {
6175
                $srcfile = $name;
6176
            }
6177
 
227 dpurdie 6178
            if ( $full )
6179
            {
335 dpurdie 6180
                my $subdir = StripFileExt($srcfile);
6181
                $subdir = $1
6182
                    if ( $subdir =~ m~^$ProjectBase/(.*)~ );
6183
                $dir .= '/' . $subdir;
6184
                $dir =~ s~//~/~g;
6185
                $dir =~ s~/./~/~g;
6186
                $dir =~ s~/$~~g;
6187
                $name = $basename;
227 dpurdie 6188
            }
6189
 
6276 dpurdie 6190
            $name = StripPath($name, $strip) if ($strip);
227 dpurdie 6191
 
6192
            Debug( "InstallHdr( $dir/$name, src: $srcfile, dest: $dir)" );
6193
 
6194
            $package_entry{'src'} = $srcfile;
6195
            $package_entry{'dir'} = StripFileExt( "$dir/$name" );
6196
            $INSTALL_HDRS{ "$dir/$name" } = {%package_entry};
6197
        }
6198
    }
6199
 
6200
#.. Package
6201
#
6202
    PackageHdr( @_ )                            # auto package
6203
        if ( $package );
6204
}
6205
 
6206
 
6207
sub InstallLib
6208
{
6209
    my( $platforms, @elements ) = @_;
6210
    my( $base, $dir, $package );
6211
    my( $lib, $strip );
289 dpurdie 6212
    my $org_lib;
227 dpurdie 6213
 
6214
    Debug2( "InstallLib($platforms, @elements)" );
6215
 
6216
    return if ( ! ActivePlatform($platforms) );
6217
    Warning ("InstallLib: Needs local directory specified in build.pl") unless ( $::ScmLocal );
6218
 
6219
#.. Arguments
6220
#
6221
    $base = $PackageInfo{'Lib'}{'IBase'};       # Base of target
6222
    $dir = $base . $PackageInfo{'Lib'}{'Dir'};  # Installation path (default)
6223
 
285 dpurdie 6224
    foreach ( @elements )
227 dpurdie 6225
    {
6226
                                                # Standard targets
6227
        my $rv = __TargetDir(0, $base, $_, \$dir);
6228
        next if ( $rv == 1 );
6229
        return if ( $rv == 2 );
6230
 
6231
        if (/^--Package$/ || /^--Package=(.*)/) {
6232
            $package = 1;
6233
 
6234
        } elsif (/^--Strip$/) {                 # Strip path from source files
6276 dpurdie 6235
            $strip = -1;
227 dpurdie 6236
 
6276 dpurdie 6237
        } elsif (/^--Strip=(\d+)$/) {           # Strip some f the path from source files
6238
            $strip = $1;
6239
 
227 dpurdie 6240
        } elsif (/^--(.*)/) {
6241
            Message( "InstallLib: unknown option $_ -- ignored\n" );
6242
        }
6243
    }
6244
 
6245
#.. Files
6246
#
285 dpurdie 6247
    foreach ( @elements )
227 dpurdie 6248
    {
6249
        my %package_entry;
6250
        if ( ! /^--(.*)/ )
6251
        {
6276 dpurdie 6252
            $_ = StripPath($_, $strip) if ($strip);
289 dpurdie 6253
            $org_lib = $_;                      # Original name
227 dpurdie 6254
 
6255
            if ( $ScmTargetHost eq "Unix" ) {
6256
                $lib = "lib$_";                 # Prefix "lib" ....
6257
                $lib =~ s/^liblib/lib/;         # @LIBS already has lib added
6258
            } else {
6259
                $lib = $_;
6260
            }
6261
 
289 dpurdie 6262
            if (  my $libp = $SHLIBS->Get($lib) )
227 dpurdie 6263
            {
6264
                Debug( "InstallLib( $dir/$lib\$(GBE_TYPE).$::so, " .
6265
                    "src: \$(LIBDIR)/$lib\$(GBE_TYPE).$::so, dest: $dir)" );
6266
 
6267
                #
6268
                #   Create a "placekeeper" entry within $INSTALL_SHLIBS
6269
                #   The exact format of the name of the shared library is
6270
                #   toolset specific. Create an entry to allow the toolset
6271
                #   to extend the packaging information when the shared library
6272
                #   recipe is constructed.
6273
                #
289 dpurdie 6274
                my $ver = $libp->{ VERSION };
227 dpurdie 6275
                my $name = "$dir/$lib.$ver.PlaceKeeper";
6276
 
6277
                $package_entry{'placekeeper'} = 1;
6278
                $package_entry{'version'} = $ver;
6279
                $package_entry{'lib'} = $lib;
6280
                $package_entry{'dir'} = $dir;
289 dpurdie 6281
 
6282
                push @{$SHLIB_INS{$lib}}, $name;
227 dpurdie 6283
                $INSTALL_SHLIBS{$name} = {%package_entry};
6284
            }
6285
 
289 dpurdie 6286
            #
6287
            #   Clean up the package_entry
6288
            #   Insert common items
6289
            #
6290
            %package_entry = ();
6291
            $package_entry{'lib'} = $lib;
6292
            $package_entry{'dir'} = $dir;
6293
 
321 dpurdie 6294
            if ( my $libfile = $SRCS{$org_lib} )
227 dpurdie 6295
            {
6296
                #
6297
                #   Allow the user to package a sourced file as a library
289 dpurdie 6298
                #   But must be the un-massaged name of the file.
227 dpurdie 6299
                #
289 dpurdie 6300
                $package_entry{'dst'} = "$dir/$org_lib";
6301
                $package_entry{'src'} = $libfile;
6302
            }
6303
            elsif ( $LIBS->Get($lib) )
6304
            {
6305
                #
6306
                #   Install a library known to the makefile
6307
                #
6308
                my $libp = $LIBS->Get($lib);
227 dpurdie 6309
 
289 dpurdie 6310
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
6311
                $package_entry{'src'}    = $libp->getPath();
227 dpurdie 6312
            }
289 dpurdie 6313
            elsif ( ! $SHLIBS->Get($lib) )
227 dpurdie 6314
            {
289 dpurdie 6315
                #
6316
                #   Not a known shared lib
6317
                #   Not a known static lib
6318
                #   Not a 'sourced' file
6319
                #   Assume the a static library has magically appeared
6320
                #   in the standard LIB directory. May have been placed there
6321
                #   by a 'rule'
6322
                #
6323
                my $libp = $LIBS->New($lib);
227 dpurdie 6324
 
289 dpurdie 6325
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
6326
                $package_entry{'src'}    = $libp->getPath();
6327
            }
227 dpurdie 6328
 
289 dpurdie 6329
            #
6330
            #   Add entry to various lists if required
6331
            #
6332
            PackageLib_AddEntry ('InstallLib', \%LIB_INS, \%INSTALL_LIBS, \%package_entry )
6333
                if ( exists $package_entry{'dst'} );
227 dpurdie 6334
        }
6335
    }
6336
 
6337
#.. Package
6338
#
6339
    PackageLib( @_ )                            # auto package
6340
        if ( $package );
6341
}
6342
 
6343
 
6344
sub InstallJar
6345
{
6346
    my( $platforms, @elements ) = @_;
6347
    my( $base, $dir, $package );
6348
    my( $jar );
6349
 
6350
    Debug2( "InstallJar($platforms, @elements)" );
6351
 
6352
    return if ( ! ActivePlatform($platforms) );
6353
    Warning ("InstallJar: Needs local directory specified in build.pl") unless ( $::ScmLocal );
6354
 
6355
#.. Arguments
6356
#
6357
    $base = $PackageInfo{'Jar'}{'IBase'};       # Base of target
6358
    $dir = $base . $PackageInfo{'Jar'}{'Dir'};  # Installation path (default)
6359
 
285 dpurdie 6360
    foreach ( @elements )
227 dpurdie 6361
    {
6362
                                                # Standard targets
6363
        my $rv = __TargetDir(0, $base, $_, \$dir);
6364
        next if ( $rv == 1 );
6365
        return if ( $rv == 2 );
6366
 
6367
        if (/^--Package$/ || /^--Package=(.*)/) {
6368
            $package = 1;
6369
 
6370
        } elsif (/^--(.*)/) {
6371
            Message( "InstallJar: unknown option $_ -- ignored\n" );
6372
        }
6373
    }
6374
 
6375
 
6376
#.. Files
6377
#
285 dpurdie 6378
    foreach ( @elements )
227 dpurdie 6379
    {
6380
        my %package_entry;
6381
        if ( ! /^--(.*)/ )
6382
        {
6383
            $jar = $_;
6384
            my $src;
6385
            my $dest;
6386
 
6387
            if ( $JAR_FILES{$jar} )
6388
            {
6389
                $src = $JAR_FILES{$jar};
6390
                $dest = $jar;
6391
            }
6392
            else
6393
            {
6394
                $src = "\$(CLSDIR)/$jar\$(GBE_TYPE).jar";
6395
                $dest = "$jar\$(GBE_TYPE).jar";
6396
            }
6397
 
6398
 
6399
            Debug( "InstallJar( $dir/$dest, " .
6400
                "src: $src, dest: $dir)" );
6401
 
6402
            $package_entry{'src'} = $src;
6403
            $package_entry{'dir'} = $dir;
6404
            $INSTALL_CLSS{ "$dir/$dest" } = {%package_entry};
6405
 
6406
        }
6407
    }
6408
 
6409
#.. Package
6410
#
6411
    PackageJar( @_ )                            # auto package
6412
        if ( $package );
6413
}
6414
 
6415
 
6416
sub InstallProg
6417
{
6418
    my( $platforms, @elements ) = @_;
6419
    my( $base, $dir, $package );
6420
    my( $prog );
6421
 
6422
    Debug2( "InstallProg($platforms, @elements)" );
6423
 
6424
    return if ( ! ActivePlatform($platforms) );
6425
    Warning ("InstallProg: Needs local directory specified in build.pl") unless ( $::ScmLocal );
6426
 
6427
#.. Arguments
6428
#
6429
    $base = $PackageInfo{'Prog'}{'IBase'};       # Base of target
6430
    $dir = $base . $PackageInfo{'Prog'}{'Dir'};  # Installation path (default)
6431
 
285 dpurdie 6432
    foreach ( @elements )
227 dpurdie 6433
    {
6434
                                                # Standard targets
6435
        my $rv = __TargetDir($T_TYPE, $base, $_, \$dir);
6436
        next if ( $rv == 1 );
6437
        return if ( $rv == 2 );
6438
 
6439
        if (/^--Package$/ || /^--Package=(.*)/) {
6440
            $package = 1;
6441
 
6442
        } elsif (/^--(.*)/) {
6443
            Message( "InstallProg: unknown option $_ -- ignored\n" );
6444
        }
6445
    }
6446
 
6447
#.. Files
6448
#
285 dpurdie 6449
    foreach ( @elements )
227 dpurdie 6450
    {
6451
        my %package_entry;
6452
        if ( ! /^--(.*)/ )
6453
        {
6454
            my $ext = "";
6455
            $prog = $_;
6456
 
6457
            #
6458
            #   If the named target is a program then append the correct
6459
            #   extension. Otherwise assume that the target is either a script
6460
            #   or a some other file - and don't append an extension
6461
            #
6462
            $ext = $::exe
289 dpurdie 6463
                if ( $PROGS->Get($prog) );
227 dpurdie 6464
 
6465
            #
6466
            #   A "file" that is specified with a "Src" directive may be
6467
            #   installed as though it were a program
6468
            #
6469
            my $progfile;
6470
            $progfile = "\$(BINDIR)/$prog$ext"
6471
                unless ( $progfile = $SRCS{$prog} );
6472
 
6473
            Debug( "InstallProg( $dir/$prog$ext, " .
6474
                 "src: $progfile, dest: $dir)" );
6475
 
6476
            push @{$PROG_INS{$prog}}, "$dir/$prog$ext";
6477
 
6478
            $package_entry{'src'} = $progfile;
6479
            $package_entry{'dir'} = $dir;
6480
            $INSTALL_PROGS{ "$dir/$prog$ext" } = {%package_entry};
6481
        }
6482
    }
6483
 
6484
#.. Package
6485
#
6486
    PackageProg( @_ )                           # auto package
6487
        if ( $package );
6488
}
6489
 
6276 dpurdie 6490
#-------------------------------------------------------------------------------
6491
# Function        : StripPath 
6492
#
6493
# Description     : Internal function to strip bits from a pathname
6494
#                   Will never strip the filename, even if asked to strip too much
6495
#
6496
# Inputs          : $name       - Name to process
6497
#                   $stripCount - Strip part
6498
#                                 <0 - strip all paths
6499
#                                 =0  - Do nothing
6500
#                                 >0 - Strip count
6501
#
6502
# Returns         : Processed name
6503
#
6504
sub StripPath
6505
{
6506
    my( $name, $stripCount) = @_;
227 dpurdie 6507
 
6276 dpurdie 6508
    if ($stripCount)
6509
    {
6510
        $name =~ s~\\~/~g;
6511
        $name =~ s~//~~g;
6512
 
6513
        my @items = split('/', $name);
6514
        if ($stripCount > 0)
6515
        {
6516
            my $len = scalar @items;
6517
            my $remove = $stripCount; 
6518
            if ($stripCount >= $len ) {
6519
                $remove = $len - 1;
6520
            }
6521
            splice @items, 0, $remove;
6522
            $name = join('/', @items);
6523
        }
6524
        else
6525
        {
6526
            $name = pop @items;
6527
        }
6528
    }
6529
    return $name;
6530
}
6531
 
6532
 
227 dpurdie 6533
###############################################################################
6534
#
6535
#   Packaging
6536
#
6537
sub PackageDist
6538
{
6539
    my( $name, @elements ) = @_;
6540
 
6541
    Debug2( "PackageDist($name, @elements)" );
6542
 
6543
    foreach ( @elements )
6544
    {
6545
    #.. Distribution sets
6546
    #
6547
        HashJoin( \%PACKAGE_DIST, $;, $name, "$_" );
6548
 
6549
    #.. Summary of distribution sets
6550
    #
267 dpurdie 6551
        $PACKAGE_SETS{ $_ }{'TAG'} = 1
6552
            if ( ! exists $PACKAGE_SETS{ $_ }{'TAG'} );
227 dpurdie 6553
    }
6554
}
6555
 
311 dpurdie 6556
#-------------------------------------------------------------------------------
6387 dpurdie 6557
# Function        : PackageDir 
6558
#                   InstallDir
6559
#
6560
# Description     : Directive to package an entire directory tree
6561
#                   Will package the contents of the directory without regard as to there content
6562
#                   
6563
#                   Differs from PackageFile (... --DirTree ) in that the process is dynamic
6564
#                   It will support the packaging of files that are generated
6565
#                   
6566
#                   NOT intended to support the JATS BIN and LIB structure
6567
#                   It knows nothing of these types of files
6568
#
6569
# Inputs          : platforms   - Active platform list
6570
#                   Options:    - Many from PackageFile
6571
#                       --DirTree=xxx   Source Tree [Mandatory]
6572
#                       --Subdir=yyy    Target [ Mandatory]
6573
#
6574
sub PackageDir { 
6575
    return if ( !$ScmPackage );                 # Packaging enabled ?
6576
    _PackageInstallDir('PackageDir', 'PBase', \@PACKAGE_DIRS, @_);
6577
    }
6578
 
6579
sub InstallDir { 
6580
    Warning ("InstallDir: Needs local directory specified in build.pl") unless ( $::ScmLocal );
6581
    _PackageInstallDir('InstallDir', 'IBase', \@INSTALL_DIRS, @_);
6582
    }
6583
 
6584
sub _PackageInstallDir
6585
{
6586
    my( $cmdName, $tbase, $dirRef, $platforms, @elements ) = @_;
6587
    my( $base, $dir, $path, $type );
6588
    my %data;
6589
 
6590
    Debug2( "$cmdName($platforms, @elements)" );
6591
 
6592
    return if ( ! ActivePlatform($platforms) );
6593
 
6594
#.. Arguments
6595
#
6596
    $base = $PackageInfo{'File'}{$tbase};           # Base of target
6597
    $dir = $base . $PackageInfo{'File'}{'Dir'};     # Installation path (default)
6598
 
6599
    foreach ( @elements )
6600
    {
6601
        my $rv = __TargetDir($T_MACH|$T_GBE|$T_FILE, $base, $_, \$dir, \$type);
6602
        next if ( $rv == 1 );
6603
        return if ( $rv == 2 );
6604
 
6605
        if (/^--Executable$/) {                  # Mark the file as executable
6606
            $data{exefile} = "X";
6607
 
6608
        } elsif (/^--PreserveSymlink/i) {        # Preserve symlink to local file
6609
            delete $data{noPreserveSymlink};
6610
 
6611
        } elsif (/^--NoPreserveSymlink/i) {      # Preserve symlink to local file
6612
            $data{noPreserveSymlink} = 1;
6613
 
6614
        } elsif ( /^--DirTree=(.*)/ ) {
6615
            Error("DirTree. Multiple directories not allowed.") if ( $data{dirTree} );
6616
            $data{dirTree} =  $1;
6617
 
6618
        } elsif ( /^--FilterOut=(.*)/ ) {
6619
            push @{$data{exclude}}, $1;
6620
 
6621
        } elsif ( /^--FilterIn=(.*)/ ) {
6622
            push @{$data{include}}, $1;
6623
 
6624
        } elsif ( /^--FilterOutRe=(.*)/ ) {
6625
            push @{$data{excludeRe}}, $1;
6626
 
6627
        } elsif ( /^--FilterInRe=(.*)/ ) {
6628
            push @{$data{includeRe}}, $1;
6629
 
6630
        } elsif ( /^--StripDir/ ) {
6631
            $data{strip_base} = 1;
6632
 
6633
        } elsif ( m/^--Recurse/ ) {
6634
            delete $data{noRecurse};
6635
 
6636
        } elsif ( m/^--NoRecurse/ ) {
6637
            $data{noRecurse} = 1;
6638
 
6639
        } elsif (/^--(.*)/) {
6640
            Message( "$cmdName: unknown option $_ -- ignored\n" );
6641
        }
6642
    }
6643
    Error("DirTree. No path specified") unless ( defined($data{dirTree}) && $data{dirTree} ne "" );
6644
    Debug2( "$cmdName. Raw DirTree: $data{dirTree}" );
6645
 
6646
    # Prevent the user from escaping from the current directory
6647
    Error("$cmdName. Absolute paths are not allowed",
6648
          "Directory: $data{dirTree}") if ( $data{dirTree} =~ m~^/~ || $data{dirTree} =~ m~^.\:~ );
6649
 
6650
    #
6651
    #   Convert the relative path to one that is truely relative to the current
6652
    #   directory. This may occur when the user uses $ProjectBase
6653
    #
6654
    my $abs_dir_tree = AbsPath($data{dirTree});
6655
    $data{dirTree} = RelPath($abs_dir_tree);
6656
 
6657
    #
6658
    #   Ensure that the user is not trying to escape the package
6659
    #   Don't allow the user to attempt to package the entire package either
6660
    #
6661
    #   Calculate the relative path from $ProjectBase to the target directory
6662
    #   It must not be above the $ProjectBase 
6663
    #
6664
    if ( $data{dirTree} =~ m~^\.\.~)
6665
    {
6666
        my $dirFromBase = RelPath($abs_dir_tree, AbsPath($ProjectBase));
6667
        Error("$cmdName. DirTree cannot extend outside current package.",
6668
              "Directory: $dirFromBase") if ( $dirFromBase =~ m~\.\.~ );
6669
        Error("$cmdName. DirTree cannot package entire package.",
6670
            "Directory: $dirFromBase") if ( $dirFromBase eq '.' );
6671
    }
6672
 
6673
    Debug( "$cmdName( $data{dirTree}");
6674
    $data{dir} = $dir;
6675
    $data{type} = $type if defined $type;
6676
    #DebugDumpData("$cmdName", \%data);
6677
    push @{$dirRef}, \%data;
6678
}
6679
 
6680
#-------------------------------------------------------------------------------
311 dpurdie 6681
# Function        : PackageFile
6682
#
6683
# Description     : Directive to package files
6684
#                   Not to be used to package libraries, executables, headers
6685
#                   as this should be done by specialised directives
6686
#
6687
#                   Use to package other files
6688
#                   Can package an entire tree (ugly)
6689
#
6690
# Inputs          : 
6691
#
6692
#
227 dpurdie 6693
sub PackageFile
6694
{
6695
    my( $platforms, @elements ) = @_;
335 dpurdie 6696
    my( $base, $dir, $full, $path, $dist, $strip, $exefile, $type );
227 dpurdie 6697
    my( $name, $basename, $len, $srcfile );
4257 dpurdie 6698
    my( $dir_tree, @dir_tree_exclude, @dir_tree_include, $strip_base, $strip_dots );
335 dpurdie 6699
    my $recurse = 1;
6133 dpurdie 6700
    my $preserveSymlink = 0;
227 dpurdie 6701
 
6702
    Debug2( "PackageFile($platforms, @elements)" );
6703
 
6704
    return if ( !$ScmPackage );                 # Packaging enabled ?
6705
    return if ( ! ActivePlatform($platforms) );
6706
 
6707
#.. Arguments
6708
#
6709
    $dist = "ALL";                                  # Default set (ALL)
6710
    $base = $PackageInfo{'File'}{'PBase'};          # Base of target
6711
    $dir = $base . $PackageInfo{'File'}{'Dir'};     # Installation path (default)
335 dpurdie 6712
    $full = 0;
227 dpurdie 6713
    $strip = 0;
341 dpurdie 6714
    $strip_base = 0;
4257 dpurdie 6715
    $strip_dots = 0;
227 dpurdie 6716
    $exefile = 0;
6717
 
285 dpurdie 6718
    foreach ( @elements )
227 dpurdie 6719
    {
6720
        my $rv = __TargetDir($T_PKG|$T_MACH|$T_GBE|$T_FILE, $base, $_, \$dir, \$type);
6721
        next if ( $rv == 1 );
6722
        return if ( $rv == 2 );
6723
 
6724
        if (/^--Full/) {                        # Using full (resolved) path
6725
            $full = 1;
6726
 
6727
        } elsif (/^--Set=(.*)/) {               # Distribution set
6728
            $dist = "$1";
6729
 
6730
        } elsif (/^--Package$/) {               # Package .. call by InstallFile
6731
        } elsif (/^--Package=(.*)/) {
6732
            $dist = "$1";
6733
 
6734
        } elsif (/^--Strip$/) {                 # Strip path from source files
6276 dpurdie 6735
            $strip = -1;
227 dpurdie 6736
 
6294 dpurdie 6737
        } elsif (/^--Strip=(\d+)$/) {           # Strip path from source files
6276 dpurdie 6738
            $strip = $1;
6739
 
227 dpurdie 6740
        } elsif (/^--Executable$/) {            # Mark the file as executable
6741
            $exefile = "X";
6742
 
6133 dpurdie 6743
        } elsif (/^--PreserveSymlink/i) {       # Preserve symlink to local file
6744
            $preserveSymlink = 1;
6745
 
227 dpurdie 6746
        } elsif ( /^--DirTree=(.*)/ ) {
6747
            Error("DirTree. Multiple directories not allowed.") if ( $dir_tree );
4163 dpurdie 6748
            $dir_tree =  $1;
4257 dpurdie 6749
            Error("DirTree. No path specified") unless ( defined($dir_tree) && $dir_tree ne "" );
227 dpurdie 6750
 
4163 dpurdie 6751
            # Prevent the user from escaping from the current directory
6752
            Error("DirTree. Absolute paths are not allowed",
6753
                  "Directory: $dir_tree") if ( $dir_tree =~ m~^/~ || $dir_tree =~ m~^.\:~ );
6754
 
6755
            #
6756
            #   Convert the relative path to one that is truely relative to the current
6757
            #   directory. This may occur when the user uses $ProjectBase
6758
            #
4257 dpurdie 6759
            my $abs_dir_tree = AbsPath($dir_tree);
6760
            $dir_tree = RelPath($abs_dir_tree);
6761
 
6762
            #
6763
            #   Ensure that the user is not trying to escape the package
4265 dpurdie 6764
            #   Don't allow the user to attempt to package the entire package either
4257 dpurdie 6765
            #
6766
            #   Calculate the relative path from $ProjectBase to the target directory
6767
            #   It must not be above the $ProjectBase 
6768
            #
4265 dpurdie 6769
            if ( $dir_tree =~ m~^\.\.~)
6770
            {
6771
                my $dirFromBase = RelPath($abs_dir_tree, AbsPath($ProjectBase));
6772
                Error("DirTree cannot extend outside current package.",
6773
                      "Directory: $dirFromBase") if ( $dirFromBase =~ m~\.\.~ );
6774
                Error("DirTree cannot package entire package.",
6775
                    "Directory: $dirFromBase") if ( $dirFromBase eq '.' );
6776
            }
4257 dpurdie 6777
 
4163 dpurdie 6778
            Debug2( "PackageFile. DirTree: $dir_tree" );
6779
 
227 dpurdie 6780
            Error("DirTree. Directory not found",
6781
                  "Directory: $dir_tree") unless  ( -d $dir_tree );
6782
 
4257 dpurdie 6783
            # If packaging a parent directory then force dot_stripping of the base directory
6784
            # strip_base will have precedence if both are active
6785
            if ( $dir_tree =~ m~\.\.~ )
6786
            {
6787
                $dir_tree =~ m~(\.\./)+~;
6788
                $strip_dots = length($1);
6789
            }
6790
 
227 dpurdie 6791
        } elsif ( /^--FilterOut=(.*)/ ) {
6792
            push @dir_tree_exclude, $1;
6793
 
6794
        } elsif ( /^--FilterIn=(.*)/ ) {
6795
            push @dir_tree_include, $1;
6796
 
6797
        } elsif ( /^--StripDir/ ) {
341 dpurdie 6798
            $strip_base = 1;
227 dpurdie 6799
 
335 dpurdie 6800
        } elsif ( m/^--Recurse/ ) {
6801
            $recurse = 1;
6802
 
6803
        } elsif ( m/^--NoRecurse/ ) {
6804
            $recurse = 0;
6805
 
227 dpurdie 6806
        } elsif (/^--(.*)/) {
6807
            Message( "PackageFile: unknown option $_ -- ignored\n" );
6808
        }
6809
    }
6810
 
6811
 
6812
    #.. DirTree expansion
6813
    #   Note: Uses REs, not simple globs
6814
    #         Use JatsLocateFiles to do the hard work
6815
    if ( $dir_tree )
6816
    {
335 dpurdie 6817
        my $search = JatsLocateFiles->new('FullPath' );
6818
        $search->recurse($recurse);
227 dpurdie 6819
        $search->filter_in_re ( $_ ) foreach ( @dir_tree_include );
6820
        $search->filter_out_re( $_ ) foreach ( @dir_tree_exclude );
1431 dpurdie 6821
        $search->filter_out_re( '/\.svn/' );
5848 dpurdie 6822
        $search->filter_out_re( '/\.git/' );
227 dpurdie 6823
        @elements = $search->search ( $dir_tree );
4257 dpurdie 6824
        if ($strip_base){
6825
            $strip_base = length( $dir_tree ) if ( $strip_base );
6826
        } elsif ($strip_dots) {
6827
            $strip_base = $strip_dots;
6828
        }
6403 dpurdie 6829
    } else {
6830
        $strip_base = 0;
227 dpurdie 6831
    }
6832
 
6833
#.. Files
6834
#
285 dpurdie 6835
    foreach ( @elements )
227 dpurdie 6836
    {
6837
        my %package_entry;
299 dpurdie 6838
        $name = $_;
6133 dpurdie 6839
        my $symlink;
299 dpurdie 6840
 
227 dpurdie 6841
        #
299 dpurdie 6842
        #   Trap special files
6843
        #       DPACKAGE - but only if we have a DPackageLibrary directive
6844
        #                  in the same makefile.
6845
        #
6846
        if ( m~^DPACKAGE$~ && $DPackageDirective ) {
6847
            $name = 'DPACKAGE.' . $::GBE_MACHTYPE;
6848
        }
6849
 
227 dpurdie 6850
        if ( ! /^--(.*)/ )
6851
        {
6852
            $basename = StripDir( $name );
335 dpurdie 6853
            if ( !($srcfile = $SRCS{ $basename }) ) {
6854
                $srcfile = $name;
6855
            }
6856
 
227 dpurdie 6857
            if ( $full )
6858
            {
335 dpurdie 6859
                my $subdir = StripFileExt($srcfile);
6860
                $subdir = $1
6861
                    if ( $subdir =~ m~^$ProjectBase/(.*)~ );
6862
                $dir .= '/' . $subdir;
6863
                $dir =~ s~//~/~g;
6864
                $dir =~ s~/./~/~g;
6865
                $dir =~ s~/$~~g;
6866
                $name = $basename;
227 dpurdie 6867
            }
6868
 
6276 dpurdie 6869
            $name = StripPath($name, $strip) if ($strip);
227 dpurdie 6870
 
341 dpurdie 6871
            if ( $strip_base )
6872
            {
6873
                $name = substr $name, $strip_base;
6874
                $name =~ s~^/~~;
6875
            }
6876
 
227 dpurdie 6877
            $dir =~ s~//~/~g;
6878
            $dir =~ s~/$~~;
6879
 
6880
            #
6133 dpurdie 6881
            #   Preserve Symlink
6882
            #
6883
            if ($preserveSymlink && -l $srcfile)
6884
            {
6885
                $symlink = 1;
6886
            }
6887
 
6888
            #
227 dpurdie 6889
            #   Sanity test the source filename
6890
            #   User may have misused an option
6891
            #
6387 dpurdie 6892
            if ( !$dir_tree && ( ( $srcfile =~ m/=/ ) || ( $srcfile =~ m/^-/ ) || ( $srcfile =~ m~/-~ ))  )
227 dpurdie 6893
            {
6894
               Warning ("PackageFile: Suspect source filename: $srcfile");
6895
            }
6896
 
6897
            Debug( "PackageFile( $dir/$name, " .
6898
                "src: $srcfile, dest: $dir, dist: $dist, exe: $exefile )" );
6899
 
6900
            $package_entry{'src'} = $srcfile;
6901
            $package_entry{'dir'} = StripFileExt( "$dir/$name" );
6902
            $package_entry{'set'} = $dist;
6903
            $package_entry{'exe'} = $exefile if $exefile;
6904
            $package_entry{'type'} = $type if ( $type );
6133 dpurdie 6905
            $package_entry{'symlink'} = 1 if ( $symlink );
227 dpurdie 6906
 
6907
            $PACKAGE_FILES{ "$dir/$name" } = {%package_entry};
6908
        }
6909
    }
6910
}
6911
 
6912
sub PackageHdr
6913
{
6914
    my( $platforms, @elements ) = @_;
335 dpurdie 6915
    my( $base, $dir, $full, $path, $dist, $strip );
227 dpurdie 6916
    my( $name, $basename, $len, $srcfile );
6917
 
6918
    Debug2( "PackageHdr($platforms, @elements)" );
6919
 
6920
    return if ( !$ScmPackage );                 # Packaging enabled ?
6921
    return if ( ! ActivePlatform($platforms) );
6922
 
6923
#.. Arguments
6924
#
6925
    $dist = "ALL";                                  # Default set (ALL)
6926
    $base = $PackageInfo{'Hdr'}{'PBase'};           # Base of target
6927
    $dir = $base . $PackageInfo{'Hdr'}{'Dir'};      # Installation path (default)
335 dpurdie 6928
    $full = 0;
227 dpurdie 6929
    $strip = 0;
6930
 
285 dpurdie 6931
    foreach ( @elements )
227 dpurdie 6932
    {
6933
        my $rv = __TargetDir($T_PKG, $base, $_, \$dir);
6934
        next if ( $rv == 1 );
6935
        return if ( $rv == 2 );
6936
 
6937
        if (/^--Full/) {                        # Using full (resolved) path
6938
            $full = 1;
6939
 
6940
        } elsif (/^--Set=(.*)/) {               # Distribution set
6941
            $dist = "$1";
6942
 
6943
        } elsif (/^--Package$/) {               # Package .. call by InstallHdr
6944
        } elsif (/^--Package=(.*)/) {
6945
            $dist = "$1";
6946
 
6947
        } elsif (/^--Strip$/) {                 # Strip path from source files
6276 dpurdie 6948
            $strip = -1;
227 dpurdie 6949
 
6276 dpurdie 6950
        } elsif (/^--Strip=(\d+)$/) {           # Strip some f the path from source files
6951
            $strip = $1;
6952
 
227 dpurdie 6953
        } elsif (/^--(.*)/) {
6954
            Message( "PackageHdr: unknown option $_ -- ignored\n" );
6955
        }
6956
    }
6957
 
6958
#.. Files
6959
#
285 dpurdie 6960
    foreach ( @elements )
227 dpurdie 6961
    {
6962
        my %package_entry;
6963
        if ( ! /^--(.*)/ )
6964
        {
5991 dpurdie 6965
            $name = $_;
227 dpurdie 6966
            $basename = StripDir( $name );
335 dpurdie 6967
            if ( !($srcfile = $SRCS{ $basename }) ) {
6968
                $srcfile = $name;
6969
            }
6970
 
227 dpurdie 6971
            if ( $full )
6972
            {
335 dpurdie 6973
                my $subdir = StripFileExt($srcfile);
6974
                $subdir = $1
6975
                    if ( $subdir =~ m~^$ProjectBase/(.*)~ );
6976
                $dir .= '/' . $subdir;
6977
                $dir =~ s~//~/~g;
6978
                $dir =~ s~/./~/~g;
6979
                $dir =~ s~/$~~g;
6980
                $name = $basename;
227 dpurdie 6981
            }
6982
 
6276 dpurdie 6983
            $name = StripPath($name, $strip) if ($strip);
227 dpurdie 6984
 
6985
            Debug( "PackageHdr( $dir/$name, " .
6986
                "src: $srcfile, dest: $dir, dist: $dist )" );
6987
 
6988
            $package_entry{'src'} = $srcfile;
6989
            $package_entry{'dir'} = StripFileExt( "$dir/$name" );
6990
            $package_entry{'set'} = $dist;
6991
 
6992
            $PACKAGE_HDRS{ "$dir/$name" } = {%package_entry};
6993
        }
6994
    }
6995
}
6996
 
6997
 
6998
sub PackageLib
6999
{
7000
    my( $platforms, @elements ) = @_;
7001
    my( $base, $dir, $dist, $type );
7002
    my( $lib, $org_lib, %extras, $strip );
7003
 
7004
    Debug2( "PackageLib($platforms, @elements)" );
7005
 
7006
    return if ( !$ScmPackage );                 # Packaging enabled ?
7007
    return if ( ! ActivePlatform($platforms) );
7008
 
7009
#.. Arguments
7010
#
7011
    $dist = "ALL";                              # Default set (ALL)
7012
    $base = $PackageInfo{'Lib'}{'PBase'};       # Base of target
7013
    $dir = $base . $PackageInfo{'Lib'}{'Dir'};  # Installation path (default)
7014
    $type = "";
7015
 
285 dpurdie 7016
    foreach ( @elements )
227 dpurdie 7017
    {
7018
                                                # Standard targets
7019
        my $rv = __TargetDir($T_PKG, $base, $_, \$dir, \$type);
7020
        next if ( $rv == 1 );
7021
        return if ( $rv == 2 );
7022
 
7023
        if (/^--Set=(.*)/) {                    # Distribution set(s)
7024
            $dist = "$1";
7025
 
7026
        } elsif (/^--Package$/) {               # Package .. call by PackageLib
7027
        } elsif (/^--Package=(.*)/) {
7028
            $dist = "$1";
7029
 
7030
        } elsif (/^--Extras=(.*)/) {            # Extras=[none, .. ,all]
7031
            foreach my $elem ( split( ',', $1 ) )
7032
            {
7033
                Error ("PackageLib: Unknown Extras mode: $elem")
7034
                    unless ( grep m/$elem/, qw(none stub map lint debug all) );
7035
                $extras{$elem} = 1;
7036
            }
7037
            %extras = () if ( $extras{'all'} );
7038
 
7039
        } elsif (/^--Strip$/) {                 # Strip path from source files
6276 dpurdie 7040
            $strip = -1;
227 dpurdie 7041
 
6276 dpurdie 7042
        } elsif (/^--Strip=(\d+)$/) {           # Strip some f the path from source files
7043
            $strip = $1;
7044
 
227 dpurdie 7045
        } elsif (/^--(.*)/) {
7046
            Message( "PackageLib: unknown option $_ -- ignored\n" );
7047
        }
7048
    }
7049
 
7050
#.. Files
7051
#
285 dpurdie 7052
    foreach ( @elements )
227 dpurdie 7053
    {
7054
        my %package_entry;
7055
        if ( ! /^--(.*)/ )
7056
        {
6276 dpurdie 7057
            $_ = StripPath($_, $strip) if ($strip);
227 dpurdie 7058
 
7059
            $org_lib = $_;                      # Original name
7060
            if ( $ScmTargetHost eq "Unix" ) {
7061
                $lib = "lib$_";                 # Prefix "lib" ....
7062
                $lib =~ s/^liblib/lib/;         # @LIBS already has lib added
7063
            } else {
7064
                $lib = $_;
7065
            }
7066
 
289 dpurdie 7067
            if (  my $libp = $SHLIBS->Get($lib) )
227 dpurdie 7068
            {
7069
                Debug( "PackageLib( $dir/$lib\$(GBE_TYPE).$::so, " .
7070
                    "src: \$(LIBDIR)/$lib\$(GBE_TYPE).$::so, dest: $dir, dist: $dist, type: $type )" );
7071
 
7072
                #
7073
                #   Create a "placekeeper" entry within $PACKAGE_SHLIBS
7074
                #   The exact format of the name of the shared library is
7075
                #   toolset specific. Create an entry to allow the toolset
7076
                #   to extend the packaging information when the shared library
7077
                #   recipe is constructed.
7078
                #
7079
                #
289 dpurdie 7080
                my $ver = $libp->{ VERSION };
227 dpurdie 7081
                my $name = "$dir/$lib.$ver.PlaceKeeper";
7082
 
7083
                $package_entry{'placekeeper'} = 1;
7084
                $package_entry{'version'} = $ver;
7085
                $package_entry{'lib'} = $lib;
7086
                $package_entry{'dir'} = $dir;
7087
                $package_entry{'set'} = $dist;
7088
                $package_entry{'type'} = $type if ( $type );
7089
                $package_entry{'extras'} = {%extras} if ( scalar %extras );
289 dpurdie 7090
 
7091
                push @{$SHLIB_PKG{$lib}}, $name;
227 dpurdie 7092
                $PACKAGE_SHLIBS{$name} = {%package_entry};
7093
            }
7094
 
289 dpurdie 7095
            #
7096
            #   Clean up the package_entry
7097
            #   Insert common items
7098
            #
7099
            %package_entry = ();
7100
            $package_entry{'lib'} = $lib;
7101
            $package_entry{'dir'} = $dir;
7102
            $package_entry{'set'} = $dist;
7103
            $package_entry{'extras'} = {%extras} if ( scalar %extras );
7104
            $package_entry{'type'} = $type if ( $type );
7105
 
227 dpurdie 7106
            if ( my $libfile = $SRCS{$org_lib} )
7107
            {
7108
                #
7109
                #   Allow the user to package a sourced file as a library
7110
                #   But must be the un-massaged name of the file.
7111
                #
5991 dpurdie 7112
                $package_entry{'dst'} = "$dir/$org_lib";
7113
                $package_entry{'src'} = $libfile;
289 dpurdie 7114
            }
7115
            elsif ( $LIBS->Get($lib) )
7116
            {
7117
                #
7118
                #   Package up a library known to the makefile
7119
                #
7120
                my $libp = $LIBS->Get($lib);
227 dpurdie 7121
 
289 dpurdie 7122
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
7123
                $package_entry{'src'}    = $libp->getPath();
227 dpurdie 7124
            }
289 dpurdie 7125
            elsif ( ! $SHLIBS->Get($lib) )
227 dpurdie 7126
            {
289 dpurdie 7127
                #
7128
                #   Not a known shared lib
7129
                #   Not a known static lib
7130
                #   Not a 'sourced' file
7131
                #   Assume the a static library has magically appeared
7132
                #   in the standard LIB directory. May have been placed there
7133
                #   by a 'rule'
7134
                #
7135
                my $libp = $LIBS->New($lib);
227 dpurdie 7136
 
289 dpurdie 7137
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
7138
                $package_entry{'src'}    = $libp->getPath();
7139
            }
227 dpurdie 7140
 
289 dpurdie 7141
            #
7142
            #   Add entry to various lists if required
7143
            #
7144
            PackageLib_AddEntry ('PackageLib', \%LIB_PKG, \%PACKAGE_LIBS, \%package_entry )
7145
                if ( exists $package_entry{'dst'} );
227 dpurdie 7146
        }
7147
    }
7148
}
7149
 
289 dpurdie 7150
#-------------------------------------------------------------------------------
7151
# Function        : PackageLib_AddEntry
7152
#
7153
# Description     : Helper function to add a package entry
7154
#                   to the lists
7155
#
7156
# Inputs          : $directive          - Directive name
7157
#                   $pList              - Ref to array list to maintain
7158
#                   $pHash              - Ref to hash to maintain
7159
#                   $pData              - Packaging Data
7160
#                                         Must Take a copy.
7161
#
7162
# Returns         : 
7163
#
227 dpurdie 7164
 
289 dpurdie 7165
sub PackageLib_AddEntry
7166
{
7167
    my ($directive, $pList, $pHash, $pData) = @_;
7168
 
7169
    my $lib = delete $pData->{'lib'};
7170
    my $dst = delete $pData->{'dst'};
7171
 
7172
    Error ("INTERNAL PackageLib_AddEntry: lib or dst not defined")
7173
        unless ( $lib && $dst );
7174
 
7175
    Debug( "$directive( ",$dst,
7176
            ", src: " ,$pData->{'src'},
7177
            ", dest: ",$pData->{'dir'},
7178
            ", dist: ",$pData->{'set'},
7179
            ", type: ",$pData->{'type'} || '',
7180
            " )" );
7181
 
7182
    push @{$pList->{$lib }}, $dst;
7183
    $pHash->{$dst } = {%$pData};
7184
}
7185
 
7186
 
227 dpurdie 7187
sub PackageProg
7188
{
7189
    my( $platforms, @elements ) = @_;
7190
    my( $base, $dir, $dist, $type );
7191
    my( $prog, %extras, $strip );
7192
 
7193
    Debug2( "PackageProg($platforms, @elements)" );
7194
 
7195
    return if ( !$ScmPackage );                 # Packaging enabled ?
7196
    return if ( ! ActivePlatform($platforms) );
7197
 
7198
#.. Arguments
7199
#
7200
    $dist = "ALL";                              # Default set (ALL)
7201
    $base = $PackageInfo{'Prog'}{'PBase'};       # Base of target
7202
    $dir = $base . $PackageInfo{'Prog'}{'Dir'};  # Installation path (default)
7203
    $type = "";
7204
 
285 dpurdie 7205
    foreach ( @elements )
227 dpurdie 7206
    {
7207
                                                # Standard targets
7208
        my $rv = __TargetDir($T_PKG|$T_TYPE, $base, $_, \$dir, \$type);
7209
        next if ( $rv == 1 );
7210
        return if ( $rv == 2 );
7211
 
7212
        if (/^--Set=(.*)/) {                    # Distribution set(s)
7213
            $dist = "$1";
7214
 
7215
        } elsif (/^--Package$/) {               # Package .. call by PackageLib
7216
        } elsif (/^--Package=(.*)/) {
7217
            $dist = "$1";
7218
 
7219
        } elsif (/^--Tool(([=])(.*))?$/) {      # Allow Tool and Tool=xxx specfic target
7220
            my $path = ( defined( $3) ) ? "/$3" : "";
261 dpurdie 7221
            $dir = "\$(PKGDIR)$path/\$(GBE_HOSTMACH)";
227 dpurdie 7222
 
7223
        } elsif (/^--Extras=(.*)/) {            # Extras=[none, .. ,all]
7224
            foreach my $elem ( split( ',', $1 ) )
7225
            {
7226
                Error ("PackageLib: Unknown Extras mode: $elem")
7227
                    unless ( grep m/$elem/, qw(none stub map lint debug all) );
7228
                $extras{$elem} = 1;
7229
            }
7230
            %extras = () if ( $extras{'all'} );
7231
 
7232
        } elsif (/^--Strip$/) {                 # Strip path from source files
6276 dpurdie 7233
            $strip = -1;
227 dpurdie 7234
 
6276 dpurdie 7235
        } elsif (/^--Strip=(\d+)$/) {           # Strip some f the path from source files
7236
            $strip = $1;
7237
 
227 dpurdie 7238
        } elsif (/^--(.*)/) {
7239
            Message( "PackageProg: unknown option $_ -- ignored\n" );
7240
        }
7241
    }
7242
 
7243
#.. Files
7244
#
285 dpurdie 7245
    foreach ( @elements )
227 dpurdie 7246
    {
7247
        my %package_entry;
7248
        if ( m~descpkg~ ) {
7249
            PackageFile($platforms, @elements);
7250
 
7251
        } elsif ( ! /^--(.*)/ ) {
6276 dpurdie 7252
            $_ = StripPath($_, $strip) if ($strip);
227 dpurdie 7253
 
7254
            my $ext = "";
7255
            $prog = $_;
7256
 
7257
            #
7258
            #   If the named target is a program then append the correct
7259
            #   extension. Otherwise assume that the target is either a script
7260
            #   or a some other file - and don't append an extension
7261
            #
7262
            #   A program may not have any object files, only libraries
7263
            #
7264
            $ext = $::exe
289 dpurdie 7265
                if ( $PROGS->Get($prog) );
227 dpurdie 7266
 
7267
            #
7268
            #   A "file" that is specified with a "Src" directive may be
7269
            #   installed as though it were a program
7270
            #
7271
            my $progfile;
387 dpurdie 7272
            if ( $progfile = $SRCS{$prog} )
7273
            {
5991 dpurdie 7274
                $progfile = $progfile;
7275
                $prog = $prog;
387 dpurdie 7276
            }
7277
            else
7278
            {
7279
                $progfile = "\$(BINDIR)/$prog$ext";
7280
            }
227 dpurdie 7281
 
7282
            Debug( "PackageProg( $dir/$prog$ext, " .
7283
                 "src: $progfile, dest: $dir, dist: $dist, type: $type )" );
7284
 
7285
            my $target = "$dir/$prog$ext";
7286
            push @{$PROG_PKG{$prog}}, $target;
7287
 
7288
            $package_entry{'src'}   = $progfile;
7289
            $package_entry{'dir'}   = $dir;
7290
            $package_entry{'set'}   = $dist;
7291
            $package_entry{'extras'}= {%extras} if ( scalar %extras );
7292
            $package_entry{'type'}  = $type if ( $type );
7293
 
7294
            $PACKAGE_PROGS{$target} = {%package_entry};
7295
        }
7296
    }
7297
}
7298
 
7299
 
7300
sub PackageJar
7301
{
7302
    my( $platforms, @elements ) = @_;
7303
    my( $base, $dir, $dist, $type );
7304
    my( $jar );
7305
 
7306
    Debug2( "PackageJar($platforms, @elements)" );
7307
 
7308
    return if ( !$ScmPackage );                 # Packaging enabled ?
7309
    return if ( ! ActivePlatform($platforms) );
7310
 
7311
#.. Arguments
7312
#
7313
    $dist = "ALL";                              # Default set (ALL)
7314
    $base = $PackageInfo{'Jar'}{'PBase'};       # Base of target
7315
    $dir = $base . $PackageInfo{'Jar'}{'Dir'};  # Installation path (default)
7316
    $type = "";
7317
 
285 dpurdie 7318
    foreach ( @elements )
227 dpurdie 7319
    {
7320
                                                # Standard targets
7321
        my $rv = __TargetDir($T_PKG, $base, $_, \$dir, \$type);
7322
        next if ( $rv == 1 );
7323
        return if ( $rv == 2 );
7324
 
7325
        if (/^--Set=(.*)/) {                    # Distribution set(s)
7326
            $dist = "$1";
7327
 
7328
        } elsif (/^--Package$/) {               # Package .. call by InstallJar
7329
        } elsif (/^--Package=(.*)/) {
7330
            $dist = "$1";
7331
 
7332
        } elsif (/^--(.*)/) {
7333
            Message( "PackageJar: unknown option $_ -- ignored\n" );
7334
        }
7335
    }
7336
 
7337
#.. Files
7338
#
285 dpurdie 7339
    foreach ( @elements )
227 dpurdie 7340
    {
7341
        my %package_entry;
7342
        if ( ! /^--(.*)/ )
7343
        {
7344
            $jar = $_;
7345
            my $src;
7346
            my $dest;
7347
 
7348
            if ( $JAR_FILES{$jar} )
7349
            {
7350
                $src = $JAR_FILES{$jar};
7351
                $dest = $jar;
7352
            }
7353
            else
7354
            {
7355
                $src = "\$(CLSDIR)/$jar\$(GBE_TYPE).jar";
7356
                $dest = "$jar\$(GBE_TYPE).jar";
7357
            }
7358
 
7359
 
7360
            Debug( "PackageJar( $dir/$dest, " .
7361
                "src: $src, dest: $dir, dist: $dist, type: $type )" );
7362
 
7363
            $package_entry{'src'} = $src;;
7364
            $package_entry{'dir'} = $dir;
7365
            $package_entry{'set'} = $dist;
7366
            $package_entry{'type'} = $type if ( $type );
7367
 
7368
            $PACKAGE_CLSS{ "$dir/$dest" } = {%package_entry};
7369
 
7370
        }
7371
    }
7372
}
7373
 
7374
#-------------------------------------------------------------------------------
7375
# Function        : PackageProgAddFiles         - Add files to a PackageProg
7376
#                   PackageLibAddFiles          - Add files to a PackageLib
7377
#                   PackageShlibAddFiles        - Add files to a PackageLib (shared lib)
7378
#                   PackageShlibAddLibFiles     - Add files to a PackageLib (shared lib)
7379
#                                                 Add static library files
7380
#
7381
# Description     : Add files to a Program package or installation
7382
#                   For use by Tool sets to allow additional files to be
7383
#                   packaged with a program.
7384
#
7385
#                   The files are only added if the named program is being
7386
#                   packaged and/or installed.
7387
#
7388
#
7389
# Inputs          : prog        - program identifier
7390
#                   file        - A file to be add
7391
#                   args        - Additional packageing arguments
7392
#
7393
# Returns         : Nothing
7394
#
7395
 
7396
sub PackageProgAddFiles
7397
{
7398
    Debug("PackageProgAddFiles");
7399
 
7400
    PackageAddFiles ( \%PACKAGE_PROGS, \%PACKAGE_PROGS, \%PROG_PKG, @_);
7401
    PackageAddFiles ( \%INSTALL_PROGS, \%INSTALL_PROGS, \%PROG_INS, @_);
7402
}
7403
 
7404
sub PackageLibAddFiles
7405
{
7406
    Debug("PackageLibAddFiles");
7407
 
7408
    PackageAddFiles ( \%PACKAGE_LIBS, \%PACKAGE_LIBS, \%LIB_PKG, @_ );
7409
    PackageAddFiles ( \%INSTALL_LIBS, \%INSTALL_LIBS, \%LIB_INS, @_ );
7410
}
7411
 
7412
sub PackageShlibAddFiles
7413
{
7414
    my ($prog, $file, @args) = @_;
7415
    Debug("PackageShlibAddFiles");
7416
 
7417
    PackageAddFiles ( \%INSTALL_SHLIBS, \%INSTALL_SHLIBS, \%SHLIB_INS, @_ );
7418
    PackageAddFiles ( \%PACKAGE_SHLIBS, \%PACKAGE_SHLIBS, \%SHLIB_PKG, @_ );
7419
 
7420
    #
7421
    #   These files become the target of the "make_install_shlib" operation unless:
7422
    #       Conditionally packaged files are not always created
7423
    #       RemoveOnly files are not always generated
7424
    #
7425
    my $no_add;
7426
    foreach ( @args )
7427
    {
4382 dpurdie 7428
        if ( m/^defined=/ or m/^RemoveOnly=/ or /NoTarget=/ )
227 dpurdie 7429
        {
7430
            $no_add = 1;
7431
            last;
7432
        }
7433
    }
7434
 
7435
    push (@SHLIB_TARGETS, $file ) unless $no_add;
7436
}
7437
 
7438
sub PackageShlibAddLibFiles
7439
{
7440
    Debug("PackageShlibAddLibFiles");
7441
 
7442
    PackageAddFiles ( \%PACKAGE_SHLIBS, \%PACKAGE_LIBS, \%SHLIB_PKG, @_ , 'Class=lib');
7443
    PackageAddFiles ( \%INSTALL_SHLIBS, \%INSTALL_LIBS, \%SHLIB_INS, @_ , 'Class=lib');
7444
}
7445
 
7446
#-------------------------------------------------------------------------------
7447
# Function        : PackageAddFiles
7448
#
7449
# Description     : Internal function to add files to the data structures that
7450
#                   describe a package or installation
7451
#
7452
#                   Use this function to package or install additional files with
7453
#                   the Progs and Libs
7454
#
7455
#                   ie: Add a LIB file to be packaged with a Shared Library
7456
#                   ie: Add a MAP file to be packaged with a program
7457
#
7458
# Inputs          : ref_spkg  - Reference to the hash that contains the package data
7459
#                   ref_dpkg  - Reference to the target package/install hash
7460
#                               Normally the same as ref_dpkg, but does allow
289 dpurdie 7461
#                               a static library to be added to a dynamic library
227 dpurdie 7462
#                               package.
7463
#                   ref_list  - Reference to a hash that may contain package keys to process
7464
#                   prog      - Key for index to above
7465
#                   file      - A file to be added
7466
#                   args      - Additional packaging arguments
7467
#
7468
# Returns         :
7469
#
7470
sub PackageAddFiles
7471
{
7472
    my ($ref_spkg, $ref_dpkg, $ref_list, $prog, $file, @args ) = @_;
7473
 
7474
    #
7475
    #   Process entry
7476
    #   The files may need to be added to multiple packages
7477
    #
7478
    Debug("PackageAddFiles: $file");
7479
 
7480
    return unless ( $ref_list->{$prog} );
7481
 
7482
    #
7483
    #   Parse arguments and extract the "Class=xxx" argument. This may be used
7484
    #   to limit the extra files piggybacked with the base file
7485
    #   All files without a class will be treated as base files
7486
    #
7487
    my $class;
7488
    foreach ( @args )
7489
    {
7490
        next unless ( m~^Class=(.*)$~ );
7491
        $class = $1 unless ( $1 eq 'none' );
7492
    }
7493
    Debug("PackageAddFiles: Class: ", $class || 'Default=None');
7494
 
7495
    foreach my $entry_key ( @{$ref_list->{$prog}} )
7496
    {
7497
        Debug("PackageAddFiles: Entry found: $entry_key");
7498
 
7499
        #
7500
        #   Copy of the template entry
7501
        #
7502
        my %package_entry = %{$ref_spkg->{$entry_key}};
7503
        Error ("INTERNAL: Expected entry in PACKAGE_ hash not found: $entry_key" )
7504
            unless ( %package_entry );
7505
 
7506
        #
7507
        #   Do not add the file if the user has limited the extra files added
7508
        #   to the packaging list and the current file is not in the class list
7509
        #
7510
        if ( $class && $package_entry{'extras'} )
7511
        {
7512
            next unless ( $package_entry{'extras'}{$class} );
7513
        }
7514
 
7515
        #
7516
        #   Create new entries for the file
7517
        #
7518
        $package_entry{'src'} = $file;
7519
        foreach ( @args )
7520
        {
7521
            m~^(.*)=(.*)$~;
7522
            $package_entry{$1} = $2;
7523
        }
7524
 
7525
        #
7526
        #   Clean out useless fields
7527
        #   Must remove the placekeeper marker to allow the entry to be visible
7528
        #
7529
        delete $package_entry{'placekeeper'};
7530
        delete $package_entry{'version'};
7531
        delete $package_entry{'lib'};
261 dpurdie 7532
#       delete $package_entry{'extras'};                   # Keep these
227 dpurdie 7533
        delete $package_entry{'Class'};
7534
 
7535
        #
7536
        #   Add the entry
7537
        #
7538
        #   Under some conditions is it possible to attempt to add the same named
7539
        #   file. This will result in a circular dependancy in the makefile
7540
        #
7541
        #   The condition is when merged libaries with PDBs (WINCE+WIN32) are merged
261 dpurdie 7542
        #   and the source for the merge is the "local directory.
227 dpurdie 7543
        #
7544
        #
7545
        my $dst = $package_entry{'dir'} ;
7546
        ( my $dfile = $file) =~ s~.*/~~;
7547
        Debug( "    added $dst/$dfile = $file" );
7548
 
7549
        $ref_dpkg->{"$dst/$dfile"} = {%package_entry}
7550
            unless ( "$dst/$dfile" eq "$file" );
7551
    }
7552
}
7553
 
7554
#-------------------------------------------------------------------------------
7555
# Function        : PackageProgRemoveFiles
7556
#
7557
# Description     : Flag a Packaged program to be not packaged
7558
#                   This mechanism is used to remove a program from packageing
7559
#                   under conditions where the toolset has generated a different
7560
#                   program.
7561
#
7562
#                   The entry is flagged as a placeholder
7563
#
7564
# Inputs          : prog        - Program to process
7565
#
7566
# Returns         : Nothing
7567
#
7568
sub PackageProgRemoveFiles
7569
{
7570
    my ($prog) = @_;
7571
    Verbose ("PackageProgRemoveFiles: $prog" );
7572
    return unless (exists($PROG_PKG{$prog}));
7573
 
7574
    #
7575
    #   Must lookup the TAG to locate the  required entry
7576
    #
7577
    my $tag = $PROG_PKG{$prog};
7578
    foreach my $entry ( @$tag )
7579
    {
7580
        Verbose("Do not package: $entry");
7581
        if ( exists $PACKAGE_PROGS{$entry} )
7582
        {
7583
            $PACKAGE_PROGS{$entry}{placekeeper} = 'ProgRemoved';
7584
        }
7585
    }
7586
}
7587
 
7588
#-------------------------------------------------------------------------------
7589
# Function        : DPackageLibrary
7590
#
7591
# Description     : Collect information to allow the generation of a DPACKAGE
299 dpurdie 7592
#                   file. This directive allows the generation of "Library"
227 dpurdie 7593
#                   directives within the final DPACKAGE
7594
#
7595
#                   This directive does generate the DPACKAGE file.
7596
#
7597
# Inputs          : platform    - This does not need to be an active platform
7598
#                                 it is simply passed to the DPACKAGE builder
7599
#
7600
#                   using       - The "using" target
7601
#
7602
#                   ...         - Arguments for the Library directive
7603
#
7604
# Returns         :
7605
#
7606
sub DPackageLibrary
7607
{
7608
    JatsDPackage::DPackageAdd ( @_ );
299 dpurdie 7609
    $DPackageDirective = 1;
227 dpurdie 7610
}
7611
 
7612
#-------------------------------------------------------------------------------
7613
# Function        : SetProjectBase
7614
#
7615
# Description     : Allows the user to modify the build's concept of the Base
7616
#                   of the build. By default the base is the same directory as
7617
#                   the build.pl file, but in some contorted environments it
7618
#                   is a great deal simpler to specify a differnt base.
7619
#
7620
#                   The use may use the variable $ProjectBase as a path
7621
#                   specifier to locate files and directories
7622
#
7623
#                   Both absolute and relative paths are supported
7624
#                   If the initial value of $ProjectBase is relative then
7625
#                   it will be maintained as a relative path.
7626
#
7627
# Inputs          : elements        path to base
7628
#                                   These may be:
7629
#                                       --Up=xx
7630
#                                       name
7631
#
7632
# Returns         : Nothing
7633
#
7634
 
7635
#
7636
#   Allow the user to modify the project base variable
7637
#
7638
sub SetProjectBase
7639
{
7640
    my $rip = 0;
7641
    my $path = "";
7642
    my $is_relative;
7643
 
7644
    Debug("ProjectBase Initial: $ProjectBase, @_");
7645
 
7646
    #
7647
    #   Ensure that the ProjectBase is in a "nice" form
7648
    #   1) No /./ bits
7649
    #   2) No trailing /
7650
    #   3) Not equal to .
7651
    #   4) No training /.
7652
    #   5) No //
7653
    #
7654
    $ProjectBase =~ s~/\./~/~g;
7655
    $ProjectBase =~ s~/$~~g;
7656
    $ProjectBase =~ s~^\.$~~g;
7657
    $ProjectBase =~ s~/\.$~~g;
7658
    $ProjectBase =~ s~//$~/~g;
7659
 
7660
    #
7661
    #   ProjectBase may be absolute or relative
7662
    #   Determine this before we mess with it
7663
    #
7664
    $is_relative = ($ProjectBase !~ m~^/~);
7665
 
7666
    #
7667
    #   Process each argument
7668
    #
7669
    foreach ( @_ )
7670
    {
7671
        if ( /^--Up=([0-9]*)/ ) {
7672
            $rip = $1;
7673
        } elsif ( /^--/ ) {
7674
            Warning( "SetProjectBase - unknown option \"$_\" - ignored" );
7675
        } else {
7676
            $path = $_;
7677
        }
7678
    }
7679
 
7680
    #
7681
    #   Process the UP requests
7682
    #   If the tail directory is a ".." then up is done by adding another ".."
7683
    #   If the tail directory is not a "..", then up is done by removing it
7684
    #
7685
    #   If we go past the start of the path then simply add ".."
7686
    #
7687
    while ( $rip-- > 0 )
7688
    {
7689
        Debug2("ProjectBase: $ProjectBase, Up: $rip, IsRel: $is_relative");
7690
 
7691
        #
7692
        #   If ending in a /.. or is exactly equal to ..
7693
        #   Then its a dot-dot and the way to go UP is to append another ..
7694
        #
7695
        if ( $ProjectBase =~ m~(/\.\.$)|(^\.\.$)~ )
7696
        {
7697
            $ProjectBase .= '/..';
7698
        }
7699
        else
7700
        {
7701
            #
7702
            #   Not a dot-dot ending
7703
            #   Attempt to remove the last directory of the form
7704
            #       /xxxxx
7705
            #   Where the leading / is optional
7706
            #   Note: Must have at least one character in the dirname
7707
            #         This prevents leading / from matching - which is needed
7708
            #
7709
            unless ($ProjectBase =~ s~/?[^/]+$~~)
7710
            {
7711
                #
7712
                #   Removal failed
7713
                #   If a relative path then we can keep on going up,
7714
                #   otherwise we are dead.
7715
                #
7716
                Error ("ProjectBase outside project") unless ($is_relative);
7717
                $ProjectBase = '..';
7718
            }
7719
 
7720
            #
7721
            #   Ensure that the leading / in an absolute path is not deleted
7722
            #
7723
            $ProjectBase = '/'
7724
                unless ( $is_relative || $ProjectBase );
7725
        }
7726
    }
7727
 
7728
    #
7729
    #   Append the user path
7730
    #
7731
    $ProjectBase .= '/' . $path if ( $path );
7732
    $ProjectBase = '.' unless ( $ProjectBase );
7733
    Debug("ProjectBase set to : $ProjectBase");
7734
 
7735
    #
7736
    #   Once upon a time I tried to convert paths that contained spaces into
7737
    #   short (mangled) names. This was not sucessful because:
7738
    #       1) Clearcase dynamic views do not support name mangling
7739
    #       2) Samba file system does not appear to support name mangling
7740
    #
7741
    #   Spaces in paths are not good for MAKE
7742
    #   Now I simple generate a message
7743
    #
7744
    Warning( "ProjectBase contains a space: $ProjectBase")
7745
        if ( $ProjectBase =~ m/ / );
7746
 
7747
    #
7748
    #   Sanity check
7749
    #   Absolute paths can be checked easily
7750
    #   Checking of relative paths does not appear to work
7751
    #   When I tested it chdir, opendir and stat would limit themselves
7752
    #   and drop into the root directory ( under windows )
7753
    #
7754
    #   Solution: Check the path does not extend beyond the file tree
7755
    #
7756
    my $distance = 1;
7757
    my $tpath = $ProjectBase;
7758
 
7759
    if ( $is_relative && $tpath ne '.' )
7760
    {
7761
        #
7762
        #   Build up the complete pathname by merging it with the
7763
        #   current directory. Then clean it up.
7764
        #
7765
        $tpath = $::Cwd . '/' . $ProjectBase;
7766
 
7767
        #
7768
        #   Scan the list of diretories and count the distance from the root
7769
        #   This should not be greater than zero for sanity
7770
        #   Note: Get an empty elemement from the split due to
7771
        #         the leading / of the ABS path
7772
        #
7773
        $distance = 0;
7774
        foreach (  split ('/', $tpath) )
7775
        {
7776
            if ( m~\.\.~ )
7777
            {
7778
                $distance--;
7779
            }
7780
            else
7781
            {
7782
                $distance++;
7783
            }
7784
        }
7785
    }
7786
 
7787
    #
7788
    #   Warn if not a valid directory
7789
    #
7790
    Warning( "ProjectBase is not a directory: $ProjectBase")
7791
        if ( $distance <= 0 || !  -d $tpath  );
7792
 
7793
    #
7794
    #   $ProjectBase will always be a valid directory, but if its the top
7795
    #   directory (/) and it is added to a path we will get //path
7796
    #   This is not good, so // will be removed later in the AddIncDir and
7797
    #   AddSrcDir commands where $ProjectBase is really used.
7798
    #
7799
    #   Alternatively we could set $ProjectBase to an empty string, but then
7800
    #   this may be confused with an empty relative directory
7801
    #
7802
    Debug("ProjectBase Final  : $ProjectBase");
7803
}
7804
 
7805
#-------------------------------------------------------------------------------
7806
# Function        : DeployPackage
7807
#
7808
# Description     : Generate a deployed package
7809
#                   This is a gateway to a different packaging system
7810
#
7811
#                  DeployPackage and PackageXxxxx directives are mutually
7812
#                  exclusive. Only one person can play in the package area.
7813
#
7814
# Inputs          : Platform Specifier
7815
#                   Package Name    (Optional)
7816
#                   Options
7817
#                       --Name : Base name of the package. The default is taken
7818
#                                from the build.pl file
7819
#                       --Dir  : Package directory
7820
#                                The default is based on the package name
7821
#
7822
# Returns         :
7823
#
7824
sub DeployPackage
7825
{
7826
    my( $platforms, @elements ) = @_;
7827
    my $dir;
7828
    my $name;
7829
 
267 dpurdie 7830
    #
7831
    #   Flag that this build creates a deployable package, even if its not
7832
    #   active on this platform.
7833
    #
7834
    $DEPLOYPACKAGE = 1;
7835
 
7836
 
227 dpurdie 7837
    Debug2( "DeployPackage($platforms, @elements)" );
7838
    return if ( ! ActivePlatform($platforms) );
7839
 
7840
    #
7841
    #   Only allow one use of this directive
7842
    #
7843
    Error("DeployPackage can only be used once" ) if ( %DEPLOYPACKAGE );
267 dpurdie 7844
    $DEPLOYPACKAGE = 2;
227 dpurdie 7845
 
7846
    #
7847
    #   Ensure that the deployment file is available
7848
    #
7849
    my $command_file = $ScmDeploymentPatch ? "deploypatch.pl" : "deployfile.pl";
7850
    Error("DeployPackage: $command_file not found") unless (-f "./$command_file");
7851
    #
7852
    #   Collect arguments
7853
    #
7854
    foreach (@elements )
7855
    {
7856
        if ( m/^--Dir=(.*)/ ) {
7857
            Error ("DeployPackage: Package directory defined multiple times") if $dir;
7858
            $dir = $1;
7859
 
7860
        } elsif ( m/^--Name=(.*)/ ) {
7861
            Error ("DeployPackage: Package name defined multiple times") if $name;
7862
            $name = $1;
7863
 
7864
        } elsif ( m/^--/ ) {
7865
            Warning( "DeployPackage: Unknown option ignored: $_");
7866
 
7867
        } else {
7868
            Error ("DeployPackage: Package name defined multiple times") if $name;
7869
            $name = $_;
7870
 
7871
        }
7872
    }
7873
 
7874
    $name = $::ScmBuildPackage unless ( $name );
7875
 
7876
    #
7877
    #   Save the deployment data
7878
    #
7879
    $dir = lc($name) unless ( $dir );
7880
    $DEPLOYPACKAGE{'name'} = $name;
7881
    $DEPLOYPACKAGE{'dir'} = $dir;
7882
    $DEPLOYPACKAGE{'cmdfile'} = $command_file;
7883
 
7884
    #
7885
    #   Flag that toolset tests should be supressed
7886
    #   The Deploy world does not really use the full makefiles and if the
7887
    #   compilers are not installed will not be able to create deployment
7888
    #   packages
7889
    #
7890
    $ScmNoToolsTest = 1;
7891
}
7892
 
7893
 
7894
###############################################################################
7895
###############################################################################
7896
# Private function section.
7897
#       The following functions are used INTERNALLY by makelib.pl2.
7898
###############################################################################
7899
 
7900
###############################################################################
7901
#   A collection of functions to write to the MAKEFILE handle
7902
#
7903
#   MakeHeader          - Write a nice section header
7904
#   MakeNewLine         - Print a new line
7905
#   MakePrint           - Print a line ( without trailing \n)
7906
#   MakeQuote           - Escape \ and " character, then print a line
7907
#   MakePrintList       - Print an array
7908
#   MakeEntry           - Complex line printer
7909
#   MakePadded          - Padded line printer (internal)
7910
#   PadToPosn           - Calc space+tabs to tabstop (internal)
7911
#   MakeEntry3          - Complex Line Printer
7912
#   MakeDefEntry        - Print a definition line (Production + Debug support)
7913
#   MakeIfDefEntry      - Print ifdef entry
261 dpurdie 7914
#   MakeIfnDefEntry     - Print ifndef entry
7915
#   MakeIfZeroEntry     - Print ifeq entry
227 dpurdie 7916
#
7917
###############################################################################
7918
 
7919
sub MakeHeader
7920
{
7921
    my ($text, @rest) = @_;
7922
    my $length = length ($text);
7923
 
7924
    print MAKEFILE "\n";
7925
    print MAKEFILE "#--------- $text ", '-' x (80 - 12 - $length)  ,"\n";
7926
    print MAKEFILE "#    $_\n" foreach  ( @rest ) ;
7927
    print MAKEFILE "#\n";
7928
}
7929
 
7930
sub MakeNewLine         # Print a newline to the current 'Makefile'
7931
{
7932
    print MAKEFILE "\n";
7933
}
7934
 
7935
sub MakePrint           # Print to the current 'Makefile'
7936
{
7937
    print MAKEFILE @_
7938
        if ( defined $_[0] );
7939
}
7940
 
7941
sub MakeQuote           # Quote a makefile text line
7942
{
7943
    my( $line ) = @_;
7944
    $line =~ s/\\/\\\\/g;                       # quote all '\' characters
7945
    $line =~ s/"/\\"/g;                         # Then quote '"' characters
255 dpurdie 7946
    $line =~ s/=#/=\\#/g;                       # Then quote '=#' sequence
227 dpurdie 7947
    print MAKEFILE $line;
7948
}
7949
 
7950
sub MakePrintList
7951
{
7952
    print MAKEFILE $_ . "\n" foreach (@{$_[0]});
7953
}
7954
 
2429 dpurdie 7955
sub QuoteArray
7956
{
7957
    my $quote = "'";
7958
    if ( @_ ) {
7959
        return ($quote . join("$quote $quote", @_) . $quote);
7960
    }
7961
    return '';
7962
}
227 dpurdie 7963
 
7964
#-------------------------------------------------------------------------------
7965
# Function        : MakeEntry
7966
#
7967
# Description     : Build a entry based on the element list
7968
#                   Creates text of the form
7969
#                       $(BINDIR)/prog.exe: object1.obj \
7970
#                                           object2.obj
7971
#
7972
#
7973
# Inputs          : $prelim         - Preamble (one-off)
7974
#                   $postlim        - Postamble (one-off)
7975
#                   $prefix         - Pefix (to each element of array)
7976
#                   $postfix        - Postfix (to each element of array )
7977
#                   @elements       - Array of element to wrap
7978
#
7979
# Returns         :   1 Always
7980
#
7981
# Notes:
7982
#       The above description means that the following entry format is
7983
#       produced:
7984
#
7985
#           <preliminary><prefix><variant1><prefix><variant2>...<final>
7986
#
7987
#       With judicious use of newline and tab characters, a target
7988
#       and dependency list along with the command(s) to build the
7989
#       target can be constructed.
7990
#
7991
sub MakeEntry
7992
{
7993
    my( $prelim, $postlim, $prefix, $postfix, @elements ) = @_;
7994
 
7995
    MakePrint $prelim;
7996
    MakePrint "${prefix}${_}${postfix}" foreach ( @elements );
7997
    MakePrint $postlim if ($postlim);
7998
    return 1;
7999
}
8000
 
8001
#-------------------------------------------------------------------------------
8002
# Function        : MakePadded
8003
#
8004
# Description     : Generate aligned output of the form
8005
#                       Prefix_text           Aligned_text
8006
#                   where the aligned text is at a specified TAB boundary
8007
#
8008
# Inputs          : $align      - Tab stop (One tab = 8 chars)
8009
#                   $prefix     - Text to print before alignment occurs
8010
#                   @line       - Remainder of the line
8011
#
8012
sub MakePadded          # Print to the current 'Makefile', tab aligning
8013
{
8014
    my( $align, $prefix, @line ) = @_;
8015
 
8016
    my $strlen = length( $prefix );
8017
    my $pad = PadToPosn( $strlen, $align * 8 );
8018
 
8019
    print MAKEFILE $prefix . $pad;
8020
    print MAKEFILE @line;
8021
}
8022
 
8023
#-------------------------------------------------------------------------------
8024
# Function        : PadToPosn
8025
#
8026
# Description     : Given that we are at $startposn return a tab and space
8027
#                   string to place us at $endposn
8028
#
8029
sub PadToPosn
8030
{
8031
    my ($startposn, $endposn ) = @_;
8032
 
8033
 
8034
    #
8035
    #   Case where we are already too far into the line
8036
    #
8037
    return ( ' ' )if ( $endposn <= $startposn );
8038
 
8039
    my $tcount = 0;
8040
    my $scount = 0;
8041
 
8042
    while ( $startposn < $endposn )
8043
    {
8044
        $tcount ++;
8045
        $startposn = ($startposn >> 3) * 8 + 8;
8046
 
8047
        my $delta = $endposn - $startposn;
8048
        if ( $delta < 8 )
8049
        {
8050
            $scount = $delta;
8051
            last;
8052
        }
8053
 
8054
    }
8055
    return ( "\t" x $tcount .  ' ' x $scount );
8056
}
8057
 
8058
#-------------------------------------------------------------------------------
8059
# Function        : MakeEntry3
8060
#
8061
# Description     : Build a makefile entry based on the element list, tab aligned
8062
#                   Can creat text of the form:
8063
#                       TAG = NAME0 \       TAG : NAME0 \ 
8064
#                             NAME1               NAME1
8065
#
8066
#
8067
# Inputs          : $prelim             - Preliminary text
8068
#                   $presep             - Preliminary seperator
8069
#                   $elem_ref           - Either a single name or a reference to
8070
#                                         and array of names, or a hash.
8071
#
8072
# Returns         : Writes directly to the Makefile
8073
#
8074
sub MakeEntry3
8075
{
8076
    my( $prelim, $presep, $elem_ref ) = @_;
8077
 
8078
    #
8079
    #   The prelim may have some "\n" characters at the start
8080
    #   These simplify formatting, but mess up the nice formatting
8081
    #
8082
    if ($prelim =~ m~(^\n+)(.*)~ )
8083
    {
8084
        MakePrint $1;
8085
        $prelim = $2;
8086
    }
8087
 
8088
    #
8089
    #   Print the definition and the sep with nice padding
8090
    #
8091
    MakePadded ( 3, $prelim, $presep );
8092
    my $leadin = ' ';
8093
 
8094
    #
8095
    #   If a HASH reference then use a sorted list of keys from the hash.
8096
    #
8097
    if ( ref ($elem_ref) eq "HASH" )
8098
    {
8099
        my @hash_list;
8100
        @hash_list = sort keys ( %{$elem_ref} );
8101
        $elem_ref = \@hash_list;
8102
    }
8103
 
8104
    #
8105
    #   If the list is only one element long, then create a simple form
8106
    #   If the list is not an array ref, then treat it as a single element
8107
    #
8108
    if ( ref ($elem_ref) eq "ARRAY" )
8109
    {
8110
        my $line = 0;
8111
        foreach my $element ( @$elem_ref )
8112
        {
8113
            print MAKEFILE $leadin . $element;
8114
            $leadin = " \\\n" . PadToPosn(0,24 + length( $presep ) + 1 ) unless ($line++);
8115
        }
8116
    }
8117
    elsif ( defined $elem_ref )
8118
    {
8119
            print MAKEFILE $leadin . $elem_ref;
8120
    }
8121
    MakeNewLine();
8122
    return 1;
8123
}
8124
 
8125
#-------------------------------------------------------------------------------
8126
# Function        : MakeDefEntry
8127
#
8128
# Description     : Make a definition entry of the form
8129
#
8130
#                       TAG = NAME0 \
8131
#                             NAME1
8132
#
8133
#                   Support a list of definitions that will always be created
8134
#                   as well as a production and a debug list.
8135
#
8136
#                   Will always generate the "TAG = " string, even if the list
8137
#                   is empty.
8138
#
8139
#                   Will supress the TAG if there is no data if the FIRST opr starts with a '+'
8140
#
8141
# Inputs          : TAG         - Text tag to create
8142
#                   FIRST       - First assignement opr. = or +=
8143
#                   ALL_LIST    - A reference to a list of names to assign
8144
#                                 or a single name.
8145
#                   PROD_LIST   - Optional list to extend the definition with for a production build
8146
#                   DEBUG_LIST  - Optional list to extend the definition with for a debug build
8147
#
8148
# Returns         : Nothing
8149
#
8150
 
8151
sub MakeDefEntry
8152
{
8153
    my( $tag, $assign, $all, $prod, $debug ) = @_;
8154
 
8155
    #
8156
    #   Do not generate anything if the $opr is "+=" and there is no data
8157
    #   to output. ie: Supress empty TAG += statements
8158
    #
8159
    return if ( $assign =~ m/\+/ && ( ref($all) && ! defined $all->[0] ) );
8160
 
8161
    #
8162
    #   TAG for all entries
8163
    #
8164
    MakeEntry3( $tag, $assign, $all );
8165
 
8166
 
8167
    #
8168
    #   TAGs for PROD build
8169
    #   TAGs for DEBUG build
8170
    #
8171
    if ( defined $prod && defined $prod->[0] )
8172
    {
8173
        print MAKEFILE 'ifeq "$(DEBUG)" "0"' . "\n";
8174
        MakeEntry3( $tag, "+=", $prod );
267 dpurdie 8175
        print MAKEFILE 'endif' . "\n";
227 dpurdie 8176
    }
8177
 
8178
    if ( defined $debug && defined $debug->[0] )
8179
    {
8180
        print MAKEFILE 'ifeq "$(DEBUG)" "1"' . "\n";
8181
        MakeEntry3( $tag, "+=", $debug );
267 dpurdie 8182
        print MAKEFILE 'endif' . "\n";
227 dpurdie 8183
    }
8184
 
8185
}
8186
 
8187
sub MakeIfDefEntry
8188
{
8189
    my( $iftag, @rest ) = @_;
8190
 
8191
    print MAKEFILE "ifdef $iftag\n";
8192
    MakeDefEntry (@rest);
8193
    print MAKEFILE "endif\n\n";
8194
}
8195
 
8196
sub MakeIfnDefEntry
8197
{
8198
    my( $iftag, @rest ) = @_;
8199
 
8200
    print MAKEFILE "ifndef $iftag\n";
8201
    MakeDefEntry (@rest);
8202
    print MAKEFILE "endif\n\n";
8203
}
8204
 
261 dpurdie 8205
sub MakeIfZeroEntry
8206
{
8207
    my( $iftag, @rest ) = @_;
8208
 
8209
    print MAKEFILE "ifeq (\$($iftag),0)\n";
8210
    MakeDefEntry (@rest);
8211
    print MAKEFILE "endif\n\n";
8212
}
8213
 
227 dpurdie 8214
#-------------------------------------------------------------------------------
8215
# Function        : CreateNameList
8216
#
8217
# Description     : Create a list of names by adding a prefix and suffix to a
8218
#                   list of items. This is used to add a directory prefix and a
8219
#                   file suffix to a list of files.
8220
#
8221
# Inputs          : $prefix             ie: '$(OBJDIR)/'
8222
#                   $suffix             ie: '.obj'
8223
#                   $elem_ref           ie: A list of files ( passed be ref )
8224
#                                           If a Hash then its sorted keys is used
8225
#
8226
# Returns         : A ref to the resulting list
8227
#
8228
sub CreateNameList
8229
{
8230
    my( $prefix, $suffix, $elem_ref ) = @_;
8231
    my @result;
8232
 
8233
    if ( ref ($elem_ref) eq "HASH" )
8234
    {
8235
        my @hash_list;
8236
        @hash_list = sort keys ( %{$elem_ref} );
8237
        $elem_ref = \@hash_list;
8238
    }
8239
 
8240
    foreach  ( @$elem_ref )
8241
    {
8242
        push @result, $prefix . $_ . $suffix;
8243
    }
8244
    return \@result;
8245
}
8246
 
8247
#-------------------------------------------------------------------------------
8248
# Function        : ListGeneratedProjects
8249
#
8250
# Description     : Return a list of generated/nongenerated projects
8251
#                   Used in conjunction with CreateNameList
8252
#
8253
# Inputs          : $type       - TRUE : Generated
8254
#                                 FALSE: Not Generated
8255
#
8256
# Returns         : A reference to a list of projects
8257
#                   undef will be retuend if there are no projects
8258
#
8259
sub ListGeneratedProjects
8260
{
8261
    my ($type) = @_;
8262
    my @list;
8263
    foreach my $project ( @PROJECTS_ORDER )
8264
    {
8265
        if ( exists($PROJECTS{$project}->{'generated'}) xor $type )
8266
        {
8267
            push @list, $project;
8268
        }
8269
    }
8270
    return @list ? \@list : undef;
8271
}
8272
 
8273
#-------------------------------------------------------------------------------
8274
# Function        : ListCleanGenerated
8275
#
8276
# Description     : return a list of generated targets that have 'clean'
8277
#                   operations. This is used in conjunction with CreateNameList
8278
#
8279
# Inputs          : None
8280
#
8281
# Returns         : A list of project indexes, that can be cleaned
8282
#
8283
sub ListCleanGenerated
8284
{
8285
    my @list;
8286
    foreach my $i ( @GENERATE_FILES )
8287
    {
8288
        push @list, $i->{'index'}
8289
            if ( $i->{'clean'} );
8290
    }
8291
    return \@list;
8292
}
8293
 
251 dpurdie 8294
#-------------------------------------------------------------------------------
8295
# Function        : MakeResolve
8296
#
8297
# Description     : Internal Function
8298
#                   Locate a source file by examining a list of directories
8299
#
8300
#                   Don't use directly
8301
#                   Use MakeSrcResolve or MakeSrcResolveExtended
8302
#
8303
# Inputs          : $dirs           - Ref to an array of directories to scan
8304
#                   $source         - File to locate
8305
#
8306
# Returns         : Resolved path to the file
8307
#                   Will warn if multiple instances of the file are found
8308
#
227 dpurdie 8309
sub MakeResolve
8310
{
8311
    my( $dirs, $source ) = @_;
285 dpurdie 8312
    my( $first, $count );
227 dpurdie 8313
 
237 dpurdie 8314
    #
8315
    #   If the path contains a '$' then its assumed to be
8316
    #   a variable name in the path. Just assume that it exists
8317
    #
8318
    return $source if ( $source =~ m#\$# );
8319
 
8320
    #
8321
    #   If the path is absolute or contains a leading ., then don't search
8322
    #   Warn if it can't be found
8323
    #
8324
    if ( $source =~ m#^(/|\.)# )
8325
    {
8326
        Warning( "Unable to resolve '$source' path" ) unless -f $source;
8327
        return $source;
227 dpurdie 8328
    }
8329
 
6276 dpurdie 8330
    my @found;
8331
    # Search the local path first
8332
    push (@found, $source ) if -f ($source);
237 dpurdie 8333
 
285 dpurdie 8334
    foreach my $dir (@$dirs)
227 dpurdie 8335
    {
331 dpurdie 8336
        next if ( $dir eq '.' );
6276 dpurdie 8337
        my $temp = $dir . '/' . $source;
227 dpurdie 8338
        Debug2( "MakeResolve: Looking in: $temp" );
6276 dpurdie 8339
        push (@found, $temp) if (-f $temp);
227 dpurdie 8340
    }
8341
 
6276 dpurdie 8342
    Warning( "Unable to resolve path to '$source'" ) unless $found[0];
8343
    if (scalar @found > 1)
8344
    {
8345
        Warning("Duplicates for '$source'. Using the first", @found);
227 dpurdie 8346
    }
6276 dpurdie 8347
 
8348
    return $found[0] || "";
227 dpurdie 8349
}
8350
 
251 dpurdie 8351
#-------------------------------------------------------------------------------
8352
# Function        : MakeSrcResolve
8353
#
8354
# Description     : Locate a source file by examining the list of source
8355
#                   directories. There are a few frills
8356
#
8357
#                   Look for a source file in
8358
#                       1) %::BUILD_KNOWNFILES
8359
#                       2) %SRCS
8360
#                       3) Dirs specified by the array @SRCSDIRS
8361
#
8362
# Inputs          : Name of a file to resolve
8363
#
8364
# Returns         : Resolved path.
283 dpurdie 8365
#                   Input file - if not found at all
251 dpurdie 8366
#
227 dpurdie 8367
sub MakeSrcResolve
8368
{
8369
    my ($name) = @_;
8370
    my $file;
8371
 
251 dpurdie 8372
    if ( exists ( $::BUILD_KNOWNFILES{$name} ) ) {
8373
        #
8374
        #   The Known Files list is relative to ScmRoot
8375
        #   This must be included in the full path
8376
        #
8377
        $file = $ScmRoot . '/' . $::BUILD_KNOWNFILES{$name};
8378
 
8379
    } elsif ( exists $SRCS{$name} ) {
8380
        $file = $SRCS{$name};
8381
 
8382
    } else {
8383
        $file = MakeResolve( \@SRCDIRS, @_ )
8384
    }
227 dpurdie 8385
    return $file;
8386
}
8387
 
8388
 
8389
# MakeSrcResolveExtended
8390
#   from_global = 0 : Search user specified directories
8391
#               = 1 : Search LinkPkgArchive list
8392
#
8393
our @PkgSrcDirList;
8394
sub MakeSrcResolveExtended
8395
{
8396
    my ( $from_global, $file ) = @_;
8397
 
8398
    #
8399
    #   Simple Case. Resolve source from known source directories
8400
    #
8401
    #
8402
    return MakeSrcResolve( $file )
8403
        unless ( $from_global );
8404
 
8405
    #
8406
    #   Not so simple Case
8407
    #   Resolve the source from the imported packages
8408
    #
8409
    #   Create a list of directores to search, but only the first time
311 dpurdie 8410
    #       - Interface directories - from BuildPkgArchive
227 dpurdie 8411
    #       - LnkPkgArchive directories
8412
    #         Using target,product,platform include directories
8413
    #
8414
    unless ( @PkgSrcDirList )
8415
    {
8416
        for my $entry (@{$::ScmBuildPkgRules{$ScmPlatform} })
8417
        {
311 dpurdie 8418
            next if ( $entry->{'TYPE'} eq 'build' ); # Ignore BuildPkgArchives
8419
 
227 dpurdie 8420
            for (@{$entry->{'PINCDIRS'}}, @{$entry->{'THXDIRS'}}, '' )
8421
            {
8422
                my $dir = $entry->{'ROOT'} . "/" . $_ ;
8423
                $dir =~ s~//~/~g;
8424
                $dir =~ s~/$~~;
311 dpurdie 8425
                push ( @PkgSrcDirList, $dir );
227 dpurdie 8426
            }
8427
        }
311 dpurdie 8428
    }
227 dpurdie 8429
 
8430
    return MakeResolve( \@PkgSrcDirList, $file );
8431
}
8432
 
8433
#-------------------------------------------------------------------------------
8434
# Function        : GetPackageRoot
8435
#
8436
# Description     : Determine the root directory for a given package
8437
#                   This routine is intended for non-standard JATS scripts that
8438
#                   access package contents directly
8439
#
8440
#                   Note: This routine does not attempt to handle multiple
8441
#                         instances of a package ( sysbasetypes ).
8442
#
8443
# Inputs          : $pname          - Name of the package
8444
#
8445
# Returns         :
8446
#
8447
sub GetPackageRoot
8448
{
8449
    my( $pname ) = @_;
8450
    Debug( "GetPackageRoot(@_)" );
8451
 
8452
    my $result = undef;
8453
    my $pkg = GetPackageEntry( $pname );
8454
    if ( $pkg )
8455
    {
8456
        $result = $pkg->{'ROOT'};
8457
        Debug( "GetPackageRoot: $result" );
8458
    }
8459
 
8460
    return $result;
8461
}
8462
 
8463
#-------------------------------------------------------------------------------
8464
# Function        : ActiveProject
8465
#
8466
# Description     : Determine if the specified project is currenly 'active'
8467
#
345 dpurdie 8468
# Inputs          : $project            - one or more project names separated
8469
#                                         by either a comma or a colon
227 dpurdie 8470
#
8471
# Returns         : TRUE    if the project is active
8472
#
8473
sub ActiveProject
8474
{
8475
    my ($project) = @_;
345 dpurdie 8476
    foreach (  split( '\s*[:,]\s*', $project ) )
227 dpurdie 8477
    {
8478
        return 1
8479
            if ( $_ eq $::ScmBuildProject );
8480
    }
8481
    return 0;
8482
}
8483
 
345 dpurdie 8484
#-------------------------------------------------------------------------------
8485
# Function        : ActiveDefine
8486
#
8487
# Description     : Determine if the specified definition is currenly 'active'
8488
#
8489
# Inputs          : $defs               - one or more variable names separated
8490
#                                         by either a comma or a colon
8491
#
8492
# Returns         : TRUE    if any of the definitions are known
8493
#
8494
sub ActiveDefine
8495
{
8496
    my ($defs) = @_;
8497
    no strict 'refs';
8498
    foreach (  split( '\s*[:,]\s*', $defs ) )
8499
    {
8500
        return 1
4455 dpurdie 8501
            if ( defined( $$_ ) || ( @$_ ) );
345 dpurdie 8502
    }
8503
    use strict 'refs';
8504
    return 0;
8505
}
227 dpurdie 8506
 
8507
#-------------------------------------------------------------------------------
345 dpurdie 8508
# Function        : ActiveMachType
8509
#
8510
# Description     : Determine if the specified MachType is currenly 'active'
8511
#
8512
# Inputs          : $mtype              - one or more machine names separated
8513
#                                         by either a comma or a colon
8514
#
8515
# Returns         : TRUE    if any of the current MachType is in the list
8516
#
8517
sub ActiveMachType
8518
{
8519
    my ($mtype) = @_;
8520
    foreach (  split( '\s*[:,]\s*', $mtype ) )
8521
    {
8522
        return 1
8523
            if ( uc($_) eq uc($::GBE_MACHTYPE) );
8524
    }
8525
    return 0;
8526
}
8527
 
8528
#-------------------------------------------------------------------------------
6133 dpurdie 8529
# Function        : ActiveAlias
8530
#
8531
# Description     : Determine if the specified Alias is currenly 'active'
8532
#
8533
# Inputs          : $mtype              - one or more alias names separated
8534
#                                         by either a comma or a colon
8535
#
8536
# Returns         : TRUE    if any of the current Aliases is in the list
8537
#
8538
sub ActiveAlias
8539
{
8540
    my ($mtype) = @_;
8541
    foreach (  split( '\s*[:,]\s*', $mtype ) )
8542
    {
8543
        return 1
8544
            if ( isAnAlias( uc($_) ) );
8545
    }
8546
    return 0;
8547
}
8548
 
8549
 
8550
#-------------------------------------------------------------------------------
227 dpurdie 8551
# Function        : ActivePlatform
8552
#
8553
# Description     : Determine if the specified platform is currently 'active'
8554
#                   This is used by all user directives in order to determine
8555
#                   if the directive should be ignored for the current platform
8556
#
8557
# Inputs          : $platform_spec      - A platform specifier
8558
#                                         This is a bit complex.
8559
#
241 dpurdie 8560
#                   Format of platform_spec. One or more of
8561
#                       PlatformName
8562
#                       AliasName
6133 dpurdie 8563
#                       TargetName[,--Target]
345 dpurdie 8564
#                   Special Options (Must all be True)
8565
#                       --Project=ProjectName[:ProjectName]+
8566
#                       --Defined=SomeValue[:SomeValue]+
6133 dpurdie 8567
#                       --MachType=SomeMachType[:SomeMachType]+
8568
#                       --Alias=SomeAlias[:SomeAlias]+
8569
#                   Some shortcuts
8570
#                       '*'     ==> Always true
8571
#
345 dpurdie 8572
#                   Each can be prefixed with a '!' to negate the test
6133 dpurdie 8573
#                   
8574
#                   PlatformNames are either additive or negative(prefixed with !)
8575
#                       Order is not important                   
8576
#                       All additive names are accumulated before the negative items are considered.
8577
#                           ie: aa,!bb => !bb,aa
8578
#                       If only negative names are provided then JATS assumes a leading '*'
8579
#                           ie: !aaa => *,!aaa
8580
#                   
241 dpurdie 8581
#                   Valid options are:
271 dpurdie 8582
#                       --Target        - indicates that the platform is a 'target'
241 dpurdie 8583
#
8584
# Returns         : TRUE if the platform spec is satisfied
8585
#
227 dpurdie 8586
sub ActivePlatform
8587
{
8588
    my( $platform_spec ) = @_;
8589
    my( @platforms, $scmplatform, $platform );
6133 dpurdie 8590
    my( %arguments, @args );
241 dpurdie 8591
    my @plist;
227 dpurdie 8592
 
241 dpurdie 8593
    #
8594
    #   Short circuit check
6133 dpurdie 8595
    #       '*' is used so often that it pays to check it first
241 dpurdie 8596
    #
8597
    if ( $platform_spec eq '*' )
8598
    {
8599
        Debug3( " ActivePlatform(@_) = TRUE" );
8600
        return 1;
8601
    }
227 dpurdie 8602
 
241 dpurdie 8603
    #
8604
    #   Platform specifier may be a comma seperated list
8605
    #   ie:  WIN32,MOS,XXX
8606
    #   Extract non-platform arguments
279 dpurdie 8607
    #   Process to yield a dummy platform of '0' or '1' - these will be seen later
241 dpurdie 8608
    #
8609
    foreach ( split( '\s*,\s*', $platform_spec ) )
8610
    {
345 dpurdie 8611
        my ($result, $not);
8612
        if ( m~^(!?)--Project=(.+)~ ) {
325 dpurdie 8613
            $not = $1;
345 dpurdie 8614
            $result = ActiveProject($2);
277 dpurdie 8615
 
345 dpurdie 8616
        } elsif ( m~^(!?)--Defined=(.+)~ ) {
325 dpurdie 8617
            $not = $1;
345 dpurdie 8618
            $result = ActiveDefine($2);
241 dpurdie 8619
 
345 dpurdie 8620
        } elsif ( m~^(!?)--MachType=(.+)~ ) {
325 dpurdie 8621
            $not = $1;
345 dpurdie 8622
            $result = ActiveMachType($2);
8623
 
6133 dpurdie 8624
        } elsif ( m~^(!?)--Alias=(.+)~ ) {
8625
            $not = $1;
8626
            $result = ActiveAlias($2);
8627
 
325 dpurdie 8628
        } else {
8629
            #
8630
            #   Must be a platform argument
8631
            #   Add to a list
8632
            #
8633
            push @platforms, $_;
241 dpurdie 8634
            next;
8635
        }
8636
 
8637
        #
325 dpurdie 8638
        #   Continue processing non-platform arguments
345 dpurdie 8639
        #   Each one must be TRUE, allowing for negation.
241 dpurdie 8640
        #
325 dpurdie 8641
        $result = $result ? 1 : 0;
345 dpurdie 8642
        $result = ! $result if ( $not );
8643
        return 0 unless ( $result );
241 dpurdie 8644
    }
8645
 
4128 dpurdie 8646
    #
8647
    #   If we have no platforms then the test was purely non-platform arguments.
8648
    #
6133 dpurdie 8649
    if ($platform_spec ne '' && ! @platforms) {
8650
        Debug3( " ActivePlatform(@_ == $ScmPlatform) = TRUE" );
4128 dpurdie 8651
        return 1;
8652
    }
8653
 
6133 dpurdie 8654
    unless (@platforms) {
8655
        Debug3( " ActivePlatform(@_ == $ScmPlatform) = FALSE" );
8656
        return 0;
8657
    }
8658
 
8659
 
241 dpurdie 8660
    #   Platform specified may be an Alias
8661
    #   Perform alias expansion
8662
    #
8663
    @platforms = ExpandPlatforms( @platforms );         # aliasing
227 dpurdie 8664
    Debug3( " ActivePlatform(@_)" );
6198 dpurdie 8665
#    Debug0( " Platforms(@platforms)" );
227 dpurdie 8666
 
8667
#.. Arguments
241 dpurdie 8668
#   At this point we have a list of platforms and arguments
8669
#   Build up a hash of arguments for each platform being parsed
227 dpurdie 8670
#   Multiple arguments can follow a platform name
241 dpurdie 8671
#   Arguments apply to the preceeding platform name
227 dpurdie 8672
#
241 dpurdie 8673
    $platform = undef;
227 dpurdie 8674
    foreach ( @platforms )
8675
    {
241 dpurdie 8676
        if ( /^--Target/ ) {                     # Arguments
8677
            if ( $platform ) {
8678
                $arguments{$platform}{'Target'} = 1;
8679
            } else {
317 dpurdie 8680
                Warning ("No Platform preceding platform option: $_");
241 dpurdie 8681
            }
8682
 
305 dpurdie 8683
        } elsif ( /^--Only(Prod)|(Debug)/ || /--board=/ ) {
273 dpurdie 8684
            # Known arguments
305 dpurdie 8685
            # Bit of a kludge. Must be a better way
273 dpurdie 8686
 
241 dpurdie 8687
        } elsif ( /^--/ ) {
8688
            Warning ("Unknown platform option: $_");
8689
 
227 dpurdie 8690
        } else {                                # Target
8691
            $platform = $_;
241 dpurdie 8692
            push @plist, $platform;
227 dpurdie 8693
        }
8694
    }
8695
 
241 dpurdie 8696
#.. Scan the expression
227 dpurdie 8697
#
6198 dpurdie 8698
    $scmplatform = uc( $ScmPlatform );              # current platform
6133 dpurdie 8699
    my @add;
8700
    my @remove;
8701
    foreach ( @plist ) {
6198 dpurdie 8702
        my $platform = uc( Trim( $_ ) );            # trim white and convert case
6133 dpurdie 8703
        my $pname = $platform;
8704
        my $invert = 0;
8705
        if (substr($platform, 0, 1) eq '!') {
8706
            $invert = 1;
8707
            $pname = substr($platform, 1)
8708
        }
325 dpurdie 8709
 
227 dpurdie 8710
        #
241 dpurdie 8711
        #   Determine filter comparison
6133 dpurdie 8712
        #       Either a Platform or a Target
241 dpurdie 8713
        #
6133 dpurdie 8714
        if ( $arguments{$platform}{'Target'} ) {
8715
            $pname = $scmplatform if ($pname eq  uc( $ScmTarget ));
227 dpurdie 8716
        }
241 dpurdie 8717
 
6133 dpurdie 8718
        #
8719
        #   Catch some historically bad practices
8720
        #
8721
        $pname = $scmplatform if ( $pname eq '*'  || $pname eq '1' ); 
227 dpurdie 8722
 
6133 dpurdie 8723
        Debug3( "   Platform=$platform, PName=$pname" );
8724
 
227 dpurdie 8725
        #
8726
        #   Examine platform names
6133 dpurdie 8727
        #   Allow negation (removal) of the name
227 dpurdie 8728
        #
6133 dpurdie 8729
        if ( substr($platform, 0, 1) eq '!' )  {
8730
            push @remove, $pname; 
8731
        } else {
8732
            push @add, $pname; 
227 dpurdie 8733
        }
8734
    }
8735
 
241 dpurdie 8736
    #
6133 dpurdie 8737
    #   Build complete list of allowed platforms
8738
    #       Process additive rules before removal rules
8739
    #       If there are no additive rules, then assume all protaforms
241 dpurdie 8740
    #
6133 dpurdie 8741
    my %calcList;
8742
    @add = @::BUILDPLATFORMS unless @add;
6204 dpurdie 8743
    $calcList{uc $_} = 1 foreach (@add);
8744
    delete $calcList{uc $_} foreach (@remove);
6133 dpurdie 8745
#DebugDumpData("Add", \@add);
8746
#DebugDumpData("Remove", \@remove);
8747
#DebugDumpData("calcList", \%calcList);
241 dpurdie 8748
 
8749
    #
6133 dpurdie 8750
    #   If the current build target is left in the platform list, then we are building for it
8751
    #   
6198 dpurdie 8752
    if (exists $calcList{$scmplatform}) {
227 dpurdie 8753
        Debug3( " ActivePlatform(@_ == $ScmPlatform) = TRUE" );
8754
        return 1;
8755
    }
241 dpurdie 8756
 
227 dpurdie 8757
    Debug3( " ActivePlatform(@_ == $ScmPlatform) = FALSE" );
8758
    return 0;
8759
}
8760
 
8761
#-------------------------------------------------------------------------------
321 dpurdie 8762
# Function        : If
8763
#
8764
# Description     : Function for embedding arguments in directives
8765
#                   To be used within another directive
8766
#                   ie:
8767
#                       AnyDirective ('*',  arg1, arg2, ...
8768
#                                           If (SomePlatform, arg1, .. ,argn))
8769
#
8770
# Inputs          : $platform               - Active Platform speciifier
8771
#                   @args                   - Args
8772
#
8773
# Returns         : @args or nothing
8774
#
8775
sub  If
8776
{
8777
    my $platform = shift;
8778
    return @_
8779
        if ( ActivePlatform( $platform ));
8780
    return;
8781
}
8782
 
8783
#-------------------------------------------------------------------------------
227 dpurdie 8784
# Function        : RegisterMakefileGenerate
8785
#
8786
# Description     : Register a function to be called at the start of the
8787
#                   makefile generation process
8788
#
8789
# Inputs          : $fname      - Name of the function
8790
#                   $args       - Function Arguments
8791
#
8792
# Returns         : Nothing
8793
#
8794
our @MF_Generators;
8795
sub RegisterMakefileGenerate
8796
{
8797
   my ($fref) = @_;
8798
   my $rtype = ref($fref) || 'not a reference';
8799
 
8800
   Error ("RegisterMakefileGenerate called incorrectly",
8801
          "First argument MUST be a code reference",
8802
          "It is a $rtype"
8803
          ) unless ( $rtype eq 'CODE' );
8804
 
8805
   #
8806
   #    Save the arguments by reference in an array
8807
   #    The array will be processed later
8808
   #
8809
   push @MF_Generators, \@_;
8810
}
8811
 
8812
#-------------------------------------------------------------------------------
271 dpurdie 8813
# Function        : RegisterSrcHook
8814
#
8815
# Description     : Register a function to be called when a source file is
8816
#                   declared
8817
#
8818
# Inputs          : $ext        - Extension of interest
8819
#                                 '*' will be used by all
8820
#                   $fname      - Name of the function
8821
#                   $args       - Function Arguments
8822
#
8823
# Returns         : Nothing
8824
#
8825
sub RegisterSrcHook
8826
{
8827
    my $ext = shift;
8828
    my ($fref) = @_;
8829
    my $rtype = ref($fref) || 'not a reference';
8830
 
8831
    Error ("RegisterSrcHook called incorrectly",
8832
           "Second argument MUST be a code reference",
8833
           "It is a $rtype"
8834
           ) unless ( $rtype eq 'CODE' );
8835
 
8836
    #
8837
    #    Save the arguments by reference in an array
8838
    #    The array will be processed later
8839
    #
8840
    push @{$MF_RegisterSrcHooks{$ext}}, \@_;
8841
}
8842
 
8843
 
8844
#-------------------------------------------------------------------------------
227 dpurdie 8845
# Function        : MakefileHeader
8846
#
8847
# Description:    : Generate a "standard" makefile header.
8848
#
8849
#..
8850
 
8851
sub MakefileHeader
8852
{
8853
    my ($file, $desc, $by, @trailing) = @_;
8854
    my ($diff);
8855
 
8856
    $diff = 0 if (($diff = ((80-5) - length($desc))) < 0);
8857
    $desc .= ' ' . ('-' x $diff);
8858
 
8859
    print $file <<EOF;
8860
#-- $desc
8861
#
8862
#                   -- Please do not edit this file. --
8863
#
8864
#       To do so may result in a system failure, in additional to any
8865
#       changes made shall be overwritten.
8866
#
8867
# Created by $by
8868
#         on $::CurrentTime
8869
#
8870
EOF
8871
    #
8872
    #   Print out the trailer
8873
    #   This is an array. Place each entry on a new line
8874
    #
8875
    print $file $_ . "\n" for ( @trailing );
8876
}
8877
 
8878
###############################################################################
8879
# MakeFileGenerate:
8880
#       This subroutine does all of the actual make file generation based
8881
#       on information provided in the calls to the various public
8882
#       interface routines.
8883
#
8884
# Inputs:
8885
#
8886
# Returns:
8887
###############################################################################
8888
 
8889
my $MakefileGenerate_once = 0;
8890
sub MakefileGenerate
8891
{
8892
    my $Makefile = "$ScmPlatform.mk";
8893
    Debug( "MakefileGenerate: $Makefile" );
8894
 
8895
    #
8896
    #   Nasty things happen when we generate a makefile twice
8897
    #   Just warn the user and do nothing
8898
    #   If its in the common makefile.pl then just ignore it
8899
    #
8900
    if ( $ScmProcessingRootMake )
8901
    {
8902
        Warning ("MakefileGenerate directive is not allowed in common makefile.pl");
8903
        return;
8904
    }
8905
 
8906
    if ( $MakefileGenerate_once )
8907
    {
8908
        Warning ("MakefileGenerate should only be called once.",
8909
                 "Dir: $::Cwd");
8910
        return;
8911
    }
8912
    $MakefileGenerate_once = 1;
8913
 
8914
    #
8915
    #   Invoke all registered Makefile Generator functions
8916
    #   These allow clever directives to collect information to be
8917
    #   processed before the makefiles are created
8918
    #
8919
    while ( @MF_Generators )
8920
    {
8921
        Debug( "MakefileGenerate: Invoke RegisterMakefileGenerate function" );
8922
        my ($fname, @args) = @{shift @MF_Generators};
8923
        &$fname ( @args );
8924
    }
8925
 
8926
    #
8927
    #   Allow the toolset the opportunity to process all the collected data
8928
    #   before the makefile is created. This is optional
8929
    #
8930
    my( $if ) = MakeIf::Factory();              # build interface
8931
    $if->Preprocess();
8932
 
8933
    #
343 dpurdie 8934
    #   If we have supressed the Toolset use, then we need to sanity test
8935
    #   the use of the toolset
8936
    #
8937
    if ( $ScmNoToolsTest )
8938
    {
8939
        ReportError ("Building programs not supported with --NoToolset") if ( @PROGS || @TESTPROGS );
8940
        ReportError ("Building libraries not supported with --NoToolset") if ( @LIBS || @MLIBS || @SHLIBS );
8941
        ReportError ("Building projects not supported with --NoToolset") if ( %PROJECTS );
8942
        ErrorDoExit();
8943
    }
8944
 
8945
    #
227 dpurdie 8946
    #   Auto package the 'descpkg' file
8947
    #   If this makefile packages any files, then it can also package the descpkg file
8948
    #   The descpkg will be piggybacked into all makefiles that do a package
8949
    #
8950
    if ( %PACKAGE_FILES || %PACKAGE_HDRS || %PACKAGE_CLSS || %PACKAGE_LIBS
6387 dpurdie 8951
                        || %PACKAGE_SHLIBS || %PACKAGE_PROGS || @PACKAGE_DIRS )
227 dpurdie 8952
    {
251 dpurdie 8953
        Src ('*', 'descpkg') unless ($SRCS{ descpkg });
8954
        PackageFile ('*', 'descpkg');
227 dpurdie 8955
    }
8956
 
8957
    #
8958
    #   Some toolsets NEED a relative root
261 dpurdie 8959
    #   Note: At the moment ScmRoot is relative anyway, thus this code
8960
    #         does nothing
227 dpurdie 8961
    #
8962
    my $gbe_root = $::ScmRoot;
8963
    if ( $::UseRelativeRoot )
8964
    {
8965
        $gbe_root =  RelPath( $::ScmRoot );
8966
    }
8967
 
8968
    #
8969
    #   Now start to create the makefile
8970
    #
6133 dpurdie 8971
    ToolsetFiles::AddFile($Makefile);
285 dpurdie 8972
    open( MAKEFILE, '>', $Makefile ) || Error( "Cannot create $Makefile" );
227 dpurdie 8973
    ::MakefileHeader( *MAKEFILE,
8974
                      'Auto-generated Platform Dependent Makefile',
8975
                      "$ScmMakelib (version $ScmVersion)",
6177 dpurdie 8976
                      "# COPYRIGHT - VIX IP PTY LTD (\"VIX\"). ALL RIGHTS RESERVED.",
227 dpurdie 8977
                      '#',
8978
                      "# Located in $::Cwd",
8979
                      "# Platform $::ScmPlatform",
8980
                      '#' . ('-' x 79),
8981
                      );
8982
 
8983
    #
8984
    #   Ensure that some essential variables are set
8985
    #
8986
    print MAKEFILE <<EOF;
8987
#
8988
#   Validate essential environment variables
8989
#
8990
ifndef GBE_BIN
8991
    \$(error ERROR: GBE_BIN is not available)
8992
endif
8993
ifndef GBE_PERL
8994
    \$(error ERROR: GBE_PERL is not available)
8995
endif
8996
ifndef DEBUG
8997
    \$(error ERROR: DEBUG is not defined)
8998
endif
8999
EOF
9000
 
9001
 
9002
    print MAKEFILE <<EOF;
9003
 
9004
#
9005
#   Basic definitions
9006
#
343 dpurdie 9007
GBE_ROOT      := $gbe_root
9008
GBE_ROOT_ABS  := \$(abspath \$(GBE_ROOT))
9009
GBE_HOST      := $::ScmHost
9010
GBE_HOSTMACH  := $::GBE_MACHTYPE
9011
GBE_TARGET    := $::ScmTarget
9012
GBE_MACHTYPE  := $::ScmMachType
9013
GBE_PLATFORM  := $::ScmPlatform
9014
GBE_PBASE     := $::Pbase
9015
GBE_TYPE      := \$(if \$(findstring 1,\$(DEBUG)),D,P)
227 dpurdie 9016
EOF
9017
 
343 dpurdie 9018
MakePrint( "GBE_ARGS      := @ScmPlatformArgs\n" )
227 dpurdie 9019
    if ( scalar @ScmPlatformArgs );
9020
 
343 dpurdie 9021
MakePrint( "GBE_PRODUCT   := $ScmProduct\n" )
227 dpurdie 9022
    if ( $ScmProduct ne "" );
9023
 
343 dpurdie 9024
MakePrint( "GBE_OS_COMMON := $::BUILDINFO{$ScmPlatform}{OS_COMMON}\n" )
227 dpurdie 9025
    if ( exists($::BUILDINFO{$ScmPlatform}{OS_COMMON}) );
9026
 
9027
    print MAKEFILE <<EOF;
9028
 
9029
SHELL           := \$(GBE_BIN)/sh
9030
SHELLARGS       :=
9031
EXTENDED_LINE   := \$(GBE_BIN)/extend.lst
9032
export EXTENDED_LINE MAKE
9033
 
343 dpurdie 9034
MFLAGS           := --no-print --warn -r
9035
BUILDNAME        := $::ScmBuildName
9036
BUILDVER         := $::ScmBuildVersionFull
9037
BUILDVERNUM      := $::ScmBuildVersion
227 dpurdie 9038
BUILDPREVIOUSVER := $::ScmBuildPreviousVersion
343 dpurdie 9039
DEPLOYPATCH      := $ScmDeploymentPatch
9040
GBE_NOTOOLSTEST  := $ScmNoToolsTest
4781 dpurdie 9041
MAKEFILEUID      := $ScmMakeUid
9042
export MAKEFILEUID
227 dpurdie 9043
 
9044
#
9045
#   Ensure PWD is correctly set
9046
#
9047
PWD             := \$(CURDIR)
9048
export PWD
9049
 
261 dpurdie 9050
#
9051
#   NODEPEND    - Used to suppress generated dependency file checking
9052
#                 Mostly done in jmake.pl
9053
#   EXPERT      - Used to suppress dependency on this makefile
9054
#
9055
EOF
9056
 
285 dpurdie 9057
MakePrint( "EXPERT\t\t?= " . ($ScmExpert ? '1' : '0' ) . "\n" );
9058
MakePrint( "NODEPEND\t?= 0\n" );
261 dpurdie 9059
 
9060
print MAKEFILE <<EOF;
9061
 
9062
#
9063
#   SCM_MAKEFILE - The name of the file to depend upon
9064
#                  Supressed in EXPERT mode
9065
#
9066
ifneq (\$(EXPERT),0)
9067
SCM_MAKEFILE	:=
9068
else
9069
SCM_MAKEFILE	:= $Makefile
9070
endif
9071
EOF
9072
 
267 dpurdie 9073
#
9074
#   Setup the base directory for the packaging process
9075
#   When building a deployable package the base directory is changed to match
9076
#   that used by the deployment world. This is done so that the descpkg file
9077
#   can be created in the correct location
9078
#
9079
my  $PKGDIR = "pkg/$::Pbase";
9080
    $PKGDIR = "build/deploy" if ( $DEPLOYPACKAGE );
9081
Verbose("Setting PKGDIR: $PKGDIR");
9082
 
261 dpurdie 9083
print MAKEFILE <<EOF;
9084
 
227 dpurdie 9085
#--------- Targets -------------------------------------------------------------
9086
 
9087
.PHONY: 	default all build install package unpackage uninstall \\
9088
		clean unbuild clobber deploy
9089
 
373 dpurdie 9090
default:
227 dpurdie 9091
all:		install package deploy
9092
build:		make_init generate install_hdr depend make_lib \\
6387 dpurdie 9093
		install_lib make_install_shlib make_prog install_class install_dirs
227 dpurdie 9094
install:	build install_prog
6387 dpurdie 9095
package:	package_dirs package_files package_hdr package_lib package_shlib \\
9096
		package_prog package_class
227 dpurdie 9097
unpackage:	unpackage_class unpackage_prog unpackage_shlib \\
6387 dpurdie 9098
		unpackage_lib unpackage_hdr unpackage_files unpackage_dirs 
9099
uninstall:	uninstall_dirs uninstall_class uninstall_prog uninstall_shlib \\
227 dpurdie 9100
		uninstall_lib uninstall_hdr
9101
clean:		make_clean unmake_prog unmake_test unmake_lib unobj \\
261 dpurdie 9102
		undepend ungenerate rmlitter unmake_dir
227 dpurdie 9103
unbuild:	clean uninstall
9104
clobber:	unpackage unbuild
9105
deploy:		install run_deploy
9106
 
9107
#--------- Macros --------------------------------------------------------------
9108
 
9109
OBJDIR		= \$(GBE_PLATFORM)\$(GBE_TYPE).OBJ
9110
LIBDIR		= \$(GBE_PLATFORM).LIB
9111
BINDIR		= \$(GBE_PLATFORM)\$(GBE_TYPE).BIN
9112
CLSDIR		= classes\$(GBE_TYPE)
9113
 
267 dpurdie 9114
PKGDIR		= \$(GBE_ROOT)/$PKGDIR
227 dpurdie 9115
INCDIR_PKG	= \$(PKGDIR)/include
9116
LIBDIR_PKG	= \$(PKGDIR)/lib
9117
BINDIR_PKG	= \$(PKGDIR)/bin
9118
CLSDIR_PKG	= \$(PKGDIR)/classes
4996 dpurdie 9119
UTFDIR_PKG	= \$(GBE_ROOT_ABS)/$PKGDIR/utfResults
227 dpurdie 9120
 
9121
LOCALDIR	= \$(GBE_ROOT)/local
9122
INCDIR_LOCAL	= \$(LOCALDIR)/inc
9123
LIBDIR_LOCAL	= \$(LOCALDIR)/lib
9124
BINDIR_LOCAL	= \$(LOCALDIR)/bin
9125
CLSDIR_LOCAL	= \$(LOCALDIR)/classes
9126
BINDIR_LOCAL_PATH = \$(GBE_ROOT_ABS)/local/bin/\$(GBE_PLATFORM)\$(GBE_TYPE)
9127
 
9128
INTERFACEDIR	= \$(GBE_ROOT)/$ScmInterface
9129
INCDIR_INTERFACE= \$(INTERFACEDIR)/include
9130
LIBDIR_INTERFACE= \$(INTERFACEDIR)/lib
9131
BINDIR_INTERFACE= \$(INTERFACEDIR)/bin
9132
CLSDIR_INTERFACE= \$(INTERFACEDIR)/classes
9133
 
9134
.SUFFIXES:		# Delete the default suffixes
9135
 
9136
EOF
9137
 
9138
    MakePrintList( \@DEFINES );
9139
    MakeNewLine();
9140
 
9141
#-------------------------------------------------------------------------------
9142
#
9143
#
261 dpurdie 9144
    MakeHeader ("Defines, flags and file sets");
227 dpurdie 9145
 
9146
    # Flags
6177 dpurdie 9147
    foreach my $opt ( sort keys %ScmCompilerOpts )
261 dpurdie 9148
    {
9149
        MakeDefEntry ( $opt, "=", $ScmCompilerOpts{$opt} );
9150
    }
227 dpurdie 9151
 
261 dpurdie 9152
    MakeDefEntry( "CFLAGS",         "=", \@CFLAGS, \@CFLAGS_PROD, \@CFLAGS_DEBUG );
9153
    MakeDefEntry( "CLINTFLAGS",     "=", \@CLINTFLAGS, \@CLINTFLAGS_PROD, \@CLINTFLAGS_DEBUG );
9154
    MakeDefEntry( "CDEPENDFLAGS",   "=", \@CFLAGS, \@CFLAGS_PROD, \@CFLAGS_DEBUG );
9155
    MakeDefEntry( "CXXFLAGS",       "=", \@CXXFLAGS, \@CXXFLAGS_PROD, \@CXXFLAGS_DEBUG );
9156
    MakeDefEntry( "CXXLINTFLAGS",   "=", \@CXXLINTFLAGS, \@CXXLINTFLAGS_PROD, \@CXXLINTFLAGS_DEBUG );
9157
    MakeDefEntry( "CXXDEPENDFLAG",  "=", \@CXXFLAGS, \@CXXFLAGS_PROD, \@CXXFLAGS_DEBUG );
267 dpurdie 9158
    MakeDefEntry( "ASFLAGS",        "=", \@ASFLAGS, \@ASFLAGS_PROD, \@ASFLAGS_DEBUG );
9159
    MakeDefEntry( "LDFLAGS",        "=", \@LDFLAGS, \@LDFLAGS_PROD, \@LDFLAGS_DEBUG );
227 dpurdie 9160
 
9161
 
9162
#-------------------------------------------------------------------------------
9163
#   
9164
#
261 dpurdie 9165
    MakeHeader ("Tool Search Path",
9166
                "Extend the PATH seen by all the tools to include",
9167
                "The tools/bin directories discovered in Packages" );
9168
    my $put_PATH;
9169
    my $put_LD_LIBRARY_PATH;
9170
    for my $path ( ToolExtensionPaths() )
9171
    {
9172
        MakePrint( "PATH := $path$::ScmPathSep\$(PATH)\n" );
9173
        $put_PATH = 1;
227 dpurdie 9174
 
261 dpurdie 9175
        if ( $::ScmHost eq "Unix" )
9176
        {
227 dpurdie 9177
        MakePrint( "LD_LIBRARY_PATH ?= \n" );
9178
        MakePrint( "LD_LIBRARY_PATH := $path$::ScmPathSep\$(LD_LIBRARY_PATH)\n" );
261 dpurdie 9179
            $put_LD_LIBRARY_PATH =1;
9180
        }
227 dpurdie 9181
    }
9182
 
261 dpurdie 9183
    #   Export the appropriate environment variables
9184
    #   Note: Windows has an issue with PATH and Path
9185
    #         Haven't got to the bottom of it yet, but it would appear that DLL
9186
    #         searching uses Path and other stuff uses PATH. Not too sure how we
9187
    #         end up with two (or more in the environment)
9188
    #
9189
    #
9190
    if ( $put_LD_LIBRARY_PATH )
9191
    {
343 dpurdie 9192
        MakePrint( "export LD_LIBRARY_PATH\n" );
261 dpurdie 9193
    }
227 dpurdie 9194
 
261 dpurdie 9195
    if ( $put_PATH )
9196
    {
343 dpurdie 9197
        MakePrint( "Path := \$(PATH)\n" );
9198
        MakePrint( "export PATH Path\n" );
261 dpurdie 9199
    }
227 dpurdie 9200
 
9201
#-------------------------------------------------------------------------------
9202
#   
9203
#
261 dpurdie 9204
    MakeHeader ("Perl Module Search Path",
9205
                "Extend the PERL5LIB seen by invocations of perl");
227 dpurdie 9206
 
261 dpurdie 9207
    my $perl_module_found;
9208
    for my $path ( ToolExtensionPaths() )
227 dpurdie 9209
    {
6276 dpurdie 9210
        if (my @results =  glob( "$path/*.pm"))
261 dpurdie 9211
        {
6276 dpurdie 9212
            MakePrint( "PERL5LIB := $path$::ScmPathSep\$(PERL5LIB)\n" );
261 dpurdie 9213
            $perl_module_found = 1;
9214
        }
227 dpurdie 9215
    }
261 dpurdie 9216
    if ( $perl_module_found  )
9217
    {
227 dpurdie 9218
    MakePrint( "export PERL5LIB\n" );
261 dpurdie 9219
    }
227 dpurdie 9220
 
261 dpurdie 9221
#-------------------------------------------------------------------------------
227 dpurdie 9222
#   
9223
#
261 dpurdie 9224
    MakeHeader ("Include Search Paths",
367 dpurdie 9225
                "Package Include Paths for header files and libraries" );
227 dpurdie 9226
 
6177 dpurdie 9227
    MakeDefEntry( 'PINCDIRS'  , '=', '# includes');
9228
    MakeDefEntry( 'PINCDIRS_INTERFACE', '=', '# Interface includes');
9229
    MakeDefEntry( 'PINCDIRS_LOCAL', '=', '# Local includes');
9230
    MakeDefEntry( 'PLIBDIRS'  , '=', '# libraries');
9231
    MakeDefEntry( 'PLIBDIRS_INTERFACE', '=', '# Interface libraries');
9232
    MakeDefEntry( 'PLIBDIRS_LOCAL', '=', '# Local libraries');
367 dpurdie 9233
 
9234
    for my $package (@{$::ScmBuildPkgRules{$ScmPlatform} })
9235
    {
9236
        #
9237
        #   Skip the pseudo package that encapsulates the interface
9238
        #   directory. Currently the makefiles do this in a different
9239
        #   manner - to be resolved
9240
        #
9241
        #   Just comment out the lines so that the data is visible
9242
        #   Its a hint to make use of the data
9243
        #
9244
        my $prefix = '';
6177 dpurdie 9245
        my $suffix = '';
367 dpurdie 9246
        $prefix = '# ' if ( $package->{'TYPE'} eq 'build' );
9247
 
6177 dpurdie 9248
        #
9249
        #   The interface directory is a little bit different
9250
        #
9251
        my ($name,$base);
9252
        if ( $package->{'TYPE'} eq 'interface' ) {
9253
            $base = '$(INTERFACEDIR)';
9254
            $name = 'Interface Directory';
9255
            $suffix = '_INTERFACE';
9256
        } else {
9257
            $name = $package->{'NAME'} . '/' . $package->{'VERSION'};
9258
            $base = $package->{'ROOT'};
9259
        }
367 dpurdie 9260
 
1329 dpurdie 9261
        my @doc;
9262
        push (@doc, "From: $base");
9263
        push (@doc, 'BuildPkgArchive via Interface' )if $package->{'TYPE'} eq 'build' ;
367 dpurdie 9264
 
1329 dpurdie 9265
        MakeHeader ("Source: $name", @doc);
9266
 
367 dpurdie 9267
        #
9268
        #   List include and library directories
9269
        #   Note: Need the True Path for windows.
9270
        #       Some makefile functions (wildcard) only work as expected
9271
        #       if the case of the pathname is correct. Really only a problem
6177 dpurdie 9272
        #       with badly formed legacy packages where the Windows user
367 dpurdie 9273
        #       guessed at the package format.
9274
        #
9275
        #       The conversion to a TruePath is done when ScmBuildPkgRules
6177 dpurdie 9276
        #       is created. Create once, use many time.
367 dpurdie 9277
        #
6177 dpurdie 9278
        for my $type (qw (PINCDIRS PLIBDIRS) ) {
9279
            for my $path ( @{$package->{$type}} ) {
9280
                MakeDefEntry ( "$prefix$type$suffix", "+=", $base . $path);
367 dpurdie 9281
            }
9282
        }
9283
    }
9284
 
6177 dpurdie 9285
    #
9286
    #   Local Paths
9287
    #   These are a little bit special
9288
    #
9289
    MakeHeader ('Source: Local',  'From: Package Local');
9290
 
9291
    sub MakeLocalPaths 
9292
    {
9293
        my ($name, $root, $addRoot) = @_;
9294
        my @pathlist;
9295
 
9296
        foreach my $tag ( $ScmPlatform, $ScmProduct, $ScmTarget ) {
9297
            UniquePush( \@pathlist, "$root/$tag" ) if ( $tag );
9298
        }
9299
 
9300
        #   Add the root directory too
9301
        UniquePush( \@pathlist, $root) if $addRoot;
9302
 
9303
        MakeDefEntry ( $name , "+=", \@pathlist);
9304
    }
9305
 
9306
    MakeLocalPaths ( 'PINCDIRS_LOCAL', '$(INCDIR_LOCAL)', 1 );
9307
    MakeLocalPaths ( 'PLIBDIRS_LOCAL', '$(LIBDIR_LOCAL)', 0 );
9308
 
9309
 
367 dpurdie 9310
#-------------------------------------------------------------------------------
9311
#   
9312
#
9313
    MakeHeader ("Include Search Paths",
9314
                "Local Include Paths",
9315
                " LINKDIRS - Local include search path (short)",
9316
                " INCDIRS  - Include search path (complete)",
9317
                " NODEPDIRS - ",
9318
                " SRCDIRS - ",
9319
                " LIBDIRS - Library search path",
9320
 
9321
                );
9322
 
227 dpurdie 9323
    # Include search path
9324
    #
9325
    #   user-local
367 dpurdie 9326
    #   local
9327
    #   interface
9328
    #       BuildPkgArchive
9329
    #       LinkPkgArchive
227 dpurdie 9330
    #   user-global
9331
    #
9332
 
6177 dpurdie 9333
    MakeDefEntry ( "\nLINCDIRS",    "= ", \@L_INCDIRS );                    # .. Local
9334
    MakeDefEntry ( "LINCDIRS",      "+=", '$(PINCDIRS_LOCAL)');             # .. Sandbox local
9335
    MakeDefEntry ( "LINCDIRS",      "+=", '$(PINCDIRS_INTERFACE)');         # .. Sandbox interface
9336
    MakeDefEntry ( "LINCDIRS",      "+=", \@G_INCDIRS );                    # .. Global
227 dpurdie 9337
 
6177 dpurdie 9338
    MakeDefEntry ( "INCDIRS",  "= ", '$(LINCDIRS)' );                       # Local
9339
    MakeDefEntry ( "INCDIRS",  "+=", '$(PINCDIRS)' );                       # Package
9340
    MakeDefEntry ( "LINCDIRS", "+=", \@S_INCDIRS );                         # System
227 dpurdie 9341
 
9342
    # Source search path
9343
 
261 dpurdie 9344
    MakeDefEntry( "\nNODEPDIRS",        "=", \@NODEPDIRS );
227 dpurdie 9345
 
6177 dpurdie 9346
    MakeDefEntry( "\nSRCDIRS","= "  , [ @L_SRCDIRS, @G_SRCDIRS ] );         # Local
9347
    MakeDefEntry ( "SRCDIRS", "+=" , '$(PINCDIRS)' );                       # Package
9348
    MakeDefEntry ( "SRCDIRS", "+=" , \@S_INCDIRS );                         # System
227 dpurdie 9349
 
9350
    # Library search path
9351
    #
9352
    #   user-local
367 dpurdie 9353
    #   local
9354
    #   interface
9355
    #       BuildPkgArchive
9356
    #       LinkPkgArchive
227 dpurdie 9357
    #   user-global
6177 dpurdie 9358
    #   
9359
    #   Kludge Note:
9360
    #       The LIBDIRS path needs an element with a directory seperator in it
9361
    #       Needed by (broken) cmdfile o determine the file seperator to use
9362
    #       
227 dpurdie 9363
 
367 dpurdie 9364
    MakeDefEntry( "\nLIBDIRS",  "= ", '$(LIBDIR)' );                    # User Local
261 dpurdie 9365
    MakeDefEntry( "LIBDIRS",    "+=", \@L_LIBDIRS );                    # Local
6177 dpurdie 9366
    MakeDefEntry( "LIBDIRS",    "+=", '$(PLIBDIRS_LOCAL)' );            # Sandbox/local
9367
    MakeDefEntry( "LIBDIRS",    "+=", '$(PLIBDIRS_INTERFACE)' );        # Sandbox/interface
9368
    MakeDefEntry( "LIBDIRS",    "+=", '$(LIBDIR_INTERFACE)' );          # Kludge. See note above
261 dpurdie 9369
    MakeDefEntry( "LIBDIRS",    "+=", \@G_LIBDIRS );                    # Global
367 dpurdie 9370
    MakeDefEntry( "LIBDIRS",    "+=", '$(PLIBDIRS)' );                  # Package
261 dpurdie 9371
    MakeDefEntry( "LIBDIRS",    "+=", \@S_LIBDIRS );                    # System
227 dpurdie 9372
 
9373
#-------------------------------------------------------------------------------
9374
#
9375
#   Subdir creation and deletion
9376
#   Creation is done on the fly
9377
#   Deletion is done AFTER the toolset functions have been invoked to create the
9378
#   build artifacts so that the toolsets can create directories too
9379
 
9380
    MakeHeader ("Subdir creation");
9381
    CreateMkdirRules();
6177 dpurdie 9382
    MkdirRule( '$(OBJDIR)', 'OBJDIR', '--Extra=depend,depend.err' );    # Object build directory
2429 dpurdie 9383
    MkdirRule( '$(OBJDIR)/'.$_ ) foreach (@SHLIBS);                     # Shared library build directory
9384
    MkdirRule( '$(LIBDIR)', 'LIBDIR' );                                 # Library directory
9385
    MkdirRule( '$(BINDIR)', 'BINDIR' );                                 # Binary directory
227 dpurdie 9386
 
261 dpurdie 9387
    #
9388
    #   Create a directory for library merge tool to work within
9389
    #
9390
    MkdirRule( "\$(MLIBDIR)", 'MLIBDIR', '--Path=$(GBE_PLATFORM).MRG', '--RemoveAll' ) if (@MLIBS);
9391
 
227 dpurdie 9392
#-------------------------------------------------------------------------------
9393
#   Generate rules and recipes to create all the toolset specific parts
9394
#   This is done fairly early to allow the toolsets to extend various
9395
#   definitions that may be used later in the makefile construction
9396
#
9397
    MakeHeader ("Construct Programs");
9398
 
9399
    foreach my $i ( @PROGS )
9400
    {
289 dpurdie 9401
        my $pProg = $PROGS->Get($i);
9402
        my $pArgs = $pProg->getItems('ARGS');
9403
        my $pObjs = $pProg->getItems('OBJS');
9404
        my $pLibs = $pProg->getItems('LIBS');
227 dpurdie 9405
 
289 dpurdie 9406
        #
9407
        #   Create a list of program object files
9408
        #
9409
        push @PROGOBJS, @$pObjs;
227 dpurdie 9410
 
9411
        MakePrint( "#---- (${i})\n\n" );
9412
        if ( $ScmToolsetProgDependancies )
9413
        {
261 dpurdie 9414
            #
9415
            #   Original style Prog Interface
271 dpurdie 9416
            #   Write some dependency information here and some in the toolset
9417
            #   Problems:
9418
            #       1) Errors in library dependency generation will be
9419
            #          reported after all the object files have been created
9420
            #          Thus the error message and the make-stop are seperated
9421
            #          by many,many lines of output. This makes it difficult
9422
            #          to see the error.
261 dpurdie 9423
            #
271 dpurdie 9424
            #       2) Lack of Flexability
9425
            #
293 dpurdie 9426
            MakeEntry( "\$(BINDIR)/$i$::exe: ", "", "\\\n\t\t", ".$::o ", @$pObjs );
227 dpurdie 9427
        }
9428
        else
9429
        {
261 dpurdie 9430
            #
9431
            #   New Style Prog Interface
9432
            #   The toolset does it all
9433
            #
9434
            #   Flag the progam packaging as a placeholder.
9435
            #   The toolset will replace/update it.
9436
            #
227 dpurdie 9437
            PackageProgRemoveFiles( $i );
9438
        }
9439
 
289 dpurdie 9440
        $if->LD    ( $i, $pArgs, $pObjs, $pLibs );
9441
        $if->LDLINT( $i, $pArgs, $pObjs, $pLibs );
227 dpurdie 9442
    }
9443
 
9444
#-------------------------------------------------------------------------------
9445
#   
9446
#
9447
    MakeHeader ("Construct Test Programs");
289 dpurdie 9448
    foreach my $i ( @TESTPROGS )
227 dpurdie 9449
    {
289 dpurdie 9450
        my $pProg = $TESTPROGS->Get($i);
9451
        my $pArgs = $pProg->getItems('ARGS');
9452
        my $pObjs = $pProg->getItems('OBJS');
9453
        my $pLibs = $pProg->getItems('LIBS');
227 dpurdie 9454
 
289 dpurdie 9455
        #
9456
        #   Create a list of program object files
9457
        #
9458
        push @TESTPROGOBJS, @$pObjs;
9459
 
227 dpurdie 9460
        MakePrint( "#---- (${i})\n\n" );
9461
        if ( $ScmToolsetProgDependancies )
9462
        {
293 dpurdie 9463
            MakeEntry( "\$(BINDIR)/$i$::exe: ", "", "\\\n\t\t", ".$::o ", @$pObjs );
227 dpurdie 9464
        }
9465
        else
9466
        {
9467
            PackageProgRemoveFiles( $i );
9468
        }
9469
 
289 dpurdie 9470
        $if->LD    ( $i, $pArgs, $pObjs, $pLibs );
9471
        $if->LDLINT( $i, $pArgs, $pObjs, $pLibs );
227 dpurdie 9472
    }
9473
 
9474
#-------------------------------------------------------------------------------
9475
#
9476
#
9477
    MakeHeader ("Transfer Scripts to BINDIR");
9478
    foreach my $i ( sort ( values %SCRIPTS ))
9479
    {
9480
        my $tname = "\$(BINDIR)/" . StripDir( $i );
9481
 
9482
 
9483
        MakePrint( "$i:\t\tmakefile.pl\n" .
6177 dpurdie 9484
            "\t\$(XX_PRE)if [ ! -f \"$i\" ]; then echo 'Script [$i] not found'; exit 2; fi\n\n" );
227 dpurdie 9485
 
9486
        #
9487
        #   Create a rule to copy the script into the BIN directory
9488
        #   Mark the script as executable - It can't hurt and its there
9489
        #   to be run as part of a test.
9490
        #
9491
        MakePrint "$tname:\t\$(GBE_BINDIR) $i\n" .
9492
                  "\t\$(XX_PRE)\$(cp) -f $i $tname\n" .
9493
                  "\t\$(XX_PRE)\$(chmod) -f +wx $tname\n\n"
9494
    }
9495
 
9496
#-------------------------------------------------------------------------------
9497
#   
9498
#
9499
    MakeHeader ("Construct Libraries");
9500
    foreach my $i ( @LIBS )
9501
    {
289 dpurdie 9502
        my $pLib  = $LIBS->Get($i);
9503
        my $pArgs = $pLib->getItems('ARGS');
9504
        my $pObjs = $pLib->getItems('OBJS');
227 dpurdie 9505
 
363 dpurdie 9506
        unless ( $ScmToolsetNillLibSrc )
9507
        {
9508
            Error ("Library has no component objects: $i")
9509
                if ( scalar @$pObjs <= 0 );
9510
        }
299 dpurdie 9511
 
227 dpurdie 9512
        MakePrint "#---- (${i})\n\n";
289 dpurdie 9513
        $if->AR(     $i, $pArgs, $pObjs, $pLib);
9514
        $if->ARLINT( $i, $pArgs, $pObjs, $pLib );
227 dpurdie 9515
    }
9516
 
289 dpurdie 9517
#-------------------------------------------------------------------------------
9518
#   
9519
#
9520
    MakeHeader ("Construct Merged Libraries");
227 dpurdie 9521
    sub MlibEntry
9522
    {
289 dpurdie 9523
        my( $mlib, $plib, $pLibs ) = @_;
227 dpurdie 9524
        my @flib;
9525
 
289 dpurdie 9526
        MakePrint '$(LIBDIR)/' . GenLibName($mlib) . ":";
9527
        foreach my $lib ( @$pLibs )
227 dpurdie 9528
        {
289 dpurdie 9529
            #
9530
            #   Each library name may contains one embedded option which
9531
            #   specifies the source directory
9532
            #       libname[,--Option | BaseSubdir]
9533
            #
227 dpurdie 9534
            my ($slib, $sdir) = split( ',', $lib );
343 dpurdie 9535
            my $mode;
227 dpurdie 9536
 
9537
            #
283 dpurdie 9538
            #   By default the librares are pulled from LOCAL unless the
9539
            #   library is built in this directory, in which case it will
289 dpurdie 9540
            #   be used.
227 dpurdie 9541
            #
289 dpurdie 9542
            $sdir = ( $LIBS->Get($slib) ) ? '--Here' : '--Local'
9543
                unless ( $sdir );
227 dpurdie 9544
 
9545
            #
9546
            #   --Interface     - Pull library from the interface directory
9547
            #   --Local         - Pull library from the local directory
9548
            #   --SubDir=xxxx   - Pull library from specified subdirectory
283 dpurdie 9549
            #   --Here          - Pull from local directory if built locally
227 dpurdie 9550
            #   otherwise       - Pull library from specified subdirectory
9551
            #
9552
            if ($sdir eq '--Interface') {
9553
                $sdir = '$(LIBDIR_INTERFACE)/$(GBE_PLATFORM)';
9554
 
343 dpurdie 9555
 
9556
            } elsif ($sdir eq '--InterfacePlain') {
9557
                $sdir = '$(LIBDIR_INTERFACE)/$(GBE_PLATFORM)';
9558
                $mode = 1;
9559
 
227 dpurdie 9560
            } elsif ( $sdir eq '--Local') {
9561
                $sdir = $PackageInfo{'Lib'}{'IBase'} .  # Base of Installed libs
9562
                        $PackageInfo{'Lib'}{'Dir'};     # Default subdir
9563
 
9564
            } elsif ( $sdir =~ m~^--SubDir=(.*)~ ) {
9565
                $sdir = $1 . '/$(LIBDIR)';
9566
 
283 dpurdie 9567
            } elsif ( $sdir eq '--Here') {
9568
                $sdir = '$(LIBDIR)';
9569
 
227 dpurdie 9570
            } else {
9571
                $sdir .= '/$(LIBDIR)';
9572
            }
9573
 
343 dpurdie 9574
            MakePrint " \\\n\t\t${sdir}/" . GenLibName($slib, $mode);
227 dpurdie 9575
            push @flib, "${sdir}/${slib}";
9576
        }
289 dpurdie 9577
        return \@flib;
227 dpurdie 9578
    }
9579
 
9580
    foreach my $i ( @MLIBS )
9581
    {
289 dpurdie 9582
        my $pLib  = $MLIBS->Get($i);
9583
        my $pArgs = $pLib->getItems('ARGS');
9584
        my $pLibs = $pLib->getItems('LIBS');
227 dpurdie 9585
 
261 dpurdie 9586
        MakePrint "#---- (${i})\n\n";
9587
 
227 dpurdie 9588
        unless ( defined &ToolsetARMerge )
9589
        {
9590
            Warning( "Merging of libraries not supported in this toolset yet" );
9591
            Warning( "MergeLibrary: \"$i\" will not be created" );
9592
        }
9593
        else
9594
        {
9595
            #
9596
            #   Create the dependency rule
9597
            #       Target library : source library list
9598
            #           Recipe - generated by the toolset
9599
            #
289 dpurdie 9600
            foreach ( @$pArgs )
227 dpurdie 9601
            {
9602
                Warning( "Ignoring unknown argument to MergeLibrary. $_" );
9603
            }
289 dpurdie 9604
            $pLibs = MlibEntry( $i, $pLib, $pLibs );
9605
            $if->ARMerge( $i, $pArgs, $pLibs, $pLib );
227 dpurdie 9606
        }
9607
    }
9608
 
289 dpurdie 9609
#-------------------------------------------------------------------------------
9610
#   
9611
#
9612
    MakeHeader ("Construct Shared Libraries");
339 dpurdie 9613
 
227 dpurdie 9614
    foreach my $i ( @SHLIBS )
9615
    {
289 dpurdie 9616
        my $pShlib  = $SHLIBS->Get($i);
9617
        my $pArgs = $pShlib->getItems('ARGS');
9618
        my $pObjs = $pShlib->getItems('OBJS');
9619
        my $pLibs = $pShlib->getItems('LIBS');
9620
        my $version = $pShlib->{VERSION};
227 dpurdie 9621
 
289 dpurdie 9622
        $if->SHLD    ( $i, $pArgs, $pObjs, $pLibs, $version );
9623
        $if->SHLDLINT( $i, $pArgs, $pObjs, $pLibs, $version );
227 dpurdie 9624
    }
9625
 
9626
#-------------------------------------------------------------------------------
9627
#   Construct Objects
9628
#   For each object within OBJSOURCE construct the following:
9629
#
9630
#   $(OBJDIR)/object-name:     source-name [makefile]
9631
#       Toolset ...
9632
#
9633
#   
9634
#
9635
    MakeHeader ("Construct Objects");
371 dpurdie 9636
 
227 dpurdie 9637
    foreach my $i ( sort keys %OBJSOURCE )
9638
    {
9639
        my( $src, $sname, $ext, $type, @args );
9640
 
9641
        $src  = $OBJSOURCE{ $i };
9642
        $sname = StripDir( $src );
9643
        $ext  = StripFile( $src );
9644
        $ext = lc($ext)
9645
            if ( $::ScmHost ne "Unix" );
381 dpurdie 9646
        $type = ($ScmSourceTypes{ $ext } || '')
227 dpurdie 9647
            unless (( $type = $SRC_TYPE{ $sname }) );
9648
 
9649
        #
9650
        #   Object source is an object file
9651
        #   No need the generate the object, just create makefile rule
261 dpurdie 9652
        #   [ddp] Not too sure how we get here
227 dpurdie 9653
        #
9654
        if ( $ext eq ".$::o" )
9655
        {
9656
            MakePrint "$src:";
261 dpurdie 9657
            MakePrint " \$(SCM_MAKEFILE)";
227 dpurdie 9658
            MakeNewLine();
9659
            next;
9660
        }
9661
 
9662
        #
9663
        #   Need to create object file
9664
        #
9665
        @args = split( /$;/, $SRC_ARGS{ StripDir( $sname ) } )
9666
            if $SRC_ARGS{ $sname };
9667
 
9668
        push( @args, "--Shared" )
9669
            if ( exists $SHOBJ_LIB{$i} );
9670
 
9671
        #
9672
        #   Convert relative paths to absolute paths if required by the
9673
        #   toolset. Some compilers need ABS paths to generate nice debug
9674
        #   information.
9675
        #
9676
        $src = AbsPath($src)
9677
            if ( $UseAbsObjects );
9678
 
9679
        #
9680
        #   Extract any user specified dependancies
261 dpurdie 9681
        #   These will be added to the dependency list
227 dpurdie 9682
        #
9683
        my @dlist;
9684
        @dlist = split( /$;/, $SRC_DEPEND{$sname} )
9685
            if ( exists $SRC_DEPEND{$sname} );
9686
 
261 dpurdie 9687
        #
9688
        #   Create the dependency part of the object rule
9689
        #   The source file MUST be the first dependent recipes
9690
        #   may assume that $< is the name source file
9691
        #
9692
        MakeEntry( "\$(OBJDIR)/$i.$::o: $src \$(SCM_MAKEFILE)", "", " \\\n\t", "", @dlist );
227 dpurdie 9693
 
9694
        if ( $type eq ".c" ) {
9695
            $if->CC(  $src, $i, \@args );
261 dpurdie 9696
 
227 dpurdie 9697
        } elsif ( $type eq ".cc" ) {
9698
            $if->CXX( $src, $i, \@args );
261 dpurdie 9699
 
227 dpurdie 9700
        } elsif ( $type eq ".asm" ) {
9701
            $if->AS( $src, $i, \@args );
261 dpurdie 9702
 
227 dpurdie 9703
        } else {
9704
            $if->EXT( $src, $i, \@args ) ||
9705
                Warning( "Don't know how to build '$ext' images' for $src, $i" );
9706
            MakeNewLine();
9707
        }
9708
    }
9709
 
9710
#-------------------------------------------------------------------------------
9711
#   Construct Projects
9712
#   Construct toolset specific projects
9713
#
9714
    MakeHeader ("Construct Projects");
9715
    while ( my($project, $entry) = each %PROJECTS)
9716
    {
9717
        $if->PROJECT( $entry );
9718
    }
9719
 
9720
#-------------------------------------------------------------------------------
4761 dpurdie 9721
#   Automated tests
9722
#
9723
    MakeHeader ("Automated tests");
9724
 
9725
    my $idx = 0;
9726
    my @copy_set = ();
9727
 
227 dpurdie 9728
    foreach my $pEntry ( @TESTS_TO_RUN )
9729
    {                                           # Foreach test
9730
        $idx++;
9731
        $pEntry->{'index'} = $idx;
9732
        $pEntry->{'test_name'} = "run_test_$idx";
5708 dpurdie 9733
        $pEntry->{'echoname'} = $pEntry->{'utfname'} || '';  
4781 dpurdie 9734
        $pEntry->{'utfname'} = $pEntry->{'test_name'} unless defined $pEntry->{'utfname'};  
227 dpurdie 9735
 
9736
        #
9737
        #   If the test is being run within a 'FrameWork' then the underlying
9738
        #   toolset must instantiate the frame work.
9739
        #
9740
        #   This may change. Perhaps frameworks shouldn't be a part of the
9741
        #   toolset. Perhaps they should be standalone. May change
9742
        #
9743
        if ( $pEntry->{framework} )
9744
        {
9745
            $if->TESTFRAMEWORK( $pEntry );
9746
        }
9747
 
9748
        #
9749
        #   Create a rule to run the test
9750
        #
9751
 
9752
        my $tdir_alias = $pEntry->{'testdir'};
9753
        my $tdir = '$(' . $tdir_alias . ')';
9754
 
9755
        my $test_name = $pEntry->{'test_name'};
4996 dpurdie 9756
        push @TESTPROJECT_TO_URUN, $test_name;
4501 dpurdie 9757
        push @TESTPROJECT_TO_ARUN, $test_name if     ($pEntry->{'auto'} );
227 dpurdie 9758
 
9759
        my $tprog = $tdir . '/' . StripDir( $pEntry->{'prog'} );
5695 dpurdie 9760
 
9761
        #
9762
        #   Determine the maximum time that the automated test should run
9763
        #       Default is 30 minutes
9764
        #   Non-auto tests are not time limited
9765
        #       
9766
        my $timeout = '';
5848 dpurdie 9767
        if ($pEntry->{'auto'})
5695 dpurdie 9768
        {
5848 dpurdie 9769
            $timeout = 'timeout -Time:' . ($pEntry->{'maxtime'} || '30m') . ' ';
5695 dpurdie 9770
        }
227 dpurdie 9771
 
9772
        my $me = MakeEntry::New( *MAKEFILE, $test_name, '--Phony' );
4781 dpurdie 9773
 
9774
        #
4996 dpurdie 9775
        #   Export GBE_UTF... for the duration of the test
4781 dpurdie 9776
        #
9777
        $me->AddDefn('export GBE_UTFNAME', $pEntry->{'utfname'});
9778
        $me->AddDefn('export GBE_UTFUID', '$(MAKEFILEUID)' . '_' . $pEntry->{'index'});
4996 dpurdie 9779
        $me->AddDefn('export GBE_UTFFILE','$(UTFDIR_PKG)/$(GBE_PLATFORM)-$(GBE_TYPE)-$(GBE_UTFUID)' . '.xml');
4781 dpurdie 9780
 
5986 dpurdie 9781
        # Workaround for dirsep under windows when being wrapped in a timeout
9782
        $me->AddDefn('dirsep', '$(dirsep)$(dirsep)') if ($timeout && ($::ScmHost ne "Unix"));
9783
 
227 dpurdie 9784
        $me->AddDependancy( "\$(GBE_$tdir_alias)" );
9785
        $me->AddDependancy( "\$(INTERFACEDIR)/set_$::ScmPlatform.sh" );
9786
        $me->AddDependancy( $tprog ) if $pEntry->{'copyprog'};
9787
        $me->AddDependancy( @{ $pEntry->{'copyin' } } );
9788
        $me->AddDependancy( map { $tdir . '/' . StripDir($_) } @{ $pEntry->{'copyonce' } } );
9789
        $me->AddDependancy( @{ $pEntry->{'preq'} } );
9790
        $me->RecipePrefix ('$(XX_PRE)');
5708 dpurdie 9791
        $me->RecipeWrapper( $timeout . 'sh -c \'', '\'') if $timeout;
9792
        $me->RecipeComment( "------ Running test [$idx] $pEntry->{'echoname'} ..." );
227 dpurdie 9793
 
9794
        #
4996 dpurdie 9795
        #   Create package utfResults directory
9796
        #       Simplify use of the file
9797
        #
9798
        $me->AddShellRecipe ( 'mkdir -p $(UTFDIR_PKG)' );
9799
 
9800
        #
227 dpurdie 9801
        #   Extend the PATH seen by the script to include the local/bin directory
9802
        #   Allows programs and tests that have been created elsewhere in the component
9803
        #   to be accessed within the script.
9804
        #
9805
        $me->AddShellRecipe ( ". \$(INTERFACEDIR)/set_$::ScmPlatform.sh" );
9806
 
9807
        #
9808
        #   Copy in the files that we need
9809
        #
9810
        foreach my $file ( @{$pEntry->{'copyin'}} )
9811
        {
9812
            my $dst = $tdir . '/' . StripDir( $file );
9813
            UniquePush( \@COPYIN, $dst );
9814
            UniquePush( \@copy_set, $file );
9815
            $me->AddShellRecipe ( "\$(cp) -f $file $dst" );
9816
            $me->AddShellRecipe ( "\$(chmod) -f +wx $dst" );
9817
        }
9818
 
9819
        #
4778 dpurdie 9820
        #   Insert any FrameWork Recipe bits
227 dpurdie 9821
        #
9822
        $me->AddShellRecipe ( @{$pEntry->{'ShellRecipe'}} );
9823
 
4781 dpurdie 9824
        #
9825
        #   Insert command
5035 dpurdie 9826
        #       Save result code to a known file
4781 dpurdie 9827
        #
227 dpurdie 9828
        $me->AddShellRecipe ( "cd $tdir" );
9829
        $me->AddShellRecipe ( ["GBE_TYPE=\$(GBE_TYPE)",
9830
                               "GBE_HOST=\$(GBE_HOST)",
9831
                               "GBE_ROOT=\$(GBE_ROOT_ABS)",
4095 dpurdie 9832
                               "PATH=.\\$::ScmPathSep\$(BINDIR_LOCAL_PATH)\\$::ScmPathSep\$\$PATH",
5708 dpurdie 9833
                               $pEntry->{'command'},
227 dpurdie 9834
                               @{$pEntry->{'args'}},
5035 dpurdie 9835
                               ] , 
9836
                               'echo $$? > utf.$${GBE_UTFUID}.rc' );
9837
 
9838
        #
9839
        #   Create the basic command line for 'jats_runutf'
9840
        #       Use the simplistic 'internal' filter unless the user has provided one
9841
        #
9842
        my @cmdline;
9843
        push @cmdline, '--';
9844
        push @cmdline, '$(VERBOSE_OPT)';
9845
        push @cmdline, '-filter=' . ($pEntry->{'utfformat'} || 'internal');
9846
        push @cmdline, '-root=$(GBE_ROOT_ABS)' ;
9847
        push @cmdline, "-dir=$tdir";
9848
        push @cmdline, '-target=$(GBE_PLATFORM)';
9849
        push @cmdline, '-pkgdir=$(PKGDIR)';
9850
        push @cmdline, '-local=$(LOCALDIR)';
9851
        push @cmdline, '-interface=$(INTERFACEDIR)';
9852
        foreach my $entry (@{$pEntry->{'utfargs' }})
4778 dpurdie 9853
        {
5035 dpurdie 9854
            push @cmdline, '-arg=' . $entry;
4778 dpurdie 9855
        }
5035 dpurdie 9856
 
9857
        #
9858
        #   Insert commands to post process the test results according to the specified formatter
9859
        #
9860
        $me->NewSection     ();
9861
        $me->SectionIfDef   ('UTF_POSTPROCESS');
9862
        $me->RecipePrefix   ('$(XX_PRE)');
9863
        $me->AddRecipe      ( "\$(GBE_PERL) -Mjats_runutf -e processUtf " . join(" \\\n\t\t\t", @cmdline)  );
4778 dpurdie 9864
 
227 dpurdie 9865
        $me->Print();
9866
 
9867
 
9868
        #
9869
        #   Create entries to handle the copy-once files
9870
        #
9871
        foreach my $file ( @{ $pEntry->{'copyonce' } } )
9872
        {
9873
            my $tname = $tdir . '/' . StripDir($file);
9874
            my $me = MakeEntry::New( *MAKEFILE, $tname  );
9875
            $me->AddDependancy( $file );
9876
            $me->AddRecipe ( "\$(call CopyFile,CopyIn,$tname,$file,$tdir,)"  );
9877
            $me->Print();
9878
 
9879
            UniquePush( \@COPYIN, $tname );
9880
            UniquePush( \@copy_set, $file );
9881
 
9882
        }
9883
    }
9884
 
9885
    #
9886
    #   Generate sanity test for each copyin script
9887
    #   Simply to provide a nice error message for generated scripts
9888
    #   that do not exist at run-time
9889
    #
9890
    test_copy_in:
9891
    foreach my $i ( @copy_set )
9892
    {
9893
        next if ( $SCRIPTS{$i} );
9894
        foreach (  @SHLIB_TARGETS )
9895
        {
9896
            next test_copy_in if ( $i eq $_ );
9897
        }
9898
        MakePrint( "\n$i:\t\tmakefile.pl\n" .
6177 dpurdie 9899
            "\t\@if [ ! -f \"$i\" ]; then echo 'ERROR: CopyIn Script [$i] not found'; exit 2; fi\n" );
227 dpurdie 9900
    }
9901
 
261 dpurdie 9902
#-------------------------------------------------------------------------------
9903
#   Deploy rules
9904
#
9905
MakeHeader ("Deploy Rules");
227 dpurdie 9906
 
261 dpurdie 9907
print MAKEFILE <<EOF;
9908
.PHONY:		run_deploy
9909
EOF
227 dpurdie 9910
 
261 dpurdie 9911
#
9912
#   Build up the deployfile.pl command line from the available pieces
9913
#
9914
my $command_file = "";
9915
my @command_line;
9916
 
9917
if ( %DEPLOYPACKAGE )
9918
{
9919
    $command_file = $DEPLOYPACKAGE{'cmdfile'};
9920
 
9921
    push @command_line, "\$(XX_PRE)\$(GBE_PERL) -w $command_file";
9922
    push @command_line, "-r \"\$(GBE_ROOT)\"";
9923
    push @command_line, "-n \"$DEPLOYPACKAGE{'name'}\"";
9924
    push @command_line, "-d \"$DEPLOYPACKAGE{'dir'}\"";
9925
    push @command_line, "-v \"\$(BUILDVER)\"";
9926
    push @command_line, "-t \"\$(GBE_TYPE)\"";
9927
    push @command_line, "-o \"\$(BUILDPREVIOUSVER)\"";
9928
    push @command_line, "-m \"\$(GBE_PLATFORM)\"";
9929
    push @command_line, "-g \"\$(GBE_TARGET)\"";
9930
    push @command_line, "-k \"\$(GBE_PRODUCT)\""        if ( $ScmProduct );
9931
    push @command_line, "-p \"\$(DEPLOYPATCH)\""        if ( $ScmDeploymentPatch );
9932
 
9933
}
9934
 
9935
MakeEntry( "run_deploy:\t$command_file\n", "\n", "\t\t", " \\\n", @command_line );
9936
 
227 dpurdie 9937
#-------------------------------------------------------------------------------
261 dpurdie 9938
#   Custom Rules
9939
#
9940
    MakeHeader ("Custom Rules");
9941
    MakePrintList ( \@RULES );
9942
 
9943
#-------------------------------------------------------------------------------
9944
#   Generated Files
9945
#
9946
    MakeHeader ("Generated Files");
9947
    MakePrint ("\n.PHONY: phony_generate\n\n" );
9948
 
9949
    foreach my $i ( @GENERATE_FILES )
9950
    {
9951
        my $gen_tag = $i->{'index'};
6415 dpurdie 9952
        #
9953
        #   Generate user-provided recipe names to allow the rule to be called by name.
9954
        #
9955
        my $recipeTag = $i->{'recipeTag'} || '';
9956
        my $recipeName = '';
9957
        my $recipeCleanName = '';
261 dpurdie 9958
 
6415 dpurdie 9959
        if ($recipeTag) {
9960
            $recipeName = $recipeTag;
9961
            $recipeCleanName = 'clean_' . $recipeTag;
9962
 
9963
            # for 'jats make help'
9964
            $ScmRecipeTags{$recipeTag} = defined $i->{'clean'} ? 1 : 0;
9965
 
9966
            MakePrint( ".PHONY: $recipeName $recipeCleanName\n"); 
9967
        }
9968
 
261 dpurdie 9969
        #
263 dpurdie 9970
        #   If predelete is enabled, then create a list of files to delete
9971
        #
9972
        if ( $i->{'predelete'}  )
9973
        {
9974
            MakeDefEntry( "generate_gen_$gen_tag", "=",  $i->{'gen'} );
9975
            MakePrint("\n")
9976
        }
9977
 
9978
 
9979
        #
261 dpurdie 9980
        #   Generate the basic generate rule and recipe
9981
        #   together with the prerequisites
9982
        #
6415 dpurdie 9983
        MakeEntry ( "", ":", "", " ", @{$i->{'gen'}}, $recipeName );
261 dpurdie 9984
 
9985
        unless ( $i->{'clean'} && $i->{'shell'} )
9986
        {
9987
            MakeEntry ( "", "", " \\\n\t\t", "", @{$i->{'preq'}} );
9988
            MakeEntry ( "", "", " \\\n\t\t", "", "phony_generate" ) if $i->{'preq_sus'};
9989
            MakeEntry ( "", "", " \\\n\t\t", "", "\$(SCM_MAKEFILE)" );
9990
 
6177 dpurdie 9991
            MakePrint ("\n\t" . "\@\$(echo) '[$i->{'text'}] generating..'" );
263 dpurdie 9992
            if ( $i->{'predelete'}  )
9993
            {
9994
                MakePrint ("\n\t" . "\$(XX_PRE)\$(call RmFiles,generate_gen_$gen_tag)" );
9995
            }
261 dpurdie 9996
            MakePrint ("\n\t" . "\$(XX_PRE)\$(call generate_$gen_tag,)" );
9997
        }
9998
 
9999
        #
10000
        #   Generate 'clean' rules and recipes
10001
        #
10002
        if ( $i->{'clean'} )
10003
        {
10004
            MakePrint ("\n\nPHONY: clean_generate_$gen_tag" );
6415 dpurdie 10005
            MakePrint ("\nclean_generate_$gen_tag $recipeCleanName:" );
343 dpurdie 10006
            MakePrint ("\n\t" . "\$(XX_PRE)-\$(call generate_$gen_tag,$i->{'clean'})" );
261 dpurdie 10007
        }
10008
 
10009
        #
10010
        #   Define a function to contain the body of the generation call
10011
        #   The first argument will be a 'clean' argument
10012
        #
10013
        MakePrint ("\n\ndefine generate_$gen_tag" );
10014
        if ( $i->{'shell'} )
10015
        {
10016
            MakeEntry ("\n\t(" , "\\\n\t)\n", " \\\n\t", ";" , @{$i->{'toolargs'}} );
10017
        }
10018
        else
10019
        {
10020
            MakeEntry ("\n\t" . $i->{'tool'} . ' $1', "\n", " \\\n\t\t", "" , @{$i->{'toolargs'}} );
10021
        }
10022
        MakePrint ("endef\n\n" );
10023
    }
10024
 
10025
#-------------------------------------------------------------------------------
10026
#   Toolset Post Processing
10027
#   Allow the toolset to perform any post processing, before we finally write
10028
#   out any definitions.
10029
#
10030
#   We will not interprete any more user directives, but new stuff may get added
10031
#
10032
#
10033
MakeHeader ("Toolset Post Processing");
10034
$if->Postprocess();
10035
 
10036
################################################################################
10037
#   All interactions with the toolset are now complete
10038
#   All lists are now complete
10039
#
10040
#   Can now create internal definitions
10041
#   
10042
################################################################################
10043
 
10044
    #
10045
    #   Would be nice if this would work
10046
    #   Unfortunatelty we still need $if for the CCDEPENDS and CTAGS work
10047
    #   These must be defined AFTER the definitions
10048
    #
10049
    #   Ideally we should construct our makefile in sections
10050
    #   and then we can order the sections when we write them out
10051
    #
10052
#$if = 0;                            # Ensure the MakeIf class is not called
10053
                                     # If this file is modified
10054
 
10055
#-------------------------------------------------------------------------------
227 dpurdie 10056
#   Sources
10057
#
10058
MakeHeader  ( "Sources");
10059
MakeDefEntry( "CSRCS",      "=",  \@CSRCS );
10060
MakeDefEntry( "CXXSRCS",    "=",  \@CXXSRCS );
10061
MakeDefEntry( "ASSRCS",     "=",  \@ASSRCS );
10062
 
10063
#-------------------------------------------------------------------------------
10064
#   Generated, Installed and Packaged components
10065
#
10066
MakeHeader  ("Generated, Installed and Packaged components");
10067
MakeDefEntry( "INITS",           "=",  \@INITS )   if ( @INITS );
10068
MakeDefEntry( "GENERATED",       "=",  \@GENERATED ) if ( @GENERATED );
10069
MakeDefEntry( "GENERATED_NOTSRC","=",  \@GENERATED_NOTSRC ) if ( @GENERATED_NOTSRC );
10070
MakeDefEntry( "GENERATEDCLEAN",  "=",  CreateNameList( 'clean_generate_', '', ListCleanGenerated() ));
10071
MakeDefEntry( "INSTALL_HDRS",    "=",  \%INSTALL_HDRS ) if ( %INSTALL_HDRS );
10072
MakeDefEntry( "INSTALL_CLSS",    "=",  \%INSTALL_CLSS ) if ( %INSTALL_CLSS );
10073
MakeDefEntry( "OBJS",            "=", CreateNameList( '$(OBJDIR)/', ".$::o", \@OBJS) );
10074
MakeDefEntry( "SHOBJS",          "=", CreateNameList( '$(OBJDIR)/', ".$::o", \%SHOBJ_LIB ));
289 dpurdie 10075
MakeDefEntry( "PROGOBJS",        "=", CreateNameList( '', ".$::o", \@PROGOBJS ));
10076
MakeDefEntry( "TESTPROGOBJS",    "=", CreateNameList( '', ".$::o", \@TESTPROGOBJS ));
10077
MakeDefEntry( "LIBS",            "=", $LIBS->AllTargets() ) if ($::a);
10078
MakeDefEntry( "MLIBS",           "=", $MLIBS->AllTargets() ) if ($::a);
227 dpurdie 10079
MakeDefEntry( "SHNAMES",         "=", \@SHLIBS );
10080
MakeDefEntry( "SHDIRS",          "=", CreateNameList( '$(OBJDIR)/', "", \@SHLIBS ));
10081
MakeDefEntry( "SHLIBS",          "=", \@SHLIB_TARGETS );
10082
MakeDefEntry( "SCRIPTS",         "=", CreateNameList( '$(BINDIR)/', "", \%SCRIPTS ));
10083
MakeDefEntry( "COPYIN",          "=", \@COPYIN );
289 dpurdie 10084
MakeDefEntry( "PROGS",           "=", $PROGS->AllTargets() );
227 dpurdie 10085
MakeDefEntry( "PROGS_EXTRA",     "=", \@PROGS_EXTRA );
289 dpurdie 10086
MakeDefEntry( "TESTPROGS",       "=", $TESTPROGS->AllTargets());
227 dpurdie 10087
MakeDefEntry( "LINTLIBS",        "=", CreateNameList( 'lib_', '_lint', \@LINTLIBS ));
10088
MakeDefEntry( "LINTSHLIBS",      "=", CreateNameList( 'shlib_', '_lint', \@LINTSHLIBS ));
10089
MakeDefEntry( "LINTPROGS",       "=", CreateNameList( 'prog_', '_lint', \@PROGS ));
289 dpurdie 10090
MakeDefEntry( "LINTPROGS",      "+=", CreateNameList( 'prog_', '_lint', \@TESTPROGS ));
227 dpurdie 10091
MakeDefEntry( "PROJECTS",        "=", CreateNameList( 'Project_', '', ListGeneratedProjects(1) ));
10092
MakeDefEntry( "PROJECTSGEN",     "=", CreateNameList( 'Project_', '', ListGeneratedProjects(0) ));
10093
MakeDefEntry( "PROJECTSCLEAN",   "=", CreateNameList( 'ProjectClean_', '', \%PROJECTS ));
10094
 
4501 dpurdie 10095
MakeDefEntry( "UNITTESTS",       "=", \@TESTPROJECT_TO_URUN );
10096
MakeDefEntry( "AUTOUNITTESTS",   "=", \@TESTPROJECT_TO_ARUN );
10097
 
4778 dpurdie 10098
MakeDefEntry( "AUTOUNITTESTS_PRE",    "=", \@TOOLSET_UTF_PRE );
10099
MakeDefEntry( "AUTOUNITTESTS_POST",   "=", \@TOOLSET_UTF_POST );
10100
MakeDefEntry( "AUTOUNITTESTS_COLLATE","=", \@TOOLSET_UTF_COLLATE );
10101
 
10102
 
261 dpurdie 10103
MakeHeader ("Toolset components");
10104
MakeDefEntry( "USERGENERATED",        "=", \@USERGENERATED )    if ( @USERGENERATED );
10105
MakeDefEntry( "TOOLSETGENERATED",     "=", \@TOOLSETGENERATED ) if ( @TOOLSETGENERATED );
10106
MakeDefEntry( "TOOLSETOBJS",          "=", \@TOOLSETOBJS )      if ( @TOOLSETOBJS );
10107
MakeDefEntry( "TOOLSETLIBS",          "=", \@TOOLSETLIBS )      if ( @TOOLSETLIBS );
10108
MakeDefEntry( "TOOLSETPROGS",         "=", \@TOOLSETPROGS )     if ( @TOOLSETPROGS );
10109
MakeDefEntry( "TOOLSETDIRS",          "=", \@TOOLSETDIRS )      if ( @TOOLSETDIRS );
10110
MakeDefEntry( "TOOLSETDIRTREES",      "=", \@TOOLSETDIRTREES )  if ( @TOOLSETDIRTREES );
227 dpurdie 10111
 
10112
#--------- Determine compiler flag groups to use ----------------------------
10113
#
10114
#   Allows the compiler options to be controlled for both the debug and
10115
#   the production builds. Allows control over
10116
#       1) Optimisations
10117
#       2) Debug Information
10118
#
10119
MakeHeader ("Determine compiler flag groups to use");
10120
 
10121
print MAKEFILE <<EOF;
10122
 
10123
ifneq "\$(DEBUG)" "1"
10124
USE_OPTIMISE	:= \$(PROD_USE_OPTIMISE)
10125
USE_DEBUGINFO	:= \$(PROD_USE_DEBUGINFO)
10126
else
10127
USE_OPTIMISE	:= \$(DEBUG_USE_OPTIMISE)
10128
USE_DEBUGINFO	:= \$(DEBUG_USE_DEBUGINFO)
10129
endif
10130
 
10131
EOF
10132
 
261 dpurdie 10133
#-------------------------------------------------------------------------------
10134
#   Source browsing tools
10135
#
10136
MakeHeader ("Source browsing tools");
10137
    print MAKEFILE <<EOF;
10138
.PHONY:			ctags
10139
ctags:
10140
EOF
10141
    $if->CTAGS()
10142
        if (@CSRCS || @CXXSRCS);
227 dpurdie 10143
 
261 dpurdie 10144
#-------------------------------------------------------------------------------
10145
#   Depend
10146
#   If we are build C or C++ source files then create rules and recipes
10147
#   to invoke a dependency generator.
227 dpurdie 10148
#
261 dpurdie 10149
#   NODEPEND is used to disable, at make-time, the dependency generation
10150
#   and inclusion process.
10151
#
10152
#
10153
MakeHeader ("Depend");
6133 dpurdie 10154
if ($::o && (@CSRCS || @CXXSRCS) && $ScmNotGeneric)
261 dpurdie 10155
{
10156
    $ScmDependTags = 1;
10157
    print MAKEFILE <<EOF;
10158
depend:			\$(OBJDIR)/depend
10159
 
10160
\$(OBJDIR)/depend:	\$(SCM_MAKEFILE) \$(GBE_OBJDIR)
10161
\$(OBJDIR)/depend:	\$(CSRCS) \$(CXXSRCS)
10162
ifeq (\$(NODEPEND),0)
6177 dpurdie 10163
	\@echo '[\$@] Doing a make depend..'
261 dpurdie 10164
	-\$(XX_PRE)\$(rm) -f \$(OBJDIR)/depend
10165
EOF
10166
    $if->CCDepend( "\$(OBJDIR)/depend", "\$(CSRCS)" )
10167
        if ( @CSRCS );
10168
    $if->CXXDepend( "\$(OBJDIR)/depend", "\$(CXXSRCS)" )
10169
        if ( @CXXSRCS );
10170
    MakePrint
10171
        "\t-\@\$(touch) -f \$(OBJDIR)/depend\n";
10172
    print MAKEFILE <<EOF;
10173
else
6177 dpurdie 10174
	\@echo '[\$@] Skipping make depend..'
261 dpurdie 10175
	-\$(XX_PRE)\$(rm) -f \$(OBJDIR)/depend
10176
endif
10177
EOF
10178
}
10179
else
10180
{
10181
    print MAKEFILE <<EOF;
10182
depend:
10183
EOF
10184
}
10185
 
10186
#
10187
#   Rule to unmake the depend file
2429 dpurdie 10188
#       No longer neeed.
10189
#       The file is deleted as a part of the OBJDIR cleanup
261 dpurdie 10190
#
10191
    print MAKEFILE <<EOF;
10192
 
10193
undepend:
10194
EOF
10195
 
10196
#--------- IFLAG Documentation -------------------------------------------------
10197
#
10198
#   IFLAG - iteration flag. This is setting by the calling process
10199
#                           and is a function of the phase being processed
227 dpurdie 10200
#       0   No external dependencies.
10201
#       1   Source dependency list.
261 dpurdie 10202
#       2   Shared library dependency list
10203
#       3   Application dependency list
227 dpurdie 10204
#
10205
#
261 dpurdie 10206
#--------- Dependencies --------------------------------------------------------
10207
#   Include the 'depend' file if required
10208
#
10209
    MakeHeader ("Dependency Inclusion");
10210
    print MAKEFILE <<EOF;
10211
ifeq (\$(NODEPEND),0)
10212
 ifdef IFLAG
10213
  ifneq "\$(IFLAG)" "0"
10214
-include	\$(OBJDIR)/depend
10215
  endif
227 dpurdie 10216
 endif
10217
endif
10218
 
10219
EOF
10220
 
10221
#-------------------------------------------------------------------------------
10222
#   Standard rules
10223
#
5991 dpurdie 10224
    MakeHeader ("Standard rules");
10225
    print MAKEFILE <<EOF;
373 dpurdie 10226
.PHONY:		make_clean
227 dpurdie 10227
make_clean:
10228
	-\@echo "Removing generated files (objects, libraries, binaries etc)";
10229
 
10230
.PHONY:		rmlitter
10231
rmlitter:
2429 dpurdie 10232
	-\$(AA_PRE)JatsFileUtil 'D0' 'Removing litter' '.' 'core' '*.bak' '*.tmp' '*.err'
227 dpurdie 10233
 
261 dpurdie 10234
.PHONY:		lint_init
10235
lint_init:
10236
 
227 dpurdie 10237
EOF
10238
 
261 dpurdie 10239
#
10240
#   Dependencies for 'make_init'
10241
#
10242
#
10243
my @initdep;
10244
push @initdep, '$(INITS)' if ( @INITS );
227 dpurdie 10245
 
261 dpurdie 10246
#
10247
#   Dependencies for 'make_dir'
10248
#
10249
my @mkdirdep;
289 dpurdie 10250
push @mkdirdep, '$(GBE_OBJDIR)' if ( @CSRCS || @CXXSRCS || @OBJS || @PROGOBJS || @TESTPROGOBJS );
261 dpurdie 10251
push @mkdirdep, '$(SHDIRS)'     if ( %SHOBJ_LIB || @SHLIBS);
10252
push @mkdirdep, '$(GBE_LIBDIR)' if ( @LIBS || @MLIBS || @SHLIBS || %INSTALL_LIBS || %PACKAGE_LIBS );
289 dpurdie 10253
push @mkdirdep, '$(GBE_BINDIR)' if ( @SHLIBS || %SCRIPTS || @PROGS || @TESTPROGS || %INSTALL_PROGS || %PACKAGE_PROGS );
227 dpurdie 10254
 
261 dpurdie 10255
#
10256
#   Actions for for 'unobj'
10257
#
10258
my @unobjact;
10259
push @unobjact, RmFilesCmd( 'OBJS' )            if ( @OBJS );
10260
push @unobjact, RmFilesCmd( 'SHOBJS' )          if ( %SHOBJ_LIB );
10261
push @unobjact, RmFilesCmd( 'PROGOBJS' )        if ( @PROGOBJS );
289 dpurdie 10262
push @unobjact, RmFilesCmd( 'TESTPROGOBJS' )    if ( @TESTPROGOBJS );
261 dpurdie 10263
push @unobjact, RmFilesCmd( 'TOOLSETOBJS' )     if ( @TOOLSETOBJS );
227 dpurdie 10264
 
261 dpurdie 10265
#
10266
#   Dependencies for 'make_lib'
10267
#
10268
my @libdep;
10269
push @libdep, '$(GBE_OBJDIR)', '$(GBE_LIBDIR)', '$(LIBS)' if ( @LIBS );
227 dpurdie 10270
 
261 dpurdie 10271
#
10272
#   Dependencies for 'lint_lib'
10273
#
10274
my @liblintdep;
10275
push @liblintdep, 'lint_init', '$(GBE_OBJDIR)', '$(GBE_LIBDIR)', '$(LINTLIBS)' if ( @LIBS );
227 dpurdie 10276
 
261 dpurdie 10277
#
10278
#   Dependencies for 'make_mlib'
10279
#
10280
my @mlibdep;
10281
push @mlibdep, '$(GBE_OBJDIR)', '$(GBE_LIBDIR)', '$(GBE_MLIBDIR)', '$(MLIBS)' if ( @MLIBS );
227 dpurdie 10282
 
261 dpurdie 10283
#
10284
#   Dependencies for 'make_install_shlib' (tag)
10285
#
10286
my @shlibdep;
10287
push @shlibdep, '$(SHDIRS)', '$(SHLIBS)' if ( @SHLIBS );
227 dpurdie 10288
 
261 dpurdie 10289
#
10290
#   Dependencies for 'lint_shlib'
10291
#
10292
my @shliblintdep;
10293
push @shliblintdep, 'lint_init', '$(GBE_LIBDIR)', '$(LINTSHLIBS)' if ( @SHLIBS );
227 dpurdie 10294
 
261 dpurdie 10295
#
10296
#   Actions for 'unmake_lib'
10297
#
10298
my @unlibact;
10299
push @unlibact, RmFilesCmd( 'SHLIBS' )      if ( @SHLIBS );
10300
push @unlibact, RmFilesCmd( 'MLIBS' )       if ( @MLIBS );
10301
push @unlibact, RmFilesCmd( 'LIBS' )        if ( @LIBS );
10302
push @unlibact, RmFilesCmd( 'TOOLSETLIBS' ) if ( @TOOLSETLIBS );
227 dpurdie 10303
 
261 dpurdie 10304
#
10305
#   Actions for 'unmake_mlib'
10306
#
10307
my @unmlibact;
10308
push @unmlibact, RmFilesCmd( 'MLIBS' ) if ( @MLIBS );
227 dpurdie 10309
 
261 dpurdie 10310
#
10311
#   Dependencies for 'make_script'
10312
#
10313
my @scriptdep;
10314
push @scriptdep, '$(GBE_BINDIR)', '$(SCRIPTS)' if ( %SCRIPTS );
227 dpurdie 10315
 
261 dpurdie 10316
#
10317
#   Actions for 'unmake_script'
10318
#
10319
my @unscriptact;
10320
push @unscriptact , RmFilesCmd( 'SCRIPTS' ) if ( %SCRIPTS );
10321
push @unscriptact , RmFilesCmd( 'COPYIN' )  if ( @COPYIN );
227 dpurdie 10322
 
261 dpurdie 10323
#
10324
#   Dependencies for 'make_prog'
10325
#
10326
my @progdep;
10327
push @progdep, '$(GBE_OBJDIR)', '$(GBE_BINDIR)', '$(PROGS)' if ( @PROGS );
10328
push @progdep, '$(PROGS_EXTRA)' if (@PROGS_EXTRA);
227 dpurdie 10329
 
261 dpurdie 10330
#
10331
#   Dependencies for 'make_prog' created for 'projects'
10332
#
10333
my @projectdep;
10334
push @projectdep, '$(PROJECTS)' if (ListGeneratedProjects(1) );
227 dpurdie 10335
 
261 dpurdie 10336
#
10337
#   Dependencies for 'generate' created for 'projects'
10338
#
10339
my @projectgendep;
10340
push @projectgendep, '$(PROJECTSGEN)' if (ListGeneratedProjects(0) );
227 dpurdie 10341
 
261 dpurdie 10342
#
10343
#   Dependencies for 'unmake_prog' created for 'projects'
10344
#
10345
my @projectcleandep;
10346
push @projectcleandep, '$(PROJECTSCLEAN)' if (%PROJECTS);
227 dpurdie 10347
 
261 dpurdie 10348
#
10349
#   Dependencies for 'lint_prog'
10350
#
10351
my @proglintdep;
289 dpurdie 10352
push @proglintdep, 'lint_init', '$(GBE_OBJDIR)', '$(GBE_BINDIR)', '$(LINTPROGS)' if ( @PROGS || @TESTPROGS );
227 dpurdie 10353
 
261 dpurdie 10354
#
10355
#   Actions for 'unmake_prog'
10356
#
10357
my @unprogact;
10358
push @unprogact, RmFilesCmd( 'PROGS' )        if ( @PROGS );
10359
push @unprogact, RmFilesCmd( 'TOOLSETPROGS' ) if ( @TOOLSETPROGS );
227 dpurdie 10360
 
261 dpurdie 10361
#
4728 dpurdie 10362
#   Dependencies for 'exec_tests'
261 dpurdie 10363
#
10364
my @testprogdep;
289 dpurdie 10365
push @testprogdep, '$(GBE_OBJDIR)', '$(GBE_BINDIR)', '$(TESTPROGS)' if ( @TESTPROGS );
227 dpurdie 10366
 
4501 dpurdie 10367
my @autoruntestdep;
10368
push @autoruntestdep, 'makefile.pl', '$(AUTOUNITTESTS)' if ( @TESTPROJECT_TO_ARUN );
10369
 
10370
my @runtestdep;
4996 dpurdie 10371
push @runtestdep    , 'makefile.pl', '$(UNITTESTS)' if ( @TESTPROJECT_TO_URUN );
4501 dpurdie 10372
 
227 dpurdie 10373
#
4728 dpurdie 10374
#   Dependencies for 'exec_tests' and friends
261 dpurdie 10375
#
10376
my @untestprogact;
289 dpurdie 10377
push @untestprogact ,RmFilesCmd( 'TESTPROGS' ) if ( @TESTPROGS );
227 dpurdie 10378
 
261 dpurdie 10379
#
10380
#   Dependencies for 'generated'
10381
#
10382
my @generatedep;
10383
push @generatedep, '$(GENERATED)' if ( @GENERATED );
10384
 
10385
#
10386
#   Actions for 'ungenerate'
10387
#
10388
my @ungenact;
10389
push @ungenact, RmFilesCmd( 'GENERATED' ) if ( @GENERATED );
10390
push @ungenact, RmFilesCmd( 'GENERATED_NOTSRC' ) if ( @GENERATED_NOTSRC );
10391
push @ungenact, RmFilesCmd( 'TOOLSETGENERATED' ) if ( @TOOLSETGENERATED );
10392
push @ungenact, RmFilesCmd( 'USERGENERATED' ) if ( @USERGENERATED );
10393
 
10394
#
10395
#   Dependencies for 'ungenerate'
10396
#
10397
my @ungeneratedep;
10398
push @ungeneratedep, '$(GENERATEDCLEAN)';
10399
 
227 dpurdie 10400
#-------------------------------------------------------------------------------
261 dpurdie 10401
# Function        : PrintPhonyRule
227 dpurdie 10402
#
261 dpurdie 10403
# Description     : Helper function to print some internal phony makefile targets
10404
#                   These are used to hold the basic makefile together
10405
#
10406
# Inputs          : $target         - Name of the phony target
10407
#                   $prereq         - Prerequisites
10408
#                                     Leading spaces removed
10409
#                   $recipe         - Optional Reference to an array of recipes
10410
#                                     Will be printed one per line
10411
#
10412
#
10413
sub PrintPhonyRule
227 dpurdie 10414
{
261 dpurdie 10415
    my ($target, $prereq, $recipe) = @_;
10416
    $prereq =~ s/^\s+//;
227 dpurdie 10417
 
261 dpurdie 10418
    MakePadded( 2, '.PHONY:', $target, "\n");
10419
    MakePadded( 2,"$target:", $prereq, "\n");
10420
    MakePrint ("\t\t" . $_ . "\n") foreach ( @{$recipe} );
10421
    MakePrint ("\n");
227 dpurdie 10422
}
10423
 
261 dpurdie 10424
#   make_init - Test toolset presence and sanity
10425
#   Will only be called ONCE for each platform in a recursive build
10426
#   Should be used to ensure that the required toolset is present
10427
#
4778 dpurdie 10428
PrintPhonyRule ('make_init',            "@initdep" );
227 dpurdie 10429
 
261 dpurdie 10430
#   make_dir    - Create required subdirectories
10431
#   Will be invoked as a part of most targets that create files
10432
#   Will be invoked by the calling wrappers
10433
#   Should not be invoked when cleaning
10434
#
4778 dpurdie 10435
PrintPhonyRule ('make_dir',             "@mkdirdep" );
261 dpurdie 10436
 
4778 dpurdie 10437
PrintPhonyRule ('generate',             "@generatedep @projectgendep" );
10438
PrintPhonyRule ('ungenerate',           "@ungeneratedep",  \@ungenact);
10439
PrintPhonyRule ('unobj',                "",  \@unobjact);
10440
PrintPhonyRule ('make_lib',             "@libdep" );
10441
PrintPhonyRule ('lint_lib',             "@liblintdep" );
10442
PrintPhonyRule ('make_mlib',            "@mlibdep" );
10443
PrintPhonyRule ('lint_shlib',           "@shliblintdep" );
10444
PrintPhonyRule ('unmake_lib',           "", \@unlibact );
10445
PrintPhonyRule ('unmake_mlib',          "", \@unmlibact );
10446
PrintPhonyRule ('make_script',          "@scriptdep" );
10447
PrintPhonyRule ('unmake_script',        "", \@unscriptact );
10448
PrintPhonyRule ('make_prog',            "make_script @progdep @projectdep" );
10449
PrintPhonyRule ('unmake_prog',          "unmake_script @projectcleandep", \@unprogact );
10450
PrintPhonyRule ('lint_prog',            "@proglintdep" );
10451
PrintPhonyRule ('exec_tests',           "make_script @testprogdep @runtestdep" );
10452
PrintPhonyRule ('exec_unit_tests',      "make_script @testprogdep @autoruntestdep" );
10453
PrintPhonyRule ('make_test',            "make_script @testprogdep" );
10454
PrintPhonyRule ('unmake_test',          "unmake_script", \@untestprogact );
10455
PrintPhonyRule ('preprocess_tests',     '$(AUTOUNITTESTS_PRE)' );
10456
PrintPhonyRule ('postprocess_tests',    '$(AUTOUNITTESTS_POST)' );
10457
PrintPhonyRule ('collate_test_results', '$(AUTOUNITTESTS_COLLATE)' );
261 dpurdie 10458
 
227 dpurdie 10459
#-------------------------------------------------------------------------------
10460
#   Package and Installation Summary
10461
#
10462
    MakeHeader ("Package and Installation Summary");
10463
    sub InstallTarget
10464
    {
10465
        my( $target, $hashp, $prereq, $fprereq ) = @_;
10466
        my( $element );
10467
 
5991 dpurdie 10468
        my $me = MakeEntry::New( *MAKEFILE, $target, '--Phony' );
10469
        $me->AddDependancy( $fprereq ) if ($fprereq);
227 dpurdie 10470
        foreach my $element ( sort keys %{$hashp} )
10471
        {
10472
            #
10473
            #   Skip placekeepers
10474
            #
10475
            next if ( $hashp->{$element}{'placekeeper'} );
10476
 
10477
            #
10478
            #   Prepend any prerequisites (once)
10479
            #
5991 dpurdie 10480
            $me->AddDependancy( $prereq ) if ( $prereq );
10481
            $prereq = 0;
227 dpurdie 10482
 
5991 dpurdie 10483
            $me->AddDependancyEscaped( $element );
227 dpurdie 10484
        }
5991 dpurdie 10485
        $me->Print();
10486
 
227 dpurdie 10487
    }
10488
 
10489
InstallTarget( "install_hdr",       \%INSTALL_HDRS );
10490
InstallTarget( "install_lib",       \%INSTALL_LIBS,  'make_mlib' );
261 dpurdie 10491
InstallTarget( "make_install_shlib",\%INSTALL_SHLIBS, '', "@shlibdep" );
227 dpurdie 10492
InstallTarget( "install_prog",      \%INSTALL_PROGS, 'make_script' );
10493
InstallTarget( "install_class",     \%INSTALL_CLSS );
10494
 
10495
InstallTarget( "package_files",     \%PACKAGE_FILES );
10496
InstallTarget( "package_hdr",       \%PACKAGE_HDRS );
10497
InstallTarget( "package_lib",       \%PACKAGE_LIBS );
10498
InstallTarget( "package_shlib",     \%PACKAGE_SHLIBS );
10499
InstallTarget( "package_prog",      \%PACKAGE_PROGS, 'make_script' );
10500
InstallTarget( "package_class",     \%PACKAGE_CLSS );
10501
 
10502
#-------------------------------------------------------------------------------
10503
#   Installations
10504
 
10505
MakeHeader ("Installations");
6387 dpurdie 10506
PackageRule    ( \&InstallCmd, \%INSTALL_HDRS  );
10507
PackageRule    ( \&InstallCmd, \%INSTALL_CLSS  );
10508
PackageRule    ( \&InstallCmd, \%INSTALL_LIBS  );
10509
PackageRule    ( \&InstallCmd, \%INSTALL_SHLIBS  );
10510
PackageRule    ( \&InstallCmd, \%INSTALL_PROGS  );
10511
PackageDirRule ('install_dirs',    \@INSTALL_DIRS);
227 dpurdie 10512
 
10513
#-------------------------------------------------------------------------------
10514
#   Packaging
10515
#
10516
MakeHeader ("Packaging");
6387 dpurdie 10517
PackageRule    ( \&PackageCmd, \%PACKAGE_FILES );
10518
PackageRule    ( \&PackageCmd, \%PACKAGE_HDRS );
10519
PackageRule    ( \&PackageCmd, \%PACKAGE_CLSS );
10520
PackageRule    ( \&PackageCmd, \%PACKAGE_LIBS );
10521
PackageRule    ( \&PackageCmd, \%PACKAGE_SHLIBS );
10522
PackageRule    ( \&PackageCmd, \%PACKAGE_PROGS );
10523
PackageDirRule ('package_dirs', \@PACKAGE_DIRS);
227 dpurdie 10524
 
10525
#-------------------------------------------------------------------------------
10526
#   Uninstall/unpackaging
10527
#
10528
MakeHeader ("Uninstall/unpackaging");
10529
 
6387 dpurdie 10530
UnpackageRule  ( 'uninstall_hdr',         \&UninstallCmd, \%INSTALL_HDRS );
10531
UnpackageRule  ( 'uninstall_lib',         \&UninstallCmd, \%INSTALL_LIBS );
10532
UnpackageRule  ( 'uninstall_shlib',       \&UninstallCmd, \%INSTALL_SHLIBS );
10533
UnpackageRule  ( 'uninstall_prog',        \&UninstallCmd, \%INSTALL_PROGS );
10534
UnpackageRule  ( 'uninstall_class',       \&UninstallCmd, \%INSTALL_CLSS );
10535
PackageDirRule ( 'uninstall_dirs',        \@INSTALL_DIRS);
227 dpurdie 10536
 
6387 dpurdie 10537
UnpackageRule  ( 'unpackage_files',       \&UnpackageCmd, \%PACKAGE_FILES );
10538
UnpackageRule  ( 'unpackage_hdr',         \&UnpackageCmd, \%PACKAGE_HDRS );
10539
UnpackageRule  ( 'unpackage_lib',         \&UnpackageCmd, \%PACKAGE_LIBS );
10540
UnpackageRule  ( 'unpackage_shlib',       \&UnpackageCmd, \%PACKAGE_SHLIBS );
10541
UnpackageRule  ( 'unpackage_prog',        \&UnpackageCmd, \%PACKAGE_PROGS );
10542
UnpackageRule  ( 'unpackage_class',       \&UnpackageCmd, \%PACKAGE_CLSS );
10543
PackageDirRule ( 'unpackage_dirs',        \@PACKAGE_DIRS);
227 dpurdie 10544
 
261 dpurdie 10545
#-------------------------------------------------------------------------------
267 dpurdie 10546
#   Distribution Sets
261 dpurdie 10547
#
267 dpurdie 10548
MakeHeader ("Distribution Sets");
10549
PackageSetRules();
10550
 
10551
#-------------------------------------------------------------------------------
10552
#
261 dpurdie 10553
#   Subdir deletion
10554
#   This is done AFTER the toolset functions have been invoked to create the
10555
#   build artifacts so that the toolsets can create directories too
10556
#
10557
#   Note: Toolset directories are deleted first
10558
#   Note: User Directories are deleted in the reverse order of creation
10559
#
2429 dpurdie 10560
#   Add them into the directory data structure
10561
#
10562
    foreach my $path ( @TOOLSETDIRS )
10563
    {
10564
        MkdirRule( $path, '', '--NoCreate' );
10565
    }
10566
 
10567
    foreach my $path ( @TOOLSETDIRTREES )
10568
    {
10569
        MkdirRule( $path, '', '--NoCreate' , '--RemoveAll');
10570
    }
10571
 
261 dpurdie 10572
    MakeHeader ("Subdir deletion");
10573
    RmdirRules();
10574
    MakeNewLine();
227 dpurdie 10575
 
261 dpurdie 10576
#--------- Toolset Rules -------------------------------------------------------
10577
    MakeHeader ("Toolset Rules");
10578
    MakePrintList ( \@TOOLSETRULES );
10579
 
10580
#--------- Maketags ------------------------------------------------------------
227 dpurdie 10581
 
10582
    Maketag( "make_init",           @INITS );
261 dpurdie 10583
    Maketag( "make_dir",            @mkdirdep );
10584
    Maketag( "generate",            @generatedep || @projectgendep || @USERGENERATED || ($ScmToolsetGenerate != 0) );
227 dpurdie 10585
    Maketag( "depend",              $ScmDependTags != 0 );
261 dpurdie 10586
    Maketag( "make_lib",            @libdep );
10587
    Maketag( "make_mlib",           @mlibdep );
10588
    Maketag( "make_install_shlib",  %INSTALL_SHLIBS || @shlibdep);
10589
    Maketag( "make_script",         @scriptdep );
10590
    Maketag( "make_prog",           @progdep || @projectdep );
10591
    Maketag( "make_test",           @testprogdep );
4996 dpurdie 10592
    Maketag( "exec_tests",          $TESTS_TO_RUN     || @TESTPROJECT_TO_URUN );
4728 dpurdie 10593
    Maketag( "exec_unit_tests",     $TESTS_TO_AUTORUN || @TESTPROJECT_TO_ARUN );
4778 dpurdie 10594
    Maketag( "process_tests",       @TOOLSET_UTF_PRE || @TOOLSET_UTF_POST || @TOOLSET_UTF_COLLATE);
227 dpurdie 10595
    Maketag( "install_hdr",         %INSTALL_HDRS );
10596
    Maketag( "install_class",       %INSTALL_CLSS );
10597
    Maketag( "install_lib",         %INSTALL_LIBS );
10598
    Maketag( "install_prog",        %INSTALL_PROGS );
6387 dpurdie 10599
    Maketag( "install_dirs",        @INSTALL_DIRS );
227 dpurdie 10600
    Maketag( "deploy",              %DEPLOYPACKAGE );
10601
    Maketag( "package",             %PACKAGE_FILES || %PACKAGE_HDRS || %PACKAGE_CLSS ||
10602
                                    %PACKAGE_LIBS || %PACKAGE_SHLIBS || %PACKAGE_PROGS );
10603
 
261 dpurdie 10604
    #
10605
    #   Display tags in the MAKEFILE
4778 dpurdie 10606
    #       Not used here - just for show
261 dpurdie 10607
    #
10608
    MakeHeader ("Maketags");
10609
    foreach my $tag ( sort keys %MakeTags )
10610
    {
4778 dpurdie 10611
        MakePadded( 3, "#   $tag:", '1', "\n");
261 dpurdie 10612
    }
10613
 
227 dpurdie 10614
#-------------------------------------------------------------------------------
10615
#   End of Makefile
10616
#
10617
    MakeHeader ("End of Makefile");
10618
    close( MAKEFILE );
10619
 
10620
#
10621
#   Save all platform information
10622
#   Done after the makefile is written as toolsets can extend the data
10623
#
10624
    WriteParsedConfig();
10625
 
10626
#
10627
#   Write out any accumulated DPACKAGE data
10628
#
10629
    JatsDPackage::DPackageSave();
10630
 
10631
    return 0;
10632
}
10633
 
10634
#-------------------------------------------------------------------------------
387 dpurdie 10635
# Function        : QuoteForMake
10636
#
10637
# Description     : Escape/Quote a pathname for make
10638
#                       Allow files with a $ in the name
10639
#                       Allow files with a space in the name
10640
#                       Allow files with a comma in the name
10641
#                       Allow for paths that have make-varible prefixes
6423 dpurdie 10642
#                           $(GBE_...) or ${GBE_...} or $(OBJDIR) or $(BUILDVERNUM)
387 dpurdie 10643
#                           as these may be generated internally
5991 dpurdie 10644
#                       Allow for files with a colon in the name
10645
#                           Mode dependent
10646
#                               0 - No effect
10647
#                               T - \\\:
10648
#                               S = \:    
387 dpurdie 10649
#
399 dpurdie 10650
#                       Must also allow $(GBE_TYPE) in the remainder
10651
#
5991 dpurdie 10652
# Inputs          : uarg            - Arg to quote
10653
#                   mode            - Mode of operation
10654
#                                     T - Makefile target
10655
#                                     S - Makefile source
10656
#                                     0 - Neither
387 dpurdie 10657
#
10658
# Returns         : Quoted arg
10659
#
10660
 
5991 dpurdie 10661
sub QuoteForMake($;$)
387 dpurdie 10662
{
5991 dpurdie 10663
    my ($uarg, $mode) = @_;
10664
    $mode = '0' unless defined $mode;
387 dpurdie 10665
 
10666
    #
10667
    #   Split into two
10668
    #       $(xxx)/             - Makefile variables
10669
    #       Remainder           - Stuff to quote
10670
    #
10671
    $uarg =~ m~^((\$\(.*?\)/)*)(.*)~;
10672
    my $prefix = defined $1 ? $1 : '';
10673
    my $arg    = defined $3 ? $3 : '';
10674
 
6423 dpurdie 10675
    $arg =~ s~\$(?!\(GBE_[A-Z]+\)|{GBE_[A-Z]+}|\(OBJDIR\)|\(BUILDVERNUM\))~\$\$~g;       # $, not followed by (GBE_ or ${GBE_ or (OBJDIR)- is not $(GBE_ AND not $(OBJDIR)
387 dpurdie 10676
    $arg =~ s~ ~\\ ~g;
10677
    $arg =~ s~,~\$(comma)~g;
2764 dpurdie 10678
    $arg =~ s~%~\\%~g;
5999 dpurdie 10679
    $arg =~ s~:~\\\\\\:~g if ($mode eq 'T' &&  $::ScmHost eq "Unix");
10680
    $arg =~ s~:~\\:~g     if ($mode eq 'S' &&  $::ScmHost eq "Unix");
387 dpurdie 10681
    return $prefix . $arg;
10682
}
10683
 
10684
#-------------------------------------------------------------------------------
227 dpurdie 10685
# Function        : Maketag
10686
#
10687
# Description     : Create Makefile tags to speed up recursive makes
10688
#
10689
# Inputs          : tag_name
10690
#                   dep
10691
#
10692
# Returns         : 
10693
#
10694
sub Maketag
10695
{
10696
    my( $tag, $dep ) = @_;
10697
    $MakeTags{$tag} = 1 if ( defined($dep) && $dep );
10698
}
10699
 
10700
#-------------------------------------------------------------------------------
10701
#   Function to create and delete directories within the build system
10702
#
10703
#    To stop make regenerating directory dependent targets each time the
10704
#    directory content is modified, rule should only be dependent on a internally
10705
#    created alias file 'gbedir', which represents the time a dir was created not
10706
#    last modified.
10707
#
10708
#    Must use tags like GBE_BINDIR, GBE_LIBDIR and GBE_OBJDIR to ensure that the
10709
#    directories are created correctly.
10710
#
10711
my %MkdirRuleData;
10712
my @MkdirRuleOrder;
10713
my $MkdirRulePrinting = 0;
10714
my $MkdirRuleGbeFile = ( $::ScmHost eq "Unix" ) ? ".gbedir" : "_gbedir";
10715
 
10716
#-------------------------------------------------------------------------------
10717
# Function        : MkdirRule
10718
#
10719
# Description     : Create Rules and Recipes to create a directory at make-time
10720
#                   Mark the information for such that the directories will
10721
#                   be deleted in a 'clean'
10722
#
10723
#                   Can be called before we start writing the makefile
10724
#                   Such entries will be retained and dumped at a known time
10725
#
10726
# Inputs          : $subdir     - Symbolic name of the subdir $(OBJDIR)
10727
#                   $alias      - Optional script alias for the dir 'OBJDIR' --> GBE_OBJDIR
10728
#                   Options:
2429 dpurdie 10729
#                       --Path=path             Optional value of $subdir '$(GBE_PLATFORM)$(GBE_TYPE).OBJ'
10730
#                       --RemoveAll             Remove all files on clean
6177 dpurdie 10731
#                       --Extra=file[,file]     Additional files to remove
2429 dpurdie 10732
#                       --NoCreate              Do not Create the Directory, just delete it
227 dpurdie 10733
#
10734
# Returns         : Nothing
10735
#
10736
 
10737
sub MkdirRule
10738
{
10739
    my( $subdir, $alias, @opts ) = @_;
10740
 
10741
    #
10742
    #   Create data entry once
10743
    #
10744
    $alias =~ s~^GBE_~~ if $alias;
10745
    unless ( $MkdirRuleData{$subdir}  )
10746
    {
10747
        my %data;
10748
 
10749
        #
10750
        #   Parse options
10751
        #
10752
        foreach ( @opts )
10753
        {
10754
            if ( /^--Path=(.+)/ ) {
10755
                $data{path} = $1;
10756
            } elsif ( /^--RemoveAll/ ) {
10757
                $data{remove_all} = 1;
2429 dpurdie 10758
            } elsif ( /^--NoCreate/ ) {
10759
                $data{noCreate} = 1;
10760
            } elsif ( /^--Extra=(.+)/ ) {
10761
                @{$data{extraFiles}} = split(/,/, $1);
227 dpurdie 10762
            } else {
10763
                Error ("MkdirRule: Unknown option: $_");
10764
            }
10765
        }
10766
        $data{alias} = $alias if ( $alias );
10767
 
10768
        $MkdirRuleData{$subdir} = \%data;
10769
        push @MkdirRuleOrder, $subdir;
10770
    }
10771
 
10772
    #
10773
    #   Save or print
10774
    #
10775
    return unless ( $MkdirRulePrinting );
2429 dpurdie 10776
    return if ( $MkdirRuleData{$subdir}{noCreate} );
227 dpurdie 10777
 
10778
    #
10779
    #   Create a definition of the physical directory
10780
    #
10781
    my $path = $MkdirRuleData{$subdir}{path};
261 dpurdie 10782
    MakePadded (2, $alias, ":= $path\n") if ( $path && $alias );
227 dpurdie 10783
 
10784
    #   Create an alias to be used within rules
10785
    #   The defined aliase will be prefixed with 'GBE_'
10786
    #
261 dpurdie 10787
    MakePadded (2, "GBE_$alias", ":= $subdir/$MkdirRuleGbeFile\n") if ( $alias );
227 dpurdie 10788
 
10789
    #
10790
    #   Create a recipe to create the directory
10791
    #   This is not as simple as it sounds
10792
    #   The touch is required.
10793
    #       Had 'timestamp' issues on solaris'. The 'echo' did not appear
10794
    #       to be enough. Perhaps the output was not flushed
10795
    #
261 dpurdie 10796
    MakePadded (2, "$subdir", ": $subdir/$MkdirRuleGbeFile\n");
227 dpurdie 10797
    MakePrint
10798
        "$subdir/$MkdirRuleGbeFile:\n".
10799
        "\t\$(XX_PRE)if [ ! -d $subdir ]; then \$(mkdir) -p $subdir; fi; \\\n".
10800
        "\t\$(echo) '# DO NOT REMOVE.' > \$@; \\\n".
10801
        "\t\$(touch) \$@\n\n";
10802
}
10803
 
10804
#-------------------------------------------------------------------------------
10805
# Function        : RmdirRules
10806
#
2429 dpurdie 10807
# Description     : Create the body of a recipe to delete the directories that
227 dpurdie 10808
#                   have been created.
10809
#
2429 dpurdie 10810
#                   Use JatsFileUtil rather than shell script
10811
#                       Faster under windows (and others)
10812
#                       Solved long pathname issues
10813
#                       Simpler to use and control
227 dpurdie 10814
#
10815
# Inputs          : Uses $MkdirRuleData
10816
#
10817
# Returns         : Nothing.
10818
#                   Prints to the makefile
10819
#
10820
sub RmdirRules
10821
{
2429 dpurdie 10822
    MakePrint( ".PHONY:\tunmake_dir\n" );
10823
    MakePrint( "unmake_dir:\n" );
10824
 
227 dpurdie 10825
    #
10826
    #   Determine the list of directories to delete
2429 dpurdie 10827
    #   Sort such that subdirs are deleted first
227 dpurdie 10828
    #
2429 dpurdie 10829
    my $txt = 'Removing directories';
227 dpurdie 10830
    foreach my $subdir ( reverse sort keys %MkdirRuleData )
10831
    {
2429 dpurdie 10832
        my @args = $subdir;
10833
 
5816 dpurdie 10834
        push (@args, $MkdirRuleGbeFile, 'core', '*.bak', '*.tmp', '*.err', 'utf.*.rc')
2429 dpurdie 10835
            unless $MkdirRuleData{$subdir}{remove_all};
10836
 
10837
        push (@args, @{$MkdirRuleData{$subdir}{extraFiles}})
10838
            if ( $MkdirRuleData{$subdir}{extraFiles} );
10839
 
10840
        my $mode = $MkdirRuleData{$subdir}{remove_all} ? 'T0' : 'D0';
10841
 
10842
        MakePrint ("\t-\$(AA_PRE)JatsFileUtil ", QuoteArray( $mode, $txt, @args ), "\n");
10843
        $txt = '';
227 dpurdie 10844
    }
10845
}
10846
 
10847
#-------------------------------------------------------------------------------
10848
# Function        : CreateMkdirRules
10849
#
10850
# Description     : Create Rules to make dirs at runtime
10851
#                   This function is called to instantiate those entries
10852
#                   That have been requested before the makefile has has
10853
#                   started to be created.
10854
#
10855
#                   Once this function has been called all new MkdirRule calls
10856
#                   will result in the recipes being created in-line.
10857
#
10858
# Inputs          : Nothing
10859
#
10860
# Returns         : Even Less
10861
#
10862
#
10863
sub CreateMkdirRules
10864
{
10865
    $MkdirRulePrinting = 1;
10866
    foreach my $subdir ( @MkdirRuleOrder )
10867
    {
10868
        my $data = $MkdirRuleData{$subdir};
10869
        MkdirRule($subdir, $data->{alias}, $data->{path} );
10870
    }
10871
}
10872
 
10873
#-------------------------------------------------------------------------------
10874
# Function        : PackageRule
10875
#
10876
# Description     : Generate rules and recipes to "install" and "package" files
10877
#
10878
# Inputs          : codecmd     - A code reference to the actual installer routine
10879
#                   hashp       - A reference to a INSTALL or PACKAGE hash
10880
#
299 dpurdie 10881
#                   hashp is a reference to a hash
227 dpurdie 10882
#                       The key is the full path of the install target
10883
#                       The value is (another) hash that describes the install options
10884
#
10885
#                   Valid keys are:
10886
#                       src                 - Path of the source file [Mandatory]
10887
#                       dir                 - Target directory [Mandatory]
10888
#
10889
#                       defined             - Copy the file only if value is defined
4382 dpurdie 10890
#                       Exists              - Copy the file only if it exists
227 dpurdie 10891
#                       exe                 - Mark the file as executable
10892
#                       Mode                - File modes. Default is -w
10893
#                       placekeeper         - Marks SHARED library placekeepers
10894
#                       set                 - Distribution sets
10895
#                       type                - Copy the file in DEBUG or PROD mode
10896
#                                             Valid values are "D" or "P"         
10897
#                       version             - Shared library version information
5882 dpurdie 10898
#                       symlink             - File is a symlink
227 dpurdie 10899
#                       RemoveOnly          - Do not install the file. Entries are
10900
#                                             created to allow the removal of the file
4382 dpurdie 10901
#                       NoTarget            - Reserved - Implemented elsewhere
227 dpurdie 10902
#
10903
# Returns         :
10904
#
10905
sub PackageRule
10906
{
10907
    my ($codecmd, $hashp) = @_;
10908
 
10909
    foreach my $dest ( keys %{$hashp} )
10910
    {
10911
 
10912
        my $entry = $hashp->{$dest};
5991 dpurdie 10913
        my $destText = QuoteForMake($dest,'T');
227 dpurdie 10914
        #
10915
        #   Skip placekeepers
10916
        #
10917
        next if ( $entry->{'placekeeper'} );
10918
 
10919
        #
10920
        #   Some entries are not installed via this mechanism, but can be removed
10921
        #   if they exist. Mark these as PHONY to keep targets happy
10922
        #
10923
        if ( $entry->{'RemoveOnly'} )
10924
        {
5991 dpurdie 10925
            MakePrint ".PHONY:\t$destText\n";
10926
            MakePrint "$destText:\n\n";
227 dpurdie 10927
            next;
10928
        }
10929
 
10930
        my $fname = $entry->{'src'};
5991 dpurdie 10931
        my $fnameText = QuoteForMake($fname,'S');
227 dpurdie 10932
        my $fmode = $entry->{'Mode'};
10933
        $fmode .= "+x" if ( $entry->{'exe'}  );
5882 dpurdie 10934
        $fmode .= "+l" if ( $entry->{'symlink'}  );
227 dpurdie 10935
 
10936
        #
10937
        #   User conditionional
10938
        #   Mark both the source and the target as PHONY if the condition is not met
10939
        #   This will ensure that the target need not be built.
10940
        #
10941
        my $udef = $entry->{'defined'};
10942
        if ( $udef )
10943
        {
10944
            MakePrint "ifndef $udef \n";
5991 dpurdie 10945
            MakePrint ".PHONY:\t\t$destText\n";
10946
            MakePrint ".PHONY:\t\t$fnameText\n";
10947
            MakePrint "$destText:\n";
227 dpurdie 10948
            MakePrint "else\n"
10949
        }
10950
 
10951
        #
4382 dpurdie 10952
        #   File exists
10953
        #   Only package the file if it has been generated. ie: .exe.manifest
10954
        #
10955
        my $fexist = $entry->{'Exists'};
10956
        if ($fexist)
10957
        {
5991 dpurdie 10958
            MakePrint "ifeq (\"\$(wildcard $fnameText)\",\"\")\n";
10959
            MakePrint ".PHONY:\t\t$destText\n";
10960
            MakePrint "$destText:\n";
4382 dpurdie 10961
            MakePrint "else\n"
10962
        }
10963
 
10964
        #
227 dpurdie 10965
        #   Conditional installation for DEBUG/PRODUCTION
10966
        #
10967
        my $type = $entry->{'type'};
10968
        if ( $type )
10969
        {
10970
            if ( $type eq "D" ) {
10971
                MakePrint 'ifeq "$(DEBUG)" "0"'."\n";
10972
            } elsif ( $type eq "P" ) {
10973
                MakePrint 'ifneq "$(DEBUG)" "0"'."\n";
10974
            } else {
10975
                Error("INTERNAL: Unexpected packaging type: $type");
10976
            }
5991 dpurdie 10977
            MakePrint ".PHONY:\t\t$destText\n";
10978
            MakePrint "$destText:\n";
227 dpurdie 10979
            MakePrint "else\n"
10980
        }
10981
 
10982
        #
10983
        #   The body of the copy
10984
        #
5991 dpurdie 10985
        MakePadded( 4, $destText . ':' );
10986
        MakePrint "\t" . $fnameText . "\n";
2429 dpurdie 10987
        MakePrint $codecmd->( $dest, $fname, $fmode );
227 dpurdie 10988
        MakeNewLine();
10989
 
10990
        #
10991
        #   Unwind conditionals
10992
        #
10993
        MakePrint "endif\n" if ( $type );
4382 dpurdie 10994
        MakePrint "endif\n" if ( $fexist );
227 dpurdie 10995
        MakePrint "endif\n" if ( $udef );
10996
 
10997
        #
10998
        #   Distribution sets
10999
        #
11000
        my $dist = $entry->{'set'};
11001
        if ( $dist )
11002
        {
267 dpurdie 11003
            foreach my $set ( split( ',', $dist ) )
11004
            {
11005
                push @{$PACKAGE_SETS{$set}{LIST}}, $dest;
227 dpurdie 11006
            }
11007
            MakeNewLine();
11008
        }
11009
    }
11010
}
11011
 
11012
#-------------------------------------------------------------------------------
6387 dpurdie 11013
# Function        : PackageDirRule 
11014
#
11015
# Description     : Generate special rules for dynamic packaging/installation of directories 
11016
#
11017
# Inputs          : $mode        - package_dirs/unpackage_dirs/install_dirs/uninstall_dirs
11018
#                   $dataRef     - Ref to package/install list
11019
#                       
11020
#
11021
# Returns         : 
11022
#
11023
sub PackageDirRule
11024
{
11025
    my ($mode, $dataRef) = @_;
11026
    my $me = MakeEntry::New( *MAKEFILE, $mode , '--Phony' );
11027
 
11028
    my $modeText = 'packaging';
11029
    my $cmdText = 'PackageDir';
11030
    if ($mode =~ m~install~) {
11031
        $modeText = 'installing';
11032
        $cmdText = 'InstallDir';
11033
    }
11034
    my $cmd = 'copyDir'; 
11035
    if ($mode =~ m~^un~) {
11036
        $cmd = 'unCopyDir';
11037
        $modeText = 'un' . $modeText;
11038
        $cmdText = 'Un' . $cmdText;
11039
    }
11040
 
11041
 
11042
    foreach my $entry ( @{$dataRef}) {
11043
        $me->NewSection();
11044
 
11045
        #
11046
        #   Conditional installation for DEBUG/PRODUCTION
11047
        #
11048
        my $type = $entry->{'type'};
11049
        if ( $type )
11050
        {
11051
           if ( $type eq "D" ) {
11052
               $me->SectionIfNeq('$(DEBUG)','0');
11053
           } elsif ( $type eq "P" ) {
11054
               $me->SectionIfEq('$(DEBUG)','0');
11055
           } else {
11056
               Error("INTERNAL: Unexpected packaging type: $type");
11057
           }
11058
        }
11059
 
11060
        #
11061
        #   Quote the REs so that they can be passed to a command line
11062
        #       Replace $ with $$
11063
        #
11064
        my $QuoteRe = sub {
11065
            my ($arg) = @_;
11066
            $arg=~ s~\$~\$\$~g;
11067
            return $arg;
11068
            };
11069
 
11070
        #
11071
        #   The body of the copy
11072
        #   Create a command line for run-time command
11073
        #   
11074
        my @cmd;
11075
        push @cmd, '$(JatsRunTime)', $cmd, '--', '-$(VERBOSE_OPT)', '--Name='. $cmdText, '--';
11076
        push @cmd, '-mode=' . $modeText;
11077
        push @cmd, "'" . '-src=' . $entry->{dirTree} . "'";
11078
        push @cmd, "'" . '-dst=' . $entry->{dir} . "'";
11079
        push (@cmd, '-execute' ) if $entry->{exefile};
11080
        push (@cmd, '-noSymlink' ) if $entry->{noPreserveSymlink};
11081
        push (@cmd, '-noRecurse' ) if $entry->{noRecurse};
11082
        push (@cmd, '-stripBase' ) if $entry->{strip_base};
11083
        push (@cmd, "'" . '-exclude+=' . $QuoteRe->($_) . "'" ) foreach @{$entry->{exclude}};
11084
        push (@cmd, "'" . '-include+=' . $QuoteRe->($_) . "'" ) foreach @{$entry->{include}};
11085
        push (@cmd, "'" . '-excludeRe+=' . $QuoteRe->($_) . "'" ) foreach @{$entry->{excludeRe}};
11086
        push (@cmd, "'" . '-includeRe+=' . $QuoteRe->($_) . "'" ) foreach @{$entry->{includeRe}};
11087
 
11088
        $me->AddRecipe(join(' ', @cmd ) );
11089
    }
11090
    $me->Print();
11091
}
11092
 
11093
#-------------------------------------------------------------------------------
267 dpurdie 11094
# Function        : PackageSetRules
11095
#
11096
# Description     : Generate the packageset rules
11097
#                   These appear to be a now-defuct feature
11098
#
11099
#                   By default all packaged files are a part of package_setALL
11100
#
11101
# Inputs          : None
11102
#                   Takes data from %PACKAGE_SET
11103
#
11104
# Returns         : Nothing
11105
#
11106
sub PackageSetRules
11107
{
11108
    foreach my $set ( sort keys %PACKAGE_SETS )
11109
    {
11110
        my $me = MakeEntry::New( *MAKEFILE, "package_set$set", '--Phony' );
5991 dpurdie 11111
        $me->AddDependancyEscaped( @{$PACKAGE_SETS{$set}{LIST}} );
267 dpurdie 11112
        $me->Print();
11113
    }
11114
}
11115
 
11116
#-------------------------------------------------------------------------------
227 dpurdie 11117
# Function        : UnPackageRule
11118
#
11119
# Description     : Generate rules and recipes to "uninstall" and "unpackage" files
11120
#
11121
# Inputs          : target      - Name of the target
11122
#                   codecmd     - A code reference to the actual installer routine
11123
#                   hashp       - A reference to a INSTALL or PACKAGE hash
11124
#
11125
# Returns         :
11126
#
11127
sub UnpackageRule
11128
{
11129
    my ($target, $codecmd, $hashp) = @_;
11130
 
11131
    MakePrint ".PHONY:\t\t"."$target\n";
11132
    MakePrint "$target:\t";
11133
 
11134
    foreach my $dest ( sort keys %{$hashp} )
11135
    {
11136
 
11137
        my $entry = $hashp->{$dest};
11138
 
11139
        #
11140
        #   Skip placekeepers
11141
        #
11142
        next if ( $entry->{'placekeeper'} );
11143
 
11144
        MakePrint "\n" . $codecmd->($dest);
11145
    }
11146
    MakePrint "\n\n";
11147
}
11148
 
11149
 
11150
#
11151
#   Internal macro interface, see RULE.STD for definitions:
11152
#
11153
sub RmFilesCmd
11154
{
11155
    my ( $list ) = @_;
261 dpurdie 11156
    return "\$(call RmFiles,$list)";
227 dpurdie 11157
}
11158
 
11159
sub InstallCmd
11160
{
2429 dpurdie 11161
    my( $dest, $file, $fmode ) = @_;
227 dpurdie 11162
 
11163
    $fmode = "-w"                           # default, read-only
11164
        if ( !defined( $fmode ) || $fmode eq "" );
11165
 
5991 dpurdie 11166
    $dest = QuoteForMake($dest);
11167
    $file = QuoteForMake($file);
2429 dpurdie 11168
    return "\t\$(call InstallFile,$dest,$file,$fmode)";
227 dpurdie 11169
}
11170
 
11171
sub UninstallCmd
11172
{
11173
    my( $file ) = @_;
5991 dpurdie 11174
    $file = QuoteForMake($file);
227 dpurdie 11175
    return "\t\$(call UninstallFile,$file)";
11176
}
11177
 
11178
sub PackageCmd
11179
{
2429 dpurdie 11180
    my( $dest, $file, $fmode ) = @_;
227 dpurdie 11181
 
11182
    $fmode = "-w"                           # default, read-only
11183
        if ( !defined( $fmode ) || $fmode eq "" );
11184
 
5991 dpurdie 11185
    $dest = QuoteForMake($dest);
11186
    $file = QuoteForMake($file);
2429 dpurdie 11187
    return "\t\$(call PackageFile,$dest,$file,$fmode)";
227 dpurdie 11188
}
11189
 
11190
sub UnpackageCmd
11191
{
11192
    my( $file ) = @_;
5991 dpurdie 11193
    $file = QuoteForMake($file);
227 dpurdie 11194
    return "\t\$(call UnpackageFile,$file)";
11195
}
11196
 
11197
1;
11198