Subversion Repositories DevTools

Rev

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