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