| 227 |
dpurdie |
1 |
# -*- mode: perl; tabs: 8; indent-width: 4; show-tabs: yes; -*-
|
|
|
2 |
# Copyright (C) 1998-2004 ERG Transit Systems, All rights reserved
|
|
|
3 |
#
|
|
|
4 |
# Module name : Makelib.pl
|
|
|
5 |
# Module type : Makefile system
|
|
|
6 |
#
|
|
|
7 |
# Description:
|
|
|
8 |
# This modules builds the primary makefile for each directory,
|
|
|
9 |
# used in conjunction with Makelib.pl2. The produced makefile
|
|
|
10 |
# acts as a frontend to platform builds.
|
|
|
11 |
#
|
|
|
12 |
# Notes:
|
|
|
13 |
#
|
|
|
14 |
# *** DO NOT DETAB ***
|
|
|
15 |
#
|
|
|
16 |
# Beware the use of space v's tab characters within the
|
|
|
17 |
# makefile generation sessions.
|
|
|
18 |
#
|
|
|
19 |
#.........................................................................#
|
|
|
20 |
|
| 255 |
dpurdie |
21 |
require 5.006_001;
|
| 227 |
dpurdie |
22 |
use strict;
|
|
|
23 |
use warnings;
|
|
|
24 |
use JatsEnv;
|
|
|
25 |
use JatsMakeInfo qw(:create);
|
|
|
26 |
|
|
|
27 |
our $MakelibVersion = "2.33"; # makelib.pl version
|
|
|
28 |
|
|
|
29 |
our $Generated = 10; # Generated error code ..
|
|
|
30 |
|
|
|
31 |
our $ScmRoot = "";
|
|
|
32 |
our $ScmSrcDir = "";
|
|
|
33 |
our $ScmMakelib = "";
|
|
|
34 |
our @ScmDepends = ();
|
|
|
35 |
our $ScmForce = 0;
|
|
|
36 |
our $ScmExpert = 0;
|
|
|
37 |
our $ScmAll = 0;
|
|
|
38 |
our $ProjectBase = ""; # Base of the user's project
|
|
|
39 |
our $ScmInterface = "interface";
|
|
|
40 |
|
|
|
41 |
our @SUBDIRS = ();
|
|
|
42 |
our @PLATFORMS = ();
|
|
|
43 |
our %PLATFORMARGS = ();
|
|
|
44 |
our @DEFINES = "";
|
|
|
45 |
our @RULES = ();
|
|
|
46 |
|
|
|
47 |
our %PACKAGE_DIST = ();
|
|
|
48 |
|
|
|
49 |
our $ROOTMAKEFILE = 0;
|
|
|
50 |
our $PLATFORMINCLUDED = 0;
|
|
|
51 |
our @BUILDPLATFORMS = ();
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
#.. Running under 'buildlib.pl' ?
|
|
|
55 |
#
|
|
|
56 |
unless ( $::ScmBuildlib )
|
|
|
57 |
{
|
|
|
58 |
MakeLibInit();
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
sub MakeLibInit
|
|
|
62 |
{
|
|
|
63 |
my ( $argc ); # argument count
|
|
|
64 |
|
|
|
65 |
#.. Test environment
|
|
|
66 |
#
|
|
|
67 |
EnvImport( "GBE_BIN" );
|
|
|
68 |
EnvImport( "GBE_PERL" );
|
|
|
69 |
EnvImport( "GBE_TOOLS" );
|
|
|
70 |
EnvImport( "GBE_CONFIG" );
|
|
|
71 |
EnvImport( "GBE_MACHTYPE" );
|
|
|
72 |
|
|
|
73 |
#.. Common stuff
|
|
|
74 |
#
|
|
|
75 |
require "$::GBE_TOOLS/common.pl";
|
|
|
76 |
|
|
|
77 |
CommonInit( "makelib " );
|
|
|
78 |
Debug( "version: $MakelibVersion" );
|
|
|
79 |
|
|
|
80 |
#.. Parse command line
|
|
|
81 |
# makefile.pl rootdir Makelib.pl [options ...]
|
|
|
82 |
#
|
|
|
83 |
$::ScmRoot = StripDrive( ${ARGV[0]} );
|
|
|
84 |
$::ProjectBase= $::ScmRoot;
|
|
|
85 |
$::ScmMakelib = ${ARGV[1]};
|
|
|
86 |
|
|
|
87 |
Debug( "ARGV: @ARGV" );
|
|
|
88 |
Debug( "Root: $::ScmRoot" );
|
|
|
89 |
Debug( "Makelib: $::ScmMakelib" );
|
|
|
90 |
|
|
|
91 |
$argc = 2;
|
|
|
92 |
while ($_ = $ARGV[ $argc++ ])
|
|
|
93 |
{
|
|
|
94 |
last if ( ! /^-/ ); # end of options
|
|
|
95 |
|
|
|
96 |
Debug( "option: $_" );
|
|
|
97 |
|
|
|
98 |
/^-h$|^-help$|^--help$|^--usage$|^-?$/ && MLUsage();
|
|
|
99 |
|
|
|
100 |
# long arguments
|
|
|
101 |
if (/^--interface=(.*)/) {
|
|
|
102 |
$::ScmInterface = $1;
|
|
|
103 |
Debug( "Interface: $::ScmInterface" );
|
|
|
104 |
next;
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
if (/^--expert(.*)/) {
|
|
|
108 |
if ($1) {
|
|
|
109 |
$::ScmExpert = $1;
|
|
|
110 |
} else {
|
|
|
111 |
$::ScmExpert = 1;
|
|
|
112 |
}
|
|
|
113 |
Debug( "Expert: $::ScmExpert" );
|
|
|
114 |
next;
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
if (/^--all/) {
|
|
|
118 |
$::ScmAll = 1;
|
|
|
119 |
Debug( "All: $::ScmAll" );
|
|
|
120 |
next;
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
last if (/^--$/); # end of arguments
|
|
|
124 |
|
|
|
125 |
if (/^-D(.*)/) {
|
|
|
126 |
if ($1) {
|
|
|
127 |
$::ScmDebug = $1;
|
|
|
128 |
} else {
|
|
|
129 |
$::ScmDebug = $ARGV[0];
|
|
|
130 |
$argc++;
|
|
|
131 |
}
|
|
|
132 |
Debug( "ScmDebug: $::ScmDebug" );
|
|
|
133 |
next;
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
next if (/^-V/ && ($::ScmVerbose = 1));
|
|
|
137 |
|
|
|
138 |
next if (/^-F/ && ($::ScmForce = 1));
|
|
|
139 |
|
|
|
140 |
if (/^-.*/) { # unknown option
|
|
|
141 |
MLUsage( "unknown option '$_'\n\n" );
|
|
|
142 |
}
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
|
|
|
146 |
#.. Get the stuff from the platform definition file
|
|
|
147 |
#
|
|
|
148 |
ConfigLoad();
|
|
|
149 |
|
|
|
150 |
#.. Get the stuff from the package definition file
|
|
|
151 |
#
|
|
|
152 |
require "$::ScmRoot/package.pl"
|
|
|
153 |
if ( -f "$::ScmRoot/package.pl" );
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
# MLUsage ---
|
|
|
157 |
# Makelib command line usage.
|
|
|
158 |
#..
|
|
|
159 |
|
|
|
160 |
sub MLUsage
|
|
|
161 |
{
|
|
|
162 |
my( $msg ) = @_;
|
|
|
163 |
|
|
|
164 |
print "makefile $msg\n\n"
|
|
|
165 |
if ( $msg ne "" );
|
|
|
166 |
|
|
|
167 |
print "Usage: perl makefile.pl <ROOTDIR> <Makelib.pl> [options]\n
|
|
|
168 |
Valid options:
|
|
|
169 |
\t-V Verbose mode.
|
|
|
170 |
\t-D<debug-level> Set the debug level.
|
|
|
171 |
\t except all SCM support files are removed (eg CVS).
|
|
|
172 |
\n";
|
|
|
173 |
exit(42);
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
#-------------------------------------------------------------------------------
|
|
|
177 |
# Function : SubDir
|
|
|
178 |
#
|
|
|
179 |
# Description : Recurse into the specified sub directories
|
|
|
180 |
# This is one of the very few directives in a 'makefile.pl'
|
|
|
181 |
# that is processed by this script - all the others are
|
|
|
182 |
# processed by makelib.pl2.
|
|
|
183 |
#
|
|
|
184 |
# This directive MUST appear before the 'Platform' directive
|
|
|
185 |
#
|
|
|
186 |
# Inputs : List of sub directories to visit
|
|
|
187 |
#
|
|
|
188 |
# Returns : Nothing
|
|
|
189 |
#
|
|
|
190 |
sub SubDir
|
|
|
191 |
{
|
|
|
192 |
my( @NewDirs );
|
|
|
193 |
Debug( "SubDir(@_)" );
|
|
|
194 |
Error ("Directive 'SubDir' not allowed in this context") if ( $::ScmBuildlib );
|
|
|
195 |
|
|
|
196 |
#
|
|
|
197 |
# Support different constructs:
|
|
|
198 |
# 'dir1 dir2'
|
|
|
199 |
# 'dir1','dir2'
|
|
|
200 |
#
|
|
|
201 |
@NewDirs = map { split /\s+/ } @_;
|
|
|
202 |
@NewDirs = grep { defined $_ } @NewDirs;
|
|
|
203 |
|
|
|
204 |
foreach my $ThisDir ( @NewDirs )
|
|
|
205 |
{
|
|
|
206 |
Warning ("SubDir contains a '\\' character: $ThisDir" )
|
|
|
207 |
if ( $ThisDir =~ m~\\~);
|
|
|
208 |
|
|
|
209 |
if ( grep /^$ThisDir$/, @::SUBDIRS )
|
|
|
210 |
{
|
|
|
211 |
Warning( "Duplicate SubDir '$ThisDir' -- ignored." );
|
|
|
212 |
next;
|
|
|
213 |
}
|
|
|
214 |
if ( ! ( -e $ThisDir and -d $ThisDir ) )
|
|
|
215 |
{
|
|
|
216 |
Error( "SubDir(): Subdirectory not found: '$ThisDir'",
|
|
|
217 |
"Current directory: $::Cwd" );
|
|
|
218 |
}
|
|
|
219 |
if ( ! -f $ThisDir . '/makefile.pl' )
|
|
|
220 |
{
|
|
|
221 |
Error( "SubDir(): makefile.pl not found in subdirectory: '$ThisDir'",
|
|
|
222 |
"Current directory: $::Cwd" );
|
|
|
223 |
}
|
|
|
224 |
|
|
|
225 |
push(@::SUBDIRS, $ThisDir);
|
|
|
226 |
}
|
|
|
227 |
}
|
|
|
228 |
|
|
|
229 |
|
|
|
230 |
#-------------------------------------------------------------------------------
|
|
|
231 |
# Function : RootMakefile
|
|
|
232 |
#
|
|
|
233 |
# Description : This function is called from buildlib.pl prior to the
|
|
|
234 |
# generation of the root makefile. The Root Makefile is
|
|
|
235 |
# different to the others in this it does not have any platform
|
|
|
236 |
# specific makefiles associated with it. It is simply used to
|
|
|
237 |
# invoke the makefile in the 'src' subdirectory
|
|
|
238 |
#
|
|
|
239 |
# Inputs : None
|
|
|
240 |
#
|
|
|
241 |
# Returns : Nothing
|
|
|
242 |
#
|
|
|
243 |
sub RootMakefile
|
|
|
244 |
{
|
|
|
245 |
Error ("Directive 'RootMakefile' not allowed in this context") if ( $::ScmBuildlib );
|
|
|
246 |
$::ROOTMAKEFILE = 1;
|
|
|
247 |
}
|
|
|
248 |
|
|
|
249 |
|
|
|
250 |
sub PackageDist
|
|
|
251 |
{
|
|
|
252 |
my( $name, @elements ) = @_;
|
|
|
253 |
Error ("Directive 'PackageDist' not allowed in this context") if ( $::ScmBuildlib );
|
|
|
254 |
|
|
|
255 |
foreach ( @elements ) {
|
|
|
256 |
HashJoin( \%::PACKAGE_DIST, $;, $name, "$_" );
|
|
|
257 |
}
|
|
|
258 |
}
|
|
|
259 |
|
|
|
260 |
|
|
|
261 |
sub Define
|
|
|
262 |
{
|
|
|
263 |
Error ("Directive 'Define' not allowed in this context") if ( $::ScmBuildlib );
|
|
|
264 |
push( @::DEFINES, @_ );
|
|
|
265 |
}
|
|
|
266 |
|
|
|
267 |
|
|
|
268 |
sub Defines
|
|
|
269 |
{
|
|
|
270 |
my( $path, $script ) = @_;
|
|
|
271 |
my( $line );
|
|
|
272 |
Error ("Directive 'Defines' not allowed in this context") if ( $::ScmBuildlib );
|
|
|
273 |
|
|
|
274 |
$script = Exists( $path, $script, "Defines" );
|
|
|
275 |
open( SCRIPT, $script ) ||
|
|
|
276 |
Error( "cannot open '$script'" );
|
|
|
277 |
while (<SCRIPT>) {
|
|
|
278 |
$_ =~ s/\s*(\n|$)//; # kill trailing whitespace & nl
|
|
|
279 |
push( @::DEFINES, $_ );
|
|
|
280 |
}
|
|
|
281 |
push( @::ScmDepends, "$script" ); # makefile dependencies
|
|
|
282 |
close( SCRIPT );
|
|
|
283 |
}
|
|
|
284 |
|
|
|
285 |
|
|
|
286 |
sub Rule
|
|
|
287 |
{
|
|
|
288 |
Error ("Directive 'Rule' not allowed in this context") if ( $::ScmBuildlib );
|
|
|
289 |
push( @::RULES, @_ );
|
|
|
290 |
}
|
|
|
291 |
|
|
|
292 |
|
|
|
293 |
sub Rules
|
|
|
294 |
{
|
|
|
295 |
Error ("Directive 'Rules' not allowed in this context") if ( $::ScmBuildlib );
|
|
|
296 |
my( $path, $script ) = @_;
|
|
|
297 |
my( $line );
|
|
|
298 |
|
|
|
299 |
$script = Exists( $path, $script, "Rules" );
|
|
|
300 |
open( SCRIPT, $script ) ||
|
|
|
301 |
Error( "cannot open '$script'" );
|
|
|
302 |
while (<SCRIPT>) {
|
|
|
303 |
$_ =~ s/\s*(\n|$)//; # kill trailing whitespace & nl
|
|
|
304 |
push( @::RULES, $_ );
|
|
|
305 |
}
|
|
|
306 |
push( @::ScmDepends, "$script" ); # makefile dependencies
|
|
|
307 |
close( SCRIPT );
|
|
|
308 |
}
|
|
|
309 |
|
|
|
310 |
#-------------------------------------------------------------------------------
|
|
|
311 |
# Function : Platform
|
|
|
312 |
#
|
|
|
313 |
# Description : Within "makelib.pl" the Platform directive is processed
|
|
|
314 |
# in such a manner as to trigger the verification and
|
|
|
315 |
# generation of Makefile and xxxxx.mk files in the tree
|
|
|
316 |
# below the makefile.pl
|
|
|
317 |
#
|
|
|
318 |
# Inputs : A list of platforms for which the body of the makefile.pl
|
|
|
319 |
# are to be processed + GBE_PLATFORM
|
|
|
320 |
#
|
|
|
321 |
# "*", ... - A wildcard for all platforms
|
|
|
322 |
# Options include
|
|
|
323 |
# --Targets (Not Products)
|
|
|
324 |
# --Products
|
|
|
325 |
# --NoPlatformBuilds
|
|
|
326 |
# !xxx - Exclude a platform
|
|
|
327 |
#
|
|
|
328 |
# "--NoPlatformBuilds"
|
|
|
329 |
#
|
|
|
330 |
# "xxx"[, "yyy"]* - A list of platforms and aliases
|
|
|
331 |
#
|
|
|
332 |
# "!xxx" - A platform to be excluded
|
|
|
333 |
#
|
|
|
334 |
# Returns :
|
|
|
335 |
#
|
|
|
336 |
sub Platform
|
|
|
337 |
{
|
|
|
338 |
my ( @platforms ) = @_;
|
|
|
339 |
my ( $dir, $exitVal, $platform );
|
|
|
340 |
my $noplatforms = 0;
|
|
|
341 |
my $defplatforms = 0;
|
|
|
342 |
my %platforms;
|
|
|
343 |
|
|
|
344 |
Debug( "Platform(@_)" );
|
|
|
345 |
Error ("Directive 'Platform' not allowed in this context") if ( $::ScmBuildlib );
|
|
|
346 |
|
|
|
347 |
#
|
|
|
348 |
# Import user platform specification (GBE_PLATFORM)
|
|
|
349 |
# Note: This is also used by the Makefile and it cannot be
|
|
|
350 |
# alias expanded or sanitised. Its not really really useful
|
|
|
351 |
#
|
|
|
352 |
# Only use GB_PLATFORM if the user has not specified to build ALL
|
|
|
353 |
# makefiles.
|
|
|
354 |
#
|
|
|
355 |
my %filter;
|
|
|
356 |
my $filter_present = 0;
|
|
|
357 |
|
|
|
358 |
if ( $::ScmAll == 0 )
|
|
|
359 |
{
|
| 239 |
dpurdie |
360 |
$filter{GENERIC} = 1;
|
| 227 |
dpurdie |
361 |
foreach ( split( ' ', $ENV{ "GBE_PLATFORM" } || '' ) )
|
|
|
362 |
{
|
|
|
363 |
$filter{$_} = 1;
|
|
|
364 |
$filter_present = 1;
|
|
|
365 |
}
|
|
|
366 |
}
|
|
|
367 |
|
|
|
368 |
#
|
|
|
369 |
# Expand out the directive platform list (and optional arguments)
|
|
|
370 |
# Expand wildcards and aliases
|
|
|
371 |
#
|
|
|
372 |
# Handle format
|
|
|
373 |
# Platform ('*', '--Options', [!Name]);
|
|
|
374 |
# Platform ('--NoPlatformBuilds' );
|
|
|
375 |
# Platform ('Name', '--Options', [!Name] );
|
|
|
376 |
# Platform ('!Name' );
|
|
|
377 |
#
|
|
|
378 |
#
|
|
|
379 |
if ( $platforms[0] && $platforms[0] eq '*' )
|
|
|
380 |
{
|
|
|
381 |
my( $targets, $products ); # options
|
|
|
382 |
my( @args );
|
|
|
383 |
my( @exclude );
|
|
|
384 |
|
|
|
385 |
$targets = $products = 0;
|
|
|
386 |
|
|
|
387 |
foreach $_ ( @platforms ) {
|
|
|
388 |
next if ( /^\*$/);
|
|
|
389 |
next if ( /^--Targets$/ && ($targets = 1));
|
|
|
390 |
next if ( /^--Products$/ && ($products = 1));
|
|
|
391 |
next if ( /^--NoPlatformBuilds/ && ($noplatforms = 1));
|
|
|
392 |
next if ( /^--/ && push @args, $_ );
|
|
|
393 |
next if ( /^!/ && push @exclude, $_ );
|
|
|
394 |
Warning( "Platform: unknown option $_ -- ignored\n" );
|
|
|
395 |
}
|
|
|
396 |
|
|
|
397 |
#
|
|
|
398 |
# Determine the list of platforms to expand the '*' into
|
|
|
399 |
# The result may be modified by optional arguments
|
|
|
400 |
# --Targets # Expands to all targets
|
|
|
401 |
# --Products # Expands to all products
|
|
|
402 |
# OtherWise # Expands to all build platforms
|
|
|
403 |
#
|
|
|
404 |
@platforms = (); # zap list
|
|
|
405 |
|
|
|
406 |
# 'all' platforms
|
|
|
407 |
push( @platforms, @::DEFBUILDPLATFORMS )
|
|
|
408 |
unless ( $targets | $products );
|
|
|
409 |
|
|
|
410 |
#
|
|
|
411 |
# Expand the '*' into a list of platforms that are NOT products
|
|
|
412 |
#
|
|
|
413 |
if ( $targets && defined( %::ScmBuildPlatforms ) )
|
|
|
414 |
{ # targets
|
|
|
415 |
foreach my $key (keys %::ScmBuildPlatforms) {
|
|
|
416 |
push( @platforms, $key )
|
|
|
417 |
if (! defined( %::ScmBuildProducts ) ||
|
|
|
418 |
! scalar $::ScmBuildProducts{ $key } );
|
|
|
419 |
}
|
|
|
420 |
}
|
|
|
421 |
|
|
|
422 |
#
|
|
|
423 |
# Expand the '*' into a list of platforms that are 'products'
|
|
|
424 |
#
|
|
|
425 |
if ( $products && defined( %::ScmBuildProducts ) )
|
|
|
426 |
{ # products
|
|
|
427 |
foreach my $key (keys %::ScmBuildProducts) {
|
|
|
428 |
push( @platforms, $key );
|
|
|
429 |
}
|
|
|
430 |
}
|
|
|
431 |
|
|
|
432 |
#
|
|
|
433 |
# Distribute arguments over all expanded platforms
|
|
|
434 |
#
|
|
|
435 |
if ( @args )
|
|
|
436 |
{
|
|
|
437 |
my @baseplatforms;
|
|
|
438 |
foreach ( @platforms )
|
|
|
439 |
{
|
|
|
440 |
push @baseplatforms, $_, @args;
|
|
|
441 |
}
|
|
|
442 |
@platforms = @baseplatforms;
|
|
|
443 |
}
|
|
|
444 |
|
|
|
445 |
#
|
|
|
446 |
# Place the excluded platforms at the end of the list
|
|
|
447 |
#
|
|
|
448 |
push @platforms, ExpandPlatforms( @exclude );
|
|
|
449 |
|
|
|
450 |
}
|
|
|
451 |
elsif ( scalar @platforms == 1 && $platforms[0] eq "--NoPlatformBuilds" )
|
|
|
452 |
{ # short-cut
|
|
|
453 |
$noplatforms = 1;
|
|
|
454 |
@platforms = @::DEFBUILDPLATFORMS;
|
|
|
455 |
}
|
|
|
456 |
else
|
|
|
457 |
{ # aliasing
|
|
|
458 |
@platforms = ExpandPlatforms( @platforms );
|
|
|
459 |
#
|
|
|
460 |
# Process excluded platform lists
|
|
|
461 |
# Migrate excluded platforms to the end of the list
|
|
|
462 |
#
|
|
|
463 |
my (@include, @exclude);
|
|
|
464 |
|
|
|
465 |
foreach ( @platforms )
|
|
|
466 |
{
|
|
|
467 |
next if ( m/^!/ && push @exclude, $_ );
|
|
|
468 |
push @include, $_;
|
|
|
469 |
}
|
|
|
470 |
|
|
|
471 |
#
|
|
|
472 |
# If no included platforms have been found then assume that the
|
|
|
473 |
# list is an exclusion list and seed the platform list with
|
|
|
474 |
# a set of defualt platforms - like '*'
|
|
|
475 |
#
|
|
|
476 |
#
|
|
|
477 |
@include = @::DEFBUILDPLATFORMS unless @include;
|
|
|
478 |
@platforms = ( @include, @exclude );
|
|
|
479 |
}
|
|
|
480 |
|
|
|
481 |
$platform = ""; # current platform
|
|
|
482 |
|
|
|
483 |
#
|
|
|
484 |
# Process the directives expanded list of platforms
|
|
|
485 |
#
|
|
|
486 |
|
|
|
487 |
#
|
|
|
488 |
# Generate a HASH of lowercase known platform names
|
|
|
489 |
# This will be used to quickly validate platform names
|
|
|
490 |
#
|
|
|
491 |
my %lc_platforms;
|
|
|
492 |
foreach ( @::BUILDPLATFORMS )
|
|
|
493 |
{
|
|
|
494 |
$lc_platforms{ lc($_) } = $_;
|
|
|
495 |
}
|
|
|
496 |
|
|
|
497 |
FILTER:
|
|
|
498 |
foreach $_ ( @platforms )
|
|
|
499 |
{
|
|
|
500 |
if ( ! /^--(.*)/ )
|
|
|
501 |
{
|
|
|
502 |
$_ =~ s/^\s*//g; # leading white space
|
|
|
503 |
$_ =~ s/\s*(\n|$)//; # trailing white space
|
|
|
504 |
|
|
|
505 |
|
|
|
506 |
#
|
|
|
507 |
# Remove specific platforms from the list
|
|
|
508 |
#
|
|
|
509 |
$defplatforms = 1;
|
|
|
510 |
if ( m/!(.*)/ )
|
|
|
511 |
{
|
|
|
512 |
Verbose( "Excluded platform removed: $1" );
|
|
|
513 |
delete $platforms{$1};
|
|
|
514 |
next FILTER;
|
|
|
515 |
}
|
|
|
516 |
|
|
|
517 |
|
|
|
518 |
if ( exists $platforms{$_} )
|
|
|
519 |
{
|
|
|
520 |
Warning( "duplicate platform '$_' -- ignored." );
|
|
|
521 |
$platform = "";
|
|
|
522 |
next FILTER;
|
|
|
523 |
}
|
|
|
524 |
|
|
|
525 |
#
|
|
|
526 |
# validate 'platform'
|
|
|
527 |
# Allow the user to have a bad case match ( Fred == fred == FRED )
|
|
|
528 |
#
|
|
|
529 |
my $lc_platform = lc($_);
|
|
|
530 |
unless ( exists( $lc_platforms{$lc_platform} ) )
|
|
|
531 |
{
|
|
|
532 |
Warning( "Platform '$_' not contained within BuildPlatforms -- ignored." )
|
|
|
533 |
unless ( exists( $::ScmBuildPlatforms{$_} ));
|
|
|
534 |
$platform = "";
|
|
|
535 |
next FILTER;
|
|
|
536 |
}
|
|
|
537 |
|
|
|
538 |
$lc_platform = $lc_platforms{$lc_platform};
|
|
|
539 |
if ( $_ ne $lc_platform )
|
|
|
540 |
{
|
|
|
541 |
Warning( "Mixed case usage of platform '$_' -- corrected." );
|
|
|
542 |
$_ = $lc_platform;
|
|
|
543 |
}
|
|
|
544 |
|
|
|
545 |
# filter 'platform'
|
|
|
546 |
if ( $filter_present )
|
|
|
547 |
{
|
|
|
548 |
if ( ! exists $filter{$_} )
|
|
|
549 |
{
|
|
|
550 |
Verbose( "GBE_PLATFORM override $_ -- ignored" );
|
|
|
551 |
$platform = "";
|
|
|
552 |
next FILTER;
|
|
|
553 |
}
|
|
|
554 |
}
|
|
|
555 |
|
|
|
556 |
#
|
|
|
557 |
# Platform not filtered out - must be using it.
|
|
|
558 |
#
|
|
|
559 |
Verbose( "Platform ... $_" );
|
|
|
560 |
$platforms{$_} = 1; # Add to platform list
|
|
|
561 |
$platform = $_; # new platform
|
|
|
562 |
}
|
|
|
563 |
|
|
|
564 |
elsif ( /^--NoPlatformBuilds$/ )
|
|
|
565 |
{
|
|
|
566 |
$noplatforms = 1;
|
|
|
567 |
}
|
|
|
568 |
|
|
|
569 |
elsif ( $platform ne "" )
|
|
|
570 |
{ # other arguments
|
|
|
571 |
Verbose( " .. $_" );
|
|
|
572 |
|
|
|
573 |
HashUniqueJoin( \%::PLATFORMARGS, $; , $platform, $1 ) ||
|
|
|
574 |
Warning( "Duplicate argument '$platform=$_' -- ignored." );
|
|
|
575 |
}
|
|
|
576 |
}
|
|
|
577 |
#
|
|
|
578 |
# Sort the platforms to ensure that the ordering is consistient throughout
|
|
|
579 |
#
|
|
|
580 |
@::PLATFORMS = sort keys %platforms;
|
|
|
581 |
|
|
|
582 |
#
|
|
|
583 |
# Trap makefiles that don't have any platforms
|
|
|
584 |
# The user 'should' mark these as --NoPlatformBuilds
|
|
|
585 |
#
|
|
|
586 |
unless ( @::PLATFORMS )
|
|
|
587 |
{
|
|
|
588 |
Warning( "No platform definitions." )
|
|
|
589 |
unless( $noplatforms || $defplatforms);
|
|
|
590 |
$noplatforms = 1;
|
|
|
591 |
}
|
|
|
592 |
|
|
|
593 |
#.. Common rules
|
|
|
594 |
#
|
|
|
595 |
my( $file ) = Require( "$::GBE_CONFIG", "Rules", "Common rules " );
|
|
|
596 |
push( @::ScmDepends, "$file" );
|
|
|
597 |
|
|
|
598 |
|
|
|
599 |
#.. Generate primary makefile
|
|
|
600 |
#
|
|
|
601 |
$exitVal = Generate( $noplatforms );
|
|
|
602 |
if ($::ROOTMAKEFILE == 1) {
|
|
|
603 |
print STDERR "WARNING: problem generating Makefile ($exitVal)\n"
|
|
|
604 |
unless (($exitVal == $::Generated) || ($exitVal == 0));
|
|
|
605 |
return ($exitVal);
|
|
|
606 |
}
|
|
|
607 |
|
|
|
608 |
Debug( "Platform ExitVal: $exitVal" );
|
|
|
609 |
exit( $exitVal );
|
|
|
610 |
}
|
|
|
611 |
|
|
|
612 |
###############################################################################
|
|
|
613 |
# Private function section.
|
|
|
614 |
# The following functions are used INTERNALLY by makelib.pl.
|
|
|
615 |
#
|
|
|
616 |
###############################################################################
|
|
|
617 |
|
|
|
618 |
#-------------------------------------------------------------------------------
|
|
|
619 |
# Function : Generate
|
|
|
620 |
#
|
|
|
621 |
# Description : Build makefiles ...
|
|
|
622 |
# Creates the command data files and the per-target .MK files
|
|
|
623 |
#
|
|
|
624 |
# Inputs : $noplatforms - 1 if this makefile does not have
|
|
|
625 |
# any platforms
|
|
|
626 |
#
|
|
|
627 |
# Returns : $exitVal
|
|
|
628 |
#
|
|
|
629 |
sub Generate
|
|
|
630 |
{
|
|
|
631 |
my( $noplatforms ) = @_;
|
|
|
632 |
my( $exitVal ) = 0;
|
|
|
633 |
|
|
|
634 |
#.. Dont build platforms within root directory
|
|
|
635 |
#
|
|
|
636 |
$noplatforms = 1
|
|
|
637 |
if ($::ROOTMAKEFILE == 1);
|
|
|
638 |
|
|
|
639 |
#.. Build 'makefile'
|
|
|
640 |
#
|
|
|
641 |
$exitVal = GeneratePlatforms()
|
|
|
642 |
unless ($noplatforms );
|
|
|
643 |
|
|
|
644 |
GenerateMakefile( $noplatforms );
|
|
|
645 |
$exitVal = $::Generated if ( $exitVal == 0);
|
|
|
646 |
|
|
|
647 |
return $exitVal;
|
|
|
648 |
}
|
|
|
649 |
|
|
|
650 |
|
|
|
651 |
#
|
|
|
652 |
# Note:
|
|
|
653 |
# Currently this function will create all .mk files in the current directory
|
|
|
654 |
#
|
|
|
655 |
# Note: Cleanup of unused .mk files is done when the WriteCommonInfo is
|
|
|
656 |
# processed. Makefiles that are no lonker used will be purged
|
|
|
657 |
#
|
|
|
658 |
sub GeneratePlatforms
|
|
|
659 |
{
|
|
|
660 |
my( $exitVal, $exitVal2 ) = 0;
|
|
|
661 |
|
|
|
662 |
foreach my $platform ( @::PLATFORMS )
|
|
|
663 |
{
|
|
|
664 |
my( $Cmdline ) = "$::GBE_PERL $0 $::ScmRoot " . $::ScmMakelib . "2" . " $platform";
|
|
|
665 |
|
|
|
666 |
$Cmdline .= " --interface=$::ScmInterface"
|
|
|
667 |
if ( $::ScmInterface ne "" );
|
|
|
668 |
|
|
|
669 |
#
|
|
|
670 |
# Insert platform local arguments
|
|
|
671 |
#
|
|
|
672 |
if ($::PLATFORMARGS{ $platform })
|
|
|
673 |
{
|
|
|
674 |
my( @args ) = split( /$;/, $::PLATFORMARGS{ $platform } );
|
|
|
675 |
foreach my $arg (@args) {
|
|
|
676 |
$Cmdline .= " --arg=$arg";
|
|
|
677 |
}
|
|
|
678 |
}
|
|
|
679 |
|
|
|
680 |
$Cmdline .= " --expert"
|
|
|
681 |
if ( $::ScmExpert );
|
|
|
682 |
|
|
|
683 |
$Cmdline .= " --all"
|
|
|
684 |
if ( $::ScmAll );
|
|
|
685 |
|
|
|
686 |
$exitVal2 = System( $Cmdline );
|
|
|
687 |
|
|
|
688 |
Warning ("Problem generating $platform.mk in $::Cwd ($exitVal2)")
|
|
|
689 |
unless (($exitVal2 == $::Generated) || ($exitVal2 == 0));
|
|
|
690 |
|
|
|
691 |
if ($exitVal == 0) {
|
|
|
692 |
$exitVal = $exitVal2;
|
|
|
693 |
} elsif ($exitVal == $::Generated) {
|
|
|
694 |
$exitVal = $exitVal2
|
|
|
695 |
if ($exitVal2);
|
|
|
696 |
}
|
|
|
697 |
}
|
|
|
698 |
|
|
|
699 |
return $exitVal;
|
|
|
700 |
}
|
|
|
701 |
|
|
|
702 |
#-------------------------------------------------------------------------------
|
|
|
703 |
# Function : GenerateMakefile
|
|
|
704 |
#
|
|
|
705 |
# Description : Generate the non-platform specific makefile
|
|
|
706 |
# Once upon a time this was a real makefile
|
|
|
707 |
# Now its a simple file and a database as this offeres greater
|
|
|
708 |
# flexability.
|
|
|
709 |
#
|
|
|
710 |
# The file, "Makefile.gbe" contains enough info to get to the
|
|
|
711 |
# interface directory.
|
|
|
712 |
#
|
|
|
713 |
# The "database" is held in the interface directory as
|
|
|
714 |
# Makfile.cfg - index to locate Makefile_nn.cfg
|
|
|
715 |
# Makefile_nn.cfg - data from a makefile.pl
|
|
|
716 |
#
|
|
|
717 |
# Inputs : $noplatforms - 1: no platform makefiles in this dir
|
|
|
718 |
#
|
|
|
719 |
# Returns : Nothing
|
|
|
720 |
#
|
|
|
721 |
sub GenerateMakefile
|
|
|
722 |
{
|
|
|
723 |
my( $noplatforms ) = @_;
|
|
|
724 |
my %platform_info;
|
|
|
725 |
|
|
|
726 |
#
|
|
|
727 |
# Determine targets that are limited to either debug or production builds
|
|
|
728 |
# This information may come from several places
|
|
|
729 |
#
|
|
|
730 |
foreach my $key ( @PLATFORMS )
|
|
|
731 |
{
|
|
|
732 |
my @args;
|
|
|
733 |
UniquePush (\@args, split ( /$;/, $::PLATFORMARGS{$key} ))
|
|
|
734 |
if ($::PLATFORMARGS{$key});
|
|
|
735 |
|
|
|
736 |
UniquePush (\@args, map { s/^--//; $_} split ( /$;/, $::ScmBuildPlatforms{$key} ))
|
|
|
737 |
if($::ScmBuildPlatforms{$key});
|
|
|
738 |
|
|
|
739 |
my $hasOnlyProd = grep /^OnlyProd/, @args;
|
|
|
740 |
my $hasOnlyDebug = grep /^OnlyDebug/, @args;
|
|
|
741 |
|
|
|
742 |
if ( $hasOnlyProd && $hasOnlyDebug )
|
|
|
743 |
{
|
|
|
744 |
Warning ("Target \"$key\" has both OnlyDebug and OnlyProd options",
|
|
|
745 |
"Both options ignored. Target will be built" );
|
|
|
746 |
|
|
|
747 |
$hasOnlyProd = $hasOnlyDebug = 0;
|
|
|
748 |
}
|
|
|
749 |
$platform_info{$key}{prod} = 1 unless $hasOnlyDebug;
|
|
|
750 |
$platform_info{$key}{debug} = 1 unless $hasOnlyProd;
|
|
|
751 |
}
|
|
|
752 |
|
|
|
753 |
#
|
|
|
754 |
# Update common information in the Makefile_x.cfg file
|
|
|
755 |
#
|
|
|
756 |
WriteCommonInfo( \@::SUBDIRS, \%platform_info, $noplatforms, $::ROOTMAKEFILE );
|
|
|
757 |
|
|
|
758 |
#
|
|
|
759 |
#.. Maintain local information in Makefile.gbe
|
|
|
760 |
# This allows us to locate the interface directory
|
|
|
761 |
#
|
|
|
762 |
Message "[Control] $::Cwd";
|
|
|
763 |
CreateMakeInfo();
|
|
|
764 |
}
|
|
|
765 |
|
|
|
766 |
1;
|
|
|
767 |
|