Cleaning up usage of examples/{examplebase,symbianpkgrules}.pri
[qt-netbsd.git] / bin / patch_capabilities.pl
blobbfd34f089d306958facac4482cffdddc6470a219
1 #!/usr/bin/perl
2 #############################################################################
3 ##
4 ## Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
5 ## All rights reserved.
6 ## Contact: Nokia Corporation (qt-info@nokia.com)
7 ##
8 ## This file is part of the S60 port of the Qt Toolkit.
9 ##
10 ## $QT_BEGIN_LICENSE:LGPL$
11 ## No Commercial Usage
12 ## This file contains pre-release code and may not be distributed.
13 ## You may use this file in accordance with the terms and conditions
14 ## contained in the Technology Preview License Agreement accompanying
15 ## this package.
17 ## GNU Lesser General Public License Usage
18 ## Alternatively, this file may be used under the terms of the GNU Lesser
19 ## General Public License version 2.1 as published by the Free Software
20 ## Foundation and appearing in the file LICENSE.LGPL included in the
21 ## packaging of this file. Please review the following information to
22 ## ensure the GNU Lesser General Public License version 2.1 requirements
23 ## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ## In addition, as a special exception, Nokia gives you certain additional
26 ## rights. These rights are described in the Nokia Qt LGPL Exception
27 ## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ## If you have questions regarding the use of this file, please contact
30 ## Nokia at qt-info@nokia.com.
39 ## $QT_END_LICENSE$
41 #############################################################################
43 #######################################################################
45 # A script for setting binary capabilities based on .pkg file contents.
47 #######################################################################
49 sub Usage() {
50 print("This script can be used to set capabilities of all binaries\n");
51 print("specified for deployment in a .pkg file.\n");
52 print("If no capabilities are given, the binaries will be given the\n");
53 print("capabilities supported by self-signed certificates.\n");
54 print("\n *** NOTE: If *_template.pkg file is given, 'target-platform' is REQUIRED. ***\n");
55 print("\nUsage: patch_capabilities.pl pkg_filename <target-platform> [capability list]\n");
56 print("\nE.g. patch_capabilities.pl myapp_template.pkg release-armv5 \"All -TCB\"\n");
57 exit();
60 my @capabilitiesToSet = ("LocalServices", "NetworkServices", "ReadUserData", "UserEnvironment", "WriteUserData");
62 # If arguments were given to the script,
63 if (@ARGV)
65 # Parse the first given script argument as a ".pkg" file name.
66 my $pkgFileName = shift(@ARGV);
68 # These variables will only be set for template .pkg files.
69 my $target;
70 my $platform;
72 # Check if using template .pkg and set target/platform variables
73 if (($pkgFileName =~ m|_template\.pkg$|i) && -r($pkgFileName))
75 my $targetplatform;
76 unless ($targetplatform = shift(@ARGV))
78 Usage();
81 my @tmpvalues = split('-', $targetplatform);
82 $target = $tmpvalues[0];
83 $platform = $tmpvalues[1];
85 # Convert visual target to real target (debug->udeb and release->urel)
86 $target =~ s/debug/udeb/i;
87 $target =~ s/release/urel/i;
90 # If the specified ".pkg" file exists (and can be read),
91 if (($pkgFileName =~ m|\.pkg$|i) && -r($pkgFileName))
93 # If there are more arguments given, parse them as capabilities.
94 if (@ARGV)
96 @capabilitiesToSet = ();
97 while (@ARGV)
99 push (@capabilitiesToSet, pop(@ARGV));
103 # Start with no binaries listed.
104 my @binaries = ();
106 my $tempPkgFileName = $pkgFileName."_@@TEMP@@";
107 unlink($tempPkgFileName);
108 open (NEW_PKG, ">>".$tempPkgFileName);
109 open (PKG, "<".$pkgFileName);
111 # Parse each line.
112 while (<PKG>)
114 my $line = $_;
115 my $newLine = $line;
116 if ( $line =~ m/^\#.*\(0x[0-9|a-f|A-F]*\).*$/)
118 $newLine =~ s/\(0x./\(0xE/;
120 print NEW_PKG $newLine;
122 chomp ($line);
124 # If the line specifies a file, parse the source and destination locations.
125 if ($line =~ m|\"([^\"]+)\"\s*\-\s*\"([^\"]+)\"|)
127 my $sourcePath = $1;
128 my $destinationPath = $2;
130 # If the given file is a binary, check the target and binary type (+ the actual filename) from its path.
131 if ($sourcePath =~ m:/epoc32/release/([^/]+)/(udeb|urel|\$\(TARGET\))/(\w+(\.dll|\.exe)):i)
133 # Do preprocessing for template pkg,
134 # In case of template pkg target and platform variables are set
135 if(length($target) && length($platform))
137 $sourcePath =~ s/\$\(PLATFORM\)/$platform/gm;
138 $sourcePath =~ s/\$\(TARGET\)/$target/gm;
141 push (@binaries, $sourcePath);
146 close (PKG);
147 close (NEW_PKG);
149 unlink($pkgFileName);
150 rename($tempPkgFileName, $pkgFileName);
152 print ("\n");
154 my $baseCommandToExecute = "elftran -vid 0x0 -capability \"";
155 if (@capabilitiesToSet)
157 $baseCommandToExecute .= join(" ", @capabilitiesToSet);
159 $baseCommandToExecute .= "\" ";
161 # Actually set the capabilities of the listed binaries.
162 foreach my $binaryPath(@binaries)
164 # Create the command line for setting the capabilities.
165 my $commandToExecute = $baseCommandToExecute;
166 $commandToExecute .= $binaryPath;
168 # Actually execute the elftran command to set the capabilities.
169 system ($commandToExecute." > NUL");
170 print ("Executed ".$commandToExecute."\n");
172 ## Create another command line to check that the set capabilities are correct.
173 #$commandToExecute = "elftran -dump s ".$binaryPath;
176 print ("\n");
179 else
181 Usage();