Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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