Updated Polish translation by Mateusz Kubica
[maemo-rb.git] / wps / wpsbuild.pl
blob2cab5374f855105a18a922a6bdc582b1f31b1802
1 #!/usr/bin/perl
2 # __________ __ ___.
3 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 # \/ \/ \/ \/ \/
8 # $Id$
11 $ROOT="..";
13 if($ARGV[0] eq "-r") {
14 $ROOT=$ARGV[1];
15 shift @ARGV;
16 shift @ARGV;
19 my $verbose;
20 if($ARGV[0] eq "-v") {
21 $verbose =1;
22 shift @ARGV;
25 my $firmdir="$ROOT/firmware";
27 my $wpslist=$ARGV[0];
29 my $target = $ARGV[1];
30 my $cppdef = $target;
31 my @depthlist = ( 16, 8, 4, 2, 1 );
33 if(!$wpslist) {
34 print "Usage: wpsbuilds.pl <WPSLIST> <target>\n",
35 "Run this script in the root of the target build, and it will put all the\n",
36 "stuff in .rockbox/wps/\n";
37 exit;
40 sub getlcdsizes {
41 my ($remote) = @_;
43 open(GCC, ">gcctemp");
44 if($remote) {
45 # Get the remote LCD screen size
46 print GCC <<STOP
47 \#include "config.h"
48 #ifdef HAVE_REMOTE_LCD
49 Height: LCD_REMOTE_HEIGHT
50 Width: LCD_REMOTE_WIDTH
51 Depth: LCD_REMOTE_DEPTH
52 #endif
53 STOP
56 else {
57 print GCC <<STOP
58 \#include "config.h"
59 Height: LCD_HEIGHT
60 Width: LCD_WIDTH
61 Depth: LCD_DEPTH
62 STOP
65 close(GCC);
67 my $c="cat gcctemp | gcc $cppdef -I. -I$firmdir/export -E -P -";
69 #print "CMD $c\n";
71 open(GETSIZE, "$c|");
73 my ($height, $width);
74 while(<GETSIZE>) {
75 if($_ =~ /^Height: (\d*)/) {
76 $height = $1;
78 elsif($_ =~ /^Width: (\d*)/) {
79 $width = $1;
81 elsif($_ =~ /^Depth: (\d*)/) {
82 $depth = $1;
84 if($height && $width && $depth) {
85 last;
88 close(GETSIZE);
89 unlink("gcctemp");
91 return ($height, $width, $depth);
94 sub mkdirs {
95 my $wpsdir = $wps;
96 $wpsdir =~ s/\.(r|)wps//;
97 mkdir ".rockbox/wps", 0777;
98 mkdir ".rockbox/themes", 0777;
100 if( -d ".rockbox/wps/$wpsdir") {
101 #print STDERR "wpsbuild warning: directory wps/$wpsdir already exists!\n";
103 else
105 mkdir ".rockbox/wps/$wpsdir", 0777;
109 sub copybackdrop {
110 #copy the backdrop file into the build dir
112 $backdrop =~ /\/(.*backdrops\/(.*))/i;
113 `cp $ROOT/backdrops/$2 $1`;
116 sub copythemefont {
117 #copy the font specified by the theme
119 $o=$font;
120 $o =~ s/\.fnt/\.bdf/;
121 `mkdir .rockbox/fonts/ >/dev/null 2>&1`;
122 $cmd ="$ROOT/tools/convbdf -f -o \".rockbox/fonts/$font\" \"$ROOT/fonts/$o\" ";
123 `$cmd`;
126 sub copythemeicon {
127 #copy the icon specified by the theme
129 $iconset =~ /\/(.*icons\/(.*))/i;
130 `cp $ROOT/icons/$2 $1`;
133 sub copythemeviewericon {
134 #copy the viewer icon specified by the theme
136 $viewericon =~ /\/(.*icons\/(.*))/i;
137 `cp $ROOT/icons/$2 $1`;
141 sub copywps {
142 # we assume that we copy the WPS files from the same dir the WPSLIST
143 # file is located in
144 my $dir;
145 my @filelist;
146 my $file;
148 if($wpslist =~ /(.*)WPSLIST/) {
149 $dir = $1;
150 # system("cp $dir/$wps .rockbox/wps/");
151 # print "$req_t_wps $req_g_wps\n";
153 if (-e "$dir/$req_t_wps" ) {
154 system("cp $dir/$req_t_wps .rockbox/wps/$wps");
156 } elsif (-e "$dir/$req_g_wps") {
157 system("cp $dir/$req_g_wps .rockbox/wps/$wps");
159 open(WPSFILE, "$dir/$req_g_wps");
160 while (<WPSFILE>) {
161 $filelist[$#filelist + 1] = $1 if (/\|([^|]*?.bmp)\|/);
163 close(WPSFILE);
165 if ($#filelist >= 0) {
166 if (-e "$dir/$wps_prefix/$req_g") {
167 foreach $file (@filelist) {
168 system("cp $dir/$wps_prefix/$req_g/$file .rockbox/wps/$wps_prefix/");
171 elsif (-e "$dir/$wps_prefix") {
172 foreach $file (@filelist) {
173 system("cp $dir/$wps_prefix/$file .rockbox/wps/$wps_prefix/");
176 else {
177 print STDERR "beep, no dir to copy WPS from!\n";
181 } else {
182 print STDERR "Skipping $wps - no matching resolution.\n";
184 } else {
185 print STDERR "No source directory!\n";
189 sub buildcfg {
190 my $cfg = $wps;
191 my @out;
193 $cfg =~ s/\.(r|)wps/.cfg/;
195 push @out, <<MOO
197 \# $cfg generated by wpsbuild.pl
198 \# $wps is made by $author
200 wps: /.rockbox/wps/$wps
203 if($font) {
204 push @out, "font: /.rockbox/fonts/$font\n";
206 if($fgcolor) {
207 push @out, "foreground color: $fgcolor\n";
209 if($bgcolor) {
210 push @out, "background color: $bgcolor\n";
212 if($statusbar) {
213 push @out, "statusbar: $statusbar\n";
215 if($backdrop) {
216 push @out, "backdrop: $backdrop\n";
218 if($lineselectstart) {
219 push @out, "line selector start color: $lineselectstart\n";
221 if($lineselectend) {
222 push @out, "line selector end color: $lineselectend\n";
224 if($selecttype) {
225 push @out, "selector type: $selecttype\n";
227 if($iconset) {
228 push @out, "iconset: $iconset\n";
230 if($viewericon) {
231 push @out, "viewers iconset: $viewericon\n";
233 if($lineselecttextcolor) {
234 push @out, "line selector text color: $lineselecttextcolor\n";
236 if($filetylecolor) {
237 push @out, "filetype colours: $filetylecolor\n";
239 if($rwps && $has_remote ) {
240 push @out, "rwps: /.rockbox/wps/$rwps\n";
242 if(-f ".rockbox/wps/$cfg") {
243 print STDERR "wpsbuild warning: wps/$cfg already exists!\n";
245 else {
246 open(CFG, ">.rockbox/themes/$cfg");
247 print CFG @out;
248 close(CFG);
252 # Get the LCD sizes first
253 my ($main_height, $main_width, $main_depth) = getlcdsizes();
254 my ($remote_height, $remote_width, $remote_depth) = getlcdsizes(1);
256 #print "LCD: ${main_height}x${main_width}x${main_depth}\n";
257 $has_remote = 1 if ($remote_height && $remote_width && remote_depth);
259 open(WPS, "<$wpslist");
260 while(<WPS>) {
261 my $l = $_;
262 if($l =~ /^ *\#/) {
263 # skip comment
264 next;
266 if($l =~ /^ *<(r|)wps>/i) {
267 $isrwps = $1;
268 $within = 1;
269 # undef is a unary operator (!)
270 undef $wps;
271 undef $wps_prefix;
272 undef $rwps;
273 undef $width;
274 undef $height;
275 undef $font;
276 undef $fgcolor;
277 undef $bgcolor;
278 undef $statusbar;
279 undef $author;
280 undef $req_g_wps;
281 undef $req_t_wps;
282 undef $backdrop;
283 undef $lineselectstart;
284 undef $lineselectend;
285 undef $selecttype;
286 undef $iconset;
287 undef $viewericon;
288 undef $lineselecttextcolor;
289 undef $filetylecolor;
291 next;
293 if($within) {
294 if($l =~ /^ *<\/${isrwps}wps>/i) {
295 # Get the required width and height
296 my ($rheight, $rwidth, $rdepth);
297 if($isrwps) {
298 ($rheight, $rwidth, $rdepth) =
299 ($remote_height, $remote_width, $remote_depth);
301 else {
302 ($rheight, $rwidth, $rdepth) =
303 ($main_height, $main_width, $main_depth);
306 if(!$rheight || !$rwidth) {
307 #printf STDERR "wpsbuild notice: No %sLCD size, skipping $wps\n",
308 #$isrwps?"remote ":"";
309 $within = 0;
310 next;
312 $wpslist =~ /(.*)WPSLIST/;
313 my $wpsdir = $1;
314 # If this WPS installable on this platform, one of the following
315 # two files will be present
316 foreach $d (@depthlist) {
317 next if ($d > $rdepth);
319 $req_g = $rwidth . "x" . $rheight . "x" . $d;
321 $req_g_wps = $wps_prefix . "." . $req_g . ".wps";
322 last if (-e "$wpsdir/$req_g_wps");
324 if ($isrwps) {
325 $req_g = $req_g . "." . $main_width . "x" . $main_height . "x" . "$main_depth";
327 $req_g_wps = $wps_prefix . "." . $req_g . ".wps";
328 last if (-e "$wpsdir/$req_g_wps");
331 $req_t_wps = $wps_prefix . ".txt" . ".wps";
333 #print "LCD: $wps wants $height x $width\n";
334 #print "LCD: is $rheight x $rwidth\n";
336 #print "gwps: $wpsdir/$req_g_wps" . "\n";
337 if (-e "$wpsdir/$req_g_wps" || -e "$wpsdir/$req_t_wps" ) {
339 # The target model has an LCD that is suitable for this
340 # WPS
342 #print "Size requirement is fine!\n";
343 mkdirs() if (-e "$wpsdir/$req_g_wps");
344 if(!$isrwps) {
345 # We only make .cfg files for <wps> sections:
346 buildcfg();
348 copywps();
350 else {
351 #print "(${wps_prefix}-${rwidth}x${rheight}x$rdepth) ";
352 #print "Skip $wps due to size restraints\n";
354 $within = 0;
356 elsif($l =~ /^Name: (.*)/i) {
357 # Note that in the case this is within <rwps>, $wps will contain the
358 # name of the rwps. Use $isrwps to figure out what type it is.
359 $wps = $wps_prefix = $1;
360 $wps_prefix =~ s/\.(r|)wps//;
361 # print $wps_prefix . "\n";
363 elsif($l =~ /^RWPS: (.*)/i) {
364 $rwps = $1;
366 elsif($l =~ /^RWPS\.${main_width}x${main_height}x$main_depth: (.*)/i) {
367 $rwps = $1;
369 elsif($l =~ /^Author: (.*)/i) {
370 $author = $1;
372 elsif($l =~ /^Width: (.*)/i) {
373 $width = $1;
375 elsif($l =~ /^Width\.${main_width}x${main_height}x$main_depth: (.*)/i) {
376 $width = $1;
378 elsif($l =~ /^Height: (.*)/i) {
379 $height = $1;
381 elsif($l =~ /^Height\.${main_width}x${main_height}x$main_depth: (.*)/i) {
382 $height = $1;
384 elsif($l =~ /^Font: (.*)/i) {
385 $font = $1;
387 elsif($l =~ /^Foreground Color: (.*)/i) {
388 $fgcolor = $1;
390 elsif($l =~ /^Background Color: (.*)/i) {
391 $bgcolor = $1;
393 elsif($l =~ /^Font\.${main_width}x${main_height}x$main_depth: (.*)/i) {
394 $font = $1;
395 copythemefont();
397 elsif($l =~ /^Statusbar: (.*)/i) {
398 $statusbar = $1;
400 elsif($l =~ /^Statusbar\.${main_width}x${main_height}x$main_depth: (.*)/i) {
401 $statusbar = $1;
403 elsif($l =~ /^Backdrop: (.*)/i) {
404 $backdrop = $1;
405 copybackdrop();
407 elsif($l =~ /^Backdrop\.${main_width}x${main_height}x$main_depth: (.*)/i) {
408 $backdrop = $1;
409 copybackdrop();
411 elsif($l =~ /^line selector start color: (.*)/i) {
412 $lineselectstart = $1;
414 elsif($l =~ /^line selector end color: (.*)/i) {
415 $lineselectend = $1;
417 elsif($l =~ /^selector type: (.*)/i) {
418 $selecttype = $1;
420 elsif($l =~ /^selector type\.${main_width}x${main_height}x$main_depth: (.*)/i) {
421 $selecttype = $1;
423 elsif($l =~ /^iconset: (.*)/i) {
424 $iconset = $1;
425 copythemeicon();
427 elsif($l =~ /^iconset\.${main_width}x${main_height}x$main_depth: (.*)/i) {
428 $iconset = $1;
429 copythemeicon();
431 elsif($l =~ /^viewers iconset: (.*)/i) {
432 $viewericon = $1;
433 copythemeviewericon();
435 elsif($l =~ /^viewers iconset\.${main_width}x${main_height}x$main_depth: (.*)/i) {
436 $viewericon = $1;
437 copythemeviewericon();
439 elsif($l =~ /^line selector text color: (.*)/i) {
440 $lineselecttextcolor = $1;
442 elsif($l =~ /^filetype colours: (.*)/i) {
443 $filetylecolor = $1;
445 else{
446 #print "Unknown line: $l!\n";
454 close(WPS);