initial custom statusbar commit
[kugel-rb.git] / wps / wpsbuild.pl
blob04e28460254ef28220a03bf8d27654e2f9ec823d
1 #!/usr/bin/perl
2 # __________ __ ___.
3 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 # \/ \/ \/ \/ \/
8 # $Id$
11 use strict;
12 use Getopt::Long qw(:config pass_through); # pass_through so not confused by -DTYPE_STUFF
14 my $ROOT="..";
15 my $verbose;
16 my $rbdir=".rockbox";
17 my $wpslist;
18 my $target;
19 my $modelname;
21 # Get options
22 GetOptions ( 'r|root=s' => \$ROOT,
23 'm|modelname=s' => \$modelname,
24 'v|verbose' => \$verbose,
25 'rbdir=s' => \$rbdir, # If we want to put in a different directory
28 ($wpslist, $target) = @ARGV;
30 my $firmdir="$ROOT/firmware";
31 my $cppdef = $target;
32 my @depthlist = ( 16, 8, 4, 2, 1 );
34 # These parameters are filled in as we parse wpslist
35 my $req_size;
36 my $req_g_wps;
37 my $req_t;
38 my $req_t_wps;
39 my $wps;
40 my $wps_prefix;
41 my $sb_prefix;
42 my $rwps;
43 my $sb;
44 my $sb_w_size;
45 my $rsb;
46 my $rsb_w_size;
47 my $width;
48 my $height;
49 my $font;
50 my $fgcolor;
51 my $bgcolor;
52 my $statusbar;
53 my $author;
54 my $backdrop;
55 my $lineselectstart;
56 my $lineselectend;
57 my $selecttype;
58 my $iconset;
59 my $viewericon;
60 my $lineselecttextcolor;
61 my $filetylecolor;
62 my $listviewport;
63 my $remotelistviewport;
65 # LCD sizes
66 my ($main_height, $main_width, $main_depth);
67 my ($remote_height, $remote_width, $remote_depth);
68 my $has_remote;
71 if(!$wpslist) {
72 print "Usage: wpsbuilds.pl <WPSLIST> <target>\n",
73 "Run this script in the root of the target build, and it will put all the\n",
74 "stuff in $rbdir/wps/\n";
75 exit;
78 sub getlcdsizes
80 my ($remote) = @_;
82 open(GCC, ">gcctemp");
83 if($remote) {
84 # Get the remote LCD screen size
85 print GCC <<STOP
86 \#include "config.h"
87 #ifdef HAVE_REMOTE_LCD
88 Height: LCD_REMOTE_HEIGHT
89 Width: LCD_REMOTE_WIDTH
90 Depth: LCD_REMOTE_DEPTH
91 #endif
92 STOP
95 else {
96 print GCC <<STOP
97 \#include "config.h"
98 Height: LCD_HEIGHT
99 Width: LCD_WIDTH
100 Depth: LCD_DEPTH
101 STOP
104 close(GCC);
106 my $c="cat gcctemp | gcc $cppdef -I. -I$firmdir/export -E -P -";
108 #print "CMD $c\n";
110 open(GETSIZE, "$c|");
112 my ($height, $width, $depth);
113 while(<GETSIZE>) {
114 if($_ =~ /^Height: (\d*)/) {
115 $height = $1;
117 elsif($_ =~ /^Width: (\d*)/) {
118 $width = $1;
120 elsif($_ =~ /^Depth: (\d*)/) {
121 $depth = $1;
123 if($height && $width && $depth) {
124 last;
127 close(GETSIZE);
128 unlink("gcctemp");
130 return ($height, $width, $depth);
133 sub mkdirs
135 my $wpsdir = $wps;
136 $wpsdir =~ s/\.(r|)wps//;
137 mkdir "$rbdir/wps", 0777;
138 mkdir "$rbdir/themes", 0777;
140 if( -d "$rbdir/wps/$wpsdir") {
141 #print STDERR "wpsbuild warning: directory wps/$wpsdir already exists!\n";
143 else
145 mkdir "$rbdir/wps/$wpsdir", 0777;
149 sub copybackdrop
151 #copy the backdrop file into the build dir
152 if ($backdrop ne '') {
153 my $dst = $backdrop;
154 $dst =~ s/(\.[0-9]*x[0-9]*x[0-9]*)//;
155 my $cmd = "cp $ROOT/$backdrop $rbdir/$dst";
156 `$cmd`;
160 sub copythemefont
162 #copy the font specified by the theme
164 my $o=$font;
165 $o =~ s/\.fnt/\.bdf/;
166 mkdir "$rbdir/fonts";
167 my $cmd ="$ROOT/tools/convbdf -f -o \"$rbdir/fonts/$font\" \"$ROOT/fonts/$o\" ";
168 `$cmd`;
171 sub copythemeicon
173 #copy the icon specified by the theme
175 if ($iconset ne '') {
176 $iconset =~ s/.rockbox/$rbdir/;
177 $iconset =~ /\/(.*icons\/(.*))/i;
178 `cp $ROOT/icons/$2 $1`;
182 sub copythemeviewericon
184 #copy the viewer icon specified by the theme
186 if ($viewericon ne '') {
187 $viewericon =~ s/.rockbox/$rbdir/;
188 $viewericon =~ /\/(.*icons\/(.*))/i;
189 `cp $ROOT/icons/$2 $1`;
193 sub copywps
195 # we assume that we copy the WPS files from the same dir the WPSLIST
196 # file is located in
197 my $dir;
198 my @filelist;
199 my $file;
200 my $__sb;
202 if($wpslist =~ /(.*)WPSLIST/) {
203 $dir = $1;
204 $__sb = $sb_prefix . "." . $req_size . ".sb";
205 print "$req_t_wps $req_g_wps $sb_prefix\n";
206 print "$dir/$__sb\n";
208 # system("cp $dir/$wps .rockbox/wps/");
209 # check for <name>.WIDTHxHEIGHTxDEPTH.sb
210 if (-e "$dir/$__sb") {
211 system("cp $dir/$__sb $rbdir/wps/$sb");
213 # check for <name>.WIDTHxHEIGHTxDEPTH.<model>.sb and overwrite the
214 # previous sb if needed
215 $__sb = $sb_prefix . "." . $req_size . "." . $modelname . ".sb";
216 if (-e "$dir/$__sb") {
217 system("cp $dir/$__sb $rbdir/wps/$sb");
220 if (-e "$dir/$req_t_wps" ) {
221 system("cp $dir/$req_t_wps $rbdir/wps/$wps");
223 } elsif (-e "$dir/$req_g_wps") {
224 system("cp $dir/$req_g_wps $rbdir/wps/$wps");
226 open(WPSFILE, "$dir/$req_g_wps");
227 while (<WPSFILE>) {
228 $filelist[$#filelist + 1] = $1 if (/\|([^|]*?.bmp)\|/);
230 close(WPSFILE);
232 if ($#filelist >= 0) {
233 if (-e "$dir/$wps_prefix/$req_size") {
234 foreach $file (@filelist) {
235 system("cp $dir/$wps_prefix/$req_size/$file $rbdir/wps/$wps_prefix/");
238 elsif (-e "$dir/$wps_prefix") {
239 foreach $file (@filelist) {
240 system("cp $dir/$wps_prefix/$file $rbdir/wps/$wps_prefix/");
243 else {
244 print STDERR "beep, no dir to copy WPS from!\n";
248 } else {
249 print STDERR "Skipping $wps - no matching resolution.\n";
251 } else {
252 print STDERR "No source directory!\n";
256 sub buildcfg {
257 my $cfg = $wps;
258 my @out;
260 $cfg =~ s/\.(r|)wps/.cfg/;
262 push @out, <<MOO
264 \# $cfg generated by wpsbuild.pl
265 \# $wps is made by $author
267 wps: /$rbdir/wps/$wps
270 if($font) {
271 push @out, "font: /$rbdir/fonts/$font\n";
273 if($fgcolor && $main_depth > 2) {
274 push @out, "foreground color: $fgcolor\n";
276 if($bgcolor && $main_depth > 2) {
277 push @out, "background color: $bgcolor\n";
279 if($statusbar) {
280 if($rwps && $has_remote ) {
281 push @out, "remote statusbar: $statusbar\n";
283 push @out, "statusbar: $statusbar\n";
285 if(defined($backdrop)) {
286 if ($backdrop eq '') {
287 push @out, "backdrop:\n";
288 } else {
289 # clip resolution from filename
290 $backdrop =~ s/(\.[0-9]*x[0-9]*x[0-9]*)//;
291 push @out, "backdrop: /$rbdir/$backdrop\n";
294 if($lineselectstart && $main_depth > 2) {
295 push @out, "line selector start color: $lineselectstart\n";
297 if($lineselectend && $main_depth > 2) {
298 push @out, "line selector end color: $lineselectend\n";
300 if($selecttype) {
301 push @out, "selector type: $selecttype\n";
303 if(defined($iconset)) {
304 push @out, "iconset: $iconset\n";
306 if(defined($viewericon)) {
307 push @out, "viewers iconset: $viewericon\n";
309 if($lineselecttextcolor && $main_depth > 2 ) {
310 push @out, "line selector text color: $lineselecttextcolor\n";
312 if($filetylecolor && $main_depth > 2) {
313 push @out, "filetype colours: $filetylecolor\n";
315 if($rwps && $has_remote ) {
316 push @out, "rwps: /$rbdir/wps/$rwps\n";
318 if(defined($listviewport)) {
319 push @out, "ui viewport: $listviewport\n";
321 if(defined($remotelistviewport) && $has_remote) {
322 push @out, "remote ui viewport: $listviewport\n";
324 if(-f "$rbdir/wps/$cfg") {
325 print STDERR "wpsbuild warning: wps/$cfg already exists!\n";
327 else {
328 open(CFG, ">$rbdir/themes/$cfg");
329 print CFG @out;
330 close(CFG);
334 # Get the LCD sizes first
335 ($main_height, $main_width, $main_depth) = getlcdsizes();
336 ($remote_height, $remote_width, $remote_depth) = getlcdsizes(1);
338 #print "LCD: ${main_width}x${main_height}x${main_depth}\n";
339 $has_remote = 1 if ($remote_height && $remote_width && $remote_depth);
341 my $isrwps;
342 my $within;
344 open(WPS, "<$wpslist");
345 while(<WPS>) {
346 my $l = $_;
348 # remove CR
349 $l =~ s/\r//g;
350 if($l =~ /^ *\#/) {
351 # skip comment
352 next;
354 if($l =~ /^ *<(r|)wps>/i) {
355 $isrwps = $1;
356 $within = 1;
357 # undef is a unary operator (!)
358 undef $wps;
359 undef $wps_prefix;
360 undef $rwps;
361 undef $sb;
362 undef $rsb;
363 undef $width;
364 undef $height;
365 undef $font;
366 undef $fgcolor;
367 undef $bgcolor;
368 undef $statusbar;
369 undef $author;
370 undef $req_g_wps;
371 undef $req_t_wps;
372 undef $backdrop;
373 undef $lineselectstart;
374 undef $lineselectend;
375 undef $selecttype;
376 undef $iconset;
377 undef $viewericon;
378 undef $lineselecttextcolor;
379 undef $filetylecolor;
380 undef $listviewport;
381 undef $remotelistviewport;
383 next;
385 if($within) {
386 if($l =~ /^ *<\/${isrwps}wps>/i) {
387 # Get the required width and height
388 my ($rheight, $rwidth, $rdepth);
389 if($isrwps) {
390 ($rheight, $rwidth, $rdepth) =
391 ($remote_height, $remote_width, $remote_depth);
393 else {
394 ($rheight, $rwidth, $rdepth) =
395 ($main_height, $main_width, $main_depth);
398 if(!$rheight || !$rwidth) {
399 #printf STDERR "wpsbuild notice: No %sLCD size, skipping $wps\n",
400 #$isrwps?"remote ":"";
401 $within = 0;
402 next;
404 $wpslist =~ /(.*)WPSLIST/;
405 my $wpsdir = $1;
406 # If this WPS installable on this platform, one of the following
407 # two files will be present
408 foreach my $d (@depthlist) {
409 next if ($d > $rdepth);
411 $req_size = $rwidth . "x" . $rheight . "x" . $d;
413 # check for model specific wps
414 $req_g_wps = $wps_prefix . "." . $req_size . "." . $modelname . ".wps";
415 last if (-e "$wpsdir/$req_g_wps");
417 # check for normal wps (with WIDTHxHEIGHTxDEPTH)
418 $req_g_wps = $wps_prefix . "." . $req_size . ".wps";
419 last if (-e "$wpsdir/$req_g_wps");
421 if ($isrwps) {
422 $req_size = $req_size . "." . $main_width . "x" . $main_height . "x" . "$main_depth";
424 $req_g_wps = $wps_prefix . "." . $req_size . ".wps";
425 last if (-e "$wpsdir/$req_g_wps");
428 $req_t_wps = $wps_prefix . $req_t . ".wps";
430 #print "LCD: $wps wants $width x $height\n";
431 #print "LCD: is $rwidth x $rheight\n";
433 #print "gwps: $wpsdir/$req_g_wps" . "\n";
434 if (-e "$wpsdir/$req_g_wps" || -e "$wpsdir/$req_t_wps" ) {
436 # The target model has an LCD that is suitable for this
437 # WPS
439 #print "Size requirement is fine!\n";
440 mkdirs() if (-e "$wpsdir/$req_g_wps");
441 # Do the copying before building the .cfg - buildcfg()
442 # mangles some filenames
443 if ($backdrop) {
444 copybackdrop();
446 if ($iconset) {
447 copythemeicon();
449 if ($viewericon) {
450 copythemeviewericon();
452 if ($font) {
453 copythemefont();
455 if(!$isrwps) {
456 # We only make .cfg files for <wps> sections:
457 buildcfg();
459 copywps();
461 else {
462 #print "(${wps_prefix}-${rwidth}x${rheight}x$rdepth) ";
463 #print "Skip $wps due to size restraints\n";
465 $within = 0;
467 elsif($l =~ /^Name: *(.*)/i) {
468 # Note that in the case this is within <rwps>, $wps will contain the
469 # name of the rwps. Use $isrwps to figure out what type it is.
470 $wps = $wps_prefix = $1;
471 $wps_prefix =~ s/\.(r|)wps//;
472 #print $wps_prefix . "\n";
474 elsif($l =~ /^RWPS: *(.*)/i) {
475 $rwps = $1;
477 elsif($l =~ /^RWPS\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
478 $rwps = $1;
480 elsif($l =~ /^SB: *(.*)/i) {
481 $sb = $sb_prefix = $1;
482 $sb_prefix =~ s/\.(r|)sb//;
484 elsif($l =~ /^SB\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
485 $sb = $1;
487 elsif($l =~ /^RSB: *(.*)/i) {
488 $rsb = $1;
490 elsif($l =~ /^RSB\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
491 $rsb = $1;
493 elsif($l =~ /^Author: *(.*)/i) {
494 $author = $1;
496 elsif($l =~ /^Width: *(.*)/i) {
497 $width = $1;
499 elsif($l =~ /^Width\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
500 $width = $1;
502 elsif($l =~ /^Height: *(.*)/i) {
503 $height = $1;
505 elsif($l =~ /^Height\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
506 $height = $1;
508 elsif($l =~ /^Font: *(.*)/i) {
509 $font = $1;
511 elsif($l =~ /^Font\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
512 $font = $1;
514 elsif($l =~ /^Foreground Color: *(.*)/i) {
515 $fgcolor = $1;
517 elsif($l =~ /^Background Color: *(.*)/i) {
518 $bgcolor = $1;
520 elsif($l =~ /^Statusbar: *(.*)/i) {
521 $statusbar = $1;
523 elsif($l =~ /^Statusbar\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
524 $statusbar = $1;
526 elsif($l =~ /^Backdrop: *(.*)/i) {
527 $backdrop = $1;
529 elsif($l =~ /^Backdrop\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
530 $backdrop = $1;
532 elsif($l =~ /^line selector start color: *(.*)/i) {
533 $lineselectstart = $1;
535 elsif($l =~ /^line selector end color: *(.*)/i) {
536 $lineselectend = $1;
538 elsif($l =~ /^selector type: *(.*)/i) {
539 $selecttype = $1;
541 elsif($l =~ /^selector type\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
542 $selecttype = $1;
544 elsif($l =~ /^iconset: *(.*)/i) {
545 $iconset = $1;
547 elsif($l =~ /^iconset\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
548 $iconset = $1;
550 elsif($l =~ /^viewers iconset: *(.*)/i) {
551 $viewericon = $1;
553 elsif($l =~ /^viewers iconset\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
554 $viewericon = $1;
556 elsif($l =~ /^line selector text color: *(.*)/i) {
557 $lineselecttextcolor = $1;
559 elsif($l =~ /^filetype colours: *(.*)/i) {
560 $filetylecolor = $1;
562 elsif($l =~ /^ui viewport: *(.*)/i) {
563 $listviewport = $1;
565 elsif($l =~ /^ui viewport\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
566 $listviewport = $1;
568 elsif($l =~ /^remote ui viewport: *(.*)/i) {
569 $remotelistviewport = $1;
571 elsif($l =~ /^remote ui viewport\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
572 $remotelistviewport = $1;
574 else{
575 #print "Unknown line: $l!\n";
580 close(WPS);