1 # |
|
2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of the License "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # This script belongs to the SIF Reference Installer. It builds a binary reference package that |
|
16 # contains a pkg file describing the (base) component to be installed and (optionally) embedded |
|
17 # components. |
|
18 # The structure of an output file is as follows: |
|
19 # 36 bytes header |
|
20 # 4 bytes the size of a pkg file describing the component (pkgSize) |
|
21 # pkgSize bytes the content of a pkg file describing the component |
|
22 # 4 bytes the number of embedded components in a package (numEmbComps) |
|
23 # 4 bytes the length of the name of an embedded component (embCompFileNameLen) \ |
|
24 # embCompFileNameLen bytes the name of an embedded component } this block repeats numEmbComps times |
|
25 # 4 bytes the size of an embedded component (embCompFileSize) / |
|
26 # embCompFileSize bytes the content of an embedded component / |
|
27 # 45 bytes - footer |
|
28 # |
|
29 # |
|
30 |
|
31 use Getopt::Long; |
|
32 use File::Basename; |
|
33 |
|
34 my $KCopyChunkSize = 65536; |
|
35 |
|
36 my $header = '_SifReferenceInstallerPackageHeader_'; |
|
37 my $footer = '_SifReferenceInstallerPackageFooter_'; |
|
38 |
|
39 # Read and check arguments |
|
40 my $help = "\nExample usage:\nmakebinpkg.pl --pkg base.sifrefpkg --emb simple.sis --binpkg compound.sifrefbinpkg\n"; |
|
41 my $inPkg = ''; |
|
42 my @embComps = (); |
|
43 my $outPkg = ''; |
|
44 GetOptions("pkg=s" => \$inPkg, "emb=s" => \@embComps, "binpkg=s" => \$outPkg) or die "GetOptions failed.\n$help"; |
|
45 $outPkg or die "Output file not defined\n$help"; |
|
46 my $numEmbComps = @embComps; |
|
47 $numEmbComps <= 16 or die "Too many embedded components.\n$help"; |
|
48 |
|
49 # Create the output file |
|
50 unlink($outPkg); |
|
51 open OUTFILE, ">$outPkg" or die "\nCan't open $outPkg for writing: $!\n"; |
|
52 binmode OUTFILE; |
|
53 |
|
54 # Write the header |
|
55 print OUTFILE $header; |
|
56 |
|
57 # Write the size of the input pkg file |
|
58 my $inPkgFileSize = -s $inPkg; |
|
59 print "Input pkg file: $inPkg, size: $inPkgFileSize\n"; |
|
60 print OUTFILE pack("i", $inPkgFileSize); |
|
61 |
|
62 # Write the content of the input pkg file |
|
63 open INPKGFILE, $inPkg or die "\nCan't open $inPkg file for reading: $!\n"; |
|
64 binmode INPKGFILE; |
|
65 my $buffer; |
|
66 while (read (INPKGFILE, $buffer, $KCopyChunkSize) and print OUTFILE $buffer) # read in (up to) 64k chunks, write, exit if read or write fails |
|
67 {}; die "Problem copying: $!\n" if $!; |
|
68 close INPKGFILE; |
|
69 |
|
70 # Write the number of input files |
|
71 print OUTFILE pack("i", $numEmbComps); |
|
72 |
|
73 # Iterate over the embedded components adding them into the output file |
|
74 foreach (@embComps) |
|
75 { |
|
76 my $baseName = basename($_); |
|
77 |
|
78 # Write the length of the file name |
|
79 print "Processing file: $_"; |
|
80 print OUTFILE pack("i", length($baseName)); |
|
81 |
|
82 # Write the file name |
|
83 print OUTFILE $baseName; |
|
84 |
|
85 # Write the size of the file |
|
86 my $embCompFileSize = -s $_; |
|
87 print ", size: $embCompFileSize\n"; |
|
88 print OUTFILE pack("i", $embCompFileSize); |
|
89 |
|
90 # Write the content of the file |
|
91 open EMBFILE, $_ or die "\nCan't open $srcfile for reading: $!\n"; |
|
92 binmode EMBFILE; |
|
93 my $buffer; |
|
94 while ( read (EMBFILE, $buffer, $KCopyChunkSize) and print OUTFILE $buffer) # read in (up to) 64k chunks, write, exit if read or write fails |
|
95 {}; die "Problem copying: $!\n" if $!; |
|
96 close EMBFILE; |
|
97 } |
|
98 |
|
99 # Write the footer and close the output file |
|
100 print OUTFILE $footer; |
|
101 close OUTFILE; |
|