exampleapps/alfexstickers/sis/sisTool.pl
changeset 0 15bf7259bb7c
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     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 "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 #
       
    16 
       
    17 sub updateVersion ;
       
    18 sub signSis ;
       
    19 
       
    20 my @args = @ARGV;
       
    21 # signing related variables
       
    22 my $certPath = "\\s60_RnD\\RD_RootCA";
       
    23 my $certificate = "rd.cer";
       
    24 my $key = "rd-key.pem";
       
    25 my $version = "10.1";
       
    26 my $packageFile = undef;
       
    27 my $sisFile = undef;
       
    28 
       
    29 # path to copy signed sis (if optional -c argument used)
       
    30 my $copyPath = undef;
       
    31 
       
    32 # 
       
    33 my $updateDllVersion = 0;
       
    34     
       
    35 # print help if needed
       
    36 if ( scalar(@args) == 0 || 
       
    37      $args[0] =~ /-[h,\?]/i )
       
    38     {
       
    39 print <<HELP;
       
    40 
       
    41 -------------------------------------------------------------------------
       
    42 ======= Script for making and signing an installation (.sis) file =======
       
    43 
       
    44 Usage: sisTool <package-file-w/o-ext> [-d<version>] [-c<destination-path>] 
       
    45                [-s<stub-package-file-w/o-ext>]
       
    46 
       
    47  -d changes minor DLL version number - needed when eclipsing DLLs in ROM.
       
    48  -c copies target file to specific destination
       
    49  -s also creates stub SIS. File name is not needed if it same as base file
       
    50     name followed by "_stub" (e.g. pkg files for eclipsing SIS and stub SIS
       
    51     are component.pkg and component_stub.pkg respectively).
       
    52 
       
    53 Examples:
       
    54 =========
       
    55 sisTool myPackage -d2
       
    56 
       
    57   Creates and signs(* 'myPackage.sis' from 'myPackage.pkg'.
       
    58   Before creating sis file myPackage.pkg is searched for DLLs
       
    59   and their version numbers are changed to 10.2 (i.e. minor
       
    60   version is changed - default major version number is 10).
       
    61 
       
    62 sisTool myPackage -d -s
       
    63   
       
    64   Same as first example but uses default minor version number (=1)
       
    65   for DLLs, and creates stub sis with name myPackage_stub.sis.
       
    66 
       
    67                                                      
       
    68 (* Uses R&D certificate 'rd.cer' from \\S60\\s60_RnD\\RD_RootCA
       
    69 HELP
       
    70     exit;
       
    71     }
       
    72 $packageFile = shift;
       
    73 
       
    74 foreach ( @args ) {
       
    75     # check if dll version number should be updated
       
    76     if ( /-d(\d+)?\b/ ) {
       
    77         $version = $1 ;
       
    78         $version = 1 if ( not defined $version );            
       
    79         $updateDllVersion = 1;
       
    80         }
       
    81     # check if stub SIS should be created
       
    82     elsif ( /-s((\w|\.|\\|_|:|-)+)?/ )
       
    83         {
       
    84         my $stubPkgFile = "${packageFile}_stub.pkg";
       
    85         if ( defined $1 ) {
       
    86             # user defined stub
       
    87             $stubPkgFile = $1; 
       
    88             $stubPkgFile = $stubPkgFile . ".pkg" if $stubPkgFile !~ /\.pkg$/; 
       
    89             }        
       
    90         my $cmd = "makesis -s $stubPkgFile";
       
    91         print "\n";
       
    92         system "$cmd";
       
    93         print "\n";
       
    94         }
       
    95     $copyPath = $1 if /-c(\S+)/;
       
    96     }
       
    97 
       
    98 if ( defined($packageFile) ) {
       
    99     ( -e "$packageFile.pkg" ) or die "package file '$packageFile' not found.\n";
       
   100     
       
   101     # Update version number of DLLs listed in pkg-file.
       
   102     updateVersion if $updateDllVersion;
       
   103 
       
   104     my $cmd = "makesis $packageFile\.pkg\n";
       
   105    
       
   106     if ( !defined( $sisFile ) ) {
       
   107         $sisFile = "$packageFile.sis";
       
   108         }
       
   109     #################
       
   110     # Do create sis #
       
   111     #################
       
   112     
       
   113     my $err = system "$cmd";
       
   114     die "\nFailed making sis file $!" if $err;
       
   115     signSis;
       
   116     if ( defined( $copyPath ) )
       
   117         {
       
   118         system "xcopy $sisFile $copyPath 2>&1";
       
   119         }
       
   120     }
       
   121 
       
   122 sub signSis {
       
   123     # sign a sis file
       
   124     my $signedFile = "${sisFile}S\.sis";
       
   125     ( -e "$certPath\\$certificate" ) or die <<NOCERT;
       
   126     
       
   127     
       
   128 Certificate could not be found from $certPath\\$certificate
       
   129 Check and modifiy the path in line ~17 in the script if needed.
       
   130 NOCERT
       
   131 
       
   132     my $cmd = "signsis -s $packageFile.sis $signedFile $certPath\\$certificate $certPath\\$key";        
       
   133     if ( system ( "$cmd" ) == 0 )
       
   134         {        
       
   135         # delete original unsigned sis file
       
   136         system "del $sisFile";
       
   137         system "ren $signedFile $sisFile";
       
   138         print "\nSigned with R&D certificate\n";
       
   139         if ( defined ( $copyPath ) ) {
       
   140             # copy signed sis to specified directory
       
   141             system "xcopy $sisFile $copyPath";
       
   142             }
       
   143         }        
       
   144     }
       
   145     
       
   146 
       
   147 sub updateVersion {
       
   148     open PACKAGE, "<$packageFile.pkg";    
       
   149     foreach ( <PACKAGE> )
       
   150         {
       
   151         if ( /\"(.*?\.dll)\"/i ) 
       
   152             {                        
       
   153             system "elftran -version 10\.$version $1";
       
   154             system "elftran -compressionmethod bytepair $1";
       
   155             print STDOUT "\nUpdated version number of\n$1 to 10.$version\n";
       
   156             }
       
   157         }
       
   158     close PACKAGE;  
       
   159     }