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