|
1 # |
|
2 # Copyright (c) 2007-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 # |
|
16 |
|
17 # features tool version |
|
18 use constant TOOL_VERSION=>"0.2"; |
|
19 |
|
20 # global variables |
|
21 my $PerlLibPath; # fully qualified pathname of the directory containing our Perl modules |
|
22 my $ibyPath; # destination path for the iby files |
|
23 my $hdrPath; # destination path for the header files |
|
24 my $datPath; # destination path for the features.DAT file |
|
25 my $convPath; # destination path for the feature registry database convertion |
|
26 my $epocroot = $ENV{EPOCROOT}; # epcoroot directory |
|
27 |
|
28 # |
|
29 # xml database file name(s) |
|
30 # |
|
31 my @xmlDBFile; |
|
32 |
|
33 # |
|
34 # flags to suppress the output files |
|
35 # 0x01 = generate header files only |
|
36 # 0x02 = genereate iby files only |
|
37 # 0x04 = generate dat files only |
|
38 # 0x08 = convert feature registry database to feature manager database |
|
39 # |
|
40 use constant FLG_GENHDR=>0x01; |
|
41 use constant FLG_GENIBY=>0x02; |
|
42 use constant FLG_GENDAT=>0x04; |
|
43 use constant FLG_CONVFR=>0x08; |
|
44 my $flagOut = 0; |
|
45 |
|
46 use FindBin; # for FindBin::Bin |
|
47 BEGIN { |
|
48 # check user has a version of perl that will cope |
|
49 require 5.005_03; |
|
50 # establish the path to the Perl libraries |
|
51 $PerlLibPath = $FindBin::Bin; # X:/epoc32/tools |
|
52 $PerlLibPath .= "/"; |
|
53 } |
|
54 use lib $PerlLibPath; |
|
55 # Includes the validation perl modules for XML validation against the given DTD. |
|
56 use lib "$PerlLibPath/build/lib"; |
|
57 # Include routines to create the feature header and iby files. |
|
58 use features; |
|
59 |
|
60 # |
|
61 # main - Tool entry function |
|
62 # |
|
63 { |
|
64 # Default path settings |
|
65 &processPath(\$epocroot); |
|
66 &features::set_DefaultPath($epocroot, \$hdrPath, \$ibyPath, \$datPath, \$convPath); |
|
67 |
|
68 # Process the command line arguments |
|
69 if(&process_cmdline_arguments()) { |
|
70 # Open the xml database |
|
71 if(&features::open_Database(@xmlDBFile)) { |
|
72 |
|
73 # Generate the header file in the appropriate format with the featureset attributes |
|
74 &features::generate_Headerfile($hdrPath) if($flagOut&FLG_GENHDR); |
|
75 |
|
76 # Generate the obey file in the appropriate format with the featureset attributes |
|
77 &features::generate_Obeyfile($ibyPath) if($flagOut&FLG_GENIBY); |
|
78 |
|
79 # Generate the feature dat file |
|
80 &features::generate_DATfile($datPath) if($flagOut&FLG_GENDAT); |
|
81 |
|
82 # Convert the feature registry database to feature manager database |
|
83 &features::convert_FeatRegToFeatMgr($convPath,@xmlDBFile) if($flagOut&FLG_CONVFR); |
|
84 } |
|
85 } |
|
86 } |
|
87 |
|
88 # |
|
89 # Process the command line arguments |
|
90 # |
|
91 sub process_cmdline_arguments |
|
92 { |
|
93 my $helpCmd = 0; |
|
94 |
|
95 foreach my $arg (@ARGV) |
|
96 { |
|
97 if( ($arg =~ /^--(\S+)$/) or ($arg =~ /^-([ridc]=.+)$/) ) |
|
98 { |
|
99 $arg = $1; |
|
100 if( (($arg =~ /^hdrfile$/i) || ($arg =~ /^hdrfile=(.+)/i)) or ($arg =~ /^r=(.+)/) ) { |
|
101 # option to generate only header files |
|
102 if($1) { |
|
103 $hdrPath = $1; |
|
104 processPath(\$hdrPath); |
|
105 } |
|
106 $flagOut |= FLG_GENHDR; |
|
107 } |
|
108 elsif( (($arg =~ /^ibyfile$/i) || ($arg =~ /^ibyfile=(.+)/i)) or ($arg =~ /^i=(.+)/) ) { |
|
109 # option to generate only iby files |
|
110 if($1) { |
|
111 $ibyPath = $1; |
|
112 processPath(\$ibyPath); |
|
113 } |
|
114 $flagOut |= FLG_GENIBY; |
|
115 } |
|
116 elsif( (($arg =~ /^datfile$/i) || ($arg =~ /^datfile=(.+)/i)) or ($arg =~ /^d=(.+)/) ) { |
|
117 # option to generate only dat files |
|
118 if($1) { |
|
119 $datPath = $1; |
|
120 processPath(\$datPath); |
|
121 } |
|
122 $flagOut |= FLG_GENDAT; |
|
123 } |
|
124 elsif( (($arg =~ /^convert$/i) || ($arg =~ /^convert=(.+)/i)) or ($arg =~ /^c=(.+)/) ) { |
|
125 # option to convert feature registry database |
|
126 if($1) { |
|
127 $convPath = $1; |
|
128 processPath(\$convPath); |
|
129 } |
|
130 $flagOut |= FLG_CONVFR; |
|
131 } |
|
132 elsif( $arg =~ /^verbose$/i ) { |
|
133 # option to enable verbose mode |
|
134 &printTitle(); |
|
135 &features::set_VerboseMode(); |
|
136 } |
|
137 elsif( $arg =~ /^strict$/i ) { |
|
138 # option to enable strict mode |
|
139 &features::set_StrictMode(); |
|
140 } |
|
141 elsif( $arg =~ /^help$/i ) { |
|
142 # print the usage on console |
|
143 $helpCmd = 1; |
|
144 } |
|
145 elsif( $arg =~ /^version$/i ) { |
|
146 # print the title on console |
|
147 &printTitle(); |
|
148 return 1 if(scalar(@ARGV) == 1); # if this is the only option |
|
149 } |
|
150 else |
|
151 { |
|
152 print "Error: Unknown parameter $arg\n"; |
|
153 return 0; |
|
154 } |
|
155 next; |
|
156 } |
|
157 elsif( $arg =~ /^-(\S+)$/ ) |
|
158 { |
|
159 my @flags = split("",$1); |
|
160 |
|
161 foreach my $opt (@flags) { |
|
162 if( $opt =~ /^r/i ) { |
|
163 # option to generate only header files |
|
164 $flagOut |= FLG_GENHDR; |
|
165 } |
|
166 elsif( $opt =~ /^i/i ) { |
|
167 # option to generate only iby files |
|
168 $flagOut |= FLG_GENIBY; |
|
169 } |
|
170 elsif( $opt =~ /^d/i ) { |
|
171 # option to generate only dat files |
|
172 $flagOut |= FLG_GENDAT; |
|
173 } |
|
174 elsif( $opt =~ /^c/i ) { |
|
175 # option to convert feature registry database |
|
176 $flagOut |= FLG_CONVFR; |
|
177 } |
|
178 elsif( $opt =~ /^v/i ) { |
|
179 # option to enable verbose mode |
|
180 &printTitle(); |
|
181 &features::set_VerboseMode(); |
|
182 } |
|
183 elsif( $opt =~ /^s/i ) { |
|
184 # option to enable strict mode |
|
185 &features::set_StrictMode(); |
|
186 } |
|
187 elsif( $opt =~ /^h/i ) { |
|
188 # print the usage on console |
|
189 $helpCmd = 1; |
|
190 } |
|
191 else |
|
192 { |
|
193 print "Error: Unknown option $opt\n"; |
|
194 return 0; |
|
195 } |
|
196 } |
|
197 next; |
|
198 } |
|
199 |
|
200 next if(xmlfile($arg)); |
|
201 next if(xmlfile("$arg.xml")); |
|
202 next if(xmlfile("$epocroot"."epoc32/rom/include/$arg")); |
|
203 |
|
204 print "Error: Cannot find xml file: $arg\n"; |
|
205 } |
|
206 |
|
207 # process the help command |
|
208 if($helpCmd) { |
|
209 &print_usage(); |
|
210 return 1 if(scalar(@ARGV) == 1); # if this is the only option |
|
211 } |
|
212 |
|
213 if(!@xmlDBFile) { |
|
214 # xml database is must here |
|
215 print "Error: No xml database given\n"; |
|
216 &print_usage() if(!$helpCmd); |
|
217 return 0; |
|
218 } |
|
219 |
|
220 # if the suppress output option is not passed then generate both |
|
221 $flagOut = (FLG_GENHDR|FLG_GENIBY|FLG_GENDAT|FLG_CONVFR) if(!$flagOut); |
|
222 |
|
223 return 1; |
|
224 } |
|
225 |
|
226 # --Utility Functions |
|
227 |
|
228 # |
|
229 # check whether the given file exists |
|
230 # @param - file name for the existance check |
|
231 # |
|
232 sub xmlfile |
|
233 { |
|
234 my ($file) = shift; |
|
235 |
|
236 if(-e $file) { |
|
237 push @xmlDBFile, $file; |
|
238 return 1; |
|
239 } |
|
240 return 0; |
|
241 } |
|
242 |
|
243 # |
|
244 # Process the given absolute path |
|
245 # Add backslash at the end if required |
|
246 # @param - path to be processed |
|
247 # |
|
248 sub processPath |
|
249 { |
|
250 my ($path) = shift; |
|
251 |
|
252 return if( $$path =~ /(\\$)/ ); |
|
253 return if( $$path =~ /(\/$)/ ); |
|
254 $$path .= "/"; |
|
255 } |
|
256 |
|
257 # |
|
258 # Print the title |
|
259 # |
|
260 sub printTitle |
|
261 { |
|
262 print "FEATURES - Features manager tool V".TOOL_VERSION."\n"; |
|
263 print "Copyright (c) 2009 Nokia Corporation.\n\n" |
|
264 } |
|
265 |
|
266 # |
|
267 # print the usage of this tool |
|
268 # |
|
269 sub print_usage |
|
270 { |
|
271 #........1.........2.........3.........4.........5.........6.........7..... |
|
272 &printTitle(); |
|
273 print <<USAGE_EOF; |
|
274 Usage: |
|
275 features [options] <xml database> [<xml database> <xml database> ...] |
|
276 |
|
277 Generation of C++ header file and IBY file for the given featuremanger |
|
278 database file. It also generates features DAT file for the given |
|
279 featuemanager/featureregistry database file |
|
280 |
|
281 Options: |
|
282 -r or --hdrfile[=<destination path>] - generates only header file |
|
283 -i or --ibyfile[=<destination path>] - generates only IBY file |
|
284 -d or --datfile[=<destination path>] - generates only features.DAT file |
|
285 -c or --convert[=<destination path>] - converts feature registry database |
|
286 |
|
287 -s or --strict - enable strict mode |
|
288 -v or --verbose - enable verbose mode |
|
289 -h or --help - displays this help |
|
290 |
|
291 --version - displays the tools version |
|
292 |
|
293 Ex: option combination \"-ri\" generates header and IBY files |
|
294 |
|
295 Default destination paths: |
|
296 <header file> - $EPOCROOT\\epoc32\\include\\ |
|
297 <iby file> - $EPOCROOT\\epoc32\\rom\\include\\ |
|
298 <features.dat file> - generates in current directory |
|
299 |
|
300 Note: The conversion(--convert) of feature registry database requires the |
|
301 feature registry dtd file(featureuids.dtd) in $EPOCROOT\\epoc32\\tools\\ |
|
302 USAGE_EOF |
|
303 } |