sl@0: #!perl sl@0: sl@0: # Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: # All rights reserved. sl@0: # This component and the accompanying materials are made available sl@0: # under the terms of "Eclipse Public License v1.0" sl@0: # which accompanies this distribution, and is available sl@0: # at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: # sl@0: # Initial Contributors: sl@0: # Nokia Corporation - initial contribution. sl@0: # sl@0: # Contributors: sl@0: # sl@0: # Description: sl@0: # sl@0: sl@0: use strict; sl@0: use File::Copy; sl@0: use Getopt::Long; sl@0: use File::Basename; sl@0: use File::Spec; sl@0: sl@0: my $basedir; sl@0: my $platform; sl@0: my $cfg; sl@0: my $certpem; sl@0: my $certkey; sl@0: my $outdir; sl@0: my $maketrgt; sl@0: my $sources; sl@0: my $stublist; sl@0: sl@0: GetOptions( sl@0: 'basedir=s' => \$basedir, sl@0: 'platform=s' => \$platform, sl@0: 'cfg=s' => \$cfg, sl@0: 'certpem=s' => \$certpem, sl@0: 'certkey=s' => \$certkey, sl@0: 'outdir=s' => \$outdir, sl@0: 'maketrgt=s' => \$maketrgt, sl@0: 'sources=s' => \$sources, sl@0: 'stublist=s' => \$stublist, sl@0: ); sl@0: sl@0: my $ROOT = $ENV{EPOCROOT}; sl@0: $ROOT =~ s#\\#/#g; sl@0: sl@0: if ($maketrgt =~ /RELEASABLES/i or $maketrgt =~ /EXTRATARGET/i) sl@0: { sl@0: my @targets = (); sl@0: my @extra = (); sl@0: my $s; sl@0: my @a = split(/\s+/, $sources); sl@0: foreach my $pkg (@a) sl@0: { sl@0: my $isStub = $stublist =~ /\b$pkg\b/i; sl@0: my $destdir = GetTargetDir($isStub); sl@0: my $trgtname = PkgToSis($pkg, $isStub); sl@0: $s = "$destdir/$trgtname"; sl@0: GetExternalForm(\$s); sl@0: push(@targets, $s); sl@0: sl@0: if ($destdir =~ /epoc32\/data\/z\/.*\/udeb/ || $isStub) sl@0: { sl@0: my $extratrgt = $destdir; sl@0: $extratrgt =~ s/\/udeb//; sl@0: $s = "$extratrgt/$trgtname"; sl@0: GetExternalForm(\$s); sl@0: push(@extra, $s); sl@0: } sl@0: } sl@0: sl@0: $s = join(' ', @targets); sl@0: $s = join(' ', @extra) if ($maketrgt =~ /EXTRATARGET/i); sl@0: print "$s"; sl@0: exit(0); sl@0: } sl@0: sl@0: # Getting here is build final. The pkg file must be in basedir. sl@0: chdir($basedir); sl@0: sl@0: # $ARGV[0] is one of the targets generated in RELEASABLES above. sl@0: my $arg = $ARGV[0]; sl@0: my $filename = basename($arg); sl@0: my $trgtdir = dirname($arg); sl@0: RecursiveMkDir($trgtdir); sl@0: sl@0: my $isStub; sl@0: ($filename, $isStub) = SisToPkg($filename); sl@0: die "Pkg $filename does not exist!\n" if (! -f $filename); sl@0: sl@0: my $cmd; sl@0: if ($isStub) sl@0: { sl@0: $cmd = "makesis -s $filename $arg"; sl@0: system($cmd); sl@0: } sl@0: else sl@0: { sl@0: # change the source locations in pkg file sl@0: my $generatedpkg = "generated.pkg"; sl@0: EditPkgFile($filename, $generatedpkg); sl@0: sl@0: my $generatedsis = "generated.sis"; sl@0: $cmd = "makesis $generatedpkg $generatedsis"; sl@0: system($cmd); sl@0: sl@0: $cmd = "signsis -S $generatedsis $arg $certpem $certkey"; sl@0: system($cmd); sl@0: sl@0: # make an extra copy in /epoc32/data/z/tef_ecomswi. sl@0: # iby files normally do not expect files in udeb or urel sl@0: # under /epoc32/data/z. sl@0: if ($trgtdir =~ /\bepoc32\b.\bdata\b.\bz\b.*\budeb\b/) sl@0: { sl@0: my $extratrgt = $arg; sl@0: $extratrgt =~ s/[\/\\]udeb//; sl@0: copy($arg, $extratrgt); sl@0: } sl@0: sl@0: unlink($generatedsis); sl@0: unlink($generatedpkg); sl@0: } sl@0: sl@0: ################################################### sl@0: # subroutines sl@0: ################################################### sl@0: sub GetTargetDir sl@0: { sl@0: my $isStub = shift; sl@0: sl@0: # for armv5, store all artefacts in data/z. sl@0: my $d = "${ROOT}epoc32/data/z/$outdir/$cfg"; sl@0: $d =~ s#/$cfg## if ($isStub); sl@0: sl@0: if ($platform =~ /winscw/i) sl@0: { sl@0: $d = "${ROOT}epoc32/release/$platform/$cfg/z/$outdir"; sl@0: $d = "${ROOT}epoc32/release/$platform/$cfg/z/system/install" if ($isStub); sl@0: } sl@0: return $d; sl@0: } sl@0: sl@0: sub PkgToSis sl@0: { sl@0: my $f = shift; sl@0: my $isStub = shift; sl@0: $f =~ s/\.pkg$//i; sl@0: my $suffix = ($isStub) ? ".sis" : "signed.sis"; sl@0: $f .= $suffix; sl@0: return $f; sl@0: } sl@0: sl@0: sub SisToPkg sl@0: { sl@0: my $f = shift; sl@0: my $isStub = 1; sl@0: $isStub = 0 if ($f =~ s/signed.sis$//); sl@0: $f =~ s/\.sis$//; sl@0: $f .= ".pkg"; sl@0: return ($f, $isStub); sl@0: } sl@0: sl@0: sub EditPkgFile sl@0: { sl@0: my $inf = shift; sl@0: my $outf = shift; sl@0: sl@0: open(FIN, $inf) or die "fail to read $inf $!\n"; sl@0: open(FOUT, ">$outf") or die "fail to write $outf $!\n"; sl@0: local $/ = undef; sl@0: my $data = ; sl@0: close(FIN); sl@0: sl@0: $data =~ s/_PLATFORM_/$platform/g; sl@0: $data =~ s/_CFG_/$cfg/g; sl@0: print FOUT $data; sl@0: close(FOUT); sl@0: } sl@0: sl@0: # simple one, cannot handle cases like \\londata04\somedir sl@0: sub RecursiveMkDir sl@0: { sl@0: my $path = shift; sl@0: $path =~ s#\\#/#g; sl@0: sl@0: my $i = 1; sl@0: my $s; sl@0: do { sl@0: $i = index($path, "/", $i); sl@0: if ($i != -1) sl@0: { sl@0: $s = substr($path, 0, $i++); sl@0: mkdir($s, 0777) if (! -d $s); sl@0: } sl@0: } while ($i != -1); sl@0: sl@0: mkdir($path, 0777) if (! -d $path); sl@0: } sl@0: sl@0: sub GetExternalForm sl@0: { sl@0: my $refs = shift; sl@0: my @a = split(/[\/\\]/, $$refs); sl@0: $$refs = File::Spec->catfile(@a); sl@0: }