Subversion Repositories DevTools

Rev

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

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