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
        #
5867 dpurdie 2469
        #   Add the file to any source file lists that may like to know
227 dpurdie 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
                {
5867 dpurdie 3106
                    if ($gtype == 2)
303 dpurdie 3107
                    {
5867 dpurdie 3108
                        if ($SRCS{ StripDir( $fn ) })
3109
                        {
3110
                            abtWarning(1,"GenerateFiles. Generated File also a Src file: $fn");
3111
                        }
3112
                        elsif ( GenerateSrcFile ( $gtype, $fn  ) )
3113
                        {
3114
                            push @has_source, $fn;
3115
                        }
303 dpurdie 3116
                    }
3117
                }
227 dpurdie 3118
 
3119
                #
3120
                #   Use the directory or the full name
3121
                #   If using the directory then ensure that we have a name
3122
                #   even if its "."
3123
                #
3124
                $fn = ($use_dir) ? "$use_dir" : "."
3125
                    if ( $cmd =~ /Directory/ );
3126
 
3127
                Debug( "GenerateFiles: Generate: $fn" );
3128
 
3129
            }
3130
            elsif ( $cmd =~ /^Prereq/ )
3131
            {
3132
                #
3133
                #   Prerequisite filename
3134
                #       Resolve the full name of the file. It may be known
3135
                #       as a source file (possibly generated) or it may be
3136
                #       located in a known source directory
3137
                #
3138
                $fn = LocatePreReq ($ufn);
3139
                UniquePush (\@preq_files, $fn);
3140
 
3141
                Debug( "GenerateFiles: Prereq: $fn" );
3142
 
3143
            }
3144
            elsif ( $cmd =~ /^PackageBase/ )
3145
            {
3146
                $fn = GetPackageBase( "GenerateFiles", $raw_arg );
3147
                UniquePush (\@preq_files, $fn);
3148
            }
3149
            elsif ( $cmd =~ /^PackageInfo/ )
3150
            {
3151
                $fn = GetPackageInfo( "GenerateFiles", $raw_arg );
3152
            }
3153
            elsif ( $cmd =~ /^Var/ )
3154
            {
343 dpurdie 3155
                ($fnp, $fn, $is_path) = ExpandGenVar( "GenerateFiles", $raw_arg, @var_opts );
227 dpurdie 3156
                $flags = '';
343 dpurdie 3157
                if ( $raw_arg eq 'ObjDir' ) {
3158
                    UniquePush (\@preq_files, '$(GBE_OBJDIR)');
3159
                } elsif ( $raw_arg eq 'BinDir' ) {
3160
                    UniquePush (\@preq_files, '$(GBE_BINDIR)');
3161
                } elsif ( $raw_arg eq 'LibDir' ) {
3162
                    UniquePush (\@preq_files, '$(GBE_LIBDIR)');
3163
                }
227 dpurdie 3164
            }
3165
            else
3166
            {
3167
                Warning ("GenerateFiles: Unknown replacement command: $cmd");
3168
                $fn = $ufn;
3169
            }
3170
 
3171
            #
3172
            #   Process path modification flags
3173
            #
3174
            $fn = ProcessPathName( $fn, $flags );
3175
 
3176
            #
3177
            #   Minor kludge under windows. Ensure directores have a "\" sep
3178
            #   Unless the user has specified a straight shell command
3179
            #
303 dpurdie 3180
            $fn = "\$(subst /,\\,$fn)"
343 dpurdie 3181
                if ( $is_path && $::ScmHost eq "WIN" && ! defined($shell_script) );
227 dpurdie 3182
 
3183
            #
343 dpurdie 3184
            #   Prepend any $fn Prefix
3185
            #   This will be a tag and is not subject to path processing
3186
            #
3187
            $fn = $fnp . $fn;
3188
 
3189
            #
227 dpurdie 3190
            #   Replace the found string with the real name of the file
3191
            #   Note: 4 argument version of substr is not always available
3192
            #         so we must do it the hard way
3193
            #               substr( $arg, $mb, $me - $mb, $fn);
3194
            #
3195
            $arg = substr( $arg, 0, $mb ) . $fn . substr( $arg, $me );
3196
 
3197
            Debug2( "GenerateFiles: subs: $all -> $fn" );
3198
        }
3199
 
3200
        #
3201
        #   Save the tool arguments in an array
3202
        #
3203
        push @tool_args, $arg;
3204
    }
3205
 
3206
 
3207
    #
5867 dpurdie 3208
    #   Sanity test. Ensure that some file have been marked as generated
227 dpurdie 3209
    #                Warn if no prerequisites found
3210
    #
303 dpurdie 3211
    Warning( "GenerateFiles. --AutoGenerate option has no effect",
3212
             "The following files are 'source' files",  @has_source ) if ( @has_source );
227 dpurdie 3213
    Warning( "No Prerequisite files found in $tool",@tool_args) unless ( $no_warn || $#preq_files >= 0 );
3214
    Error  ( "No generated files found in $tool",@tool_args) unless ($#gen_files >= 0);
3215
 
3216
 
3217
    #
3218
    #   Save information
3219
    #   Will be used to create makefile statements later
3220
    #
3221
    my %gen_data;
3222
 
3223
    $gen_data{'index'}      = $NoGenIndex++;
3224
    $gen_data{'shell'}      = $shell_cmds;
3225
    $gen_data{'gen'}        = \@gen_files;
3226
    $gen_data{'preq'}       = \@preq_files;
3227
    $gen_data{'tool'}       = $tool;
3228
    $gen_data{'toolargs'}   = \@tool_args;
3229
    $gen_data{'clean'}      = $clean_tag;
3230
    $gen_data{'text'}       = $text || $gen_files[0];
3231
    $gen_data{'preq_sus'}   = 1 if ( $preq_unknown );
263 dpurdie 3232
    $gen_data{'predelete'}  = 1 if ( $predelete );
227 dpurdie 3233
 
3234
    push(@GENERATE_FILES, \%gen_data);
3235
 
3236
    Debug2( "GenerateFiles: cmd: $tool @tool_args" );
3237
}
3238
 
3239
#-------------------------------------------------------------------------------
3240
# Function        : MakePerlModule
3241
#
3242
# Description     : Build Perl Module(s) using the Perl Build System
3243
#                   This is a thin wrapper around a specialised script
3244
#
3245
#                   The user can do the same job with correct use of
3246
#                   a GenerateFiles, but this is a lot tidier.
3247
#
3248
# Inputs          : $1      - platform specifier '*' (comma delemitered)
3249
#                   $*      - Paths to Perl Modules[,command options]
3250
#                             Options to the BuildPerl script
3251
#
3252
# Returns         :
3253
#
3254
sub MakePerlModule
3255
{
3256
    my ( $platforms, @args) = @_;
3257
 
3258
    return if ( ! ActivePlatform($platforms) );
3259
 
3260
    Debug2( "MakePerlModule:($platforms, @args)" );
3261
    my @opts;
3262
 
3263
    #
3264
    #   Extract options from paths to Perl Packages
3265
    #   Package names do not start with a '-'
3266
    #
3267
    foreach my $arg ( @args )
3268
    {
3269
        if ( $arg =~ /^-/ ) {
3270
            push @opts, $arg;
3271
 
3272
        } else {
3273
            #
3274
            #   Perl Package Directory Name
3275
            #   This may also contain embedded command to the Make command
3276
            #   These will be seperated with a comma
3277
            #       ie: module,-options=fred
3278
            #
3279
            my ($name,$options) = split( ',', $arg );
3280
            push @opts, "-PerlPackage=$arg";
3281
            push @opts, "--Prereq=$name/Makefile.PL";
3282
        }
3283
    }
3284
 
3285
    #
3286
    #   Invoke GenerateFiles with a bunch of additional arguments
3287
    #
3288
    GenerateFiles ($platforms, "--Tool=jats_buildperl.pl",
3289
                          '--Var(MachType)',                        # Build Machine type
3290
                          '--Var(PackageDir)',                      # Package dir
3291
                          '--NoGenerate',                           # Don't know the output
3292
                          '--Text=Make Perl Module',                # Pretty print
3293
                          '--NoWarn',
3294
                          '--Clean=-clean_build',                   # Jats clean support
3295
                          '--NoVarTag',                             # No more Tags
3296
                          @opts,
3297
                          );
3298
}
3299
 
3300
#-------------------------------------------------------------------------------
3301
# Function        : MakeLinuxDriver
3302
#
3303
# Description     : Build a Linux Device Driver using the Linux Device Driver
3304
#                   Build System
3305
#                   This is a thin wrapper around a specialised script
3306
#
3307
#                   The user can do the same job with correct use of
3308
#                   a GenerateFiles, but this is a lot tidier.
3309
#
3310
# Inputs          : $1      - platform specifier '*' (comma delemitered)
3311
#                   $2      - name of the driver. No extension
3312
#                   $*      - Driver sources
3313
#                             Options to the script
3314
#
3315
# Returns         :
3316
#
3317
sub MakeLinuxDriver
3318
{
3319
    my ( $platforms, $driver_name, @args) = @_;
3320
 
3321
    return if ( ! ActivePlatform($platforms) );
3322
 
285 dpurdie 3323
    Error ("No driver name specified") unless ( $driver_name );
227 dpurdie 3324
    Debug2( "MakeLinuxDriver:($platforms, $driver_name ,@args)" );
3325
    my @srcs;
3326
    my @opts;
3327
 
3328
    #
3329
    #   Extract options from source files
3330
    #   Package names do not start with a '-'
3331
    #
3332
    foreach my $arg ( @args )
3333
    {
3334
         if ( $arg =~ /^--Define=(.)/ ) {
3335
            push @opts, $arg;
5672 dpurdie 3336
 
3337
         } elsif ( $arg =~ /^--ExternalModule=(.)/ ) {
3338
               push @opts, $arg;
227 dpurdie 3339
 
3340
         } elsif ( $arg =~ /^-/ ) {
3341
            push @opts, $arg;
3342
            Warning ("MakeLinuxDriver: Unknown option: $arg. Passed to script");
3343
 
3344
        } else {
3345
            push @srcs, $arg;
3346
            push @opts, "--Prereq=$arg";
3347
        }
3348
    }
3349
 
3350
    #
3351
    #   Cleanup the drive name
3352
    #
3353
    $driver_name =~ s~\.ko$~~;
3354
 
3355
    #
3356
    #   Remove the specified sources from the list of object files
3357
    #   that will be build. This will ensure that some internal rules are
3358
    #   not generated.
3359
    #
3360
    foreach ( @srcs )
3361
    {
3362
        my $file = StripExt(StripDir( $_ ));
3363
        delete $OBJSOURCE{ $file };
3364
        @OBJS = grep(!/^$file$/, @OBJS);
3365
    }
3366
 
3367
    #
3368
    #   Invoke GenerateFiles with a bunch of additional arguments
3369
    #   At runtime the include directories will be added as
3370
    #   absolute paths
3371
    #
3372
    GenerateFiles ($platforms, "--Tool=jats_buildlinux.pl",
3373
                    "-Output=--GeneratedProg($driver_name.ko)",
3374
                    "-Driver=$driver_name",
3375
                    "-GccPath=\$(GCC_CC)",
3376
                    "-Arch=\$(HOST_CPU)",
3377
                    "-LeaveTmp=\$(LEAVETMP)",
3378
                    "-Verbose=\$(CC_PRE)",
3379
                    "-Type=\$(GBE_TYPE)",
3380
                    "-Platform=\$(GBE_PLATFORM)",
5672 dpurdie 3381
                    "--Var(LocalBinDir)",
227 dpurdie 3382
                    '$(patsubst %,-Incdir=%,$(INCDIRS))',
5672 dpurdie 3383
                    '--Clean',
227 dpurdie 3384
                    @opts,
3385
                    @srcs
3386
                    );
3387
}
3388
 
3389
#-------------------------------------------------------------------------------
3390
# Function        : GetPackageBase
3391
#
3392
# Description     : Helper routine
3393
#                   Given a package name, determine the base address of the
3394
#                   package
3395
#
3396
# Inputs          : $dname         - Directive name     (Reporting)
3397
#                   $name          - Required package
3398
#                                    Allows two forms:
3399
#                                       package_name
3400
#                                       package_name,ext
3401
#
3402
# Returns         : Path to the directory in which the files are installed
3403
#                   This may be the interface directory
3404
#
3405
sub GetPackageBase
3406
{
3407
    my ($dname, $fname) = @_;
3408
    my $pkg;
3409
    my ($name, $ext) = split(',', $fname);
3410
 
3411
    $pkg = GetPackageEntry( $name, $ext );
3412
    Error ("$dname: Package not found: $fname") unless ( $pkg );
3413
 
3414
    #
3415
    #   If a BuildPkgArchive then use the interface directory
3416
    #
3417
    return ( $pkg->{'TYPE'} eq 'link' ) ? $pkg->{'ROOT'} : '$(INTERFACEDIR)';
3418
}
3419
 
3420
#-------------------------------------------------------------------------------
3421
# Function        : GetPackageInfo
3422
#
3423
# Description     : Helper routine
3424
#                   Given a package name, return some information about the package
3425
#                   Only one information item is allowed with each call
3426
#
3427
# Inputs          : $dname         - Directive name     (Reporting)
3428
#                   $name          - Required package
3429
#                                    Allows two forms:
3430
#                                       package_name
3431
#                                       package_name,ext
3432
#                                    Selector
3433
#                                       --path
3434
#                                       --version
3435
#                                       --fullversion
3436
#                                       --project
3437
#
3438
# Returns         : Package information
3439
my %GetPackageInfo = qw(path ROOT
3440
                        version DVERSION
3441
                        fullversion VERSION
3442
                        project DPROJ);
3443
sub GetPackageInfo
3444
{
3445
    my ($dname, $args) = @_;
3446
    my $pkg;
3447
    my $name;
3448
    my $ext;
3449
    my $info;
3450
 
363 dpurdie 3451
    #
3452
    #   Split up the arguments
3453
    #       Options start with '--'
3454
    #   First non-option is the package name
3455
    #   2nd non-option is the packag extension
3456
    #
3457
    #   Only one option allowed
3458
    #       Convert it into a known package info item
3459
    #
3460
    #
227 dpurdie 3461
    foreach ( split(',', $args) )
3462
    {
3463
        if ( m/^--(.*)/ ) {
3464
            Error( "$dname: Too many info requests: $args") if ( $info );
3465
            $info = $GetPackageInfo{$1};
3466
            Error( "$dname: Unknown info type: $_") unless ($info);
363 dpurdie 3467
 
227 dpurdie 3468
        } elsif ( $ext ) {
3469
            Error("$dname: Too many names: $args");
363 dpurdie 3470
 
227 dpurdie 3471
        } elsif ( $name ) {
3472
            $ext = $_;
363 dpurdie 3473
 
227 dpurdie 3474
        } else {
3475
            $name = $_;
3476
        }
3477
    }
3478
 
3479
    $pkg = GetPackageEntry( $name, $ext );
3480
    Error ("$dname: Package not found: $args") unless ( $pkg );
3481
 
3482
    #
3483
    #   If a BuildPkgArchive then use the interface directory
363 dpurdie 3484
    #   Default data item - path to the package
227 dpurdie 3485
    #
363 dpurdie 3486
    $info = 'ROOT' unless ( $info );
3487
    if ( $info eq 'ROOT' &&  $pkg->{'TYPE'} ne 'link' )
227 dpurdie 3488
    {
3489
        return ( '$(INTERFACEDIR)');
3490
    }
363 dpurdie 3491
 
227 dpurdie 3492
    return ( $pkg->{$info} );
3493
}
3494
 
3495
#-------------------------------------------------------------------------------
3496
# Function        : GetPackageEntry
3497
#
3498
# Description     : Return the package class pointer given a package name
3499
#
3500
# Inputs          : $name          - Required package
3501
#                   $ext           - Option package extension
3502
#
3503
# Returns         : Class pointer
3504
#
3505
sub GetPackageEntry
3506
{
3507
    my ($name, $ext) = @_;
3508
    $ext = '' unless ( $ext );
3509
 
3510
    for my $entry (@{$::ScmBuildPkgRules{$ScmPlatform} })
3511
    {
3512
        next unless ( $entry->{'NAME'} eq $name );
3513
        next if ( $ext && $entry->{'DPROJ'} ne $ext );
3514
        return $entry;
3515
    }
285 dpurdie 3516
    return;
227 dpurdie 3517
}
3518
 
3519
#-------------------------------------------------------------------------------
3520
# Function        : ExpandGenVar
3521
#
3522
# Description     : Expand a known variable for the Generate Files option
3523
#
3524
# Inputs          : $dname         - Directive name     (Reporting)
3525
#                   $arg           - Raw argument
3526
#                                    This of the form of
3527
#                                       Tag[,--option]+
3528
#                                    Tags are specified in %ExpandGenVarConvert
3529
#
3530
#                                   Options are:
3531
#                                       --tag
3532
#                                       --notag
3533
#                                       --tag=<SomeTag>
3534
#                                       --absdrive
3535
#                                       --abspath
285 dpurdie 3536
#                                       --default=text
343 dpurdie 3537
#                                       --allownone
227 dpurdie 3538
#                                   Not all options are avalaible on all variables
3539
#                   @opts           - Options
3540
#                                       --notag     - Default is --notag
3541
#
343 dpurdie 3542
# Returns         : Tag             - Any tag component of the expansion
3543
#                   Path/Value      - Path/Value of the component
3544
#                   is_path         - Above is a path
3545
#                   is_abs          - Path is absolute
227 dpurdie 3546
#
3547
 
3548
#
3549
#   Create a Hash to simplify the process of converting Var names
343 dpurdie 3550
#   into makefile variables. There are two data items, separated by a comma.
3551
#       The first is the runtime expansion value
3552
#       The second describes the first:
3553
#           NotPresent  - Expansion is not a path
3554
#           '-'         - Expansion is a path and is relative to CWD
3555
#           '+'         - Expansion is a path and is absolute
227 dpurdie 3556
#
3557
my %ExpandGenVarConvert = (
3558
    'BuildName'         => '$(GBE_PBASE)',
3559
    'BuildVersion'      => '$(BUILDVER)',
3560
    'BuildVersionNum'   => '$(BUILDVERNUM)',
3561
 
3562
    'PackageDir'        => '$(PKGDIR),+',
3563
    'PackagePkgDir'     => '$(PKGDIR)/pkg/pkg.$(GBE_PLATFORM),+',
3564
    'PackageIncDir'     => '$(INCDIR_PKG),+',
3565
    'PackageLibDir'     => '$(LIBDIR_PKG)/$(GBE_PLATFORM),+',
3566
    'PackageBinDir'     => '$(BINDIR_PKG)/$(GBE_PLATFORM)$(GBE_TYPE),+',
3567
 
3568
    'PackageToolDir'    => '$(PKGDIR)/tools,+',
3569
    'PackageToolBin'    => '$(PKGDIR)/tools/bin/$(GBE_HOSTMACH),+',
3570
    'PackageToolScript' => '$(PKGDIR)/tools/scripts,+',
3571
 
3572
    'LibDir'            => '$(LIBDIR),+',
3573
    'BinDir'            => '$(BINDIR),+',
3574
    'ObjDir'            => '$(OBJDIR),+',
3575
 
3576
    'InterfaceDir'      => '$(INTERFACEDIR),+',
3577
    'InterfaceIncDir'   => '$(INCDIR_INTERFACE),+',
3578
    'InterfaceLibDir'   => '$(LIBDIR_INTERFACE)/$(GBE_PLATFORM),+',
3579
    'InterfaceBinDir'   => '$(BINDIR_INTERFACE)/$(GBE_PLATFORM)$(GBE_TYPE),+',
3580
 
3581
    'LocalDir'          => '$(LOCALDIR),+',
3582
    'LocalIncDir'       => '$(INCDIR_LOCAL),+',
3583
    'LocalLibDir'       => '$(LIBDIR_LOCAL)/$(GBE_PLATFORM),+',
3584
    'LocalBinDir'       => '$(BINDIR_LOCAL)/$(GBE_PLATFORM)$(GBE_TYPE),+',
3585
 
3586
    'Platform'          => '$(GBE_PLATFORM)',
3587
    'Product'           => '$(GBE_PRODUCT)',
3588
    'Target'            => '$(GBE_TARGET)',
3589
 
3590
    'Type'              => '$(GBE_TYPE)',
3591
    'Arch'              => '$(HOST_CPU)',
3592
    'Architecture'      => '$(HOST_CPU)',
3593
    'MachType'          => '$(GBE_HOSTMACH)',
3594
    'BuildRoot'         => '$(GBE_ROOT),+',
3595
 
3596
 
3597
    'Verbose'           => '$(CC_PRE)',
3598
    'LeaveTmp'          => '$(LEAVETMP)',
329 dpurdie 3599
    'Cwd'               => '$(CURDIR),-',
227 dpurdie 3600
 
3601
    'CompilerPath'      => '$(SCM_COMPILERPATH)',
3967 dpurdie 3602
    'PkgArch'           => '$(PACKAGE_ARCH)',
227 dpurdie 3603
    );
3604
 
3605
sub ExpandGenVar
3606
{
3607
    my ($dname, $args, @uopts) = @_;
3608
    my $expansion;
3609
    my $prefix='';
3610
    my ($tag, @opts) = split('\s*,\s*', $args);
3611
    my $no_prefix;
285 dpurdie 3612
    my $default_value;
3613
    my $allow_none;
329 dpurdie 3614
    my $is_abs = 0;
227 dpurdie 3615
 
285 dpurdie 3616
    #
3617
    #   Parse options lists
3618
    #       Options provided by the caller
3619
    #       Options embedded in the argument
227 dpurdie 3620
    foreach ( @uopts )
3621
    {
3622
        if ( m/^--notag$/ ) {
3623
            $no_prefix = 1;
3624
        } else{
3625
            Error ("$dname: Unknown option: $_")
3626
        }
3627
    }
3628
 
285 dpurdie 3629
    foreach ( @opts )
3630
    {
3631
        if ( m/^--default=(.+)/i ) {
3632
            $default_value = $1;
3633
        } elsif ( m/^--allownone$/i ) {
3634
            $allow_none = 1;
3635
        }
3636
    }
3637
 
227 dpurdie 3638
    #
3639
    #   Perform run-time update on the %ExpandGenVarConvert
3640
    #   Most of it can be initialised at startup - but not all of it.
3641
    #
3642
    $ExpandGenVarConvert{CompilerPath} = undef unless $::ScmToolsetCompilerPath;
3643
    $ExpandGenVarConvert{Product}      = '$(GBE_PLATFORM)' unless $ScmProduct;
3644
 
3645
    #
3646
    #   Look up a hash of conversions
3647
    #   Could allow for a code ref, but not needed yet
3648
    #
3649
    Error ("$dname: Unknown expansion --Var($tag)")
3650
        unless ( exists $ExpandGenVarConvert{$tag} );
3651
 
285 dpurdie 3652
    #
3653
    #   Handle undefined expansions
3654
    #   Only 'CompilerPath', but it can be a pain in user land
3655
    #
3656
    $expansion = $ExpandGenVarConvert{$tag};
3657
    unless ( defined $expansion  )
3658
    {
3659
        return '' if ( $allow_none );
3660
        $expansion = $default_value;
3661
        Error ("$dname: Expansion --Var($tag) not be supported by toolset: $ScmToolset")
3662
            unless ( $expansion );
3663
    }
227 dpurdie 3664
 
285 dpurdie 3665
 
227 dpurdie 3666
    ($expansion,my $is_path) = split (',', $expansion );
329 dpurdie 3667
    $is_abs = 1
3668
        if ($is_path && $is_path eq '-' );
227 dpurdie 3669
 
3670
    #
3671
    #   Process options
3672
    #   Assume that a tag will be provided
3673
    #
3674
    $prefix =  $no_prefix ? '' : "-$tag=";
3675
    foreach my $opt ( @opts )
3676
    {
3677
        if ( $opt =~ /^--tag=(.*)/i ) {
3678
            $prefix = "$1=";
3679
 
3680
        } elsif ( $opt =~ m/^--tag$/i ) {
3681
            $prefix = "-$tag=";
3682
 
3683
        } elsif ( $opt =~ m/^--notag/i ) {
3684
            $prefix = '';
3685
 
329 dpurdie 3686
        } elsif ( $is_path && !$is_abs && $opt =~ /--abspath|--absdrive/i ) {
227 dpurdie 3687
            $expansion = '$(CURDIR)/' . $expansion;
329 dpurdie 3688
            $is_abs = 1;
227 dpurdie 3689
 
285 dpurdie 3690
        } elsif ( $opt =~ m/^--default=(.+)/i ) {
3691
            # Already processed
3692
        } elsif ( $opt =~ m/^--allownone$/i ) {
3693
            # Already processed
227 dpurdie 3694
        } else {
3695
            Error ("$dname: Unsupported option($opt) for --Var(@_)");
3696
        }
3697
    }
3698
 
3699
    Debug ("ExpandGenVar: args $args --> $prefix$expansion");
343 dpurdie 3700
    return $prefix , $expansion, $is_path ? 1 : 0, $is_abs;
227 dpurdie 3701
 
3702
}
3703
 
3704
#-------------------------------------------------------------------------------
3705
# Function        : ProcessPathName
3706
#
3707
# Description     : Massage a pathname according to a set of flags
3708
#
3709
# Inputs          : $fn         - Patchname to massage
3710
#                   $flags      - Flags in a string
3711
#                                   --dir       - only the directory part ( or a "." )
3712
#                                   --file      - only the file part
3713
#                                   --abspath   - Absolute path
3714
#                                   --absdrive  - Absolute path with drive letter(WIN)
3715
#
3716
# Returns         : Massaged pathname
3717
#
3718
sub ProcessPathName
3719
{
3720
    my ( $fn, $flags ) = @_;
3721
    #
3722
    #   Process flags
3723
    #       --dir           - only the directory part ( or a "." )
3724
    #       --file          - only the file part
3725
    #       --abspath       - Absolute path
3726
    #       --absdrive      - Absolute path with drive letter(WIN)
3727
    #
3728
    if ( $flags =~ /--dir/ )
3729
    {
3730
        $fn = '.'
3731
            unless ( $fn =~ s~/[^/]*$~~);
3732
    }
3733
 
3734
    if ( $flags =~ /--file/ )
3735
    {
3736
        $fn =~ s~.*/~~;
3737
    }
3738
 
3739
    if ( $flags =~ /--abspath/ )
3740
    {
3741
        $fn = AbsPath( $fn );
3742
    }
3743
    elsif ( $flags =~ /--absdrive/ )
3744
    {
3745
        $fn = AbsPath( $fn );
3746
        if ( $::ScmHost eq "WIN" )
3747
        {
3748
            $fn = $::CwdDrive . '/' . $fn
3749
                unless ( $fn =~ m~^\w:/~  );
3750
            $fn =~ s~//~/~g;
3751
        }
3752
    }
3753
 
3754
  return $fn;
3755
}
3756
 
3757
#-------------------------------------------------------------------------------
3758
# Function        : LocatePreReq
3759
#
3760
# Description     : Locate a file known to JATS
3761
#                   There are many places to search
3762
#                       1) Src files - specified with a Src directive
3763
#                       2) Scripts - specified with a script directive
3764
#                       3) Search - Files in the specified search path
3765
#                       4) Programs specified with a 'Prog' directive
3766
#
3767
#                   Should also look in other locations (Libs, SharedLibs)
3768
#                   Not done yet. May be issues of a name clash if a program
3769
#                   and a library have the same name.
3770
#
3771
# Inputs          : Name to locate
3772
#
3773
# Returns         : Full pathname of file
3774
#
3775
sub LocatePreReq
3776
{
3777
    my ( $name ) = @_;
3778
    Debug ("LocatePreReq:Looking for $name");
3779
    #
3780
    #   Try a Src file first
3781
    #
3782
    if ( exists $SRCS{ $name } )
3783
    {
3784
        return $SRCS{ $name };
3785
    }
3786
 
3787
    #
3788
    #   Try a script
3789
    #
3790
    if ( exists $SCRIPTS{ $name } )
3791
    {
3792
        return $SCRIPTS{ $name };
3793
    }
3794
 
3795
    #
3796
    #   Try a PROG
3797
    #
289 dpurdie 3798
    if ( my $pProg = $PROGS->Get($name) )
227 dpurdie 3799
    {
289 dpurdie 3800
        return $pProg->getPath();
227 dpurdie 3801
    }
3802
 
3803
    #
3804
    #   Try searching for the file
3805
    #   Uses Data from AddSrcDir
3806
    #
3807
    #   Done: last because it generates warning messages
3808
    #
3809
    return MakeSrcResolve( $name );
3810
}
3811
 
3812
#-------------------------------------------------------------------------------
3813
# Function        : ToolExtensionPaths
3814
#
3815
# Description     : Return a list of toolset extension directories
3816
#                   The data will have been discovered by the build process
3817
#                   and will have been saved for the makefile creation phase
3818
#
3819
# Inputs          : None
3820
#
3821
# Returns         : Return an ordered unique list
3822
#
3823
sub ToolExtensionPaths
3824
{
3825
    Debug( "ToolExtensionPaths:", @::BUILDTOOLSPATH );
3826
    return @::BUILDTOOLSPATH;
3827
}
3828
 
3829
#-------------------------------------------------------------------------------
3830
# Function        : ToolExtensionProgram
3831
#
3832
# Description     : Determine if the named program exists within the PATH
3833
#                   that also includes the toolset extension
3834
#
3835
# Inputs          : program             - Name of program
3836
#                   elist               - An array of possible program extensions
3837
#
4324 dpurdie 3838
# Returns         : Full path the to program or an empty elelent (not undef)
227 dpurdie 3839
#
3840
sub ToolExtensionProgram
3841
{
3842
    my ($program, @elist ) = @_;
3843
 
3844
    #
3845
    #   If elist is empty then insert a defined entry
3846
    #
3847
    push @elist, '' unless ( @elist );
3848
 
3849
    #
3850
    #   Scan all toolset directories
3851
    #   for the program
3852
    #
3853
    for my $dir ( ToolExtensionPaths() )
3854
    {
3855
        for my $ext ( @elist )
3856
        {
3857
            my $tool = "$dir/$program$ext";
4324 dpurdie 3858
            Debug( "ToolsetExtensionProgram: Look for: $tool" );
227 dpurdie 3859
 
3860
            return $tool if ( -f $tool );
3861
        }
3862
    }
3863
}
3864
 
3865
sub Define
3866
{
3867
    Debug2( "Define(@_)" );
3868
 
3869
    push( @DEFINES, @_ );
3870
}
3871
 
3872
 
3873
sub Defines
3874
{
3875
    my( $path, $script ) = @_;
3876
    my( $line );
3877
 
3878
    Debug2( "Defines($path, $script)" );
3879
 
3880
    $script = Exists( $path, $script, "Defines" );
271 dpurdie 3881
    push( @DEFINES, "# Defines from: $script" );
285 dpurdie 3882
    open( my $fh, '<', $script ) || Error( "Opening $script" );
3883
    while (<$fh>) {
227 dpurdie 3884
        $_ =~ s/\s*(\n|$)//;                    # kill trailing whitespace & nl
3885
        push( @DEFINES, $_ );
3886
    }
3887
    push( @ScmDepends, "$script" );             # makefile dependencies
285 dpurdie 3888
    close( $fh );
227 dpurdie 3889
}
271 dpurdie 3890
#-------------------------------------------------------------------------------
3891
# Function        : Rule
3892
#
3893
# Description     : Add a Rule and Recipe to the generated makefile
3894
#                   This is not encouraged as it has been misused to create
3895
#                   unreadable and unmaintainable makefiles.
3896
#
3897
#                   Rules will be added to the makefile after the rules and
3898
#                   recipes created by JATS directives
3899
#
3900
# Inputs          : $platform               - Platform predicate
3901
#                   @rule                   - Array of rules to add
3902
#
3903
# Returns         : 
3904
#
227 dpurdie 3905
sub Rule
3906
{
3907
    my( $platforms, @rule ) = @_;
3908
 
3909
    return if ( ! ActivePlatform($platforms) );
3910
 
3911
    push( @RULES, @rule );
3912
    Message("Rule directive used. Consider replacing with GenerateFiles");
3913
}
3914
 
271 dpurdie 3915
#-------------------------------------------------------------------------------
3916
# Function        : Rules
3917
#
3918
# Description     : Add a file of Rules and Recipes to the generated makefile
3919
#                   Used internally ONLY as there is no platform predicate
3920
#                   Similar to 'Rule()'
3921
#
3922
# Inputs          : $path                   - path to script
3923
#                   $script                 - File fo Rules
3924
#
3925
# Returns         : 
3926
#
227 dpurdie 3927
sub Rules
3928
{
3929
    my( $path, $script ) = @_;
3930
    my( $line );
3931
 
3932
    $script = Exists( $path, $script, "Rules" );
271 dpurdie 3933
    push( @RULES, "# Rules from: $script" );
285 dpurdie 3934
    open( my $fh, '<', $script ) || Error( "Opening $script" );
3935
    while (<$fh>) {
227 dpurdie 3936
        $_ =~ s/\s*(\n|$)//;                    # kill trailing whitespace & nl
3937
        push( @RULES, $_ );
3938
    }
3939
    push( @ScmDepends, "$script" );             # makefile dependencies
285 dpurdie 3940
    close( $fh );
227 dpurdie 3941
}
3942
 
271 dpurdie 3943
#-------------------------------------------------------------------------------
3944
# Function        : AddRule
3945
#
3946
# Description     : Inernal function
3947
#                   Add a line to the Rules area
3948
#
3949
# Inputs          : @elements                   - Array of lines to add
3950
#
3951
# Returns         : Nothing
3952
#
3953
sub AddRule
3954
{
3955
    push( @RULES, @_ );
3956
}
227 dpurdie 3957
 
271 dpurdie 3958
#-------------------------------------------------------------------------------
3959
# Function        : Src
3960
#
3961
# Description     : This directive is used to identify files to JATS
3962
#                   Once a file has been identified as a 'Source' file, then it
3963
#                   can be used by name, without the need to locate the file again.
3964
#                   This implies that filenames must be unique.
3965
#                   The directories cannot be used to make files of the same name
3966
#                   unqiue - this is not the JATS way
3967
#
3968
#                   Source files will be classified as one of:
3969
#                       c, c++, header, assembler or other
3970
#
3971
#
3972
# Inputs          : $platform               - Active Platform Predicate
3973
#                   @elements               - A list of files and options
3974
#
3975
#                   Valid options are:
3976
#                       --c                 - Specifies the type of file
3977
#                       --cpp
3978
#                       --h, --headers
3979
#                       --asm
3980
#                       --FromPackage       - Search packages for the file
3981
#                       --List=xxx          - Append file to a named list
3982
#                       --Depends=xxx       - Manually name a dependency
3983
#
3984
#                   Options are processed before file elements
3985
#                   Thus options apply to all files in the list
3986
#
3987
# Returns         : Nothing
3988
#
227 dpurdie 3989
sub Src
3990
{
3991
    my( $platforms, @elements ) = @_;
3992
    my( $type, @args, $source, $basename, $from_package, @lists );
3993
    my( @depends, @srcs );
3994
 
3995
    $platforms = '' unless ( $platforms );
3996
    Debug2( "Src($platforms, @elements)" );
3997
 
3998
    #
3999
    #   Ensure that there is a file within the list
4000
    #
4001
    Warning( "Src directive does not specify any files: Src($platforms, @elements)" )
4002
        unless (grep( /^[^-]/, @elements ) );
4003
 
4004
    return if ( ! ActivePlatform($platforms) );
4005
 
4006
    #
4007
    #   Remove spaces from both ends of the arguments.
4008
    #   It is easier to remove spaces now than to detect them later
4009
    #
4010
    foreach ( @elements )
4011
    {
4012
        s/^\s+//;
4013
        s/\s+$//;
4014
        s~//~/~g;                               # Remove multiple /
4015
    }
4016
 
4017
    #.. Collect arguments
4018
    #
4019
    $type = "";
4020
    foreach ( @elements )
4021
    {
4022
        if ( /^--c$/ )
4023
        {
4024
            Debug( "Src: --c" );
4025
            $type = ".c";
4026
        }
4027
        elsif ( /^--cpp$/ )
4028
        {
4029
            Debug( "Src: --cpp" );
4030
            $type = ".cc";
4031
        }
4032
        elsif ( /^--h$/ || /^--header$/ )
4033
        {
4034
            Debug( "Src: --h" );
4035
            $type = ".h";
4036
        }
4037
        elsif ( /^--asm$/ )
4038
        {
4039
            Debug( "Src: --asm" );
4040
            $type = ".asm";
4041
        }
4042
        elsif ( /^--FromPackage$/ )
4043
        {
4044
            $from_package = 1;
4045
        }
4046
        elsif ( /^--List=(.*)/ )
4047
        {
4048
            my $list_name = $1;
4049
            Error( "Bad list name: $list_name" )
4050
                unless ( $list_name =~ m/^[A-Za-z]\w+/ );
4051
            push @lists, $list_name;
4052
        }
4053
        elsif ( /^--Depends=(.*)/ )
4054
        {
4055
            foreach ( split( ',', $1) )
4056
            {
4057
                my $full = MakeSrcResolveExtended( $from_package, $_ );
4058
                push @depends, $full;
4059
            }
4060
        }
4061
        elsif ( /^-(.*)/ )
4062
        {
4063
            Debug( "Src: arg $_" );
4064
            push @args, $_;
4065
        }
4066
        else
4067
        {
4068
            push @srcs, $_;
4069
            Warning ("Src files contains a '\\' character: $_" ) if (m~\\~);
4070
        }
4071
    }
4072
 
4073
    #.. Push source file(s)
4074
    foreach ( @srcs )
4075
    {
4076
        if ( ! /^-(.*)/ )
4077
        {
4078
            $source = MakeSrcResolveExtended( $from_package, $_ );
4079
            $basename = StripDir( $source );
4080
            Debug( "Src: $_ -> $source=$basename (@args),(@depends)" );
4081
 
4082
            if ( $SRCS{ $basename } ) {
4083
                Warning( "Duplicate src ignored '$source'");
4084
                next;
4085
            }
4086
            $SRCS{ $basename } = $source;
4087
 
4088
            HashJoin( \%SRC_ARGS, $;, $basename, @args )
4089
                if (@args);
4090
 
4091
            HashJoin( \%SRC_DEPEND, $;, $basename, @depends )
4092
                if ( @depends );
4093
 
4094
            $SRC_TYPE{ $basename } = $type
4095
                if ($type);
4096
 
4097
 
4098
            foreach (@lists) {
4099
                my $lname_short = "LIST_$_";
4100
                my $lname_full = "LIST_FULL_$_";
4101
 
4102
                no strict 'refs';
4103
 
4104
                push @$lname_short,$basename;
4105
                push @$lname_full ,$source;
4106
 
4107
                use strict 'refs';
4108
            }
4109
 
4110
            __AddSourceFile( 1, $source, "", $type );
4111
        }
4112
    }
4113
}
4114
 
4115
 
4116
###############################################################################
4117
#  sub LibNameSplit
4118
#      Just a little help to deal with major/minor stuff for shared libs -
4119
#      given the name of the library as the argument, split out major and minor
4120
#      parts and return the basename, i.e name without major and minor and
4121
#      the pair of major and minor.
4122
###############################################################################
4123
 
4124
sub LibNameSplit
4125
{
4126
    my ( @bits ) = split('\.', $_[0]);
4127
    my ( $major, $minor );
4128
 
4129
    if ($#bits >= 1) {
4130
        $major = $bits[0]; $minor = $bits[1];
4131
    } elsif ($#bits >= 0) {
4132
        $major = $bits[0]; $minor = 0;
4133
    } else {
4134
        $major = 1; $minor = 0;
4135
    }
4136
    Debug( "LibName: $@_[0] ($major.$minor)" );
4137
    return ($major, $minor);
4138
}
4139
 
4140
#-------------------------------------------------------------------------------
4141
# Function        : Lib
4142
#
4143
# Description     : Generate a static library
4144
#
4145
# Inputs          : Platform specifier
4146
#                   Name of the library
4147
#                   Arguemnts ...
4148
#
4149
# Returns         :
4150
#
4151
sub Lib
4152
{
4153
    my( $platforms, $lib, @args ) = @_;
4154
    return if ( ! ActivePlatform($platforms) );
4155
 
4156
    Error ("Lib: Library name not defined") unless ( $lib );
4157
 
4158
    #
4159
    #   May be a shared library or a static library - for historic reasons
4160
    #   If the user has specified a --Shared then its a shared library
4161
    #
4162
    return SharedLib( @_ )
4163
        if ( grep (/^--Shared/, @args) );
4164
 
4165
    #
4166
    #   Does this toolset support libraries
4167
    #
4168
    Error ("Libraries are not supported") unless ( defined $::a );
4169
 
4170
    #.. Fully qualify library path for addition to library list.
4171
    $lib = "lib$lib"
4172
       if ( $ScmTargetHost eq "Unix" && $lib !~ m/^lib/);
4173
    Debug( "Lib: $lib" );
4174
 
4175
    #
289 dpurdie 4176
    #   Create a new object to describe the library
227 dpurdie 4177
    #   Ensure that only one such lib exists
289 dpurdie 4178
    #   Add the library to the list of static libraries
227 dpurdie 4179
    #
4180
    Error( "Library of the same name already defined: $lib" )
289 dpurdie 4181
        if ( $LIBS->Get($lib) );
4182
    $LIBS->NewAdd($lib);
227 dpurdie 4183
 
4184
    #
4185
    #   Process arguments
4186
    #
4187
    push( @LINTLIBS, $lib );
4188
    _LibArgs( $lib, @args );
4189
}
4190
 
4191
 
4192
#-------------------------------------------------------------------------------
4193
# Function        : SharedLib
4194
#
4195
# Description     : Generate a shared library
4196
#
4197
# Inputs          : Platform specifier
4198
#                   Name of the library
4199
#                   Arguemnts ...
4200
#
4201
# Returns         :
4202
#
4203
sub SharedLib
4204
{
4205
    my( $platforms, $lib, @args ) = @_;
4206
 
4207
    return if ( ! ActivePlatform($platforms) );
4208
 
4209
    Error ("SharedLib: Library name not defined") unless ( $lib );
4210
    Error ("Shared Libraries are not supported") unless ( defined $::so );
4211
 
4212
#.. Fully qualify library path for addition to library list.
4213
    $lib = "lib$lib"
4214
       if ( $ScmTargetHost eq "Unix" && $lib !~ m/^lib/);
4215
    Debug( "ShLib: $lib" );
4216
 
4217
    #
4218
    #   Ensure that only one such lib exists
4219
    #
289 dpurdie 4220
    Error( "Library of the same name already defined: $lib" )
4221
        if ( $SHLIBS->Get($lib) );
4222
    $SHLIBS->NewAdd($lib);
293 dpurdie 4223
 
227 dpurdie 4224
    #
4225
    #   If the user has not specified a --Shared parameter then provide one
4226
    #
4227
    push @args, "--Shared=Current"
4228
        unless ( grep (/^--Shared/, @args) );
4229
 
4230
    #
4231
    #   Process arguments
4232
    #
4233
    push( @LINTSHLIBS, $lib );
4234
    _SharedLibArgs( $lib, @args );
4235
}
4236
 
4237
 
4238
#-------------------------------------------------------------------------------
4239
# Function        : LibArgs
4240
#
4241
# Description     : Add arguments to an existing library directive
4242
#
4243
# Inputs          : Platform specifier
4244
#                   Name of the library
4245
#                   Arguemnts ...
4246
#
4247
# Returns         :
4248
#
4249
sub LibArgs
4250
{
4251
    my( $platforms, $lib, @args ) = @_;
4252
    return if ( ! ActivePlatform($platforms) );
4253
 
4254
#.. Fully qualify library path for addition to library list.
4255
    $lib = "lib$lib"
4256
       if ( $ScmTargetHost eq "Unix" && $lib !~ m/^lib/);
4257
    Debug( "LibArgs: $lib" );
4258
 
4259
    #
4260
    #   Process the arguments
4261
    #
4262
    _LibArgs( $lib, @args );
4263
}
4264
 
4265
 
4266
#-------------------------------------------------------------------------------
4267
# Function        : _LibArgs
4268
#
4269
# Description     : Process static library arguments
4270
#                   Internal use only
4271
#
4272
# Inputs          : Name of the library
4273
#                   Arguments to process
4274
#
4275
sub _LibArgs
4276
{
4277
    my( $lib, @elements) = @_;
4278
    my $obj;
4279
 
4280
    #
289 dpurdie 4281
    #   Ensure that only one such lib exists
4282
    #
4283
    my $libp = $LIBS->Get($lib);
4284
    Error("Library name not defined: $lib")
4285
        unless ( $libp );
4286
 
4287
    #
227 dpurdie 4288
    #   Process each element
4289
    #
4290
    foreach (@elements)
4291
    {
371 dpurdie 4292
        if ( /^\s+/ )
4293
        {
4294
            Error ("Argument cannot start with a space: '$_'");
4295
        }
227 dpurdie 4296
        if ( /^--Shared/ )
4297
        {
4298
            Error( "--Shared not valid for a static library" );
4299
        }
4300
 
4301
        if ( /^-l(.*)/ || /^--l(.*)/ || /^-L(.*)/ || /^--L(.*)/ )
4302
        {
4303
        #.. Target library specified - add to library list.
4304
        #
4305
            Warning( "$_ within non shared library specification" );
4306
            next;
4307
        }
4308
 
4309
        if ( /^--if(.*)/ )
4310
        {
4311
            Warning( "$_ within non shared library specification" );
4312
            next;
4313
        }
4314
 
4315
        if ( /^--(.*)/ )
4316
        {
4317
            Debug( "LibArgs: arg $_" );
4318
 
4319
            #.. Argument specified - add to argument list
4320
            #
289 dpurdie 4321
            $libp->addItem('ARGS', $_);
4322
 
227 dpurdie 4323
            next;
4324
        }
4325
 
369 dpurdie 4326
        if ( %::ScmToolsetProgSource )
227 dpurdie 4327
        {
4328
            #
4329
            #   Toolset provides support for some file types
4330
            #   to be passed directly to the librarian builder
4331
            #
4332
            my $ext  = StripFile($_);
4333
            if ( exists ($::ScmToolsetProgSource{$ext}) )
4334
            {
4335
                my $full_path = MakeSrcResolve ( $_ );
4336
                my $flag = $::ScmToolsetProgSource{$ext};
4337
                Debug( "LibArgs: src $_" );
289 dpurdie 4338
                $libp->addItem('ARGS', "$flag$full_path" );
227 dpurdie 4339
                next;
4340
            }
4341
        }
4342
 
4343
        if ( $::o )
4344
        {
4345
        #.. Object specified - add to object list.
4346
        #
4347
            $obj = _LibObject( "", $_ );
4348
 
4349
        #.. Add to object list.
4350
        #   Note:   Object path must be explicit as several
4351
        #           toolsets add additional objects.
4352
        #
289 dpurdie 4353
            $libp->addItem('OBJS', "\$(OBJDIR)/$obj" );
227 dpurdie 4354
            next;
4355
        }
4356
 
4357
        #
4358
        #   Don't know how to handle this type of argument
4359
        #
4360
        Error ("LibArgs: Don't know how to handle: $_" );
4361
    }
4362
}
4363
 
4364
 
4365
#-------------------------------------------------------------------------------
4366
# Function        : SharedLibArgs
4367
#
4368
# Description     : Add arguments to an existing shared library directive
4369
#
4370
# Inputs          : Platform specifier
4371
#                   Name of the library
4372
#                   Arguemnts ...
4373
#
4374
# Returns         :
4375
#
4376
sub SharedLibArgs
4377
{
4378
    my( $platforms, $lib, @args ) = @_;
4379
    return if ( ! ActivePlatform($platforms) );
4380
 
4381
#.. Fully qualify library path for addition to library list.
4382
    $lib = "lib$lib"
4383
       if ( $ScmTargetHost eq "Unix" && $lib !~ m/^lib/);
4384
    Debug( "ShLibArgs: $lib" );
4385
 
4386
    _SharedLibArgs( $lib, @args );
4387
}
4388
 
4389
 
4390
#-------------------------------------------------------------------------------
4391
# Function        : _SharedLibArgs
4392
#
4393
# Description     : Process shared library arguments
4394
#                   Internal use only
4395
#
4396
# Inputs          : Name of the library
4397
#                   Arguments to process
4398
#
4399
sub _SharedLibArgs
4400
{
4401
    my ( $lib, @elements) = @_;
4402
 
289 dpurdie 4403
    my $libp = $SHLIBS->Get($lib);
4404
    Error("Library name not defined: $lib")
4405
        unless ( $libp );
4406
 
227 dpurdie 4407
    #
289 dpurdie 4408
    #.. Collect --Shared arguments
339 dpurdie 4409
    #   Need to process this one first so that we have a version number
227 dpurdie 4410
    #
4411
    foreach (@elements)
4412
    {
371 dpurdie 4413
        if ( /^\s+/ )
4414
        {
4415
            Error ("Argument cannot start with a space: '$_'");
4416
        }
289 dpurdie 4417
        next unless ( /^--Shared/ );
4418
 
4419
        my $shared;
227 dpurdie 4420
        if ( /^--Shared$/ )
4421
        {
4422
        #.. Shared library, default library version 1.0
4423
        #
4424
            $shared = "1.0";
4425
        }
4426
        elsif ( /^--Shared=Current$/ )
4427
        {
4428
        #.. Shared library, using 'current' build version
4429
        #
4430
            $shared = $::ScmBuildVersion;
289 dpurdie 4431
            $shared = "1.0" if ($shared eq "");
227 dpurdie 4432
        }
4433
        elsif ( /^--Shared=(.*)/ )
4434
        {
4435
        #.. Shared library, specific version
4436
        #
4437
            my($M, $m) = LibNameSplit($1);
289 dpurdie 4438
            $shared = "$M.$m";
4439
        }
227 dpurdie 4440
 
289 dpurdie 4441
        #
4442
        #   Update the shared Names
4443
        #
4444
        if ( defined $shared )
4445
        {
227 dpurdie 4446
            Warning( "multiple --Shared arguments" )
339 dpurdie 4447
                if (exists $libp->{ VERSION });
227 dpurdie 4448
            Debug( "ShLibArgs: shared $_ ($shared)" );
289 dpurdie 4449
            $libp->{ VERSION } = $shared;
227 dpurdie 4450
        }
289 dpurdie 4451
        else
4452
        {
4453
            Error ("ShLibArgs: --Shared argument not understood");
4454
        }
227 dpurdie 4455
    }
4456
 
4457
 
4458
#.. Parse all of the object and argument entries.
4459
#
4460
    foreach (@elements)
4461
    {
289 dpurdie 4462
        next if ( /^--Shared(.*)/ );
227 dpurdie 4463
 
4464
        if ( /^[-]{1,2}([lL])(.*)/ )
4465
        {
4466
        #.. Target library specified - add to library list.
339 dpurdie 4467
        #   Support --L and -L and --l and -l
227 dpurdie 4468
        #
4469
            Debug( "ShLibArgs: lib  -$1$2" );
289 dpurdie 4470
            $libp->addItem('LIBS', "-$1$2" );
227 dpurdie 4471
            next;
4472
        }
4473
 
4474
        if ( /^--if(.*)/ )
4475
        {
4476
        #.. Library conditional - add to library list.
4477
        #
4478
            Debug( "ShLibArgs: cond $_" );
289 dpurdie 4479
            $libp->addItem('LIBS', $_);
227 dpurdie 4480
            next;
4481
        }
4482
 
339 dpurdie 4483
        if ( /^--SoName=(.*)/i )
4484
        {
4485
        #.. Specify the SoName of the library
4486
        #   Not supported by all toolsets
4487
        #
4488
            my $soMode = $1;
4489
            if ( !$ScmToolsetSoName )
4490
            {
4491
                Warning ("Toolset does not support --SoName. Option ignored");
4492
                next;
4493
            }
4494
 
4495
            Error ("SharedLib: $lib. Multiple --SoName arguments not allowed")
4496
                if ( $libp->{ SONAME } );
4497
 
4498
            my ($major, $minor, $patch, $build, $raw_patch) = SplitVersion($::ScmBuildVersionFull);
4499
            my $soname = '.';
4500
            if ( $soMode =~ m/Major/i ) {
4501
                $soname .= $major;
4502
            } elsif ( $soMode =~ m/^Minor/i ) {
4503
                $soname .= "$major.$minor";
4504
            } elsif ( $soMode =~ m/^Patch/i ) {
4505
                $soname .= "$major.$minor.$patch";
4506
            } elsif ( $soMode =~ m/^Build/i ) {
4507
                $soname .= "$major.$minor.$patch.$build";
4508
            } elsif ( $soMode =~ m/^Full/i ) {
4509
                $soname .= $libp->{ VERSION };
4510
            } elsif ( $soMode =~ m/^None/i ) {
4511
                $soname = '';
4512
            } elsif ( $soMode =~ m/^[0-9.]+$/ ) {
4513
                $soname .= $soMode;
4514
            } else {
4515
                Error ("Unknown --SoName mode: $soMode");
4516
            }
4517
            $libp->addItem('ARGS', '--SoNameSuffix=' . $soname);
4518
            $libp->{ SONAME } = 1;
4519
            next;
4520
        }
4521
 
227 dpurdie 4522
        if ( /^-(.*)/ )
4523
        {                           
4524
        #.. Argument specified - add to argument list
4525
        #
4526
            Debug( "ShLibArgs: arg  $_" );
289 dpurdie 4527
            $libp->addItem('ARGS', $_);
227 dpurdie 4528
            next;
4529
        }
4530
 
369 dpurdie 4531
        if ( %::ScmToolsetProgSource )
227 dpurdie 4532
        {
4533
            #
4534
            #   Toolset provides support for some file types
4535
            #   to be passed directly to the program builder
4536
            #
4537
            my $ext  = StripFile($_);
4538
            if ( exists ($::ScmToolsetProgSource{$ext}) )
4539
            {
4540
                my $full_path = MakeSrcResolve ( $_ );
4541
                my $flag = $::ScmToolsetProgSource{$ext};
4542
                Debug( "ShLibArgs: src $_" );
289 dpurdie 4543
                $libp->addItem('ARGS', "$flag$full_path");
227 dpurdie 4544
                next;
4545
            }
4546
        }
4547
 
4548
        if ( $::o )
4549
        {
4550
        #.. Object specified - add to object list.
4551
        #
4552
            my ($obj) = _LibObject( $lib, $_ );
4553
 
4554
        #.. Add to object list.
4555
        #   Note:   Object path must be explicit as several
4556
        #           toolsets add additional objects.
4557
        #
4558
            $SHOBJ_LIB{ $obj } = $lib;
289 dpurdie 4559
            $libp->addItem('OBJS', "\$(OBJDIR)/$obj");
227 dpurdie 4560
            next;
4561
        }
4562
 
4563
        #
4564
        #   Don't know how to handle this type of argument
4565
        #
4566
        Error ("SharedLib: Don't know how to handle: $_" );
4567
    }
4568
}
4569
 
4570
 
4571
#-------------------------------------------------------------------------------
4572
# Function        : _LibObject
4573
#
4574
# Description     : Process library object file
4575
#                   Common processing routine for static and shared library
4576
#                   Internal use only
4577
#
4578
# Inputs          : shared  - Name of the shared library is shared, if defined
4579
#                   fname   - Name of file
4580
#
4581
# Returns         : Name of the object file
4582
#
4583
sub _LibObject
4584
{
4585
    my ($shared, $fname) = @_;
4586
    my ($file, $ext, $obj, $srcfile, $delete_obj);
4587
 
4588
    #.. Object specified - add to object list.
4589
    #
4424 dpurdie 4590
    #   Want to handle several cases
4591
    #       Normal - User has provided the name of an object file (without the obj suffix)
4592
    #       Other  - User has provided the name of a source file
4593
    #                Need to perform implicit source file processing
4594
    #
4595
    #   The hard part is detecting the difference
4596
    #   Just can't use the existence of a '.' 
4597
    #
4598
    if ($OBJSOURCE{$fname}) {
4599
        $file = $fname;                             # Already know about this file
4600
        $ext = '';                                  # Don't need to split it
4601
    } else {
4602
        $file = StripDirExt($fname);                # file name, without extension or Dir
4603
        $ext  = StripFile($fname);                  # extension
4604
    }
227 dpurdie 4605
 
4606
    if ($shared) {
4607
        $obj = "$shared/$file";                 # library specific subdir
4608
    } else {
4609
        $obj = "$file";
4610
    }
4611
 
4612
    Debug( "LibObjs: obj [$shared]$fname ($file$ext)" );
4613
 
4614
    #.. Unqualified object name
4615
    #
4424 dpurdie 4616
    if ( $ext eq '' ) {
227 dpurdie 4617
        #
4618
        #   Object file not covered by a "Src" statement
4619
        #   Assume that it will be created
4620
        #
4424 dpurdie 4621
        unless ( $srcfile = $OBJSOURCE{$file} )
227 dpurdie 4622
        {
4623
            #
4424 dpurdie 4624
            #   If the object is "generated" then it will be in the
227 dpurdie 4625
            #   SRCS list
4626
            #
4627
            unless ( $srcfile = $SRCS{"$file.$::o"} )
4628
            {
4629
                Warning( "No source for object '$fname' ($file)" );
4630
            }
4631
        }
4632
        $delete_obj = 1;
4633
    }
4634
 
4635
    #.. Qualified object name (ie has extension)
4636
    #       Strip extension and resolve ...
4637
    #       Assume that the named file can be built into an object file
4638
    #
4639
    else
4640
    {
4641
        #.. Resolve
4642
        #
4643
        if ( !($srcfile = $OBJSOURCE{ "$file" }) )
4644
        {
4645
            $srcfile = MakeSrcResolve( $fname );
4646
            $SRCS{ $fname } = $srcfile;
4647
            __AddSourceFile( 0, $fname, $obj );
4648
            $delete_obj = 1;
4649
        }
4650
    }
4651
 
4652
    #.. Delete generated object file
4653
    #   Ensure that the object file is added to the delete list
4654
    #   Add it to the ToolsetObj deletion list as the main OBJ deleltion
4655
    #   list will aready have been processed
4656
    #
4657
    ToolsetObj( "\$(OBJDIR)/$obj" )
4658
        if ( $delete_obj );
4659
 
4660
 
4661
    #.. Shared library objects,
4662
    #       Must explicitly relate source and object, as shared libraries
4663
    #       objects are built within a library specific subdirs.
4664
    #
4665
    $OBJSOURCE{ $obj } = $srcfile
371 dpurdie 4666
        if ( $shared && defined $srcfile );
227 dpurdie 4667
 
4668
    return $obj;
4669
}
4670
 
4671
 
4672
# MergeLibrary
4673
#   Merge a list of libraries into one library
4674
#
4675
sub MergeLibrary
4676
{
4677
    my( $platforms, $lib, @elements ) = @_;
4678
 
4679
    return if ( ! ActivePlatform($platforms) );
4680
 
4681
 
4682
#.. Fully qualify library path for addition to library list.
4683
    $lib = "lib$lib"
4684
       if ( $ScmTargetHost eq "Unix" && $lib !~ m/^lib/);
4685
    Debug( "MergeLibrary: $lib" );
4686
 
289 dpurdie 4687
    #
4688
    #   Create a new object to describe the library
4689
    #   Ensure that only one such lib exists
4690
    #   Add the library to the list of static libraries
4691
    #
4692
    Error( "Merged Library of the same name already defined: $lib" )
4693
        if ( $MLIBS->Get($lib) );
4694
    my $libp = $MLIBS->NewAdd($lib);
4695
 
227 dpurdie 4696
#.. Parse all of the object and argument entries.
4697
#
4698
    foreach (@elements)
4699
    {
4700
        if ( /^--(.*)/ )
4701
        {
289 dpurdie 4702
            $libp->addItem('ARGS', $_);
227 dpurdie 4703
        }
4704
        else
4705
        {
4706
            my ($llib);
4707
 
4708
            #
4709
            #   Collect the source libraries
4710
            #   These must have been installed and will be in a known area
4711
            #   Create full names for the libaries
4712
            #
4713
            if ( $ScmTargetHost eq "Unix" ) {
4714
                $llib = "lib$_";                # Prefix "lib" ....
4715
                $lib =~ s/^liblib/lib/;         # @LIBS already has lib added
4716
            } else {
4717
                $llib = $_;
4718
            }
4719
 
4720
            Debug( "MergeLibrary: merge $llib" );
289 dpurdie 4721
            $libp->addItem('LIBS', $llib);
227 dpurdie 4722
        }
4723
    }
4724
}
4725
 
4726
#-------------------------------------------------------------------------------
4727
# Function        : Script
4728
#
4729
# Description     : Locate a script for test purposes
4730
#
4731
# Inputs          : $platforms      - Platform selector
4732
#                   $script         - A single script name
4733
#                   $execute        - Flag to indicate that the script is to
4734
#                                     marked as executable when used in a TestProg
4735
#                                     This flag is NOT used as the script will
4736
#                                     be forced executable
4737
#
4738
# Returns         : Nothing
4739
#
4740
sub Script
4741
{
4742
    my( $platforms, $script, $execute ) = @_;
4743
 
4744
    Debug2( "Script(@_)" );
4745
 
4746
    return if ( ! ActivePlatform($platforms) );
4747
 
4748
    #
4749
    #   Locate the script as a source file
4750
    #
4751
    my $file = MakeSrcResolve ( $script );
4752
    $script = StripDir( $file );
4753
    $SCRIPTS{ $script } = $file;
4754
}
4755
 
4756
#-------------------------------------------------------------------------------
4757
# Function        : RunTest
4758
#
4759
# Description     : Define a test to be run with the 'run_tests' and 'run_unit_tests'
4760
#
4761
# Inputs          : $platform       - Enabled for these platforms
4762
#                   $prog           - Program to run
4763
#                                     This SHOULD return a non-zero exit status
4764
#                                     on error. The program may be a 'TestProg'
4765
#                                     or a 'Script'.
4766
#                   @elements       - Options and test arguments
4767
#                                     Options are:
4778 dpurdie 4768
#                                       --Auto              - Non interactive unit test
4769
#                                       --Unit              - Same and --Auto
4770
#                                       --UtfFormat=nnn     - Specifies Automated Unit Test, 
4771
#                                                             results post processed with formatter
4781 dpurdie 4772
#                                       --UtfArg=nnn        - Argument passed into the UTF formatter    
4773
#                                       --Name=nnn          - Test Name.
5695 dpurdie 4774
#                                       --CopyIn=file       - A file to be copied into the test directory.
4775
#                                       --MaxTime=fff.ff[smhd] - Max Test Time. Default 30m
227 dpurdie 4776
#
4777
#                                     Non Options are passed to the test program.
4778
#                                     --PackageBase(xxx)    - Base of package
4779
#                                     --PackageInfo(xxx)    - Package information
4780
#                                     --File(xxx)           - Resolved name of file
4781
#                                     --Var(xxx)            - Expanded variable
4782
#                                     --Local(xxx)          - File within the local directory
4783
#
4778 dpurdie 4784
#                                     Toolset Framework support (ie NUNIT in csharp.pl)
4785
#                                       --FrameWork=name    - Name of framework
4786
#                                       --xxxx              - Args passed to framework constructor
4787
#
227 dpurdie 4788
# Returns         : Nothing
4789
#
4781 dpurdie 4790
my %RunTestNames;                       # Unique Name Tests
227 dpurdie 4791
sub RunTest
4792
{
4793
    my( $platforms, $prog, @elements ) = @_;
4794
    my $command = './';                 # program prefix / command
4795
    my $winprog = 1;                    # 1: Convert / -> \ (WIN32 only)
4796
    my $framework;
4797
    my @framework_opts;
4798
    my @copy = ();
4799
    my $auto;
4778 dpurdie 4800
    my $utfFormat;
4781 dpurdie 4801
    my @utfArgs;
4802
    my $utfName;
5695 dpurdie 4803
    my $maxTime;
227 dpurdie 4804
 
4805
    return if ( ! ActivePlatform($platforms) );
4806
 
4807
    #
4808
    #   Scan @elements and extract useful information
4809
    #   Need to process twice as some args will modify the
4810
    #   processing done later
4811
    #
4812
    my @args;
4813
    foreach ( @elements )
4814
    {
4815
        if ( m/^--FrameWork=(.+)/ ) {
4816
            $framework = $1;
4817
 
4818
        } elsif ( m/^--Auto/ || m/^--Unit/) {
4819
            $auto = 1;
4820
 
4781 dpurdie 4821
        } elsif ( m/^--Name=(.*)/) {
4822
            $utfName = $1;
4823
 
4824
            Error("Duplicate Test Name: $utfName")
4825
                if (exists $RunTestNames{$utfName} );
4826
            $RunTestNames{$utfName} = 1;
4827
 
4778 dpurdie 4828
        } elsif ( m/^--UtfFormat=(.*)/) {
4829
            $utfFormat = $1;
4830
 
4781 dpurdie 4831
        } elsif ( m/^--UtfArg=(.*)/) {
4832
            push @utfArgs, $1;
4833
 
5695 dpurdie 4834
        } elsif ( m/^--MaxTime=(.*)/) {
4835
            $maxTime = $1;
4836
            unless ($maxTime =~ m~^[0-9]*\.?[0-9]+[smhd]?$~) {
4837
                Error("MaxTime invalid: $maxTime");
4838
            }
4839
 
227 dpurdie 4840
        } elsif ( m/^--CopyIn=(.*)/ ) {
4841
            push @copy, MakeSrcResolve ( $1 );
4842
 
4843
        } elsif ( $framework && m/^--\w+=(.+)/ ) {
4844
            push @framework_opts, $_;
4845
 
4846
        } else {
4847
            push @args, $_;
4848
        }
4849
    }
4850
    @elements = @args;
4851
    @args = ();
4852
 
4853
    #
4854
    #   Determine the source of the test prog
4612 dpurdie 4855
    #   If using a plug-in framework, then we don't know
227 dpurdie 4856
    #   If not, then may be a script or a TESTPROGS
4857
    #
4858
 
4859
    unless ( $framework )
4860
    {
289 dpurdie 4861
        if ( $TESTPROGS->Get($prog) || $PROGS->Get($prog)  ) {
227 dpurdie 4862
            #
4863
            #   Append a suitable EXE suffix
4864
            #
289 dpurdie 4865
            $prog = GenProgName( $prog );
227 dpurdie 4866
 
4867
        } elsif ( exists $SCRIPTS{$prog} ) {
4868
            #
4869
            #   Script names are raw
4870
            #   Perl script are invoked directly
4871
            #
4872
            $command = "\$(GBE_PERL) -w "
4873
                if ( $prog =~ /\.pl$/ );
4874
 
4875
            #
4876
            #   Pass / to shells
4877
            #
4878
            $winprog = 0
4879
                unless ( $prog =~ m~\.bat$~ )
4880
 
4881
        } else {
4882
            Warning("RunTest program not known: $prog",
261 dpurdie 4883
                  "It is not a TestProg, Prog or a Script",
4884
                  "The test may fail" );
227 dpurdie 4885
        }
4886
    }
4887
 
4888
    #
4889
    #   Extract and process options
4890
    #
4891
    my @uargs = ();
4892
    my @preq_files;
4893
 
4894
    foreach my $arg (@elements) {
4895
        #
4896
        #   Process the tool arguments and extract file information
4897
        #   Extract all fields of the form:
4898
        #           --xxxxx(yyyyyy[,zzzzz])
4899
        #           --xxxxx{yyyyyyy}
4900
        #           --xxxxx[yyyyyyy] to allow embedded brackets
4901
        #
4902
        while ( $arg =~ m/--(\w+)               # --CommandWord         $1
4903
                                (               # Just for grouping
4904
                                \((.*?)\)   |   # Stuff like (yyyyy)    $3
4905
                                {(.*?)}     |   # or    like {yyyyy}    $4
4906
                                \[(.*?)\]       # or    like [yyyyy]    $5
4907
                                )/x )           # Allow comments and whitespace
4908
        {
4909
            my $cmd = $1;                       # The command
4910
            my $ufn = $3 || $4 || $5;           # User filename + options
4911
            my $mb = $-[0];                     # Match begin offset
4912
            my $me = $+[0];                     # Match end
4913
            my $flags = '';                     # Optional flags ( --dir or --file )
4914
            my $raw_arg = $ufn;                 # Raw arguments
285 dpurdie 4915
            my $all = substr( $arg, $mb, $me ); # All of match. Avoid use of $&
329 dpurdie 4916
            my $is_abs;
4917
            my $is_path = 1;
227 dpurdie 4918
 
4919
            Error ("RunTest. Empty element not allowed: $all")
4920
                unless ( defined($ufn) );
4921
 
4922
            $ufn =~ s/\s+$//;
4923
            $ufn =~ s~//~/~g;                   # Remove multiple /
4924
            if ( $ufn =~ m/(.*?),(.*)/ )        # Extract out any flags
4925
            {
4926
                $ufn = $1;
4927
                $flags = $2;
4928
            }
4929
 
4930
            my $fn = $ufn ;                     # Replacement filename
343 dpurdie 4931
            my $fnp = '';                       # Prefix to $fn
227 dpurdie 4932
            Error ("RunTest. Empty element not allowed: $all" )
4933
                if ( length ($ufn) <= 0 );
4934
 
4935
            #
4936
            #   Process found user command
4937
            #
4938
            if ( $cmd =~ /^File/ )
4939
            {
4940
                #
4941
                #   Prerequisite filename
4942
                #       Resolve the full name of the file. It may be known
4943
                #       as a source file (possibly generated) or it may be
4944
                #       located in a known source directory
4945
                #
4946
                $fn = MakeSrcResolve ( $ufn );
4947
                UniquePush (\@preq_files, $fn);
4948
 
4949
                Debug( "RunTest: Prereq: $fn" );
4950
 
4951
            }
4952
            elsif ( $cmd =~ /^PackageBase/ )
4953
            {
4954
                $fn = GetPackageBase( "RunTest", $raw_arg );
4955
                UniquePush (\@preq_files, $fn);
4956
            }
4957
            elsif ( $cmd =~ /^PackageInfo/ )
4958
            {
4959
                $fn = GetPackageInfo( "RunTest", $raw_arg );
4960
            }
4961
            elsif ( $cmd =~ /^Var/ )
4962
            {
343 dpurdie 4963
                ($fnp, $fn, $is_path, $is_abs) = ExpandGenVar( "RunTest", $raw_arg );
227 dpurdie 4964
                $flags = '';
4965
            }
4966
            elsif ( $cmd =~ /^Local/ )
4967
            {
4968
                $fn = '$(LOCALDIR)/' . $ufn ;
4969
                UniquePush (\@preq_files, $fn);
4970
            }
4971
            else
4972
            {
4973
                Warning ("RunTest: Unknown replacement command: $cmd");
4974
                $fn = $ufn;
4975
            }
4976
 
4977
            #
4978
            #   Process path modification flags
4979
            #       --dir           - only the directory part ( or a "." )
4980
            #       --file          - only the file part
4981
            #       --abspath       - Absolute path
4982
            #       --absdrive      - Absolute path with drive letter(WIN)
4983
            #
4984
            $fn = ProcessPathName( $fn, $flags );
4985
 
4986
            #
4987
            #   The program is going to be executed within a subdirectory
4988
            #   so add one more level of indirection to the path, but only if
4989
            #   the path is relative
4990
            #
329 dpurdie 4991
            if ( $is_path && ! $is_abs )
227 dpurdie 4992
            {
329 dpurdie 4993
                unless ( $fn =~ m~^/|^\w:/~  )
4994
                {
4995
                    $fn = '../' . $fn
4996
                        unless( $fn =~ s~=~=../~ );
4997
                    $fn =~ s~/.$~~;
4998
                }
227 dpurdie 4999
            }
5000
 
5001
            #
5002
            #   Minor kludge under windows. Ensure directores have a "\" sep
5003
            #   Unless the user has specified a straight shell command
5004
            #
303 dpurdie 5005
            $fn = "\$(subst /,\\,$fn)"
227 dpurdie 5006
                if ( $::ScmHost eq "WIN" && $winprog );
5007
 
5008
            #
343 dpurdie 5009
            #   Prepend any $fn Prefix
5010
            #   This will be a tag and is not subject to path processing
5011
            #
5012
            $fn = $fnp . $fn;
5013
 
5014
            #
227 dpurdie 5015
            #   Replace the found string with the real name of the file
5016
            #   Note: 4 argument version of substr is not always available
5017
            #         so we must do it the hard way
5018
            #               substr( $arg, $mb, $me - $mb, $fn);
5019
            #
5020
            $arg = substr( $arg, 0, $mb ) . $fn . substr( $arg, $me );
5021
 
5022
            Debug2( "RunTest: subs: $all -> $fn" );
5023
        }
5024
        push(@uargs, "'$arg'");
5025
    }
5026
 
5027
    #
5028
    #   Create the test entry
5029
    #   This is a structure that will be placed in an array
5030
    #   The array preserves order and uniqness
5031
    #
5032
    my %test_entry;
5033
    $test_entry{'framework'}= $framework if ( $framework );
5034
    $test_entry{'framework_opts'}= \@framework_opts if ( $framework );
5035
    $test_entry{'command'}  = $command . $prog unless ( $framework);
5036
 
5037
    $test_entry{'prog'}     = $prog;
5038
    $test_entry{'copyprog'} = 1;
5039
    $test_entry{'args'}     = \@uargs;
5040
    $test_entry{'auto'}     = $auto if ( $auto );
4778 dpurdie 5041
    $test_entry{'utfformat'}= $utfFormat if ( $utfFormat );
4781 dpurdie 5042
    $test_entry{'utfargs'}  = \@utfArgs;
5043
    $test_entry{'utfname'}  = $utfName;
5695 dpurdie 5044
    $test_entry{'maxtime'}  = $maxTime if ($maxTime);
227 dpurdie 5045
    $test_entry{'copyin'}   = \@copy;
5046
    $test_entry{'copyonce'} = ();
5047
    $test_entry{'preq'}     = \@preq_files;
5048
    $test_entry{'testdir'}  = 'BINDIR';
5049
 
5050
    push ( @TESTS_TO_RUN, \%test_entry );
5051
 
5052
    #
5053
    #   Flag Auto Run processing required
5054
    #
4501 dpurdie 5055
    $TESTS_TO_RUN = 1;
227 dpurdie 5056
    $TESTS_TO_AUTORUN = 1 if ( $auto );
5057
}
5058
 
5059
 
5060
sub TestProg
5061
{
5062
    my( $platforms, $prog, @elements ) = @_;
5063
 
5064
    Debug2( "TestProg($platforms, $prog, @elements)" );
5065
 
5066
    return if ( ! ActivePlatform($platforms) );
5067
 
5068
    Error ("TestProg: Program name not defined") unless ( $prog );
5069
    Error ("Programs are not supported") unless ( defined $::exe );
5070
 
289 dpurdie 5071
    #
5072
    #   Create a new Prog object, or retrieve any existing one
5073
    #
5074
    my $pProg = $TESTPROGS->Get($prog);
5075
    $pProg = $TESTPROGS->NewAdd($prog)
5076
        unless ( $pProg );
227 dpurdie 5077
 
5078
#.. Parse all of the object, library and argument entries
5079
    Debug( "TestProg: $prog" );
5080
    foreach (@elements)
5081
    {
5082
        if ( /^[-]{1,2}([lL])(.*)/ )
5083
        {
5084
        #.. Target Library specified - add to library list.
5085
        #  
5086
            Debug( "TestProg: lib  -$1$2" );
289 dpurdie 5087
            $pProg->addItem('LIBS', "-$1$2");
227 dpurdie 5088
            next;
5089
        }
5090
 
5091
        if ( /^--if(.*)/ )
5092
        {
5093
        #.. Library conditional - add to library list.
5094
        #
5095
            Debug( "TestProg: cond $_" );
289 dpurdie 5096
            $pProg->addItem('LIBS', $_);
227 dpurdie 5097
            next;
5098
        }
5099
 
5100
        if ( /^-(.*)/ )
5101
        {
5102
        #.. Argument specified - add to argument list
5103
        #
5104
            Debug( "TestProg: arg $_" );
289 dpurdie 5105
            $pProg->addItem('ARGS', $_);
227 dpurdie 5106
            next;
5107
        }
5108
 
369 dpurdie 5109
        if ( %::ScmToolsetProgSource )
227 dpurdie 5110
        {
5111
            #
5112
            #   Toolset provides support for some file types
5113
            #   to be passed directly to the program builder
5114
            #
5115
            my $ext  = StripFile($_);
5116
            if ( exists ($::ScmToolsetProgSource{$ext}) )
5117
            {
5118
                my $full_path = MakeSrcResolve ( $_ );
5119
                my $flag = $::ScmToolsetProgSource{$ext};
5120
                Debug( "TestProg: src $_" );
289 dpurdie 5121
                $pProg->addItem('ARGS', "$flag$full_path");
227 dpurdie 5122
                next;
5123
            }
5124
        }
5125
 
5126
        if ( $::o )
5127
        {
5128
        #.. Object specified - add to object list.
5129
        #
5130
            my $obj = _LibObject( "", $_ );
5131
 
5132
        #.. Add to program object list.
289 dpurdie 5133
            $pProg->addItem('OBJS', "\$(OBJDIR)/$obj");
227 dpurdie 5134
            next;
5135
        }
5136
 
5137
        #
5138
        #   Don't know how to handle this type of argument
5139
        #
5140
        Error ("TestProg: Don't know how to handle: $_" );
5141
    }
5142
}
5143
 
5144
 
5145
sub Prog
5146
{
5147
    my( $platforms, $prog, @elements ) = @_;
5148
 
5149
    Debug2( "Prog($platforms, $prog, @elements)" );
5150
 
5151
    return if ( ! ActivePlatform($platforms) );
5152
 
5153
    Error ("Prog: Program name not defined") unless ( $prog );
5154
    Error ("Programs are not supported") unless ( defined $::exe );
5155
 
289 dpurdie 5156
    #
5157
    #   Create a new Prog object, or retrieve any existing one
5158
    #
5159
    my $pProg = $PROGS->Get($prog);
5160
    $pProg = $PROGS->NewAdd($prog)
5161
        unless ( $pProg );
227 dpurdie 5162
 
5163
#.. Parse all of the object, library and argument entries
5164
    Debug( "Prog: $prog" );
5165
    foreach (@elements)
5166
    {
5167
        if ( /^[-]{1,2}([lL])(.*)/ )
5168
        {
5169
        #.. Target Library specified - add to library list.
5170
        #  
5171
            Debug( "Prog: lib  -$1$2" );
289 dpurdie 5172
            $pProg->addItem('LIBS', "-$1$2");
227 dpurdie 5173
            next;
5174
        }
5175
 
5176
        if ( /^--if(.*)/ )
5177
        {
5178
        #.. Library conditional - add to library list.
5179
        #
5180
            Debug( "Prog: cond $_" );
289 dpurdie 5181
            $pProg->addItem('LIBS', $_);
227 dpurdie 5182
            next;
5183
        }
5184
 
5185
        if ( /^-(.*)/ )
5186
        {
5187
        #.. Argument specified - add to argument list
5188
        #
5189
            Debug( "Prog: arg $_" );
289 dpurdie 5190
            $pProg->addItem('ARGS', $_);
227 dpurdie 5191
            next;
5192
        }
5193
 
369 dpurdie 5194
        if ( %::ScmToolsetProgSource )
227 dpurdie 5195
        {
5196
            #
5197
            #   Toolset provides support for some file types
5198
            #   to be passed directly to the program builder
5199
            #
5200
            my $ext  = StripFile($_);
5201
            if ( exists ($::ScmToolsetProgSource{$ext}) )
5202
            {
5203
                my $full_path = MakeSrcResolve ( $_ );
5204
                my $flag = $::ScmToolsetProgSource{$ext};
5205
                Debug( "Prog: src $_" );
289 dpurdie 5206
                $pProg->addItem('ARGS', "$flag$full_path");
227 dpurdie 5207
                next;
5208
            }
5209
        }
5210
 
5211
        if ( $::o )
5212
        {
5213
        #.. Object specified - add to object list.
5214
        #
5215
            my $obj = _LibObject( "", $_ );
5216
 
5217
        #.. Add to program object list.
289 dpurdie 5218
            $pProg->addItem('OBJS', "\$(OBJDIR)/$obj");
227 dpurdie 5219
            next;
5220
        }
5221
 
5222
        #
5223
        #   Don't know how to handle this type of argument
5224
        #
5225
        Error ("Prog: Don't know how to handle: $_" );
5226
    }
5227
}
5228
 
5229
#-------------------------------------------------------------------------------
5230
# Function        : ProgAddExtra
5231
#
5232
# Description     : This (internal) function allows a toolset to list additional
5233
#                   binaries as a part of a program. This will ensure that the
5234
#                   binaries are generated in the 'make_prog' phase with the main
5235
#                   program.
5236
#
5237
#                   The files are not listed for packaging, by this function
5238
#
5239
#                   The function does not ensure that the files are not already
5240
#                   listed as a @PROG ( as @PROGS is not fully resolved at this point )
5241
#
5242
# Inputs          :     $name               - Tag name of program being built
5243
#                                             Not used (yet)
5244
#                       $prog               - Fully resolved path to a file
5245
#
5246
# Returns         : Nothing
5247
#
5248
sub ProgAddExtra
5249
{
5250
    my ($name, $prog) = @_;
5251
    Debug2( "ProgAddExtra($name: $prog)" );
5252
 
5253
    UniquePush(\@PROGS_EXTRA, $prog);
5254
}
5255
 
4261 dpurdie 5256
our %PROJECTS;                          # Project information
5257
my  @PROJECTS_ORDER;
227 dpurdie 5258
#-------------------------------------------------------------------------------
4261 dpurdie 5259
# Function        : MakeProjectName 
5260
#
5261
# Description     : Create a uniq project name
5262
#
5263
# Inputs          : srcPath 
5264
#
5265
# Returns         : A unique project name 
5266
#
5267
sub MakeProjectName
5268
{
5269
    my ($srcPath) = @_;
5270
    my $suffix = "";
5271
    my $index = 1;
5272
 
5273
    my $proj = StripDir( $srcPath );
5274
    while (exists $PROJECTS{$proj . $suffix})
5275
    {
5276
        $suffix = '.' . $index++;
5277
    }
5278
    return $proj . $suffix; 
5279
}
5280
 
5281
#-------------------------------------------------------------------------------
227 dpurdie 5282
# Function        : MakeProject
5283
#
5284
# Description     : A nasty directive that is intended to build a Microsoft
5285
#                   project for WINCE, WIN32 and .NET builds.
5286
#
5287
#                   There are many constraints:
5288
#                       Cannot be mixed with multi-platform builds
5289
#                       Some parameters are tool specific
5290
#
267 dpurdie 5291
#                   Allow programs to be Installed as well as Packaged
5292
#                   The 'Progect' is treated' as a program and it doesn't work
5293
#                   to well if we Install libraries.
227 dpurdie 5294
#
267 dpurdie 5295
#                   Only Reason to Install Programs is to allow the Cab Maker
5296
#                   to locate them.
5297
#
227 dpurdie 5298
# Inputs          : Platform        - Active platform
5299
#                   Project         - Project Name with extension
5300
#                   Options         - Many options
5301
#
5302
# Returns         :
5303
#
5304
sub MakeProject
5305
{
5306
    my( $platforms, $proj, @elements ) = @_;
5307
 
5308
    Debug2( "MakeProject($platforms, $proj, @elements)" );
5309
 
5310
    return if ( ! ActivePlatform($platforms) );
5311
 
5312
    #
5313
    #   Sanity test
5314
    #
5315
    Error ("MakeProject: Project name not defined") unless ( $proj );
5316
 
5317
    #
5318
    #   Take the project name and convert it into a full path
4261 dpurdie 5319
    #   Need to create a uniq project name - allowing for multiple uses
227 dpurdie 5320
    #
5321
    my $project = MakeSrcResolve ( $proj );
4261 dpurdie 5322
    $proj = MakeProjectName($project);
5323
 
237 dpurdie 5324
    Error ("Project File Not found: $project") unless ( -f $project );
227 dpurdie 5325
 
5326
    my $basedir = StripFileExt( $project );
5327
 
5328
    #
5329
    #   Collect user arguments
5330
    #   They are all processed within the toolset
5331
    #
5332
    my @tool_options;
5411 dpurdie 5333
    my $unit_tests;
5334
    my $auto_tests;
227 dpurdie 5335
    foreach ( @elements )
5336
    {
5337
        if ( m/^--Debug/ ) {
5338
            $PROJECTS{$proj}{'Debug'} = 1;
5339
 
5340
        } elsif ( m/^--Prod/ ) {
5341
            $PROJECTS{$proj}{'Prod'} = 1;
5342
 
267 dpurdie 5343
        } elsif ( m/^--(Package|Install)ProgDebug=(.*)/ ) {
5344
            _PackageFromProject( $1, $proj, $basedir,'Prog', 'D', $2 );
227 dpurdie 5345
 
267 dpurdie 5346
        } elsif ( m/^--(Package|Install)Prog(Prod)*=(.*)/ ) {
5347
            _PackageFromProject( $1, $proj, $basedir, 'Prog', 'P', $3 );
227 dpurdie 5348
 
267 dpurdie 5349
        } elsif ( m/^--(Package)LibDebug=(.*)/ ) {
5350
            _PackageFromProject( $1, $proj, $basedir, 'Lib', 'D', $2 );
227 dpurdie 5351
 
267 dpurdie 5352
        } elsif ( m/^--(Package)Lib(Prod)*=(.*)/ ) {
5353
            _PackageFromProject( $1, $proj, $basedir, 'Lib', 'P', $3 );
227 dpurdie 5354
 
267 dpurdie 5355
        } elsif ( m/^--(Package)SharedLibDebug=(.*)/ ) {
5356
            _PackageFromProject( $1, $proj, $basedir, 'Lib', 'D', $2 );
227 dpurdie 5357
 
267 dpurdie 5358
        } elsif ( m/^--(Package)SharedLib(Prod)*=(.*)/ ) {
5359
            _PackageFromProject( $1, $proj, $basedir, 'Lib', 'P', $3 );
227 dpurdie 5360
 
267 dpurdie 5361
        } elsif ( m/^--(Package)Hdr=(.*)/ ) {
5362
            _PackageFromProject( $1, $proj, $basedir, 'Hdr', undef, $2 );
227 dpurdie 5363
 
267 dpurdie 5364
        } elsif ( m/^--(Package)File=(.*)/ ) {
5365
            _PackageFromProject( $1, $proj, $basedir, 'File', undef, $2 );
227 dpurdie 5366
 
267 dpurdie 5367
        } elsif ( m/^--(Package)Tool(Prod)*=(.*)/ ) {
5368
            _PackageFromProject( $1, $proj, $basedir, 'Tool', 'P', $3 );
241 dpurdie 5369
 
267 dpurdie 5370
        } elsif ( m/^--(Package)ToolDebug=(.*)/ ) {
5371
            _PackageFromProject( $1, $proj, $basedir, 'Tool', 'D', $2 );
241 dpurdie 5372
 
267 dpurdie 5373
        } elsif ( m/^--(Package|Install)/ ) {
5374
            Error("MakeProject. Unknown $1 option: $_");
227 dpurdie 5375
 
5411 dpurdie 5376
        } elsif ( m/^--UnitTest/ ) {
5377
            $unit_tests = 1;
5378
 
5379
        } elsif ( m/^--AutoTest/ ) {
5380
            $auto_tests = 1;
5381
 
227 dpurdie 5382
        } else {
5383
            push @tool_options, $_;
5384
        }
5385
    }
5386
 
5387
    #
5388
    #   Save the information
5389
    #
5390
    $PROJECTS{$proj}{'options'} = \@tool_options;
5391
    $PROJECTS{$proj}{'name'} = $proj;
5392
    $PROJECTS{$proj}{'project'} = $project;
5393
    $PROJECTS{$proj}{'basedir'} = $basedir;
5411 dpurdie 5394
    $PROJECTS{$proj}{'unittest'} = $unit_tests if ( $unit_tests );
5395
    $PROJECTS{$proj}{'autotest'} = $auto_tests if ( $auto_tests );
227 dpurdie 5396
    UniquePush (\@PROJECTS_ORDER, $proj);
5397
 
5398
    #
5399
    #   Validate some of the arguments
5400
    #
5401
    Error ("Makeproject. Conflicting options --Debug and --Prod" )
5402
        if ( $PROJECTS{$proj}{'Debug'}  && $PROJECTS{$proj}{'Prod'} );
5403
}
5404
 
5405
#-------------------------------------------------------------------------------
5406
# Function        : _PackageFromProject
5407
#
5408
# Description     : Save Packaged data from the project
5409
#
267 dpurdie 5410
# Inputs          : $tgt        - Install or Package
5411
#                   $proj       - Name of the project
227 dpurdie 5412
#                   $base       - Base directory of files
5413
#                   $etype      - Type of Package (Progs, Libs, ... )
5414
#                   $type       - Debug or Production or both
5415
#                   $items      - Item to add. It may be comma seperated
5416
#
267 dpurdie 5417
my %PackageToData = ( 'Package' =>
5418
                        { 'Hdr'   => \%PACKAGE_HDRS,
5419
                          'Lib'   => \%PACKAGE_LIBS,
5420
                          'Prog'  => \%PACKAGE_PROGS,
5421
                          'File'  => \%PACKAGE_FILES,
5422
                          'Tool'  => \%PACKAGE_FILES,
5423
                          '_BASE' => 'PBase',
5424
                        },
5425
                      'Install' =>
5426
                        { 'Hdr'   => \%INSTALL_HDRS,
5427
                          'Lib'   => \%INSTALL_LIBS,
5428
                          'Prog'  => \%INSTALL_PROGS,
5429
                          'File'  => undef,
5430
                          'Tool'  => undef,
5431
                          '_BASE' => 'IBase',
5432
                        },
227 dpurdie 5433
                    );
5434
 
5435
sub _PackageFromProject
5436
{
267 dpurdie 5437
    my( $tgt, $proj, $base, $etype, $type, $items ) = @_;
227 dpurdie 5438
    my $subdir = '';
5439
 
5440
    #
267 dpurdie 5441
    #   Sanity test
5442
    #
5443
    $type = '' unless ( $type );
5444
    Error ("INTERNAL. Bad packaging option: $tgt")   unless ( exists $PackageToData{$tgt} );
5445
    Error ("INTERNAL. Bad packaging option: $etype") unless ( exists $PackageToData{$tgt}{$etype} );
5446
    Error ("Unsupported packaging combination: $tgt$etype$type=$items") unless ( defined $PackageToData{$tgt}{$etype} );
5447
 
5448
    #
5449
    #   Determine the index into the 'PackageInfo' structure
5450
    #   This provides the symbolic name for the target package path
5451
    #   for Package or Install
5452
    #
5453
    #   The key '_BASE' is internal. Used only to provide this information
5454
    #
5455
    my $tbase = $PackageToData{$tgt}{'_BASE'};
5456
 
5457
    #
227 dpurdie 5458
    #   Process options
5459
    #
5460
    foreach my $item ( split (/,/, $items ) )
5461
    {
5462
        next unless ( $item =~ m/^--/ );
5463
        if ( $item =~ m/^--Subdir=(.*)/ )
5464
        {
5465
            $subdir = '/' . $1;
5466
            $subdir =~ s~//~/~g;
5467
            $subdir =~ s~/$~~g;
5468
        }
5469
        else
5470
        {
5471
            Warning( "MakeProject: Unknown packaging option ignored: $_" );
5472
        }
5473
    }
5474
 
5475
    #
5476
    #   Process files
5477
    #
5478
    foreach my $item ( split (/,/, $items ) )
5479
    {
5480
        next if ( $item =~ m/^--/ );
5481
 
267 dpurdie 5482
        my $tdir = $PackageInfo{$etype}{$tbase} . $PackageInfo{$etype}{'Dir'} . $subdir ;
227 dpurdie 5483
        my $fname = StripDir( $item );
5484
        my $target = $tdir . '/' . $fname;
5485
 
5486
        $item = "$base/$item" if ( $base );
5487
 
5488
        #
5489
        #   Do not use $(GBE_TYPE) in the target name
5490
        #   The existing package mechanism does not handle different
5491
        #   production and debug file naming mechanism, whereas the project
5492
        #   must. Convert $(GBE_TYPE) into P or D to ensure uniquness
5493
        #
387 dpurdie 5494
        $item = QuoteForMake($item);
5495
        $target = QuoteForMake($target);
227 dpurdie 5496
        $target =~ s~\$\(GBE_TYPE\)~$type~ if ($type);
5497
 
5498
        #
5499
        #   Create a PACKAGE entry suitable for processing by the normal packaging
5500
        #   routines. This is complicated because the Projects do not adhere to
267 dpurdie 5501
        #   the JATS file name conventions
227 dpurdie 5502
        #
5503
        my %package_entry;
5504
        $package_entry{'src'}   = $item;
5505
        $package_entry{'dir'}   = $tdir;
267 dpurdie 5506
        $package_entry{'set'}   = 'ALL' if ($tgt eq 'Package');
227 dpurdie 5507
        $package_entry{'type'}  = $type if ($type);
5508
 
267 dpurdie 5509
        $PackageToData{$tgt}{$etype}->{$target} = {%package_entry};
227 dpurdie 5510
    }
5511
}
5512
 
5513
#-------------------------------------------------------------------------------
5514
# Function        : MakeAnt
5515
#
5516
# Description     : A nasty directive to create JAR files via ANT
5517
#                   There are several limitations
5518
#                   This is closely related to the MakeProject directive
5519
#
5520
#
5521
# Inputs          : Platform            - Active platform
5522
#                   buildfile           - Name of the build.xml file
5523
#                   Options             - A few options
5524
#                                         --Jar=file
5525
#                                               Generated JAR file(s)
5526
#                                         --GeneratedFile=file
5527
#                                               Other generated files
5528
#                                               Used to flag JNI that must
5529
#                                               Occur early
5530
#                                          --AutoTest=<name>
5531
#                                               Supports unitAutomated unit test
5532
#                                               by calling build target <name>
5533
#                                          --UnitTest=<name>
5534
#                                               Supports unit test
5535
#                                               by calling build target <name>
5536
#                                          --PackageBase
5537
#                                               Provides path to base of all packages
5538
#
5539
# Returns         :
5540
#
5541
our %JAR_FILES;
5542
sub MakeAnt
5543
{
5544
    my( $platforms, $proj, @elements ) = @_;
5545
 
5546
    Debug2( "MakeAnt($platforms, $proj, @elements)" );
5547
 
5548
    return if ( ! ActivePlatform($platforms) );
5549
 
5550
    #
5551
    #   Sanity test
5552
    #
5553
    Error ("MakeAnt: build.xml name not defined") unless ( $proj );
5554
 
5555
    #
5556
    #   Take the project name and convert it into a full path
5557
    #
5558
    my $project;
5559
    $project = MakeSrcResolve ( $proj );
4261 dpurdie 5560
    $proj = MakeProjectName($project);
237 dpurdie 5561
    Error ("Build File Not found: $project") unless ( -f $project );
227 dpurdie 5562
 
5563
    my $basedir = StripFileExt( $project );
5564
 
5565
    #
5566
    #   Collect user arguments
5567
    #   They are all processed within the toolset
5568
    #
5569
    my @tool_options;
5570
    my @generated;
5571
    my $unit_tests;
5572
    my $auto_tests;
5573
    my $package_base;
5574
 
5575
    foreach ( @elements )
5576
    {
5577
        if ( m/^--Debug/ ) {
5578
            $PROJECTS{$proj}{'Debug'} = 1;
5579
 
5580
        } elsif ( m/^--Prod/ ) {
5581
            $PROJECTS{$proj}{'Prod'} = 1;
5582
 
5583
        } elsif ( m/^--Jar=(.*)/ ) {
5584
            my $tgt = $1;
5585
               $tgt = "$basedir/$tgt" if ( $basedir );
5586
            my $fn = StripDir( $1 );
5587
            $JAR_FILES{$fn} = $tgt;
5588
            GenerateSrcFile( 0, $tgt );
5589
 
5590
        } elsif ( m/^--GeneratedFile=(.*)/ ) {
5591
            my $tgt = $1;
5592
            $tgt = "$basedir/$tgt" if ( $basedir );
5593
            push @generated, $tgt;
5594
            GenerateSrcFile( 2, $tgt );
5595
 
5596
        } elsif ( m/^--UnitTest=(.*)/ ) {
5597
            $unit_tests = $1
5598
 
5599
        } elsif ( m/^--AutoTest=(.*)/ ) {
5600
            $auto_tests = $1
5601
 
5602
        } elsif ( m/^--PackageBase/ ) {
5603
            $package_base = 1;
5604
 
5605
 
5606
        } elsif ( m/^--/ ) {
5607
            Error("MakeAnt. Unknown option ignored: $_");
5608
 
5609
        } else {
5610
            push @tool_options, $_;
5611
        }
5612
    }
5613
 
5614
    #
5615
    #   Extend option arguments to include the base dir of packages
5616
    #   Create definitions of the form PACKAGE_<name>
5617
    #
5618
    for my $entry (@{$::ScmBuildPkgRules{$ScmPlatform} })
5619
    {
5620
        next unless ( $entry->{'TYPE'} eq 'link' );
5621
        my $dir = $entry->{'ROOT'};
5622
        my $name = $entry->{'NAME'};
5623
        unless ( $package_base )
5624
        {
5625
            $dir .= '/jar';
5626
            next unless ( -d $dir );
5627
        }
5628
        push @tool_options, "-DPACKAGE_$name=$dir";
5629
    }
5630
    #
5631
    #   Extend options to include the base dir of the created package
5632
    #   Allows careful use for direct packaging of artifacts
5633
    #
5634
    push @tool_options, '-DPACKAGEDIR=$(PWD)/$(PKGDIR)';
5635
 
5636
    #
5637
    #   Save the information
5638
    #
5639
    $PROJECTS{$proj}{'options'} = \@tool_options;
5640
    $PROJECTS{$proj}{'generated'} = \@generated if ( @generated );
5641
    $PROJECTS{$proj}{'name'}    = $proj;
5642
    $PROJECTS{$proj}{'project'} = $project;
5643
    $PROJECTS{$proj}{'basedir'} = $basedir;
5644
    $PROJECTS{$proj}{'type'}    = 'ant';
5645
    $PROJECTS{$proj}{'unittest'} = $unit_tests if ( $unit_tests );
5646
    $PROJECTS{$proj}{'autotest'} = $auto_tests if ( $auto_tests );
5647
    UniquePush (\@PROJECTS_ORDER, $proj);
5648
 
5649
    $TESTS_TO_AUTORUN = 1 if ( $auto_tests );
4501 dpurdie 5650
    $TESTS_TO_RUN     = 1 if ( $unit_tests || $auto_tests );
227 dpurdie 5651
 
5652
    #
5653
    #   Validate some of the arguments
5654
    #
5655
    Error ("MakeAnt. Conflicting options --Debug and --Prod" )
5656
        if ( $PROJECTS{$proj}{'Debug'}  && $PROJECTS{$proj}{'Prod'} );
5657
}
5658
 
5659
###############################################################################
5660
#
5661
#   Installation/Packaging util functions
5662
#
5663
#-------------------------------------------------------------------------------
5664
# Function        : __TargetDir
5665
#
5666
# Description     : Internal function to process common arguments for
5667
#                   the PackageXxx directives
5668
#
5669
# Inputs          : flags           - Indicate how to handle this argument
5670
#                   base            - Base directory for this type of package
5671
#                   argument        - Argument to process
5672
#                   pdir            - Reference to resultant directory
5673
#                   ptype           - Reference to resultant type (P or D)(optional)
5674
#
5675
# Returns         : 0               - Agument not consumed
5676
#                   1               - Argument consumed
5677
#                   2               - Skip this directive
5678
#
5679
my $T_TYPE  = 0x0001;                           # Postfix GBE_TYPE
5680
my $T_PKG   = 0x0002;                           # Special --Dir handling
5681
my $T_MACH  = 0x0004;                           # Allow --Machine too
5682
my $T_GBE   = 0x0008;                           # Allow --Gbe too
5683
my $T_FILE  = 0x0010;                           # Suffix or prefix subdir
5684
 
5685
sub __TargetDir
5686
{
5687
    my( $flags, $base, $argument, $pdir, $ptype ) = @_;
5688
    my $dir  = "";
5689
    my $consumed = 0;
5690
 
5691
    #
5692
    #   Generate basic parts
5693
    #   Note Product will default to Platform
5694
    #
5695
    my $str_platform = '$(GBE_PLATFORM)';
5696
    my $str_product = $ScmProduct ? '$(GBE_PRODUCT)' : '$(GBE_PLATFORM)';
5697
    my $str_target = '$(GBE_TARGET)';
5698
    my $str_common = '$(GBE_OS_COMMON)';
5699
 
5700
    my $str_common_avail = 0;
5701
       $str_common_avail = 1 if ( exists( $::BUILDINFO{$ScmPlatform}{OS_COMMON} ));
5702
 
5703
 
5704
    #
5705
    #   Add requested suffix
5706
    #
5707
    if ($flags & $T_TYPE)
5708
    {
5709
        $str_platform .= '$(GBE_TYPE)';
5710
        $str_product  .= '$(GBE_TYPE)';
5711
        $str_target   .= '$(GBE_TYPE)';
5712
        $str_common   .= '$(GBE_TYPE)';
5713
    }
5714
 
5715
    #
5716
    #   Process the argument
5717
    #
5718
    $_ = $argument;
5719
    if ( /^--Debug/ ) {                         # In the Debug build only
5720
        if ( $ptype ) {
5721
            $$ptype = "D";
5722
            $consumed = 1;
5723
        }
5724
 
5725
    } elsif ( /^--Prod$/ || /^--Production$/ ) { # In the Production build only
5726
        if ( $ptype ) {
5727
            $$ptype = "P";
5728
            $consumed = 1;
5729
        }
5730
 
5731
    } elsif (/^--Prefix=(.*)/) {                # Prefix with subdir
5732
        $dir = "$base/$1";
5733
 
5734
    } elsif (/^--Subdir=(.*)/) {                # same as 'prefix'
5735
        $dir = "$base/$1";
5736
 
5737
    } elsif (/^--Platform$/) {                  # Platform installation
5738
        $dir = "$base/$str_platform";
5739
 
5740
    } elsif (/^--Platform=(.*?),(.*)/) {        # prefix and suffix with platform specific subdir
5741
        $dir = "$base/$1/$str_platform/$2";
5742
 
5743
    } elsif (/^--Platform=(.*)/) {              # prefix with platform specific subdir
5744
        if ($flags & $T_FILE) {
5745
            $dir = "$base/$1/$str_platform";
5746
        } else {
5747
            $dir = "$base/$str_platform/$1";
5748
        }
5749
 
5750
    } elsif (/^--Product$/) {                   # Product installation
5751
        $dir = "$base/$str_product";
5752
 
5753
    } elsif (/^--Product=(.*?),(.*)/) {         # prefix and suffix with product specific subdir
5754
        $dir = "$base/$1/$str_product/$2";
5755
 
5756
    } elsif (/^--Product=(.*)/) {               # prefix with product specific subdir
5757
        if ($flags & $T_FILE) {
5758
            $dir = "$base/$1/$str_product";
5759
        } else {
5760
            $dir = "$base/$str_product/$1";
5761
        }
5762
 
5763
    } elsif (/^--Target$/) {                    # Target installation
5764
        $dir = "$base/$str_target";
5765
 
5766
    } elsif (/^--Target=(.*?),(.*)/) {          # prefix and suffix with target specific subdir
5767
        $dir = "$base/$1/$str_target/$2";
5768
 
5769
    } elsif (/^--Target=(.*)/) {                # prefix with target specific subdir
5770
        if ($flags & $T_FILE) {
5771
            $dir = "$base/$1/$str_target";
5772
        } else {
5773
            $dir = "$base/$str_target/$1";
5774
        }
5775
 
5776
    } elsif (/^--OsCommon/) {
5777
 
5778
        unless ( $str_common_avail ) {
5779
            Warning("Packaging option --OsCommon not supported on this platform($ScmPlatform). Directive skipped");
5780
            $consumed = 2;
5781
 
5782
        } elsif (/^--OsCommon$/) {                  # OS installation
5783
            $dir = "$base/$str_common";
5784
 
5785
        } elsif (/^--OsCommon=(.*?),(.*)/) {        # prefix and suffix with target specific subdir
5786
            $dir = "$base/$1/$str_common/$2";
5787
 
5788
        } elsif (/^--OsCommon=(.*)/) {              # prefix with target specific subdir
5789
            if ($flags & $T_FILE) {
5790
                $dir = "$base/$1/$str_common";
5791
            } else {
5792
                $dir = "$base/$str_common/$1";
5793
            }
5794
        }
5795
 
5796
    } elsif (/^--Derived=(.*?),(.*?),(.*)/) {   # Derived target + prefix + subdir
5797
        $dir = "$base/$2/$1_$str_platform/$3";
5798
 
5799
    } elsif (/^--Derived=(.*?),(.*)/) {         # Derived target + subdir
5800
        if ($flags & $T_FILE) {
5801
            $dir = "$base/$2/$1_$str_platform";
5802
        } else {
5803
            $dir = "$base/$1_$str_platform/$2";
5804
        }
5805
 
5806
    } elsif (/^--Derived=(.*)/) {               # Derived target
5807
        $dir = "$base/$1_$str_platform";
5808
 
5809
    } elsif ($flags & $T_MACH && /^--Machine(([=])(.*))?$/) {   # Allow Machine and Machine=xxx specfic target
5810
        #
5811
        #   Special: Append machine type to user dir
5812
        #            Intended to create tools/bin/win32 and tools/bin/sparc directories
5813
        my $path = ( defined( $3) ) ? "/$3" : "";
5814
        $dir = "$base$path/\$(GBE_HOSTMACH)";
5815
 
5816
    } elsif ($flags & $T_GBE && /^--Gbe(([=])(.*))?$/) {   # Allow Gbe and Gbe=xxx specfic target
5817
        my $path = ( defined( $3) ) ? "/$3" : "";
5818
        $dir = "$base/gbe$path";
5819
 
5820
    } elsif (/^--Dir=(.*)/) {                   # prefix with target specific subdir
5821
        Error ('Packaging directive with --Dir option does not specify a directory.',
5822
               'Possible bad use of option of the form:--Dir=$xxx',
5823
               'Note: Use of package.pl and this construct is deprecated') unless ( $1 );
241 dpurdie 5824
        my $udir = $1;
5825
 
5826
        #
5827
        #   Remove leading ./
5828
        #   Check for leading ../
5568 dpurdie 5829
        #   
5830
        #   Remove any stupid path manipulation elements
5831
        #   
5827 dpurdie 5832
        if ($udir =~ s~^([./]*/)~~)
5833
        {
5834
            Warning("Packaging directive with --Dir option contains path manipulation elements (removed)", "Option: $_");
5835
        }
241 dpurdie 5836
 
227 dpurdie 5837
        if ($flags & $T_PKG) {
241 dpurdie 5838
            $dir = __PkgDir( $udir );
227 dpurdie 5839
        } else {
241 dpurdie 5840
            $dir = "\$(LOCALDIR)/$udir";
227 dpurdie 5841
        }
5842
    }
5843
 
5844
    return ($consumed) if ($dir eq "");
5845
    $dir =~ s~//~/~g;
5846
    $dir =~ s~/$~~;
5847
    $$pdir = $dir;
5848
    return (1);
5849
}
5850
 
5851
 
5852
#   __PkgDir ---
5853
#       Convert --Dir Package directives, removing leading subdir if
5854
#       matching the global $Pbase value.
5855
#
5856
#       Required as PKGDIR has the value 'GBE_ROOT/pkg/$Pbase'.
5857
#       Required to maintain compatability with older (package.pl) constructs
5858
#..
5859
 
5860
sub __PkgDir
5861
{
5862
    my( $dir ) = @_;
5863
    my $org = $dir;
5864
 
245 dpurdie 5865
    $dir =~ s~^\Q$::Pbase\E[/]?~~;
227 dpurdie 5866
    Debug2( "  PkgDir: converted \"$org\" to \"$dir\"" );
5867
 
5868
    $dir = "\$(PKGDIR)/$dir";
5869
    return $dir;
5870
}
5871
 
5872
 
5873
#   getMajorMinor ---
5874
#       Just a little help to deal with major/minor stuff for shared libs -
5875
#       given the name of the library as the argument, split out major and
5876
#       minor parts and return the basename, i.e name without major and minor
5877
#       and the pair of major and minor.
5878
#..
5879
 
285 dpurdie 5880
sub getMajorMinor
227 dpurdie 5881
{
5882
    my @bits = split ('\.', $_[0]);
5883
    my $stop;
5884
    my $major;
5885
    my $minor;
5886
 
5887
    if ( $#bits > 2 )
5888
    {
5889
        $stop = $#bits - 2;
5890
        $major = $bits[$#bits-1];
5891
        $minor = $bits[$#bits];
5892
    }
5893
    elsif ($#bits > 1)
5894
    {
5895
        $stop = $#bits-1;
5896
        $major = $bits[$#bits];
5897
        $minor=0;
5898
    }
5899
    else
5900
    {
5901
        $stop = $#bits; $major = 1; $minor = 0;
5902
    }
5903
 
5904
    my $base = $bits[0];
5905
    for ( my $i=1; $i <= $stop; $i++ ) {
5906
        $base = join ('.', $base, $bits[$i]);
5907
    }
5908
 
5909
    return ($base, $major, $minor);
5910
}
5911
 
5912
###############################################################################
5913
#
5914
#   Installation
5915
#
5916
 
5917
sub InstallHdr
5918
{
5919
    my( $platforms, @elements ) = @_;
335 dpurdie 5920
    my( $base, $dir, $srcfile, $full, $strip, $package );
227 dpurdie 5921
    my( $len, $name, $basename );
5922
 
5923
    Debug2( "InstallHdr($platforms, @elements)" );
5924
 
5925
    return if ( ! ActivePlatform($platforms) );
5926
    Warning ("InstallHdr: Needs local directory specified in build.pl") unless ( $::ScmLocal );
5927
 
5928
#.. Arguments
5929
#
5930
    $base = $PackageInfo{'Hdr'}{'IBase'};       # Base of target
5931
    $dir = $base . $PackageInfo{'Hdr'}{'Dir'};  # Installation path (default)
335 dpurdie 5932
    $full = $strip = 0;
227 dpurdie 5933
 
285 dpurdie 5934
    foreach ( @elements )
227 dpurdie 5935
    {
5936
                                                # Standard targets
5937
        my $rv = __TargetDir(0, $base, $_, \$dir);
5938
        next if ( $rv == 1 );
5939
        return if ( $rv == 2 );
5940
 
5941
        if (/^--Full/) {                        # using full (resolved) path
5942
            $full = 1;
5943
 
5944
        } elsif (/^--Strip$/) {                 # Strip path from source files
5945
            $strip = 1;
5946
 
5947
                                                # Package
5948
        } elsif (/^--Package$/ || /^--Package=(.*)/) {
5949
            $package = 1;
5950
 
5951
        } elsif (/^--(.*)/) {
5952
            Message( "InstallHdr: unknown option $_ -- ignored\n" );
5953
        }
5954
    }
5955
 
5956
#.. Files
5957
#
285 dpurdie 5958
    foreach ( @elements )
227 dpurdie 5959
    {
5960
        my %package_entry;
5961
        if ( ! /^--(.*)/ )
5962
        {
5963
            $name = $_;
5964
            $basename = StripDir( $name );
335 dpurdie 5965
            if ( !($srcfile = $SRCS{ $basename }) ) {
5966
                $srcfile = $name;
5967
            }
5968
 
227 dpurdie 5969
            if ( $full )
5970
            {
335 dpurdie 5971
                my $subdir = StripFileExt($srcfile);
5972
                $subdir = $1
5973
                    if ( $subdir =~ m~^$ProjectBase/(.*)~ );
5974
                $dir .= '/' . $subdir;
5975
                $dir =~ s~//~/~g;
5976
                $dir =~ s~/./~/~g;
5977
                $dir =~ s~/$~~g;
5978
                $name = $basename;
227 dpurdie 5979
            }
5980
 
5981
            $name = $basename
5982
                if ( $strip );
5983
 
5984
            Debug( "InstallHdr( $dir/$name, src: $srcfile, dest: $dir)" );
5985
 
5986
            $package_entry{'src'} = $srcfile;
5987
            $package_entry{'dir'} = StripFileExt( "$dir/$name" );
5988
            $INSTALL_HDRS{ "$dir/$name" } = {%package_entry};
5989
        }
5990
    }
5991
 
5992
#.. Package
5993
#
5994
    PackageHdr( @_ )                            # auto package
5995
        if ( $package );
5996
}
5997
 
5998
 
5999
sub InstallLib
6000
{
6001
    my( $platforms, @elements ) = @_;
6002
    my( $base, $dir, $package );
6003
    my( $lib, $strip );
289 dpurdie 6004
    my $org_lib;
227 dpurdie 6005
 
6006
    Debug2( "InstallLib($platforms, @elements)" );
6007
 
6008
    return if ( ! ActivePlatform($platforms) );
6009
    Warning ("InstallLib: Needs local directory specified in build.pl") unless ( $::ScmLocal );
6010
 
6011
#.. Arguments
6012
#
6013
    $base = $PackageInfo{'Lib'}{'IBase'};       # Base of target
6014
    $dir = $base . $PackageInfo{'Lib'}{'Dir'};  # Installation path (default)
6015
 
285 dpurdie 6016
    foreach ( @elements )
227 dpurdie 6017
    {
6018
                                                # Standard targets
6019
        my $rv = __TargetDir(0, $base, $_, \$dir);
6020
        next if ( $rv == 1 );
6021
        return if ( $rv == 2 );
6022
 
6023
        if (/^--Package$/ || /^--Package=(.*)/) {
6024
            $package = 1;
6025
 
6026
        } elsif (/^--Strip$/) {                 # Strip path from source files
6027
            $strip = 1;
6028
 
6029
        } elsif (/^--(.*)/) {
6030
            Message( "InstallLib: unknown option $_ -- ignored\n" );
6031
        }
6032
    }
6033
 
6034
#.. Files
6035
#
285 dpurdie 6036
    foreach ( @elements )
227 dpurdie 6037
    {
6038
        my %package_entry;
6039
        if ( ! /^--(.*)/ )
6040
        {
6041
            $_ = basename ($_)
6042
                if ( $strip );
289 dpurdie 6043
            $org_lib = $_;                      # Original name
227 dpurdie 6044
 
6045
            if ( $ScmTargetHost eq "Unix" ) {
6046
                $lib = "lib$_";                 # Prefix "lib" ....
6047
                $lib =~ s/^liblib/lib/;         # @LIBS already has lib added
6048
            } else {
6049
                $lib = $_;
6050
            }
6051
 
289 dpurdie 6052
            if (  my $libp = $SHLIBS->Get($lib) )
227 dpurdie 6053
            {
6054
                Debug( "InstallLib( $dir/$lib\$(GBE_TYPE).$::so, " .
6055
                    "src: \$(LIBDIR)/$lib\$(GBE_TYPE).$::so, dest: $dir)" );
6056
 
6057
                #
6058
                #   Create a "placekeeper" entry within $INSTALL_SHLIBS
6059
                #   The exact format of the name of the shared library is
6060
                #   toolset specific. Create an entry to allow the toolset
6061
                #   to extend the packaging information when the shared library
6062
                #   recipe is constructed.
6063
                #
289 dpurdie 6064
                my $ver = $libp->{ VERSION };
227 dpurdie 6065
                my $name = "$dir/$lib.$ver.PlaceKeeper";
6066
 
6067
                $package_entry{'placekeeper'} = 1;
6068
                $package_entry{'version'} = $ver;
6069
                $package_entry{'lib'} = $lib;
6070
                $package_entry{'dir'} = $dir;
289 dpurdie 6071
 
6072
                push @{$SHLIB_INS{$lib}}, $name;
227 dpurdie 6073
                $INSTALL_SHLIBS{$name} = {%package_entry};
6074
            }
6075
 
289 dpurdie 6076
            #
6077
            #   Clean up the package_entry
6078
            #   Insert common items
6079
            #
6080
            %package_entry = ();
6081
            $package_entry{'lib'} = $lib;
6082
            $package_entry{'dir'} = $dir;
6083
 
321 dpurdie 6084
            if ( my $libfile = $SRCS{$org_lib} )
227 dpurdie 6085
            {
6086
                #
6087
                #   Allow the user to package a sourced file as a library
289 dpurdie 6088
                #   But must be the un-massaged name of the file.
227 dpurdie 6089
                #
289 dpurdie 6090
                $package_entry{'dst'} = "$dir/$org_lib";
6091
                $package_entry{'src'} = $libfile;
6092
            }
6093
            elsif ( $LIBS->Get($lib) )
6094
            {
6095
                #
6096
                #   Install a library known to the makefile
6097
                #
6098
                my $libp = $LIBS->Get($lib);
227 dpurdie 6099
 
289 dpurdie 6100
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
6101
                $package_entry{'src'}    = $libp->getPath();
227 dpurdie 6102
            }
289 dpurdie 6103
            elsif ( ! $SHLIBS->Get($lib) )
227 dpurdie 6104
            {
289 dpurdie 6105
                #
6106
                #   Not a known shared lib
6107
                #   Not a known static lib
6108
                #   Not a 'sourced' file
6109
                #   Assume the a static library has magically appeared
6110
                #   in the standard LIB directory. May have been placed there
6111
                #   by a 'rule'
6112
                #
6113
                my $libp = $LIBS->New($lib);
227 dpurdie 6114
 
289 dpurdie 6115
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
6116
                $package_entry{'src'}    = $libp->getPath();
6117
            }
227 dpurdie 6118
 
289 dpurdie 6119
            #
6120
            #   Add entry to various lists if required
6121
            #
6122
            PackageLib_AddEntry ('InstallLib', \%LIB_INS, \%INSTALL_LIBS, \%package_entry )
6123
                if ( exists $package_entry{'dst'} );
227 dpurdie 6124
        }
6125
    }
6126
 
6127
#.. Package
6128
#
6129
    PackageLib( @_ )                            # auto package
6130
        if ( $package );
6131
}
6132
 
6133
 
6134
sub InstallJar
6135
{
6136
    my( $platforms, @elements ) = @_;
6137
    my( $base, $dir, $package );
6138
    my( $jar );
6139
 
6140
    Debug2( "InstallJar($platforms, @elements)" );
6141
 
6142
    return if ( ! ActivePlatform($platforms) );
6143
    Warning ("InstallJar: Needs local directory specified in build.pl") unless ( $::ScmLocal );
6144
 
6145
#.. Arguments
6146
#
6147
    $base = $PackageInfo{'Jar'}{'IBase'};       # Base of target
6148
    $dir = $base . $PackageInfo{'Jar'}{'Dir'};  # Installation path (default)
6149
 
285 dpurdie 6150
    foreach ( @elements )
227 dpurdie 6151
    {
6152
                                                # Standard targets
6153
        my $rv = __TargetDir(0, $base, $_, \$dir);
6154
        next if ( $rv == 1 );
6155
        return if ( $rv == 2 );
6156
 
6157
        if (/^--Package$/ || /^--Package=(.*)/) {
6158
            $package = 1;
6159
 
6160
        } elsif (/^--(.*)/) {
6161
            Message( "InstallJar: unknown option $_ -- ignored\n" );
6162
        }
6163
    }
6164
 
6165
 
6166
#.. Files
6167
#
285 dpurdie 6168
    foreach ( @elements )
227 dpurdie 6169
    {
6170
        my %package_entry;
6171
        if ( ! /^--(.*)/ )
6172
        {
6173
            $jar = $_;
6174
            my $src;
6175
            my $dest;
6176
 
6177
            if ( $JAR_FILES{$jar} )
6178
            {
6179
                $src = $JAR_FILES{$jar};
6180
                $dest = $jar;
6181
            }
6182
            else
6183
            {
6184
                $src = "\$(CLSDIR)/$jar\$(GBE_TYPE).jar";
6185
                $dest = "$jar\$(GBE_TYPE).jar";
6186
            }
6187
 
6188
 
6189
            Debug( "InstallJar( $dir/$dest, " .
6190
                "src: $src, dest: $dir)" );
6191
 
6192
            $package_entry{'src'} = $src;
6193
            $package_entry{'dir'} = $dir;
6194
            $INSTALL_CLSS{ "$dir/$dest" } = {%package_entry};
6195
 
6196
        }
6197
    }
6198
 
6199
#.. Package
6200
#
6201
    PackageJar( @_ )                            # auto package
6202
        if ( $package );
6203
}
6204
 
6205
 
6206
sub InstallProg
6207
{
6208
    my( $platforms, @elements ) = @_;
6209
    my( $base, $dir, $package );
6210
    my( $prog );
6211
 
6212
    Debug2( "InstallProg($platforms, @elements)" );
6213
 
6214
    return if ( ! ActivePlatform($platforms) );
6215
    Warning ("InstallProg: Needs local directory specified in build.pl") unless ( $::ScmLocal );
6216
 
6217
#.. Arguments
6218
#
6219
    $base = $PackageInfo{'Prog'}{'IBase'};       # Base of target
6220
    $dir = $base . $PackageInfo{'Prog'}{'Dir'};  # Installation path (default)
6221
 
285 dpurdie 6222
    foreach ( @elements )
227 dpurdie 6223
    {
6224
                                                # Standard targets
6225
        my $rv = __TargetDir($T_TYPE, $base, $_, \$dir);
6226
        next if ( $rv == 1 );
6227
        return if ( $rv == 2 );
6228
 
6229
        if (/^--Package$/ || /^--Package=(.*)/) {
6230
            $package = 1;
6231
 
6232
        } elsif (/^--(.*)/) {
6233
            Message( "InstallProg: unknown option $_ -- ignored\n" );
6234
        }
6235
    }
6236
 
6237
#.. Files
6238
#
285 dpurdie 6239
    foreach ( @elements )
227 dpurdie 6240
    {
6241
        my %package_entry;
6242
        if ( ! /^--(.*)/ )
6243
        {
6244
            my $ext = "";
6245
            $prog = $_;
6246
 
6247
            #
6248
            #   If the named target is a program then append the correct
6249
            #   extension. Otherwise assume that the target is either a script
6250
            #   or a some other file - and don't append an extension
6251
            #
6252
            $ext = $::exe
289 dpurdie 6253
                if ( $PROGS->Get($prog) );
227 dpurdie 6254
 
6255
            #
6256
            #   A "file" that is specified with a "Src" directive may be
6257
            #   installed as though it were a program
6258
            #
6259
            my $progfile;
6260
            $progfile = "\$(BINDIR)/$prog$ext"
6261
                unless ( $progfile = $SRCS{$prog} );
6262
 
6263
            Debug( "InstallProg( $dir/$prog$ext, " .
6264
                 "src: $progfile, dest: $dir)" );
6265
 
6266
            push @{$PROG_INS{$prog}}, "$dir/$prog$ext";
6267
 
6268
            $package_entry{'src'} = $progfile;
6269
            $package_entry{'dir'} = $dir;
6270
            $INSTALL_PROGS{ "$dir/$prog$ext" } = {%package_entry};
6271
        }
6272
    }
6273
 
6274
#.. Package
6275
#
6276
    PackageProg( @_ )                           # auto package
6277
        if ( $package );
6278
}
6279
 
6280
 
6281
###############################################################################
6282
#
6283
#   Packaging
6284
#
6285
sub PackageDist
6286
{
6287
    my( $name, @elements ) = @_;
6288
 
6289
    Debug2( "PackageDist($name, @elements)" );
6290
 
6291
    foreach ( @elements )
6292
    {
6293
    #.. Distribution sets
6294
    #
6295
        HashJoin( \%PACKAGE_DIST, $;, $name, "$_" );
6296
 
6297
    #.. Summary of distribution sets
6298
    #
267 dpurdie 6299
        $PACKAGE_SETS{ $_ }{'TAG'} = 1
6300
            if ( ! exists $PACKAGE_SETS{ $_ }{'TAG'} );
227 dpurdie 6301
    }
6302
}
6303
 
311 dpurdie 6304
#-------------------------------------------------------------------------------
6305
# Function        : PackageFile
6306
#
6307
# Description     : Directive to package files
6308
#                   Not to be used to package libraries, executables, headers
6309
#                   as this should be done by specialised directives
6310
#
6311
#                   Use to package other files
6312
#                   Can package an entire tree (ugly)
6313
#
6314
# Inputs          : 
6315
#
6316
#
227 dpurdie 6317
sub PackageFile
6318
{
6319
    my( $platforms, @elements ) = @_;
335 dpurdie 6320
    my( $base, $dir, $full, $path, $dist, $strip, $exefile, $type );
227 dpurdie 6321
    my( $name, $basename, $len, $srcfile );
4257 dpurdie 6322
    my( $dir_tree, @dir_tree_exclude, @dir_tree_include, $strip_base, $strip_dots );
335 dpurdie 6323
    my $recurse = 1;
227 dpurdie 6324
 
6325
    Debug2( "PackageFile($platforms, @elements)" );
6326
 
6327
    return if ( !$ScmPackage );                 # Packaging enabled ?
6328
    return if ( ! ActivePlatform($platforms) );
6329
 
6330
#.. Arguments
6331
#
6332
    $dist = "ALL";                                  # Default set (ALL)
6333
    $base = $PackageInfo{'File'}{'PBase'};          # Base of target
6334
    $dir = $base . $PackageInfo{'File'}{'Dir'};     # Installation path (default)
335 dpurdie 6335
    $full = 0;
227 dpurdie 6336
    $strip = 0;
341 dpurdie 6337
    $strip_base = 0;
4257 dpurdie 6338
    $strip_dots = 0;
227 dpurdie 6339
    $exefile = 0;
6340
 
285 dpurdie 6341
    foreach ( @elements )
227 dpurdie 6342
    {
6343
        my $rv = __TargetDir($T_PKG|$T_MACH|$T_GBE|$T_FILE, $base, $_, \$dir, \$type);
6344
        next if ( $rv == 1 );
6345
        return if ( $rv == 2 );
6346
 
6347
        if (/^--Full/) {                        # Using full (resolved) path
6348
            $full = 1;
6349
 
6350
        } elsif (/^--Set=(.*)/) {               # Distribution set
6351
            $dist = "$1";
6352
 
6353
        } elsif (/^--Package$/) {               # Package .. call by InstallFile
6354
        } elsif (/^--Package=(.*)/) {
6355
            $dist = "$1";
6356
 
6357
        } elsif (/^--Strip$/) {                 # Strip path from source files
6358
            $strip = 1;
6359
 
6360
        } elsif (/^--Executable$/) {            # Mark the file as executable
6361
            $exefile = "X";
6362
 
6363
        } elsif ( /^--DirTree=(.*)/ ) {
6364
            Error("DirTree. Multiple directories not allowed.") if ( $dir_tree );
4163 dpurdie 6365
            $dir_tree =  $1;
4257 dpurdie 6366
            Error("DirTree. No path specified") unless ( defined($dir_tree) && $dir_tree ne "" );
227 dpurdie 6367
 
4163 dpurdie 6368
            # Prevent the user from escaping from the current directory
6369
            Error("DirTree. Absolute paths are not allowed",
6370
                  "Directory: $dir_tree") if ( $dir_tree =~ m~^/~ || $dir_tree =~ m~^.\:~ );
6371
 
6372
            #
6373
            #   Convert the relative path to one that is truely relative to the current
6374
            #   directory. This may occur when the user uses $ProjectBase
6375
            #
4257 dpurdie 6376
            my $abs_dir_tree = AbsPath($dir_tree);
6377
            $dir_tree = RelPath($abs_dir_tree);
6378
 
6379
            #
6380
            #   Ensure that the user is not trying to escape the package
4265 dpurdie 6381
            #   Don't allow the user to attempt to package the entire package either
4257 dpurdie 6382
            #
6383
            #   Calculate the relative path from $ProjectBase to the target directory
6384
            #   It must not be above the $ProjectBase 
6385
            #
4265 dpurdie 6386
            if ( $dir_tree =~ m~^\.\.~)
6387
            {
6388
                my $dirFromBase = RelPath($abs_dir_tree, AbsPath($ProjectBase));
6389
                Error("DirTree cannot extend outside current package.",
6390
                      "Directory: $dirFromBase") if ( $dirFromBase =~ m~\.\.~ );
6391
                Error("DirTree cannot package entire package.",
6392
                    "Directory: $dirFromBase") if ( $dirFromBase eq '.' );
6393
            }
4257 dpurdie 6394
 
4163 dpurdie 6395
            Debug2( "PackageFile. DirTree: $dir_tree" );
6396
 
227 dpurdie 6397
            Error("DirTree. Directory not found",
6398
                  "Directory: $dir_tree") unless  ( -d $dir_tree );
6399
 
4257 dpurdie 6400
            # If packaging a parent directory then force dot_stripping of the base directory
6401
            # strip_base will have precedence if both are active
6402
            if ( $dir_tree =~ m~\.\.~ )
6403
            {
6404
                $dir_tree =~ m~(\.\./)+~;
6405
                $strip_dots = length($1);
6406
            }
6407
 
227 dpurdie 6408
        } elsif ( /^--FilterOut=(.*)/ ) {
6409
            push @dir_tree_exclude, $1;
6410
 
6411
        } elsif ( /^--FilterIn=(.*)/ ) {
6412
            push @dir_tree_include, $1;
6413
 
6414
        } elsif ( /^--StripDir/ ) {
341 dpurdie 6415
            $strip_base = 1;
227 dpurdie 6416
 
335 dpurdie 6417
        } elsif ( m/^--Recurse/ ) {
6418
            $recurse = 1;
6419
 
6420
        } elsif ( m/^--NoRecurse/ ) {
6421
            $recurse = 0;
6422
 
227 dpurdie 6423
        } elsif (/^--(.*)/) {
6424
            Message( "PackageFile: unknown option $_ -- ignored\n" );
6425
        }
6426
    }
6427
 
6428
 
6429
    #.. DirTree expansion
6430
    #   Note: Uses REs, not simple globs
6431
    #         Use JatsLocateFiles to do the hard work
6432
    if ( $dir_tree )
6433
    {
335 dpurdie 6434
        my $search = JatsLocateFiles->new('FullPath' );
6435
        $search->recurse($recurse);
227 dpurdie 6436
        $search->filter_in_re ( $_ ) foreach ( @dir_tree_include );
6437
        $search->filter_out_re( $_ ) foreach ( @dir_tree_exclude );
1431 dpurdie 6438
        $search->filter_out_re( '/\.svn/' );
5848 dpurdie 6439
        $search->filter_out_re( '/\.git/' );
227 dpurdie 6440
        @elements = $search->search ( $dir_tree );
4257 dpurdie 6441
        if ($strip_base){
6442
            $strip_base = length( $dir_tree ) if ( $strip_base );
6443
        } elsif ($strip_dots) {
6444
            $strip_base = $strip_dots;
6445
        }
227 dpurdie 6446
    }
6447
 
6448
#.. Files
6449
#
285 dpurdie 6450
    foreach ( @elements )
227 dpurdie 6451
    {
6452
        my %package_entry;
299 dpurdie 6453
        $name = $_;
6454
 
227 dpurdie 6455
        #
299 dpurdie 6456
        #   Trap special files
6457
        #       DPACKAGE - but only if we have a DPackageLibrary directive
6458
        #                  in the same makefile.
6459
        #
6460
        if ( m~^DPACKAGE$~ && $DPackageDirective ) {
6461
            $name = 'DPACKAGE.' . $::GBE_MACHTYPE;
6462
        }
6463
 
6464
        #
387 dpurdie 6465
        #   Allow for named files that must be quoted
6466
        $name = QuoteForMake( $name );
227 dpurdie 6467
 
6468
        if ( ! /^--(.*)/ )
6469
        {
6470
            $basename = StripDir( $name );
335 dpurdie 6471
            if ( !($srcfile = $SRCS{ $basename }) ) {
6472
                $srcfile = $name;
6473
            }
6474
 
227 dpurdie 6475
            if ( $full )
6476
            {
335 dpurdie 6477
                my $subdir = StripFileExt($srcfile);
6478
                $subdir = $1
6479
                    if ( $subdir =~ m~^$ProjectBase/(.*)~ );
6480
                $dir .= '/' . $subdir;
6481
                $dir =~ s~//~/~g;
6482
                $dir =~ s~/./~/~g;
6483
                $dir =~ s~/$~~g;
6484
                $name = $basename;
227 dpurdie 6485
            }
6486
 
6487
            $name = $basename
6488
                if ( $strip );
6489
 
341 dpurdie 6490
            if ( $strip_base )
6491
            {
6492
                $name = substr $name, $strip_base;
6493
                $name =~ s~^/~~;
6494
            }
6495
 
227 dpurdie 6496
            $dir =~ s~//~/~g;
6497
            $dir =~ s~/$~~;
6498
 
6499
            #
6500
            #   Sanity test the source filename
6501
            #   User may have misused an option
6502
            #
6503
            if ( ( $srcfile =~ m/=/ ) || ( $srcfile =~ m/^-/ ) || ( $srcfile =~ m~/-~ )  )
6504
            {
6505
               Warning ("PackageFile: Suspect source filename: $srcfile");
6506
            }
6507
 
6508
            Debug( "PackageFile( $dir/$name, " .
6509
                "src: $srcfile, dest: $dir, dist: $dist, exe: $exefile )" );
6510
 
6511
            $package_entry{'src'} = $srcfile;
6512
            $package_entry{'dir'} = StripFileExt( "$dir/$name" );
6513
            $package_entry{'set'} = $dist;
6514
            $package_entry{'exe'} = $exefile if $exefile;
6515
            $package_entry{'type'} = $type if ( $type );
6516
 
6517
            $PACKAGE_FILES{ "$dir/$name" } = {%package_entry};
6518
        }
6519
    }
6520
}
6521
 
6522
sub PackageHdr
6523
{
6524
    my( $platforms, @elements ) = @_;
335 dpurdie 6525
    my( $base, $dir, $full, $path, $dist, $strip );
227 dpurdie 6526
    my( $name, $basename, $len, $srcfile );
6527
 
6528
    Debug2( "PackageHdr($platforms, @elements)" );
6529
 
6530
    return if ( !$ScmPackage );                 # Packaging enabled ?
6531
    return if ( ! ActivePlatform($platforms) );
6532
 
6533
#.. Arguments
6534
#
6535
    $dist = "ALL";                                  # Default set (ALL)
6536
    $base = $PackageInfo{'Hdr'}{'PBase'};           # Base of target
6537
    $dir = $base . $PackageInfo{'Hdr'}{'Dir'};      # Installation path (default)
335 dpurdie 6538
    $full = 0;
227 dpurdie 6539
    $strip = 0;
6540
 
285 dpurdie 6541
    foreach ( @elements )
227 dpurdie 6542
    {
6543
        my $rv = __TargetDir($T_PKG, $base, $_, \$dir);
6544
        next if ( $rv == 1 );
6545
        return if ( $rv == 2 );
6546
 
6547
        if (/^--Full/) {                        # Using full (resolved) path
6548
            $full = 1;
6549
 
6550
        } elsif (/^--Set=(.*)/) {               # Distribution set
6551
            $dist = "$1";
6552
 
6553
        } elsif (/^--Package$/) {               # Package .. call by InstallHdr
6554
        } elsif (/^--Package=(.*)/) {
6555
            $dist = "$1";
6556
 
6557
        } elsif (/^--Strip$/) {                 # Strip path from source files
6558
            $strip = 1;
6559
 
6560
        } elsif (/^--(.*)/) {
6561
            Message( "PackageHdr: unknown option $_ -- ignored\n" );
6562
        }
6563
    }
6564
 
6565
#.. Files
6566
#
285 dpurdie 6567
    foreach ( @elements )
227 dpurdie 6568
    {
6569
        my %package_entry;
6570
        if ( ! /^--(.*)/ )
6571
        {
387 dpurdie 6572
            $name = QuoteForMake($_);
227 dpurdie 6573
            $basename = StripDir( $name );
335 dpurdie 6574
            if ( !($srcfile = $SRCS{ $basename }) ) {
6575
                $srcfile = $name;
6576
            }
6577
 
227 dpurdie 6578
            if ( $full )
6579
            {
335 dpurdie 6580
                my $subdir = StripFileExt($srcfile);
6581
                $subdir = $1
6582
                    if ( $subdir =~ m~^$ProjectBase/(.*)~ );
6583
                $dir .= '/' . $subdir;
6584
                $dir =~ s~//~/~g;
6585
                $dir =~ s~/./~/~g;
6586
                $dir =~ s~/$~~g;
6587
                $name = $basename;
227 dpurdie 6588
            }
6589
 
6590
            $name = $basename
6591
                if ( $strip );
6592
 
6593
            Debug( "PackageHdr( $dir/$name, " .
6594
                "src: $srcfile, dest: $dir, dist: $dist )" );
6595
 
6596
            $package_entry{'src'} = $srcfile;
6597
            $package_entry{'dir'} = StripFileExt( "$dir/$name" );
6598
            $package_entry{'set'} = $dist;
6599
 
6600
            $PACKAGE_HDRS{ "$dir/$name" } = {%package_entry};
6601
        }
6602
    }
6603
}
6604
 
6605
 
6606
sub PackageLib
6607
{
6608
    my( $platforms, @elements ) = @_;
6609
    my( $base, $dir, $dist, $type );
6610
    my( $lib, $org_lib, %extras, $strip );
6611
 
6612
    Debug2( "PackageLib($platforms, @elements)" );
6613
 
6614
    return if ( !$ScmPackage );                 # Packaging enabled ?
6615
    return if ( ! ActivePlatform($platforms) );
6616
 
6617
#.. Arguments
6618
#
6619
    $dist = "ALL";                              # Default set (ALL)
6620
    $base = $PackageInfo{'Lib'}{'PBase'};       # Base of target
6621
    $dir = $base . $PackageInfo{'Lib'}{'Dir'};  # Installation path (default)
6622
    $type = "";
6623
 
285 dpurdie 6624
    foreach ( @elements )
227 dpurdie 6625
    {
6626
                                                # Standard targets
6627
        my $rv = __TargetDir($T_PKG, $base, $_, \$dir, \$type);
6628
        next if ( $rv == 1 );
6629
        return if ( $rv == 2 );
6630
 
6631
        if (/^--Set=(.*)/) {                    # Distribution set(s)
6632
            $dist = "$1";
6633
 
6634
        } elsif (/^--Package$/) {               # Package .. call by PackageLib
6635
        } elsif (/^--Package=(.*)/) {
6636
            $dist = "$1";
6637
 
6638
        } elsif (/^--Extras=(.*)/) {            # Extras=[none, .. ,all]
6639
            foreach my $elem ( split( ',', $1 ) )
6640
            {
6641
                Error ("PackageLib: Unknown Extras mode: $elem")
6642
                    unless ( grep m/$elem/, qw(none stub map lint debug all) );
6643
                $extras{$elem} = 1;
6644
            }
6645
            %extras = () if ( $extras{'all'} );
6646
 
6647
        } elsif (/^--Strip$/) {                 # Strip path from source files
6648
            $strip = 1;
6649
 
6650
        } elsif (/^--(.*)/) {
6651
            Message( "PackageLib: unknown option $_ -- ignored\n" );
6652
        }
6653
    }
6654
 
6655
#.. Files
6656
#
285 dpurdie 6657
    foreach ( @elements )
227 dpurdie 6658
    {
6659
        my %package_entry;
6660
        if ( ! /^--(.*)/ )
6661
        {
6662
            $_ = StripDir( $_ )
6663
                if ( $strip );
6664
 
6665
            $org_lib = $_;                      # Original name
6666
            if ( $ScmTargetHost eq "Unix" ) {
6667
                $lib = "lib$_";                 # Prefix "lib" ....
6668
                $lib =~ s/^liblib/lib/;         # @LIBS already has lib added
6669
            } else {
6670
                $lib = $_;
6671
            }
6672
 
289 dpurdie 6673
            if (  my $libp = $SHLIBS->Get($lib) )
227 dpurdie 6674
            {
6675
                Debug( "PackageLib( $dir/$lib\$(GBE_TYPE).$::so, " .
6676
                    "src: \$(LIBDIR)/$lib\$(GBE_TYPE).$::so, dest: $dir, dist: $dist, type: $type )" );
6677
 
6678
                #
6679
                #   Create a "placekeeper" entry within $PACKAGE_SHLIBS
6680
                #   The exact format of the name of the shared library is
6681
                #   toolset specific. Create an entry to allow the toolset
6682
                #   to extend the packaging information when the shared library
6683
                #   recipe is constructed.
6684
                #
6685
                #
289 dpurdie 6686
                my $ver = $libp->{ VERSION };
227 dpurdie 6687
                my $name = "$dir/$lib.$ver.PlaceKeeper";
6688
 
6689
                $package_entry{'placekeeper'} = 1;
6690
                $package_entry{'version'} = $ver;
6691
                $package_entry{'lib'} = $lib;
6692
                $package_entry{'dir'} = $dir;
6693
                $package_entry{'set'} = $dist;
6694
                $package_entry{'type'} = $type if ( $type );
6695
                $package_entry{'extras'} = {%extras} if ( scalar %extras );
289 dpurdie 6696
 
6697
                push @{$SHLIB_PKG{$lib}}, $name;
227 dpurdie 6698
                $PACKAGE_SHLIBS{$name} = {%package_entry};
6699
            }
6700
 
289 dpurdie 6701
            #
6702
            #   Clean up the package_entry
6703
            #   Insert common items
6704
            #
6705
            %package_entry = ();
6706
            $package_entry{'lib'} = $lib;
6707
            $package_entry{'dir'} = $dir;
6708
            $package_entry{'set'} = $dist;
6709
            $package_entry{'extras'} = {%extras} if ( scalar %extras );
6710
            $package_entry{'type'} = $type if ( $type );
6711
 
227 dpurdie 6712
            if ( my $libfile = $SRCS{$org_lib} )
6713
            {
6714
                #
6715
                #   Allow the user to package a sourced file as a library
6716
                #   But must be the un-massaged name of the file.
6717
                #
387 dpurdie 6718
                $package_entry{'dst'} = QuoteForMake("$dir/$org_lib");
6719
                $package_entry{'src'} = QuoteForMake($libfile);
289 dpurdie 6720
            }
6721
            elsif ( $LIBS->Get($lib) )
6722
            {
6723
                #
6724
                #   Package up a library known to the makefile
6725
                #
6726
                my $libp = $LIBS->Get($lib);
227 dpurdie 6727
 
289 dpurdie 6728
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
6729
                $package_entry{'src'}    = $libp->getPath();
227 dpurdie 6730
            }
289 dpurdie 6731
            elsif ( ! $SHLIBS->Get($lib) )
227 dpurdie 6732
            {
289 dpurdie 6733
                #
6734
                #   Not a known shared lib
6735
                #   Not a known static lib
6736
                #   Not a 'sourced' file
6737
                #   Assume the a static library has magically appeared
6738
                #   in the standard LIB directory. May have been placed there
6739
                #   by a 'rule'
6740
                #
6741
                my $libp = $LIBS->New($lib);
227 dpurdie 6742
 
289 dpurdie 6743
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
6744
                $package_entry{'src'}    = $libp->getPath();
6745
            }
227 dpurdie 6746
 
289 dpurdie 6747
            #
6748
            #   Add entry to various lists if required
6749
            #
6750
            PackageLib_AddEntry ('PackageLib', \%LIB_PKG, \%PACKAGE_LIBS, \%package_entry )
6751
                if ( exists $package_entry{'dst'} );
227 dpurdie 6752
        }
6753
    }
6754
}
6755
 
289 dpurdie 6756
#-------------------------------------------------------------------------------
6757
# Function        : PackageLib_AddEntry
6758
#
6759
# Description     : Helper function to add a package entry
6760
#                   to the lists
6761
#
6762
# Inputs          : $directive          - Directive name
6763
#                   $pList              - Ref to array list to maintain
6764
#                   $pHash              - Ref to hash to maintain
6765
#                   $pData              - Packaging Data
6766
#                                         Must Take a copy.
6767
#
6768
# Returns         : 
6769
#
227 dpurdie 6770
 
289 dpurdie 6771
sub PackageLib_AddEntry
6772
{
6773
    my ($directive, $pList, $pHash, $pData) = @_;
6774
 
6775
    my $lib = delete $pData->{'lib'};
6776
    my $dst = delete $pData->{'dst'};
6777
 
6778
    Error ("INTERNAL PackageLib_AddEntry: lib or dst not defined")
6779
        unless ( $lib && $dst );
6780
 
6781
    Debug( "$directive( ",$dst,
6782
            ", src: " ,$pData->{'src'},
6783
            ", dest: ",$pData->{'dir'},
6784
            ", dist: ",$pData->{'set'},
6785
            ", type: ",$pData->{'type'} || '',
6786
            " )" );
6787
 
6788
    push @{$pList->{$lib }}, $dst;
6789
    $pHash->{$dst } = {%$pData};
6790
}
6791
 
6792
 
227 dpurdie 6793
sub PackageProg
6794
{
6795
    my( $platforms, @elements ) = @_;
6796
    my( $base, $dir, $dist, $type );
6797
    my( $prog, %extras, $strip );
6798
 
6799
    Debug2( "PackageProg($platforms, @elements)" );
6800
 
6801
    return if ( !$ScmPackage );                 # Packaging enabled ?
6802
    return if ( ! ActivePlatform($platforms) );
6803
 
6804
#.. Arguments
6805
#
6806
    $dist = "ALL";                              # Default set (ALL)
6807
    $base = $PackageInfo{'Prog'}{'PBase'};       # Base of target
6808
    $dir = $base . $PackageInfo{'Prog'}{'Dir'};  # Installation path (default)
6809
    $type = "";
6810
 
285 dpurdie 6811
    foreach ( @elements )
227 dpurdie 6812
    {
6813
                                                # Standard targets
6814
        my $rv = __TargetDir($T_PKG|$T_TYPE, $base, $_, \$dir, \$type);
6815
        next if ( $rv == 1 );
6816
        return if ( $rv == 2 );
6817
 
6818
        if (/^--Set=(.*)/) {                    # Distribution set(s)
6819
            $dist = "$1";
6820
 
6821
        } elsif (/^--Package$/) {               # Package .. call by PackageLib
6822
        } elsif (/^--Package=(.*)/) {
6823
            $dist = "$1";
6824
 
6825
        } elsif (/^--Tool(([=])(.*))?$/) {      # Allow Tool and Tool=xxx specfic target
6826
            my $path = ( defined( $3) ) ? "/$3" : "";
261 dpurdie 6827
            $dir = "\$(PKGDIR)$path/\$(GBE_HOSTMACH)";
227 dpurdie 6828
 
6829
        } elsif (/^--Extras=(.*)/) {            # Extras=[none, .. ,all]
6830
            foreach my $elem ( split( ',', $1 ) )
6831
            {
6832
                Error ("PackageLib: Unknown Extras mode: $elem")
6833
                    unless ( grep m/$elem/, qw(none stub map lint debug all) );
6834
                $extras{$elem} = 1;
6835
            }
6836
            %extras = () if ( $extras{'all'} );
6837
 
6838
        } elsif (/^--Strip$/) {                 # Strip path from source files
6839
            $strip = 1;
6840
 
6841
        } elsif (/^--(.*)/) {
6842
            Message( "PackageProg: unknown option $_ -- ignored\n" );
6843
        }
6844
    }
6845
 
6846
#.. Files
6847
#
285 dpurdie 6848
    foreach ( @elements )
227 dpurdie 6849
    {
6850
        my %package_entry;
6851
        if ( m~descpkg~ ) {
6852
            PackageFile($platforms, @elements);
6853
 
6854
        } elsif ( ! /^--(.*)/ ) {
6855
            $_ = StripDir( $_ )
6856
                if ( $strip );
6857
 
6858
            my $ext = "";
6859
            $prog = $_;
6860
 
6861
            #
6862
            #   If the named target is a program then append the correct
6863
            #   extension. Otherwise assume that the target is either a script
6864
            #   or a some other file - and don't append an extension
6865
            #
6866
            #   A program may not have any object files, only libraries
6867
            #
6868
            $ext = $::exe
289 dpurdie 6869
                if ( $PROGS->Get($prog) );
227 dpurdie 6870
 
6871
            #
6872
            #   A "file" that is specified with a "Src" directive may be
6873
            #   installed as though it were a program
6874
            #
6875
            my $progfile;
387 dpurdie 6876
            if ( $progfile = $SRCS{$prog} )
6877
            {
6878
                $progfile = QuoteForMake($progfile);
6879
                $prog = QuoteForMake($prog);
6880
            }
6881
            else
6882
            {
6883
                $progfile = "\$(BINDIR)/$prog$ext";
6884
            }
227 dpurdie 6885
 
6886
            Debug( "PackageProg( $dir/$prog$ext, " .
6887
                 "src: $progfile, dest: $dir, dist: $dist, type: $type )" );
6888
 
6889
            my $target = "$dir/$prog$ext";
6890
            push @{$PROG_PKG{$prog}}, $target;
6891
 
6892
            $package_entry{'src'}   = $progfile;
6893
            $package_entry{'dir'}   = $dir;
6894
            $package_entry{'set'}   = $dist;
6895
            $package_entry{'extras'}= {%extras} if ( scalar %extras );
6896
            $package_entry{'type'}  = $type if ( $type );
6897
 
6898
            $PACKAGE_PROGS{$target} = {%package_entry};
6899
        }
6900
    }
6901
}
6902
 
6903
 
6904
sub PackageJar
6905
{
6906
    my( $platforms, @elements ) = @_;
6907
    my( $base, $dir, $dist, $type );
6908
    my( $jar );
6909
 
6910
    Debug2( "PackageJar($platforms, @elements)" );
6911
 
6912
    return if ( !$ScmPackage );                 # Packaging enabled ?
6913
    return if ( ! ActivePlatform($platforms) );
6914
 
6915
#.. Arguments
6916
#
6917
    $dist = "ALL";                              # Default set (ALL)
6918
    $base = $PackageInfo{'Jar'}{'PBase'};       # Base of target
6919
    $dir = $base . $PackageInfo{'Jar'}{'Dir'};  # Installation path (default)
6920
    $type = "";
6921
 
285 dpurdie 6922
    foreach ( @elements )
227 dpurdie 6923
    {
6924
                                                # Standard targets
6925
        my $rv = __TargetDir($T_PKG, $base, $_, \$dir, \$type);
6926
        next if ( $rv == 1 );
6927
        return if ( $rv == 2 );
6928
 
6929
        if (/^--Set=(.*)/) {                    # Distribution set(s)
6930
            $dist = "$1";
6931
 
6932
        } elsif (/^--Package$/) {               # Package .. call by InstallJar
6933
        } elsif (/^--Package=(.*)/) {
6934
            $dist = "$1";
6935
 
6936
        } elsif (/^--(.*)/) {
6937
            Message( "PackageJar: unknown option $_ -- ignored\n" );
6938
        }
6939
    }
6940
 
6941
#.. Files
6942
#
285 dpurdie 6943
    foreach ( @elements )
227 dpurdie 6944
    {
6945
        my %package_entry;
6946
        if ( ! /^--(.*)/ )
6947
        {
6948
            $jar = $_;
6949
            my $src;
6950
            my $dest;
6951
 
6952
            if ( $JAR_FILES{$jar} )
6953
            {
6954
                $src = $JAR_FILES{$jar};
6955
                $dest = $jar;
6956
            }
6957
            else
6958
            {
6959
                $src = "\$(CLSDIR)/$jar\$(GBE_TYPE).jar";
6960
                $dest = "$jar\$(GBE_TYPE).jar";
6961
            }
6962
 
6963
 
6964
            Debug( "PackageJar( $dir/$dest, " .
6965
                "src: $src, dest: $dir, dist: $dist, type: $type )" );
6966
 
6967
            $package_entry{'src'} = $src;;
6968
            $package_entry{'dir'} = $dir;
6969
            $package_entry{'set'} = $dist;
6970
            $package_entry{'type'} = $type if ( $type );
6971
 
6972
            $PACKAGE_CLSS{ "$dir/$dest" } = {%package_entry};
6973
 
6974
        }
6975
    }
6976
}
6977
 
6978
#-------------------------------------------------------------------------------
6979
# Function        : PackageProgAddFiles         - Add files to a PackageProg
6980
#                   PackageLibAddFiles          - Add files to a PackageLib
6981
#                   PackageShlibAddFiles        - Add files to a PackageLib (shared lib)
6982
#                   PackageShlibAddLibFiles     - Add files to a PackageLib (shared lib)
6983
#                                                 Add static library files
6984
#
6985
# Description     : Add files to a Program package or installation
6986
#                   For use by Tool sets to allow additional files to be
6987
#                   packaged with a program.
6988
#
6989
#                   The files are only added if the named program is being
6990
#                   packaged and/or installed.
6991
#
6992
#
6993
# Inputs          : prog        - program identifier
6994
#                   file        - A file to be add
6995
#                   args        - Additional packageing arguments
6996
#
6997
# Returns         : Nothing
6998
#
6999
 
7000
sub PackageProgAddFiles
7001
{
7002
    Debug("PackageProgAddFiles");
7003
 
7004
    PackageAddFiles ( \%PACKAGE_PROGS, \%PACKAGE_PROGS, \%PROG_PKG, @_);
7005
    PackageAddFiles ( \%INSTALL_PROGS, \%INSTALL_PROGS, \%PROG_INS, @_);
7006
}
7007
 
7008
sub PackageLibAddFiles
7009
{
7010
    Debug("PackageLibAddFiles");
7011
 
7012
    PackageAddFiles ( \%PACKAGE_LIBS, \%PACKAGE_LIBS, \%LIB_PKG, @_ );
7013
    PackageAddFiles ( \%INSTALL_LIBS, \%INSTALL_LIBS, \%LIB_INS, @_ );
7014
}
7015
 
7016
sub PackageShlibAddFiles
7017
{
7018
    my ($prog, $file, @args) = @_;
7019
    Debug("PackageShlibAddFiles");
7020
 
7021
    PackageAddFiles ( \%INSTALL_SHLIBS, \%INSTALL_SHLIBS, \%SHLIB_INS, @_ );
7022
    PackageAddFiles ( \%PACKAGE_SHLIBS, \%PACKAGE_SHLIBS, \%SHLIB_PKG, @_ );
7023
 
7024
    #
7025
    #   These files become the target of the "make_install_shlib" operation unless:
7026
    #       Conditionally packaged files are not always created
7027
    #       RemoveOnly files are not always generated
7028
    #
7029
    my $no_add;
7030
    foreach ( @args )
7031
    {
4382 dpurdie 7032
        if ( m/^defined=/ or m/^RemoveOnly=/ or /NoTarget=/ )
227 dpurdie 7033
        {
7034
            $no_add = 1;
7035
            last;
7036
        }
7037
    }
7038
 
7039
    push (@SHLIB_TARGETS, $file ) unless $no_add;
7040
}
7041
 
7042
sub PackageShlibAddLibFiles
7043
{
7044
    Debug("PackageShlibAddLibFiles");
7045
 
7046
    PackageAddFiles ( \%PACKAGE_SHLIBS, \%PACKAGE_LIBS, \%SHLIB_PKG, @_ , 'Class=lib');
7047
    PackageAddFiles ( \%INSTALL_SHLIBS, \%INSTALL_LIBS, \%SHLIB_INS, @_ , 'Class=lib');
7048
}
7049
 
7050
#-------------------------------------------------------------------------------
7051
# Function        : PackageAddFiles
7052
#
7053
# Description     : Internal function to add files to the data structures that
7054
#                   describe a package or installation
7055
#
7056
#                   Use this function to package or install additional files with
7057
#                   the Progs and Libs
7058
#
7059
#                   ie: Add a LIB file to be packaged with a Shared Library
7060
#                   ie: Add a MAP file to be packaged with a program
7061
#
7062
# Inputs          : ref_spkg  - Reference to the hash that contains the package data
7063
#                   ref_dpkg  - Reference to the target package/install hash
7064
#                               Normally the same as ref_dpkg, but does allow
289 dpurdie 7065
#                               a static library to be added to a dynamic library
227 dpurdie 7066
#                               package.
7067
#                   ref_list  - Reference to a hash that may contain package keys to process
7068
#                   prog      - Key for index to above
7069
#                   file      - A file to be added
7070
#                   args      - Additional packaging arguments
7071
#
7072
# Returns         :
7073
#
7074
sub PackageAddFiles
7075
{
7076
    my ($ref_spkg, $ref_dpkg, $ref_list, $prog, $file, @args ) = @_;
7077
 
7078
    #
7079
    #   Process entry
7080
    #   The files may need to be added to multiple packages
7081
    #
7082
    Debug("PackageAddFiles: $file");
7083
 
7084
    return unless ( $ref_list->{$prog} );
7085
 
7086
    #
7087
    #   Parse arguments and extract the "Class=xxx" argument. This may be used
7088
    #   to limit the extra files piggybacked with the base file
7089
    #   All files without a class will be treated as base files
7090
    #
7091
    my $class;
7092
    foreach ( @args )
7093
    {
7094
        next unless ( m~^Class=(.*)$~ );
7095
        $class = $1 unless ( $1 eq 'none' );
7096
    }
7097
    Debug("PackageAddFiles: Class: ", $class || 'Default=None');
7098
 
7099
    foreach my $entry_key ( @{$ref_list->{$prog}} )
7100
    {
7101
        Debug("PackageAddFiles: Entry found: $entry_key");
7102
 
7103
        #
7104
        #   Copy of the template entry
7105
        #
7106
        my %package_entry = %{$ref_spkg->{$entry_key}};
7107
        Error ("INTERNAL: Expected entry in PACKAGE_ hash not found: $entry_key" )
7108
            unless ( %package_entry );
7109
 
7110
        #
7111
        #   Do not add the file if the user has limited the extra files added
7112
        #   to the packaging list and the current file is not in the class list
7113
        #
7114
        if ( $class && $package_entry{'extras'} )
7115
        {
7116
            next unless ( $package_entry{'extras'}{$class} );
7117
        }
7118
 
7119
        #
7120
        #   Create new entries for the file
7121
        #
7122
        $package_entry{'src'} = $file;
7123
        foreach ( @args )
7124
        {
7125
            m~^(.*)=(.*)$~;
7126
            $package_entry{$1} = $2;
7127
        }
7128
 
7129
        #
7130
        #   Clean out useless fields
7131
        #   Must remove the placekeeper marker to allow the entry to be visible
7132
        #
7133
        delete $package_entry{'placekeeper'};
7134
        delete $package_entry{'version'};
7135
        delete $package_entry{'lib'};
261 dpurdie 7136
#       delete $package_entry{'extras'};                   # Keep these
227 dpurdie 7137
        delete $package_entry{'Class'};
7138
 
7139
        #
7140
        #   Add the entry
7141
        #
7142
        #   Under some conditions is it possible to attempt to add the same named
7143
        #   file. This will result in a circular dependancy in the makefile
7144
        #
7145
        #   The condition is when merged libaries with PDBs (WINCE+WIN32) are merged
261 dpurdie 7146
        #   and the source for the merge is the "local directory.
227 dpurdie 7147
        #
7148
        #
7149
        my $dst = $package_entry{'dir'} ;
7150
        ( my $dfile = $file) =~ s~.*/~~;
7151
        Debug( "    added $dst/$dfile = $file" );
7152
 
7153
        $ref_dpkg->{"$dst/$dfile"} = {%package_entry}
7154
            unless ( "$dst/$dfile" eq "$file" );
7155
    }
7156
}
7157
 
7158
#-------------------------------------------------------------------------------
7159
# Function        : PackageProgRemoveFiles
7160
#
7161
# Description     : Flag a Packaged program to be not packaged
7162
#                   This mechanism is used to remove a program from packageing
7163
#                   under conditions where the toolset has generated a different
7164
#                   program.
7165
#
7166
#                   The entry is flagged as a placeholder
7167
#
7168
# Inputs          : prog        - Program to process
7169
#
7170
# Returns         : Nothing
7171
#
7172
sub PackageProgRemoveFiles
7173
{
7174
    my ($prog) = @_;
7175
    Verbose ("PackageProgRemoveFiles: $prog" );
7176
    return unless (exists($PROG_PKG{$prog}));
7177
 
7178
    #
7179
    #   Must lookup the TAG to locate the  required entry
7180
    #
7181
    my $tag = $PROG_PKG{$prog};
7182
    foreach my $entry ( @$tag )
7183
    {
7184
        Verbose("Do not package: $entry");
7185
        if ( exists $PACKAGE_PROGS{$entry} )
7186
        {
7187
            $PACKAGE_PROGS{$entry}{placekeeper} = 'ProgRemoved';
7188
        }
7189
    }
7190
}
7191
 
7192
#-------------------------------------------------------------------------------
7193
# Function        : DPackageLibrary
7194
#
7195
# Description     : Collect information to allow the generation of a DPACKAGE
299 dpurdie 7196
#                   file. This directive allows the generation of "Library"
227 dpurdie 7197
#                   directives within the final DPACKAGE
7198
#
7199
#                   This directive does generate the DPACKAGE file.
7200
#
7201
# Inputs          : platform    - This does not need to be an active platform
7202
#                                 it is simply passed to the DPACKAGE builder
7203
#
7204
#                   using       - The "using" target
7205
#
7206
#                   ...         - Arguments for the Library directive
7207
#
7208
# Returns         :
7209
#
7210
sub DPackageLibrary
7211
{
7212
    JatsDPackage::DPackageAdd ( @_ );
299 dpurdie 7213
    $DPackageDirective = 1;
227 dpurdie 7214
}
7215
 
7216
#-------------------------------------------------------------------------------
7217
# Function        : SetProjectBase
7218
#
7219
# Description     : Allows the user to modify the build's concept of the Base
7220
#                   of the build. By default the base is the same directory as
7221
#                   the build.pl file, but in some contorted environments it
7222
#                   is a great deal simpler to specify a differnt base.
7223
#
7224
#                   The use may use the variable $ProjectBase as a path
7225
#                   specifier to locate files and directories
7226
#
7227
#                   Both absolute and relative paths are supported
7228
#                   If the initial value of $ProjectBase is relative then
7229
#                   it will be maintained as a relative path.
7230
#
7231
# Inputs          : elements        path to base
7232
#                                   These may be:
7233
#                                       --Up=xx
7234
#                                       name
7235
#
7236
# Returns         : Nothing
7237
#
7238
 
7239
#
7240
#   Allow the user to modify the project base variable
7241
#
7242
sub SetProjectBase
7243
{
7244
    my $rip = 0;
7245
    my $path = "";
7246
    my $is_relative;
7247
 
7248
    Debug("ProjectBase Initial: $ProjectBase, @_");
7249
 
7250
    #
7251
    #   Ensure that the ProjectBase is in a "nice" form
7252
    #   1) No /./ bits
7253
    #   2) No trailing /
7254
    #   3) Not equal to .
7255
    #   4) No training /.
7256
    #   5) No //
7257
    #
7258
    $ProjectBase =~ s~/\./~/~g;
7259
    $ProjectBase =~ s~/$~~g;
7260
    $ProjectBase =~ s~^\.$~~g;
7261
    $ProjectBase =~ s~/\.$~~g;
7262
    $ProjectBase =~ s~//$~/~g;
7263
 
7264
    #
7265
    #   ProjectBase may be absolute or relative
7266
    #   Determine this before we mess with it
7267
    #
7268
    $is_relative = ($ProjectBase !~ m~^/~);
7269
 
7270
    #
7271
    #   Process each argument
7272
    #
7273
    foreach ( @_ )
7274
    {
7275
        if ( /^--Up=([0-9]*)/ ) {
7276
            $rip = $1;
7277
        } elsif ( /^--/ ) {
7278
            Warning( "SetProjectBase - unknown option \"$_\" - ignored" );
7279
        } else {
7280
            $path = $_;
7281
        }
7282
    }
7283
 
7284
    #
7285
    #   Process the UP requests
7286
    #   If the tail directory is a ".." then up is done by adding another ".."
7287
    #   If the tail directory is not a "..", then up is done by removing it
7288
    #
7289
    #   If we go past the start of the path then simply add ".."
7290
    #
7291
    while ( $rip-- > 0 )
7292
    {
7293
        Debug2("ProjectBase: $ProjectBase, Up: $rip, IsRel: $is_relative");
7294
 
7295
        #
7296
        #   If ending in a /.. or is exactly equal to ..
7297
        #   Then its a dot-dot and the way to go UP is to append another ..
7298
        #
7299
        if ( $ProjectBase =~ m~(/\.\.$)|(^\.\.$)~ )
7300
        {
7301
            $ProjectBase .= '/..';
7302
        }
7303
        else
7304
        {
7305
            #
7306
            #   Not a dot-dot ending
7307
            #   Attempt to remove the last directory of the form
7308
            #       /xxxxx
7309
            #   Where the leading / is optional
7310
            #   Note: Must have at least one character in the dirname
7311
            #         This prevents leading / from matching - which is needed
7312
            #
7313
            unless ($ProjectBase =~ s~/?[^/]+$~~)
7314
            {
7315
                #
7316
                #   Removal failed
7317
                #   If a relative path then we can keep on going up,
7318
                #   otherwise we are dead.
7319
                #
7320
                Error ("ProjectBase outside project") unless ($is_relative);
7321
                $ProjectBase = '..';
7322
            }
7323
 
7324
            #
7325
            #   Ensure that the leading / in an absolute path is not deleted
7326
            #
7327
            $ProjectBase = '/'
7328
                unless ( $is_relative || $ProjectBase );
7329
        }
7330
    }
7331
 
7332
    #
7333
    #   Append the user path
7334
    #
7335
    $ProjectBase .= '/' . $path if ( $path );
7336
    $ProjectBase = '.' unless ( $ProjectBase );
7337
    Debug("ProjectBase set to : $ProjectBase");
7338
 
7339
    #
7340
    #   Once upon a time I tried to convert paths that contained spaces into
7341
    #   short (mangled) names. This was not sucessful because:
7342
    #       1) Clearcase dynamic views do not support name mangling
7343
    #       2) Samba file system does not appear to support name mangling
7344
    #
7345
    #   Spaces in paths are not good for MAKE
7346
    #   Now I simple generate a message
7347
    #
7348
    Warning( "ProjectBase contains a space: $ProjectBase")
7349
        if ( $ProjectBase =~ m/ / );
7350
 
7351
    #
7352
    #   Sanity check
7353
    #   Absolute paths can be checked easily
7354
    #   Checking of relative paths does not appear to work
7355
    #   When I tested it chdir, opendir and stat would limit themselves
7356
    #   and drop into the root directory ( under windows )
7357
    #
7358
    #   Solution: Check the path does not extend beyond the file tree
7359
    #
7360
    my $distance = 1;
7361
    my $tpath = $ProjectBase;
7362
 
7363
    if ( $is_relative && $tpath ne '.' )
7364
    {
7365
        #
7366
        #   Build up the complete pathname by merging it with the
7367
        #   current directory. Then clean it up.
7368
        #
7369
        $tpath = $::Cwd . '/' . $ProjectBase;
7370
 
7371
        #
7372
        #   Scan the list of diretories and count the distance from the root
7373
        #   This should not be greater than zero for sanity
7374
        #   Note: Get an empty elemement from the split due to
7375
        #         the leading / of the ABS path
7376
        #
7377
        $distance = 0;
7378
        foreach (  split ('/', $tpath) )
7379
        {
7380
            if ( m~\.\.~ )
7381
            {
7382
                $distance--;
7383
            }
7384
            else
7385
            {
7386
                $distance++;
7387
            }
7388
        }
7389
    }
7390
 
7391
    #
7392
    #   Warn if not a valid directory
7393
    #
7394
    Warning( "ProjectBase is not a directory: $ProjectBase")
7395
        if ( $distance <= 0 || !  -d $tpath  );
7396
 
7397
    #
7398
    #   $ProjectBase will always be a valid directory, but if its the top
7399
    #   directory (/) and it is added to a path we will get //path
7400
    #   This is not good, so // will be removed later in the AddIncDir and
7401
    #   AddSrcDir commands where $ProjectBase is really used.
7402
    #
7403
    #   Alternatively we could set $ProjectBase to an empty string, but then
7404
    #   this may be confused with an empty relative directory
7405
    #
7406
    Debug("ProjectBase Final  : $ProjectBase");
7407
}
7408
 
7409
#-------------------------------------------------------------------------------
7410
# Function        : DeployPackage
7411
#
7412
# Description     : Generate a deployed package
7413
#                   This is a gateway to a different packaging system
7414
#
7415
#                  DeployPackage and PackageXxxxx directives are mutually
7416
#                  exclusive. Only one person can play in the package area.
7417
#
7418
# Inputs          : Platform Specifier
7419
#                   Package Name    (Optional)
7420
#                   Options
7421
#                       --Name : Base name of the package. The default is taken
7422
#                                from the build.pl file
7423
#                       --Dir  : Package directory
7424
#                                The default is based on the package name
7425
#
7426
# Returns         :
7427
#
7428
sub DeployPackage
7429
{
7430
    my( $platforms, @elements ) = @_;
7431
    my $dir;
7432
    my $name;
7433
 
267 dpurdie 7434
    #
7435
    #   Flag that this build creates a deployable package, even if its not
7436
    #   active on this platform.
7437
    #
7438
    $DEPLOYPACKAGE = 1;
7439
 
7440
 
227 dpurdie 7441
    Debug2( "DeployPackage($platforms, @elements)" );
7442
    return if ( ! ActivePlatform($platforms) );
7443
 
7444
    #
7445
    #   Only allow one use of this directive
7446
    #
7447
    Error("DeployPackage can only be used once" ) if ( %DEPLOYPACKAGE );
267 dpurdie 7448
    $DEPLOYPACKAGE = 2;
227 dpurdie 7449
 
7450
    #
7451
    #   Ensure that the deployment file is available
7452
    #
7453
    my $command_file = $ScmDeploymentPatch ? "deploypatch.pl" : "deployfile.pl";
7454
    Error("DeployPackage: $command_file not found") unless (-f "./$command_file");
7455
    #
7456
    #   Collect arguments
7457
    #
7458
    foreach (@elements )
7459
    {
7460
        if ( m/^--Dir=(.*)/ ) {
7461
            Error ("DeployPackage: Package directory defined multiple times") if $dir;
7462
            $dir = $1;
7463
 
7464
        } elsif ( m/^--Name=(.*)/ ) {
7465
            Error ("DeployPackage: Package name defined multiple times") if $name;
7466
            $name = $1;
7467
 
7468
        } elsif ( m/^--/ ) {
7469
            Warning( "DeployPackage: Unknown option ignored: $_");
7470
 
7471
        } else {
7472
            Error ("DeployPackage: Package name defined multiple times") if $name;
7473
            $name = $_;
7474
 
7475
        }
7476
    }
7477
 
7478
    $name = $::ScmBuildPackage unless ( $name );
7479
 
7480
    #
7481
    #   Save the deployment data
7482
    #
7483
    $dir = lc($name) unless ( $dir );
7484
    $DEPLOYPACKAGE{'name'} = $name;
7485
    $DEPLOYPACKAGE{'dir'} = $dir;
7486
    $DEPLOYPACKAGE{'cmdfile'} = $command_file;
7487
 
7488
    #
7489
    #   Flag that toolset tests should be supressed
7490
    #   The Deploy world does not really use the full makefiles and if the
7491
    #   compilers are not installed will not be able to create deployment
7492
    #   packages
7493
    #
7494
    $ScmNoToolsTest = 1;
7495
}
7496
 
7497
 
7498
###############################################################################
7499
###############################################################################
7500
# Private function section.
7501
#       The following functions are used INTERNALLY by makelib.pl2.
7502
###############################################################################
7503
 
7504
###############################################################################
7505
#   A collection of functions to write to the MAKEFILE handle
7506
#
7507
#   MakeHeader          - Write a nice section header
7508
#   MakeNewLine         - Print a new line
7509
#   MakePrint           - Print a line ( without trailing \n)
7510
#   MakeQuote           - Escape \ and " character, then print a line
7511
#   MakePrintList       - Print an array
7512
#   MakeEntry           - Complex line printer
7513
#   MakePadded          - Padded line printer (internal)
7514
#   PadToPosn           - Calc space+tabs to tabstop (internal)
7515
#   MakeEntry3          - Complex Line Printer
7516
#   MakeDefEntry        - Print a definition line (Production + Debug support)
7517
#   MakeIfDefEntry      - Print ifdef entry
261 dpurdie 7518
#   MakeIfnDefEntry     - Print ifndef entry
7519
#   MakeIfZeroEntry     - Print ifeq entry
227 dpurdie 7520
#
7521
###############################################################################
7522
 
7523
sub MakeHeader
7524
{
7525
    my ($text, @rest) = @_;
7526
    my $length = length ($text);
7527
 
7528
    print MAKEFILE "\n";
7529
    print MAKEFILE "#--------- $text ", '-' x (80 - 12 - $length)  ,"\n";
7530
    print MAKEFILE "#    $_\n" foreach  ( @rest ) ;
7531
    print MAKEFILE "#\n";
7532
}
7533
 
7534
sub MakeNewLine         # Print a newline to the current 'Makefile'
7535
{
7536
    print MAKEFILE "\n";
7537
}
7538
 
7539
sub MakePrint           # Print to the current 'Makefile'
7540
{
7541
    print MAKEFILE @_
7542
        if ( defined $_[0] );
7543
}
7544
 
7545
sub MakeQuote           # Quote a makefile text line
7546
{
7547
    my( $line ) = @_;
7548
    $line =~ s/\\/\\\\/g;                       # quote all '\' characters
7549
    $line =~ s/"/\\"/g;                         # Then quote '"' characters
255 dpurdie 7550
    $line =~ s/=#/=\\#/g;                       # Then quote '=#' sequence
227 dpurdie 7551
    print MAKEFILE $line;
7552
}
7553
 
7554
sub MakePrintList
7555
{
7556
    print MAKEFILE $_ . "\n" foreach (@{$_[0]});
7557
}
7558
 
2429 dpurdie 7559
sub QuoteArray
7560
{
7561
    my $quote = "'";
7562
    if ( @_ ) {
7563
        return ($quote . join("$quote $quote", @_) . $quote);
7564
    }
7565
    return '';
7566
}
227 dpurdie 7567
 
7568
#-------------------------------------------------------------------------------
7569
# Function        : MakeEntry
7570
#
7571
# Description     : Build a entry based on the element list
7572
#                   Creates text of the form
7573
#                       $(BINDIR)/prog.exe: object1.obj \
7574
#                                           object2.obj
7575
#
7576
#
7577
# Inputs          : $prelim         - Preamble (one-off)
7578
#                   $postlim        - Postamble (one-off)
7579
#                   $prefix         - Pefix (to each element of array)
7580
#                   $postfix        - Postfix (to each element of array )
7581
#                   @elements       - Array of element to wrap
7582
#
7583
# Returns         :   1 Always
7584
#
7585
# Notes:
7586
#       The above description means that the following entry format is
7587
#       produced:
7588
#
7589
#           <preliminary><prefix><variant1><prefix><variant2>...<final>
7590
#
7591
#       With judicious use of newline and tab characters, a target
7592
#       and dependency list along with the command(s) to build the
7593
#       target can be constructed.
7594
#
7595
sub MakeEntry
7596
{
7597
    my( $prelim, $postlim, $prefix, $postfix, @elements ) = @_;
7598
 
7599
    MakePrint $prelim;
7600
    MakePrint "${prefix}${_}${postfix}" foreach ( @elements );
7601
    MakePrint $postlim if ($postlim);
7602
    return 1;
7603
}
7604
 
7605
#-------------------------------------------------------------------------------
7606
# Function        : MakePadded
7607
#
7608
# Description     : Generate aligned output of the form
7609
#                       Prefix_text           Aligned_text
7610
#                   where the aligned text is at a specified TAB boundary
7611
#
7612
# Inputs          : $align      - Tab stop (One tab = 8 chars)
7613
#                   $prefix     - Text to print before alignment occurs
7614
#                   @line       - Remainder of the line
7615
#
7616
sub MakePadded          # Print to the current 'Makefile', tab aligning
7617
{
7618
    my( $align, $prefix, @line ) = @_;
7619
 
7620
    my $strlen = length( $prefix );
7621
    my $pad = PadToPosn( $strlen, $align * 8 );
7622
 
7623
    print MAKEFILE $prefix . $pad;
7624
    print MAKEFILE @line;
7625
}
7626
 
7627
#-------------------------------------------------------------------------------
7628
# Function        : PadToPosn
7629
#
7630
# Description     : Given that we are at $startposn return a tab and space
7631
#                   string to place us at $endposn
7632
#
7633
sub PadToPosn
7634
{
7635
    my ($startposn, $endposn ) = @_;
7636
 
7637
 
7638
    #
7639
    #   Case where we are already too far into the line
7640
    #
7641
    return ( ' ' )if ( $endposn <= $startposn );
7642
 
7643
    my $tcount = 0;
7644
    my $scount = 0;
7645
 
7646
    while ( $startposn < $endposn )
7647
    {
7648
        $tcount ++;
7649
        $startposn = ($startposn >> 3) * 8 + 8;
7650
 
7651
        my $delta = $endposn - $startposn;
7652
        if ( $delta < 8 )
7653
        {
7654
            $scount = $delta;
7655
            last;
7656
        }
7657
 
7658
    }
7659
    return ( "\t" x $tcount .  ' ' x $scount );
7660
}
7661
 
7662
#-------------------------------------------------------------------------------
7663
# Function        : MakeEntry3
7664
#
7665
# Description     : Build a makefile entry based on the element list, tab aligned
7666
#                   Can creat text of the form:
7667
#                       TAG = NAME0 \       TAG : NAME0 \ 
7668
#                             NAME1               NAME1
7669
#
7670
#
7671
# Inputs          : $prelim             - Preliminary text
7672
#                   $presep             - Preliminary seperator
7673
#                   $elem_ref           - Either a single name or a reference to
7674
#                                         and array of names, or a hash.
7675
#
7676
# Returns         : Writes directly to the Makefile
7677
#
7678
sub MakeEntry3
7679
{
7680
    my( $prelim, $presep, $elem_ref ) = @_;
7681
 
7682
    #
7683
    #   The prelim may have some "\n" characters at the start
7684
    #   These simplify formatting, but mess up the nice formatting
7685
    #
7686
    if ($prelim =~ m~(^\n+)(.*)~ )
7687
    {
7688
        MakePrint $1;
7689
        $prelim = $2;
7690
    }
7691
 
7692
    #
7693
    #   Print the definition and the sep with nice padding
7694
    #
7695
    MakePadded ( 3, $prelim, $presep );
7696
    my $leadin = ' ';
7697
 
7698
    #
7699
    #   If a HASH reference then use a sorted list of keys from the hash.
7700
    #
7701
    if ( ref ($elem_ref) eq "HASH" )
7702
    {
7703
        my @hash_list;
7704
        @hash_list = sort keys ( %{$elem_ref} );
7705
        $elem_ref = \@hash_list;
7706
    }
7707
 
7708
    #
7709
    #   If the list is only one element long, then create a simple form
7710
    #   If the list is not an array ref, then treat it as a single element
7711
    #
7712
    if ( ref ($elem_ref) eq "ARRAY" )
7713
    {
7714
        my $line = 0;
7715
        foreach my $element ( @$elem_ref )
7716
        {
7717
            print MAKEFILE $leadin . $element;
7718
            $leadin = " \\\n" . PadToPosn(0,24 + length( $presep ) + 1 ) unless ($line++);
7719
        }
7720
    }
7721
    elsif ( defined $elem_ref )
7722
    {
7723
            print MAKEFILE $leadin . $elem_ref;
7724
    }
7725
    MakeNewLine();
7726
    return 1;
7727
}
7728
 
7729
#-------------------------------------------------------------------------------
7730
# Function        : MakeDefEntry
7731
#
7732
# Description     : Make a definition entry of the form
7733
#
7734
#                       TAG = NAME0 \
7735
#                             NAME1
7736
#
7737
#                   Support a list of definitions that will always be created
7738
#                   as well as a production and a debug list.
7739
#
7740
#                   Will always generate the "TAG = " string, even if the list
7741
#                   is empty.
7742
#
7743
#                   Will supress the TAG if there is no data if the FIRST opr starts with a '+'
7744
#
7745
# Inputs          : TAG         - Text tag to create
7746
#                   FIRST       - First assignement opr. = or +=
7747
#                   ALL_LIST    - A reference to a list of names to assign
7748
#                                 or a single name.
7749
#                   PROD_LIST   - Optional list to extend the definition with for a production build
7750
#                   DEBUG_LIST  - Optional list to extend the definition with for a debug build
7751
#
7752
# Returns         : Nothing
7753
#
7754
 
7755
sub MakeDefEntry
7756
{
7757
    my( $tag, $assign, $all, $prod, $debug ) = @_;
7758
 
7759
    #
7760
    #   Do not generate anything if the $opr is "+=" and there is no data
7761
    #   to output. ie: Supress empty TAG += statements
7762
    #
7763
    return if ( $assign =~ m/\+/ && ( ref($all) && ! defined $all->[0] ) );
7764
 
7765
    #
7766
    #   TAG for all entries
7767
    #
7768
    MakeEntry3( $tag, $assign, $all );
7769
 
7770
 
7771
    #
7772
    #   TAGs for PROD build
7773
    #   TAGs for DEBUG build
7774
    #
7775
    if ( defined $prod && defined $prod->[0] )
7776
    {
7777
        print MAKEFILE 'ifeq "$(DEBUG)" "0"' . "\n";
7778
        MakeEntry3( $tag, "+=", $prod );
267 dpurdie 7779
        print MAKEFILE 'endif' . "\n";
227 dpurdie 7780
    }
7781
 
7782
    if ( defined $debug && defined $debug->[0] )
7783
    {
7784
        print MAKEFILE 'ifeq "$(DEBUG)" "1"' . "\n";
7785
        MakeEntry3( $tag, "+=", $debug );
267 dpurdie 7786
        print MAKEFILE 'endif' . "\n";
227 dpurdie 7787
    }
7788
 
7789
}
7790
 
7791
sub MakeIfDefEntry
7792
{
7793
    my( $iftag, @rest ) = @_;
7794
 
7795
    print MAKEFILE "ifdef $iftag\n";
7796
    MakeDefEntry (@rest);
7797
    print MAKEFILE "endif\n\n";
7798
}
7799
 
7800
sub MakeIfnDefEntry
7801
{
7802
    my( $iftag, @rest ) = @_;
7803
 
7804
    print MAKEFILE "ifndef $iftag\n";
7805
    MakeDefEntry (@rest);
7806
    print MAKEFILE "endif\n\n";
7807
}
7808
 
261 dpurdie 7809
sub MakeIfZeroEntry
7810
{
7811
    my( $iftag, @rest ) = @_;
7812
 
7813
    print MAKEFILE "ifeq (\$($iftag),0)\n";
7814
    MakeDefEntry (@rest);
7815
    print MAKEFILE "endif\n\n";
7816
}
7817
 
227 dpurdie 7818
#-------------------------------------------------------------------------------
7819
# Function        : CreateNameList
7820
#
7821
# Description     : Create a list of names by adding a prefix and suffix to a
7822
#                   list of items. This is used to add a directory prefix and a
7823
#                   file suffix to a list of files.
7824
#
7825
# Inputs          : $prefix             ie: '$(OBJDIR)/'
7826
#                   $suffix             ie: '.obj'
7827
#                   $elem_ref           ie: A list of files ( passed be ref )
7828
#                                           If a Hash then its sorted keys is used
7829
#
7830
# Returns         : A ref to the resulting list
7831
#
7832
sub CreateNameList
7833
{
7834
    my( $prefix, $suffix, $elem_ref ) = @_;
7835
    my @result;
7836
 
7837
    if ( ref ($elem_ref) eq "HASH" )
7838
    {
7839
        my @hash_list;
7840
        @hash_list = sort keys ( %{$elem_ref} );
7841
        $elem_ref = \@hash_list;
7842
    }
7843
 
7844
    foreach  ( @$elem_ref )
7845
    {
7846
        push @result, $prefix . $_ . $suffix;
7847
    }
7848
    return \@result;
7849
}
7850
 
7851
#-------------------------------------------------------------------------------
7852
# Function        : ListGeneratedProjects
7853
#
7854
# Description     : Return a list of generated/nongenerated projects
7855
#                   Used in conjunction with CreateNameList
7856
#
7857
# Inputs          : $type       - TRUE : Generated
7858
#                                 FALSE: Not Generated
7859
#
7860
# Returns         : A reference to a list of projects
7861
#                   undef will be retuend if there are no projects
7862
#
7863
sub ListGeneratedProjects
7864
{
7865
    my ($type) = @_;
7866
    my @list;
7867
    foreach my $project ( @PROJECTS_ORDER )
7868
    {
7869
        if ( exists($PROJECTS{$project}->{'generated'}) xor $type )
7870
        {
7871
            push @list, $project;
7872
        }
7873
    }
7874
    return @list ? \@list : undef;
7875
}
7876
 
7877
#-------------------------------------------------------------------------------
7878
# Function        : ListCleanGenerated
7879
#
7880
# Description     : return a list of generated targets that have 'clean'
7881
#                   operations. This is used in conjunction with CreateNameList
7882
#
7883
# Inputs          : None
7884
#
7885
# Returns         : A list of project indexes, that can be cleaned
7886
#
7887
sub ListCleanGenerated
7888
{
7889
    my @list;
7890
    foreach my $i ( @GENERATE_FILES )
7891
    {
7892
        push @list, $i->{'index'}
7893
            if ( $i->{'clean'} );
7894
    }
7895
    return \@list;
7896
}
7897
 
251 dpurdie 7898
#-------------------------------------------------------------------------------
7899
# Function        : MakeResolve
7900
#
7901
# Description     : Internal Function
7902
#                   Locate a source file by examining a list of directories
7903
#
7904
#                   Don't use directly
7905
#                   Use MakeSrcResolve or MakeSrcResolveExtended
7906
#
7907
# Inputs          : $dirs           - Ref to an array of directories to scan
7908
#                   $source         - File to locate
7909
#
7910
# Returns         : Resolved path to the file
7911
#                   Will warn if multiple instances of the file are found
7912
#
227 dpurdie 7913
sub MakeResolve
7914
{
7915
    my( $dirs, $source ) = @_;
285 dpurdie 7916
    my( $first, $count );
227 dpurdie 7917
 
237 dpurdie 7918
    #
7919
    #   If the path contains a '$' then its assumed to be
7920
    #   a variable name in the path. Just assume that it exists
7921
    #
7922
    return $source if ( $source =~ m#\$# );
7923
 
7924
    #
7925
    #   If the path is absolute or contains a leading ., then don't search
7926
    #   Warn if it can't be found
7927
    #
7928
    if ( $source =~ m#^(/|\.)# )
7929
    {
7930
        Warning( "Unable to resolve '$source' path" ) unless -f $source;
7931
        return $source;
227 dpurdie 7932
    }
7933
 
237 dpurdie 7934
 
227 dpurdie 7935
#.. search local path first
7936
#
7937
    $count = 0;
7938
    $first = "";
331 dpurdie 7939
    $first = "$source"                              # was ./$source
227 dpurdie 7940
        if (-r "$source");
7941
 
7942
#.. search directory paths
7943
#
285 dpurdie 7944
    foreach my $dir (@$dirs)
227 dpurdie 7945
    {
331 dpurdie 7946
        next if ( $dir eq '.' );
7947
        my $temp = "$dir/$source";                  # was ./$dir/$source
227 dpurdie 7948
        Debug2( "MakeResolve: Looking in: $temp" );
7949
        if (-r "$temp")
7950
        {
7951
            if ($first eq "") {
7952
                $first = $temp;
7953
            } else {
7954
                Warning( "Duplicate '$source' image - '$temp'" );
7955
                $count++;
7956
            }
7957
        }
7958
        Debug3( "MakeResolve: $count, $temp" );
7959
    }
7960
 
7961
    if ($first eq "") {
7962
        $first = $source;
7963
        Warning( "Unable to resolve '$source' path" );
7964
    } else {
7965
        Warning( "          using '$first'" )
7966
            if ($count);
7967
    }
7968
    return $first;
7969
}
7970
 
251 dpurdie 7971
#-------------------------------------------------------------------------------
7972
# Function        : MakeSrcResolve
7973
#
7974
# Description     : Locate a source file by examining the list of source
7975
#                   directories. There are a few frills
7976
#
7977
#                   Look for a source file in
7978
#                       1) %::BUILD_KNOWNFILES
7979
#                       2) %SRCS
7980
#                       3) Dirs specified by the array @SRCSDIRS
7981
#
7982
# Inputs          : Name of a file to resolve
7983
#
7984
# Returns         : Resolved path.
283 dpurdie 7985
#                   Input file - if not found at all
251 dpurdie 7986
#
227 dpurdie 7987
sub MakeSrcResolve
7988
{
7989
    my ($name) = @_;
7990
    my $file;
7991
 
251 dpurdie 7992
    if ( exists ( $::BUILD_KNOWNFILES{$name} ) ) {
7993
        #
7994
        #   The Known Files list is relative to ScmRoot
7995
        #   This must be included in the full path
7996
        #
7997
        $file = $ScmRoot . '/' . $::BUILD_KNOWNFILES{$name};
7998
 
7999
    } elsif ( exists $SRCS{$name} ) {
8000
        $file = $SRCS{$name};
8001
 
8002
    } else {
8003
        $file = MakeResolve( \@SRCDIRS, @_ )
8004
    }
227 dpurdie 8005
    return $file;
8006
}
8007
 
8008
 
8009
# MakeSrcResolveExtended
8010
#   from_global = 0 : Search user specified directories
8011
#               = 1 : Search LinkPkgArchive list
8012
#
8013
our @PkgSrcDirList;
8014
sub MakeSrcResolveExtended
8015
{
8016
    my ( $from_global, $file ) = @_;
8017
 
8018
    #
8019
    #   Simple Case. Resolve source from known source directories
8020
    #
8021
    #
8022
    return MakeSrcResolve( $file )
8023
        unless ( $from_global );
8024
 
8025
    #
8026
    #   Not so simple Case
8027
    #   Resolve the source from the imported packages
8028
    #
8029
    #   Create a list of directores to search, but only the first time
311 dpurdie 8030
    #       - Interface directories - from BuildPkgArchive
227 dpurdie 8031
    #       - LnkPkgArchive directories
8032
    #         Using target,product,platform include directories
8033
    #
8034
    unless ( @PkgSrcDirList )
8035
    {
8036
        for my $entry (@{$::ScmBuildPkgRules{$ScmPlatform} })
8037
        {
311 dpurdie 8038
            next if ( $entry->{'TYPE'} eq 'build' ); # Ignore BuildPkgArchives
8039
 
227 dpurdie 8040
            for (@{$entry->{'PINCDIRS'}}, @{$entry->{'THXDIRS'}}, '' )
8041
            {
8042
                my $dir = $entry->{'ROOT'} . "/" . $_ ;
8043
                $dir =~ s~//~/~g;
8044
                $dir =~ s~/$~~;
311 dpurdie 8045
                push ( @PkgSrcDirList, $dir );
227 dpurdie 8046
            }
8047
        }
311 dpurdie 8048
    }
227 dpurdie 8049
 
8050
    return MakeResolve( \@PkgSrcDirList, $file );
8051
}
8052
 
8053
#-------------------------------------------------------------------------------
8054
# Function        : GetPackageRoot
8055
#
8056
# Description     : Determine the root directory for a given package
8057
#                   This routine is intended for non-standard JATS scripts that
8058
#                   access package contents directly
8059
#
8060
#                   Note: This routine does not attempt to handle multiple
8061
#                         instances of a package ( sysbasetypes ).
8062
#
8063
# Inputs          : $pname          - Name of the package
8064
#
8065
# Returns         :
8066
#
8067
sub GetPackageRoot
8068
{
8069
    my( $pname ) = @_;
8070
    Debug( "GetPackageRoot(@_)" );
8071
 
8072
    my $result = undef;
8073
    my $pkg = GetPackageEntry( $pname );
8074
    if ( $pkg )
8075
    {
8076
        $result = $pkg->{'ROOT'};
8077
        Debug( "GetPackageRoot: $result" );
8078
    }
8079
 
8080
    return $result;
8081
}
8082
 
8083
#-------------------------------------------------------------------------------
8084
# Function        : ActiveProject
8085
#
8086
# Description     : Determine if the specified project is currenly 'active'
8087
#
345 dpurdie 8088
# Inputs          : $project            - one or more project names separated
8089
#                                         by either a comma or a colon
227 dpurdie 8090
#
8091
# Returns         : TRUE    if the project is active
8092
#
8093
sub ActiveProject
8094
{
8095
    my ($project) = @_;
345 dpurdie 8096
    foreach (  split( '\s*[:,]\s*', $project ) )
227 dpurdie 8097
    {
8098
        return 1
8099
            if ( $_ eq $::ScmBuildProject );
8100
    }
8101
    return 0;
8102
}
8103
 
345 dpurdie 8104
#-------------------------------------------------------------------------------
8105
# Function        : ActiveDefine
8106
#
8107
# Description     : Determine if the specified definition is currenly 'active'
8108
#
8109
# Inputs          : $defs               - one or more variable names separated
8110
#                                         by either a comma or a colon
8111
#
8112
# Returns         : TRUE    if any of the definitions are known
8113
#
8114
sub ActiveDefine
8115
{
8116
    my ($defs) = @_;
8117
    no strict 'refs';
8118
    foreach (  split( '\s*[:,]\s*', $defs ) )
8119
    {
8120
        return 1
4455 dpurdie 8121
            if ( defined( $$_ ) || ( @$_ ) );
345 dpurdie 8122
    }
8123
    use strict 'refs';
8124
    return 0;
8125
}
227 dpurdie 8126
 
8127
#-------------------------------------------------------------------------------
345 dpurdie 8128
# Function        : ActiveMachType
8129
#
8130
# Description     : Determine if the specified MachType is currenly 'active'
8131
#
8132
# Inputs          : $mtype              - one or more machine names separated
8133
#                                         by either a comma or a colon
8134
#
8135
# Returns         : TRUE    if any of the current MachType is in the list
8136
#
8137
sub ActiveMachType
8138
{
8139
    my ($mtype) = @_;
8140
    foreach (  split( '\s*[:,]\s*', $mtype ) )
8141
    {
8142
        return 1
8143
            if ( uc($_) eq uc($::GBE_MACHTYPE) );
8144
    }
8145
    return 0;
8146
}
8147
 
8148
#-------------------------------------------------------------------------------
227 dpurdie 8149
# Function        : ActivePlatform
8150
#
8151
# Description     : Determine if the specified platform is currently 'active'
8152
#                   This is used by all user directives in order to determine
8153
#                   if the directive should be ignored for the current platform
8154
#
8155
# Inputs          : $platform_spec      - A platform specifier
8156
#                                         This is a bit complex.
8157
#
241 dpurdie 8158
#                   Format of platform_spec. One or more of
8159
#                       PlatformName
8160
#                       AliasName
8161
#                       TargetName,--Target
345 dpurdie 8162
#                   Special Options (Must all be True)
8163
#                       --Project=ProjectName[:ProjectName]+
8164
#                       --Defined=SomeValue[:SomeValue]+
8165
#                       --MachType=SomeValue[:SomeValue]+
8166
 
8167
#                   Each can be prefixed with a '!' to negate the test
227 dpurdie 8168
#
241 dpurdie 8169
#                   Valid options are:
271 dpurdie 8170
#                       --Target        - indicates that the platform is a 'target'
241 dpurdie 8171
#
8172
# Returns         : TRUE if the platform spec is satisfied
8173
#
227 dpurdie 8174
sub ActivePlatform
8175
{
8176
    my( $platform_spec ) = @_;
8177
    my( @platforms, $scmplatform, $platform );
8178
    my( %arguments, @args, $filter );
241 dpurdie 8179
    my @plist;
8180
    my ($match_count, $count_invert, $count_vert) = (0,0,0);
227 dpurdie 8181
 
241 dpurdie 8182
    #
8183
    #   Short circuit check
8184
    #   '*' is used so often that it pays to check it first
8185
    #
8186
    if ( $platform_spec eq '*' )
8187
    {
8188
        Debug3( " ActivePlatform(@_) = TRUE" );
8189
        return 1;
8190
    }
227 dpurdie 8191
 
241 dpurdie 8192
    #
8193
    #   Platform specifier may be a comma seperated list
8194
    #   ie:  WIN32,MOS,XXX
8195
    #   Extract non-platform arguments
279 dpurdie 8196
    #   Process to yield a dummy platform of '0' or '1' - these will be seen later
241 dpurdie 8197
    #
8198
    foreach ( split( '\s*,\s*', $platform_spec ) )
8199
    {
345 dpurdie 8200
        my ($result, $not);
8201
        if ( m~^(!?)--Project=(.+)~ ) {
325 dpurdie 8202
            $not = $1;
345 dpurdie 8203
            $result = ActiveProject($2);
277 dpurdie 8204
 
345 dpurdie 8205
        } elsif ( m~^(!?)--Defined=(.+)~ ) {
325 dpurdie 8206
            $not = $1;
345 dpurdie 8207
            $result = ActiveDefine($2);
241 dpurdie 8208
 
345 dpurdie 8209
        } elsif ( m~^(!?)--MachType=(.+)~ ) {
325 dpurdie 8210
            $not = $1;
345 dpurdie 8211
            $result = ActiveMachType($2);
8212
 
325 dpurdie 8213
        } else {
8214
            #
8215
            #   Must be a platform argument
8216
            #   Add to a list
8217
            #
8218
            push @platforms, $_;
241 dpurdie 8219
            next;
8220
        }
8221
 
8222
        #
325 dpurdie 8223
        #   Continue processing non-platform arguments
345 dpurdie 8224
        #   Each one must be TRUE, allowing for negation.
241 dpurdie 8225
        #
325 dpurdie 8226
        $result = $result ? 1 : 0;
345 dpurdie 8227
        $result = ! $result if ( $not );
8228
        return 0 unless ( $result );
241 dpurdie 8229
    }
8230
 
4128 dpurdie 8231
    #
8232
    #   If we have no platforms then the test was purely non-platform arguments.
8233
    #   
8234
    #
8235
    if ($platform_spec ne '' && ! @platforms)
8236
    {
8237
        return 1;
8238
    }
8239
 
241 dpurdie 8240
    #   Platform specified may be an Alias
8241
    #   Perform alias expansion
8242
    #
8243
    @platforms = ExpandPlatforms( @platforms );         # aliasing
227 dpurdie 8244
    Debug3( " ActivePlatform(@_)" );
325 dpurdie 8245
#    Debug0( " Platforms(@platforms)", "PLIST(@plist)" );
227 dpurdie 8246
 
8247
#.. Arguments
241 dpurdie 8248
#   At this point we have a list of platforms and arguments
8249
#   Build up a hash of arguments for each platform being parsed
227 dpurdie 8250
#   Multiple arguments can follow a platform name
241 dpurdie 8251
#   Arguments apply to the preceeding platform name
227 dpurdie 8252
#
241 dpurdie 8253
    $platform = undef;
227 dpurdie 8254
    foreach ( @platforms )
8255
    {
241 dpurdie 8256
        if ( /^--Target/ ) {                     # Arguments
8257
            if ( $platform ) {
8258
                $arguments{$platform}{'Target'} = 1;
8259
            } else {
317 dpurdie 8260
                Warning ("No Platform preceding platform option: $_");
241 dpurdie 8261
            }
8262
 
305 dpurdie 8263
        } elsif ( /^--Only(Prod)|(Debug)/ || /--board=/ ) {
273 dpurdie 8264
            # Known arguments
305 dpurdie 8265
            # Bit of a kludge. Must be a better way
273 dpurdie 8266
 
241 dpurdie 8267
        } elsif ( /^--/ ) {
8268
            Warning ("Unknown platform option: $_");
8269
 
227 dpurdie 8270
        } else {                                # Target
8271
            $platform = $_;
241 dpurdie 8272
            push @plist, $platform;
227 dpurdie 8273
        }
8274
    }
8275
 
241 dpurdie 8276
#.. Scan the expression
227 dpurdie 8277
#
8278
    $scmplatform = uc( $ScmPlatform );          # current platform
325 dpurdie 8279
 
241 dpurdie 8280
    foreach ( @plist )
227 dpurdie 8281
    {
8282
        $platform = uc( Trim( $_ ) );           # trim white and convert case
8283
 
8284
        #
241 dpurdie 8285
        #   Determine filter comparison
8286
        #   Either a Platform or a Target
8287
        #
8288
        if ( $arguments{$platform}{'Target'} )
227 dpurdie 8289
        {
241 dpurdie 8290
            $filter = uc( $ScmTarget );
227 dpurdie 8291
        }
241 dpurdie 8292
        else
8293
        {
8294
            $filter = $scmplatform;             # filter specification
8295
        }
8296
 
227 dpurdie 8297
        Debug3( "   Platform=$platform, Filter=$filter" );
8298
 
8299
        #
8300
        #   Examine platform names
8301
        #   Allow negation of name (!), but all the names must be negated
8302
        #   as a mix does not make sense.
8303
        #   ie:     !P1,!P2,!P3     - All except P1,P2 or P3
8304
        #            P1,P2,P2       - Only P1,P2,P3
8305
        #
241 dpurdie 8306
        my $invert = 0;
8307
        if ( substr($platform, 0, 1) eq '!' )
8308
        {
8309
            $count_invert++;
8310
            $platform = substr($platform, 1);
227 dpurdie 8311
        }
8312
        else
241 dpurdie 8313
        {
8314
            $count_vert++;
8315
        }
227 dpurdie 8316
 
241 dpurdie 8317
        $match_count++ if ( $platform eq ''  ||
8318
                            $platform eq '*' ||
8319
                            $platform eq '1' ||
8320
                            $platform eq $filter );
227 dpurdie 8321
    }
8322
 
241 dpurdie 8323
    #
8324
    #   Sanity test
8325
    #   Force failure on bad sanity
8326
    #
8327
    if ( $count_vert && $count_invert )
8328
    {
8329
        Warning( "Platform expression makes no sense. Mixed use of '!' operator",
8330
                 "Expression: @_" );
8331
        return 0;
8332
    }
8333
 
8334
    #
8335
    #   Test for pass
8336
    #   If not using '!', then any match passes : P1 or P2 or P3
8337
    #   If are using '!', then any match is bad : !P1 and !P2 and !P3 == !(P1 or P2 or P3)
8338
    #
8339
    if ( ( $count_vert && $match_count ) || ( $count_invert && ( not $match_count) )   )
8340
    {
227 dpurdie 8341
        Debug3( " ActivePlatform(@_ == $ScmPlatform) = TRUE" );
8342
        return 1;
8343
    }
241 dpurdie 8344
 
227 dpurdie 8345
    Debug3( " ActivePlatform(@_ == $ScmPlatform) = FALSE" );
8346
    return 0;
8347
}
8348
 
8349
#-------------------------------------------------------------------------------
321 dpurdie 8350
# Function        : If
8351
#
8352
# Description     : Function for embedding arguments in directives
8353
#                   To be used within another directive
8354
#                   ie:
8355
#                       AnyDirective ('*',  arg1, arg2, ...
8356
#                                           If (SomePlatform, arg1, .. ,argn))
8357
#
8358
# Inputs          : $platform               - Active Platform speciifier
8359
#                   @args                   - Args
8360
#
8361
# Returns         : @args or nothing
8362
#
8363
sub  If
8364
{
8365
    my $platform = shift;
8366
    return @_
8367
        if ( ActivePlatform( $platform ));
8368
    return;
8369
}
8370
 
8371
#-------------------------------------------------------------------------------
227 dpurdie 8372
# Function        : RegisterMakefileGenerate
8373
#
8374
# Description     : Register a function to be called at the start of the
8375
#                   makefile generation process
8376
#
8377
# Inputs          : $fname      - Name of the function
8378
#                   $args       - Function Arguments
8379
#
8380
# Returns         : Nothing
8381
#
8382
our @MF_Generators;
8383
sub RegisterMakefileGenerate
8384
{
8385
   my ($fref) = @_;
8386
   my $rtype = ref($fref) || 'not a reference';
8387
 
8388
   Error ("RegisterMakefileGenerate called incorrectly",
8389
          "First argument MUST be a code reference",
8390
          "It is a $rtype"
8391
          ) unless ( $rtype eq 'CODE' );
8392
 
8393
   #
8394
   #    Save the arguments by reference in an array
8395
   #    The array will be processed later
8396
   #
8397
   push @MF_Generators, \@_;
8398
}
8399
 
8400
#-------------------------------------------------------------------------------
271 dpurdie 8401
# Function        : RegisterSrcHook
8402
#
8403
# Description     : Register a function to be called when a source file is
8404
#                   declared
8405
#
8406
# Inputs          : $ext        - Extension of interest
8407
#                                 '*' will be used by all
8408
#                   $fname      - Name of the function
8409
#                   $args       - Function Arguments
8410
#
8411
# Returns         : Nothing
8412
#
8413
sub RegisterSrcHook
8414
{
8415
    my $ext = shift;
8416
    my ($fref) = @_;
8417
    my $rtype = ref($fref) || 'not a reference';
8418
 
8419
    Error ("RegisterSrcHook called incorrectly",
8420
           "Second argument MUST be a code reference",
8421
           "It is a $rtype"
8422
           ) unless ( $rtype eq 'CODE' );
8423
 
8424
    #
8425
    #    Save the arguments by reference in an array
8426
    #    The array will be processed later
8427
    #
8428
    push @{$MF_RegisterSrcHooks{$ext}}, \@_;
8429
}
8430
 
8431
 
8432
#-------------------------------------------------------------------------------
227 dpurdie 8433
# Function        : MakefileHeader
8434
#
8435
# Description:    : Generate a "standard" makefile header.
8436
#
8437
#..
8438
 
8439
sub MakefileHeader
8440
{
8441
    my ($file, $desc, $by, @trailing) = @_;
8442
    my ($diff);
8443
 
8444
    $diff = 0 if (($diff = ((80-5) - length($desc))) < 0);
8445
    $desc .= ' ' . ('-' x $diff);
8446
 
8447
    print $file <<EOF;
8448
#-- $desc
8449
#
8450
#                   -- Please do not edit this file. --
8451
#
8452
#       To do so may result in a system failure, in additional to any
8453
#       changes made shall be overwritten.
8454
#
8455
# Created by $by
8456
#         on $::CurrentTime
8457
#
8458
EOF
8459
    #
8460
    #   Print out the trailer
8461
    #   This is an array. Place each entry on a new line
8462
    #
8463
    print $file $_ . "\n" for ( @trailing );
8464
}
8465
 
8466
###############################################################################
8467
# MakeFileGenerate:
8468
#       This subroutine does all of the actual make file generation based
8469
#       on information provided in the calls to the various public
8470
#       interface routines.
8471
#
8472
# Inputs:
8473
#
8474
# Returns:
8475
###############################################################################
8476
 
8477
my $MakefileGenerate_once = 0;
8478
sub MakefileGenerate
8479
{
8480
    my $Makefile = "$ScmPlatform.mk";
8481
    Debug( "MakefileGenerate: $Makefile" );
8482
 
8483
    #
8484
    #   Nasty things happen when we generate a makefile twice
8485
    #   Just warn the user and do nothing
8486
    #   If its in the common makefile.pl then just ignore it
8487
    #
8488
    if ( $ScmProcessingRootMake )
8489
    {
8490
        Warning ("MakefileGenerate directive is not allowed in common makefile.pl");
8491
        return;
8492
    }
8493
 
8494
    if ( $MakefileGenerate_once )
8495
    {
8496
        Warning ("MakefileGenerate should only be called once.",
8497
                 "Dir: $::Cwd");
8498
        return;
8499
    }
8500
    $MakefileGenerate_once = 1;
8501
 
8502
    #
8503
    #   Invoke all registered Makefile Generator functions
8504
    #   These allow clever directives to collect information to be
8505
    #   processed before the makefiles are created
8506
    #
8507
    while ( @MF_Generators )
8508
    {
8509
        Debug( "MakefileGenerate: Invoke RegisterMakefileGenerate function" );
8510
        my ($fname, @args) = @{shift @MF_Generators};
8511
        &$fname ( @args );
8512
    }
8513
 
8514
    #
8515
    #   Allow the toolset the opportunity to process all the collected data
8516
    #   before the makefile is created. This is optional
8517
    #
8518
    my( $if ) = MakeIf::Factory();              # build interface
8519
    $if->Preprocess();
8520
 
8521
    #
343 dpurdie 8522
    #   If we have supressed the Toolset use, then we need to sanity test
8523
    #   the use of the toolset
8524
    #
8525
    if ( $ScmNoToolsTest )
8526
    {
8527
        ReportError ("Building programs not supported with --NoToolset") if ( @PROGS || @TESTPROGS );
8528
        ReportError ("Building libraries not supported with --NoToolset") if ( @LIBS || @MLIBS || @SHLIBS );
8529
        ReportError ("Building projects not supported with --NoToolset") if ( %PROJECTS );
8530
        ErrorDoExit();
8531
    }
8532
 
8533
    #
227 dpurdie 8534
    #   Auto package the 'descpkg' file
8535
    #   If this makefile packages any files, then it can also package the descpkg file
8536
    #   The descpkg will be piggybacked into all makefiles that do a package
8537
    #
8538
    if ( %PACKAGE_FILES || %PACKAGE_HDRS || %PACKAGE_CLSS || %PACKAGE_LIBS
8539
                        || %PACKAGE_SHLIBS || %PACKAGE_PROGS )
8540
    {
251 dpurdie 8541
        Src ('*', 'descpkg') unless ($SRCS{ descpkg });
8542
        PackageFile ('*', 'descpkg');
227 dpurdie 8543
    }
8544
 
8545
    #
8546
    #   Some toolsets NEED a relative root
261 dpurdie 8547
    #   Note: At the moment ScmRoot is relative anyway, thus this code
8548
    #         does nothing
227 dpurdie 8549
    #
8550
    my $gbe_root = $::ScmRoot;
8551
    if ( $::UseRelativeRoot )
8552
    {
8553
        $gbe_root =  RelPath( $::ScmRoot );
8554
    }
8555
 
8556
    #
8557
    #   Now start to create the makefile
8558
    #
3967 dpurdie 8559
    ::ToolsetFile ($Makefile);
285 dpurdie 8560
    open( MAKEFILE, '>', $Makefile ) || Error( "Cannot create $Makefile" );
227 dpurdie 8561
    ::MakefileHeader( *MAKEFILE,
8562
                      'Auto-generated Platform Dependent Makefile',
8563
                      "$ScmMakelib (version $ScmVersion)",
4778 dpurdie 8564
                      "# Copyright (c) VIX TECHNOLOGY (AUST) LTD",
227 dpurdie 8565
                      '#',
8566
                      "# Located in $::Cwd",
8567
                      "# Platform $::ScmPlatform",
8568
                      '#' . ('-' x 79),
8569
                      );
8570
 
8571
    #
8572
    #   Ensure that some essential variables are set
8573
    #
8574
    print MAKEFILE <<EOF;
8575
#
8576
#   Validate essential environment variables
8577
#
8578
ifndef GBE_BIN
8579
    \$(error ERROR: GBE_BIN is not available)
8580
endif
8581
ifndef GBE_PERL
8582
    \$(error ERROR: GBE_PERL is not available)
8583
endif
8584
ifndef DEBUG
8585
    \$(error ERROR: DEBUG is not defined)
8586
endif
8587
EOF
8588
 
8589
 
8590
    print MAKEFILE <<EOF;
8591
 
8592
#
8593
#   Basic definitions
8594
#
343 dpurdie 8595
GBE_ROOT      := $gbe_root
8596
GBE_ROOT_ABS  := \$(abspath \$(GBE_ROOT))
8597
GBE_HOST      := $::ScmHost
8598
GBE_HOSTMACH  := $::GBE_MACHTYPE
8599
GBE_TARGET    := $::ScmTarget
8600
GBE_MACHTYPE  := $::ScmMachType
8601
GBE_PLATFORM  := $::ScmPlatform
8602
GBE_PBASE     := $::Pbase
8603
GBE_TYPE      := \$(if \$(findstring 1,\$(DEBUG)),D,P)
227 dpurdie 8604
EOF
8605
 
343 dpurdie 8606
MakePrint( "GBE_ARGS      := @ScmPlatformArgs\n" )
227 dpurdie 8607
    if ( scalar @ScmPlatformArgs );
8608
 
343 dpurdie 8609
MakePrint( "GBE_PRODUCT   := $ScmProduct\n" )
227 dpurdie 8610
    if ( $ScmProduct ne "" );
8611
 
343 dpurdie 8612
MakePrint( "GBE_OS_COMMON := $::BUILDINFO{$ScmPlatform}{OS_COMMON}\n" )
227 dpurdie 8613
    if ( exists($::BUILDINFO{$ScmPlatform}{OS_COMMON}) );
8614
 
8615
    print MAKEFILE <<EOF;
8616
 
8617
SHELL           := \$(GBE_BIN)/sh
8618
SHELLARGS       :=
8619
EXTENDED_LINE   := \$(GBE_BIN)/extend.lst
8620
export EXTENDED_LINE MAKE
8621
 
343 dpurdie 8622
MFLAGS           := --no-print --warn -r
8623
BUILDNAME        := $::ScmBuildName
8624
BUILDVER         := $::ScmBuildVersionFull
8625
BUILDVERNUM      := $::ScmBuildVersion
227 dpurdie 8626
BUILDPREVIOUSVER := $::ScmBuildPreviousVersion
343 dpurdie 8627
DEPLOYPATCH      := $ScmDeploymentPatch
8628
GBE_NOTOOLSTEST  := $ScmNoToolsTest
4781 dpurdie 8629
MAKEFILEUID      := $ScmMakeUid
8630
export MAKEFILEUID
227 dpurdie 8631
 
8632
#
8633
#   Ensure PWD is correctly set
8634
#
8635
PWD             := \$(CURDIR)
8636
export PWD
8637
 
261 dpurdie 8638
#
8639
#   NODEPEND    - Used to suppress generated dependency file checking
8640
#                 Mostly done in jmake.pl
8641
#   EXPERT      - Used to suppress dependency on this makefile
8642
#
8643
EOF
8644
 
285 dpurdie 8645
MakePrint( "EXPERT\t\t?= " . ($ScmExpert ? '1' : '0' ) . "\n" );
8646
MakePrint( "NODEPEND\t?= 0\n" );
261 dpurdie 8647
 
8648
print MAKEFILE <<EOF;
8649
 
8650
#
8651
#   SCM_MAKEFILE - The name of the file to depend upon
8652
#                  Supressed in EXPERT mode
8653
#
8654
ifneq (\$(EXPERT),0)
8655
SCM_MAKEFILE	:=
8656
else
8657
SCM_MAKEFILE	:= $Makefile
8658
endif
8659
EOF
8660
 
267 dpurdie 8661
#
8662
#   Setup the base directory for the packaging process
8663
#   When building a deployable package the base directory is changed to match
8664
#   that used by the deployment world. This is done so that the descpkg file
8665
#   can be created in the correct location
8666
#
8667
my  $PKGDIR = "pkg/$::Pbase";
8668
    $PKGDIR = "build/deploy" if ( $DEPLOYPACKAGE );
8669
Verbose("Setting PKGDIR: $PKGDIR");
8670
 
261 dpurdie 8671
print MAKEFILE <<EOF;
8672
 
227 dpurdie 8673
#--------- Targets -------------------------------------------------------------
8674
 
8675
.PHONY: 	default all build install package unpackage uninstall \\
8676
		clean unbuild clobber deploy
8677
 
373 dpurdie 8678
default:
227 dpurdie 8679
all:		install package deploy
8680
build:		make_init generate install_hdr depend make_lib \\
8681
		install_lib make_install_shlib make_prog install_class
8682
install:	build install_prog
8683
package:	package_files package_hdr package_lib package_shlib package_prog \\
8684
		package_class
8685
unpackage:	unpackage_class unpackage_prog unpackage_shlib \\
8686
		unpackage_lib unpackage_hdr unpackage_files
8687
uninstall:	uninstall_class uninstall_prog uninstall_shlib \\
8688
		uninstall_lib uninstall_hdr
8689
clean:		make_clean unmake_prog unmake_test unmake_lib unobj \\
261 dpurdie 8690
		undepend ungenerate rmlitter unmake_dir
227 dpurdie 8691
unbuild:	clean uninstall
8692
clobber:	unpackage unbuild
8693
deploy:		install run_deploy
8694
 
8695
#--------- Macros --------------------------------------------------------------
8696
 
8697
OBJDIR		= \$(GBE_PLATFORM)\$(GBE_TYPE).OBJ
8698
LIBDIR		= \$(GBE_PLATFORM).LIB
8699
BINDIR		= \$(GBE_PLATFORM)\$(GBE_TYPE).BIN
8700
CLSDIR		= classes\$(GBE_TYPE)
8701
 
267 dpurdie 8702
PKGDIR		= \$(GBE_ROOT)/$PKGDIR
227 dpurdie 8703
INCDIR_PKG	= \$(PKGDIR)/include
8704
LIBDIR_PKG	= \$(PKGDIR)/lib
8705
BINDIR_PKG	= \$(PKGDIR)/bin
8706
CLSDIR_PKG	= \$(PKGDIR)/classes
4996 dpurdie 8707
UTFDIR_PKG	= \$(GBE_ROOT_ABS)/$PKGDIR/utfResults
227 dpurdie 8708
 
8709
LOCALDIR	= \$(GBE_ROOT)/local
8710
INCDIR_LOCAL	= \$(LOCALDIR)/inc
8711
LIBDIR_LOCAL	= \$(LOCALDIR)/lib
8712
BINDIR_LOCAL	= \$(LOCALDIR)/bin
8713
CLSDIR_LOCAL	= \$(LOCALDIR)/classes
8714
BINDIR_LOCAL_PATH = \$(GBE_ROOT_ABS)/local/bin/\$(GBE_PLATFORM)\$(GBE_TYPE)
8715
 
8716
INTERFACEDIR	= \$(GBE_ROOT)/$ScmInterface
8717
INCDIR_INTERFACE= \$(INTERFACEDIR)/include
8718
LIBDIR_INTERFACE= \$(INTERFACEDIR)/lib
8719
BINDIR_INTERFACE= \$(INTERFACEDIR)/bin
8720
CLSDIR_INTERFACE= \$(INTERFACEDIR)/classes
8721
 
8722
.SUFFIXES:		# Delete the default suffixes
8723
 
8724
EOF
8725
 
8726
    MakePrintList( \@DEFINES );
8727
    MakeNewLine();
8728
 
8729
#-------------------------------------------------------------------------------
8730
#
8731
#
261 dpurdie 8732
    MakeHeader ("Defines, flags and file sets");
227 dpurdie 8733
 
8734
    # Flags
261 dpurdie 8735
    foreach my $opt ( keys %ScmCompilerOpts )
8736
    {
8737
        MakeDefEntry ( $opt, "=", $ScmCompilerOpts{$opt} );
8738
    }
227 dpurdie 8739
 
261 dpurdie 8740
    MakeDefEntry( "CFLAGS",         "=", \@CFLAGS, \@CFLAGS_PROD, \@CFLAGS_DEBUG );
8741
    MakeDefEntry( "CLINTFLAGS",     "=", \@CLINTFLAGS, \@CLINTFLAGS_PROD, \@CLINTFLAGS_DEBUG );
8742
    MakeDefEntry( "CDEPENDFLAGS",   "=", \@CFLAGS, \@CFLAGS_PROD, \@CFLAGS_DEBUG );
8743
    MakeDefEntry( "CXXFLAGS",       "=", \@CXXFLAGS, \@CXXFLAGS_PROD, \@CXXFLAGS_DEBUG );
8744
    MakeDefEntry( "CXXLINTFLAGS",   "=", \@CXXLINTFLAGS, \@CXXLINTFLAGS_PROD, \@CXXLINTFLAGS_DEBUG );
8745
    MakeDefEntry( "CXXDEPENDFLAG",  "=", \@CXXFLAGS, \@CXXFLAGS_PROD, \@CXXFLAGS_DEBUG );
267 dpurdie 8746
    MakeDefEntry( "ASFLAGS",        "=", \@ASFLAGS, \@ASFLAGS_PROD, \@ASFLAGS_DEBUG );
8747
    MakeDefEntry( "LDFLAGS",        "=", \@LDFLAGS, \@LDFLAGS_PROD, \@LDFLAGS_DEBUG );
227 dpurdie 8748
 
8749
 
8750
#-------------------------------------------------------------------------------
8751
#   
8752
#
261 dpurdie 8753
    MakeHeader ("Tool Search Path",
8754
                "Extend the PATH seen by all the tools to include",
8755
                "The tools/bin directories discovered in Packages" );
8756
    my $put_PATH;
8757
    my $put_LD_LIBRARY_PATH;
8758
    for my $path ( ToolExtensionPaths() )
8759
    {
8760
        MakePrint( "PATH := $path$::ScmPathSep\$(PATH)\n" );
8761
        $put_PATH = 1;
227 dpurdie 8762
 
261 dpurdie 8763
        if ( $::ScmHost eq "Unix" )
8764
        {
227 dpurdie 8765
        MakePrint( "LD_LIBRARY_PATH ?= \n" );
8766
        MakePrint( "LD_LIBRARY_PATH := $path$::ScmPathSep\$(LD_LIBRARY_PATH)\n" );
261 dpurdie 8767
            $put_LD_LIBRARY_PATH =1;
8768
        }
227 dpurdie 8769
    }
8770
 
261 dpurdie 8771
    #   Export the appropriate environment variables
8772
    #   Note: Windows has an issue with PATH and Path
8773
    #         Haven't got to the bottom of it yet, but it would appear that DLL
8774
    #         searching uses Path and other stuff uses PATH. Not too sure how we
8775
    #         end up with two (or more in the environment)
8776
    #
8777
    #
8778
    if ( $put_LD_LIBRARY_PATH )
8779
    {
343 dpurdie 8780
        MakePrint( "export LD_LIBRARY_PATH\n" );
261 dpurdie 8781
    }
227 dpurdie 8782
 
261 dpurdie 8783
    if ( $put_PATH )
8784
    {
343 dpurdie 8785
        MakePrint( "Path := \$(PATH)\n" );
8786
        MakePrint( "export PATH Path\n" );
261 dpurdie 8787
    }
227 dpurdie 8788
 
8789
#-------------------------------------------------------------------------------
8790
#   
8791
#
261 dpurdie 8792
    MakeHeader ("Perl Module Search Path",
8793
                "Extend the PERL5LIB seen by invocations of perl");
227 dpurdie 8794
 
261 dpurdie 8795
    my $perl_module_found;
8796
    for my $path ( ToolExtensionPaths() )
227 dpurdie 8797
    {
261 dpurdie 8798
        if (glob( "$path/*.pm"))
8799
        {
227 dpurdie 8800
        MakePrint( "PERL5LIB := $path$::ScmPathSep\$(PERL5LIB)\n" );
261 dpurdie 8801
            $perl_module_found = 1;
8802
        }
227 dpurdie 8803
    }
261 dpurdie 8804
    if ( $perl_module_found  )
8805
    {
227 dpurdie 8806
    MakePrint( "export PERL5LIB\n" );
261 dpurdie 8807
    }
227 dpurdie 8808
 
261 dpurdie 8809
#-------------------------------------------------------------------------------
8810
#   Internal Helper Functions
8811
#   Creating INCLUDE and LIBRARY paths
8812
#
8813
 
8814
# Assist in creating a list paths
8815
#   $pList  - Reference to an array to which $data will be added
8816
#   $pSeen  - Hash Ref to track tags that have been seen
8817
#   $data   - Data item to add, if tag is defined, but not seen
8818
#   $tag    - Resolved name for item
8819
#
227 dpurdie 8820
    sub PushPath
8821
    {
8822
        my ($pList, $pSeen, $data, $tag) = @_;
8823
        if ( $tag )
8824
        {
8825
            unless ( exists $pSeen->{$tag} )
8826
            {
8827
                $pSeen->{$tag} = 1;
8828
                push @{$pList}, $data;
8829
            }
8830
        }
8831
    }
8832
 
8833
    #
8834
    # Search paths for include files and libraries
8835
    # Currently symbolic paths are created, but there is very little need for this
8836
    #
8837
    sub MakePaths
8838
    {
8839
        my( $root ) = @_;
8840
        my @pathlist;
8841
        my %seen;
8842
 
8843
        #
379 dpurdie 8844
        #   Interface and Local directories are now treated quite
8845
        #   diffently. The Local is under our control.
227 dpurdie 8846
        #
8847
        if ( $root =~ /INTERFACE/ ) {
379 dpurdie 8848
 
8849
            #   eg. SCA_WIN32   and SCA_WIN32       and SCA_SOLARIS
8850
            #       SCA             WIN32_i386          SPARC
8851
            #       WIN32           SCA                 SCA
8852
            #       .               WIN32               SOLARIS
8853
            #                       .                   .
8854
            #..
8855
 
8856
            #
8857
            #   For Interface Path List use the 'PARTS' as calculated within
8858
            #   the build file. Its good enough for everthing else in JATS
8859
            #
8860
            foreach ( @{$::BUILDINFO{$ScmPlatform}{PARTS}} ) {
227 dpurdie 8861
                PushPath( \@pathlist, \%seen, "$root/$_",   $_ );
8862
            }
8863
        }
379 dpurdie 8864
        else
8865
        {
8866
            #
8867
            #   Local directory
8868
            #   The user can (should) only install stuff into a few known
8869
            #   locations.
8870
            #
8871
            foreach ( $ScmPlatform, $ScmProduct, $ScmTarget ) {
8872
                PushPath( \@pathlist, \%seen, "$root/$_",   $_ );
8873
            }
8874
        }
227 dpurdie 8875
 
379 dpurdie 8876
        #
8877
        #   Add OS Common Directory
8878
        ### May need more testing before being added
8879
        #
8880
        #if ( exists($::BUILDINFO{$ScmPlatform}{OS_COMMON}) )
8881
        #{
8882
        #    my $os_common = $::BUILDINFO{$ScmPlatform}{OS_COMMON};
8883
        #    PushPath( \@pathlist, \%seen, "$root/$os_common", $os_common );
8884
        #}
227 dpurdie 8885
 
379 dpurdie 8886
        #
8887
        #   Add the root directory too
8888
        #
227 dpurdie 8889
        push @pathlist, "$root";
8890
        return \@pathlist;
8891
    }
379 dpurdie 8892
 
227 dpurdie 8893
 
8894
#-------------------------------------------------------------------------------
8895
#   
8896
#
261 dpurdie 8897
    MakeHeader ("Include Search Paths",
367 dpurdie 8898
                "Package Include Paths for header files and libraries" );
227 dpurdie 8899
 
367 dpurdie 8900
    MakeDefEntry( 'PINCDIRS', '=', '# includes');
8901
    MakeDefEntry( 'PLIBDIRS', '=', '# libraries');
8902
 
8903
    for my $package (@{$::ScmBuildPkgRules{$ScmPlatform} })
8904
    {
8905
        #
8906
        #   Skip the pseudo package that encapsulates the interface
8907
        #   directory. Currently the makefiles do this in a different
8908
        #   manner - to be resolved
8909
        #
8910
        #   Just comment out the lines so that the data is visible
8911
        #   Its a hint to make use of the data
8912
        #
8913
        my $prefix = '';
8914
        $prefix = '# ' if ( $package->{'TYPE'} eq 'interface' );
8915
        $prefix = '# ' if ( $package->{'TYPE'} eq 'build' );
8916
 
8917
 
8918
        my $name = $package->{'NAME'} . '/' . $package->{'VERSION'};
8919
        my $base = $package->{'ROOT'};
8920
 
1329 dpurdie 8921
        my @doc;
8922
        push (@doc, "From: $base");
8923
        push (@doc, 'BuildPkgArchive via Interface' )if $package->{'TYPE'} eq 'build' ;
8924
        push (@doc, 'Is Interface' ) if $package->{'TYPE'} eq 'interface' ;
367 dpurdie 8925
 
1329 dpurdie 8926
        MakeHeader ("Source: $name", @doc);
8927
 
367 dpurdie 8928
        #
8929
        #   List include and library directories
8930
        #   Note: Need the True Path for windows.
8931
        #       Some makefile functions (wildcard) only work as expected
8932
        #       if the case of the pathname is correct. Really only a problem
8933
        #       with badly formed legecy packages where the Windows user
8934
        #       guessed at the package format.
8935
        #
8936
        #       The conversion to a TruePath is done when ScmBuildPkgRules
8937
        #       is created. Create one, use many time.
8938
        #
8939
        #
8940
        for my $type (qw (PINCDIRS PLIBDIRS) )
8941
        {
8942
            for my $path ( @{$package->{$type}} )
8943
            {
8944
                MakeDefEntry ( "$prefix$type", "+=", $base . $path);
8945
            }
8946
        }
8947
    }
8948
 
8949
#-------------------------------------------------------------------------------
8950
#   
8951
#
8952
    MakeHeader ("Include Search Paths",
8953
                "Local Include Paths",
8954
                " LINKDIRS - Local include search path (short)",
8955
                " INCDIRS  - Include search path (complete)",
8956
                " NODEPDIRS - ",
8957
                " SRCDIRS - ",
8958
                " LIBDIRS - Library search path",
8959
 
8960
                );
8961
 
227 dpurdie 8962
    # Include search path
8963
    #
8964
    #   user-local
367 dpurdie 8965
    #   local
8966
    #   interface
8967
    #       BuildPkgArchive
8968
    #       LinkPkgArchive
227 dpurdie 8969
    #   user-global
8970
    #
8971
 
367 dpurdie 8972
    MakeDefEntry ( "\nLINCDIRS",    "= ", \@L_INCDIRS );     # .. Local
261 dpurdie 8973
    MakeDefEntry ( "LINCDIRS",      "+=", MakePaths( '$(INCDIR_LOCAL)' ));     # .. Sandbox interface
8974
    MakeDefEntry ( "LINCDIRS",      "+=", MakePaths( '$(INCDIR_INTERFACE)' )); # .. Sandbox interface
8975
    MakeDefEntry ( "LINCDIRS",      "+=", \@G_INCDIRS );    # .. Global
227 dpurdie 8976
 
367 dpurdie 8977
    MakeDefEntry ( "INCDIRS",  "= ", '$(LINCDIRS)' );               # Local
8978
    MakeDefEntry ( "INCDIRS",  "+=", '$(PINCDIRS)' );               # Package
8979
    MakeDefEntry ( "LINCDIRS", "+=", \@S_INCDIRS );                 # System
227 dpurdie 8980
 
8981
    # Source search path
8982
 
261 dpurdie 8983
    MakeDefEntry( "\nNODEPDIRS",        "=", \@NODEPDIRS );
227 dpurdie 8984
 
367 dpurdie 8985
    MakeDefEntry( "\nSRCDIRS","= "  , [ @L_SRCDIRS, @G_SRCDIRS ] ); # Local
8986
    MakeDefEntry ( "SRCDIRS", "+=" , '$(PINCDIRS)' );               # Package
8987
    MakeDefEntry ( "SRCDIRS", "+=" , \@S_INCDIRS );                 # System
227 dpurdie 8988
 
8989
    # Library search path
8990
    #
8991
    #   user-local
367 dpurdie 8992
    #   local
8993
    #   interface
8994
    #       BuildPkgArchive
8995
    #       LinkPkgArchive
227 dpurdie 8996
    #   user-global
8997
 
367 dpurdie 8998
    MakeDefEntry( "\nLIBDIRS",  "= ", '$(LIBDIR)' );                    # User Local
261 dpurdie 8999
    MakeDefEntry( "LIBDIRS",    "+=", \@L_LIBDIRS );                    # Local
9000
    MakeDefEntry( "LIBDIRS",    "+=", MakePaths( '$(LIBDIR_LOCAL)' ));  # Sandbox/interface
9001
    MakeDefEntry( "LIBDIRS",    "+=", MakePaths( '$(LIBDIR_INTERFACE)' ));
9002
    MakeDefEntry( "LIBDIRS",    "+=", \@G_LIBDIRS );                    # Global
367 dpurdie 9003
    MakeDefEntry( "LIBDIRS",    "+=", '$(PLIBDIRS)' );                  # Package
261 dpurdie 9004
    MakeDefEntry( "LIBDIRS",    "+=", \@S_LIBDIRS );                    # System
227 dpurdie 9005
 
9006
#-------------------------------------------------------------------------------
9007
#
9008
#   Subdir creation and deletion
9009
#   Creation is done on the fly
9010
#   Deletion is done AFTER the toolset functions have been invoked to create the
9011
#   build artifacts so that the toolsets can create directories too
9012
 
9013
    MakeHeader ("Subdir creation");
9014
    CreateMkdirRules();
2429 dpurdie 9015
    MkdirRule( '$(OBJDIR)', 'OBJDIR', '--Extra=depend,depend.err' );  # Object build directory
9016
    MkdirRule( '$(OBJDIR)/'.$_ ) foreach (@SHLIBS);                     # Shared library build directory
9017
    MkdirRule( '$(LIBDIR)', 'LIBDIR' );                                 # Library directory
9018
    MkdirRule( '$(BINDIR)', 'BINDIR' );                                 # Binary directory
227 dpurdie 9019
 
261 dpurdie 9020
    #
9021
    #   Create a directory for library merge tool to work within
9022
    #
9023
    MkdirRule( "\$(MLIBDIR)", 'MLIBDIR', '--Path=$(GBE_PLATFORM).MRG', '--RemoveAll' ) if (@MLIBS);
9024
 
227 dpurdie 9025
#-------------------------------------------------------------------------------
9026
#   Generate rules and recipes to create all the toolset specific parts
9027
#   This is done fairly early to allow the toolsets to extend various
9028
#   definitions that may be used later in the makefile construction
9029
#
9030
    MakeHeader ("Construct Programs");
9031
 
9032
    foreach my $i ( @PROGS )
9033
    {
289 dpurdie 9034
        my $pProg = $PROGS->Get($i);
9035
        my $pArgs = $pProg->getItems('ARGS');
9036
        my $pObjs = $pProg->getItems('OBJS');
9037
        my $pLibs = $pProg->getItems('LIBS');
227 dpurdie 9038
 
289 dpurdie 9039
        #
9040
        #   Create a list of program object files
9041
        #
9042
        push @PROGOBJS, @$pObjs;
227 dpurdie 9043
 
9044
        MakePrint( "#---- (${i})\n\n" );
9045
        if ( $ScmToolsetProgDependancies )
9046
        {
261 dpurdie 9047
            #
9048
            #   Original style Prog Interface
271 dpurdie 9049
            #   Write some dependency information here and some in the toolset
9050
            #   Problems:
9051
            #       1) Errors in library dependency generation will be
9052
            #          reported after all the object files have been created
9053
            #          Thus the error message and the make-stop are seperated
9054
            #          by many,many lines of output. This makes it difficult
9055
            #          to see the error.
261 dpurdie 9056
            #
271 dpurdie 9057
            #       2) Lack of Flexability
9058
            #
293 dpurdie 9059
            MakeEntry( "\$(BINDIR)/$i$::exe: ", "", "\\\n\t\t", ".$::o ", @$pObjs );
227 dpurdie 9060
        }
9061
        else
9062
        {
261 dpurdie 9063
            #
9064
            #   New Style Prog Interface
9065
            #   The toolset does it all
9066
            #
9067
            #   Flag the progam packaging as a placeholder.
9068
            #   The toolset will replace/update it.
9069
            #
227 dpurdie 9070
            PackageProgRemoveFiles( $i );
9071
        }
9072
 
289 dpurdie 9073
        $if->LD    ( $i, $pArgs, $pObjs, $pLibs );
9074
        $if->LDLINT( $i, $pArgs, $pObjs, $pLibs );
227 dpurdie 9075
    }
9076
 
9077
#-------------------------------------------------------------------------------
9078
#   
9079
#
9080
    MakeHeader ("Construct Test Programs");
289 dpurdie 9081
    foreach my $i ( @TESTPROGS )
227 dpurdie 9082
    {
289 dpurdie 9083
        my $pProg = $TESTPROGS->Get($i);
9084
        my $pArgs = $pProg->getItems('ARGS');
9085
        my $pObjs = $pProg->getItems('OBJS');
9086
        my $pLibs = $pProg->getItems('LIBS');
227 dpurdie 9087
 
289 dpurdie 9088
        #
9089
        #   Create a list of program object files
9090
        #
9091
        push @TESTPROGOBJS, @$pObjs;
9092
 
227 dpurdie 9093
        MakePrint( "#---- (${i})\n\n" );
9094
        if ( $ScmToolsetProgDependancies )
9095
        {
293 dpurdie 9096
            MakeEntry( "\$(BINDIR)/$i$::exe: ", "", "\\\n\t\t", ".$::o ", @$pObjs );
227 dpurdie 9097
        }
9098
        else
9099
        {
9100
            PackageProgRemoveFiles( $i );
9101
        }
9102
 
289 dpurdie 9103
        $if->LD    ( $i, $pArgs, $pObjs, $pLibs );
9104
        $if->LDLINT( $i, $pArgs, $pObjs, $pLibs );
227 dpurdie 9105
    }
9106
 
9107
#-------------------------------------------------------------------------------
9108
#
9109
#
9110
    MakeHeader ("Transfer Scripts to BINDIR");
9111
    foreach my $i ( sort ( values %SCRIPTS ))
9112
    {
9113
        my $tname = "\$(BINDIR)/" . StripDir( $i );
9114
 
9115
 
9116
        MakePrint( "$i:\t\tmakefile.pl\n" .
261 dpurdie 9117
            "\t\$(XX_PRE)if [ ! -f \"$i\" ]; then echo Script [$i] not found; exit 2; fi\n\n" );
227 dpurdie 9118
 
9119
        #
9120
        #   Create a rule to copy the script into the BIN directory
9121
        #   Mark the script as executable - It can't hurt and its there
9122
        #   to be run as part of a test.
9123
        #
9124
        MakePrint "$tname:\t\$(GBE_BINDIR) $i\n" .
9125
                  "\t\$(XX_PRE)\$(cp) -f $i $tname\n" .
9126
                  "\t\$(XX_PRE)\$(chmod) -f +wx $tname\n\n"
9127
    }
9128
 
9129
#-------------------------------------------------------------------------------
9130
#   
9131
#
9132
    MakeHeader ("Construct Libraries");
9133
    foreach my $i ( @LIBS )
9134
    {
289 dpurdie 9135
        my $pLib  = $LIBS->Get($i);
9136
        my $pArgs = $pLib->getItems('ARGS');
9137
        my $pObjs = $pLib->getItems('OBJS');
227 dpurdie 9138
 
363 dpurdie 9139
        unless ( $ScmToolsetNillLibSrc )
9140
        {
9141
            Error ("Library has no component objects: $i")
9142
                if ( scalar @$pObjs <= 0 );
9143
        }
299 dpurdie 9144
 
227 dpurdie 9145
        MakePrint "#---- (${i})\n\n";
289 dpurdie 9146
        $if->AR(     $i, $pArgs, $pObjs, $pLib);
9147
        $if->ARLINT( $i, $pArgs, $pObjs, $pLib );
227 dpurdie 9148
    }
9149
 
289 dpurdie 9150
#-------------------------------------------------------------------------------
9151
#   
9152
#
9153
    MakeHeader ("Construct Merged Libraries");
227 dpurdie 9154
    sub MlibEntry
9155
    {
289 dpurdie 9156
        my( $mlib, $plib, $pLibs ) = @_;
227 dpurdie 9157
        my @flib;
9158
 
289 dpurdie 9159
        MakePrint '$(LIBDIR)/' . GenLibName($mlib) . ":";
9160
        foreach my $lib ( @$pLibs )
227 dpurdie 9161
        {
289 dpurdie 9162
            #
9163
            #   Each library name may contains one embedded option which
9164
            #   specifies the source directory
9165
            #       libname[,--Option | BaseSubdir]
9166
            #
227 dpurdie 9167
            my ($slib, $sdir) = split( ',', $lib );
343 dpurdie 9168
            my $mode;
227 dpurdie 9169
 
9170
            #
283 dpurdie 9171
            #   By default the librares are pulled from LOCAL unless the
9172
            #   library is built in this directory, in which case it will
289 dpurdie 9173
            #   be used.
227 dpurdie 9174
            #
289 dpurdie 9175
            $sdir = ( $LIBS->Get($slib) ) ? '--Here' : '--Local'
9176
                unless ( $sdir );
227 dpurdie 9177
 
9178
            #
9179
            #   --Interface     - Pull library from the interface directory
9180
            #   --Local         - Pull library from the local directory
9181
            #   --SubDir=xxxx   - Pull library from specified subdirectory
283 dpurdie 9182
            #   --Here          - Pull from local directory if built locally
227 dpurdie 9183
            #   otherwise       - Pull library from specified subdirectory
9184
            #
9185
            if ($sdir eq '--Interface') {
9186
                $sdir = '$(LIBDIR_INTERFACE)/$(GBE_PLATFORM)';
9187
 
343 dpurdie 9188
 
9189
            } elsif ($sdir eq '--InterfacePlain') {
9190
                $sdir = '$(LIBDIR_INTERFACE)/$(GBE_PLATFORM)';
9191
                $mode = 1;
9192
 
227 dpurdie 9193
            } elsif ( $sdir eq '--Local') {
9194
                $sdir = $PackageInfo{'Lib'}{'IBase'} .  # Base of Installed libs
9195
                        $PackageInfo{'Lib'}{'Dir'};     # Default subdir
9196
 
9197
            } elsif ( $sdir =~ m~^--SubDir=(.*)~ ) {
9198
                $sdir = $1 . '/$(LIBDIR)';
9199
 
283 dpurdie 9200
            } elsif ( $sdir eq '--Here') {
9201
                $sdir = '$(LIBDIR)';
9202
 
227 dpurdie 9203
            } else {
9204
                $sdir .= '/$(LIBDIR)';
9205
            }
9206
 
343 dpurdie 9207
            MakePrint " \\\n\t\t${sdir}/" . GenLibName($slib, $mode);
227 dpurdie 9208
            push @flib, "${sdir}/${slib}";
9209
        }
289 dpurdie 9210
        return \@flib;
227 dpurdie 9211
    }
9212
 
9213
    foreach my $i ( @MLIBS )
9214
    {
289 dpurdie 9215
        my $pLib  = $MLIBS->Get($i);
9216
        my $pArgs = $pLib->getItems('ARGS');
9217
        my $pLibs = $pLib->getItems('LIBS');
227 dpurdie 9218
 
261 dpurdie 9219
        MakePrint "#---- (${i})\n\n";
9220
 
227 dpurdie 9221
        unless ( defined &ToolsetARMerge )
9222
        {
9223
            Warning( "Merging of libraries not supported in this toolset yet" );
9224
            Warning( "MergeLibrary: \"$i\" will not be created" );
9225
        }
9226
        else
9227
        {
9228
            #
9229
            #   Create the dependency rule
9230
            #       Target library : source library list
9231
            #           Recipe - generated by the toolset
9232
            #
289 dpurdie 9233
            foreach ( @$pArgs )
227 dpurdie 9234
            {
9235
                Warning( "Ignoring unknown argument to MergeLibrary. $_" );
9236
            }
289 dpurdie 9237
            $pLibs = MlibEntry( $i, $pLib, $pLibs );
9238
            $if->ARMerge( $i, $pArgs, $pLibs, $pLib );
227 dpurdie 9239
        }
9240
    }
9241
 
289 dpurdie 9242
#-------------------------------------------------------------------------------
9243
#   
9244
#
9245
    MakeHeader ("Construct Shared Libraries");
339 dpurdie 9246
 
227 dpurdie 9247
    foreach my $i ( @SHLIBS )
9248
    {
289 dpurdie 9249
        my $pShlib  = $SHLIBS->Get($i);
9250
        my $pArgs = $pShlib->getItems('ARGS');
9251
        my $pObjs = $pShlib->getItems('OBJS');
9252
        my $pLibs = $pShlib->getItems('LIBS');
9253
        my $version = $pShlib->{VERSION};
227 dpurdie 9254
 
289 dpurdie 9255
        $if->SHLD    ( $i, $pArgs, $pObjs, $pLibs, $version );
9256
        $if->SHLDLINT( $i, $pArgs, $pObjs, $pLibs, $version );
227 dpurdie 9257
    }
9258
 
9259
#-------------------------------------------------------------------------------
9260
#   Construct Objects
9261
#   For each object within OBJSOURCE construct the following:
9262
#
9263
#   $(OBJDIR)/object-name:     source-name [makefile]
9264
#       Toolset ...
9265
#
9266
#   
9267
#
9268
    MakeHeader ("Construct Objects");
371 dpurdie 9269
 
227 dpurdie 9270
    foreach my $i ( sort keys %OBJSOURCE )
9271
    {
9272
        my( $src, $sname, $ext, $type, @args );
9273
 
9274
        $src  = $OBJSOURCE{ $i };
9275
        $sname = StripDir( $src );
9276
        $ext  = StripFile( $src );
9277
        $ext = lc($ext)
9278
            if ( $::ScmHost ne "Unix" );
381 dpurdie 9279
        $type = ($ScmSourceTypes{ $ext } || '')
227 dpurdie 9280
            unless (( $type = $SRC_TYPE{ $sname }) );
9281
 
9282
        #
9283
        #   Object source is an object file
9284
        #   No need the generate the object, just create makefile rule
261 dpurdie 9285
        #   [ddp] Not too sure how we get here
227 dpurdie 9286
        #
9287
        if ( $ext eq ".$::o" )
9288
        {
9289
            MakePrint "$src:";
261 dpurdie 9290
            MakePrint " \$(SCM_MAKEFILE)";
227 dpurdie 9291
            MakeNewLine();
9292
            next;
9293
        }
9294
 
9295
        #
9296
        #   Need to create object file
9297
        #
9298
        @args = split( /$;/, $SRC_ARGS{ StripDir( $sname ) } )
9299
            if $SRC_ARGS{ $sname };
9300
 
9301
        push( @args, "--Shared" )
9302
            if ( exists $SHOBJ_LIB{$i} );
9303
 
9304
        #
9305
        #   Convert relative paths to absolute paths if required by the
9306
        #   toolset. Some compilers need ABS paths to generate nice debug
9307
        #   information.
9308
        #
9309
        $src = AbsPath($src)
9310
            if ( $UseAbsObjects );
9311
 
9312
        #
9313
        #   Extract any user specified dependancies
261 dpurdie 9314
        #   These will be added to the dependency list
227 dpurdie 9315
        #
9316
        my @dlist;
9317
        @dlist = split( /$;/, $SRC_DEPEND{$sname} )
9318
            if ( exists $SRC_DEPEND{$sname} );
9319
 
261 dpurdie 9320
        #
9321
        #   Create the dependency part of the object rule
9322
        #   The source file MUST be the first dependent recipes
9323
        #   may assume that $< is the name source file
9324
        #
9325
        MakeEntry( "\$(OBJDIR)/$i.$::o: $src \$(SCM_MAKEFILE)", "", " \\\n\t", "", @dlist );
227 dpurdie 9326
 
9327
        if ( $type eq ".c" ) {
9328
            $if->CC(  $src, $i, \@args );
261 dpurdie 9329
 
227 dpurdie 9330
        } elsif ( $type eq ".cc" ) {
9331
            $if->CXX( $src, $i, \@args );
261 dpurdie 9332
 
227 dpurdie 9333
        } elsif ( $type eq ".asm" ) {
9334
            $if->AS( $src, $i, \@args );
261 dpurdie 9335
 
227 dpurdie 9336
        } else {
9337
            $if->EXT( $src, $i, \@args ) ||
9338
                Warning( "Don't know how to build '$ext' images' for $src, $i" );
9339
            MakeNewLine();
9340
        }
9341
    }
9342
 
9343
#-------------------------------------------------------------------------------
9344
#   Construct Projects
9345
#   Construct toolset specific projects
9346
#
9347
    MakeHeader ("Construct Projects");
9348
    while ( my($project, $entry) = each %PROJECTS)
9349
    {
9350
        $if->PROJECT( $entry );
9351
    }
9352
 
9353
#-------------------------------------------------------------------------------
4761 dpurdie 9354
#   Automated tests
9355
#
9356
    MakeHeader ("Automated tests");
9357
 
9358
    my $idx = 0;
9359
    my @copy_set = ();
9360
 
227 dpurdie 9361
    foreach my $pEntry ( @TESTS_TO_RUN )
9362
    {                                           # Foreach test
9363
        $idx++;
9364
        $pEntry->{'index'} = $idx;
9365
        $pEntry->{'test_name'} = "run_test_$idx";
5708 dpurdie 9366
        $pEntry->{'echoname'} = $pEntry->{'utfname'} || '';  
4781 dpurdie 9367
        $pEntry->{'utfname'} = $pEntry->{'test_name'} unless defined $pEntry->{'utfname'};  
227 dpurdie 9368
 
9369
        #
9370
        #   If the test is being run within a 'FrameWork' then the underlying
9371
        #   toolset must instantiate the frame work.
9372
        #
9373
        #   This may change. Perhaps frameworks shouldn't be a part of the
9374
        #   toolset. Perhaps they should be standalone. May change
9375
        #
9376
        if ( $pEntry->{framework} )
9377
        {
9378
            $if->TESTFRAMEWORK( $pEntry );
9379
        }
9380
 
9381
        #
9382
        #   Create a rule to run the test
9383
        #
9384
 
9385
        my $tdir_alias = $pEntry->{'testdir'};
9386
        my $tdir = '$(' . $tdir_alias . ')';
9387
 
9388
        my $test_name = $pEntry->{'test_name'};
4996 dpurdie 9389
        push @TESTPROJECT_TO_URUN, $test_name;
4501 dpurdie 9390
        push @TESTPROJECT_TO_ARUN, $test_name if     ($pEntry->{'auto'} );
227 dpurdie 9391
 
9392
        my $tprog = $tdir . '/' . StripDir( $pEntry->{'prog'} );
5695 dpurdie 9393
 
9394
        #
9395
        #   Determine the maximum time that the automated test should run
9396
        #       Default is 30 minutes
9397
        #   Non-auto tests are not time limited
9398
        #       
9399
        my $timeout = '';
5848 dpurdie 9400
        if ($pEntry->{'auto'})
5695 dpurdie 9401
        {
5848 dpurdie 9402
            $timeout = 'timeout -Time:' . ($pEntry->{'maxtime'} || '30m') . ' ';
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