Subversion Repositories DevTools

Rev

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

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