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