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
4265 dpurdie 6183
            #   Don't allow the user to attempt to package the entire package either
4257 dpurdie 6184
            #
6185
            #   Calculate the relative path from $ProjectBase to the target directory
6186
            #   It must not be above the $ProjectBase 
6187
            #
4265 dpurdie 6188
            if ( $dir_tree =~ m~^\.\.~)
6189
            {
6190
                my $dirFromBase = RelPath($abs_dir_tree, AbsPath($ProjectBase));
6191
                Error("DirTree cannot extend outside current package.",
6192
                      "Directory: $dirFromBase") if ( $dirFromBase =~ m~\.\.~ );
6193
                Error("DirTree cannot package entire package.",
6194
                    "Directory: $dirFromBase") if ( $dirFromBase eq '.' );
6195
            }
4257 dpurdie 6196
 
4163 dpurdie 6197
            Debug2( "PackageFile. DirTree: $dir_tree" );
6198
 
227 dpurdie 6199
            Error("DirTree. Directory not found",
6200
                  "Directory: $dir_tree") unless  ( -d $dir_tree );
6201
 
4257 dpurdie 6202
            # If packaging a parent directory then force dot_stripping of the base directory
6203
            # strip_base will have precedence if both are active
6204
            if ( $dir_tree =~ m~\.\.~ )
6205
            {
6206
                $dir_tree =~ m~(\.\./)+~;
6207
                $strip_dots = length($1);
6208
            }
6209
 
227 dpurdie 6210
        } elsif ( /^--FilterOut=(.*)/ ) {
6211
            push @dir_tree_exclude, $1;
6212
 
6213
        } elsif ( /^--FilterIn=(.*)/ ) {
6214
            push @dir_tree_include, $1;
6215
 
6216
        } elsif ( /^--StripDir/ ) {
341 dpurdie 6217
            $strip_base = 1;
227 dpurdie 6218
 
335 dpurdie 6219
        } elsif ( m/^--Recurse/ ) {
6220
            $recurse = 1;
6221
 
6222
        } elsif ( m/^--NoRecurse/ ) {
6223
            $recurse = 0;
6224
 
227 dpurdie 6225
        } elsif (/^--(.*)/) {
6226
            Message( "PackageFile: unknown option $_ -- ignored\n" );
6227
        }
6228
    }
6229
 
6230
 
6231
    #.. DirTree expansion
6232
    #   Note: Uses REs, not simple globs
6233
    #         Use JatsLocateFiles to do the hard work
6234
    if ( $dir_tree )
6235
    {
335 dpurdie 6236
        my $search = JatsLocateFiles->new('FullPath' );
6237
        $search->recurse($recurse);
227 dpurdie 6238
        $search->filter_in_re ( $_ ) foreach ( @dir_tree_include );
6239
        $search->filter_out_re( $_ ) foreach ( @dir_tree_exclude );
1431 dpurdie 6240
        $search->filter_out_re( '/\.svn/' );
227 dpurdie 6241
        @elements = $search->search ( $dir_tree );
4257 dpurdie 6242
        if ($strip_base){
6243
            $strip_base = length( $dir_tree ) if ( $strip_base );
6244
        } elsif ($strip_dots) {
6245
            $strip_base = $strip_dots;
6246
        }
227 dpurdie 6247
    }
6248
 
6249
#.. Files
6250
#
285 dpurdie 6251
    foreach ( @elements )
227 dpurdie 6252
    {
6253
        my %package_entry;
299 dpurdie 6254
        $name = $_;
6255
 
227 dpurdie 6256
        #
299 dpurdie 6257
        #   Trap special files
6258
        #       DPACKAGE - but only if we have a DPackageLibrary directive
6259
        #                  in the same makefile.
6260
        #
6261
        if ( m~^DPACKAGE$~ && $DPackageDirective ) {
6262
            $name = 'DPACKAGE.' . $::GBE_MACHTYPE;
6263
        }
6264
 
6265
        #
387 dpurdie 6266
        #   Allow for named files that must be quoted
6267
        $name = QuoteForMake( $name );
227 dpurdie 6268
 
6269
        if ( ! /^--(.*)/ )
6270
        {
6271
            $basename = StripDir( $name );
335 dpurdie 6272
            if ( !($srcfile = $SRCS{ $basename }) ) {
6273
                $srcfile = $name;
6274
            }
6275
 
227 dpurdie 6276
            if ( $full )
6277
            {
335 dpurdie 6278
                my $subdir = StripFileExt($srcfile);
6279
                $subdir = $1
6280
                    if ( $subdir =~ m~^$ProjectBase/(.*)~ );
6281
                $dir .= '/' . $subdir;
6282
                $dir =~ s~//~/~g;
6283
                $dir =~ s~/./~/~g;
6284
                $dir =~ s~/$~~g;
6285
                $name = $basename;
227 dpurdie 6286
            }
6287
 
6288
            $name = $basename
6289
                if ( $strip );
6290
 
341 dpurdie 6291
            if ( $strip_base )
6292
            {
6293
                $name = substr $name, $strip_base;
6294
                $name =~ s~^/~~;
6295
            }
6296
 
227 dpurdie 6297
            $dir =~ s~//~/~g;
6298
            $dir =~ s~/$~~;
6299
 
6300
            #
6301
            #   Sanity test the source filename
6302
            #   User may have misused an option
6303
            #
6304
            if ( ( $srcfile =~ m/=/ ) || ( $srcfile =~ m/^-/ ) || ( $srcfile =~ m~/-~ )  )
6305
            {
6306
               Warning ("PackageFile: Suspect source filename: $srcfile");
6307
            }
6308
 
6309
            Debug( "PackageFile( $dir/$name, " .
6310
                "src: $srcfile, dest: $dir, dist: $dist, exe: $exefile )" );
6311
 
6312
            $package_entry{'src'} = $srcfile;
6313
            $package_entry{'dir'} = StripFileExt( "$dir/$name" );
6314
            $package_entry{'set'} = $dist;
6315
            $package_entry{'exe'} = $exefile if $exefile;
6316
            $package_entry{'type'} = $type if ( $type );
6317
 
6318
            $PACKAGE_FILES{ "$dir/$name" } = {%package_entry};
6319
        }
6320
    }
6321
}
6322
 
6323
sub PackageHdr
6324
{
6325
    my( $platforms, @elements ) = @_;
335 dpurdie 6326
    my( $base, $dir, $full, $path, $dist, $strip );
227 dpurdie 6327
    my( $name, $basename, $len, $srcfile );
6328
 
6329
    Debug2( "PackageHdr($platforms, @elements)" );
6330
 
6331
    return if ( !$ScmPackage );                 # Packaging enabled ?
6332
    return if ( ! ActivePlatform($platforms) );
6333
 
6334
#.. Arguments
6335
#
6336
    $dist = "ALL";                                  # Default set (ALL)
6337
    $base = $PackageInfo{'Hdr'}{'PBase'};           # Base of target
6338
    $dir = $base . $PackageInfo{'Hdr'}{'Dir'};      # Installation path (default)
335 dpurdie 6339
    $full = 0;
227 dpurdie 6340
    $strip = 0;
6341
 
285 dpurdie 6342
    foreach ( @elements )
227 dpurdie 6343
    {
6344
        my $rv = __TargetDir($T_PKG, $base, $_, \$dir);
6345
        next if ( $rv == 1 );
6346
        return if ( $rv == 2 );
6347
 
6348
        if (/^--Full/) {                        # Using full (resolved) path
6349
            $full = 1;
6350
 
6351
        } elsif (/^--Set=(.*)/) {               # Distribution set
6352
            $dist = "$1";
6353
 
6354
        } elsif (/^--Package$/) {               # Package .. call by InstallHdr
6355
        } elsif (/^--Package=(.*)/) {
6356
            $dist = "$1";
6357
 
6358
        } elsif (/^--Strip$/) {                 # Strip path from source files
6359
            $strip = 1;
6360
 
6361
        } elsif (/^--(.*)/) {
6362
            Message( "PackageHdr: unknown option $_ -- ignored\n" );
6363
        }
6364
    }
6365
 
6366
#.. Files
6367
#
285 dpurdie 6368
    foreach ( @elements )
227 dpurdie 6369
    {
6370
        my %package_entry;
6371
        if ( ! /^--(.*)/ )
6372
        {
387 dpurdie 6373
            $name = QuoteForMake($_);
227 dpurdie 6374
            $basename = StripDir( $name );
335 dpurdie 6375
            if ( !($srcfile = $SRCS{ $basename }) ) {
6376
                $srcfile = $name;
6377
            }
6378
 
227 dpurdie 6379
            if ( $full )
6380
            {
335 dpurdie 6381
                my $subdir = StripFileExt($srcfile);
6382
                $subdir = $1
6383
                    if ( $subdir =~ m~^$ProjectBase/(.*)~ );
6384
                $dir .= '/' . $subdir;
6385
                $dir =~ s~//~/~g;
6386
                $dir =~ s~/./~/~g;
6387
                $dir =~ s~/$~~g;
6388
                $name = $basename;
227 dpurdie 6389
            }
6390
 
6391
            $name = $basename
6392
                if ( $strip );
6393
 
6394
            Debug( "PackageHdr( $dir/$name, " .
6395
                "src: $srcfile, dest: $dir, dist: $dist )" );
6396
 
6397
            $package_entry{'src'} = $srcfile;
6398
            $package_entry{'dir'} = StripFileExt( "$dir/$name" );
6399
            $package_entry{'set'} = $dist;
6400
 
6401
            $PACKAGE_HDRS{ "$dir/$name" } = {%package_entry};
6402
        }
6403
    }
6404
}
6405
 
6406
 
6407
sub PackageLib
6408
{
6409
    my( $platforms, @elements ) = @_;
6410
    my( $base, $dir, $dist, $type );
6411
    my( $lib, $org_lib, %extras, $strip );
6412
 
6413
    Debug2( "PackageLib($platforms, @elements)" );
6414
 
6415
    return if ( !$ScmPackage );                 # Packaging enabled ?
6416
    return if ( ! ActivePlatform($platforms) );
6417
 
6418
#.. Arguments
6419
#
6420
    $dist = "ALL";                              # Default set (ALL)
6421
    $base = $PackageInfo{'Lib'}{'PBase'};       # Base of target
6422
    $dir = $base . $PackageInfo{'Lib'}{'Dir'};  # Installation path (default)
6423
    $type = "";
6424
 
285 dpurdie 6425
    foreach ( @elements )
227 dpurdie 6426
    {
6427
                                                # Standard targets
6428
        my $rv = __TargetDir($T_PKG, $base, $_, \$dir, \$type);
6429
        next if ( $rv == 1 );
6430
        return if ( $rv == 2 );
6431
 
6432
        if (/^--Set=(.*)/) {                    # Distribution set(s)
6433
            $dist = "$1";
6434
 
6435
        } elsif (/^--Package$/) {               # Package .. call by PackageLib
6436
        } elsif (/^--Package=(.*)/) {
6437
            $dist = "$1";
6438
 
6439
        } elsif (/^--Extras=(.*)/) {            # Extras=[none, .. ,all]
6440
            foreach my $elem ( split( ',', $1 ) )
6441
            {
6442
                Error ("PackageLib: Unknown Extras mode: $elem")
6443
                    unless ( grep m/$elem/, qw(none stub map lint debug all) );
6444
                $extras{$elem} = 1;
6445
            }
6446
            %extras = () if ( $extras{'all'} );
6447
 
6448
        } elsif (/^--Strip$/) {                 # Strip path from source files
6449
            $strip = 1;
6450
 
6451
        } elsif (/^--(.*)/) {
6452
            Message( "PackageLib: unknown option $_ -- ignored\n" );
6453
        }
6454
    }
6455
 
6456
#.. Files
6457
#
285 dpurdie 6458
    foreach ( @elements )
227 dpurdie 6459
    {
6460
        my %package_entry;
6461
        if ( ! /^--(.*)/ )
6462
        {
6463
            $_ = StripDir( $_ )
6464
                if ( $strip );
6465
 
6466
            $org_lib = $_;                      # Original name
6467
            if ( $ScmTargetHost eq "Unix" ) {
6468
                $lib = "lib$_";                 # Prefix "lib" ....
6469
                $lib =~ s/^liblib/lib/;         # @LIBS already has lib added
6470
            } else {
6471
                $lib = $_;
6472
            }
6473
 
289 dpurdie 6474
            if (  my $libp = $SHLIBS->Get($lib) )
227 dpurdie 6475
            {
6476
                Debug( "PackageLib( $dir/$lib\$(GBE_TYPE).$::so, " .
6477
                    "src: \$(LIBDIR)/$lib\$(GBE_TYPE).$::so, dest: $dir, dist: $dist, type: $type )" );
6478
 
6479
                #
6480
                #   Create a "placekeeper" entry within $PACKAGE_SHLIBS
6481
                #   The exact format of the name of the shared library is
6482
                #   toolset specific. Create an entry to allow the toolset
6483
                #   to extend the packaging information when the shared library
6484
                #   recipe is constructed.
6485
                #
6486
                #
289 dpurdie 6487
                my $ver = $libp->{ VERSION };
227 dpurdie 6488
                my $name = "$dir/$lib.$ver.PlaceKeeper";
6489
 
6490
                $package_entry{'placekeeper'} = 1;
6491
                $package_entry{'version'} = $ver;
6492
                $package_entry{'lib'} = $lib;
6493
                $package_entry{'dir'} = $dir;
6494
                $package_entry{'set'} = $dist;
6495
                $package_entry{'type'} = $type if ( $type );
6496
                $package_entry{'extras'} = {%extras} if ( scalar %extras );
289 dpurdie 6497
 
6498
                push @{$SHLIB_PKG{$lib}}, $name;
227 dpurdie 6499
                $PACKAGE_SHLIBS{$name} = {%package_entry};
6500
            }
6501
 
289 dpurdie 6502
            #
6503
            #   Clean up the package_entry
6504
            #   Insert common items
6505
            #
6506
            %package_entry = ();
6507
            $package_entry{'lib'} = $lib;
6508
            $package_entry{'dir'} = $dir;
6509
            $package_entry{'set'} = $dist;
6510
            $package_entry{'extras'} = {%extras} if ( scalar %extras );
6511
            $package_entry{'type'} = $type if ( $type );
6512
 
227 dpurdie 6513
            if ( my $libfile = $SRCS{$org_lib} )
6514
            {
6515
                #
6516
                #   Allow the user to package a sourced file as a library
6517
                #   But must be the un-massaged name of the file.
6518
                #
387 dpurdie 6519
                $package_entry{'dst'} = QuoteForMake("$dir/$org_lib");
6520
                $package_entry{'src'} = QuoteForMake($libfile);
289 dpurdie 6521
            }
6522
            elsif ( $LIBS->Get($lib) )
6523
            {
6524
                #
6525
                #   Package up a library known to the makefile
6526
                #
6527
                my $libp = $LIBS->Get($lib);
227 dpurdie 6528
 
289 dpurdie 6529
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
6530
                $package_entry{'src'}    = $libp->getPath();
227 dpurdie 6531
            }
289 dpurdie 6532
            elsif ( ! $SHLIBS->Get($lib) )
227 dpurdie 6533
            {
289 dpurdie 6534
                #
6535
                #   Not a known shared lib
6536
                #   Not a known static lib
6537
                #   Not a 'sourced' file
6538
                #   Assume the a static library has magically appeared
6539
                #   in the standard LIB directory. May have been placed there
6540
                #   by a 'rule'
6541
                #
6542
                my $libp = $LIBS->New($lib);
227 dpurdie 6543
 
289 dpurdie 6544
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
6545
                $package_entry{'src'}    = $libp->getPath();
6546
            }
227 dpurdie 6547
 
289 dpurdie 6548
            #
6549
            #   Add entry to various lists if required
6550
            #
6551
            PackageLib_AddEntry ('PackageLib', \%LIB_PKG, \%PACKAGE_LIBS, \%package_entry )
6552
                if ( exists $package_entry{'dst'} );
227 dpurdie 6553
        }
6554
    }
6555
}
6556
 
289 dpurdie 6557
#-------------------------------------------------------------------------------
6558
# Function        : PackageLib_AddEntry
6559
#
6560
# Description     : Helper function to add a package entry
6561
#                   to the lists
6562
#
6563
# Inputs          : $directive          - Directive name
6564
#                   $pList              - Ref to array list to maintain
6565
#                   $pHash              - Ref to hash to maintain
6566
#                   $pData              - Packaging Data
6567
#                                         Must Take a copy.
6568
#
6569
# Returns         : 
6570
#
227 dpurdie 6571
 
289 dpurdie 6572
sub PackageLib_AddEntry
6573
{
6574
    my ($directive, $pList, $pHash, $pData) = @_;
6575
 
6576
    my $lib = delete $pData->{'lib'};
6577
    my $dst = delete $pData->{'dst'};
6578
 
6579
    Error ("INTERNAL PackageLib_AddEntry: lib or dst not defined")
6580
        unless ( $lib && $dst );
6581
 
6582
    Debug( "$directive( ",$dst,
6583
            ", src: " ,$pData->{'src'},
6584
            ", dest: ",$pData->{'dir'},
6585
            ", dist: ",$pData->{'set'},
6586
            ", type: ",$pData->{'type'} || '',
6587
            " )" );
6588
 
6589
    push @{$pList->{$lib }}, $dst;
6590
    $pHash->{$dst } = {%$pData};
6591
}
6592
 
6593
 
227 dpurdie 6594
sub PackageProg
6595
{
6596
    my( $platforms, @elements ) = @_;
6597
    my( $base, $dir, $dist, $type );
6598
    my( $prog, %extras, $strip );
6599
 
6600
    Debug2( "PackageProg($platforms, @elements)" );
6601
 
6602
    return if ( !$ScmPackage );                 # Packaging enabled ?
6603
    return if ( ! ActivePlatform($platforms) );
6604
 
6605
#.. Arguments
6606
#
6607
    $dist = "ALL";                              # Default set (ALL)
6608
    $base = $PackageInfo{'Prog'}{'PBase'};       # Base of target
6609
    $dir = $base . $PackageInfo{'Prog'}{'Dir'};  # Installation path (default)
6610
    $type = "";
6611
 
285 dpurdie 6612
    foreach ( @elements )
227 dpurdie 6613
    {
6614
                                                # Standard targets
6615
        my $rv = __TargetDir($T_PKG|$T_TYPE, $base, $_, \$dir, \$type);
6616
        next if ( $rv == 1 );
6617
        return if ( $rv == 2 );
6618
 
6619
        if (/^--Set=(.*)/) {                    # Distribution set(s)
6620
            $dist = "$1";
6621
 
6622
        } elsif (/^--Package$/) {               # Package .. call by PackageLib
6623
        } elsif (/^--Package=(.*)/) {
6624
            $dist = "$1";
6625
 
6626
        } elsif (/^--Tool(([=])(.*))?$/) {      # Allow Tool and Tool=xxx specfic target
6627
            my $path = ( defined( $3) ) ? "/$3" : "";
261 dpurdie 6628
            $dir = "\$(PKGDIR)$path/\$(GBE_HOSTMACH)";
227 dpurdie 6629
 
6630
        } elsif (/^--Extras=(.*)/) {            # Extras=[none, .. ,all]
6631
            foreach my $elem ( split( ',', $1 ) )
6632
            {
6633
                Error ("PackageLib: Unknown Extras mode: $elem")
6634
                    unless ( grep m/$elem/, qw(none stub map lint debug all) );
6635
                $extras{$elem} = 1;
6636
            }
6637
            %extras = () if ( $extras{'all'} );
6638
 
6639
        } elsif (/^--Strip$/) {                 # Strip path from source files
6640
            $strip = 1;
6641
 
6642
        } elsif (/^--(.*)/) {
6643
            Message( "PackageProg: unknown option $_ -- ignored\n" );
6644
        }
6645
    }
6646
 
6647
#.. Files
6648
#
285 dpurdie 6649
    foreach ( @elements )
227 dpurdie 6650
    {
6651
        my %package_entry;
6652
        if ( m~descpkg~ ) {
6653
            PackageFile($platforms, @elements);
6654
 
6655
        } elsif ( ! /^--(.*)/ ) {
6656
            $_ = StripDir( $_ )
6657
                if ( $strip );
6658
 
6659
            my $ext = "";
6660
            $prog = $_;
6661
 
6662
            #
6663
            #   If the named target is a program then append the correct
6664
            #   extension. Otherwise assume that the target is either a script
6665
            #   or a some other file - and don't append an extension
6666
            #
6667
            #   A program may not have any object files, only libraries
6668
            #
6669
            $ext = $::exe
289 dpurdie 6670
                if ( $PROGS->Get($prog) );
227 dpurdie 6671
 
6672
            #
6673
            #   A "file" that is specified with a "Src" directive may be
6674
            #   installed as though it were a program
6675
            #
6676
            my $progfile;
387 dpurdie 6677
            if ( $progfile = $SRCS{$prog} )
6678
            {
6679
                $progfile = QuoteForMake($progfile);
6680
                $prog = QuoteForMake($prog);
6681
            }
6682
            else
6683
            {
6684
                $progfile = "\$(BINDIR)/$prog$ext";
6685
            }
227 dpurdie 6686
 
6687
            Debug( "PackageProg( $dir/$prog$ext, " .
6688
                 "src: $progfile, dest: $dir, dist: $dist, type: $type )" );
6689
 
6690
            my $target = "$dir/$prog$ext";
6691
            push @{$PROG_PKG{$prog}}, $target;
6692
 
6693
            $package_entry{'src'}   = $progfile;
6694
            $package_entry{'dir'}   = $dir;
6695
            $package_entry{'set'}   = $dist;
6696
            $package_entry{'extras'}= {%extras} if ( scalar %extras );
6697
            $package_entry{'type'}  = $type if ( $type );
6698
 
6699
            $PACKAGE_PROGS{$target} = {%package_entry};
6700
        }
6701
    }
6702
}
6703
 
6704
 
6705
sub PackageJar
6706
{
6707
    my( $platforms, @elements ) = @_;
6708
    my( $base, $dir, $dist, $type );
6709
    my( $jar );
6710
 
6711
    Debug2( "PackageJar($platforms, @elements)" );
6712
 
6713
    return if ( !$ScmPackage );                 # Packaging enabled ?
6714
    return if ( ! ActivePlatform($platforms) );
6715
 
6716
#.. Arguments
6717
#
6718
    $dist = "ALL";                              # Default set (ALL)
6719
    $base = $PackageInfo{'Jar'}{'PBase'};       # Base of target
6720
    $dir = $base . $PackageInfo{'Jar'}{'Dir'};  # Installation path (default)
6721
    $type = "";
6722
 
285 dpurdie 6723
    foreach ( @elements )
227 dpurdie 6724
    {
6725
                                                # Standard targets
6726
        my $rv = __TargetDir($T_PKG, $base, $_, \$dir, \$type);
6727
        next if ( $rv == 1 );
6728
        return if ( $rv == 2 );
6729
 
6730
        if (/^--Set=(.*)/) {                    # Distribution set(s)
6731
            $dist = "$1";
6732
 
6733
        } elsif (/^--Package$/) {               # Package .. call by InstallJar
6734
        } elsif (/^--Package=(.*)/) {
6735
            $dist = "$1";
6736
 
6737
        } elsif (/^--(.*)/) {
6738
            Message( "PackageJar: unknown option $_ -- ignored\n" );
6739
        }
6740
    }
6741
 
6742
#.. Files
6743
#
285 dpurdie 6744
    foreach ( @elements )
227 dpurdie 6745
    {
6746
        my %package_entry;
6747
        if ( ! /^--(.*)/ )
6748
        {
6749
            $jar = $_;
6750
            my $src;
6751
            my $dest;
6752
 
6753
            if ( $JAR_FILES{$jar} )
6754
            {
6755
                $src = $JAR_FILES{$jar};
6756
                $dest = $jar;
6757
            }
6758
            else
6759
            {
6760
                $src = "\$(CLSDIR)/$jar\$(GBE_TYPE).jar";
6761
                $dest = "$jar\$(GBE_TYPE).jar";
6762
            }
6763
 
6764
 
6765
            Debug( "PackageJar( $dir/$dest, " .
6766
                "src: $src, dest: $dir, dist: $dist, type: $type )" );
6767
 
6768
            $package_entry{'src'} = $src;;
6769
            $package_entry{'dir'} = $dir;
6770
            $package_entry{'set'} = $dist;
6771
            $package_entry{'type'} = $type if ( $type );
6772
 
6773
            $PACKAGE_CLSS{ "$dir/$dest" } = {%package_entry};
6774
 
6775
        }
6776
    }
6777
}
6778
 
6779
#-------------------------------------------------------------------------------
6780
# Function        : PackageProgAddFiles         - Add files to a PackageProg
6781
#                   PackageLibAddFiles          - Add files to a PackageLib
6782
#                   PackageShlibAddFiles        - Add files to a PackageLib (shared lib)
6783
#                   PackageShlibAddLibFiles     - Add files to a PackageLib (shared lib)
6784
#                                                 Add static library files
6785
#
6786
# Description     : Add files to a Program package or installation
6787
#                   For use by Tool sets to allow additional files to be
6788
#                   packaged with a program.
6789
#
6790
#                   The files are only added if the named program is being
6791
#                   packaged and/or installed.
6792
#
6793
#
6794
# Inputs          : prog        - program identifier
6795
#                   file        - A file to be add
6796
#                   args        - Additional packageing arguments
6797
#
6798
# Returns         : Nothing
6799
#
6800
 
6801
sub PackageProgAddFiles
6802
{
6803
    Debug("PackageProgAddFiles");
6804
 
6805
    PackageAddFiles ( \%PACKAGE_PROGS, \%PACKAGE_PROGS, \%PROG_PKG, @_);
6806
    PackageAddFiles ( \%INSTALL_PROGS, \%INSTALL_PROGS, \%PROG_INS, @_);
6807
}
6808
 
6809
sub PackageLibAddFiles
6810
{
6811
    Debug("PackageLibAddFiles");
6812
 
6813
    PackageAddFiles ( \%PACKAGE_LIBS, \%PACKAGE_LIBS, \%LIB_PKG, @_ );
6814
    PackageAddFiles ( \%INSTALL_LIBS, \%INSTALL_LIBS, \%LIB_INS, @_ );
6815
}
6816
 
6817
sub PackageShlibAddFiles
6818
{
6819
    my ($prog, $file, @args) = @_;
6820
    Debug("PackageShlibAddFiles");
6821
 
6822
    PackageAddFiles ( \%INSTALL_SHLIBS, \%INSTALL_SHLIBS, \%SHLIB_INS, @_ );
6823
    PackageAddFiles ( \%PACKAGE_SHLIBS, \%PACKAGE_SHLIBS, \%SHLIB_PKG, @_ );
6824
 
6825
    #
6826
    #   These files become the target of the "make_install_shlib" operation unless:
6827
    #       Conditionally packaged files are not always created
6828
    #       RemoveOnly files are not always generated
6829
    #
6830
    my $no_add;
6831
    foreach ( @args )
6832
    {
6833
        if ( m/^defined=/ or m/^RemoveOnly=/ )
6834
        {
6835
            $no_add = 1;
6836
            last;
6837
        }
6838
    }
6839
 
6840
    push (@SHLIB_TARGETS, $file ) unless $no_add;
6841
}
6842
 
6843
sub PackageShlibAddLibFiles
6844
{
6845
    Debug("PackageShlibAddLibFiles");
6846
 
6847
    PackageAddFiles ( \%PACKAGE_SHLIBS, \%PACKAGE_LIBS, \%SHLIB_PKG, @_ , 'Class=lib');
6848
    PackageAddFiles ( \%INSTALL_SHLIBS, \%INSTALL_LIBS, \%SHLIB_INS, @_ , 'Class=lib');
6849
}
6850
 
6851
#-------------------------------------------------------------------------------
6852
# Function        : PackageAddFiles
6853
#
6854
# Description     : Internal function to add files to the data structures that
6855
#                   describe a package or installation
6856
#
6857
#                   Use this function to package or install additional files with
6858
#                   the Progs and Libs
6859
#
6860
#                   ie: Add a LIB file to be packaged with a Shared Library
6861
#                   ie: Add a MAP file to be packaged with a program
6862
#
6863
# Inputs          : ref_spkg  - Reference to the hash that contains the package data
6864
#                   ref_dpkg  - Reference to the target package/install hash
6865
#                               Normally the same as ref_dpkg, but does allow
289 dpurdie 6866
#                               a static library to be added to a dynamic library
227 dpurdie 6867
#                               package.
6868
#                   ref_list  - Reference to a hash that may contain package keys to process
6869
#                   prog      - Key for index to above
6870
#                   file      - A file to be added
6871
#                   args      - Additional packaging arguments
6872
#
6873
# Returns         :
6874
#
6875
sub PackageAddFiles
6876
{
6877
    my ($ref_spkg, $ref_dpkg, $ref_list, $prog, $file, @args ) = @_;
6878
 
6879
    #
6880
    #   Process entry
6881
    #   The files may need to be added to multiple packages
6882
    #
6883
    Debug("PackageAddFiles: $file");
6884
 
6885
    return unless ( $ref_list->{$prog} );
6886
 
6887
    #
6888
    #   Parse arguments and extract the "Class=xxx" argument. This may be used
6889
    #   to limit the extra files piggybacked with the base file
6890
    #   All files without a class will be treated as base files
6891
    #
6892
    my $class;
6893
    foreach ( @args )
6894
    {
6895
        next unless ( m~^Class=(.*)$~ );
6896
        $class = $1 unless ( $1 eq 'none' );
6897
    }
6898
    Debug("PackageAddFiles: Class: ", $class || 'Default=None');
6899
 
6900
    foreach my $entry_key ( @{$ref_list->{$prog}} )
6901
    {
6902
        Debug("PackageAddFiles: Entry found: $entry_key");
6903
 
6904
        #
6905
        #   Copy of the template entry
6906
        #
6907
        my %package_entry = %{$ref_spkg->{$entry_key}};
6908
        Error ("INTERNAL: Expected entry in PACKAGE_ hash not found: $entry_key" )
6909
            unless ( %package_entry );
6910
 
6911
        #
6912
        #   Do not add the file if the user has limited the extra files added
6913
        #   to the packaging list and the current file is not in the class list
6914
        #
6915
        if ( $class && $package_entry{'extras'} )
6916
        {
6917
            next unless ( $package_entry{'extras'}{$class} );
6918
        }
6919
 
6920
        #
6921
        #   Create new entries for the file
6922
        #
6923
        $package_entry{'src'} = $file;
6924
        foreach ( @args )
6925
        {
6926
            m~^(.*)=(.*)$~;
6927
            $package_entry{$1} = $2;
6928
        }
6929
 
6930
        #
6931
        #   Clean out useless fields
6932
        #   Must remove the placekeeper marker to allow the entry to be visible
6933
        #
6934
        delete $package_entry{'placekeeper'};
6935
        delete $package_entry{'version'};
6936
        delete $package_entry{'lib'};
261 dpurdie 6937
#       delete $package_entry{'extras'};                   # Keep these
227 dpurdie 6938
        delete $package_entry{'Class'};
6939
 
6940
        #
6941
        #   Add the entry
6942
        #
6943
        #   Under some conditions is it possible to attempt to add the same named
6944
        #   file. This will result in a circular dependancy in the makefile
6945
        #
6946
        #   The condition is when merged libaries with PDBs (WINCE+WIN32) are merged
261 dpurdie 6947
        #   and the source for the merge is the "local directory.
227 dpurdie 6948
        #
6949
        #
6950
        my $dst = $package_entry{'dir'} ;
6951
        ( my $dfile = $file) =~ s~.*/~~;
6952
        Debug( "    added $dst/$dfile = $file" );
6953
 
6954
        $ref_dpkg->{"$dst/$dfile"} = {%package_entry}
6955
            unless ( "$dst/$dfile" eq "$file" );
6956
    }
6957
}
6958
 
6959
#-------------------------------------------------------------------------------
6960
# Function        : PackageProgRemoveFiles
6961
#
6962
# Description     : Flag a Packaged program to be not packaged
6963
#                   This mechanism is used to remove a program from packageing
6964
#                   under conditions where the toolset has generated a different
6965
#                   program.
6966
#
6967
#                   The entry is flagged as a placeholder
6968
#
6969
# Inputs          : prog        - Program to process
6970
#
6971
# Returns         : Nothing
6972
#
6973
sub PackageProgRemoveFiles
6974
{
6975
    my ($prog) = @_;
6976
    Verbose ("PackageProgRemoveFiles: $prog" );
6977
    return unless (exists($PROG_PKG{$prog}));
6978
 
6979
    #
6980
    #   Must lookup the TAG to locate the  required entry
6981
    #
6982
    my $tag = $PROG_PKG{$prog};
6983
    foreach my $entry ( @$tag )
6984
    {
6985
        Verbose("Do not package: $entry");
6986
        if ( exists $PACKAGE_PROGS{$entry} )
6987
        {
6988
            $PACKAGE_PROGS{$entry}{placekeeper} = 'ProgRemoved';
6989
        }
6990
    }
6991
}
6992
 
6993
#-------------------------------------------------------------------------------
6994
# Function        : DPackageLibrary
6995
#
6996
# Description     : Collect information to allow the generation of a DPACKAGE
299 dpurdie 6997
#                   file. This directive allows the generation of "Library"
227 dpurdie 6998
#                   directives within the final DPACKAGE
6999
#
7000
#                   This directive does generate the DPACKAGE file.
7001
#
7002
# Inputs          : platform    - This does not need to be an active platform
7003
#                                 it is simply passed to the DPACKAGE builder
7004
#
7005
#                   using       - The "using" target
7006
#
7007
#                   ...         - Arguments for the Library directive
7008
#
7009
# Returns         :
7010
#
7011
sub DPackageLibrary
7012
{
7013
    JatsDPackage::DPackageAdd ( @_ );
299 dpurdie 7014
    $DPackageDirective = 1;
227 dpurdie 7015
}
7016
 
7017
#-------------------------------------------------------------------------------
7018
# Function        : SetProjectBase
7019
#
7020
# Description     : Allows the user to modify the build's concept of the Base
7021
#                   of the build. By default the base is the same directory as
7022
#                   the build.pl file, but in some contorted environments it
7023
#                   is a great deal simpler to specify a differnt base.
7024
#
7025
#                   The use may use the variable $ProjectBase as a path
7026
#                   specifier to locate files and directories
7027
#
7028
#                   Both absolute and relative paths are supported
7029
#                   If the initial value of $ProjectBase is relative then
7030
#                   it will be maintained as a relative path.
7031
#
7032
# Inputs          : elements        path to base
7033
#                                   These may be:
7034
#                                       --Up=xx
7035
#                                       name
7036
#
7037
# Returns         : Nothing
7038
#
7039
 
7040
#
7041
#   Allow the user to modify the project base variable
7042
#
7043
sub SetProjectBase
7044
{
7045
    my $rip = 0;
7046
    my $path = "";
7047
    my $is_relative;
7048
 
7049
    Debug("ProjectBase Initial: $ProjectBase, @_");
7050
 
7051
    #
7052
    #   Ensure that the ProjectBase is in a "nice" form
7053
    #   1) No /./ bits
7054
    #   2) No trailing /
7055
    #   3) Not equal to .
7056
    #   4) No training /.
7057
    #   5) No //
7058
    #
7059
    $ProjectBase =~ s~/\./~/~g;
7060
    $ProjectBase =~ s~/$~~g;
7061
    $ProjectBase =~ s~^\.$~~g;
7062
    $ProjectBase =~ s~/\.$~~g;
7063
    $ProjectBase =~ s~//$~/~g;
7064
 
7065
    #
7066
    #   ProjectBase may be absolute or relative
7067
    #   Determine this before we mess with it
7068
    #
7069
    $is_relative = ($ProjectBase !~ m~^/~);
7070
 
7071
    #
7072
    #   Process each argument
7073
    #
7074
    foreach ( @_ )
7075
    {
7076
        if ( /^--Up=([0-9]*)/ ) {
7077
            $rip = $1;
7078
        } elsif ( /^--/ ) {
7079
            Warning( "SetProjectBase - unknown option \"$_\" - ignored" );
7080
        } else {
7081
            $path = $_;
7082
        }
7083
    }
7084
 
7085
    #
7086
    #   Process the UP requests
7087
    #   If the tail directory is a ".." then up is done by adding another ".."
7088
    #   If the tail directory is not a "..", then up is done by removing it
7089
    #
7090
    #   If we go past the start of the path then simply add ".."
7091
    #
7092
    while ( $rip-- > 0 )
7093
    {
7094
        Debug2("ProjectBase: $ProjectBase, Up: $rip, IsRel: $is_relative");
7095
 
7096
        #
7097
        #   If ending in a /.. or is exactly equal to ..
7098
        #   Then its a dot-dot and the way to go UP is to append another ..
7099
        #
7100
        if ( $ProjectBase =~ m~(/\.\.$)|(^\.\.$)~ )
7101
        {
7102
            $ProjectBase .= '/..';
7103
        }
7104
        else
7105
        {
7106
            #
7107
            #   Not a dot-dot ending
7108
            #   Attempt to remove the last directory of the form
7109
            #       /xxxxx
7110
            #   Where the leading / is optional
7111
            #   Note: Must have at least one character in the dirname
7112
            #         This prevents leading / from matching - which is needed
7113
            #
7114
            unless ($ProjectBase =~ s~/?[^/]+$~~)
7115
            {
7116
                #
7117
                #   Removal failed
7118
                #   If a relative path then we can keep on going up,
7119
                #   otherwise we are dead.
7120
                #
7121
                Error ("ProjectBase outside project") unless ($is_relative);
7122
                $ProjectBase = '..';
7123
            }
7124
 
7125
            #
7126
            #   Ensure that the leading / in an absolute path is not deleted
7127
            #
7128
            $ProjectBase = '/'
7129
                unless ( $is_relative || $ProjectBase );
7130
        }
7131
    }
7132
 
7133
    #
7134
    #   Append the user path
7135
    #
7136
    $ProjectBase .= '/' . $path if ( $path );
7137
    $ProjectBase = '.' unless ( $ProjectBase );
7138
    Debug("ProjectBase set to : $ProjectBase");
7139
 
7140
    #
7141
    #   Once upon a time I tried to convert paths that contained spaces into
7142
    #   short (mangled) names. This was not sucessful because:
7143
    #       1) Clearcase dynamic views do not support name mangling
7144
    #       2) Samba file system does not appear to support name mangling
7145
    #
7146
    #   Spaces in paths are not good for MAKE
7147
    #   Now I simple generate a message
7148
    #
7149
    Warning( "ProjectBase contains a space: $ProjectBase")
7150
        if ( $ProjectBase =~ m/ / );
7151
 
7152
    #
7153
    #   Sanity check
7154
    #   Absolute paths can be checked easily
7155
    #   Checking of relative paths does not appear to work
7156
    #   When I tested it chdir, opendir and stat would limit themselves
7157
    #   and drop into the root directory ( under windows )
7158
    #
7159
    #   Solution: Check the path does not extend beyond the file tree
7160
    #
7161
    my $distance = 1;
7162
    my $tpath = $ProjectBase;
7163
 
7164
    if ( $is_relative && $tpath ne '.' )
7165
    {
7166
        #
7167
        #   Build up the complete pathname by merging it with the
7168
        #   current directory. Then clean it up.
7169
        #
7170
        $tpath = $::Cwd . '/' . $ProjectBase;
7171
 
7172
        #
7173
        #   Scan the list of diretories and count the distance from the root
7174
        #   This should not be greater than zero for sanity
7175
        #   Note: Get an empty elemement from the split due to
7176
        #         the leading / of the ABS path
7177
        #
7178
        $distance = 0;
7179
        foreach (  split ('/', $tpath) )
7180
        {
7181
            if ( m~\.\.~ )
7182
            {
7183
                $distance--;
7184
            }
7185
            else
7186
            {
7187
                $distance++;
7188
            }
7189
        }
7190
    }
7191
 
7192
    #
7193
    #   Warn if not a valid directory
7194
    #
7195
    Warning( "ProjectBase is not a directory: $ProjectBase")
7196
        if ( $distance <= 0 || !  -d $tpath  );
7197
 
7198
    #
7199
    #   $ProjectBase will always be a valid directory, but if its the top
7200
    #   directory (/) and it is added to a path we will get //path
7201
    #   This is not good, so // will be removed later in the AddIncDir and
7202
    #   AddSrcDir commands where $ProjectBase is really used.
7203
    #
7204
    #   Alternatively we could set $ProjectBase to an empty string, but then
7205
    #   this may be confused with an empty relative directory
7206
    #
7207
    Debug("ProjectBase Final  : $ProjectBase");
7208
}
7209
 
7210
#-------------------------------------------------------------------------------
7211
# Function        : DeployPackage
7212
#
7213
# Description     : Generate a deployed package
7214
#                   This is a gateway to a different packaging system
7215
#
7216
#                  DeployPackage and PackageXxxxx directives are mutually
7217
#                  exclusive. Only one person can play in the package area.
7218
#
7219
# Inputs          : Platform Specifier
7220
#                   Package Name    (Optional)
7221
#                   Options
7222
#                       --Name : Base name of the package. The default is taken
7223
#                                from the build.pl file
7224
#                       --Dir  : Package directory
7225
#                                The default is based on the package name
7226
#
7227
# Returns         :
7228
#
7229
sub DeployPackage
7230
{
7231
    my( $platforms, @elements ) = @_;
7232
    my $dir;
7233
    my $name;
7234
 
267 dpurdie 7235
    #
7236
    #   Flag that this build creates a deployable package, even if its not
7237
    #   active on this platform.
7238
    #
7239
    $DEPLOYPACKAGE = 1;
7240
 
7241
 
227 dpurdie 7242
    Debug2( "DeployPackage($platforms, @elements)" );
7243
    return if ( ! ActivePlatform($platforms) );
7244
 
7245
    #
7246
    #   Only allow one use of this directive
7247
    #
7248
    Error("DeployPackage can only be used once" ) if ( %DEPLOYPACKAGE );
267 dpurdie 7249
    $DEPLOYPACKAGE = 2;
227 dpurdie 7250
 
7251
    #
7252
    #   Ensure that the deployment file is available
7253
    #
7254
    my $command_file = $ScmDeploymentPatch ? "deploypatch.pl" : "deployfile.pl";
7255
    Error("DeployPackage: $command_file not found") unless (-f "./$command_file");
7256
    #
7257
    #   Collect arguments
7258
    #
7259
    foreach (@elements )
7260
    {
7261
        if ( m/^--Dir=(.*)/ ) {
7262
            Error ("DeployPackage: Package directory defined multiple times") if $dir;
7263
            $dir = $1;
7264
 
7265
        } elsif ( m/^--Name=(.*)/ ) {
7266
            Error ("DeployPackage: Package name defined multiple times") if $name;
7267
            $name = $1;
7268
 
7269
        } elsif ( m/^--/ ) {
7270
            Warning( "DeployPackage: Unknown option ignored: $_");
7271
 
7272
        } else {
7273
            Error ("DeployPackage: Package name defined multiple times") if $name;
7274
            $name = $_;
7275
 
7276
        }
7277
    }
7278
 
7279
    $name = $::ScmBuildPackage unless ( $name );
7280
 
7281
    #
7282
    #   Save the deployment data
7283
    #
7284
    $dir = lc($name) unless ( $dir );
7285
    $DEPLOYPACKAGE{'name'} = $name;
7286
    $DEPLOYPACKAGE{'dir'} = $dir;
7287
    $DEPLOYPACKAGE{'cmdfile'} = $command_file;
7288
 
7289
    #
7290
    #   Flag that toolset tests should be supressed
7291
    #   The Deploy world does not really use the full makefiles and if the
7292
    #   compilers are not installed will not be able to create deployment
7293
    #   packages
7294
    #
7295
    $ScmNoToolsTest = 1;
7296
}
7297
 
7298
 
7299
###############################################################################
7300
###############################################################################
7301
# Private function section.
7302
#       The following functions are used INTERNALLY by makelib.pl2.
7303
###############################################################################
7304
 
7305
###############################################################################
7306
#   A collection of functions to write to the MAKEFILE handle
7307
#
7308
#   MakeHeader          - Write a nice section header
7309
#   MakeNewLine         - Print a new line
7310
#   MakePrint           - Print a line ( without trailing \n)
7311
#   MakeQuote           - Escape \ and " character, then print a line
7312
#   MakePrintList       - Print an array
7313
#   MakeEntry           - Complex line printer
7314
#   MakePadded          - Padded line printer (internal)
7315
#   PadToPosn           - Calc space+tabs to tabstop (internal)
7316
#   MakeEntry3          - Complex Line Printer
7317
#   MakeDefEntry        - Print a definition line (Production + Debug support)
7318
#   MakeIfDefEntry      - Print ifdef entry
261 dpurdie 7319
#   MakeIfnDefEntry     - Print ifndef entry
7320
#   MakeIfZeroEntry     - Print ifeq entry
227 dpurdie 7321
#
7322
###############################################################################
7323
 
7324
sub MakeHeader
7325
{
7326
    my ($text, @rest) = @_;
7327
    my $length = length ($text);
7328
 
7329
    print MAKEFILE "\n";
7330
    print MAKEFILE "#--------- $text ", '-' x (80 - 12 - $length)  ,"\n";
7331
    print MAKEFILE "#    $_\n" foreach  ( @rest ) ;
7332
    print MAKEFILE "#\n";
7333
}
7334
 
7335
sub MakeNewLine         # Print a newline to the current 'Makefile'
7336
{
7337
    print MAKEFILE "\n";
7338
}
7339
 
7340
sub MakePrint           # Print to the current 'Makefile'
7341
{
7342
    print MAKEFILE @_
7343
        if ( defined $_[0] );
7344
}
7345
 
7346
sub MakeQuote           # Quote a makefile text line
7347
{
7348
    my( $line ) = @_;
7349
    $line =~ s/\\/\\\\/g;                       # quote all '\' characters
7350
    $line =~ s/"/\\"/g;                         # Then quote '"' characters
255 dpurdie 7351
    $line =~ s/=#/=\\#/g;                       # Then quote '=#' sequence
227 dpurdie 7352
    print MAKEFILE $line;
7353
}
7354
 
7355
sub MakePrintList
7356
{
7357
    print MAKEFILE $_ . "\n" foreach (@{$_[0]});
7358
}
7359
 
2429 dpurdie 7360
sub QuoteArray
7361
{
7362
    my $quote = "'";
7363
    if ( @_ ) {
7364
        return ($quote . join("$quote $quote", @_) . $quote);
7365
    }
7366
    return '';
7367
}
227 dpurdie 7368
 
7369
#-------------------------------------------------------------------------------
7370
# Function        : MakeEntry
7371
#
7372
# Description     : Build a entry based on the element list
7373
#                   Creates text of the form
7374
#                       $(BINDIR)/prog.exe: object1.obj \
7375
#                                           object2.obj
7376
#
7377
#
7378
# Inputs          : $prelim         - Preamble (one-off)
7379
#                   $postlim        - Postamble (one-off)
7380
#                   $prefix         - Pefix (to each element of array)
7381
#                   $postfix        - Postfix (to each element of array )
7382
#                   @elements       - Array of element to wrap
7383
#
7384
# Returns         :   1 Always
7385
#
7386
# Notes:
7387
#       The above description means that the following entry format is
7388
#       produced:
7389
#
7390
#           <preliminary><prefix><variant1><prefix><variant2>...<final>
7391
#
7392
#       With judicious use of newline and tab characters, a target
7393
#       and dependency list along with the command(s) to build the
7394
#       target can be constructed.
7395
#
7396
sub MakeEntry
7397
{
7398
    my( $prelim, $postlim, $prefix, $postfix, @elements ) = @_;
7399
 
7400
    MakePrint $prelim;
7401
    MakePrint "${prefix}${_}${postfix}" foreach ( @elements );
7402
    MakePrint $postlim if ($postlim);
7403
    return 1;
7404
}
7405
 
7406
#-------------------------------------------------------------------------------
7407
# Function        : MakePadded
7408
#
7409
# Description     : Generate aligned output of the form
7410
#                       Prefix_text           Aligned_text
7411
#                   where the aligned text is at a specified TAB boundary
7412
#
7413
# Inputs          : $align      - Tab stop (One tab = 8 chars)
7414
#                   $prefix     - Text to print before alignment occurs
7415
#                   @line       - Remainder of the line
7416
#
7417
sub MakePadded          # Print to the current 'Makefile', tab aligning
7418
{
7419
    my( $align, $prefix, @line ) = @_;
7420
 
7421
    my $strlen = length( $prefix );
7422
    my $pad = PadToPosn( $strlen, $align * 8 );
7423
 
7424
    print MAKEFILE $prefix . $pad;
7425
    print MAKEFILE @line;
7426
}
7427
 
7428
#-------------------------------------------------------------------------------
7429
# Function        : PadToPosn
7430
#
7431
# Description     : Given that we are at $startposn return a tab and space
7432
#                   string to place us at $endposn
7433
#
7434
sub PadToPosn
7435
{
7436
    my ($startposn, $endposn ) = @_;
7437
 
7438
 
7439
    #
7440
    #   Case where we are already too far into the line
7441
    #
7442
    return ( ' ' )if ( $endposn <= $startposn );
7443
 
7444
    my $tcount = 0;
7445
    my $scount = 0;
7446
 
7447
    while ( $startposn < $endposn )
7448
    {
7449
        $tcount ++;
7450
        $startposn = ($startposn >> 3) * 8 + 8;
7451
 
7452
        my $delta = $endposn - $startposn;
7453
        if ( $delta < 8 )
7454
        {
7455
            $scount = $delta;
7456
            last;
7457
        }
7458
 
7459
    }
7460
    return ( "\t" x $tcount .  ' ' x $scount );
7461
}
7462
 
7463
#-------------------------------------------------------------------------------
7464
# Function        : MakeEntry3
7465
#
7466
# Description     : Build a makefile entry based on the element list, tab aligned
7467
#                   Can creat text of the form:
7468
#                       TAG = NAME0 \       TAG : NAME0 \ 
7469
#                             NAME1               NAME1
7470
#
7471
#
7472
# Inputs          : $prelim             - Preliminary text
7473
#                   $presep             - Preliminary seperator
7474
#                   $elem_ref           - Either a single name or a reference to
7475
#                                         and array of names, or a hash.
7476
#
7477
# Returns         : Writes directly to the Makefile
7478
#
7479
sub MakeEntry3
7480
{
7481
    my( $prelim, $presep, $elem_ref ) = @_;
7482
 
7483
    #
7484
    #   The prelim may have some "\n" characters at the start
7485
    #   These simplify formatting, but mess up the nice formatting
7486
    #
7487
    if ($prelim =~ m~(^\n+)(.*)~ )
7488
    {
7489
        MakePrint $1;
7490
        $prelim = $2;
7491
    }
7492
 
7493
    #
7494
    #   Print the definition and the sep with nice padding
7495
    #
7496
    MakePadded ( 3, $prelim, $presep );
7497
    my $leadin = ' ';
7498
 
7499
    #
7500
    #   If a HASH reference then use a sorted list of keys from the hash.
7501
    #
7502
    if ( ref ($elem_ref) eq "HASH" )
7503
    {
7504
        my @hash_list;
7505
        @hash_list = sort keys ( %{$elem_ref} );
7506
        $elem_ref = \@hash_list;
7507
    }
7508
 
7509
    #
7510
    #   If the list is only one element long, then create a simple form
7511
    #   If the list is not an array ref, then treat it as a single element
7512
    #
7513
    if ( ref ($elem_ref) eq "ARRAY" )
7514
    {
7515
        my $line = 0;
7516
        foreach my $element ( @$elem_ref )
7517
        {
7518
            print MAKEFILE $leadin . $element;
7519
            $leadin = " \\\n" . PadToPosn(0,24 + length( $presep ) + 1 ) unless ($line++);
7520
        }
7521
    }
7522
    elsif ( defined $elem_ref )
7523
    {
7524
            print MAKEFILE $leadin . $elem_ref;
7525
    }
7526
    MakeNewLine();
7527
    return 1;
7528
}
7529
 
7530
#-------------------------------------------------------------------------------
7531
# Function        : MakeDefEntry
7532
#
7533
# Description     : Make a definition entry of the form
7534
#
7535
#                       TAG = NAME0 \
7536
#                             NAME1
7537
#
7538
#                   Support a list of definitions that will always be created
7539
#                   as well as a production and a debug list.
7540
#
7541
#                   Will always generate the "TAG = " string, even if the list
7542
#                   is empty.
7543
#
7544
#                   Will supress the TAG if there is no data if the FIRST opr starts with a '+'
7545
#
7546
# Inputs          : TAG         - Text tag to create
7547
#                   FIRST       - First assignement opr. = or +=
7548
#                   ALL_LIST    - A reference to a list of names to assign
7549
#                                 or a single name.
7550
#                   PROD_LIST   - Optional list to extend the definition with for a production build
7551
#                   DEBUG_LIST  - Optional list to extend the definition with for a debug build
7552
#
7553
# Returns         : Nothing
7554
#
7555
 
7556
sub MakeDefEntry
7557
{
7558
    my( $tag, $assign, $all, $prod, $debug ) = @_;
7559
 
7560
    #
7561
    #   Do not generate anything if the $opr is "+=" and there is no data
7562
    #   to output. ie: Supress empty TAG += statements
7563
    #
7564
    return if ( $assign =~ m/\+/ && ( ref($all) && ! defined $all->[0] ) );
7565
 
7566
    #
7567
    #   TAG for all entries
7568
    #
7569
    MakeEntry3( $tag, $assign, $all );
7570
 
7571
 
7572
    #
7573
    #   TAGs for PROD build
7574
    #   TAGs for DEBUG build
7575
    #
7576
    if ( defined $prod && defined $prod->[0] )
7577
    {
7578
        print MAKEFILE 'ifeq "$(DEBUG)" "0"' . "\n";
7579
        MakeEntry3( $tag, "+=", $prod );
267 dpurdie 7580
        print MAKEFILE 'endif' . "\n";
227 dpurdie 7581
    }
7582
 
7583
    if ( defined $debug && defined $debug->[0] )
7584
    {
7585
        print MAKEFILE 'ifeq "$(DEBUG)" "1"' . "\n";
7586
        MakeEntry3( $tag, "+=", $debug );
267 dpurdie 7587
        print MAKEFILE 'endif' . "\n";
227 dpurdie 7588
    }
7589
 
7590
}
7591
 
7592
sub MakeIfDefEntry
7593
{
7594
    my( $iftag, @rest ) = @_;
7595
 
7596
    print MAKEFILE "ifdef $iftag\n";
7597
    MakeDefEntry (@rest);
7598
    print MAKEFILE "endif\n\n";
7599
}
7600
 
7601
sub MakeIfnDefEntry
7602
{
7603
    my( $iftag, @rest ) = @_;
7604
 
7605
    print MAKEFILE "ifndef $iftag\n";
7606
    MakeDefEntry (@rest);
7607
    print MAKEFILE "endif\n\n";
7608
}
7609
 
261 dpurdie 7610
sub MakeIfZeroEntry
7611
{
7612
    my( $iftag, @rest ) = @_;
7613
 
7614
    print MAKEFILE "ifeq (\$($iftag),0)\n";
7615
    MakeDefEntry (@rest);
7616
    print MAKEFILE "endif\n\n";
7617
}
7618
 
227 dpurdie 7619
#-------------------------------------------------------------------------------
7620
# Function        : CreateNameList
7621
#
7622
# Description     : Create a list of names by adding a prefix and suffix to a
7623
#                   list of items. This is used to add a directory prefix and a
7624
#                   file suffix to a list of files.
7625
#
7626
# Inputs          : $prefix             ie: '$(OBJDIR)/'
7627
#                   $suffix             ie: '.obj'
7628
#                   $elem_ref           ie: A list of files ( passed be ref )
7629
#                                           If a Hash then its sorted keys is used
7630
#
7631
# Returns         : A ref to the resulting list
7632
#
7633
sub CreateNameList
7634
{
7635
    my( $prefix, $suffix, $elem_ref ) = @_;
7636
    my @result;
7637
 
7638
    if ( ref ($elem_ref) eq "HASH" )
7639
    {
7640
        my @hash_list;
7641
        @hash_list = sort keys ( %{$elem_ref} );
7642
        $elem_ref = \@hash_list;
7643
    }
7644
 
7645
    foreach  ( @$elem_ref )
7646
    {
7647
        push @result, $prefix . $_ . $suffix;
7648
    }
7649
    return \@result;
7650
}
7651
 
7652
#-------------------------------------------------------------------------------
7653
# Function        : ListGeneratedProjects
7654
#
7655
# Description     : Return a list of generated/nongenerated projects
7656
#                   Used in conjunction with CreateNameList
7657
#
7658
# Inputs          : $type       - TRUE : Generated
7659
#                                 FALSE: Not Generated
7660
#
7661
# Returns         : A reference to a list of projects
7662
#                   undef will be retuend if there are no projects
7663
#
7664
sub ListGeneratedProjects
7665
{
7666
    my ($type) = @_;
7667
    my @list;
7668
    foreach my $project ( @PROJECTS_ORDER )
7669
    {
7670
        if ( exists($PROJECTS{$project}->{'generated'}) xor $type )
7671
        {
7672
            push @list, $project;
7673
        }
7674
    }
7675
    return @list ? \@list : undef;
7676
}
7677
 
7678
#-------------------------------------------------------------------------------
7679
# Function        : ListCleanGenerated
7680
#
7681
# Description     : return a list of generated targets that have 'clean'
7682
#                   operations. This is used in conjunction with CreateNameList
7683
#
7684
# Inputs          : None
7685
#
7686
# Returns         : A list of project indexes, that can be cleaned
7687
#
7688
sub ListCleanGenerated
7689
{
7690
    my @list;
7691
    foreach my $i ( @GENERATE_FILES )
7692
    {
7693
        push @list, $i->{'index'}
7694
            if ( $i->{'clean'} );
7695
    }
7696
    return \@list;
7697
}
7698
 
251 dpurdie 7699
#-------------------------------------------------------------------------------
7700
# Function        : MakeResolve
7701
#
7702
# Description     : Internal Function
7703
#                   Locate a source file by examining a list of directories
7704
#
7705
#                   Don't use directly
7706
#                   Use MakeSrcResolve or MakeSrcResolveExtended
7707
#
7708
# Inputs          : $dirs           - Ref to an array of directories to scan
7709
#                   $source         - File to locate
7710
#
7711
# Returns         : Resolved path to the file
7712
#                   Will warn if multiple instances of the file are found
7713
#
227 dpurdie 7714
sub MakeResolve
7715
{
7716
    my( $dirs, $source ) = @_;
285 dpurdie 7717
    my( $first, $count );
227 dpurdie 7718
 
237 dpurdie 7719
    #
7720
    #   If the path contains a '$' then its assumed to be
7721
    #   a variable name in the path. Just assume that it exists
7722
    #
7723
    return $source if ( $source =~ m#\$# );
7724
 
7725
    #
7726
    #   If the path is absolute or contains a leading ., then don't search
7727
    #   Warn if it can't be found
7728
    #
7729
    if ( $source =~ m#^(/|\.)# )
7730
    {
7731
        Warning( "Unable to resolve '$source' path" ) unless -f $source;
7732
        return $source;
227 dpurdie 7733
    }
7734
 
237 dpurdie 7735
 
227 dpurdie 7736
#.. search local path first
7737
#
7738
    $count = 0;
7739
    $first = "";
331 dpurdie 7740
    $first = "$source"                              # was ./$source
227 dpurdie 7741
        if (-r "$source");
7742
 
7743
#.. search directory paths
7744
#
285 dpurdie 7745
    foreach my $dir (@$dirs)
227 dpurdie 7746
    {
331 dpurdie 7747
        next if ( $dir eq '.' );
7748
        my $temp = "$dir/$source";                  # was ./$dir/$source
227 dpurdie 7749
        Debug2( "MakeResolve: Looking in: $temp" );
7750
        if (-r "$temp")
7751
        {
7752
            if ($first eq "") {
7753
                $first = $temp;
7754
            } else {
7755
                Warning( "Duplicate '$source' image - '$temp'" );
7756
                $count++;
7757
            }
7758
        }
7759
        Debug3( "MakeResolve: $count, $temp" );
7760
    }
7761
 
7762
    if ($first eq "") {
7763
        $first = $source;
7764
        Warning( "Unable to resolve '$source' path" );
7765
    } else {
7766
        Warning( "          using '$first'" )
7767
            if ($count);
7768
    }
7769
    return $first;
7770
}
7771
 
251 dpurdie 7772
#-------------------------------------------------------------------------------
7773
# Function        : MakeSrcResolve
7774
#
7775
# Description     : Locate a source file by examining the list of source
7776
#                   directories. There are a few frills
7777
#
7778
#                   Look for a source file in
7779
#                       1) %::BUILD_KNOWNFILES
7780
#                       2) %SRCS
7781
#                       3) Dirs specified by the array @SRCSDIRS
7782
#
7783
# Inputs          : Name of a file to resolve
7784
#
7785
# Returns         : Resolved path.
283 dpurdie 7786
#                   Input file - if not found at all
251 dpurdie 7787
#
227 dpurdie 7788
sub MakeSrcResolve
7789
{
7790
    my ($name) = @_;
7791
    my $file;
7792
 
251 dpurdie 7793
    if ( exists ( $::BUILD_KNOWNFILES{$name} ) ) {
7794
        #
7795
        #   The Known Files list is relative to ScmRoot
7796
        #   This must be included in the full path
7797
        #
7798
        $file = $ScmRoot . '/' . $::BUILD_KNOWNFILES{$name};
7799
 
7800
    } elsif ( exists $SRCS{$name} ) {
7801
        $file = $SRCS{$name};
7802
 
7803
    } else {
7804
        $file = MakeResolve( \@SRCDIRS, @_ )
7805
    }
227 dpurdie 7806
    return $file;
7807
}
7808
 
7809
 
7810
# MakeSrcResolveExtended
7811
#   from_global = 0 : Search user specified directories
7812
#               = 1 : Search LinkPkgArchive list
7813
#
7814
our @PkgSrcDirList;
7815
sub MakeSrcResolveExtended
7816
{
7817
    my ( $from_global, $file ) = @_;
7818
 
7819
    #
7820
    #   Simple Case. Resolve source from known source directories
7821
    #
7822
    #
7823
    return MakeSrcResolve( $file )
7824
        unless ( $from_global );
7825
 
7826
    #
7827
    #   Not so simple Case
7828
    #   Resolve the source from the imported packages
7829
    #
7830
    #   Create a list of directores to search, but only the first time
311 dpurdie 7831
    #       - Interface directories - from BuildPkgArchive
227 dpurdie 7832
    #       - LnkPkgArchive directories
7833
    #         Using target,product,platform include directories
7834
    #
7835
    unless ( @PkgSrcDirList )
7836
    {
7837
        for my $entry (@{$::ScmBuildPkgRules{$ScmPlatform} })
7838
        {
311 dpurdie 7839
            next if ( $entry->{'TYPE'} eq 'build' ); # Ignore BuildPkgArchives
7840
 
227 dpurdie 7841
            for (@{$entry->{'PINCDIRS'}}, @{$entry->{'THXDIRS'}}, '' )
7842
            {
7843
                my $dir = $entry->{'ROOT'} . "/" . $_ ;
7844
                $dir =~ s~//~/~g;
7845
                $dir =~ s~/$~~;
311 dpurdie 7846
                push ( @PkgSrcDirList, $dir );
227 dpurdie 7847
            }
7848
        }
311 dpurdie 7849
    }
227 dpurdie 7850
 
7851
    return MakeResolve( \@PkgSrcDirList, $file );
7852
}
7853
 
7854
#-------------------------------------------------------------------------------
7855
# Function        : GetPackageRoot
7856
#
7857
# Description     : Determine the root directory for a given package
7858
#                   This routine is intended for non-standard JATS scripts that
7859
#                   access package contents directly
7860
#
7861
#                   Note: This routine does not attempt to handle multiple
7862
#                         instances of a package ( sysbasetypes ).
7863
#
7864
# Inputs          : $pname          - Name of the package
7865
#
7866
# Returns         :
7867
#
7868
sub GetPackageRoot
7869
{
7870
    my( $pname ) = @_;
7871
    Debug( "GetPackageRoot(@_)" );
7872
 
7873
    my $result = undef;
7874
    my $pkg = GetPackageEntry( $pname );
7875
    if ( $pkg )
7876
    {
7877
        $result = $pkg->{'ROOT'};
7878
        Debug( "GetPackageRoot: $result" );
7879
    }
7880
 
7881
    return $result;
7882
}
7883
 
7884
#-------------------------------------------------------------------------------
7885
# Function        : ActiveProject
7886
#
7887
# Description     : Determine if the specified project is currenly 'active'
7888
#
345 dpurdie 7889
# Inputs          : $project            - one or more project names separated
7890
#                                         by either a comma or a colon
227 dpurdie 7891
#
7892
# Returns         : TRUE    if the project is active
7893
#
7894
sub ActiveProject
7895
{
7896
    my ($project) = @_;
345 dpurdie 7897
    foreach (  split( '\s*[:,]\s*', $project ) )
227 dpurdie 7898
    {
7899
        return 1
7900
            if ( $_ eq $::ScmBuildProject );
7901
    }
7902
    return 0;
7903
}
7904
 
345 dpurdie 7905
#-------------------------------------------------------------------------------
7906
# Function        : ActiveDefine
7907
#
7908
# Description     : Determine if the specified definition is currenly 'active'
7909
#
7910
# Inputs          : $defs               - one or more variable names separated
7911
#                                         by either a comma or a colon
7912
#
7913
# Returns         : TRUE    if any of the definitions are known
7914
#
7915
sub ActiveDefine
7916
{
7917
    my ($defs) = @_;
7918
    no strict 'refs';
7919
    foreach (  split( '\s*[:,]\s*', $defs ) )
7920
    {
7921
        return 1
7922
            if ( defined( $$_ ) || defined( @$_ ) );
7923
    }
7924
    use strict 'refs';
7925
    return 0;
7926
}
227 dpurdie 7927
 
7928
#-------------------------------------------------------------------------------
345 dpurdie 7929
# Function        : ActiveMachType
7930
#
7931
# Description     : Determine if the specified MachType is currenly 'active'
7932
#
7933
# Inputs          : $mtype              - one or more machine names separated
7934
#                                         by either a comma or a colon
7935
#
7936
# Returns         : TRUE    if any of the current MachType is in the list
7937
#
7938
sub ActiveMachType
7939
{
7940
    my ($mtype) = @_;
7941
    foreach (  split( '\s*[:,]\s*', $mtype ) )
7942
    {
7943
        return 1
7944
            if ( uc($_) eq uc($::GBE_MACHTYPE) );
7945
    }
7946
    return 0;
7947
}
7948
 
7949
#-------------------------------------------------------------------------------
227 dpurdie 7950
# Function        : ActivePlatform
7951
#
7952
# Description     : Determine if the specified platform is currently 'active'
7953
#                   This is used by all user directives in order to determine
7954
#                   if the directive should be ignored for the current platform
7955
#
7956
# Inputs          : $platform_spec      - A platform specifier
7957
#                                         This is a bit complex.
7958
#
241 dpurdie 7959
#                   Format of platform_spec. One or more of
7960
#                       PlatformName
7961
#                       AliasName
7962
#                       TargetName,--Target
345 dpurdie 7963
#                   Special Options (Must all be True)
7964
#                       --Project=ProjectName[:ProjectName]+
7965
#                       --Defined=SomeValue[:SomeValue]+
7966
#                       --MachType=SomeValue[:SomeValue]+
7967
 
7968
#                   Each can be prefixed with a '!' to negate the test
227 dpurdie 7969
#
241 dpurdie 7970
#                   Valid options are:
271 dpurdie 7971
#                       --Target        - indicates that the platform is a 'target'
241 dpurdie 7972
#
7973
# Returns         : TRUE if the platform spec is satisfied
7974
#
227 dpurdie 7975
sub ActivePlatform
7976
{
7977
    my( $platform_spec ) = @_;
7978
    my( @platforms, $scmplatform, $platform );
7979
    my( %arguments, @args, $filter );
241 dpurdie 7980
    my @plist;
7981
    my ($match_count, $count_invert, $count_vert) = (0,0,0);
227 dpurdie 7982
 
241 dpurdie 7983
    #
7984
    #   Short circuit check
7985
    #   '*' is used so often that it pays to check it first
7986
    #
7987
    if ( $platform_spec eq '*' )
7988
    {
7989
        Debug3( " ActivePlatform(@_) = TRUE" );
7990
        return 1;
7991
    }
227 dpurdie 7992
 
241 dpurdie 7993
    #
7994
    #   Platform specifier may be a comma seperated list
7995
    #   ie:  WIN32,MOS,XXX
7996
    #   Extract non-platform arguments
279 dpurdie 7997
    #   Process to yield a dummy platform of '0' or '1' - these will be seen later
241 dpurdie 7998
    #
7999
    foreach ( split( '\s*,\s*', $platform_spec ) )
8000
    {
345 dpurdie 8001
        my ($result, $not);
8002
        if ( m~^(!?)--Project=(.+)~ ) {
325 dpurdie 8003
            $not = $1;
345 dpurdie 8004
            $result = ActiveProject($2);
277 dpurdie 8005
 
345 dpurdie 8006
        } elsif ( m~^(!?)--Defined=(.+)~ ) {
325 dpurdie 8007
            $not = $1;
345 dpurdie 8008
            $result = ActiveDefine($2);
241 dpurdie 8009
 
345 dpurdie 8010
        } elsif ( m~^(!?)--MachType=(.+)~ ) {
325 dpurdie 8011
            $not = $1;
345 dpurdie 8012
            $result = ActiveMachType($2);
8013
 
325 dpurdie 8014
        } else {
8015
            #
8016
            #   Must be a platform argument
8017
            #   Add to a list
8018
            #
8019
            push @platforms, $_;
241 dpurdie 8020
            next;
8021
        }
8022
 
8023
        #
325 dpurdie 8024
        #   Continue processing non-platform arguments
345 dpurdie 8025
        #   Each one must be TRUE, allowing for negation.
241 dpurdie 8026
        #
325 dpurdie 8027
        $result = $result ? 1 : 0;
345 dpurdie 8028
        $result = ! $result if ( $not );
8029
        return 0 unless ( $result );
241 dpurdie 8030
    }
8031
 
4128 dpurdie 8032
    #
8033
    #   If we have no platforms then the test was purely non-platform arguments.
8034
    #   
8035
    #
8036
    if ($platform_spec ne '' && ! @platforms)
8037
    {
8038
        return 1;
8039
    }
8040
 
241 dpurdie 8041
    #   Platform specified may be an Alias
8042
    #   Perform alias expansion
8043
    #
8044
    @platforms = ExpandPlatforms( @platforms );         # aliasing
227 dpurdie 8045
    Debug3( " ActivePlatform(@_)" );
325 dpurdie 8046
#    Debug0( " Platforms(@platforms)", "PLIST(@plist)" );
227 dpurdie 8047
 
8048
#.. Arguments
241 dpurdie 8049
#   At this point we have a list of platforms and arguments
8050
#   Build up a hash of arguments for each platform being parsed
227 dpurdie 8051
#   Multiple arguments can follow a platform name
241 dpurdie 8052
#   Arguments apply to the preceeding platform name
227 dpurdie 8053
#
241 dpurdie 8054
    $platform = undef;
227 dpurdie 8055
    foreach ( @platforms )
8056
    {
241 dpurdie 8057
        if ( /^--Target/ ) {                     # Arguments
8058
            if ( $platform ) {
8059
                $arguments{$platform}{'Target'} = 1;
8060
            } else {
317 dpurdie 8061
                Warning ("No Platform preceding platform option: $_");
241 dpurdie 8062
            }
8063
 
305 dpurdie 8064
        } elsif ( /^--Only(Prod)|(Debug)/ || /--board=/ ) {
273 dpurdie 8065
            # Known arguments
305 dpurdie 8066
            # Bit of a kludge. Must be a better way
273 dpurdie 8067
 
241 dpurdie 8068
        } elsif ( /^--/ ) {
8069
            Warning ("Unknown platform option: $_");
8070
 
227 dpurdie 8071
        } else {                                # Target
8072
            $platform = $_;
241 dpurdie 8073
            push @plist, $platform;
227 dpurdie 8074
        }
8075
    }
8076
 
241 dpurdie 8077
#.. Scan the expression
227 dpurdie 8078
#
8079
    $scmplatform = uc( $ScmPlatform );          # current platform
325 dpurdie 8080
 
241 dpurdie 8081
    foreach ( @plist )
227 dpurdie 8082
    {
8083
        $platform = uc( Trim( $_ ) );           # trim white and convert case
8084
 
8085
        #
241 dpurdie 8086
        #   Determine filter comparison
8087
        #   Either a Platform or a Target
8088
        #
8089
        if ( $arguments{$platform}{'Target'} )
227 dpurdie 8090
        {
241 dpurdie 8091
            $filter = uc( $ScmTarget );
227 dpurdie 8092
        }
241 dpurdie 8093
        else
8094
        {
8095
            $filter = $scmplatform;             # filter specification
8096
        }
8097
 
227 dpurdie 8098
        Debug3( "   Platform=$platform, Filter=$filter" );
8099
 
8100
        #
8101
        #   Examine platform names
8102
        #   Allow negation of name (!), but all the names must be negated
8103
        #   as a mix does not make sense.
8104
        #   ie:     !P1,!P2,!P3     - All except P1,P2 or P3
8105
        #            P1,P2,P2       - Only P1,P2,P3
8106
        #
241 dpurdie 8107
        my $invert = 0;
8108
        if ( substr($platform, 0, 1) eq '!' )
8109
        {
8110
            $count_invert++;
8111
            $platform = substr($platform, 1);
227 dpurdie 8112
        }
8113
        else
241 dpurdie 8114
        {
8115
            $count_vert++;
8116
        }
227 dpurdie 8117
 
241 dpurdie 8118
        $match_count++ if ( $platform eq ''  ||
8119
                            $platform eq '*' ||
8120
                            $platform eq '1' ||
8121
                            $platform eq $filter );
227 dpurdie 8122
    }
8123
 
241 dpurdie 8124
    #
8125
    #   Sanity test
8126
    #   Force failure on bad sanity
8127
    #
8128
    if ( $count_vert && $count_invert )
8129
    {
8130
        Warning( "Platform expression makes no sense. Mixed use of '!' operator",
8131
                 "Expression: @_" );
8132
        return 0;
8133
    }
8134
 
8135
    #
8136
    #   Test for pass
8137
    #   If not using '!', then any match passes : P1 or P2 or P3
8138
    #   If are using '!', then any match is bad : !P1 and !P2 and !P3 == !(P1 or P2 or P3)
8139
    #
8140
    if ( ( $count_vert && $match_count ) || ( $count_invert && ( not $match_count) )   )
8141
    {
227 dpurdie 8142
        Debug3( " ActivePlatform(@_ == $ScmPlatform) = TRUE" );
8143
        return 1;
8144
    }
241 dpurdie 8145
 
227 dpurdie 8146
    Debug3( " ActivePlatform(@_ == $ScmPlatform) = FALSE" );
8147
    return 0;
8148
}
8149
 
8150
#-------------------------------------------------------------------------------
321 dpurdie 8151
# Function        : If
8152
#
8153
# Description     : Function for embedding arguments in directives
8154
#                   To be used within another directive
8155
#                   ie:
8156
#                       AnyDirective ('*',  arg1, arg2, ...
8157
#                                           If (SomePlatform, arg1, .. ,argn))
8158
#
8159
# Inputs          : $platform               - Active Platform speciifier
8160
#                   @args                   - Args
8161
#
8162
# Returns         : @args or nothing
8163
#
8164
sub  If
8165
{
8166
    my $platform = shift;
8167
    return @_
8168
        if ( ActivePlatform( $platform ));
8169
    return;
8170
}
8171
 
8172
#-------------------------------------------------------------------------------
227 dpurdie 8173
# Function        : RegisterMakefileGenerate
8174
#
8175
# Description     : Register a function to be called at the start of the
8176
#                   makefile generation process
8177
#
8178
# Inputs          : $fname      - Name of the function
8179
#                   $args       - Function Arguments
8180
#
8181
# Returns         : Nothing
8182
#
8183
our @MF_Generators;
8184
sub RegisterMakefileGenerate
8185
{
8186
   my ($fref) = @_;
8187
   my $rtype = ref($fref) || 'not a reference';
8188
 
8189
   Error ("RegisterMakefileGenerate called incorrectly",
8190
          "First argument MUST be a code reference",
8191
          "It is a $rtype"
8192
          ) unless ( $rtype eq 'CODE' );
8193
 
8194
   #
8195
   #    Save the arguments by reference in an array
8196
   #    The array will be processed later
8197
   #
8198
   push @MF_Generators, \@_;
8199
}
8200
 
8201
#-------------------------------------------------------------------------------
271 dpurdie 8202
# Function        : RegisterSrcHook
8203
#
8204
# Description     : Register a function to be called when a source file is
8205
#                   declared
8206
#
8207
# Inputs          : $ext        - Extension of interest
8208
#                                 '*' will be used by all
8209
#                   $fname      - Name of the function
8210
#                   $args       - Function Arguments
8211
#
8212
# Returns         : Nothing
8213
#
8214
sub RegisterSrcHook
8215
{
8216
    my $ext = shift;
8217
    my ($fref) = @_;
8218
    my $rtype = ref($fref) || 'not a reference';
8219
 
8220
    Error ("RegisterSrcHook called incorrectly",
8221
           "Second argument MUST be a code reference",
8222
           "It is a $rtype"
8223
           ) unless ( $rtype eq 'CODE' );
8224
 
8225
    #
8226
    #    Save the arguments by reference in an array
8227
    #    The array will be processed later
8228
    #
8229
    push @{$MF_RegisterSrcHooks{$ext}}, \@_;
8230
}
8231
 
8232
 
8233
#-------------------------------------------------------------------------------
227 dpurdie 8234
# Function        : MakefileHeader
8235
#
8236
# Description:    : Generate a "standard" makefile header.
8237
#
8238
#..
8239
 
8240
sub MakefileHeader
8241
{
8242
    my ($file, $desc, $by, @trailing) = @_;
8243
    my ($diff);
8244
 
8245
    $diff = 0 if (($diff = ((80-5) - length($desc))) < 0);
8246
    $desc .= ' ' . ('-' x $diff);
8247
 
8248
    print $file <<EOF;
8249
#-- $desc
8250
#
8251
#                   -- Please do not edit this file. --
8252
#
8253
#       To do so may result in a system failure, in additional to any
8254
#       changes made shall be overwritten.
8255
#
8256
# Created by $by
8257
#         on $::CurrentTime
8258
#
8259
EOF
8260
    #
8261
    #   Print out the trailer
8262
    #   This is an array. Place each entry on a new line
8263
    #
8264
    print $file $_ . "\n" for ( @trailing );
8265
}
8266
 
8267
###############################################################################
8268
# MakeFileGenerate:
8269
#       This subroutine does all of the actual make file generation based
8270
#       on information provided in the calls to the various public
8271
#       interface routines.
8272
#
8273
# Inputs:
8274
#
8275
# Returns:
8276
###############################################################################
8277
 
8278
my $MakefileGenerate_once = 0;
8279
sub MakefileGenerate
8280
{
8281
    my $Makefile = "$ScmPlatform.mk";
8282
    Debug( "MakefileGenerate: $Makefile" );
8283
 
8284
    #
8285
    #   Nasty things happen when we generate a makefile twice
8286
    #   Just warn the user and do nothing
8287
    #   If its in the common makefile.pl then just ignore it
8288
    #
8289
    if ( $ScmProcessingRootMake )
8290
    {
8291
        Warning ("MakefileGenerate directive is not allowed in common makefile.pl");
8292
        return;
8293
    }
8294
 
8295
    if ( $MakefileGenerate_once )
8296
    {
8297
        Warning ("MakefileGenerate should only be called once.",
8298
                 "Dir: $::Cwd");
8299
        return;
8300
    }
8301
    $MakefileGenerate_once = 1;
8302
 
8303
    #
8304
    #   Invoke all registered Makefile Generator functions
8305
    #   These allow clever directives to collect information to be
8306
    #   processed before the makefiles are created
8307
    #
8308
    while ( @MF_Generators )
8309
    {
8310
        Debug( "MakefileGenerate: Invoke RegisterMakefileGenerate function" );
8311
        my ($fname, @args) = @{shift @MF_Generators};
8312
        &$fname ( @args );
8313
    }
8314
 
8315
    #
8316
    #   Allow the toolset the opportunity to process all the collected data
8317
    #   before the makefile is created. This is optional
8318
    #
8319
    my( $if ) = MakeIf::Factory();              # build interface
8320
    $if->Preprocess();
8321
 
8322
    #
343 dpurdie 8323
    #   If we have supressed the Toolset use, then we need to sanity test
8324
    #   the use of the toolset
8325
    #
8326
    if ( $ScmNoToolsTest )
8327
    {
8328
        ReportError ("Building programs not supported with --NoToolset") if ( @PROGS || @TESTPROGS );
8329
        ReportError ("Building libraries not supported with --NoToolset") if ( @LIBS || @MLIBS || @SHLIBS );
8330
        ReportError ("Building projects not supported with --NoToolset") if ( %PROJECTS );
8331
        ErrorDoExit();
8332
    }
8333
 
8334
    #
227 dpurdie 8335
    #   Auto package the 'descpkg' file
8336
    #   If this makefile packages any files, then it can also package the descpkg file
8337
    #   The descpkg will be piggybacked into all makefiles that do a package
8338
    #
8339
    if ( %PACKAGE_FILES || %PACKAGE_HDRS || %PACKAGE_CLSS || %PACKAGE_LIBS
8340
                        || %PACKAGE_SHLIBS || %PACKAGE_PROGS )
8341
    {
251 dpurdie 8342
        Src ('*', 'descpkg') unless ($SRCS{ descpkg });
8343
        PackageFile ('*', 'descpkg');
227 dpurdie 8344
    }
8345
 
8346
    #
8347
    #   Some toolsets NEED a relative root
261 dpurdie 8348
    #   Note: At the moment ScmRoot is relative anyway, thus this code
8349
    #         does nothing
227 dpurdie 8350
    #
8351
    my $gbe_root = $::ScmRoot;
8352
    if ( $::UseRelativeRoot )
8353
    {
8354
        $gbe_root =  RelPath( $::ScmRoot );
8355
    }
8356
 
8357
    #
8358
    #   Now start to create the makefile
8359
    #
3967 dpurdie 8360
    ::ToolsetFile ($Makefile);
285 dpurdie 8361
    open( MAKEFILE, '>', $Makefile ) || Error( "Cannot create $Makefile" );
227 dpurdie 8362
    ::MakefileHeader( *MAKEFILE,
8363
                      'Auto-generated Platform Dependent Makefile',
8364
                      "$ScmMakelib (version $ScmVersion)",
343 dpurdie 8365
                      "# Copyright (C) 1995-$::CurrentYear Vix-ERG, All rights reserved",
227 dpurdie 8366
                      '#',
8367
                      "# Located in $::Cwd",
8368
                      "# Platform $::ScmPlatform",
8369
                      '#' . ('-' x 79),
8370
                      );
8371
 
8372
    #
8373
    #   Ensure that some essential variables are set
8374
    #
8375
    print MAKEFILE <<EOF;
8376
#
8377
#   Validate essential environment variables
8378
#
8379
ifndef GBE_BIN
8380
    \$(error ERROR: GBE_BIN is not available)
8381
endif
8382
ifndef GBE_PERL
8383
    \$(error ERROR: GBE_PERL is not available)
8384
endif
8385
ifndef DEBUG
8386
    \$(error ERROR: DEBUG is not defined)
8387
endif
8388
EOF
8389
 
8390
 
8391
    print MAKEFILE <<EOF;
8392
 
8393
#
8394
#   Basic definitions
8395
#
343 dpurdie 8396
GBE_ROOT      := $gbe_root
8397
GBE_ROOT_ABS  := \$(abspath \$(GBE_ROOT))
8398
GBE_HOST      := $::ScmHost
8399
GBE_HOSTMACH  := $::GBE_MACHTYPE
8400
GBE_TARGET    := $::ScmTarget
8401
GBE_MACHTYPE  := $::ScmMachType
8402
GBE_PLATFORM  := $::ScmPlatform
8403
GBE_PBASE     := $::Pbase
8404
GBE_TYPE      := \$(if \$(findstring 1,\$(DEBUG)),D,P)
227 dpurdie 8405
EOF
8406
 
343 dpurdie 8407
MakePrint( "GBE_ARGS      := @ScmPlatformArgs\n" )
227 dpurdie 8408
    if ( scalar @ScmPlatformArgs );
8409
 
343 dpurdie 8410
MakePrint( "GBE_PRODUCT   := $ScmProduct\n" )
227 dpurdie 8411
    if ( $ScmProduct ne "" );
8412
 
343 dpurdie 8413
MakePrint( "GBE_OS_COMMON := $::BUILDINFO{$ScmPlatform}{OS_COMMON}\n" )
227 dpurdie 8414
    if ( exists($::BUILDINFO{$ScmPlatform}{OS_COMMON}) );
8415
 
8416
 
8417
    print MAKEFILE <<EOF;
8418
 
8419
SHELL           := \$(GBE_BIN)/sh
8420
SHELLARGS       :=
8421
EXTENDED_LINE   := \$(GBE_BIN)/extend.lst
8422
export EXTENDED_LINE MAKE
8423
 
343 dpurdie 8424
MFLAGS           := --no-print --warn -r
8425
BUILDNAME        := $::ScmBuildName
8426
BUILDVER         := $::ScmBuildVersionFull
8427
BUILDVERNUM      := $::ScmBuildVersion
227 dpurdie 8428
BUILDPREVIOUSVER := $::ScmBuildPreviousVersion
343 dpurdie 8429
DEPLOYPATCH      := $ScmDeploymentPatch
8430
GBE_NOTOOLSTEST  := $ScmNoToolsTest
227 dpurdie 8431
 
8432
#
8433
#   Ensure PWD is correctly set
8434
#
8435
PWD             := \$(CURDIR)
8436
export PWD
8437
 
261 dpurdie 8438
#
8439
#   NODEPEND    - Used to suppress generated dependency file checking
8440
#                 Mostly done in jmake.pl
8441
#   EXPERT      - Used to suppress dependency on this makefile
8442
#
8443
EOF
8444
 
285 dpurdie 8445
MakePrint( "EXPERT\t\t?= " . ($ScmExpert ? '1' : '0' ) . "\n" );
8446
MakePrint( "NODEPEND\t?= 0\n" );
261 dpurdie 8447
 
8448
print MAKEFILE <<EOF;
8449
 
8450
#
8451
#   SCM_MAKEFILE - The name of the file to depend upon
8452
#                  Supressed in EXPERT mode
8453
#
8454
ifneq (\$(EXPERT),0)
8455
SCM_MAKEFILE	:=
8456
else
8457
SCM_MAKEFILE	:= $Makefile
8458
endif
8459
EOF
8460
 
267 dpurdie 8461
#
8462
#   Setup the base directory for the packaging process
8463
#   When building a deployable package the base directory is changed to match
8464
#   that used by the deployment world. This is done so that the descpkg file
8465
#   can be created in the correct location
8466
#
8467
my  $PKGDIR = "pkg/$::Pbase";
8468
    $PKGDIR = "build/deploy" if ( $DEPLOYPACKAGE );
8469
Verbose("Setting PKGDIR: $PKGDIR");
8470
 
261 dpurdie 8471
print MAKEFILE <<EOF;
8472
 
227 dpurdie 8473
#--------- Targets -------------------------------------------------------------
8474
 
8475
.PHONY: 	default all build install package unpackage uninstall \\
8476
		clean unbuild clobber deploy
8477
 
373 dpurdie 8478
default:
227 dpurdie 8479
all:		install package deploy
8480
build:		make_init generate install_hdr depend make_lib \\
8481
		install_lib make_install_shlib make_prog install_class
8482
install:	build install_prog
8483
package:	package_files package_hdr package_lib package_shlib package_prog \\
8484
		package_class
8485
unpackage:	unpackage_class unpackage_prog unpackage_shlib \\
8486
		unpackage_lib unpackage_hdr unpackage_files
8487
uninstall:	uninstall_class uninstall_prog uninstall_shlib \\
8488
		uninstall_lib uninstall_hdr
8489
clean:		make_clean unmake_prog unmake_test unmake_lib unobj \\
261 dpurdie 8490
		undepend ungenerate rmlitter unmake_dir
227 dpurdie 8491
unbuild:	clean uninstall
8492
clobber:	unpackage unbuild
8493
deploy:		install run_deploy
8494
 
8495
#--------- Macros --------------------------------------------------------------
8496
 
8497
OBJDIR		= \$(GBE_PLATFORM)\$(GBE_TYPE).OBJ
8498
LIBDIR		= \$(GBE_PLATFORM).LIB
8499
BINDIR		= \$(GBE_PLATFORM)\$(GBE_TYPE).BIN
8500
CLSDIR		= classes\$(GBE_TYPE)
8501
 
267 dpurdie 8502
PKGDIR		= \$(GBE_ROOT)/$PKGDIR
227 dpurdie 8503
INCDIR_PKG	= \$(PKGDIR)/include
8504
LIBDIR_PKG	= \$(PKGDIR)/lib
8505
BINDIR_PKG	= \$(PKGDIR)/bin
8506
CLSDIR_PKG	= \$(PKGDIR)/classes
8507
 
8508
LOCALDIR	= \$(GBE_ROOT)/local
8509
INCDIR_LOCAL	= \$(LOCALDIR)/inc
8510
LIBDIR_LOCAL	= \$(LOCALDIR)/lib
8511
BINDIR_LOCAL	= \$(LOCALDIR)/bin
8512
CLSDIR_LOCAL	= \$(LOCALDIR)/classes
8513
BINDIR_LOCAL_PATH = \$(GBE_ROOT_ABS)/local/bin/\$(GBE_PLATFORM)\$(GBE_TYPE)
8514
 
8515
INTERFACEDIR	= \$(GBE_ROOT)/$ScmInterface
8516
INCDIR_INTERFACE= \$(INTERFACEDIR)/include
8517
LIBDIR_INTERFACE= \$(INTERFACEDIR)/lib
8518
BINDIR_INTERFACE= \$(INTERFACEDIR)/bin
8519
CLSDIR_INTERFACE= \$(INTERFACEDIR)/classes
8520
 
8521
.SUFFIXES:		# Delete the default suffixes
8522
 
8523
EOF
8524
 
8525
    MakePrintList( \@DEFINES );
8526
    MakeNewLine();
8527
 
8528
#-------------------------------------------------------------------------------
8529
#
8530
#
261 dpurdie 8531
    MakeHeader ("Defines, flags and file sets");
227 dpurdie 8532
 
8533
    # Flags
261 dpurdie 8534
    foreach my $opt ( keys %ScmCompilerOpts )
8535
    {
8536
        MakeDefEntry ( $opt, "=", $ScmCompilerOpts{$opt} );
8537
    }
227 dpurdie 8538
 
261 dpurdie 8539
    MakeDefEntry( "CFLAGS",         "=", \@CFLAGS, \@CFLAGS_PROD, \@CFLAGS_DEBUG );
8540
    MakeDefEntry( "CLINTFLAGS",     "=", \@CLINTFLAGS, \@CLINTFLAGS_PROD, \@CLINTFLAGS_DEBUG );
8541
    MakeDefEntry( "CDEPENDFLAGS",   "=", \@CFLAGS, \@CFLAGS_PROD, \@CFLAGS_DEBUG );
8542
    MakeDefEntry( "CXXFLAGS",       "=", \@CXXFLAGS, \@CXXFLAGS_PROD, \@CXXFLAGS_DEBUG );
8543
    MakeDefEntry( "CXXLINTFLAGS",   "=", \@CXXLINTFLAGS, \@CXXLINTFLAGS_PROD, \@CXXLINTFLAGS_DEBUG );
8544
    MakeDefEntry( "CXXDEPENDFLAG",  "=", \@CXXFLAGS, \@CXXFLAGS_PROD, \@CXXFLAGS_DEBUG );
267 dpurdie 8545
    MakeDefEntry( "ASFLAGS",        "=", \@ASFLAGS, \@ASFLAGS_PROD, \@ASFLAGS_DEBUG );
8546
    MakeDefEntry( "LDFLAGS",        "=", \@LDFLAGS, \@LDFLAGS_PROD, \@LDFLAGS_DEBUG );
227 dpurdie 8547
 
8548
 
8549
#-------------------------------------------------------------------------------
8550
#   
8551
#
261 dpurdie 8552
    MakeHeader ("Tool Search Path",
8553
                "Extend the PATH seen by all the tools to include",
8554
                "The tools/bin directories discovered in Packages" );
8555
    my $put_PATH;
8556
    my $put_LD_LIBRARY_PATH;
8557
    for my $path ( ToolExtensionPaths() )
8558
    {
8559
        MakePrint( "PATH := $path$::ScmPathSep\$(PATH)\n" );
8560
        $put_PATH = 1;
227 dpurdie 8561
 
261 dpurdie 8562
        if ( $::ScmHost eq "Unix" )
8563
        {
227 dpurdie 8564
        MakePrint( "LD_LIBRARY_PATH ?= \n" );
8565
        MakePrint( "LD_LIBRARY_PATH := $path$::ScmPathSep\$(LD_LIBRARY_PATH)\n" );
261 dpurdie 8566
            $put_LD_LIBRARY_PATH =1;
8567
        }
227 dpurdie 8568
    }
8569
 
261 dpurdie 8570
    #   Export the appropriate environment variables
8571
    #   Note: Windows has an issue with PATH and Path
8572
    #         Haven't got to the bottom of it yet, but it would appear that DLL
8573
    #         searching uses Path and other stuff uses PATH. Not too sure how we
8574
    #         end up with two (or more in the environment)
8575
    #
8576
    #
8577
    if ( $put_LD_LIBRARY_PATH )
8578
    {
343 dpurdie 8579
        MakePrint( "export LD_LIBRARY_PATH\n" );
261 dpurdie 8580
    }
227 dpurdie 8581
 
261 dpurdie 8582
    if ( $put_PATH )
8583
    {
343 dpurdie 8584
        MakePrint( "Path := \$(PATH)\n" );
8585
        MakePrint( "export PATH Path\n" );
261 dpurdie 8586
    }
227 dpurdie 8587
 
8588
#-------------------------------------------------------------------------------
8589
#   
8590
#
261 dpurdie 8591
    MakeHeader ("Perl Module Search Path",
8592
                "Extend the PERL5LIB seen by invocations of perl");
227 dpurdie 8593
 
261 dpurdie 8594
    my $perl_module_found;
8595
    for my $path ( ToolExtensionPaths() )
227 dpurdie 8596
    {
261 dpurdie 8597
        if (glob( "$path/*.pm"))
8598
        {
227 dpurdie 8599
        MakePrint( "PERL5LIB := $path$::ScmPathSep\$(PERL5LIB)\n" );
261 dpurdie 8600
            $perl_module_found = 1;
8601
        }
227 dpurdie 8602
    }
261 dpurdie 8603
    if ( $perl_module_found  )
8604
    {
227 dpurdie 8605
    MakePrint( "export PERL5LIB\n" );
261 dpurdie 8606
    }
227 dpurdie 8607
 
261 dpurdie 8608
#-------------------------------------------------------------------------------
8609
#   Internal Helper Functions
8610
#   Creating INCLUDE and LIBRARY paths
8611
#
8612
 
8613
# Assist in creating a list paths
8614
#   $pList  - Reference to an array to which $data will be added
8615
#   $pSeen  - Hash Ref to track tags that have been seen
8616
#   $data   - Data item to add, if tag is defined, but not seen
8617
#   $tag    - Resolved name for item
8618
#
227 dpurdie 8619
    sub PushPath
8620
    {
8621
        my ($pList, $pSeen, $data, $tag) = @_;
8622
        if ( $tag )
8623
        {
8624
            unless ( exists $pSeen->{$tag} )
8625
            {
8626
                $pSeen->{$tag} = 1;
8627
                push @{$pList}, $data;
8628
            }
8629
        }
8630
    }
8631
 
8632
    #
8633
    # Search paths for include files and libraries
8634
    # Currently symbolic paths are created, but there is very little need for this
8635
    #
8636
    sub MakePaths
8637
    {
8638
        my( $root ) = @_;
8639
        my @pathlist;
8640
        my %seen;
8641
 
8642
        #
379 dpurdie 8643
        #   Interface and Local directories are now treated quite
8644
        #   diffently. The Local is under our control.
227 dpurdie 8645
        #
8646
        if ( $root =~ /INTERFACE/ ) {
379 dpurdie 8647
 
8648
            #   eg. SCA_WIN32   and SCA_WIN32       and SCA_SOLARIS
8649
            #       SCA             WIN32_i386          SPARC
8650
            #       WIN32           SCA                 SCA
8651
            #       .               WIN32               SOLARIS
8652
            #                       .                   .
8653
            #..
8654
 
8655
            #
8656
            #   For Interface Path List use the 'PARTS' as calculated within
8657
            #   the build file. Its good enough for everthing else in JATS
8658
            #
8659
            foreach ( @{$::BUILDINFO{$ScmPlatform}{PARTS}} ) {
227 dpurdie 8660
                PushPath( \@pathlist, \%seen, "$root/$_",   $_ );
8661
            }
8662
        }
379 dpurdie 8663
        else
8664
        {
8665
            #
8666
            #   Local directory
8667
            #   The user can (should) only install stuff into a few known
8668
            #   locations.
8669
            #
8670
            foreach ( $ScmPlatform, $ScmProduct, $ScmTarget ) {
8671
                PushPath( \@pathlist, \%seen, "$root/$_",   $_ );
8672
            }
8673
        }
227 dpurdie 8674
 
379 dpurdie 8675
        #
8676
        #   Add OS Common Directory
8677
        ### May need more testing before being added
8678
        #
8679
        #if ( exists($::BUILDINFO{$ScmPlatform}{OS_COMMON}) )
8680
        #{
8681
        #    my $os_common = $::BUILDINFO{$ScmPlatform}{OS_COMMON};
8682
        #    PushPath( \@pathlist, \%seen, "$root/$os_common", $os_common );
8683
        #}
227 dpurdie 8684
 
379 dpurdie 8685
        #
8686
        #   Add the root directory too
8687
        #
227 dpurdie 8688
        push @pathlist, "$root";
8689
        return \@pathlist;
8690
    }
379 dpurdie 8691
 
227 dpurdie 8692
 
8693
#-------------------------------------------------------------------------------
8694
#   
8695
#
261 dpurdie 8696
    MakeHeader ("Include Search Paths",
367 dpurdie 8697
                "Package Include Paths for header files and libraries" );
227 dpurdie 8698
 
367 dpurdie 8699
    MakeDefEntry( 'PINCDIRS', '=', '# includes');
8700
    MakeDefEntry( 'PLIBDIRS', '=', '# libraries');
8701
 
8702
    for my $package (@{$::ScmBuildPkgRules{$ScmPlatform} })
8703
    {
8704
        #
8705
        #   Skip the pseudo package that encapsulates the interface
8706
        #   directory. Currently the makefiles do this in a different
8707
        #   manner - to be resolved
8708
        #
8709
        #   Just comment out the lines so that the data is visible
8710
        #   Its a hint to make use of the data
8711
        #
8712
        my $prefix = '';
8713
        $prefix = '# ' if ( $package->{'TYPE'} eq 'interface' );
8714
        $prefix = '# ' if ( $package->{'TYPE'} eq 'build' );
8715
 
8716
 
8717
        my $name = $package->{'NAME'} . '/' . $package->{'VERSION'};
8718
        my $base = $package->{'ROOT'};
8719
 
1329 dpurdie 8720
        my @doc;
8721
        push (@doc, "From: $base");
8722
        push (@doc, 'BuildPkgArchive via Interface' )if $package->{'TYPE'} eq 'build' ;
8723
        push (@doc, 'Is Interface' ) if $package->{'TYPE'} eq 'interface' ;
367 dpurdie 8724
 
1329 dpurdie 8725
        MakeHeader ("Source: $name", @doc);
8726
 
367 dpurdie 8727
        #
8728
        #   List include and library directories
8729
        #   Note: Need the True Path for windows.
8730
        #       Some makefile functions (wildcard) only work as expected
8731
        #       if the case of the pathname is correct. Really only a problem
8732
        #       with badly formed legecy packages where the Windows user
8733
        #       guessed at the package format.
8734
        #
8735
        #       The conversion to a TruePath is done when ScmBuildPkgRules
8736
        #       is created. Create one, use many time.
8737
        #
8738
        #
8739
        for my $type (qw (PINCDIRS PLIBDIRS) )
8740
        {
8741
            for my $path ( @{$package->{$type}} )
8742
            {
8743
                MakeDefEntry ( "$prefix$type", "+=", $base . $path);
8744
            }
8745
        }
8746
    }
8747
 
8748
#-------------------------------------------------------------------------------
8749
#   
8750
#
8751
    MakeHeader ("Include Search Paths",
8752
                "Local Include Paths",
8753
                " LINKDIRS - Local include search path (short)",
8754
                " INCDIRS  - Include search path (complete)",
8755
                " NODEPDIRS - ",
8756
                " SRCDIRS - ",
8757
                " LIBDIRS - Library search path",
8758
 
8759
                );
8760
 
227 dpurdie 8761
    # Include search path
8762
    #
8763
    #   user-local
367 dpurdie 8764
    #   local
8765
    #   interface
8766
    #       BuildPkgArchive
8767
    #       LinkPkgArchive
227 dpurdie 8768
    #   user-global
8769
    #
8770
 
367 dpurdie 8771
    MakeDefEntry ( "\nLINCDIRS",    "= ", \@L_INCDIRS );     # .. Local
261 dpurdie 8772
    MakeDefEntry ( "LINCDIRS",      "+=", MakePaths( '$(INCDIR_LOCAL)' ));     # .. Sandbox interface
8773
    MakeDefEntry ( "LINCDIRS",      "+=", MakePaths( '$(INCDIR_INTERFACE)' )); # .. Sandbox interface
8774
    MakeDefEntry ( "LINCDIRS",      "+=", \@G_INCDIRS );    # .. Global
227 dpurdie 8775
 
367 dpurdie 8776
    MakeDefEntry ( "INCDIRS",  "= ", '$(LINCDIRS)' );               # Local
8777
    MakeDefEntry ( "INCDIRS",  "+=", '$(PINCDIRS)' );               # Package
8778
    MakeDefEntry ( "LINCDIRS", "+=", \@S_INCDIRS );                 # System
227 dpurdie 8779
 
8780
    # Source search path
8781
 
261 dpurdie 8782
    MakeDefEntry( "\nNODEPDIRS",        "=", \@NODEPDIRS );
227 dpurdie 8783
 
367 dpurdie 8784
    MakeDefEntry( "\nSRCDIRS","= "  , [ @L_SRCDIRS, @G_SRCDIRS ] ); # Local
8785
    MakeDefEntry ( "SRCDIRS", "+=" , '$(PINCDIRS)' );               # Package
8786
    MakeDefEntry ( "SRCDIRS", "+=" , \@S_INCDIRS );                 # System
227 dpurdie 8787
 
8788
    # Library search path
8789
    #
8790
    #   user-local
367 dpurdie 8791
    #   local
8792
    #   interface
8793
    #       BuildPkgArchive
8794
    #       LinkPkgArchive
227 dpurdie 8795
    #   user-global
8796
 
367 dpurdie 8797
    MakeDefEntry( "\nLIBDIRS",  "= ", '$(LIBDIR)' );                    # User Local
261 dpurdie 8798
    MakeDefEntry( "LIBDIRS",    "+=", \@L_LIBDIRS );                    # Local
8799
    MakeDefEntry( "LIBDIRS",    "+=", MakePaths( '$(LIBDIR_LOCAL)' ));  # Sandbox/interface
8800
    MakeDefEntry( "LIBDIRS",    "+=", MakePaths( '$(LIBDIR_INTERFACE)' ));
8801
    MakeDefEntry( "LIBDIRS",    "+=", \@G_LIBDIRS );                    # Global
367 dpurdie 8802
    MakeDefEntry( "LIBDIRS",    "+=", '$(PLIBDIRS)' );                  # Package
261 dpurdie 8803
    MakeDefEntry( "LIBDIRS",    "+=", \@S_LIBDIRS );                    # System
227 dpurdie 8804
 
8805
#-------------------------------------------------------------------------------
8806
#
8807
#   Subdir creation and deletion
8808
#   Creation is done on the fly
8809
#   Deletion is done AFTER the toolset functions have been invoked to create the
8810
#   build artifacts so that the toolsets can create directories too
8811
 
8812
    MakeHeader ("Subdir creation");
8813
    CreateMkdirRules();
2429 dpurdie 8814
    MkdirRule( '$(OBJDIR)', 'OBJDIR', '--Extra=depend,depend.err' );  # Object build directory
8815
    MkdirRule( '$(OBJDIR)/'.$_ ) foreach (@SHLIBS);                     # Shared library build directory
8816
    MkdirRule( '$(LIBDIR)', 'LIBDIR' );                                 # Library directory
8817
    MkdirRule( '$(BINDIR)', 'BINDIR' );                                 # Binary directory
227 dpurdie 8818
 
261 dpurdie 8819
    #
8820
    #   Create a directory for library merge tool to work within
8821
    #
8822
    MkdirRule( "\$(MLIBDIR)", 'MLIBDIR', '--Path=$(GBE_PLATFORM).MRG', '--RemoveAll' ) if (@MLIBS);
8823
 
227 dpurdie 8824
#-------------------------------------------------------------------------------
8825
#   Generate rules and recipes to create all the toolset specific parts
8826
#   This is done fairly early to allow the toolsets to extend various
8827
#   definitions that may be used later in the makefile construction
8828
#
8829
    MakeHeader ("Construct Programs");
8830
 
8831
    foreach my $i ( @PROGS )
8832
    {
289 dpurdie 8833
        my $pProg = $PROGS->Get($i);
8834
        my $pArgs = $pProg->getItems('ARGS');
8835
        my $pObjs = $pProg->getItems('OBJS');
8836
        my $pLibs = $pProg->getItems('LIBS');
227 dpurdie 8837
 
289 dpurdie 8838
        #
8839
        #   Create a list of program object files
8840
        #
8841
        push @PROGOBJS, @$pObjs;
227 dpurdie 8842
 
8843
        MakePrint( "#---- (${i})\n\n" );
8844
        if ( $ScmToolsetProgDependancies )
8845
        {
261 dpurdie 8846
            #
8847
            #   Original style Prog Interface
271 dpurdie 8848
            #   Write some dependency information here and some in the toolset
8849
            #   Problems:
8850
            #       1) Errors in library dependency generation will be
8851
            #          reported after all the object files have been created
8852
            #          Thus the error message and the make-stop are seperated
8853
            #          by many,many lines of output. This makes it difficult
8854
            #          to see the error.
261 dpurdie 8855
            #
271 dpurdie 8856
            #       2) Lack of Flexability
8857
            #
293 dpurdie 8858
            MakeEntry( "\$(BINDIR)/$i$::exe: ", "", "\\\n\t\t", ".$::o ", @$pObjs );
227 dpurdie 8859
        }
8860
        else
8861
        {
261 dpurdie 8862
            #
8863
            #   New Style Prog Interface
8864
            #   The toolset does it all
8865
            #
8866
            #   Flag the progam packaging as a placeholder.
8867
            #   The toolset will replace/update it.
8868
            #
227 dpurdie 8869
            PackageProgRemoveFiles( $i );
8870
        }
8871
 
289 dpurdie 8872
        $if->LD    ( $i, $pArgs, $pObjs, $pLibs );
8873
        $if->LDLINT( $i, $pArgs, $pObjs, $pLibs );
227 dpurdie 8874
    }
8875
 
8876
#-------------------------------------------------------------------------------
8877
#   
8878
#
8879
    MakeHeader ("Construct Test Programs");
289 dpurdie 8880
    foreach my $i ( @TESTPROGS )
227 dpurdie 8881
    {
289 dpurdie 8882
        my $pProg = $TESTPROGS->Get($i);
8883
        my $pArgs = $pProg->getItems('ARGS');
8884
        my $pObjs = $pProg->getItems('OBJS');
8885
        my $pLibs = $pProg->getItems('LIBS');
227 dpurdie 8886
 
289 dpurdie 8887
        #
8888
        #   Create a list of program object files
8889
        #
8890
        push @TESTPROGOBJS, @$pObjs;
8891
 
227 dpurdie 8892
        MakePrint( "#---- (${i})\n\n" );
8893
        if ( $ScmToolsetProgDependancies )
8894
        {
293 dpurdie 8895
            MakeEntry( "\$(BINDIR)/$i$::exe: ", "", "\\\n\t\t", ".$::o ", @$pObjs );
227 dpurdie 8896
        }
8897
        else
8898
        {
8899
            PackageProgRemoveFiles( $i );
8900
        }
8901
 
289 dpurdie 8902
        $if->LD    ( $i, $pArgs, $pObjs, $pLibs );
8903
        $if->LDLINT( $i, $pArgs, $pObjs, $pLibs );
227 dpurdie 8904
    }
8905
 
8906
#-------------------------------------------------------------------------------
8907
#
8908
#
8909
    MakeHeader ("Transfer Scripts to BINDIR");
8910
    foreach my $i ( sort ( values %SCRIPTS ))
8911
    {
8912
        my $tname = "\$(BINDIR)/" . StripDir( $i );
8913
 
8914
 
8915
        MakePrint( "$i:\t\tmakefile.pl\n" .
261 dpurdie 8916
            "\t\$(XX_PRE)if [ ! -f \"$i\" ]; then echo Script [$i] not found; exit 2; fi\n\n" );
227 dpurdie 8917
 
8918
        #
8919
        #   Create a rule to copy the script into the BIN directory
8920
        #   Mark the script as executable - It can't hurt and its there
8921
        #   to be run as part of a test.
8922
        #
8923
        MakePrint "$tname:\t\$(GBE_BINDIR) $i\n" .
8924
                  "\t\$(XX_PRE)\$(cp) -f $i $tname\n" .
8925
                  "\t\$(XX_PRE)\$(chmod) -f +wx $tname\n\n"
8926
    }
8927
 
8928
#-------------------------------------------------------------------------------
8929
#   
8930
#
8931
    MakeHeader ("Construct Libraries");
8932
    foreach my $i ( @LIBS )
8933
    {
289 dpurdie 8934
        my $pLib  = $LIBS->Get($i);
8935
        my $pArgs = $pLib->getItems('ARGS');
8936
        my $pObjs = $pLib->getItems('OBJS');
227 dpurdie 8937
 
363 dpurdie 8938
        unless ( $ScmToolsetNillLibSrc )
8939
        {
8940
            Error ("Library has no component objects: $i")
8941
                if ( scalar @$pObjs <= 0 );
8942
        }
299 dpurdie 8943
 
227 dpurdie 8944
        MakePrint "#---- (${i})\n\n";
289 dpurdie 8945
        $if->AR(     $i, $pArgs, $pObjs, $pLib);
8946
        $if->ARLINT( $i, $pArgs, $pObjs, $pLib );
227 dpurdie 8947
    }
8948
 
289 dpurdie 8949
#-------------------------------------------------------------------------------
8950
#   
8951
#
8952
    MakeHeader ("Construct Merged Libraries");
227 dpurdie 8953
    sub MlibEntry
8954
    {
289 dpurdie 8955
        my( $mlib, $plib, $pLibs ) = @_;
227 dpurdie 8956
        my @flib;
8957
 
289 dpurdie 8958
        MakePrint '$(LIBDIR)/' . GenLibName($mlib) . ":";
8959
        foreach my $lib ( @$pLibs )
227 dpurdie 8960
        {
289 dpurdie 8961
            #
8962
            #   Each library name may contains one embedded option which
8963
            #   specifies the source directory
8964
            #       libname[,--Option | BaseSubdir]
8965
            #
227 dpurdie 8966
            my ($slib, $sdir) = split( ',', $lib );
343 dpurdie 8967
            my $mode;
227 dpurdie 8968
 
8969
            #
283 dpurdie 8970
            #   By default the librares are pulled from LOCAL unless the
8971
            #   library is built in this directory, in which case it will
289 dpurdie 8972
            #   be used.
227 dpurdie 8973
            #
289 dpurdie 8974
            $sdir = ( $LIBS->Get($slib) ) ? '--Here' : '--Local'
8975
                unless ( $sdir );
227 dpurdie 8976
 
8977
            #
8978
            #   --Interface     - Pull library from the interface directory
8979
            #   --Local         - Pull library from the local directory
8980
            #   --SubDir=xxxx   - Pull library from specified subdirectory
283 dpurdie 8981
            #   --Here          - Pull from local directory if built locally
227 dpurdie 8982
            #   otherwise       - Pull library from specified subdirectory
8983
            #
8984
            if ($sdir eq '--Interface') {
8985
                $sdir = '$(LIBDIR_INTERFACE)/$(GBE_PLATFORM)';
8986
 
343 dpurdie 8987
 
8988
            } elsif ($sdir eq '--InterfacePlain') {
8989
                $sdir = '$(LIBDIR_INTERFACE)/$(GBE_PLATFORM)';
8990
                $mode = 1;
8991
 
227 dpurdie 8992
            } elsif ( $sdir eq '--Local') {
8993
                $sdir = $PackageInfo{'Lib'}{'IBase'} .  # Base of Installed libs
8994
                        $PackageInfo{'Lib'}{'Dir'};     # Default subdir
8995
 
8996
            } elsif ( $sdir =~ m~^--SubDir=(.*)~ ) {
8997
                $sdir = $1 . '/$(LIBDIR)';
8998
 
283 dpurdie 8999
            } elsif ( $sdir eq '--Here') {
9000
                $sdir = '$(LIBDIR)';
9001
 
227 dpurdie 9002
            } else {
9003
                $sdir .= '/$(LIBDIR)';
9004
            }
9005
 
343 dpurdie 9006
            MakePrint " \\\n\t\t${sdir}/" . GenLibName($slib, $mode);
227 dpurdie 9007
            push @flib, "${sdir}/${slib}";
9008
        }
289 dpurdie 9009
        return \@flib;
227 dpurdie 9010
    }
9011
 
9012
    foreach my $i ( @MLIBS )
9013
    {
289 dpurdie 9014
        my $pLib  = $MLIBS->Get($i);
9015
        my $pArgs = $pLib->getItems('ARGS');
9016
        my $pLibs = $pLib->getItems('LIBS');
227 dpurdie 9017
 
261 dpurdie 9018
        MakePrint "#---- (${i})\n\n";
9019
 
227 dpurdie 9020
        unless ( defined &ToolsetARMerge )
9021
        {
9022
            Warning( "Merging of libraries not supported in this toolset yet" );
9023
            Warning( "MergeLibrary: \"$i\" will not be created" );
9024
        }
9025
        else
9026
        {
9027
            #
9028
            #   Create the dependency rule
9029
            #       Target library : source library list
9030
            #           Recipe - generated by the toolset
9031
            #
289 dpurdie 9032
            foreach ( @$pArgs )
227 dpurdie 9033
            {
9034
                Warning( "Ignoring unknown argument to MergeLibrary. $_" );
9035
            }
289 dpurdie 9036
            $pLibs = MlibEntry( $i, $pLib, $pLibs );
9037
            $if->ARMerge( $i, $pArgs, $pLibs, $pLib );
227 dpurdie 9038
        }
9039
    }
9040
 
289 dpurdie 9041
#-------------------------------------------------------------------------------
9042
#   
9043
#
9044
    MakeHeader ("Construct Shared Libraries");
339 dpurdie 9045
 
227 dpurdie 9046
    foreach my $i ( @SHLIBS )
9047
    {
289 dpurdie 9048
        my $pShlib  = $SHLIBS->Get($i);
9049
        my $pArgs = $pShlib->getItems('ARGS');
9050
        my $pObjs = $pShlib->getItems('OBJS');
9051
        my $pLibs = $pShlib->getItems('LIBS');
9052
        my $version = $pShlib->{VERSION};
227 dpurdie 9053
 
289 dpurdie 9054
        $if->SHLD    ( $i, $pArgs, $pObjs, $pLibs, $version );
9055
        $if->SHLDLINT( $i, $pArgs, $pObjs, $pLibs, $version );
227 dpurdie 9056
    }
9057
 
9058
#-------------------------------------------------------------------------------
9059
#   Construct Objects
9060
#   For each object within OBJSOURCE construct the following:
9061
#
9062
#   $(OBJDIR)/object-name:     source-name [makefile]
9063
#       Toolset ...
9064
#
9065
#   
9066
#
9067
    MakeHeader ("Construct Objects");
371 dpurdie 9068
 
227 dpurdie 9069
    foreach my $i ( sort keys %OBJSOURCE )
9070
    {
9071
        my( $src, $sname, $ext, $type, @args );
9072
 
9073
        $src  = $OBJSOURCE{ $i };
9074
        $sname = StripDir( $src );
9075
        $ext  = StripFile( $src );
9076
        $ext = lc($ext)
9077
            if ( $::ScmHost ne "Unix" );
381 dpurdie 9078
        $type = ($ScmSourceTypes{ $ext } || '')
227 dpurdie 9079
            unless (( $type = $SRC_TYPE{ $sname }) );
9080
 
9081
        #
9082
        #   Object source is an object file
9083
        #   No need the generate the object, just create makefile rule
261 dpurdie 9084
        #   [ddp] Not too sure how we get here
227 dpurdie 9085
        #
9086
        if ( $ext eq ".$::o" )
9087
        {
9088
            MakePrint "$src:";
261 dpurdie 9089
            MakePrint " \$(SCM_MAKEFILE)";
227 dpurdie 9090
            MakeNewLine();
9091
            next;
9092
        }
9093
 
9094
        #
9095
        #   Need to create object file
9096
        #
9097
        @args = split( /$;/, $SRC_ARGS{ StripDir( $sname ) } )
9098
            if $SRC_ARGS{ $sname };
9099
 
9100
        push( @args, "--Shared" )
9101
            if ( exists $SHOBJ_LIB{$i} );
9102
 
9103
        #
9104
        #   Convert relative paths to absolute paths if required by the
9105
        #   toolset. Some compilers need ABS paths to generate nice debug
9106
        #   information.
9107
        #
9108
        $src = AbsPath($src)
9109
            if ( $UseAbsObjects );
9110
 
9111
        #
9112
        #   Extract any user specified dependancies
261 dpurdie 9113
        #   These will be added to the dependency list
227 dpurdie 9114
        #
9115
        my @dlist;
9116
        @dlist = split( /$;/, $SRC_DEPEND{$sname} )
9117
            if ( exists $SRC_DEPEND{$sname} );
9118
 
261 dpurdie 9119
        #
9120
        #   Create the dependency part of the object rule
9121
        #   The source file MUST be the first dependent recipes
9122
        #   may assume that $< is the name source file
9123
        #
9124
        MakeEntry( "\$(OBJDIR)/$i.$::o: $src \$(SCM_MAKEFILE)", "", " \\\n\t", "", @dlist );
227 dpurdie 9125
 
9126
        if ( $type eq ".c" ) {
9127
            $if->CC(  $src, $i, \@args );
261 dpurdie 9128
 
227 dpurdie 9129
        } elsif ( $type eq ".cc" ) {
9130
            $if->CXX( $src, $i, \@args );
261 dpurdie 9131
 
227 dpurdie 9132
        } elsif ( $type eq ".asm" ) {
9133
            $if->AS( $src, $i, \@args );
261 dpurdie 9134
 
227 dpurdie 9135
        } else {
9136
            $if->EXT( $src, $i, \@args ) ||
9137
                Warning( "Don't know how to build '$ext' images' for $src, $i" );
9138
            MakeNewLine();
9139
        }
9140
    }
9141
 
9142
#-------------------------------------------------------------------------------
9143
#   Construct Projects
9144
#   Construct toolset specific projects
9145
#
9146
    MakeHeader ("Construct Projects");
9147
    while ( my($project, $entry) = each %PROJECTS)
9148
    {
9149
        $if->PROJECT( $entry );
9150
    }
9151
 
9152
#-------------------------------------------------------------------------------
9153
#   Automated tests
9154
#
9155
    MakeHeader ("Automated tests");
9156
 
9157
    my $idx = 0;
4095 dpurdie 9158
    my @test_set;
9159
    my @test_set_auto;
227 dpurdie 9160
    my @copy_set = ();
9161
 
9162
    foreach my $pEntry ( @TESTS_TO_RUN )
9163
    {                                           # Foreach test
9164
        $idx++;
9165
        $pEntry->{'index'} = $idx;
9166
        $pEntry->{'test_name'} = "run_test_$idx";
9167
 
9168
        #
9169
        #   If the test is being run within a 'FrameWork' then the underlying
9170
        #   toolset must instantiate the frame work.
9171
        #
9172
        #   This may change. Perhaps frameworks shouldn't be a part of the
9173
        #   toolset. Perhaps they should be standalone. May change
9174
        #
9175
        if ( $pEntry->{framework} )
9176
        {
9177
            $if->TESTFRAMEWORK( $pEntry );
9178
        }
9179
 
9180
        #
9181
        #   Create a rule to run the test
9182
        #
9183
 
9184
        my $tdir_alias = $pEntry->{'testdir'};
9185
        my $tdir = '$(' . $tdir_alias . ')';
9186
 
9187
        my $test_name = $pEntry->{'test_name'};
9188
        push @test_set, $test_name;
9189
        push @test_set_auto, $test_name if ($pEntry->{'auto'} );
9190
 
9191
        my $tprog = $tdir . '/' . StripDir( $pEntry->{'prog'} );
9192
 
9193
        my $me = MakeEntry::New( *MAKEFILE, $test_name, '--Phony' );
9194
        $me->AddDependancy( "\$(GBE_$tdir_alias)" );
9195
        $me->AddDependancy( "\$(INTERFACEDIR)/set_$::ScmPlatform.sh" );
9196
        $me->AddDependancy( $tprog ) if $pEntry->{'copyprog'};
9197
        $me->AddDependancy( @{ $pEntry->{'copyin' } } );
9198
        $me->AddDependancy( map { $tdir . '/' . StripDir($_) } @{ $pEntry->{'copyonce' } } );
9199
        $me->AddDependancy( @{ $pEntry->{'preq'} } );
9200
        $me->RecipePrefix ('$(XX_PRE)');
9201
        $me->RecipeComment( "------ Running test [$idx] ..." );
9202
 
9203
        #
9204
        #   Extend the PATH seen by the script to include the local/bin directory
9205
        #   Allows programs and tests that have been created elsewhere in the component
9206
        #   to be accessed within the script.
9207
        #
9208
        $me->AddShellRecipe ( ". \$(INTERFACEDIR)/set_$::ScmPlatform.sh" );
9209
 
9210
        #
9211
        #   Copy in the files that we need
9212
        #
9213
        foreach my $file ( @{$pEntry->{'copyin'}} )
9214
        {
9215
            my $dst = $tdir . '/' . StripDir( $file );
9216
            UniquePush( \@COPYIN, $dst );
9217
            UniquePush( \@copy_set, $file );
9218
            $me->AddShellRecipe ( "\$(cp) -f $file $dst" );
9219
            $me->AddShellRecipe ( "\$(chmod) -f +wx $dst" );
9220
        }
9221
 
9222
        #
9223
        #   Insert and FrameWork Recipe bits
9224
        #
9225
        $me->AddShellRecipe ( @{$pEntry->{'ShellRecipe'}} );
9226
 
9227
        $me->AddShellRecipe ( "cd $tdir" );
9228
        $me->AddShellRecipe ( ["GBE_TYPE=\$(GBE_TYPE)",
9229
                               "GBE_HOST=\$(GBE_HOST)",
9230
                               "GBE_ROOT=\$(GBE_ROOT_ABS)",
4095 dpurdie 9231
                               "PATH=.\\$::ScmPathSep\$(BINDIR_LOCAL_PATH)\\$::ScmPathSep\$\$PATH",
227 dpurdie 9232
                               $pEntry->{'command'},
9233
                               @{$pEntry->{'args'}},
9234
                               ] );
9235
        $me->Print();
9236
 
9237
 
9238
        #
9239
        #   Create entries to handle the copy-once files
9240
        #
9241
        foreach my $file ( @{ $pEntry->{'copyonce' } } )
9242
        {
9243
            my $tname = $tdir . '/' . StripDir($file);
9244
            my $me = MakeEntry::New( *MAKEFILE, $tname  );
9245
            $me->AddDependancy( $file );
9246
            $me->AddRecipe ( "\$(call CopyFile,CopyIn,$tname,$file,$tdir,)"  );
9247
            $me->Print();
9248
 
9249
            UniquePush( \@COPYIN, $tname );
9250
            UniquePush( \@copy_set, $file );
9251
 
9252
        }
9253
    }
9254
 
9255
    #
9256
    #   Generate a target that specifies the tests to be run
9257
    #   Each test is provided with a dummy name
9258
    #
9259
    push @test_set, @TESTPROJECT_TO_ARUN;
9260
    push @test_set, @TESTPROJECT_TO_URUN;
4095 dpurdie 9261
    if (@test_set)
9262
    {
9263
        unshift @test_set, 'makefile.pl';
9264
        MakeEntry3("\nrun_tests", ":", \@test_set );
9265
    }
227 dpurdie 9266
 
9267
    push @test_set_auto, @TESTPROJECT_TO_ARUN;
4095 dpurdie 9268
    if (@test_set_auto)
9269
    {
9270
        unshift @test_set_auto, 'makefile.pl';
9271
        MakeEntry3("\nrun_unit_tests", ":", \@test_set_auto );
9272
    }
227 dpurdie 9273
 
9274
    #
9275
    #   Generate sanity test for each copyin script
9276
    #   Simply to provide a nice error message for generated scripts
9277
    #   that do not exist at run-time
9278
    #
9279
    test_copy_in:
9280
    foreach my $i ( @copy_set )
9281
    {
9282
        next if ( $SCRIPTS{$i} );
9283
        foreach (  @SHLIB_TARGETS )
9284
        {
9285
            next test_copy_in if ( $i eq $_ );
9286
        }
9287
        MakePrint( "\n$i:\t\tmakefile.pl\n" .
9288
            "\t\@if [ ! -f \"$i\" ]; then echo ERROR: CopyIn Script [$i] not found; exit 2; fi\n" );
9289
    }
9290
 
261 dpurdie 9291
#-------------------------------------------------------------------------------
9292
#   Deploy rules
9293
#
9294
MakeHeader ("Deploy Rules");
227 dpurdie 9295
 
261 dpurdie 9296
print MAKEFILE <<EOF;
9297
.PHONY:		run_deploy
9298
EOF
227 dpurdie 9299
 
261 dpurdie 9300
#
9301
#   Build up the deployfile.pl command line from the available pieces
9302
#
9303
my $command_file = "";
9304
my @command_line;
9305
 
9306
if ( %DEPLOYPACKAGE )
9307
{
9308
    $command_file = $DEPLOYPACKAGE{'cmdfile'};
9309
 
9310
    push @command_line, "\$(XX_PRE)\$(GBE_PERL) -w $command_file";
9311
    push @command_line, "-r \"\$(GBE_ROOT)\"";
9312
    push @command_line, "-n \"$DEPLOYPACKAGE{'name'}\"";
9313
    push @command_line, "-d \"$DEPLOYPACKAGE{'dir'}\"";
9314
    push @command_line, "-v \"\$(BUILDVER)\"";
9315
    push @command_line, "-t \"\$(GBE_TYPE)\"";
9316
    push @command_line, "-o \"\$(BUILDPREVIOUSVER)\"";
9317
    push @command_line, "-m \"\$(GBE_PLATFORM)\"";
9318
    push @command_line, "-g \"\$(GBE_TARGET)\"";
9319
    push @command_line, "-k \"\$(GBE_PRODUCT)\""        if ( $ScmProduct );
9320
    push @command_line, "-p \"\$(DEPLOYPATCH)\""        if ( $ScmDeploymentPatch );
9321
 
9322
}
9323
 
9324
MakeEntry( "run_deploy:\t$command_file\n", "\n", "\t\t", " \\\n", @command_line );
9325
 
227 dpurdie 9326
#-------------------------------------------------------------------------------
261 dpurdie 9327
#   Custom Rules
9328
#
9329
    MakeHeader ("Custom Rules");
9330
    MakePrintList ( \@RULES );
9331
 
9332
#-------------------------------------------------------------------------------
9333
#   Generated Files
9334
#
9335
    MakeHeader ("Generated Files");
9336
    MakePrint ("\n.PHONY: phony_generate\n\n" );
9337
 
9338
    foreach my $i ( @GENERATE_FILES )
9339
    {
9340
        my $gen_tag = $i->{'index'};
9341
 
9342
        #
263 dpurdie 9343
        #   If predelete is enabled, then create a list of files to delete
9344
        #
9345
        if ( $i->{'predelete'}  )
9346
        {
9347
            MakeDefEntry( "generate_gen_$gen_tag", "=",  $i->{'gen'} );
9348
            MakePrint("\n")
9349
        }
9350
 
9351
 
9352
        #
261 dpurdie 9353
        #   Generate the basic generate rule and recipe
9354
        #   together with the prerequisites
9355
        #
9356
        MakeEntry ( "", ":", "", " ", @{$i->{'gen'}} );
9357
 
9358
        unless ( $i->{'clean'} && $i->{'shell'} )
9359
        {
9360
            MakeEntry ( "", "", " \\\n\t\t", "", @{$i->{'preq'}} );
9361
            MakeEntry ( "", "", " \\\n\t\t", "", "phony_generate" ) if $i->{'preq_sus'};
9362
            MakeEntry ( "", "", " \\\n\t\t", "", "\$(SCM_MAKEFILE)" );
9363
 
9364
            MakePrint ("\n\t" . "\@\$(echo) [$i->{'text'}] generating.." );
263 dpurdie 9365
            if ( $i->{'predelete'}  )
9366
            {
9367
                MakePrint ("\n\t" . "\$(XX_PRE)\$(call RmFiles,generate_gen_$gen_tag)" );
9368
            }
261 dpurdie 9369
            MakePrint ("\n\t" . "\$(XX_PRE)\$(call generate_$gen_tag,)" );
9370
        }
9371
 
9372
        #
9373
        #   Generate 'clean' rules and recipes
9374
        #
9375
        if ( $i->{'clean'} )
9376
        {
9377
            MakePrint ("\n\nPHONY: clean_generate_$gen_tag" );
9378
            MakePrint ("\nclean_generate_$gen_tag:" );
343 dpurdie 9379
            MakePrint ("\n\t" . "\$(XX_PRE)-\$(call generate_$gen_tag,$i->{'clean'})" );
261 dpurdie 9380
        }
9381
 
9382
        #
9383
        #   Define a function to contain the body of the generation call
9384
        #   The first argument will be a 'clean' argument
9385
        #
9386
        MakePrint ("\n\ndefine generate_$gen_tag" );
9387
        if ( $i->{'shell'} )
9388
        {
9389
            MakeEntry ("\n\t(" , "\\\n\t)\n", " \\\n\t", ";" , @{$i->{'toolargs'}} );
9390
        }
9391
        else
9392
        {
9393
            MakeEntry ("\n\t" . $i->{'tool'} . ' $1', "\n", " \\\n\t\t", "" , @{$i->{'toolargs'}} );
9394
        }
9395
        MakePrint ("endef\n\n" );
9396
    }
9397
 
9398
#-------------------------------------------------------------------------------
9399
#   Toolset Post Processing
9400
#   Allow the toolset to perform any post processing, before we finally write
9401
#   out any definitions.
9402
#
9403
#   We will not interprete any more user directives, but new stuff may get added
9404
#
9405
#
9406
MakeHeader ("Toolset Post Processing");
9407
$if->Postprocess();
9408
 
9409
################################################################################
9410
#   All interactions with the toolset are now complete
9411
#   All lists are now complete
9412
#
9413
#   Can now create internal definitions
9414
#   
9415
################################################################################
9416
 
9417
    #
9418
    #   Would be nice if this would work
9419
    #   Unfortunatelty we still need $if for the CCDEPENDS and CTAGS work
9420
    #   These must be defined AFTER the definitions
9421
    #
9422
    #   Ideally we should construct our makefile in sections
9423
    #   and then we can order the sections when we write them out
9424
    #
9425
#$if = 0;                            # Ensure the MakeIf class is not called
9426
                                     # If this file is modified
9427
 
9428
#-------------------------------------------------------------------------------
227 dpurdie 9429
#   Sources
9430
#
9431
MakeHeader  ( "Sources");
9432
MakeDefEntry( "CSRCS",      "=",  \@CSRCS );
9433
MakeDefEntry( "CXXSRCS",    "=",  \@CXXSRCS );
9434
MakeDefEntry( "ASSRCS",     "=",  \@ASSRCS );
9435
 
9436
#-------------------------------------------------------------------------------
9437
#   Generated, Installed and Packaged components
9438
#
9439
MakeHeader  ("Generated, Installed and Packaged components");
9440
MakeDefEntry( "INITS",           "=",  \@INITS )   if ( @INITS );
9441
MakeDefEntry( "GENERATED",       "=",  \@GENERATED ) if ( @GENERATED );
9442
MakeDefEntry( "GENERATED_NOTSRC","=",  \@GENERATED_NOTSRC ) if ( @GENERATED_NOTSRC );
9443
MakeDefEntry( "GENERATEDCLEAN",  "=",  CreateNameList( 'clean_generate_', '', ListCleanGenerated() ));
9444
MakeDefEntry( "INSTALL_HDRS",    "=",  \%INSTALL_HDRS ) if ( %INSTALL_HDRS );
9445
MakeDefEntry( "INSTALL_CLSS",    "=",  \%INSTALL_CLSS ) if ( %INSTALL_CLSS );
9446
MakeDefEntry( "OBJS",            "=", CreateNameList( '$(OBJDIR)/', ".$::o", \@OBJS) );
9447
MakeDefEntry( "SHOBJS",          "=", CreateNameList( '$(OBJDIR)/', ".$::o", \%SHOBJ_LIB ));
289 dpurdie 9448
MakeDefEntry( "PROGOBJS",        "=", CreateNameList( '', ".$::o", \@PROGOBJS ));
9449
MakeDefEntry( "TESTPROGOBJS",    "=", CreateNameList( '', ".$::o", \@TESTPROGOBJS ));
9450
MakeDefEntry( "LIBS",            "=", $LIBS->AllTargets() ) if ($::a);
9451
MakeDefEntry( "MLIBS",           "=", $MLIBS->AllTargets() ) if ($::a);
227 dpurdie 9452
MakeDefEntry( "SHNAMES",         "=", \@SHLIBS );
9453
MakeDefEntry( "SHDIRS",          "=", CreateNameList( '$(OBJDIR)/', "", \@SHLIBS ));
9454
MakeDefEntry( "SHLIBS",          "=", \@SHLIB_TARGETS );
9455
MakeDefEntry( "SCRIPTS",         "=", CreateNameList( '$(BINDIR)/', "", \%SCRIPTS ));
9456
MakeDefEntry( "COPYIN",          "=", \@COPYIN );
289 dpurdie 9457
MakeDefEntry( "PROGS",           "=", $PROGS->AllTargets() );
227 dpurdie 9458
MakeDefEntry( "PROGS_EXTRA",     "=", \@PROGS_EXTRA );
289 dpurdie 9459
MakeDefEntry( "TESTPROGS",       "=", $TESTPROGS->AllTargets());
227 dpurdie 9460
MakeDefEntry( "LINTLIBS",        "=", CreateNameList( 'lib_', '_lint', \@LINTLIBS ));
9461
MakeDefEntry( "LINTSHLIBS",      "=", CreateNameList( 'shlib_', '_lint', \@LINTSHLIBS ));
9462
MakeDefEntry( "LINTPROGS",       "=", CreateNameList( 'prog_', '_lint', \@PROGS ));
289 dpurdie 9463
MakeDefEntry( "LINTPROGS",      "+=", CreateNameList( 'prog_', '_lint', \@TESTPROGS ));
227 dpurdie 9464
MakeDefEntry( "PROJECTS",        "=", CreateNameList( 'Project_', '', ListGeneratedProjects(1) ));
9465
MakeDefEntry( "PROJECTSGEN",     "=", CreateNameList( 'Project_', '', ListGeneratedProjects(0) ));
9466
MakeDefEntry( "PROJECTSCLEAN",   "=", CreateNameList( 'ProjectClean_', '', \%PROJECTS ));
9467
 
261 dpurdie 9468
MakeHeader ("Toolset components");
9469
MakeDefEntry( "USERGENERATED",        "=", \@USERGENERATED )    if ( @USERGENERATED );
9470
MakeDefEntry( "TOOLSETGENERATED",     "=", \@TOOLSETGENERATED ) if ( @TOOLSETGENERATED );
9471
MakeDefEntry( "TOOLSETOBJS",          "=", \@TOOLSETOBJS )      if ( @TOOLSETOBJS );
9472
MakeDefEntry( "TOOLSETLIBS",          "=", \@TOOLSETLIBS )      if ( @TOOLSETLIBS );
9473
MakeDefEntry( "TOOLSETPROGS",         "=", \@TOOLSETPROGS )     if ( @TOOLSETPROGS );
9474
MakeDefEntry( "TOOLSETDIRS",          "=", \@TOOLSETDIRS )      if ( @TOOLSETDIRS );
9475
MakeDefEntry( "TOOLSETDIRTREES",      "=", \@TOOLSETDIRTREES )  if ( @TOOLSETDIRTREES );
227 dpurdie 9476
 
9477
#--------- Determine compiler flag groups to use ----------------------------
9478
#
9479
#   Allows the compiler options to be controlled for both the debug and
9480
#   the production builds. Allows control over
9481
#       1) Optimisations
9482
#       2) Debug Information
9483
#
9484
MakeHeader ("Determine compiler flag groups to use");
9485
 
9486
print MAKEFILE <<EOF;
9487
 
9488
ifneq "\$(DEBUG)" "1"
9489
USE_OPTIMISE	:= \$(PROD_USE_OPTIMISE)
9490
USE_DEBUGINFO	:= \$(PROD_USE_DEBUGINFO)
9491
else
9492
USE_OPTIMISE	:= \$(DEBUG_USE_OPTIMISE)
9493
USE_DEBUGINFO	:= \$(DEBUG_USE_DEBUGINFO)
9494
endif
9495
 
9496
EOF
9497
 
261 dpurdie 9498
#-------------------------------------------------------------------------------
9499
#   Source browsing tools
9500
#
9501
MakeHeader ("Source browsing tools");
9502
    print MAKEFILE <<EOF;
9503
.PHONY:			ctags
9504
ctags:
9505
EOF
9506
    $if->CTAGS()
9507
        if (@CSRCS || @CXXSRCS);
227 dpurdie 9508
 
261 dpurdie 9509
#-------------------------------------------------------------------------------
9510
#   Depend
9511
#   If we are build C or C++ source files then create rules and recipes
9512
#   to invoke a dependency generator.
227 dpurdie 9513
#
261 dpurdie 9514
#   NODEPEND is used to disable, at make-time, the dependency generation
9515
#   and inclusion process.
9516
#
9517
#
9518
MakeHeader ("Depend");
9519
if ($::o && (@CSRCS || @CXXSRCS))
9520
{
9521
    $ScmDependTags = 1;
9522
    print MAKEFILE <<EOF;
9523
depend:			\$(OBJDIR)/depend
9524
 
9525
\$(OBJDIR)/depend:	\$(SCM_MAKEFILE) \$(GBE_OBJDIR)
9526
\$(OBJDIR)/depend:	\$(CSRCS) \$(CXXSRCS)
9527
ifeq (\$(NODEPEND),0)
9528
	\@echo [\$@] Doing a make depend..
9529
	-\$(XX_PRE)\$(rm) -f \$(OBJDIR)/depend
9530
EOF
9531
    $if->CCDepend( "\$(OBJDIR)/depend", "\$(CSRCS)" )
9532
        if ( @CSRCS );
9533
    $if->CXXDepend( "\$(OBJDIR)/depend", "\$(CXXSRCS)" )
9534
        if ( @CXXSRCS );
9535
    MakePrint
9536
        "\t-\@\$(touch) -f \$(OBJDIR)/depend\n";
9537
    print MAKEFILE <<EOF;
9538
else
9539
	\@echo [\$@] Skipping make depend..
9540
	-\$(XX_PRE)\$(rm) -f \$(OBJDIR)/depend
9541
endif
9542
EOF
9543
}
9544
else
9545
{
9546
    print MAKEFILE <<EOF;
9547
depend:
9548
EOF
9549
}
9550
 
9551
#
9552
#   Rule to unmake the depend file
2429 dpurdie 9553
#       No longer neeed.
9554
#       The file is deleted as a part of the OBJDIR cleanup
261 dpurdie 9555
#
9556
    print MAKEFILE <<EOF;
9557
 
9558
undepend:
9559
EOF
9560
 
9561
#--------- IFLAG Documentation -------------------------------------------------
9562
#
9563
#   IFLAG - iteration flag. This is setting by the calling process
9564
#                           and is a function of the phase being processed
227 dpurdie 9565
#       0   No external dependencies.
9566
#       1   Source dependency list.
261 dpurdie 9567
#       2   Shared library dependency list
9568
#       3   Application dependency list
227 dpurdie 9569
#
9570
#
261 dpurdie 9571
#--------- Dependencies --------------------------------------------------------
9572
#   Include the 'depend' file if required
9573
#
9574
    MakeHeader ("Dependency Inclusion");
9575
    print MAKEFILE <<EOF;
9576
ifeq (\$(NODEPEND),0)
9577
 ifdef IFLAG
9578
  ifneq "\$(IFLAG)" "0"
9579
-include	\$(OBJDIR)/depend
9580
  endif
227 dpurdie 9581
 endif
9582
endif
9583
 
9584
EOF
9585
 
9586
#-------------------------------------------------------------------------------
9587
#   Standard rules
9588
#
9589
MakeHeader ("Standard rules");
9590
 
373 dpurdie 9591
print MAKEFILE <<EOF;
227 dpurdie 9592
 
373 dpurdie 9593
.PHONY:		make_clean
227 dpurdie 9594
make_clean:
9595
	-\@echo "Removing generated files (objects, libraries, binaries etc)";
9596
 
9597
.PHONY:		rmlitter
9598
rmlitter:
2429 dpurdie 9599
	-\$(AA_PRE)JatsFileUtil 'D0' 'Removing litter' '.' 'core' '*.bak' '*.tmp' '*.err'
227 dpurdie 9600
 
261 dpurdie 9601
.PHONY:		lint_init
9602
lint_init:
9603
 
227 dpurdie 9604
EOF
9605
 
261 dpurdie 9606
#
9607
#   Dependencies for 'make_init'
9608
#
9609
#
9610
my @initdep;
9611
push @initdep, '$(INITS)' if ( @INITS );
227 dpurdie 9612
 
261 dpurdie 9613
#
9614
#   Dependencies for 'make_dir'
9615
#
9616
my @mkdirdep;
289 dpurdie 9617
push @mkdirdep, '$(GBE_OBJDIR)' if ( @CSRCS || @CXXSRCS || @OBJS || @PROGOBJS || @TESTPROGOBJS );
261 dpurdie 9618
push @mkdirdep, '$(SHDIRS)'     if ( %SHOBJ_LIB || @SHLIBS);
9619
push @mkdirdep, '$(GBE_LIBDIR)' if ( @LIBS || @MLIBS || @SHLIBS || %INSTALL_LIBS || %PACKAGE_LIBS );
289 dpurdie 9620
push @mkdirdep, '$(GBE_BINDIR)' if ( @SHLIBS || %SCRIPTS || @PROGS || @TESTPROGS || %INSTALL_PROGS || %PACKAGE_PROGS );
227 dpurdie 9621
 
261 dpurdie 9622
#
9623
#   Actions for for 'unobj'
9624
#
9625
my @unobjact;
9626
push @unobjact, RmFilesCmd( 'OBJS' )            if ( @OBJS );
9627
push @unobjact, RmFilesCmd( 'SHOBJS' )          if ( %SHOBJ_LIB );
9628
push @unobjact, RmFilesCmd( 'PROGOBJS' )        if ( @PROGOBJS );
289 dpurdie 9629
push @unobjact, RmFilesCmd( 'TESTPROGOBJS' )    if ( @TESTPROGOBJS );
261 dpurdie 9630
push @unobjact, RmFilesCmd( 'TOOLSETOBJS' )     if ( @TOOLSETOBJS );
227 dpurdie 9631
 
261 dpurdie 9632
#
9633
#   Dependencies for 'make_lib'
9634
#
9635
my @libdep;
9636
push @libdep, '$(GBE_OBJDIR)', '$(GBE_LIBDIR)', '$(LIBS)' if ( @LIBS );
227 dpurdie 9637
 
261 dpurdie 9638
#
9639
#   Dependencies for 'lint_lib'
9640
#
9641
my @liblintdep;
9642
push @liblintdep, 'lint_init', '$(GBE_OBJDIR)', '$(GBE_LIBDIR)', '$(LINTLIBS)' if ( @LIBS );
227 dpurdie 9643
 
261 dpurdie 9644
#
9645
#   Dependencies for 'make_mlib'
9646
#
9647
my @mlibdep;
9648
push @mlibdep, '$(GBE_OBJDIR)', '$(GBE_LIBDIR)', '$(GBE_MLIBDIR)', '$(MLIBS)' if ( @MLIBS );
227 dpurdie 9649
 
261 dpurdie 9650
#
9651
#   Dependencies for 'make_install_shlib' (tag)
9652
#
9653
my @shlibdep;
9654
push @shlibdep, '$(SHDIRS)', '$(SHLIBS)' if ( @SHLIBS );
227 dpurdie 9655
 
261 dpurdie 9656
#
9657
#   Dependencies for 'lint_shlib'
9658
#
9659
my @shliblintdep;
9660
push @shliblintdep, 'lint_init', '$(GBE_LIBDIR)', '$(LINTSHLIBS)' if ( @SHLIBS );
227 dpurdie 9661
 
261 dpurdie 9662
#
9663
#   Actions for 'unmake_lib'
9664
#
9665
my @unlibact;
9666
push @unlibact, RmFilesCmd( 'SHLIBS' )      if ( @SHLIBS );
9667
push @unlibact, RmFilesCmd( 'MLIBS' )       if ( @MLIBS );
9668
push @unlibact, RmFilesCmd( 'LIBS' )        if ( @LIBS );
9669
push @unlibact, RmFilesCmd( 'TOOLSETLIBS' ) if ( @TOOLSETLIBS );
227 dpurdie 9670
 
261 dpurdie 9671
#
9672
#   Actions for 'unmake_mlib'
9673
#
9674
my @unmlibact;
9675
push @unmlibact, RmFilesCmd( 'MLIBS' ) if ( @MLIBS );
227 dpurdie 9676
 
261 dpurdie 9677
#
9678
#   Dependencies for 'make_script'
9679
#
9680
my @scriptdep;
9681
push @scriptdep, '$(GBE_BINDIR)', '$(SCRIPTS)' if ( %SCRIPTS );
227 dpurdie 9682
 
261 dpurdie 9683
#
9684
#   Actions for 'unmake_script'
9685
#
9686
my @unscriptact;
9687
push @unscriptact , RmFilesCmd( 'SCRIPTS' ) if ( %SCRIPTS );
9688
push @unscriptact , RmFilesCmd( 'COPYIN' )  if ( @COPYIN );
227 dpurdie 9689
 
261 dpurdie 9690
#
9691
#   Dependencies for 'make_prog'
9692
#
9693
my @progdep;
9694
push @progdep, '$(GBE_OBJDIR)', '$(GBE_BINDIR)', '$(PROGS)' if ( @PROGS );
9695
push @progdep, '$(PROGS_EXTRA)' if (@PROGS_EXTRA);
227 dpurdie 9696
 
261 dpurdie 9697
#
9698
#   Dependencies for 'make_prog' created for 'projects'
9699
#
9700
my @projectdep;
9701
push @projectdep, '$(PROJECTS)' if (ListGeneratedProjects(1) );
227 dpurdie 9702
 
261 dpurdie 9703
#
9704
#   Dependencies for 'generate' created for 'projects'
9705
#
9706
my @projectgendep;
9707
push @projectgendep, '$(PROJECTSGEN)' if (ListGeneratedProjects(0) );
227 dpurdie 9708
 
261 dpurdie 9709
#
9710
#   Dependencies for 'unmake_prog' created for 'projects'
9711
#
9712
my @projectcleandep;
9713
push @projectcleandep, '$(PROJECTSCLEAN)' if (%PROJECTS);
227 dpurdie 9714
 
261 dpurdie 9715
#
9716
#   Dependencies for 'lint_prog'
9717
#
9718
my @proglintdep;
289 dpurdie 9719
push @proglintdep, 'lint_init', '$(GBE_OBJDIR)', '$(GBE_BINDIR)', '$(LINTPROGS)' if ( @PROGS || @TESTPROGS );
227 dpurdie 9720
 
261 dpurdie 9721
#
9722
#   Actions for 'unmake_prog'
9723
#
9724
my @unprogact;
9725
push @unprogact, RmFilesCmd( 'PROGS' )        if ( @PROGS );
9726
push @unprogact, RmFilesCmd( 'TOOLSETPROGS' ) if ( @TOOLSETPROGS );
227 dpurdie 9727
 
261 dpurdie 9728
#
9729
#   Dependencies for 'lint_prog'
9730
#
9731
my @testprogdep;
289 dpurdie 9732
push @testprogdep, '$(GBE_OBJDIR)', '$(GBE_BINDIR)', '$(TESTPROGS)' if ( @TESTPROGS );
227 dpurdie 9733
 
9734
#
261 dpurdie 9735
#   Dependencies for 'run_tests' and friends
9736
#
9737
my @untestprogact;
289 dpurdie 9738
push @untestprogact ,RmFilesCmd( 'TESTPROGS' ) if ( @TESTPROGS );
227 dpurdie 9739
 
261 dpurdie 9740
#
9741
#   Dependencies for 'generated'
9742
#
9743
my @generatedep;
9744
push @generatedep, '$(GENERATED)' if ( @GENERATED );
9745
 
9746
#
9747
#   Actions for 'ungenerate'
9748
#
9749
my @ungenact;
9750
push @ungenact, RmFilesCmd( 'GENERATED' ) if ( @GENERATED );
9751
push @ungenact, RmFilesCmd( 'GENERATED_NOTSRC' ) if ( @GENERATED_NOTSRC );
9752
push @ungenact, RmFilesCmd( 'TOOLSETGENERATED' ) if ( @TOOLSETGENERATED );
9753
push @ungenact, RmFilesCmd( 'USERGENERATED' ) if ( @USERGENERATED );
9754
 
9755
#
9756
#   Dependencies for 'ungenerate'
9757
#
9758
my @ungeneratedep;
9759
push @ungeneratedep, '$(GENERATEDCLEAN)';
9760
 
227 dpurdie 9761
#-------------------------------------------------------------------------------
261 dpurdie 9762
# Function        : PrintPhonyRule
227 dpurdie 9763
#
261 dpurdie 9764
# Description     : Helper function to print some internal phony makefile targets
9765
#                   These are used to hold the basic makefile together
9766
#
9767
# Inputs          : $target         - Name of the phony target
9768
#                   $prereq         - Prerequisites
9769
#                                     Leading spaces removed
9770
#                   $recipe         - Optional Reference to an array of recipes
9771
#                                     Will be printed one per line
9772
#
9773
#
9774
sub PrintPhonyRule
227 dpurdie 9775
{
261 dpurdie 9776
    my ($target, $prereq, $recipe) = @_;
9777
    $prereq =~ s/^\s+//;
227 dpurdie 9778
 
261 dpurdie 9779
    MakePadded( 2, '.PHONY:', $target, "\n");
9780
    MakePadded( 2,"$target:", $prereq, "\n");
9781
    MakePrint ("\t\t" . $_ . "\n") foreach ( @{$recipe} );
9782
    MakePrint ("\n");
227 dpurdie 9783
}
9784
 
261 dpurdie 9785
#   make_init - Test toolset presence and sanity
9786
#   Will only be called ONCE for each platform in a recursive build
9787
#   Should be used to ensure that the required toolset is present
9788
#
9789
PrintPhonyRule ('make_init',       "@initdep" );
227 dpurdie 9790
 
261 dpurdie 9791
#   make_dir    - Create required subdirectories
9792
#   Will be invoked as a part of most targets that create files
9793
#   Will be invoked by the calling wrappers
9794
#   Should not be invoked when cleaning
9795
#
9796
PrintPhonyRule ('make_dir',       "@mkdirdep" );
9797
 
9798
 
9799
PrintPhonyRule ('generate',       "@generatedep @projectgendep" );
9800
PrintPhonyRule ('ungenerate',     "@ungeneratedep",  \@ungenact);
9801
PrintPhonyRule ('unobj',          "",  \@unobjact);
9802
PrintPhonyRule ('make_lib',       "@libdep" );
9803
PrintPhonyRule ('lint_lib',       "@liblintdep" );
9804
PrintPhonyRule ('make_mlib',      "@mlibdep" );
9805
PrintPhonyRule ('lint_shlib',     "@shliblintdep" );
9806
PrintPhonyRule ('unmake_lib',     "", \@unlibact );
9807
PrintPhonyRule ('unmake_mlib',    "", \@unmlibact );
9808
PrintPhonyRule ('make_script',    "@scriptdep" );
9809
PrintPhonyRule ('unmake_script',  "", \@unscriptact );
9810
PrintPhonyRule ('make_prog',      "@scriptdep @progdep @projectdep" );
9811
PrintPhonyRule ('lint_prog',      "@proglintdep" );
9812
PrintPhonyRule ('run_tests',      "@scriptdep @testprogdep" );
9813
PrintPhonyRule ('run_unit_tests', "@scriptdep @testprogdep" );
9814
PrintPhonyRule ('unmake_prog',    "unmake_script @projectcleandep", \@unprogact );
9815
PrintPhonyRule ('make_test',      "@scriptdep @testprogdep" );
9816
PrintPhonyRule ('unmake_test',    "unmake_script", \@untestprogact );
9817
 
227 dpurdie 9818
#-------------------------------------------------------------------------------
9819
#   Package and Installation Summary
9820
#
9821
    MakeHeader ("Package and Installation Summary");
9822
    sub InstallTarget
9823
    {
9824
        my( $target, $hashp, $prereq, $fprereq ) = @_;
9825
        my( $element );
9826
 
343 dpurdie 9827
        MakePrint ".PHONY:\t\t"."$target\n";
227 dpurdie 9828
        MakePrint "$target:";
9829
        MakePrint "\t$fprereq" if ($fprereq);
9830
 
9831
        foreach my $element ( sort keys %{$hashp} )
9832
        {
9833
            #
9834
            #   Skip placekeepers
9835
            #
9836
            next if ( $hashp->{$element}{'placekeeper'} );
9837
 
9838
            #
9839
            #   Prepend any prerequisites (once)
9840
            #
9841
            if ( $prereq )
9842
            {
9843
                MakePrint " \\\n\t${prereq}";
9844
                $prereq = 0;
9845
            }
9846
 
9847
            MakePrint " \\\n\t${element}";
9848
        }
9849
        MakePrint "\n\n";
9850
    }
9851
 
9852
InstallTarget( "install_hdr",       \%INSTALL_HDRS );
9853
InstallTarget( "install_lib",       \%INSTALL_LIBS,  'make_mlib' );
261 dpurdie 9854
InstallTarget( "make_install_shlib",\%INSTALL_SHLIBS, '', "@shlibdep" );
227 dpurdie 9855
InstallTarget( "install_prog",      \%INSTALL_PROGS, 'make_script' );
9856
InstallTarget( "install_class",     \%INSTALL_CLSS );
9857
 
9858
InstallTarget( "package_files",     \%PACKAGE_FILES );
9859
InstallTarget( "package_hdr",       \%PACKAGE_HDRS );
9860
InstallTarget( "package_lib",       \%PACKAGE_LIBS );
9861
InstallTarget( "package_shlib",     \%PACKAGE_SHLIBS );
9862
InstallTarget( "package_prog",      \%PACKAGE_PROGS, 'make_script' );
9863
InstallTarget( "package_class",     \%PACKAGE_CLSS );
9864
 
9865
#-------------------------------------------------------------------------------
9866
#   Installations
9867
 
9868
MakeHeader ("Installations");
9869
PackageRule ( \&InstallCmd, \%INSTALL_HDRS  );
9870
PackageRule ( \&InstallCmd, \%INSTALL_CLSS  );
9871
PackageRule ( \&InstallCmd, \%INSTALL_LIBS  );
9872
PackageRule ( \&InstallCmd, \%INSTALL_SHLIBS  );
9873
PackageRule ( \&InstallCmd, \%INSTALL_PROGS  );
9874
 
9875
 
9876
#-------------------------------------------------------------------------------
9877
#   Packaging
9878
#
9879
MakeHeader ("Packaging");
9880
PackageRule ( \&PackageCmd, \%PACKAGE_FILES );
9881
PackageRule ( \&PackageCmd, \%PACKAGE_HDRS );
9882
PackageRule ( \&PackageCmd, \%PACKAGE_CLSS );
9883
PackageRule ( \&PackageCmd, \%PACKAGE_LIBS );
9884
PackageRule ( \&PackageCmd, \%PACKAGE_SHLIBS );
9885
PackageRule ( \&PackageCmd, \%PACKAGE_PROGS );
9886
 
9887
#-------------------------------------------------------------------------------
9888
#   Uninstall/unpackaging
9889
#
9890
MakeHeader ("Uninstall/unpackaging");
9891
 
9892
UnpackageRule( "uninstall_hdr",         \&UninstallCmd, \%INSTALL_HDRS );
9893
UnpackageRule( "uninstall_lib",         \&UninstallCmd, \%INSTALL_LIBS );
9894
UnpackageRule( "uninstall_shlib",       \&UninstallCmd, \%INSTALL_SHLIBS );
9895
UnpackageRule( "uninstall_prog",        \&UninstallCmd, \%INSTALL_PROGS );
9896
UnpackageRule( "uninstall_class",       \&UninstallCmd, \%INSTALL_CLSS );
9897
 
9898
UnpackageRule( "unpackage_files",       \&UnpackageCmd, \%PACKAGE_FILES );
9899
UnpackageRule( "unpackage_hdr",         \&UnpackageCmd, \%PACKAGE_HDRS );
9900
UnpackageRule( "unpackage_lib",         \&UnpackageCmd, \%PACKAGE_LIBS );
9901
UnpackageRule( "unpackage_shlib",       \&UnpackageCmd, \%PACKAGE_SHLIBS );
9902
UnpackageRule( "unpackage_prog",        \&UnpackageCmd, \%PACKAGE_PROGS );
9903
UnpackageRule( "unpackage_class",       \&UnpackageCmd, \%PACKAGE_CLSS );
9904
 
261 dpurdie 9905
#-------------------------------------------------------------------------------
267 dpurdie 9906
#   Distribution Sets
261 dpurdie 9907
#
267 dpurdie 9908
MakeHeader ("Distribution Sets");
9909
PackageSetRules();
9910
 
9911
#-------------------------------------------------------------------------------
9912
#
261 dpurdie 9913
#   Subdir deletion
9914
#   This is done AFTER the toolset functions have been invoked to create the
9915
#   build artifacts so that the toolsets can create directories too
9916
#
9917
#   Note: Toolset directories are deleted first
9918
#   Note: User Directories are deleted in the reverse order of creation
9919
#
2429 dpurdie 9920
#   Add them into the directory data structure
9921
#
9922
    foreach my $path ( @TOOLSETDIRS )
9923
    {
9924
        MkdirRule( $path, '', '--NoCreate' );
9925
    }
9926
 
9927
    foreach my $path ( @TOOLSETDIRTREES )
9928
    {
9929
        MkdirRule( $path, '', '--NoCreate' , '--RemoveAll');
9930
    }
9931
 
261 dpurdie 9932
    MakeHeader ("Subdir deletion");
9933
    RmdirRules();
9934
    MakeNewLine();
227 dpurdie 9935
 
261 dpurdie 9936
#--------- Toolset Rules -------------------------------------------------------
9937
    MakeHeader ("Toolset Rules");
9938
    MakePrintList ( \@TOOLSETRULES );
9939
 
9940
#--------- Maketags ------------------------------------------------------------
227 dpurdie 9941
 
9942
    Maketag( "make_init",           @INITS );
261 dpurdie 9943
    Maketag( "make_dir",            @mkdirdep );
9944
    Maketag( "generate",            @generatedep || @projectgendep || @USERGENERATED || ($ScmToolsetGenerate != 0) );
227 dpurdie 9945
    Maketag( "depend",              $ScmDependTags != 0 );
261 dpurdie 9946
    Maketag( "make_lib",            @libdep );
9947
    Maketag( "make_mlib",           @mlibdep );
9948
    Maketag( "make_install_shlib",  %INSTALL_SHLIBS || @shlibdep);
9949
    Maketag( "make_script",         @scriptdep );
9950
    Maketag( "make_prog",           @progdep || @projectdep );
9951
    Maketag( "make_test",           @testprogdep );
263 dpurdie 9952
    Maketag( "run_tests",           @TESTS_TO_RUN || @TESTPROJECT_TO_URUN || $TESTS_TO_RUN);
227 dpurdie 9953
    Maketag( "run_unit_tests",      $TESTS_TO_AUTORUN || @TESTPROJECT_TO_ARUN);
9954
    Maketag( "install_hdr",         %INSTALL_HDRS );
9955
    Maketag( "install_class",       %INSTALL_CLSS );
9956
    Maketag( "install_lib",         %INSTALL_LIBS );
9957
    Maketag( "install_prog",        %INSTALL_PROGS );
9958
    Maketag( "deploy",              %DEPLOYPACKAGE );
9959
    Maketag( "package",             %PACKAGE_FILES || %PACKAGE_HDRS || %PACKAGE_CLSS ||
9960
                                    %PACKAGE_LIBS || %PACKAGE_SHLIBS || %PACKAGE_PROGS );
9961
 
261 dpurdie 9962
    #
9963
    #   Display tags in the MAKEFILE
9964
    #   Not used here - just for show
9965
    #
9966
    MakeHeader ("Maketags");
9967
    foreach my $tag ( sort keys %MakeTags )
9968
    {
9969
        MakePadded( 2, "#   $tag:", defined ($MakeTags{$tag}) ? 1 : 0, "\n");
9970
    }
9971
 
227 dpurdie 9972
#-------------------------------------------------------------------------------
9973
#   End of Makefile
9974
#
9975
    MakeHeader ("End of Makefile");
9976
    close( MAKEFILE );
9977
 
9978
#
9979
#   Save all platform information
9980
#   Done after the makefile is written as toolsets can extend the data
9981
#
9982
    WriteParsedConfig();
9983
 
9984
#
9985
#   Write out any accumulated DPACKAGE data
9986
#
9987
    JatsDPackage::DPackageSave();
9988
 
9989
    return 0;
9990
}
9991
 
9992
#-------------------------------------------------------------------------------
387 dpurdie 9993
# Function        : QuoteForMake
9994
#
9995
# Description     : Escape/Quote a pathname for make
9996
#                       Allow files with a $ in the name
9997
#                       Allow files with a space in the name
9998
#                       Allow files with a comma in the name
9999
#                       Allow for paths that have make-varible prefixes
10000
#                           $(GBE_...)/
10001
#                           as these may be generated internally
10002
#
399 dpurdie 10003
#                       Must also allow $(GBE_TYPE) in the remainder
10004
#
387 dpurdie 10005
# Inputs          : uarg                - Arg to quote
10006
#
10007
# Returns         : Quoted arg
10008
#
10009
 
10010
sub QuoteForMake()
10011
{
10012
    my ($uarg) = @_;
10013
 
10014
    #
10015
    #   Split into two
10016
    #       $(xxx)/             - Makefile variables
10017
    #       Remainder           - Stuff to quote
10018
    #
10019
    $uarg =~ m~^((\$\(.*?\)/)*)(.*)~;
10020
    my $prefix = defined $1 ? $1 : '';
10021
    my $arg    = defined $3 ? $3 : '';
10022
 
399 dpurdie 10023
    $arg =~ s~\$(?!\(GBE_)~\$\$~g;       # $, not followed by (GBE_ - id not $(GBE_
387 dpurdie 10024
    $arg =~ s~ ~\\ ~g;
10025
    $arg =~ s~,~\$(comma)~g;
2764 dpurdie 10026
    $arg =~ s~%~\\%~g;
387 dpurdie 10027
    return $prefix . $arg;
10028
}
10029
 
10030
 
10031
#-------------------------------------------------------------------------------
227 dpurdie 10032
# Function        : Maketag
10033
#
10034
# Description     : Create Makefile tags to speed up recursive makes
10035
#
10036
# Inputs          : tag_name
10037
#                   dep
10038
#
10039
# Returns         : 
10040
#
10041
sub Maketag
10042
{
10043
    my( $tag, $dep ) = @_;
10044
    $MakeTags{$tag} = 1 if ( defined($dep) && $dep );
10045
}
10046
 
10047
#-------------------------------------------------------------------------------
10048
#   Function to create and delete directories within the build system
10049
#
10050
#    To stop make regenerating directory dependent targets each time the
10051
#    directory content is modified, rule should only be dependent on a internally
10052
#    created alias file 'gbedir', which represents the time a dir was created not
10053
#    last modified.
10054
#
10055
#    Must use tags like GBE_BINDIR, GBE_LIBDIR and GBE_OBJDIR to ensure that the
10056
#    directories are created correctly.
10057
#
10058
my %MkdirRuleData;
10059
my @MkdirRuleOrder;
10060
my $MkdirRulePrinting = 0;
10061
my $MkdirRuleGbeFile = ( $::ScmHost eq "Unix" ) ? ".gbedir" : "_gbedir";
10062
 
10063
#-------------------------------------------------------------------------------
10064
# Function        : MkdirRule
10065
#
10066
# Description     : Create Rules and Recipes to create a directory at make-time
10067
#                   Mark the information for such that the directories will
10068
#                   be deleted in a 'clean'
10069
#
10070
#                   Can be called before we start writing the makefile
10071
#                   Such entries will be retained and dumped at a known time
10072
#
10073
# Inputs          : $subdir     - Symbolic name of the subdir $(OBJDIR)
10074
#                   $alias      - Optional script alias for the dir 'OBJDIR' --> GBE_OBJDIR
10075
#                   Options:
2429 dpurdie 10076
#                       --Path=path             Optional value of $subdir '$(GBE_PLATFORM)$(GBE_TYPE).OBJ'
10077
#                       --RemoveAll             Remove all files on clean
10078
#                       --Extra=file[,file]     Additiona files to remove
10079
#                       --NoCreate              Do not Create the Directory, just delete it
227 dpurdie 10080
#
10081
# Returns         : Nothing
10082
#
10083
 
10084
sub MkdirRule
10085
{
10086
    my( $subdir, $alias, @opts ) = @_;
10087
 
10088
    #
10089
    #   Create data entry once
10090
    #
10091
    $alias =~ s~^GBE_~~ if $alias;
10092
    unless ( $MkdirRuleData{$subdir}  )
10093
    {
10094
        my %data;
10095
 
10096
        #
10097
        #   Parse options
10098
        #
10099
        foreach ( @opts )
10100
        {
10101
            if ( /^--Path=(.+)/ ) {
10102
                $data{path} = $1;
10103
            } elsif ( /^--RemoveAll/ ) {
10104
                $data{remove_all} = 1;
2429 dpurdie 10105
            } elsif ( /^--NoCreate/ ) {
10106
                $data{noCreate} = 1;
10107
            } elsif ( /^--Extra=(.+)/ ) {
10108
                @{$data{extraFiles}} = split(/,/, $1);
227 dpurdie 10109
            } else {
10110
                Error ("MkdirRule: Unknown option: $_");
10111
            }
10112
        }
10113
        $data{alias} = $alias if ( $alias );
10114
 
10115
        $MkdirRuleData{$subdir} = \%data;
10116
        push @MkdirRuleOrder, $subdir;
10117
    }
10118
 
10119
    #
10120
    #   Save or print
10121
    #
10122
    return unless ( $MkdirRulePrinting );
2429 dpurdie 10123
    return if ( $MkdirRuleData{$subdir}{noCreate} );
227 dpurdie 10124
 
10125
    #
10126
    #   Create a definition of the physical directory
10127
    #
10128
    my $path = $MkdirRuleData{$subdir}{path};
261 dpurdie 10129
    MakePadded (2, $alias, ":= $path\n") if ( $path && $alias );
227 dpurdie 10130
 
10131
    #   Create an alias to be used within rules
10132
    #   The defined aliase will be prefixed with 'GBE_'
10133
    #
261 dpurdie 10134
    MakePadded (2, "GBE_$alias", ":= $subdir/$MkdirRuleGbeFile\n") if ( $alias );
227 dpurdie 10135
 
10136
    #
10137
    #   Create a recipe to create the directory
10138
    #   This is not as simple as it sounds
10139
    #   The touch is required.
10140
    #       Had 'timestamp' issues on solaris'. The 'echo' did not appear
10141
    #       to be enough. Perhaps the output was not flushed
10142
    #
261 dpurdie 10143
    MakePadded (2, "$subdir", ": $subdir/$MkdirRuleGbeFile\n");
227 dpurdie 10144
    MakePrint
10145
        "$subdir/$MkdirRuleGbeFile:\n".
10146
        "\t\$(XX_PRE)if [ ! -d $subdir ]; then \$(mkdir) -p $subdir; fi; \\\n".
10147
        "\t\$(echo) '# DO NOT REMOVE.' > \$@; \\\n".
10148
        "\t\$(touch) \$@\n\n";
10149
}
10150
 
10151
#-------------------------------------------------------------------------------
10152
# Function        : RmdirRules
10153
#
2429 dpurdie 10154
# Description     : Create the body of a recipe to delete the directories that
227 dpurdie 10155
#                   have been created.
10156
#
2429 dpurdie 10157
#                   Use JatsFileUtil rather than shell script
10158
#                       Faster under windows (and others)
10159
#                       Solved long pathname issues
10160
#                       Simpler to use and control
227 dpurdie 10161
#
10162
# Inputs          : Uses $MkdirRuleData
10163
#
10164
# Returns         : Nothing.
10165
#                   Prints to the makefile
10166
#
10167
sub RmdirRules
10168
{
2429 dpurdie 10169
    MakePrint( ".PHONY:\tunmake_dir\n" );
10170
    MakePrint( "unmake_dir:\n" );
10171
 
227 dpurdie 10172
    #
10173
    #   Determine the list of directories to delete
2429 dpurdie 10174
    #   Sort such that subdirs are deleted first
227 dpurdie 10175
    #
2429 dpurdie 10176
    my $txt = 'Removing directories';
227 dpurdie 10177
    foreach my $subdir ( reverse sort keys %MkdirRuleData )
10178
    {
2429 dpurdie 10179
        my @args = $subdir;
10180
 
10181
        push (@args, $MkdirRuleGbeFile, 'core', '*.bak', '*.tmp', '*.err')
10182
            unless $MkdirRuleData{$subdir}{remove_all};
10183
 
10184
        push (@args, @{$MkdirRuleData{$subdir}{extraFiles}})
10185
            if ( $MkdirRuleData{$subdir}{extraFiles} );
10186
 
10187
        my $mode = $MkdirRuleData{$subdir}{remove_all} ? 'T0' : 'D0';
10188
 
10189
        MakePrint ("\t-\$(AA_PRE)JatsFileUtil ", QuoteArray( $mode, $txt, @args ), "\n");
10190
        $txt = '';
227 dpurdie 10191
    }
10192
}
10193
 
10194
#-------------------------------------------------------------------------------
10195
# Function        : CreateMkdirRules
10196
#
10197
# Description     : Create Rules to make dirs at runtime
10198
#                   This function is called to instantiate those entries
10199
#                   That have been requested before the makefile has has
10200
#                   started to be created.
10201
#
10202
#                   Once this function has been called all new MkdirRule calls
10203
#                   will result in the recipes being created in-line.
10204
#
10205
# Inputs          : Nothing
10206
#
10207
# Returns         : Even Less
10208
#
10209
#
10210
sub CreateMkdirRules
10211
{
10212
    $MkdirRulePrinting = 1;
10213
    foreach my $subdir ( @MkdirRuleOrder )
10214
    {
10215
        my $data = $MkdirRuleData{$subdir};
10216
        MkdirRule($subdir, $data->{alias}, $data->{path} );
10217
    }
10218
}
10219
 
10220
#-------------------------------------------------------------------------------
10221
# Function        : PackageRule
10222
#
10223
# Description     : Generate rules and recipes to "install" and "package" files
10224
#
10225
# Inputs          : codecmd     - A code reference to the actual installer routine
10226
#                   hashp       - A reference to a INSTALL or PACKAGE hash
10227
#
299 dpurdie 10228
#                   hashp is a reference to a hash
227 dpurdie 10229
#                       The key is the full path of the install target
10230
#                       The value is (another) hash that describes the install options
10231
#
10232
#                   Valid keys are:
10233
#                       src                 - Path of the source file [Mandatory]
10234
#                       dir                 - Target directory [Mandatory]
10235
#
10236
#                       defined             - Copy the file only if value is defined
10237
#                       exe                 - Mark the file as executable
10238
#                       Mode                - File modes. Default is -w
10239
#                       placekeeper         - Marks SHARED library placekeepers
10240
#                       set                 - Distribution sets
10241
#                       type                - Copy the file in DEBUG or PROD mode
10242
#                                             Valid values are "D" or "P"         
10243
#                       version             - Shared library version information
10244
#                       RemoveOnly          - Do not install the file. Entries are
10245
#                                             created to allow the removal of the file
10246
#
10247
# Returns         :
10248
#
10249
sub PackageRule
10250
{
10251
    my ($codecmd, $hashp) = @_;
10252
 
10253
    foreach my $dest ( keys %{$hashp} )
10254
    {
10255
 
10256
        my $entry = $hashp->{$dest};
10257
 
10258
        #
10259
        #   Skip placekeepers
10260
        #
10261
        next if ( $entry->{'placekeeper'} );
10262
 
10263
        #
10264
        #   Some entries are not installed via this mechanism, but can be removed
10265
        #   if they exist. Mark these as PHONY to keep targets happy
10266
        #
10267
        if ( $entry->{'RemoveOnly'} )
10268
        {
10269
            MakePrint ".PHONY:\t$dest\n";
10270
            MakePrint "$dest:\n\n";
10271
            next;
10272
        }
10273
 
10274
        my $fname = $entry->{'src'};
10275
        my $fmode = $entry->{'Mode'};
10276
        $fmode .= "+x" if ( $entry->{'exe'}  );
10277
 
10278
        #
10279
        #   User conditionional
10280
        #   Mark both the source and the target as PHONY if the condition is not met
10281
        #   This will ensure that the target need not be built.
10282
        #
10283
        my $udef = $entry->{'defined'};
10284
        if ( $udef )
10285
        {
10286
            MakePrint "ifndef $udef \n";
10287
            MakePrint ".PHONY:\t\t$dest\n";
10288
            MakePrint ".PHONY:\t\t$fname\n";
10289
            MakePrint "$dest:\n";
10290
            MakePrint "else\n"
10291
        }
10292
 
10293
        #
10294
        #   Conditional installation for DEBUG/PRODUCTION
10295
        #
10296
        my $type = $entry->{'type'};
10297
        if ( $type )
10298
        {
10299
            if ( $type eq "D" ) {
10300
                MakePrint 'ifeq "$(DEBUG)" "0"'."\n";
10301
            } elsif ( $type eq "P" ) {
10302
                MakePrint 'ifneq "$(DEBUG)" "0"'."\n";
10303
            } else {
10304
                Error("INTERNAL: Unexpected packaging type: $type");
10305
            }
10306
            MakePrint ".PHONY:\t\t$dest\n";
10307
            MakePrint "$dest:\n";
10308
            MakePrint "else\n"
10309
        }
10310
 
10311
        #
10312
        #   The body of the copy
10313
        #
10314
        MakePadded( 4, "$dest:" );
10315
        MakePrint "\t$fname\n";
2429 dpurdie 10316
        MakePrint $codecmd->( $dest, $fname, $fmode );
227 dpurdie 10317
        MakeNewLine();
10318
 
10319
 
10320
        #
10321
        #   Unwind conditionals
10322
        #
10323
        MakePrint "endif\n" if ( $type );
10324
        MakePrint "endif\n" if ( $udef );
10325
 
10326
        #
10327
        #   Distribution sets
10328
        #
10329
        my $dist = $entry->{'set'};
10330
        if ( $dist )
10331
        {
267 dpurdie 10332
            foreach my $set ( split( ',', $dist ) )
10333
            {
10334
                push @{$PACKAGE_SETS{$set}{LIST}}, $dest;
227 dpurdie 10335
            }
10336
            MakeNewLine();
10337
        }
10338
    }
10339
}
10340
 
10341
#-------------------------------------------------------------------------------
267 dpurdie 10342
# Function        : PackageSetRules
10343
#
10344
# Description     : Generate the packageset rules
10345
#                   These appear to be a now-defuct feature
10346
#
10347
#                   By default all packaged files are a part of package_setALL
10348
#
10349
# Inputs          : None
10350
#                   Takes data from %PACKAGE_SET
10351
#
10352
# Returns         : Nothing
10353
#
10354
sub PackageSetRules
10355
{
10356
    foreach my $set ( sort keys %PACKAGE_SETS )
10357
    {
10358
        my $me = MakeEntry::New( *MAKEFILE, "package_set$set", '--Phony' );
10359
        $me->AddDependancy( @{$PACKAGE_SETS{$set}{LIST}} );
10360
        $me->Print();
10361
    }
10362
}
10363
 
10364
#-------------------------------------------------------------------------------
227 dpurdie 10365
# Function        : UnPackageRule
10366
#
10367
# Description     : Generate rules and recipes to "uninstall" and "unpackage" files
10368
#
10369
# Inputs          : target      - Name of the target
10370
#                   codecmd     - A code reference to the actual installer routine
10371
#                   hashp       - A reference to a INSTALL or PACKAGE hash
10372
#
10373
# Returns         :
10374
#
10375
sub UnpackageRule
10376
{
10377
    my ($target, $codecmd, $hashp) = @_;
10378
 
10379
    MakePrint ".PHONY:\t\t"."$target\n";
10380
    MakePrint "$target:\t";
10381
 
10382
    foreach my $dest ( sort keys %{$hashp} )
10383
    {
10384
 
10385
        my $entry = $hashp->{$dest};
10386
 
10387
        #
10388
        #   Skip placekeepers
10389
        #
10390
        next if ( $entry->{'placekeeper'} );
10391
 
10392
        MakePrint "\n" . $codecmd->($dest);
10393
    }
10394
    MakePrint "\n\n";
10395
}
10396
 
10397
 
10398
#
10399
#   Internal macro interface, see RULE.STD for definitions:
10400
#
10401
sub RmFilesCmd
10402
{
10403
    my ( $list ) = @_;
261 dpurdie 10404
    return "\$(call RmFiles,$list)";
227 dpurdie 10405
}
10406
 
10407
sub InstallCmd
10408
{
2429 dpurdie 10409
    my( $dest, $file, $fmode ) = @_;
227 dpurdie 10410
 
10411
    $fmode = "-w"                           # default, read-only
10412
        if ( !defined( $fmode ) || $fmode eq "" );
10413
 
2429 dpurdie 10414
    return "\t\$(call InstallFile,$dest,$file,$fmode)";
227 dpurdie 10415
}
10416
 
10417
sub UninstallCmd
10418
{
10419
    my( $file ) = @_;
10420
 
10421
    return "\t\$(call UninstallFile,$file)";
10422
}
10423
 
10424
sub PackageCmd
10425
{
2429 dpurdie 10426
    my( $dest, $file, $fmode ) = @_;
227 dpurdie 10427
 
10428
    $fmode = "-w"                           # default, read-only
10429
        if ( !defined( $fmode ) || $fmode eq "" );
10430
 
2429 dpurdie 10431
    return "\t\$(call PackageFile,$dest,$file,$fmode)";
227 dpurdie 10432
}
10433
 
10434
sub UnpackageCmd
10435
{
10436
    my( $file ) = @_;
10437
    return "\t\$(call UnpackageFile,$file)";
10438
}
10439
 
10440
1;
10441