Subversion Repositories DevTools

Rev

Rev 1109 | Rev 1113 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1109 Rev 1111
Line 1... Line 1...
1
########################################################################
1
########################################################################
2
# Copyright (C) 2008 ERG Limited, All rights reserved
2
# Copyright (C) 2008 ERG Limited, All rights reserved
3
#
3
#
4
# Module name   : Proc_day0fs_script.pl
4
# Module name   : Proc_day0fs_script.pl
5
# Module type   : Makefile system
5
# Module type   : Makefile system
6
# Compiler(s)   : Perl
6
# Compiler(s)   : Perl
7
# Environment(s): jats
7
# Environment(s): jats
8
#
8
#
9
# Description   :
9
# Description   :
10
#
10
#
11
# Usage:
11
# Usage:
12
#
12
#
13
#......................................................................#
13
#......................................................................#
14
 
14
 
15
require 5.008_002;
15
require 5.008_002;
16
 
16
 
17
use strict;
17
use strict;
18
use warnings;
18
use warnings;
19
 
19
 
20
use Pod::Usage;
20
use Pod::Usage;
21
use Getopt::Long;
21
use Getopt::Long;
22
use File::Path;
22
use File::Path;
23
use File::Copy;
23
use File::Copy;
24
 
24
 
25
use FindBin;                                    # Determine the current directory
25
use FindBin;                                    # Determine the current directory
26
use lib "$FindBin::Bin";                        # Allow Modules in current directory
26
use lib "$FindBin::Bin";                        # Allow Modules in current directory
27
 
27
 
28
use JatsError;
28
use JatsError;
29
use JatsSystem;
29
use JatsSystem;
30
use FileUtils;
30
use FileUtils;
31
use JatsCopy qw(SetCopyDirDefaults DeleteDir CopyDir CreateDir);
31
use JatsCopy qw(SetCopyDirDefaults DeleteDir CopyDir CreateDir);
32
use CreateSdImage qw( CreateSdImage );
32
use CreateSdImage qw( CreateSdImage );
33
 
33
 
34
#
34
#
35
#
35
#
36
#   Global Variables
36
#   Global Variables
37
#
37
#
38
my $VERSION = 1.0;
38
my $VERSION = 1.0;
39
our $AUTOLOAD;
39
our $AUTOLOAD;
40
my $BUILD = 'build';                        # Build subdir
40
my $BUILD = 'build';                        # Build subdir
41
my $WORK = "${BUILD}/image";
41
my $WORK = "${BUILD}/image";
42
 
42
 
43
my $source_specified = 0;                   # Ensure that source is specified
43
my $source_specified = 0;                   # Ensure that source is specified
44
my $output_image = 0;                       # Ensure output is specified
44
my $output_image = 0;                       # Ensure output is specified
45
my $output_sd = 0;
45
my $output_sd = 0;
46
 
46
 
47
#
47
#
48
#   Command line options
48
#   Command line options
49
#
49
#
50
my $opt_debug   = $ENV{'GBE_DEBUG'};        # Allow global debug
50
my $opt_debug   = $ENV{'GBE_DEBUG'};        # Allow global debug
51
my $opt_verbose = $ENV{'GBE_VERBOSE'};      # Allow global verbose
51
my $opt_verbose = $ENV{'GBE_VERBOSE'};      # Allow global verbose
52
my $opt_vargs;                              # Verbose arg
52
my $opt_vargs;                              # Verbose arg
53
my $opt_help = 0;
53
my $opt_help = 0;
54
my $opt_manual = 0;
54
my $opt_manual = 0;
55
my $opt_clean = 0;
55
my $opt_clean = 0;
56
my $opt_platform;
56
my $opt_platform;
57
my $opt_type;
57
my $opt_type;
58
my $opt_buildname;
58
my $opt_buildname;
59
my $opt_packagedir;
59
my $opt_packagedir;
60
my $opt_interfacedir;
60
my $opt_interfacedir;
61
my $opt_compilerpath;
61
my $opt_compilerpath;
62
my $opt_product;
62
my $opt_product;
63
my $opt_packagebindir;
63
my $opt_packagebindir;
64
our $opt_buildroot;
64
our $opt_buildroot;
65
my $opt_target;
65
my $opt_target;
66
my $opt_version;
66
my $opt_version;
67
my $opt_userscript;
67
my $opt_userscript;
68
 
68
 
69
#-------------------------------------------------------------------------------
69
#-------------------------------------------------------------------------------
70
# Function        : Mainline Entry Point
70
# Function        : Mainline Entry Point
71
#
71
#
72
# Description     :
72
# Description     :
73
#
73
#
74
# Inputs          :
74
# Inputs          :
75
#
75
#
76
my $result = GetOptions (
76
my $result = GetOptions (
77
                "help+"             => \$opt_help,
77
                "help+"             => \$opt_help,
78
                "manual"            => \$opt_manual,
78
                "manual"            => \$opt_manual,
79
                "verbose:s"         => \$opt_vargs,
79
                "verbose:s"         => \$opt_vargs,
80
                "clean"             => \$opt_clean,
80
                "clean"             => \$opt_clean,
81
                "Platform=s"        => \$opt_platform,
81
                "Platform=s"        => \$opt_platform,
82
                "Type=s"            => \$opt_type,
82
                "Type=s"            => \$opt_type,
83
                "BuildName=s"       => \$opt_buildname,
83
                "BuildName=s"       => \$opt_buildname,
84
                "PackageDir=s"      => \$opt_packagedir,
84
                "PackageDir=s"      => \$opt_packagedir,
85
                "InterfaceDir=s"    => \$opt_interfacedir,
85
                "InterfaceDir=s"    => \$opt_interfacedir,
86
                "CompilerPath=s"    => \$opt_compilerpath,
86
                "CompilerPath=s"    => \$opt_compilerpath,
87
                "Product=s"         => \$opt_product,
87
                "Product=s"         => \$opt_product,
88
                "PackageBinDir=s"   => \$opt_packagebindir,
88
                "PackageBinDir=s"   => \$opt_packagebindir,
89
                "BuildRoot=s"       => \$opt_buildroot,
89
                "BuildRoot=s"       => \$opt_buildroot,
90
                "Target=s"          => \$opt_target,
90
                "Target=s"          => \$opt_target,
91
                "BuildVersion=s"    => \$opt_version,
91
                "BuildVersion=s"    => \$opt_version,
92
                "UserScript=s"      => \$opt_userscript,
92
                "UserScript=s"      => \$opt_userscript,
93
 
93
 
94
    );
94
    );
95
 
95
 
96
#
96
#
97
#   Process help and manual options
97
#   Process help and manual options
98
#
98
#
99
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
99
pod2usage(-verbose => 0, -message => "Version: $VERSION")  if ($opt_help == 1  || ! $result);
100
pod2usage(-verbose => 1)  if ($opt_help == 2 );
100
pod2usage(-verbose => 1)  if ($opt_help == 2 );
101
pod2usage(-verbose => 2)  if ($opt_manual || ($opt_help > 2));
101
pod2usage(-verbose => 2)  if ($opt_manual || ($opt_help > 2));
102
 
102
 
103
#
103
#
104
#   Configure the error reporting process now that we have the user options
104
#   Configure the error reporting process now that we have the user options
105
#
105
#
106
$opt_verbose++ unless ( $opt_vargs eq '@' );
106
$opt_verbose++ unless ( $opt_vargs eq '@' );
107
ErrorConfig( 'name'    => 'Proc_Day0fs',
107
ErrorConfig( 'name'    => 'Proc_Day0fs',
108
             'verbose' => $opt_verbose );
108
             'verbose' => $opt_verbose );
109
 
109
 
110
#
110
#
111
#   Configure the System command to fail on any error
111
#   Configure the System command to fail on any error
112
#
112
#
113
SystemConfig ( ExitOnError => 1 );
113
SystemConfig ( ExitOnError => 1 );
114
SetCopyDirDefaults ( 'EmptyDirs' => 1 ,Log => 0 );
114
SetCopyDirDefaults ( 'EmptyDirs' => 1 ,Log => 0 );
115
 
115
 
116
#
116
#
117
#   Init the FileSystem Uiltity interface
117
#   Init the FileSystem Uiltity interface
118
#
118
#
119
InitFileUtils();
119
InitFileUtils();
120
 
120
 
121
#
121
#
122
#   Ensure that we have all required options
122
#   Ensure that we have all required options
123
#
123
#
124
Error ("CompilePath not set")       unless ( $opt_compilerpath );
124
Error ("CompilePath not set")       unless ( $opt_compilerpath );
125
Error ("Platform not set")          unless ( $opt_platform );
125
Error ("Platform not set")          unless ( $opt_platform );
126
Error ("Type not set")              unless ( $opt_type );
126
Error ("Type not set")              unless ( $opt_type );
127
Error ("BuildName not set")         unless ( $opt_buildname );
127
Error ("BuildName not set")         unless ( $opt_buildname );
128
Error ("PackageBinDir not set")     unless ( $opt_packagebindir );
128
Error ("PackageBinDir not set")     unless ( $opt_packagebindir );
129
Error ("InterfaceDir not set")      unless ( $opt_interfacedir );
129
Error ("InterfaceDir not set")      unless ( $opt_interfacedir );
130
Error ("CompilePath not set")       unless ( $opt_compilerpath );
130
Error ("CompilePath not set")       unless ( $opt_compilerpath );
131
Error ("Product not set")           unless ( $opt_product );
131
Error ("Product not set")           unless ( $opt_product );
132
Error ("BuildRoot not set")         unless ( $opt_buildroot );
132
Error ("BuildRoot not set")         unless ( $opt_buildroot );
133
Error ("Target not set")            unless ( $opt_target );
133
Error ("Target not set")            unless ( $opt_target );
134
Error ("User Script not set")       unless ( $opt_userscript );
134
Error ("User Script not set")       unless ( $opt_userscript );
135
 
135
 
136
#
136
#
137
#   Calculate a few paths
137
#   Calculate a few paths
138
#
138
#
139
my $TOOLSUITE = $opt_compilerpath;
139
my $TOOLSUITE = $opt_compilerpath;
140
$TOOLSUITE =~ s~^.*/~~;
140
$TOOLSUITE =~ s~^.*/~~;
141
$TOOLSUITE =~ s~-gcc$~~;
141
$TOOLSUITE =~ s~-gcc$~~;
142
 
142
 
143
my $CROSSLIBS = $opt_compilerpath;
143
my $CROSSLIBS = $opt_compilerpath;
144
$CROSSLIBS =~ s~/bin/.*$~~;
144
$CROSSLIBS =~ s~/bin/.*$~~;
145
$CROSSLIBS .= "/${TOOLSUITE}/lib";
145
$CROSSLIBS .= "/${TOOLSUITE}/lib";
146
 
146
 
147
my $CROSSEXE = $opt_compilerpath;
147
my $CROSSEXE = $opt_compilerpath;
148
$CROSSEXE =~ s~/bin/.*$~~;
148
$CROSSEXE =~ s~/bin/.*$~~;
149
$CROSSEXE .= "/${TOOLSUITE}";
149
$CROSSEXE .= "/${TOOLSUITE}";
150
 
150
 
151
 
151
 
152
my $CROSS_COMPILE = $opt_compilerpath;
152
my $CROSS_COMPILE = $opt_compilerpath;
153
$CROSS_COMPILE =~ s~gcc$~~;
153
$CROSS_COMPILE =~ s~gcc$~~;
154
 
154
 
155
my $CROSS_STRIP = ${CROSS_COMPILE} . "strip";
155
my $CROSS_STRIP = ${CROSS_COMPILE} . "strip";
156
 
156
 
157
#
157
#
158
#   Display variables used
158
#   Display variables used
159
#
159
#
160
Message    "======================================================================";
160
Message    "======================================================================";
161
Message    "Build day0 file system";
161
Message    "Build day0 file system";
162
Message    "           Package: ${opt_buildname}";
162
Message    "           Package: ${opt_buildname}";
163
Message    "           Version: ${opt_version}";
163
Message    "           Version: ${opt_version}";
164
Message    "      Building for: ${opt_platform}, $opt_target";
164
Message    "      Building for: ${opt_platform}, $opt_target";
165
Message    "           Product: ${opt_product}";
165
Message    "           Product: ${opt_product}";
166
Message    "              Type: ${opt_type}";
166
Message    "              Type: ${opt_type}";
167
Message    "            Script: ${opt_userscript}";
167
Message    "            Script: ${opt_userscript}";
168
Verbose    "           Verbose: ${opt_verbose}";
168
Verbose    "           Verbose: ${opt_verbose}";
169
Message    "         BuildRoot: ${opt_buildroot}";
169
Message    "         BuildRoot: ${opt_buildroot}";
170
Verbose    "         BuildRoot: ${opt_buildroot}";
170
Verbose    "         BuildRoot: ${opt_buildroot}";
171
Verbose    "      InterfaceDir: ${opt_interfacedir}";
171
Verbose    "      InterfaceDir: ${opt_interfacedir}";
172
Verbose    "     CROSS_COMPILE: ${CROSS_COMPILE}";
172
Verbose    "     CROSS_COMPILE: ${CROSS_COMPILE}";
173
Verbose    "         CROSSLIBS: ${CROSSLIBS}";
173
Verbose    "         CROSSLIBS: ${CROSSLIBS}";
174
Verbose    "       CROSS_STRIP: ${CROSS_STRIP}";
174
Verbose    "       CROSS_STRIP: ${CROSS_STRIP}";
175
Message    "======================================================================";
175
Message    "======================================================================";
176
 
176
 
177
#
177
#
178
#   Perform Clean up
178
#   Perform Clean up
179
#   Invoked during "make clean" or "make clobber"
179
#   Invoked during "make clean" or "make clobber"
180
#
180
#
181
if ( $opt_clean )
181
if ( $opt_clean )
182
{
182
{
183
    Message ("Remove build directory: $BUILD");
183
    Message ("Remove build directory: $BUILD");
184
    rmtree( $BUILD );
184
    rmtree( $BUILD );
185
    exit;
185
    exit;
186
}
186
}
187
 
187
 
188
#
188
#
189
#   Have setup the basics
189
#   Have setup the basics
190
#   Invoke the user script to drive the remainder of the process
190
#   Invoke the user script to drive the remainder of the process
191
#       The script should only contain known directives
191
#       The script should only contain known directives
192
#       The directives will build up data structures that will be processed
192
#       The directives will build up data structures that will be processed
193
#       after the script has been read
193
#       after the script has been read
194
#
194
#
195
#
195
#
196
Message ("Process User Script: $opt_userscript");
196
Message ("Process User Script: $opt_userscript");
197
Error ("Board Specfic file Not found: $opt_userscript") unless ( -f $opt_userscript );
197
Error ("Board Specfic file Not found: $opt_userscript") unless ( -f $opt_userscript );
198
require $opt_userscript;
198
require $opt_userscript;
199
 
199
 
200
#
200
#
201
#   The process of requiring the user script
201
#   The process of requiring the user script
202
#   will have done all the required work
202
#   will have done all the required work
203
#   Perform minor sanity testing
203
#   Perform minor sanity testing
204
#
204
#
205
#
205
#
206
#   All done
206
#   All done
207
#
207
#
208
Error ( "No package output specified" )
208
Error ( "No package output specified" )
209
    unless ( $output_image || $output_sd );
209
    unless ( $output_image || $output_sd );
210
exit 0;
210
exit 0;
211
 
211
 
212
 
212
 
213
################################################################################
213
################################################################################
214
################################################################################
214
################################################################################
215
#
215
#
216
#   The following functions are intended to be used to manipulate files within
216
#   The following functions are intended to be used to manipulate files within
217
#   the output image.
217
#   the output image.
218
#
218
#
219
#   These may be used by the board specfic functions.
219
#   These may be used by the board specfic functions.
220
#
220
#
221
################################################################################
221
################################################################################
222
 
222
 
223
#-------------------------------------------------------------------------------
223
#-------------------------------------------------------------------------------
224
# Function        : Day0Source
224
# Function        : Day0Source
225
#
225
#
226
# Description     : Determine the source of the Day0 File System
226
# Description     : Determine the source of the Day0 File System
227
#                   Use of this directive is mandatory
227
#                   Use of this directive is mandatory
228
#
228
#
229
#
229
#
230
# Inputs          : Options
230
# Inputs          : Options
231
#                       --Dir=name              - Source dir
231
#                       --Dir=name              - Source dir
232
#                       --Image=name            - Source image
232
#                       --Image=name            - Source image
233
#
233
#
234
# Returns         : Nothing
234
# Returns         : Nothing
235
#
235
#
236
sub Day0Source
236
sub Day0Source
237
{
237
{
238
    my ($opt) = @_;
238
    my ($opt) = @_;
239
    #
239
    #
240
    #   Can only use this directive ONCE
240
    #   Can only use this directive ONCE
241
    #
241
    #
242
    Error ("Multiple Day0Source directives not allowed")
242
    Error ("Multiple Day0Source directives not allowed")
243
        if ( $source_specified++ );
243
        if ( $source_specified++ );
244
 
244
 
245
    #
245
    #
246
    #   Start with a clean slate
246
    #   Start with a clean slate
247
    #
247
    #
248
    DeleteDir ( $WORK );
248
    DeleteDir ( $WORK );
249
 
249
 
250
    #
250
    #
251
    #   Process options
251
    #   Process options
252
    #
252
    #
253
    if ( $opt =~ /^--Dir=(.+)/ ) {
253
    if ( $opt =~ /^--Dir=(.+)/ ) {
254
        #
254
        #
255
        #   User has specified a directory
255
        #   User has specified a directory
256
        #   Copy the entire directory to the work area
256
        #   Copy the entire directory to the work area
257
        #
257
        #
258
        Message ("Copy in Day0 source directory: $WORK");
258
        Message ("Copy in Day0 source directory: $WORK");
259
        CopyDir ( $1, $WORK, 'DeleteFirst' => 1 );
259
        CopyDir ( $1, $WORK, 'DeleteFirst' => 1 );
260
 
260
 
261
    } elsif ( $opt =~ /^--Image=(.+)/ ) {
261
    } elsif ( $opt =~ /^--Image=(.+)/ ) {
262
 
262
 
263
        #
263
        #
264
        #   User has specified an Image
264
        #   User has specified an Image
265
        #   Locate the image and extract it into the work area
265
        #   Locate the image and extract it into the work area
266
        #
266
        #
267
        my $name = $1;
267
        my $name = $1;
268
        Message ("Extract File System Image: $name");
268
        Message ("Extract File System Image: $name");
269
 
269
 
270
        #
270
        #
271
        #   File will come from a Package
271
        #   File will come from a Package
272
        #   This is where the tool places output files
272
        #   This is where the tool places output files
273
        #
273
        #
274
        my $fname = Internal::LocateFile ('bin', $name . '.tgz' );
274
        my $fname = Internal::LocateFile ('bin', $name . '.tgz' );
275
        Error ("Cannot locate Day0 source image: $name")
275
        Error ("Cannot locate Day0 source image: $name")
276
            unless $fname;
276
            unless $fname;
277
 
277
 
278
        #
278
        #
279
        #   Create a Tar command
279
        #   Create a Tar command
280
        #   Assumes the presence of a GNU style tar
280
        #   Assumes the presence of a GNU style tar
281
        #
281
        #
282
        CreateDir ( $WORK );
282
        CreateDir ( $WORK );
283
        System ( 'gtar',
283
        System ( 'gtar',
284
                 '--extract',
284
                 '--extract',
285
                 '--file',  $fname,
285
                 '--file',  $fname,
286
                 '--gzip',
286
                 '--gzip',
287
                 IsVerbose(1) ? ( '--verbose' ) : (),
287
                 IsVerbose(1) ? ( '--verbose' ) : (),
288
                 '--directory', $WORK,
288
                 '--directory', $WORK,
289
                 );
289
                 );
290
 
290
 
291
    } else {
291
    } else {
292
        Error ("Unknown Day0Source option: $opt");
292
        Error ("Unknown Day0Source option: $opt");
293
    }
293
    }
294
}
294
}
295
 
295
 
296
 
296
 
297
#-------------------------------------------------------------------------------
297
#-------------------------------------------------------------------------------
298
# Function        : Day0Operation
298
# Function        : Day0Operation
299
#
299
#
300
# Description     : Perform one of the special Day0 Operations
300
# Description     : Perform one of the special Day0 Operations
301
#
301
#
302
# Inputs          : $subfunction            - Sub function to perform
302
# Inputs          : $subfunction            - Sub function to perform
303
#                   @opts                   - Sub function options
303
#                   @opts                   - Sub function options
304
#
304
#
305
# Returns         : Nothing
305
# Returns         : Nothing
306
#
306
#
307
sub Day0Operation
307
sub Day0Operation
308
{
308
{
309
    Error ("Day0Source must be specified first")
309
    Error ("Day0Source must be specified first")
310
        unless ( $source_specified );
310
        unless ( $source_specified );
311
 
311
 
312
    #
312
    #
313
    #   Perform the Day0Operation
313
    #   Perform the Day0Operation
314
    #   These are specialised operations and normally only performed on the
314
    #   These are specialised operations and normally only performed on the
315
    #   the basic skelton.
315
    #   the basic skelton.
316
    #
316
    #
317
    #   Dispatch to the required function
317
    #   Dispatch to the required function
318
    #
318
    #
319
    my $opt = shift (@_);
319
    my $opt = shift (@_);
320
    if ( my $fref = UNIVERSAL::can ( 'Day0Ops', lc($opt) ) )
320
    if ( my $fref = UNIVERSAL::can ( 'Day0Ops', lc($opt) ) )
321
    {
321
    {
322
        &$fref( @_ );
322
        &$fref( @_ );
323
    }
323
    }
324
    else
324
    else
325
    {
325
    {
326
        Error ("Unknown Day0Operation option: $opt @_");
326
        Error ("Unknown Day0Operation option: $opt @_");
327
    }
327
    }
328
}
328
}
329
 
329
 
330
#-------------------------------------------------------------------------------
330
#-------------------------------------------------------------------------------
331
# Function        : Day0BuildImage
331
# Function        : Day0BuildImage
332
#
332
#
333
# Description     : Package up the created image as a tar-zip file
333
# Description     : Package up the created image as a tar-zip file
334
#                   This allows the Image to be processed again later
334
#                   This allows the Image to be processed again later
335
#
335
#
336
# Inputs          : Options
336
# Inputs          : Options
337
#                       --name=Name             - Output Name
337
#                       --name=Name             - Output Name
338
#
338
#
339
# Returns         : 
339
# Returns         : 
340
#
340
#
341
sub Day0BuildImage
341
sub Day0BuildImage
342
{
342
{
343
    my $name = 'Day0Image';
343
    my $name = 'Day0Image';
344
    Message ("Create File System Image; $name");
344
    Message ("Create File System Image; $name");
345
 
345
 
346
    #
346
    #
347
    #   Indicate that we have created some output
347
    #   Indicate that we have created some output
348
    #
348
    #
349
    Error ("Day0Source must be specified first")
349
    Error ("Day0Source must be specified first")
350
        unless ( $source_specified );
350
        unless ( $source_specified );
351
    $output_image++;
351
    $output_image++;
352
 
352
 
353
    #
353
    #
354
    #   Process user options
354
    #   Process user options
355
    #
355
    #
356
    foreach  ( @_ )
356
    foreach  ( @_ )
357
    {
357
    {
358
        if ( m~^--Name=(.+)~i ) {
358
        if ( m~^--Name=(.+)~i ) {
359
            $name = $1;
359
            $name = $1;
360
        } else {
360
        } else {
361
            Error ("Day0BuildImage: Unknown option: $_");
361
            Error ("Day0BuildImage: Unknown option: $_");
362
        }
362
        }
363
    }
363
    }
364
 
364
 
365
    #
365
    #
366
    #   Place the file in the BIN directory
366
    #   Place the file in the BIN directory
367
    #   Have no reall good reason
367
    #   Have no reall good reason
368
    #
368
    #
369
    $name = $opt_packagebindir . '/' . $name . '.tgz';
369
    $name = $opt_packagebindir . '/' . $name . '.tgz';
370
    CreateDir ( $opt_packagebindir);
370
    CreateDir ( $opt_packagebindir);
371
 
371
 
372
    #
372
    #
373
    #   Create a Tar command
373
    #   Create a Tar command
374
    #   Assumes the presence of a GNU style tar
374
    #   Assumes the presence of a GNU style tar
375
    #
375
    #
376
    System ( 'gtar',
376
    System ( 'gtar',
377
             '--create',
377
             '--create',
378
             '--file',  $name,
378
             '--file',  $name,
379
             '--gzip',
379
             '--gzip',
380
             IsVerbose(1) ? ( '--verbose' ) : (),
380
             IsVerbose(1) ? ( '--verbose' ) : (),
381
             '--directory', $WORK,
381
             '--directory', $WORK,
382
             '.' );
382
             '.' );
383
}
383
}
384
 
384
 
385
#-------------------------------------------------------------------------------
385
#-------------------------------------------------------------------------------
386
# Function        : Day0BuildSdImage
386
# Function        : Day0BuildSdImage
387
#
387
#
388
# Description     : Package up the created image and create an SD memory image
388
# Description     : Package up the created image and create an SD memory image
389
#                   This is destructive and can only be done one
389
#                   This is destructive and can only be done one
390
#
390
#
391
# Inputs          : Options
391
# Inputs          : Options
392
#                       --disk_blocks           - Size the output disk
392
#                       --disk_blocks           - Size the output disk
393
#                       --full_image            - Size of Full Image
393
#                       --full_image            - Size of Full Image
394
#                       --debug
394
#                       --debug
395
#
395
#
396
# Returns         : 
396
# Returns         : 
397
#
397
#
398
sub Day0BuildSdImage
398
sub Day0BuildSdImage
399
{
399
{
400
    my $debug;
400
    my $debug;
401
    my %diskGeometry = (
401
    my %diskGeometry = (
402
            fullfs  => 0,                   # Test Image Size
402
            fullfs  => 0,                   # Test Image Size
403
            size    => 501248,              # Block Size of Entire Disk
403
            size    => 501248,              # Block Size of Entire Disk
404
            rootfs  => 30,                  # Root Size (Megabytes)
404
            rootfs  => 30,                  # Root Size (Megabytes)
405
            logfs   => 20,                  # Log
405
            logfs   => 20,                  # Log
406
            afcfs   => 150,                 # AFC
406
            afcfs   => 150,                 # AFC
407
            varfs   => 'rest'               # Var - has the rest
407
            varfs   => 'rest'               # Var - has the rest
408
            );
408
            );
409
 
409
 
410
 
410
 
411
    #
411
    #
412
    #   Ensure that some work is being done
412
    #   Ensure that some work is being done
413
    #
413
    #
414
    Error ("Day0Source must be specified first")
414
    Error ("Day0Source must be specified first")
415
        unless ( $source_specified );
415
        unless ( $source_specified );
416
 
416
 
417
    Error ("Cannot create multiple SD images")
417
    Error ("Cannot create multiple SD images")
418
        if ( $output_sd++ );
418
        if ( $output_sd++ );
419
 
419
 
420
    #
420
    #
421
    #   Process user options
421
    #   Process user options
422
    #
422
    #
423
    foreach  ( @_ )
423
    foreach  ( @_ )
424
    {
424
    {
425
        if ( m~^--disk-blocks=(\d+)$~i ) {
425
        if ( m~^--disk-blocks=(\d+)$~i ) {
426
            $diskGeometry{'size'} = $1;
426
            $diskGeometry{'size'} = $1;
427
 
427
 
428
        } elsif ( m~^--full_image=(\d+)$~i ) {
428
        } elsif ( m~^--full_image=(\d+)$~i ) {
429
            $diskGeometry{'fullfs'} = $1;
429
            $diskGeometry{'fullfs'} = $1;
430
 
430
 
431
        } elsif ( m~^--rootfs=(\d+)$~i ) {
431
        } elsif ( m~^--rootfs=(\d+)$~i ) {
432
            $diskGeometry{'rootfs'} = $1;
432
            $diskGeometry{'rootfs'} = $1;
433
 
433
 
434
        } elsif ( m~^--logfs=(\d+)$~i ) {
434
        } elsif ( m~^--logfs=(\d+)$~i ) {
435
            $diskGeometry{'logfs'} = $1;
435
            $diskGeometry{'logfs'} = $1;
436
 
436
 
437
        } elsif ( m~^--afcfs=(\d+)$~i ) {
437
        } elsif ( m~^--afcfs=(\d+)$~i ) {
438
            $diskGeometry{'afcfs'} = $1;
438
            $diskGeometry{'afcfs'} = $1;
439
            
439
            
440
        } elsif ( m~^--varfs=~i ) {
440
        } elsif ( m~^--varfs=~i ) {
441
            Error ('Var File System cannot be configured');
441
            Error ('Var File System cannot be configured');
442
 
442
 
443
        } elsif ( m~^--debug~i ) {
443
        } elsif ( m~^--debug~i ) {
444
            $debug = 1;
444
            $debug = 1;
445
        } else {
445
        } else {
446
            Error ("Day0BuildSdImage: Unknown option: $_");
446
            Error ("Day0BuildSdImage: Unknown option: $_");
447
        }
447
        }
448
    }
448
    }
449
 
449
 
450
    #
450
    #
451
    #   Perform specific processing on the image
451
    #   Perform specific processing on the image
452
    #
452
    #
453
 
453
 
454
    #
454
    #
455
    #   Scan the skeleton and process .LINKS files
455
    #   Scan the skeleton and process .LINKS files
456
    #   File links do not store well in version control systems
456
    #   File links do not store well in version control systems
457
    #   NOTE: .LINKS are a local invention and not a part of e2fsimage like
457
    #   NOTE: .LINKS are a local invention and not a part of e2fsimage like
458
    #         .DEVICES on which they are modelled.
458
    #         .DEVICES on which they are modelled.
459
    #
459
    #
460
    Message ("Locate LINKFILES in $WORK");
460
    Message ("Locate LINKFILES in $WORK");
461
    foreach my $linkfile ( Internal::FindFiles( $WORK, ".LINKS" ))
461
    foreach my $linkfile ( Internal::FindFiles( $WORK, ".LINKS" ))
462
    {
462
    {
463
        my $BASEDIR = StripFileExt( $linkfile );
463
        my $BASEDIR = StripFileExt( $linkfile );
464
        $BASEDIR =~ s~^$WORK/~~;
464
        $BASEDIR =~ s~^$WORK/~~;
465
        Message "Expand links: $BASEDIR";
465
        Message "Expand links: $BASEDIR";
466
        open (LF, "<", $linkfile ) || Error ("Cannot open link file: $linkfile" );
466
        open (LF, "<", $linkfile ) || Error ("Cannot open link file: $linkfile" );
467
        while ( <LF> )
467
        while ( <LF> )
468
        {
468
        {
469
            chomp;
469
            chomp;
470
            next if ( m~^#~ );
470
            next if ( m~^#~ );
471
            next unless ( $_ );
471
            next unless ( $_ );
472
            my ($link, $file) = split;
472
            my ($link, $file) = split;
473
 
473
 
474
            Internal::MakeSymLink($file ,"$BASEDIR/$link", '--NoDotDot' );
474
            Internal::MakeSymLink($file ,"$BASEDIR/$link", '--NoDotDot' );
475
        }
475
        }
476
        close (LF);
476
        close (LF);
477
        unlink $linkfile;
477
        unlink $linkfile;
478
    }
478
    }
479
    
479
    
480
 
480
 
481
    #   Update the Shared Library Cache
481
    #   Update the Shared Library Cache
482
    #
482
    #
483
    Message ("Create Shared Library Cache");
483
    Message ("Create Shared Library Cache");
484
    System ('/sbin/ldconfig', '-r', $WORK );
484
    System ('/sbin/ldconfig', '-r', $WORK );
485
 
485
 
486
    #
486
    #
487
    #   Make every thing executable
487
    #   Make every thing executable
488
    #       This is good for directories
488
    #       This is good for directories
489
    #       This is good for all files. Shouldn't be an issue to files in /etc
489
    #       This is good for all files. Shouldn't be an issue to files in /etc
490
    #
490
    #
491
    Message ("Mark files as executable");
491
    Message ("Mark files as executable");
492
    foreach my $dir ( glob ("$WORK/*") )
492
    foreach my $dir ( glob ("$WORK/*") )
493
    {
493
    {
494
        next if ( $dir =~ m~/etc$~ );
494
        next if ( $dir =~ m~/etc$~ );
495
        System ('chmod', '-R', 'a+rx', $dir );
495
        System ('chmod', '-R', 'a+rx', $dir );
496
    }
496
    }
497
 
497
 
498
    foreach my $dir ( glob ("$WORK/etc/*") )
498
    foreach my $dir ( glob ("$WORK/etc/*") )
499
    {
499
    {
500
        next unless ( -d $dir );
500
        next unless ( -d $dir );
501
        System ('chmod', '-R', 'a+rx', $dir );
501
        System ('chmod', '-R', 'a+rx', $dir );
502
    }
502
    }
503
 
503
 
504
    #
504
    #
505
    #   Special considertaion
505
    #   Special considertaion
506
    #       /etc/busybox.conf   - Accessible by root
506
    #       /etc/busybox.conf   - Accessible by root
507
    #       /bin/busybox        - setuid
507
    #       /bin/busybox        - setuid
508
    #
508
    #
509
    System ('chmod', '600',  "$WORK/etc/busybox.conf" );
509
    System ('chmod', '600',  "$WORK/etc/busybox.conf" );
510
    System ('chmod', '4755', "$WORK/bin/busybox" );
510
    System ('chmod', '4755', "$WORK/bin/busybox" );
511
 
511
 
512
    #
512
    #
513
    #   Stop here if debugging
513
    #   Stop here if debugging
514
    #   Don't create the actual image as the process destroys the image
514
    #   Don't create the actual image as the process destroys the image
515
    #
515
    #
516
    Error ("Day0BuildSdImage: Debug Image. SD Image not built")
516
    Error ("Day0BuildSdImage: Debug Image. SD Image not built")
517
        if ( $debug );
517
        if ( $debug );
518
 
518
 
519
    #
519
    #
520
    #   Invoke SD build function
520
    #   Invoke SD build function
521
    #   Held in another package to make this one readable
521
    #   Held in another package to make this one readable
522
    #
522
    #
523
    my $name = "${opt_buildname}-${opt_version}-${opt_target}";
523
    my $name = "${opt_buildname}-${opt_version}-${opt_target}";
524
    CreateSdImage( $opt_packagebindir, $name, $WORK, $BUILD, \%diskGeometry );
524
    CreateSdImage( $opt_packagebindir, $name, $WORK, $BUILD, \%diskGeometry );
525
}
525
}
526
 
526
 
527
#-------------------------------------------------------------------------------
527
#-------------------------------------------------------------------------------
528
# Function        : AddInitScript
528
# Function        : AddInitScript
529
#
529
#
530
# Description     : Add an Init Script to the target
530
# Description     : Add an Init Script to the target
531
#                   Optionally create start and stop links
531
#                   Optionally create start and stop links
532
#
532
#
533
#                   Existing links will always be delete
533
#                   Existing links will always be delete
534
#
534
#
535
# Inputs          : $script     - Name of the init script
535
# Inputs          : $script     - Name of the init script
536
#                   $start      - Start Number
536
#                   $start      - Start Number
537
#                   $stop       - Stop Number
537
#                   $stop       - Stop Number
538
#                   Options:
538
#                   Options:
539
#                       --NoCopy    - Don't copy the script, just add links
539
#                       --NoCopy    - Don't copy the script, just add links
540
#
540
#
541
# Returns         : 
541
# Returns         : 
542
#
542
#
543
sub AddInitScript
543
sub AddInitScript
544
{
544
{
545
    my ( $script, $start, $stop, @opts ) = @_;
545
    my ( $script, $start, $stop, @opts ) = @_;
546
 
546
 
547
    Error ("Day0Source must be specified first")
547
    Error ("Day0Source must be specified first")
548
        unless ( $source_specified );
548
        unless ( $source_specified );
549
    
549
    
550
    Message ("AddInitScript: $script, $start, $stop");
550
    Message ("AddInitScript: $script, $start, $stop");
551
 
551
 
552
    my $tdir = "/etc/init.d/init.d";
552
    my $tdir = "/etc/init.d/init.d";
553
    my $base = StripDir($script);
553
    my $base = StripDir($script);
554
 
554
 
555
    unless ( grep '^--NoCopy', @opts )
555
    unless ( grep '^--NoCopy', @opts )
556
    {
556
    {
557
        ::CopyFile( $script, $tdir );
557
        ::CopyFile( $script, $tdir );
558
    }
558
    }
559
 
559
 
560
    #
560
    #
561
    #   Delete any existing links
561
    #   Delete any existing links
562
    #
562
    #
563
    foreach my $file ( glob("$WORK/etc/init.d/*$base") )
563
    foreach my $file ( glob("$WORK/etc/init.d/*$base") )
564
    {
564
    {
565
        next unless ( $file =~ m~/[KS][\d]+${base}~ );
565
        next unless ( $file =~ m~/[KS][\d]+${base}~ );
566
        unlink $file;
566
        unlink $file;
567
    }
567
    }
568
 
568
 
569
    my $link;
569
    my $link;
570
    if ( $start )
570
    if ( $start )
571
    {
571
    {
572
        $link = sprintf ("/etc/init.d/S%2.2d%s", $start, $base );
572
        $link = sprintf ("/etc/init.d/S%2.2d%s", $start, $base );
573
        Internal::MakeSymLink( "$tdir/$base", $link);
573
        Internal::MakeSymLink( "$tdir/$base", $link);
574
    }
574
    }
575
 
575
 
576
    if ( $stop )
576
    if ( $stop )
577
    {
577
    {
578
        $link = sprintf ("/etc/init.d/K%2.2d%s", $stop, $base );
578
        $link = sprintf ("/etc/init.d/K%2.2d%s", $stop, $base );
579
        Internal::MakeSymLink( "$tdir/$base", $link);
579
        Internal::MakeSymLink( "$tdir/$base", $link);
580
    }
580
    }
581
}
581
}
582
 
582
 
583
#-------------------------------------------------------------------------------
583
#-------------------------------------------------------------------------------
584
# Function        : EchoFile
584
# Function        : EchoFile
585
#
585
#
586
# Description     : Echo simple text to a file
586
# Description     : Echo simple text to a file
587
#
587
#
588
# Inputs          : $file   - Within the output workspace
588
# Inputs          : $file   - Within the output workspace
589
#                   $text
589
#                   $text
590
#
590
#
591
# Returns         : 
591
# Returns         : 
592
#
592
#
593
sub EchoFile
593
sub EchoFile
594
{
594
{
595
    my ($file, $text) = @_;
595
    my ($file, $text) = @_;
596
    Error ("Day0Source must be specified first")
596
    Error ("Day0Source must be specified first")
597
        unless ( $source_specified );
597
        unless ( $source_specified );
598
 
598
 
599
    $file = $WORK . '/' . $file;
599
    $file = $WORK . '/' . $file;
600
    $file =~ s~//~/~;
600
    $file =~ s~//~/~;
601
 
601
 
602
    unlink $file;
602
    unlink $file;
603
    open (DT, ">", $file ) || Error ("Cannot create $file");
603
    open (DT, ">", $file ) || Error ("Cannot create $file");
604
    print DT  $text || Error ("Cannot print to $file");
604
    print DT  $text || Error ("Cannot print to $file");
605
    close DT;
605
    close DT;
606
}
606
}
607
 
607
 
608
#-------------------------------------------------------------------------------
608
#-------------------------------------------------------------------------------
609
# Function        : CopyPkgDir
609
# Function        : CopyPkgDir
610
#
610
#
611
# Description     : Copy a directory to a target dir
611
# Description     : Copy a directory to a target dir
612
#                   Source directory is within a 'package'
612
#                   Source directory is within a 'package'
613
#                   Does not delete the target directory, but will add files
613
#                   Does not delete the target directory, but will add files
614
#
614
#
615
#                   Currently does not support
615
#                   Currently does not support
616
#                       Recursion
616
#                       Recursion
617
#                       Flattening
617
#                       Flattening
618
#
618
#
619
#
619
#
620
# Inputs          : $src_dir    - Within a package
620
# Inputs          : $src_dir    - Within a package
621
#                   $dst_dir    - Within the output workspace
621
#                   $dst_dir    - Within the output workspace
622
#
622
#
623
#                   Options:
623
#                   Options:
624
#                       --FilterIn=Filter           Simple filter
624
#                       --FilterIn=Filter           Simple filter
625
#                       --FilterOut=Filter          Simple filter
625
#                       --FilterOut=Filter          Simple filter
626
#
626
#
627
# Returns         :
627
# Returns         :
628
#
628
#
629
sub CopyPkgDir
629
sub CopyPkgDir
630
{
630
{
631
    my @filter_out;
631
    my @filter_out;
632
    my @filter_in;
632
    my @filter_in;
633
    my @args;
633
    my @args;
634
 
634
 
635
    Error ("Day0Source must be specified first")
635
    Error ("Day0Source must be specified first")
636
        unless ( $source_specified );
636
        unless ( $source_specified );
637
 
637
 
638
    #
638
    #
639
    #   Process options
639
    #   Process options
640
    #
640
    #
641
    foreach  ( @_ )
641
    foreach  ( @_ )
642
    {
642
    {
643
        if ( m/^--FilterIn=(.+)/ ) {
643
        if ( m/^--FilterIn=(.+)/ ) {
644
            push @filter_in, $1;
644
            push @filter_in, $1;
645
 
645
 
646
        } elsif ( m/^--FilterOut=(.+)/ ) {
646
        } elsif ( m/^--FilterOut=(.+)/ ) {
647
            push @filter_out, $1;
647
            push @filter_out, $1;
648
 
648
 
649
        } elsif ( m/^-/ ) {
649
        } elsif ( m/^-/ ) {
650
            Error("CopyPkgDir: Unknown option: $_");
650
            Error("CopyPkgDir: Unknown option: $_");
651
 
651
 
652
        } else {
652
        } else {
653
            push @args, $_;
653
            push @args, $_;
654
        }
654
        }
655
    }
655
    }
656
    my ($src_dir, $dst_dir) = @args;
656
    my ($src_dir, $dst_dir) = @args;
657
    #
657
    #
658
    #   Calculate the destination path
658
    #   Calculate the destination path
659
    #
659
    #
660
    $dst_dir = $WORK . '/' . $dst_dir;
660
    $dst_dir = $WORK . '/' . $dst_dir;
661
    $dst_dir =~ s~//~/~;
661
    $dst_dir =~ s~//~/~;
662
 
662
 
663
    #
663
    #
664
    #   Validate source dir
664
    #   Validate source dir
665
    #
665
    #
666
    my $full_src_dir = "$opt_interfacedir/$src_dir";
666
    my $full_src_dir = "$opt_interfacedir/$src_dir";
667
    Error("CopyPkgDir: Source dir not found: $src_dir") unless ( -d $full_src_dir );
667
    Error("CopyPkgDir: Source dir not found: $src_dir") unless ( -d $full_src_dir );
668
 
668
 
669
    #
669
    #
670
    #   Copy as required
670
    #   Copy as required
671
    #
671
    #
672
    CopyDir ( $full_src_dir, $dst_dir,
672
    CopyDir ( $full_src_dir, $dst_dir,
673
                    'Flatten' => 1,
673
                    'Flatten' => 1,
674
                    'NoSubDirs' => 1,
674
                    'NoSubDirs' => 1,
675
                    'Ignore' =>  \@filter_out,
675
                    'Ignore' =>  \@filter_out,
676
                    'Match' => \@filter_in,
676
                    'Match' => \@filter_in,
677
                    );
677
                    );
678
}
678
}
679
 
679
 
680
#-------------------------------------------------------------------------------
680
#-------------------------------------------------------------------------------
681
# Function        : CopyPackage
681
# Function        : CopyPackage
682
#
682
#
683
# Description     : Copy in files from a package located in the interface
683
# Description     : Copy in files from a package located in the interface
684
#                   directory.
684
#                   directory.
685
#
685
#
686
#                   The source directory may be:
686
#                   The source directory may be:
687
#                       pkg/<platform>
687
#                       pkg/<platform>
688
#                       pkg/<product>
688
#                       pkg/<product>
689
#                       pkg/<target>
689
#                       pkg/<target>
690
#
690
#
691
# Inputs          : $section    - Section to search
691
# Inputs          : $section    - Section to search
692
#                   $file       - Source Path within a package
692
#                   $file       - Source Path within a package
693
#                   @llist      - list of softlinks
693
#                   @llist      - list of softlinks
694
#                                 Abs or Relative to destination dir
694
#                                 Abs or Relative to destination dir
695
#
695
#
696
#                   Embedded Options:
696
#                   Embedded Options:
697
#                               --Dest=Dir (Default is taken from $file)
697
#                               --Dest=Dir (Default is taken from $file)
698
#                               --LinkFile (Append to .LINKS file)
698
#                               --LinkFile (Append to .LINKS file)
699
#                               --Rename=Name
699
#                               --Rename=Name
700
#
700
#
701
# Returns         :  Path to the target file
701
# Returns         :  Path to the target file
702
#
702
#
703
sub CopyPackage
703
sub CopyPackage
704
{
704
{
705
    my $dest;
705
    my $dest;
706
    my $isa_linkfile;
706
    my $isa_linkfile;
707
    my @args;
707
    my @args;
708
    my $dfile;
708
    my $dfile;
709
    my @options;
709
    my @options;
710
 
710
 
711
    Error ("Day0Source must be specified first")
711
    Error ("Day0Source must be specified first")
712
        unless ( $source_specified );
712
        unless ( $source_specified );
713
    
713
    
714
    #
714
    #
715
    #   Process and Remove options
715
    #   Process and Remove options
716
    #
716
    #
717
    foreach  ( @_ )
717
    foreach  ( @_ )
718
    {
718
    {
719
        if ( m/^--Dest=(.*)/ ) {
719
        if ( m/^--Dest=(.*)/ ) {
720
            $dest = $1 . '/xxx';
720
            $dest = $1 . '/xxx';
721
 
721
 
722
        } elsif ( m/^--LinkFile/ ) {
722
        } elsif ( m/^--LinkFile/ ) {
723
            $isa_linkfile = 1;
723
            $isa_linkfile = 1;
724
 
724
 
725
        } elsif ( m/^--Rename=(.+)/ ) {
725
        } elsif ( m/^--Rename=(.+)/ ) {
726
            push @options, $_;
726
            push @options, $_;
727
 
727
 
728
        } elsif ( m/^--/ ) {
728
        } elsif ( m/^--/ ) {
729
            Error ("CopyPackage: Unknown option: $_");
729
            Error ("CopyPackage: Unknown option: $_");
730
 
730
 
731
        } else {
731
        } else {
732
            push @args, $_;
732
            push @args, $_;
733
 
733
 
734
        }
734
        }
735
    }
735
    }
736
 
736
 
737
    my ($section, $file, @llist) = @args;
737
    my ($section, $file, @llist) = @args;
738
 
738
 
739
    #
739
    #
740
    #   Default destination is the same as the source
740
    #   Default destination is the same as the source
741
    #
741
    #
742
    $dest = $file unless ( $dest );
742
    $dest = $file unless ( $dest );
743
    my $dest_dir = StripFileExt($dest);
743
    my $dest_dir = StripFileExt($dest);
744
 
744
 
745
    my $tfile = Internal::LocateFile($section, $file);
745
    my $tfile = Internal::LocateFile($section, $file);
746
    Error ("CopyPackage: File not found: $file") unless $tfile;
746
    Error ("CopyPackage: File not found: $file") unless $tfile;
747
 
747
 
748
    #
748
    #
749
    #   LinkFiles are special
749
    #   LinkFiles are special
750
    #   They get concatenated to any existing Link File
750
    #   They get concatenated to any existing Link File
751
    #
751
    #
752
    if ( $isa_linkfile )
752
    if ( $isa_linkfile )
753
    {
753
    {
754
        CatFile ( $tfile, "$dest_dir/.LINKS" );
754
        CatFile ( $tfile, "$dest_dir/.LINKS" );
755
    }
755
    }
756
    else
756
    else
757
    {
757
    {
758
        $dfile = CopyFile ($tfile, $dest_dir, @options );
758
        $dfile = CopyFile ($tfile, $dest_dir, @options );
759
        foreach my $lname ( @llist )
759
        foreach my $lname ( @llist )
760
        {
760
        {
761
            $lname = $dest_dir . '/' . $lname unless ( $lname =~ m ~^/~ );
761
            $lname = $dest_dir . '/' . $lname unless ( $lname =~ m ~^/~ );
762
            my $dest_file = $dest_dir . '/' . StripDir($dfile);
762
            my $dest_file = $dest_dir . '/' . StripDir($dfile);
763
            Internal::MakeSymLink($dest_file ,$lname);
763
            Internal::MakeSymLink($dest_file ,$lname);
764
        }
764
        }
765
    }
765
    }
766
 
766
 
767
    return $dfile;
767
    return $dfile;
768
}
768
}
769
 
769
 
770
#-------------------------------------------------------------------------------
770
#-------------------------------------------------------------------------------
771
# Function        : CatFile
771
# Function        : CatFile
772
#
772
#
773
# Description     : Copy a file to the end of a file
773
# Description     : Copy a file to the end of a file
774
#
774
#
775
# Inputs          : $src
775
# Inputs          : $src
776
#                   $dst    - Within the output workspace
776
#                   $dst    - Within the output workspace
777
#
777
#
778
# Returns         :
778
# Returns         :
779
#
779
#
780
sub CatFile
780
sub CatFile
781
{
781
{
782
    my ($src, $dst) = @_;
782
    my ($src, $dst) = @_;
783
    $dst = $WORK . '/' . $dst;
783
    $dst = $WORK . '/' . $dst;
784
    $dst =~ s~//~/~;
784
    $dst =~ s~//~/~;
785
    Verbose ("CatFile: $src, $dst");
785
    Verbose ("CatFile: $src, $dst");
786
 
786
 
787
    Error ("Day0Source must be specified first")
787
    Error ("Day0Source must be specified first")
788
        unless ( $source_specified );
788
        unless ( $source_specified );
789
 
789
 
790
    open (SF, '<', $src)  || Error ("CatFile: Cannot open $src");
790
    open (SF, '<', $src)  || Error ("CatFile: Cannot open $src");
791
    open (DF, '>>', $dst) || Error ("CatFile: Cannot create:$dst");
791
    open (DF, '>>', $dst) || Error ("CatFile: Cannot create:$dst");
792
    while ( <SF> )
792
    while ( <SF> )
793
    {
793
    {
794
        print DF $_;
794
        print DF $_;
795
    }
795
    }
796
    close (SF);
796
    close (SF);
797
    close (DF);
797
    close (DF);
798
}
798
}
799
 
799
 
800
 
800
 
801
#-------------------------------------------------------------------------------
801
#-------------------------------------------------------------------------------
802
# Function        : CopyFile
802
# Function        : CopyFile
803
#
803
#
804
# Description     : Copy a file to a target dir
804
# Description     : Copy a file to a target dir
805
#
805
#
806
# Inputs          : $src
806
# Inputs          : $src
807
#                   $dst_dir    - Within the output workspace
807
#                   $dst_dir    - Within the output workspace
808
#                   Options     - Optional flags
808
#                   Options     - Optional flags
809
#                                 --Symlink
809
#                                 --Symlink
810
#                                   Copies symlink, not symlink target
810
#                                   Copies symlink, not symlink target
811
#                                 --Rename=xxx
811
#                                 --Rename=xxx
812
#                                   Renames file
812
#                                   Renames file
813
#
813
#
814
# Returns         : Full path to destination file
814
# Returns         : Full path to destination file
815
#
815
#
816
sub CopyFile
816
sub CopyFile
817
{
817
{
818
    my ($src, $dst_dir, @opts ) = @_;
818
    my ($src, $dst_dir, @opts ) = @_;
819
    my $tfile = StripDir($src);
819
    my $tfile = StripDir($src);
820
    my %opts;
820
    my %opts;
821
 
821
 
822
    Error ("Day0Source must be specified first")
822
    Error ("Day0Source must be specified first")
823
        unless ( $source_specified );
823
        unless ( $source_specified );
824
    
824
    
825
    #
825
    #
826
    #   Extract options
826
    #   Extract options
827
    #
827
    #
828
    foreach  ( @opts )
828
    foreach  ( @opts )
829
    {
829
    {
830
        if ( m/^--Symlink/ ) {
830
        if ( m/^--Symlink/ ) {
831
            $opts{DuplicateLinks} = 1;
831
            $opts{DuplicateLinks} = 1;
832
 
832
 
833
        } elsif ( m/^--Rename=(.+)/ ) {
833
        } elsif ( m/^--Rename=(.+)/ ) {
834
            $tfile = $1;
834
            $tfile = $1;
835
 
835
 
836
        } else {
836
        } else {
837
            Error("CopyFile: Unknown option: $_");
837
            Error("CopyFile: Unknown option: $_");
838
        }
838
        }
839
    }
839
    }
840
 
840
 
841
    #
841
    #
842
    #   Calculate the destination path
842
    #   Calculate the destination path
843
    #
843
    #
844
    $dst_dir = $WORK . '/' . $dst_dir;
844
    $dst_dir = $WORK . '/' . $dst_dir;
845
    $dst_dir =~ s~//~/~;
845
    $dst_dir =~ s~//~/~;
846
 
846
 
847
    #
847
    #
848
    #   Determine the full name of the target
848
    #   Determine the full name of the target
849
    #
849
    #
850
    my $dst_file = "$dst_dir/$tfile";
850
    my $dst_file = "$dst_dir/$tfile";
851
 
851
 
852
    Verbose ("CopyFile: $src, $dst_dir");
852
    Verbose ("CopyFile: $src, $dst_dir");
853
    return JatsCopy::CopyFile( $src, $dst_file, \%opts );
853
    return JatsCopy::CopyFile( $src, $dst_file, \%opts );
854
}
854
}
855
 
855
 
856
#-------------------------------------------------------------------------------
856
#-------------------------------------------------------------------------------
857
# Function        : AUTOLOAD
857
# Function        : AUTOLOAD
858
#
858
#
859
# Description     : Intercept bad user directives and issue a nice error message
859
# Description     : Intercept bad user directives and issue a nice error message
860
#                   This is a simple routine to report unknown user directives
860
#                   This is a simple routine to report unknown user directives
861
#                   It does not attempt to distinguish between user errors and
861
#                   It does not attempt to distinguish between user errors and
862
#                   programming errors. It assumes that the program has been
862
#                   programming errors. It assumes that the program has been
863
#                   tested. The function simply report filename and line number
863
#                   tested. The function simply report filename and line number
864
#                   of the bad directive.
864
#                   of the bad directive.
865
#
865
#
866
# Inputs          : Original function arguments ( not used )
866
# Inputs          : Original function arguments ( not used )
867
#
867
#
868
# Returns         : This function does not return
868
# Returns         : This function does not return
869
#
869
#
870
sub AUTOLOAD
870
sub AUTOLOAD
871
{
871
{
872
    my $fname = $::AUTOLOAD;
872
    my $fname = $::AUTOLOAD;
873
    $fname =~ s~^\w+::~~;
873
    $fname =~ s~^\w+::~~;
874
    my ($package, $filename, $line) = caller;
874
    my ($package, $filename, $line) = caller;
875
 
875
 
876
    Error ("Directive not known or not allowed in this context: $fname",
876
    Error ("Directive not known or not allowed in this context: $fname",
877
           "Directive: $fname( @_ );",
877
           "Directive: $fname( @_ );",
878
           "File: $filename, Line: $line" );
878
           "File: $filename, Line: $line" );
879
}
879
}
880
 
880
 
881
 
881
 
882
#-------------------------------------------------------------------------------
882
#-------------------------------------------------------------------------------
883
# Function        : FirstBoot
883
# Function        : FirstBoot
884
#
884
#
885
# Description     : Add a file to the first boot section
885
# Description     : Add a file to the first boot section
886
#                   Assumes that the firstboot directory is /var/afc/firstboot
886
#                   Assumes that the firstboot directory is /var/afc/firstboot
887
#                   This is the default
887
#                   This is the default
888
#
888
#
889
# Inputs          : All options
889
# Inputs          : All options
890
#                       --Debian=xxx[,opts] - Locate debian package
890
#                       --Debian=xxx[,opts] - Locate debian package
891
#                                             Sub opts are:
891
#                                             Sub opts are:
892
#                                               --Arch=xxx
892
#                                               --Arch=xxx
893
#                                               --Product=xxx
893
#                                               --Product=xxx
894
#                                               --Debug
894
#                                               --Debug
895
#                                               --Prod
895
#                                               --Prod
896
#                       --File=yyy          - Locate a files
896
#                       --File=yyy          - Locate a files
897
#                       --Level=nn          - Level to run (default=50)
897
#                       --Level=nn          - Level to run (default=50)
898
#
898
#
899
# Returns         : 
899
# Returns         : 
900
#
900
#
901
sub FirstBoot
901
sub FirstBoot
902
{
902
{
903
    my  $file;
903
    my  $file;
904
    my  $level = 50;
904
    my  $level = 50;
905
 
905
 
906
    Error ("Day0Source must be specified first")
906
    Error ("Day0Source must be specified first")
907
        unless ( $source_specified );
907
        unless ( $source_specified );
908
    
908
    
909
    #
909
    #
910
    #   Collect user items
910
    #   Collect user items
911
    #
911
    #
912
    foreach ( @_ )
912
    foreach ( @_ )
913
    {
913
    {
914
        if ( m~^--Debian=(.+)~ ) {
914
        if ( m~^--Debian=(.+)~ ) {
915
            Error ("FirstBoot: Multiple source files not supported in one directive: $_") if $file;
915
            Error ("FirstBoot: Multiple source files not supported in one directive: $_") if $file;
916
            $file = Internal::LocateDebianFile($1, $opt_target, $opt_product);
916
            $file = Internal::LocateDebianFile($1, $opt_target, $opt_product);
917
 
917
 
918
        } elsif ( m~^--File=(.+)~ ) {
918
        } elsif ( m~^--File=(.+)~ ) {
919
            Error ("FirstBoot: Multiple source files not supported in one directive: $_") if $file;
919
            Error ("FirstBoot: Multiple source files not supported in one directive: $_") if $file;
920
            $file = $1;
920
            $file = $1;
921
 
921
 
922
        } elsif ( m~^--Level=(\d+)~ ) {
922
        } elsif ( m~^--Level=(\d+)~ ) {
923
            $level = $1;
923
            $level = $1;
924
            Error ("FirstBoot: Invalid Level: $_") if ($level < 0 || $level > 99);
924
            Error ("FirstBoot: Invalid Level: $_") if ($level < 0 || $level > 99);
925
 
925
 
926
        } else {
926
        } else {
927
            Error ("FirstBoot: Unknown option or argument: $_");
927
            Error ("FirstBoot: Unknown option or argument: $_");
928
        }
928
        }
929
    }
929
    }
930
 
930
 
931
    #
931
    #
932
    #   Insert the required file
932
    #   Insert the required file
933
    #       Prepend name with a two digit level
933
    #       Prepend name with a two digit level
934
    #
934
    #
935
    my $fname = sprintf ('%2.2d.%s', $level, StripDir($file)  );
935
    my $fname = sprintf ('%2.2d.%s', $level, StripDir($file)  );
936
    Message ("FirstBoot: $fname");
936
    Message ("FirstBoot: $fname");
937
    
937
    
938
    CopyFile ( $file, '/var/afc/firstboot', "--Rename=$fname" );
938
    CopyFile ( $file, '/var/afc/firstboot', "--Rename=$fname" );
939
}
939
}
940
 
940
 
941
################################################################################
941
################################################################################
942
################################################################################
942
################################################################################
943
#   
943
#   
944
#   Package to contain DayOp opereration
944
#   Package to contain DayOp opereration
945
#
945
#
946
package Day0Ops;
946
package Day0Ops;
947
 
947
 
948
use strict;
948
use strict;
949
use warnings;
949
use warnings;
950
 
950
 
951
 
951
 
952
use JatsError;
952
use JatsError;
953
use JatsSystem;
953
use JatsSystem;
954
use JatsCopy qw(SetCopyDirDefaults DeleteDir CopyDir CreateDir);
954
use JatsCopy qw(SetCopyDirDefaults DeleteDir CopyDir CreateDir);
955
 
955
 
956
#-------------------------------------------------------------------------------
956
#-------------------------------------------------------------------------------
957
# Function        : hostname
957
# Function        : hostname
958
#
958
#
959
# Description     : Insert hostname information into the target
959
# Description     : Insert hostname information into the target
960
#                       Insert /etc/devicetype
960
#                       Insert /etc/devicetype
961
#                       Insert into hostname too
961
#                       Insert into hostname too
962
#
962
#
963
#
963
#
964
# Inputs          : 
964
# Inputs          : 
965
#
965
#
966
# Returns         : 
966
# Returns         : 
967
#
967
#
968
sub hostname
968
sub hostname
969
{
969
{
970
    Message ("Insert Hostname an Devicename: ${opt_product}");
970
    Message ("Insert Hostname an Devicename: ${opt_product}");
971
    ::EchoFile ( "/etc/devicetype", $opt_product );
971
    ::EchoFile ( "/etc/devicetype", $opt_product );
972
    ::EchoFile ( "/etc/hostname", $opt_product );
972
    ::EchoFile ( "/etc/hostname", $opt_product );
973
    ::EchoFile ( "/etc/day0-version", "$opt_buildname $opt_version $opt_product $opt_platform $opt_target" );
973
    ::EchoFile ( "/etc/day0-version", "$opt_buildname $opt_version $opt_product $opt_platform $opt_target" );
974
}
974
}
975
 
975
 
976
#-------------------------------------------------------------------------------
976
#-------------------------------------------------------------------------------
977
# Function        : setupbusybox
977
# Function        : setupbusybox
978
#
978
#
979
# Description     : Insert busybox into the skeleton
979
# Description     : Insert busybox into the skeleton
980
#                   Locate busybox and associated links file
980
#                   Locate busybox and associated links file
981
#
981
#
982
# Inputs          : None
982
# Inputs          : None
983
#
983
#
984
# Returns         : Nothing
984
# Returns         : Nothing
985
#
985
#
986
sub setupbusybox
986
sub setupbusybox
987
{
987
{
988
    #
988
    #
989
    #   Insert busybox into the skeleton
989
    #   Insert busybox into the skeleton
990
    #   Locate busybox and associated links file
990
    #   Locate busybox and associated links file
991
    #
991
    #
992
    Message ("Copy in busybox");
992
    Message ("Copy in busybox");
993
    my $bbfile  = ::CopyPackage ('bin', 'busybox',       "--Dest=bin" );
993
    my $bbfile  = ::CopyPackage ('bin', 'busybox',       "--Dest=bin" );
994
    my $bblinks = ::CopyPackage ('bin', 'busybox.links', "--Dest=bin" );
994
    my $bblinks = ::CopyPackage ('bin', 'busybox.links', "--Dest=bin" );
995
 
995
 
996
    #
996
    #
997
    #   Expand the busybox links
997
    #   Expand the busybox links
998
    #   Use soft links. Expect that they will be easier to update in the field
998
    #   Use soft links. Expect that they will be easier to update in the field
999
    #   Keep the .links file on the target.
999
    #   Keep the .links file on the target.
1000
    #
1000
    #
1001
    Message "Expand busybox links";
1001
    Message "Expand busybox links";
1002
    open ( BBLINK, "<", $bblinks ) || Error ("Cannot open BusyBox Links file");
1002
    open ( BBLINK, "<", $bblinks ) || Error ("Cannot open BusyBox Links file");
1003
    while ( <BBLINK> )
1003
    while ( <BBLINK> )
1004
    {
1004
    {
1005
        s~\s+~~;
1005
        s~\s+~~;
1006
        Internal::MakeSymLink ("/bin/busybox", $_, '--NoDotDot'  );
1006
        Internal::MakeSymLink ("/bin/busybox", $_, '--NoDotDot'  );
1007
    }
1007
    }
1008
    close BBLINK;
1008
    close BBLINK;
1009
 
1009
 
1010
    #
1010
    #
1011
    #   May want to convert busybox.links into a .LINKS file and process
1011
    #   May want to convert busybox.links into a .LINKS file and process
1012
    #   it when we instantiate the file system
1012
    #   it when we instantiate the file system
1013
    #
1013
    #
1014
 
1014
 
1015
}
1015
}
1016
 
1016
 
1017
#-------------------------------------------------------------------------------
1017
#-------------------------------------------------------------------------------
1018
# Function        : upgrade
1018
# Function        : upgrade
1019
#
1019
#
1020
# Description     : Insert day0 upgrade components
1020
# Description     : Insert day0 upgrade components
1021
#
1021
#
1022
# Inputs          : None
1022
# Inputs          : None
1023
#
1023
#
1024
# Returns         : Nothing
1024
# Returns         : Nothing
1025
#
1025
#
1026
sub upgrade
1026
sub upgrade
1027
{
1027
{
1028
    Message ("Copy in day0 upgrade");
1028
    Message ("Copy in day0 upgrade");
1029
    my $DAY0BIN="/afc/day-zero/bin";       #/day-zero
1029
    my $DAY0BIN="/afc/day-zero/bin";       #/day-zero
1030
 
1030
 
1031
    ::CopyPackage ('bin',     "--Dest=$DAY0BIN", 'udp_broadcast' );
1031
    ::CopyPackage ('bin',     "--Dest=$DAY0BIN", 'udp_broadcast' );
1032
    ::CopyPackage ('bin',     "--Dest=$DAY0BIN", 'udp_listen' );
1032
    ::CopyPackage ('bin',     "--Dest=$DAY0BIN", 'udp_listen' );
1033
    ::CopyPackage ('scripts', "--Dest=$DAY0BIN", 'day-zero.conf' );
1033
    ::CopyPackage ('scripts', "--Dest=$DAY0BIN", 'day-zero.conf' );
1034
    ::CopyPackage ('scripts', "--Dest=$DAY0BIN", 'day-zero.sh', 'day-zero' );
1034
    ::CopyPackage ('scripts', "--Dest=$DAY0BIN", 'day-zero.sh', 'day-zero' );
1035
 
1035
 
1036
    #
1036
    #
1037
    #   Start Day-Zero Service
1037
    #   Start Day-Zero Service
1038
    #   The service script is a part of the skeleton
1038
    #   The service script is a part of the skeleton
1039
    #
1039
    #
1040
    ::AddInitScript ("day-zero"   , 95, 100-95, "--NoCopy" );
1040
    ::AddInitScript ("day-zero"   , 95, 100-95, "--NoCopy" );
1041
}
1041
}
1042
 
1042
 
1043
#-------------------------------------------------------------------------------
1043
#-------------------------------------------------------------------------------
1044
# Function        : dams
1044
# Function        : dams
1045
#
1045
#
1046
# Description     : Insert DAMS
1046
# Description     : Insert DAMS
1047
#                   Only sutable for single exe versions
1047
#                   Only sutable for single exe versions
1048
#
1048
#
1049
# Inputs          : 
1049
# Inputs          : 
1050
#
1050
#
1051
# Returns         : 
1051
# Returns         : 
1052
#
1052
#
1053
sub dams
1053
sub dams
1054
{
1054
{
1055
    Message ("Copy in DAMS");
1055
    Message ("Copy in DAMS");
1056
    ::CopyPackage ('bin',     "--Dest=/afc/dams/bin", 'dams' );
1056
    ::CopyPackage ('bin',     "--Dest=/afc/dams/bin", 'dams' );
1057
}
1057
}
1058
 
1058
 
1059
#-------------------------------------------------------------------------------
1059
#-------------------------------------------------------------------------------
1060
# Function        : wirelesstools
1060
# Function        : wirelesstools
1061
#
1061
#
1062
# Description     : Insert wireless tools
1062
# Description     : Insert wireless tools
1063
#                   This is a multi-call binary
1063
#                   This is a multi-call binary
1064
# Inputs          :
1064
# Inputs          :
1065
#
1065
#
1066
# Returns         : 
1066
# Returns         : 
1067
#
1067
#
1068
sub wirelesstools
1068
sub wirelesstools
1069
{
1069
{
1070
    Message ("Copy in wireless tools");
1070
    Message ("Copy in wireless tools");
1071
 
1071
 
1072
    ::CopyPackage ('bin', 'ifrename'  , "--Dest=/sbin");
1072
    ::CopyPackage ('bin', 'ifrename'  , "--Dest=/sbin");
1073
    ::CopyPackage ('bin', 'iwconfig'  , "--Dest=/sbin");
1073
    ::CopyPackage ('bin', 'iwconfig'  , "--Dest=/sbin");
1074
    ::CopyPackage ('bin', 'iwevent'   , "--Dest=/sbin");
1074
    ::CopyPackage ('bin', 'iwevent'   , "--Dest=/sbin");
1075
    ::CopyPackage ('bin', 'iwgetid'   , "--Dest=/sbin");
1075
    ::CopyPackage ('bin', 'iwgetid'   , "--Dest=/sbin");
1076
    ::CopyPackage ('bin', 'iwlist'    , "--Dest=/sbin");
1076
    ::CopyPackage ('bin', 'iwlist'    , "--Dest=/sbin");
1077
    ::CopyPackage ('bin', 'iwpriv'    , "--Dest=/sbin");
1077
    ::CopyPackage ('bin', 'iwpriv'    , "--Dest=/sbin");
1078
    ::CopyPackage ('bin', 'iwspy'     , "--Dest=/sbin");
1078
    ::CopyPackage ('bin', 'iwspy'     , "--Dest=/sbin");
1079
}
1079
}
1080
 
1080
 
1081
#-------------------------------------------------------------------------------
1081
#-------------------------------------------------------------------------------
1082
# Function        : zd1211
1082
# Function        : zd1211
1083
#
1083
#
1084
# Description     : Copy in the zd1211 support files
1084
# Description     : Copy in the zd1211 support files
1085
#
1085
#
1086
# Inputs          : 
1086
# Inputs          : 
1087
#
1087
#
1088
# Returns         : 
1088
# Returns         : 
1089
#
1089
#
1090
 
1090
 
1091
sub zd1211
1091
sub zd1211
1092
{
1092
{
1093
    Message ("Copy in zd1211 firmware");
1093
    Message ("Copy in zd1211 firmware");
1094
    ::CopyPkgDir  ( 'pkg/zd1211', '/lib/firmware/zd1211', '--FilterOut=READ*' );
1094
    ::CopyPkgDir  ( 'pkg/zd1211', '/lib/firmware/zd1211', '--FilterOut=READ*' );
1095
 
1095
 
1096
    #
1096
    #
1097
    #   Install the start up script
1097
    #   Install the start up script
1098
    #   This will be delivered by the kernel package
1098
    #   This will be delivered by the kernel package
1099
    #
1099
    #
1100
    ::AddInitScript ("$opt_interfacedir/etc/zd1211", 41, 100-41 );
1100
    ::AddInitScript ("$opt_interfacedir/etc/zd1211", 41, 100-41 );
1101
}
1101
}
1102
 
1102
 
1103
#-------------------------------------------------------------------------------
1103
#-------------------------------------------------------------------------------
1104
# Function        : kernelmodules
1104
# Function        : kernelmodules
1105
#
1105
#
1106
# Description     : Insert Kernel Modules
1106
# Description     : Insert Kernel Modules
1107
#                   Note: The EMU flavour does not have any kernel modules (yet)
1107
#                   Note: The EMU flavour does not have any kernel modules (yet)
1108
#                          Allow for no files to be present or copied
1108
#                          Allow for no files to be present or copied
1109
#
1109
#
1110
# Inputs          : 
1110
# Inputs          : 
1111
#
1111
#
1112
# Returns         : 
1112
# Returns         : 
1113
#
1113
#
1114
sub kernelmodules
1114
sub kernelmodules
1115
{
1115
{
1116
    Message ("Copy in Kernel Modules");
1116
    Message ("Copy in Kernel Modules");
1117
    CopyDir ( "${opt_interfacedir}/bin", "$WORK/lib/modules",
1117
    CopyDir ( "${opt_interfacedir}/bin", "$WORK/lib/modules",
1118
                    'Flatten' => 1,
1118
                    'Flatten' => 1,
1119
                    'Match' => [ '*.ko' ],
1119
                    'Match' => [ '*.ko' ],
1120
                    'Log' => 1,
1120
                    'Log' => 1,
1121
                     );
1121
                     );
1122
}
1122
}
1123
 
1123
 
1124
#-------------------------------------------------------------------------------
1124
#-------------------------------------------------------------------------------
1125
# Function        : e2fsprogs
1125
# Function        : e2fsprogs
1126
#
1126
#
1127
# Description     : Insert e2fsprogs
1127
# Description     : Insert e2fsprogs
1128
#                   Busybox 1.4.2 and later does not provide these utilities
1128
#                   Busybox 1.4.2 and later does not provide these utilities
1129
#                   so they have been built up.
1129
#                   so they have been built up.
1130
#
1130
#
1131
# Inputs          :
1131
# Inputs          :
1132
#
1132
#
1133
# Returns         : 
1133
# Returns         : 
1134
#
1134
#
1135
sub e2fsprogs
1135
sub e2fsprogs
1136
{
1136
{
1137
    #
1137
    #
1138
    #   Only install the files that are needed
1138
    #   Only install the files that are needed
1139
    #
1139
    #
1140
    Message        ("Copy in e2fsprogs");
1140
    Message        ("Copy in e2fsprogs");
1141
    ::CopyPackage    ('pkg', "/etc/mke2fs.conf");
1141
    ::CopyPackage    ('pkg', "/etc/mke2fs.conf");
1142
    ::CopyPackage    ('pkg', "/sbin/fsck");
1142
    ::CopyPackage    ('pkg', "/sbin/fsck");
1143
    ::CopyPackage    ('pkg', "/sbin/tune2fs"   ,"e2label"   ,"findfs");
1143
    ::CopyPackage    ('pkg', "/sbin/tune2fs"   ,"e2label"   ,"findfs");
1144
    ::CopyPackage    ('pkg', "/sbin/mke2fs"    ,"mkfs.ext2" ,"mkfs.ext3");
1144
    ::CopyPackage    ('pkg', "/sbin/mke2fs"    ,"mkfs.ext2" ,"mkfs.ext3");
1145
    ::CopyPackage    ('pkg', "/sbin/e2fsck"    ,"fsck.ext2" ,"fsck.ext3");
1145
    ::CopyPackage    ('pkg', "/sbin/e2fsck"    ,"fsck.ext2" ,"fsck.ext3");
1146
    #::CopyPackage   ('pkg', "/sbin/badblocks");
1146
    #::CopyPackage   ('pkg', "/sbin/badblocks");
1147
    #::CopyPackage   ('pkg', "/sbin/blkid");
1147
    #::CopyPackage   ('pkg', "/sbin/blkid");
1148
    #::CopyPackage   ('pkg', "/sbin/debugfs");
1148
    #::CopyPackage   ('pkg', "/sbin/debugfs");
1149
    #::CopyPackage   ('pkg', "/sbin/dumpe2fs");
1149
    #::CopyPackage   ('pkg', "/sbin/dumpe2fs");
1150
    #::CopyPackage   ('pkg', "/sbin/logsave");
1150
    #::CopyPackage   ('pkg', "/sbin/logsave");
1151
    ::CopyPackage    ('pkg', "/sbin/resize2fs");
1151
    ::CopyPackage    ('pkg', "/sbin/resize2fs");
1152
}
1152
}
1153
 
1153
 
1154
#-------------------------------------------------------------------------------
1154
#-------------------------------------------------------------------------------
1155
# Function        : compilerruntime
1155
# Function        : compilerruntime
1156
#
1156
#
1157
# Description     : Copy in the runtime shared libraries provided by the compiler
1157
# Description     : Copy in the runtime shared libraries provided by the compiler
1158
#                       Many libraries are also symlinked
1158
#                       Many libraries are also symlinked
1159
#                       Need to ensure that the linkis copied
1159
#                       Need to ensure that the linkis copied
1160
#
1160
#
1161
#                       Strip many ( but not all) of the libaries
1161
#                       Strip many ( but not all) of the libaries
1162
#                       Some are special
1162
#                       Some are special
1163
# Inputs          : 
1163
# Inputs          : 
1164
#
1164
#
1165
# Returns         : 
1165
# Returns         : 
1166
#
1166
#
1167
sub compilerruntime
1167
sub compilerruntime
1168
{
1168
{
1169
    Message ("Copy in Compiler Shared Libaries");
1169
    Message ("Copy in Compiler Shared Libaries");
1170
    my @slibs;
1170
    my @slibs;
1171
    JatsCopy::CopyDir( $CROSSLIBS, "$WORK/lib",
1171
    JatsCopy::CopyDir( $CROSSLIBS, "$WORK/lib",
1172
                            'Flatten' => 1,
1172
                            'Flatten' => 1,
1173
                            'NoSubDirs' => 1,
1173
                            'NoSubDirs' => 1,
1174
                            'DuplicateLinks' => 1,
1174
                            'DuplicateLinks' => 1,
1175
                            'Match' => [ '*.so', '*.so.*[0-9]' ],
1175
                            'Match' => [ '*.so', '*.so.*[0-9]' ],
1176
                            'FileList' => \@slibs,
1176
                            'FileList' => \@slibs,
1177
                            );
1177
                            );
1178
 
1178
 
1179
 
1179
 
1180
    foreach my $file (@slibs)
1180
    foreach my $file (@slibs)
1181
    {
1181
    {
1182
        next if ( -d $file );
1182
        next if ( -d $file );
1183
        next if ( -l $file );
1183
        next if ( -l $file );
1184
        next if ( $file =~ m~libc.so$~ );
1184
        next if ( $file =~ m~libgcc_s.so$~ );
1185
        next if ( $file =~ m~libpthread.so$~ );
1185
        next if ( $file =~ m~libc.so$~ );
1186
        next if ( $file =~ m~libthread_db.*\.so~ );         # Needs symbols
1186
        next if ( $file =~ m~libpthread.so$~ );
1187
        Verbose ("Stripping: $file");
1187
        next if ( $file =~ m~libthread_db.*\.so~ );         # Needs symbols
1188
        System ($CROSS_STRIP, $file );
1188
        Verbose ("Stripping: $file");
1189
    }
1189
        System ($CROSS_STRIP, $file );
1190
 
1190
    }
1191
    #
1191
 
1192
    #   Copy in ldconfig
1192
    #
1193
    #
1193
    #   Copy in ldconfig
1194
    Message ("Copy in the ldconfig utility");
1194
    #
1195
    ::CopyFile ( "${CROSSEXE}/sbin/ldconfig", "/sbin" );
1195
    Message ("Copy in the ldconfig utility");
1196
}
1196
#    ::CopyFile ( "${CROSSEXE}/sbin/ldconfig", "/sbin" );
1197
 
1197
    ::CopyFile ( "${CROSSEXE}/sbin/ldconfig",          "/sbin" ) if (${CROSSEXE} =~ m~gcc-4\.1\.1-glibc-2\.5~);
1198
#-------------------------------------------------------------------------------
1198
    ::CopyFile ( "${CROSSEXE}/sys-root/sbin/ldconfig", "/sbin" ) if (${CROSSEXE} =~ m~gcc-4\.4\.3-glibc-2\.9~);
1199
# Function        : grub
1199
}
1200
#
1200
 
1201
# Description     : Install grub related files, if requested by the user
1201
#-------------------------------------------------------------------------------
1202
#
1202
# Function        : grub
1203
# Inputs          : Options
1203
#
1204
#                       --Menu=file             - Found locally
1204
# Description     : Install grub related files, if requested by the user
1205
#                       --Kernel=file           - Found in Bin
1205
#
1206
#
1206
# Inputs          : Options
1207
# Returns         : 
1207
#                       --Menu=file             - Found locally
1208
#
1208
#                       --Kernel=file           - Found in Bin
1209
sub grub
1209
#
1210
{
1210
# Returns         : 
1211
    my $menu;
1211
#
1212
    my $kernel;
1212
sub grub
1213
 
1213
{
1214
    Message ("Installing Grub");
1214
    my $menu;
1215
 
1215
    my $kernel;
1216
    #
1216
 
1217
    #   Extract options
1217
    Message ("Installing Grub");
1218
    #
1218
 
1219
    foreach ( @_ )
1219
    #
1220
    {
1220
    #   Extract options
1221
        if ( m~^--Menu=(.+)~ ) {
1221
    #
1222
            $menu = $1;
1222
    foreach ( @_ )
1223
        } elsif ( m~^--Kernel=(.+)~ ) {
1223
    {
1224
            $kernel = $1;
1224
        if ( m~^--Menu=(.+)~ ) {
1225
        } else {
1225
            $menu = $1;
1226
            Error ("Day0 Grub: Unknown option: $_");
1226
        } elsif ( m~^--Kernel=(.+)~ ) {
1227
        }
1227
            $kernel = $1;
1228
    }
1228
        } else {
1229
 
1229
            Error ("Day0 Grub: Unknown option: $_");
1230
    Error ("Day0 Grub: No Menu file specified") unless ( $menu );
1230
        }
1231
    Error ("Day0 Grub: No Kernel file specified") unless ( $kernel );
1231
    }
1232
 
1232
 
1233
    ::CopyPackage ( 'pkg', '/boot/grub/grub');                     # Not really needed
1233
    Error ("Day0 Grub: No Menu file specified") unless ( $menu );
1234
    ::CopyPackage ( 'pkg', '/boot/grub/stage1');                   # These are ..
1234
    Error ("Day0 Grub: No Kernel file specified") unless ( $kernel );
1235
    ::CopyPackage ( 'pkg', '/boot/grub/stage2');
1235
 
1236
    ::CopyPackage ( 'pkg', '/boot/grub/e2fs_stage1_5');
1236
    ::CopyPackage ( 'pkg', '/boot/grub/grub');                     # Not really needed
1237
 
1237
    ::CopyPackage ( 'pkg', '/boot/grub/stage1');                   # These are ..
1238
    #
1238
    ::CopyPackage ( 'pkg', '/boot/grub/stage2');
1239
    #   Copy in the user specified boot related files
1239
    ::CopyPackage ( 'pkg', '/boot/grub/e2fs_stage1_5');
1240
    #
1240
 
1241
    ::CopyFile   ( $menu,  '/boot/grub' );
1241
    #
1242
    ::CopyPackage ('bin', $kernel, '--Dest=/boot');
1242
    #   Copy in the user specified boot related files
1243
    
1243
    #
1244
}
1244
    ::CopyFile   ( $menu,  '/boot/grub' );
1245
 
1245
    ::CopyPackage ('bin', $kernel, '--Dest=/boot');
1246
 
1246
    
1247
 
1247
}
1248
################################################################################
1248
 
1249
################################################################################
1249
 
1250
#
1250
 
1251
#   Package to contain Internal functions
1251
################################################################################
1252
#   Functions placed here are not available to the user in the user scripts
1252
################################################################################
1253
#   They have been placed here simply to hide them from the user
1253
#
1254
#
1254
#   Package to contain Internal functions
1255
#
1255
#   Functions placed here are not available to the user in the user scripts
1256
package Internal;
1256
#   They have been placed here simply to hide them from the user
1257
 
1257
#
1258
use strict;
1258
#
1259
use warnings;
1259
package Internal;
1260
 
1260
 
1261
use File::Find;
1261
use strict;
1262
use JatsError;
1262
use warnings;
1263
use FileUtils;
1263
 
1264
 
1264
use File::Find;
1265
#-------------------------------------------------------------------------------
1265
use JatsError;
1266
# Function        : MakeSymLink
1266
use FileUtils;
1267
#
1267
 
1268
# Description     : Create a symlink - with error detection
1268
#-------------------------------------------------------------------------------
1269
#
1269
# Function        : MakeSymLink
1270
# Inputs          : old_file    - Link Target
1270
#
1271
#                                 Path to the link target
1271
# Description     : Create a symlink - with error detection
1272
#                                 If an ABS path is provided, the routine will
1272
#
1273
#                                 attempt to create a relative link.
1273
# Inputs          : old_file    - Link Target
1274
#                   new_file    - Relative to the output work space
1274
#                                 Path to the link target
1275
#                                 Path to where the 'link' file will be created
1275
#                                 If an ABS path is provided, the routine will
1276
#                   Options     - Must be last
1276
#                                 attempt to create a relative link.
1277
#                                 --NoClean         - Don't play with links
1277
#                   new_file    - Relative to the output work space
1278
#                                 --NoDotDot        - Don't create symlinks with ..
1278
#                                 Path to where the 'link' file will be created
1279
#
1279
#                   Options     - Must be last
1280
# Returns         : Nothing
1280
#                                 --NoClean         - Don't play with links
1281
#
1281
#                                 --NoDotDot        - Don't create symlinks with ..
1282
sub MakeSymLink
1282
#
1283
{
1283
# Returns         : Nothing
1284
    my $no_clean;
1284
#
1285
    my $no_dot;
1285
sub MakeSymLink
1286
    my @args;
1286
{
1287
 
1287
    my $no_clean;
1288
    #
1288
    my $no_dot;
1289
    #   Extract options
1289
    my @args;
1290
    #
1290
 
1291
    foreach ( @_ )
1291
    #
1292
    {
1292
    #   Extract options
1293
        if ( m/^--NoClean/i ) {
1293
    #
1294
            $no_clean = 1;
1294
    foreach ( @_ )
1295
 
1295
    {
1296
        } elsif ( m/^--NoDotDot/i ) {
1296
        if ( m/^--NoClean/i ) {
1297
            $no_dot = 1;
1297
            $no_clean = 1;
1298
 
1298
 
1299
        } elsif ( m/^--/ ) {
1299
        } elsif ( m/^--NoDotDot/i ) {
1300
            Error ("MakeSymLink: Unknown option: $_");
1300
            $no_dot = 1;
1301
 
1301
 
1302
        } else {
1302
        } elsif ( m/^--/ ) {
1303
            push @args, $_;
1303
            Error ("MakeSymLink: Unknown option: $_");
1304
        }
1304
 
1305
    }
1305
        } else {
1306
 
1306
            push @args, $_;
1307
    my ($old_file, $new_file) = @args;
1307
        }
1308
 
1308
    }
1309
    my $tfile = $WORK . '/' . $new_file;
1309
 
1310
    $tfile =~ s~//~/~;
1310
    my ($old_file, $new_file) = @args;
1311
    Verbose ("Symlink $old_file -> $new_file" );
1311
 
1312
 
1312
    my $tfile = $WORK . '/' . $new_file;
1313
    #
1313
    $tfile =~ s~//~/~;
1314
    #   Create the directory in which the link will be placed
1314
    Verbose ("Symlink $old_file -> $new_file" );
1315
    #   Remove any existing file of the same name
1315
 
1316
    #
1316
    #
1317
    my $dir = StripFileExt( $tfile );
1317
    #   Create the directory in which the link will be placed
1318
    mkdir $dir unless -d $dir;
1318
    #   Remove any existing file of the same name
1319
    unlink $tfile;
1319
    #
1320
 
1320
    my $dir = StripFileExt( $tfile );
1321
    #
1321
    mkdir $dir unless -d $dir;
1322
    #   Determine a good name of the link
1322
    unlink $tfile;
1323
    #   Convert to a relative link in an attempt to prune them
1323
 
1324
    #
1324
    #
1325
    my $sfile = $old_file;
1325
    #   Determine a good name of the link
1326
    unless ( $no_clean )
1326
    #   Convert to a relative link in an attempt to prune them
1327
    {
1327
    #
1328
        $sfile = CalcRelPath( StripFileExt( $new_file ), $old_file );
1328
    my $sfile = $old_file;
1329
        if ( $no_dot && $sfile =~ m~^../~ )
1329
    unless ( $no_clean )
1330
        {
1330
    {
1331
            $sfile = $old_file;
1331
        $sfile = CalcRelPath( StripFileExt( $new_file ), $old_file );
1332
        }
1332
        if ( $no_dot && $sfile =~ m~^../~ )
1333
    }
1333
        {
1334
 
1334
            $sfile = $old_file;
1335
    my $result = symlink $sfile, $tfile;
1335
        }
1336
    Error ("Cannot create symlink. $old_file -> $new_file") unless ( $result );
1336
    }
1337
}
1337
 
1338
 
1338
    my $result = symlink $sfile, $tfile;
1339
#-------------------------------------------------------------------------------
1339
    Error ("Cannot create symlink. $old_file -> $new_file") unless ( $result );
1340
# Function        : LocateFile
1340
}
1341
#
1341
 
1342
# Description     : Locate a file within the interface directory
1342
#-------------------------------------------------------------------------------
1343
#                   These files will have come from an external package
1343
# Function        : LocateFile
1344
#
1344
#
1345
# Inputs          : $section            One of: bin, lib, pkg, scripts
1345
# Description     : Locate a file within the interface directory
1346
#                                       Will be translated into a suitable path
1346
#                   These files will have come from an external package
1347
#                   $file               Path to file
1347
#
1348
#
1348
# Inputs          : $section            One of: bin, lib, pkg, scripts
1349
# Returns         : Full path to the file
1349
#                                       Will be translated into a suitable path
1350
#                   Will return 'undef' if not found
1350
#                   $file               Path to file
1351
#                   The user must generate the error
1351
#
1352
#
1352
# Returns         : Full path to the file
1353
sub LocateFile
1353
#                   Will return 'undef' if not found
1354
{
1354
#                   The user must generate the error
1355
    my ($section, $file) = @_;
1355
#
1356
    my $base = "$opt_interfacedir/$section";
1356
sub LocateFile
1357
 
1357
{
1358
    unless ( -d $base )
1358
    my ($section, $file) = @_;
1359
    {
1359
    my $base = "$opt_interfacedir/$section";
1360
        Warning("LocateFile: Section not found: $section");
1360
 
1361
        return undef;
1361
    unless ( -d $base )
1362
    }
1362
    {
1363
 
1363
        Warning("LocateFile: Section not found: $section");
1364
    my @done;
1364
        return undef;
1365
    my @parts = GetBuildParts ($opt_interfacedir, $opt_platform );
1365
    }
1366
    push @parts, '';
1366
 
1367
    foreach my $type ( $opt_type, '' )
1367
    my @done;
1368
    {
1368
    my @parts = GetBuildParts ($opt_interfacedir, $opt_platform );
1369
        foreach my $subdir ( @parts )
1369
    push @parts, '';
1370
        {
1370
    foreach my $type ( $opt_type, '' )
1371
            my $sfile = "$base/$subdir$type/$file";
1371
    {
1372
            $sfile =~ s~//~/~g;
1372
        foreach my $subdir ( @parts )
1373
            Verbose2("LocateFile: $sfile");
1373
        {
1374
            if ( -f $sfile )
1374
            my $sfile = "$base/$subdir$type/$file";
1375
            {
1375
            $sfile =~ s~//~/~g;
1376
                unless ( @done )
1376
            Verbose2("LocateFile: $sfile");
1377
                {
1377
            if ( -f $sfile )
1378
                    push @done, $sfile;
1378
            {
1379
                }
1379
                unless ( @done )
1380
            }
1380
                {
1381
        }
1381
                    push @done, $sfile;
1382
    }
1382
                }
1383
 
1383
            }
1384
    if ( $#done > 0)
1384
        }
1385
    {
1385
    }
1386
        Warning ("LocateFile: Multiple instances of file found. Only first is used", @done);
1386
 
1387
    }
1387
    if ( $#done > 0)
1388
    return $done[0];
1388
    {
1389
}
1389
        Warning ("LocateFile: Multiple instances of file found. Only first is used", @done);
1390
 
1390
    }
1391
#-------------------------------------------------------------------------------
1391
    return $done[0];
1392
# Function        : LocateDebianFile
1392
}
1393
#
1393
 
1394
# Description     : Locate a debian file
1394
#-------------------------------------------------------------------------------
1395
#                   Internal Function
1395
# Function        : LocateDebianFile
1396
#
1396
#
1397
#                   Scan packages for the Debian package specified
1397
# Description     : Locate a debian file
1398
#                   The user provides the base name of the package
1398
#                   Internal Function
1399
#                   A Debian Package name has several fields
1399
#
1400
#                   These are:
1400
#                   Scan packages for the Debian package specified
1401
#                       1) Base Name - Provided by the user
1401
#                   The user provides the base name of the package
1402
#                       2) Version - Version will be wildcarded
1402
#                   A Debian Package name has several fields
1403
#                       3) Architecture - Wildcarded. Uses bin/arch directory
1403
#                   These are:
1404
#                   
1404
#                       1) Base Name - Provided by the user
1405
#                   Expect to find Debian Packages in the bin/PLATFORM subdir
1405
#                       2) Version - Version will be wildcarded
1406
#
1406
#                       3) Architecture - Wildcarded. Uses bin/arch directory
1407
# Inputs          : Debian base name, complete with suboptions
1407
#                   
1408
#
1408
#                   Expect to find Debian Packages in the bin/PLATFORM subdir
1409
# Returns         : Full path of the file
1409
#
1410
#
1410
# Inputs          : Debian base name, complete with suboptions
1411
sub LocateDebianFile
1411
#
1412
{
1412
# Returns         : Full path of the file
1413
    my ($arg, $arch, $product) = @_;
1413
#
1414
    Verbose("LocateDebianFile: Processing: $arg");
1414
sub LocateDebianFile
1415
 
1415
{
1416
    my @type = qw( P D );
1416
    my ($arg, $arch, $product) = @_;
1417
    my %debian_file_path;
1417
    Verbose("LocateDebianFile: Processing: $arg");
1418
    
1418
 
1419
    #
1419
    my @type = qw( P D );
1420
    #   Extract sub-options
1420
    my %debian_file_path;
1421
    #       --Prod[uction]
1421
    
1422
    #       --Debug
1422
    #
1423
    #       --Arch[itecture]=yyy
1423
    #   Extract sub-options
1424
    #
1424
    #       --Prod[uction]
1425
    my ($base_name, @opts) = split( ',', $arg );
1425
    #       --Debug
1426
    foreach ( @opts )
1426
    #       --Arch[itecture]=yyy
1427
    {
1427
    #
1428
        if ( m/^--Arch(.*)=(.+)/ ) {
1428
    my ($base_name, @opts) = split( ',', $arg );
1429
            $arch=$2;
1429
    foreach ( @opts )
1430
        } elsif ( m/^--Product=(.+)/ ) {
1430
    {
1431
            $product=$1;
1431
        if ( m/^--Arch(.*)=(.+)/ ) {
1432
        } elsif ( m/^--Prod/ ) {
1432
            $arch=$2;
1433
            @type = 'P';
1433
        } elsif ( m/^--Product=(.+)/ ) {
1434
        } elsif ( m/^--Debug/ ) {
1434
            $product=$1;
1435
            @type = 'D';
1435
        } elsif ( m/^--Prod/ ) {
1436
        }
1436
            @type = 'P';
1437
    }
1437
        } elsif ( m/^--Debug/ ) {
1438
 
1438
            @type = 'D';
1439
    #
1439
        }
1440
    #   Create a list of products
1440
    }
1441
    #   ie: PRODUCT_ARCH
1441
 
1442
    #
1442
    #
1443
    my @products;
1443
    #   Create a list of products
1444
    push @products, $product . '_' . $arch if ( $product );
1444
    #   ie: PRODUCT_ARCH
1445
    push @products, $arch;
1445
    #
1446
 
1446
    my @products;
1447
    #
1447
    push @products, $product . '_' . $arch if ( $product );
1448
    #   Scan all packages for the specified debian package
1448
    push @products, $arch;
1449
    #
1449
 
1450
    foreach my $package_dir ( $opt_interfacedir )
1450
    #
1451
    {
1451
    #   Scan all packages for the specified debian package
1452
        foreach my $type ( @type )
1452
    #
1453
        {
1453
    foreach my $package_dir ( $opt_interfacedir )
1454
            foreach my $prd ( @products )
1454
    {
1455
            {
1455
        foreach my $type ( @type )
1456
                foreach my $joiner ( qw(/ .) )
1456
        {
1457
                {
1457
            foreach my $prd ( @products )
1458
                    my $dir = "$package_dir/bin$joiner$prd$type";
1458
            {
1459
                    Verbose("LocateDebianFile: Search in $dir");
1459
                foreach my $joiner ( qw(/ .) )
1460
                    next unless ( -d $dir );
1460
                {
1461
                    my @files = glob ( "$dir/${base_name}_*.deb" );
1461
                    my $dir = "$package_dir/bin$joiner$prd$type";
1462
                    next unless ( @files );
1462
                    Verbose("LocateDebianFile: Search in $dir");
1463
                    push @{$debian_file_path{$type}}, @files;
1463
                    next unless ( -d $dir );
1464
                }
1464
                    my @files = glob ( "$dir/${base_name}_*.deb" );
1465
            }
1465
                    next unless ( @files );
1466
        }
1466
                    push @{$debian_file_path{$type}}, @files;
1467
    }
1467
                }
1468
 
1468
            }
1469
    Error ("Required Debain package not found: $base_name",) unless %debian_file_path;
1469
        }
1470
 
1470
    }
1471
    #
1471
 
1472
    #   Select 'preferred' type of file
1472
    Error ("Required Debain package not found: $base_name",) unless %debian_file_path;
1473
    #   If we are doing a debug build, then prefer debug package
1473
 
1474
    #   If not available then use any available
1474
    #
1475
    #
1475
    #   Select 'preferred' type of file
1476
    my @debian_file_path = @{$debian_file_path{$opt_type}};
1476
    #   If we are doing a debug build, then prefer debug package
1477
    if ( ! @debian_file_path )
1477
    #   If not available then use any available
1478
    {
1478
    #
1479
        foreach ( keys %debian_file_path )
1479
    my @debian_file_path = @{$debian_file_path{$opt_type}};
1480
        {
1480
    if ( ! @debian_file_path )
1481
            push @debian_file_path,@{$debian_file_path{$_}};
1481
    {
1482
        }
1482
        foreach ( keys %debian_file_path )
1483
    }
1483
        {
1484
 
1484
            push @debian_file_path,@{$debian_file_path{$_}};
1485
    Error ("Multiple matching Debian Packages located", @debian_file_path)
1485
        }
1486
        if ( $#debian_file_path > 0 );
1486
    }
1487
 
1487
 
1488
    return $debian_file_path[0];
1488
    Error ("Multiple matching Debian Packages located", @debian_file_path)
1489
}
1489
        if ( $#debian_file_path > 0 );
1490
 
1490
 
1491
#-------------------------------------------------------------------------------
1491
    return $debian_file_path[0];
1492
# Function        : CalcRelPath
1492
}
1493
#
1493
 
1494
# Description     : Return the relative path to the current working directory
1494
#-------------------------------------------------------------------------------
1495
#                   as provided in $Cwd
1495
# Function        : CalcRelPath
1496
#
1496
#
1497
# Inputs          : $Cwd - Base dir
1497
# Description     : Return the relative path to the current working directory
1498
#                   $base - Path to convert
1498
#                   as provided in $Cwd
1499
#
1499
#
1500
# Returns         : Relative path from the $Cwd
1500
# Inputs          : $Cwd - Base dir
1501
#
1501
#                   $base - Path to convert
1502
sub CalcRelPath
1502
#
1503
{
1503
# Returns         : Relative path from the $Cwd
1504
    my ($Cwd, $base) = @_;
1504
#
1505
 
1505
sub CalcRelPath
1506
    my @base = split ('/', $base );
1506
{
1507
    my @here = split ('/', $Cwd );
1507
    my ($Cwd, $base) = @_;
1508
    my $result;
1508
 
1509
 
1509
    my @base = split ('/', $base );
1510
    Debug("CalcRelPath: Source: $base");
1510
    my @here = split ('/', $Cwd );
1511
 
1511
    my $result;
1512
    return $base unless ( $base =~ m~^/~ );
1512
 
1513
    
1513
    Debug("CalcRelPath: Source: $base");
1514
    #
1514
 
1515
    #   Remove common bits from the head of both lists
1515
    return $base unless ( $base =~ m~^/~ );
1516
    #
1516
    
1517
    while ( $#base >= 0 && $#here >= 0 && $base[0] eq $here[0] )
1517
    #
1518
    {
1518
    #   Remove common bits from the head of both lists
1519
        shift @base;
1519
    #
1520
        shift @here;
1520
    while ( $#base >= 0 && $#here >= 0 && $base[0] eq $here[0] )
1521
    }
1521
    {
1522
 
1522
        shift @base;
1523
    #
1523
        shift @here;
1524
    #   Need to go up some directories from here and then down into base
1524
    }
1525
    #
1525
 
1526
    $result = '../' x ($#here + 1);
1526
    #
1527
    $result .= join ( '/', @base);
1527
    #   Need to go up some directories from here and then down into base
1528
    $result = '.' unless ( $result );
1528
    #
1529
    $result =~ s~//~/~g;
1529
    $result = '../' x ($#here + 1);
1530
    $result =~ s~/$~~;
1530
    $result .= join ( '/', @base);
1531
 
1531
    $result = '.' unless ( $result );
1532
    Debug("CalcRelPath: Result: $result");
1532
    $result =~ s~//~/~g;
1533
    return $result;
1533
    $result =~ s~/$~~;
1534
}
1534
 
1535
 
1535
    Debug("CalcRelPath: Result: $result");
1536
#-------------------------------------------------------------------------------
1536
    return $result;
1537
# Function        : GetBuildParts
1537
}
1538
#
1538
 
1539
# Description     : Determine the 'parts' of the build for the current platform
1539
#-------------------------------------------------------------------------------
1540
#                   This is complex information. It is held within the build.cfg
1540
# Function        : GetBuildParts
1541
#                   file.
1541
#
1542
#
1542
# Description     : Determine the 'parts' of the build for the current platform
1543
# Inputs          : $interface_dir          - Path to the interface dir
1543
#                   This is complex information. It is held within the build.cfg
1544
#                   $platform               - Platform to process
1544
#                   file.
1545
#
1545
#
1546
# Returns         : An array of platform parts
1546
# Inputs          : $interface_dir          - Path to the interface dir
1547
#
1547
#                   $platform               - Platform to process
1548
 
1548
#
1549
#
1549
# Returns         : An array of platform parts
1550
#   The following varaibles are "read" in from the build.cfg file
1550
#
1551
#   In order to access them we need to declare them
1551
 
1552
#
1552
#
1553
our %ScmBuildPkgRules;
1553
#   The following varaibles are "read" in from the build.cfg file
1554
our %BUILDPLATFORM_PARTS;
1554
#   In order to access them we need to declare them
1555
 
1555
#
1556
sub GetBuildParts
1556
our %ScmBuildPkgRules;
1557
{
1557
our %BUILDPLATFORM_PARTS;
1558
    my ($interface_dir, $platform) = @_;
1558
 
1559
 
1559
sub GetBuildParts
1560
    #
1560
{
1561
    #   Tthe build.cfg file is within the interface directory
1561
    my ($interface_dir, $platform) = @_;
1562
    #
1562
 
1563
    my $cfgfile = "$interface_dir/build.cfg";
1563
    #
1564
    Error ("Cannot find file: $cfgfile" ) unless ( -f $cfgfile );
1564
    #   Tthe build.cfg file is within the interface directory
1565
 
1565
    #
1566
    #
1566
    my $cfgfile = "$interface_dir/build.cfg";
1567
    #   Include the build.cfg data
1567
    Error ("Cannot find file: $cfgfile" ) unless ( -f $cfgfile );
1568
    #
1568
 
1569
    require ( $cfgfile );
1569
    #
1570
 
1570
    #   Include the build.cfg data
1571
    #
1571
    #
1572
    #   Extract the platform parts
1572
    require ( $cfgfile );
1573
    #
1573
 
1574
    if ( exists  $BUILDPLATFORM_PARTS{$platform})
1574
    #
1575
    {
1575
    #   Extract the platform parts
1576
        return @{$BUILDPLATFORM_PARTS{$platform}};
1576
    #
1577
    }
1577
    if ( exists  $BUILDPLATFORM_PARTS{$platform})
1578
    else
1578
    {
1579
    {
1579
        return @{$BUILDPLATFORM_PARTS{$platform}};
1580
        Error ("Platform not found in build.cfg: $platform");
1580
    }
1581
    }
1581
    else
1582
}
1582
    {
1583
 
1583
        Error ("Platform not found in build.cfg: $platform");
1584
#-------------------------------------------------------------------------------
1584
    }
1585
# Function        : FindFiles
1585
}
1586
#
1586
 
1587
# Description     : Locate files within a given dir tree
1587
#-------------------------------------------------------------------------------
1588
#
1588
# Function        : FindFiles
1589
# Inputs          : $root           - Base of the search
1589
#
1590
#                   $match          - Re to match
1590
# Description     : Locate files within a given dir tree
1591
#
1591
#
1592
# Returns         : A list of files that match
1592
# Inputs          : $root           - Base of the search
1593
#
1593
#                   $match          - Re to match
1594
my @FIND_LIST;
1594
#
1595
my $FIND_NAME;
1595
# Returns         : A list of files that match
1596
 
1596
#
1597
sub FindFiles
1597
my @FIND_LIST;
1598
{
1598
my $FIND_NAME;
1599
    my ($root, $match ) = @_;
1599
 
1600
    Verbose2("FindFiles: Root: $root, Match: $match");
1600
sub FindFiles
1601
 
1601
{
1602
    #
1602
    my ($root, $match ) = @_;
1603
    #   Becareful of closure, Must use globals
1603
    Verbose2("FindFiles: Root: $root, Match: $match");
1604
    #
1604
 
1605
    @FIND_LIST = ();
1605
    #
1606
    $FIND_NAME = $match;
1606
    #   Becareful of closure, Must use globals
1607
    File::Find::find( \&find_files, $root);
1607
    #
1608
 
1608
    @FIND_LIST = ();
1609
    #
1609
    $FIND_NAME = $match;
1610
    #   Find callback program
1610
    File::Find::find( \&find_files, $root);
1611
    #
1611
 
1612
    sub find_files
1612
    #
1613
    {
1613
    #   Find callback program
1614
        my $item =  $File::Find::name;
1614
    #
1615
        return if ( -d $_ );
1615
    sub find_files
1616
        return unless ( $_ =~ m~$FIND_NAME~ );
1616
    {
1617
        push @FIND_LIST, $item;
1617
        my $item =  $File::Find::name;
1618
    }
1618
        return if ( -d $_ );
1619
    return @FIND_LIST;
1619
        return unless ( $_ =~ m~$FIND_NAME~ );
1620
}
1620
        push @FIND_LIST, $item;
1621
 
1621
    }
1622
 
1622
    return @FIND_LIST;
1623
 
1623
}
-
 
1624
 
-
 
1625
 
-
 
1626