|
1 # |
|
2 # Copyright (c) 2005 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 # Configures the pictograph building environment during the build process. |
|
16 # |
|
17 use strict; |
|
18 use File::Path; |
|
19 my ($myname, $mydir); |
|
20 # |
|
21 # Determine where this program is |
|
22 # |
|
23 BEGIN { |
|
24 ($myname = $0) =~ s@.*(\\|/)@@; |
|
25 ($mydir = $0) =~ s@(\\|/)[^(\\|/)]*$@@; |
|
26 $mydir =~ s@\\@/@g; #replace \ with / |
|
27 $mydir = "." if ($mydir eq $myname); |
|
28 } |
|
29 |
|
30 #constants for directory paths |
|
31 use constant CONFIG_ROOT_DIR => "$mydir/../config"; |
|
32 use constant CONFIG_FILE_NAME => "config.ini"; |
|
33 use constant PICTOGRAPH_BITMAPS_ROOT => "$mydir/../../aknpictographbitmaps"; |
|
34 use constant PICTOGRAPH_BITMAPS_DATA => PICTOGRAPH_BITMAPS_ROOT."/data"; |
|
35 use constant GENERATED_FILES_DIR => "$mydir/../generated"; |
|
36 |
|
37 # supported keys in config.ini |
|
38 use constant PICT_HEIGHTS => "PICTOGRAPH_HEIGHTS"; |
|
39 use constant PICTOGRAPH_BITMAPS_SOURCE_DIR => "PICTOGRAPH_BITMAPS_SOURCE_DIR"; |
|
40 use constant PICT_BITMAP_DISPLAY_MODE => "PICTOGRAPH_BITMAP_DISPLAY_MODE"; |
|
41 use constant PICT_BITMAP_MASK_DISPLAY_MODE => "PICTOGRAPH_BITMAP_MASK_DISPLAY_MODE"; |
|
42 |
|
43 # supported display modes for pictograph bitmaps/masks |
|
44 use constant ECOLOR256 => "EColor256"; |
|
45 use constant ECOLOR64K => "EColor64K"; |
|
46 use constant EGRAY2 => "EGray2"; |
|
47 use constant EGRAY256 => "EGray256"; |
|
48 |
|
49 #heade file template related |
|
50 use constant COLORMODE_BITMAP_TAG_VALUE => "COLORMODE_BITMAP_TAG_VALUE"; |
|
51 use constant COLORMODE_MASK_TAG_VALUE => "COLORMODE_MASK_TAG_VALUE"; |
|
52 use constant DISPLAY_MODE_BITMAP_VALUE => "DISPLAY_MODE_BITMAP_VALUE"; |
|
53 use constant DISPLAY_MODE_MASK_VALUE => "DISPLAY_MODE_MASK_VALUE"; |
|
54 use constant CONF_HEADER_FILE_NAME => "aknpictographconfig.h"; |
|
55 use constant CONF_HEADER_FILE_NAME_DEF => "AKNPICTOGRAPHCONFIG_H"; |
|
56 use constant CONF_HEADER_FILE_TEMPLATE => |
|
57 "// This file is generated by AknPictographConfig.pl. Do not edit!!\n\n\n\n\n". |
|
58 "#ifndef @{[CONF_HEADER_FILE_NAME_DEF]}\n". |
|
59 "#define @{[CONF_HEADER_FILE_NAME_DEF]}\n\n". |
|
60 "#include <gdi.h>\n\n". |
|
61 "// Color mode tags for BMCONV tool\n". |
|
62 "_LIT8( KBitmapTag, @{[COLORMODE_BITMAP_TAG_VALUE]} );\n". |
|
63 "_LIT8( KMaskTag, @{[COLORMODE_MASK_TAG_VALUE]} );\n\n". |
|
64 "// Display modes for pictograph bitmap/mask creation\n". |
|
65 "const TDisplayMode KBitmapDisplayMode = @{[DISPLAY_MODE_BITMAP_VALUE]};\n". |
|
66 "const TDisplayMode KMaskDisplayMode = @{[DISPLAY_MODE_MASK_VALUE]};\n\n". |
|
67 "#endif // @{[CONF_HEADER_FILE_NAME_DEF]}\n\n". |
|
68 "// End of file\n"; |
|
69 |
|
70 # hash for supported display modes for pictograph bitmaps |
|
71 my %supported_bitmap_display_modes = |
|
72 ( |
|
73 uc (ECOLOR256) => +ECOLOR256, |
|
74 uc (ECOLOR64K) => +ECOLOR64K |
|
75 ); |
|
76 # hash for supported display modes for pictograph masks |
|
77 my %supported_bitmap_mask_display_modes = |
|
78 ( |
|
79 uc (EGRAY2) => +EGRAY2, |
|
80 uc (EGRAY256) => +EGRAY256 |
|
81 ); |
|
82 |
|
83 # hash for supported bitmap/mask color mode tags for BMCONV tool |
|
84 my %supported_color_mode_tags = |
|
85 ( |
|
86 @{[ECOLOR256]} => qq("/c8"), |
|
87 @{[ECOLOR64K]} => qq("/c16"), |
|
88 @{[EGRAY2]} => qq("/1"), |
|
89 @{[EGRAY256]} => qq("/8") |
|
90 ); |
|
91 |
|
92 my $usage = "Usage:\n". |
|
93 " perl AknPictographConfig.pl <config_dir_name>\n\n". |
|
94 " <config_dir_name> = directory below directory '<location of AknPictographConfig.pl>/../config'\n\n"; |
|
95 |
|
96 ############################################################################### |
|
97 # main code |
|
98 ############################################################################### |
|
99 my $config_dir_name = shift || die $usage; |
|
100 $config_dir_name = lc $config_dir_name; |
|
101 |
|
102 my $values_ref = ParseConfigFile($config_dir_name); |
|
103 PrintConfigInfo($values_ref,$config_dir_name); |
|
104 GenerateConfigHeader($values_ref); |
|
105 PrepareBuildEnvironment($values_ref,$config_dir_name); |
|
106 |
|
107 ############################################################################### |
|
108 # subroutines |
|
109 ############################################################################### |
|
110 |
|
111 # |
|
112 # Subroutine for parsing pictograph configuration file |
|
113 # |
|
114 # parameters |
|
115 # $_[0] - name of the configuration directory under CONFIG_ROOT_DIR |
|
116 # |
|
117 # return: reference to a hash of key value pairs |
|
118 # |
|
119 sub ParseConfigFile{ |
|
120 my $config_dir_name = shift || die "ParseConfigFile: argument error!"; |
|
121 my $filename = CONFIG_ROOT_DIR."/$config_dir_name/".CONFIG_FILE_NAME; |
|
122 my $content; |
|
123 my %values; |
|
124 open(FILE, $filename) || die "Unable to open file $filename: $!"; |
|
125 { |
|
126 local $/ ; |
|
127 undef $/ ; # reads the whole file on the next line |
|
128 $content = <FILE> ; |
|
129 } |
|
130 close FILE; |
|
131 |
|
132 #remove comments from $content |
|
133 #Note: comments start with // and ends with line end |
|
134 $content =~ s@//.*?$@@mg; |
|
135 |
|
136 # Regular expression for matching a token after '=' in $1. |
|
137 # The token is trimmed from left and right |
|
138 my $match_token = '[^\S\n]*=[^\S\n]*(\w.*?)[^\S\n]*$'; |
|
139 |
|
140 #match PICT_HEIGHTS key value pair |
|
141 #value is list of heights |
|
142 my $tmp = PICT_HEIGHTS; |
|
143 $content =~ /$tmp$match_token/mi || die "$tmp or value is not specified in $filename !\n"; |
|
144 $_=$1; |
|
145 @{$values{$tmp}} = split; |
|
146 die "At least a single pictograph height must be specified for $tmp in $filename\n" if @{$values{$tmp}}==0; |
|
147 |
|
148 #match PICTOGRAPH_BITMAPS_SOURCE_DIR key value pair |
|
149 $tmp = PICTOGRAPH_BITMAPS_SOURCE_DIR; |
|
150 $values{$tmp} = $config_dir_name; #default value |
|
151 $values{$tmp} = $1 if ($content =~ /$tmp$match_token/mi); |
|
152 |
|
153 #match PICT_BITMAP_DISPLAY_MODE key value pair |
|
154 $tmp = PICT_BITMAP_DISPLAY_MODE; |
|
155 $values{$tmp} = ECOLOR256; #default value |
|
156 if ($content =~ /$tmp$match_token/mi){ |
|
157 $_ = $supported_bitmap_display_modes{uc $1} || die "Value \'$1\' is not supported for $tmp!\n"; |
|
158 $values{$tmp} = $_; |
|
159 } |
|
160 |
|
161 #match PICT_BITMAP_MASK_DISPLAY_MODE key value pair |
|
162 $tmp = PICT_BITMAP_MASK_DISPLAY_MODE; |
|
163 $values{$tmp} = EGRAY2; #default value |
|
164 if ($content =~ /$tmp$match_token/mi){ |
|
165 $_ = $supported_bitmap_mask_display_modes{uc $1} || die "Value \'$1\' is not supported for $tmp!\n"; |
|
166 $values{$tmp} = $_; |
|
167 } |
|
168 return \%values; |
|
169 } |
|
170 |
|
171 # |
|
172 # Subroutine for preparing build environment for building pictographs |
|
173 # bitmaps. |
|
174 # |
|
175 # parameters |
|
176 # $_[0] - reference to a hash of key value pairs |
|
177 # $_[1] - name of the configuration directory under CONFIG_ROOT_DIR |
|
178 # |
|
179 sub PrepareBuildEnvironment{ |
|
180 die "PrepareBuildEnvironment: argument error!" if @_!=2; |
|
181 my ($values_ref,$config_dir_name) = @_; |
|
182 my $bitmap_target = PICTOGRAPH_BITMAPS_DATA; |
|
183 $bitmap_target =~ s@/@\\@g; #replace '/' with '\\' for Xcopy, del |
|
184 my $config_source = CONFIG_ROOT_DIR; |
|
185 $config_source =~ s@/@\\@g; #replace '/' with '\\' for Xcopy, del |
|
186 |
|
187 print "Cleanup...\n"; |
|
188 |
|
189 system("del /q /f $bitmap_target\\*.* > nul 2>&1"); |
|
190 system("del /q /f $config_source\\*.* > nul 2>&1"); |
|
191 |
|
192 my @pict_height_list = @{$values_ref->{+PICT_HEIGHTS}}; |
|
193 print "Extracting pictographs for $config_dir_name with heights: @pict_height_list in progress...\n"; |
|
194 |
|
195 my $command = "unzip -o -qq @{[PICTOGRAPH_BITMAPS_ROOT]}/$values_ref->{+PICTOGRAPH_BITMAPS_SOURCE_DIR}/*.zip -d @{[PICTOGRAPH_BITMAPS_DATA]}"; |
|
196 system("$command > nul 2>&1") == 0 or die qq(Command "$command" has failed: $?\n); |
|
197 |
|
198 foreach (@pict_height_list){ |
|
199 my $command = "xcopy $config_source\\$config_dir_name\\picto"."$_".".ini $config_source\\"; |
|
200 system("$command > nul 2>&1") == 0 or die qq(Command "$command" has failed: $?\n); |
|
201 } |
|
202 print "Configuring build environment is successful.\n"; |
|
203 } |
|
204 |
|
205 # |
|
206 # Subroutine for generating configuration header file |
|
207 # |
|
208 # parameters |
|
209 # $_[0] - reference to a hash of key value pairs |
|
210 # |
|
211 sub GenerateConfigHeader{ |
|
212 my $values_ref = shift || die "GenerateConfigHeader: argument error!"; |
|
213 my $conf_header_content = CONF_HEADER_FILE_TEMPLATE; |
|
214 |
|
215 my $tmp = $values_ref->{+PICT_BITMAP_DISPLAY_MODE}; |
|
216 $conf_header_content =~ s/@{[DISPLAY_MODE_BITMAP_VALUE]}/$tmp/si; #insert bitmap display mode |
|
217 $conf_header_content =~ s/@{[COLORMODE_BITMAP_TAG_VALUE]}/$supported_color_mode_tags{$tmp}/si; #insert bitmap color mode tag |
|
218 $tmp = $values_ref->{+PICT_BITMAP_MASK_DISPLAY_MODE}; |
|
219 $conf_header_content =~ s/@{[DISPLAY_MODE_MASK_VALUE]}/$tmp/si; #insert mask display mode |
|
220 $conf_header_content =~ s/@{[COLORMODE_MASK_TAG_VALUE]}/$supported_color_mode_tags{$tmp}/si; #insert mask color mode tag |
|
221 |
|
222 mkpath GENERATED_FILES_DIR; |
|
223 $tmp = GENERATED_FILES_DIR."/".CONF_HEADER_FILE_NAME; |
|
224 open(OUTFILE, ">$tmp") || die "Unable to create file $tmp: $!"; |
|
225 print OUTFILE $conf_header_content; |
|
226 close OUTFILE; |
|
227 } |
|
228 |
|
229 # Subroutine for printing info to stdout about the current |
|
230 # pictograph build configuration |
|
231 # |
|
232 # parameters |
|
233 # $_[0] - reference to a hash of key value pairs |
|
234 # $_[1] - name of the configuration directory under CONFIG_ROOT_DIR |
|
235 # |
|
236 sub PrintConfigInfo{ |
|
237 die "PrintConfigInfo: argument error!" if @_!=2; |
|
238 my ($values_ref,$config_dir_name) = @_; |
|
239 print "Pictograph configuration dir: $config_dir_name\n"; |
|
240 print "Pictographs heights: @{$values_ref->{+PICT_HEIGHTS}}\n"; |
|
241 print "Pictograph bitmaps color mode: $values_ref->{+PICT_BITMAP_DISPLAY_MODE}\n"; |
|
242 print "Pictograph bitmap masks color mode: $values_ref->{+PICT_BITMAP_MASK_DISPLAY_MODE}\n"; |
|
243 } |