Subversion Repositories DevTools

Rev

Rev 2650 | Rev 3965 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 dpurdie 1
# -*- mode: perl; tabs: 8; indent-width: 4; show-tabs: yes; -*-
261 dpurdie 2
# Copyright (C) 1998-2008 ERG Transit Systems, All rights reserved
227 dpurdie 3
#
4
# Module name   : makelib.pl2
5
# Module type   : Makefile system
6
#
7
# Description:
8
#       This modules builds the platform definition makefiles(s)
9
#
10
# Notes:                *** DO NOT DETAB ***
11
#       Beware the use of space v's tab characters within the
12
#       makefile generation sessions.
13
#
14
##############################################################################
15
# Globals:
16
#  $ScmVersion          Makelib.pl2 version
17
#  $ScmRoot             Command line parameter that gives the root directory
18
#                       location for this directory tree.
19
#  $ScmMakelib          Command line parameter that points to the location
20
#                       of THIS script.  ie. location of makelib.pl.
21
#  $ScmPlatform         Current platform
22
#  $ScmProduct          Current product (if any)
23
#  $ScmTarget           Resulting target (derived from Platform)
24
#  @ScmPlatformArgs     Platform arguments
25
#  $ScmToolset          Toolset
26
#  @ScmToolsetArgs      Toolset arguments
27
#  $ScmDebug            Debug level
28
#  $ScmVerbose          Verbose setting
29
#  $ScmSourceTypes      Source types, aliasing for C, C++ and assembler
30
#                       source.
31
#  @CFLAGS              List containing all of the defined C flags
32
#  @CXXFLAGS            List containing all of the defined C++ flags
33
#  @ASFLAGS             List containing all of the defined assembler flags
34
#  @CLINTFLAGS          List containing all of the defined C lint flags
35
#  @CXXLINTFLAGS        List containing all of the defined C++ lint flags
36
#  @{G|L}_INCDIRS       List containing all of include paths
37
#  @{G|L}_SRCDIRS       List containing all of source search paths
38
#  @{G|L}_LIBDIRS       List containing all of library search paths
39
#  @LDFLAGS             List containing all of the defined linker flags
40
#  @SRCS                List of ALL source files. ie. C/C++ and other (eg .x)
41
#                       Key is source file, value is source path
42
#  @OBJS                List of ALL (non-shared) object files.
289 dpurdie 43
#  %SHOBJ_LIB           List of ALL shared library object files and associated library.
227 dpurdie 44
#  %OBJSOURCE           List of ALL object files
45
#                       from that should result from later makes.
46
#                       Key is objectfile, value is source file
47
#  %OBJREFS             List of ALL object files, built options.
48
#  @PROGOBJS            List of ALL application object files.
49
#  %SRC_ARGS            List of arguments that are to be used when making the
50
#                       nominated source.  Key is the source name, the
51
#                       value is a string of arguments to apply.  The
52
#                       arguments are '$;' separated.
53
#  %SRC_TYPE            Source file type (user override).
54
#  @CHDRS               List of C header files.
55
#  @CSRCS               List of C files
56
#                       Key is objectfile, value is source file
57
#  @CXXSRCS             List of C++ files
58
#  @ASHDRS              List of assembler include files (.inc)
59
#  @ASSRCS              List of assembler source files
60
#  @GENERATED           List of files that should result from a 'generate'
61
#                       make rule.  The programmer is expected to provide
62
#                       the necessary rule(s).
63
#  @RULES               List of additional make rules the programmer
64
#                       has specified to be included in the make.
65
#  %INSTALL_HDRS        List of headers that are to be installed for later
66
#                       "public" consumption.
67
#  %INSTALL_CLSS        List of Java classes or JAR files that are to be installed
68
#                       for later "public" consumption.
69
#  @LIBS                List of libraries that are to be built.
289 dpurdie 70
#  $LIBS                Ref to a collection of static library descriptors
71
#                       Indexed by lib name
227 dpurdie 72
#  %INSTALL_LIBS        List of libraries that are to be installed for later
73
#                       public consumption.
74
#  @MLIBS               List of libraries that are to be built via merging
289 dpurdie 75
#  $MLIBS               Ref to a collection of merged lib descriptors
227 dpurdie 76
#  @SHLIBS              List of shared libraries that are to be built.
289 dpurdie 77
#  $SHLIBS              Ref to collection of shared library information
227 dpurdie 78
#  %INSTALL_SHLIBS      List of libraries that are to be installed for later
79
#                       public consumption.
80
#  @PROGS               List of programs (binary executables) that are
81
#                       to be built
289 dpurdie 82
#  $PROGS               Ref to collection of program information
227 dpurdie 83
#  %SCRIPTS             List of scripts to 'create' (key) and whether they
84
#                       should be made executable or not (value).  Script
85
#                       set to executable is denoted by the value being
86
#                       defined AND true.
87
#  %INSTALL_PROGS       List of programs for "public" cosumption to install
88
#                       where (key) is the file and where to install it
89
#                       to vs. (value) which is composed of the original
90
#                       location of the file, the destination directory
91
#                       and a list of service providers this file applies to.
92
# $ProjectBase          Base of the user's project. This variable is designed to
93
#                       be used by the user.
94
#....
95
 
255 dpurdie 96
require 5.006_001;
227 dpurdie 97
use strict;
98
use warnings;
261 dpurdie 99
use Getopt::Long;
227 dpurdie 100
use Data::Dumper;
271 dpurdie 101
use JatsError;
227 dpurdie 102
use JatsEnv;
103
use MakeEntry;
104
use JatsLocateFiles;
105
use JatsDPackage;
271 dpurdie 106
use MakeIf;
289 dpurdie 107
use ToolsetPrinter;
108
use MakeObject;
339 dpurdie 109
use JatsVersionUtils;
227 dpurdie 110
 
111
 
112
our $ScmVersion             = "2.34";
113
our $ScmGlobal              = 0;
114
our $ScmExpert              = 0;
115
our $ScmInterface           = "interface";      # default 'interface'
116
our $ScmPackage             = 1;                # package active by default.
117
our $ScmProcessingRootMake  = 0;                # Processing root makefile.pl
118
our $ScmPlatformSeen        = 0;                # Platform directive has been seen
119
 
120
our $ScmToolsetVersion      = "";               # version of toolset
121
our $ScmToolsetGenerate     = 1;                # generate active by default.
122
our $ScmToolsetProgDependancies = 1;            # 1: Write program dependancies
123
                                                # 0: Don't write progdeps. Prog is Phony
289 dpurdie 124
our $ScmToolsetSingleType   = 0;                # Toolset does not support Debug and Production
227 dpurdie 125
our $ScmToolsetProgSource   = ();               # Toolset Program Source
339 dpurdie 126
our $ScmToolsetSoName       = 0;                # 1: Shared library supports SoName
363 dpurdie 127
our $ScmToolsetNillLibSrc   = 0;                # 1: Librarys created without source specified
128
 
227 dpurdie 129
our $ScmRoot                = "";
130
our $ScmMakelib             = "";
131
our $ScmPlatform            = "";
132
our $ScmMachType            = "";
133
our $ScmSrcDir              = "";
134
our @ScmPlatformDirs        = ();
135
our @ScmPlatformArgs        = ();
289 dpurdie 136
our $ScmBuildType           = 0;                # 0, P, D. 0 == P and D
227 dpurdie 137
our $ScmProduct             = "";
138
our $ScmTarget              = "";
139
our $ScmTargetHost          = "";
140
our $ScmToolset             = "";
141
our @ScmToolsetArgs         = ();
142
our @ScmDepends             = ();
143
our %ScmSourceTypes         = ();
144
our $ScmDeploymentPatch     = "";
145
our $ProjectBase            = "";               # Base of the user's project
146
our $ScmNoToolsTest         = "";               # Supress compiler tests
147
our $ScmDependTags          = 0;                # Create dependancy scanning tag
148
 
149
our @CFLAGS                 = ();
150
our @CFLAGS_DEBUG           = ();
151
our @CFLAGS_PROD            = ();
152
our @CLINTFLAGS             = ();
153
our @CLINTFLAGS_DEBUG       = ();
154
our @CLINTFLAGS_PROD        = ();
155
our @CXXFLAGS               = ();
156
our @CXXFLAGS_DEBUG         = ();
157
our @CXXFLAGS_PROD          = ();
158
our @CXXLINTFLAGS           = ();
159
our @CXXLINTFLAGS_DEBUG     = ();
160
our @CXXLINTFLAGS_PROD      = ();
161
our @ASFLAGS                = ();
267 dpurdie 162
our @ASFLAGS_DEBUG          = ();
163
our @ASFLAGS_PROD           = ();
227 dpurdie 164
our @LDFLAGS                = ();
267 dpurdie 165
our @LDFLAGS_DEBUG          = ();
166
our @LDFLAGS_PROD           = ();
227 dpurdie 167
 
168
our @INCDIRS                = ();
169
our @NODEPDIRS              = ();
170
our @S_INCDIRS              = ();
171
our @G_INCDIRS              = ();
172
our @L_INCDIRS              = ();
173
our @SRCDIRS                = ();
174
our @S_SRCDIRS              = ();
175
our @G_SRCDIRS              = ();
176
our @L_SRCDIRS              = ();
177
our @LIBDIRS                = ();
178
our @S_LIBDIRS              = ();
179
our @G_LIBDIRS              = ();
180
our @L_LIBDIRS              = ();
181
 
182
our %SRCS                   = ();
183
our %SRC_ARGS               = ();
184
our %SRC_TYPE               = ();
185
our %SRC_DEPEND             = ();
186
our %SCRIPTS                = ();
187
our @COPYIN                 = ();
188
our @INITS                  = ();
189
our @DEFINES                = ();
190
our @OBJS                   = ();
191
our %SHOBJ_LIB              = ();
192
our @PROGOBJS               = ();
289 dpurdie 193
our @TESTPROGOBJS           = ();
227 dpurdie 194
our %OBJSOURCE              = ();
195
our @CHDRS                  = ();
196
our @CSRCS                  = ();
197
our @CXXSRCS                = ();
198
our @ASHDRS                 = ();
199
our @ASSRCS                 = ();
200
our @GENERATED              = ();
201
our @GENERATED_NOTSRC       = ();
202
our @RULES                  = ();
203
our @TOOLSETRULES           = ();
204
our @TOOLSETDIRS            = ();
205
our @TOOLSETDIRTREES        = ();
206
our @TOOLSETGENERATED       = ();
207
our @USERGENERATED          = ();
208
our @TOOLSETOBJS            = ();
209
our @TOOLSETLIBS            = ();
210
our @TOOLSETPROGS           = ();
211
our %INSTALL_HDRS           = ();
212
our %INSTALL_CLSS           = ();
213
 
214
our @LIBS                   = ();
289 dpurdie 215
our $LIBS                   = ();
227 dpurdie 216
our %LIB_PKG                = ();
217
our %LIB_INS                = ();
218
our %INSTALL_LIBS           = ();
219
 
220
our @MLIBS                  = ();
289 dpurdie 221
our $MLIBS                  = ();
227 dpurdie 222
 
223
our @SHLIBS                 = ();
289 dpurdie 224
our $SHLIBS                 = ();
227 dpurdie 225
our @SHLIB_TARGETS          = ();
226
our %SHLIB_PKG              = ();
227
our %SHLIB_INS              = ();
228
our %INSTALL_SHLIBS         = ();
229
 
289 dpurdie 230
our $TESTPROGS              = ();
231
our @TESTPROGS              = ();
227 dpurdie 232
 
289 dpurdie 233
our $PROGS                  = ();           # Simplify tracking of progs
227 dpurdie 234
our @PROGS                  = ();
289 dpurdie 235
our @PROGS_EXTRA            = ();           # Look at doing better !!
227 dpurdie 236
our %PROG_PKG               = ();
237
our %PROG_INS               = ();
238
our %INSTALL_PROGS          = ();
239
 
240
our %PACKAGE_DIST           = ();
241
our %PACKAGE_SETS           = ();
242
our %PACKAGE_HDRS           = ();
243
our %PACKAGE_LIBS           = ();
244
our %PACKAGE_CLSS           = ();
245
our %PACKAGE_SHLIBS         = ();
246
our %PACKAGE_PROGS          = ();
247
our %PACKAGE_FILES          = ();
248
 
249
our @PACKAGE_VARS           = ( '%PACKAGE_CLSS',  '%PACKAGE_FILES', '%PACKAGE_HDRS',
250
                                '%PACKAGE_LIBS',  '%PACKAGE_PROGS', '%PACKAGE_SHLIBS' );
251
our @INSTALL_VARS           = ( '%INSTALL_CLSS',  '%INSTALL_HDRS',  '%INSTALL_LIBS',
252
                                '%INSTALL_PROGS', '%INSTALL_SHLIBS');
253
 
254
our @LINTLIBS               = ();
255
our @LINTSHLIBS             = ();
256
 
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",
2449 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
 
2547
        TOOL_SEARCH:
2548
        {
2549
            #
2550
            #   Locate tool with package
2551
            #
2552
            if ( my $fname = ToolExtensionProgram( $tool, @extension_list ))
2553
            {
2554
                $tool = $fname;
2555
                last TOOL_SEARCH;
2556
            }
2557
 
2558
            #
2559
            #   Search the JATS tools and Bin directory
2560
            #   Retain the symbolic name of the JATS directory
2561
            #
2562
            for my $ext ( @extension_list )
2563
            {
2564
                foreach my $jdir ( qw( / /DEPLOY/ /LOCAL/ ) )
2565
                {
2566
                    if ( -f "$::GBE_TOOLS$jdir$tool$ext" )
2567
                    {
2568
                        $tool = "\$(GBE_TOOLS)$jdir$tool$ext";
2569
                        last TOOL_SEARCH;
2570
                    }
2571
                }
2572
 
2573
                if ( -f "$::GBE_BIN/$tool$ext" )
2574
                {
2575
                    $tool = "\$(GBE_BIN)/$tool$ext";
2576
                    last TOOL_SEARCH;
2577
                }
2578
            }
2579
 
2580
            #
2581
            #   Has the user provided an absolute PATH
2582
            #   This is not good, but for testing we can use it
2583
            #
2584
            if ( $tool =~ m~^/~ || $tool =~ m~^.:~ )
2585
            {
2586
                Warning("Absolute path program specified. Uncontrolled tool: $tool");
2587
                for my $ext ( @extension_list )
2588
                {
2589
                    if ( -f "$tool$ext" )
2590
                    {
2591
                        $tool = "$tool$ext";
2592
                        last TOOL_SEARCH;
2593
                    }
2594
                }
2595
            }
2596
 
2597
            #
2598
            #   May have a relative path to a local tool
2599
            #
2600
            if ( -f $tool )
2601
            {
2602
                UniquePush (\@preq_files, $tool);
2603
                last TOOL_SEARCH;
2604
            }
2605
 
2606
            #
2607
            #   Search the users PATH
2608
            #   Generate a warning if the program is found. These programs are
2609
            #   not nice as they are not really controlled.
2610
            #
2611
            for my $dir (split( $::ScmPathSep, $ENV{'PATH'} ) )
2612
            {
2613
                for my $ext ( @extension_list )
2614
                {
2615
                    if ( -f "$dir/$tool$ext" )
2616
                    {
2617
                        Warning("External program found in the user's PATH. Uncontrolled tool: $tool");
2618
                        $tool = "$dir/$tool$ext";
2619
 
2620
                        #
2621
                        #   Do not make the program a pre-requisite if we are running
2622
                        #   under Windows. This avoids two problems:
2623
                        #       1) May have spaces in pathname
2624
                        #       2) May have driver letter in pathname
2625
                        #
2626
                        $tool_no_prereq = 1 if ( $::ScmHost eq "WIN" );
2627
                        last TOOL_SEARCH;
2628
                    }
2629
                }
2630
            }
2631
 
2632
            #
2633
            #   Specified progrom not found
2634
            #   Generate a warning and use the raw name
2635
            #
2636
            Warning("Tool not found: $tool");
2637
            $tool_no_prereq = 1;
2638
        }
2639
        UniquePush (\@preq_files, $tool) unless ($tool_no_prereq);
2640
 
2641
    } elsif ( $tool =~ /^--Script=(.*)/ ) {
2642
 
2643
        #
2644
        #   Locate the script in a known source directory and make
2645
        #   the script a prerequisite of the target files, since the
2646
        #   script may be generated.
2647
        #
2648
        $tool = MakeSrcResolve ( $1 );
2649
        UniquePush (\@preq_files, $tool);
2650
 
2651
    } elsif ( $tool =~ /^--Shell$/ ) {
2652
        #
2653
        #   The user has provided a shell script within the command body
2654
        #   This will be executed directly by a shell
2655
        #   directores will need to use a "/" separator
2656
        #
2657
        $tool = "InternalShell";
2658
        $shell_script = 1;
2659
        $shell_cmds = 1;
2660
 
2661
 
2662
    } elsif ( $tool =~ /^--Prog=(.*)$/ ) {
2663
        #
2664
        #   Using a program that has been created within this script
2665
        #
2666
        my $prog = $1;
289 dpurdie 2667
        if ( my $pProg = $PROGS->Get($prog) )
227 dpurdie 2668
        {
289 dpurdie 2669
            $tool = $pProg->getPath()
227 dpurdie 2670
                unless ( $tool = $SRCS{$prog} );
2671
        UniquePush (\@preq_files, $tool);
2672
        }
2673
        else
2674
        {
2675
            Error ("Unknown program: $prog");
2676
        }
2677
 
2678
    } else {
2679
 
2680
        #
2681
        #   Currently generate a warning and then use the raw tool name
2682
        #
2683
        Error ("Unknown TOOL syntax: $tool");
2684
    }
2685
 
2686
    #
2687
    #   May need to quote the path
2688
    #   If the toolpath contains spaces then ugliness can occur - so quote the program
2689
    #
2690
    $tool = '"' . $tool . '"'
2691
        if ( (! $shell_script ) && $tool =~ m~\s~ );
2692
 
2693
    #
2694
    #   Determine special startup for various programs
2695
    #       Perl  - use known implemenatation
2696
    #       Shell - use known implemenatation
2697
    #       Otherwise - simply run it
2698
    #
2699
    #   Windows: Shell and Perl don't need '\' in paths
2700
    #
2701
    if ( $tool =~ /\.pl$/ )
2702
    {
2703
        $tool = "\$(GBE_PERL) $tool";
2704
        $shell_script = 1;
2705
    }
2706
    elsif ( $tool =~ /\.k?sh$/ )
2707
    {
2708
        $tool = "\$(GBE_BIN)/sh $tool";
2709
        $shell_script = 1;
2710
    }
2711
    Debug( "GenerateFiles: Tool: $tool" );
2712
 
2713
 
2714
    #
2715
    #   Process the remaining arguments
2716
    #   These will be command line arguments or options/flags
2717
    #   Command line arguments are concatenated together
2718
    #
2719
    for my $arg (@args)
2720
    {
263 dpurdie 2721
        if ( $arg =~ /^--PreDelete$/ )
2722
        {
2723
            #
2724
            #   Delete generated files before running the generation process
2725
            #   Some programs refuse to overwrite existing files
2726
            #
2727
            $predelete = 1;
2728
            next;
2729
        }
2730
 
227 dpurdie 2731
        if ( $arg =~ /^--NoVarTag$/ )
2732
        {
2733
            #
2734
            #   Modify the operation of --Var to supress the tags
2735
            #   Should be usd early as will only affect following --Var usage
2736
            #
2737
            push @var_opts, "--notag";
2738
            next;
2739
        }
2740
 
2741
        if ( $arg =~ /^--NoWarn$/ )
2742
        {
2743
            #
2744
            #   Supress warnings - No prequisites found
2745
            #   This is acceptable, but normally a tool should take an input
2746
            #   and create some output from it.
2747
            #
2748
            $no_warn = 1;
2749
            next;
2750
        }
2751
 
2752
        if ( $arg =~ /^--NoGenerate$/ )
2753
        {
2754
            #
2755
            #   Tool does generate a definable output
2756
            #   Should only be used internally
2757
            #
2758
            #   Need to create a dummy name for the rule
2759
            #   Use a base name and a number
2760
            #
2761
            my $dummy_target = 'generate_files_' . $NoGenIndex;
2762
            UniquePush (\@gen_files, $dummy_target );
2763
            UniquePush (\@GENERATED, $dummy_target);
2764
            next;
2765
        }
2766
 
2767
        if ( $arg =~ /^--UnknownPreq/ )
2768
        {
2769
            #
2770
            #   Indicate that the prequisites are not known, or too complex to
2771
            #   describe. ie: All files in a directory. May be used by packaging
2772
            #   tools.
2773
            #   The recipe will be run EVERY time we want to use the target.
2774
            #
2775
            $preq_unknown = 1;
2776
            $no_warn = 1;
2777
            next;
2778
        }
2779
 
2780
        if ( $arg =~ /^--AutoGenerate/ )
2781
        {
2782
            #
2783
            #   Determine when to run the tool based on the types of files that
2784
            #   are generated. Existance of a source file will force the tool
2785
            #   to be run during the 'generate' phase, othewise the tool will be run
2786
            #   when the generated components are required.
2787
            #
2788
            $gtype = 2;
261 dpurdie 2789
            Warning ("AutoGenerate MUST occur before options that declare generation of files",
2790
                     "Have seen:", @genreq_seen)
2791
                if (@genreq_seen);
227 dpurdie 2792
            next;
2793
        }
2794
 
2795
        if ( $arg =~ /^--Prereq=(.*)/ )
2796
        {
2797
            #
2798
            #   Specify a prerequisite file, that is not a part of the command line
2799
            #   Simply add the files to the list of preq files
2800
            #
2801
            my $fn = LocatePreReq ($1);
2802
            UniquePush ( \@preq_files, $fn );
2803
            Debug( "GenerateFiles: ExtraPrereq: $fn" );
2804
            next;
2805
        }
2806
 
2807
        if ( $arg =~ /^--Created(.*)=(.*)/ )
2808
        {
2809
            #
2810
            #   Specify a generated file, that is not a part of the command line
2811
            #   Add the files to the list of generated files
2812
            #
2813
            my $type = $1;
2814
            my $fn = $2;
2815
 
343 dpurdie 2816
            #
2817
            #   Append object suffix to CreatedObject
2818
            #
227 dpurdie 2819
            $fn .= '.' . $::o
2820
                if ( $type =~ m/Object/ );
2821
 
343 dpurdie 2822
            #
2823
            #   If the files is 'created' in a subdir, then add the dir
2824
            #   as a prerequisite.
2825
            #
2826
            if ( $type =~ m/Prog/ ) {
2827
                $fn = "\$(BINDIR)/$fn";
2828
                UniquePush (\@preq_files, '$(GBE_BINDIR)');
2829
 
2830
            } elsif ( $type !~ m/Common/ ) {
2831
                $fn = "\$(OBJDIR)/$fn";
2832
                UniquePush (\@preq_files, '$(GBE_OBJDIR)');
2833
            }
227 dpurdie 2834
 
2835
            #
2836
            #   Examine the file and see if it needs to be compiled
2837
            #   Add to the list of source files
2838
            #
261 dpurdie 2839
            push @genreq_seen, $arg;
303 dpurdie 2840
            if ( UniquePush (\@gen_files, $fn) )
2841
            {
2842
                if ( GenerateSrcFile ( $gtype, $fn  ) && $gtype == 2 )
2843
                {
2844
                    push @has_source, $fn;
2845
                }
2846
            }
227 dpurdie 2847
            Debug( "GenerateFiles: ExtraCreated: $fn" );
2848
            next;
2849
        }
2850
 
2851
        if ( $arg =~ /^--Clean($|=(.*))/ )
2852
        {
2853
            #
2854
            #   Detect Clean option
2855
            #
2856
            $clean_tag = $2 ? $2 : '-clean';
2857
 
2858
            #
2859
            #   Shell command with a --Clean will only
2860
            #   be run during a clean phase. They should not have any prereq
2861
            #   and should not generate any files, so simplify the interface.
2862
            #
2863
            push @args, '--NoWarn', '--NoGenerate'
2864
                if ( $shell_cmds );
2865
 
2866
            next;
2867
        }
2868
 
2869
        if ( $arg =~ /^--Text=(.*)/ )
2870
        {
2871
            #
2872
            #   Display this text when executing commands
2873
            #
2874
            $text = $1;
2875
            next;
2876
        }
2877
 
2878
 
2879
        #   Not an option. Must be an argument to the tool/program
2880
        #   Process the tool arguments and extract file information
2881
        #   Extract all fields of the form:
2882
        #           --xxxxx(yyyyyy[,zzzzz])
2883
        #           --xxxxx{yyyyyyy}
2884
        #           --xxxxx[yyyyyyy] to allow embedded brackets
2885
        #
2886
        while ( $arg =~ m/--(\w+)               # --CommandWord         $1
2887
                                (               # Just for grouping
2888
                                \((.*?)\)   |   # Stuff like (yyyyy)    $3
2889
                                {(.*?)}     |   # or    like {yyyyy}    $4
2890
                                \[(.*?)\]       # or    like [yyyyy]    $5
2891
                                )/x )           # Allow comments and whitespace
2892
        {
2893
            my $cmd = $1;                       # The command
2894
            my $ufn = $3 || $4 || $5;           # User filename + options
2895
            my $mb = $-[0];                     # Match begin offset
2896
            my $me = $+[0];                     # Match end
2897
            my $flags = '';                     # Optional flags ( --dir or --file )
2898
            my $raw_arg = $ufn;                 # Raw arguments
285 dpurdie 2899
            my $all = substr( $arg, $mb, $me ); # All of match. Avoid use of $&
343 dpurdie 2900
            my $is_path = 1;
285 dpurdie 2901
 
227 dpurdie 2902
 
2903
            Error ("GenerateFiles. Empty element not allowed: $all")
2904
                unless ( defined($ufn) );
2905
 
2906
            $ufn =~ s/\s+$//;
2907
            $ufn =~ s/^\s+//;
2908
            $ufn =~ s~//~/~g;                   # Remove multiple /
2909
            if ( $ufn =~ m/(.*?),(.*)/ )        # Extract out any flags
2910
            {
2911
                $ufn = $1;
2912
                $flags = $2;
2913
            }
2914
 
2915
            my $fn = $ufn ;                     # Replacement filename
343 dpurdie 2916
            my $fnp = '';                       # Prefix to $fn
227 dpurdie 2917
            Error ("GenerateFiles. Empty element not allowed: $all" )
2918
                if ( length ($ufn) <= 0 );
2919
 
2920
            #
2921
            #   Process found user command
2922
            #
2923
            if ( $cmd =~ /^Generated/ )
2924
            {
2925
                my $use_dir = "";
343 dpurdie 2926
 
227 dpurdie 2927
                #
2928
                #   Generated filename
2929
                #       Determine the target directory
2930
                #       Determine the full name of the file.
2931
                #       Flag the file as generated
2932
                #
2933
                if ( $cmd =~ /Prog/ )
2934
                {
2935
                    #
2936
                    #   Generated Prog are generated in the BIN directory
2937
                    #   Ensure the directory exists by using its symbolic name
2938
                    #   as a prerequisite.
2939
                    #
343 dpurdie 2940
                    $use_dir = '$(BINDIR)';
2941
                    UniquePush (\@preq_files, '$(GBE_BINDIR)');
227 dpurdie 2942
                }
2943
                elsif ( $cmd !~ /Common/ )
2944
                {
2945
                    #
2946
                    #   Files that are not Common are generated in the
2947
                    #   object directory. This directory must exist, so it
2948
                    #   symbolic name GBE_OBJDIR is made a prerequisite too.
2949
                    #
2950
                    #   If the file is a header file, then add the directory
2951
                    #   to the include search path too.
2952
                    #
343 dpurdie 2953
                    $use_dir = '$(OBJDIR)';
2954
                    UniquePush (\@preq_files, '$(GBE_OBJDIR)');
2955
                    AddIncDir( $platforms , '$(OBJDIR)', '--NoWarn' )
227 dpurdie 2956
                        if ( $ScmSourceTypes{ StripFile($fn) } && $ScmSourceTypes{ StripFile($fn) } eq ".h" );
2957
                }
2958
 
2959
 
2960
                #
2961
                #   Append a toolset specfic object file name suffix
2962
                #   for Object files only
2963
                #
2964
                $fn .= ".$::o"
2965
                    if ( $cmd =~ /Object/ );
2966
 
2967
                #
2968
                #   Merge directory and filename parts
2969
                #
2970
                $fn = $use_dir . ( $use_dir ? "/" : ""  ) . $fn;
2971
 
2972
                #
2973
                #   Save for later user
2974
                #   Flag the file as a generated file
2975
                #
261 dpurdie 2976
                push @genreq_seen, $cmd;
303 dpurdie 2977
                if ( UniquePush (\@gen_files, $fn) )
2978
                {
2979
                    if ( GenerateSrcFile ( $gtype, $fn  ) && $gtype == 2 )
2980
                    {
2981
                        push @has_source, $fn;
2982
                    }
2983
                }
227 dpurdie 2984
 
2985
                #
2986
                #   Use the directory or the full name
2987
                #   If using the directory then ensure that we have a name
2988
                #   even if its "."
2989
                #
2990
                $fn = ($use_dir) ? "$use_dir" : "."
2991
                    if ( $cmd =~ /Directory/ );
2992
 
2993
                Debug( "GenerateFiles: Generate: $fn" );
2994
 
2995
            }
2996
            elsif ( $cmd =~ /^Prereq/ )
2997
            {
2998
                #
2999
                #   Prerequisite filename
3000
                #       Resolve the full name of the file. It may be known
3001
                #       as a source file (possibly generated) or it may be
3002
                #       located in a known source directory
3003
                #
3004
                $fn = LocatePreReq ($ufn);
3005
                UniquePush (\@preq_files, $fn);
3006
 
3007
                Debug( "GenerateFiles: Prereq: $fn" );
3008
 
3009
            }
3010
            elsif ( $cmd =~ /^PackageBase/ )
3011
            {
3012
                $fn = GetPackageBase( "GenerateFiles", $raw_arg );
3013
                UniquePush (\@preq_files, $fn);
3014
            }
3015
            elsif ( $cmd =~ /^PackageInfo/ )
3016
            {
3017
                $fn = GetPackageInfo( "GenerateFiles", $raw_arg );
3018
            }
3019
            elsif ( $cmd =~ /^Var/ )
3020
            {
343 dpurdie 3021
                ($fnp, $fn, $is_path) = ExpandGenVar( "GenerateFiles", $raw_arg, @var_opts );
227 dpurdie 3022
                $flags = '';
343 dpurdie 3023
                if ( $raw_arg eq 'ObjDir' ) {
3024
                    UniquePush (\@preq_files, '$(GBE_OBJDIR)');
3025
                } elsif ( $raw_arg eq 'BinDir' ) {
3026
                    UniquePush (\@preq_files, '$(GBE_BINDIR)');
3027
                } elsif ( $raw_arg eq 'LibDir' ) {
3028
                    UniquePush (\@preq_files, '$(GBE_LIBDIR)');
3029
                }
227 dpurdie 3030
            }
3031
            else
3032
            {
3033
                Warning ("GenerateFiles: Unknown replacement command: $cmd");
3034
                $fn = $ufn;
3035
            }
3036
 
3037
            #
3038
            #   Process path modification flags
3039
            #
3040
            $fn = ProcessPathName( $fn, $flags );
3041
 
3042
            #
3043
            #   Minor kludge under windows. Ensure directores have a "\" sep
3044
            #   Unless the user has specified a straight shell command
3045
            #
303 dpurdie 3046
            $fn = "\$(subst /,\\,$fn)"
343 dpurdie 3047
                if ( $is_path && $::ScmHost eq "WIN" && ! defined($shell_script) );
227 dpurdie 3048
 
3049
            #
343 dpurdie 3050
            #   Prepend any $fn Prefix
3051
            #   This will be a tag and is not subject to path processing
3052
            #
3053
            $fn = $fnp . $fn;
3054
 
3055
            #
227 dpurdie 3056
            #   Replace the found string with the real name of the file
3057
            #   Note: 4 argument version of substr is not always available
3058
            #         so we must do it the hard way
3059
            #               substr( $arg, $mb, $me - $mb, $fn);
3060
            #
3061
            $arg = substr( $arg, 0, $mb ) . $fn . substr( $arg, $me );
3062
 
3063
            Debug2( "GenerateFiles: subs: $all -> $fn" );
3064
        }
3065
 
3066
        #
3067
        #   Save the tool arguments in an array
3068
        #
3069
        push @tool_args, $arg;
3070
    }
3071
 
3072
 
3073
    #
3074
    #   Sanity test. Ensure that some file have been marged as generated
3075
    #                Warn if no prerequisites found
3076
    #
303 dpurdie 3077
    Warning( "GenerateFiles. --AutoGenerate option has no effect",
3078
             "The following files are 'source' files",  @has_source ) if ( @has_source );
227 dpurdie 3079
    Warning( "No Prerequisite files found in $tool",@tool_args) unless ( $no_warn || $#preq_files >= 0 );
3080
    Error  ( "No generated files found in $tool",@tool_args) unless ($#gen_files >= 0);
3081
 
3082
 
3083
    #
3084
    #   Save information
3085
    #   Will be used to create makefile statements later
3086
    #
3087
    my %gen_data;
3088
 
3089
    $gen_data{'index'}      = $NoGenIndex++;
3090
    $gen_data{'shell'}      = $shell_cmds;
3091
    $gen_data{'gen'}        = \@gen_files;
3092
    $gen_data{'preq'}       = \@preq_files;
3093
    $gen_data{'tool'}       = $tool;
3094
    $gen_data{'toolargs'}   = \@tool_args;
3095
    $gen_data{'clean'}      = $clean_tag;
3096
    $gen_data{'text'}       = $text || $gen_files[0];
3097
    $gen_data{'preq_sus'}   = 1 if ( $preq_unknown );
263 dpurdie 3098
    $gen_data{'predelete'}  = 1 if ( $predelete );
227 dpurdie 3099
 
3100
    push(@GENERATE_FILES, \%gen_data);
3101
 
3102
    Debug2( "GenerateFiles: cmd: $tool @tool_args" );
3103
}
3104
 
3105
#-------------------------------------------------------------------------------
3106
# Function        : MakePerlModule
3107
#
3108
# Description     : Build Perl Module(s) using the Perl Build System
3109
#                   This is a thin wrapper around a specialised script
3110
#
3111
#                   The user can do the same job with correct use of
3112
#                   a GenerateFiles, but this is a lot tidier.
3113
#
3114
# Inputs          : $1      - platform specifier '*' (comma delemitered)
3115
#                   $*      - Paths to Perl Modules[,command options]
3116
#                             Options to the BuildPerl script
3117
#
3118
# Returns         :
3119
#
3120
sub MakePerlModule
3121
{
3122
    my ( $platforms, @args) = @_;
3123
 
3124
    return if ( ! ActivePlatform($platforms) );
3125
 
3126
    Debug2( "MakePerlModule:($platforms, @args)" );
3127
    my @opts;
3128
 
3129
    #
3130
    #   Extract options from paths to Perl Packages
3131
    #   Package names do not start with a '-'
3132
    #
3133
    foreach my $arg ( @args )
3134
    {
3135
        if ( $arg =~ /^-/ ) {
3136
            push @opts, $arg;
3137
 
3138
        } else {
3139
            #
3140
            #   Perl Package Directory Name
3141
            #   This may also contain embedded command to the Make command
3142
            #   These will be seperated with a comma
3143
            #       ie: module,-options=fred
3144
            #
3145
            my ($name,$options) = split( ',', $arg );
3146
            push @opts, "-PerlPackage=$arg";
3147
            push @opts, "--Prereq=$name/Makefile.PL";
3148
        }
3149
    }
3150
 
3151
    #
3152
    #   Invoke GenerateFiles with a bunch of additional arguments
3153
    #
3154
    GenerateFiles ($platforms, "--Tool=jats_buildperl.pl",
3155
                          '--Var(MachType)',                        # Build Machine type
3156
                          '--Var(PackageDir)',                      # Package dir
3157
                          '--NoGenerate',                           # Don't know the output
3158
                          '--Text=Make Perl Module',                # Pretty print
3159
                          '--NoWarn',
3160
                          '--Clean=-clean_build',                   # Jats clean support
3161
                          '--NoVarTag',                             # No more Tags
3162
                          @opts,
3163
                          );
3164
}
3165
 
3166
#-------------------------------------------------------------------------------
3167
# Function        : MakeLinuxDriver
3168
#
3169
# Description     : Build a Linux Device Driver using the Linux Device Driver
3170
#                   Build System
3171
#                   This is a thin wrapper around a specialised script
3172
#
3173
#                   The user can do the same job with correct use of
3174
#                   a GenerateFiles, but this is a lot tidier.
3175
#
3176
# Inputs          : $1      - platform specifier '*' (comma delemitered)
3177
#                   $2      - name of the driver. No extension
3178
#                   $*      - Driver sources
3179
#                             Options to the script
3180
#
3181
# Returns         :
3182
#
3183
sub MakeLinuxDriver
3184
{
3185
    my ( $platforms, $driver_name, @args) = @_;
3186
 
3187
    return if ( ! ActivePlatform($platforms) );
3188
 
285 dpurdie 3189
    Error ("No driver name specified") unless ( $driver_name );
227 dpurdie 3190
    Debug2( "MakeLinuxDriver:($platforms, $driver_name ,@args)" );
3191
    my @srcs;
3192
    my @opts;
3193
 
3194
    #
3195
    #   Extract options from source files
3196
    #   Package names do not start with a '-'
3197
    #
3198
    foreach my $arg ( @args )
3199
    {
3200
         if ( $arg =~ /^--Define=(.)/ ) {
3201
            push @opts, $arg;
3202
 
3203
         } elsif ( $arg =~ /^-/ ) {
3204
            push @opts, $arg;
3205
            Warning ("MakeLinuxDriver: Unknown option: $arg. Passed to script");
3206
 
3207
        } else {
3208
            push @srcs, $arg;
3209
            push @opts, "--Prereq=$arg";
3210
        }
3211
    }
3212
 
3213
    #
3214
    #   Cleanup the drive name
3215
    #
3216
    $driver_name =~ s~\.ko$~~;
3217
 
3218
    #
3219
    #   Remove the specified sources from the list of object files
3220
    #   that will be build. This will ensure that some internal rules are
3221
    #   not generated.
3222
    #
3223
    foreach ( @srcs )
3224
    {
3225
        my $file = StripExt(StripDir( $_ ));
3226
        delete $OBJSOURCE{ $file };
3227
        @OBJS = grep(!/^$file$/, @OBJS);
3228
    }
3229
 
3230
    #
3231
    #   Invoke GenerateFiles with a bunch of additional arguments
3232
    #   At runtime the include directories will be added as
3233
    #   absolute paths
3234
    #
3235
    GenerateFiles ($platforms, "--Tool=jats_buildlinux.pl",
3236
                    "-Output=--GeneratedProg($driver_name.ko)",
3237
                    "-Driver=$driver_name",
3238
                    "-GccPath=\$(GCC_CC)",
3239
                    "-Arch=\$(HOST_CPU)",
3240
                    "-LeaveTmp=\$(LEAVETMP)",
3241
                    "-Verbose=\$(CC_PRE)",
3242
                    "-Type=\$(GBE_TYPE)",
3243
                    "-Platform=\$(GBE_PLATFORM)",
3244
                    '$(patsubst %,-Incdir=%,$(INCDIRS))',
3245
                    @opts,
3246
                    @srcs
3247
                    );
3248
}
3249
 
3250
#-------------------------------------------------------------------------------
3251
# Function        : GetPackageBase
3252
#
3253
# Description     : Helper routine
3254
#                   Given a package name, determine the base address of the
3255
#                   package
3256
#
3257
# Inputs          : $dname         - Directive name     (Reporting)
3258
#                   $name          - Required package
3259
#                                    Allows two forms:
3260
#                                       package_name
3261
#                                       package_name,ext
3262
#
3263
# Returns         : Path to the directory in which the files are installed
3264
#                   This may be the interface directory
3265
#
3266
sub GetPackageBase
3267
{
3268
    my ($dname, $fname) = @_;
3269
    my $pkg;
3270
    my ($name, $ext) = split(',', $fname);
3271
 
3272
    $pkg = GetPackageEntry( $name, $ext );
3273
    Error ("$dname: Package not found: $fname") unless ( $pkg );
3274
 
3275
    #
3276
    #   If a BuildPkgArchive then use the interface directory
3277
    #
3278
    return ( $pkg->{'TYPE'} eq 'link' ) ? $pkg->{'ROOT'} : '$(INTERFACEDIR)';
3279
}
3280
 
3281
#-------------------------------------------------------------------------------
3282
# Function        : GetPackageInfo
3283
#
3284
# Description     : Helper routine
3285
#                   Given a package name, return some information about the package
3286
#                   Only one information item is allowed with each call
3287
#
3288
# Inputs          : $dname         - Directive name     (Reporting)
3289
#                   $name          - Required package
3290
#                                    Allows two forms:
3291
#                                       package_name
3292
#                                       package_name,ext
3293
#                                    Selector
3294
#                                       --path
3295
#                                       --version
3296
#                                       --fullversion
3297
#                                       --project
3298
#
3299
# Returns         : Package information
3300
my %GetPackageInfo = qw(path ROOT
3301
                        version DVERSION
3302
                        fullversion VERSION
3303
                        project DPROJ);
3304
sub GetPackageInfo
3305
{
3306
    my ($dname, $args) = @_;
3307
    my $pkg;
3308
    my $name;
3309
    my $ext;
3310
    my $info;
3311
 
363 dpurdie 3312
    #
3313
    #   Split up the arguments
3314
    #       Options start with '--'
3315
    #   First non-option is the package name
3316
    #   2nd non-option is the packag extension
3317
    #
3318
    #   Only one option allowed
3319
    #       Convert it into a known package info item
3320
    #
3321
    #
227 dpurdie 3322
    foreach ( split(',', $args) )
3323
    {
3324
        if ( m/^--(.*)/ ) {
3325
            Error( "$dname: Too many info requests: $args") if ( $info );
3326
            $info = $GetPackageInfo{$1};
3327
            Error( "$dname: Unknown info type: $_") unless ($info);
363 dpurdie 3328
 
227 dpurdie 3329
        } elsif ( $ext ) {
3330
            Error("$dname: Too many names: $args");
363 dpurdie 3331
 
227 dpurdie 3332
        } elsif ( $name ) {
3333
            $ext = $_;
363 dpurdie 3334
 
227 dpurdie 3335
        } else {
3336
            $name = $_;
3337
        }
3338
    }
3339
 
3340
    $pkg = GetPackageEntry( $name, $ext );
3341
    Error ("$dname: Package not found: $args") unless ( $pkg );
3342
 
3343
    #
3344
    #   If a BuildPkgArchive then use the interface directory
363 dpurdie 3345
    #   Default data item - path to the package
227 dpurdie 3346
    #
363 dpurdie 3347
    $info = 'ROOT' unless ( $info );
3348
    if ( $info eq 'ROOT' &&  $pkg->{'TYPE'} ne 'link' )
227 dpurdie 3349
    {
3350
        return ( '$(INTERFACEDIR)');
3351
    }
363 dpurdie 3352
 
227 dpurdie 3353
    return ( $pkg->{$info} );
3354
}
3355
 
3356
#-------------------------------------------------------------------------------
3357
# Function        : GetPackageEntry
3358
#
3359
# Description     : Return the package class pointer given a package name
3360
#
3361
# Inputs          : $name          - Required package
3362
#                   $ext           - Option package extension
3363
#
3364
# Returns         : Class pointer
3365
#
3366
sub GetPackageEntry
3367
{
3368
    my ($name, $ext) = @_;
3369
    $ext = '' unless ( $ext );
3370
 
3371
    for my $entry (@{$::ScmBuildPkgRules{$ScmPlatform} })
3372
    {
3373
        next unless ( $entry->{'NAME'} eq $name );
3374
        next if ( $ext && $entry->{'DPROJ'} ne $ext );
3375
        return $entry;
3376
    }
285 dpurdie 3377
    return;
227 dpurdie 3378
}
3379
 
3380
#-------------------------------------------------------------------------------
3381
# Function        : ExpandGenVar
3382
#
3383
# Description     : Expand a known variable for the Generate Files option
3384
#
3385
# Inputs          : $dname         - Directive name     (Reporting)
3386
#                   $arg           - Raw argument
3387
#                                    This of the form of
3388
#                                       Tag[,--option]+
3389
#                                    Tags are specified in %ExpandGenVarConvert
3390
#
3391
#                                   Options are:
3392
#                                       --tag
3393
#                                       --notag
3394
#                                       --tag=<SomeTag>
3395
#                                       --absdrive
3396
#                                       --abspath
285 dpurdie 3397
#                                       --default=text
343 dpurdie 3398
#                                       --allownone
227 dpurdie 3399
#                                   Not all options are avalaible on all variables
3400
#                   @opts           - Options
3401
#                                       --notag     - Default is --notag
3402
#
343 dpurdie 3403
# Returns         : Tag             - Any tag component of the expansion
3404
#                   Path/Value      - Path/Value of the component
3405
#                   is_path         - Above is a path
3406
#                   is_abs          - Path is absolute
227 dpurdie 3407
#
3408
 
3409
#
3410
#   Create a Hash to simplify the process of converting Var names
343 dpurdie 3411
#   into makefile variables. There are two data items, separated by a comma.
3412
#       The first is the runtime expansion value
3413
#       The second describes the first:
3414
#           NotPresent  - Expansion is not a path
3415
#           '-'         - Expansion is a path and is relative to CWD
3416
#           '+'         - Expansion is a path and is absolute
227 dpurdie 3417
#
3418
my %ExpandGenVarConvert = (
3419
    'BuildName'         => '$(GBE_PBASE)',
3420
    'BuildVersion'      => '$(BUILDVER)',
3421
    'BuildVersionNum'   => '$(BUILDVERNUM)',
3422
 
3423
    'PackageDir'        => '$(PKGDIR),+',
3424
    'PackagePkgDir'     => '$(PKGDIR)/pkg/pkg.$(GBE_PLATFORM),+',
3425
    'PackageIncDir'     => '$(INCDIR_PKG),+',
3426
    'PackageLibDir'     => '$(LIBDIR_PKG)/$(GBE_PLATFORM),+',
3427
    'PackageBinDir'     => '$(BINDIR_PKG)/$(GBE_PLATFORM)$(GBE_TYPE),+',
3428
 
3429
    'PackageToolDir'    => '$(PKGDIR)/tools,+',
3430
    'PackageToolBin'    => '$(PKGDIR)/tools/bin/$(GBE_HOSTMACH),+',
3431
    'PackageToolScript' => '$(PKGDIR)/tools/scripts,+',
3432
 
3433
    'LibDir'            => '$(LIBDIR),+',
3434
    'BinDir'            => '$(BINDIR),+',
3435
    'ObjDir'            => '$(OBJDIR),+',
3436
 
3437
    'InterfaceDir'      => '$(INTERFACEDIR),+',
3438
    'InterfaceIncDir'   => '$(INCDIR_INTERFACE),+',
3439
    'InterfaceLibDir'   => '$(LIBDIR_INTERFACE)/$(GBE_PLATFORM),+',
3440
    'InterfaceBinDir'   => '$(BINDIR_INTERFACE)/$(GBE_PLATFORM)$(GBE_TYPE),+',
3441
 
3442
    'LocalDir'          => '$(LOCALDIR),+',
3443
    'LocalIncDir'       => '$(INCDIR_LOCAL),+',
3444
    'LocalLibDir'       => '$(LIBDIR_LOCAL)/$(GBE_PLATFORM),+',
3445
    'LocalBinDir'       => '$(BINDIR_LOCAL)/$(GBE_PLATFORM)$(GBE_TYPE),+',
3446
 
3447
    'Platform'          => '$(GBE_PLATFORM)',
3448
    'Product'           => '$(GBE_PRODUCT)',
3449
    'Target'            => '$(GBE_TARGET)',
3450
 
3451
    'Type'              => '$(GBE_TYPE)',
3452
    'Arch'              => '$(HOST_CPU)',
3453
    'Architecture'      => '$(HOST_CPU)',
3454
    'MachType'          => '$(GBE_HOSTMACH)',
3455
    'BuildRoot'         => '$(GBE_ROOT),+',
3456
 
3457
 
3458
    'Verbose'           => '$(CC_PRE)',
3459
    'LeaveTmp'          => '$(LEAVETMP)',
329 dpurdie 3460
    'Cwd'               => '$(CURDIR),-',
227 dpurdie 3461
 
3462
    'CompilerPath'      => '$(SCM_COMPILERPATH)',
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
 
5069
#-------------------------------------------------------------------------------
5070
# Function        : MakeProject
5071
#
5072
# Description     : A nasty directive that is intended to build a Microsoft
5073
#                   project for WINCE, WIN32 and .NET builds.
5074
#
5075
#                   There are many constraints:
5076
#                       Cannot be mixed with multi-platform builds
5077
#                       Some parameters are tool specific
5078
#
267 dpurdie 5079
#                   Allow programs to be Installed as well as Packaged
5080
#                   The 'Progect' is treated' as a program and it doesn't work
5081
#                   to well if we Install libraries.
227 dpurdie 5082
#
267 dpurdie 5083
#                   Only Reason to Install Programs is to allow the Cab Maker
5084
#                   to locate them.
5085
#
227 dpurdie 5086
# Inputs          : Platform        - Active platform
5087
#                   Project         - Project Name with extension
5088
#                   Options         - Many options
5089
#
5090
# Returns         :
5091
#
5092
our %PROJECTS;                          # Project information
5093
my  @PROJECTS_ORDER;
5094
sub MakeProject
5095
{
5096
    my( $platforms, $proj, @elements ) = @_;
5097
 
5098
    Debug2( "MakeProject($platforms, $proj, @elements)" );
5099
 
5100
    return if ( ! ActivePlatform($platforms) );
5101
 
5102
    #
5103
    #   Sanity test
5104
    #
5105
    Error ("MakeProject: Project name not defined") unless ( $proj );
5106
 
5107
    #
5108
    #   Take the project name and convert it into a full path
5109
    #
5110
    my $project = MakeSrcResolve ( $proj );
5111
    $proj = StripDir( $project );
237 dpurdie 5112
    Error ("Project File Not found: $project") unless ( -f $project );
227 dpurdie 5113
 
5114
    my $basedir = StripFileExt( $project );
5115
 
5116
    #
5117
    #   Collect user arguments
5118
    #   They are all processed within the toolset
5119
    #
5120
    my @tool_options;
5121
    foreach ( @elements )
5122
    {
5123
        if ( m/^--Debug/ ) {
5124
            $PROJECTS{$proj}{'Debug'} = 1;
5125
 
5126
        } elsif ( m/^--Prod/ ) {
5127
            $PROJECTS{$proj}{'Prod'} = 1;
5128
 
267 dpurdie 5129
        } elsif ( m/^--(Package|Install)ProgDebug=(.*)/ ) {
5130
            _PackageFromProject( $1, $proj, $basedir,'Prog', 'D', $2 );
227 dpurdie 5131
 
267 dpurdie 5132
        } elsif ( m/^--(Package|Install)Prog(Prod)*=(.*)/ ) {
5133
            _PackageFromProject( $1, $proj, $basedir, 'Prog', 'P', $3 );
227 dpurdie 5134
 
267 dpurdie 5135
        } elsif ( m/^--(Package)LibDebug=(.*)/ ) {
5136
            _PackageFromProject( $1, $proj, $basedir, 'Lib', 'D', $2 );
227 dpurdie 5137
 
267 dpurdie 5138
        } elsif ( m/^--(Package)Lib(Prod)*=(.*)/ ) {
5139
            _PackageFromProject( $1, $proj, $basedir, 'Lib', 'P', $3 );
227 dpurdie 5140
 
267 dpurdie 5141
        } elsif ( m/^--(Package)SharedLibDebug=(.*)/ ) {
5142
            _PackageFromProject( $1, $proj, $basedir, 'Lib', 'D', $2 );
227 dpurdie 5143
 
267 dpurdie 5144
        } elsif ( m/^--(Package)SharedLib(Prod)*=(.*)/ ) {
5145
            _PackageFromProject( $1, $proj, $basedir, 'Lib', 'P', $3 );
227 dpurdie 5146
 
267 dpurdie 5147
        } elsif ( m/^--(Package)Hdr=(.*)/ ) {
5148
            _PackageFromProject( $1, $proj, $basedir, 'Hdr', undef, $2 );
227 dpurdie 5149
 
267 dpurdie 5150
        } elsif ( m/^--(Package)File=(.*)/ ) {
5151
            _PackageFromProject( $1, $proj, $basedir, 'File', undef, $2 );
227 dpurdie 5152
 
267 dpurdie 5153
        } elsif ( m/^--(Package)Tool(Prod)*=(.*)/ ) {
5154
            _PackageFromProject( $1, $proj, $basedir, 'Tool', 'P', $3 );
241 dpurdie 5155
 
267 dpurdie 5156
        } elsif ( m/^--(Package)ToolDebug=(.*)/ ) {
5157
            _PackageFromProject( $1, $proj, $basedir, 'Tool', 'D', $2 );
241 dpurdie 5158
 
267 dpurdie 5159
        } elsif ( m/^--(Package|Install)/ ) {
5160
            Error("MakeProject. Unknown $1 option: $_");
227 dpurdie 5161
 
5162
        } else {
5163
            push @tool_options, $_;
5164
        }
5165
    }
5166
 
5167
    #
5168
    #   Save the information
5169
    #
5170
    $PROJECTS{$proj}{'options'} = \@tool_options;
5171
    $PROJECTS{$proj}{'name'} = $proj;
5172
    $PROJECTS{$proj}{'project'} = $project;
5173
    $PROJECTS{$proj}{'basedir'} = $basedir;
5174
    UniquePush (\@PROJECTS_ORDER, $proj);
5175
 
5176
    #
5177
    #   Validate some of the arguments
5178
    #
5179
    Error ("Makeproject. Conflicting options --Debug and --Prod" )
5180
        if ( $PROJECTS{$proj}{'Debug'}  && $PROJECTS{$proj}{'Prod'} );
5181
}
5182
 
5183
#-------------------------------------------------------------------------------
5184
# Function        : _PackageFromProject
5185
#
5186
# Description     : Save Packaged data from the project
5187
#
267 dpurdie 5188
# Inputs          : $tgt        - Install or Package
5189
#                   $proj       - Name of the project
227 dpurdie 5190
#                   $base       - Base directory of files
5191
#                   $etype      - Type of Package (Progs, Libs, ... )
5192
#                   $type       - Debug or Production or both
5193
#                   $items      - Item to add. It may be comma seperated
5194
#
267 dpurdie 5195
my %PackageToData = ( 'Package' =>
5196
                        { 'Hdr'   => \%PACKAGE_HDRS,
5197
                          'Lib'   => \%PACKAGE_LIBS,
5198
                          'Prog'  => \%PACKAGE_PROGS,
5199
                          'File'  => \%PACKAGE_FILES,
5200
                          'Tool'  => \%PACKAGE_FILES,
5201
                          '_BASE' => 'PBase',
5202
                        },
5203
                      'Install' =>
5204
                        { 'Hdr'   => \%INSTALL_HDRS,
5205
                          'Lib'   => \%INSTALL_LIBS,
5206
                          'Prog'  => \%INSTALL_PROGS,
5207
                          'File'  => undef,
5208
                          'Tool'  => undef,
5209
                          '_BASE' => 'IBase',
5210
                        },
227 dpurdie 5211
                    );
5212
 
5213
sub _PackageFromProject
5214
{
267 dpurdie 5215
    my( $tgt, $proj, $base, $etype, $type, $items ) = @_;
227 dpurdie 5216
    my $subdir = '';
5217
 
5218
    #
267 dpurdie 5219
    #   Sanity test
5220
    #
5221
    $type = '' unless ( $type );
5222
    Error ("INTERNAL. Bad packaging option: $tgt")   unless ( exists $PackageToData{$tgt} );
5223
    Error ("INTERNAL. Bad packaging option: $etype") unless ( exists $PackageToData{$tgt}{$etype} );
5224
    Error ("Unsupported packaging combination: $tgt$etype$type=$items") unless ( defined $PackageToData{$tgt}{$etype} );
5225
 
5226
    #
5227
    #   Determine the index into the 'PackageInfo' structure
5228
    #   This provides the symbolic name for the target package path
5229
    #   for Package or Install
5230
    #
5231
    #   The key '_BASE' is internal. Used only to provide this information
5232
    #
5233
    my $tbase = $PackageToData{$tgt}{'_BASE'};
5234
 
5235
    #
227 dpurdie 5236
    #   Process options
5237
    #
5238
    foreach my $item ( split (/,/, $items ) )
5239
    {
5240
        next unless ( $item =~ m/^--/ );
5241
        if ( $item =~ m/^--Subdir=(.*)/ )
5242
        {
5243
            $subdir = '/' . $1;
5244
            $subdir =~ s~//~/~g;
5245
            $subdir =~ s~/$~~g;
5246
        }
5247
        else
5248
        {
5249
            Warning( "MakeProject: Unknown packaging option ignored: $_" );
5250
        }
5251
    }
5252
 
5253
    #
5254
    #   Process files
5255
    #
5256
    foreach my $item ( split (/,/, $items ) )
5257
    {
5258
        next if ( $item =~ m/^--/ );
5259
 
267 dpurdie 5260
        my $tdir = $PackageInfo{$etype}{$tbase} . $PackageInfo{$etype}{'Dir'} . $subdir ;
227 dpurdie 5261
        my $fname = StripDir( $item );
5262
        my $target = $tdir . '/' . $fname;
5263
 
5264
        $item = "$base/$item" if ( $base );
5265
 
5266
        #
5267
        #   Do not use $(GBE_TYPE) in the target name
5268
        #   The existing package mechanism does not handle different
5269
        #   production and debug file naming mechanism, whereas the project
5270
        #   must. Convert $(GBE_TYPE) into P or D to ensure uniquness
5271
        #
387 dpurdie 5272
        $item = QuoteForMake($item);
5273
        $target = QuoteForMake($target);
227 dpurdie 5274
        $target =~ s~\$\(GBE_TYPE\)~$type~ if ($type);
5275
 
5276
        #
5277
        #   Create a PACKAGE entry suitable for processing by the normal packaging
5278
        #   routines. This is complicated because the Projects do not adhere to
267 dpurdie 5279
        #   the JATS file name conventions
227 dpurdie 5280
        #
5281
        my %package_entry;
5282
        $package_entry{'src'}   = $item;
5283
        $package_entry{'dir'}   = $tdir;
267 dpurdie 5284
        $package_entry{'set'}   = 'ALL' if ($tgt eq 'Package');
227 dpurdie 5285
        $package_entry{'type'}  = $type if ($type);
5286
 
267 dpurdie 5287
        $PackageToData{$tgt}{$etype}->{$target} = {%package_entry};
227 dpurdie 5288
    }
5289
}
5290
 
5291
#-------------------------------------------------------------------------------
5292
# Function        : MakeAnt
5293
#
5294
# Description     : A nasty directive to create JAR files via ANT
5295
#                   There are several limitations
5296
#                   This is closely related to the MakeProject directive
5297
#
5298
#
5299
# Inputs          : Platform            - Active platform
5300
#                   buildfile           - Name of the build.xml file
5301
#                   Options             - A few options
5302
#                                         --Jar=file
5303
#                                               Generated JAR file(s)
5304
#                                         --GeneratedFile=file
5305
#                                               Other generated files
5306
#                                               Used to flag JNI that must
5307
#                                               Occur early
5308
#                                          --AutoTest=<name>
5309
#                                               Supports unitAutomated unit test
5310
#                                               by calling build target <name>
5311
#                                          --UnitTest=<name>
5312
#                                               Supports unit test
5313
#                                               by calling build target <name>
5314
#                                          --PackageBase
5315
#                                               Provides path to base of all packages
5316
#
5317
# Returns         :
5318
#
5319
our %JAR_FILES;
5320
sub MakeAnt
5321
{
5322
    my( $platforms, $proj, @elements ) = @_;
5323
 
5324
    Debug2( "MakeAnt($platforms, $proj, @elements)" );
5325
 
5326
    return if ( ! ActivePlatform($platforms) );
5327
 
5328
    #
5329
    #   Sanity test
5330
    #
5331
    Error ("MakeAnt: build.xml name not defined") unless ( $proj );
5332
 
5333
    #
5334
    #   Take the project name and convert it into a full path
5335
    #
5336
    my $project;
5337
    $project = MakeSrcResolve ( $proj );
5338
    $proj = StripDir( $project );
237 dpurdie 5339
    Error ("Build File Not found: $project") unless ( -f $project );
227 dpurdie 5340
 
5341
    my $basedir = StripFileExt( $project );
5342
 
5343
    #
5344
    #   Collect user arguments
5345
    #   They are all processed within the toolset
5346
    #
5347
    my @tool_options;
5348
    my @generated;
5349
    my $unit_tests;
5350
    my $auto_tests;
5351
    my $package_base;
5352
 
5353
    foreach ( @elements )
5354
    {
5355
        if ( m/^--Debug/ ) {
5356
            $PROJECTS{$proj}{'Debug'} = 1;
5357
 
5358
        } elsif ( m/^--Prod/ ) {
5359
            $PROJECTS{$proj}{'Prod'} = 1;
5360
 
5361
        } elsif ( m/^--Jar=(.*)/ ) {
5362
            my $tgt = $1;
5363
               $tgt = "$basedir/$tgt" if ( $basedir );
5364
            my $fn = StripDir( $1 );
5365
            $JAR_FILES{$fn} = $tgt;
5366
            GenerateSrcFile( 0, $tgt );
5367
 
5368
        } elsif ( m/^--GeneratedFile=(.*)/ ) {
5369
            my $tgt = $1;
5370
            $tgt = "$basedir/$tgt" if ( $basedir );
5371
            push @generated, $tgt;
5372
            GenerateSrcFile( 2, $tgt );
5373
 
5374
        } elsif ( m/^--UnitTest=(.*)/ ) {
5375
            $unit_tests = $1
5376
 
5377
        } elsif ( m/^--AutoTest=(.*)/ ) {
5378
            $auto_tests = $1
5379
 
5380
        } elsif ( m/^--PackageBase/ ) {
5381
            $package_base = 1;
5382
 
5383
 
5384
        } elsif ( m/^--/ ) {
5385
            Error("MakeAnt. Unknown option ignored: $_");
5386
 
5387
        } else {
5388
            push @tool_options, $_;
5389
        }
5390
    }
5391
 
5392
    #
5393
    #   Extend option arguments to include the base dir of packages
5394
    #   Create definitions of the form PACKAGE_<name>
5395
    #
5396
    for my $entry (@{$::ScmBuildPkgRules{$ScmPlatform} })
5397
    {
5398
        next unless ( $entry->{'TYPE'} eq 'link' );
5399
        my $dir = $entry->{'ROOT'};
5400
        my $name = $entry->{'NAME'};
5401
        unless ( $package_base )
5402
        {
5403
            $dir .= '/jar';
5404
            next unless ( -d $dir );
5405
        }
5406
        push @tool_options, "-DPACKAGE_$name=$dir";
5407
    }
5408
    #
5409
    #   Extend options to include the base dir of the created package
5410
    #   Allows careful use for direct packaging of artifacts
5411
    #
5412
    push @tool_options, '-DPACKAGEDIR=$(PWD)/$(PKGDIR)';
5413
 
5414
    #
5415
    #   Save the information
5416
    #
5417
    $PROJECTS{$proj}{'options'} = \@tool_options;
5418
    $PROJECTS{$proj}{'generated'} = \@generated if ( @generated );
5419
    $PROJECTS{$proj}{'name'}    = $proj;
5420
    $PROJECTS{$proj}{'project'} = $project;
5421
    $PROJECTS{$proj}{'basedir'} = $basedir;
5422
    $PROJECTS{$proj}{'type'}    = 'ant';
5423
    $PROJECTS{$proj}{'unittest'} = $unit_tests if ( $unit_tests );
5424
    $PROJECTS{$proj}{'autotest'} = $auto_tests if ( $auto_tests );
5425
    UniquePush (\@PROJECTS_ORDER, $proj);
5426
 
5427
    $TESTS_TO_AUTORUN = 1 if ( $auto_tests );
263 dpurdie 5428
    $TESTS_TO_RUN = 1 if ( $unit_tests || $auto_tests );
227 dpurdie 5429
 
5430
    #
5431
    #   Validate some of the arguments
5432
    #
5433
    Error ("MakeAnt. Conflicting options --Debug and --Prod" )
5434
        if ( $PROJECTS{$proj}{'Debug'}  && $PROJECTS{$proj}{'Prod'} );
5435
}
5436
 
5437
###############################################################################
5438
#
5439
#   Installation/Packaging util functions
5440
#
5441
#-------------------------------------------------------------------------------
5442
# Function        : __TargetDir
5443
#
5444
# Description     : Internal function to process common arguments for
5445
#                   the PackageXxx directives
5446
#
5447
# Inputs          : flags           - Indicate how to handle this argument
5448
#                   base            - Base directory for this type of package
5449
#                   argument        - Argument to process
5450
#                   pdir            - Reference to resultant directory
5451
#                   ptype           - Reference to resultant type (P or D)(optional)
5452
#
5453
# Returns         : 0               - Agument not consumed
5454
#                   1               - Argument consumed
5455
#                   2               - Skip this directive
5456
#
5457
my $T_TYPE  = 0x0001;                           # Postfix GBE_TYPE
5458
my $T_PKG   = 0x0002;                           # Special --Dir handling
5459
my $T_MACH  = 0x0004;                           # Allow --Machine too
5460
my $T_GBE   = 0x0008;                           # Allow --Gbe too
5461
my $T_FILE  = 0x0010;                           # Suffix or prefix subdir
5462
 
5463
sub __TargetDir
5464
{
5465
    my( $flags, $base, $argument, $pdir, $ptype ) = @_;
5466
    my $dir  = "";
5467
    my $consumed = 0;
5468
 
5469
    #
5470
    #   Generate basic parts
5471
    #   Note Product will default to Platform
5472
    #
5473
    my $str_platform = '$(GBE_PLATFORM)';
5474
    my $str_product = $ScmProduct ? '$(GBE_PRODUCT)' : '$(GBE_PLATFORM)';
5475
    my $str_target = '$(GBE_TARGET)';
5476
    my $str_common = '$(GBE_OS_COMMON)';
5477
 
5478
    my $str_common_avail = 0;
5479
       $str_common_avail = 1 if ( exists( $::BUILDINFO{$ScmPlatform}{OS_COMMON} ));
5480
 
5481
 
5482
    #
5483
    #   Add requested suffix
5484
    #
5485
    if ($flags & $T_TYPE)
5486
    {
5487
        $str_platform .= '$(GBE_TYPE)';
5488
        $str_product  .= '$(GBE_TYPE)';
5489
        $str_target   .= '$(GBE_TYPE)';
5490
        $str_common   .= '$(GBE_TYPE)';
5491
    }
5492
 
5493
    #
5494
    #   Process the argument
5495
    #
5496
    $_ = $argument;
5497
    if ( /^--Debug/ ) {                         # In the Debug build only
5498
        if ( $ptype ) {
5499
            $$ptype = "D";
5500
            $consumed = 1;
5501
        }
5502
 
5503
    } elsif ( /^--Prod$/ || /^--Production$/ ) { # In the Production build only
5504
        if ( $ptype ) {
5505
            $$ptype = "P";
5506
            $consumed = 1;
5507
        }
5508
 
5509
    } elsif (/^--Prefix=(.*)/) {                # Prefix with subdir
5510
        $dir = "$base/$1";
5511
 
5512
    } elsif (/^--Subdir=(.*)/) {                # same as 'prefix'
5513
        $dir = "$base/$1";
5514
 
5515
    } elsif (/^--Platform$/) {                  # Platform installation
5516
        $dir = "$base/$str_platform";
5517
 
5518
    } elsif (/^--Platform=(.*?),(.*)/) {        # prefix and suffix with platform specific subdir
5519
        $dir = "$base/$1/$str_platform/$2";
5520
 
5521
    } elsif (/^--Platform=(.*)/) {              # prefix with platform specific subdir
5522
        if ($flags & $T_FILE) {
5523
            $dir = "$base/$1/$str_platform";
5524
        } else {
5525
            $dir = "$base/$str_platform/$1";
5526
        }
5527
 
5528
    } elsif (/^--Product$/) {                   # Product installation
5529
        $dir = "$base/$str_product";
5530
 
5531
    } elsif (/^--Product=(.*?),(.*)/) {         # prefix and suffix with product specific subdir
5532
        $dir = "$base/$1/$str_product/$2";
5533
 
5534
    } elsif (/^--Product=(.*)/) {               # prefix with product specific subdir
5535
        if ($flags & $T_FILE) {
5536
            $dir = "$base/$1/$str_product";
5537
        } else {
5538
            $dir = "$base/$str_product/$1";
5539
        }
5540
 
5541
    } elsif (/^--Target$/) {                    # Target installation
5542
        $dir = "$base/$str_target";
5543
 
5544
    } elsif (/^--Target=(.*?),(.*)/) {          # prefix and suffix with target specific subdir
5545
        $dir = "$base/$1/$str_target/$2";
5546
 
5547
    } elsif (/^--Target=(.*)/) {                # prefix with target specific subdir
5548
        if ($flags & $T_FILE) {
5549
            $dir = "$base/$1/$str_target";
5550
        } else {
5551
            $dir = "$base/$str_target/$1";
5552
        }
5553
 
5554
    } elsif (/^--OsCommon/) {
5555
 
5556
        unless ( $str_common_avail ) {
5557
            Warning("Packaging option --OsCommon not supported on this platform($ScmPlatform). Directive skipped");
5558
            $consumed = 2;
5559
 
5560
        } elsif (/^--OsCommon$/) {                  # OS installation
5561
            $dir = "$base/$str_common";
5562
 
5563
        } elsif (/^--OsCommon=(.*?),(.*)/) {        # prefix and suffix with target specific subdir
5564
            $dir = "$base/$1/$str_common/$2";
5565
 
5566
        } elsif (/^--OsCommon=(.*)/) {              # prefix with target specific subdir
5567
            if ($flags & $T_FILE) {
5568
                $dir = "$base/$1/$str_common";
5569
            } else {
5570
                $dir = "$base/$str_common/$1";
5571
            }
5572
        }
5573
 
5574
    } elsif (/^--Derived=(.*?),(.*?),(.*)/) {   # Derived target + prefix + subdir
5575
        $dir = "$base/$2/$1_$str_platform/$3";
5576
 
5577
    } elsif (/^--Derived=(.*?),(.*)/) {         # Derived target + subdir
5578
        if ($flags & $T_FILE) {
5579
            $dir = "$base/$2/$1_$str_platform";
5580
        } else {
5581
            $dir = "$base/$1_$str_platform/$2";
5582
        }
5583
 
5584
    } elsif (/^--Derived=(.*)/) {               # Derived target
5585
        $dir = "$base/$1_$str_platform";
5586
 
5587
    } elsif ($flags & $T_MACH && /^--Machine(([=])(.*))?$/) {   # Allow Machine and Machine=xxx specfic target
5588
        #
5589
        #   Special: Append machine type to user dir
5590
        #            Intended to create tools/bin/win32 and tools/bin/sparc directories
5591
        my $path = ( defined( $3) ) ? "/$3" : "";
5592
        $dir = "$base$path/\$(GBE_HOSTMACH)";
5593
 
5594
    } elsif ($flags & $T_GBE && /^--Gbe(([=])(.*))?$/) {   # Allow Gbe and Gbe=xxx specfic target
5595
        my $path = ( defined( $3) ) ? "/$3" : "";
5596
        $dir = "$base/gbe$path";
5597
 
5598
    } elsif (/^--Dir=(.*)/) {                   # prefix with target specific subdir
5599
        Error ('Packaging directive with --Dir option does not specify a directory.',
5600
               'Possible bad use of option of the form:--Dir=$xxx',
5601
               'Note: Use of package.pl and this construct is deprecated') unless ( $1 );
241 dpurdie 5602
        my $udir = $1;
5603
 
5604
        #
5605
        #   Remove leading ./
5606
        #   Check for leading ../
5607
        while ( $udir =~ s{^\./}{} ){};
5608
 
5609
        if ( $udir =~ m~^\.\./~ )
5610
        {
5611
            Warning("Packaging directive with --Dir option contains relative path (removed)", "Option: $_");
5612
            while ( $udir =~ s{^\.\./}{} ){};
5613
        }
227 dpurdie 5614
        if ($flags & $T_PKG) {
241 dpurdie 5615
            $dir = __PkgDir( $udir );
227 dpurdie 5616
        } else {
241 dpurdie 5617
            $dir = "\$(LOCALDIR)/$udir";
227 dpurdie 5618
        }
5619
    }
5620
 
5621
    return ($consumed) if ($dir eq "");
5622
    $dir =~ s~//~/~g;
5623
    $dir =~ s~/$~~;
5624
    $$pdir = $dir;
5625
    return (1);
5626
}
5627
 
5628
 
5629
#   __PkgDir ---
5630
#       Convert --Dir Package directives, removing leading subdir if
5631
#       matching the global $Pbase value.
5632
#
5633
#       Required as PKGDIR has the value 'GBE_ROOT/pkg/$Pbase'.
5634
#       Required to maintain compatability with older (package.pl) constructs
5635
#..
5636
 
5637
sub __PkgDir
5638
{
5639
    my( $dir ) = @_;
5640
    my $org = $dir;
5641
 
245 dpurdie 5642
    $dir =~ s~^\Q$::Pbase\E[/]?~~;
227 dpurdie 5643
    Debug2( "  PkgDir: converted \"$org\" to \"$dir\"" );
5644
 
5645
    $dir = "\$(PKGDIR)/$dir";
5646
    return $dir;
5647
}
5648
 
5649
 
5650
#   getMajorMinor ---
5651
#       Just a little help to deal with major/minor stuff for shared libs -
5652
#       given the name of the library as the argument, split out major and
5653
#       minor parts and return the basename, i.e name without major and minor
5654
#       and the pair of major and minor.
5655
#..
5656
 
285 dpurdie 5657
sub getMajorMinor
227 dpurdie 5658
{
5659
    my @bits = split ('\.', $_[0]);
5660
    my $stop;
5661
    my $major;
5662
    my $minor;
5663
 
5664
    if ( $#bits > 2 )
5665
    {
5666
        $stop = $#bits - 2;
5667
        $major = $bits[$#bits-1];
5668
        $minor = $bits[$#bits];
5669
    }
5670
    elsif ($#bits > 1)
5671
    {
5672
        $stop = $#bits-1;
5673
        $major = $bits[$#bits];
5674
        $minor=0;
5675
    }
5676
    else
5677
    {
5678
        $stop = $#bits; $major = 1; $minor = 0;
5679
    }
5680
 
5681
    my $base = $bits[0];
5682
    for ( my $i=1; $i <= $stop; $i++ ) {
5683
        $base = join ('.', $base, $bits[$i]);
5684
    }
5685
 
5686
    return ($base, $major, $minor);
5687
}
5688
 
5689
###############################################################################
5690
#
5691
#   Installation
5692
#
5693
 
5694
sub InstallHdr
5695
{
5696
    my( $platforms, @elements ) = @_;
335 dpurdie 5697
    my( $base, $dir, $srcfile, $full, $strip, $package );
227 dpurdie 5698
    my( $len, $name, $basename );
5699
 
5700
    Debug2( "InstallHdr($platforms, @elements)" );
5701
 
5702
    return if ( ! ActivePlatform($platforms) );
5703
    Warning ("InstallHdr: Needs local directory specified in build.pl") unless ( $::ScmLocal );
5704
 
5705
#.. Arguments
5706
#
5707
    $base = $PackageInfo{'Hdr'}{'IBase'};       # Base of target
5708
    $dir = $base . $PackageInfo{'Hdr'}{'Dir'};  # Installation path (default)
335 dpurdie 5709
    $full = $strip = 0;
227 dpurdie 5710
 
285 dpurdie 5711
    foreach ( @elements )
227 dpurdie 5712
    {
5713
                                                # Standard targets
5714
        my $rv = __TargetDir(0, $base, $_, \$dir);
5715
        next if ( $rv == 1 );
5716
        return if ( $rv == 2 );
5717
 
5718
        if (/^--Full/) {                        # using full (resolved) path
5719
            $full = 1;
5720
 
5721
        } elsif (/^--Strip$/) {                 # Strip path from source files
5722
            $strip = 1;
5723
 
5724
                                                # Package
5725
        } elsif (/^--Package$/ || /^--Package=(.*)/) {
5726
            $package = 1;
5727
 
5728
        } elsif (/^--(.*)/) {
5729
            Message( "InstallHdr: unknown option $_ -- ignored\n" );
5730
        }
5731
    }
5732
 
5733
#.. Files
5734
#
285 dpurdie 5735
    foreach ( @elements )
227 dpurdie 5736
    {
5737
        my %package_entry;
5738
        if ( ! /^--(.*)/ )
5739
        {
5740
            $name = $_;
5741
            $basename = StripDir( $name );
335 dpurdie 5742
            if ( !($srcfile = $SRCS{ $basename }) ) {
5743
                $srcfile = $name;
5744
            }
5745
 
227 dpurdie 5746
            if ( $full )
5747
            {
335 dpurdie 5748
                my $subdir = StripFileExt($srcfile);
5749
                $subdir = $1
5750
                    if ( $subdir =~ m~^$ProjectBase/(.*)~ );
5751
                $dir .= '/' . $subdir;
5752
                $dir =~ s~//~/~g;
5753
                $dir =~ s~/./~/~g;
5754
                $dir =~ s~/$~~g;
5755
                $name = $basename;
227 dpurdie 5756
            }
5757
 
5758
            $name = $basename
5759
                if ( $strip );
5760
 
5761
            Debug( "InstallHdr( $dir/$name, src: $srcfile, dest: $dir)" );
5762
 
5763
            $package_entry{'src'} = $srcfile;
5764
            $package_entry{'dir'} = StripFileExt( "$dir/$name" );
5765
            $INSTALL_HDRS{ "$dir/$name" } = {%package_entry};
5766
        }
5767
    }
5768
 
5769
#.. Package
5770
#
5771
    PackageHdr( @_ )                            # auto package
5772
        if ( $package );
5773
}
5774
 
5775
 
5776
sub InstallLib
5777
{
5778
    my( $platforms, @elements ) = @_;
5779
    my( $base, $dir, $package );
5780
    my( $lib, $strip );
289 dpurdie 5781
    my $org_lib;
227 dpurdie 5782
 
5783
    Debug2( "InstallLib($platforms, @elements)" );
5784
 
5785
    return if ( ! ActivePlatform($platforms) );
5786
    Warning ("InstallLib: Needs local directory specified in build.pl") unless ( $::ScmLocal );
5787
 
5788
#.. Arguments
5789
#
5790
    $base = $PackageInfo{'Lib'}{'IBase'};       # Base of target
5791
    $dir = $base . $PackageInfo{'Lib'}{'Dir'};  # Installation path (default)
5792
 
285 dpurdie 5793
    foreach ( @elements )
227 dpurdie 5794
    {
5795
                                                # Standard targets
5796
        my $rv = __TargetDir(0, $base, $_, \$dir);
5797
        next if ( $rv == 1 );
5798
        return if ( $rv == 2 );
5799
 
5800
        if (/^--Package$/ || /^--Package=(.*)/) {
5801
            $package = 1;
5802
 
5803
        } elsif (/^--Strip$/) {                 # Strip path from source files
5804
            $strip = 1;
5805
 
5806
        } elsif (/^--(.*)/) {
5807
            Message( "InstallLib: unknown option $_ -- ignored\n" );
5808
        }
5809
    }
5810
 
5811
#.. Files
5812
#
285 dpurdie 5813
    foreach ( @elements )
227 dpurdie 5814
    {
5815
        my %package_entry;
5816
        if ( ! /^--(.*)/ )
5817
        {
5818
            $_ = basename ($_)
5819
                if ( $strip );
289 dpurdie 5820
            $org_lib = $_;                      # Original name
227 dpurdie 5821
 
5822
            if ( $ScmTargetHost eq "Unix" ) {
5823
                $lib = "lib$_";                 # Prefix "lib" ....
5824
                $lib =~ s/^liblib/lib/;         # @LIBS already has lib added
5825
            } else {
5826
                $lib = $_;
5827
            }
5828
 
289 dpurdie 5829
            if (  my $libp = $SHLIBS->Get($lib) )
227 dpurdie 5830
            {
5831
                Debug( "InstallLib( $dir/$lib\$(GBE_TYPE).$::so, " .
5832
                    "src: \$(LIBDIR)/$lib\$(GBE_TYPE).$::so, dest: $dir)" );
5833
 
5834
                #
5835
                #   Create a "placekeeper" entry within $INSTALL_SHLIBS
5836
                #   The exact format of the name of the shared library is
5837
                #   toolset specific. Create an entry to allow the toolset
5838
                #   to extend the packaging information when the shared library
5839
                #   recipe is constructed.
5840
                #
289 dpurdie 5841
                my $ver = $libp->{ VERSION };
227 dpurdie 5842
                my $name = "$dir/$lib.$ver.PlaceKeeper";
5843
 
5844
                $package_entry{'placekeeper'} = 1;
5845
                $package_entry{'version'} = $ver;
5846
                $package_entry{'lib'} = $lib;
5847
                $package_entry{'dir'} = $dir;
289 dpurdie 5848
 
5849
                push @{$SHLIB_INS{$lib}}, $name;
227 dpurdie 5850
                $INSTALL_SHLIBS{$name} = {%package_entry};
5851
            }
5852
 
289 dpurdie 5853
            #
5854
            #   Clean up the package_entry
5855
            #   Insert common items
5856
            #
5857
            %package_entry = ();
5858
            $package_entry{'lib'} = $lib;
5859
            $package_entry{'dir'} = $dir;
5860
 
321 dpurdie 5861
            if ( my $libfile = $SRCS{$org_lib} )
227 dpurdie 5862
            {
5863
                #
5864
                #   Allow the user to package a sourced file as a library
289 dpurdie 5865
                #   But must be the un-massaged name of the file.
227 dpurdie 5866
                #
289 dpurdie 5867
                $package_entry{'dst'} = "$dir/$org_lib";
5868
                $package_entry{'src'} = $libfile;
5869
            }
5870
            elsif ( $LIBS->Get($lib) )
5871
            {
5872
                #
5873
                #   Install a library known to the makefile
5874
                #
5875
                my $libp = $LIBS->Get($lib);
227 dpurdie 5876
 
289 dpurdie 5877
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
5878
                $package_entry{'src'}    = $libp->getPath();
227 dpurdie 5879
            }
289 dpurdie 5880
            elsif ( ! $SHLIBS->Get($lib) )
227 dpurdie 5881
            {
289 dpurdie 5882
                #
5883
                #   Not a known shared lib
5884
                #   Not a known static lib
5885
                #   Not a 'sourced' file
5886
                #   Assume the a static library has magically appeared
5887
                #   in the standard LIB directory. May have been placed there
5888
                #   by a 'rule'
5889
                #
5890
                my $libp = $LIBS->New($lib);
227 dpurdie 5891
 
289 dpurdie 5892
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
5893
                $package_entry{'src'}    = $libp->getPath();
5894
            }
227 dpurdie 5895
 
289 dpurdie 5896
            #
5897
            #   Add entry to various lists if required
5898
            #
5899
            PackageLib_AddEntry ('InstallLib', \%LIB_INS, \%INSTALL_LIBS, \%package_entry )
5900
                if ( exists $package_entry{'dst'} );
227 dpurdie 5901
        }
5902
    }
5903
 
5904
#.. Package
5905
#
5906
    PackageLib( @_ )                            # auto package
5907
        if ( $package );
5908
}
5909
 
5910
 
5911
sub InstallJar
5912
{
5913
    my( $platforms, @elements ) = @_;
5914
    my( $base, $dir, $package );
5915
    my( $jar );
5916
 
5917
    Debug2( "InstallJar($platforms, @elements)" );
5918
 
5919
    return if ( ! ActivePlatform($platforms) );
5920
    Warning ("InstallJar: Needs local directory specified in build.pl") unless ( $::ScmLocal );
5921
 
5922
#.. Arguments
5923
#
5924
    $base = $PackageInfo{'Jar'}{'IBase'};       # Base of target
5925
    $dir = $base . $PackageInfo{'Jar'}{'Dir'};  # Installation path (default)
5926
 
285 dpurdie 5927
    foreach ( @elements )
227 dpurdie 5928
    {
5929
                                                # Standard targets
5930
        my $rv = __TargetDir(0, $base, $_, \$dir);
5931
        next if ( $rv == 1 );
5932
        return if ( $rv == 2 );
5933
 
5934
        if (/^--Package$/ || /^--Package=(.*)/) {
5935
            $package = 1;
5936
 
5937
        } elsif (/^--(.*)/) {
5938
            Message( "InstallJar: unknown option $_ -- ignored\n" );
5939
        }
5940
    }
5941
 
5942
 
5943
#.. Files
5944
#
285 dpurdie 5945
    foreach ( @elements )
227 dpurdie 5946
    {
5947
        my %package_entry;
5948
        if ( ! /^--(.*)/ )
5949
        {
5950
            $jar = $_;
5951
            my $src;
5952
            my $dest;
5953
 
5954
            if ( $JAR_FILES{$jar} )
5955
            {
5956
                $src = $JAR_FILES{$jar};
5957
                $dest = $jar;
5958
            }
5959
            else
5960
            {
5961
                $src = "\$(CLSDIR)/$jar\$(GBE_TYPE).jar";
5962
                $dest = "$jar\$(GBE_TYPE).jar";
5963
            }
5964
 
5965
 
5966
            Debug( "InstallJar( $dir/$dest, " .
5967
                "src: $src, dest: $dir)" );
5968
 
5969
            $package_entry{'src'} = $src;
5970
            $package_entry{'dir'} = $dir;
5971
            $INSTALL_CLSS{ "$dir/$dest" } = {%package_entry};
5972
 
5973
        }
5974
    }
5975
 
5976
#.. Package
5977
#
5978
    PackageJar( @_ )                            # auto package
5979
        if ( $package );
5980
}
5981
 
5982
 
5983
sub InstallProg
5984
{
5985
    my( $platforms, @elements ) = @_;
5986
    my( $base, $dir, $package );
5987
    my( $prog );
5988
 
5989
    Debug2( "InstallProg($platforms, @elements)" );
5990
 
5991
    return if ( ! ActivePlatform($platforms) );
5992
    Warning ("InstallProg: Needs local directory specified in build.pl") unless ( $::ScmLocal );
5993
 
5994
#.. Arguments
5995
#
5996
    $base = $PackageInfo{'Prog'}{'IBase'};       # Base of target
5997
    $dir = $base . $PackageInfo{'Prog'}{'Dir'};  # Installation path (default)
5998
 
285 dpurdie 5999
    foreach ( @elements )
227 dpurdie 6000
    {
6001
                                                # Standard targets
6002
        my $rv = __TargetDir($T_TYPE, $base, $_, \$dir);
6003
        next if ( $rv == 1 );
6004
        return if ( $rv == 2 );
6005
 
6006
        if (/^--Package$/ || /^--Package=(.*)/) {
6007
            $package = 1;
6008
 
6009
        } elsif (/^--(.*)/) {
6010
            Message( "InstallProg: unknown option $_ -- ignored\n" );
6011
        }
6012
    }
6013
 
6014
#.. Files
6015
#
285 dpurdie 6016
    foreach ( @elements )
227 dpurdie 6017
    {
6018
        my %package_entry;
6019
        if ( ! /^--(.*)/ )
6020
        {
6021
            my $ext = "";
6022
            $prog = $_;
6023
 
6024
            #
6025
            #   If the named target is a program then append the correct
6026
            #   extension. Otherwise assume that the target is either a script
6027
            #   or a some other file - and don't append an extension
6028
            #
6029
            $ext = $::exe
289 dpurdie 6030
                if ( $PROGS->Get($prog) );
227 dpurdie 6031
 
6032
            #
6033
            #   A "file" that is specified with a "Src" directive may be
6034
            #   installed as though it were a program
6035
            #
6036
            my $progfile;
6037
            $progfile = "\$(BINDIR)/$prog$ext"
6038
                unless ( $progfile = $SRCS{$prog} );
6039
 
6040
            Debug( "InstallProg( $dir/$prog$ext, " .
6041
                 "src: $progfile, dest: $dir)" );
6042
 
6043
            push @{$PROG_INS{$prog}}, "$dir/$prog$ext";
6044
 
6045
            $package_entry{'src'} = $progfile;
6046
            $package_entry{'dir'} = $dir;
6047
            $INSTALL_PROGS{ "$dir/$prog$ext" } = {%package_entry};
6048
        }
6049
    }
6050
 
6051
#.. Package
6052
#
6053
    PackageProg( @_ )                           # auto package
6054
        if ( $package );
6055
}
6056
 
6057
 
6058
###############################################################################
6059
#
6060
#   Packaging
6061
#
6062
sub PackageDist
6063
{
6064
    my( $name, @elements ) = @_;
6065
 
6066
    Debug2( "PackageDist($name, @elements)" );
6067
 
6068
    foreach ( @elements )
6069
    {
6070
    #.. Distribution sets
6071
    #
6072
        HashJoin( \%PACKAGE_DIST, $;, $name, "$_" );
6073
 
6074
    #.. Summary of distribution sets
6075
    #
267 dpurdie 6076
        $PACKAGE_SETS{ $_ }{'TAG'} = 1
6077
            if ( ! exists $PACKAGE_SETS{ $_ }{'TAG'} );
227 dpurdie 6078
    }
6079
}
6080
 
311 dpurdie 6081
#-------------------------------------------------------------------------------
6082
# Function        : PackageFile
6083
#
6084
# Description     : Directive to package files
6085
#                   Not to be used to package libraries, executables, headers
6086
#                   as this should be done by specialised directives
6087
#
6088
#                   Use to package other files
6089
#                   Can package an entire tree (ugly)
6090
#
6091
# Inputs          : 
6092
#
6093
#
227 dpurdie 6094
sub PackageFile
6095
{
6096
    my( $platforms, @elements ) = @_;
335 dpurdie 6097
    my( $base, $dir, $full, $path, $dist, $strip, $exefile, $type );
227 dpurdie 6098
    my( $name, $basename, $len, $srcfile );
341 dpurdie 6099
    my( $dir_tree, @dir_tree_exclude, @dir_tree_include, $strip_base );
335 dpurdie 6100
    my $recurse = 1;
227 dpurdie 6101
 
6102
    Debug2( "PackageFile($platforms, @elements)" );
6103
 
6104
    return if ( !$ScmPackage );                 # Packaging enabled ?
6105
    return if ( ! ActivePlatform($platforms) );
6106
 
6107
#.. Arguments
6108
#
6109
    $dist = "ALL";                                  # Default set (ALL)
6110
    $base = $PackageInfo{'File'}{'PBase'};          # Base of target
6111
    $dir = $base . $PackageInfo{'File'}{'Dir'};     # Installation path (default)
335 dpurdie 6112
    $full = 0;
227 dpurdie 6113
    $strip = 0;
341 dpurdie 6114
    $strip_base = 0;
227 dpurdie 6115
    $exefile = 0;
6116
 
285 dpurdie 6117
    foreach ( @elements )
227 dpurdie 6118
    {
6119
        my $rv = __TargetDir($T_PKG|$T_MACH|$T_GBE|$T_FILE, $base, $_, \$dir, \$type);
6120
        next if ( $rv == 1 );
6121
        return if ( $rv == 2 );
6122
 
6123
        if (/^--Full/) {                        # Using full (resolved) path
6124
            $full = 1;
6125
 
6126
        } elsif (/^--Set=(.*)/) {               # Distribution set
6127
            $dist = "$1";
6128
 
6129
        } elsif (/^--Package$/) {               # Package .. call by InstallFile
6130
        } elsif (/^--Package=(.*)/) {
6131
            $dist = "$1";
6132
 
6133
        } elsif (/^--Strip$/) {                 # Strip path from source files
6134
            $strip = 1;
6135
 
6136
        } elsif (/^--Executable$/) {            # Mark the file as executable
6137
            $exefile = "X";
6138
 
6139
        } elsif ( /^--DirTree=(.*)/ ) {
6140
            Error("DirTree. Multiple directories not allowed.") if ( $dir_tree );
6141
            $dir_tree = $1;
6142
 
6143
            Error("DirTree cannot extend outside current subtree. '..' not allowed.",
6144
                  "Directory: $dir_tree") if ( $dir_tree =~ m~\.\.~ );
6145
            Error("DirTree. Absolute paths are not allowed",
6146
                  "Directory: $dir_tree") if ( $dir_tree =~ m~^/~ || $dir_tree =~ m~^.\:~ );
6147
            Error("DirTree. Directory not found",
6148
                  "Directory: $dir_tree") unless  ( -d $dir_tree );
6149
 
6150
        } elsif ( /^--FilterOut=(.*)/ ) {
6151
            push @dir_tree_exclude, $1;
6152
 
6153
        } elsif ( /^--FilterIn=(.*)/ ) {
6154
            push @dir_tree_include, $1;
6155
 
6156
        } elsif ( /^--StripDir/ ) {
341 dpurdie 6157
            $strip_base = 1;
227 dpurdie 6158
 
335 dpurdie 6159
        } elsif ( m/^--Recurse/ ) {
6160
            $recurse = 1;
6161
 
6162
        } elsif ( m/^--NoRecurse/ ) {
6163
            $recurse = 0;
6164
 
227 dpurdie 6165
        } elsif (/^--(.*)/) {
6166
            Message( "PackageFile: unknown option $_ -- ignored\n" );
6167
        }
6168
    }
6169
 
6170
 
6171
    #.. DirTree expansion
6172
    #   Note: Uses REs, not simple globs
6173
    #         Use JatsLocateFiles to do the hard work
6174
    if ( $dir_tree )
6175
    {
335 dpurdie 6176
        my $search = JatsLocateFiles->new('FullPath' );
6177
        $search->recurse($recurse);
227 dpurdie 6178
        $search->filter_in_re ( $_ ) foreach ( @dir_tree_include );
6179
        $search->filter_out_re( $_ ) foreach ( @dir_tree_exclude );
1429 dpurdie 6180
        $search->filter_out_re( '/\.svn/' );
227 dpurdie 6181
        @elements = $search->search ( $dir_tree );
341 dpurdie 6182
        $strip_base = length( $dir_tree ) if ( $strip_base );
227 dpurdie 6183
    }
6184
 
6185
#.. Files
6186
#
285 dpurdie 6187
    foreach ( @elements )
227 dpurdie 6188
    {
6189
        my %package_entry;
299 dpurdie 6190
        $name = $_;
6191
 
227 dpurdie 6192
        #
299 dpurdie 6193
        #   Trap special files
6194
        #       DPACKAGE - but only if we have a DPackageLibrary directive
6195
        #                  in the same makefile.
6196
        #
6197
        if ( m~^DPACKAGE$~ && $DPackageDirective ) {
6198
            $name = 'DPACKAGE.' . $::GBE_MACHTYPE;
6199
        }
6200
 
6201
        #
387 dpurdie 6202
        #   Allow for named files that must be quoted
6203
        $name = QuoteForMake( $name );
227 dpurdie 6204
 
6205
        if ( ! /^--(.*)/ )
6206
        {
6207
            $basename = StripDir( $name );
335 dpurdie 6208
            if ( !($srcfile = $SRCS{ $basename }) ) {
6209
                $srcfile = $name;
6210
            }
6211
 
227 dpurdie 6212
            if ( $full )
6213
            {
335 dpurdie 6214
                my $subdir = StripFileExt($srcfile);
6215
                $subdir = $1
6216
                    if ( $subdir =~ m~^$ProjectBase/(.*)~ );
6217
                $dir .= '/' . $subdir;
6218
                $dir =~ s~//~/~g;
6219
                $dir =~ s~/./~/~g;
6220
                $dir =~ s~/$~~g;
6221
                $name = $basename;
227 dpurdie 6222
            }
6223
 
6224
            $name = $basename
6225
                if ( $strip );
6226
 
341 dpurdie 6227
            if ( $strip_base )
6228
            {
6229
                $name = substr $name, $strip_base;
6230
                $name =~ s~^/~~;
6231
            }
6232
 
227 dpurdie 6233
            $dir =~ s~//~/~g;
6234
            $dir =~ s~/$~~;
6235
 
6236
            #
6237
            #   Sanity test the source filename
6238
            #   User may have misused an option
6239
            #
6240
            if ( ( $srcfile =~ m/=/ ) || ( $srcfile =~ m/^-/ ) || ( $srcfile =~ m~/-~ )  )
6241
            {
6242
               Warning ("PackageFile: Suspect source filename: $srcfile");
6243
            }
6244
 
6245
            Debug( "PackageFile( $dir/$name, " .
6246
                "src: $srcfile, dest: $dir, dist: $dist, exe: $exefile )" );
6247
 
6248
            $package_entry{'src'} = $srcfile;
6249
            $package_entry{'dir'} = StripFileExt( "$dir/$name" );
6250
            $package_entry{'set'} = $dist;
6251
            $package_entry{'exe'} = $exefile if $exefile;
6252
            $package_entry{'type'} = $type if ( $type );
6253
 
6254
            $PACKAGE_FILES{ "$dir/$name" } = {%package_entry};
6255
        }
6256
    }
6257
}
6258
 
6259
sub PackageHdr
6260
{
6261
    my( $platforms, @elements ) = @_;
335 dpurdie 6262
    my( $base, $dir, $full, $path, $dist, $strip );
227 dpurdie 6263
    my( $name, $basename, $len, $srcfile );
6264
 
6265
    Debug2( "PackageHdr($platforms, @elements)" );
6266
 
6267
    return if ( !$ScmPackage );                 # Packaging enabled ?
6268
    return if ( ! ActivePlatform($platforms) );
6269
 
6270
#.. Arguments
6271
#
6272
    $dist = "ALL";                                  # Default set (ALL)
6273
    $base = $PackageInfo{'Hdr'}{'PBase'};           # Base of target
6274
    $dir = $base . $PackageInfo{'Hdr'}{'Dir'};      # Installation path (default)
335 dpurdie 6275
    $full = 0;
227 dpurdie 6276
    $strip = 0;
6277
 
285 dpurdie 6278
    foreach ( @elements )
227 dpurdie 6279
    {
6280
        my $rv = __TargetDir($T_PKG, $base, $_, \$dir);
6281
        next if ( $rv == 1 );
6282
        return if ( $rv == 2 );
6283
 
6284
        if (/^--Full/) {                        # Using full (resolved) path
6285
            $full = 1;
6286
 
6287
        } elsif (/^--Set=(.*)/) {               # Distribution set
6288
            $dist = "$1";
6289
 
6290
        } elsif (/^--Package$/) {               # Package .. call by InstallHdr
6291
        } elsif (/^--Package=(.*)/) {
6292
            $dist = "$1";
6293
 
6294
        } elsif (/^--Strip$/) {                 # Strip path from source files
6295
            $strip = 1;
6296
 
6297
        } elsif (/^--(.*)/) {
6298
            Message( "PackageHdr: unknown option $_ -- ignored\n" );
6299
        }
6300
    }
6301
 
6302
#.. Files
6303
#
285 dpurdie 6304
    foreach ( @elements )
227 dpurdie 6305
    {
6306
        my %package_entry;
6307
        if ( ! /^--(.*)/ )
6308
        {
387 dpurdie 6309
            $name = QuoteForMake($_);
227 dpurdie 6310
            $basename = StripDir( $name );
335 dpurdie 6311
            if ( !($srcfile = $SRCS{ $basename }) ) {
6312
                $srcfile = $name;
6313
            }
6314
 
227 dpurdie 6315
            if ( $full )
6316
            {
335 dpurdie 6317
                my $subdir = StripFileExt($srcfile);
6318
                $subdir = $1
6319
                    if ( $subdir =~ m~^$ProjectBase/(.*)~ );
6320
                $dir .= '/' . $subdir;
6321
                $dir =~ s~//~/~g;
6322
                $dir =~ s~/./~/~g;
6323
                $dir =~ s~/$~~g;
6324
                $name = $basename;
227 dpurdie 6325
            }
6326
 
6327
            $name = $basename
6328
                if ( $strip );
6329
 
6330
            Debug( "PackageHdr( $dir/$name, " .
6331
                "src: $srcfile, dest: $dir, dist: $dist )" );
6332
 
6333
            $package_entry{'src'} = $srcfile;
6334
            $package_entry{'dir'} = StripFileExt( "$dir/$name" );
6335
            $package_entry{'set'} = $dist;
6336
 
6337
            $PACKAGE_HDRS{ "$dir/$name" } = {%package_entry};
6338
        }
6339
    }
6340
}
6341
 
6342
 
6343
sub PackageLib
6344
{
6345
    my( $platforms, @elements ) = @_;
6346
    my( $base, $dir, $dist, $type );
6347
    my( $lib, $org_lib, %extras, $strip );
6348
 
6349
    Debug2( "PackageLib($platforms, @elements)" );
6350
 
6351
    return if ( !$ScmPackage );                 # Packaging enabled ?
6352
    return if ( ! ActivePlatform($platforms) );
6353
 
6354
#.. Arguments
6355
#
6356
    $dist = "ALL";                              # Default set (ALL)
6357
    $base = $PackageInfo{'Lib'}{'PBase'};       # Base of target
6358
    $dir = $base . $PackageInfo{'Lib'}{'Dir'};  # Installation path (default)
6359
    $type = "";
6360
 
285 dpurdie 6361
    foreach ( @elements )
227 dpurdie 6362
    {
6363
                                                # Standard targets
6364
        my $rv = __TargetDir($T_PKG, $base, $_, \$dir, \$type);
6365
        next if ( $rv == 1 );
6366
        return if ( $rv == 2 );
6367
 
6368
        if (/^--Set=(.*)/) {                    # Distribution set(s)
6369
            $dist = "$1";
6370
 
6371
        } elsif (/^--Package$/) {               # Package .. call by PackageLib
6372
        } elsif (/^--Package=(.*)/) {
6373
            $dist = "$1";
6374
 
6375
        } elsif (/^--Extras=(.*)/) {            # Extras=[none, .. ,all]
6376
            foreach my $elem ( split( ',', $1 ) )
6377
            {
6378
                Error ("PackageLib: Unknown Extras mode: $elem")
6379
                    unless ( grep m/$elem/, qw(none stub map lint debug all) );
6380
                $extras{$elem} = 1;
6381
            }
6382
            %extras = () if ( $extras{'all'} );
6383
 
6384
        } elsif (/^--Strip$/) {                 # Strip path from source files
6385
            $strip = 1;
6386
 
6387
        } elsif (/^--(.*)/) {
6388
            Message( "PackageLib: unknown option $_ -- ignored\n" );
6389
        }
6390
    }
6391
 
6392
#.. Files
6393
#
285 dpurdie 6394
    foreach ( @elements )
227 dpurdie 6395
    {
6396
        my %package_entry;
6397
        if ( ! /^--(.*)/ )
6398
        {
6399
            $_ = StripDir( $_ )
6400
                if ( $strip );
6401
 
6402
            $org_lib = $_;                      # Original name
6403
            if ( $ScmTargetHost eq "Unix" ) {
6404
                $lib = "lib$_";                 # Prefix "lib" ....
6405
                $lib =~ s/^liblib/lib/;         # @LIBS already has lib added
6406
            } else {
6407
                $lib = $_;
6408
            }
6409
 
289 dpurdie 6410
            if (  my $libp = $SHLIBS->Get($lib) )
227 dpurdie 6411
            {
6412
                Debug( "PackageLib( $dir/$lib\$(GBE_TYPE).$::so, " .
6413
                    "src: \$(LIBDIR)/$lib\$(GBE_TYPE).$::so, dest: $dir, dist: $dist, type: $type )" );
6414
 
6415
                #
6416
                #   Create a "placekeeper" entry within $PACKAGE_SHLIBS
6417
                #   The exact format of the name of the shared library is
6418
                #   toolset specific. Create an entry to allow the toolset
6419
                #   to extend the packaging information when the shared library
6420
                #   recipe is constructed.
6421
                #
6422
                #
289 dpurdie 6423
                my $ver = $libp->{ VERSION };
227 dpurdie 6424
                my $name = "$dir/$lib.$ver.PlaceKeeper";
6425
 
6426
                $package_entry{'placekeeper'} = 1;
6427
                $package_entry{'version'} = $ver;
6428
                $package_entry{'lib'} = $lib;
6429
                $package_entry{'dir'} = $dir;
6430
                $package_entry{'set'} = $dist;
6431
                $package_entry{'type'} = $type if ( $type );
6432
                $package_entry{'extras'} = {%extras} if ( scalar %extras );
289 dpurdie 6433
 
6434
                push @{$SHLIB_PKG{$lib}}, $name;
227 dpurdie 6435
                $PACKAGE_SHLIBS{$name} = {%package_entry};
6436
            }
6437
 
289 dpurdie 6438
            #
6439
            #   Clean up the package_entry
6440
            #   Insert common items
6441
            #
6442
            %package_entry = ();
6443
            $package_entry{'lib'} = $lib;
6444
            $package_entry{'dir'} = $dir;
6445
            $package_entry{'set'} = $dist;
6446
            $package_entry{'extras'} = {%extras} if ( scalar %extras );
6447
            $package_entry{'type'} = $type if ( $type );
6448
 
227 dpurdie 6449
            if ( my $libfile = $SRCS{$org_lib} )
6450
            {
6451
                #
6452
                #   Allow the user to package a sourced file as a library
6453
                #   But must be the un-massaged name of the file.
6454
                #
387 dpurdie 6455
                $package_entry{'dst'} = QuoteForMake("$dir/$org_lib");
6456
                $package_entry{'src'} = QuoteForMake($libfile);
289 dpurdie 6457
            }
6458
            elsif ( $LIBS->Get($lib) )
6459
            {
6460
                #
6461
                #   Package up a library known to the makefile
6462
                #
6463
                my $libp = $LIBS->Get($lib);
227 dpurdie 6464
 
289 dpurdie 6465
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
6466
                $package_entry{'src'}    = $libp->getPath();
227 dpurdie 6467
            }
289 dpurdie 6468
            elsif ( ! $SHLIBS->Get($lib) )
227 dpurdie 6469
            {
289 dpurdie 6470
                #
6471
                #   Not a known shared lib
6472
                #   Not a known static lib
6473
                #   Not a 'sourced' file
6474
                #   Assume the a static library has magically appeared
6475
                #   in the standard LIB directory. May have been placed there
6476
                #   by a 'rule'
6477
                #
6478
                my $libp = $LIBS->New($lib);
227 dpurdie 6479
 
289 dpurdie 6480
                $package_entry{'dst'}    = $dir . '/' . $libp->getFullName();
6481
                $package_entry{'src'}    = $libp->getPath();
6482
            }
227 dpurdie 6483
 
289 dpurdie 6484
            #
6485
            #   Add entry to various lists if required
6486
            #
6487
            PackageLib_AddEntry ('PackageLib', \%LIB_PKG, \%PACKAGE_LIBS, \%package_entry )
6488
                if ( exists $package_entry{'dst'} );
227 dpurdie 6489
        }
6490
    }
6491
}
6492
 
289 dpurdie 6493
#-------------------------------------------------------------------------------
6494
# Function        : PackageLib_AddEntry
6495
#
6496
# Description     : Helper function to add a package entry
6497
#                   to the lists
6498
#
6499
# Inputs          : $directive          - Directive name
6500
#                   $pList              - Ref to array list to maintain
6501
#                   $pHash              - Ref to hash to maintain
6502
#                   $pData              - Packaging Data
6503
#                                         Must Take a copy.
6504
#
6505
# Returns         : 
6506
#
227 dpurdie 6507
 
289 dpurdie 6508
sub PackageLib_AddEntry
6509
{
6510
    my ($directive, $pList, $pHash, $pData) = @_;
6511
 
6512
    my $lib = delete $pData->{'lib'};
6513
    my $dst = delete $pData->{'dst'};
6514
 
6515
    Error ("INTERNAL PackageLib_AddEntry: lib or dst not defined")
6516
        unless ( $lib && $dst );
6517
 
6518
    Debug( "$directive( ",$dst,
6519
            ", src: " ,$pData->{'src'},
6520
            ", dest: ",$pData->{'dir'},
6521
            ", dist: ",$pData->{'set'},
6522
            ", type: ",$pData->{'type'} || '',
6523
            " )" );
6524
 
6525
    push @{$pList->{$lib }}, $dst;
6526
    $pHash->{$dst } = {%$pData};
6527
}
6528
 
6529
 
227 dpurdie 6530
sub PackageProg
6531
{
6532
    my( $platforms, @elements ) = @_;
6533
    my( $base, $dir, $dist, $type );
6534
    my( $prog, %extras, $strip );
6535
 
6536
    Debug2( "PackageProg($platforms, @elements)" );
6537
 
6538
    return if ( !$ScmPackage );                 # Packaging enabled ?
6539
    return if ( ! ActivePlatform($platforms) );
6540
 
6541
#.. Arguments
6542
#
6543
    $dist = "ALL";                              # Default set (ALL)
6544
    $base = $PackageInfo{'Prog'}{'PBase'};       # Base of target
6545
    $dir = $base . $PackageInfo{'Prog'}{'Dir'};  # Installation path (default)
6546
    $type = "";
6547
 
285 dpurdie 6548
    foreach ( @elements )
227 dpurdie 6549
    {
6550
                                                # Standard targets
6551
        my $rv = __TargetDir($T_PKG|$T_TYPE, $base, $_, \$dir, \$type);
6552
        next if ( $rv == 1 );
6553
        return if ( $rv == 2 );
6554
 
6555
        if (/^--Set=(.*)/) {                    # Distribution set(s)
6556
            $dist = "$1";
6557
 
6558
        } elsif (/^--Package$/) {               # Package .. call by PackageLib
6559
        } elsif (/^--Package=(.*)/) {
6560
            $dist = "$1";
6561
 
6562
        } elsif (/^--Tool(([=])(.*))?$/) {      # Allow Tool and Tool=xxx specfic target
6563
            my $path = ( defined( $3) ) ? "/$3" : "";
261 dpurdie 6564
            $dir = "\$(PKGDIR)$path/\$(GBE_HOSTMACH)";
227 dpurdie 6565
 
6566
        } elsif (/^--Extras=(.*)/) {            # Extras=[none, .. ,all]
6567
            foreach my $elem ( split( ',', $1 ) )
6568
            {
6569
                Error ("PackageLib: Unknown Extras mode: $elem")
6570
                    unless ( grep m/$elem/, qw(none stub map lint debug all) );
6571
                $extras{$elem} = 1;
6572
            }
6573
            %extras = () if ( $extras{'all'} );
6574
 
6575
        } elsif (/^--Strip$/) {                 # Strip path from source files
6576
            $strip = 1;
6577
 
6578
        } elsif (/^--(.*)/) {
6579
            Message( "PackageProg: unknown option $_ -- ignored\n" );
6580
        }
6581
    }
6582
 
6583
#.. Files
6584
#
285 dpurdie 6585
    foreach ( @elements )
227 dpurdie 6586
    {
6587
        my %package_entry;
6588
        if ( m~descpkg~ ) {
6589
            PackageFile($platforms, @elements);
6590
 
6591
        } elsif ( ! /^--(.*)/ ) {
6592
            $_ = StripDir( $_ )
6593
                if ( $strip );
6594
 
6595
            my $ext = "";
6596
            $prog = $_;
6597
 
6598
            #
6599
            #   If the named target is a program then append the correct
6600
            #   extension. Otherwise assume that the target is either a script
6601
            #   or a some other file - and don't append an extension
6602
            #
6603
            #   A program may not have any object files, only libraries
6604
            #
6605
            $ext = $::exe
289 dpurdie 6606
                if ( $PROGS->Get($prog) );
227 dpurdie 6607
 
6608
            #
6609
            #   A "file" that is specified with a "Src" directive may be
6610
            #   installed as though it were a program
6611
            #
6612
            my $progfile;
387 dpurdie 6613
            if ( $progfile = $SRCS{$prog} )
6614
            {
6615
                $progfile = QuoteForMake($progfile);
6616
                $prog = QuoteForMake($prog);
6617
            }
6618
            else
6619
            {
6620
                $progfile = "\$(BINDIR)/$prog$ext";
6621
            }
227 dpurdie 6622
 
6623
            Debug( "PackageProg( $dir/$prog$ext, " .
6624
                 "src: $progfile, dest: $dir, dist: $dist, type: $type )" );
6625
 
6626
            my $target = "$dir/$prog$ext";
6627
            push @{$PROG_PKG{$prog}}, $target;
6628
 
6629
            $package_entry{'src'}   = $progfile;
6630
            $package_entry{'dir'}   = $dir;
6631
            $package_entry{'set'}   = $dist;
6632
            $package_entry{'extras'}= {%extras} if ( scalar %extras );
6633
            $package_entry{'type'}  = $type if ( $type );
6634
 
6635
            $PACKAGE_PROGS{$target} = {%package_entry};
6636
        }
6637
    }
6638
}
6639
 
6640
 
6641
sub PackageJar
6642
{
6643
    my( $platforms, @elements ) = @_;
6644
    my( $base, $dir, $dist, $type );
6645
    my( $jar );
6646
 
6647
    Debug2( "PackageJar($platforms, @elements)" );
6648
 
6649
    return if ( !$ScmPackage );                 # Packaging enabled ?
6650
    return if ( ! ActivePlatform($platforms) );
6651
 
6652
#.. Arguments
6653
#
6654
    $dist = "ALL";                              # Default set (ALL)
6655
    $base = $PackageInfo{'Jar'}{'PBase'};       # Base of target
6656
    $dir = $base . $PackageInfo{'Jar'}{'Dir'};  # Installation path (default)
6657
    $type = "";
6658
 
285 dpurdie 6659
    foreach ( @elements )
227 dpurdie 6660
    {
6661
                                                # Standard targets
6662
        my $rv = __TargetDir($T_PKG, $base, $_, \$dir, \$type);
6663
        next if ( $rv == 1 );
6664
        return if ( $rv == 2 );
6665
 
6666
        if (/^--Set=(.*)/) {                    # Distribution set(s)
6667
            $dist = "$1";
6668
 
6669
        } elsif (/^--Package$/) {               # Package .. call by InstallJar
6670
        } elsif (/^--Package=(.*)/) {
6671
            $dist = "$1";
6672
 
6673
        } elsif (/^--(.*)/) {
6674
            Message( "PackageJar: unknown option $_ -- ignored\n" );
6675
        }
6676
    }
6677
 
6678
#.. Files
6679
#
285 dpurdie 6680
    foreach ( @elements )
227 dpurdie 6681
    {
6682
        my %package_entry;
6683
        if ( ! /^--(.*)/ )
6684
        {
6685
            $jar = $_;
6686
            my $src;
6687
            my $dest;
6688
 
6689
            if ( $JAR_FILES{$jar} )
6690
            {
6691
                $src = $JAR_FILES{$jar};
6692
                $dest = $jar;
6693
            }
6694
            else
6695
            {
6696
                $src = "\$(CLSDIR)/$jar\$(GBE_TYPE).jar";
6697
                $dest = "$jar\$(GBE_TYPE).jar";
6698
            }
6699
 
6700
 
6701
            Debug( "PackageJar( $dir/$dest, " .
6702
                "src: $src, dest: $dir, dist: $dist, type: $type )" );
6703
 
6704
            $package_entry{'src'} = $src;;
6705
            $package_entry{'dir'} = $dir;
6706
            $package_entry{'set'} = $dist;
6707
            $package_entry{'type'} = $type if ( $type );
6708
 
6709
            $PACKAGE_CLSS{ "$dir/$dest" } = {%package_entry};
6710
 
6711
        }
6712
    }
6713
}
6714
 
6715
#-------------------------------------------------------------------------------
6716
# Function        : PackageProgAddFiles         - Add files to a PackageProg
6717
#                   PackageLibAddFiles          - Add files to a PackageLib
6718
#                   PackageShlibAddFiles        - Add files to a PackageLib (shared lib)
6719
#                   PackageShlibAddLibFiles     - Add files to a PackageLib (shared lib)
6720
#                                                 Add static library files
6721
#
6722
# Description     : Add files to a Program package or installation
6723
#                   For use by Tool sets to allow additional files to be
6724
#                   packaged with a program.
6725
#
6726
#                   The files are only added if the named program is being
6727
#                   packaged and/or installed.
6728
#
6729
#
6730
# Inputs          : prog        - program identifier
6731
#                   file        - A file to be add
6732
#                   args        - Additional packageing arguments
6733
#
6734
# Returns         : Nothing
6735
#
6736
 
6737
sub PackageProgAddFiles
6738
{
6739
    Debug("PackageProgAddFiles");
6740
 
6741
    PackageAddFiles ( \%PACKAGE_PROGS, \%PACKAGE_PROGS, \%PROG_PKG, @_);
6742
    PackageAddFiles ( \%INSTALL_PROGS, \%INSTALL_PROGS, \%PROG_INS, @_);
6743
}
6744
 
6745
sub PackageLibAddFiles
6746
{
6747
    Debug("PackageLibAddFiles");
6748
 
6749
    PackageAddFiles ( \%PACKAGE_LIBS, \%PACKAGE_LIBS, \%LIB_PKG, @_ );
6750
    PackageAddFiles ( \%INSTALL_LIBS, \%INSTALL_LIBS, \%LIB_INS, @_ );
6751
}
6752
 
6753
sub PackageShlibAddFiles
6754
{
6755
    my ($prog, $file, @args) = @_;
6756
    Debug("PackageShlibAddFiles");
6757
 
6758
    PackageAddFiles ( \%INSTALL_SHLIBS, \%INSTALL_SHLIBS, \%SHLIB_INS, @_ );
6759
    PackageAddFiles ( \%PACKAGE_SHLIBS, \%PACKAGE_SHLIBS, \%SHLIB_PKG, @_ );
6760
 
6761
    #
6762
    #   These files become the target of the "make_install_shlib" operation unless:
6763
    #       Conditionally packaged files are not always created
6764
    #       RemoveOnly files are not always generated
6765
    #
6766
    my $no_add;
6767
    foreach ( @args )
6768
    {
6769
        if ( m/^defined=/ or m/^RemoveOnly=/ )
6770
        {
6771
            $no_add = 1;
6772
            last;
6773
        }
6774
    }
6775
 
6776
    push (@SHLIB_TARGETS, $file ) unless $no_add;
6777
}
6778
 
6779
sub PackageShlibAddLibFiles
6780
{
6781
    Debug("PackageShlibAddLibFiles");
6782
 
6783
    PackageAddFiles ( \%PACKAGE_SHLIBS, \%PACKAGE_LIBS, \%SHLIB_PKG, @_ , 'Class=lib');
6784
    PackageAddFiles ( \%INSTALL_SHLIBS, \%INSTALL_LIBS, \%SHLIB_INS, @_ , 'Class=lib');
6785
}
6786
 
6787
#-------------------------------------------------------------------------------
6788
# Function        : PackageAddFiles
6789
#
6790
# Description     : Internal function to add files to the data structures that
6791
#                   describe a package or installation
6792
#
6793
#                   Use this function to package or install additional files with
6794
#                   the Progs and Libs
6795
#
6796
#                   ie: Add a LIB file to be packaged with a Shared Library
6797
#                   ie: Add a MAP file to be packaged with a program
6798
#
6799
# Inputs          : ref_spkg  - Reference to the hash that contains the package data
6800
#                   ref_dpkg  - Reference to the target package/install hash
6801
#                               Normally the same as ref_dpkg, but does allow
289 dpurdie 6802
#                               a static library to be added to a dynamic library
227 dpurdie 6803
#                               package.
6804
#                   ref_list  - Reference to a hash that may contain package keys to process
6805
#                   prog      - Key for index to above
6806
#                   file      - A file to be added
6807
#                   args      - Additional packaging arguments
6808
#
6809
# Returns         :
6810
#
6811
sub PackageAddFiles
6812
{
6813
    my ($ref_spkg, $ref_dpkg, $ref_list, $prog, $file, @args ) = @_;
6814
 
6815
    #
6816
    #   Process entry
6817
    #   The files may need to be added to multiple packages
6818
    #
6819
    Debug("PackageAddFiles: $file");
6820
 
6821
    return unless ( $ref_list->{$prog} );
6822
 
6823
    #
6824
    #   Parse arguments and extract the "Class=xxx" argument. This may be used
6825
    #   to limit the extra files piggybacked with the base file
6826
    #   All files without a class will be treated as base files
6827
    #
6828
    my $class;
6829
    foreach ( @args )
6830
    {
6831
        next unless ( m~^Class=(.*)$~ );
6832
        $class = $1 unless ( $1 eq 'none' );
6833
    }
6834
    Debug("PackageAddFiles: Class: ", $class || 'Default=None');
6835
 
6836
    foreach my $entry_key ( @{$ref_list->{$prog}} )
6837
    {
6838
        Debug("PackageAddFiles: Entry found: $entry_key");
6839
 
6840
        #
6841
        #   Copy of the template entry
6842
        #
6843
        my %package_entry = %{$ref_spkg->{$entry_key}};
6844
        Error ("INTERNAL: Expected entry in PACKAGE_ hash not found: $entry_key" )
6845
            unless ( %package_entry );
6846
 
6847
        #
6848
        #   Do not add the file if the user has limited the extra files added
6849
        #   to the packaging list and the current file is not in the class list
6850
        #
6851
        if ( $class && $package_entry{'extras'} )
6852
        {
6853
            next unless ( $package_entry{'extras'}{$class} );
6854
        }
6855
 
6856
        #
6857
        #   Create new entries for the file
6858
        #
6859
        $package_entry{'src'} = $file;
6860
        foreach ( @args )
6861
        {
6862
            m~^(.*)=(.*)$~;
6863
            $package_entry{$1} = $2;
6864
        }
6865
 
6866
        #
6867
        #   Clean out useless fields
6868
        #   Must remove the placekeeper marker to allow the entry to be visible
6869
        #
6870
        delete $package_entry{'placekeeper'};
6871
        delete $package_entry{'version'};
6872
        delete $package_entry{'lib'};
261 dpurdie 6873
#       delete $package_entry{'extras'};                   # Keep these
227 dpurdie 6874
        delete $package_entry{'Class'};
6875
 
6876
        #
6877
        #   Add the entry
6878
        #
6879
        #   Under some conditions is it possible to attempt to add the same named
6880
        #   file. This will result in a circular dependancy in the makefile
6881
        #
6882
        #   The condition is when merged libaries with PDBs (WINCE+WIN32) are merged
261 dpurdie 6883
        #   and the source for the merge is the "local directory.
227 dpurdie 6884
        #
6885
        #
6886
        my $dst = $package_entry{'dir'} ;
6887
        ( my $dfile = $file) =~ s~.*/~~;
6888
        Debug( "    added $dst/$dfile = $file" );
6889
 
6890
        $ref_dpkg->{"$dst/$dfile"} = {%package_entry}
6891
            unless ( "$dst/$dfile" eq "$file" );
6892
    }
6893
}
6894
 
6895
#-------------------------------------------------------------------------------
6896
# Function        : PackageProgRemoveFiles
6897
#
6898
# Description     : Flag a Packaged program to be not packaged
6899
#                   This mechanism is used to remove a program from packageing
6900
#                   under conditions where the toolset has generated a different
6901
#                   program.
6902
#
6903
#                   The entry is flagged as a placeholder
6904
#
6905
# Inputs          : prog        - Program to process
6906
#
6907
# Returns         : Nothing
6908
#
6909
sub PackageProgRemoveFiles
6910
{
6911
    my ($prog) = @_;
6912
    Verbose ("PackageProgRemoveFiles: $prog" );
6913
    return unless (exists($PROG_PKG{$prog}));
6914
 
6915
    #
6916
    #   Must lookup the TAG to locate the  required entry
6917
    #
6918
    my $tag = $PROG_PKG{$prog};
6919
    foreach my $entry ( @$tag )
6920
    {
6921
        Verbose("Do not package: $entry");
6922
        if ( exists $PACKAGE_PROGS{$entry} )
6923
        {
6924
            $PACKAGE_PROGS{$entry}{placekeeper} = 'ProgRemoved';
6925
        }
6926
    }
6927
}
6928
 
6929
#-------------------------------------------------------------------------------
6930
# Function        : DPackageLibrary
6931
#
6932
# Description     : Collect information to allow the generation of a DPACKAGE
299 dpurdie 6933
#                   file. This directive allows the generation of "Library"
227 dpurdie 6934
#                   directives within the final DPACKAGE
6935
#
6936
#                   This directive does generate the DPACKAGE file.
6937
#
6938
# Inputs          : platform    - This does not need to be an active platform
6939
#                                 it is simply passed to the DPACKAGE builder
6940
#
6941
#                   using       - The "using" target
6942
#
6943
#                   ...         - Arguments for the Library directive
6944
#
6945
# Returns         :
6946
#
6947
sub DPackageLibrary
6948
{
6949
    JatsDPackage::DPackageAdd ( @_ );
299 dpurdie 6950
    $DPackageDirective = 1;
227 dpurdie 6951
}
6952
 
6953
#-------------------------------------------------------------------------------
6954
# Function        : SetProjectBase
6955
#
6956
# Description     : Allows the user to modify the build's concept of the Base
6957
#                   of the build. By default the base is the same directory as
6958
#                   the build.pl file, but in some contorted environments it
6959
#                   is a great deal simpler to specify a differnt base.
6960
#
6961
#                   The use may use the variable $ProjectBase as a path
6962
#                   specifier to locate files and directories
6963
#
6964
#                   Both absolute and relative paths are supported
6965
#                   If the initial value of $ProjectBase is relative then
6966
#                   it will be maintained as a relative path.
6967
#
6968
# Inputs          : elements        path to base
6969
#                                   These may be:
6970
#                                       --Up=xx
6971
#                                       name
6972
#
6973
# Returns         : Nothing
6974
#
6975
 
6976
#
6977
#   Allow the user to modify the project base variable
6978
#
6979
sub SetProjectBase
6980
{
6981
    my $rip = 0;
6982
    my $path = "";
6983
    my $is_relative;
6984
 
6985
    Debug("ProjectBase Initial: $ProjectBase, @_");
6986
 
6987
    #
6988
    #   Ensure that the ProjectBase is in a "nice" form
6989
    #   1) No /./ bits
6990
    #   2) No trailing /
6991
    #   3) Not equal to .
6992
    #   4) No training /.
6993
    #   5) No //
6994
    #
6995
    $ProjectBase =~ s~/\./~/~g;
6996
    $ProjectBase =~ s~/$~~g;
6997
    $ProjectBase =~ s~^\.$~~g;
6998
    $ProjectBase =~ s~/\.$~~g;
6999
    $ProjectBase =~ s~//$~/~g;
7000
 
7001
    #
7002
    #   ProjectBase may be absolute or relative
7003
    #   Determine this before we mess with it
7004
    #
7005
    $is_relative = ($ProjectBase !~ m~^/~);
7006
 
7007
    #
7008
    #   Process each argument
7009
    #
7010
    foreach ( @_ )
7011
    {
7012
        if ( /^--Up=([0-9]*)/ ) {
7013
            $rip = $1;
7014
        } elsif ( /^--/ ) {
7015
            Warning( "SetProjectBase - unknown option \"$_\" - ignored" );
7016
        } else {
7017
            $path = $_;
7018
        }
7019
    }
7020
 
7021
    #
7022
    #   Process the UP requests
7023
    #   If the tail directory is a ".." then up is done by adding another ".."
7024
    #   If the tail directory is not a "..", then up is done by removing it
7025
    #
7026
    #   If we go past the start of the path then simply add ".."
7027
    #
7028
    while ( $rip-- > 0 )
7029
    {
7030
        Debug2("ProjectBase: $ProjectBase, Up: $rip, IsRel: $is_relative");
7031
 
7032
        #
7033
        #   If ending in a /.. or is exactly equal to ..
7034
        #   Then its a dot-dot and the way to go UP is to append another ..
7035
        #
7036
        if ( $ProjectBase =~ m~(/\.\.$)|(^\.\.$)~ )
7037
        {
7038
            $ProjectBase .= '/..';
7039
        }
7040
        else
7041
        {
7042
            #
7043
            #   Not a dot-dot ending
7044
            #   Attempt to remove the last directory of the form
7045
            #       /xxxxx
7046
            #   Where the leading / is optional
7047
            #   Note: Must have at least one character in the dirname
7048
            #         This prevents leading / from matching - which is needed
7049
            #
7050
            unless ($ProjectBase =~ s~/?[^/]+$~~)
7051
            {
7052
                #
7053
                #   Removal failed
7054
                #   If a relative path then we can keep on going up,
7055
                #   otherwise we are dead.
7056
                #
7057
                Error ("ProjectBase outside project") unless ($is_relative);
7058
                $ProjectBase = '..';
7059
            }
7060
 
7061
            #
7062
            #   Ensure that the leading / in an absolute path is not deleted
7063
            #
7064
            $ProjectBase = '/'
7065
                unless ( $is_relative || $ProjectBase );
7066
        }
7067
    }
7068
 
7069
    #
7070
    #   Append the user path
7071
    #
7072
    $ProjectBase .= '/' . $path if ( $path );
7073
    $ProjectBase = '.' unless ( $ProjectBase );
7074
    Debug("ProjectBase set to : $ProjectBase");
7075
 
7076
    #
7077
    #   Once upon a time I tried to convert paths that contained spaces into
7078
    #   short (mangled) names. This was not sucessful because:
7079
    #       1) Clearcase dynamic views do not support name mangling
7080
    #       2) Samba file system does not appear to support name mangling
7081
    #
7082
    #   Spaces in paths are not good for MAKE
7083
    #   Now I simple generate a message
7084
    #
7085
    Warning( "ProjectBase contains a space: $ProjectBase")
7086
        if ( $ProjectBase =~ m/ / );
7087
 
7088
    #
7089
    #   Sanity check
7090
    #   Absolute paths can be checked easily
7091
    #   Checking of relative paths does not appear to work
7092
    #   When I tested it chdir, opendir and stat would limit themselves
7093
    #   and drop into the root directory ( under windows )
7094
    #
7095
    #   Solution: Check the path does not extend beyond the file tree
7096
    #
7097
    my $distance = 1;
7098
    my $tpath = $ProjectBase;
7099
 
7100
    if ( $is_relative && $tpath ne '.' )
7101
    {
7102
        #
7103
        #   Build up the complete pathname by merging it with the
7104
        #   current directory. Then clean it up.
7105
        #
7106
        $tpath = $::Cwd . '/' . $ProjectBase;
7107
 
7108
        #
7109
        #   Scan the list of diretories and count the distance from the root
7110
        #   This should not be greater than zero for sanity
7111
        #   Note: Get an empty elemement from the split due to
7112
        #         the leading / of the ABS path
7113
        #
7114
        $distance = 0;
7115
        foreach (  split ('/', $tpath) )
7116
        {
7117
            if ( m~\.\.~ )
7118
            {
7119
                $distance--;
7120
            }
7121
            else
7122
            {
7123
                $distance++;
7124
            }
7125
        }
7126
    }
7127
 
7128
    #
7129
    #   Warn if not a valid directory
7130
    #
7131
    Warning( "ProjectBase is not a directory: $ProjectBase")
7132
        if ( $distance <= 0 || !  -d $tpath  );
7133
 
7134
    #
7135
    #   $ProjectBase will always be a valid directory, but if its the top
7136
    #   directory (/) and it is added to a path we will get //path
7137
    #   This is not good, so // will be removed later in the AddIncDir and
7138
    #   AddSrcDir commands where $ProjectBase is really used.
7139
    #
7140
    #   Alternatively we could set $ProjectBase to an empty string, but then
7141
    #   this may be confused with an empty relative directory
7142
    #
7143
    Debug("ProjectBase Final  : $ProjectBase");
7144
}
7145
 
7146
#-------------------------------------------------------------------------------
7147
# Function        : DeployPackage
7148
#
7149
# Description     : Generate a deployed package
7150
#                   This is a gateway to a different packaging system
7151
#
7152
#                  DeployPackage and PackageXxxxx directives are mutually
7153
#                  exclusive. Only one person can play in the package area.
7154
#
7155
# Inputs          : Platform Specifier
7156
#                   Package Name    (Optional)
7157
#                   Options
7158
#                       --Name : Base name of the package. The default is taken
7159
#                                from the build.pl file
7160
#                       --Dir  : Package directory
7161
#                                The default is based on the package name
7162
#
7163
# Returns         :
7164
#
7165
sub DeployPackage
7166
{
7167
    my( $platforms, @elements ) = @_;
7168
    my $dir;
7169
    my $name;
7170
 
267 dpurdie 7171
    #
7172
    #   Flag that this build creates a deployable package, even if its not
7173
    #   active on this platform.
7174
    #
7175
    $DEPLOYPACKAGE = 1;
7176
 
7177
 
227 dpurdie 7178
    Debug2( "DeployPackage($platforms, @elements)" );
7179
    return if ( ! ActivePlatform($platforms) );
7180
 
7181
    #
7182
    #   Only allow one use of this directive
7183
    #
7184
    Error("DeployPackage can only be used once" ) if ( %DEPLOYPACKAGE );
267 dpurdie 7185
    $DEPLOYPACKAGE = 2;
227 dpurdie 7186
 
7187
    #
7188
    #   Ensure that the deployment file is available
7189
    #
7190
    my $command_file = $ScmDeploymentPatch ? "deploypatch.pl" : "deployfile.pl";
7191
    Error("DeployPackage: $command_file not found") unless (-f "./$command_file");
7192
    #
7193
    #   Collect arguments
7194
    #
7195
    foreach (@elements )
7196
    {
7197
        if ( m/^--Dir=(.*)/ ) {
7198
            Error ("DeployPackage: Package directory defined multiple times") if $dir;
7199
            $dir = $1;
7200
 
7201
        } elsif ( m/^--Name=(.*)/ ) {
7202
            Error ("DeployPackage: Package name defined multiple times") if $name;
7203
            $name = $1;
7204
 
7205
        } elsif ( m/^--/ ) {
7206
            Warning( "DeployPackage: Unknown option ignored: $_");
7207
 
7208
        } else {
7209
            Error ("DeployPackage: Package name defined multiple times") if $name;
7210
            $name = $_;
7211
 
7212
        }
7213
    }
7214
 
7215
    $name = $::ScmBuildPackage unless ( $name );
7216
 
7217
    #
7218
    #   Save the deployment data
7219
    #
7220
    $dir = lc($name) unless ( $dir );
7221
    $DEPLOYPACKAGE{'name'} = $name;
7222
    $DEPLOYPACKAGE{'dir'} = $dir;
7223
    $DEPLOYPACKAGE{'cmdfile'} = $command_file;
7224
 
7225
    #
7226
    #   Flag that toolset tests should be supressed
7227
    #   The Deploy world does not really use the full makefiles and if the
7228
    #   compilers are not installed will not be able to create deployment
7229
    #   packages
7230
    #
7231
    $ScmNoToolsTest = 1;
7232
}
7233
 
7234
 
7235
###############################################################################
7236
###############################################################################
7237
# Private function section.
7238
#       The following functions are used INTERNALLY by makelib.pl2.
7239
###############################################################################
7240
 
7241
###############################################################################
7242
#   A collection of functions to write to the MAKEFILE handle
7243
#
7244
#   MakeHeader          - Write a nice section header
7245
#   MakeNewLine         - Print a new line
7246
#   MakePrint           - Print a line ( without trailing \n)
7247
#   MakeQuote           - Escape \ and " character, then print a line
7248
#   MakePrintList       - Print an array
7249
#   MakeEntry           - Complex line printer
7250
#   MakePadded          - Padded line printer (internal)
7251
#   PadToPosn           - Calc space+tabs to tabstop (internal)
7252
#   MakeEntry3          - Complex Line Printer
7253
#   MakeDefEntry        - Print a definition line (Production + Debug support)
7254
#   MakeIfDefEntry      - Print ifdef entry
261 dpurdie 7255
#   MakeIfnDefEntry     - Print ifndef entry
7256
#   MakeIfZeroEntry     - Print ifeq entry
227 dpurdie 7257
#
7258
###############################################################################
7259
 
7260
sub MakeHeader
7261
{
7262
    my ($text, @rest) = @_;
7263
    my $length = length ($text);
7264
 
7265
    print MAKEFILE "\n";
7266
    print MAKEFILE "#--------- $text ", '-' x (80 - 12 - $length)  ,"\n";
7267
    print MAKEFILE "#    $_\n" foreach  ( @rest ) ;
7268
    print MAKEFILE "#\n";
7269
}
7270
 
7271
sub MakeNewLine         # Print a newline to the current 'Makefile'
7272
{
7273
    print MAKEFILE "\n";
7274
}
7275
 
7276
sub MakePrint           # Print to the current 'Makefile'
7277
{
7278
    print MAKEFILE @_
7279
        if ( defined $_[0] );
7280
}
7281
 
7282
sub MakeQuote           # Quote a makefile text line
7283
{
7284
    my( $line ) = @_;
7285
    $line =~ s/\\/\\\\/g;                       # quote all '\' characters
7286
    $line =~ s/"/\\"/g;                         # Then quote '"' characters
255 dpurdie 7287
    $line =~ s/=#/=\\#/g;                       # Then quote '=#' sequence
227 dpurdie 7288
    print MAKEFILE $line;
7289
}
7290
 
7291
sub MakePrintList
7292
{
7293
    print MAKEFILE $_ . "\n" foreach (@{$_[0]});
7294
}
7295
 
2312 dpurdie 7296
sub QuoteArray
7297
{
7298
    my $quote = "'";
7299
    if ( @_ ) {
7300
        return ($quote . join("$quote $quote", @_) . $quote);
7301
    }
7302
    return '';
7303
}
227 dpurdie 7304
 
7305
#-------------------------------------------------------------------------------
7306
# Function        : MakeEntry
7307
#
7308
# Description     : Build a entry based on the element list
7309
#                   Creates text of the form
7310
#                       $(BINDIR)/prog.exe: object1.obj \
7311
#                                           object2.obj
7312
#
7313
#
7314
# Inputs          : $prelim         - Preamble (one-off)
7315
#                   $postlim        - Postamble (one-off)
7316
#                   $prefix         - Pefix (to each element of array)
7317
#                   $postfix        - Postfix (to each element of array )
7318
#                   @elements       - Array of element to wrap
7319
#
7320
# Returns         :   1 Always
7321
#
7322
# Notes:
7323
#       The above description means that the following entry format is
7324
#       produced:
7325
#
7326
#           <preliminary><prefix><variant1><prefix><variant2>...<final>
7327
#
7328
#       With judicious use of newline and tab characters, a target
7329
#       and dependency list along with the command(s) to build the
7330
#       target can be constructed.
7331
#
7332
sub MakeEntry
7333
{
7334
    my( $prelim, $postlim, $prefix, $postfix, @elements ) = @_;
7335
 
7336
    MakePrint $prelim;
7337
    MakePrint "${prefix}${_}${postfix}" foreach ( @elements );
7338
    MakePrint $postlim if ($postlim);
7339
    return 1;
7340
}
7341
 
7342
#-------------------------------------------------------------------------------
7343
# Function        : MakePadded
7344
#
7345
# Description     : Generate aligned output of the form
7346
#                       Prefix_text           Aligned_text
7347
#                   where the aligned text is at a specified TAB boundary
7348
#
7349
# Inputs          : $align      - Tab stop (One tab = 8 chars)
7350
#                   $prefix     - Text to print before alignment occurs
7351
#                   @line       - Remainder of the line
7352
#
7353
sub MakePadded          # Print to the current 'Makefile', tab aligning
7354
{
7355
    my( $align, $prefix, @line ) = @_;
7356
 
7357
    my $strlen = length( $prefix );
7358
    my $pad = PadToPosn( $strlen, $align * 8 );
7359
 
7360
    print MAKEFILE $prefix . $pad;
7361
    print MAKEFILE @line;
7362
}
7363
 
7364
#-------------------------------------------------------------------------------
7365
# Function        : PadToPosn
7366
#
7367
# Description     : Given that we are at $startposn return a tab and space
7368
#                   string to place us at $endposn
7369
#
7370
sub PadToPosn
7371
{
7372
    my ($startposn, $endposn ) = @_;
7373
 
7374
 
7375
    #
7376
    #   Case where we are already too far into the line
7377
    #
7378
    return ( ' ' )if ( $endposn <= $startposn );
7379
 
7380
    my $tcount = 0;
7381
    my $scount = 0;
7382
 
7383
    while ( $startposn < $endposn )
7384
    {
7385
        $tcount ++;
7386
        $startposn = ($startposn >> 3) * 8 + 8;
7387
 
7388
        my $delta = $endposn - $startposn;
7389
        if ( $delta < 8 )
7390
        {
7391
            $scount = $delta;
7392
            last;
7393
        }
7394
 
7395
    }
7396
    return ( "\t" x $tcount .  ' ' x $scount );
7397
}
7398
 
7399
#-------------------------------------------------------------------------------
7400
# Function        : MakeEntry3
7401
#
7402
# Description     : Build a makefile entry based on the element list, tab aligned
7403
#                   Can creat text of the form:
7404
#                       TAG = NAME0 \       TAG : NAME0 \ 
7405
#                             NAME1               NAME1
7406
#
7407
#
7408
# Inputs          : $prelim             - Preliminary text
7409
#                   $presep             - Preliminary seperator
7410
#                   $elem_ref           - Either a single name or a reference to
7411
#                                         and array of names, or a hash.
7412
#
7413
# Returns         : Writes directly to the Makefile
7414
#
7415
sub MakeEntry3
7416
{
7417
    my( $prelim, $presep, $elem_ref ) = @_;
7418
 
7419
    #
7420
    #   The prelim may have some "\n" characters at the start
7421
    #   These simplify formatting, but mess up the nice formatting
7422
    #
7423
    if ($prelim =~ m~(^\n+)(.*)~ )
7424
    {
7425
        MakePrint $1;
7426
        $prelim = $2;
7427
    }
7428
 
7429
    #
7430
    #   Print the definition and the sep with nice padding
7431
    #
7432
    MakePadded ( 3, $prelim, $presep );
7433
    my $leadin = ' ';
7434
 
7435
    #
7436
    #   If a HASH reference then use a sorted list of keys from the hash.
7437
    #
7438
    if ( ref ($elem_ref) eq "HASH" )
7439
    {
7440
        my @hash_list;
7441
        @hash_list = sort keys ( %{$elem_ref} );
7442
        $elem_ref = \@hash_list;
7443
    }
7444
 
7445
    #
7446
    #   If the list is only one element long, then create a simple form
7447
    #   If the list is not an array ref, then treat it as a single element
7448
    #
7449
    if ( ref ($elem_ref) eq "ARRAY" )
7450
    {
7451
        my $line = 0;
7452
        foreach my $element ( @$elem_ref )
7453
        {
7454
            print MAKEFILE $leadin . $element;
7455
            $leadin = " \\\n" . PadToPosn(0,24 + length( $presep ) + 1 ) unless ($line++);
7456
        }
7457
    }
7458
    elsif ( defined $elem_ref )
7459
    {
7460
            print MAKEFILE $leadin . $elem_ref;
7461
    }
7462
    MakeNewLine();
7463
    return 1;
7464
}
7465
 
7466
#-------------------------------------------------------------------------------
7467
# Function        : MakeDefEntry
7468
#
7469
# Description     : Make a definition entry of the form
7470
#
7471
#                       TAG = NAME0 \
7472
#                             NAME1
7473
#
7474
#                   Support a list of definitions that will always be created
7475
#                   as well as a production and a debug list.
7476
#
7477
#                   Will always generate the "TAG = " string, even if the list
7478
#                   is empty.
7479
#
7480
#                   Will supress the TAG if there is no data if the FIRST opr starts with a '+'
7481
#
7482
# Inputs          : TAG         - Text tag to create
7483
#                   FIRST       - First assignement opr. = or +=
7484
#                   ALL_LIST    - A reference to a list of names to assign
7485
#                                 or a single name.
7486
#                   PROD_LIST   - Optional list to extend the definition with for a production build
7487
#                   DEBUG_LIST  - Optional list to extend the definition with for a debug build
7488
#
7489
# Returns         : Nothing
7490
#
7491
 
7492
sub MakeDefEntry
7493
{
7494
    my( $tag, $assign, $all, $prod, $debug ) = @_;
7495
 
7496
    #
7497
    #   Do not generate anything if the $opr is "+=" and there is no data
7498
    #   to output. ie: Supress empty TAG += statements
7499
    #
7500
    return if ( $assign =~ m/\+/ && ( ref($all) && ! defined $all->[0] ) );
7501
 
7502
    #
7503
    #   TAG for all entries
7504
    #
7505
    MakeEntry3( $tag, $assign, $all );
7506
 
7507
 
7508
    #
7509
    #   TAGs for PROD build
7510
    #   TAGs for DEBUG build
7511
    #
7512
    if ( defined $prod && defined $prod->[0] )
7513
    {
7514
        print MAKEFILE 'ifeq "$(DEBUG)" "0"' . "\n";
7515
        MakeEntry3( $tag, "+=", $prod );
267 dpurdie 7516
        print MAKEFILE 'endif' . "\n";
227 dpurdie 7517
    }
7518
 
7519
    if ( defined $debug && defined $debug->[0] )
7520
    {
7521
        print MAKEFILE 'ifeq "$(DEBUG)" "1"' . "\n";
7522
        MakeEntry3( $tag, "+=", $debug );
267 dpurdie 7523
        print MAKEFILE 'endif' . "\n";
227 dpurdie 7524
    }
7525
 
7526
}
7527
 
7528
sub MakeIfDefEntry
7529
{
7530
    my( $iftag, @rest ) = @_;
7531
 
7532
    print MAKEFILE "ifdef $iftag\n";
7533
    MakeDefEntry (@rest);
7534
    print MAKEFILE "endif\n\n";
7535
}
7536
 
7537
sub MakeIfnDefEntry
7538
{
7539
    my( $iftag, @rest ) = @_;
7540
 
7541
    print MAKEFILE "ifndef $iftag\n";
7542
    MakeDefEntry (@rest);
7543
    print MAKEFILE "endif\n\n";
7544
}
7545
 
261 dpurdie 7546
sub MakeIfZeroEntry
7547
{
7548
    my( $iftag, @rest ) = @_;
7549
 
7550
    print MAKEFILE "ifeq (\$($iftag),0)\n";
7551
    MakeDefEntry (@rest);
7552
    print MAKEFILE "endif\n\n";
7553
}
7554
 
227 dpurdie 7555
#-------------------------------------------------------------------------------
7556
# Function        : CreateNameList
7557
#
7558
# Description     : Create a list of names by adding a prefix and suffix to a
7559
#                   list of items. This is used to add a directory prefix and a
7560
#                   file suffix to a list of files.
7561
#
7562
# Inputs          : $prefix             ie: '$(OBJDIR)/'
7563
#                   $suffix             ie: '.obj'
7564
#                   $elem_ref           ie: A list of files ( passed be ref )
7565
#                                           If a Hash then its sorted keys is used
7566
#
7567
# Returns         : A ref to the resulting list
7568
#
7569
sub CreateNameList
7570
{
7571
    my( $prefix, $suffix, $elem_ref ) = @_;
7572
    my @result;
7573
 
7574
    if ( ref ($elem_ref) eq "HASH" )
7575
    {
7576
        my @hash_list;
7577
        @hash_list = sort keys ( %{$elem_ref} );
7578
        $elem_ref = \@hash_list;
7579
    }
7580
 
7581
    foreach  ( @$elem_ref )
7582
    {
7583
        push @result, $prefix . $_ . $suffix;
7584
    }
7585
    return \@result;
7586
}
7587
 
7588
#-------------------------------------------------------------------------------
7589
# Function        : ListGeneratedProjects
7590
#
7591
# Description     : Return a list of generated/nongenerated projects
7592
#                   Used in conjunction with CreateNameList
7593
#
7594
# Inputs          : $type       - TRUE : Generated
7595
#                                 FALSE: Not Generated
7596
#
7597
# Returns         : A reference to a list of projects
7598
#                   undef will be retuend if there are no projects
7599
#
7600
sub ListGeneratedProjects
7601
{
7602
    my ($type) = @_;
7603
    my @list;
7604
    foreach my $project ( @PROJECTS_ORDER )
7605
    {
7606
        if ( exists($PROJECTS{$project}->{'generated'}) xor $type )
7607
        {
7608
            push @list, $project;
7609
        }
7610
    }
7611
    return @list ? \@list : undef;
7612
}
7613
 
7614
#-------------------------------------------------------------------------------
7615
# Function        : ListCleanGenerated
7616
#
7617
# Description     : return a list of generated targets that have 'clean'
7618
#                   operations. This is used in conjunction with CreateNameList
7619
#
7620
# Inputs          : None
7621
#
7622
# Returns         : A list of project indexes, that can be cleaned
7623
#
7624
sub ListCleanGenerated
7625
{
7626
    my @list;
7627
    foreach my $i ( @GENERATE_FILES )
7628
    {
7629
        push @list, $i->{'index'}
7630
            if ( $i->{'clean'} );
7631
    }
7632
    return \@list;
7633
}
7634
 
251 dpurdie 7635
#-------------------------------------------------------------------------------
7636
# Function        : MakeResolve
7637
#
7638
# Description     : Internal Function
7639
#                   Locate a source file by examining a list of directories
7640
#
7641
#                   Don't use directly
7642
#                   Use MakeSrcResolve or MakeSrcResolveExtended
7643
#
7644
# Inputs          : $dirs           - Ref to an array of directories to scan
7645
#                   $source         - File to locate
7646
#
7647
# Returns         : Resolved path to the file
7648
#                   Will warn if multiple instances of the file are found
7649
#
227 dpurdie 7650
sub MakeResolve
7651
{
7652
    my( $dirs, $source ) = @_;
285 dpurdie 7653
    my( $first, $count );
227 dpurdie 7654
 
237 dpurdie 7655
    #
7656
    #   If the path contains a '$' then its assumed to be
7657
    #   a variable name in the path. Just assume that it exists
7658
    #
7659
    return $source if ( $source =~ m#\$# );
7660
 
7661
    #
7662
    #   If the path is absolute or contains a leading ., then don't search
7663
    #   Warn if it can't be found
7664
    #
7665
    if ( $source =~ m#^(/|\.)# )
7666
    {
7667
        Warning( "Unable to resolve '$source' path" ) unless -f $source;
7668
        return $source;
227 dpurdie 7669
    }
7670
 
237 dpurdie 7671
 
227 dpurdie 7672
#.. search local path first
7673
#
7674
    $count = 0;
7675
    $first = "";
331 dpurdie 7676
    $first = "$source"                              # was ./$source
227 dpurdie 7677
        if (-r "$source");
7678
 
7679
#.. search directory paths
7680
#
285 dpurdie 7681
    foreach my $dir (@$dirs)
227 dpurdie 7682
    {
331 dpurdie 7683
        next if ( $dir eq '.' );
7684
        my $temp = "$dir/$source";                  # was ./$dir/$source
227 dpurdie 7685
        Debug2( "MakeResolve: Looking in: $temp" );
7686
        if (-r "$temp")
7687
        {
7688
            if ($first eq "") {
7689
                $first = $temp;
7690
            } else {
7691
                Warning( "Duplicate '$source' image - '$temp'" );
7692
                $count++;
7693
            }
7694
        }
7695
        Debug3( "MakeResolve: $count, $temp" );
7696
    }
7697
 
7698
    if ($first eq "") {
7699
        $first = $source;
7700
        Warning( "Unable to resolve '$source' path" );
7701
    } else {
7702
        Warning( "          using '$first'" )
7703
            if ($count);
7704
    }
7705
    return $first;
7706
}
7707
 
251 dpurdie 7708
#-------------------------------------------------------------------------------
7709
# Function        : MakeSrcResolve
7710
#
7711
# Description     : Locate a source file by examining the list of source
7712
#                   directories. There are a few frills
7713
#
7714
#                   Look for a source file in
7715
#                       1) %::BUILD_KNOWNFILES
7716
#                       2) %SRCS
7717
#                       3) Dirs specified by the array @SRCSDIRS
7718
#
7719
# Inputs          : Name of a file to resolve
7720
#
7721
# Returns         : Resolved path.
283 dpurdie 7722
#                   Input file - if not found at all
251 dpurdie 7723
#
227 dpurdie 7724
sub MakeSrcResolve
7725
{
7726
    my ($name) = @_;
7727
    my $file;
7728
 
251 dpurdie 7729
    if ( exists ( $::BUILD_KNOWNFILES{$name} ) ) {
7730
        #
7731
        #   The Known Files list is relative to ScmRoot
7732
        #   This must be included in the full path
7733
        #
7734
        $file = $ScmRoot . '/' . $::BUILD_KNOWNFILES{$name};
7735
 
7736
    } elsif ( exists $SRCS{$name} ) {
7737
        $file = $SRCS{$name};
7738
 
7739
    } else {
7740
        $file = MakeResolve( \@SRCDIRS, @_ )
7741
    }
227 dpurdie 7742
    return $file;
7743
}
7744
 
7745
 
7746
# MakeSrcResolveExtended
7747
#   from_global = 0 : Search user specified directories
7748
#               = 1 : Search LinkPkgArchive list
7749
#
7750
our @PkgSrcDirList;
7751
sub MakeSrcResolveExtended
7752
{
7753
    my ( $from_global, $file ) = @_;
7754
 
7755
    #
7756
    #   Simple Case. Resolve source from known source directories
7757
    #
7758
    #
7759
    return MakeSrcResolve( $file )
7760
        unless ( $from_global );
7761
 
7762
    #
7763
    #   Not so simple Case
7764
    #   Resolve the source from the imported packages
7765
    #
7766
    #   Create a list of directores to search, but only the first time
311 dpurdie 7767
    #       - Interface directories - from BuildPkgArchive
227 dpurdie 7768
    #       - LnkPkgArchive directories
7769
    #         Using target,product,platform include directories
7770
    #
7771
    unless ( @PkgSrcDirList )
7772
    {
7773
        for my $entry (@{$::ScmBuildPkgRules{$ScmPlatform} })
7774
        {
311 dpurdie 7775
            next if ( $entry->{'TYPE'} eq 'build' ); # Ignore BuildPkgArchives
7776
 
227 dpurdie 7777
            for (@{$entry->{'PINCDIRS'}}, @{$entry->{'THXDIRS'}}, '' )
7778
            {
7779
                my $dir = $entry->{'ROOT'} . "/" . $_ ;
7780
                $dir =~ s~//~/~g;
7781
                $dir =~ s~/$~~;
311 dpurdie 7782
                push ( @PkgSrcDirList, $dir );
227 dpurdie 7783
            }
7784
        }
311 dpurdie 7785
    }
227 dpurdie 7786
 
7787
    return MakeResolve( \@PkgSrcDirList, $file );
7788
}
7789
 
7790
#-------------------------------------------------------------------------------
7791
# Function        : GetPackageRoot
7792
#
7793
# Description     : Determine the root directory for a given package
7794
#                   This routine is intended for non-standard JATS scripts that
7795
#                   access package contents directly
7796
#
7797
#                   Note: This routine does not attempt to handle multiple
7798
#                         instances of a package ( sysbasetypes ).
7799
#
7800
# Inputs          : $pname          - Name of the package
7801
#
7802
# Returns         :
7803
#
7804
sub GetPackageRoot
7805
{
7806
    my( $pname ) = @_;
7807
    Debug( "GetPackageRoot(@_)" );
7808
 
7809
    my $result = undef;
7810
    my $pkg = GetPackageEntry( $pname );
7811
    if ( $pkg )
7812
    {
7813
        $result = $pkg->{'ROOT'};
7814
        Debug( "GetPackageRoot: $result" );
7815
    }
7816
 
7817
    return $result;
7818
}
7819
 
7820
#-------------------------------------------------------------------------------
7821
# Function        : ActiveProject
7822
#
7823
# Description     : Determine if the specified project is currenly 'active'
7824
#
345 dpurdie 7825
# Inputs          : $project            - one or more project names separated
7826
#                                         by either a comma or a colon
227 dpurdie 7827
#
7828
# Returns         : TRUE    if the project is active
7829
#
7830
sub ActiveProject
7831
{
7832
    my ($project) = @_;
345 dpurdie 7833
    foreach (  split( '\s*[:,]\s*', $project ) )
227 dpurdie 7834
    {
7835
        return 1
7836
            if ( $_ eq $::ScmBuildProject );
7837
    }
7838
    return 0;
7839
}
7840
 
345 dpurdie 7841
#-------------------------------------------------------------------------------
7842
# Function        : ActiveDefine
7843
#
7844
# Description     : Determine if the specified definition is currenly 'active'
7845
#
7846
# Inputs          : $defs               - one or more variable names separated
7847
#                                         by either a comma or a colon
7848
#
7849
# Returns         : TRUE    if any of the definitions are known
7850
#
7851
sub ActiveDefine
7852
{
7853
    my ($defs) = @_;
7854
    no strict 'refs';
7855
    foreach (  split( '\s*[:,]\s*', $defs ) )
7856
    {
7857
        return 1
7858
            if ( defined( $$_ ) || defined( @$_ ) );
7859
    }
7860
    use strict 'refs';
7861
    return 0;
7862
}
227 dpurdie 7863
 
7864
#-------------------------------------------------------------------------------
345 dpurdie 7865
# Function        : ActiveMachType
7866
#
7867
# Description     : Determine if the specified MachType is currenly 'active'
7868
#
7869
# Inputs          : $mtype              - one or more machine names separated
7870
#                                         by either a comma or a colon
7871
#
7872
# Returns         : TRUE    if any of the current MachType is in the list
7873
#
7874
sub ActiveMachType
7875
{
7876
    my ($mtype) = @_;
7877
    foreach (  split( '\s*[:,]\s*', $mtype ) )
7878
    {
7879
        return 1
7880
            if ( uc($_) eq uc($::GBE_MACHTYPE) );
7881
    }
7882
    return 0;
7883
}
7884
 
7885
#-------------------------------------------------------------------------------
227 dpurdie 7886
# Function        : ActivePlatform
7887
#
7888
# Description     : Determine if the specified platform is currently 'active'
7889
#                   This is used by all user directives in order to determine
7890
#                   if the directive should be ignored for the current platform
7891
#
7892
# Inputs          : $platform_spec      - A platform specifier
7893
#                                         This is a bit complex.
7894
#
241 dpurdie 7895
#                   Format of platform_spec. One or more of
7896
#                       PlatformName
7897
#                       AliasName
7898
#                       TargetName,--Target
345 dpurdie 7899
#                   Special Options (Must all be True)
7900
#                       --Project=ProjectName[:ProjectName]+
7901
#                       --Defined=SomeValue[:SomeValue]+
7902
#                       --MachType=SomeValue[:SomeValue]+
7903
 
7904
#                   Each can be prefixed with a '!' to negate the test
227 dpurdie 7905
#
241 dpurdie 7906
#                   Valid options are:
271 dpurdie 7907
#                       --Target        - indicates that the platform is a 'target'
241 dpurdie 7908
#
7909
# Returns         : TRUE if the platform spec is satisfied
7910
#
227 dpurdie 7911
sub ActivePlatform
7912
{
7913
    my( $platform_spec ) = @_;
7914
    my( @platforms, $scmplatform, $platform );
7915
    my( %arguments, @args, $filter );
241 dpurdie 7916
    my @plist;
7917
    my ($match_count, $count_invert, $count_vert) = (0,0,0);
227 dpurdie 7918
 
241 dpurdie 7919
    #
7920
    #   Short circuit check
7921
    #   '*' is used so often that it pays to check it first
7922
    #
7923
    if ( $platform_spec eq '*' )
7924
    {
7925
        Debug3( " ActivePlatform(@_) = TRUE" );
7926
        return 1;
7927
    }
227 dpurdie 7928
 
241 dpurdie 7929
    #
7930
    #   Platform specifier may be a comma seperated list
7931
    #   ie:  WIN32,MOS,XXX
7932
    #   Extract non-platform arguments
279 dpurdie 7933
    #   Process to yield a dummy platform of '0' or '1' - these will be seen later
241 dpurdie 7934
    #
7935
    foreach ( split( '\s*,\s*', $platform_spec ) )
7936
    {
345 dpurdie 7937
        my ($result, $not);
7938
        if ( m~^(!?)--Project=(.+)~ ) {
325 dpurdie 7939
            $not = $1;
345 dpurdie 7940
            $result = ActiveProject($2);
277 dpurdie 7941
 
345 dpurdie 7942
        } elsif ( m~^(!?)--Defined=(.+)~ ) {
325 dpurdie 7943
            $not = $1;
345 dpurdie 7944
            $result = ActiveDefine($2);
241 dpurdie 7945
 
345 dpurdie 7946
        } elsif ( m~^(!?)--MachType=(.+)~ ) {
325 dpurdie 7947
            $not = $1;
345 dpurdie 7948
            $result = ActiveMachType($2);
7949
 
325 dpurdie 7950
        } else {
7951
            #
7952
            #   Must be a platform argument
7953
            #   Add to a list
7954
            #
7955
            push @platforms, $_;
241 dpurdie 7956
            next;
7957
        }
7958
 
7959
        #
325 dpurdie 7960
        #   Continue processing non-platform arguments
345 dpurdie 7961
        #   Each one must be TRUE, allowing for negation.
241 dpurdie 7962
        #
325 dpurdie 7963
        $result = $result ? 1 : 0;
345 dpurdie 7964
        $result = ! $result if ( $not );
7965
        return 0 unless ( $result );
241 dpurdie 7966
    }
7967
 
7968
    #   Platform specified may be an Alias
7969
    #   Perform alias expansion
7970
    #
7971
    @platforms = ExpandPlatforms( @platforms );         # aliasing
227 dpurdie 7972
    Debug3( " ActivePlatform(@_)" );
325 dpurdie 7973
#    Debug0( " Platforms(@platforms)", "PLIST(@plist)" );
227 dpurdie 7974
 
7975
#.. Arguments
241 dpurdie 7976
#   At this point we have a list of platforms and arguments
7977
#   Build up a hash of arguments for each platform being parsed
227 dpurdie 7978
#   Multiple arguments can follow a platform name
241 dpurdie 7979
#   Arguments apply to the preceeding platform name
227 dpurdie 7980
#
241 dpurdie 7981
    $platform = undef;
227 dpurdie 7982
    foreach ( @platforms )
7983
    {
241 dpurdie 7984
        if ( /^--Target/ ) {                     # Arguments
7985
            if ( $platform ) {
7986
                $arguments{$platform}{'Target'} = 1;
7987
            } else {
317 dpurdie 7988
                Warning ("No Platform preceding platform option: $_");
241 dpurdie 7989
            }
7990
 
305 dpurdie 7991
        } elsif ( /^--Only(Prod)|(Debug)/ || /--board=/ ) {
273 dpurdie 7992
            # Known arguments
305 dpurdie 7993
            # Bit of a kludge. Must be a better way
273 dpurdie 7994
 
241 dpurdie 7995
        } elsif ( /^--/ ) {
7996
            Warning ("Unknown platform option: $_");
7997
 
227 dpurdie 7998
        } else {                                # Target
7999
            $platform = $_;
241 dpurdie 8000
            push @plist, $platform;
227 dpurdie 8001
        }
8002
    }
8003
 
241 dpurdie 8004
#.. Scan the expression
227 dpurdie 8005
#
8006
    $scmplatform = uc( $ScmPlatform );          # current platform
325 dpurdie 8007
 
241 dpurdie 8008
    foreach ( @plist )
227 dpurdie 8009
    {
8010
        $platform = uc( Trim( $_ ) );           # trim white and convert case
8011
 
8012
        #
241 dpurdie 8013
        #   Determine filter comparison
8014
        #   Either a Platform or a Target
8015
        #
8016
        if ( $arguments{$platform}{'Target'} )
227 dpurdie 8017
        {
241 dpurdie 8018
            $filter = uc( $ScmTarget );
227 dpurdie 8019
        }
241 dpurdie 8020
        else
8021
        {
8022
            $filter = $scmplatform;             # filter specification
8023
        }
8024
 
227 dpurdie 8025
        Debug3( "   Platform=$platform, Filter=$filter" );
8026
 
8027
        #
8028
        #   Examine platform names
8029
        #   Allow negation of name (!), but all the names must be negated
8030
        #   as a mix does not make sense.
8031
        #   ie:     !P1,!P2,!P3     - All except P1,P2 or P3
8032
        #            P1,P2,P2       - Only P1,P2,P3
8033
        #
241 dpurdie 8034
        my $invert = 0;
8035
        if ( substr($platform, 0, 1) eq '!' )
8036
        {
8037
            $count_invert++;
8038
            $platform = substr($platform, 1);
227 dpurdie 8039
        }
8040
        else
241 dpurdie 8041
        {
8042
            $count_vert++;
8043
        }
227 dpurdie 8044
 
241 dpurdie 8045
        $match_count++ if ( $platform eq ''  ||
8046
                            $platform eq '*' ||
8047
                            $platform eq '1' ||
8048
                            $platform eq $filter );
227 dpurdie 8049
    }
8050
 
241 dpurdie 8051
    #
8052
    #   Sanity test
8053
    #   Force failure on bad sanity
8054
    #
8055
    if ( $count_vert && $count_invert )
8056
    {
8057
        Warning( "Platform expression makes no sense. Mixed use of '!' operator",
8058
                 "Expression: @_" );
8059
        return 0;
8060
    }
8061
 
8062
    #
8063
    #   Test for pass
8064
    #   If not using '!', then any match passes : P1 or P2 or P3
8065
    #   If are using '!', then any match is bad : !P1 and !P2 and !P3 == !(P1 or P2 or P3)
8066
    #
8067
    if ( ( $count_vert && $match_count ) || ( $count_invert && ( not $match_count) )   )
8068
    {
227 dpurdie 8069
        Debug3( " ActivePlatform(@_ == $ScmPlatform) = TRUE" );
8070
        return 1;
8071
    }
241 dpurdie 8072
 
227 dpurdie 8073
    Debug3( " ActivePlatform(@_ == $ScmPlatform) = FALSE" );
8074
    return 0;
8075
}
8076
 
8077
#-------------------------------------------------------------------------------
321 dpurdie 8078
# Function        : If
8079
#
8080
# Description     : Function for embedding arguments in directives
8081
#                   To be used within another directive
8082
#                   ie:
8083
#                       AnyDirective ('*',  arg1, arg2, ...
8084
#                                           If (SomePlatform, arg1, .. ,argn))
8085
#
8086
# Inputs          : $platform               - Active Platform speciifier
8087
#                   @args                   - Args
8088
#
8089
# Returns         : @args or nothing
8090
#
8091
sub  If
8092
{
8093
    my $platform = shift;
8094
    return @_
8095
        if ( ActivePlatform( $platform ));
8096
    return;
8097
}
8098
 
8099
#-------------------------------------------------------------------------------
227 dpurdie 8100
# Function        : RegisterMakefileGenerate
8101
#
8102
# Description     : Register a function to be called at the start of the
8103
#                   makefile generation process
8104
#
8105
# Inputs          : $fname      - Name of the function
8106
#                   $args       - Function Arguments
8107
#
8108
# Returns         : Nothing
8109
#
8110
our @MF_Generators;
8111
sub RegisterMakefileGenerate
8112
{
8113
   my ($fref) = @_;
8114
   my $rtype = ref($fref) || 'not a reference';
8115
 
8116
   Error ("RegisterMakefileGenerate called incorrectly",
8117
          "First argument MUST be a code reference",
8118
          "It is a $rtype"
8119
          ) unless ( $rtype eq 'CODE' );
8120
 
8121
   #
8122
   #    Save the arguments by reference in an array
8123
   #    The array will be processed later
8124
   #
8125
   push @MF_Generators, \@_;
8126
}
8127
 
8128
#-------------------------------------------------------------------------------
271 dpurdie 8129
# Function        : RegisterSrcHook
8130
#
8131
# Description     : Register a function to be called when a source file is
8132
#                   declared
8133
#
8134
# Inputs          : $ext        - Extension of interest
8135
#                                 '*' will be used by all
8136
#                   $fname      - Name of the function
8137
#                   $args       - Function Arguments
8138
#
8139
# Returns         : Nothing
8140
#
8141
sub RegisterSrcHook
8142
{
8143
    my $ext = shift;
8144
    my ($fref) = @_;
8145
    my $rtype = ref($fref) || 'not a reference';
8146
 
8147
    Error ("RegisterSrcHook called incorrectly",
8148
           "Second argument MUST be a code reference",
8149
           "It is a $rtype"
8150
           ) unless ( $rtype eq 'CODE' );
8151
 
8152
    #
8153
    #    Save the arguments by reference in an array
8154
    #    The array will be processed later
8155
    #
8156
    push @{$MF_RegisterSrcHooks{$ext}}, \@_;
8157
}
8158
 
8159
 
8160
#-------------------------------------------------------------------------------
227 dpurdie 8161
# Function        : MakefileHeader
8162
#
8163
# Description:    : Generate a "standard" makefile header.
8164
#
8165
#..
8166
 
8167
sub MakefileHeader
8168
{
8169
    my ($file, $desc, $by, @trailing) = @_;
8170
    my ($diff);
8171
 
8172
    $diff = 0 if (($diff = ((80-5) - length($desc))) < 0);
8173
    $desc .= ' ' . ('-' x $diff);
8174
 
8175
    print $file <<EOF;
8176
# -*- mode: mak; -*-
8177
#-- $desc
8178
#
8179
#                   -- Please do not edit this file. --
8180
#
8181
#       To do so may result in a system failure, in additional to any
8182
#       changes made shall be overwritten.
8183
#
8184
# Created by $by
8185
#         on $::CurrentTime
8186
#
8187
EOF
8188
    #
8189
    #   Print out the trailer
8190
    #   This is an array. Place each entry on a new line
8191
    #
8192
    print $file $_ . "\n" for ( @trailing );
8193
}
8194
 
8195
###############################################################################
8196
# MakeFileGenerate:
8197
#       This subroutine does all of the actual make file generation based
8198
#       on information provided in the calls to the various public
8199
#       interface routines.
8200
#
8201
# Inputs:
8202
#
8203
# Returns:
8204
###############################################################################
8205
 
8206
my $MakefileGenerate_once = 0;
8207
sub MakefileGenerate
8208
{
8209
    my $Makefile = "$ScmPlatform.mk";
8210
    Debug( "MakefileGenerate: $Makefile" );
8211
 
8212
    #
8213
    #   Nasty things happen when we generate a makefile twice
8214
    #   Just warn the user and do nothing
8215
    #   If its in the common makefile.pl then just ignore it
8216
    #
8217
    if ( $ScmProcessingRootMake )
8218
    {
8219
        Warning ("MakefileGenerate directive is not allowed in common makefile.pl");
8220
        return;
8221
    }
8222
 
8223
    if ( $MakefileGenerate_once )
8224
    {
8225
        Warning ("MakefileGenerate should only be called once.",
8226
                 "Dir: $::Cwd");
8227
        return;
8228
    }
8229
    $MakefileGenerate_once = 1;
8230
 
8231
    #
8232
    #   Invoke all registered Makefile Generator functions
8233
    #   These allow clever directives to collect information to be
8234
    #   processed before the makefiles are created
8235
    #
8236
    while ( @MF_Generators )
8237
    {
8238
        Debug( "MakefileGenerate: Invoke RegisterMakefileGenerate function" );
8239
        my ($fname, @args) = @{shift @MF_Generators};
8240
        &$fname ( @args );
8241
    }
8242
 
8243
    #
8244
    #   Allow the toolset the opportunity to process all the collected data
8245
    #   before the makefile is created. This is optional
8246
    #
8247
    my( $if ) = MakeIf::Factory();              # build interface
8248
    $if->Preprocess();
8249
 
8250
    #
343 dpurdie 8251
    #   If we have supressed the Toolset use, then we need to sanity test
8252
    #   the use of the toolset
8253
    #
8254
    if ( $ScmNoToolsTest )
8255
    {
8256
        ReportError ("Building programs not supported with --NoToolset") if ( @PROGS || @TESTPROGS );
8257
        ReportError ("Building libraries not supported with --NoToolset") if ( @LIBS || @MLIBS || @SHLIBS );
8258
        ReportError ("Building projects not supported with --NoToolset") if ( %PROJECTS );
8259
        ErrorDoExit();
8260
    }
8261
 
8262
    #
227 dpurdie 8263
    #   Auto package the 'descpkg' file
8264
    #   If this makefile packages any files, then it can also package the descpkg file
8265
    #   The descpkg will be piggybacked into all makefiles that do a package
8266
    #
8267
    if ( %PACKAGE_FILES || %PACKAGE_HDRS || %PACKAGE_CLSS || %PACKAGE_LIBS
8268
                        || %PACKAGE_SHLIBS || %PACKAGE_PROGS )
8269
    {
251 dpurdie 8270
        Src ('*', 'descpkg') unless ($SRCS{ descpkg });
8271
        PackageFile ('*', 'descpkg');
227 dpurdie 8272
    }
8273
 
8274
    #
8275
    #   Some toolsets NEED a relative root
261 dpurdie 8276
    #   Note: At the moment ScmRoot is relative anyway, thus this code
8277
    #         does nothing
227 dpurdie 8278
    #
8279
    my $gbe_root = $::ScmRoot;
8280
    if ( $::UseRelativeRoot )
8281
    {
8282
        $gbe_root =  RelPath( $::ScmRoot );
8283
    }
8284
 
8285
    #
8286
    #   Now start to create the makefile
8287
    #
3890 dpurdie 8288
    ::ToolsetFile ($Makefile);
285 dpurdie 8289
    open( MAKEFILE, '>', $Makefile ) || Error( "Cannot create $Makefile" );
227 dpurdie 8290
    ::MakefileHeader( *MAKEFILE,
8291
                      'Auto-generated Platform Dependent Makefile',
8292
                      "$ScmMakelib (version $ScmVersion)",
343 dpurdie 8293
                      "# Copyright (C) 1995-$::CurrentYear Vix-ERG, All rights reserved",
227 dpurdie 8294
                      '#',
8295
                      "# Located in $::Cwd",
8296
                      "# Platform $::ScmPlatform",
8297
                      '#' . ('-' x 79),
8298
                      );
8299
 
8300
    #
8301
    #   Ensure that some essential variables are set
8302
    #
8303
    print MAKEFILE <<EOF;
8304
#
8305
#   Validate essential environment variables
8306
#
8307
ifndef GBE_BIN
8308
    \$(error ERROR: GBE_BIN is not available)
8309
endif
8310
ifndef GBE_PERL
8311
    \$(error ERROR: GBE_PERL is not available)
8312
endif
8313
ifndef DEBUG
8314
    \$(error ERROR: DEBUG is not defined)
8315
endif
8316
EOF
8317
 
8318
 
8319
    print MAKEFILE <<EOF;
8320
 
8321
#
8322
#   Basic definitions
8323
#
343 dpurdie 8324
GBE_ROOT      := $gbe_root
8325
GBE_ROOT_ABS  := \$(abspath \$(GBE_ROOT))
8326
GBE_HOST      := $::ScmHost
8327
GBE_HOSTMACH  := $::GBE_MACHTYPE
8328
GBE_TARGET    := $::ScmTarget
8329
GBE_MACHTYPE  := $::ScmMachType
8330
GBE_PLATFORM  := $::ScmPlatform
8331
GBE_PBASE     := $::Pbase
8332
GBE_TYPE      := \$(if \$(findstring 1,\$(DEBUG)),D,P)
227 dpurdie 8333
EOF
8334
 
343 dpurdie 8335
MakePrint( "GBE_ARGS      := @ScmPlatformArgs\n" )
227 dpurdie 8336
    if ( scalar @ScmPlatformArgs );
8337
 
343 dpurdie 8338
MakePrint( "GBE_PRODUCT   := $ScmProduct\n" )
227 dpurdie 8339
    if ( $ScmProduct ne "" );
8340
 
343 dpurdie 8341
MakePrint( "GBE_OS_COMMON := $::BUILDINFO{$ScmPlatform}{OS_COMMON}\n" )
227 dpurdie 8342
    if ( exists($::BUILDINFO{$ScmPlatform}{OS_COMMON}) );
8343
 
8344
 
8345
    print MAKEFILE <<EOF;
8346
 
8347
SHELL           := \$(GBE_BIN)/sh
8348
SHELLARGS       :=
8349
EXTENDED_LINE   := \$(GBE_BIN)/extend.lst
8350
export EXTENDED_LINE MAKE
8351
 
343 dpurdie 8352
MFLAGS           := --no-print --warn -r
8353
BUILDNAME        := $::ScmBuildName
8354
BUILDVER         := $::ScmBuildVersionFull
8355
BUILDVERNUM      := $::ScmBuildVersion
227 dpurdie 8356
BUILDPREVIOUSVER := $::ScmBuildPreviousVersion
343 dpurdie 8357
DEPLOYPATCH      := $ScmDeploymentPatch
8358
GBE_NOTOOLSTEST  := $ScmNoToolsTest
227 dpurdie 8359
 
8360
#
8361
#   Ensure PWD is correctly set
8362
#
8363
PWD             := \$(CURDIR)
8364
export PWD
8365
 
261 dpurdie 8366
#
8367
#   NODEPEND    - Used to suppress generated dependency file checking
8368
#                 Mostly done in jmake.pl
8369
#   EXPERT      - Used to suppress dependency on this makefile
8370
#
8371
EOF
8372
 
285 dpurdie 8373
MakePrint( "EXPERT\t\t?= " . ($ScmExpert ? '1' : '0' ) . "\n" );
8374
MakePrint( "NODEPEND\t?= 0\n" );
261 dpurdie 8375
 
8376
print MAKEFILE <<EOF;
8377
 
8378
#
8379
#   SCM_MAKEFILE - The name of the file to depend upon
8380
#                  Supressed in EXPERT mode
8381
#
8382
ifneq (\$(EXPERT),0)
8383
SCM_MAKEFILE	:=
8384
else
8385
SCM_MAKEFILE	:= $Makefile
8386
endif
8387
EOF
8388
 
267 dpurdie 8389
#
8390
#   Setup the base directory for the packaging process
8391
#   When building a deployable package the base directory is changed to match
8392
#   that used by the deployment world. This is done so that the descpkg file
8393
#   can be created in the correct location
8394
#
8395
my  $PKGDIR = "pkg/$::Pbase";
8396
    $PKGDIR = "build/deploy" if ( $DEPLOYPACKAGE );
8397
Verbose("Setting PKGDIR: $PKGDIR");
8398
 
261 dpurdie 8399
print MAKEFILE <<EOF;
8400
 
227 dpurdie 8401
#--------- Targets -------------------------------------------------------------
8402
 
8403
.PHONY: 	default all build install package unpackage uninstall \\
8404
		clean unbuild clobber deploy
8405
 
373 dpurdie 8406
default:
227 dpurdie 8407
all:		install package deploy
8408
build:		make_init generate install_hdr depend make_lib \\
8409
		install_lib make_install_shlib make_prog install_class
8410
install:	build install_prog
8411
package:	package_files package_hdr package_lib package_shlib package_prog \\
8412
		package_class
8413
unpackage:	unpackage_class unpackage_prog unpackage_shlib \\
8414
		unpackage_lib unpackage_hdr unpackage_files
8415
uninstall:	uninstall_class uninstall_prog uninstall_shlib \\
8416
		uninstall_lib uninstall_hdr
8417
clean:		make_clean unmake_prog unmake_test unmake_lib unobj \\
261 dpurdie 8418
		undepend ungenerate rmlitter unmake_dir
227 dpurdie 8419
unbuild:	clean uninstall
8420
clobber:	unpackage unbuild
8421
deploy:		install run_deploy
8422
 
8423
#--------- Macros --------------------------------------------------------------
8424
 
8425
OBJDIR		= \$(GBE_PLATFORM)\$(GBE_TYPE).OBJ
8426
LIBDIR		= \$(GBE_PLATFORM).LIB
8427
BINDIR		= \$(GBE_PLATFORM)\$(GBE_TYPE).BIN
8428
CLSDIR		= classes\$(GBE_TYPE)
8429
 
267 dpurdie 8430
PKGDIR		= \$(GBE_ROOT)/$PKGDIR
227 dpurdie 8431
INCDIR_PKG	= \$(PKGDIR)/include
8432
LIBDIR_PKG	= \$(PKGDIR)/lib
8433
BINDIR_PKG	= \$(PKGDIR)/bin
8434
CLSDIR_PKG	= \$(PKGDIR)/classes
8435
 
8436
LOCALDIR	= \$(GBE_ROOT)/local
8437
INCDIR_LOCAL	= \$(LOCALDIR)/inc
8438
LIBDIR_LOCAL	= \$(LOCALDIR)/lib
8439
BINDIR_LOCAL	= \$(LOCALDIR)/bin
8440
CLSDIR_LOCAL	= \$(LOCALDIR)/classes
8441
BINDIR_LOCAL_PATH = \$(GBE_ROOT_ABS)/local/bin/\$(GBE_PLATFORM)\$(GBE_TYPE)
8442
 
8443
INTERFACEDIR	= \$(GBE_ROOT)/$ScmInterface
8444
INCDIR_INTERFACE= \$(INTERFACEDIR)/include
8445
LIBDIR_INTERFACE= \$(INTERFACEDIR)/lib
8446
BINDIR_INTERFACE= \$(INTERFACEDIR)/bin
8447
CLSDIR_INTERFACE= \$(INTERFACEDIR)/classes
8448
 
8449
.SUFFIXES:		# Delete the default suffixes
8450
 
8451
EOF
8452
 
8453
    MakePrintList( \@DEFINES );
8454
    MakeNewLine();
8455
 
8456
#-------------------------------------------------------------------------------
8457
#
8458
#
261 dpurdie 8459
    MakeHeader ("Defines, flags and file sets");
227 dpurdie 8460
 
8461
    # Flags
261 dpurdie 8462
    foreach my $opt ( keys %ScmCompilerOpts )
8463
    {
8464
        MakeDefEntry ( $opt, "=", $ScmCompilerOpts{$opt} );
8465
    }
227 dpurdie 8466
 
261 dpurdie 8467
    MakeDefEntry( "CFLAGS",         "=", \@CFLAGS, \@CFLAGS_PROD, \@CFLAGS_DEBUG );
8468
    MakeDefEntry( "CLINTFLAGS",     "=", \@CLINTFLAGS, \@CLINTFLAGS_PROD, \@CLINTFLAGS_DEBUG );
8469
    MakeDefEntry( "CDEPENDFLAGS",   "=", \@CFLAGS, \@CFLAGS_PROD, \@CFLAGS_DEBUG );
8470
    MakeDefEntry( "CXXFLAGS",       "=", \@CXXFLAGS, \@CXXFLAGS_PROD, \@CXXFLAGS_DEBUG );
8471
    MakeDefEntry( "CXXLINTFLAGS",   "=", \@CXXLINTFLAGS, \@CXXLINTFLAGS_PROD, \@CXXLINTFLAGS_DEBUG );
8472
    MakeDefEntry( "CXXDEPENDFLAG",  "=", \@CXXFLAGS, \@CXXFLAGS_PROD, \@CXXFLAGS_DEBUG );
267 dpurdie 8473
    MakeDefEntry( "ASFLAGS",        "=", \@ASFLAGS, \@ASFLAGS_PROD, \@ASFLAGS_DEBUG );
8474
    MakeDefEntry( "LDFLAGS",        "=", \@LDFLAGS, \@LDFLAGS_PROD, \@LDFLAGS_DEBUG );
227 dpurdie 8475
 
8476
 
8477
#-------------------------------------------------------------------------------
8478
#   
8479
#
261 dpurdie 8480
    MakeHeader ("Tool Search Path",
8481
                "Extend the PATH seen by all the tools to include",
8482
                "The tools/bin directories discovered in Packages" );
8483
    my $put_PATH;
8484
    my $put_LD_LIBRARY_PATH;
8485
    for my $path ( ToolExtensionPaths() )
8486
    {
8487
        MakePrint( "PATH := $path$::ScmPathSep\$(PATH)\n" );
8488
        $put_PATH = 1;
227 dpurdie 8489
 
261 dpurdie 8490
        if ( $::ScmHost eq "Unix" )
8491
        {
227 dpurdie 8492
        MakePrint( "LD_LIBRARY_PATH ?= \n" );
8493
        MakePrint( "LD_LIBRARY_PATH := $path$::ScmPathSep\$(LD_LIBRARY_PATH)\n" );
261 dpurdie 8494
            $put_LD_LIBRARY_PATH =1;
8495
        }
227 dpurdie 8496
    }
8497
 
261 dpurdie 8498
    #   Export the appropriate environment variables
8499
    #   Note: Windows has an issue with PATH and Path
8500
    #         Haven't got to the bottom of it yet, but it would appear that DLL
8501
    #         searching uses Path and other stuff uses PATH. Not too sure how we
8502
    #         end up with two (or more in the environment)
8503
    #
8504
    #
8505
    if ( $put_LD_LIBRARY_PATH )
8506
    {
343 dpurdie 8507
        MakePrint( "export LD_LIBRARY_PATH\n" );
261 dpurdie 8508
    }
227 dpurdie 8509
 
261 dpurdie 8510
    if ( $put_PATH )
8511
    {
343 dpurdie 8512
        MakePrint( "Path := \$(PATH)\n" );
8513
        MakePrint( "export PATH Path\n" );
261 dpurdie 8514
    }
227 dpurdie 8515
 
8516
#-------------------------------------------------------------------------------
8517
#   
8518
#
261 dpurdie 8519
    MakeHeader ("Perl Module Search Path",
8520
                "Extend the PERL5LIB seen by invocations of perl");
227 dpurdie 8521
 
261 dpurdie 8522
    my $perl_module_found;
8523
    for my $path ( ToolExtensionPaths() )
227 dpurdie 8524
    {
261 dpurdie 8525
        if (glob( "$path/*.pm"))
8526
        {
227 dpurdie 8527
        MakePrint( "PERL5LIB := $path$::ScmPathSep\$(PERL5LIB)\n" );
261 dpurdie 8528
            $perl_module_found = 1;
8529
        }
227 dpurdie 8530
    }
261 dpurdie 8531
    if ( $perl_module_found  )
8532
    {
227 dpurdie 8533
    MakePrint( "export PERL5LIB\n" );
261 dpurdie 8534
    }
227 dpurdie 8535
 
261 dpurdie 8536
#-------------------------------------------------------------------------------
8537
#   Internal Helper Functions
8538
#   Creating INCLUDE and LIBRARY paths
8539
#
8540
 
8541
# Assist in creating a list paths
8542
#   $pList  - Reference to an array to which $data will be added
8543
#   $pSeen  - Hash Ref to track tags that have been seen
8544
#   $data   - Data item to add, if tag is defined, but not seen
8545
#   $tag    - Resolved name for item
8546
#
227 dpurdie 8547
    sub PushPath
8548
    {
8549
        my ($pList, $pSeen, $data, $tag) = @_;
8550
        if ( $tag )
8551
        {
8552
            unless ( exists $pSeen->{$tag} )
8553
            {
8554
                $pSeen->{$tag} = 1;
8555
                push @{$pList}, $data;
8556
            }
8557
        }
8558
    }
8559
 
8560
    #
8561
    # Search paths for include files and libraries
8562
    # Currently symbolic paths are created, but there is very little need for this
8563
    #
8564
    sub MakePaths
8565
    {
8566
        my( $root ) = @_;
8567
        my @pathlist;
8568
        my %seen;
8569
 
8570
        #
379 dpurdie 8571
        #   Interface and Local directories are now treated quite
8572
        #   diffently. The Local is under our control.
227 dpurdie 8573
        #
8574
        if ( $root =~ /INTERFACE/ ) {
379 dpurdie 8575
 
8576
            #   eg. SCA_WIN32   and SCA_WIN32       and SCA_SOLARIS
8577
            #       SCA             WIN32_i386          SPARC
8578
            #       WIN32           SCA                 SCA
8579
            #       .               WIN32               SOLARIS
8580
            #                       .                   .
8581
            #..
8582
 
8583
            #
8584
            #   For Interface Path List use the 'PARTS' as calculated within
8585
            #   the build file. Its good enough for everthing else in JATS
8586
            #
8587
            foreach ( @{$::BUILDINFO{$ScmPlatform}{PARTS}} ) {
227 dpurdie 8588
                PushPath( \@pathlist, \%seen, "$root/$_",   $_ );
8589
            }
8590
        }
379 dpurdie 8591
        else
8592
        {
8593
            #
8594
            #   Local directory
8595
            #   The user can (should) only install stuff into a few known
8596
            #   locations.
8597
            #
8598
            foreach ( $ScmPlatform, $ScmProduct, $ScmTarget ) {
8599
                PushPath( \@pathlist, \%seen, "$root/$_",   $_ );
8600
            }
8601
        }
227 dpurdie 8602
 
379 dpurdie 8603
        #
8604
        #   Add OS Common Directory
8605
        ### May need more testing before being added
8606
        #
8607
        #if ( exists($::BUILDINFO{$ScmPlatform}{OS_COMMON}) )
8608
        #{
8609
        #    my $os_common = $::BUILDINFO{$ScmPlatform}{OS_COMMON};
8610
        #    PushPath( \@pathlist, \%seen, "$root/$os_common", $os_common );
8611
        #}
227 dpurdie 8612
 
379 dpurdie 8613
        #
8614
        #   Add the root directory too
8615
        #
227 dpurdie 8616
        push @pathlist, "$root";
8617
        return \@pathlist;
8618
    }
379 dpurdie 8619
 
227 dpurdie 8620
 
8621
#-------------------------------------------------------------------------------
8622
#   
8623
#
261 dpurdie 8624
    MakeHeader ("Include Search Paths",
367 dpurdie 8625
                "Package Include Paths for header files and libraries" );
227 dpurdie 8626
 
367 dpurdie 8627
    MakeDefEntry( 'PINCDIRS', '=', '# includes');
8628
    MakeDefEntry( 'PLIBDIRS', '=', '# libraries');
8629
 
8630
    for my $package (@{$::ScmBuildPkgRules{$ScmPlatform} })
8631
    {
8632
        #
8633
        #   Skip the pseudo package that encapsulates the interface
8634
        #   directory. Currently the makefiles do this in a different
8635
        #   manner - to be resolved
8636
        #
8637
        #   Just comment out the lines so that the data is visible
8638
        #   Its a hint to make use of the data
8639
        #
8640
        my $prefix = '';
8641
        $prefix = '# ' if ( $package->{'TYPE'} eq 'interface' );
8642
        $prefix = '# ' if ( $package->{'TYPE'} eq 'build' );
8643
 
8644
 
8645
        my $name = $package->{'NAME'} . '/' . $package->{'VERSION'};
8646
        my $base = $package->{'ROOT'};
8647
 
1328 dpurdie 8648
        my @doc;
8649
        push (@doc, "From: $base");
8650
        push (@doc, 'BuildPkgArchive via Interface' )if $package->{'TYPE'} eq 'build' ;
8651
        push (@doc, 'Is Interface' ) if $package->{'TYPE'} eq 'interface' ;
367 dpurdie 8652
 
1328 dpurdie 8653
        MakeHeader ("Source: $name", @doc);
8654
 
367 dpurdie 8655
        #
8656
        #   List include and library directories
8657
        #   Note: Need the True Path for windows.
8658
        #       Some makefile functions (wildcard) only work as expected
8659
        #       if the case of the pathname is correct. Really only a problem
8660
        #       with badly formed legecy packages where the Windows user
8661
        #       guessed at the package format.
8662
        #
8663
        #       The conversion to a TruePath is done when ScmBuildPkgRules
8664
        #       is created. Create one, use many time.
8665
        #
8666
        #
8667
        for my $type (qw (PINCDIRS PLIBDIRS) )
8668
        {
8669
            for my $path ( @{$package->{$type}} )
8670
            {
8671
                MakeDefEntry ( "$prefix$type", "+=", $base . $path);
8672
            }
8673
        }
8674
    }
8675
 
8676
#-------------------------------------------------------------------------------
8677
#   
8678
#
8679
    MakeHeader ("Include Search Paths",
8680
                "Local Include Paths",
8681
                " LINKDIRS - Local include search path (short)",
8682
                " INCDIRS  - Include search path (complete)",
8683
                " NODEPDIRS - ",
8684
                " SRCDIRS - ",
8685
                " LIBDIRS - Library search path",
8686
 
8687
                );
8688
 
227 dpurdie 8689
    # Include search path
8690
    #
8691
    #   user-local
367 dpurdie 8692
    #   local
8693
    #   interface
8694
    #       BuildPkgArchive
8695
    #       LinkPkgArchive
227 dpurdie 8696
    #   user-global
8697
    #
8698
 
367 dpurdie 8699
    MakeDefEntry ( "\nLINCDIRS",    "= ", \@L_INCDIRS );     # .. Local
261 dpurdie 8700
    MakeDefEntry ( "LINCDIRS",      "+=", MakePaths( '$(INCDIR_LOCAL)' ));     # .. Sandbox interface
8701
    MakeDefEntry ( "LINCDIRS",      "+=", MakePaths( '$(INCDIR_INTERFACE)' )); # .. Sandbox interface
8702
    MakeDefEntry ( "LINCDIRS",      "+=", \@G_INCDIRS );    # .. Global
227 dpurdie 8703
 
367 dpurdie 8704
    MakeDefEntry ( "INCDIRS",  "= ", '$(LINCDIRS)' );               # Local
8705
    MakeDefEntry ( "INCDIRS",  "+=", '$(PINCDIRS)' );               # Package
8706
    MakeDefEntry ( "LINCDIRS", "+=", \@S_INCDIRS );                 # System
227 dpurdie 8707
 
8708
    # Source search path
8709
 
261 dpurdie 8710
    MakeDefEntry( "\nNODEPDIRS",        "=", \@NODEPDIRS );
227 dpurdie 8711
 
367 dpurdie 8712
    MakeDefEntry( "\nSRCDIRS","= "  , [ @L_SRCDIRS, @G_SRCDIRS ] ); # Local
8713
    MakeDefEntry ( "SRCDIRS", "+=" , '$(PINCDIRS)' );               # Package
8714
    MakeDefEntry ( "SRCDIRS", "+=" , \@S_INCDIRS );                 # System
227 dpurdie 8715
 
8716
    # Library search path
8717
    #
8718
    #   user-local
367 dpurdie 8719
    #   local
8720
    #   interface
8721
    #       BuildPkgArchive
8722
    #       LinkPkgArchive
227 dpurdie 8723
    #   user-global
8724
 
367 dpurdie 8725
    MakeDefEntry( "\nLIBDIRS",  "= ", '$(LIBDIR)' );                    # User Local
261 dpurdie 8726
    MakeDefEntry( "LIBDIRS",    "+=", \@L_LIBDIRS );                    # Local
8727
    MakeDefEntry( "LIBDIRS",    "+=", MakePaths( '$(LIBDIR_LOCAL)' ));  # Sandbox/interface
8728
    MakeDefEntry( "LIBDIRS",    "+=", MakePaths( '$(LIBDIR_INTERFACE)' ));
8729
    MakeDefEntry( "LIBDIRS",    "+=", \@G_LIBDIRS );                    # Global
367 dpurdie 8730
    MakeDefEntry( "LIBDIRS",    "+=", '$(PLIBDIRS)' );                  # Package
261 dpurdie 8731
    MakeDefEntry( "LIBDIRS",    "+=", \@S_LIBDIRS );                    # System
227 dpurdie 8732
 
8733
#-------------------------------------------------------------------------------
8734
#
8735
#   Subdir creation and deletion
8736
#   Creation is done on the fly
8737
#   Deletion is done AFTER the toolset functions have been invoked to create the
8738
#   build artifacts so that the toolsets can create directories too
8739
 
8740
    MakeHeader ("Subdir creation");
8741
    CreateMkdirRules();
2312 dpurdie 8742
    MkdirRule( '$(OBJDIR)', 'OBJDIR', '--Extra=depend,depend.err' );  # Object build directory
8743
    MkdirRule( '$(OBJDIR)/'.$_ ) foreach (@SHLIBS);                     # Shared library build directory
8744
    MkdirRule( '$(LIBDIR)', 'LIBDIR' );                                 # Library directory
8745
    MkdirRule( '$(BINDIR)', 'BINDIR' );                                 # Binary directory
227 dpurdie 8746
 
261 dpurdie 8747
    #
8748
    #   Create a directory for library merge tool to work within
8749
    #
8750
    MkdirRule( "\$(MLIBDIR)", 'MLIBDIR', '--Path=$(GBE_PLATFORM).MRG', '--RemoveAll' ) if (@MLIBS);
8751
 
227 dpurdie 8752
#-------------------------------------------------------------------------------
8753
#   Generate rules and recipes to create all the toolset specific parts
8754
#   This is done fairly early to allow the toolsets to extend various
8755
#   definitions that may be used later in the makefile construction
8756
#
8757
    MakeHeader ("Construct Programs");
8758
 
8759
    foreach my $i ( @PROGS )
8760
    {
289 dpurdie 8761
        my $pProg = $PROGS->Get($i);
8762
        my $pArgs = $pProg->getItems('ARGS');
8763
        my $pObjs = $pProg->getItems('OBJS');
8764
        my $pLibs = $pProg->getItems('LIBS');
227 dpurdie 8765
 
289 dpurdie 8766
        #
8767
        #   Create a list of program object files
8768
        #
8769
        push @PROGOBJS, @$pObjs;
227 dpurdie 8770
 
8771
        MakePrint( "#---- (${i})\n\n" );
8772
        if ( $ScmToolsetProgDependancies )
8773
        {
261 dpurdie 8774
            #
8775
            #   Original style Prog Interface
271 dpurdie 8776
            #   Write some dependency information here and some in the toolset
8777
            #   Problems:
8778
            #       1) Errors in library dependency generation will be
8779
            #          reported after all the object files have been created
8780
            #          Thus the error message and the make-stop are seperated
8781
            #          by many,many lines of output. This makes it difficult
8782
            #          to see the error.
261 dpurdie 8783
            #
271 dpurdie 8784
            #       2) Lack of Flexability
8785
            #
293 dpurdie 8786
            MakeEntry( "\$(BINDIR)/$i$::exe: ", "", "\\\n\t\t", ".$::o ", @$pObjs );
227 dpurdie 8787
        }
8788
        else
8789
        {
261 dpurdie 8790
            #
8791
            #   New Style Prog Interface
8792
            #   The toolset does it all
8793
            #
8794
            #   Flag the progam packaging as a placeholder.
8795
            #   The toolset will replace/update it.
8796
            #
227 dpurdie 8797
            PackageProgRemoveFiles( $i );
8798
        }
8799
 
289 dpurdie 8800
        $if->LD    ( $i, $pArgs, $pObjs, $pLibs );
8801
        $if->LDLINT( $i, $pArgs, $pObjs, $pLibs );
227 dpurdie 8802
    }
8803
 
8804
#-------------------------------------------------------------------------------
8805
#   
8806
#
8807
    MakeHeader ("Construct Test Programs");
289 dpurdie 8808
    foreach my $i ( @TESTPROGS )
227 dpurdie 8809
    {
289 dpurdie 8810
        my $pProg = $TESTPROGS->Get($i);
8811
        my $pArgs = $pProg->getItems('ARGS');
8812
        my $pObjs = $pProg->getItems('OBJS');
8813
        my $pLibs = $pProg->getItems('LIBS');
227 dpurdie 8814
 
289 dpurdie 8815
        #
8816
        #   Create a list of program object files
8817
        #
8818
        push @TESTPROGOBJS, @$pObjs;
8819
 
227 dpurdie 8820
        MakePrint( "#---- (${i})\n\n" );
8821
        if ( $ScmToolsetProgDependancies )
8822
        {
293 dpurdie 8823
            MakeEntry( "\$(BINDIR)/$i$::exe: ", "", "\\\n\t\t", ".$::o ", @$pObjs );
227 dpurdie 8824
        }
8825
        else
8826
        {
8827
            PackageProgRemoveFiles( $i );
8828
        }
8829
 
289 dpurdie 8830
        $if->LD    ( $i, $pArgs, $pObjs, $pLibs );
8831
        $if->LDLINT( $i, $pArgs, $pObjs, $pLibs );
227 dpurdie 8832
    }
8833
 
8834
#-------------------------------------------------------------------------------
8835
#
8836
#
8837
    MakeHeader ("Transfer Scripts to BINDIR");
8838
    foreach my $i ( sort ( values %SCRIPTS ))
8839
    {
8840
        my $tname = "\$(BINDIR)/" . StripDir( $i );
8841
 
8842
 
8843
        MakePrint( "$i:\t\tmakefile.pl\n" .
261 dpurdie 8844
            "\t\$(XX_PRE)if [ ! -f \"$i\" ]; then echo Script [$i] not found; exit 2; fi\n\n" );
227 dpurdie 8845
 
8846
        #
8847
        #   Create a rule to copy the script into the BIN directory
8848
        #   Mark the script as executable - It can't hurt and its there
8849
        #   to be run as part of a test.
8850
        #
8851
        MakePrint "$tname:\t\$(GBE_BINDIR) $i\n" .
8852
                  "\t\$(XX_PRE)\$(cp) -f $i $tname\n" .
8853
                  "\t\$(XX_PRE)\$(chmod) -f +wx $tname\n\n"
8854
    }
8855
 
8856
#-------------------------------------------------------------------------------
8857
#   
8858
#
8859
    MakeHeader ("Construct Libraries");
8860
    foreach my $i ( @LIBS )
8861
    {
289 dpurdie 8862
        my $pLib  = $LIBS->Get($i);
8863
        my $pArgs = $pLib->getItems('ARGS');
8864
        my $pObjs = $pLib->getItems('OBJS');
227 dpurdie 8865
 
363 dpurdie 8866
        unless ( $ScmToolsetNillLibSrc )
8867
        {
8868
            Error ("Library has no component objects: $i")
8869
                if ( scalar @$pObjs <= 0 );
8870
        }
299 dpurdie 8871
 
227 dpurdie 8872
        MakePrint "#---- (${i})\n\n";
289 dpurdie 8873
        $if->AR(     $i, $pArgs, $pObjs, $pLib);
8874
        $if->ARLINT( $i, $pArgs, $pObjs, $pLib );
227 dpurdie 8875
    }
8876
 
289 dpurdie 8877
#-------------------------------------------------------------------------------
8878
#   
8879
#
8880
    MakeHeader ("Construct Merged Libraries");
227 dpurdie 8881
    sub MlibEntry
8882
    {
289 dpurdie 8883
        my( $mlib, $plib, $pLibs ) = @_;
227 dpurdie 8884
        my @flib;
8885
 
289 dpurdie 8886
        MakePrint '$(LIBDIR)/' . GenLibName($mlib) . ":";
8887
        foreach my $lib ( @$pLibs )
227 dpurdie 8888
        {
289 dpurdie 8889
            #
8890
            #   Each library name may contains one embedded option which
8891
            #   specifies the source directory
8892
            #       libname[,--Option | BaseSubdir]
8893
            #
227 dpurdie 8894
            my ($slib, $sdir) = split( ',', $lib );
343 dpurdie 8895
            my $mode;
227 dpurdie 8896
 
8897
            #
283 dpurdie 8898
            #   By default the librares are pulled from LOCAL unless the
8899
            #   library is built in this directory, in which case it will
289 dpurdie 8900
            #   be used.
227 dpurdie 8901
            #
289 dpurdie 8902
            $sdir = ( $LIBS->Get($slib) ) ? '--Here' : '--Local'
8903
                unless ( $sdir );
227 dpurdie 8904
 
8905
            #
8906
            #   --Interface     - Pull library from the interface directory
8907
            #   --Local         - Pull library from the local directory
8908
            #   --SubDir=xxxx   - Pull library from specified subdirectory
283 dpurdie 8909
            #   --Here          - Pull from local directory if built locally
227 dpurdie 8910
            #   otherwise       - Pull library from specified subdirectory
8911
            #
8912
            if ($sdir eq '--Interface') {
8913
                $sdir = '$(LIBDIR_INTERFACE)/$(GBE_PLATFORM)';
8914
 
343 dpurdie 8915
 
8916
            } elsif ($sdir eq '--InterfacePlain') {
8917
                $sdir = '$(LIBDIR_INTERFACE)/$(GBE_PLATFORM)';
8918
                $mode = 1;
8919
 
227 dpurdie 8920
            } elsif ( $sdir eq '--Local') {
8921
                $sdir = $PackageInfo{'Lib'}{'IBase'} .  # Base of Installed libs
8922
                        $PackageInfo{'Lib'}{'Dir'};     # Default subdir
8923
 
8924
            } elsif ( $sdir =~ m~^--SubDir=(.*)~ ) {
8925
                $sdir = $1 . '/$(LIBDIR)';
8926
 
283 dpurdie 8927
            } elsif ( $sdir eq '--Here') {
8928
                $sdir = '$(LIBDIR)';
8929
 
227 dpurdie 8930
            } else {
8931
                $sdir .= '/$(LIBDIR)';
8932
            }
8933
 
343 dpurdie 8934
            MakePrint " \\\n\t\t${sdir}/" . GenLibName($slib, $mode);
227 dpurdie 8935
            push @flib, "${sdir}/${slib}";
8936
        }
289 dpurdie 8937
        return \@flib;
227 dpurdie 8938
    }
8939
 
8940
    foreach my $i ( @MLIBS )
8941
    {
289 dpurdie 8942
        my $pLib  = $MLIBS->Get($i);
8943
        my $pArgs = $pLib->getItems('ARGS');
8944
        my $pLibs = $pLib->getItems('LIBS');
227 dpurdie 8945
 
261 dpurdie 8946
        MakePrint "#---- (${i})\n\n";
8947
 
227 dpurdie 8948
        unless ( defined &ToolsetARMerge )
8949
        {
8950
            Warning( "Merging of libraries not supported in this toolset yet" );
8951
            Warning( "MergeLibrary: \"$i\" will not be created" );
8952
        }
8953
        else
8954
        {
8955
            #
8956
            #   Create the dependency rule
8957
            #       Target library : source library list
8958
            #           Recipe - generated by the toolset
8959
            #
289 dpurdie 8960
            foreach ( @$pArgs )
227 dpurdie 8961
            {
8962
                Warning( "Ignoring unknown argument to MergeLibrary. $_" );
8963
            }
289 dpurdie 8964
            $pLibs = MlibEntry( $i, $pLib, $pLibs );
8965
            $if->ARMerge( $i, $pArgs, $pLibs, $pLib );
227 dpurdie 8966
        }
8967
    }
8968
 
289 dpurdie 8969
#-------------------------------------------------------------------------------
8970
#   
8971
#
8972
    MakeHeader ("Construct Shared Libraries");
339 dpurdie 8973
 
227 dpurdie 8974
    foreach my $i ( @SHLIBS )
8975
    {
289 dpurdie 8976
        my $pShlib  = $SHLIBS->Get($i);
8977
        my $pArgs = $pShlib->getItems('ARGS');
8978
        my $pObjs = $pShlib->getItems('OBJS');
8979
        my $pLibs = $pShlib->getItems('LIBS');
8980
        my $version = $pShlib->{VERSION};
227 dpurdie 8981
 
289 dpurdie 8982
        $if->SHLD    ( $i, $pArgs, $pObjs, $pLibs, $version );
8983
        $if->SHLDLINT( $i, $pArgs, $pObjs, $pLibs, $version );
227 dpurdie 8984
    }
8985
 
8986
#-------------------------------------------------------------------------------
8987
#   Construct Objects
8988
#   For each object within OBJSOURCE construct the following:
8989
#
8990
#   $(OBJDIR)/object-name:     source-name [makefile]
8991
#       Toolset ...
8992
#
8993
#   
8994
#
8995
    MakeHeader ("Construct Objects");
371 dpurdie 8996
 
227 dpurdie 8997
    foreach my $i ( sort keys %OBJSOURCE )
8998
    {
8999
        my( $src, $sname, $ext, $type, @args );
9000
 
9001
        $src  = $OBJSOURCE{ $i };
9002
        $sname = StripDir( $src );
9003
        $ext  = StripFile( $src );
9004
        $ext = lc($ext)
9005
            if ( $::ScmHost ne "Unix" );
381 dpurdie 9006
        $type = ($ScmSourceTypes{ $ext } || '')
227 dpurdie 9007
            unless (( $type = $SRC_TYPE{ $sname }) );
9008
 
9009
        #
9010
        #   Object source is an object file
9011
        #   No need the generate the object, just create makefile rule
261 dpurdie 9012
        #   [ddp] Not too sure how we get here
227 dpurdie 9013
        #
9014
        if ( $ext eq ".$::o" )
9015
        {
9016
            MakePrint "$src:";
261 dpurdie 9017
            MakePrint " \$(SCM_MAKEFILE)";
227 dpurdie 9018
            MakeNewLine();
9019
            next;
9020
        }
9021
 
9022
        #
9023
        #   Need to create object file
9024
        #
9025
        @args = split( /$;/, $SRC_ARGS{ StripDir( $sname ) } )
9026
            if $SRC_ARGS{ $sname };
9027
 
9028
        push( @args, "--Shared" )
9029
            if ( exists $SHOBJ_LIB{$i} );
9030
 
9031
        #
9032
        #   Convert relative paths to absolute paths if required by the
9033
        #   toolset. Some compilers need ABS paths to generate nice debug
9034
        #   information.
9035
        #
9036
        $src = AbsPath($src)
9037
            if ( $UseAbsObjects );
9038
 
9039
        #
9040
        #   Extract any user specified dependancies
261 dpurdie 9041
        #   These will be added to the dependency list
227 dpurdie 9042
        #
9043
        my @dlist;
9044
        @dlist = split( /$;/, $SRC_DEPEND{$sname} )
9045
            if ( exists $SRC_DEPEND{$sname} );
9046
 
261 dpurdie 9047
        #
9048
        #   Create the dependency part of the object rule
9049
        #   The source file MUST be the first dependent recipes
9050
        #   may assume that $< is the name source file
9051
        #
9052
        MakeEntry( "\$(OBJDIR)/$i.$::o: $src \$(SCM_MAKEFILE)", "", " \\\n\t", "", @dlist );
227 dpurdie 9053
 
9054
        if ( $type eq ".c" ) {
9055
            $if->CC(  $src, $i, \@args );
261 dpurdie 9056
 
227 dpurdie 9057
        } elsif ( $type eq ".cc" ) {
9058
            $if->CXX( $src, $i, \@args );
261 dpurdie 9059
 
227 dpurdie 9060
        } elsif ( $type eq ".asm" ) {
9061
            $if->AS( $src, $i, \@args );
261 dpurdie 9062
 
227 dpurdie 9063
        } else {
9064
            $if->EXT( $src, $i, \@args ) ||
9065
                Warning( "Don't know how to build '$ext' images' for $src, $i" );
9066
            MakeNewLine();
9067
        }
9068
    }
9069
 
9070
#-------------------------------------------------------------------------------
9071
#   Construct Projects
9072
#   Construct toolset specific projects
9073
#
9074
    MakeHeader ("Construct Projects");
9075
    while ( my($project, $entry) = each %PROJECTS)
9076
    {
9077
        $if->PROJECT( $entry );
9078
    }
9079
 
9080
#-------------------------------------------------------------------------------
9081
#   Automated tests
9082
#
9083
    MakeHeader ("Automated tests");
9084
 
9085
    my $idx = 0;
9086
    my @test_set = ("makefile.pl");
9087
    my @test_set_auto = ("makefile.pl");
9088
    my @copy_set = ();
9089
 
9090
    foreach my $pEntry ( @TESTS_TO_RUN )
9091
    {                                           # Foreach test
9092
        $idx++;
9093
        $pEntry->{'index'} = $idx;
9094
        $pEntry->{'test_name'} = "run_test_$idx";
9095
 
9096
        #
9097
        #   If the test is being run within a 'FrameWork' then the underlying
9098
        #   toolset must instantiate the frame work.
9099
        #
9100
        #   This may change. Perhaps frameworks shouldn't be a part of the
9101
        #   toolset. Perhaps they should be standalone. May change
9102
        #
9103
        if ( $pEntry->{framework} )
9104
        {
9105
            $if->TESTFRAMEWORK( $pEntry );
9106
        }
9107
 
9108
        #
9109
        #   Create a rule to run the test
9110
        #
9111
 
9112
        my $tdir_alias = $pEntry->{'testdir'};
9113
        my $tdir = '$(' . $tdir_alias . ')';
9114
 
9115
        my $test_name = $pEntry->{'test_name'};
9116
        push @test_set, $test_name;
9117
        push @test_set_auto, $test_name if ($pEntry->{'auto'} );
9118
 
9119
        my $tprog = $tdir . '/' . StripDir( $pEntry->{'prog'} );
9120
 
9121
        my $me = MakeEntry::New( *MAKEFILE, $test_name, '--Phony' );
9122
        $me->AddDependancy( "\$(GBE_$tdir_alias)" );
9123
        $me->AddDependancy( "\$(INTERFACEDIR)/set_$::ScmPlatform.sh" );
9124
        $me->AddDependancy( $tprog ) if $pEntry->{'copyprog'};
9125
        $me->AddDependancy( @{ $pEntry->{'copyin' } } );
9126
        $me->AddDependancy( map { $tdir . '/' . StripDir($_) } @{ $pEntry->{'copyonce' } } );
9127
        $me->AddDependancy( @{ $pEntry->{'preq'} } );
9128
        $me->RecipePrefix ('$(XX_PRE)');
9129
        $me->RecipeComment( "------ Running test [$idx] ..." );
9130
 
9131
        #
9132
        #   Extend the PATH seen by the script to include the local/bin directory
9133
        #   Allows programs and tests that have been created elsewhere in the component
9134
        #   to be accessed within the script.
9135
        #
9136
        $me->AddShellRecipe ( ". \$(INTERFACEDIR)/set_$::ScmPlatform.sh" );
9137
 
9138
        #
9139
        #   Copy in the files that we need
9140
        #
9141
        foreach my $file ( @{$pEntry->{'copyin'}} )
9142
        {
9143
            my $dst = $tdir . '/' . StripDir( $file );
9144
            UniquePush( \@COPYIN, $dst );
9145
            UniquePush( \@copy_set, $file );
9146
            $me->AddShellRecipe ( "\$(cp) -f $file $dst" );
9147
            $me->AddShellRecipe ( "\$(chmod) -f +wx $dst" );
9148
        }
9149
 
9150
        #
9151
        #   Insert and FrameWork Recipe bits
9152
        #
9153
        $me->AddShellRecipe ( @{$pEntry->{'ShellRecipe'}} );
9154
 
9155
        $me->AddShellRecipe ( "cd $tdir" );
9156
        $me->AddShellRecipe ( ["GBE_TYPE=\$(GBE_TYPE)",
9157
                               "GBE_HOST=\$(GBE_HOST)",
9158
                               "GBE_ROOT=\$(GBE_ROOT_ABS)",
9159
                    		   "PATH=.\\$::ScmPathSep\$(BINDIR_LOCAL_PATH)\\$::ScmPathSep\$\$PATH",
9160
                               $pEntry->{'command'},
9161
                               @{$pEntry->{'args'}},
9162
                               ] );
9163
        $me->Print();
9164
 
9165
 
9166
        #
9167
        #   Create entries to handle the copy-once files
9168
        #
9169
        foreach my $file ( @{ $pEntry->{'copyonce' } } )
9170
        {
9171
            my $tname = $tdir . '/' . StripDir($file);
9172
            my $me = MakeEntry::New( *MAKEFILE, $tname  );
9173
            $me->AddDependancy( $file );
9174
            $me->AddRecipe ( "\$(call CopyFile,CopyIn,$tname,$file,$tdir,)"  );
9175
            $me->Print();
9176
 
9177
            UniquePush( \@COPYIN, $tname );
9178
            UniquePush( \@copy_set, $file );
9179
 
9180
        }
9181
    }
9182
 
9183
    #
9184
    #   Generate a target that specifies the tests to be run
9185
    #   Each test is provided with a dummy name
9186
    #
9187
    push @test_set, @TESTPROJECT_TO_ARUN;
9188
    push @test_set, @TESTPROJECT_TO_URUN;
9189
    MakeEntry3("\nrun_tests", ":", \@test_set )
9190
        if (@test_set);
9191
 
9192
    push @test_set_auto, @TESTPROJECT_TO_ARUN;
9193
    MakeEntry3("\nrun_unit_tests", ":", \@test_set_auto )
9194
        if (@test_set_auto);
9195
 
9196
    #
9197
    #   Generate sanity test for each copyin script
9198
    #   Simply to provide a nice error message for generated scripts
9199
    #   that do not exist at run-time
9200
    #
9201
    test_copy_in:
9202
    foreach my $i ( @copy_set )
9203
    {
9204
        next if ( $SCRIPTS{$i} );
9205
        foreach (  @SHLIB_TARGETS )
9206
        {
9207
            next test_copy_in if ( $i eq $_ );
9208
        }
9209
        MakePrint( "\n$i:\t\tmakefile.pl\n" .
9210
            "\t\@if [ ! -f \"$i\" ]; then echo ERROR: CopyIn Script [$i] not found; exit 2; fi\n" );
9211
    }
9212
 
261 dpurdie 9213
#-------------------------------------------------------------------------------
9214
#   Deploy rules
9215
#
9216
MakeHeader ("Deploy Rules");
227 dpurdie 9217
 
261 dpurdie 9218
print MAKEFILE <<EOF;
9219
.PHONY:		run_deploy
9220
EOF
227 dpurdie 9221
 
261 dpurdie 9222
#
9223
#   Build up the deployfile.pl command line from the available pieces
9224
#
9225
my $command_file = "";
9226
my @command_line;
9227
 
9228
if ( %DEPLOYPACKAGE )
9229
{
9230
    $command_file = $DEPLOYPACKAGE{'cmdfile'};
9231
 
9232
    push @command_line, "\$(XX_PRE)\$(GBE_PERL) -w $command_file";
9233
    push @command_line, "-r \"\$(GBE_ROOT)\"";
9234
    push @command_line, "-n \"$DEPLOYPACKAGE{'name'}\"";
9235
    push @command_line, "-d \"$DEPLOYPACKAGE{'dir'}\"";
9236
    push @command_line, "-v \"\$(BUILDVER)\"";
9237
    push @command_line, "-t \"\$(GBE_TYPE)\"";
9238
    push @command_line, "-o \"\$(BUILDPREVIOUSVER)\"";
9239
    push @command_line, "-m \"\$(GBE_PLATFORM)\"";
9240
    push @command_line, "-g \"\$(GBE_TARGET)\"";
9241
    push @command_line, "-k \"\$(GBE_PRODUCT)\""        if ( $ScmProduct );
9242
    push @command_line, "-p \"\$(DEPLOYPATCH)\""        if ( $ScmDeploymentPatch );
9243
 
9244
}
9245
 
9246
MakeEntry( "run_deploy:\t$command_file\n", "\n", "\t\t", " \\\n", @command_line );
9247
 
227 dpurdie 9248
#-------------------------------------------------------------------------------
261 dpurdie 9249
#   Custom Rules
9250
#
9251
    MakeHeader ("Custom Rules");
9252
    MakePrintList ( \@RULES );
9253
 
9254
#-------------------------------------------------------------------------------
9255
#   Generated Files
9256
#
9257
    MakeHeader ("Generated Files");
9258
    MakePrint ("\n.PHONY: phony_generate\n\n" );
9259
 
9260
    foreach my $i ( @GENERATE_FILES )
9261
    {
9262
        my $gen_tag = $i->{'index'};
9263
 
9264
        #
263 dpurdie 9265
        #   If predelete is enabled, then create a list of files to delete
9266
        #
9267
        if ( $i->{'predelete'}  )
9268
        {
9269
            MakeDefEntry( "generate_gen_$gen_tag", "=",  $i->{'gen'} );
9270
            MakePrint("\n")
9271
        }
9272
 
9273
 
9274
        #
261 dpurdie 9275
        #   Generate the basic generate rule and recipe
9276
        #   together with the prerequisites
9277
        #
9278
        MakeEntry ( "", ":", "", " ", @{$i->{'gen'}} );
9279
 
9280
        unless ( $i->{'clean'} && $i->{'shell'} )
9281
        {
9282
            MakeEntry ( "", "", " \\\n\t\t", "", @{$i->{'preq'}} );
9283
            MakeEntry ( "", "", " \\\n\t\t", "", "phony_generate" ) if $i->{'preq_sus'};
9284
            MakeEntry ( "", "", " \\\n\t\t", "", "\$(SCM_MAKEFILE)" );
9285
 
9286
            MakePrint ("\n\t" . "\@\$(echo) [$i->{'text'}] generating.." );
263 dpurdie 9287
            if ( $i->{'predelete'}  )
9288
            {
9289
                MakePrint ("\n\t" . "\$(XX_PRE)\$(call RmFiles,generate_gen_$gen_tag)" );
9290
            }
261 dpurdie 9291
            MakePrint ("\n\t" . "\$(XX_PRE)\$(call generate_$gen_tag,)" );
9292
        }
9293
 
9294
        #
9295
        #   Generate 'clean' rules and recipes
9296
        #
9297
        if ( $i->{'clean'} )
9298
        {
9299
            MakePrint ("\n\nPHONY: clean_generate_$gen_tag" );
9300
            MakePrint ("\nclean_generate_$gen_tag:" );
343 dpurdie 9301
            MakePrint ("\n\t" . "\$(XX_PRE)-\$(call generate_$gen_tag,$i->{'clean'})" );
261 dpurdie 9302
        }
9303
 
9304
        #
9305
        #   Define a function to contain the body of the generation call
9306
        #   The first argument will be a 'clean' argument
9307
        #
9308
        MakePrint ("\n\ndefine generate_$gen_tag" );
9309
        if ( $i->{'shell'} )
9310
        {
9311
            MakeEntry ("\n\t(" , "\\\n\t)\n", " \\\n\t", ";" , @{$i->{'toolargs'}} );
9312
        }
9313
        else
9314
        {
9315
            MakeEntry ("\n\t" . $i->{'tool'} . ' $1', "\n", " \\\n\t\t", "" , @{$i->{'toolargs'}} );
9316
        }
9317
        MakePrint ("endef\n\n" );
9318
    }
9319
 
9320
#-------------------------------------------------------------------------------
9321
#   Toolset Post Processing
9322
#   Allow the toolset to perform any post processing, before we finally write
9323
#   out any definitions.
9324
#
9325
#   We will not interprete any more user directives, but new stuff may get added
9326
#
9327
#
9328
MakeHeader ("Toolset Post Processing");
9329
$if->Postprocess();
9330
 
9331
################################################################################
9332
#   All interactions with the toolset are now complete
9333
#   All lists are now complete
9334
#
9335
#   Can now create internal definitions
9336
#   
9337
################################################################################
9338
 
9339
    #
9340
    #   Would be nice if this would work
9341
    #   Unfortunatelty we still need $if for the CCDEPENDS and CTAGS work
9342
    #   These must be defined AFTER the definitions
9343
    #
9344
    #   Ideally we should construct our makefile in sections
9345
    #   and then we can order the sections when we write them out
9346
    #
9347
#$if = 0;                            # Ensure the MakeIf class is not called
9348
                                     # If this file is modified
9349
 
9350
#-------------------------------------------------------------------------------
227 dpurdie 9351
#   Sources
9352
#
9353
MakeHeader  ( "Sources");
9354
MakeDefEntry( "CSRCS",      "=",  \@CSRCS );
9355
MakeDefEntry( "CXXSRCS",    "=",  \@CXXSRCS );
9356
MakeDefEntry( "ASSRCS",     "=",  \@ASSRCS );
9357
 
9358
#-------------------------------------------------------------------------------
9359
#   Generated, Installed and Packaged components
9360
#
9361
MakeHeader  ("Generated, Installed and Packaged components");
9362
MakeDefEntry( "INITS",           "=",  \@INITS )   if ( @INITS );
9363
MakeDefEntry( "GENERATED",       "=",  \@GENERATED ) if ( @GENERATED );
9364
MakeDefEntry( "GENERATED_NOTSRC","=",  \@GENERATED_NOTSRC ) if ( @GENERATED_NOTSRC );
9365
MakeDefEntry( "GENERATEDCLEAN",  "=",  CreateNameList( 'clean_generate_', '', ListCleanGenerated() ));
9366
MakeDefEntry( "INSTALL_HDRS",    "=",  \%INSTALL_HDRS ) if ( %INSTALL_HDRS );
9367
MakeDefEntry( "INSTALL_CLSS",    "=",  \%INSTALL_CLSS ) if ( %INSTALL_CLSS );
9368
MakeDefEntry( "OBJS",            "=", CreateNameList( '$(OBJDIR)/', ".$::o", \@OBJS) );
9369
MakeDefEntry( "SHOBJS",          "=", CreateNameList( '$(OBJDIR)/', ".$::o", \%SHOBJ_LIB ));
289 dpurdie 9370
MakeDefEntry( "PROGOBJS",        "=", CreateNameList( '', ".$::o", \@PROGOBJS ));
9371
MakeDefEntry( "TESTPROGOBJS",    "=", CreateNameList( '', ".$::o", \@TESTPROGOBJS ));
9372
MakeDefEntry( "LIBS",            "=", $LIBS->AllTargets() ) if ($::a);
9373
MakeDefEntry( "MLIBS",           "=", $MLIBS->AllTargets() ) if ($::a);
227 dpurdie 9374
MakeDefEntry( "SHNAMES",         "=", \@SHLIBS );
9375
MakeDefEntry( "SHDIRS",          "=", CreateNameList( '$(OBJDIR)/', "", \@SHLIBS ));
9376
MakeDefEntry( "SHLIBS",          "=", \@SHLIB_TARGETS );
9377
MakeDefEntry( "SCRIPTS",         "=", CreateNameList( '$(BINDIR)/', "", \%SCRIPTS ));
9378
MakeDefEntry( "COPYIN",          "=", \@COPYIN );
289 dpurdie 9379
MakeDefEntry( "PROGS",           "=", $PROGS->AllTargets() );
227 dpurdie 9380
MakeDefEntry( "PROGS_EXTRA",     "=", \@PROGS_EXTRA );
289 dpurdie 9381
MakeDefEntry( "TESTPROGS",       "=", $TESTPROGS->AllTargets());
227 dpurdie 9382
MakeDefEntry( "LINTLIBS",        "=", CreateNameList( 'lib_', '_lint', \@LINTLIBS ));
9383
MakeDefEntry( "LINTSHLIBS",      "=", CreateNameList( 'shlib_', '_lint', \@LINTSHLIBS ));
9384
MakeDefEntry( "LINTPROGS",       "=", CreateNameList( 'prog_', '_lint', \@PROGS ));
289 dpurdie 9385
MakeDefEntry( "LINTPROGS",      "+=", CreateNameList( 'prog_', '_lint', \@TESTPROGS ));
227 dpurdie 9386
MakeDefEntry( "PROJECTS",        "=", CreateNameList( 'Project_', '', ListGeneratedProjects(1) ));
9387
MakeDefEntry( "PROJECTSGEN",     "=", CreateNameList( 'Project_', '', ListGeneratedProjects(0) ));
9388
MakeDefEntry( "PROJECTSCLEAN",   "=", CreateNameList( 'ProjectClean_', '', \%PROJECTS ));
9389
 
261 dpurdie 9390
MakeHeader ("Toolset components");
9391
MakeDefEntry( "USERGENERATED",        "=", \@USERGENERATED )    if ( @USERGENERATED );
9392
MakeDefEntry( "TOOLSETGENERATED",     "=", \@TOOLSETGENERATED ) if ( @TOOLSETGENERATED );
9393
MakeDefEntry( "TOOLSETOBJS",          "=", \@TOOLSETOBJS )      if ( @TOOLSETOBJS );
9394
MakeDefEntry( "TOOLSETLIBS",          "=", \@TOOLSETLIBS )      if ( @TOOLSETLIBS );
9395
MakeDefEntry( "TOOLSETPROGS",         "=", \@TOOLSETPROGS )     if ( @TOOLSETPROGS );
9396
MakeDefEntry( "TOOLSETDIRS",          "=", \@TOOLSETDIRS )      if ( @TOOLSETDIRS );
9397
MakeDefEntry( "TOOLSETDIRTREES",      "=", \@TOOLSETDIRTREES )  if ( @TOOLSETDIRTREES );
227 dpurdie 9398
 
9399
#--------- Determine compiler flag groups to use ----------------------------
9400
#
9401
#   Allows the compiler options to be controlled for both the debug and
9402
#   the production builds. Allows control over
9403
#       1) Optimisations
9404
#       2) Debug Information
9405
#
9406
MakeHeader ("Determine compiler flag groups to use");
9407
 
9408
print MAKEFILE <<EOF;
9409
 
9410
ifneq "\$(DEBUG)" "1"
9411
USE_OPTIMISE	:= \$(PROD_USE_OPTIMISE)
9412
USE_DEBUGINFO	:= \$(PROD_USE_DEBUGINFO)
9413
else
9414
USE_OPTIMISE	:= \$(DEBUG_USE_OPTIMISE)
9415
USE_DEBUGINFO	:= \$(DEBUG_USE_DEBUGINFO)
9416
endif
9417
 
9418
EOF
9419
 
261 dpurdie 9420
#-------------------------------------------------------------------------------
9421
#   Source browsing tools
9422
#
9423
MakeHeader ("Source browsing tools");
9424
    print MAKEFILE <<EOF;
9425
.PHONY:			ctags
9426
ctags:
9427
EOF
9428
    $if->CTAGS()
9429
        if (@CSRCS || @CXXSRCS);
227 dpurdie 9430
 
261 dpurdie 9431
#-------------------------------------------------------------------------------
9432
#   Depend
9433
#   If we are build C or C++ source files then create rules and recipes
9434
#   to invoke a dependency generator.
227 dpurdie 9435
#
261 dpurdie 9436
#   NODEPEND is used to disable, at make-time, the dependency generation
9437
#   and inclusion process.
9438
#
9439
#
9440
MakeHeader ("Depend");
9441
if ($::o && (@CSRCS || @CXXSRCS))
9442
{
9443
    $ScmDependTags = 1;
9444
    print MAKEFILE <<EOF;
9445
depend:			\$(OBJDIR)/depend
9446
 
9447
\$(OBJDIR)/depend:	\$(SCM_MAKEFILE) \$(GBE_OBJDIR)
9448
\$(OBJDIR)/depend:	\$(CSRCS) \$(CXXSRCS)
9449
ifeq (\$(NODEPEND),0)
9450
	\@echo [\$@] Doing a make depend..
9451
	-\$(XX_PRE)\$(rm) -f \$(OBJDIR)/depend
9452
EOF
9453
    $if->CCDepend( "\$(OBJDIR)/depend", "\$(CSRCS)" )
9454
        if ( @CSRCS );
9455
    $if->CXXDepend( "\$(OBJDIR)/depend", "\$(CXXSRCS)" )
9456
        if ( @CXXSRCS );
9457
    MakePrint
9458
        "\t-\@\$(touch) -f \$(OBJDIR)/depend\n";
9459
    print MAKEFILE <<EOF;
9460
else
9461
	\@echo [\$@] Skipping make depend..
9462
	-\$(XX_PRE)\$(rm) -f \$(OBJDIR)/depend
9463
endif
9464
EOF
9465
}
9466
else
9467
{
9468
    print MAKEFILE <<EOF;
9469
depend:
9470
EOF
9471
}
9472
 
9473
#
9474
#   Rule to unmake the depend file
2312 dpurdie 9475
#       No longer neeed.
9476
#       The file is deleted as a part of the OBJDIR cleanup
261 dpurdie 9477
#
9478
    print MAKEFILE <<EOF;
9479
 
9480
undepend:
9481
EOF
9482
 
9483
#--------- IFLAG Documentation -------------------------------------------------
9484
#
9485
#   IFLAG - iteration flag. This is setting by the calling process
9486
#                           and is a function of the phase being processed
227 dpurdie 9487
#       0   No external dependencies.
9488
#       1   Source dependency list.
261 dpurdie 9489
#       2   Shared library dependency list
9490
#       3   Application dependency list
227 dpurdie 9491
#
9492
#
261 dpurdie 9493
#--------- Dependencies --------------------------------------------------------
9494
#   Include the 'depend' file if required
9495
#
9496
    MakeHeader ("Dependency Inclusion");
9497
    print MAKEFILE <<EOF;
9498
ifeq (\$(NODEPEND),0)
9499
 ifdef IFLAG
9500
  ifneq "\$(IFLAG)" "0"
9501
-include	\$(OBJDIR)/depend
9502
  endif
227 dpurdie 9503
 endif
9504
endif
9505
 
9506
EOF
9507
 
9508
#-------------------------------------------------------------------------------
9509
#   Standard rules
9510
#
9511
MakeHeader ("Standard rules");
9512
 
373 dpurdie 9513
print MAKEFILE <<EOF;
227 dpurdie 9514
 
373 dpurdie 9515
.PHONY:		make_clean
227 dpurdie 9516
make_clean:
9517
	-\@echo "Removing generated files (objects, libraries, binaries etc)";
9518
 
9519
.PHONY:		rmlitter
9520
rmlitter:
2312 dpurdie 9521
	-\$(AA_PRE)JatsFileUtil 'D0' 'Removing litter' '.' 'core' '*.bak' '*.tmp' '*.err'
227 dpurdie 9522
 
261 dpurdie 9523
.PHONY:		lint_init
9524
lint_init:
9525
 
227 dpurdie 9526
EOF
9527
 
261 dpurdie 9528
#
9529
#   Dependencies for 'make_init'
9530
#
9531
#
9532
my @initdep;
9533
push @initdep, '$(INITS)' if ( @INITS );
227 dpurdie 9534
 
261 dpurdie 9535
#
9536
#   Dependencies for 'make_dir'
9537
#
9538
my @mkdirdep;
289 dpurdie 9539
push @mkdirdep, '$(GBE_OBJDIR)' if ( @CSRCS || @CXXSRCS || @OBJS || @PROGOBJS || @TESTPROGOBJS );
261 dpurdie 9540
push @mkdirdep, '$(SHDIRS)'     if ( %SHOBJ_LIB || @SHLIBS);
9541
push @mkdirdep, '$(GBE_LIBDIR)' if ( @LIBS || @MLIBS || @SHLIBS || %INSTALL_LIBS || %PACKAGE_LIBS );
289 dpurdie 9542
push @mkdirdep, '$(GBE_BINDIR)' if ( @SHLIBS || %SCRIPTS || @PROGS || @TESTPROGS || %INSTALL_PROGS || %PACKAGE_PROGS );
227 dpurdie 9543
 
261 dpurdie 9544
#
9545
#   Actions for for 'unobj'
9546
#
9547
my @unobjact;
9548
push @unobjact, RmFilesCmd( 'OBJS' )            if ( @OBJS );
9549
push @unobjact, RmFilesCmd( 'SHOBJS' )          if ( %SHOBJ_LIB );
9550
push @unobjact, RmFilesCmd( 'PROGOBJS' )        if ( @PROGOBJS );
289 dpurdie 9551
push @unobjact, RmFilesCmd( 'TESTPROGOBJS' )    if ( @TESTPROGOBJS );
261 dpurdie 9552
push @unobjact, RmFilesCmd( 'TOOLSETOBJS' )     if ( @TOOLSETOBJS );
227 dpurdie 9553
 
261 dpurdie 9554
#
9555
#   Dependencies for 'make_lib'
9556
#
9557
my @libdep;
9558
push @libdep, '$(GBE_OBJDIR)', '$(GBE_LIBDIR)', '$(LIBS)' if ( @LIBS );
227 dpurdie 9559
 
261 dpurdie 9560
#
9561
#   Dependencies for 'lint_lib'
9562
#
9563
my @liblintdep;
9564
push @liblintdep, 'lint_init', '$(GBE_OBJDIR)', '$(GBE_LIBDIR)', '$(LINTLIBS)' if ( @LIBS );
227 dpurdie 9565
 
261 dpurdie 9566
#
9567
#   Dependencies for 'make_mlib'
9568
#
9569
my @mlibdep;
9570
push @mlibdep, '$(GBE_OBJDIR)', '$(GBE_LIBDIR)', '$(GBE_MLIBDIR)', '$(MLIBS)' if ( @MLIBS );
227 dpurdie 9571
 
261 dpurdie 9572
#
9573
#   Dependencies for 'make_install_shlib' (tag)
9574
#
9575
my @shlibdep;
9576
push @shlibdep, '$(SHDIRS)', '$(SHLIBS)' if ( @SHLIBS );
227 dpurdie 9577
 
261 dpurdie 9578
#
9579
#   Dependencies for 'lint_shlib'
9580
#
9581
my @shliblintdep;
9582
push @shliblintdep, 'lint_init', '$(GBE_LIBDIR)', '$(LINTSHLIBS)' if ( @SHLIBS );
227 dpurdie 9583
 
261 dpurdie 9584
#
9585
#   Actions for 'unmake_lib'
9586
#
9587
my @unlibact;
9588
push @unlibact, RmFilesCmd( 'SHLIBS' )      if ( @SHLIBS );
9589
push @unlibact, RmFilesCmd( 'MLIBS' )       if ( @MLIBS );
9590
push @unlibact, RmFilesCmd( 'LIBS' )        if ( @LIBS );
9591
push @unlibact, RmFilesCmd( 'TOOLSETLIBS' ) if ( @TOOLSETLIBS );
227 dpurdie 9592
 
261 dpurdie 9593
#
9594
#   Actions for 'unmake_mlib'
9595
#
9596
my @unmlibact;
9597
push @unmlibact, RmFilesCmd( 'MLIBS' ) if ( @MLIBS );
227 dpurdie 9598
 
261 dpurdie 9599
#
9600
#   Dependencies for 'make_script'
9601
#
9602
my @scriptdep;
9603
push @scriptdep, '$(GBE_BINDIR)', '$(SCRIPTS)' if ( %SCRIPTS );
227 dpurdie 9604
 
261 dpurdie 9605
#
9606
#   Actions for 'unmake_script'
9607
#
9608
my @unscriptact;
9609
push @unscriptact , RmFilesCmd( 'SCRIPTS' ) if ( %SCRIPTS );
9610
push @unscriptact , RmFilesCmd( 'COPYIN' )  if ( @COPYIN );
227 dpurdie 9611
 
261 dpurdie 9612
#
9613
#   Dependencies for 'make_prog'
9614
#
9615
my @progdep;
9616
push @progdep, '$(GBE_OBJDIR)', '$(GBE_BINDIR)', '$(PROGS)' if ( @PROGS );
9617
push @progdep, '$(PROGS_EXTRA)' if (@PROGS_EXTRA);
227 dpurdie 9618
 
261 dpurdie 9619
#
9620
#   Dependencies for 'make_prog' created for 'projects'
9621
#
9622
my @projectdep;
9623
push @projectdep, '$(PROJECTS)' if (ListGeneratedProjects(1) );
227 dpurdie 9624
 
261 dpurdie 9625
#
9626
#   Dependencies for 'generate' created for 'projects'
9627
#
9628
my @projectgendep;
9629
push @projectgendep, '$(PROJECTSGEN)' if (ListGeneratedProjects(0) );
227 dpurdie 9630
 
261 dpurdie 9631
#
9632
#   Dependencies for 'unmake_prog' created for 'projects'
9633
#
9634
my @projectcleandep;
9635
push @projectcleandep, '$(PROJECTSCLEAN)' if (%PROJECTS);
227 dpurdie 9636
 
261 dpurdie 9637
#
9638
#   Dependencies for 'lint_prog'
9639
#
9640
my @proglintdep;
289 dpurdie 9641
push @proglintdep, 'lint_init', '$(GBE_OBJDIR)', '$(GBE_BINDIR)', '$(LINTPROGS)' if ( @PROGS || @TESTPROGS );
227 dpurdie 9642
 
261 dpurdie 9643
#
9644
#   Actions for 'unmake_prog'
9645
#
9646
my @unprogact;
9647
push @unprogact, RmFilesCmd( 'PROGS' )        if ( @PROGS );
9648
push @unprogact, RmFilesCmd( 'TOOLSETPROGS' ) if ( @TOOLSETPROGS );
227 dpurdie 9649
 
261 dpurdie 9650
#
9651
#   Dependencies for 'lint_prog'
9652
#
9653
my @testprogdep;
289 dpurdie 9654
push @testprogdep, '$(GBE_OBJDIR)', '$(GBE_BINDIR)', '$(TESTPROGS)' if ( @TESTPROGS );
227 dpurdie 9655
 
9656
#
261 dpurdie 9657
#   Dependencies for 'run_tests' and friends
9658
#
9659
my @untestprogact;
289 dpurdie 9660
push @untestprogact ,RmFilesCmd( 'TESTPROGS' ) if ( @TESTPROGS );
227 dpurdie 9661
 
261 dpurdie 9662
#
9663
#   Dependencies for 'generated'
9664
#
9665
my @generatedep;
9666
push @generatedep, '$(GENERATED)' if ( @GENERATED );
9667
 
9668
#
9669
#   Actions for 'ungenerate'
9670
#
9671
my @ungenact;
9672
push @ungenact, RmFilesCmd( 'GENERATED' ) if ( @GENERATED );
9673
push @ungenact, RmFilesCmd( 'GENERATED_NOTSRC' ) if ( @GENERATED_NOTSRC );
9674
push @ungenact, RmFilesCmd( 'TOOLSETGENERATED' ) if ( @TOOLSETGENERATED );
9675
push @ungenact, RmFilesCmd( 'USERGENERATED' ) if ( @USERGENERATED );
9676
 
9677
#
9678
#   Dependencies for 'ungenerate'
9679
#
9680
my @ungeneratedep;
9681
push @ungeneratedep, '$(GENERATEDCLEAN)';
9682
 
227 dpurdie 9683
#-------------------------------------------------------------------------------
261 dpurdie 9684
# Function        : PrintPhonyRule
227 dpurdie 9685
#
261 dpurdie 9686
# Description     : Helper function to print some internal phony makefile targets
9687
#                   These are used to hold the basic makefile together
9688
#
9689
# Inputs          : $target         - Name of the phony target
9690
#                   $prereq         - Prerequisites
9691
#                                     Leading spaces removed
9692
#                   $recipe         - Optional Reference to an array of recipes
9693
#                                     Will be printed one per line
9694
#
9695
#
9696
sub PrintPhonyRule
227 dpurdie 9697
{
261 dpurdie 9698
    my ($target, $prereq, $recipe) = @_;
9699
    $prereq =~ s/^\s+//;
227 dpurdie 9700
 
261 dpurdie 9701
    MakePadded( 2, '.PHONY:', $target, "\n");
9702
    MakePadded( 2,"$target:", $prereq, "\n");
9703
    MakePrint ("\t\t" . $_ . "\n") foreach ( @{$recipe} );
9704
    MakePrint ("\n");
227 dpurdie 9705
}
9706
 
261 dpurdie 9707
#   make_init - Test toolset presence and sanity
9708
#   Will only be called ONCE for each platform in a recursive build
9709
#   Should be used to ensure that the required toolset is present
9710
#
9711
PrintPhonyRule ('make_init',       "@initdep" );
227 dpurdie 9712
 
261 dpurdie 9713
#   make_dir    - Create required subdirectories
9714
#   Will be invoked as a part of most targets that create files
9715
#   Will be invoked by the calling wrappers
9716
#   Should not be invoked when cleaning
9717
#
9718
PrintPhonyRule ('make_dir',       "@mkdirdep" );
9719
 
9720
 
9721
PrintPhonyRule ('generate',       "@generatedep @projectgendep" );
9722
PrintPhonyRule ('ungenerate',     "@ungeneratedep",  \@ungenact);
9723
PrintPhonyRule ('unobj',          "",  \@unobjact);
9724
PrintPhonyRule ('make_lib',       "@libdep" );
9725
PrintPhonyRule ('lint_lib',       "@liblintdep" );
9726
PrintPhonyRule ('make_mlib',      "@mlibdep" );
9727
PrintPhonyRule ('lint_shlib',     "@shliblintdep" );
9728
PrintPhonyRule ('unmake_lib',     "", \@unlibact );
9729
PrintPhonyRule ('unmake_mlib',    "", \@unmlibact );
9730
PrintPhonyRule ('make_script',    "@scriptdep" );
9731
PrintPhonyRule ('unmake_script',  "", \@unscriptact );
9732
PrintPhonyRule ('make_prog',      "@scriptdep @progdep @projectdep" );
9733
PrintPhonyRule ('lint_prog',      "@proglintdep" );
9734
PrintPhonyRule ('run_tests',      "@scriptdep @testprogdep" );
9735
PrintPhonyRule ('run_unit_tests', "@scriptdep @testprogdep" );
9736
PrintPhonyRule ('unmake_prog',    "unmake_script @projectcleandep", \@unprogact );
9737
PrintPhonyRule ('make_test',      "@scriptdep @testprogdep" );
9738
PrintPhonyRule ('unmake_test',    "unmake_script", \@untestprogact );
9739
 
227 dpurdie 9740
#-------------------------------------------------------------------------------
9741
#   Package and Installation Summary
9742
#
9743
    MakeHeader ("Package and Installation Summary");
9744
    sub InstallTarget
9745
    {
9746
        my( $target, $hashp, $prereq, $fprereq ) = @_;
9747
        my( $element );
9748
 
343 dpurdie 9749
        MakePrint ".PHONY:\t\t"."$target\n";
227 dpurdie 9750
        MakePrint "$target:";
9751
        MakePrint "\t$fprereq" if ($fprereq);
9752
 
9753
        foreach my $element ( sort keys %{$hashp} )
9754
        {
9755
            #
9756
            #   Skip placekeepers
9757
            #
9758
            next if ( $hashp->{$element}{'placekeeper'} );
9759
 
9760
            #
9761
            #   Prepend any prerequisites (once)
9762
            #
9763
            if ( $prereq )
9764
            {
9765
                MakePrint " \\\n\t${prereq}";
9766
                $prereq = 0;
9767
            }
9768
 
9769
            MakePrint " \\\n\t${element}";
9770
        }
9771
        MakePrint "\n\n";
9772
    }
9773
 
9774
InstallTarget( "install_hdr",       \%INSTALL_HDRS );
9775
InstallTarget( "install_lib",       \%INSTALL_LIBS,  'make_mlib' );
261 dpurdie 9776
InstallTarget( "make_install_shlib",\%INSTALL_SHLIBS, '', "@shlibdep" );
227 dpurdie 9777
InstallTarget( "install_prog",      \%INSTALL_PROGS, 'make_script' );
9778
InstallTarget( "install_class",     \%INSTALL_CLSS );
9779
 
9780
InstallTarget( "package_files",     \%PACKAGE_FILES );
9781
InstallTarget( "package_hdr",       \%PACKAGE_HDRS );
9782
InstallTarget( "package_lib",       \%PACKAGE_LIBS );
9783
InstallTarget( "package_shlib",     \%PACKAGE_SHLIBS );
9784
InstallTarget( "package_prog",      \%PACKAGE_PROGS, 'make_script' );
9785
InstallTarget( "package_class",     \%PACKAGE_CLSS );
9786
 
9787
#-------------------------------------------------------------------------------
9788
#   Installations
9789
 
9790
MakeHeader ("Installations");
9791
PackageRule ( \&InstallCmd, \%INSTALL_HDRS  );
9792
PackageRule ( \&InstallCmd, \%INSTALL_CLSS  );
9793
PackageRule ( \&InstallCmd, \%INSTALL_LIBS  );
9794
PackageRule ( \&InstallCmd, \%INSTALL_SHLIBS  );
9795
PackageRule ( \&InstallCmd, \%INSTALL_PROGS  );
9796
 
9797
 
9798
#-------------------------------------------------------------------------------
9799
#   Packaging
9800
#
9801
MakeHeader ("Packaging");
9802
PackageRule ( \&PackageCmd, \%PACKAGE_FILES );
9803
PackageRule ( \&PackageCmd, \%PACKAGE_HDRS );
9804
PackageRule ( \&PackageCmd, \%PACKAGE_CLSS );
9805
PackageRule ( \&PackageCmd, \%PACKAGE_LIBS );
9806
PackageRule ( \&PackageCmd, \%PACKAGE_SHLIBS );
9807
PackageRule ( \&PackageCmd, \%PACKAGE_PROGS );
9808
 
9809
#-------------------------------------------------------------------------------
9810
#   Uninstall/unpackaging
9811
#
9812
MakeHeader ("Uninstall/unpackaging");
9813
 
9814
UnpackageRule( "uninstall_hdr",         \&UninstallCmd, \%INSTALL_HDRS );
9815
UnpackageRule( "uninstall_lib",         \&UninstallCmd, \%INSTALL_LIBS );
9816
UnpackageRule( "uninstall_shlib",       \&UninstallCmd, \%INSTALL_SHLIBS );
9817
UnpackageRule( "uninstall_prog",        \&UninstallCmd, \%INSTALL_PROGS );
9818
UnpackageRule( "uninstall_class",       \&UninstallCmd, \%INSTALL_CLSS );
9819
 
9820
UnpackageRule( "unpackage_files",       \&UnpackageCmd, \%PACKAGE_FILES );
9821
UnpackageRule( "unpackage_hdr",         \&UnpackageCmd, \%PACKAGE_HDRS );
9822
UnpackageRule( "unpackage_lib",         \&UnpackageCmd, \%PACKAGE_LIBS );
9823
UnpackageRule( "unpackage_shlib",       \&UnpackageCmd, \%PACKAGE_SHLIBS );
9824
UnpackageRule( "unpackage_prog",        \&UnpackageCmd, \%PACKAGE_PROGS );
9825
UnpackageRule( "unpackage_class",       \&UnpackageCmd, \%PACKAGE_CLSS );
9826
 
261 dpurdie 9827
#-------------------------------------------------------------------------------
267 dpurdie 9828
#   Distribution Sets
261 dpurdie 9829
#
267 dpurdie 9830
MakeHeader ("Distribution Sets");
9831
PackageSetRules();
9832
 
9833
#-------------------------------------------------------------------------------
9834
#
261 dpurdie 9835
#   Subdir deletion
9836
#   This is done AFTER the toolset functions have been invoked to create the
9837
#   build artifacts so that the toolsets can create directories too
9838
#
9839
#   Note: Toolset directories are deleted first
9840
#   Note: User Directories are deleted in the reverse order of creation
9841
#
2312 dpurdie 9842
#   Add them into the directory data structure
9843
#
9844
    foreach my $path ( @TOOLSETDIRS )
9845
    {
9846
        MkdirRule( $path, '', '--NoCreate' );
9847
    }
9848
 
9849
    foreach my $path ( @TOOLSETDIRTREES )
9850
    {
9851
        MkdirRule( $path, '', '--NoCreate' , '--RemoveAll');
9852
    }
9853
 
261 dpurdie 9854
    MakeHeader ("Subdir deletion");
9855
    RmdirRules();
9856
    MakeNewLine();
227 dpurdie 9857
 
261 dpurdie 9858
#--------- Toolset Rules -------------------------------------------------------
9859
    MakeHeader ("Toolset Rules");
9860
    MakePrintList ( \@TOOLSETRULES );
9861
 
9862
#--------- Maketags ------------------------------------------------------------
227 dpurdie 9863
 
9864
    Maketag( "make_init",           @INITS );
261 dpurdie 9865
    Maketag( "make_dir",            @mkdirdep );
9866
    Maketag( "generate",            @generatedep || @projectgendep || @USERGENERATED || ($ScmToolsetGenerate != 0) );
227 dpurdie 9867
    Maketag( "depend",              $ScmDependTags != 0 );
261 dpurdie 9868
    Maketag( "make_lib",            @libdep );
9869
    Maketag( "make_mlib",           @mlibdep );
9870
    Maketag( "make_install_shlib",  %INSTALL_SHLIBS || @shlibdep);
9871
    Maketag( "make_script",         @scriptdep );
9872
    Maketag( "make_prog",           @progdep || @projectdep );
9873
    Maketag( "make_test",           @testprogdep );
263 dpurdie 9874
    Maketag( "run_tests",           @TESTS_TO_RUN || @TESTPROJECT_TO_URUN || $TESTS_TO_RUN);
227 dpurdie 9875
    Maketag( "run_unit_tests",      $TESTS_TO_AUTORUN || @TESTPROJECT_TO_ARUN);
9876
    Maketag( "install_hdr",         %INSTALL_HDRS );
9877
    Maketag( "install_class",       %INSTALL_CLSS );
9878
    Maketag( "install_lib",         %INSTALL_LIBS );
9879
    Maketag( "install_prog",        %INSTALL_PROGS );
9880
    Maketag( "deploy",              %DEPLOYPACKAGE );
9881
    Maketag( "package",             %PACKAGE_FILES || %PACKAGE_HDRS || %PACKAGE_CLSS ||
9882
                                    %PACKAGE_LIBS || %PACKAGE_SHLIBS || %PACKAGE_PROGS );
9883
 
261 dpurdie 9884
    #
9885
    #   Display tags in the MAKEFILE
9886
    #   Not used here - just for show
9887
    #
9888
    MakeHeader ("Maketags");
9889
    foreach my $tag ( sort keys %MakeTags )
9890
    {
9891
        MakePadded( 2, "#   $tag:", defined ($MakeTags{$tag}) ? 1 : 0, "\n");
9892
    }
9893
 
227 dpurdie 9894
#-------------------------------------------------------------------------------
9895
#   End of Makefile
9896
#
9897
    MakeHeader ("End of Makefile");
9898
    close( MAKEFILE );
9899
 
9900
#
9901
#   Save all platform information
9902
#   Done after the makefile is written as toolsets can extend the data
9903
#
9904
    WriteParsedConfig();
9905
 
9906
#
9907
#   Write out any accumulated DPACKAGE data
9908
#
9909
    JatsDPackage::DPackageSave();
9910
 
9911
    return 0;
9912
}
9913
 
9914
#-------------------------------------------------------------------------------
387 dpurdie 9915
# Function        : QuoteForMake
9916
#
9917
# Description     : Escape/Quote a pathname for make
9918
#                       Allow files with a $ in the name
9919
#                       Allow files with a space in the name
9920
#                       Allow files with a comma in the name
9921
#                       Allow for paths that have make-varible prefixes
9922
#                           $(GBE_...)/
9923
#                           as these may be generated internally
9924
#
392 dpurdie 9925
#                       Must also allow $(GBE_TYPE) in the remainder
9926
#
387 dpurdie 9927
# Inputs          : uarg                - Arg to quote
9928
#
9929
# Returns         : Quoted arg
9930
#
9931
 
9932
sub QuoteForMake()
9933
{
9934
    my ($uarg) = @_;
9935
 
9936
    #
9937
    #   Split into two
9938
    #       $(xxx)/             - Makefile variables
9939
    #       Remainder           - Stuff to quote
9940
    #
9941
    $uarg =~ m~^((\$\(.*?\)/)*)(.*)~;
9942
    my $prefix = defined $1 ? $1 : '';
9943
    my $arg    = defined $3 ? $3 : '';
9944
 
392 dpurdie 9945
    $arg =~ s~\$(?!\(GBE_)~\$\$~g;       # $, not followed by (GBE_ - id not $(GBE_
387 dpurdie 9946
    $arg =~ s~ ~\\ ~g;
9947
    $arg =~ s~,~\$(comma)~g;
2650 dpurdie 9948
    $arg =~ s~%~\\%~g;
387 dpurdie 9949
    return $prefix . $arg;
9950
}
9951
 
9952
 
9953
#-------------------------------------------------------------------------------
227 dpurdie 9954
# Function        : Maketag
9955
#
9956
# Description     : Create Makefile tags to speed up recursive makes
9957
#
9958
# Inputs          : tag_name
9959
#                   dep
9960
#
9961
# Returns         : 
9962
#
9963
sub Maketag
9964
{
9965
    my( $tag, $dep ) = @_;
9966
    $MakeTags{$tag} = 1 if ( defined($dep) && $dep );
9967
}
9968
 
9969
#-------------------------------------------------------------------------------
9970
#   Function to create and delete directories within the build system
9971
#
9972
#    To stop make regenerating directory dependent targets each time the
9973
#    directory content is modified, rule should only be dependent on a internally
9974
#    created alias file 'gbedir', which represents the time a dir was created not
9975
#    last modified.
9976
#
9977
#    Must use tags like GBE_BINDIR, GBE_LIBDIR and GBE_OBJDIR to ensure that the
9978
#    directories are created correctly.
9979
#
9980
my %MkdirRuleData;
9981
my @MkdirRuleOrder;
9982
my $MkdirRulePrinting = 0;
9983
my $MkdirRuleGbeFile = ( $::ScmHost eq "Unix" ) ? ".gbedir" : "_gbedir";
9984
 
9985
#-------------------------------------------------------------------------------
9986
# Function        : MkdirRule
9987
#
9988
# Description     : Create Rules and Recipes to create a directory at make-time
9989
#                   Mark the information for such that the directories will
9990
#                   be deleted in a 'clean'
9991
#
9992
#                   Can be called before we start writing the makefile
9993
#                   Such entries will be retained and dumped at a known time
9994
#
9995
# Inputs          : $subdir     - Symbolic name of the subdir $(OBJDIR)
9996
#                   $alias      - Optional script alias for the dir 'OBJDIR' --> GBE_OBJDIR
9997
#                   Options:
2312 dpurdie 9998
#                       --Path=path             Optional value of $subdir '$(GBE_PLATFORM)$(GBE_TYPE).OBJ'
9999
#                       --RemoveAll             Remove all files on clean
10000
#                       --Extra=file[,file]     Additiona files to remove
10001
#                       --NoCreate              Do not Create the Directory, just delete it
227 dpurdie 10002
#
10003
# Returns         : Nothing
10004
#
10005
 
10006
sub MkdirRule
10007
{
10008
    my( $subdir, $alias, @opts ) = @_;
10009
 
10010
    #
10011
    #   Create data entry once
10012
    #
10013
    $alias =~ s~^GBE_~~ if $alias;
10014
    unless ( $MkdirRuleData{$subdir}  )
10015
    {
10016
        my %data;
10017
 
10018
        #
10019
        #   Parse options
10020
        #
10021
        foreach ( @opts )
10022
        {
10023
            if ( /^--Path=(.+)/ ) {
10024
                $data{path} = $1;
10025
            } elsif ( /^--RemoveAll/ ) {
10026
                $data{remove_all} = 1;
2312 dpurdie 10027
            } elsif ( /^--NoCreate/ ) {
10028
                $data{noCreate} = 1;
10029
            } elsif ( /^--Extra=(.+)/ ) {
10030
                @{$data{extraFiles}} = split(/,/, $1);
227 dpurdie 10031
            } else {
10032
                Error ("MkdirRule: Unknown option: $_");
10033
            }
10034
        }
10035
        $data{alias} = $alias if ( $alias );
10036
 
10037
        $MkdirRuleData{$subdir} = \%data;
10038
        push @MkdirRuleOrder, $subdir;
10039
    }
10040
 
10041
    #
10042
    #   Save or print
10043
    #
10044
    return unless ( $MkdirRulePrinting );
2312 dpurdie 10045
    return if ( $MkdirRuleData{$subdir}{noCreate} );
227 dpurdie 10046
 
10047
    #
10048
    #   Create a definition of the physical directory
10049
    #
10050
    my $path = $MkdirRuleData{$subdir}{path};
261 dpurdie 10051
    MakePadded (2, $alias, ":= $path\n") if ( $path && $alias );
227 dpurdie 10052
 
10053
    #   Create an alias to be used within rules
10054
    #   The defined aliase will be prefixed with 'GBE_'
10055
    #
261 dpurdie 10056
    MakePadded (2, "GBE_$alias", ":= $subdir/$MkdirRuleGbeFile\n") if ( $alias );
227 dpurdie 10057
 
10058
    #
10059
    #   Create a recipe to create the directory
10060
    #   This is not as simple as it sounds
10061
    #   The touch is required.
10062
    #       Had 'timestamp' issues on solaris'. The 'echo' did not appear
10063
    #       to be enough. Perhaps the output was not flushed
10064
    #
261 dpurdie 10065
    MakePadded (2, "$subdir", ": $subdir/$MkdirRuleGbeFile\n");
227 dpurdie 10066
    MakePrint
10067
        "$subdir/$MkdirRuleGbeFile:\n".
10068
        "\t\$(XX_PRE)if [ ! -d $subdir ]; then \$(mkdir) -p $subdir; fi; \\\n".
10069
        "\t\$(echo) '# DO NOT REMOVE.' > \$@; \\\n".
10070
        "\t\$(touch) \$@\n\n";
10071
}
10072
 
10073
#-------------------------------------------------------------------------------
10074
# Function        : RmdirRules
10075
#
2312 dpurdie 10076
# Description     : Create the body of a recipe to delete the directories that
227 dpurdie 10077
#                   have been created.
10078
#
2312 dpurdie 10079
#                   Use JatsFileUtil rather than shell script
10080
#                       Faster under windows (and others)
10081
#                       Solved long pathname issues
10082
#                       Simpler to use and control
227 dpurdie 10083
#
10084
# Inputs          : Uses $MkdirRuleData
10085
#
10086
# Returns         : Nothing.
10087
#                   Prints to the makefile
10088
#
10089
sub RmdirRules
10090
{
2312 dpurdie 10091
    MakePrint( ".PHONY:\tunmake_dir\n" );
10092
    MakePrint( "unmake_dir:\n" );
10093
 
227 dpurdie 10094
    #
10095
    #   Determine the list of directories to delete
2312 dpurdie 10096
    #   Sort such that subdirs are deleted first
227 dpurdie 10097
    #
2312 dpurdie 10098
    my $txt = 'Removing directories';
227 dpurdie 10099
    foreach my $subdir ( reverse sort keys %MkdirRuleData )
10100
    {
2312 dpurdie 10101
        my @args = $subdir;
10102
 
10103
        push (@args, $MkdirRuleGbeFile, 'core', '*.bak', '*.tmp', '*.err')
10104
            unless $MkdirRuleData{$subdir}{remove_all};
10105
 
10106
        push (@args, @{$MkdirRuleData{$subdir}{extraFiles}})
10107
            if ( $MkdirRuleData{$subdir}{extraFiles} );
10108
 
10109
        my $mode = $MkdirRuleData{$subdir}{remove_all} ? 'T0' : 'D0';
10110
 
10111
        MakePrint ("\t-\$(AA_PRE)JatsFileUtil ", QuoteArray( $mode, $txt, @args ), "\n");
10112
        $txt = '';
227 dpurdie 10113
    }
10114
}
10115
 
10116
#-------------------------------------------------------------------------------
10117
# Function        : CreateMkdirRules
10118
#
10119
# Description     : Create Rules to make dirs at runtime
10120
#                   This function is called to instantiate those entries
10121
#                   That have been requested before the makefile has has
10122
#                   started to be created.
10123
#
10124
#                   Once this function has been called all new MkdirRule calls
10125
#                   will result in the recipes being created in-line.
10126
#
10127
# Inputs          : Nothing
10128
#
10129
# Returns         : Even Less
10130
#
10131
#
10132
sub CreateMkdirRules
10133
{
10134
    $MkdirRulePrinting = 1;
10135
    foreach my $subdir ( @MkdirRuleOrder )
10136
    {
10137
        my $data = $MkdirRuleData{$subdir};
10138
        MkdirRule($subdir, $data->{alias}, $data->{path} );
10139
    }
10140
}
10141
 
10142
#-------------------------------------------------------------------------------
10143
# Function        : PackageRule
10144
#
10145
# Description     : Generate rules and recipes to "install" and "package" files
10146
#
10147
# Inputs          : codecmd     - A code reference to the actual installer routine
10148
#                   hashp       - A reference to a INSTALL or PACKAGE hash
10149
#
299 dpurdie 10150
#                   hashp is a reference to a hash
227 dpurdie 10151
#                       The key is the full path of the install target
10152
#                       The value is (another) hash that describes the install options
10153
#
10154
#                   Valid keys are:
10155
#                       src                 - Path of the source file [Mandatory]
10156
#                       dir                 - Target directory [Mandatory]
10157
#
10158
#                       defined             - Copy the file only if value is defined
10159
#                       exe                 - Mark the file as executable
10160
#                       Mode                - File modes. Default is -w
10161
#                       placekeeper         - Marks SHARED library placekeepers
10162
#                       set                 - Distribution sets
10163
#                       type                - Copy the file in DEBUG or PROD mode
10164
#                                             Valid values are "D" or "P"         
10165
#                       version             - Shared library version information
10166
#                       RemoveOnly          - Do not install the file. Entries are
10167
#                                             created to allow the removal of the file
10168
#
10169
# Returns         :
10170
#
10171
sub PackageRule
10172
{
10173
    my ($codecmd, $hashp) = @_;
10174
 
10175
    foreach my $dest ( keys %{$hashp} )
10176
    {
10177
 
10178
        my $entry = $hashp->{$dest};
10179
 
10180
        #
10181
        #   Skip placekeepers
10182
        #
10183
        next if ( $entry->{'placekeeper'} );
10184
 
10185
        #
10186
        #   Some entries are not installed via this mechanism, but can be removed
10187
        #   if they exist. Mark these as PHONY to keep targets happy
10188
        #
10189
        if ( $entry->{'RemoveOnly'} )
10190
        {
10191
            MakePrint ".PHONY:\t$dest\n";
10192
            MakePrint "$dest:\n\n";
10193
            next;
10194
        }
10195
 
10196
        my $fname = $entry->{'src'};
10197
        my $fmode = $entry->{'Mode'};
10198
        $fmode .= "+x" if ( $entry->{'exe'}  );
10199
 
10200
        #
10201
        #   User conditionional
10202
        #   Mark both the source and the target as PHONY if the condition is not met
10203
        #   This will ensure that the target need not be built.
10204
        #
10205
        my $udef = $entry->{'defined'};
10206
        if ( $udef )
10207
        {
10208
            MakePrint "ifndef $udef \n";
10209
            MakePrint ".PHONY:\t\t$dest\n";
10210
            MakePrint ".PHONY:\t\t$fname\n";
10211
            MakePrint "$dest:\n";
10212
            MakePrint "else\n"
10213
        }
10214
 
10215
        #
10216
        #   Conditional installation for DEBUG/PRODUCTION
10217
        #
10218
        my $type = $entry->{'type'};
10219
        if ( $type )
10220
        {
10221
            if ( $type eq "D" ) {
10222
                MakePrint 'ifeq "$(DEBUG)" "0"'."\n";
10223
            } elsif ( $type eq "P" ) {
10224
                MakePrint 'ifneq "$(DEBUG)" "0"'."\n";
10225
            } else {
10226
                Error("INTERNAL: Unexpected packaging type: $type");
10227
            }
10228
            MakePrint ".PHONY:\t\t$dest\n";
10229
            MakePrint "$dest:\n";
10230
            MakePrint "else\n"
10231
        }
10232
 
10233
        #
10234
        #   The body of the copy
10235
        #
10236
        MakePadded( 4, "$dest:" );
10237
        MakePrint "\t$fname\n";
2074 dpurdie 10238
        MakePrint $codecmd->( $dest, $fname, $fmode );
227 dpurdie 10239
        MakeNewLine();
10240
 
10241
 
10242
        #
10243
        #   Unwind conditionals
10244
        #
10245
        MakePrint "endif\n" if ( $type );
10246
        MakePrint "endif\n" if ( $udef );
10247
 
10248
        #
10249
        #   Distribution sets
10250
        #
10251
        my $dist = $entry->{'set'};
10252
        if ( $dist )
10253
        {
267 dpurdie 10254
            foreach my $set ( split( ',', $dist ) )
10255
            {
10256
                push @{$PACKAGE_SETS{$set}{LIST}}, $dest;
227 dpurdie 10257
            }
10258
            MakeNewLine();
10259
        }
10260
    }
10261
}
10262
 
10263
#-------------------------------------------------------------------------------
267 dpurdie 10264
# Function        : PackageSetRules
10265
#
10266
# Description     : Generate the packageset rules
10267
#                   These appear to be a now-defuct feature
10268
#
10269
#                   By default all packaged files are a part of package_setALL
10270
#
10271
# Inputs          : None
10272
#                   Takes data from %PACKAGE_SET
10273
#
10274
# Returns         : Nothing
10275
#
10276
sub PackageSetRules
10277
{
10278
    foreach my $set ( sort keys %PACKAGE_SETS )
10279
    {
10280
        my $me = MakeEntry::New( *MAKEFILE, "package_set$set", '--Phony' );
10281
        $me->AddDependancy( @{$PACKAGE_SETS{$set}{LIST}} );
10282
        $me->Print();
10283
    }
10284
}
10285
 
10286
#-------------------------------------------------------------------------------
227 dpurdie 10287
# Function        : UnPackageRule
10288
#
10289
# Description     : Generate rules and recipes to "uninstall" and "unpackage" files
10290
#
10291
# Inputs          : target      - Name of the target
10292
#                   codecmd     - A code reference to the actual installer routine
10293
#                   hashp       - A reference to a INSTALL or PACKAGE hash
10294
#
10295
# Returns         :
10296
#
10297
sub UnpackageRule
10298
{
10299
    my ($target, $codecmd, $hashp) = @_;
10300
 
10301
    MakePrint ".PHONY:\t\t"."$target\n";
10302
    MakePrint "$target:\t";
10303
 
10304
    foreach my $dest ( sort keys %{$hashp} )
10305
    {
10306
 
10307
        my $entry = $hashp->{$dest};
10308
 
10309
        #
10310
        #   Skip placekeepers
10311
        #
10312
        next if ( $entry->{'placekeeper'} );
10313
 
10314
        MakePrint "\n" . $codecmd->($dest);
10315
    }
10316
    MakePrint "\n\n";
10317
}
10318
 
10319
 
10320
#
10321
#   Internal macro interface, see RULE.STD for definitions:
10322
#
10323
sub RmFilesCmd
10324
{
10325
    my ( $list ) = @_;
261 dpurdie 10326
    return "\$(call RmFiles,$list)";
227 dpurdie 10327
}
10328
 
10329
sub InstallCmd
10330
{
2074 dpurdie 10331
    my( $dest, $file, $fmode ) = @_;
227 dpurdie 10332
 
10333
    $fmode = "-w"                           # default, read-only
10334
        if ( !defined( $fmode ) || $fmode eq "" );
10335
 
2074 dpurdie 10336
    return "\t\$(call InstallFile,$dest,$file,$fmode)";
227 dpurdie 10337
}
10338
 
10339
sub UninstallCmd
10340
{
10341
    my( $file ) = @_;
10342
 
10343
    return "\t\$(call UninstallFile,$file)";
10344
}
10345
 
10346
sub PackageCmd
10347
{
2074 dpurdie 10348
    my( $dest, $file, $fmode ) = @_;
227 dpurdie 10349
 
10350
    $fmode = "-w"                           # default, read-only
10351
        if ( !defined( $fmode ) || $fmode eq "" );
10352
 
2074 dpurdie 10353
    return "\t\$(call PackageFile,$dest,$file,$fmode)";
227 dpurdie 10354
}
10355
 
10356
sub UnpackageCmd
10357
{
10358
    my( $file ) = @_;
10359
    return "\t\$(call UnpackageFile,$file)";
10360
}
10361
 
10362
1;
10363