MPIO: move files a bit in preparation for HD300 port
[kugel-rb.git] / wps / wpsbuild.pl
blobe516c3d444ff1c75c4d98e47454924575a4f53ba
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 $tempdir=".rockbox";
18 my $wpslist;
19 my $target;
20 my $modelname;
22 # Get options
23 GetOptions ( 'r|root=s' => \$ROOT,
24 'm|modelname=s' => \$modelname,
25 'v|verbose' => \$verbose,
26 'rbdir=s' => \$rbdir, # If we want to put in a different directory
27 'tempdir=s' => \$tempdir, # override .rockbox temporary dir
30 ($wpslist, $target) = @ARGV;
32 my $firmdir="$ROOT/firmware";
33 my $cppdef = $target;
34 my @depthlist = ( 16, 8, 4, 2, 1 );
36 # These parameters are filled in as we parse wpslist
37 my $req_size;
38 my $req_g_wps;
39 my $req_t;
40 my $req_t_wps;
41 my $wps;
42 my $wps_prefix;
43 my $sbs_prefix;
44 my $rwps;
45 my $sbs;
46 my $sbs_w_size;
47 my $rsbs;
48 my $rsbs_w_size;
49 my $width;
50 my $height;
51 my $font;
52 my $remotefont;
53 my $fgcolor;
54 my $bgcolor;
55 my $statusbar;
56 my $author;
57 my $backdrop;
58 my $lineselectstart;
59 my $lineselectend;
60 my $selecttype;
61 my $iconset;
62 my $viewericon;
63 my $lineselecttextcolor;
64 my $filetylecolor;
65 my $listviewport;
66 my $remotelistviewport;
68 # LCD sizes
69 my ($main_height, $main_width, $main_depth);
70 my ($remote_height, $remote_width, $remote_depth);
71 my $has_remote;
74 if(!$wpslist) {
75 print "Usage: wpsbuilds.pl <WPSLIST> <target>\n",
76 "Run this script in the root of the target build, and it will put all the\n",
77 "stuff in $tempdir/wps/\n and build the cfg according to $rbdir";
78 exit;
81 sub getlcdsizes
83 my ($remote) = @_;
85 open(GCC, ">gcctemp");
86 if($remote) {
87 # Get the remote LCD screen size
88 print GCC <<STOP
89 \#include "config.h"
90 #ifdef HAVE_REMOTE_LCD
91 Height: LCD_REMOTE_HEIGHT
92 Width: LCD_REMOTE_WIDTH
93 Depth: LCD_REMOTE_DEPTH
94 #endif
95 STOP
98 else {
99 print GCC <<STOP
100 \#include "config.h"
101 Height: LCD_HEIGHT
102 Width: LCD_WIDTH
103 Depth: LCD_DEPTH
104 STOP
107 close(GCC);
109 my $c="cat gcctemp | gcc $cppdef -I. -I$firmdir/export -E -P -";
111 #print "CMD $c\n";
113 open(GETSIZE, "$c|");
115 my ($height, $width, $depth);
116 while(<GETSIZE>) {
117 if($_ =~ /^Height: (\d*)/) {
118 $height = $1;
120 elsif($_ =~ /^Width: (\d*)/) {
121 $width = $1;
123 elsif($_ =~ /^Depth: (\d*)/) {
124 $depth = $1;
126 if($height && $width && $depth) {
127 last;
130 close(GETSIZE);
131 unlink("gcctemp");
133 return ($height, $width, $depth);
136 sub mkdirs
138 my $wpsdir = $wps;
139 $wpsdir =~ s/\.(r|)wps//;
140 mkdir "$tempdir/wps", 0777;
141 mkdir "$tempdir/themes", 0777;
143 if( -d "$tempdir/wps/$wpsdir") {
144 #print STDERR "wpsbuild warning: directory wps/$wpsdir already exists!\n";
146 else
148 mkdir "$tempdir/wps/$wpsdir", 0777;
152 sub copybackdrop
154 #copy the backdrop file into the build dir
155 if ($backdrop ne '') {
156 my $dst = $backdrop;
157 $dst =~ s/(\.[0-9]*x[0-9]*x[0-9]*)//;
158 my $cmd = "cp $ROOT/$backdrop $tempdir/$dst";
159 `$cmd`;
163 sub copythemefont
165 #copy the font specified by the theme
166 my $o = $_[0];
168 $o =~ s/\.fnt/\.bdf/;
169 mkdir "$tempdir/fonts";
170 my $cmd ="$ROOT/tools/convbdf -f -o \"$tempdir/fonts/$_[0]\" \"$ROOT/fonts/$o\" ";
171 `$cmd`;
174 sub copythemeicon
176 #copy the icon specified by the theme
177 if ($iconset ne '') {
178 my $tempicon = $tempdir . "/" . $iconset;
179 $iconset = $rbdir . "/" . $iconset;
180 $tempicon =~ /\/.*icons\/(.*)/i;
181 `cp $ROOT/icons/$1 $tempicon`;
185 sub copythemeviewericon
187 #copy the viewer icon specified by the theme
189 if ($viewericon ne '') {
190 my $tempviewericon = $tempdir . "/" . $viewericon;
191 $viewericon = $rbdir . "/" . $viewericon;
192 $tempviewericon =~ /\/.*icons\/(.*)/i;
193 `cp $ROOT/icons/$1 $tempviewericon`;
197 sub copywps
199 # we assume that we copy the WPS files from the same dir the WPSLIST
200 # file is located in
201 my $dir;
202 my @filelist;
203 my $file;
204 my $__sb;
206 if($wpslist =~ /(.*)WPSLIST/) {
207 $dir = $1;
208 $__sb = $sbs_prefix . "." . $req_size . ".sbs";
209 #print "$req_t_wps $req_g_wps $sbs_prefix\n";
210 #print "$dir/$__sb\n";
212 # system("cp $dir/$wps .rockbox/wps/");
213 # check for <name>.WIDTHxHEIGHTxDEPTH.sbs
214 if (-e "$dir/$__sb") {
215 system("cp $dir/$__sb $tempdir/wps/$sbs");
217 # check for <name>.WIDTHxHEIGHTxDEPTH.<model>.sbs and overwrite the
218 # previous sb if needed
219 $__sb = $sbs_prefix . "." . $req_size . "." . $modelname . ".sbs";
220 if (-e "$dir/$__sb") {
221 system("cp $dir/$__sb $tempdir/wps/$sbs");
224 if (-e "$dir/$req_t_wps" ) {
225 system("cp $dir/$req_t_wps $tempdir/wps/$wps");
227 } elsif (-e "$dir/$req_g_wps") {
228 system("cp $dir/$req_g_wps $tempdir/wps/$wps");
230 open(WPSFILE, "$dir/$req_g_wps");
231 while (<WPSFILE>) {
232 $filelist[$#filelist + 1] = $1 if (/[\(,]([^,]*?.bmp)[\),]/);
234 close(WPSFILE);
236 if ($#filelist >= 0) {
237 if (-e "$dir/$wps_prefix/$req_size") {
238 foreach $file (@filelist) {
239 system("cp $dir/$wps_prefix/$req_size/$file $tempdir/wps/$wps_prefix/");
242 elsif (-e "$dir/$wps_prefix") {
243 foreach $file (@filelist) {
244 system("cp $dir/$wps_prefix/$file $tempdir/wps/$wps_prefix/");
247 else {
248 print STDERR "beep, no dir to copy WPS from!\n";
252 } else {
253 print STDERR "Skipping $wps - no matching resolution.\n";
255 } else {
256 print STDERR "No source directory!\n";
260 sub buildcfg {
261 my $cfg = $wps;
262 my @out;
264 $cfg =~ s/\.(r|)wps/.cfg/;
266 push @out, <<MOO
268 \# $cfg generated by wpsbuild.pl
269 \# $wps is made by $author
271 wps: $rbdir/wps/$wps
274 if(defined($sbs)) {
275 if ($sbs eq '') {
276 push @out, "sbs: -\n";
277 } else {
278 push @out, "sbs: $rbdir/wps/$sbs\n";
281 if(defined($rsbs) && $has_remote) {
282 if ($rsbs eq '') {
283 push @out, "rsbs: -\n";
284 } else {
285 push @out, "rsbs: $rbdir/wps/$rsbs\n";
288 if($font) {
289 if ($font eq '') {
290 push @out, "font: -\n";
291 } else {
292 push @out, "font: $rbdir/fonts/$font\n";
295 if(defined($remotefont) && $has_remote) {
296 if ($remotefont eq '') {
297 push @out, "remote font: -\n";
298 } else {
299 push @out, "remote font: $rbdir/fonts/$remotefont\n";
302 if($fgcolor && $main_depth > 2) {
303 push @out, "foreground color: $fgcolor\n";
305 if($bgcolor && $main_depth > 2) {
306 push @out, "background color: $bgcolor\n";
308 if($statusbar) {
309 if($rwps && $has_remote ) {
310 push @out, "remote statusbar: $statusbar\n";
312 push @out, "statusbar: $statusbar\n";
314 if(defined($backdrop)) {
315 if ($backdrop eq '') {
316 push @out, "backdrop: -\n";
317 } else {
318 # clip resolution from filename
319 $backdrop =~ s/(\.[0-9]*x[0-9]*x[0-9]*)//;
320 push @out, "backdrop: $rbdir/$backdrop\n";
323 if($lineselectstart && $main_depth > 2) {
324 push @out, "line selector start color: $lineselectstart\n";
326 if($lineselectend && $main_depth > 2) {
327 push @out, "line selector end color: $lineselectend\n";
329 if($selecttype) {
330 push @out, "selector type: $selecttype\n";
332 if(defined($iconset)) {
333 if ($iconset eq '') {
334 push @out, "iconset: -\n";
335 } else {
336 push @out, "iconset: $iconset\n";
339 if(defined($viewericon)) {
340 if ($viewericon eq '') {
341 push @out, "viewers iconset: -\n";
342 } else {
343 push @out, "viewers iconset: $viewericon\n";
346 if($lineselecttextcolor && $main_depth > 2 ) {
347 push @out, "line selector text color: $lineselecttextcolor\n";
349 if($filetylecolor && $main_depth > 2) {
350 if ($filetylecolor eq '') {
351 push @out, "filetype colours: -\n";
352 } else {
353 push @out, "filetype colours: $filetylecolor\n";
356 if($rwps && $has_remote ) {
357 if ($rwps eq '') {
358 push @out, "rwps: -\n";
359 } else {
360 push @out, "rwps: $rbdir/wps/$rwps\n";
363 if(defined($listviewport)) {
364 if ($listviewport eq '') {
365 push @out, "ui viewport: -\n";
366 } else {
367 push @out, "ui viewport: $listviewport\n";
370 if(defined($remotelistviewport) && $has_remote) {
371 if ($remotelistviewport eq '') {
372 push @out, "remote ui viewport: -\n";
373 } else {
374 push @out, "remote ui viewport: $listviewport\n";
377 if(-f "$tempdir/wps/$cfg") {
378 print STDERR "wpsbuild warning: wps/$cfg already exists!\n";
380 else {
381 open(CFG, ">$tempdir/themes/$cfg");
382 print CFG @out;
383 close(CFG);
387 # Get the LCD sizes first
388 ($main_height, $main_width, $main_depth) = getlcdsizes();
389 ($remote_height, $remote_width, $remote_depth) = getlcdsizes(1);
391 #print "LCD: ${main_width}x${main_height}x${main_depth}\n";
392 $has_remote = 1 if ($remote_height && $remote_width && $remote_depth);
394 my $isrwps;
395 my $within;
397 open(WPS, "<$wpslist");
398 while(<WPS>) {
399 my $l = $_;
401 # remove CR
402 $l =~ s/\r//g;
403 if($l =~ /^ *\#/) {
404 # skip comment
405 next;
408 # prefix $rbdir with / if needed (needed for the theme.cfg)
409 unless ($rbdir =~ m/^\/.*/) {
410 $rbdir = "/" . $rbdir;
413 if($l =~ /^ *<(r|)wps>/i) {
414 $isrwps = $1;
415 $within = 1;
416 # undef is a unary operator (!)
417 undef $wps;
418 undef $wps_prefix;
419 undef $rwps;
420 undef $sbs;
421 undef $rsbs;
422 undef $width;
423 undef $height;
424 undef $font;
425 undef $remotefont;
426 undef $fgcolor;
427 undef $bgcolor;
428 undef $statusbar;
429 undef $author;
430 undef $req_g_wps;
431 undef $req_t_wps;
432 undef $backdrop;
433 undef $lineselectstart;
434 undef $lineselectend;
435 undef $selecttype;
436 undef $iconset;
437 undef $viewericon;
438 undef $lineselecttextcolor;
439 undef $filetylecolor;
440 undef $listviewport;
441 undef $remotelistviewport;
443 next;
445 if($within) {
446 if($l =~ /^ *<\/${isrwps}wps>/i) {
447 # Get the required width and height
448 my ($rheight, $rwidth, $rdepth);
449 if($isrwps) {
450 ($rheight, $rwidth, $rdepth) =
451 ($remote_height, $remote_width, $remote_depth);
453 else {
454 ($rheight, $rwidth, $rdepth) =
455 ($main_height, $main_width, $main_depth);
458 if(!$rheight || !$rwidth) {
459 #printf STDERR "wpsbuild notice: No %sLCD size, skipping $wps\n",
460 #$isrwps?"remote ":"";
461 $within = 0;
462 next;
464 $wpslist =~ /(.*)WPSLIST/;
465 my $wpsdir = $1;
466 # If this WPS installable on this platform, one of the following
467 # two files will be present
468 foreach my $d (@depthlist) {
469 next if ($d > $rdepth);
471 $req_size = $rwidth . "x" . $rheight . "x" . $d;
473 # check for model specific wps
474 $req_g_wps = $wps_prefix . "." . $req_size . "." . $modelname . ".wps";
475 last if (-e "$wpsdir/$req_g_wps");
477 # check for normal wps (with WIDTHxHEIGHTxDEPTH)
478 $req_g_wps = $wps_prefix . "." . $req_size . ".wps";
479 last if (-e "$wpsdir/$req_g_wps");
481 if ($isrwps) {
482 $req_size = $req_size . "." . $main_width . "x" . $main_height . "x" . "$main_depth";
484 $req_g_wps = $wps_prefix . "." . $req_size . ".wps";
485 last if (-e "$wpsdir/$req_g_wps");
488 $req_t_wps = $wps_prefix . ".txt" . ".wps";
490 #print "LCD: $wps wants $width x $height\n";
491 #print "LCD: is $rwidth x $rheight\n";
493 #print "gwps: $wpsdir/$req_g_wps" . "\n";
494 if (-e "$wpsdir/$req_g_wps" || -e "$wpsdir/$req_t_wps" ) {
496 # The target model has an LCD that is suitable for this
497 # WPS
499 #print "Size requirement is fine!\n";
500 mkdirs() if (-e "$wpsdir/$req_g_wps");
501 # Do the copying before building the .cfg - buildcfg()
502 # mangles some filenames
503 if ($backdrop) {
504 copybackdrop();
506 if ($iconset) {
507 copythemeicon();
509 if ($viewericon) {
510 copythemeviewericon();
512 if ($font) {
513 copythemefont($font);
515 if ($remotefont) {
516 copythemefont($remotefont);
518 if(!$isrwps) {
519 # We only make .cfg files for <wps> sections:
520 buildcfg();
522 copywps();
524 else {
525 #print "(${wps_prefix}-${rwidth}x${rheight}x$rdepth) ";
526 #print "Skip $wps due to size restraints\n";
528 $within = 0;
530 elsif($l =~ /^Name: *(.*)/i) {
531 # Note that in the case this is within <rwps>, $wps will contain the
532 # name of the rwps. Use $isrwps to figure out what type it is.
533 $wps = $wps_prefix = $1;
534 $wps_prefix =~ s/\.(r|)wps//;
535 #print $wps_prefix . "\n";
537 elsif($l =~ /^RWPS: *(.*)/i) {
538 $rwps = $1;
540 elsif($l =~ /^RWPS\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
541 $rwps = $1;
543 elsif($l =~ /^SBS: *(.*)/i) {
544 $sbs = $sbs_prefix = $1;
545 $sbs_prefix =~ s/\.(r|)sbs//;
547 elsif($l =~ /^SBS\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
548 $sbs = $sbs_prefix = $1;
549 $sbs_prefix =~ s/\.(r|)sbs//;
551 elsif($l =~ /^RSBS: *(.*)/i) {
552 $rsbs = $1;
554 elsif($l =~ /^RSBS\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
555 $rsbs = $1;
557 elsif($l =~ /^Author: *(.*)/i) {
558 $author = $1;
560 elsif($l =~ /^Width: *(.*)/i) {
561 $width = $1;
563 elsif($l =~ /^Width\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
564 $width = $1;
566 elsif($l =~ /^Height: *(.*)/i) {
567 $height = $1;
569 elsif($l =~ /^Height\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
570 $height = $1;
572 elsif($l =~ /^Font: *(.*)/i) {
573 $font = $1;
575 elsif($l =~ /^Font\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
576 $font = $1;
578 elsif($l =~ /^Remote Font\.${remote_width}x${remote_height}x$remote_depth: *(.*)/i) {
579 $remotefont = $1;
581 elsif($l =~ /^Remote Font: *(.*)/i) {
582 $remotefont = $1;
584 elsif($l =~ /^Foreground Color: *(.*)/i) {
585 $fgcolor = $1;
587 elsif($l =~ /^Background Color: *(.*)/i) {
588 $bgcolor = $1;
590 elsif($l =~ /^Statusbar: *(.*)/i) {
591 $statusbar = $1;
593 elsif($l =~ /^Statusbar\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
594 $statusbar = $1;
596 elsif($l =~ /^Backdrop: *(.*)/i) {
597 $backdrop = $1;
599 elsif($l =~ /^Backdrop\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
600 $backdrop = $1;
602 elsif($l =~ /^line selector start color: *(.*)/i) {
603 $lineselectstart = $1;
605 elsif($l =~ /^line selector end color: *(.*)/i) {
606 $lineselectend = $1;
608 elsif($l =~ /^selector type: *(.*)/i) {
609 $selecttype = $1;
611 elsif($l =~ /^selector type\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
612 $selecttype = $1;
614 elsif($l =~ /^iconset: *(.*)/i) {
615 $iconset = $1;
617 elsif($l =~ /^iconset\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
618 $iconset = $1;
620 elsif($l =~ /^viewers iconset: *(.*)/i) {
621 $viewericon = $1;
623 elsif($l =~ /^viewers iconset\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
624 $viewericon = $1;
626 elsif($l =~ /^line selector text color: *(.*)/i) {
627 $lineselecttextcolor = $1;
629 elsif($l =~ /^filetype colours: *(.*)/i) {
630 $filetylecolor = $1;
632 elsif($l =~ /^ui viewport: *(.*)/i) {
633 $listviewport = $1;
635 elsif($l =~ /^ui viewport\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
636 $listviewport = $1;
638 elsif($l =~ /^remote ui viewport: *(.*)/i) {
639 $remotelistviewport = $1;
641 elsif($l =~ /^remote ui viewport\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
642 $remotelistviewport = $1;
644 else{
645 #print "Unknown line: $l!\n";
650 close(WPS);