Subversion Repositories DevTools

Rev

Rev 6403 | Rev 6423 | 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
 
3306
 
3307
    #
3308
    #   Save information
3309
    #   Will be used to create makefile statements later
3310
    #
3311
    my %gen_data;
3312
 
3313
    $gen_data{'index'}      = $NoGenIndex++;
6415 dpurdie 3314
    $gen_data{'recipeTag'}  = $recipeTag if defined $recipeTag;
227 dpurdie 3315
    $gen_data{'shell'}      = $shell_cmds;
3316
    $gen_data{'gen'}        = \@gen_files;
3317
    $gen_data{'preq'}       = \@preq_files;
3318
    $gen_data{'tool'}       = $tool;
3319
    $gen_data{'toolargs'}   = \@tool_args;
3320
    $gen_data{'clean'}      = $clean_tag;
3321
    $gen_data{'text'}       = $text || $gen_files[0];
3322
    $gen_data{'preq_sus'}   = 1 if ( $preq_unknown );
263 dpurdie 3323
    $gen_data{'predelete'}  = 1 if ( $predelete );
227 dpurdie 3324
 
3325
    push(@GENERATE_FILES, \%gen_data);
6387 dpurdie 3326
#DebugDumpData("GenerateFiles", \%gen_data);
227 dpurdie 3327
    Debug2( "GenerateFiles: cmd: $tool @tool_args" );
3328
}
3329
 
3330
#-------------------------------------------------------------------------------
3331
# Function        : MakePerlModule
3332
#
3333
# Description     : Build Perl Module(s) using the Perl Build System
3334
#                   This is a thin wrapper around a specialised script
3335
#
3336
#                   The user can do the same job with correct use of
3337
#                   a GenerateFiles, but this is a lot tidier.
3338
#
3339
# Inputs          : $1      - platform specifier '*' (comma delemitered)
3340
#                   $*      - Paths to Perl Modules[,command options]
3341
#                             Options to the BuildPerl script
3342
#
3343
# Returns         :
3344
#
3345
sub MakePerlModule
3346
{
3347
    my ( $platforms, @args) = @_;
3348
 
3349
    return if ( ! ActivePlatform($platforms) );
3350
 
3351
    Debug2( "MakePerlModule:($platforms, @args)" );
3352
    my @opts;
3353
 
3354
    #
3355
    #   Extract options from paths to Perl Packages
3356
    #   Package names do not start with a '-'
3357
    #
3358
    foreach my $arg ( @args )
3359
    {
3360
        if ( $arg =~ /^-/ ) {
3361
            push @opts, $arg;
3362
 
3363
        } else {
3364
            #
3365
            #   Perl Package Directory Name
3366
            #   This may also contain embedded command to the Make command
3367
            #   These will be seperated with a comma
3368
            #       ie: module,-options=fred
3369
            #
3370
            my ($name,$options) = split( ',', $arg );
3371
            push @opts, "-PerlPackage=$arg";
3372
            push @opts, "--Prereq=$name/Makefile.PL";
3373
        }
3374
    }
3375
 
3376
    #
3377
    #   Invoke GenerateFiles with a bunch of additional arguments
3378
    #
3379
    GenerateFiles ($platforms, "--Tool=jats_buildperl.pl",
3380
                          '--Var(MachType)',                        # Build Machine type
3381
                          '--Var(PackageDir)',                      # Package dir
3382
                          '--NoGenerate',                           # Don't know the output
3383
                          '--Text=Make Perl Module',                # Pretty print
3384
                          '--NoWarn',
3385
                          '--Clean=-clean_build',                   # Jats clean support
3386
                          '--NoVarTag',                             # No more Tags
3387
                          @opts,
3388
                          );
3389
}
3390
 
3391
#-------------------------------------------------------------------------------
3392
# Function        : MakeLinuxDriver
3393
#
3394
# Description     : Build a Linux Device Driver using the Linux Device Driver
3395
#                   Build System
3396
#                   This is a thin wrapper around a specialised script
3397
#
3398
#                   The user can do the same job with correct use of
3399
#                   a GenerateFiles, but this is a lot tidier.
3400
#
3401
# Inputs          : $1      - platform specifier '*' (comma delemitered)
3402
#                   $2      - name of the driver. No extension
3403
#                   $*      - Driver sources
3404
#                             Options to the script
3405
#
3406
# Returns         :
3407
#
3408
sub MakeLinuxDriver
3409
{
3410
    my ( $platforms, $driver_name, @args) = @_;
3411
 
3412
    return if ( ! ActivePlatform($platforms) );
3413
 
285 dpurdie 3414
    Error ("No driver name specified") unless ( $driver_name );
227 dpurdie 3415
    Debug2( "MakeLinuxDriver:($platforms, $driver_name ,@args)" );
3416
    my @srcs;
3417
    my @opts;
3418
 
3419
    #
3420
    #   Extract options from source files
3421
    #   Package names do not start with a '-'
3422
    #
3423
    foreach my $arg ( @args )
3424
    {
3425
         if ( $arg =~ /^--Define=(.)/ ) {
3426
            push @opts, $arg;
5672 dpurdie 3427
 
3428
         } elsif ( $arg =~ /^--ExternalModule=(.)/ ) {
3429
               push @opts, $arg;
227 dpurdie 3430
 
3431
         } elsif ( $arg =~ /^-/ ) {
3432
            push @opts, $arg;
3433
            Warning ("MakeLinuxDriver: Unknown option: $arg. Passed to script");
3434
 
3435
        } else {
3436
            push @srcs, $arg;
3437
            push @opts, "--Prereq=$arg";
3438
        }
3439
    }
3440
 
3441
    #
3442
    #   Cleanup the drive name
3443
    #
3444
    $driver_name =~ s~\.ko$~~;
3445
 
3446
    #
3447
    #   Remove the specified sources from the list of object files
3448
    #   that will be build. This will ensure that some internal rules are
3449
    #   not generated.
3450
    #
3451
    foreach ( @srcs )
3452
    {
3453
        my $file = StripExt(StripDir( $_ ));
3454
        delete $OBJSOURCE{ $file };
3455
        @OBJS = grep(!/^$file$/, @OBJS);
3456
    }
3457
 
3458
    #
3459
    #   Invoke GenerateFiles with a bunch of additional arguments
3460
    #   At runtime the include directories will be added as
3461
    #   absolute paths
3462
    #
3463
    GenerateFiles ($platforms, "--Tool=jats_buildlinux.pl",
3464
                    "-Output=--GeneratedProg($driver_name.ko)",
3465
                    "-Driver=$driver_name",
3466
                    "-GccPath=\$(GCC_CC)",
3467
                    "-Arch=\$(HOST_CPU)",
3468
                    "-LeaveTmp=\$(LEAVETMP)",
3469
                    "-Verbose=\$(CC_PRE)",
3470
                    "-Type=\$(GBE_TYPE)",
3471
                    "-Platform=\$(GBE_PLATFORM)",
5672 dpurdie 3472
                    "--Var(LocalBinDir)",
227 dpurdie 3473
                    '$(patsubst %,-Incdir=%,$(INCDIRS))',
5672 dpurdie 3474
                    '--Clean',
227 dpurdie 3475
                    @opts,
3476
                    @srcs
3477
                    );
3478
}
3479
 
3480
#-------------------------------------------------------------------------------
3481
# Function        : GetPackageBase
3482
#
3483
# Description     : Helper routine
3484
#                   Given a package name, determine the base address of the
3485
#                   package
3486
#
3487
# Inputs          : $dname         - Directive name     (Reporting)
3488
#                   $name          - Required package
3489
#                                    Allows two forms:
3490
#                                       package_name
3491
#                                       package_name,ext
3492
#
3493
# Returns         : Path to the directory in which the files are installed
3494
#                   This may be the interface directory
3495
#
3496
sub GetPackageBase
3497
{
3498
    my ($dname, $fname) = @_;
3499
    my $pkg;
3500
    my ($name, $ext) = split(',', $fname);
3501
 
3502
    $pkg = GetPackageEntry( $name, $ext );
3503
    Error ("$dname: Package not found: $fname") unless ( $pkg );
3504
 
3505
    #
3506
    #   If a BuildPkgArchive then use the interface directory
3507
    #
3508
    return ( $pkg->{'TYPE'} eq 'link' ) ? $pkg->{'ROOT'} : '$(INTERFACEDIR)';
3509
}
3510
 
3511
#-------------------------------------------------------------------------------
3512
# Function        : GetPackageInfo
3513
#
3514
# Description     : Helper routine
3515
#                   Given a package name, return some information about the package
3516
#                   Only one information item is allowed with each call
3517
#
3518
# Inputs          : $dname         - Directive name     (Reporting)
3519
#                   $name          - Required package
3520
#                                    Allows two forms:
3521
#                                       package_name
3522
#                                       package_name,ext
3523
#                                    Selector
3524
#                                       --path
3525
#                                       --version
3526
#                                       --fullversion
3527
#                                       --project
3528
#
3529
# Returns         : Package information
3530
my %GetPackageInfo = qw(path ROOT
3531
                        version DVERSION
3532
                        fullversion VERSION
3533
                        project DPROJ);
3534
sub GetPackageInfo
3535
{
3536
    my ($dname, $args) = @_;
3537
    my $pkg;
3538
    my $name;
3539
    my $ext;
3540
    my $info;
3541
 
363 dpurdie 3542
    #
3543
    #   Split up the arguments
3544
    #       Options start with '--'
3545
    #   First non-option is the package name
3546
    #   2nd non-option is the packag extension
3547
    #
3548
    #   Only one option allowed
3549
    #       Convert it into a known package info item
3550
    #
3551
    #
227 dpurdie 3552
    foreach ( split(',', $args) )
3553
    {
3554
        if ( m/^--(.*)/ ) {
3555
            Error( "$dname: Too many info requests: $args") if ( $info );
3556
            $info = $GetPackageInfo{$1};
3557
            Error( "$dname: Unknown info type: $_") unless ($info);
363 dpurdie 3558
 
227 dpurdie 3559
        } elsif ( $ext ) {
3560
            Error("$dname: Too many names: $args");
363 dpurdie 3561
 
227 dpurdie 3562
        } elsif ( $name ) {
3563
            $ext = $_;
363 dpurdie 3564
 
227 dpurdie 3565
        } else {
3566
            $name = $_;
3567
        }
3568
    }
3569
 
3570
    $pkg = GetPackageEntry( $name, $ext );
3571
    Error ("$dname: Package not found: $args") unless ( $pkg );
3572
 
3573
    #
3574
    #   If a BuildPkgArchive then use the interface directory
363 dpurdie 3575
    #   Default data item - path to the package
227 dpurdie 3576
    #
363 dpurdie 3577
    $info = 'ROOT' unless ( $info );
3578
    if ( $info eq 'ROOT' &&  $pkg->{'TYPE'} ne 'link' )
227 dpurdie 3579
    {
3580
        return ( '$(INTERFACEDIR)');
3581
    }
363 dpurdie 3582
 
227 dpurdie 3583
    return ( $pkg->{$info} );
3584
}
3585
 
3586
#-------------------------------------------------------------------------------
3587
# Function        : GetPackageEntry
3588
#
3589
# Description     : Return the package class pointer given a package name
3590
#
3591
# Inputs          : $name          - Required package
3592
#                   $ext           - Option package extension
3593
#
3594
# Returns         : Class pointer
3595
#
3596
sub GetPackageEntry
3597
{
3598
    my ($name, $ext) = @_;
3599
    $ext = '' unless ( $ext );
3600
 
3601
    for my $entry (@{$::ScmBuildPkgRules{$ScmPlatform} })
3602
    {
3603
        next unless ( $entry->{'NAME'} eq $name );
3604
        next if ( $ext && $entry->{'DPROJ'} ne $ext );
3605
        return $entry;
3606
    }
285 dpurdie 3607
    return;
227 dpurdie 3608
}
3609
 
3610
#-------------------------------------------------------------------------------
3611
# Function        : ExpandGenVar
3612
#
3613
# Description     : Expand a known variable for the Generate Files option
3614
#
3615
# Inputs          : $dname         - Directive name     (Reporting)
3616
#                   $arg           - Raw argument
3617
#                                    This of the form of
3618
#                                       Tag[,--option]+
3619
#                                    Tags are specified in %ExpandGenVarConvert
3620
#
3621
#                                   Options are:
3622
#                                       --tag
3623
#                                       --notag
3624
#                                       --tag=<SomeTag>
3625
#                                       --absdrive
3626
#                                       --abspath
285 dpurdie 3627
#                                       --default=text
343 dpurdie 3628
#                                       --allownone
227 dpurdie 3629
#                                   Not all options are avalaible on all variables
3630
#                   @opts           - Options
3631
#                                       --notag     - Default is --notag
3632
#
343 dpurdie 3633
# Returns         : Tag             - Any tag component of the expansion
3634
#                   Path/Value      - Path/Value of the component
3635
#                   is_path         - Above is a path
3636
#                   is_abs          - Path is absolute
227 dpurdie 3637
#
3638
 
3639
#
3640
#   Create a Hash to simplify the process of converting Var names
343 dpurdie 3641
#   into makefile variables. There are two data items, separated by a comma.
3642
#       The first is the runtime expansion value
3643
#       The second describes the first:
3644
#           NotPresent  - Expansion is not a path
3645
#           '-'         - Expansion is a path and is relative to CWD
3646
#           '+'         - Expansion is a path and is absolute
227 dpurdie 3647
#
3648
my %ExpandGenVarConvert = (
3649
    'BuildName'         => '$(GBE_PBASE)',
3650
    'BuildVersion'      => '$(BUILDVER)',
3651
    'BuildVersionNum'   => '$(BUILDVERNUM)',
3652
 
3653
    'PackageDir'        => '$(PKGDIR),+',
3654
    'PackagePkgDir'     => '$(PKGDIR)/pkg/pkg.$(GBE_PLATFORM),+',
3655
    'PackageIncDir'     => '$(INCDIR_PKG),+',
6133 dpurdie 3656
    'PackageIncPlatDir' => '$(INCDIR_PKG)/$(GBE_PLATFORM),+',
227 dpurdie 3657
    'PackageLibDir'     => '$(LIBDIR_PKG)/$(GBE_PLATFORM),+',
3658
    'PackageBinDir'     => '$(BINDIR_PKG)/$(GBE_PLATFORM)$(GBE_TYPE),+',
3659
 
3660
    'PackageToolDir'    => '$(PKGDIR)/tools,+',
3661
    'PackageToolBin'    => '$(PKGDIR)/tools/bin/$(GBE_HOSTMACH),+',
3662
    'PackageToolScript' => '$(PKGDIR)/tools/scripts,+',
3663
 
3664
    'LibDir'            => '$(LIBDIR),+',
3665
    'BinDir'            => '$(BINDIR),+',
3666
    'ObjDir'            => '$(OBJDIR),+',
3667
 
3668
    'InterfaceDir'      => '$(INTERFACEDIR),+',
3669
    'InterfaceIncDir'   => '$(INCDIR_INTERFACE),+',
3670
    'InterfaceLibDir'   => '$(LIBDIR_INTERFACE)/$(GBE_PLATFORM),+',
3671
    'InterfaceBinDir'   => '$(BINDIR_INTERFACE)/$(GBE_PLATFORM)$(GBE_TYPE),+',
3672
 
3673
    'LocalDir'          => '$(LOCALDIR),+',
3674
    'LocalIncDir'       => '$(INCDIR_LOCAL),+',
3675
    'LocalLibDir'       => '$(LIBDIR_LOCAL)/$(GBE_PLATFORM),+',
3676
    'LocalBinDir'       => '$(BINDIR_LOCAL)/$(GBE_PLATFORM)$(GBE_TYPE),+',
3677
 
3678
    'Platform'          => '$(GBE_PLATFORM)',
3679
    'Product'           => '$(GBE_PRODUCT)',
3680
    'Target'            => '$(GBE_TARGET)',
3681
 
3682
    'Type'              => '$(GBE_TYPE)',
3683
    'Arch'              => '$(HOST_CPU)',
3684
    'Architecture'      => '$(HOST_CPU)',
3685
    'MachType'          => '$(GBE_HOSTMACH)',
3686
    'BuildRoot'         => '$(GBE_ROOT),+',
3687
 
3688
 
3689
    'Verbose'           => '$(CC_PRE)',
3690
    'LeaveTmp'          => '$(LEAVETMP)',
329 dpurdie 3691
    'Cwd'               => '$(CURDIR),-',
227 dpurdie 3692
 
6133 dpurdie 3693
    # Generated when used
227 dpurdie 3694
    'CompilerPath'      => '$(SCM_COMPILERPATH)',
3967 dpurdie 3695
    'PkgArch'           => '$(PACKAGE_ARCH)',
6133 dpurdie 3696
 
3697
    'Native'            => '0',
3698
    'Toolset'           => '0',
3699
 
227 dpurdie 3700
    );
3701
 
3702
sub ExpandGenVar
3703
{
3704
    my ($dname, $args, @uopts) = @_;
3705
    my $expansion;
3706
    my $prefix='';
3707
    my ($tag, @opts) = split('\s*,\s*', $args);
3708
    my $no_prefix;
285 dpurdie 3709
    my $default_value;
3710
    my $allow_none;
329 dpurdie 3711
    my $is_abs = 0;
227 dpurdie 3712
 
285 dpurdie 3713
    #
3714
    #   Parse options lists
3715
    #       Options provided by the caller
3716
    #       Options embedded in the argument
227 dpurdie 3717
    foreach ( @uopts )
3718
    {
3719
        if ( m/^--notag$/ ) {
3720
            $no_prefix = 1;
3721
        } else{
3722
            Error ("$dname: Unknown option: $_")
3723
        }
3724
    }
3725
 
285 dpurdie 3726
    foreach ( @opts )
3727
    {
3728
        if ( m/^--default=(.+)/i ) {
3729
            $default_value = $1;
3730
        } elsif ( m/^--allownone$/i ) {
3731
            $allow_none = 1;
3732
        }
3733
    }
3734
 
227 dpurdie 3735
    #
3736
    #   Perform run-time update on the %ExpandGenVarConvert
3737
    #   Most of it can be initialised at startup - but not all of it.
3738
    #
3739
    $ExpandGenVarConvert{CompilerPath} = undef unless $::ScmToolsetCompilerPath;
3740
    $ExpandGenVarConvert{Product}      = '$(GBE_PLATFORM)' unless $ScmProduct;
3741
 
6133 dpurdie 3742
    $ExpandGenVarConvert{Native}      = '1'  if isAnAlias ('NATIVE');
3743
    $ExpandGenVarConvert{Toolset}     = '1'  if isAnAlias ('TOOLSET');
3744
 
3745
 
227 dpurdie 3746
    #
3747
    #   Look up a hash of conversions
3748
    #   Could allow for a code ref, but not needed yet
3749
    #
3750
    Error ("$dname: Unknown expansion --Var($tag)")
3751
        unless ( exists $ExpandGenVarConvert{$tag} );
3752
 
285 dpurdie 3753
    #
3754
    #   Handle undefined expansions
3755
    #   Only 'CompilerPath', but it can be a pain in user land
3756
    #
3757
    $expansion = $ExpandGenVarConvert{$tag};
3758
    unless ( defined $expansion  )
3759
    {
3760
        return '' if ( $allow_none );
3761
        $expansion = $default_value;
3762
        Error ("$dname: Expansion --Var($tag) not be supported by toolset: $ScmToolset")
3763
            unless ( $expansion );
3764
    }
227 dpurdie 3765
 
285 dpurdie 3766
 
227 dpurdie 3767
    ($expansion,my $is_path) = split (',', $expansion );
329 dpurdie 3768
    $is_abs = 1
3769
        if ($is_path && $is_path eq '-' );
227 dpurdie 3770
 
3771
    #
3772
    #   Process options
3773
    #   Assume that a tag will be provided
3774
    #
3775
    $prefix =  $no_prefix ? '' : "-$tag=";
3776
    foreach my $opt ( @opts )
3777
    {
3778
        if ( $opt =~ /^--tag=(.*)/i ) {
3779
            $prefix = "$1=";
3780
 
3781
        } elsif ( $opt =~ m/^--tag$/i ) {
3782
            $prefix = "-$tag=";
3783
 
3784
        } elsif ( $opt =~ m/^--notag/i ) {
3785
            $prefix = '';
3786
 
329 dpurdie 3787
        } elsif ( $is_path && !$is_abs && $opt =~ /--abspath|--absdrive/i ) {
227 dpurdie 3788
            $expansion = '$(CURDIR)/' . $expansion;
329 dpurdie 3789
            $is_abs = 1;
227 dpurdie 3790
 
285 dpurdie 3791
        } elsif ( $opt =~ m/^--default=(.+)/i ) {
3792
            # Already processed
3793
        } elsif ( $opt =~ m/^--allownone$/i ) {
3794
            # Already processed
227 dpurdie 3795
        } else {
3796
            Error ("$dname: Unsupported option($opt) for --Var(@_)");
3797
        }
3798
    }
3799
 
3800
    Debug ("ExpandGenVar: args $args --> $prefix$expansion");
343 dpurdie 3801
    return $prefix , $expansion, $is_path ? 1 : 0, $is_abs;
227 dpurdie 3802
 
3803
}
3804
 
3805
#-------------------------------------------------------------------------------
6133 dpurdie 3806
# Function        : isAnAlias 
3807
#
3808
# Description     : Internal Helper
3809
#                   Determine if this platform is an alias for ...
3810
#
3811
# Inputs          :  $target    - Test against this target
3812
#
3813
# Returns         :  True - Is an alais for $target.
3814
#
3815
sub isAnAlias
3816
{
3817
    my ($target) = @_;
3818
    if (exists ($::BUILDINFO{$ScmPlatform}{'USERALIAS'}) )
3819
    {
3820
        if ( grep /^$target$/, @{$::BUILDINFO{$ScmPlatform}{'USERALIAS'}} )
3821
        {
3822
                return 1;    
3823
        }
3824
 
3825
    }
3826
    if (exists ($::BUILDINFO{$ScmPlatform}{'ALIAS'}) )
3827
    {
3828
        if ( $target eq $::BUILDINFO{$ScmPlatform}{'ALIAS'} )
3829
        {
3830
                return 1;    
3831
        }
3832
    }
3833
 
3834
    return 0;
3835
}
3836
 
3837
#-------------------------------------------------------------------------------
227 dpurdie 3838
# Function        : ProcessPathName
3839
#
3840
# Description     : Massage a pathname according to a set of flags
3841
#
3842
# Inputs          : $fn         - Patchname to massage
3843
#                   $flags      - Flags in a string
3844
#                                   --dir       - only the directory part ( or a "." )
3845
#                                   --file      - only the file part
3846
#                                   --abspath   - Absolute path
3847
#                                   --absdrive  - Absolute path with drive letter(WIN)
3848
#
3849
# Returns         : Massaged pathname
3850
#
3851
sub ProcessPathName
3852
{
3853
    my ( $fn, $flags ) = @_;
3854
    #
3855
    #   Process flags
3856
    #       --dir           - only the directory part ( or a "." )
3857
    #       --file          - only the file part
3858
    #       --abspath       - Absolute path
3859
    #       --absdrive      - Absolute path with drive letter(WIN)
3860
    #
3861
    if ( $flags =~ /--dir/ )
3862
    {
3863
        $fn = '.'
3864
            unless ( $fn =~ s~/[^/]*$~~);
3865
    }
3866
 
3867
    if ( $flags =~ /--file/ )
3868
    {
3869
        $fn =~ s~.*/~~;
3870
    }
3871
 
3872
    if ( $flags =~ /--abspath/ )
3873
    {
3874
        $fn = AbsPath( $fn );
3875
    }
3876
    elsif ( $flags =~ /--absdrive/ )
3877
    {
3878
        $fn = AbsPath( $fn );
3879
        if ( $::ScmHost eq "WIN" )
3880
        {
3881
            $fn = $::CwdDrive . '/' . $fn
3882
                unless ( $fn =~ m~^\w:/~  );
3883
            $fn =~ s~//~/~g;
3884
        }
3885
    }
3886
 
3887
  return $fn;
3888
}
3889
 
3890
#-------------------------------------------------------------------------------
3891
# Function        : LocatePreReq
3892
#
3893
# Description     : Locate a file known to JATS
3894
#                   There are many places to search
3895
#                       1) Src files - specified with a Src directive
3896
#                       2) Scripts - specified with a script directive
3897
#                       3) Search - Files in the specified search path
3898
#                       4) Programs specified with a 'Prog' directive
3899
#
3900
#                   Should also look in other locations (Libs, SharedLibs)
3901
#                   Not done yet. May be issues of a name clash if a program
3902
#                   and a library have the same name.
3903
#
3904
# Inputs          : Name to locate
3905
#
3906
# Returns         : Full pathname of file
3907
#
3908
sub LocatePreReq
3909
{
3910
    my ( $name ) = @_;
3911
    Debug ("LocatePreReq:Looking for $name");
3912
    #
3913
    #   Try a Src file first
3914
    #
3915
    if ( exists $SRCS{ $name } )
3916
    {
3917
        return $SRCS{ $name };
3918
    }
3919
 
3920
    #
3921
    #   Try a script
3922
    #
3923
    if ( exists $SCRIPTS{ $name } )
3924
    {
3925
        return $SCRIPTS{ $name };
3926
    }
3927
 
3928
    #
3929
    #   Try a PROG
3930
    #
289 dpurdie 3931
    if ( my $pProg = $PROGS->Get($name) )
227 dpurdie 3932
    {
289 dpurdie 3933
        return $pProg->getPath();
227 dpurdie 3934
    }
3935
 
3936
    #
3937
    #   Try searching for the file
3938
    #   Uses Data from AddSrcDir
3939
    #
3940
    #   Done: last because it generates warning messages
3941
    #
3942
    return MakeSrcResolve( $name );
3943
}
3944
 
3945
#-------------------------------------------------------------------------------
3946
# Function        : ToolExtensionPaths
3947
#
3948
# Description     : Return a list of toolset extension directories
3949
#                   The data will have been discovered by the build process
3950
#                   and will have been saved for the makefile creation phase
3951
#
3952
# Inputs          : None
3953
#
3954
# Returns         : Return an ordered unique list
3955
#
3956
sub ToolExtensionPaths
3957
{
3958
    Debug( "ToolExtensionPaths:", @::BUILDTOOLSPATH );
3959
    return @::BUILDTOOLSPATH;
3960
}
3961
 
3962
#-------------------------------------------------------------------------------
3963
# Function        : ToolExtensionProgram
3964
#
3965
# Description     : Determine if the named program exists within the PATH
3966
#                   that also includes the toolset extension
3967
#
3968
# Inputs          : program             - Name of program
3969
#                   elist               - An array of possible program extensions
3970
#
4324 dpurdie 3971
# Returns         : Full path the to program or an empty elelent (not undef)
227 dpurdie 3972
#
3973
sub ToolExtensionProgram
3974
{
3975
    my ($program, @elist ) = @_;
3976
 
3977
    #
3978
    #   If elist is empty then insert a defined entry
3979
    #
3980
    push @elist, '' unless ( @elist );
3981
 
3982
    #
3983
    #   Scan all toolset directories
3984
    #   for the program
3985
    #
3986
    for my $dir ( ToolExtensionPaths() )
3987
    {
3988
        for my $ext ( @elist )
3989
        {
3990
            my $tool = "$dir/$program$ext";
4324 dpurdie 3991
            Debug( "ToolsetExtensionProgram: Look for: $tool" );
227 dpurdie 3992
 
3993
            return $tool if ( -f $tool );
3994
        }
3995
    }
3996
}
3997
 
3998
sub Define
3999
{
4000
    Debug2( "Define(@_)" );
4001
 
4002
    push( @DEFINES, @_ );
4003
}
4004
 
4005
 
4006
sub Defines
4007
{
4008
    my( $path, $script ) = @_;
4009
    my( $line );
4010
 
4011
    Debug2( "Defines($path, $script)" );
4012
 
4013
    $script = Exists( $path, $script, "Defines" );
271 dpurdie 4014
    push( @DEFINES, "# Defines from: $script" );
285 dpurdie 4015
    open( my $fh, '<', $script ) || Error( "Opening $script" );
4016
    while (<$fh>) {
227 dpurdie 4017
        $_ =~ s/\s*(\n|$)//;                    # kill trailing whitespace & nl
4018
        push( @DEFINES, $_ );
4019
    }
4020
    push( @ScmDepends, "$script" );             # makefile dependencies
285 dpurdie 4021
    close( $fh );
227 dpurdie 4022
}
271 dpurdie 4023
#-------------------------------------------------------------------------------
4024
# Function        : Rule
4025
#
4026
# Description     : Add a Rule and Recipe to the generated makefile
4027
#                   This is not encouraged as it has been misused to create
4028
#                   unreadable and unmaintainable makefiles.
4029
#
4030
#                   Rules will be added to the makefile after the rules and
4031
#                   recipes created by JATS directives
4032
#
4033
# Inputs          : $platform               - Platform predicate
4034
#                   @rule                   - Array of rules to add
4035
#
4036
# Returns         : 
4037
#
227 dpurdie 4038
sub Rule
4039
{
4040
    my( $platforms, @rule ) = @_;
4041
 
4042
    return if ( ! ActivePlatform($platforms) );
4043
 
4044
    push( @RULES, @rule );
4045
    Message("Rule directive used. Consider replacing with GenerateFiles");
4046
}
4047
 
271 dpurdie 4048
#-------------------------------------------------------------------------------
4049
# Function        : Rules
4050
#
4051
# Description     : Add a file of Rules and Recipes to the generated makefile
4052
#                   Used internally ONLY as there is no platform predicate
4053
#                   Similar to 'Rule()'
4054
#
4055
# Inputs          : $path                   - path to script
4056
#                   $script                 - File fo Rules
4057
#
4058
# Returns         : 
4059
#
227 dpurdie 4060
sub Rules
4061
{
4062
    my( $path, $script ) = @_;
4063
    my( $line );
4064
 
4065
    $script = Exists( $path, $script, "Rules" );
271 dpurdie 4066
    push( @RULES, "# Rules from: $script" );
285 dpurdie 4067
    open( my $fh, '<', $script ) || Error( "Opening $script" );
4068
    while (<$fh>) {
227 dpurdie 4069
        $_ =~ s/\s*(\n|$)//;                    # kill trailing whitespace & nl
4070
        push( @RULES, $_ );
4071
    }
4072
    push( @ScmDepends, "$script" );             # makefile dependencies
285 dpurdie 4073
    close( $fh );
227 dpurdie 4074
}
4075
 
271 dpurdie 4076
#-------------------------------------------------------------------------------
4077
# Function        : AddRule
4078
#
4079
# Description     : Inernal function
4080
#                   Add a line to the Rules area
4081
#
4082
# Inputs          : @elements                   - Array of lines to add
4083
#
4084
# Returns         : Nothing
4085
#
4086
sub AddRule
4087
{
4088
    push( @RULES, @_ );
4089
}
227 dpurdie 4090
 
271 dpurdie 4091
#-------------------------------------------------------------------------------
4092
# Function        : Src
4093
#
4094
# Description     : This directive is used to identify files to JATS
4095
#                   Once a file has been identified as a 'Source' file, then it
4096
#                   can be used by name, without the need to locate the file again.
4097
#                   This implies that filenames must be unique.
4098
#                   The directories cannot be used to make files of the same name
4099
#                   unqiue - this is not the JATS way
4100
#
4101
#                   Source files will be classified as one of:
4102
#                       c, c++, header, assembler or other
4103
#
4104
#
4105
# Inputs          : $platform               - Active Platform Predicate
4106
#                   @elements               - A list of files and options
4107
#
4108
#                   Valid options are:
4109
#                       --c                 - Specifies the type of file
4110
#                       --cpp
4111
#                       --h, --headers
4112
#                       --asm
4113
#                       --FromPackage       - Search packages for the file
4114
#                       --List=xxx          - Append file to a named list
4115
#                       --Depends=xxx       - Manually name a dependency
6387 dpurdie 4116
#                       --IgnoreDuplicates  - Ignore duplicates (mostly internal use)
271 dpurdie 4117
#
4118
#                   Options are processed before file elements
4119
#                   Thus options apply to all files in the list
4120
#
4121
# Returns         : Nothing
4122
#
227 dpurdie 4123
sub Src
4124
{
4125
    my( $platforms, @elements ) = @_;
6387 dpurdie 4126
    my( $type, @args, $source, $basename, $from_package, @lists, $ignoreDups );
227 dpurdie 4127
    my( @depends, @srcs );
4128
 
4129
    $platforms = '' unless ( $platforms );
4130
    Debug2( "Src($platforms, @elements)" );
4131
 
4132
    #
4133
    #   Ensure that there is a file within the list
4134
    #
4135
    Warning( "Src directive does not specify any files: Src($platforms, @elements)" )
4136
        unless (grep( /^[^-]/, @elements ) );
4137
 
4138
    return if ( ! ActivePlatform($platforms) );
4139
 
4140
    #
4141
    #   Remove spaces from both ends of the arguments.
4142
    #   It is easier to remove spaces now than to detect them later
4143
    #
4144
    foreach ( @elements )
4145
    {
4146
        s/^\s+//;
4147
        s/\s+$//;
4148
        s~//~/~g;                               # Remove multiple /
4149
    }
4150
 
4151
    #.. Collect arguments
4152
    #
4153
    $type = "";
4154
    foreach ( @elements )
4155
    {
4156
        if ( /^--c$/ )
4157
        {
4158
            Debug( "Src: --c" );
4159
            $type = ".c";
4160
        }
4161
        elsif ( /^--cpp$/ )
4162
        {
4163
            Debug( "Src: --cpp" );
4164
            $type = ".cc";
4165
        }
4166
        elsif ( /^--h$/ || /^--header$/ )
4167
        {
4168
            Debug( "Src: --h" );
4169
            $type = ".h";
4170
        }
4171
        elsif ( /^--asm$/ )
4172
        {
4173
            Debug( "Src: --asm" );
4174
            $type = ".asm";
4175
        }
6387 dpurdie 4176
        elsif ( /^--IgnoreDup/ )
4177
        {
4178
            $ignoreDups = 1;
4179
        }
227 dpurdie 4180
        elsif ( /^--FromPackage$/ )
4181
        {
4182
            $from_package = 1;
4183
        }
4184
        elsif ( /^--List=(.*)/ )
4185
        {
4186
            my $list_name = $1;
4187
            Error( "Bad list name: $list_name" )
4188
                unless ( $list_name =~ m/^[A-Za-z]\w+/ );
4189
            push @lists, $list_name;
4190
        }
4191
        elsif ( /^--Depends=(.*)/ )
4192
        {
4193
            foreach ( split( ',', $1) )
4194
            {
4195
                my $full = MakeSrcResolveExtended( $from_package, $_ );
4196
                push @depends, $full;
4197
            }
4198
        }
4199
        elsif ( /^-(.*)/ )
4200
        {
4201
            Debug( "Src: arg $_" );
4202
            push @args, $_;
4203
        }
4204
        else
4205
        {
4206
            push @srcs, $_;
4207
            Warning ("Src files contains a '\\' character: $_" ) if (m~\\~);
4208
        }
4209
    }
4210
 
4211
    #.. Push source file(s)
4212
    foreach ( @srcs )
4213
    {
4214
        if ( ! /^-(.*)/ )
4215
        {
4216
            $source = MakeSrcResolveExtended( $from_package, $_ );
4217
            $basename = StripDir( $source );
4218
            Debug( "Src: $_ -> $source=$basename (@args),(@depends)" );
4219
 
4220
            if ( $SRCS{ $basename } ) {
6387 dpurdie 4221
                Warning( "Duplicate src ignored '$source'") unless $ignoreDups;
227 dpurdie 4222
                next;
4223
            }
4224
            $SRCS{ $basename } = $source;
4225
 
4226
            HashJoin( \%SRC_ARGS, $;, $basename, @args )
4227
                if (@args);
4228
 
4229
            HashJoin( \%SRC_DEPEND, $;, $basename, @depends )
4230
                if ( @depends );
4231
 
4232
            $SRC_TYPE{ $basename } = $type
4233
                if ($type);
4234
 
4235
 
4236
            foreach (@lists) {
4237
                my $lname_short = "LIST_$_";
4238
                my $lname_full = "LIST_FULL_$_";
4239
 
4240
                no strict 'refs';
4241
 
4242
                push @$lname_short,$basename;
4243
                push @$lname_full ,$source;
4244
 
4245
                use strict 'refs';
4246
            }
4247
 
4248
            __AddSourceFile( 1, $source, "", $type );
4249
        }
4250
    }
4251
}
4252
 
6387 dpurdie 4253
#-------------------------------------------------------------------------------
4254
# Function        : AddToSrc 
4255
#
4256
# Description     : Internal function
4257
#                   Used by plugins and tools
4258
#                   
4259
#                   Will test if specified file is known to JATS, before
4260
#                   adding to the the list of known (Src) files 
4261
#
4262
# Inputs          : $platform
4263
#                   $file           - Only one file
4264
#                   @srcOpts        - Same as Src
4265
#
4266
# Returns         : True if any file can be found
4267
#                   Returns full path to the file    
4268
#
4269
sub AddToSrc
4270
{
4271
    my( $platforms, $file, @args ) = @_;
4272
    Debug2( "AddToSrc($platforms, $file, @args)" );
227 dpurdie 4273
 
6387 dpurdie 4274
    #
4275
    #   Process files
4276
    #
4277
    my $basename = StripDir( $file );
4278
    unless (exists $SRCS{$file} || exists  $SRCS{$basename} ) {
4279
        Src ('*', $file, @args);
4280
    }
4281
 
4282
    return $SRCS{$basename};
4283
}
4284
 
4285
 
227 dpurdie 4286
###############################################################################
4287
#  sub LibNameSplit
4288
#      Just a little help to deal with major/minor stuff for shared libs -
4289
#      given the name of the library as the argument, split out major and minor
4290
#      parts and return the basename, i.e name without major and minor and
4291
#      the pair of major and minor.
4292
###############################################################################
4293
 
4294
sub LibNameSplit
4295
{
4296
    my ( @bits ) = split('\.', $_[0]);
4297
    my ( $major, $minor );
4298
 
4299
    if ($#bits >= 1) {
4300
        $major = $bits[0]; $minor = $bits[1];
4301
    } elsif ($#bits >= 0) {
4302
        $major = $bits[0]; $minor = 0;
4303
    } else {
4304
        $major = 1; $minor = 0;
4305
    }
4306
    Debug( "LibName: $@_[0] ($major.$minor)" );
4307
    return ($major, $minor);
4308
}
4309
 
4310
#-------------------------------------------------------------------------------
4311
# Function        : Lib
4312
#
4313
# Description     : Generate a static library
4314
#
4315
# Inputs          : Platform specifier
4316
#                   Name of the library
4317
#                   Arguemnts ...
4318
#
4319
# Returns         :
4320
#
4321
sub Lib
4322
{
4323
    my( $platforms, $lib, @args ) = @_;
4324
    return if ( ! ActivePlatform($platforms) );
4325
 
4326
    Error ("Lib: Library name not defined") unless ( $lib );
4327
 
4328
    #
4329
    #   May be a shared library or a static library - for historic reasons
4330
    #   If the user has specified a --Shared then its a shared library
4331
    #
4332
    return SharedLib( @_ )
4333
        if ( grep (/^--Shared/, @args) );
4334
 
4335
    #
4336
    #   Does this toolset support libraries
4337
    #
4338
    Error ("Libraries are not supported") unless ( defined $::a );
4339
 
4340
    #.. Fully qualify library path for addition to library list.
4341
    $lib = "lib$lib"
4342
       if ( $ScmTargetHost eq "Unix" && $lib !~ m/^lib/);
4343
    Debug( "Lib: $lib" );
4344
 
4345
    #
289 dpurdie 4346
    #   Create a new object to describe the library
227 dpurdie 4347
    #   Ensure that only one such lib exists
289 dpurdie 4348
    #   Add the library to the list of static libraries
227 dpurdie 4349
    #
4350
    Error( "Library of the same name already defined: $lib" )
289 dpurdie 4351
        if ( $LIBS->Get($lib) );
4352
    $LIBS->NewAdd($lib);
227 dpurdie 4353
 
4354
    #
4355
    #   Process arguments
4356
    #
4357
    push( @LINTLIBS, $lib );
4358
    _LibArgs( $lib, @args );
4359
}
4360
 
4361
 
4362
#-------------------------------------------------------------------------------
4363
# Function        : SharedLib
4364
#
4365
# Description     : Generate a shared library
4366
#
4367
# Inputs          : Platform specifier
4368
#                   Name of the library
4369
#                   Arguemnts ...
4370
#
4371
# Returns         :
4372
#
4373
sub SharedLib
4374
{
4375
    my( $platforms, $lib, @args ) = @_;
4376
 
4377
    return if ( ! ActivePlatform($platforms) );
4378
 
4379
    Error ("SharedLib: Library name not defined") unless ( $lib );
4380
    Error ("Shared Libraries are not supported") unless ( defined $::so );
4381
 
4382
#.. Fully qualify library path for addition to library list.
4383
    $lib = "lib$lib"
4384
       if ( $ScmTargetHost eq "Unix" && $lib !~ m/^lib/);
4385
    Debug( "ShLib: $lib" );
4386
 
4387
    #
4388
    #   Ensure that only one such lib exists
4389
    #
289 dpurdie 4390
    Error( "Library of the same name already defined: $lib" )
4391
        if ( $SHLIBS->Get($lib) );
4392
    $SHLIBS->NewAdd($lib);
293 dpurdie 4393
 
227 dpurdie 4394
    #
4395
    #   If the user has not specified a --Shared parameter then provide one
4396
    #
4397
    push @args, "--Shared=Current"
4398
        unless ( grep (/^--Shared/, @args) );
4399
 
4400
    #
4401
    #   Process arguments
4402
    #
4403
    push( @LINTSHLIBS, $lib );
4404
    _SharedLibArgs( $lib, @args );
4405
}
4406
 
4407
 
4408
#-------------------------------------------------------------------------------
4409
# Function        : LibArgs
4410
#
4411
# Description     : Add arguments to an existing library directive
4412
#
4413
# Inputs          : Platform specifier
4414
#                   Name of the library
4415
#                   Arguemnts ...
4416
#
4417
# Returns         :
4418
#
4419
sub LibArgs
4420
{
4421
    my( $platforms, $lib, @args ) = @_;
4422
    return if ( ! ActivePlatform($platforms) );
4423
 
4424
#.. Fully qualify library path for addition to library list.
4425
    $lib = "lib$lib"
4426
       if ( $ScmTargetHost eq "Unix" && $lib !~ m/^lib/);
4427
    Debug( "LibArgs: $lib" );
4428
 
4429
    #
4430
    #   Process the arguments
4431
    #
4432
    _LibArgs( $lib, @args );
4433
}
4434
 
4435
 
4436
#-------------------------------------------------------------------------------
4437
# Function        : _LibArgs
4438
#
4439
# Description     : Process static library arguments
4440
#                   Internal use only
4441
#
4442
# Inputs          : Name of the library
4443
#                   Arguments to process
4444
#
4445
sub _LibArgs
4446
{
4447
    my( $lib, @elements) = @_;
4448
    my $obj;
4449
 
4450
    #
289 dpurdie 4451
    #   Ensure that only one such lib exists
4452
    #
4453
    my $libp = $LIBS->Get($lib);
4454
    Error("Library name not defined: $lib")
4455
        unless ( $libp );
4456
 
4457
    #
227 dpurdie 4458
    #   Process each element
4459
    #
4460
    foreach (@elements)
4461
    {
371 dpurdie 4462
        if ( /^\s+/ )
4463
        {
4464
            Error ("Argument cannot start with a space: '$_'");
4465
        }
227 dpurdie 4466
        if ( /^--Shared/ )
4467
        {
4468
            Error( "--Shared not valid for a static library" );
4469
        }
4470
 
4471
        if ( /^-l(.*)/ || /^--l(.*)/ || /^-L(.*)/ || /^--L(.*)/ )
4472
        {
4473
        #.. Target library specified - add to library list.
4474
        #
4475
            Warning( "$_ within non shared library specification" );
4476
            next;
4477
        }
4478
 
4479
        if ( /^--if(.*)/ )
4480
        {
4481
            Warning( "$_ within non shared library specification" );
4482
            next;
4483
        }
4484
 
4485
        if ( /^--(.*)/ )
4486
        {
4487
            Debug( "LibArgs: arg $_" );
4488
 
4489
            #.. Argument specified - add to argument list
4490
            #
289 dpurdie 4491
            $libp->addItem('ARGS', $_);
4492
 
227 dpurdie 4493
            next;
4494
        }
4495
 
369 dpurdie 4496
        if ( %::ScmToolsetProgSource )
227 dpurdie 4497
        {
4498
            #
4499
            #   Toolset provides support for some file types
4500
            #   to be passed directly to the librarian builder
4501
            #
4502
            my $ext  = StripFile($_);
4503
            if ( exists ($::ScmToolsetProgSource{$ext}) )
4504
            {
4505
                my $full_path = MakeSrcResolve ( $_ );
4506
                my $flag = $::ScmToolsetProgSource{$ext};
4507
                Debug( "LibArgs: src $_" );
289 dpurdie 4508
                $libp->addItem('ARGS', "$flag$full_path" );
227 dpurdie 4509
                next;
4510
            }
4511
        }
4512
 
4513
        if ( $::o )
4514
        {
4515
        #.. Object specified - add to object list.
4516
        #
4517
            $obj = _LibObject( "", $_ );
4518
 
4519
        #.. Add to object list.
4520
        #   Note:   Object path must be explicit as several
4521
        #           toolsets add additional objects.
4522
        #
289 dpurdie 4523
            $libp->addItem('OBJS', "\$(OBJDIR)/$obj" );
227 dpurdie 4524
            next;
4525
        }
4526
 
4527
        #
4528
        #   Don't know how to handle this type of argument
4529
        #
4530
        Error ("LibArgs: Don't know how to handle: $_" );
4531
    }
4532
}
4533
 
4534
 
4535
#-------------------------------------------------------------------------------
4536
# Function        : SharedLibArgs
4537
#
4538
# Description     : Add arguments to an existing shared library directive
4539
#
4540
# Inputs          : Platform specifier
4541
#                   Name of the library
4542
#                   Arguemnts ...
4543
#
4544
# Returns         :
4545
#
4546
sub SharedLibArgs
4547
{
4548
    my( $platforms, $lib, @args ) = @_;
4549
    return if ( ! ActivePlatform($platforms) );
4550
 
4551
#.. Fully qualify library path for addition to library list.
4552
    $lib = "lib$lib"
4553
       if ( $ScmTargetHost eq "Unix" && $lib !~ m/^lib/);
4554
    Debug( "ShLibArgs: $lib" );
4555
 
4556
    _SharedLibArgs( $lib, @args );
4557
}
4558
 
4559
 
4560
#-------------------------------------------------------------------------------
4561
# Function        : _SharedLibArgs
4562
#
4563
# Description     : Process shared library arguments
4564
#                   Internal use only
4565
#
4566
# Inputs          : Name of the library
4567
#                   Arguments to process
4568
#
4569
sub _SharedLibArgs
4570
{
4571
    my ( $lib, @elements) = @_;
4572
 
289 dpurdie 4573
    my $libp = $SHLIBS->Get($lib);
4574
    Error("Library name not defined: $lib")
4575
        unless ( $libp );
4576
 
227 dpurdie 4577
    #
289 dpurdie 4578
    #.. Collect --Shared arguments
339 dpurdie 4579
    #   Need to process this one first so that we have a version number
227 dpurdie 4580
    #
4581
    foreach (@elements)
4582
    {
371 dpurdie 4583
        if ( /^\s+/ )
4584
        {
4585
            Error ("Argument cannot start with a space: '$_'");
4586
        }
289 dpurdie 4587
        next unless ( /^--Shared/ );
4588
 
4589
        my $shared;
227 dpurdie 4590
        if ( /^--Shared$/ )
4591
        {
4592
        #.. Shared library, default library version 1.0
4593
        #
4594
            $shared = "1.0";
4595
        }
4596
        elsif ( /^--Shared=Current$/ )
4597
        {
4598
        #.. Shared library, using 'current' build version
4599
        #
4600
            $shared = $::ScmBuildVersion;
289 dpurdie 4601
            $shared = "1.0" if ($shared eq "");
227 dpurdie 4602
        }
4603
        elsif ( /^--Shared=(.*)/ )
4604
        {
4605
        #.. Shared library, specific version
4606
        #
4607
            my($M, $m) = LibNameSplit($1);
289 dpurdie 4608
            $shared = "$M.$m";
4609
        }
227 dpurdie 4610
 
289 dpurdie 4611
        #
4612
        #   Update the shared Names
4613
        #
4614
        if ( defined $shared )
4615
        {
227 dpurdie 4616
            Warning( "multiple --Shared arguments" )
339 dpurdie 4617
                if (exists $libp->{ VERSION });
227 dpurdie 4618
            Debug( "ShLibArgs: shared $_ ($shared)" );
289 dpurdie 4619
            $libp->{ VERSION } = $shared;
227 dpurdie 4620
        }
289 dpurdie 4621
        else
4622
        {
4623
            Error ("ShLibArgs: --Shared argument not understood");
4624
        }
227 dpurdie 4625
    }
4626
 
4627
 
4628
#.. Parse all of the object and argument entries.
4629
#
4630
    foreach (@elements)
4631
    {
289 dpurdie 4632
        next if ( /^--Shared(.*)/ );
227 dpurdie 4633
 
4634
        if ( /^[-]{1,2}([lL])(.*)/ )
4635
        {
4636
        #.. Target library specified - add to library list.
339 dpurdie 4637
        #   Support --L and -L and --l and -l
227 dpurdie 4638
        #
4639
            Debug( "ShLibArgs: lib  -$1$2" );
289 dpurdie 4640
            $libp->addItem('LIBS', "-$1$2" );
227 dpurdie 4641
            next;
4642
        }
4643
 
4644
        if ( /^--if(.*)/ )
4645
        {
4646
        #.. Library conditional - add to library list.
4647
        #
4648
            Debug( "ShLibArgs: cond $_" );
289 dpurdie 4649
            $libp->addItem('LIBS', $_);
227 dpurdie 4650
            next;
4651
        }
4652
 
339 dpurdie 4653
        if ( /^--SoName=(.*)/i )
4654
        {
4655
        #.. Specify the SoName of the library
4656
        #   Not supported by all toolsets
4657
        #
4658
            my $soMode = $1;
4659
            if ( !$ScmToolsetSoName )
4660
            {
4661
                Warning ("Toolset does not support --SoName. Option ignored");
4662
                next;
4663
            }
4664
 
4665
            Error ("SharedLib: $lib. Multiple --SoName arguments not allowed")
4666
                if ( $libp->{ SONAME } );
4667
 
4668
            my ($major, $minor, $patch, $build, $raw_patch) = SplitVersion($::ScmBuildVersionFull);
4669
            my $soname = '.';
4670
            if ( $soMode =~ m/Major/i ) {
4671
                $soname .= $major;
4672
            } elsif ( $soMode =~ m/^Minor/i ) {
4673
                $soname .= "$major.$minor";
4674
            } elsif ( $soMode =~ m/^Patch/i ) {
4675
                $soname .= "$major.$minor.$patch";
4676
            } elsif ( $soMode =~ m/^Build/i ) {
4677
                $soname .= "$major.$minor.$patch.$build";
4678
            } elsif ( $soMode =~ m/^Full/i ) {
4679
                $soname .= $libp->{ VERSION };
4680
            } elsif ( $soMode =~ m/^None/i ) {
4681
                $soname = '';
4682
            } elsif ( $soMode =~ m/^[0-9.]+$/ ) {
4683
                $soname .= $soMode;
4684
            } else {
4685
                Error ("Unknown --SoName mode: $soMode");
4686
            }
4687
            $libp->addItem('ARGS', '--SoNameSuffix=' . $soname);
4688
            $libp->{ SONAME } = 1;
4689
            next;
4690
        }
4691
 
227 dpurdie 4692
        if ( /^-(.*)/ )
4693
        {                           
4694
        #.. Argument specified - add to argument list
4695
        #
4696
            Debug( "ShLibArgs: arg  $_" );
289 dpurdie 4697
            $libp->addItem('ARGS', $_);
227 dpurdie 4698
            next;
4699
        }
4700
 
369 dpurdie 4701
        if ( %::ScmToolsetProgSource )
227 dpurdie 4702
        {
4703
            #
4704
            #   Toolset provides support for some file types
4705
            #   to be passed directly to the program builder
4706
            #
4707
            my $ext  = StripFile($_);
4708
            if ( exists ($::ScmToolsetProgSource{$ext}) )
4709
            {
4710
                my $full_path = MakeSrcResolve ( $_ );
4711
                my $flag = $::ScmToolsetProgSource{$ext};
4712
                Debug( "ShLibArgs: src $_" );
289 dpurdie 4713
                $libp->addItem('ARGS', "$flag$full_path");
227 dpurdie 4714
                next;
4715
            }
4716
        }
4717
 
4718
        if ( $::o )
4719
        {
4720
        #.. Object specified - add to object list.
4721
        #
4722
            my ($obj) = _LibObject( $lib, $_ );
4723
 
4724
        #.. Add to object list.
4725
        #   Note:   Object path must be explicit as several
4726
        #           toolsets add additional objects.
4727
        #
4728
            $SHOBJ_LIB{ $obj } = $lib;
289 dpurdie 4729
            $libp->addItem('OBJS', "\$(OBJDIR)/$obj");
227 dpurdie 4730
            next;
4731
        }
4732
 
4733
        #
4734
        #   Don't know how to handle this type of argument
4735
        #
4736
        Error ("SharedLib: Don't know how to handle: $_" );
4737
    }
4738
}
4739
 
4740
 
4741
#-------------------------------------------------------------------------------
4742
# Function        : _LibObject
4743
#
4744
# Description     : Process library object file
4745
#                   Common processing routine for static and shared library
4746
#                   Internal use only
4747
#
4748
# Inputs          : shared  - Name of the shared library is shared, if defined
4749
#                   fname   - Name of file
4750
#
4751
# Returns         : Name of the object file
4752
#
4753
sub _LibObject
4754
{
4755
    my ($shared, $fname) = @_;
4756
    my ($file, $ext, $obj, $srcfile, $delete_obj);
4757
 
4758
    #.. Object specified - add to object list.
4759
    #
4424 dpurdie 4760
    #   Want to handle several cases
4761
    #       Normal - User has provided the name of an object file (without the obj suffix)
4762
    #       Other  - User has provided the name of a source file
4763
    #                Need to perform implicit source file processing
4764
    #
4765
    #   The hard part is detecting the difference
4766
    #   Just can't use the existence of a '.' 
4767
    #
4768
    if ($OBJSOURCE{$fname}) {
4769
        $file = $fname;                             # Already know about this file
4770
        $ext = '';                                  # Don't need to split it
4771
    } else {
4772
        $file = StripDirExt($fname);                # file name, without extension or Dir
4773
        $ext  = StripFile($fname);                  # extension
4774
    }
227 dpurdie 4775
 
4776
    if ($shared) {
4777
        $obj = "$shared/$file";                 # library specific subdir
4778
    } else {
4779
        $obj = "$file";
4780
    }
4781
 
4782
    Debug( "LibObjs: obj [$shared]$fname ($file$ext)" );
4783
 
4784
    #.. Unqualified object name
4785
    #
4424 dpurdie 4786
    if ( $ext eq '' ) {
227 dpurdie 4787
        #
4788
        #   Object file not covered by a "Src" statement
4789
        #   Assume that it will be created
4790
        #
4424 dpurdie 4791
        unless ( $srcfile = $OBJSOURCE{$file} )
227 dpurdie 4792
        {
4793
            #
4424 dpurdie 4794
            #   If the object is "generated" then it will be in the
227 dpurdie 4795
            #   SRCS list
4796
            #
4797
            unless ( $srcfile = $SRCS{"$file.$::o"} )
4798
            {
4799
                Warning( "No source for object '$fname' ($file)" );
4800
            }
4801
        }
4802
        $delete_obj = 1;
4803
    }
4804
 
4805
    #.. Qualified object name (ie has extension)
4806
    #       Strip extension and resolve ...
4807
    #       Assume that the named file can be built into an object file
4808
    #
4809
    else
4810
    {
4811
        #.. Resolve
4812
        #
4813
        if ( !($srcfile = $OBJSOURCE{ "$file" }) )
4814
        {
4815
            $srcfile = MakeSrcResolve( $fname );
4816
            $SRCS{ $fname } = $srcfile;
4817
            __AddSourceFile( 0, $fname, $obj );
4818
            $delete_obj = 1;
4819
        }
4820
    }
4821
 
4822
    #.. Delete generated object file
4823
    #   Ensure that the object file is added to the delete list
4824
    #   Add it to the ToolsetObj deletion list as the main OBJ deleltion
4825
    #   list will aready have been processed
4826
    #
4827
    ToolsetObj( "\$(OBJDIR)/$obj" )
4828
        if ( $delete_obj );
4829
 
4830
 
4831
    #.. Shared library objects,
4832
    #       Must explicitly relate source and object, as shared libraries
4833
    #       objects are built within a library specific subdirs.
4834
    #
4835
    $OBJSOURCE{ $obj } = $srcfile
371 dpurdie 4836
        if ( $shared && defined $srcfile );
227 dpurdie 4837
 
4838
    return $obj;
4839
}
4840
 
4841
 
4842
# MergeLibrary
4843
#   Merge a list of libraries into one library
4844
#
4845
sub MergeLibrary
4846
{
4847
    my( $platforms, $lib, @elements ) = @_;
4848
 
4849
    return if ( ! ActivePlatform($platforms) );
4850
 
4851
 
4852
#.. Fully qualify library path for addition to library list.
4853
    $lib = "lib$lib"
4854
       if ( $ScmTargetHost eq "Unix" && $lib !~ m/^lib/);
4855
    Debug( "MergeLibrary: $lib" );
4856
 
289 dpurdie 4857
    #
4858
    #   Create a new object to describe the library
4859
    #   Ensure that only one such lib exists
4860
    #   Add the library to the list of static libraries
4861
    #
4862
    Error( "Merged Library of the same name already defined: $lib" )
4863
        if ( $MLIBS->Get($lib) );
4864
    my $libp = $MLIBS->NewAdd($lib);
4865
 
227 dpurdie 4866
#.. Parse all of the object and argument entries.
4867
#
4868
    foreach (@elements)
4869
    {
4870
        if ( /^--(.*)/ )
4871
        {
289 dpurdie 4872
            $libp->addItem('ARGS', $_);
227 dpurdie 4873
        }
4874
        else
4875
        {
4876
            my ($llib);
4877
 
4878
            #
4879
            #   Collect the source libraries
4880
            #   These must have been installed and will be in a known area
4881
            #   Create full names for the libaries
4882
            #
4883
            if ( $ScmTargetHost eq "Unix" ) {
4884
                $llib = "lib$_";                # Prefix "lib" ....
4885
                $lib =~ s/^liblib/lib/;         # @LIBS already has lib added
4886
            } else {
4887
                $llib = $_;
4888
            }
4889
 
4890
            Debug( "MergeLibrary: merge $llib" );
289 dpurdie 4891
            $libp->addItem('LIBS', $llib);
227 dpurdie 4892
        }
4893
    }
4894
}
4895
 
4896
#-------------------------------------------------------------------------------
4897
# Function        : Script
4898
#
4899
# Description     : Locate a script for test purposes
4900
#
4901
# Inputs          : $platforms      - Platform selector
4902
#                   $script         - A single script name
4903
#                   $execute        - Flag to indicate that the script is to
4904
#                                     marked as executable when used in a TestProg
4905
#                                     This flag is NOT used as the script will
4906
#                                     be forced executable
4907
#
4908
# Returns         : Nothing
4909
#
4910
sub Script
4911
{
4912
    my( $platforms, $script, $execute ) = @_;
4913
 
4914
    Debug2( "Script(@_)" );
4915
 
4916
    return if ( ! ActivePlatform($platforms) );
4917
 
4918
    #
4919
    #   Locate the script as a source file
4920
    #
4921
    my $file = MakeSrcResolve ( $script );
4922
    $script = StripDir( $file );
4923
    $SCRIPTS{ $script } = $file;
4924
}
4925
 
4926
#-------------------------------------------------------------------------------
4927
# Function        : RunTest
4928
#
4929
# Description     : Define a test to be run with the 'run_tests' and 'run_unit_tests'
4930
#
4931
# Inputs          : $platform       - Enabled for these platforms
4932
#                   $prog           - Program to run
4933
#                                     This SHOULD return a non-zero exit status
4934
#                                     on error. The program may be a 'TestProg'
4935
#                                     or a 'Script'.
4936
#                   @elements       - Options and test arguments
4937
#                                     Options are:
4778 dpurdie 4938
#                                       --Auto              - Non interactive unit test
4939
#                                       --Unit              - Same and --Auto
4940
#                                       --UtfFormat=nnn     - Specifies Automated Unit Test, 
4941
#                                                             results post processed with formatter
4781 dpurdie 4942
#                                       --UtfArg=nnn        - Argument passed into the UTF formatter    
4943
#                                       --Name=nnn          - Test Name.
5695 dpurdie 4944
#                                       --CopyIn=file       - A file to be copied into the test directory.
4945
#                                       --MaxTime=fff.ff[smhd] - Max Test Time. Default 30m
227 dpurdie 4946
#
4947
#                                     Non Options are passed to the test program.
4948
#                                     --PackageBase(xxx)    - Base of package
4949
#                                     --PackageInfo(xxx)    - Package information
4950
#                                     --File(xxx)           - Resolved name of file
4951
#                                     --Var(xxx)            - Expanded variable
4952
#                                     --Local(xxx)          - File within the local directory
4953
#
4778 dpurdie 4954
#                                     Toolset Framework support (ie NUNIT in csharp.pl)
4955
#                                       --FrameWork=name    - Name of framework
4956
#                                       --xxxx              - Args passed to framework constructor
4957
#
227 dpurdie 4958
# Returns         : Nothing
4959
#
4781 dpurdie 4960
my %RunTestNames;                       # Unique Name Tests
227 dpurdie 4961
sub RunTest
4962
{
4963
    my( $platforms, $prog, @elements ) = @_;
4964
    my $command = './';                 # program prefix / command
4965
    my $winprog = 1;                    # 1: Convert / -> \ (WIN32 only)
4966
    my $framework;
4967
    my @framework_opts;
4968
    my @copy = ();
4969
    my $auto;
4778 dpurdie 4970
    my $utfFormat;
4781 dpurdie 4971
    my @utfArgs;
4972
    my $utfName;
5695 dpurdie 4973
    my $maxTime;
227 dpurdie 4974
 
4975
    return if ( ! ActivePlatform($platforms) );
4976
 
4977
    #
4978
    #   Scan @elements and extract useful information
4979
    #   Need to process twice as some args will modify the
4980
    #   processing done later
4981
    #
4982
    my @args;
4983
    foreach ( @elements )
4984
    {
4985
        if ( m/^--FrameWork=(.+)/ ) {
4986
            $framework = $1;
4987
 
4988
        } elsif ( m/^--Auto/ || m/^--Unit/) {
4989
            $auto = 1;
4990
 
4781 dpurdie 4991
        } elsif ( m/^--Name=(.*)/) {
4992
            $utfName = $1;
4993
 
4994
            Error("Duplicate Test Name: $utfName")
4995
                if (exists $RunTestNames{$utfName} );
4996
            $RunTestNames{$utfName} = 1;
4997
 
4778 dpurdie 4998
        } elsif ( m/^--UtfFormat=(.*)/) {
4999
            $utfFormat = $1;
5000
 
4781 dpurdie 5001
        } elsif ( m/^--UtfArg=(.*)/) {
5002
            push @utfArgs, $1;
5003
 
5695 dpurdie 5004
        } elsif ( m/^--MaxTime=(.*)/) {
5005
            $maxTime = $1;
5006
            unless ($maxTime =~ m~^[0-9]*\.?[0-9]+[smhd]?$~) {
5007
                Error("MaxTime invalid: $maxTime");
5008
            }
5009
 
227 dpurdie 5010
        } elsif ( m/^--CopyIn=(.*)/ ) {
5011
            push @copy, MakeSrcResolve ( $1 );
5012
 
5013
        } elsif ( $framework && m/^--\w+=(.+)/ ) {
5014
            push @framework_opts, $_;
5015
 
5016
        } else {
5017
            push @args, $_;
5018
        }
5019
    }
5020
    @elements = @args;
5021
    @args = ();
5022
 
5023
    #
5024
    #   Determine the source of the test prog
4612 dpurdie 5025
    #   If using a plug-in framework, then we don't know
227 dpurdie 5026
    #   If not, then may be a script or a TESTPROGS
5027
    #
5028
 
5029
    unless ( $framework )
5030
    {
289 dpurdie 5031
        if ( $TESTPROGS->Get($prog) || $PROGS->Get($prog)  ) {
227 dpurdie 5032
            #
5033
            #   Append a suitable EXE suffix
5034
            #
289 dpurdie 5035
            $prog = GenProgName( $prog );
227 dpurdie 5036
 
5037
        } elsif ( exists $SCRIPTS{$prog} ) {
5038
            #
5039
            #   Script names are raw
5040
            #   Perl script are invoked directly
5041
            #
5042
            $command = "\$(GBE_PERL) -w "
5043
                if ( $prog =~ /\.pl$/ );
5044
 
5045
            #
5046
            #   Pass / to shells
5047
            #
5048
            $winprog = 0
5049
                unless ( $prog =~ m~\.bat$~ )
5050
 
5051
        } else {
5052
            Warning("RunTest program not known: $prog",
261 dpurdie 5053
                  "It is not a TestProg, Prog or a Script",
5054
                  "The test may fail" );
227 dpurdie 5055
        }
5056
    }
5057
 
5058
    #
5059
    #   Extract and process options
5060
    #
5061
    my @uargs = ();
5062
    my @preq_files;
5063
 
5064
    foreach my $arg (@elements) {
5065
        #
5066
        #   Process the tool arguments and extract file information
5067
        #   Extract all fields of the form:
5068
        #           --xxxxx(yyyyyy[,zzzzz])
5069
        #           --xxxxx{yyyyyyy}
5070
        #           --xxxxx[yyyyyyy] to allow embedded brackets
5071
        #
5072
        while ( $arg =~ m/--(\w+)               # --CommandWord         $1
5073
                                (               # Just for grouping
5074
                                \((.*?)\)   |   # Stuff like (yyyyy)    $3
5075
                                {(.*?)}     |   # or    like {yyyyy}    $4
5076
                                \[(.*?)\]       # or    like [yyyyy]    $5
5077
                                )/x )           # Allow comments and whitespace
5078
        {
5079
            my $cmd = $1;                       # The command
5080
            my $ufn = $3 || $4 || $5;           # User filename + options
5081
            my $mb = $-[0];                     # Match begin offset
5082
            my $me = $+[0];                     # Match end
5083
            my $flags = '';                     # Optional flags ( --dir or --file )
5084
            my $raw_arg = $ufn;                 # Raw arguments
6387 dpurdie 5085
            my $all = substr( $arg, $mb, $me - $mb ); # All of match. Avoid use of $&
329 dpurdie 5086
            my $is_abs;
5087
            my $is_path = 1;
227 dpurdie 5088
 
5089
            Error ("RunTest. Empty element not allowed: $all")
5090
                unless ( defined($ufn) );
5091
 
5092
            $ufn =~ s/\s+$//;
5093
            $ufn =~ s~//~/~g;                   # Remove multiple /
5094
            if ( $ufn =~ m/(.*?),(.*)/ )        # Extract out any flags
5095
            {
5096
                $ufn = $1;
5097
                $flags = $2;
5098
            }
5099
 
5100
            my $fn = $ufn ;                     # Replacement filename
343 dpurdie 5101
            my $fnp = '';                       # Prefix to $fn
227 dpurdie 5102
            Error ("RunTest. Empty element not allowed: $all" )
5103
                if ( length ($ufn) <= 0 );
5104
 
5105
            #
5106
            #   Process found user command
5107
            #
5108
            if ( $cmd =~ /^File/ )
5109
            {
5110
                #
5111
                #   Prerequisite filename
5112
                #       Resolve the full name of the file. It may be known
5113
                #       as a source file (possibly generated) or it may be
5114
                #       located in a known source directory
5115
                #
5116
                $fn = MakeSrcResolve ( $ufn );
5117
                UniquePush (\@preq_files, $fn);
5118
 
5119
                Debug( "RunTest: Prereq: $fn" );
5120
 
5121
            }
5122
            elsif ( $cmd =~ /^PackageBase/ )
5123
            {
5124
                $fn = GetPackageBase( "RunTest", $raw_arg );
5125
                UniquePush (\@preq_files, $fn);
5126
            }
5127
            elsif ( $cmd =~ /^PackageInfo/ )
5128
            {
5129
                $fn = GetPackageInfo( "RunTest", $raw_arg );
5130
            }
5131
            elsif ( $cmd =~ /^Var/ )
5132
            {
343 dpurdie 5133
                ($fnp, $fn, $is_path, $is_abs) = ExpandGenVar( "RunTest", $raw_arg );
227 dpurdie 5134
                $flags = '';
5135
            }
5136
            elsif ( $cmd =~ /^Local/ )
5137
            {
5138
                $fn = '$(LOCALDIR)/' . $ufn ;
5139
                UniquePush (\@preq_files, $fn);
5140
            }
6387 dpurdie 5141
            elsif ( $cmd =~ /^Dir/ )
5142
            {
5143
                # Item is a directory.
5144
                # Must be massaged so that it will be correct within the context
5145
                # Modified path is simply added to the command line
5146
                # 
5147
                $fn = $ufn;
5148
                unless (-d $fn) {
5149
                    if (-f $fn) {
5150
                        Warning ("Not a directory. Its a file: $arg") ;
5151
                    } else {
5152
                        Warning ("Directory not found: $arg");
5153
                    }
5154
                }
5155
            }
227 dpurdie 5156
            else
5157
            {
5158
                Warning ("RunTest: Unknown replacement command: $cmd");
5159
                $fn = $ufn;
5160
            }
5161
 
5162
            #
5163
            #   Process path modification flags
5164
            #       --dir           - only the directory part ( or a "." )
5165
            #       --file          - only the file part
5166
            #       --abspath       - Absolute path
5167
            #       --absdrive      - Absolute path with drive letter(WIN)
5168
            #
5169
            $fn = ProcessPathName( $fn, $flags );
5170
 
5171
            #
5172
            #   The program is going to be executed within a subdirectory
5173
            #   so add one more level of indirection to the path, but only if
5174
            #   the path is relative
5175
            #
329 dpurdie 5176
            if ( $is_path && ! $is_abs )
227 dpurdie 5177
            {
329 dpurdie 5178
                unless ( $fn =~ m~^/|^\w:/~  )
5179
                {
5180
                    $fn = '../' . $fn
5181
                        unless( $fn =~ s~=~=../~ );
5182
                    $fn =~ s~/.$~~;
5183
                }
227 dpurdie 5184
            }
5185
 
5186
            #
5187
            #   Minor kludge under windows. Ensure directores have a "\" sep
5188
            #   Unless the user has specified a straight shell command
5189
            #
5986 dpurdie 5190
            $fn = "\$(subst /,\$(dirsep),$fn)"
227 dpurdie 5191
                if ( $::ScmHost eq "WIN" && $winprog );
5192
 
5193
            #
343 dpurdie 5194
            #   Prepend any $fn Prefix
5195
            #   This will be a tag and is not subject to path processing
5196
            #
5197
            $fn = $fnp . $fn;
5198
 
5199
            #
227 dpurdie 5200
            #   Replace the found string with the real name of the file
5201
            #   Note: 4 argument version of substr is not always available
5202
            #         so we must do it the hard way
5203
            #               substr( $arg, $mb, $me - $mb, $fn);
5204
            #
5205
            $arg = substr( $arg, 0, $mb ) . $fn . substr( $arg, $me );
5206
 
5207
            Debug2( "RunTest: subs: $all -> $fn" );
5208
        }
5209
        push(@uargs, "'$arg'");
5210
    }
5211
 
5212
    #
5213
    #   Create the test entry
5214
    #   This is a structure that will be placed in an array
5215
    #   The array preserves order and uniqness
5216
    #
5217
    my %test_entry;
5218
    $test_entry{'framework'}= $framework if ( $framework );
5219
    $test_entry{'framework_opts'}= \@framework_opts if ( $framework );
5220
    $test_entry{'command'}  = $command . $prog unless ( $framework);
5221
 
5222
    $test_entry{'prog'}     = $prog;
5223
    $test_entry{'copyprog'} = 1;
5224
    $test_entry{'args'}     = \@uargs;
5225
    $test_entry{'auto'}     = $auto if ( $auto );
4778 dpurdie 5226
    $test_entry{'utfformat'}= $utfFormat if ( $utfFormat );
4781 dpurdie 5227
    $test_entry{'utfargs'}  = \@utfArgs;
5228
    $test_entry{'utfname'}  = $utfName;
5695 dpurdie 5229
    $test_entry{'maxtime'}  = $maxTime if ($maxTime);
227 dpurdie 5230
    $test_entry{'copyin'}   = \@copy;
5231
    $test_entry{'copyonce'} = ();
5232
    $test_entry{'preq'}     = \@preq_files;
5233
    $test_entry{'testdir'}  = 'BINDIR';
5234
 
5235
    push ( @TESTS_TO_RUN, \%test_entry );
5236
 
5237
    #
5238
    #   Flag Auto Run processing required
5239
    #
4501 dpurdie 5240
    $TESTS_TO_RUN = 1;
227 dpurdie 5241
    $TESTS_TO_AUTORUN = 1 if ( $auto );
5242
}
5243
 
5244
 
5245
sub TestProg
5246
{
5247
    my( $platforms, $prog, @elements ) = @_;
5248
 
5249
    Debug2( "TestProg($platforms, $prog, @elements)" );
5250
 
5251
    return if ( ! ActivePlatform($platforms) );
5252
 
5253
    Error ("TestProg: Program name not defined") unless ( $prog );
5254
    Error ("Programs are not supported") unless ( defined $::exe );
5255
 
289 dpurdie 5256
    #
5257
    #   Create a new Prog object, or retrieve any existing one
5258
    #
5259
    my $pProg = $TESTPROGS->Get($prog);
5260
    $pProg = $TESTPROGS->NewAdd($prog)
5261
        unless ( $pProg );
227 dpurdie 5262
 
5263
#.. Parse all of the object, library and argument entries
5264
    Debug( "TestProg: $prog" );
5265
    foreach (@elements)
5266
    {
5267
        if ( /^[-]{1,2}([lL])(.*)/ )
5268
        {
5269
        #.. Target Library specified - add to library list.
5270
        #  
5271
            Debug( "TestProg: lib  -$1$2" );
289 dpurdie 5272
            $pProg->addItem('LIBS', "-$1$2");
227 dpurdie 5273
            next;
5274
        }
5275
 
5276
        if ( /^--if(.*)/ )
5277
        {
5278
        #.. Library conditional - add to library list.
5279
        #
5280
            Debug( "TestProg: cond $_" );
289 dpurdie 5281
            $pProg->addItem('LIBS', $_);
227 dpurdie 5282
            next;
5283
        }
5284
 
5285
        if ( /^-(.*)/ )
5286
        {
5287
        #.. Argument specified - add to argument list
5288
        #
5289
            Debug( "TestProg: arg $_" );
289 dpurdie 5290
            $pProg->addItem('ARGS', $_);
227 dpurdie 5291
            next;
5292
        }
5293
 
369 dpurdie 5294
        if ( %::ScmToolsetProgSource )
227 dpurdie 5295
        {
5296
            #
5297
            #   Toolset provides support for some file types
5298
            #   to be passed directly to the program builder
5299
            #
5300
            my $ext  = StripFile($_);
5301
            if ( exists ($::ScmToolsetProgSource{$ext}) )
5302
            {
5303
                my $full_path = MakeSrcResolve ( $_ );
5304
                my $flag = $::ScmToolsetProgSource{$ext};
5305
                Debug( "TestProg: src $_" );
289 dpurdie 5306
                $pProg->addItem('ARGS', "$flag$full_path");
227 dpurdie 5307
                next;
5308
            }
5309
        }
5310
 
5311
        if ( $::o )
5312
        {
5313
        #.. Object specified - add to object list.
5314
        #
5315
            my $obj = _LibObject( "", $_ );
5316
 
5317
        #.. Add to program object list.
289 dpurdie 5318
            $pProg->addItem('OBJS', "\$(OBJDIR)/$obj");
227 dpurdie 5319
            next;
5320
        }
5321
 
5322
        #
5323
        #   Don't know how to handle this type of argument
5324
        #
5325
        Error ("TestProg: Don't know how to handle: $_" );
5326
    }
5327
}
5328
 
5329
 
5330
sub Prog
5331
{
5332
    my( $platforms, $prog, @elements ) = @_;
5333
 
5334
    Debug2( "Prog($platforms, $prog, @elements)" );
5335
 
5336
    return if ( ! ActivePlatform($platforms) );
5337
 
5338
    Error ("Prog: Program name not defined") unless ( $prog );
5339
    Error ("Programs are not supported") unless ( defined $::exe );
5340
 
289 dpurdie 5341
    #
5342
    #   Create a new Prog object, or retrieve any existing one
5343
    #
5344
    my $pProg = $PROGS->Get($prog);
5345
    $pProg = $PROGS->NewAdd($prog)
5346
        unless ( $pProg );
227 dpurdie 5347
 
5348
#.. Parse all of the object, library and argument entries
5349
    Debug( "Prog: $prog" );
5350
    foreach (@elements)
5351
    {
5352
        if ( /^[-]{1,2}([lL])(.*)/ )
5353
        {
5354
        #.. Target Library specified - add to library list.
5355
        #  
5356
            Debug( "Prog: lib  -$1$2" );
289 dpurdie 5357
            $pProg->addItem('LIBS', "-$1$2");
227 dpurdie 5358
            next;
5359
        }
5360
 
5361
        if ( /^--if(.*)/ )
5362
        {
5363
        #.. Library conditional - add to library list.
5364
        #
5365
            Debug( "Prog: cond $_" );
289 dpurdie 5366
            $pProg->addItem('LIBS', $_);
227 dpurdie 5367
            next;
5368
        }
5369
 
5370
        if ( /^-(.*)/ )
5371
        {
5372
        #.. Argument specified - add to argument list
5373
        #
5374
            Debug( "Prog: arg $_" );
289 dpurdie 5375
            $pProg->addItem('ARGS', $_);
227 dpurdie 5376
            next;
5377
        }
5378
 
369 dpurdie 5379
        if ( %::ScmToolsetProgSource )
227 dpurdie 5380
        {
5381
            #
5382
            #   Toolset provides support for some file types
5383
            #   to be passed directly to the program builder
5384
            #
5385
            my $ext  = StripFile($_);
5386
            if ( exists ($::ScmToolsetProgSource{$ext}) )
5387
            {
5388
                my $full_path = MakeSrcResolve ( $_ );
5389
                my $flag = $::ScmToolsetProgSource{$ext};
5390
                Debug( "Prog: src $_" );
289 dpurdie 5391
                $pProg->addItem('ARGS', "$flag$full_path");
227 dpurdie 5392
                next;
5393
            }
5394
        }
5395
 
5396
        if ( $::o )
5397
        {
5398
        #.. Object specified - add to object list.
5399
        #
5400
            my $obj = _LibObject( "", $_ );
5401
 
5402
        #.. Add to program object list.
289 dpurdie 5403
            $pProg->addItem('OBJS', "\$(OBJDIR)/$obj");
227 dpurdie 5404
            next;
5405
        }
5406
 
5407
        #
5408
        #   Don't know how to handle this type of argument
5409
        #
5410
        Error ("Prog: Don't know how to handle: $_" );
5411
    }
5412
}
5413
 
5414
#-------------------------------------------------------------------------------
5415
# Function        : ProgAddExtra
5416
#
5417
# Description     : This (internal) function allows a toolset to list additional
5418
#                   binaries as a part of a program. This will ensure that the
5419
#                   binaries are generated in the 'make_prog' phase with the main
5420
#                   program.
5421
#
5422
#                   The files are not listed for packaging, by this function
5423
#
5424
#                   The function does not ensure that the files are not already
5425
#                   listed as a @PROG ( as @PROGS is not fully resolved at this point )
5426
#
5427
# Inputs          :     $name               - Tag name of program being built
5428
#                                             Not used (yet)
5429
#                       $prog               - Fully resolved path to a file
5430
#
5431
# Returns         : Nothing
5432
#
5433
sub ProgAddExtra
5434
{
5435
    my ($name, $prog) = @_;
5436
    Debug2( "ProgAddExtra($name: $prog)" );
5437
 
5438
    UniquePush(\@PROGS_EXTRA, $prog);
5439
}
5440
 
4261 dpurdie 5441
our %PROJECTS;                          # Project information
5442
my  @PROJECTS_ORDER;
227 dpurdie 5443
#-------------------------------------------------------------------------------
4261 dpurdie 5444
# Function        : MakeProjectName 
5445
#
5446
# Description     : Create a uniq project name
5447
#
5448
# Inputs          : srcPath 
5449
#
5450
# Returns         : A unique project name 
5451
#
5452
sub MakeProjectName
5453
{
5454
    my ($srcPath) = @_;
5455
    my $suffix = "";
5456
    my $index = 1;
5457
 
5458
    my $proj = StripDir( $srcPath );
5459
    while (exists $PROJECTS{$proj . $suffix})
5460
    {
5461
        $suffix = '.' . $index++;
5462
    }
5463
    return $proj . $suffix; 
5464
}
5465
 
5466
#-------------------------------------------------------------------------------
227 dpurdie 5467
# Function        : MakeProject
5468
#
5469
# Description     : A nasty directive that is intended to build a Microsoft
5470
#                   project for WINCE, WIN32 and .NET builds.
5471
#
5472
#                   There are many constraints:
5473
#                       Cannot be mixed with multi-platform builds
5474
#                       Some parameters are tool specific
5475
#
267 dpurdie 5476
#                   Allow programs to be Installed as well as Packaged
5477
#                   The 'Progect' is treated' as a program and it doesn't work
5478
#                   to well if we Install libraries.
227 dpurdie 5479
#
267 dpurdie 5480
#                   Only Reason to Install Programs is to allow the Cab Maker
5481
#                   to locate them.
5482
#
227 dpurdie 5483
# Inputs          : Platform        - Active platform
5484
#                   Project         - Project Name with extension
5485
#                   Options         - Many options
5486
#
5487
# Returns         :
5488
#
5489
sub MakeProject
5490
{
5491
    my( $platforms, $proj, @elements ) = @_;
5492
 
5493
    Debug2( "MakeProject($platforms, $proj, @elements)" );
5494
 
5495
    return if ( ! ActivePlatform($platforms) );
5496
 
5497
    #
5498
    #   Sanity test
5499
    #
5500
    Error ("MakeProject: Project name not defined") unless ( $proj );
5501
 
5502
    #
5503
    #   Take the project name and convert it into a full path
4261 dpurdie 5504
    #   Need to create a uniq project name - allowing for multiple uses
227 dpurdie 5505
    #
5506
    my $project = MakeSrcResolve ( $proj );
4261 dpurdie 5507
    $proj = MakeProjectName($project);
5508
 
237 dpurdie 5509
    Error ("Project File Not found: $project") unless ( -f $project );
227 dpurdie 5510
 
5511
    my $basedir = StripFileExt( $project );
5512
 
5513
    #
5514
    #   Collect user arguments
5515
    #   They are all processed within the toolset
5516
    #
5517
    my @tool_options;
5411 dpurdie 5518
    my $unit_tests;
5519
    my $auto_tests;
227 dpurdie 5520
    foreach ( @elements )
5521
    {
5522
        if ( m/^--Debug/ ) {
5523
            $PROJECTS{$proj}{'Debug'} = 1;
5524
 
5525
        } elsif ( m/^--Prod/ ) {
5526
            $PROJECTS{$proj}{'Prod'} = 1;
5527
 
267 dpurdie 5528
        } elsif ( m/^--(Package|Install)ProgDebug=(.*)/ ) {
5529
            _PackageFromProject( $1, $proj, $basedir,'Prog', 'D', $2 );
227 dpurdie 5530
 
267 dpurdie 5531
        } elsif ( m/^--(Package|Install)Prog(Prod)*=(.*)/ ) {
5532
            _PackageFromProject( $1, $proj, $basedir, 'Prog', 'P', $3 );
227 dpurdie 5533
 
267 dpurdie 5534
        } elsif ( m/^--(Package)LibDebug=(.*)/ ) {
5535
            _PackageFromProject( $1, $proj, $basedir, 'Lib', 'D', $2 );
227 dpurdie 5536
 
267 dpurdie 5537
        } elsif ( m/^--(Package)Lib(Prod)*=(.*)/ ) {
5538
            _PackageFromProject( $1, $proj, $basedir, 'Lib', 'P', $3 );
227 dpurdie 5539
 
267 dpurdie 5540
        } elsif ( m/^--(Package)SharedLibDebug=(.*)/ ) {
5541
            _PackageFromProject( $1, $proj, $basedir, 'Lib', 'D', $2 );
227 dpurdie 5542
 
267 dpurdie 5543
        } elsif ( m/^--(Package)SharedLib(Prod)*=(.*)/ ) {
5544
            _PackageFromProject( $1, $proj, $basedir, 'Lib', 'P', $3 );
227 dpurdie 5545
 
267 dpurdie 5546
        } elsif ( m/^--(Package)Hdr=(.*)/ ) {
5547
            _PackageFromProject( $1, $proj, $basedir, 'Hdr', undef, $2 );
227 dpurdie 5548
 
267 dpurdie 5549
        } elsif ( m/^--(Package)File=(.*)/ ) {
5550
            _PackageFromProject( $1, $proj, $basedir, 'File', undef, $2 );
227 dpurdie 5551
 
267 dpurdie 5552
        } elsif ( m/^--(Package)Tool(Prod)*=(.*)/ ) {
5553
            _PackageFromProject( $1, $proj, $basedir, 'Tool', 'P', $3 );
241 dpurdie 5554
 
267 dpurdie 5555
        } elsif ( m/^--(Package)ToolDebug=(.*)/ ) {
5556
            _PackageFromProject( $1, $proj, $basedir, 'Tool', 'D', $2 );
241 dpurdie 5557
 
267 dpurdie 5558
        } elsif ( m/^--(Package|Install)/ ) {
5559
            Error("MakeProject. Unknown $1 option: $_");
227 dpurdie 5560
 
5411 dpurdie 5561
        } elsif ( m/^--UnitTest/ ) {
5562
            $unit_tests = 1;
5563
 
5564
        } elsif ( m/^--AutoTest/ ) {
5565
            $auto_tests = 1;
5566
 
227 dpurdie 5567
        } else {
5568
            push @tool_options, $_;
5569
        }
5570
    }
5571
 
5572
    #
6353 dpurdie 5573
    #   Validate some of the arguments
5574
    #   Ensure has not specified both --Prod and --Debug
5575
    #
5576
    Error ("Makeproject. Conflicting options --Debug and --Prod" )
5577
        if ( $PROJECTS{$proj}{'Debug'}  && $PROJECTS{$proj}{'Prod'} );
5578
 
5579
    #   Ensure that global --OnlyProd/Debug don't prevent builds
5580
    $PROJECTS{$proj}{'Debug'} = 1 if ($ScmBuildType eq 'D');
5581
    $PROJECTS{$proj}{'Prod'} = 1 if ($ScmBuildType eq 'P');
5582
    Error ("Makeproject. Global and Local options --Debug and --Prod prevent project being built" )
5583
        if ( $PROJECTS{$proj}{'Debug'}  && $PROJECTS{$proj}{'Prod'} );
5584
 
5585
    #
227 dpurdie 5586
    #   Save the information
5587
    #
5588
    $PROJECTS{$proj}{'options'} = \@tool_options;
5589
    $PROJECTS{$proj}{'name'} = $proj;
5590
    $PROJECTS{$proj}{'project'} = $project;
5591
    $PROJECTS{$proj}{'basedir'} = $basedir;
5411 dpurdie 5592
    $PROJECTS{$proj}{'unittest'} = $unit_tests if ( $unit_tests );
5593
    $PROJECTS{$proj}{'autotest'} = $auto_tests if ( $auto_tests );
227 dpurdie 5594
    UniquePush (\@PROJECTS_ORDER, $proj);
5595
 
5596
}
5597
 
5598
#-------------------------------------------------------------------------------
5599
# Function        : _PackageFromProject
5600
#
5601
# Description     : Save Packaged data from the project
5602
#
267 dpurdie 5603
# Inputs          : $tgt        - Install or Package
5604
#                   $proj       - Name of the project
227 dpurdie 5605
#                   $base       - Base directory of files
5606
#                   $etype      - Type of Package (Progs, Libs, ... )
5607
#                   $type       - Debug or Production or both
5608
#                   $items      - Item to add. It may be comma seperated
5609
#
267 dpurdie 5610
my %PackageToData = ( 'Package' =>
5611
                        { 'Hdr'   => \%PACKAGE_HDRS,
5612
                          'Lib'   => \%PACKAGE_LIBS,
5613
                          'Prog'  => \%PACKAGE_PROGS,
5614
                          'File'  => \%PACKAGE_FILES,
5615
                          'Tool'  => \%PACKAGE_FILES,
5616
                          '_BASE' => 'PBase',
5617
                        },
5618
                      'Install' =>
5619
                        { 'Hdr'   => \%INSTALL_HDRS,
5620
                          'Lib'   => \%INSTALL_LIBS,
5621
                          'Prog'  => \%INSTALL_PROGS,
5622
                          'File'  => undef,
5623
                          'Tool'  => undef,
5624
                          '_BASE' => 'IBase',
5625
                        },
227 dpurdie 5626
                    );
5627
 
5628
sub _PackageFromProject
5629
{
267 dpurdie 5630
    my( $tgt, $proj, $base, $etype, $type, $items ) = @_;
227 dpurdie 5631
    my $subdir = '';
5632
 
5633
    #
267 dpurdie 5634
    #   Sanity test
5635
    #
5636
    $type = '' unless ( $type );
5637
    Error ("INTERNAL. Bad packaging option: $tgt")   unless ( exists $PackageToData{$tgt} );
5638
    Error ("INTERNAL. Bad packaging option: $etype") unless ( exists $PackageToData{$tgt}{$etype} );
5639
    Error ("Unsupported packaging combination: $tgt$etype$type=$items") unless ( defined $PackageToData{$tgt}{$etype} );
5640
 
5641
    #
5642
    #   Determine the index into the 'PackageInfo' structure
5643
    #   This provides the symbolic name for the target package path
5644
    #   for Package or Install
5645
    #
5646
    #   The key '_BASE' is internal. Used only to provide this information
5647
    #
5648
    my $tbase = $PackageToData{$tgt}{'_BASE'};
5649
 
5650
    #
227 dpurdie 5651
    #   Process options
5652
    #
5653
    foreach my $item ( split (/,/, $items ) )
5654
    {
5655
        next unless ( $item =~ m/^--/ );
5656
        if ( $item =~ m/^--Subdir=(.*)/ )
5657
        {
5658
            $subdir = '/' . $1;
5659
            $subdir =~ s~//~/~g;
5660
            $subdir =~ s~/$~~g;
5661
        }
5662
        else
5663
        {
5664
            Warning( "MakeProject: Unknown packaging option ignored: $_" );
5665
        }
5666
    }
5667
 
5668
    #
5669
    #   Process files
5670
    #
5671
    foreach my $item ( split (/,/, $items ) )
5672
    {
5673
        next if ( $item =~ m/^--/ );
5674
 
267 dpurdie 5675
        my $tdir = $PackageInfo{$etype}{$tbase} . $PackageInfo{$etype}{'Dir'} . $subdir ;
227 dpurdie 5676
        my $fname = StripDir( $item );
5677
        my $target = $tdir . '/' . $fname;
5678
 
5679
        $item = "$base/$item" if ( $base );
5680
 
5681
        #
5682
        #   Do not use $(GBE_TYPE) in the target name
5683
        #   The existing package mechanism does not handle different
5684
        #   production and debug file naming mechanism, whereas the project
5685
        #   must. Convert $(GBE_TYPE) into P or D to ensure uniquness
5686
        #
5687
        $target =~ s~\$\(GBE_TYPE\)~$type~ if ($type);
5688
 
5689
        #
5690
        #   Create a PACKAGE entry suitable for processing by the normal packaging
5691
        #   routines. This is complicated because the Projects do not adhere to
267 dpurdie 5692
        #   the JATS file name conventions
227 dpurdie 5693
        #
5694
        my %package_entry;
5695
        $package_entry{'src'}   = $item;
5696
        $package_entry{'dir'}   = $tdir;
267 dpurdie 5697
        $package_entry{'set'}   = 'ALL' if ($tgt eq 'Package');
227 dpurdie 5698
        $package_entry{'type'}  = $type if ($type);
5699
 
267 dpurdie 5700
        $PackageToData{$tgt}{$etype}->{$target} = {%package_entry};
227 dpurdie 5701
    }
5702
}
5703
 
5704
#-------------------------------------------------------------------------------
5705
# Function        : MakeAnt
5706
#
5707
# Description     : A nasty directive to create JAR files via ANT
5708
#                   There are several limitations
5709
#                   This is closely related to the MakeProject directive
5710
#
5711
#
5712
# Inputs          : Platform            - Active platform
5713
#                   buildfile           - Name of the build.xml file
5714
#                   Options             - A few options
5715
#                                         --Jar=file
5716
#                                               Generated JAR file(s)
5717
#                                         --GeneratedFile=file
5718
#                                               Other generated files
5719
#                                               Used to flag JNI that must
5720
#                                               Occur early
5721
#                                          --AutoTest=<name>
5722
#                                               Supports unitAutomated unit test
5723
#                                               by calling build target <name>
5724
#                                          --UnitTest=<name>
5725
#                                               Supports unit test
5726
#                                               by calling build target <name>
5727
#                                          --PackageBase
5728
#                                               Provides path to base of all packages
6294 dpurdie 5729
#                                          --AllPackages
5730
#                                               Provide paths to both LinkPkgArchive and BuildPkgArchive
227 dpurdie 5731
#
5732
# Returns         :
5733
#
5734
our %JAR_FILES;
5735
sub MakeAnt
5736
{
5737
    my( $platforms, $proj, @elements ) = @_;
5738
 
5739
    Debug2( "MakeAnt($platforms, $proj, @elements)" );
5740
 
5741
    return if ( ! ActivePlatform($platforms) );
5742
 
5743
    #
5744
    #   Sanity test
5745
    #
5746
    Error ("MakeAnt: build.xml name not defined") unless ( $proj );
5747
 
5748
    #
5749
    #   Take the project name and convert it into a full path
5750
    #
5751
    my $project;
5752
    $project = MakeSrcResolve ( $proj );
4261 dpurdie 5753
    $proj = MakeProjectName($project);
237 dpurdie 5754
    Error ("Build File Not found: $project") unless ( -f $project );
227 dpurdie 5755
 
5756
    my $basedir = StripFileExt( $project );
5757
 
5758
    #
5759
    #   Collect user arguments
5760
    #   They are all processed within the toolset
5761
    #
5762
    my @tool_options;
5763
    my @generated;
5764
    my $unit_tests;
5765
    my $auto_tests;
5766
    my $package_base;
6294 dpurdie 5767
    my $allPackages;
227 dpurdie 5768
 
5769
    foreach ( @elements )
5770
    {
5771
        if ( m/^--Debug/ ) {
5772
            $PROJECTS{$proj}{'Debug'} = 1;
5773
 
5774
        } elsif ( m/^--Prod/ ) {
5775
            $PROJECTS{$proj}{'Prod'} = 1;
5776
 
5777
        } elsif ( m/^--Jar=(.*)/ ) {
5778
            my $tgt = $1;
5779
               $tgt = "$basedir/$tgt" if ( $basedir );
5780
            my $fn = StripDir( $1 );
5781
            $JAR_FILES{$fn} = $tgt;
5782
            GenerateSrcFile( 0, $tgt );
5783
 
5784
        } elsif ( m/^--GeneratedFile=(.*)/ ) {
5785
            my $tgt = $1;
5786
            $tgt = "$basedir/$tgt" if ( $basedir );
5787
            push @generated, $tgt;
5788
            GenerateSrcFile( 2, $tgt );
5789
 
5790
        } elsif ( m/^--UnitTest=(.*)/ ) {
5791
            $unit_tests = $1
5792
 
5793
        } elsif ( m/^--AutoTest=(.*)/ ) {
5794
            $auto_tests = $1
5795
 
5796
        } elsif ( m/^--PackageBase/ ) {
5797
            $package_base = 1;
5798
 
6294 dpurdie 5799
        } elsif ( m/^--AllPackages/i ) {
5800
            $allPackages = 1;
227 dpurdie 5801
 
5802
        } elsif ( m/^--/ ) {
5803
            Error("MakeAnt. Unknown option ignored: $_");
5804
 
5805
        } else {
5806
            push @tool_options, $_;
5807
        }
5808
    }
5809
 
5810
    #
5811
    #   Extend option arguments to include the base dir of packages
5812
    #   Create definitions of the form PACKAGE_<name>
5813
    #
6294 dpurdie 5814
    for my $entry (getPackageList())
227 dpurdie 5815
    {
6294 dpurdie 5816
        my $pkgType = $entry->getType();
5817
        next if $pkgType eq 'interface'  ;
5818
        next unless ( ( $pkgType eq 'link') || $allPackages);
5819
        my $dir = $entry->getBase(2);
5820
        my $name = $entry->getName();
227 dpurdie 5821
        unless ( $package_base )
5822
        {
5823
            $dir .= '/jar';
5824
            next unless ( -d $dir );
5825
        }
6294 dpurdie 5826
        push @tool_options, "-DPACKAGE_$name=\$(call myabspath,$dir)";
227 dpurdie 5827
    }
5828
    #
5829
    #   Extend options to include the base dir of the created package
5830
    #   Allows careful use for direct packaging of artifacts
5831
    #
6294 dpurdie 5832
    push @tool_options, '-DPACKAGEDIR=$(call myabspath,$(PKGDIR))';
227 dpurdie 5833
 
5834
    #
5835
    #   Save the information
5836
    #
5837
    $PROJECTS{$proj}{'options'} = \@tool_options;
5838
    $PROJECTS{$proj}{'generated'} = \@generated if ( @generated );
5839
    $PROJECTS{$proj}{'name'}    = $proj;
5840
    $PROJECTS{$proj}{'project'} = $project;
5841
    $PROJECTS{$proj}{'basedir'} = $basedir;
5842
    $PROJECTS{$proj}{'type'}    = 'ant';
5843
    $PROJECTS{$proj}{'unittest'} = $unit_tests if ( $unit_tests );
5844
    $PROJECTS{$proj}{'autotest'} = $auto_tests if ( $auto_tests );
5845
    UniquePush (\@PROJECTS_ORDER, $proj);
5846
 
5847
    $TESTS_TO_AUTORUN = 1 if ( $auto_tests );
4501 dpurdie 5848
    $TESTS_TO_RUN     = 1 if ( $unit_tests || $auto_tests );
227 dpurdie 5849
 
5850
    #
5851
    #   Validate some of the arguments
5852
    #
5853
    Error ("MakeAnt. Conflicting options --Debug and --Prod" )
5854
        if ( $PROJECTS{$proj}{'Debug'}  && $PROJECTS{$proj}{'Prod'} );
5855
}
5856
 
5857
###############################################################################
5858
#
5859
#   Installation/Packaging util functions
5860
#
5861
#-------------------------------------------------------------------------------
5862
# Function        : __TargetDir
5863
#
5864
# Description     : Internal function to process common arguments for
5865
#                   the PackageXxx directives
5866
#
5867
# Inputs          : flags           - Indicate how to handle this argument
5868
#                   base            - Base directory for this type of package
5869
#                   argument        - Argument to process
5870
#                   pdir            - Reference to resultant directory
5871
#                   ptype           - Reference to resultant type (P or D)(optional)
5872
#
5873
# Returns         : 0               - Agument not consumed
5874
#                   1               - Argument consumed
5875
#                   2               - Skip this directive
5876
#
5877
my $T_TYPE  = 0x0001;                           # Postfix GBE_TYPE
5878
my $T_PKG   = 0x0002;                           # Special --Dir handling
5879
my $T_MACH  = 0x0004;                           # Allow --Machine too
5880
my $T_GBE   = 0x0008;                           # Allow --Gbe too
5881
my $T_FILE  = 0x0010;                           # Suffix or prefix subdir
5882
 
5883
sub __TargetDir
5884
{
5885
    my( $flags, $base, $argument, $pdir, $ptype ) = @_;
5886
    my $dir  = "";
5887
    my $consumed = 0;
5888
 
5889
    #
5890
    #   Generate basic parts
5891
    #   Note Product will default to Platform
5892
    #
5893
    my $str_platform = '$(GBE_PLATFORM)';
5894
    my $str_product = $ScmProduct ? '$(GBE_PRODUCT)' : '$(GBE_PLATFORM)';
5895
    my $str_target = '$(GBE_TARGET)';
5896
    my $str_common = '$(GBE_OS_COMMON)';
5897
 
5898
    my $str_common_avail = 0;
5899
       $str_common_avail = 1 if ( exists( $::BUILDINFO{$ScmPlatform}{OS_COMMON} ));
5900
 
5901
 
5902
    #
5903
    #   Add requested suffix
5904
    #
5905
    if ($flags & $T_TYPE)
5906
    {
5907
        $str_platform .= '$(GBE_TYPE)';
5908
        $str_product  .= '$(GBE_TYPE)';
5909
        $str_target   .= '$(GBE_TYPE)';
5910
        $str_common   .= '$(GBE_TYPE)';
5911
    }
5912
 
5913
    #
5914
    #   Process the argument
5915
    #
5916
    $_ = $argument;
5917
    if ( /^--Debug/ ) {                         # In the Debug build only
5918
        if ( $ptype ) {
5919
            $$ptype = "D";
5920
            $consumed = 1;
5921
        }
5922
 
5923
    } elsif ( /^--Prod$/ || /^--Production$/ ) { # In the Production build only
5924
        if ( $ptype ) {
5925
            $$ptype = "P";
5926
            $consumed = 1;
5927
        }
5928
 
5929
    } elsif (/^--Prefix=(.*)/) {                # Prefix with subdir
5930
        $dir = "$base/$1";
5931
 
5932
    } elsif (/^--Subdir=(.*)/) {                # same as 'prefix'
5933
        $dir = "$base/$1";
5934
 
5935
    } elsif (/^--Platform$/) {                  # Platform installation
5936
        $dir = "$base/$str_platform";
5937
 
5938
    } elsif (/^--Platform=(.*?),(.*)/) {        # prefix and suffix with platform specific subdir
5939
        $dir = "$base/$1/$str_platform/$2";
5940
 
5941
    } elsif (/^--Platform=(.*)/) {              # prefix with platform specific subdir
5942
        if ($flags & $T_FILE) {
5943
            $dir = "$base/$1/$str_platform";
5944
        } else {
5945
            $dir = "$base/$str_platform/$1";
5946
        }
5947
 
5948
    } elsif (/^--Product$/) {                   # Product installation
5949
        $dir = "$base/$str_product";
5950
 
5951
    } elsif (/^--Product=(.*?),(.*)/) {         # prefix and suffix with product specific subdir
5952
        $dir = "$base/$1/$str_product/$2";
5953
 
5954
    } elsif (/^--Product=(.*)/) {               # prefix with product specific subdir
5955
        if ($flags & $T_FILE) {
5956
            $dir = "$base/$1/$str_product";
5957
        } else {
5958
            $dir = "$base/$str_product/$1";
5959
        }
5960
 
5961
    } elsif (/^--Target$/) {                    # Target installation
5962
        $dir = "$base/$str_target";
5963
 
5964
    } elsif (/^--Target=(.*?),(.*)/) {          # prefix and suffix with target specific subdir
5965
        $dir = "$base/$1/$str_target/$2";
5966
 
5967
    } elsif (/^--Target=(.*)/) {                # prefix with target specific subdir
5968
        if ($flags & $T_FILE) {
5969
            $dir = "$base/$1/$str_target";
5970
        } else {
5971
            $dir = "$base/$str_target/$1";
5972
        }
5973
 
5974
    } elsif (/^--OsCommon/) {
5975
 
5976
        unless ( $str_common_avail ) {
5977
            Warning("Packaging option --OsCommon not supported on this platform($ScmPlatform). Directive skipped");
5978
            $consumed = 2;
5979
 
5980
        } elsif (/^--OsCommon$/) {                  # OS installation
5981
            $dir = "$base/$str_common";
5982
 
5983
        } elsif (/^--OsCommon=(.*?),(.*)/) {        # prefix and suffix with target specific subdir
5984
            $dir = "$base/$1/$str_common/$2";
5985
 
5986
        } elsif (/^--OsCommon=(.*)/) {              # prefix with target specific subdir
5987
            if ($flags & $T_FILE) {
5988
                $dir = "$base/$1/$str_common";
5989
            } else {
5990
                $dir = "$base/$str_common/$1";
5991
            }
5992
        }
5993
 
5994
    } elsif (/^--Derived=(.*?),(.*?),(.*)/) {   # Derived target + prefix + subdir
5995
        $dir = "$base/$2/$1_$str_platform/$3";
5996
 
5997
    } elsif (/^--Derived=(.*?),(.*)/) {         # Derived target + subdir
5998
        if ($flags & $T_FILE) {
5999
            $dir = "$base/$2/$1_$str_platform";
6000
        } else {
6001
            $dir = "$base/$1_$str_platform/$2";
6002
        }
6003
 
6004
    } elsif (/^--Derived=(.*)/) {               # Derived target
6005
        $dir = "$base/$1_$str_platform";
6006
 
6007
    } elsif ($flags & $T_MACH && /^--Machine(([=])(.*))?$/) {   # Allow Machine and Machine=xxx specfic target
6008
        #
6009
        #   Special: Append machine type to user dir
6010
        #            Intended to create tools/bin/win32 and tools/bin/sparc directories
6011
        my $path = ( defined( $3) ) ? "/$3" : "";
6012
        $dir = "$base$path/\$(GBE_HOSTMACH)";
6013
 
6014
    } elsif ($flags & $T_GBE && /^--Gbe(([=])(.*))?$/) {   # Allow Gbe and Gbe=xxx specfic target
6015
        my $path = ( defined( $3) ) ? "/$3" : "";
6016
        $dir = "$base/gbe$path";
6017
 
6018
    } elsif (/^--Dir=(.*)/) {                   # prefix with target specific subdir
6019
        Error ('Packaging directive with --Dir option does not specify a directory.',
6020
               'Possible bad use of option of the form:--Dir=$xxx',
6021
               'Note: Use of package.pl and this construct is deprecated') unless ( $1 );
241 dpurdie 6022
        my $udir = $1;
6023
 
6024
        #
6025
        #   Remove leading ./
6026
        #   Check for leading ../
5568 dpurdie 6027
        #   
6028
        #   Remove any stupid path manipulation elements
6029
        #   
5827 dpurdie 6030
        if ($udir =~ s~^([./]*/)~~)
6031
        {
6032
            Warning("Packaging directive with --Dir option contains path manipulation elements (removed)", "Option: $_");
6033
        }
241 dpurdie 6034
 
227 dpurdie 6035
        if ($flags & $T_PKG) {
241 dpurdie 6036
            $dir = __PkgDir( $udir );
227 dpurdie 6037
        } else {
6387 dpurdie 6038
            $dir = $base . "/" . $udir;
227 dpurdie 6039
        }
6040
    }
6041
 
6042
    return ($consumed) if ($dir eq "");
6043
    $dir =~ s~//~/~g;
6044
    $dir =~ s~/$~~;
6045
    $$pdir = $dir;
6046
    return (1);
6047
}
6048
 
6049
 
6050
#   __PkgDir ---
6051
#       Convert --Dir Package directives, removing leading subdir if
6052
#       matching the global $Pbase value.
6053
#
6054
#       Required as PKGDIR has the value 'GBE_ROOT/pkg/$Pbase'.
6055
#       Required to maintain compatability with older (package.pl) constructs
6056
#..
6057
 
6058
sub __PkgDir
6059
{
6060
    my( $dir ) = @_;
6061
    my $org = $dir;
6062
 
245 dpurdie 6063
    $dir =~ s~^\Q$::Pbase\E[/]?~~;
227 dpurdie 6064
    Debug2( "  PkgDir: converted \"$org\" to \"$dir\"" );
6065
 
6066
    $dir = "\$(PKGDIR)/$dir";
6067
    return $dir;
6068
}
6069
 
6070
 
6071
#   getMajorMinor ---
6072
#       Just a little help to deal with major/minor stuff for shared libs -
6073
#       given the name of the library as the argument, split out major and
6074
#       minor parts and return the basename, i.e name without major and minor
6075
#       and the pair of major and minor.
6076
#..
6077
 
285 dpurdie 6078
sub getMajorMinor
227 dpurdie 6079
{
6080
    my @bits = split ('\.', $_[0]);
6081
    my $stop;
6082
    my $major;
6083
    my $minor;
6084
 
6085
    if ( $#bits > 2 )
6086
    {
6087
        $stop = $#bits - 2;
6088
        $major = $bits[$#bits-1];
6089
        $minor = $bits[$#bits];
6090
    }
6091
    elsif ($#bits > 1)
6092
    {
6093
        $stop = $#bits-1;
6094
        $major = $bits[$#bits];
6095
        $minor=0;
6096
    }
6097
    else
6098
    {
6099
        $stop = $#bits; $major = 1; $minor = 0;
6100
    }
6101
 
6102
    my $base = $bits[0];
6103
    for ( my $i=1; $i <= $stop; $i++ ) {
6104
        $base = join ('.', $base, $bits[$i]);
6105
    }
6106
 
6107
    return ($base, $major, $minor);
6108
}
6109
 
6110
###############################################################################
6111
#
6112
#   Installation
6113
#
6114
 
6115
sub InstallHdr
6116
{
6117
    my( $platforms, @elements ) = @_;
335 dpurdie 6118
    my( $base, $dir, $srcfile, $full, $strip, $package );
227 dpurdie 6119
    my( $len, $name, $basename );
6120
 
6121
    Debug2( "InstallHdr($platforms, @elements)" );
6122
 
6123
    return if ( ! ActivePlatform($platforms) );
6124
    Warning ("InstallHdr: Needs local directory specified in build.pl") unless ( $::ScmLocal );
6125
 
6126
#.. Arguments
6127
#
6128
    $base = $PackageInfo{'Hdr'}{'IBase'};       # Base of target
6129
    $dir = $base . $PackageInfo{'Hdr'}{'Dir'};  # Installation path (default)
335 dpurdie 6130
    $full = $strip = 0;
227 dpurdie 6131
 
285 dpurdie 6132
    foreach ( @elements )
227 dpurdie 6133
    {
6134
                                                # Standard targets
6135
        my $rv = __TargetDir(0, $base, $_, \$dir);
6136
        next if ( $rv == 1 );
6137
        return if ( $rv == 2 );
6138
 
6139
        if (/^--Full/) {                        # using full (resolved) path
6140
            $full = 1;
6141
 
6142
        } elsif (/^--Strip$/) {                 # Strip path from source files
6276 dpurdie 6143
            $strip = -1;
227 dpurdie 6144
 
6276 dpurdie 6145
        } elsif (/^--Strip=(\d+)$/) {           # Strip some f the path from source files
6146
            $strip = $1;
227 dpurdie 6147
                                                # Package
6148
        } elsif (/^--Package$/ || /^--Package=(.*)/) {
6149
            $package = 1;
6150
 
6151
        } elsif (/^--(.*)/) {
6152
            Message( "InstallHdr: unknown option $_ -- ignored\n" );
6153
        }
6154
    }
6155
 
6156
#.. Files
6157
#
285 dpurdie 6158
    foreach ( @elements )
227 dpurdie 6159
    {
6160
        my %package_entry;
6161
        if ( ! /^--(.*)/ )
6162
        {
6163
            $name = $_;
6164
            $basename = StripDir( $name );
335 dpurdie 6165
            if ( !($srcfile = $SRCS{ $basename }) ) {
6166
                $srcfile = $name;
6167
            }
6168
 
227 dpurdie 6169
            if ( $full )
6170
            {
335 dpurdie 6171
                my $subdir = StripFileExt($srcfile);
6172
                $subdir = $1
6173
                    if ( $subdir =~ m~^$ProjectBase/(.*)~ );
6174
                $dir .= '/' . $subdir;
6175
                $dir =~ s~//~/~g;
6176
                $dir =~ s~/./~/~g;
6177
                $dir =~ s~/$~~g;
6178
                $name = $basename;
227 dpurdie 6179
            }
6180
 
6276 dpurdie 6181
            $name = StripPath($name, $strip) if ($strip);
227 dpurdie 6182
 
6183
            Debug( "InstallHdr( $dir/$name, src: $srcfile, dest: $dir)" );
6184
 
6185
            $package_entry{'src'} = $srcfile;
6186
            $package_entry{'dir'} = StripFileExt( "$dir/$name" );
6187
            $INSTALL_HDRS{ "$dir/$name" } = {%package_entry};
6188
        }
6189
    }
6190
 
6191
#.. Package
6192
#
6193
    PackageHdr( @_ )                            # auto package
6194
        if ( $package );
6195
}
6196
 
6197
 
6198
sub InstallLib
6199
{
6200
    my( $platforms, @elements ) = @_;
6201
    my( $base, $dir, $package );
6202
    my( $lib, $strip );
289 dpurdie 6203
    my $org_lib;
227 dpurdie 6204
 
6205
    Debug2( "InstallLib($platforms, @elements)" );
6206
 
6207
    return if ( ! ActivePlatform($platforms) );
6208
    Warning ("InstallLib: Needs local directory specified in build.pl") unless ( $::ScmLocal );
6209
 
6210
#.. Arguments
6211
#
6212
    $base = $PackageInfo{'Lib'}{'IBase'};       # Base of target
6213
    $dir = $base . $PackageInfo{'Lib'}{'Dir'};  # Installation path (default)
6214
 
285 dpurdie 6215
    foreach ( @elements )
227 dpurdie 6216
    {
6217
                                                # Standard targets
6218
        my $rv = __TargetDir(0, $base, $_, \$dir);
6219
        next if ( $rv == 1 );
6220
        return if ( $rv == 2 );
6221
 
6222
        if (/^--Package$/ || /^--Package=(.*)/) {
6223
            $package = 1;
6224
 
6225
        } elsif (/^--Strip$/) {                 # Strip path from source files
6276 dpurdie 6226
            $strip = -1;
227 dpurdie 6227
 
6276 dpurdie 6228
        } elsif (/^--Strip=(\d+)$/) {           # Strip some f the path from source files
6229
            $strip = $1;
6230
 
227 dpurdie 6231
        } elsif (/^--(.*)/) {
6232
            Message( "InstallLib: unknown option $_ -- ignored\n" );
6233
        }
6234
    }
6235
 
6236
#.. Files
6237
#
285 dpurdie 6238
    foreach ( @elements )
227 dpurdie 6239
    {
6240
        my %package_entry;
6241
        if ( ! /^--(.*)/ )
6242
        {
6276 dpurdie 6243
            $_ = StripPath($_, $strip) if ($strip);
289 dpurdie 6244
            $org_lib = $_;                      # Original name
227 dpurdie 6245
 
6246
            if ( $ScmTargetHost eq "Unix" ) {
6247
                $lib = "lib$_";                 # Prefix "lib" ....
6248
                $lib =~ s/^liblib/lib/;         # @LIBS already has lib added
6249
            } else {
6250
                $lib = $_;
6251
            }
6252
 
289 dpurdie 6253
            if (  my $libp = $SHLIBS->Get($lib) )
227 dpurdie 6254
            {
6255
                Debug( "InstallLib( $dir/$lib\$(GBE_TYPE).$::so, " .
6256
                    "src: \$(LIBDIR)/$lib\$(GBE_TYPE).$::so, dest: $dir)" );
6257
 
6258
                #
6259
                #   Create a "placekeeper" entry within $INSTALL_SHLIBS
6260
                #   The exact format of the name of the shared library is
6261
                #   toolset specific. Create an entry to allow the toolset
6262
                #   to extend the packaging information when the shared library
6263
                #   recipe is constructed.
6264
                #
289 dpurdie 6265
                my $ver = $libp->{ VERSION };
227 dpurdie 6266
                my $name = "$dir/$lib.$ver.PlaceKeeper";
6267
 
6268
                $package_entry{'placekeeper'} = 1;
6269
                $package_entry{'version'} = $ver;
6270
                $package_entry{'lib'} = $lib;
6271
                $package_entry{'dir'} = $dir;
289 dpurdie 6272
 
6273
                push @{$SHLIB_INS{$lib}}, $name;
227 dpurdie 6274
                $INSTALL_SHLIBS{$name} = {%package_entry};
6275
            }
6276
 
289 dpurdie 6277
            #
6278
            #   Clean up the package_entry
6279
            #   Insert common items
6280
            #
6281
            %package_entry = ();
6282
            $package_entry{'lib'} = $lib;
6283
            $package_entry{'dir'} = $dir;
6284
 
321 dpurdie 6285
            if ( my $libfile = $SRCS{$org_lib} )
227 dpurdie 6286
            {
6287
                #
6288
                #   Allow the user to package a sourced file as a library
289 dpurdie 6289
                #   But must be the un-massaged name of the file.
227 dpurdie 6290
                #
289 dpurdie 6291
                $package_entry{'dst'} = "$dir/$org_lib";
6292
                $package_entry{'src'} = $libfile;
6293
            }
6294
            elsif ( $LIBS->Get($lib) )
6295
            {
6296
                #
6297
                #   Install a library known to the makefile
6298
                #
6299
                my $libp = $LIBS->Get($lib);
227 dpurdie 6300
 
289 dpurdie 6301
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
6302
                $package_entry{'src'}    = $libp->getPath();
227 dpurdie 6303
            }
289 dpurdie 6304
            elsif ( ! $SHLIBS->Get($lib) )
227 dpurdie 6305
            {
289 dpurdie 6306
                #
6307
                #   Not a known shared lib
6308
                #   Not a known static lib
6309
                #   Not a 'sourced' file
6310
                #   Assume the a static library has magically appeared
6311
                #   in the standard LIB directory. May have been placed there
6312
                #   by a 'rule'
6313
                #
6314
                my $libp = $LIBS->New($lib);
227 dpurdie 6315
 
289 dpurdie 6316
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
6317
                $package_entry{'src'}    = $libp->getPath();
6318
            }
227 dpurdie 6319
 
289 dpurdie 6320
            #
6321
            #   Add entry to various lists if required
6322
            #
6323
            PackageLib_AddEntry ('InstallLib', \%LIB_INS, \%INSTALL_LIBS, \%package_entry )
6324
                if ( exists $package_entry{'dst'} );
227 dpurdie 6325
        }
6326
    }
6327
 
6328
#.. Package
6329
#
6330
    PackageLib( @_ )                            # auto package
6331
        if ( $package );
6332
}
6333
 
6334
 
6335
sub InstallJar
6336
{
6337
    my( $platforms, @elements ) = @_;
6338
    my( $base, $dir, $package );
6339
    my( $jar );
6340
 
6341
    Debug2( "InstallJar($platforms, @elements)" );
6342
 
6343
    return if ( ! ActivePlatform($platforms) );
6344
    Warning ("InstallJar: Needs local directory specified in build.pl") unless ( $::ScmLocal );
6345
 
6346
#.. Arguments
6347
#
6348
    $base = $PackageInfo{'Jar'}{'IBase'};       # Base of target
6349
    $dir = $base . $PackageInfo{'Jar'}{'Dir'};  # Installation path (default)
6350
 
285 dpurdie 6351
    foreach ( @elements )
227 dpurdie 6352
    {
6353
                                                # Standard targets
6354
        my $rv = __TargetDir(0, $base, $_, \$dir);
6355
        next if ( $rv == 1 );
6356
        return if ( $rv == 2 );
6357
 
6358
        if (/^--Package$/ || /^--Package=(.*)/) {
6359
            $package = 1;
6360
 
6361
        } elsif (/^--(.*)/) {
6362
            Message( "InstallJar: unknown option $_ -- ignored\n" );
6363
        }
6364
    }
6365
 
6366
 
6367
#.. Files
6368
#
285 dpurdie 6369
    foreach ( @elements )
227 dpurdie 6370
    {
6371
        my %package_entry;
6372
        if ( ! /^--(.*)/ )
6373
        {
6374
            $jar = $_;
6375
            my $src;
6376
            my $dest;
6377
 
6378
            if ( $JAR_FILES{$jar} )
6379
            {
6380
                $src = $JAR_FILES{$jar};
6381
                $dest = $jar;
6382
            }
6383
            else
6384
            {
6385
                $src = "\$(CLSDIR)/$jar\$(GBE_TYPE).jar";
6386
                $dest = "$jar\$(GBE_TYPE).jar";
6387
            }
6388
 
6389
 
6390
            Debug( "InstallJar( $dir/$dest, " .
6391
                "src: $src, dest: $dir)" );
6392
 
6393
            $package_entry{'src'} = $src;
6394
            $package_entry{'dir'} = $dir;
6395
            $INSTALL_CLSS{ "$dir/$dest" } = {%package_entry};
6396
 
6397
        }
6398
    }
6399
 
6400
#.. Package
6401
#
6402
    PackageJar( @_ )                            # auto package
6403
        if ( $package );
6404
}
6405
 
6406
 
6407
sub InstallProg
6408
{
6409
    my( $platforms, @elements ) = @_;
6410
    my( $base, $dir, $package );
6411
    my( $prog );
6412
 
6413
    Debug2( "InstallProg($platforms, @elements)" );
6414
 
6415
    return if ( ! ActivePlatform($platforms) );
6416
    Warning ("InstallProg: Needs local directory specified in build.pl") unless ( $::ScmLocal );
6417
 
6418
#.. Arguments
6419
#
6420
    $base = $PackageInfo{'Prog'}{'IBase'};       # Base of target
6421
    $dir = $base . $PackageInfo{'Prog'}{'Dir'};  # Installation path (default)
6422
 
285 dpurdie 6423
    foreach ( @elements )
227 dpurdie 6424
    {
6425
                                                # Standard targets
6426
        my $rv = __TargetDir($T_TYPE, $base, $_, \$dir);
6427
        next if ( $rv == 1 );
6428
        return if ( $rv == 2 );
6429
 
6430
        if (/^--Package$/ || /^--Package=(.*)/) {
6431
            $package = 1;
6432
 
6433
        } elsif (/^--(.*)/) {
6434
            Message( "InstallProg: unknown option $_ -- ignored\n" );
6435
        }
6436
    }
6437
 
6438
#.. Files
6439
#
285 dpurdie 6440
    foreach ( @elements )
227 dpurdie 6441
    {
6442
        my %package_entry;
6443
        if ( ! /^--(.*)/ )
6444
        {
6445
            my $ext = "";
6446
            $prog = $_;
6447
 
6448
            #
6449
            #   If the named target is a program then append the correct
6450
            #   extension. Otherwise assume that the target is either a script
6451
            #   or a some other file - and don't append an extension
6452
            #
6453
            $ext = $::exe
289 dpurdie 6454
                if ( $PROGS->Get($prog) );
227 dpurdie 6455
 
6456
            #
6457
            #   A "file" that is specified with a "Src" directive may be
6458
            #   installed as though it were a program
6459
            #
6460
            my $progfile;
6461
            $progfile = "\$(BINDIR)/$prog$ext"
6462
                unless ( $progfile = $SRCS{$prog} );
6463
 
6464
            Debug( "InstallProg( $dir/$prog$ext, " .
6465
                 "src: $progfile, dest: $dir)" );
6466
 
6467
            push @{$PROG_INS{$prog}}, "$dir/$prog$ext";
6468
 
6469
            $package_entry{'src'} = $progfile;
6470
            $package_entry{'dir'} = $dir;
6471
            $INSTALL_PROGS{ "$dir/$prog$ext" } = {%package_entry};
6472
        }
6473
    }
6474
 
6475
#.. Package
6476
#
6477
    PackageProg( @_ )                           # auto package
6478
        if ( $package );
6479
}
6480
 
6276 dpurdie 6481
#-------------------------------------------------------------------------------
6482
# Function        : StripPath 
6483
#
6484
# Description     : Internal function to strip bits from a pathname
6485
#                   Will never strip the filename, even if asked to strip too much
6486
#
6487
# Inputs          : $name       - Name to process
6488
#                   $stripCount - Strip part
6489
#                                 <0 - strip all paths
6490
#                                 =0  - Do nothing
6491
#                                 >0 - Strip count
6492
#
6493
# Returns         : Processed name
6494
#
6495
sub StripPath
6496
{
6497
    my( $name, $stripCount) = @_;
227 dpurdie 6498
 
6276 dpurdie 6499
    if ($stripCount)
6500
    {
6501
        $name =~ s~\\~/~g;
6502
        $name =~ s~//~~g;
6503
 
6504
        my @items = split('/', $name);
6505
        if ($stripCount > 0)
6506
        {
6507
            my $len = scalar @items;
6508
            my $remove = $stripCount; 
6509
            if ($stripCount >= $len ) {
6510
                $remove = $len - 1;
6511
            }
6512
            splice @items, 0, $remove;
6513
            $name = join('/', @items);
6514
        }
6515
        else
6516
        {
6517
            $name = pop @items;
6518
        }
6519
    }
6520
    return $name;
6521
}
6522
 
6523
 
227 dpurdie 6524
###############################################################################
6525
#
6526
#   Packaging
6527
#
6528
sub PackageDist
6529
{
6530
    my( $name, @elements ) = @_;
6531
 
6532
    Debug2( "PackageDist($name, @elements)" );
6533
 
6534
    foreach ( @elements )
6535
    {
6536
    #.. Distribution sets
6537
    #
6538
        HashJoin( \%PACKAGE_DIST, $;, $name, "$_" );
6539
 
6540
    #.. Summary of distribution sets
6541
    #
267 dpurdie 6542
        $PACKAGE_SETS{ $_ }{'TAG'} = 1
6543
            if ( ! exists $PACKAGE_SETS{ $_ }{'TAG'} );
227 dpurdie 6544
    }
6545
}
6546
 
311 dpurdie 6547
#-------------------------------------------------------------------------------
6387 dpurdie 6548
# Function        : PackageDir 
6549
#                   InstallDir
6550
#
6551
# Description     : Directive to package an entire directory tree
6552
#                   Will package the contents of the directory without regard as to there content
6553
#                   
6554
#                   Differs from PackageFile (... --DirTree ) in that the process is dynamic
6555
#                   It will support the packaging of files that are generated
6556
#                   
6557
#                   NOT intended to support the JATS BIN and LIB structure
6558
#                   It knows nothing of these types of files
6559
#
6560
# Inputs          : platforms   - Active platform list
6561
#                   Options:    - Many from PackageFile
6562
#                       --DirTree=xxx   Source Tree [Mandatory]
6563
#                       --Subdir=yyy    Target [ Mandatory]
6564
#
6565
sub PackageDir { 
6566
    return if ( !$ScmPackage );                 # Packaging enabled ?
6567
    _PackageInstallDir('PackageDir', 'PBase', \@PACKAGE_DIRS, @_);
6568
    }
6569
 
6570
sub InstallDir { 
6571
    Warning ("InstallDir: Needs local directory specified in build.pl") unless ( $::ScmLocal );
6572
    _PackageInstallDir('InstallDir', 'IBase', \@INSTALL_DIRS, @_);
6573
    }
6574
 
6575
sub _PackageInstallDir
6576
{
6577
    my( $cmdName, $tbase, $dirRef, $platforms, @elements ) = @_;
6578
    my( $base, $dir, $path, $type );
6579
    my %data;
6580
 
6581
    Debug2( "$cmdName($platforms, @elements)" );
6582
 
6583
    return if ( ! ActivePlatform($platforms) );
6584
 
6585
#.. Arguments
6586
#
6587
    $base = $PackageInfo{'File'}{$tbase};           # Base of target
6588
    $dir = $base . $PackageInfo{'File'}{'Dir'};     # Installation path (default)
6589
 
6590
    foreach ( @elements )
6591
    {
6592
        my $rv = __TargetDir($T_MACH|$T_GBE|$T_FILE, $base, $_, \$dir, \$type);
6593
        next if ( $rv == 1 );
6594
        return if ( $rv == 2 );
6595
 
6596
        if (/^--Executable$/) {                  # Mark the file as executable
6597
            $data{exefile} = "X";
6598
 
6599
        } elsif (/^--PreserveSymlink/i) {        # Preserve symlink to local file
6600
            delete $data{noPreserveSymlink};
6601
 
6602
        } elsif (/^--NoPreserveSymlink/i) {      # Preserve symlink to local file
6603
            $data{noPreserveSymlink} = 1;
6604
 
6605
        } elsif ( /^--DirTree=(.*)/ ) {
6606
            Error("DirTree. Multiple directories not allowed.") if ( $data{dirTree} );
6607
            $data{dirTree} =  $1;
6608
 
6609
        } elsif ( /^--FilterOut=(.*)/ ) {
6610
            push @{$data{exclude}}, $1;
6611
 
6612
        } elsif ( /^--FilterIn=(.*)/ ) {
6613
            push @{$data{include}}, $1;
6614
 
6615
        } elsif ( /^--FilterOutRe=(.*)/ ) {
6616
            push @{$data{excludeRe}}, $1;
6617
 
6618
        } elsif ( /^--FilterInRe=(.*)/ ) {
6619
            push @{$data{includeRe}}, $1;
6620
 
6621
        } elsif ( /^--StripDir/ ) {
6622
            $data{strip_base} = 1;
6623
 
6624
        } elsif ( m/^--Recurse/ ) {
6625
            delete $data{noRecurse};
6626
 
6627
        } elsif ( m/^--NoRecurse/ ) {
6628
            $data{noRecurse} = 1;
6629
 
6630
        } elsif (/^--(.*)/) {
6631
            Message( "$cmdName: unknown option $_ -- ignored\n" );
6632
        }
6633
    }
6634
    Error("DirTree. No path specified") unless ( defined($data{dirTree}) && $data{dirTree} ne "" );
6635
    Debug2( "$cmdName. Raw DirTree: $data{dirTree}" );
6636
 
6637
    # Prevent the user from escaping from the current directory
6638
    Error("$cmdName. Absolute paths are not allowed",
6639
          "Directory: $data{dirTree}") if ( $data{dirTree} =~ m~^/~ || $data{dirTree} =~ m~^.\:~ );
6640
 
6641
    #
6642
    #   Convert the relative path to one that is truely relative to the current
6643
    #   directory. This may occur when the user uses $ProjectBase
6644
    #
6645
    my $abs_dir_tree = AbsPath($data{dirTree});
6646
    $data{dirTree} = RelPath($abs_dir_tree);
6647
 
6648
    #
6649
    #   Ensure that the user is not trying to escape the package
6650
    #   Don't allow the user to attempt to package the entire package either
6651
    #
6652
    #   Calculate the relative path from $ProjectBase to the target directory
6653
    #   It must not be above the $ProjectBase 
6654
    #
6655
    if ( $data{dirTree} =~ m~^\.\.~)
6656
    {
6657
        my $dirFromBase = RelPath($abs_dir_tree, AbsPath($ProjectBase));
6658
        Error("$cmdName. DirTree cannot extend outside current package.",
6659
              "Directory: $dirFromBase") if ( $dirFromBase =~ m~\.\.~ );
6660
        Error("$cmdName. DirTree cannot package entire package.",
6661
            "Directory: $dirFromBase") if ( $dirFromBase eq '.' );
6662
    }
6663
 
6664
    Debug( "$cmdName( $data{dirTree}");
6665
    $data{dir} = $dir;
6666
    $data{type} = $type if defined $type;
6667
    #DebugDumpData("$cmdName", \%data);
6668
    push @{$dirRef}, \%data;
6669
}
6670
 
6671
#-------------------------------------------------------------------------------
311 dpurdie 6672
# Function        : PackageFile
6673
#
6674
# Description     : Directive to package files
6675
#                   Not to be used to package libraries, executables, headers
6676
#                   as this should be done by specialised directives
6677
#
6678
#                   Use to package other files
6679
#                   Can package an entire tree (ugly)
6680
#
6681
# Inputs          : 
6682
#
6683
#
227 dpurdie 6684
sub PackageFile
6685
{
6686
    my( $platforms, @elements ) = @_;
335 dpurdie 6687
    my( $base, $dir, $full, $path, $dist, $strip, $exefile, $type );
227 dpurdie 6688
    my( $name, $basename, $len, $srcfile );
4257 dpurdie 6689
    my( $dir_tree, @dir_tree_exclude, @dir_tree_include, $strip_base, $strip_dots );
335 dpurdie 6690
    my $recurse = 1;
6133 dpurdie 6691
    my $preserveSymlink = 0;
227 dpurdie 6692
 
6693
    Debug2( "PackageFile($platforms, @elements)" );
6694
 
6695
    return if ( !$ScmPackage );                 # Packaging enabled ?
6696
    return if ( ! ActivePlatform($platforms) );
6697
 
6698
#.. Arguments
6699
#
6700
    $dist = "ALL";                                  # Default set (ALL)
6701
    $base = $PackageInfo{'File'}{'PBase'};          # Base of target
6702
    $dir = $base . $PackageInfo{'File'}{'Dir'};     # Installation path (default)
335 dpurdie 6703
    $full = 0;
227 dpurdie 6704
    $strip = 0;
341 dpurdie 6705
    $strip_base = 0;
4257 dpurdie 6706
    $strip_dots = 0;
227 dpurdie 6707
    $exefile = 0;
6708
 
285 dpurdie 6709
    foreach ( @elements )
227 dpurdie 6710
    {
6711
        my $rv = __TargetDir($T_PKG|$T_MACH|$T_GBE|$T_FILE, $base, $_, \$dir, \$type);
6712
        next if ( $rv == 1 );
6713
        return if ( $rv == 2 );
6714
 
6715
        if (/^--Full/) {                        # Using full (resolved) path
6716
            $full = 1;
6717
 
6718
        } elsif (/^--Set=(.*)/) {               # Distribution set
6719
            $dist = "$1";
6720
 
6721
        } elsif (/^--Package$/) {               # Package .. call by InstallFile
6722
        } elsif (/^--Package=(.*)/) {
6723
            $dist = "$1";
6724
 
6725
        } elsif (/^--Strip$/) {                 # Strip path from source files
6276 dpurdie 6726
            $strip = -1;
227 dpurdie 6727
 
6294 dpurdie 6728
        } elsif (/^--Strip=(\d+)$/) {           # Strip path from source files
6276 dpurdie 6729
            $strip = $1;
6730
 
227 dpurdie 6731
        } elsif (/^--Executable$/) {            # Mark the file as executable
6732
            $exefile = "X";
6733
 
6133 dpurdie 6734
        } elsif (/^--PreserveSymlink/i) {       # Preserve symlink to local file
6735
            $preserveSymlink = 1;
6736
 
227 dpurdie 6737
        } elsif ( /^--DirTree=(.*)/ ) {
6738
            Error("DirTree. Multiple directories not allowed.") if ( $dir_tree );
4163 dpurdie 6739
            $dir_tree =  $1;
4257 dpurdie 6740
            Error("DirTree. No path specified") unless ( defined($dir_tree) && $dir_tree ne "" );
227 dpurdie 6741
 
4163 dpurdie 6742
            # Prevent the user from escaping from the current directory
6743
            Error("DirTree. Absolute paths are not allowed",
6744
                  "Directory: $dir_tree") if ( $dir_tree =~ m~^/~ || $dir_tree =~ m~^.\:~ );
6745
 
6746
            #
6747
            #   Convert the relative path to one that is truely relative to the current
6748
            #   directory. This may occur when the user uses $ProjectBase
6749
            #
4257 dpurdie 6750
            my $abs_dir_tree = AbsPath($dir_tree);
6751
            $dir_tree = RelPath($abs_dir_tree);
6752
 
6753
            #
6754
            #   Ensure that the user is not trying to escape the package
4265 dpurdie 6755
            #   Don't allow the user to attempt to package the entire package either
4257 dpurdie 6756
            #
6757
            #   Calculate the relative path from $ProjectBase to the target directory
6758
            #   It must not be above the $ProjectBase 
6759
            #
4265 dpurdie 6760
            if ( $dir_tree =~ m~^\.\.~)
6761
            {
6762
                my $dirFromBase = RelPath($abs_dir_tree, AbsPath($ProjectBase));
6763
                Error("DirTree cannot extend outside current package.",
6764
                      "Directory: $dirFromBase") if ( $dirFromBase =~ m~\.\.~ );
6765
                Error("DirTree cannot package entire package.",
6766
                    "Directory: $dirFromBase") if ( $dirFromBase eq '.' );
6767
            }
4257 dpurdie 6768
 
4163 dpurdie 6769
            Debug2( "PackageFile. DirTree: $dir_tree" );
6770
 
227 dpurdie 6771
            Error("DirTree. Directory not found",
6772
                  "Directory: $dir_tree") unless  ( -d $dir_tree );
6773
 
4257 dpurdie 6774
            # If packaging a parent directory then force dot_stripping of the base directory
6775
            # strip_base will have precedence if both are active
6776
            if ( $dir_tree =~ m~\.\.~ )
6777
            {
6778
                $dir_tree =~ m~(\.\./)+~;
6779
                $strip_dots = length($1);
6780
            }
6781
 
227 dpurdie 6782
        } elsif ( /^--FilterOut=(.*)/ ) {
6783
            push @dir_tree_exclude, $1;
6784
 
6785
        } elsif ( /^--FilterIn=(.*)/ ) {
6786
            push @dir_tree_include, $1;
6787
 
6788
        } elsif ( /^--StripDir/ ) {
341 dpurdie 6789
            $strip_base = 1;
227 dpurdie 6790
 
335 dpurdie 6791
        } elsif ( m/^--Recurse/ ) {
6792
            $recurse = 1;
6793
 
6794
        } elsif ( m/^--NoRecurse/ ) {
6795
            $recurse = 0;
6796
 
227 dpurdie 6797
        } elsif (/^--(.*)/) {
6798
            Message( "PackageFile: unknown option $_ -- ignored\n" );
6799
        }
6800
    }
6801
 
6802
 
6803
    #.. DirTree expansion
6804
    #   Note: Uses REs, not simple globs
6805
    #         Use JatsLocateFiles to do the hard work
6806
    if ( $dir_tree )
6807
    {
335 dpurdie 6808
        my $search = JatsLocateFiles->new('FullPath' );
6809
        $search->recurse($recurse);
227 dpurdie 6810
        $search->filter_in_re ( $_ ) foreach ( @dir_tree_include );
6811
        $search->filter_out_re( $_ ) foreach ( @dir_tree_exclude );
1431 dpurdie 6812
        $search->filter_out_re( '/\.svn/' );
5848 dpurdie 6813
        $search->filter_out_re( '/\.git/' );
227 dpurdie 6814
        @elements = $search->search ( $dir_tree );
4257 dpurdie 6815
        if ($strip_base){
6816
            $strip_base = length( $dir_tree ) if ( $strip_base );
6817
        } elsif ($strip_dots) {
6818
            $strip_base = $strip_dots;
6819
        }
6403 dpurdie 6820
    } else {
6821
        $strip_base = 0;
227 dpurdie 6822
    }
6823
 
6824
#.. Files
6825
#
285 dpurdie 6826
    foreach ( @elements )
227 dpurdie 6827
    {
6828
        my %package_entry;
299 dpurdie 6829
        $name = $_;
6133 dpurdie 6830
        my $symlink;
299 dpurdie 6831
 
227 dpurdie 6832
        #
299 dpurdie 6833
        #   Trap special files
6834
        #       DPACKAGE - but only if we have a DPackageLibrary directive
6835
        #                  in the same makefile.
6836
        #
6837
        if ( m~^DPACKAGE$~ && $DPackageDirective ) {
6838
            $name = 'DPACKAGE.' . $::GBE_MACHTYPE;
6839
        }
6840
 
227 dpurdie 6841
        if ( ! /^--(.*)/ )
6842
        {
6843
            $basename = StripDir( $name );
335 dpurdie 6844
            if ( !($srcfile = $SRCS{ $basename }) ) {
6845
                $srcfile = $name;
6846
            }
6847
 
227 dpurdie 6848
            if ( $full )
6849
            {
335 dpurdie 6850
                my $subdir = StripFileExt($srcfile);
6851
                $subdir = $1
6852
                    if ( $subdir =~ m~^$ProjectBase/(.*)~ );
6853
                $dir .= '/' . $subdir;
6854
                $dir =~ s~//~/~g;
6855
                $dir =~ s~/./~/~g;
6856
                $dir =~ s~/$~~g;
6857
                $name = $basename;
227 dpurdie 6858
            }
6859
 
6276 dpurdie 6860
            $name = StripPath($name, $strip) if ($strip);
227 dpurdie 6861
 
341 dpurdie 6862
            if ( $strip_base )
6863
            {
6864
                $name = substr $name, $strip_base;
6865
                $name =~ s~^/~~;
6866
            }
6867
 
227 dpurdie 6868
            $dir =~ s~//~/~g;
6869
            $dir =~ s~/$~~;
6870
 
6871
            #
6133 dpurdie 6872
            #   Preserve Symlink
6873
            #
6874
            if ($preserveSymlink && -l $srcfile)
6875
            {
6876
                $symlink = 1;
6877
            }
6878
 
6879
            #
227 dpurdie 6880
            #   Sanity test the source filename
6881
            #   User may have misused an option
6882
            #
6387 dpurdie 6883
            if ( !$dir_tree && ( ( $srcfile =~ m/=/ ) || ( $srcfile =~ m/^-/ ) || ( $srcfile =~ m~/-~ ))  )
227 dpurdie 6884
            {
6885
               Warning ("PackageFile: Suspect source filename: $srcfile");
6886
            }
6887
 
6888
            Debug( "PackageFile( $dir/$name, " .
6889
                "src: $srcfile, dest: $dir, dist: $dist, exe: $exefile )" );
6890
 
6891
            $package_entry{'src'} = $srcfile;
6892
            $package_entry{'dir'} = StripFileExt( "$dir/$name" );
6893
            $package_entry{'set'} = $dist;
6894
            $package_entry{'exe'} = $exefile if $exefile;
6895
            $package_entry{'type'} = $type if ( $type );
6133 dpurdie 6896
            $package_entry{'symlink'} = 1 if ( $symlink );
227 dpurdie 6897
 
6898
            $PACKAGE_FILES{ "$dir/$name" } = {%package_entry};
6899
        }
6900
    }
6901
}
6902
 
6903
sub PackageHdr
6904
{
6905
    my( $platforms, @elements ) = @_;
335 dpurdie 6906
    my( $base, $dir, $full, $path, $dist, $strip );
227 dpurdie 6907
    my( $name, $basename, $len, $srcfile );
6908
 
6909
    Debug2( "PackageHdr($platforms, @elements)" );
6910
 
6911
    return if ( !$ScmPackage );                 # Packaging enabled ?
6912
    return if ( ! ActivePlatform($platforms) );
6913
 
6914
#.. Arguments
6915
#
6916
    $dist = "ALL";                                  # Default set (ALL)
6917
    $base = $PackageInfo{'Hdr'}{'PBase'};           # Base of target
6918
    $dir = $base . $PackageInfo{'Hdr'}{'Dir'};      # Installation path (default)
335 dpurdie 6919
    $full = 0;
227 dpurdie 6920
    $strip = 0;
6921
 
285 dpurdie 6922
    foreach ( @elements )
227 dpurdie 6923
    {
6924
        my $rv = __TargetDir($T_PKG, $base, $_, \$dir);
6925
        next if ( $rv == 1 );
6926
        return if ( $rv == 2 );
6927
 
6928
        if (/^--Full/) {                        # Using full (resolved) path
6929
            $full = 1;
6930
 
6931
        } elsif (/^--Set=(.*)/) {               # Distribution set
6932
            $dist = "$1";
6933
 
6934
        } elsif (/^--Package$/) {               # Package .. call by InstallHdr
6935
        } elsif (/^--Package=(.*)/) {
6936
            $dist = "$1";
6937
 
6938
        } elsif (/^--Strip$/) {                 # Strip path from source files
6276 dpurdie 6939
            $strip = -1;
227 dpurdie 6940
 
6276 dpurdie 6941
        } elsif (/^--Strip=(\d+)$/) {           # Strip some f the path from source files
6942
            $strip = $1;
6943
 
227 dpurdie 6944
        } elsif (/^--(.*)/) {
6945
            Message( "PackageHdr: unknown option $_ -- ignored\n" );
6946
        }
6947
    }
6948
 
6949
#.. Files
6950
#
285 dpurdie 6951
    foreach ( @elements )
227 dpurdie 6952
    {
6953
        my %package_entry;
6954
        if ( ! /^--(.*)/ )
6955
        {
5991 dpurdie 6956
            $name = $_;
227 dpurdie 6957
            $basename = StripDir( $name );
335 dpurdie 6958
            if ( !($srcfile = $SRCS{ $basename }) ) {
6959
                $srcfile = $name;
6960
            }
6961
 
227 dpurdie 6962
            if ( $full )
6963
            {
335 dpurdie 6964
                my $subdir = StripFileExt($srcfile);
6965
                $subdir = $1
6966
                    if ( $subdir =~ m~^$ProjectBase/(.*)~ );
6967
                $dir .= '/' . $subdir;
6968
                $dir =~ s~//~/~g;
6969
                $dir =~ s~/./~/~g;
6970
                $dir =~ s~/$~~g;
6971
                $name = $basename;
227 dpurdie 6972
            }
6973
 
6276 dpurdie 6974
            $name = StripPath($name, $strip) if ($strip);
227 dpurdie 6975
 
6976
            Debug( "PackageHdr( $dir/$name, " .
6977
                "src: $srcfile, dest: $dir, dist: $dist )" );
6978
 
6979
            $package_entry{'src'} = $srcfile;
6980
            $package_entry{'dir'} = StripFileExt( "$dir/$name" );
6981
            $package_entry{'set'} = $dist;
6982
 
6983
            $PACKAGE_HDRS{ "$dir/$name" } = {%package_entry};
6984
        }
6985
    }
6986
}
6987
 
6988
 
6989
sub PackageLib
6990
{
6991
    my( $platforms, @elements ) = @_;
6992
    my( $base, $dir, $dist, $type );
6993
    my( $lib, $org_lib, %extras, $strip );
6994
 
6995
    Debug2( "PackageLib($platforms, @elements)" );
6996
 
6997
    return if ( !$ScmPackage );                 # Packaging enabled ?
6998
    return if ( ! ActivePlatform($platforms) );
6999
 
7000
#.. Arguments
7001
#
7002
    $dist = "ALL";                              # Default set (ALL)
7003
    $base = $PackageInfo{'Lib'}{'PBase'};       # Base of target
7004
    $dir = $base . $PackageInfo{'Lib'}{'Dir'};  # Installation path (default)
7005
    $type = "";
7006
 
285 dpurdie 7007
    foreach ( @elements )
227 dpurdie 7008
    {
7009
                                                # Standard targets
7010
        my $rv = __TargetDir($T_PKG, $base, $_, \$dir, \$type);
7011
        next if ( $rv == 1 );
7012
        return if ( $rv == 2 );
7013
 
7014
        if (/^--Set=(.*)/) {                    # Distribution set(s)
7015
            $dist = "$1";
7016
 
7017
        } elsif (/^--Package$/) {               # Package .. call by PackageLib
7018
        } elsif (/^--Package=(.*)/) {
7019
            $dist = "$1";
7020
 
7021
        } elsif (/^--Extras=(.*)/) {            # Extras=[none, .. ,all]
7022
            foreach my $elem ( split( ',', $1 ) )
7023
            {
7024
                Error ("PackageLib: Unknown Extras mode: $elem")
7025
                    unless ( grep m/$elem/, qw(none stub map lint debug all) );
7026
                $extras{$elem} = 1;
7027
            }
7028
            %extras = () if ( $extras{'all'} );
7029
 
7030
        } elsif (/^--Strip$/) {                 # Strip path from source files
6276 dpurdie 7031
            $strip = -1;
227 dpurdie 7032
 
6276 dpurdie 7033
        } elsif (/^--Strip=(\d+)$/) {           # Strip some f the path from source files
7034
            $strip = $1;
7035
 
227 dpurdie 7036
        } elsif (/^--(.*)/) {
7037
            Message( "PackageLib: unknown option $_ -- ignored\n" );
7038
        }
7039
    }
7040
 
7041
#.. Files
7042
#
285 dpurdie 7043
    foreach ( @elements )
227 dpurdie 7044
    {
7045
        my %package_entry;
7046
        if ( ! /^--(.*)/ )
7047
        {
6276 dpurdie 7048
            $_ = StripPath($_, $strip) if ($strip);
227 dpurdie 7049
 
7050
            $org_lib = $_;                      # Original name
7051
            if ( $ScmTargetHost eq "Unix" ) {
7052
                $lib = "lib$_";                 # Prefix "lib" ....
7053
                $lib =~ s/^liblib/lib/;         # @LIBS already has lib added
7054
            } else {
7055
                $lib = $_;
7056
            }
7057
 
289 dpurdie 7058
            if (  my $libp = $SHLIBS->Get($lib) )
227 dpurdie 7059
            {
7060
                Debug( "PackageLib( $dir/$lib\$(GBE_TYPE).$::so, " .
7061
                    "src: \$(LIBDIR)/$lib\$(GBE_TYPE).$::so, dest: $dir, dist: $dist, type: $type )" );
7062
 
7063
                #
7064
                #   Create a "placekeeper" entry within $PACKAGE_SHLIBS
7065
                #   The exact format of the name of the shared library is
7066
                #   toolset specific. Create an entry to allow the toolset
7067
                #   to extend the packaging information when the shared library
7068
                #   recipe is constructed.
7069
                #
7070
                #
289 dpurdie 7071
                my $ver = $libp->{ VERSION };
227 dpurdie 7072
                my $name = "$dir/$lib.$ver.PlaceKeeper";
7073
 
7074
                $package_entry{'placekeeper'} = 1;
7075
                $package_entry{'version'} = $ver;
7076
                $package_entry{'lib'} = $lib;
7077
                $package_entry{'dir'} = $dir;
7078
                $package_entry{'set'} = $dist;
7079
                $package_entry{'type'} = $type if ( $type );
7080
                $package_entry{'extras'} = {%extras} if ( scalar %extras );
289 dpurdie 7081
 
7082
                push @{$SHLIB_PKG{$lib}}, $name;
227 dpurdie 7083
                $PACKAGE_SHLIBS{$name} = {%package_entry};
7084
            }
7085
 
289 dpurdie 7086
            #
7087
            #   Clean up the package_entry
7088
            #   Insert common items
7089
            #
7090
            %package_entry = ();
7091
            $package_entry{'lib'} = $lib;
7092
            $package_entry{'dir'} = $dir;
7093
            $package_entry{'set'} = $dist;
7094
            $package_entry{'extras'} = {%extras} if ( scalar %extras );
7095
            $package_entry{'type'} = $type if ( $type );
7096
 
227 dpurdie 7097
            if ( my $libfile = $SRCS{$org_lib} )
7098
            {
7099
                #
7100
                #   Allow the user to package a sourced file as a library
7101
                #   But must be the un-massaged name of the file.
7102
                #
5991 dpurdie 7103
                $package_entry{'dst'} = "$dir/$org_lib";
7104
                $package_entry{'src'} = $libfile;
289 dpurdie 7105
            }
7106
            elsif ( $LIBS->Get($lib) )
7107
            {
7108
                #
7109
                #   Package up a library known to the makefile
7110
                #
7111
                my $libp = $LIBS->Get($lib);
227 dpurdie 7112
 
289 dpurdie 7113
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
7114
                $package_entry{'src'}    = $libp->getPath();
227 dpurdie 7115
            }
289 dpurdie 7116
            elsif ( ! $SHLIBS->Get($lib) )
227 dpurdie 7117
            {
289 dpurdie 7118
                #
7119
                #   Not a known shared lib
7120
                #   Not a known static lib
7121
                #   Not a 'sourced' file
7122
                #   Assume the a static library has magically appeared
7123
                #   in the standard LIB directory. May have been placed there
7124
                #   by a 'rule'
7125
                #
7126
                my $libp = $LIBS->New($lib);
227 dpurdie 7127
 
289 dpurdie 7128
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
7129
                $package_entry{'src'}    = $libp->getPath();
7130
            }
227 dpurdie 7131
 
289 dpurdie 7132
            #
7133
            #   Add entry to various lists if required
7134
            #
7135
            PackageLib_AddEntry ('PackageLib', \%LIB_PKG, \%PACKAGE_LIBS, \%package_entry )
7136
                if ( exists $package_entry{'dst'} );
227 dpurdie 7137
        }
7138
    }
7139
}
7140
 
289 dpurdie 7141
#-------------------------------------------------------------------------------
7142
# Function        : PackageLib_AddEntry
7143
#
7144
# Description     : Helper function to add a package entry
7145
#                   to the lists
7146
#
7147
# Inputs          : $directive          - Directive name
7148
#                   $pList              - Ref to array list to maintain
7149
#                   $pHash              - Ref to hash to maintain
7150
#                   $pData              - Packaging Data
7151
#                                         Must Take a copy.
7152
#
7153
# Returns         : 
7154
#
227 dpurdie 7155
 
289 dpurdie 7156
sub PackageLib_AddEntry
7157
{
7158
    my ($directive, $pList, $pHash, $pData) = @_;
7159
 
7160
    my $lib = delete $pData->{'lib'};
7161
    my $dst = delete $pData->{'dst'};
7162
 
7163
    Error ("INTERNAL PackageLib_AddEntry: lib or dst not defined")
7164
        unless ( $lib && $dst );
7165
 
7166
    Debug( "$directive( ",$dst,
7167
            ", src: " ,$pData->{'src'},
7168
            ", dest: ",$pData->{'dir'},
7169
            ", dist: ",$pData->{'set'},
7170
            ", type: ",$pData->{'type'} || '',
7171
            " )" );
7172
 
7173
    push @{$pList->{$lib }}, $dst;
7174
    $pHash->{$dst } = {%$pData};
7175
}
7176
 
7177
 
227 dpurdie 7178
sub PackageProg
7179
{
7180
    my( $platforms, @elements ) = @_;
7181
    my( $base, $dir, $dist, $type );
7182
    my( $prog, %extras, $strip );
7183
 
7184
    Debug2( "PackageProg($platforms, @elements)" );
7185
 
7186
    return if ( !$ScmPackage );                 # Packaging enabled ?
7187
    return if ( ! ActivePlatform($platforms) );
7188
 
7189
#.. Arguments
7190
#
7191
    $dist = "ALL";                              # Default set (ALL)
7192
    $base = $PackageInfo{'Prog'}{'PBase'};       # Base of target
7193
    $dir = $base . $PackageInfo{'Prog'}{'Dir'};  # Installation path (default)
7194
    $type = "";
7195
 
285 dpurdie 7196
    foreach ( @elements )
227 dpurdie 7197
    {
7198
                                                # Standard targets
7199
        my $rv = __TargetDir($T_PKG|$T_TYPE, $base, $_, \$dir, \$type);
7200
        next if ( $rv == 1 );
7201
        return if ( $rv == 2 );
7202
 
7203
        if (/^--Set=(.*)/) {                    # Distribution set(s)
7204
            $dist = "$1";
7205
 
7206
        } elsif (/^--Package$/) {               # Package .. call by PackageLib
7207
        } elsif (/^--Package=(.*)/) {
7208
            $dist = "$1";
7209
 
7210
        } elsif (/^--Tool(([=])(.*))?$/) {      # Allow Tool and Tool=xxx specfic target
7211
            my $path = ( defined( $3) ) ? "/$3" : "";
261 dpurdie 7212
            $dir = "\$(PKGDIR)$path/\$(GBE_HOSTMACH)";
227 dpurdie 7213
 
7214
        } elsif (/^--Extras=(.*)/) {            # Extras=[none, .. ,all]
7215
            foreach my $elem ( split( ',', $1 ) )
7216
            {
7217
                Error ("PackageLib: Unknown Extras mode: $elem")
7218
                    unless ( grep m/$elem/, qw(none stub map lint debug all) );
7219
                $extras{$elem} = 1;
7220
            }
7221
            %extras = () if ( $extras{'all'} );
7222
 
7223
        } elsif (/^--Strip$/) {                 # Strip path from source files
6276 dpurdie 7224
            $strip = -1;
227 dpurdie 7225
 
6276 dpurdie 7226
        } elsif (/^--Strip=(\d+)$/) {           # Strip some f the path from source files
7227
            $strip = $1;
7228
 
227 dpurdie 7229
        } elsif (/^--(.*)/) {
7230
            Message( "PackageProg: unknown option $_ -- ignored\n" );
7231
        }
7232
    }
7233
 
7234
#.. Files
7235
#
285 dpurdie 7236
    foreach ( @elements )
227 dpurdie 7237
    {
7238
        my %package_entry;
7239
        if ( m~descpkg~ ) {
7240
            PackageFile($platforms, @elements);
7241
 
7242
        } elsif ( ! /^--(.*)/ ) {
6276 dpurdie 7243
            $_ = StripPath($_, $strip) if ($strip);
227 dpurdie 7244
 
7245
            my $ext = "";
7246
            $prog = $_;
7247
 
7248
            #
7249
            #   If the named target is a program then append the correct
7250
            #   extension. Otherwise assume that the target is either a script
7251
            #   or a some other file - and don't append an extension
7252
            #
7253
            #   A program may not have any object files, only libraries
7254
            #
7255
            $ext = $::exe
289 dpurdie 7256
                if ( $PROGS->Get($prog) );
227 dpurdie 7257
 
7258
            #
7259
            #   A "file" that is specified with a "Src" directive may be
7260
            #   installed as though it were a program
7261
            #
7262
            my $progfile;
387 dpurdie 7263
            if ( $progfile = $SRCS{$prog} )
7264
            {
5991 dpurdie 7265
                $progfile = $progfile;
7266
                $prog = $prog;
387 dpurdie 7267
            }
7268
            else
7269
            {
7270
                $progfile = "\$(BINDIR)/$prog$ext";
7271
            }
227 dpurdie 7272
 
7273
            Debug( "PackageProg( $dir/$prog$ext, " .
7274
                 "src: $progfile, dest: $dir, dist: $dist, type: $type )" );
7275
 
7276
            my $target = "$dir/$prog$ext";
7277
            push @{$PROG_PKG{$prog}}, $target;
7278
 
7279
            $package_entry{'src'}   = $progfile;
7280
            $package_entry{'dir'}   = $dir;
7281
            $package_entry{'set'}   = $dist;
7282
            $package_entry{'extras'}= {%extras} if ( scalar %extras );
7283
            $package_entry{'type'}  = $type if ( $type );
7284
 
7285
            $PACKAGE_PROGS{$target} = {%package_entry};
7286
        }
7287
    }
7288
}
7289
 
7290
 
7291
sub PackageJar
7292
{
7293
    my( $platforms, @elements ) = @_;
7294
    my( $base, $dir, $dist, $type );
7295
    my( $jar );
7296
 
7297
    Debug2( "PackageJar($platforms, @elements)" );
7298
 
7299
    return if ( !$ScmPackage );                 # Packaging enabled ?
7300
    return if ( ! ActivePlatform($platforms) );
7301
 
7302
#.. Arguments
7303
#
7304
    $dist = "ALL";                              # Default set (ALL)
7305
    $base = $PackageInfo{'Jar'}{'PBase'};       # Base of target
7306
    $dir = $base . $PackageInfo{'Jar'}{'Dir'};  # Installation path (default)
7307
    $type = "";
7308
 
285 dpurdie 7309
    foreach ( @elements )
227 dpurdie 7310
    {
7311
                                                # Standard targets
7312
        my $rv = __TargetDir($T_PKG, $base, $_, \$dir, \$type);
7313
        next if ( $rv == 1 );
7314
        return if ( $rv == 2 );
7315
 
7316
        if (/^--Set=(.*)/) {                    # Distribution set(s)
7317
            $dist = "$1";
7318
 
7319
        } elsif (/^--Package$/) {               # Package .. call by InstallJar
7320
        } elsif (/^--Package=(.*)/) {
7321
            $dist = "$1";
7322
 
7323
        } elsif (/^--(.*)/) {
7324
            Message( "PackageJar: unknown option $_ -- ignored\n" );
7325
        }
7326
    }
7327
 
7328
#.. Files
7329
#
285 dpurdie 7330
    foreach ( @elements )
227 dpurdie 7331
    {
7332
        my %package_entry;
7333
        if ( ! /^--(.*)/ )
7334
        {
7335
            $jar = $_;
7336
            my $src;
7337
            my $dest;
7338
 
7339
            if ( $JAR_FILES{$jar} )
7340
            {
7341
                $src = $JAR_FILES{$jar};
7342
                $dest = $jar;
7343
            }
7344
            else
7345
            {
7346
                $src = "\$(CLSDIR)/$jar\$(GBE_TYPE).jar";
7347
                $dest = "$jar\$(GBE_TYPE).jar";
7348
            }
7349
 
7350
 
7351
            Debug( "PackageJar( $dir/$dest, " .
7352
                "src: $src, dest: $dir, dist: $dist, type: $type )" );
7353
 
7354
            $package_entry{'src'} = $src;;
7355
            $package_entry{'dir'} = $dir;
7356
            $package_entry{'set'} = $dist;
7357
            $package_entry{'type'} = $type if ( $type );
7358
 
7359
            $PACKAGE_CLSS{ "$dir/$dest" } = {%package_entry};
7360
 
7361
        }
7362
    }
7363
}
7364
 
7365
#-------------------------------------------------------------------------------
7366
# Function        : PackageProgAddFiles         - Add files to a PackageProg
7367
#                   PackageLibAddFiles          - Add files to a PackageLib
7368
#                   PackageShlibAddFiles        - Add files to a PackageLib (shared lib)
7369
#                   PackageShlibAddLibFiles     - Add files to a PackageLib (shared lib)
7370
#                                                 Add static library files
7371
#
7372
# Description     : Add files to a Program package or installation
7373
#                   For use by Tool sets to allow additional files to be
7374
#                   packaged with a program.
7375
#
7376
#                   The files are only added if the named program is being
7377
#                   packaged and/or installed.
7378
#
7379
#
7380
# Inputs          : prog        - program identifier
7381
#                   file        - A file to be add
7382
#                   args        - Additional packageing arguments
7383
#
7384
# Returns         : Nothing
7385
#
7386
 
7387
sub PackageProgAddFiles
7388
{
7389
    Debug("PackageProgAddFiles");
7390
 
7391
    PackageAddFiles ( \%PACKAGE_PROGS, \%PACKAGE_PROGS, \%PROG_PKG, @_);
7392
    PackageAddFiles ( \%INSTALL_PROGS, \%INSTALL_PROGS, \%PROG_INS, @_);
7393
}
7394
 
7395
sub PackageLibAddFiles
7396
{
7397
    Debug("PackageLibAddFiles");
7398
 
7399
    PackageAddFiles ( \%PACKAGE_LIBS, \%PACKAGE_LIBS, \%LIB_PKG, @_ );
7400
    PackageAddFiles ( \%INSTALL_LIBS, \%INSTALL_LIBS, \%LIB_INS, @_ );
7401
}
7402
 
7403
sub PackageShlibAddFiles
7404
{
7405
    my ($prog, $file, @args) = @_;
7406
    Debug("PackageShlibAddFiles");
7407
 
7408
    PackageAddFiles ( \%INSTALL_SHLIBS, \%INSTALL_SHLIBS, \%SHLIB_INS, @_ );
7409
    PackageAddFiles ( \%PACKAGE_SHLIBS, \%PACKAGE_SHLIBS, \%SHLIB_PKG, @_ );
7410
 
7411
    #
7412
    #   These files become the target of the "make_install_shlib" operation unless:
7413
    #       Conditionally packaged files are not always created
7414
    #       RemoveOnly files are not always generated
7415
    #
7416
    my $no_add;
7417
    foreach ( @args )
7418
    {
4382 dpurdie 7419
        if ( m/^defined=/ or m/^RemoveOnly=/ or /NoTarget=/ )
227 dpurdie 7420
        {
7421
            $no_add = 1;
7422
            last;
7423
        }
7424
    }
7425
 
7426
    push (@SHLIB_TARGETS, $file ) unless $no_add;
7427
}
7428
 
7429
sub PackageShlibAddLibFiles
7430
{
7431
    Debug("PackageShlibAddLibFiles");
7432
 
7433
    PackageAddFiles ( \%PACKAGE_SHLIBS, \%PACKAGE_LIBS, \%SHLIB_PKG, @_ , 'Class=lib');
7434
    PackageAddFiles ( \%INSTALL_SHLIBS, \%INSTALL_LIBS, \%SHLIB_INS, @_ , 'Class=lib');
7435
}
7436
 
7437
#-------------------------------------------------------------------------------
7438
# Function        : PackageAddFiles
7439
#
7440
# Description     : Internal function to add files to the data structures that
7441
#                   describe a package or installation
7442
#
7443
#                   Use this function to package or install additional files with
7444
#                   the Progs and Libs
7445
#
7446
#                   ie: Add a LIB file to be packaged with a Shared Library
7447
#                   ie: Add a MAP file to be packaged with a program
7448
#
7449
# Inputs          : ref_spkg  - Reference to the hash that contains the package data
7450
#                   ref_dpkg  - Reference to the target package/install hash
7451
#                               Normally the same as ref_dpkg, but does allow
289 dpurdie 7452
#                               a static library to be added to a dynamic library
227 dpurdie 7453
#                               package.
7454
#                   ref_list  - Reference to a hash that may contain package keys to process
7455
#                   prog      - Key for index to above
7456
#                   file      - A file to be added
7457
#                   args      - Additional packaging arguments
7458
#
7459
# Returns         :
7460
#
7461
sub PackageAddFiles
7462
{
7463
    my ($ref_spkg, $ref_dpkg, $ref_list, $prog, $file, @args ) = @_;
7464
 
7465
    #
7466
    #   Process entry
7467
    #   The files may need to be added to multiple packages
7468
    #
7469
    Debug("PackageAddFiles: $file");
7470
 
7471
    return unless ( $ref_list->{$prog} );
7472
 
7473
    #
7474
    #   Parse arguments and extract the "Class=xxx" argument. This may be used
7475
    #   to limit the extra files piggybacked with the base file
7476
    #   All files without a class will be treated as base files
7477
    #
7478
    my $class;
7479
    foreach ( @args )
7480
    {
7481
        next unless ( m~^Class=(.*)$~ );
7482
        $class = $1 unless ( $1 eq 'none' );
7483
    }
7484
    Debug("PackageAddFiles: Class: ", $class || 'Default=None');
7485
 
7486
    foreach my $entry_key ( @{$ref_list->{$prog}} )
7487
    {
7488
        Debug("PackageAddFiles: Entry found: $entry_key");
7489
 
7490
        #
7491
        #   Copy of the template entry
7492
        #
7493
        my %package_entry = %{$ref_spkg->{$entry_key}};
7494
        Error ("INTERNAL: Expected entry in PACKAGE_ hash not found: $entry_key" )
7495
            unless ( %package_entry );
7496
 
7497
        #
7498
        #   Do not add the file if the user has limited the extra files added
7499
        #   to the packaging list and the current file is not in the class list
7500
        #
7501
        if ( $class && $package_entry{'extras'} )
7502
        {
7503
            next unless ( $package_entry{'extras'}{$class} );
7504
        }
7505
 
7506
        #
7507
        #   Create new entries for the file
7508
        #
7509
        $package_entry{'src'} = $file;
7510
        foreach ( @args )
7511
        {
7512
            m~^(.*)=(.*)$~;
7513
            $package_entry{$1} = $2;
7514
        }
7515
 
7516
        #
7517
        #   Clean out useless fields
7518
        #   Must remove the placekeeper marker to allow the entry to be visible
7519
        #
7520
        delete $package_entry{'placekeeper'};
7521
        delete $package_entry{'version'};
7522
        delete $package_entry{'lib'};
261 dpurdie 7523
#       delete $package_entry{'extras'};                   # Keep these
227 dpurdie 7524
        delete $package_entry{'Class'};
7525
 
7526
        #
7527
        #   Add the entry
7528
        #
7529
        #   Under some conditions is it possible to attempt to add the same named
7530
        #   file. This will result in a circular dependancy in the makefile
7531
        #
7532
        #   The condition is when merged libaries with PDBs (WINCE+WIN32) are merged
261 dpurdie 7533
        #   and the source for the merge is the "local directory.
227 dpurdie 7534
        #
7535
        #
7536
        my $dst = $package_entry{'dir'} ;
7537
        ( my $dfile = $file) =~ s~.*/~~;
7538
        Debug( "    added $dst/$dfile = $file" );
7539
 
7540
        $ref_dpkg->{"$dst/$dfile"} = {%package_entry}
7541
            unless ( "$dst/$dfile" eq "$file" );
7542
    }
7543
}
7544
 
7545
#-------------------------------------------------------------------------------
7546
# Function        : PackageProgRemoveFiles
7547
#
7548
# Description     : Flag a Packaged program to be not packaged
7549
#                   This mechanism is used to remove a program from packageing
7550
#                   under conditions where the toolset has generated a different
7551
#                   program.
7552
#
7553
#                   The entry is flagged as a placeholder
7554
#
7555
# Inputs          : prog        - Program to process
7556
#
7557
# Returns         : Nothing
7558
#
7559
sub PackageProgRemoveFiles
7560
{
7561
    my ($prog) = @_;
7562
    Verbose ("PackageProgRemoveFiles: $prog" );
7563
    return unless (exists($PROG_PKG{$prog}));
7564
 
7565
    #
7566
    #   Must lookup the TAG to locate the  required entry
7567
    #
7568
    my $tag = $PROG_PKG{$prog};
7569
    foreach my $entry ( @$tag )
7570
    {
7571
        Verbose("Do not package: $entry");
7572
        if ( exists $PACKAGE_PROGS{$entry} )
7573
        {
7574
            $PACKAGE_PROGS{$entry}{placekeeper} = 'ProgRemoved';
7575
        }
7576
    }
7577
}
7578
 
7579
#-------------------------------------------------------------------------------
7580
# Function        : DPackageLibrary
7581
#
7582
# Description     : Collect information to allow the generation of a DPACKAGE
299 dpurdie 7583
#                   file. This directive allows the generation of "Library"
227 dpurdie 7584
#                   directives within the final DPACKAGE
7585
#
7586
#                   This directive does generate the DPACKAGE file.
7587
#
7588
# Inputs          : platform    - This does not need to be an active platform
7589
#                                 it is simply passed to the DPACKAGE builder
7590
#
7591
#                   using       - The "using" target
7592
#
7593
#                   ...         - Arguments for the Library directive
7594
#
7595
# Returns         :
7596
#
7597
sub DPackageLibrary
7598
{
7599
    JatsDPackage::DPackageAdd ( @_ );
299 dpurdie 7600
    $DPackageDirective = 1;
227 dpurdie 7601
}
7602
 
7603
#-------------------------------------------------------------------------------
7604
# Function        : SetProjectBase
7605
#
7606
# Description     : Allows the user to modify the build's concept of the Base
7607
#                   of the build. By default the base is the same directory as
7608
#                   the build.pl file, but in some contorted environments it
7609
#                   is a great deal simpler to specify a differnt base.
7610
#
7611
#                   The use may use the variable $ProjectBase as a path
7612
#                   specifier to locate files and directories
7613
#
7614
#                   Both absolute and relative paths are supported
7615
#                   If the initial value of $ProjectBase is relative then
7616
#                   it will be maintained as a relative path.
7617
#
7618
# Inputs          : elements        path to base
7619
#                                   These may be:
7620
#                                       --Up=xx
7621
#                                       name
7622
#
7623
# Returns         : Nothing
7624
#
7625
 
7626
#
7627
#   Allow the user to modify the project base variable
7628
#
7629
sub SetProjectBase
7630
{
7631
    my $rip = 0;
7632
    my $path = "";
7633
    my $is_relative;
7634
 
7635
    Debug("ProjectBase Initial: $ProjectBase, @_");
7636
 
7637
    #
7638
    #   Ensure that the ProjectBase is in a "nice" form
7639
    #   1) No /./ bits
7640
    #   2) No trailing /
7641
    #   3) Not equal to .
7642
    #   4) No training /.
7643
    #   5) No //
7644
    #
7645
    $ProjectBase =~ s~/\./~/~g;
7646
    $ProjectBase =~ s~/$~~g;
7647
    $ProjectBase =~ s~^\.$~~g;
7648
    $ProjectBase =~ s~/\.$~~g;
7649
    $ProjectBase =~ s~//$~/~g;
7650
 
7651
    #
7652
    #   ProjectBase may be absolute or relative
7653
    #   Determine this before we mess with it
7654
    #
7655
    $is_relative = ($ProjectBase !~ m~^/~);
7656
 
7657
    #
7658
    #   Process each argument
7659
    #
7660
    foreach ( @_ )
7661
    {
7662
        if ( /^--Up=([0-9]*)/ ) {
7663
            $rip = $1;
7664
        } elsif ( /^--/ ) {
7665
            Warning( "SetProjectBase - unknown option \"$_\" - ignored" );
7666
        } else {
7667
            $path = $_;
7668
        }
7669
    }
7670
 
7671
    #
7672
    #   Process the UP requests
7673
    #   If the tail directory is a ".." then up is done by adding another ".."
7674
    #   If the tail directory is not a "..", then up is done by removing it
7675
    #
7676
    #   If we go past the start of the path then simply add ".."
7677
    #
7678
    while ( $rip-- > 0 )
7679
    {
7680
        Debug2("ProjectBase: $ProjectBase, Up: $rip, IsRel: $is_relative");
7681
 
7682
        #
7683
        #   If ending in a /.. or is exactly equal to ..
7684
        #   Then its a dot-dot and the way to go UP is to append another ..
7685
        #
7686
        if ( $ProjectBase =~ m~(/\.\.$)|(^\.\.$)~ )
7687
        {
7688
            $ProjectBase .= '/..';
7689
        }
7690
        else
7691
        {
7692
            #
7693
            #   Not a dot-dot ending
7694
            #   Attempt to remove the last directory of the form
7695
            #       /xxxxx
7696
            #   Where the leading / is optional
7697
            #   Note: Must have at least one character in the dirname
7698
            #         This prevents leading / from matching - which is needed
7699
            #
7700
            unless ($ProjectBase =~ s~/?[^/]+$~~)
7701
            {
7702
                #
7703
                #   Removal failed
7704
                #   If a relative path then we can keep on going up,
7705
                #   otherwise we are dead.
7706
                #
7707
                Error ("ProjectBase outside project") unless ($is_relative);
7708
                $ProjectBase = '..';
7709
            }
7710
 
7711
            #
7712
            #   Ensure that the leading / in an absolute path is not deleted
7713
            #
7714
            $ProjectBase = '/'
7715
                unless ( $is_relative || $ProjectBase );
7716
        }
7717
    }
7718
 
7719
    #
7720
    #   Append the user path
7721
    #
7722
    $ProjectBase .= '/' . $path if ( $path );
7723
    $ProjectBase = '.' unless ( $ProjectBase );
7724
    Debug("ProjectBase set to : $ProjectBase");
7725
 
7726
    #
7727
    #   Once upon a time I tried to convert paths that contained spaces into
7728
    #   short (mangled) names. This was not sucessful because:
7729
    #       1) Clearcase dynamic views do not support name mangling
7730
    #       2) Samba file system does not appear to support name mangling
7731
    #
7732
    #   Spaces in paths are not good for MAKE
7733
    #   Now I simple generate a message
7734
    #
7735
    Warning( "ProjectBase contains a space: $ProjectBase")
7736
        if ( $ProjectBase =~ m/ / );
7737
 
7738
    #
7739
    #   Sanity check
7740
    #   Absolute paths can be checked easily
7741
    #   Checking of relative paths does not appear to work
7742
    #   When I tested it chdir, opendir and stat would limit themselves
7743
    #   and drop into the root directory ( under windows )
7744
    #
7745
    #   Solution: Check the path does not extend beyond the file tree
7746
    #
7747
    my $distance = 1;
7748
    my $tpath = $ProjectBase;
7749
 
7750
    if ( $is_relative && $tpath ne '.' )
7751
    {
7752
        #
7753
        #   Build up the complete pathname by merging it with the
7754
        #   current directory. Then clean it up.
7755
        #
7756
        $tpath = $::Cwd . '/' . $ProjectBase;
7757
 
7758
        #
7759
        #   Scan the list of diretories and count the distance from the root
7760
        #   This should not be greater than zero for sanity
7761
        #   Note: Get an empty elemement from the split due to
7762
        #         the leading / of the ABS path
7763
        #
7764
        $distance = 0;
7765
        foreach (  split ('/', $tpath) )
7766
        {
7767
            if ( m~\.\.~ )
7768
            {
7769
                $distance--;
7770
            }
7771
            else
7772
            {
7773
                $distance++;
7774
            }
7775
        }
7776
    }
7777
 
7778
    #
7779
    #   Warn if not a valid directory
7780
    #
7781
    Warning( "ProjectBase is not a directory: $ProjectBase")
7782
        if ( $distance <= 0 || !  -d $tpath  );
7783
 
7784
    #
7785
    #   $ProjectBase will always be a valid directory, but if its the top
7786
    #   directory (/) and it is added to a path we will get //path
7787
    #   This is not good, so // will be removed later in the AddIncDir and
7788
    #   AddSrcDir commands where $ProjectBase is really used.
7789
    #
7790
    #   Alternatively we could set $ProjectBase to an empty string, but then
7791
    #   this may be confused with an empty relative directory
7792
    #
7793
    Debug("ProjectBase Final  : $ProjectBase");
7794
}
7795
 
7796
#-------------------------------------------------------------------------------
7797
# Function        : DeployPackage
7798
#
7799
# Description     : Generate a deployed package
7800
#                   This is a gateway to a different packaging system
7801
#
7802
#                  DeployPackage and PackageXxxxx directives are mutually
7803
#                  exclusive. Only one person can play in the package area.
7804
#
7805
# Inputs          : Platform Specifier
7806
#                   Package Name    (Optional)
7807
#                   Options
7808
#                       --Name : Base name of the package. The default is taken
7809
#                                from the build.pl file
7810
#                       --Dir  : Package directory
7811
#                                The default is based on the package name
7812
#
7813
# Returns         :
7814
#
7815
sub DeployPackage
7816
{
7817
    my( $platforms, @elements ) = @_;
7818
    my $dir;
7819
    my $name;
7820
 
267 dpurdie 7821
    #
7822
    #   Flag that this build creates a deployable package, even if its not
7823
    #   active on this platform.
7824
    #
7825
    $DEPLOYPACKAGE = 1;
7826
 
7827
 
227 dpurdie 7828
    Debug2( "DeployPackage($platforms, @elements)" );
7829
    return if ( ! ActivePlatform($platforms) );
7830
 
7831
    #
7832
    #   Only allow one use of this directive
7833
    #
7834
    Error("DeployPackage can only be used once" ) if ( %DEPLOYPACKAGE );
267 dpurdie 7835
    $DEPLOYPACKAGE = 2;
227 dpurdie 7836
 
7837
    #
7838
    #   Ensure that the deployment file is available
7839
    #
7840
    my $command_file = $ScmDeploymentPatch ? "deploypatch.pl" : "deployfile.pl";
7841
    Error("DeployPackage: $command_file not found") unless (-f "./$command_file");
7842
    #
7843
    #   Collect arguments
7844
    #
7845
    foreach (@elements )
7846
    {
7847
        if ( m/^--Dir=(.*)/ ) {
7848
            Error ("DeployPackage: Package directory defined multiple times") if $dir;
7849
            $dir = $1;
7850
 
7851
        } elsif ( m/^--Name=(.*)/ ) {
7852
            Error ("DeployPackage: Package name defined multiple times") if $name;
7853
            $name = $1;
7854
 
7855
        } elsif ( m/^--/ ) {
7856
            Warning( "DeployPackage: Unknown option ignored: $_");
7857
 
7858
        } else {
7859
            Error ("DeployPackage: Package name defined multiple times") if $name;
7860
            $name = $_;
7861
 
7862
        }
7863
    }
7864
 
7865
    $name = $::ScmBuildPackage unless ( $name );
7866
 
7867
    #
7868
    #   Save the deployment data
7869
    #
7870
    $dir = lc($name) unless ( $dir );
7871
    $DEPLOYPACKAGE{'name'} = $name;
7872
    $DEPLOYPACKAGE{'dir'} = $dir;
7873
    $DEPLOYPACKAGE{'cmdfile'} = $command_file;
7874
 
7875
    #
7876
    #   Flag that toolset tests should be supressed
7877
    #   The Deploy world does not really use the full makefiles and if the
7878
    #   compilers are not installed will not be able to create deployment
7879
    #   packages
7880
    #
7881
    $ScmNoToolsTest = 1;
7882
}
7883
 
7884
 
7885
###############################################################################
7886
###############################################################################
7887
# Private function section.
7888
#       The following functions are used INTERNALLY by makelib.pl2.
7889
###############################################################################
7890
 
7891
###############################################################################
7892
#   A collection of functions to write to the MAKEFILE handle
7893
#
7894
#   MakeHeader          - Write a nice section header
7895
#   MakeNewLine         - Print a new line
7896
#   MakePrint           - Print a line ( without trailing \n)
7897
#   MakeQuote           - Escape \ and " character, then print a line
7898
#   MakePrintList       - Print an array
7899
#   MakeEntry           - Complex line printer
7900
#   MakePadded          - Padded line printer (internal)
7901
#   PadToPosn           - Calc space+tabs to tabstop (internal)
7902
#   MakeEntry3          - Complex Line Printer
7903
#   MakeDefEntry        - Print a definition line (Production + Debug support)
7904
#   MakeIfDefEntry      - Print ifdef entry
261 dpurdie 7905
#   MakeIfnDefEntry     - Print ifndef entry
7906
#   MakeIfZeroEntry     - Print ifeq entry
227 dpurdie 7907
#
7908
###############################################################################
7909
 
7910
sub MakeHeader
7911
{
7912
    my ($text, @rest) = @_;
7913
    my $length = length ($text);
7914
 
7915
    print MAKEFILE "\n";
7916
    print MAKEFILE "#--------- $text ", '-' x (80 - 12 - $length)  ,"\n";
7917
    print MAKEFILE "#    $_\n" foreach  ( @rest ) ;
7918
    print MAKEFILE "#\n";
7919
}
7920
 
7921
sub MakeNewLine         # Print a newline to the current 'Makefile'
7922
{
7923
    print MAKEFILE "\n";
7924
}
7925
 
7926
sub MakePrint           # Print to the current 'Makefile'
7927
{
7928
    print MAKEFILE @_
7929
        if ( defined $_[0] );
7930
}
7931
 
7932
sub MakeQuote           # Quote a makefile text line
7933
{
7934
    my( $line ) = @_;
7935
    $line =~ s/\\/\\\\/g;                       # quote all '\' characters
7936
    $line =~ s/"/\\"/g;                         # Then quote '"' characters
255 dpurdie 7937
    $line =~ s/=#/=\\#/g;                       # Then quote '=#' sequence
227 dpurdie 7938
    print MAKEFILE $line;
7939
}
7940
 
7941
sub MakePrintList
7942
{
7943
    print MAKEFILE $_ . "\n" foreach (@{$_[0]});
7944
}
7945
 
2429 dpurdie 7946
sub QuoteArray
7947
{
7948
    my $quote = "'";
7949
    if ( @_ ) {
7950
        return ($quote . join("$quote $quote", @_) . $quote);
7951
    }
7952
    return '';
7953
}
227 dpurdie 7954
 
7955
#-------------------------------------------------------------------------------
7956
# Function        : MakeEntry
7957
#
7958
# Description     : Build a entry based on the element list
7959
#                   Creates text of the form
7960
#                       $(BINDIR)/prog.exe: object1.obj \
7961
#                                           object2.obj
7962
#
7963
#
7964
# Inputs          : $prelim         - Preamble (one-off)
7965
#                   $postlim        - Postamble (one-off)
7966
#                   $prefix         - Pefix (to each element of array)
7967
#                   $postfix        - Postfix (to each element of array )
7968
#                   @elements       - Array of element to wrap
7969
#
7970
# Returns         :   1 Always
7971
#
7972
# Notes:
7973
#       The above description means that the following entry format is
7974
#       produced:
7975
#
7976
#           <preliminary><prefix><variant1><prefix><variant2>...<final>
7977
#
7978
#       With judicious use of newline and tab characters, a target
7979
#       and dependency list along with the command(s) to build the
7980
#       target can be constructed.
7981
#
7982
sub MakeEntry
7983
{
7984
    my( $prelim, $postlim, $prefix, $postfix, @elements ) = @_;
7985
 
7986
    MakePrint $prelim;
7987
    MakePrint "${prefix}${_}${postfix}" foreach ( @elements );
7988
    MakePrint $postlim if ($postlim);
7989
    return 1;
7990
}
7991
 
7992
#-------------------------------------------------------------------------------
7993
# Function        : MakePadded
7994
#
7995
# Description     : Generate aligned output of the form
7996
#                       Prefix_text           Aligned_text
7997
#                   where the aligned text is at a specified TAB boundary
7998
#
7999
# Inputs          : $align      - Tab stop (One tab = 8 chars)
8000
#                   $prefix     - Text to print before alignment occurs
8001
#                   @line       - Remainder of the line
8002
#
8003
sub MakePadded          # Print to the current 'Makefile', tab aligning
8004
{
8005
    my( $align, $prefix, @line ) = @_;
8006
 
8007
    my $strlen = length( $prefix );
8008
    my $pad = PadToPosn( $strlen, $align * 8 );
8009
 
8010
    print MAKEFILE $prefix . $pad;
8011
    print MAKEFILE @line;
8012
}
8013
 
8014
#-------------------------------------------------------------------------------
8015
# Function        : PadToPosn
8016
#
8017
# Description     : Given that we are at $startposn return a tab and space
8018
#                   string to place us at $endposn
8019
#
8020
sub PadToPosn
8021
{
8022
    my ($startposn, $endposn ) = @_;
8023
 
8024
 
8025
    #
8026
    #   Case where we are already too far into the line
8027
    #
8028
    return ( ' ' )if ( $endposn <= $startposn );
8029
 
8030
    my $tcount = 0;
8031
    my $scount = 0;
8032
 
8033
    while ( $startposn < $endposn )
8034
    {
8035
        $tcount ++;
8036
        $startposn = ($startposn >> 3) * 8 + 8;
8037
 
8038
        my $delta = $endposn - $startposn;
8039
        if ( $delta < 8 )
8040
        {
8041
            $scount = $delta;
8042
            last;
8043
        }
8044
 
8045
    }
8046
    return ( "\t" x $tcount .  ' ' x $scount );
8047
}
8048
 
8049
#-------------------------------------------------------------------------------
8050
# Function        : MakeEntry3
8051
#
8052
# Description     : Build a makefile entry based on the element list, tab aligned
8053
#                   Can creat text of the form:
8054
#                       TAG = NAME0 \       TAG : NAME0 \ 
8055
#                             NAME1               NAME1
8056
#
8057
#
8058
# Inputs          : $prelim             - Preliminary text
8059
#                   $presep             - Preliminary seperator
8060
#                   $elem_ref           - Either a single name or a reference to
8061
#                                         and array of names, or a hash.
8062
#
8063
# Returns         : Writes directly to the Makefile
8064
#
8065
sub MakeEntry3
8066
{
8067
    my( $prelim, $presep, $elem_ref ) = @_;
8068
 
8069
    #
8070
    #   The prelim may have some "\n" characters at the start
8071
    #   These simplify formatting, but mess up the nice formatting
8072
    #
8073
    if ($prelim =~ m~(^\n+)(.*)~ )
8074
    {
8075
        MakePrint $1;
8076
        $prelim = $2;
8077
    }
8078
 
8079
    #
8080
    #   Print the definition and the sep with nice padding
8081
    #
8082
    MakePadded ( 3, $prelim, $presep );
8083
    my $leadin = ' ';
8084
 
8085
    #
8086
    #   If a HASH reference then use a sorted list of keys from the hash.
8087
    #
8088
    if ( ref ($elem_ref) eq "HASH" )
8089
    {
8090
        my @hash_list;
8091
        @hash_list = sort keys ( %{$elem_ref} );
8092
        $elem_ref = \@hash_list;
8093
    }
8094
 
8095
    #
8096
    #   If the list is only one element long, then create a simple form
8097
    #   If the list is not an array ref, then treat it as a single element
8098
    #
8099
    if ( ref ($elem_ref) eq "ARRAY" )
8100
    {
8101
        my $line = 0;
8102
        foreach my $element ( @$elem_ref )
8103
        {
8104
            print MAKEFILE $leadin . $element;
8105
            $leadin = " \\\n" . PadToPosn(0,24 + length( $presep ) + 1 ) unless ($line++);
8106
        }
8107
    }
8108
    elsif ( defined $elem_ref )
8109
    {
8110
            print MAKEFILE $leadin . $elem_ref;
8111
    }
8112
    MakeNewLine();
8113
    return 1;
8114
}
8115
 
8116
#-------------------------------------------------------------------------------
8117
# Function        : MakeDefEntry
8118
#
8119
# Description     : Make a definition entry of the form
8120
#
8121
#                       TAG = NAME0 \
8122
#                             NAME1
8123
#
8124
#                   Support a list of definitions that will always be created
8125
#                   as well as a production and a debug list.
8126
#
8127
#                   Will always generate the "TAG = " string, even if the list
8128
#                   is empty.
8129
#
8130
#                   Will supress the TAG if there is no data if the FIRST opr starts with a '+'
8131
#
8132
# Inputs          : TAG         - Text tag to create
8133
#                   FIRST       - First assignement opr. = or +=
8134
#                   ALL_LIST    - A reference to a list of names to assign
8135
#                                 or a single name.
8136
#                   PROD_LIST   - Optional list to extend the definition with for a production build
8137
#                   DEBUG_LIST  - Optional list to extend the definition with for a debug build
8138
#
8139
# Returns         : Nothing
8140
#
8141
 
8142
sub MakeDefEntry
8143
{
8144
    my( $tag, $assign, $all, $prod, $debug ) = @_;
8145
 
8146
    #
8147
    #   Do not generate anything if the $opr is "+=" and there is no data
8148
    #   to output. ie: Supress empty TAG += statements
8149
    #
8150
    return if ( $assign =~ m/\+/ && ( ref($all) && ! defined $all->[0] ) );
8151
 
8152
    #
8153
    #   TAG for all entries
8154
    #
8155
    MakeEntry3( $tag, $assign, $all );
8156
 
8157
 
8158
    #
8159
    #   TAGs for PROD build
8160
    #   TAGs for DEBUG build
8161
    #
8162
    if ( defined $prod && defined $prod->[0] )
8163
    {
8164
        print MAKEFILE 'ifeq "$(DEBUG)" "0"' . "\n";
8165
        MakeEntry3( $tag, "+=", $prod );
267 dpurdie 8166
        print MAKEFILE 'endif' . "\n";
227 dpurdie 8167
    }
8168
 
8169
    if ( defined $debug && defined $debug->[0] )
8170
    {
8171
        print MAKEFILE 'ifeq "$(DEBUG)" "1"' . "\n";
8172
        MakeEntry3( $tag, "+=", $debug );
267 dpurdie 8173
        print MAKEFILE 'endif' . "\n";
227 dpurdie 8174
    }
8175
 
8176
}
8177
 
8178
sub MakeIfDefEntry
8179
{
8180
    my( $iftag, @rest ) = @_;
8181
 
8182
    print MAKEFILE "ifdef $iftag\n";
8183
    MakeDefEntry (@rest);
8184
    print MAKEFILE "endif\n\n";
8185
}
8186
 
8187
sub MakeIfnDefEntry
8188
{
8189
    my( $iftag, @rest ) = @_;
8190
 
8191
    print MAKEFILE "ifndef $iftag\n";
8192
    MakeDefEntry (@rest);
8193
    print MAKEFILE "endif\n\n";
8194
}
8195
 
261 dpurdie 8196
sub MakeIfZeroEntry
8197
{
8198
    my( $iftag, @rest ) = @_;
8199
 
8200
    print MAKEFILE "ifeq (\$($iftag),0)\n";
8201
    MakeDefEntry (@rest);
8202
    print MAKEFILE "endif\n\n";
8203
}
8204
 
227 dpurdie 8205
#-------------------------------------------------------------------------------
8206
# Function        : CreateNameList
8207
#
8208
# Description     : Create a list of names by adding a prefix and suffix to a
8209
#                   list of items. This is used to add a directory prefix and a
8210
#                   file suffix to a list of files.
8211
#
8212
# Inputs          : $prefix             ie: '$(OBJDIR)/'
8213
#                   $suffix             ie: '.obj'
8214
#                   $elem_ref           ie: A list of files ( passed be ref )
8215
#                                           If a Hash then its sorted keys is used
8216
#
8217
# Returns         : A ref to the resulting list
8218
#
8219
sub CreateNameList
8220
{
8221
    my( $prefix, $suffix, $elem_ref ) = @_;
8222
    my @result;
8223
 
8224
    if ( ref ($elem_ref) eq "HASH" )
8225
    {
8226
        my @hash_list;
8227
        @hash_list = sort keys ( %{$elem_ref} );
8228
        $elem_ref = \@hash_list;
8229
    }
8230
 
8231
    foreach  ( @$elem_ref )
8232
    {
8233
        push @result, $prefix . $_ . $suffix;
8234
    }
8235
    return \@result;
8236
}
8237
 
8238
#-------------------------------------------------------------------------------
8239
# Function        : ListGeneratedProjects
8240
#
8241
# Description     : Return a list of generated/nongenerated projects
8242
#                   Used in conjunction with CreateNameList
8243
#
8244
# Inputs          : $type       - TRUE : Generated
8245
#                                 FALSE: Not Generated
8246
#
8247
# Returns         : A reference to a list of projects
8248
#                   undef will be retuend if there are no projects
8249
#
8250
sub ListGeneratedProjects
8251
{
8252
    my ($type) = @_;
8253
    my @list;
8254
    foreach my $project ( @PROJECTS_ORDER )
8255
    {
8256
        if ( exists($PROJECTS{$project}->{'generated'}) xor $type )
8257
        {
8258
            push @list, $project;
8259
        }
8260
    }
8261
    return @list ? \@list : undef;
8262
}
8263
 
8264
#-------------------------------------------------------------------------------
8265
# Function        : ListCleanGenerated
8266
#
8267
# Description     : return a list of generated targets that have 'clean'
8268
#                   operations. This is used in conjunction with CreateNameList
8269
#
8270
# Inputs          : None
8271
#
8272
# Returns         : A list of project indexes, that can be cleaned
8273
#
8274
sub ListCleanGenerated
8275
{
8276
    my @list;
8277
    foreach my $i ( @GENERATE_FILES )
8278
    {
8279
        push @list, $i->{'index'}
8280
            if ( $i->{'clean'} );
8281
    }
8282
    return \@list;
8283
}
8284
 
251 dpurdie 8285
#-------------------------------------------------------------------------------
8286
# Function        : MakeResolve
8287
#
8288
# Description     : Internal Function
8289
#                   Locate a source file by examining a list of directories
8290
#
8291
#                   Don't use directly
8292
#                   Use MakeSrcResolve or MakeSrcResolveExtended
8293
#
8294
# Inputs          : $dirs           - Ref to an array of directories to scan
8295
#                   $source         - File to locate
8296
#
8297
# Returns         : Resolved path to the file
8298
#                   Will warn if multiple instances of the file are found
8299
#
227 dpurdie 8300
sub MakeResolve
8301
{
8302
    my( $dirs, $source ) = @_;
285 dpurdie 8303
    my( $first, $count );
227 dpurdie 8304
 
237 dpurdie 8305
    #
8306
    #   If the path contains a '$' then its assumed to be
8307
    #   a variable name in the path. Just assume that it exists
8308
    #
8309
    return $source if ( $source =~ m#\$# );
8310
 
8311
    #
8312
    #   If the path is absolute or contains a leading ., then don't search
8313
    #   Warn if it can't be found
8314
    #
8315
    if ( $source =~ m#^(/|\.)# )
8316
    {
8317
        Warning( "Unable to resolve '$source' path" ) unless -f $source;
8318
        return $source;
227 dpurdie 8319
    }
8320
 
6276 dpurdie 8321
    my @found;
8322
    # Search the local path first
8323
    push (@found, $source ) if -f ($source);
237 dpurdie 8324
 
285 dpurdie 8325
    foreach my $dir (@$dirs)
227 dpurdie 8326
    {
331 dpurdie 8327
        next if ( $dir eq '.' );
6276 dpurdie 8328
        my $temp = $dir . '/' . $source;
227 dpurdie 8329
        Debug2( "MakeResolve: Looking in: $temp" );
6276 dpurdie 8330
        push (@found, $temp) if (-f $temp);
227 dpurdie 8331
    }
8332
 
6276 dpurdie 8333
    Warning( "Unable to resolve path to '$source'" ) unless $found[0];
8334
    if (scalar @found > 1)
8335
    {
8336
        Warning("Duplicates for '$source'. Using the first", @found);
227 dpurdie 8337
    }
6276 dpurdie 8338
 
8339
    return $found[0] || "";
227 dpurdie 8340
}
8341
 
251 dpurdie 8342
#-------------------------------------------------------------------------------
8343
# Function        : MakeSrcResolve
8344
#
8345
# Description     : Locate a source file by examining the list of source
8346
#                   directories. There are a few frills
8347
#
8348
#                   Look for a source file in
8349
#                       1) %::BUILD_KNOWNFILES
8350
#                       2) %SRCS
8351
#                       3) Dirs specified by the array @SRCSDIRS
8352
#
8353
# Inputs          : Name of a file to resolve
8354
#
8355
# Returns         : Resolved path.
283 dpurdie 8356
#                   Input file - if not found at all
251 dpurdie 8357
#
227 dpurdie 8358
sub MakeSrcResolve
8359
{
8360
    my ($name) = @_;
8361
    my $file;
8362
 
251 dpurdie 8363
    if ( exists ( $::BUILD_KNOWNFILES{$name} ) ) {
8364
        #
8365
        #   The Known Files list is relative to ScmRoot
8366
        #   This must be included in the full path
8367
        #
8368
        $file = $ScmRoot . '/' . $::BUILD_KNOWNFILES{$name};
8369
 
8370
    } elsif ( exists $SRCS{$name} ) {
8371
        $file = $SRCS{$name};
8372
 
8373
    } else {
8374
        $file = MakeResolve( \@SRCDIRS, @_ )
8375
    }
227 dpurdie 8376
    return $file;
8377
}
8378
 
8379
 
8380
# MakeSrcResolveExtended
8381
#   from_global = 0 : Search user specified directories
8382
#               = 1 : Search LinkPkgArchive list
8383
#
8384
our @PkgSrcDirList;
8385
sub MakeSrcResolveExtended
8386
{
8387
    my ( $from_global, $file ) = @_;
8388
 
8389
    #
8390
    #   Simple Case. Resolve source from known source directories
8391
    #
8392
    #
8393
    return MakeSrcResolve( $file )
8394
        unless ( $from_global );
8395
 
8396
    #
8397
    #   Not so simple Case
8398
    #   Resolve the source from the imported packages
8399
    #
8400
    #   Create a list of directores to search, but only the first time
311 dpurdie 8401
    #       - Interface directories - from BuildPkgArchive
227 dpurdie 8402
    #       - LnkPkgArchive directories
8403
    #         Using target,product,platform include directories
8404
    #
8405
    unless ( @PkgSrcDirList )
8406
    {
8407
        for my $entry (@{$::ScmBuildPkgRules{$ScmPlatform} })
8408
        {
311 dpurdie 8409
            next if ( $entry->{'TYPE'} eq 'build' ); # Ignore BuildPkgArchives
8410
 
227 dpurdie 8411
            for (@{$entry->{'PINCDIRS'}}, @{$entry->{'THXDIRS'}}, '' )
8412
            {
8413
                my $dir = $entry->{'ROOT'} . "/" . $_ ;
8414
                $dir =~ s~//~/~g;
8415
                $dir =~ s~/$~~;
311 dpurdie 8416
                push ( @PkgSrcDirList, $dir );
227 dpurdie 8417
            }
8418
        }
311 dpurdie 8419
    }
227 dpurdie 8420
 
8421
    return MakeResolve( \@PkgSrcDirList, $file );
8422
}
8423
 
8424
#-------------------------------------------------------------------------------
8425
# Function        : GetPackageRoot
8426
#
8427
# Description     : Determine the root directory for a given package
8428
#                   This routine is intended for non-standard JATS scripts that
8429
#                   access package contents directly
8430
#
8431
#                   Note: This routine does not attempt to handle multiple
8432
#                         instances of a package ( sysbasetypes ).
8433
#
8434
# Inputs          : $pname          - Name of the package
8435
#
8436
# Returns         :
8437
#
8438
sub GetPackageRoot
8439
{
8440
    my( $pname ) = @_;
8441
    Debug( "GetPackageRoot(@_)" );
8442
 
8443
    my $result = undef;
8444
    my $pkg = GetPackageEntry( $pname );
8445
    if ( $pkg )
8446
    {
8447
        $result = $pkg->{'ROOT'};
8448
        Debug( "GetPackageRoot: $result" );
8449
    }
8450
 
8451
    return $result;
8452
}
8453
 
8454
#-------------------------------------------------------------------------------
8455
# Function        : ActiveProject
8456
#
8457
# Description     : Determine if the specified project is currenly 'active'
8458
#
345 dpurdie 8459
# Inputs          : $project            - one or more project names separated
8460
#                                         by either a comma or a colon
227 dpurdie 8461
#
8462
# Returns         : TRUE    if the project is active
8463
#
8464
sub ActiveProject
8465
{
8466
    my ($project) = @_;
345 dpurdie 8467
    foreach (  split( '\s*[:,]\s*', $project ) )
227 dpurdie 8468
    {
8469
        return 1
8470
            if ( $_ eq $::ScmBuildProject );
8471
    }
8472
    return 0;
8473
}
8474
 
345 dpurdie 8475
#-------------------------------------------------------------------------------
8476
# Function        : ActiveDefine
8477
#
8478
# Description     : Determine if the specified definition is currenly 'active'
8479
#
8480
# Inputs          : $defs               - one or more variable names separated
8481
#                                         by either a comma or a colon
8482
#
8483
# Returns         : TRUE    if any of the definitions are known
8484
#
8485
sub ActiveDefine
8486
{
8487
    my ($defs) = @_;
8488
    no strict 'refs';
8489
    foreach (  split( '\s*[:,]\s*', $defs ) )
8490
    {
8491
        return 1
4455 dpurdie 8492
            if ( defined( $$_ ) || ( @$_ ) );
345 dpurdie 8493
    }
8494
    use strict 'refs';
8495
    return 0;
8496
}
227 dpurdie 8497
 
8498
#-------------------------------------------------------------------------------
345 dpurdie 8499
# Function        : ActiveMachType
8500
#
8501
# Description     : Determine if the specified MachType is currenly 'active'
8502
#
8503
# Inputs          : $mtype              - one or more machine names separated
8504
#                                         by either a comma or a colon
8505
#
8506
# Returns         : TRUE    if any of the current MachType is in the list
8507
#
8508
sub ActiveMachType
8509
{
8510
    my ($mtype) = @_;
8511
    foreach (  split( '\s*[:,]\s*', $mtype ) )
8512
    {
8513
        return 1
8514
            if ( uc($_) eq uc($::GBE_MACHTYPE) );
8515
    }
8516
    return 0;
8517
}
8518
 
8519
#-------------------------------------------------------------------------------
6133 dpurdie 8520
# Function        : ActiveAlias
8521
#
8522
# Description     : Determine if the specified Alias is currenly 'active'
8523
#
8524
# Inputs          : $mtype              - one or more alias names separated
8525
#                                         by either a comma or a colon
8526
#
8527
# Returns         : TRUE    if any of the current Aliases is in the list
8528
#
8529
sub ActiveAlias
8530
{
8531
    my ($mtype) = @_;
8532
    foreach (  split( '\s*[:,]\s*', $mtype ) )
8533
    {
8534
        return 1
8535
            if ( isAnAlias( uc($_) ) );
8536
    }
8537
    return 0;
8538
}
8539
 
8540
 
8541
#-------------------------------------------------------------------------------
227 dpurdie 8542
# Function        : ActivePlatform
8543
#
8544
# Description     : Determine if the specified platform is currently 'active'
8545
#                   This is used by all user directives in order to determine
8546
#                   if the directive should be ignored for the current platform
8547
#
8548
# Inputs          : $platform_spec      - A platform specifier
8549
#                                         This is a bit complex.
8550
#
241 dpurdie 8551
#                   Format of platform_spec. One or more of
8552
#                       PlatformName
8553
#                       AliasName
6133 dpurdie 8554
#                       TargetName[,--Target]
345 dpurdie 8555
#                   Special Options (Must all be True)
8556
#                       --Project=ProjectName[:ProjectName]+
8557
#                       --Defined=SomeValue[:SomeValue]+
6133 dpurdie 8558
#                       --MachType=SomeMachType[:SomeMachType]+
8559
#                       --Alias=SomeAlias[:SomeAlias]+
8560
#                   Some shortcuts
8561
#                       '*'     ==> Always true
8562
#
345 dpurdie 8563
#                   Each can be prefixed with a '!' to negate the test
6133 dpurdie 8564
#                   
8565
#                   PlatformNames are either additive or negative(prefixed with !)
8566
#                       Order is not important                   
8567
#                       All additive names are accumulated before the negative items are considered.
8568
#                           ie: aa,!bb => !bb,aa
8569
#                       If only negative names are provided then JATS assumes a leading '*'
8570
#                           ie: !aaa => *,!aaa
8571
#                   
241 dpurdie 8572
#                   Valid options are:
271 dpurdie 8573
#                       --Target        - indicates that the platform is a 'target'
241 dpurdie 8574
#
8575
# Returns         : TRUE if the platform spec is satisfied
8576
#
227 dpurdie 8577
sub ActivePlatform
8578
{
8579
    my( $platform_spec ) = @_;
8580
    my( @platforms, $scmplatform, $platform );
6133 dpurdie 8581
    my( %arguments, @args );
241 dpurdie 8582
    my @plist;
227 dpurdie 8583
 
241 dpurdie 8584
    #
8585
    #   Short circuit check
6133 dpurdie 8586
    #       '*' is used so often that it pays to check it first
241 dpurdie 8587
    #
8588
    if ( $platform_spec eq '*' )
8589
    {
8590
        Debug3( " ActivePlatform(@_) = TRUE" );
8591
        return 1;
8592
    }
227 dpurdie 8593
 
241 dpurdie 8594
    #
8595
    #   Platform specifier may be a comma seperated list
8596
    #   ie:  WIN32,MOS,XXX
8597
    #   Extract non-platform arguments
279 dpurdie 8598
    #   Process to yield a dummy platform of '0' or '1' - these will be seen later
241 dpurdie 8599
    #
8600
    foreach ( split( '\s*,\s*', $platform_spec ) )
8601
    {
345 dpurdie 8602
        my ($result, $not);
8603
        if ( m~^(!?)--Project=(.+)~ ) {
325 dpurdie 8604
            $not = $1;
345 dpurdie 8605
            $result = ActiveProject($2);
277 dpurdie 8606
 
345 dpurdie 8607
        } elsif ( m~^(!?)--Defined=(.+)~ ) {
325 dpurdie 8608
            $not = $1;
345 dpurdie 8609
            $result = ActiveDefine($2);
241 dpurdie 8610
 
345 dpurdie 8611
        } elsif ( m~^(!?)--MachType=(.+)~ ) {
325 dpurdie 8612
            $not = $1;
345 dpurdie 8613
            $result = ActiveMachType($2);
8614
 
6133 dpurdie 8615
        } elsif ( m~^(!?)--Alias=(.+)~ ) {
8616
            $not = $1;
8617
            $result = ActiveAlias($2);
8618
 
325 dpurdie 8619
        } else {
8620
            #
8621
            #   Must be a platform argument
8622
            #   Add to a list
8623
            #
8624
            push @platforms, $_;
241 dpurdie 8625
            next;
8626
        }
8627
 
8628
        #
325 dpurdie 8629
        #   Continue processing non-platform arguments
345 dpurdie 8630
        #   Each one must be TRUE, allowing for negation.
241 dpurdie 8631
        #
325 dpurdie 8632
        $result = $result ? 1 : 0;
345 dpurdie 8633
        $result = ! $result if ( $not );
8634
        return 0 unless ( $result );
241 dpurdie 8635
    }
8636
 
4128 dpurdie 8637
    #
8638
    #   If we have no platforms then the test was purely non-platform arguments.
8639
    #
6133 dpurdie 8640
    if ($platform_spec ne '' && ! @platforms) {
8641
        Debug3( " ActivePlatform(@_ == $ScmPlatform) = TRUE" );
4128 dpurdie 8642
        return 1;
8643
    }
8644
 
6133 dpurdie 8645
    unless (@platforms) {
8646
        Debug3( " ActivePlatform(@_ == $ScmPlatform) = FALSE" );
8647
        return 0;
8648
    }
8649
 
8650
 
241 dpurdie 8651
    #   Platform specified may be an Alias
8652
    #   Perform alias expansion
8653
    #
8654
    @platforms = ExpandPlatforms( @platforms );         # aliasing
227 dpurdie 8655
    Debug3( " ActivePlatform(@_)" );
6198 dpurdie 8656
#    Debug0( " Platforms(@platforms)" );
227 dpurdie 8657
 
8658
#.. Arguments
241 dpurdie 8659
#   At this point we have a list of platforms and arguments
8660
#   Build up a hash of arguments for each platform being parsed
227 dpurdie 8661
#   Multiple arguments can follow a platform name
241 dpurdie 8662
#   Arguments apply to the preceeding platform name
227 dpurdie 8663
#
241 dpurdie 8664
    $platform = undef;
227 dpurdie 8665
    foreach ( @platforms )
8666
    {
241 dpurdie 8667
        if ( /^--Target/ ) {                     # Arguments
8668
            if ( $platform ) {
8669
                $arguments{$platform}{'Target'} = 1;
8670
            } else {
317 dpurdie 8671
                Warning ("No Platform preceding platform option: $_");
241 dpurdie 8672
            }
8673
 
305 dpurdie 8674
        } elsif ( /^--Only(Prod)|(Debug)/ || /--board=/ ) {
273 dpurdie 8675
            # Known arguments
305 dpurdie 8676
            # Bit of a kludge. Must be a better way
273 dpurdie 8677
 
241 dpurdie 8678
        } elsif ( /^--/ ) {
8679
            Warning ("Unknown platform option: $_");
8680
 
227 dpurdie 8681
        } else {                                # Target
8682
            $platform = $_;
241 dpurdie 8683
            push @plist, $platform;
227 dpurdie 8684
        }
8685
    }
8686
 
241 dpurdie 8687
#.. Scan the expression
227 dpurdie 8688
#
6198 dpurdie 8689
    $scmplatform = uc( $ScmPlatform );              # current platform
6133 dpurdie 8690
    my @add;
8691
    my @remove;
8692
    foreach ( @plist ) {
6198 dpurdie 8693
        my $platform = uc( Trim( $_ ) );            # trim white and convert case
6133 dpurdie 8694
        my $pname = $platform;
8695
        my $invert = 0;
8696
        if (substr($platform, 0, 1) eq '!') {
8697
            $invert = 1;
8698
            $pname = substr($platform, 1)
8699
        }
325 dpurdie 8700
 
227 dpurdie 8701
        #
241 dpurdie 8702
        #   Determine filter comparison
6133 dpurdie 8703
        #       Either a Platform or a Target
241 dpurdie 8704
        #
6133 dpurdie 8705
        if ( $arguments{$platform}{'Target'} ) {
8706
            $pname = $scmplatform if ($pname eq  uc( $ScmTarget ));
227 dpurdie 8707
        }
241 dpurdie 8708
 
6133 dpurdie 8709
        #
8710
        #   Catch some historically bad practices
8711
        #
8712
        $pname = $scmplatform if ( $pname eq '*'  || $pname eq '1' ); 
227 dpurdie 8713
 
6133 dpurdie 8714
        Debug3( "   Platform=$platform, PName=$pname" );
8715
 
227 dpurdie 8716
        #
8717
        #   Examine platform names
6133 dpurdie 8718
        #   Allow negation (removal) of the name
227 dpurdie 8719
        #
6133 dpurdie 8720
        if ( substr($platform, 0, 1) eq '!' )  {
8721
            push @remove, $pname; 
8722
        } else {
8723
            push @add, $pname; 
227 dpurdie 8724
        }
8725
    }
8726
 
241 dpurdie 8727
    #
6133 dpurdie 8728
    #   Build complete list of allowed platforms
8729
    #       Process additive rules before removal rules
8730
    #       If there are no additive rules, then assume all protaforms
241 dpurdie 8731
    #
6133 dpurdie 8732
    my %calcList;
8733
    @add = @::BUILDPLATFORMS unless @add;
6204 dpurdie 8734
    $calcList{uc $_} = 1 foreach (@add);
8735
    delete $calcList{uc $_} foreach (@remove);
6133 dpurdie 8736
#DebugDumpData("Add", \@add);
8737
#DebugDumpData("Remove", \@remove);
8738
#DebugDumpData("calcList", \%calcList);
241 dpurdie 8739
 
8740
    #
6133 dpurdie 8741
    #   If the current build target is left in the platform list, then we are building for it
8742
    #   
6198 dpurdie 8743
    if (exists $calcList{$scmplatform}) {
227 dpurdie 8744
        Debug3( " ActivePlatform(@_ == $ScmPlatform) = TRUE" );
8745
        return 1;
8746
    }
241 dpurdie 8747
 
227 dpurdie 8748
    Debug3( " ActivePlatform(@_ == $ScmPlatform) = FALSE" );
8749
    return 0;
8750
}
8751
 
8752
#-------------------------------------------------------------------------------
321 dpurdie 8753
# Function        : If
8754
#
8755
# Description     : Function for embedding arguments in directives
8756
#                   To be used within another directive
8757
#                   ie:
8758
#                       AnyDirective ('*',  arg1, arg2, ...
8759
#                                           If (SomePlatform, arg1, .. ,argn))
8760
#
8761
# Inputs          : $platform               - Active Platform speciifier
8762
#                   @args                   - Args
8763
#
8764
# Returns         : @args or nothing
8765
#
8766
sub  If
8767
{
8768
    my $platform = shift;
8769
    return @_
8770
        if ( ActivePlatform( $platform ));
8771
    return;
8772
}
8773
 
8774
#-------------------------------------------------------------------------------
227 dpurdie 8775
# Function        : RegisterMakefileGenerate
8776
#
8777
# Description     : Register a function to be called at the start of the
8778
#                   makefile generation process
8779
#
8780
# Inputs          : $fname      - Name of the function
8781
#                   $args       - Function Arguments
8782
#
8783
# Returns         : Nothing
8784
#
8785
our @MF_Generators;
8786
sub RegisterMakefileGenerate
8787
{
8788
   my ($fref) = @_;
8789
   my $rtype = ref($fref) || 'not a reference';
8790
 
8791
   Error ("RegisterMakefileGenerate called incorrectly",
8792
          "First argument MUST be a code reference",
8793
          "It is a $rtype"
8794
          ) unless ( $rtype eq 'CODE' );
8795
 
8796
   #
8797
   #    Save the arguments by reference in an array
8798
   #    The array will be processed later
8799
   #
8800
   push @MF_Generators, \@_;
8801
}
8802
 
8803
#-------------------------------------------------------------------------------
271 dpurdie 8804
# Function        : RegisterSrcHook
8805
#
8806
# Description     : Register a function to be called when a source file is
8807
#                   declared
8808
#
8809
# Inputs          : $ext        - Extension of interest
8810
#                                 '*' will be used by all
8811
#                   $fname      - Name of the function
8812
#                   $args       - Function Arguments
8813
#
8814
# Returns         : Nothing
8815
#
8816
sub RegisterSrcHook
8817
{
8818
    my $ext = shift;
8819
    my ($fref) = @_;
8820
    my $rtype = ref($fref) || 'not a reference';
8821
 
8822
    Error ("RegisterSrcHook called incorrectly",
8823
           "Second argument MUST be a code reference",
8824
           "It is a $rtype"
8825
           ) unless ( $rtype eq 'CODE' );
8826
 
8827
    #
8828
    #    Save the arguments by reference in an array
8829
    #    The array will be processed later
8830
    #
8831
    push @{$MF_RegisterSrcHooks{$ext}}, \@_;
8832
}
8833
 
8834
 
8835
#-------------------------------------------------------------------------------
227 dpurdie 8836
# Function        : MakefileHeader
8837
#
8838
# Description:    : Generate a "standard" makefile header.
8839
#
8840
#..
8841
 
8842
sub MakefileHeader
8843
{
8844
    my ($file, $desc, $by, @trailing) = @_;
8845
    my ($diff);
8846
 
8847
    $diff = 0 if (($diff = ((80-5) - length($desc))) < 0);
8848
    $desc .= ' ' . ('-' x $diff);
8849
 
8850
    print $file <<EOF;
8851
#-- $desc
8852
#
8853
#                   -- Please do not edit this file. --
8854
#
8855
#       To do so may result in a system failure, in additional to any
8856
#       changes made shall be overwritten.
8857
#
8858
# Created by $by
8859
#         on $::CurrentTime
8860
#
8861
EOF
8862
    #
8863
    #   Print out the trailer
8864
    #   This is an array. Place each entry on a new line
8865
    #
8866
    print $file $_ . "\n" for ( @trailing );
8867
}
8868
 
8869
###############################################################################
8870
# MakeFileGenerate:
8871
#       This subroutine does all of the actual make file generation based
8872
#       on information provided in the calls to the various public
8873
#       interface routines.
8874
#
8875
# Inputs:
8876
#
8877
# Returns:
8878
###############################################################################
8879
 
8880
my $MakefileGenerate_once = 0;
8881
sub MakefileGenerate
8882
{
8883
    my $Makefile = "$ScmPlatform.mk";
8884
    Debug( "MakefileGenerate: $Makefile" );
8885
 
8886
    #
8887
    #   Nasty things happen when we generate a makefile twice
8888
    #   Just warn the user and do nothing
8889
    #   If its in the common makefile.pl then just ignore it
8890
    #
8891
    if ( $ScmProcessingRootMake )
8892
    {
8893
        Warning ("MakefileGenerate directive is not allowed in common makefile.pl");
8894
        return;
8895
    }
8896
 
8897
    if ( $MakefileGenerate_once )
8898
    {
8899
        Warning ("MakefileGenerate should only be called once.",
8900
                 "Dir: $::Cwd");
8901
        return;
8902
    }
8903
    $MakefileGenerate_once = 1;
8904
 
8905
    #
8906
    #   Invoke all registered Makefile Generator functions
8907
    #   These allow clever directives to collect information to be
8908
    #   processed before the makefiles are created
8909
    #
8910
    while ( @MF_Generators )
8911
    {
8912
        Debug( "MakefileGenerate: Invoke RegisterMakefileGenerate function" );
8913
        my ($fname, @args) = @{shift @MF_Generators};
8914
        &$fname ( @args );
8915
    }
8916
 
8917
    #
8918
    #   Allow the toolset the opportunity to process all the collected data
8919
    #   before the makefile is created. This is optional
8920
    #
8921
    my( $if ) = MakeIf::Factory();              # build interface
8922
    $if->Preprocess();
8923
 
8924
    #
343 dpurdie 8925
    #   If we have supressed the Toolset use, then we need to sanity test
8926
    #   the use of the toolset
8927
    #
8928
    if ( $ScmNoToolsTest )
8929
    {
8930
        ReportError ("Building programs not supported with --NoToolset") if ( @PROGS || @TESTPROGS );
8931
        ReportError ("Building libraries not supported with --NoToolset") if ( @LIBS || @MLIBS || @SHLIBS );
8932
        ReportError ("Building projects not supported with --NoToolset") if ( %PROJECTS );
8933
        ErrorDoExit();
8934
    }
8935
 
8936
    #
227 dpurdie 8937
    #   Auto package the 'descpkg' file
8938
    #   If this makefile packages any files, then it can also package the descpkg file
8939
    #   The descpkg will be piggybacked into all makefiles that do a package
8940
    #
8941
    if ( %PACKAGE_FILES || %PACKAGE_HDRS || %PACKAGE_CLSS || %PACKAGE_LIBS
6387 dpurdie 8942
                        || %PACKAGE_SHLIBS || %PACKAGE_PROGS || @PACKAGE_DIRS )
227 dpurdie 8943
    {
251 dpurdie 8944
        Src ('*', 'descpkg') unless ($SRCS{ descpkg });
8945
        PackageFile ('*', 'descpkg');
227 dpurdie 8946
    }
8947
 
8948
    #
8949
    #   Some toolsets NEED a relative root
261 dpurdie 8950
    #   Note: At the moment ScmRoot is relative anyway, thus this code
8951
    #         does nothing
227 dpurdie 8952
    #
8953
    my $gbe_root = $::ScmRoot;
8954
    if ( $::UseRelativeRoot )
8955
    {
8956
        $gbe_root =  RelPath( $::ScmRoot );
8957
    }
8958
 
8959
    #
8960
    #   Now start to create the makefile
8961
    #
6133 dpurdie 8962
    ToolsetFiles::AddFile($Makefile);
285 dpurdie 8963
    open( MAKEFILE, '>', $Makefile ) || Error( "Cannot create $Makefile" );
227 dpurdie 8964
    ::MakefileHeader( *MAKEFILE,
8965
                      'Auto-generated Platform Dependent Makefile',
8966
                      "$ScmMakelib (version $ScmVersion)",
6177 dpurdie 8967
                      "# COPYRIGHT - VIX IP PTY LTD (\"VIX\"). ALL RIGHTS RESERVED.",
227 dpurdie 8968
                      '#',
8969
                      "# Located in $::Cwd",
8970
                      "# Platform $::ScmPlatform",
8971
                      '#' . ('-' x 79),
8972
                      );
8973
 
8974
    #
8975
    #   Ensure that some essential variables are set
8976
    #
8977
    print MAKEFILE <<EOF;
8978
#
8979
#   Validate essential environment variables
8980
#
8981
ifndef GBE_BIN
8982
    \$(error ERROR: GBE_BIN is not available)
8983
endif
8984
ifndef GBE_PERL
8985
    \$(error ERROR: GBE_PERL is not available)
8986
endif
8987
ifndef DEBUG
8988
    \$(error ERROR: DEBUG is not defined)
8989
endif
8990
EOF
8991
 
8992
 
8993
    print MAKEFILE <<EOF;
8994
 
8995
#
8996
#   Basic definitions
8997
#
343 dpurdie 8998
GBE_ROOT      := $gbe_root
8999
GBE_ROOT_ABS  := \$(abspath \$(GBE_ROOT))
9000
GBE_HOST      := $::ScmHost
9001
GBE_HOSTMACH  := $::GBE_MACHTYPE
9002
GBE_TARGET    := $::ScmTarget
9003
GBE_MACHTYPE  := $::ScmMachType
9004
GBE_PLATFORM  := $::ScmPlatform
9005
GBE_PBASE     := $::Pbase
9006
GBE_TYPE      := \$(if \$(findstring 1,\$(DEBUG)),D,P)
227 dpurdie 9007
EOF
9008
 
343 dpurdie 9009
MakePrint( "GBE_ARGS      := @ScmPlatformArgs\n" )
227 dpurdie 9010
    if ( scalar @ScmPlatformArgs );
9011
 
343 dpurdie 9012
MakePrint( "GBE_PRODUCT   := $ScmProduct\n" )
227 dpurdie 9013
    if ( $ScmProduct ne "" );
9014
 
343 dpurdie 9015
MakePrint( "GBE_OS_COMMON := $::BUILDINFO{$ScmPlatform}{OS_COMMON}\n" )
227 dpurdie 9016
    if ( exists($::BUILDINFO{$ScmPlatform}{OS_COMMON}) );
9017
 
9018
    print MAKEFILE <<EOF;
9019
 
9020
SHELL           := \$(GBE_BIN)/sh
9021
SHELLARGS       :=
9022
EXTENDED_LINE   := \$(GBE_BIN)/extend.lst
9023
export EXTENDED_LINE MAKE
9024
 
343 dpurdie 9025
MFLAGS           := --no-print --warn -r
9026
BUILDNAME        := $::ScmBuildName
9027
BUILDVER         := $::ScmBuildVersionFull
9028
BUILDVERNUM      := $::ScmBuildVersion
227 dpurdie 9029
BUILDPREVIOUSVER := $::ScmBuildPreviousVersion
343 dpurdie 9030
DEPLOYPATCH      := $ScmDeploymentPatch
9031
GBE_NOTOOLSTEST  := $ScmNoToolsTest
4781 dpurdie 9032
MAKEFILEUID      := $ScmMakeUid
9033
export MAKEFILEUID
227 dpurdie 9034
 
9035
#
9036
#   Ensure PWD is correctly set
9037
#
9038
PWD             := \$(CURDIR)
9039
export PWD
9040
 
261 dpurdie 9041
#
9042
#   NODEPEND    - Used to suppress generated dependency file checking
9043
#                 Mostly done in jmake.pl
9044
#   EXPERT      - Used to suppress dependency on this makefile
9045
#
9046
EOF
9047
 
285 dpurdie 9048
MakePrint( "EXPERT\t\t?= " . ($ScmExpert ? '1' : '0' ) . "\n" );
9049
MakePrint( "NODEPEND\t?= 0\n" );
261 dpurdie 9050
 
9051
print MAKEFILE <<EOF;
9052
 
9053
#
9054
#   SCM_MAKEFILE - The name of the file to depend upon
9055
#                  Supressed in EXPERT mode
9056
#
9057
ifneq (\$(EXPERT),0)
9058
SCM_MAKEFILE	:=
9059
else
9060
SCM_MAKEFILE	:= $Makefile
9061
endif
9062
EOF
9063
 
267 dpurdie 9064
#
9065
#   Setup the base directory for the packaging process
9066
#   When building a deployable package the base directory is changed to match
9067
#   that used by the deployment world. This is done so that the descpkg file
9068
#   can be created in the correct location
9069
#
9070
my  $PKGDIR = "pkg/$::Pbase";
9071
    $PKGDIR = "build/deploy" if ( $DEPLOYPACKAGE );
9072
Verbose("Setting PKGDIR: $PKGDIR");
9073
 
261 dpurdie 9074
print MAKEFILE <<EOF;
9075
 
227 dpurdie 9076
#--------- Targets -------------------------------------------------------------
9077
 
9078
.PHONY: 	default all build install package unpackage uninstall \\
9079
		clean unbuild clobber deploy
9080
 
373 dpurdie 9081
default:
227 dpurdie 9082
all:		install package deploy
9083
build:		make_init generate install_hdr depend make_lib \\
6387 dpurdie 9084
		install_lib make_install_shlib make_prog install_class install_dirs
227 dpurdie 9085
install:	build install_prog
6387 dpurdie 9086
package:	package_dirs package_files package_hdr package_lib package_shlib \\
9087
		package_prog package_class
227 dpurdie 9088
unpackage:	unpackage_class unpackage_prog unpackage_shlib \\
6387 dpurdie 9089
		unpackage_lib unpackage_hdr unpackage_files unpackage_dirs 
9090
uninstall:	uninstall_dirs uninstall_class uninstall_prog uninstall_shlib \\
227 dpurdie 9091
		uninstall_lib uninstall_hdr
9092
clean:		make_clean unmake_prog unmake_test unmake_lib unobj \\
261 dpurdie 9093
		undepend ungenerate rmlitter unmake_dir
227 dpurdie 9094
unbuild:	clean uninstall
9095
clobber:	unpackage unbuild
9096
deploy:		install run_deploy
9097
 
9098
#--------- Macros --------------------------------------------------------------
9099
 
9100
OBJDIR		= \$(GBE_PLATFORM)\$(GBE_TYPE).OBJ
9101
LIBDIR		= \$(GBE_PLATFORM).LIB
9102
BINDIR		= \$(GBE_PLATFORM)\$(GBE_TYPE).BIN
9103
CLSDIR		= classes\$(GBE_TYPE)
9104
 
267 dpurdie 9105
PKGDIR		= \$(GBE_ROOT)/$PKGDIR
227 dpurdie 9106
INCDIR_PKG	= \$(PKGDIR)/include
9107
LIBDIR_PKG	= \$(PKGDIR)/lib
9108
BINDIR_PKG	= \$(PKGDIR)/bin
9109
CLSDIR_PKG	= \$(PKGDIR)/classes
4996 dpurdie 9110
UTFDIR_PKG	= \$(GBE_ROOT_ABS)/$PKGDIR/utfResults
227 dpurdie 9111
 
9112
LOCALDIR	= \$(GBE_ROOT)/local
9113
INCDIR_LOCAL	= \$(LOCALDIR)/inc
9114
LIBDIR_LOCAL	= \$(LOCALDIR)/lib
9115
BINDIR_LOCAL	= \$(LOCALDIR)/bin
9116
CLSDIR_LOCAL	= \$(LOCALDIR)/classes
9117
BINDIR_LOCAL_PATH = \$(GBE_ROOT_ABS)/local/bin/\$(GBE_PLATFORM)\$(GBE_TYPE)
9118
 
9119
INTERFACEDIR	= \$(GBE_ROOT)/$ScmInterface
9120
INCDIR_INTERFACE= \$(INTERFACEDIR)/include
9121
LIBDIR_INTERFACE= \$(INTERFACEDIR)/lib
9122
BINDIR_INTERFACE= \$(INTERFACEDIR)/bin
9123
CLSDIR_INTERFACE= \$(INTERFACEDIR)/classes
9124
 
9125
.SUFFIXES:		# Delete the default suffixes
9126
 
9127
EOF
9128
 
9129
    MakePrintList( \@DEFINES );
9130
    MakeNewLine();
9131
 
9132
#-------------------------------------------------------------------------------
9133
#
9134
#
261 dpurdie 9135
    MakeHeader ("Defines, flags and file sets");
227 dpurdie 9136
 
9137
    # Flags
6177 dpurdie 9138
    foreach my $opt ( sort keys %ScmCompilerOpts )
261 dpurdie 9139
    {
9140
        MakeDefEntry ( $opt, "=", $ScmCompilerOpts{$opt} );
9141
    }
227 dpurdie 9142
 
261 dpurdie 9143
    MakeDefEntry( "CFLAGS",         "=", \@CFLAGS, \@CFLAGS_PROD, \@CFLAGS_DEBUG );
9144
    MakeDefEntry( "CLINTFLAGS",     "=", \@CLINTFLAGS, \@CLINTFLAGS_PROD, \@CLINTFLAGS_DEBUG );
9145
    MakeDefEntry( "CDEPENDFLAGS",   "=", \@CFLAGS, \@CFLAGS_PROD, \@CFLAGS_DEBUG );
9146
    MakeDefEntry( "CXXFLAGS",       "=", \@CXXFLAGS, \@CXXFLAGS_PROD, \@CXXFLAGS_DEBUG );
9147
    MakeDefEntry( "CXXLINTFLAGS",   "=", \@CXXLINTFLAGS, \@CXXLINTFLAGS_PROD, \@CXXLINTFLAGS_DEBUG );
9148
    MakeDefEntry( "CXXDEPENDFLAG",  "=", \@CXXFLAGS, \@CXXFLAGS_PROD, \@CXXFLAGS_DEBUG );
267 dpurdie 9149
    MakeDefEntry( "ASFLAGS",        "=", \@ASFLAGS, \@ASFLAGS_PROD, \@ASFLAGS_DEBUG );
9150
    MakeDefEntry( "LDFLAGS",        "=", \@LDFLAGS, \@LDFLAGS_PROD, \@LDFLAGS_DEBUG );
227 dpurdie 9151
 
9152
 
9153
#-------------------------------------------------------------------------------
9154
#   
9155
#
261 dpurdie 9156
    MakeHeader ("Tool Search Path",
9157
                "Extend the PATH seen by all the tools to include",
9158
                "The tools/bin directories discovered in Packages" );
9159
    my $put_PATH;
9160
    my $put_LD_LIBRARY_PATH;
9161
    for my $path ( ToolExtensionPaths() )
9162
    {
9163
        MakePrint( "PATH := $path$::ScmPathSep\$(PATH)\n" );
9164
        $put_PATH = 1;
227 dpurdie 9165
 
261 dpurdie 9166
        if ( $::ScmHost eq "Unix" )
9167
        {
227 dpurdie 9168
        MakePrint( "LD_LIBRARY_PATH ?= \n" );
9169
        MakePrint( "LD_LIBRARY_PATH := $path$::ScmPathSep\$(LD_LIBRARY_PATH)\n" );
261 dpurdie 9170
            $put_LD_LIBRARY_PATH =1;
9171
        }
227 dpurdie 9172
    }
9173
 
261 dpurdie 9174
    #   Export the appropriate environment variables
9175
    #   Note: Windows has an issue with PATH and Path
9176
    #         Haven't got to the bottom of it yet, but it would appear that DLL
9177
    #         searching uses Path and other stuff uses PATH. Not too sure how we
9178
    #         end up with two (or more in the environment)
9179
    #
9180
    #
9181
    if ( $put_LD_LIBRARY_PATH )
9182
    {
343 dpurdie 9183
        MakePrint( "export LD_LIBRARY_PATH\n" );
261 dpurdie 9184
    }
227 dpurdie 9185
 
261 dpurdie 9186
    if ( $put_PATH )
9187
    {
343 dpurdie 9188
        MakePrint( "Path := \$(PATH)\n" );
9189
        MakePrint( "export PATH Path\n" );
261 dpurdie 9190
    }
227 dpurdie 9191
 
9192
#-------------------------------------------------------------------------------
9193
#   
9194
#
261 dpurdie 9195
    MakeHeader ("Perl Module Search Path",
9196
                "Extend the PERL5LIB seen by invocations of perl");
227 dpurdie 9197
 
261 dpurdie 9198
    my $perl_module_found;
9199
    for my $path ( ToolExtensionPaths() )
227 dpurdie 9200
    {
6276 dpurdie 9201
        if (my @results =  glob( "$path/*.pm"))
261 dpurdie 9202
        {
6276 dpurdie 9203
            MakePrint( "PERL5LIB := $path$::ScmPathSep\$(PERL5LIB)\n" );
261 dpurdie 9204
            $perl_module_found = 1;
9205
        }
227 dpurdie 9206
    }
261 dpurdie 9207
    if ( $perl_module_found  )
9208
    {
227 dpurdie 9209
    MakePrint( "export PERL5LIB\n" );
261 dpurdie 9210
    }
227 dpurdie 9211
 
261 dpurdie 9212
#-------------------------------------------------------------------------------
227 dpurdie 9213
#   
9214
#
261 dpurdie 9215
    MakeHeader ("Include Search Paths",
367 dpurdie 9216
                "Package Include Paths for header files and libraries" );
227 dpurdie 9217
 
6177 dpurdie 9218
    MakeDefEntry( 'PINCDIRS'  , '=', '# includes');
9219
    MakeDefEntry( 'PINCDIRS_INTERFACE', '=', '# Interface includes');
9220
    MakeDefEntry( 'PINCDIRS_LOCAL', '=', '# Local includes');
9221
    MakeDefEntry( 'PLIBDIRS'  , '=', '# libraries');
9222
    MakeDefEntry( 'PLIBDIRS_INTERFACE', '=', '# Interface libraries');
9223
    MakeDefEntry( 'PLIBDIRS_LOCAL', '=', '# Local libraries');
367 dpurdie 9224
 
9225
    for my $package (@{$::ScmBuildPkgRules{$ScmPlatform} })
9226
    {
9227
        #
9228
        #   Skip the pseudo package that encapsulates the interface
9229
        #   directory. Currently the makefiles do this in a different
9230
        #   manner - to be resolved
9231
        #
9232
        #   Just comment out the lines so that the data is visible
9233
        #   Its a hint to make use of the data
9234
        #
9235
        my $prefix = '';
6177 dpurdie 9236
        my $suffix = '';
367 dpurdie 9237
        $prefix = '# ' if ( $package->{'TYPE'} eq 'build' );
9238
 
6177 dpurdie 9239
        #
9240
        #   The interface directory is a little bit different
9241
        #
9242
        my ($name,$base);
9243
        if ( $package->{'TYPE'} eq 'interface' ) {
9244
            $base = '$(INTERFACEDIR)';
9245
            $name = 'Interface Directory';
9246
            $suffix = '_INTERFACE';
9247
        } else {
9248
            $name = $package->{'NAME'} . '/' . $package->{'VERSION'};
9249
            $base = $package->{'ROOT'};
9250
        }
367 dpurdie 9251
 
1329 dpurdie 9252
        my @doc;
9253
        push (@doc, "From: $base");
9254
        push (@doc, 'BuildPkgArchive via Interface' )if $package->{'TYPE'} eq 'build' ;
367 dpurdie 9255
 
1329 dpurdie 9256
        MakeHeader ("Source: $name", @doc);
9257
 
367 dpurdie 9258
        #
9259
        #   List include and library directories
9260
        #   Note: Need the True Path for windows.
9261
        #       Some makefile functions (wildcard) only work as expected
9262
        #       if the case of the pathname is correct. Really only a problem
6177 dpurdie 9263
        #       with badly formed legacy packages where the Windows user
367 dpurdie 9264
        #       guessed at the package format.
9265
        #
9266
        #       The conversion to a TruePath is done when ScmBuildPkgRules
6177 dpurdie 9267
        #       is created. Create once, use many time.
367 dpurdie 9268
        #
6177 dpurdie 9269
        for my $type (qw (PINCDIRS PLIBDIRS) ) {
9270
            for my $path ( @{$package->{$type}} ) {
9271
                MakeDefEntry ( "$prefix$type$suffix", "+=", $base . $path);
367 dpurdie 9272
            }
9273
        }
9274
    }
9275
 
6177 dpurdie 9276
    #
9277
    #   Local Paths
9278
    #   These are a little bit special
9279
    #
9280
    MakeHeader ('Source: Local',  'From: Package Local');
9281
 
9282
    sub MakeLocalPaths 
9283
    {
9284
        my ($name, $root, $addRoot) = @_;
9285
        my @pathlist;
9286
 
9287
        foreach my $tag ( $ScmPlatform, $ScmProduct, $ScmTarget ) {
9288
            UniquePush( \@pathlist, "$root/$tag" ) if ( $tag );
9289
        }
9290
 
9291
        #   Add the root directory too
9292
        UniquePush( \@pathlist, $root) if $addRoot;
9293
 
9294
        MakeDefEntry ( $name , "+=", \@pathlist);
9295
    }
9296
 
9297
    MakeLocalPaths ( 'PINCDIRS_LOCAL', '$(INCDIR_LOCAL)', 1 );
9298
    MakeLocalPaths ( 'PLIBDIRS_LOCAL', '$(LIBDIR_LOCAL)', 0 );
9299
 
9300
 
367 dpurdie 9301
#-------------------------------------------------------------------------------
9302
#   
9303
#
9304
    MakeHeader ("Include Search Paths",
9305
                "Local Include Paths",
9306
                " LINKDIRS - Local include search path (short)",
9307
                " INCDIRS  - Include search path (complete)",
9308
                " NODEPDIRS - ",
9309
                " SRCDIRS - ",
9310
                " LIBDIRS - Library search path",
9311
 
9312
                );
9313
 
227 dpurdie 9314
    # Include search path
9315
    #
9316
    #   user-local
367 dpurdie 9317
    #   local
9318
    #   interface
9319
    #       BuildPkgArchive
9320
    #       LinkPkgArchive
227 dpurdie 9321
    #   user-global
9322
    #
9323
 
6177 dpurdie 9324
    MakeDefEntry ( "\nLINCDIRS",    "= ", \@L_INCDIRS );                    # .. Local
9325
    MakeDefEntry ( "LINCDIRS",      "+=", '$(PINCDIRS_LOCAL)');             # .. Sandbox local
9326
    MakeDefEntry ( "LINCDIRS",      "+=", '$(PINCDIRS_INTERFACE)');         # .. Sandbox interface
9327
    MakeDefEntry ( "LINCDIRS",      "+=", \@G_INCDIRS );                    # .. Global
227 dpurdie 9328
 
6177 dpurdie 9329
    MakeDefEntry ( "INCDIRS",  "= ", '$(LINCDIRS)' );                       # Local
9330
    MakeDefEntry ( "INCDIRS",  "+=", '$(PINCDIRS)' );                       # Package
9331
    MakeDefEntry ( "LINCDIRS", "+=", \@S_INCDIRS );                         # System
227 dpurdie 9332
 
9333
    # Source search path
9334
 
261 dpurdie 9335
    MakeDefEntry( "\nNODEPDIRS",        "=", \@NODEPDIRS );
227 dpurdie 9336
 
6177 dpurdie 9337
    MakeDefEntry( "\nSRCDIRS","= "  , [ @L_SRCDIRS, @G_SRCDIRS ] );         # Local
9338
    MakeDefEntry ( "SRCDIRS", "+=" , '$(PINCDIRS)' );                       # Package
9339
    MakeDefEntry ( "SRCDIRS", "+=" , \@S_INCDIRS );                         # System
227 dpurdie 9340
 
9341
    # Library search path
9342
    #
9343
    #   user-local
367 dpurdie 9344
    #   local
9345
    #   interface
9346
    #       BuildPkgArchive
9347
    #       LinkPkgArchive
227 dpurdie 9348
    #   user-global
6177 dpurdie 9349
    #   
9350
    #   Kludge Note:
9351
    #       The LIBDIRS path needs an element with a directory seperator in it
9352
    #       Needed by (broken) cmdfile o determine the file seperator to use
9353
    #       
227 dpurdie 9354
 
367 dpurdie 9355
    MakeDefEntry( "\nLIBDIRS",  "= ", '$(LIBDIR)' );                    # User Local
261 dpurdie 9356
    MakeDefEntry( "LIBDIRS",    "+=", \@L_LIBDIRS );                    # Local
6177 dpurdie 9357
    MakeDefEntry( "LIBDIRS",    "+=", '$(PLIBDIRS_LOCAL)' );            # Sandbox/local
9358
    MakeDefEntry( "LIBDIRS",    "+=", '$(PLIBDIRS_INTERFACE)' );        # Sandbox/interface
9359
    MakeDefEntry( "LIBDIRS",    "+=", '$(LIBDIR_INTERFACE)' );          # Kludge. See note above
261 dpurdie 9360
    MakeDefEntry( "LIBDIRS",    "+=", \@G_LIBDIRS );                    # Global
367 dpurdie 9361
    MakeDefEntry( "LIBDIRS",    "+=", '$(PLIBDIRS)' );                  # Package
261 dpurdie 9362
    MakeDefEntry( "LIBDIRS",    "+=", \@S_LIBDIRS );                    # System
227 dpurdie 9363
 
9364
#-------------------------------------------------------------------------------
9365
#
9366
#   Subdir creation and deletion
9367
#   Creation is done on the fly
9368
#   Deletion is done AFTER the toolset functions have been invoked to create the
9369
#   build artifacts so that the toolsets can create directories too
9370
 
9371
    MakeHeader ("Subdir creation");
9372
    CreateMkdirRules();
6177 dpurdie 9373
    MkdirRule( '$(OBJDIR)', 'OBJDIR', '--Extra=depend,depend.err' );    # Object build directory
2429 dpurdie 9374
    MkdirRule( '$(OBJDIR)/'.$_ ) foreach (@SHLIBS);                     # Shared library build directory
9375
    MkdirRule( '$(LIBDIR)', 'LIBDIR' );                                 # Library directory
9376
    MkdirRule( '$(BINDIR)', 'BINDIR' );                                 # Binary directory
227 dpurdie 9377
 
261 dpurdie 9378
    #
9379
    #   Create a directory for library merge tool to work within
9380
    #
9381
    MkdirRule( "\$(MLIBDIR)", 'MLIBDIR', '--Path=$(GBE_PLATFORM).MRG', '--RemoveAll' ) if (@MLIBS);
9382
 
227 dpurdie 9383
#-------------------------------------------------------------------------------
9384
#   Generate rules and recipes to create all the toolset specific parts
9385
#   This is done fairly early to allow the toolsets to extend various
9386
#   definitions that may be used later in the makefile construction
9387
#
9388
    MakeHeader ("Construct Programs");
9389
 
9390
    foreach my $i ( @PROGS )
9391
    {
289 dpurdie 9392
        my $pProg = $PROGS->Get($i);
9393
        my $pArgs = $pProg->getItems('ARGS');
9394
        my $pObjs = $pProg->getItems('OBJS');
9395
        my $pLibs = $pProg->getItems('LIBS');
227 dpurdie 9396
 
289 dpurdie 9397
        #
9398
        #   Create a list of program object files
9399
        #
9400
        push @PROGOBJS, @$pObjs;
227 dpurdie 9401
 
9402
        MakePrint( "#---- (${i})\n\n" );
9403
        if ( $ScmToolsetProgDependancies )
9404
        {
261 dpurdie 9405
            #
9406
            #   Original style Prog Interface
271 dpurdie 9407
            #   Write some dependency information here and some in the toolset
9408
            #   Problems:
9409
            #       1) Errors in library dependency generation will be
9410
            #          reported after all the object files have been created
9411
            #          Thus the error message and the make-stop are seperated
9412
            #          by many,many lines of output. This makes it difficult
9413
            #          to see the error.
261 dpurdie 9414
            #
271 dpurdie 9415
            #       2) Lack of Flexability
9416
            #
293 dpurdie 9417
            MakeEntry( "\$(BINDIR)/$i$::exe: ", "", "\\\n\t\t", ".$::o ", @$pObjs );
227 dpurdie 9418
        }
9419
        else
9420
        {
261 dpurdie 9421
            #
9422
            #   New Style Prog Interface
9423
            #   The toolset does it all
9424
            #
9425
            #   Flag the progam packaging as a placeholder.
9426
            #   The toolset will replace/update it.
9427
            #
227 dpurdie 9428
            PackageProgRemoveFiles( $i );
9429
        }
9430
 
289 dpurdie 9431
        $if->LD    ( $i, $pArgs, $pObjs, $pLibs );
9432
        $if->LDLINT( $i, $pArgs, $pObjs, $pLibs );
227 dpurdie 9433
    }
9434
 
9435
#-------------------------------------------------------------------------------
9436
#   
9437
#
9438
    MakeHeader ("Construct Test Programs");
289 dpurdie 9439
    foreach my $i ( @TESTPROGS )
227 dpurdie 9440
    {
289 dpurdie 9441
        my $pProg = $TESTPROGS->Get($i);
9442
        my $pArgs = $pProg->getItems('ARGS');
9443
        my $pObjs = $pProg->getItems('OBJS');
9444
        my $pLibs = $pProg->getItems('LIBS');
227 dpurdie 9445
 
289 dpurdie 9446
        #
9447
        #   Create a list of program object files
9448
        #
9449
        push @TESTPROGOBJS, @$pObjs;
9450
 
227 dpurdie 9451
        MakePrint( "#---- (${i})\n\n" );
9452
        if ( $ScmToolsetProgDependancies )
9453
        {
293 dpurdie 9454
            MakeEntry( "\$(BINDIR)/$i$::exe: ", "", "\\\n\t\t", ".$::o ", @$pObjs );
227 dpurdie 9455
        }
9456
        else
9457
        {
9458
            PackageProgRemoveFiles( $i );
9459
        }
9460
 
289 dpurdie 9461
        $if->LD    ( $i, $pArgs, $pObjs, $pLibs );
9462
        $if->LDLINT( $i, $pArgs, $pObjs, $pLibs );
227 dpurdie 9463
    }
9464
 
9465
#-------------------------------------------------------------------------------
9466
#
9467
#
9468
    MakeHeader ("Transfer Scripts to BINDIR");
9469
    foreach my $i ( sort ( values %SCRIPTS ))
9470
    {
9471
        my $tname = "\$(BINDIR)/" . StripDir( $i );
9472
 
9473
 
9474
        MakePrint( "$i:\t\tmakefile.pl\n" .
6177 dpurdie 9475
            "\t\$(XX_PRE)if [ ! -f \"$i\" ]; then echo 'Script [$i] not found'; exit 2; fi\n\n" );
227 dpurdie 9476
 
9477
        #
9478
        #   Create a rule to copy the script into the BIN directory
9479
        #   Mark the script as executable - It can't hurt and its there
9480
        #   to be run as part of a test.
9481
        #
9482
        MakePrint "$tname:\t\$(GBE_BINDIR) $i\n" .
9483
                  "\t\$(XX_PRE)\$(cp) -f $i $tname\n" .
9484
                  "\t\$(XX_PRE)\$(chmod) -f +wx $tname\n\n"
9485
    }
9486
 
9487
#-------------------------------------------------------------------------------
9488
#   
9489
#
9490
    MakeHeader ("Construct Libraries");
9491
    foreach my $i ( @LIBS )
9492
    {
289 dpurdie 9493
        my $pLib  = $LIBS->Get($i);
9494
        my $pArgs = $pLib->getItems('ARGS');
9495
        my $pObjs = $pLib->getItems('OBJS');
227 dpurdie 9496
 
363 dpurdie 9497
        unless ( $ScmToolsetNillLibSrc )
9498
        {
9499
            Error ("Library has no component objects: $i")
9500
                if ( scalar @$pObjs <= 0 );
9501
        }
299 dpurdie 9502
 
227 dpurdie 9503
        MakePrint "#---- (${i})\n\n";
289 dpurdie 9504
        $if->AR(     $i, $pArgs, $pObjs, $pLib);
9505
        $if->ARLINT( $i, $pArgs, $pObjs, $pLib );
227 dpurdie 9506
    }
9507
 
289 dpurdie 9508
#-------------------------------------------------------------------------------
9509
#   
9510
#
9511
    MakeHeader ("Construct Merged Libraries");
227 dpurdie 9512
    sub MlibEntry
9513
    {
289 dpurdie 9514
        my( $mlib, $plib, $pLibs ) = @_;
227 dpurdie 9515
        my @flib;
9516
 
289 dpurdie 9517
        MakePrint '$(LIBDIR)/' . GenLibName($mlib) . ":";
9518
        foreach my $lib ( @$pLibs )
227 dpurdie 9519
        {
289 dpurdie 9520
            #
9521
            #   Each library name may contains one embedded option which
9522
            #   specifies the source directory
9523
            #       libname[,--Option | BaseSubdir]
9524
            #
227 dpurdie 9525
            my ($slib, $sdir) = split( ',', $lib );
343 dpurdie 9526
            my $mode;
227 dpurdie 9527
 
9528
            #
283 dpurdie 9529
            #   By default the librares are pulled from LOCAL unless the
9530
            #   library is built in this directory, in which case it will
289 dpurdie 9531
            #   be used.
227 dpurdie 9532
            #
289 dpurdie 9533
            $sdir = ( $LIBS->Get($slib) ) ? '--Here' : '--Local'
9534
                unless ( $sdir );
227 dpurdie 9535
 
9536
            #
9537
            #   --Interface     - Pull library from the interface directory
9538
            #   --Local         - Pull library from the local directory
9539
            #   --SubDir=xxxx   - Pull library from specified subdirectory
283 dpurdie 9540
            #   --Here          - Pull from local directory if built locally
227 dpurdie 9541
            #   otherwise       - Pull library from specified subdirectory
9542
            #
9543
            if ($sdir eq '--Interface') {
9544
                $sdir = '$(LIBDIR_INTERFACE)/$(GBE_PLATFORM)';
9545
 
343 dpurdie 9546
 
9547
            } elsif ($sdir eq '--InterfacePlain') {
9548
                $sdir = '$(LIBDIR_INTERFACE)/$(GBE_PLATFORM)';
9549
                $mode = 1;
9550
 
227 dpurdie 9551
            } elsif ( $sdir eq '--Local') {
9552
                $sdir = $PackageInfo{'Lib'}{'IBase'} .  # Base of Installed libs
9553
                        $PackageInfo{'Lib'}{'Dir'};     # Default subdir
9554
 
9555
            } elsif ( $sdir =~ m~^--SubDir=(.*)~ ) {
9556
                $sdir = $1 . '/$(LIBDIR)';
9557
 
283 dpurdie 9558
            } elsif ( $sdir eq '--Here') {
9559
                $sdir = '$(LIBDIR)';
9560
 
227 dpurdie 9561
            } else {
9562
                $sdir .= '/$(LIBDIR)';
9563
            }
9564
 
343 dpurdie 9565
            MakePrint " \\\n\t\t${sdir}/" . GenLibName($slib, $mode);
227 dpurdie 9566
            push @flib, "${sdir}/${slib}";
9567
        }
289 dpurdie 9568
        return \@flib;
227 dpurdie 9569
    }
9570
 
9571
    foreach my $i ( @MLIBS )
9572
    {
289 dpurdie 9573
        my $pLib  = $MLIBS->Get($i);
9574
        my $pArgs = $pLib->getItems('ARGS');
9575
        my $pLibs = $pLib->getItems('LIBS');
227 dpurdie 9576
 
261 dpurdie 9577
        MakePrint "#---- (${i})\n\n";
9578
 
227 dpurdie 9579
        unless ( defined &ToolsetARMerge )
9580
        {
9581
            Warning( "Merging of libraries not supported in this toolset yet" );
9582
            Warning( "MergeLibrary: \"$i\" will not be created" );
9583
        }
9584
        else
9585
        {
9586
            #
9587
            #   Create the dependency rule
9588
            #       Target library : source library list
9589
            #           Recipe - generated by the toolset
9590
            #
289 dpurdie 9591
            foreach ( @$pArgs )
227 dpurdie 9592
            {
9593
                Warning( "Ignoring unknown argument to MergeLibrary. $_" );
9594
            }
289 dpurdie 9595
            $pLibs = MlibEntry( $i, $pLib, $pLibs );
9596
            $if->ARMerge( $i, $pArgs, $pLibs, $pLib );
227 dpurdie 9597
        }
9598
    }
9599
 
289 dpurdie 9600
#-------------------------------------------------------------------------------
9601
#   
9602
#
9603
    MakeHeader ("Construct Shared Libraries");
339 dpurdie 9604
 
227 dpurdie 9605
    foreach my $i ( @SHLIBS )
9606
    {
289 dpurdie 9607
        my $pShlib  = $SHLIBS->Get($i);
9608
        my $pArgs = $pShlib->getItems('ARGS');
9609
        my $pObjs = $pShlib->getItems('OBJS');
9610
        my $pLibs = $pShlib->getItems('LIBS');
9611
        my $version = $pShlib->{VERSION};
227 dpurdie 9612
 
289 dpurdie 9613
        $if->SHLD    ( $i, $pArgs, $pObjs, $pLibs, $version );
9614
        $if->SHLDLINT( $i, $pArgs, $pObjs, $pLibs, $version );
227 dpurdie 9615
    }
9616
 
9617
#-------------------------------------------------------------------------------
9618
#   Construct Objects
9619
#   For each object within OBJSOURCE construct the following:
9620
#
9621
#   $(OBJDIR)/object-name:     source-name [makefile]
9622
#       Toolset ...
9623
#
9624
#   
9625
#
9626
    MakeHeader ("Construct Objects");
371 dpurdie 9627
 
227 dpurdie 9628
    foreach my $i ( sort keys %OBJSOURCE )
9629
    {
9630
        my( $src, $sname, $ext, $type, @args );
9631
 
9632
        $src  = $OBJSOURCE{ $i };
9633
        $sname = StripDir( $src );
9634
        $ext  = StripFile( $src );
9635
        $ext = lc($ext)
9636
            if ( $::ScmHost ne "Unix" );
381 dpurdie 9637
        $type = ($ScmSourceTypes{ $ext } || '')
227 dpurdie 9638
            unless (( $type = $SRC_TYPE{ $sname }) );
9639
 
9640
        #
9641
        #   Object source is an object file
9642
        #   No need the generate the object, just create makefile rule
261 dpurdie 9643
        #   [ddp] Not too sure how we get here
227 dpurdie 9644
        #
9645
        if ( $ext eq ".$::o" )
9646
        {
9647
            MakePrint "$src:";
261 dpurdie 9648
            MakePrint " \$(SCM_MAKEFILE)";
227 dpurdie 9649
            MakeNewLine();
9650
            next;
9651
        }
9652
 
9653
        #
9654
        #   Need to create object file
9655
        #
9656
        @args = split( /$;/, $SRC_ARGS{ StripDir( $sname ) } )
9657
            if $SRC_ARGS{ $sname };
9658
 
9659
        push( @args, "--Shared" )
9660
            if ( exists $SHOBJ_LIB{$i} );
9661
 
9662
        #
9663
        #   Convert relative paths to absolute paths if required by the
9664
        #   toolset. Some compilers need ABS paths to generate nice debug
9665
        #   information.
9666
        #
9667
        $src = AbsPath($src)
9668
            if ( $UseAbsObjects );
9669
 
9670
        #
9671
        #   Extract any user specified dependancies
261 dpurdie 9672
        #   These will be added to the dependency list
227 dpurdie 9673
        #
9674
        my @dlist;
9675
        @dlist = split( /$;/, $SRC_DEPEND{$sname} )
9676
            if ( exists $SRC_DEPEND{$sname} );
9677
 
261 dpurdie 9678
        #
9679
        #   Create the dependency part of the object rule
9680
        #   The source file MUST be the first dependent recipes
9681
        #   may assume that $< is the name source file
9682
        #
9683
        MakeEntry( "\$(OBJDIR)/$i.$::o: $src \$(SCM_MAKEFILE)", "", " \\\n\t", "", @dlist );
227 dpurdie 9684
 
9685
        if ( $type eq ".c" ) {
9686
            $if->CC(  $src, $i, \@args );
261 dpurdie 9687
 
227 dpurdie 9688
        } elsif ( $type eq ".cc" ) {
9689
            $if->CXX( $src, $i, \@args );
261 dpurdie 9690
 
227 dpurdie 9691
        } elsif ( $type eq ".asm" ) {
9692
            $if->AS( $src, $i, \@args );
261 dpurdie 9693
 
227 dpurdie 9694
        } else {
9695
            $if->EXT( $src, $i, \@args ) ||
9696
                Warning( "Don't know how to build '$ext' images' for $src, $i" );
9697
            MakeNewLine();
9698
        }
9699
    }
9700
 
9701
#-------------------------------------------------------------------------------
9702
#   Construct Projects
9703
#   Construct toolset specific projects
9704
#
9705
    MakeHeader ("Construct Projects");
9706
    while ( my($project, $entry) = each %PROJECTS)
9707
    {
9708
        $if->PROJECT( $entry );
9709
    }
9710
 
9711
#-------------------------------------------------------------------------------
4761 dpurdie 9712
#   Automated tests
9713
#
9714
    MakeHeader ("Automated tests");
9715
 
9716
    my $idx = 0;
9717
    my @copy_set = ();
9718
 
227 dpurdie 9719
    foreach my $pEntry ( @TESTS_TO_RUN )
9720
    {                                           # Foreach test
9721
        $idx++;
9722
        $pEntry->{'index'} = $idx;
9723
        $pEntry->{'test_name'} = "run_test_$idx";
5708 dpurdie 9724
        $pEntry->{'echoname'} = $pEntry->{'utfname'} || '';  
4781 dpurdie 9725
        $pEntry->{'utfname'} = $pEntry->{'test_name'} unless defined $pEntry->{'utfname'};  
227 dpurdie 9726
 
9727
        #
9728
        #   If the test is being run within a 'FrameWork' then the underlying
9729
        #   toolset must instantiate the frame work.
9730
        #
9731
        #   This may change. Perhaps frameworks shouldn't be a part of the
9732
        #   toolset. Perhaps they should be standalone. May change
9733
        #
9734
        if ( $pEntry->{framework} )
9735
        {
9736
            $if->TESTFRAMEWORK( $pEntry );
9737
        }
9738
 
9739
        #
9740
        #   Create a rule to run the test
9741
        #
9742
 
9743
        my $tdir_alias = $pEntry->{'testdir'};
9744
        my $tdir = '$(' . $tdir_alias . ')';
9745
 
9746
        my $test_name = $pEntry->{'test_name'};
4996 dpurdie 9747
        push @TESTPROJECT_TO_URUN, $test_name;
4501 dpurdie 9748
        push @TESTPROJECT_TO_ARUN, $test_name if     ($pEntry->{'auto'} );
227 dpurdie 9749
 
9750
        my $tprog = $tdir . '/' . StripDir( $pEntry->{'prog'} );
5695 dpurdie 9751
 
9752
        #
9753
        #   Determine the maximum time that the automated test should run
9754
        #       Default is 30 minutes
9755
        #   Non-auto tests are not time limited
9756
        #       
9757
        my $timeout = '';
5848 dpurdie 9758
        if ($pEntry->{'auto'})
5695 dpurdie 9759
        {
5848 dpurdie 9760
            $timeout = 'timeout -Time:' . ($pEntry->{'maxtime'} || '30m') . ' ';
5695 dpurdie 9761
        }
227 dpurdie 9762
 
9763
        my $me = MakeEntry::New( *MAKEFILE, $test_name, '--Phony' );
4781 dpurdie 9764
 
9765
        #
4996 dpurdie 9766
        #   Export GBE_UTF... for the duration of the test
4781 dpurdie 9767
        #
9768
        $me->AddDefn('export GBE_UTFNAME', $pEntry->{'utfname'});
9769
        $me->AddDefn('export GBE_UTFUID', '$(MAKEFILEUID)' . '_' . $pEntry->{'index'});
4996 dpurdie 9770
        $me->AddDefn('export GBE_UTFFILE','$(UTFDIR_PKG)/$(GBE_PLATFORM)-$(GBE_TYPE)-$(GBE_UTFUID)' . '.xml');
4781 dpurdie 9771
 
5986 dpurdie 9772
        # Workaround for dirsep under windows when being wrapped in a timeout
9773
        $me->AddDefn('dirsep', '$(dirsep)$(dirsep)') if ($timeout && ($::ScmHost ne "Unix"));
9774
 
227 dpurdie 9775
        $me->AddDependancy( "\$(GBE_$tdir_alias)" );
9776
        $me->AddDependancy( "\$(INTERFACEDIR)/set_$::ScmPlatform.sh" );
9777
        $me->AddDependancy( $tprog ) if $pEntry->{'copyprog'};
9778
        $me->AddDependancy( @{ $pEntry->{'copyin' } } );
9779
        $me->AddDependancy( map { $tdir . '/' . StripDir($_) } @{ $pEntry->{'copyonce' } } );
9780
        $me->AddDependancy( @{ $pEntry->{'preq'} } );
9781
        $me->RecipePrefix ('$(XX_PRE)');
5708 dpurdie 9782
        $me->RecipeWrapper( $timeout . 'sh -c \'', '\'') if $timeout;
9783
        $me->RecipeComment( "------ Running test [$idx] $pEntry->{'echoname'} ..." );
227 dpurdie 9784
 
9785
        #
4996 dpurdie 9786
        #   Create package utfResults directory
9787
        #       Simplify use of the file
9788
        #
9789
        $me->AddShellRecipe ( 'mkdir -p $(UTFDIR_PKG)' );
9790
 
9791
        #
227 dpurdie 9792
        #   Extend the PATH seen by the script to include the local/bin directory
9793
        #   Allows programs and tests that have been created elsewhere in the component
9794
        #   to be accessed within the script.
9795
        #
9796
        $me->AddShellRecipe ( ". \$(INTERFACEDIR)/set_$::ScmPlatform.sh" );
9797
 
9798
        #
9799
        #   Copy in the files that we need
9800
        #
9801
        foreach my $file ( @{$pEntry->{'copyin'}} )
9802
        {
9803
            my $dst = $tdir . '/' . StripDir( $file );
9804
            UniquePush( \@COPYIN, $dst );
9805
            UniquePush( \@copy_set, $file );
9806
            $me->AddShellRecipe ( "\$(cp) -f $file $dst" );
9807
            $me->AddShellRecipe ( "\$(chmod) -f +wx $dst" );
9808
        }
9809
 
9810
        #
4778 dpurdie 9811
        #   Insert any FrameWork Recipe bits
227 dpurdie 9812
        #
9813
        $me->AddShellRecipe ( @{$pEntry->{'ShellRecipe'}} );
9814
 
4781 dpurdie 9815
        #
9816
        #   Insert command
5035 dpurdie 9817
        #       Save result code to a known file
4781 dpurdie 9818
        #
227 dpurdie 9819
        $me->AddShellRecipe ( "cd $tdir" );
9820
        $me->AddShellRecipe ( ["GBE_TYPE=\$(GBE_TYPE)",
9821
                               "GBE_HOST=\$(GBE_HOST)",
9822
                               "GBE_ROOT=\$(GBE_ROOT_ABS)",
4095 dpurdie 9823
                               "PATH=.\\$::ScmPathSep\$(BINDIR_LOCAL_PATH)\\$::ScmPathSep\$\$PATH",
5708 dpurdie 9824
                               $pEntry->{'command'},
227 dpurdie 9825
                               @{$pEntry->{'args'}},
5035 dpurdie 9826
                               ] , 
9827
                               'echo $$? > utf.$${GBE_UTFUID}.rc' );
9828
 
9829
        #
9830
        #   Create the basic command line for 'jats_runutf'
9831
        #       Use the simplistic 'internal' filter unless the user has provided one
9832
        #
9833
        my @cmdline;
9834
        push @cmdline, '--';
9835
        push @cmdline, '$(VERBOSE_OPT)';
9836
        push @cmdline, '-filter=' . ($pEntry->{'utfformat'} || 'internal');
9837
        push @cmdline, '-root=$(GBE_ROOT_ABS)' ;
9838
        push @cmdline, "-dir=$tdir";
9839
        push @cmdline, '-target=$(GBE_PLATFORM)';
9840
        push @cmdline, '-pkgdir=$(PKGDIR)';
9841
        push @cmdline, '-local=$(LOCALDIR)';
9842
        push @cmdline, '-interface=$(INTERFACEDIR)';
9843
        foreach my $entry (@{$pEntry->{'utfargs' }})
4778 dpurdie 9844
        {
5035 dpurdie 9845
            push @cmdline, '-arg=' . $entry;
4778 dpurdie 9846
        }
5035 dpurdie 9847
 
9848
        #
9849
        #   Insert commands to post process the test results according to the specified formatter
9850
        #
9851
        $me->NewSection     ();
9852
        $me->SectionIfDef   ('UTF_POSTPROCESS');
9853
        $me->RecipePrefix   ('$(XX_PRE)');
9854
        $me->AddRecipe      ( "\$(GBE_PERL) -Mjats_runutf -e processUtf " . join(" \\\n\t\t\t", @cmdline)  );
4778 dpurdie 9855
 
227 dpurdie 9856
        $me->Print();
9857
 
9858
 
9859
        #
9860
        #   Create entries to handle the copy-once files
9861
        #
9862
        foreach my $file ( @{ $pEntry->{'copyonce' } } )
9863
        {
9864
            my $tname = $tdir . '/' . StripDir($file);
9865
            my $me = MakeEntry::New( *MAKEFILE, $tname  );
9866
            $me->AddDependancy( $file );
9867
            $me->AddRecipe ( "\$(call CopyFile,CopyIn,$tname,$file,$tdir,)"  );
9868
            $me->Print();
9869
 
9870
            UniquePush( \@COPYIN, $tname );
9871
            UniquePush( \@copy_set, $file );
9872
 
9873
        }
9874
    }
9875
 
9876
    #
9877
    #   Generate sanity test for each copyin script
9878
    #   Simply to provide a nice error message for generated scripts
9879
    #   that do not exist at run-time
9880
    #
9881
    test_copy_in:
9882
    foreach my $i ( @copy_set )
9883
    {
9884
        next if ( $SCRIPTS{$i} );
9885
        foreach (  @SHLIB_TARGETS )
9886
        {
9887
            next test_copy_in if ( $i eq $_ );
9888
        }
9889
        MakePrint( "\n$i:\t\tmakefile.pl\n" .
6177 dpurdie 9890
            "\t\@if [ ! -f \"$i\" ]; then echo 'ERROR: CopyIn Script [$i] not found'; exit 2; fi\n" );
227 dpurdie 9891
    }
9892
 
261 dpurdie 9893
#-------------------------------------------------------------------------------
9894
#   Deploy rules
9895
#
9896
MakeHeader ("Deploy Rules");
227 dpurdie 9897
 
261 dpurdie 9898
print MAKEFILE <<EOF;
9899
.PHONY:		run_deploy
9900
EOF
227 dpurdie 9901
 
261 dpurdie 9902
#
9903
#   Build up the deployfile.pl command line from the available pieces
9904
#
9905
my $command_file = "";
9906
my @command_line;
9907
 
9908
if ( %DEPLOYPACKAGE )
9909
{
9910
    $command_file = $DEPLOYPACKAGE{'cmdfile'};
9911
 
9912
    push @command_line, "\$(XX_PRE)\$(GBE_PERL) -w $command_file";
9913
    push @command_line, "-r \"\$(GBE_ROOT)\"";
9914
    push @command_line, "-n \"$DEPLOYPACKAGE{'name'}\"";
9915
    push @command_line, "-d \"$DEPLOYPACKAGE{'dir'}\"";
9916
    push @command_line, "-v \"\$(BUILDVER)\"";
9917
    push @command_line, "-t \"\$(GBE_TYPE)\"";
9918
    push @command_line, "-o \"\$(BUILDPREVIOUSVER)\"";
9919
    push @command_line, "-m \"\$(GBE_PLATFORM)\"";
9920
    push @command_line, "-g \"\$(GBE_TARGET)\"";
9921
    push @command_line, "-k \"\$(GBE_PRODUCT)\""        if ( $ScmProduct );
9922
    push @command_line, "-p \"\$(DEPLOYPATCH)\""        if ( $ScmDeploymentPatch );
9923
 
9924
}
9925
 
9926
MakeEntry( "run_deploy:\t$command_file\n", "\n", "\t\t", " \\\n", @command_line );
9927
 
227 dpurdie 9928
#-------------------------------------------------------------------------------
261 dpurdie 9929
#   Custom Rules
9930
#
9931
    MakeHeader ("Custom Rules");
9932
    MakePrintList ( \@RULES );
9933
 
9934
#-------------------------------------------------------------------------------
9935
#   Generated Files
9936
#
9937
    MakeHeader ("Generated Files");
9938
    MakePrint ("\n.PHONY: phony_generate\n\n" );
9939
 
9940
    foreach my $i ( @GENERATE_FILES )
9941
    {
9942
        my $gen_tag = $i->{'index'};
6415 dpurdie 9943
        #
9944
        #   Generate user-provided recipe names to allow the rule to be called by name.
9945
        #
9946
        my $recipeTag = $i->{'recipeTag'} || '';
9947
        my $recipeName = '';
9948
        my $recipeCleanName = '';
261 dpurdie 9949
 
6415 dpurdie 9950
        if ($recipeTag) {
9951
            $recipeName = $recipeTag;
9952
            $recipeCleanName = 'clean_' . $recipeTag;
9953
 
9954
            # for 'jats make help'
9955
            $ScmRecipeTags{$recipeTag} = defined $i->{'clean'} ? 1 : 0;
9956
 
9957
            MakePrint( ".PHONY: $recipeName $recipeCleanName\n"); 
9958
        }
9959
 
261 dpurdie 9960
        #
263 dpurdie 9961
        #   If predelete is enabled, then create a list of files to delete
9962
        #
9963
        if ( $i->{'predelete'}  )
9964
        {
9965
            MakeDefEntry( "generate_gen_$gen_tag", "=",  $i->{'gen'} );
9966
            MakePrint("\n")
9967
        }
9968
 
9969
 
9970
        #
261 dpurdie 9971
        #   Generate the basic generate rule and recipe
9972
        #   together with the prerequisites
9973
        #
6415 dpurdie 9974
        MakeEntry ( "", ":", "", " ", @{$i->{'gen'}}, $recipeName );
261 dpurdie 9975
 
9976
        unless ( $i->{'clean'} && $i->{'shell'} )
9977
        {
9978
            MakeEntry ( "", "", " \\\n\t\t", "", @{$i->{'preq'}} );
9979
            MakeEntry ( "", "", " \\\n\t\t", "", "phony_generate" ) if $i->{'preq_sus'};
9980
            MakeEntry ( "", "", " \\\n\t\t", "", "\$(SCM_MAKEFILE)" );
9981
 
6177 dpurdie 9982
            MakePrint ("\n\t" . "\@\$(echo) '[$i->{'text'}] generating..'" );
263 dpurdie 9983
            if ( $i->{'predelete'}  )
9984
            {
9985
                MakePrint ("\n\t" . "\$(XX_PRE)\$(call RmFiles,generate_gen_$gen_tag)" );
9986
            }
261 dpurdie 9987
            MakePrint ("\n\t" . "\$(XX_PRE)\$(call generate_$gen_tag,)" );
9988
        }
9989
 
9990
        #
9991
        #   Generate 'clean' rules and recipes
9992
        #
9993
        if ( $i->{'clean'} )
9994
        {
9995
            MakePrint ("\n\nPHONY: clean_generate_$gen_tag" );
6415 dpurdie 9996
            MakePrint ("\nclean_generate_$gen_tag $recipeCleanName:" );
343 dpurdie 9997
            MakePrint ("\n\t" . "\$(XX_PRE)-\$(call generate_$gen_tag,$i->{'clean'})" );
261 dpurdie 9998
        }
9999
 
10000
        #
10001
        #   Define a function to contain the body of the generation call
10002
        #   The first argument will be a 'clean' argument
10003
        #
10004
        MakePrint ("\n\ndefine generate_$gen_tag" );
10005
        if ( $i->{'shell'} )
10006
        {
10007
            MakeEntry ("\n\t(" , "\\\n\t)\n", " \\\n\t", ";" , @{$i->{'toolargs'}} );
10008
        }
10009
        else
10010
        {
10011
            MakeEntry ("\n\t" . $i->{'tool'} . ' $1', "\n", " \\\n\t\t", "" , @{$i->{'toolargs'}} );
10012
        }
10013
        MakePrint ("endef\n\n" );
10014
    }
10015
 
10016
#-------------------------------------------------------------------------------
10017
#   Toolset Post Processing
10018
#   Allow the toolset to perform any post processing, before we finally write
10019
#   out any definitions.
10020
#
10021
#   We will not interprete any more user directives, but new stuff may get added
10022
#
10023
#
10024
MakeHeader ("Toolset Post Processing");
10025
$if->Postprocess();
10026
 
10027
################################################################################
10028
#   All interactions with the toolset are now complete
10029
#   All lists are now complete
10030
#
10031
#   Can now create internal definitions
10032
#   
10033
################################################################################
10034
 
10035
    #
10036
    #   Would be nice if this would work
10037
    #   Unfortunatelty we still need $if for the CCDEPENDS and CTAGS work
10038
    #   These must be defined AFTER the definitions
10039
    #
10040
    #   Ideally we should construct our makefile in sections
10041
    #   and then we can order the sections when we write them out
10042
    #
10043
#$if = 0;                            # Ensure the MakeIf class is not called
10044
                                     # If this file is modified
10045
 
10046
#-------------------------------------------------------------------------------
227 dpurdie 10047
#   Sources
10048
#
10049
MakeHeader  ( "Sources");
10050
MakeDefEntry( "CSRCS",      "=",  \@CSRCS );
10051
MakeDefEntry( "CXXSRCS",    "=",  \@CXXSRCS );
10052
MakeDefEntry( "ASSRCS",     "=",  \@ASSRCS );
10053
 
10054
#-------------------------------------------------------------------------------
10055
#   Generated, Installed and Packaged components
10056
#
10057
MakeHeader  ("Generated, Installed and Packaged components");
10058
MakeDefEntry( "INITS",           "=",  \@INITS )   if ( @INITS );
10059
MakeDefEntry( "GENERATED",       "=",  \@GENERATED ) if ( @GENERATED );
10060
MakeDefEntry( "GENERATED_NOTSRC","=",  \@GENERATED_NOTSRC ) if ( @GENERATED_NOTSRC );
10061
MakeDefEntry( "GENERATEDCLEAN",  "=",  CreateNameList( 'clean_generate_', '', ListCleanGenerated() ));
10062
MakeDefEntry( "INSTALL_HDRS",    "=",  \%INSTALL_HDRS ) if ( %INSTALL_HDRS );
10063
MakeDefEntry( "INSTALL_CLSS",    "=",  \%INSTALL_CLSS ) if ( %INSTALL_CLSS );
10064
MakeDefEntry( "OBJS",            "=", CreateNameList( '$(OBJDIR)/', ".$::o", \@OBJS) );
10065
MakeDefEntry( "SHOBJS",          "=", CreateNameList( '$(OBJDIR)/', ".$::o", \%SHOBJ_LIB ));
289 dpurdie 10066
MakeDefEntry( "PROGOBJS",        "=", CreateNameList( '', ".$::o", \@PROGOBJS ));
10067
MakeDefEntry( "TESTPROGOBJS",    "=", CreateNameList( '', ".$::o", \@TESTPROGOBJS ));
10068
MakeDefEntry( "LIBS",            "=", $LIBS->AllTargets() ) if ($::a);
10069
MakeDefEntry( "MLIBS",           "=", $MLIBS->AllTargets() ) if ($::a);
227 dpurdie 10070
MakeDefEntry( "SHNAMES",         "=", \@SHLIBS );
10071
MakeDefEntry( "SHDIRS",          "=", CreateNameList( '$(OBJDIR)/', "", \@SHLIBS ));
10072
MakeDefEntry( "SHLIBS",          "=", \@SHLIB_TARGETS );
10073
MakeDefEntry( "SCRIPTS",         "=", CreateNameList( '$(BINDIR)/', "", \%SCRIPTS ));
10074
MakeDefEntry( "COPYIN",          "=", \@COPYIN );
289 dpurdie 10075
MakeDefEntry( "PROGS",           "=", $PROGS->AllTargets() );
227 dpurdie 10076
MakeDefEntry( "PROGS_EXTRA",     "=", \@PROGS_EXTRA );
289 dpurdie 10077
MakeDefEntry( "TESTPROGS",       "=", $TESTPROGS->AllTargets());
227 dpurdie 10078
MakeDefEntry( "LINTLIBS",        "=", CreateNameList( 'lib_', '_lint', \@LINTLIBS ));
10079
MakeDefEntry( "LINTSHLIBS",      "=", CreateNameList( 'shlib_', '_lint', \@LINTSHLIBS ));
10080
MakeDefEntry( "LINTPROGS",       "=", CreateNameList( 'prog_', '_lint', \@PROGS ));
289 dpurdie 10081
MakeDefEntry( "LINTPROGS",      "+=", CreateNameList( 'prog_', '_lint', \@TESTPROGS ));
227 dpurdie 10082
MakeDefEntry( "PROJECTS",        "=", CreateNameList( 'Project_', '', ListGeneratedProjects(1) ));
10083
MakeDefEntry( "PROJECTSGEN",     "=", CreateNameList( 'Project_', '', ListGeneratedProjects(0) ));
10084
MakeDefEntry( "PROJECTSCLEAN",   "=", CreateNameList( 'ProjectClean_', '', \%PROJECTS ));
10085
 
4501 dpurdie 10086
MakeDefEntry( "UNITTESTS",       "=", \@TESTPROJECT_TO_URUN );
10087
MakeDefEntry( "AUTOUNITTESTS",   "=", \@TESTPROJECT_TO_ARUN );
10088
 
4778 dpurdie 10089
MakeDefEntry( "AUTOUNITTESTS_PRE",    "=", \@TOOLSET_UTF_PRE );
10090
MakeDefEntry( "AUTOUNITTESTS_POST",   "=", \@TOOLSET_UTF_POST );
10091
MakeDefEntry( "AUTOUNITTESTS_COLLATE","=", \@TOOLSET_UTF_COLLATE );
10092
 
10093
 
261 dpurdie 10094
MakeHeader ("Toolset components");
10095
MakeDefEntry( "USERGENERATED",        "=", \@USERGENERATED )    if ( @USERGENERATED );
10096
MakeDefEntry( "TOOLSETGENERATED",     "=", \@TOOLSETGENERATED ) if ( @TOOLSETGENERATED );
10097
MakeDefEntry( "TOOLSETOBJS",          "=", \@TOOLSETOBJS )      if ( @TOOLSETOBJS );
10098
MakeDefEntry( "TOOLSETLIBS",          "=", \@TOOLSETLIBS )      if ( @TOOLSETLIBS );
10099
MakeDefEntry( "TOOLSETPROGS",         "=", \@TOOLSETPROGS )     if ( @TOOLSETPROGS );
10100
MakeDefEntry( "TOOLSETDIRS",          "=", \@TOOLSETDIRS )      if ( @TOOLSETDIRS );
10101
MakeDefEntry( "TOOLSETDIRTREES",      "=", \@TOOLSETDIRTREES )  if ( @TOOLSETDIRTREES );
227 dpurdie 10102
 
10103
#--------- Determine compiler flag groups to use ----------------------------
10104
#
10105
#   Allows the compiler options to be controlled for both the debug and
10106
#   the production builds. Allows control over
10107
#       1) Optimisations
10108
#       2) Debug Information
10109
#
10110
MakeHeader ("Determine compiler flag groups to use");
10111
 
10112
print MAKEFILE <<EOF;
10113
 
10114
ifneq "\$(DEBUG)" "1"
10115
USE_OPTIMISE	:= \$(PROD_USE_OPTIMISE)
10116
USE_DEBUGINFO	:= \$(PROD_USE_DEBUGINFO)
10117
else
10118
USE_OPTIMISE	:= \$(DEBUG_USE_OPTIMISE)
10119
USE_DEBUGINFO	:= \$(DEBUG_USE_DEBUGINFO)
10120
endif
10121
 
10122
EOF
10123
 
261 dpurdie 10124
#-------------------------------------------------------------------------------
10125
#   Source browsing tools
10126
#
10127
MakeHeader ("Source browsing tools");
10128
    print MAKEFILE <<EOF;
10129
.PHONY:			ctags
10130
ctags:
10131
EOF
10132
    $if->CTAGS()
10133
        if (@CSRCS || @CXXSRCS);
227 dpurdie 10134
 
261 dpurdie 10135
#-------------------------------------------------------------------------------
10136
#   Depend
10137
#   If we are build C or C++ source files then create rules and recipes
10138
#   to invoke a dependency generator.
227 dpurdie 10139
#
261 dpurdie 10140
#   NODEPEND is used to disable, at make-time, the dependency generation
10141
#   and inclusion process.
10142
#
10143
#
10144
MakeHeader ("Depend");
6133 dpurdie 10145
if ($::o && (@CSRCS || @CXXSRCS) && $ScmNotGeneric)
261 dpurdie 10146
{
10147
    $ScmDependTags = 1;
10148
    print MAKEFILE <<EOF;
10149
depend:			\$(OBJDIR)/depend
10150
 
10151
\$(OBJDIR)/depend:	\$(SCM_MAKEFILE) \$(GBE_OBJDIR)
10152
\$(OBJDIR)/depend:	\$(CSRCS) \$(CXXSRCS)
10153
ifeq (\$(NODEPEND),0)
6177 dpurdie 10154
	\@echo '[\$@] Doing a make depend..'
261 dpurdie 10155
	-\$(XX_PRE)\$(rm) -f \$(OBJDIR)/depend
10156
EOF
10157
    $if->CCDepend( "\$(OBJDIR)/depend", "\$(CSRCS)" )
10158
        if ( @CSRCS );
10159
    $if->CXXDepend( "\$(OBJDIR)/depend", "\$(CXXSRCS)" )
10160
        if ( @CXXSRCS );
10161
    MakePrint
10162
        "\t-\@\$(touch) -f \$(OBJDIR)/depend\n";
10163
    print MAKEFILE <<EOF;
10164
else
6177 dpurdie 10165
	\@echo '[\$@] Skipping make depend..'
261 dpurdie 10166
	-\$(XX_PRE)\$(rm) -f \$(OBJDIR)/depend
10167
endif
10168
EOF
10169
}
10170
else
10171
{
10172
    print MAKEFILE <<EOF;
10173
depend:
10174
EOF
10175
}
10176
 
10177
#
10178
#   Rule to unmake the depend file
2429 dpurdie 10179
#       No longer neeed.
10180
#       The file is deleted as a part of the OBJDIR cleanup
261 dpurdie 10181
#
10182
    print MAKEFILE <<EOF;
10183
 
10184
undepend:
10185
EOF
10186
 
10187
#--------- IFLAG Documentation -------------------------------------------------
10188
#
10189
#   IFLAG - iteration flag. This is setting by the calling process
10190
#                           and is a function of the phase being processed
227 dpurdie 10191
#       0   No external dependencies.
10192
#       1   Source dependency list.
261 dpurdie 10193
#       2   Shared library dependency list
10194
#       3   Application dependency list
227 dpurdie 10195
#
10196
#
261 dpurdie 10197
#--------- Dependencies --------------------------------------------------------
10198
#   Include the 'depend' file if required
10199
#
10200
    MakeHeader ("Dependency Inclusion");
10201
    print MAKEFILE <<EOF;
10202
ifeq (\$(NODEPEND),0)
10203
 ifdef IFLAG
10204
  ifneq "\$(IFLAG)" "0"
10205
-include	\$(OBJDIR)/depend
10206
  endif
227 dpurdie 10207
 endif
10208
endif
10209
 
10210
EOF
10211
 
10212
#-------------------------------------------------------------------------------
10213
#   Standard rules
10214
#
5991 dpurdie 10215
    MakeHeader ("Standard rules");
10216
    print MAKEFILE <<EOF;
373 dpurdie 10217
.PHONY:		make_clean
227 dpurdie 10218
make_clean:
10219
	-\@echo "Removing generated files (objects, libraries, binaries etc)";
10220
 
10221
.PHONY:		rmlitter
10222
rmlitter:
2429 dpurdie 10223
	-\$(AA_PRE)JatsFileUtil 'D0' 'Removing litter' '.' 'core' '*.bak' '*.tmp' '*.err'
227 dpurdie 10224
 
261 dpurdie 10225
.PHONY:		lint_init
10226
lint_init:
10227
 
227 dpurdie 10228
EOF
10229
 
261 dpurdie 10230
#
10231
#   Dependencies for 'make_init'
10232
#
10233
#
10234
my @initdep;
10235
push @initdep, '$(INITS)' if ( @INITS );
227 dpurdie 10236
 
261 dpurdie 10237
#
10238
#   Dependencies for 'make_dir'
10239
#
10240
my @mkdirdep;
289 dpurdie 10241
push @mkdirdep, '$(GBE_OBJDIR)' if ( @CSRCS || @CXXSRCS || @OBJS || @PROGOBJS || @TESTPROGOBJS );
261 dpurdie 10242
push @mkdirdep, '$(SHDIRS)'     if ( %SHOBJ_LIB || @SHLIBS);
10243
push @mkdirdep, '$(GBE_LIBDIR)' if ( @LIBS || @MLIBS || @SHLIBS || %INSTALL_LIBS || %PACKAGE_LIBS );
289 dpurdie 10244
push @mkdirdep, '$(GBE_BINDIR)' if ( @SHLIBS || %SCRIPTS || @PROGS || @TESTPROGS || %INSTALL_PROGS || %PACKAGE_PROGS );
227 dpurdie 10245
 
261 dpurdie 10246
#
10247
#   Actions for for 'unobj'
10248
#
10249
my @unobjact;
10250
push @unobjact, RmFilesCmd( 'OBJS' )            if ( @OBJS );
10251
push @unobjact, RmFilesCmd( 'SHOBJS' )          if ( %SHOBJ_LIB );
10252
push @unobjact, RmFilesCmd( 'PROGOBJS' )        if ( @PROGOBJS );
289 dpurdie 10253
push @unobjact, RmFilesCmd( 'TESTPROGOBJS' )    if ( @TESTPROGOBJS );
261 dpurdie 10254
push @unobjact, RmFilesCmd( 'TOOLSETOBJS' )     if ( @TOOLSETOBJS );
227 dpurdie 10255
 
261 dpurdie 10256
#
10257
#   Dependencies for 'make_lib'
10258
#
10259
my @libdep;
10260
push @libdep, '$(GBE_OBJDIR)', '$(GBE_LIBDIR)', '$(LIBS)' if ( @LIBS );
227 dpurdie 10261
 
261 dpurdie 10262
#
10263
#   Dependencies for 'lint_lib'
10264
#
10265
my @liblintdep;
10266
push @liblintdep, 'lint_init', '$(GBE_OBJDIR)', '$(GBE_LIBDIR)', '$(LINTLIBS)' if ( @LIBS );
227 dpurdie 10267
 
261 dpurdie 10268
#
10269
#   Dependencies for 'make_mlib'
10270
#
10271
my @mlibdep;
10272
push @mlibdep, '$(GBE_OBJDIR)', '$(GBE_LIBDIR)', '$(GBE_MLIBDIR)', '$(MLIBS)' if ( @MLIBS );
227 dpurdie 10273
 
261 dpurdie 10274
#
10275
#   Dependencies for 'make_install_shlib' (tag)
10276
#
10277
my @shlibdep;
10278
push @shlibdep, '$(SHDIRS)', '$(SHLIBS)' if ( @SHLIBS );
227 dpurdie 10279
 
261 dpurdie 10280
#
10281
#   Dependencies for 'lint_shlib'
10282
#
10283
my @shliblintdep;
10284
push @shliblintdep, 'lint_init', '$(GBE_LIBDIR)', '$(LINTSHLIBS)' if ( @SHLIBS );
227 dpurdie 10285
 
261 dpurdie 10286
#
10287
#   Actions for 'unmake_lib'
10288
#
10289
my @unlibact;
10290
push @unlibact, RmFilesCmd( 'SHLIBS' )      if ( @SHLIBS );
10291
push @unlibact, RmFilesCmd( 'MLIBS' )       if ( @MLIBS );
10292
push @unlibact, RmFilesCmd( 'LIBS' )        if ( @LIBS );
10293
push @unlibact, RmFilesCmd( 'TOOLSETLIBS' ) if ( @TOOLSETLIBS );
227 dpurdie 10294
 
261 dpurdie 10295
#
10296
#   Actions for 'unmake_mlib'
10297
#
10298
my @unmlibact;
10299
push @unmlibact, RmFilesCmd( 'MLIBS' ) if ( @MLIBS );
227 dpurdie 10300
 
261 dpurdie 10301
#
10302
#   Dependencies for 'make_script'
10303
#
10304
my @scriptdep;
10305
push @scriptdep, '$(GBE_BINDIR)', '$(SCRIPTS)' if ( %SCRIPTS );
227 dpurdie 10306
 
261 dpurdie 10307
#
10308
#   Actions for 'unmake_script'
10309
#
10310
my @unscriptact;
10311
push @unscriptact , RmFilesCmd( 'SCRIPTS' ) if ( %SCRIPTS );
10312
push @unscriptact , RmFilesCmd( 'COPYIN' )  if ( @COPYIN );
227 dpurdie 10313
 
261 dpurdie 10314
#
10315
#   Dependencies for 'make_prog'
10316
#
10317
my @progdep;
10318
push @progdep, '$(GBE_OBJDIR)', '$(GBE_BINDIR)', '$(PROGS)' if ( @PROGS );
10319
push @progdep, '$(PROGS_EXTRA)' if (@PROGS_EXTRA);
227 dpurdie 10320
 
261 dpurdie 10321
#
10322
#   Dependencies for 'make_prog' created for 'projects'
10323
#
10324
my @projectdep;
10325
push @projectdep, '$(PROJECTS)' if (ListGeneratedProjects(1) );
227 dpurdie 10326
 
261 dpurdie 10327
#
10328
#   Dependencies for 'generate' created for 'projects'
10329
#
10330
my @projectgendep;
10331
push @projectgendep, '$(PROJECTSGEN)' if (ListGeneratedProjects(0) );
227 dpurdie 10332
 
261 dpurdie 10333
#
10334
#   Dependencies for 'unmake_prog' created for 'projects'
10335
#
10336
my @projectcleandep;
10337
push @projectcleandep, '$(PROJECTSCLEAN)' if (%PROJECTS);
227 dpurdie 10338
 
261 dpurdie 10339
#
10340
#   Dependencies for 'lint_prog'
10341
#
10342
my @proglintdep;
289 dpurdie 10343
push @proglintdep, 'lint_init', '$(GBE_OBJDIR)', '$(GBE_BINDIR)', '$(LINTPROGS)' if ( @PROGS || @TESTPROGS );
227 dpurdie 10344
 
261 dpurdie 10345
#
10346
#   Actions for 'unmake_prog'
10347
#
10348
my @unprogact;
10349
push @unprogact, RmFilesCmd( 'PROGS' )        if ( @PROGS );
10350
push @unprogact, RmFilesCmd( 'TOOLSETPROGS' ) if ( @TOOLSETPROGS );
227 dpurdie 10351
 
261 dpurdie 10352
#
4728 dpurdie 10353
#   Dependencies for 'exec_tests'
261 dpurdie 10354
#
10355
my @testprogdep;
289 dpurdie 10356
push @testprogdep, '$(GBE_OBJDIR)', '$(GBE_BINDIR)', '$(TESTPROGS)' if ( @TESTPROGS );
227 dpurdie 10357
 
4501 dpurdie 10358
my @autoruntestdep;
10359
push @autoruntestdep, 'makefile.pl', '$(AUTOUNITTESTS)' if ( @TESTPROJECT_TO_ARUN );
10360
 
10361
my @runtestdep;
4996 dpurdie 10362
push @runtestdep    , 'makefile.pl', '$(UNITTESTS)' if ( @TESTPROJECT_TO_URUN );
4501 dpurdie 10363
 
227 dpurdie 10364
#
4728 dpurdie 10365
#   Dependencies for 'exec_tests' and friends
261 dpurdie 10366
#
10367
my @untestprogact;
289 dpurdie 10368
push @untestprogact ,RmFilesCmd( 'TESTPROGS' ) if ( @TESTPROGS );
227 dpurdie 10369
 
261 dpurdie 10370
#
10371
#   Dependencies for 'generated'
10372
#
10373
my @generatedep;
10374
push @generatedep, '$(GENERATED)' if ( @GENERATED );
10375
 
10376
#
10377
#   Actions for 'ungenerate'
10378
#
10379
my @ungenact;
10380
push @ungenact, RmFilesCmd( 'GENERATED' ) if ( @GENERATED );
10381
push @ungenact, RmFilesCmd( 'GENERATED_NOTSRC' ) if ( @GENERATED_NOTSRC );
10382
push @ungenact, RmFilesCmd( 'TOOLSETGENERATED' ) if ( @TOOLSETGENERATED );
10383
push @ungenact, RmFilesCmd( 'USERGENERATED' ) if ( @USERGENERATED );
10384
 
10385
#
10386
#   Dependencies for 'ungenerate'
10387
#
10388
my @ungeneratedep;
10389
push @ungeneratedep, '$(GENERATEDCLEAN)';
10390
 
227 dpurdie 10391
#-------------------------------------------------------------------------------
261 dpurdie 10392
# Function        : PrintPhonyRule
227 dpurdie 10393
#
261 dpurdie 10394
# Description     : Helper function to print some internal phony makefile targets
10395
#                   These are used to hold the basic makefile together
10396
#
10397
# Inputs          : $target         - Name of the phony target
10398
#                   $prereq         - Prerequisites
10399
#                                     Leading spaces removed
10400
#                   $recipe         - Optional Reference to an array of recipes
10401
#                                     Will be printed one per line
10402
#
10403
#
10404
sub PrintPhonyRule
227 dpurdie 10405
{
261 dpurdie 10406
    my ($target, $prereq, $recipe) = @_;
10407
    $prereq =~ s/^\s+//;
227 dpurdie 10408
 
261 dpurdie 10409
    MakePadded( 2, '.PHONY:', $target, "\n");
10410
    MakePadded( 2,"$target:", $prereq, "\n");
10411
    MakePrint ("\t\t" . $_ . "\n") foreach ( @{$recipe} );
10412
    MakePrint ("\n");
227 dpurdie 10413
}
10414
 
261 dpurdie 10415
#   make_init - Test toolset presence and sanity
10416
#   Will only be called ONCE for each platform in a recursive build
10417
#   Should be used to ensure that the required toolset is present
10418
#
4778 dpurdie 10419
PrintPhonyRule ('make_init',            "@initdep" );
227 dpurdie 10420
 
261 dpurdie 10421
#   make_dir    - Create required subdirectories
10422
#   Will be invoked as a part of most targets that create files
10423
#   Will be invoked by the calling wrappers
10424
#   Should not be invoked when cleaning
10425
#
4778 dpurdie 10426
PrintPhonyRule ('make_dir',             "@mkdirdep" );
261 dpurdie 10427
 
4778 dpurdie 10428
PrintPhonyRule ('generate',             "@generatedep @projectgendep" );
10429
PrintPhonyRule ('ungenerate',           "@ungeneratedep",  \@ungenact);
10430
PrintPhonyRule ('unobj',                "",  \@unobjact);
10431
PrintPhonyRule ('make_lib',             "@libdep" );
10432
PrintPhonyRule ('lint_lib',             "@liblintdep" );
10433
PrintPhonyRule ('make_mlib',            "@mlibdep" );
10434
PrintPhonyRule ('lint_shlib',           "@shliblintdep" );
10435
PrintPhonyRule ('unmake_lib',           "", \@unlibact );
10436
PrintPhonyRule ('unmake_mlib',          "", \@unmlibact );
10437
PrintPhonyRule ('make_script',          "@scriptdep" );
10438
PrintPhonyRule ('unmake_script',        "", \@unscriptact );
10439
PrintPhonyRule ('make_prog',            "make_script @progdep @projectdep" );
10440
PrintPhonyRule ('unmake_prog',          "unmake_script @projectcleandep", \@unprogact );
10441
PrintPhonyRule ('lint_prog',            "@proglintdep" );
10442
PrintPhonyRule ('exec_tests',           "make_script @testprogdep @runtestdep" );
10443
PrintPhonyRule ('exec_unit_tests',      "make_script @testprogdep @autoruntestdep" );
10444
PrintPhonyRule ('make_test',            "make_script @testprogdep" );
10445
PrintPhonyRule ('unmake_test',          "unmake_script", \@untestprogact );
10446
PrintPhonyRule ('preprocess_tests',     '$(AUTOUNITTESTS_PRE)' );
10447
PrintPhonyRule ('postprocess_tests',    '$(AUTOUNITTESTS_POST)' );
10448
PrintPhonyRule ('collate_test_results', '$(AUTOUNITTESTS_COLLATE)' );
261 dpurdie 10449
 
227 dpurdie 10450
#-------------------------------------------------------------------------------
10451
#   Package and Installation Summary
10452
#
10453
    MakeHeader ("Package and Installation Summary");
10454
    sub InstallTarget
10455
    {
10456
        my( $target, $hashp, $prereq, $fprereq ) = @_;
10457
        my( $element );
10458
 
5991 dpurdie 10459
        my $me = MakeEntry::New( *MAKEFILE, $target, '--Phony' );
10460
        $me->AddDependancy( $fprereq ) if ($fprereq);
227 dpurdie 10461
        foreach my $element ( sort keys %{$hashp} )
10462
        {
10463
            #
10464
            #   Skip placekeepers
10465
            #
10466
            next if ( $hashp->{$element}{'placekeeper'} );
10467
 
10468
            #
10469
            #   Prepend any prerequisites (once)
10470
            #
5991 dpurdie 10471
            $me->AddDependancy( $prereq ) if ( $prereq );
10472
            $prereq = 0;
227 dpurdie 10473
 
5991 dpurdie 10474
            $me->AddDependancyEscaped( $element );
227 dpurdie 10475
        }
5991 dpurdie 10476
        $me->Print();
10477
 
227 dpurdie 10478
    }
10479
 
10480
InstallTarget( "install_hdr",       \%INSTALL_HDRS );
10481
InstallTarget( "install_lib",       \%INSTALL_LIBS,  'make_mlib' );
261 dpurdie 10482
InstallTarget( "make_install_shlib",\%INSTALL_SHLIBS, '', "@shlibdep" );
227 dpurdie 10483
InstallTarget( "install_prog",      \%INSTALL_PROGS, 'make_script' );
10484
InstallTarget( "install_class",     \%INSTALL_CLSS );
10485
 
10486
InstallTarget( "package_files",     \%PACKAGE_FILES );
10487
InstallTarget( "package_hdr",       \%PACKAGE_HDRS );
10488
InstallTarget( "package_lib",       \%PACKAGE_LIBS );
10489
InstallTarget( "package_shlib",     \%PACKAGE_SHLIBS );
10490
InstallTarget( "package_prog",      \%PACKAGE_PROGS, 'make_script' );
10491
InstallTarget( "package_class",     \%PACKAGE_CLSS );
10492
 
10493
#-------------------------------------------------------------------------------
10494
#   Installations
10495
 
10496
MakeHeader ("Installations");
6387 dpurdie 10497
PackageRule    ( \&InstallCmd, \%INSTALL_HDRS  );
10498
PackageRule    ( \&InstallCmd, \%INSTALL_CLSS  );
10499
PackageRule    ( \&InstallCmd, \%INSTALL_LIBS  );
10500
PackageRule    ( \&InstallCmd, \%INSTALL_SHLIBS  );
10501
PackageRule    ( \&InstallCmd, \%INSTALL_PROGS  );
10502
PackageDirRule ('install_dirs',    \@INSTALL_DIRS);
227 dpurdie 10503
 
10504
#-------------------------------------------------------------------------------
10505
#   Packaging
10506
#
10507
MakeHeader ("Packaging");
6387 dpurdie 10508
PackageRule    ( \&PackageCmd, \%PACKAGE_FILES );
10509
PackageRule    ( \&PackageCmd, \%PACKAGE_HDRS );
10510
PackageRule    ( \&PackageCmd, \%PACKAGE_CLSS );
10511
PackageRule    ( \&PackageCmd, \%PACKAGE_LIBS );
10512
PackageRule    ( \&PackageCmd, \%PACKAGE_SHLIBS );
10513
PackageRule    ( \&PackageCmd, \%PACKAGE_PROGS );
10514
PackageDirRule ('package_dirs', \@PACKAGE_DIRS);
227 dpurdie 10515
 
10516
#-------------------------------------------------------------------------------
10517
#   Uninstall/unpackaging
10518
#
10519
MakeHeader ("Uninstall/unpackaging");
10520
 
6387 dpurdie 10521
UnpackageRule  ( 'uninstall_hdr',         \&UninstallCmd, \%INSTALL_HDRS );
10522
UnpackageRule  ( 'uninstall_lib',         \&UninstallCmd, \%INSTALL_LIBS );
10523
UnpackageRule  ( 'uninstall_shlib',       \&UninstallCmd, \%INSTALL_SHLIBS );
10524
UnpackageRule  ( 'uninstall_prog',        \&UninstallCmd, \%INSTALL_PROGS );
10525
UnpackageRule  ( 'uninstall_class',       \&UninstallCmd, \%INSTALL_CLSS );
10526
PackageDirRule ( 'uninstall_dirs',        \@INSTALL_DIRS);
227 dpurdie 10527
 
6387 dpurdie 10528
UnpackageRule  ( 'unpackage_files',       \&UnpackageCmd, \%PACKAGE_FILES );
10529
UnpackageRule  ( 'unpackage_hdr',         \&UnpackageCmd, \%PACKAGE_HDRS );
10530
UnpackageRule  ( 'unpackage_lib',         \&UnpackageCmd, \%PACKAGE_LIBS );
10531
UnpackageRule  ( 'unpackage_shlib',       \&UnpackageCmd, \%PACKAGE_SHLIBS );
10532
UnpackageRule  ( 'unpackage_prog',        \&UnpackageCmd, \%PACKAGE_PROGS );
10533
UnpackageRule  ( 'unpackage_class',       \&UnpackageCmd, \%PACKAGE_CLSS );
10534
PackageDirRule ( 'unpackage_dirs',        \@PACKAGE_DIRS);
227 dpurdie 10535
 
261 dpurdie 10536
#-------------------------------------------------------------------------------
267 dpurdie 10537
#   Distribution Sets
261 dpurdie 10538
#
267 dpurdie 10539
MakeHeader ("Distribution Sets");
10540
PackageSetRules();
10541
 
10542
#-------------------------------------------------------------------------------
10543
#
261 dpurdie 10544
#   Subdir deletion
10545
#   This is done AFTER the toolset functions have been invoked to create the
10546
#   build artifacts so that the toolsets can create directories too
10547
#
10548
#   Note: Toolset directories are deleted first
10549
#   Note: User Directories are deleted in the reverse order of creation
10550
#
2429 dpurdie 10551
#   Add them into the directory data structure
10552
#
10553
    foreach my $path ( @TOOLSETDIRS )
10554
    {
10555
        MkdirRule( $path, '', '--NoCreate' );
10556
    }
10557
 
10558
    foreach my $path ( @TOOLSETDIRTREES )
10559
    {
10560
        MkdirRule( $path, '', '--NoCreate' , '--RemoveAll');
10561
    }
10562
 
261 dpurdie 10563
    MakeHeader ("Subdir deletion");
10564
    RmdirRules();
10565
    MakeNewLine();
227 dpurdie 10566
 
261 dpurdie 10567
#--------- Toolset Rules -------------------------------------------------------
10568
    MakeHeader ("Toolset Rules");
10569
    MakePrintList ( \@TOOLSETRULES );
10570
 
10571
#--------- Maketags ------------------------------------------------------------
227 dpurdie 10572
 
10573
    Maketag( "make_init",           @INITS );
261 dpurdie 10574
    Maketag( "make_dir",            @mkdirdep );
10575
    Maketag( "generate",            @generatedep || @projectgendep || @USERGENERATED || ($ScmToolsetGenerate != 0) );
227 dpurdie 10576
    Maketag( "depend",              $ScmDependTags != 0 );
261 dpurdie 10577
    Maketag( "make_lib",            @libdep );
10578
    Maketag( "make_mlib",           @mlibdep );
10579
    Maketag( "make_install_shlib",  %INSTALL_SHLIBS || @shlibdep);
10580
    Maketag( "make_script",         @scriptdep );
10581
    Maketag( "make_prog",           @progdep || @projectdep );
10582
    Maketag( "make_test",           @testprogdep );
4996 dpurdie 10583
    Maketag( "exec_tests",          $TESTS_TO_RUN     || @TESTPROJECT_TO_URUN );
4728 dpurdie 10584
    Maketag( "exec_unit_tests",     $TESTS_TO_AUTORUN || @TESTPROJECT_TO_ARUN );
4778 dpurdie 10585
    Maketag( "process_tests",       @TOOLSET_UTF_PRE || @TOOLSET_UTF_POST || @TOOLSET_UTF_COLLATE);
227 dpurdie 10586
    Maketag( "install_hdr",         %INSTALL_HDRS );
10587
    Maketag( "install_class",       %INSTALL_CLSS );
10588
    Maketag( "install_lib",         %INSTALL_LIBS );
10589
    Maketag( "install_prog",        %INSTALL_PROGS );
6387 dpurdie 10590
    Maketag( "install_dirs",        @INSTALL_DIRS );
227 dpurdie 10591
    Maketag( "deploy",              %DEPLOYPACKAGE );
10592
    Maketag( "package",             %PACKAGE_FILES || %PACKAGE_HDRS || %PACKAGE_CLSS ||
10593
                                    %PACKAGE_LIBS || %PACKAGE_SHLIBS || %PACKAGE_PROGS );
10594
 
261 dpurdie 10595
    #
10596
    #   Display tags in the MAKEFILE
4778 dpurdie 10597
    #       Not used here - just for show
261 dpurdie 10598
    #
10599
    MakeHeader ("Maketags");
10600
    foreach my $tag ( sort keys %MakeTags )
10601
    {
4778 dpurdie 10602
        MakePadded( 3, "#   $tag:", '1', "\n");
261 dpurdie 10603
    }
10604
 
227 dpurdie 10605
#-------------------------------------------------------------------------------
10606
#   End of Makefile
10607
#
10608
    MakeHeader ("End of Makefile");
10609
    close( MAKEFILE );
10610
 
10611
#
10612
#   Save all platform information
10613
#   Done after the makefile is written as toolsets can extend the data
10614
#
10615
    WriteParsedConfig();
10616
 
10617
#
10618
#   Write out any accumulated DPACKAGE data
10619
#
10620
    JatsDPackage::DPackageSave();
10621
 
10622
    return 0;
10623
}
10624
 
10625
#-------------------------------------------------------------------------------
387 dpurdie 10626
# Function        : QuoteForMake
10627
#
10628
# Description     : Escape/Quote a pathname for make
10629
#                       Allow files with a $ in the name
10630
#                       Allow files with a space in the name
10631
#                       Allow files with a comma in the name
10632
#                       Allow for paths that have make-varible prefixes
6073 dpurdie 10633
#                           $(GBE_...) or ${GBE_...} or $(OBJDIR)
387 dpurdie 10634
#                           as these may be generated internally
5991 dpurdie 10635
#                       Allow for files with a colon in the name
10636
#                           Mode dependent
10637
#                               0 - No effect
10638
#                               T - \\\:
10639
#                               S = \:    
387 dpurdie 10640
#
399 dpurdie 10641
#                       Must also allow $(GBE_TYPE) in the remainder
10642
#
5991 dpurdie 10643
# Inputs          : uarg            - Arg to quote
10644
#                   mode            - Mode of operation
10645
#                                     T - Makefile target
10646
#                                     S - Makefile source
10647
#                                     0 - Neither
387 dpurdie 10648
#
10649
# Returns         : Quoted arg
10650
#
10651
 
5991 dpurdie 10652
sub QuoteForMake($;$)
387 dpurdie 10653
{
5991 dpurdie 10654
    my ($uarg, $mode) = @_;
10655
    $mode = '0' unless defined $mode;
387 dpurdie 10656
 
10657
    #
10658
    #   Split into two
10659
    #       $(xxx)/             - Makefile variables
10660
    #       Remainder           - Stuff to quote
10661
    #
10662
    $uarg =~ m~^((\$\(.*?\)/)*)(.*)~;
10663
    my $prefix = defined $1 ? $1 : '';
10664
    my $arg    = defined $3 ? $3 : '';
10665
 
6073 dpurdie 10666
    $arg =~ s~\$(?!\(GBE_[A-Z]+\)|{GBE_[A-Z]+}|\(OBJDIR\))~\$\$~g;       # $, not followed by (GBE_ or ${GBE_ or (OBJDIR)- is not $(GBE_ AND not $(OBJDIR)
387 dpurdie 10667
    $arg =~ s~ ~\\ ~g;
10668
    $arg =~ s~,~\$(comma)~g;
2764 dpurdie 10669
    $arg =~ s~%~\\%~g;
5999 dpurdie 10670
    $arg =~ s~:~\\\\\\:~g if ($mode eq 'T' &&  $::ScmHost eq "Unix");
10671
    $arg =~ s~:~\\:~g     if ($mode eq 'S' &&  $::ScmHost eq "Unix");
387 dpurdie 10672
    return $prefix . $arg;
10673
}
10674
 
10675
#-------------------------------------------------------------------------------
227 dpurdie 10676
# Function        : Maketag
10677
#
10678
# Description     : Create Makefile tags to speed up recursive makes
10679
#
10680
# Inputs          : tag_name
10681
#                   dep
10682
#
10683
# Returns         : 
10684
#
10685
sub Maketag
10686
{
10687
    my( $tag, $dep ) = @_;
10688
    $MakeTags{$tag} = 1 if ( defined($dep) && $dep );
10689
}
10690
 
10691
#-------------------------------------------------------------------------------
10692
#   Function to create and delete directories within the build system
10693
#
10694
#    To stop make regenerating directory dependent targets each time the
10695
#    directory content is modified, rule should only be dependent on a internally
10696
#    created alias file 'gbedir', which represents the time a dir was created not
10697
#    last modified.
10698
#
10699
#    Must use tags like GBE_BINDIR, GBE_LIBDIR and GBE_OBJDIR to ensure that the
10700
#    directories are created correctly.
10701
#
10702
my %MkdirRuleData;
10703
my @MkdirRuleOrder;
10704
my $MkdirRulePrinting = 0;
10705
my $MkdirRuleGbeFile = ( $::ScmHost eq "Unix" ) ? ".gbedir" : "_gbedir";
10706
 
10707
#-------------------------------------------------------------------------------
10708
# Function        : MkdirRule
10709
#
10710
# Description     : Create Rules and Recipes to create a directory at make-time
10711
#                   Mark the information for such that the directories will
10712
#                   be deleted in a 'clean'
10713
#
10714
#                   Can be called before we start writing the makefile
10715
#                   Such entries will be retained and dumped at a known time
10716
#
10717
# Inputs          : $subdir     - Symbolic name of the subdir $(OBJDIR)
10718
#                   $alias      - Optional script alias for the dir 'OBJDIR' --> GBE_OBJDIR
10719
#                   Options:
2429 dpurdie 10720
#                       --Path=path             Optional value of $subdir '$(GBE_PLATFORM)$(GBE_TYPE).OBJ'
10721
#                       --RemoveAll             Remove all files on clean
6177 dpurdie 10722
#                       --Extra=file[,file]     Additional files to remove
2429 dpurdie 10723
#                       --NoCreate              Do not Create the Directory, just delete it
227 dpurdie 10724
#
10725
# Returns         : Nothing
10726
#
10727
 
10728
sub MkdirRule
10729
{
10730
    my( $subdir, $alias, @opts ) = @_;
10731
 
10732
    #
10733
    #   Create data entry once
10734
    #
10735
    $alias =~ s~^GBE_~~ if $alias;
10736
    unless ( $MkdirRuleData{$subdir}  )
10737
    {
10738
        my %data;
10739
 
10740
        #
10741
        #   Parse options
10742
        #
10743
        foreach ( @opts )
10744
        {
10745
            if ( /^--Path=(.+)/ ) {
10746
                $data{path} = $1;
10747
            } elsif ( /^--RemoveAll/ ) {
10748
                $data{remove_all} = 1;
2429 dpurdie 10749
            } elsif ( /^--NoCreate/ ) {
10750
                $data{noCreate} = 1;
10751
            } elsif ( /^--Extra=(.+)/ ) {
10752
                @{$data{extraFiles}} = split(/,/, $1);
227 dpurdie 10753
            } else {
10754
                Error ("MkdirRule: Unknown option: $_");
10755
            }
10756
        }
10757
        $data{alias} = $alias if ( $alias );
10758
 
10759
        $MkdirRuleData{$subdir} = \%data;
10760
        push @MkdirRuleOrder, $subdir;
10761
    }
10762
 
10763
    #
10764
    #   Save or print
10765
    #
10766
    return unless ( $MkdirRulePrinting );
2429 dpurdie 10767
    return if ( $MkdirRuleData{$subdir}{noCreate} );
227 dpurdie 10768
 
10769
    #
10770
    #   Create a definition of the physical directory
10771
    #
10772
    my $path = $MkdirRuleData{$subdir}{path};
261 dpurdie 10773
    MakePadded (2, $alias, ":= $path\n") if ( $path && $alias );
227 dpurdie 10774
 
10775
    #   Create an alias to be used within rules
10776
    #   The defined aliase will be prefixed with 'GBE_'
10777
    #
261 dpurdie 10778
    MakePadded (2, "GBE_$alias", ":= $subdir/$MkdirRuleGbeFile\n") if ( $alias );
227 dpurdie 10779
 
10780
    #
10781
    #   Create a recipe to create the directory
10782
    #   This is not as simple as it sounds
10783
    #   The touch is required.
10784
    #       Had 'timestamp' issues on solaris'. The 'echo' did not appear
10785
    #       to be enough. Perhaps the output was not flushed
10786
    #
261 dpurdie 10787
    MakePadded (2, "$subdir", ": $subdir/$MkdirRuleGbeFile\n");
227 dpurdie 10788
    MakePrint
10789
        "$subdir/$MkdirRuleGbeFile:\n".
10790
        "\t\$(XX_PRE)if [ ! -d $subdir ]; then \$(mkdir) -p $subdir; fi; \\\n".
10791
        "\t\$(echo) '# DO NOT REMOVE.' > \$@; \\\n".
10792
        "\t\$(touch) \$@\n\n";
10793
}
10794
 
10795
#-------------------------------------------------------------------------------
10796
# Function        : RmdirRules
10797
#
2429 dpurdie 10798
# Description     : Create the body of a recipe to delete the directories that
227 dpurdie 10799
#                   have been created.
10800
#
2429 dpurdie 10801
#                   Use JatsFileUtil rather than shell script
10802
#                       Faster under windows (and others)
10803
#                       Solved long pathname issues
10804
#                       Simpler to use and control
227 dpurdie 10805
#
10806
# Inputs          : Uses $MkdirRuleData
10807
#
10808
# Returns         : Nothing.
10809
#                   Prints to the makefile
10810
#
10811
sub RmdirRules
10812
{
2429 dpurdie 10813
    MakePrint( ".PHONY:\tunmake_dir\n" );
10814
    MakePrint( "unmake_dir:\n" );
10815
 
227 dpurdie 10816
    #
10817
    #   Determine the list of directories to delete
2429 dpurdie 10818
    #   Sort such that subdirs are deleted first
227 dpurdie 10819
    #
2429 dpurdie 10820
    my $txt = 'Removing directories';
227 dpurdie 10821
    foreach my $subdir ( reverse sort keys %MkdirRuleData )
10822
    {
2429 dpurdie 10823
        my @args = $subdir;
10824
 
5816 dpurdie 10825
        push (@args, $MkdirRuleGbeFile, 'core', '*.bak', '*.tmp', '*.err', 'utf.*.rc')
2429 dpurdie 10826
            unless $MkdirRuleData{$subdir}{remove_all};
10827
 
10828
        push (@args, @{$MkdirRuleData{$subdir}{extraFiles}})
10829
            if ( $MkdirRuleData{$subdir}{extraFiles} );
10830
 
10831
        my $mode = $MkdirRuleData{$subdir}{remove_all} ? 'T0' : 'D0';
10832
 
10833
        MakePrint ("\t-\$(AA_PRE)JatsFileUtil ", QuoteArray( $mode, $txt, @args ), "\n");
10834
        $txt = '';
227 dpurdie 10835
    }
10836
}
10837
 
10838
#-------------------------------------------------------------------------------
10839
# Function        : CreateMkdirRules
10840
#
10841
# Description     : Create Rules to make dirs at runtime
10842
#                   This function is called to instantiate those entries
10843
#                   That have been requested before the makefile has has
10844
#                   started to be created.
10845
#
10846
#                   Once this function has been called all new MkdirRule calls
10847
#                   will result in the recipes being created in-line.
10848
#
10849
# Inputs          : Nothing
10850
#
10851
# Returns         : Even Less
10852
#
10853
#
10854
sub CreateMkdirRules
10855
{
10856
    $MkdirRulePrinting = 1;
10857
    foreach my $subdir ( @MkdirRuleOrder )
10858
    {
10859
        my $data = $MkdirRuleData{$subdir};
10860
        MkdirRule($subdir, $data->{alias}, $data->{path} );
10861
    }
10862
}
10863
 
10864
#-------------------------------------------------------------------------------
10865
# Function        : PackageRule
10866
#
10867
# Description     : Generate rules and recipes to "install" and "package" files
10868
#
10869
# Inputs          : codecmd     - A code reference to the actual installer routine
10870
#                   hashp       - A reference to a INSTALL or PACKAGE hash
10871
#
299 dpurdie 10872
#                   hashp is a reference to a hash
227 dpurdie 10873
#                       The key is the full path of the install target
10874
#                       The value is (another) hash that describes the install options
10875
#
10876
#                   Valid keys are:
10877
#                       src                 - Path of the source file [Mandatory]
10878
#                       dir                 - Target directory [Mandatory]
10879
#
10880
#                       defined             - Copy the file only if value is defined
4382 dpurdie 10881
#                       Exists              - Copy the file only if it exists
227 dpurdie 10882
#                       exe                 - Mark the file as executable
10883
#                       Mode                - File modes. Default is -w
10884
#                       placekeeper         - Marks SHARED library placekeepers
10885
#                       set                 - Distribution sets
10886
#                       type                - Copy the file in DEBUG or PROD mode
10887
#                                             Valid values are "D" or "P"         
10888
#                       version             - Shared library version information
5882 dpurdie 10889
#                       symlink             - File is a symlink
227 dpurdie 10890
#                       RemoveOnly          - Do not install the file. Entries are
10891
#                                             created to allow the removal of the file
4382 dpurdie 10892
#                       NoTarget            - Reserved - Implemented elsewhere
227 dpurdie 10893
#
10894
# Returns         :
10895
#
10896
sub PackageRule
10897
{
10898
    my ($codecmd, $hashp) = @_;
10899
 
10900
    foreach my $dest ( keys %{$hashp} )
10901
    {
10902
 
10903
        my $entry = $hashp->{$dest};
5991 dpurdie 10904
        my $destText = QuoteForMake($dest,'T');
227 dpurdie 10905
        #
10906
        #   Skip placekeepers
10907
        #
10908
        next if ( $entry->{'placekeeper'} );
10909
 
10910
        #
10911
        #   Some entries are not installed via this mechanism, but can be removed
10912
        #   if they exist. Mark these as PHONY to keep targets happy
10913
        #
10914
        if ( $entry->{'RemoveOnly'} )
10915
        {
5991 dpurdie 10916
            MakePrint ".PHONY:\t$destText\n";
10917
            MakePrint "$destText:\n\n";
227 dpurdie 10918
            next;
10919
        }
10920
 
10921
        my $fname = $entry->{'src'};
5991 dpurdie 10922
        my $fnameText = QuoteForMake($fname,'S');
227 dpurdie 10923
        my $fmode = $entry->{'Mode'};
10924
        $fmode .= "+x" if ( $entry->{'exe'}  );
5882 dpurdie 10925
        $fmode .= "+l" if ( $entry->{'symlink'}  );
227 dpurdie 10926
 
10927
        #
10928
        #   User conditionional
10929
        #   Mark both the source and the target as PHONY if the condition is not met
10930
        #   This will ensure that the target need not be built.
10931
        #
10932
        my $udef = $entry->{'defined'};
10933
        if ( $udef )
10934
        {
10935
            MakePrint "ifndef $udef \n";
5991 dpurdie 10936
            MakePrint ".PHONY:\t\t$destText\n";
10937
            MakePrint ".PHONY:\t\t$fnameText\n";
10938
            MakePrint "$destText:\n";
227 dpurdie 10939
            MakePrint "else\n"
10940
        }
10941
 
10942
        #
4382 dpurdie 10943
        #   File exists
10944
        #   Only package the file if it has been generated. ie: .exe.manifest
10945
        #
10946
        my $fexist = $entry->{'Exists'};
10947
        if ($fexist)
10948
        {
5991 dpurdie 10949
            MakePrint "ifeq (\"\$(wildcard $fnameText)\",\"\")\n";
10950
            MakePrint ".PHONY:\t\t$destText\n";
10951
            MakePrint "$destText:\n";
4382 dpurdie 10952
            MakePrint "else\n"
10953
        }
10954
 
10955
        #
227 dpurdie 10956
        #   Conditional installation for DEBUG/PRODUCTION
10957
        #
10958
        my $type = $entry->{'type'};
10959
        if ( $type )
10960
        {
10961
            if ( $type eq "D" ) {
10962
                MakePrint 'ifeq "$(DEBUG)" "0"'."\n";
10963
            } elsif ( $type eq "P" ) {
10964
                MakePrint 'ifneq "$(DEBUG)" "0"'."\n";
10965
            } else {
10966
                Error("INTERNAL: Unexpected packaging type: $type");
10967
            }
5991 dpurdie 10968
            MakePrint ".PHONY:\t\t$destText\n";
10969
            MakePrint "$destText:\n";
227 dpurdie 10970
            MakePrint "else\n"
10971
        }
10972
 
10973
        #
10974
        #   The body of the copy
10975
        #
5991 dpurdie 10976
        MakePadded( 4, $destText . ':' );
10977
        MakePrint "\t" . $fnameText . "\n";
2429 dpurdie 10978
        MakePrint $codecmd->( $dest, $fname, $fmode );
227 dpurdie 10979
        MakeNewLine();
10980
 
10981
        #
10982
        #   Unwind conditionals
10983
        #
10984
        MakePrint "endif\n" if ( $type );
4382 dpurdie 10985
        MakePrint "endif\n" if ( $fexist );
227 dpurdie 10986
        MakePrint "endif\n" if ( $udef );
10987
 
10988
        #
10989
        #   Distribution sets
10990
        #
10991
        my $dist = $entry->{'set'};
10992
        if ( $dist )
10993
        {
267 dpurdie 10994
            foreach my $set ( split( ',', $dist ) )
10995
            {
10996
                push @{$PACKAGE_SETS{$set}{LIST}}, $dest;
227 dpurdie 10997
            }
10998
            MakeNewLine();
10999
        }
11000
    }
11001
}
11002
 
11003
#-------------------------------------------------------------------------------
6387 dpurdie 11004
# Function        : PackageDirRule 
11005
#
11006
# Description     : Generate special rules for dynamic packaging/installation of directories 
11007
#
11008
# Inputs          : $mode        - package_dirs/unpackage_dirs/install_dirs/uninstall_dirs
11009
#                   $dataRef     - Ref to package/install list
11010
#                       
11011
#
11012
# Returns         : 
11013
#
11014
sub PackageDirRule
11015
{
11016
    my ($mode, $dataRef) = @_;
11017
    my $me = MakeEntry::New( *MAKEFILE, $mode , '--Phony' );
11018
 
11019
    my $modeText = 'packaging';
11020
    my $cmdText = 'PackageDir';
11021
    if ($mode =~ m~install~) {
11022
        $modeText = 'installing';
11023
        $cmdText = 'InstallDir';
11024
    }
11025
    my $cmd = 'copyDir'; 
11026
    if ($mode =~ m~^un~) {
11027
        $cmd = 'unCopyDir';
11028
        $modeText = 'un' . $modeText;
11029
        $cmdText = 'Un' . $cmdText;
11030
    }
11031
 
11032
 
11033
    foreach my $entry ( @{$dataRef}) {
11034
        $me->NewSection();
11035
 
11036
        #
11037
        #   Conditional installation for DEBUG/PRODUCTION
11038
        #
11039
        my $type = $entry->{'type'};
11040
        if ( $type )
11041
        {
11042
           if ( $type eq "D" ) {
11043
               $me->SectionIfNeq('$(DEBUG)','0');
11044
           } elsif ( $type eq "P" ) {
11045
               $me->SectionIfEq('$(DEBUG)','0');
11046
           } else {
11047
               Error("INTERNAL: Unexpected packaging type: $type");
11048
           }
11049
        }
11050
 
11051
        #
11052
        #   Quote the REs so that they can be passed to a command line
11053
        #       Replace $ with $$
11054
        #
11055
        my $QuoteRe = sub {
11056
            my ($arg) = @_;
11057
            $arg=~ s~\$~\$\$~g;
11058
            return $arg;
11059
            };
11060
 
11061
        #
11062
        #   The body of the copy
11063
        #   Create a command line for run-time command
11064
        #   
11065
        my @cmd;
11066
        push @cmd, '$(JatsRunTime)', $cmd, '--', '-$(VERBOSE_OPT)', '--Name='. $cmdText, '--';
11067
        push @cmd, '-mode=' . $modeText;
11068
        push @cmd, "'" . '-src=' . $entry->{dirTree} . "'";
11069
        push @cmd, "'" . '-dst=' . $entry->{dir} . "'";
11070
        push (@cmd, '-execute' ) if $entry->{exefile};
11071
        push (@cmd, '-noSymlink' ) if $entry->{noPreserveSymlink};
11072
        push (@cmd, '-noRecurse' ) if $entry->{noRecurse};
11073
        push (@cmd, '-stripBase' ) if $entry->{strip_base};
11074
        push (@cmd, "'" . '-exclude+=' . $QuoteRe->($_) . "'" ) foreach @{$entry->{exclude}};
11075
        push (@cmd, "'" . '-include+=' . $QuoteRe->($_) . "'" ) foreach @{$entry->{include}};
11076
        push (@cmd, "'" . '-excludeRe+=' . $QuoteRe->($_) . "'" ) foreach @{$entry->{excludeRe}};
11077
        push (@cmd, "'" . '-includeRe+=' . $QuoteRe->($_) . "'" ) foreach @{$entry->{includeRe}};
11078
 
11079
        $me->AddRecipe(join(' ', @cmd ) );
11080
    }
11081
    $me->Print();
11082
}
11083
 
11084
#-------------------------------------------------------------------------------
267 dpurdie 11085
# Function        : PackageSetRules
11086
#
11087
# Description     : Generate the packageset rules
11088
#                   These appear to be a now-defuct feature
11089
#
11090
#                   By default all packaged files are a part of package_setALL
11091
#
11092
# Inputs          : None
11093
#                   Takes data from %PACKAGE_SET
11094
#
11095
# Returns         : Nothing
11096
#
11097
sub PackageSetRules
11098
{
11099
    foreach my $set ( sort keys %PACKAGE_SETS )
11100
    {
11101
        my $me = MakeEntry::New( *MAKEFILE, "package_set$set", '--Phony' );
5991 dpurdie 11102
        $me->AddDependancyEscaped( @{$PACKAGE_SETS{$set}{LIST}} );
267 dpurdie 11103
        $me->Print();
11104
    }
11105
}
11106
 
11107
#-------------------------------------------------------------------------------
227 dpurdie 11108
# Function        : UnPackageRule
11109
#
11110
# Description     : Generate rules and recipes to "uninstall" and "unpackage" files
11111
#
11112
# Inputs          : target      - Name of the target
11113
#                   codecmd     - A code reference to the actual installer routine
11114
#                   hashp       - A reference to a INSTALL or PACKAGE hash
11115
#
11116
# Returns         :
11117
#
11118
sub UnpackageRule
11119
{
11120
    my ($target, $codecmd, $hashp) = @_;
11121
 
11122
    MakePrint ".PHONY:\t\t"."$target\n";
11123
    MakePrint "$target:\t";
11124
 
11125
    foreach my $dest ( sort keys %{$hashp} )
11126
    {
11127
 
11128
        my $entry = $hashp->{$dest};
11129
 
11130
        #
11131
        #   Skip placekeepers
11132
        #
11133
        next if ( $entry->{'placekeeper'} );
11134
 
11135
        MakePrint "\n" . $codecmd->($dest);
11136
    }
11137
    MakePrint "\n\n";
11138
}
11139
 
11140
 
11141
#
11142
#   Internal macro interface, see RULE.STD for definitions:
11143
#
11144
sub RmFilesCmd
11145
{
11146
    my ( $list ) = @_;
261 dpurdie 11147
    return "\$(call RmFiles,$list)";
227 dpurdie 11148
}
11149
 
11150
sub InstallCmd
11151
{
2429 dpurdie 11152
    my( $dest, $file, $fmode ) = @_;
227 dpurdie 11153
 
11154
    $fmode = "-w"                           # default, read-only
11155
        if ( !defined( $fmode ) || $fmode eq "" );
11156
 
5991 dpurdie 11157
    $dest = QuoteForMake($dest);
11158
    $file = QuoteForMake($file);
2429 dpurdie 11159
    return "\t\$(call InstallFile,$dest,$file,$fmode)";
227 dpurdie 11160
}
11161
 
11162
sub UninstallCmd
11163
{
11164
    my( $file ) = @_;
5991 dpurdie 11165
    $file = QuoteForMake($file);
227 dpurdie 11166
    return "\t\$(call UninstallFile,$file)";
11167
}
11168
 
11169
sub PackageCmd
11170
{
2429 dpurdie 11171
    my( $dest, $file, $fmode ) = @_;
227 dpurdie 11172
 
11173
    $fmode = "-w"                           # default, read-only
11174
        if ( !defined( $fmode ) || $fmode eq "" );
11175
 
5991 dpurdie 11176
    $dest = QuoteForMake($dest);
11177
    $file = QuoteForMake($file);
2429 dpurdie 11178
    return "\t\$(call PackageFile,$dest,$file,$fmode)";
227 dpurdie 11179
}
11180
 
11181
sub UnpackageCmd
11182
{
11183
    my( $file ) = @_;
5991 dpurdie 11184
    $file = QuoteForMake($file);
227 dpurdie 11185
    return "\t\$(call UnpackageFile,$file)";
11186
}
11187
 
11188
1;
11189