sl@0
|
1 |
#!perl
|
sl@0
|
2 |
|
sl@0
|
3 |
# Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
4 |
# All rights reserved.
|
sl@0
|
5 |
# This component and the accompanying materials are made available
|
sl@0
|
6 |
# under the terms of "Eclipse Public License v1.0"
|
sl@0
|
7 |
# which accompanies this distribution, and is available
|
sl@0
|
8 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
9 |
#
|
sl@0
|
10 |
# Initial Contributors:
|
sl@0
|
11 |
# Nokia Corporation - initial contribution.
|
sl@0
|
12 |
#
|
sl@0
|
13 |
# Contributors:
|
sl@0
|
14 |
#
|
sl@0
|
15 |
# Description:
|
sl@0
|
16 |
#
|
sl@0
|
17 |
|
sl@0
|
18 |
use strict;
|
sl@0
|
19 |
use File::Copy;
|
sl@0
|
20 |
use Getopt::Long;
|
sl@0
|
21 |
use File::Basename;
|
sl@0
|
22 |
use File::Spec;
|
sl@0
|
23 |
|
sl@0
|
24 |
my $basedir;
|
sl@0
|
25 |
my $platform;
|
sl@0
|
26 |
my $cfg;
|
sl@0
|
27 |
my $certpem;
|
sl@0
|
28 |
my $certkey;
|
sl@0
|
29 |
my $outdir;
|
sl@0
|
30 |
my $maketrgt;
|
sl@0
|
31 |
my $sources;
|
sl@0
|
32 |
my $stublist;
|
sl@0
|
33 |
|
sl@0
|
34 |
GetOptions(
|
sl@0
|
35 |
'basedir=s' => \$basedir,
|
sl@0
|
36 |
'platform=s' => \$platform,
|
sl@0
|
37 |
'cfg=s' => \$cfg,
|
sl@0
|
38 |
'certpem=s' => \$certpem,
|
sl@0
|
39 |
'certkey=s' => \$certkey,
|
sl@0
|
40 |
'outdir=s' => \$outdir,
|
sl@0
|
41 |
'maketrgt=s' => \$maketrgt,
|
sl@0
|
42 |
'sources=s' => \$sources,
|
sl@0
|
43 |
'stublist=s' => \$stublist,
|
sl@0
|
44 |
);
|
sl@0
|
45 |
|
sl@0
|
46 |
my $ROOT = $ENV{EPOCROOT};
|
sl@0
|
47 |
$ROOT =~ s#\\#/#g;
|
sl@0
|
48 |
|
sl@0
|
49 |
if ($maketrgt =~ /RELEASABLES/i or $maketrgt =~ /EXTRATARGET/i)
|
sl@0
|
50 |
{
|
sl@0
|
51 |
my @targets = ();
|
sl@0
|
52 |
my @extra = ();
|
sl@0
|
53 |
my $s;
|
sl@0
|
54 |
my @a = split(/\s+/, $sources);
|
sl@0
|
55 |
foreach my $pkg (@a)
|
sl@0
|
56 |
{
|
sl@0
|
57 |
my $isStub = $stublist =~ /\b$pkg\b/i;
|
sl@0
|
58 |
my $destdir = GetTargetDir($isStub);
|
sl@0
|
59 |
my $trgtname = PkgToSis($pkg, $isStub);
|
sl@0
|
60 |
$s = "$destdir/$trgtname";
|
sl@0
|
61 |
GetExternalForm(\$s);
|
sl@0
|
62 |
push(@targets, $s);
|
sl@0
|
63 |
|
sl@0
|
64 |
if ($destdir =~ /epoc32\/data\/z\/.*\/udeb/ || $isStub)
|
sl@0
|
65 |
{
|
sl@0
|
66 |
my $extratrgt = $destdir;
|
sl@0
|
67 |
$extratrgt =~ s/\/udeb//;
|
sl@0
|
68 |
$s = "$extratrgt/$trgtname";
|
sl@0
|
69 |
GetExternalForm(\$s);
|
sl@0
|
70 |
push(@extra, $s);
|
sl@0
|
71 |
}
|
sl@0
|
72 |
}
|
sl@0
|
73 |
|
sl@0
|
74 |
$s = join(' ', @targets);
|
sl@0
|
75 |
$s = join(' ', @extra) if ($maketrgt =~ /EXTRATARGET/i);
|
sl@0
|
76 |
print "$s";
|
sl@0
|
77 |
exit(0);
|
sl@0
|
78 |
}
|
sl@0
|
79 |
|
sl@0
|
80 |
# Getting here is build final. The pkg file must be in basedir.
|
sl@0
|
81 |
chdir($basedir);
|
sl@0
|
82 |
|
sl@0
|
83 |
# $ARGV[0] is one of the targets generated in RELEASABLES above.
|
sl@0
|
84 |
my $arg = $ARGV[0];
|
sl@0
|
85 |
my $filename = basename($arg);
|
sl@0
|
86 |
my $trgtdir = dirname($arg);
|
sl@0
|
87 |
RecursiveMkDir($trgtdir);
|
sl@0
|
88 |
|
sl@0
|
89 |
my $isStub;
|
sl@0
|
90 |
($filename, $isStub) = SisToPkg($filename);
|
sl@0
|
91 |
die "Pkg $filename does not exist!\n" if (! -f $filename);
|
sl@0
|
92 |
|
sl@0
|
93 |
my $cmd;
|
sl@0
|
94 |
if ($isStub)
|
sl@0
|
95 |
{
|
sl@0
|
96 |
$cmd = "makesis -s $filename $arg";
|
sl@0
|
97 |
system($cmd);
|
sl@0
|
98 |
}
|
sl@0
|
99 |
else
|
sl@0
|
100 |
{
|
sl@0
|
101 |
# change the source locations in pkg file
|
sl@0
|
102 |
my $generatedpkg = "generated.pkg";
|
sl@0
|
103 |
EditPkgFile($filename, $generatedpkg);
|
sl@0
|
104 |
|
sl@0
|
105 |
my $generatedsis = "generated.sis";
|
sl@0
|
106 |
$cmd = "makesis $generatedpkg $generatedsis";
|
sl@0
|
107 |
system($cmd);
|
sl@0
|
108 |
|
sl@0
|
109 |
$cmd = "signsis -S $generatedsis $arg $certpem $certkey";
|
sl@0
|
110 |
system($cmd);
|
sl@0
|
111 |
|
sl@0
|
112 |
# make an extra copy in /epoc32/data/z/tef_ecomswi.
|
sl@0
|
113 |
# iby files normally do not expect files in udeb or urel
|
sl@0
|
114 |
# under /epoc32/data/z.
|
sl@0
|
115 |
if ($trgtdir =~ /\bepoc32\b.\bdata\b.\bz\b.*\budeb\b/)
|
sl@0
|
116 |
{
|
sl@0
|
117 |
my $extratrgt = $arg;
|
sl@0
|
118 |
$extratrgt =~ s/[\/\\]udeb//;
|
sl@0
|
119 |
copy($arg, $extratrgt);
|
sl@0
|
120 |
}
|
sl@0
|
121 |
|
sl@0
|
122 |
unlink($generatedsis);
|
sl@0
|
123 |
unlink($generatedpkg);
|
sl@0
|
124 |
}
|
sl@0
|
125 |
|
sl@0
|
126 |
###################################################
|
sl@0
|
127 |
# subroutines
|
sl@0
|
128 |
###################################################
|
sl@0
|
129 |
sub GetTargetDir
|
sl@0
|
130 |
{
|
sl@0
|
131 |
my $isStub = shift;
|
sl@0
|
132 |
|
sl@0
|
133 |
# for armv5, store all artefacts in data/z.
|
sl@0
|
134 |
my $d = "${ROOT}epoc32/data/z/$outdir/$cfg";
|
sl@0
|
135 |
$d =~ s#/$cfg## if ($isStub);
|
sl@0
|
136 |
|
sl@0
|
137 |
if ($platform =~ /winscw/i)
|
sl@0
|
138 |
{
|
sl@0
|
139 |
$d = "${ROOT}epoc32/release/$platform/$cfg/z/$outdir";
|
sl@0
|
140 |
$d = "${ROOT}epoc32/release/$platform/$cfg/z/system/install" if ($isStub);
|
sl@0
|
141 |
}
|
sl@0
|
142 |
return $d;
|
sl@0
|
143 |
}
|
sl@0
|
144 |
|
sl@0
|
145 |
sub PkgToSis
|
sl@0
|
146 |
{
|
sl@0
|
147 |
my $f = shift;
|
sl@0
|
148 |
my $isStub = shift;
|
sl@0
|
149 |
$f =~ s/\.pkg$//i;
|
sl@0
|
150 |
my $suffix = ($isStub) ? ".sis" : "signed.sis";
|
sl@0
|
151 |
$f .= $suffix;
|
sl@0
|
152 |
return $f;
|
sl@0
|
153 |
}
|
sl@0
|
154 |
|
sl@0
|
155 |
sub SisToPkg
|
sl@0
|
156 |
{
|
sl@0
|
157 |
my $f = shift;
|
sl@0
|
158 |
my $isStub = 1;
|
sl@0
|
159 |
$isStub = 0 if ($f =~ s/signed.sis$//);
|
sl@0
|
160 |
$f =~ s/\.sis$//;
|
sl@0
|
161 |
$f .= ".pkg";
|
sl@0
|
162 |
return ($f, $isStub);
|
sl@0
|
163 |
}
|
sl@0
|
164 |
|
sl@0
|
165 |
sub EditPkgFile
|
sl@0
|
166 |
{
|
sl@0
|
167 |
my $inf = shift;
|
sl@0
|
168 |
my $outf = shift;
|
sl@0
|
169 |
|
sl@0
|
170 |
open(FIN, $inf) or die "fail to read $inf $!\n";
|
sl@0
|
171 |
open(FOUT, ">$outf") or die "fail to write $outf $!\n";
|
sl@0
|
172 |
local $/ = undef;
|
sl@0
|
173 |
my $data = <FIN>;
|
sl@0
|
174 |
close(FIN);
|
sl@0
|
175 |
|
sl@0
|
176 |
$data =~ s/_PLATFORM_/$platform/g;
|
sl@0
|
177 |
$data =~ s/_CFG_/$cfg/g;
|
sl@0
|
178 |
print FOUT $data;
|
sl@0
|
179 |
close(FOUT);
|
sl@0
|
180 |
}
|
sl@0
|
181 |
|
sl@0
|
182 |
# simple one, cannot handle cases like \\londata04\somedir
|
sl@0
|
183 |
sub RecursiveMkDir
|
sl@0
|
184 |
{
|
sl@0
|
185 |
my $path = shift;
|
sl@0
|
186 |
$path =~ s#\\#/#g;
|
sl@0
|
187 |
|
sl@0
|
188 |
my $i = 1;
|
sl@0
|
189 |
my $s;
|
sl@0
|
190 |
do {
|
sl@0
|
191 |
$i = index($path, "/", $i);
|
sl@0
|
192 |
if ($i != -1)
|
sl@0
|
193 |
{
|
sl@0
|
194 |
$s = substr($path, 0, $i++);
|
sl@0
|
195 |
mkdir($s, 0777) if (! -d $s);
|
sl@0
|
196 |
}
|
sl@0
|
197 |
} while ($i != -1);
|
sl@0
|
198 |
|
sl@0
|
199 |
mkdir($path, 0777) if (! -d $path);
|
sl@0
|
200 |
}
|
sl@0
|
201 |
|
sl@0
|
202 |
sub GetExternalForm
|
sl@0
|
203 |
{
|
sl@0
|
204 |
my $refs = shift;
|
sl@0
|
205 |
my @a = split(/[\/\\]/, $$refs);
|
sl@0
|
206 |
$$refs = File::Spec->catfile(@a);
|
sl@0
|
207 |
}
|