Correct reset and disk mode combinations for 1G - 3G iPods. Closes FS#11011.
[kugel-rb.git] / wps / wpsbuild.pl
blob81a90f3c0432839b017e9e18da070cb217909f70
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 $sbs_prefix;
42 my $rwps;
43 my $sbs;
44 my $sbs_w_size;
45 my $rsbs;
46 my $rsbs_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 = $sbs_prefix . "." . $req_size . ".sbs";
205 #print "$req_t_wps $req_g_wps $sbs_prefix\n";
206 #print "$dir/$__sb\n";
208 # system("cp $dir/$wps .rockbox/wps/");
209 # check for <name>.WIDTHxHEIGHTxDEPTH.sbs
210 if (-e "$dir/$__sb") {
211 system("cp $dir/$__sb $rbdir/wps/$sbs");
213 # check for <name>.WIDTHxHEIGHTxDEPTH.<model>.sbs and overwrite the
214 # previous sb if needed
215 $__sb = $sbs_prefix . "." . $req_size . "." . $modelname . ".sbs";
216 if (-e "$dir/$__sb") {
217 system("cp $dir/$__sb $rbdir/wps/$sbs");
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(defined($sbs)) {
271 if ($sbs eq '') {
272 push @out, "sbs: -\n";
273 } else {
274 push @out, "sbs: /$rbdir/wps/$sbs\n";
277 if(defined($rsbs) && $has_remote) {
278 if ($rsbs eq '') {
279 push @out, "rsbs: -\n";
280 } else {
281 push @out, "rsbs: /$rbdir/wps/$rsbs\n";
284 if($font) {
285 if ($font eq '') {
286 push @out, "font: -\n";
287 } else {
288 push @out, "font: /$rbdir/fonts/$font\n";
291 if($fgcolor && $main_depth > 2) {
292 push @out, "foreground color: $fgcolor\n";
294 if($bgcolor && $main_depth > 2) {
295 push @out, "background color: $bgcolor\n";
297 if($statusbar) {
298 if($rwps && $has_remote ) {
299 push @out, "remote statusbar: $statusbar\n";
301 push @out, "statusbar: $statusbar\n";
303 if(defined($backdrop)) {
304 if ($backdrop eq '') {
305 push @out, "backdrop: -\n";
306 } else {
307 # clip resolution from filename
308 $backdrop =~ s/(\.[0-9]*x[0-9]*x[0-9]*)//;
309 push @out, "backdrop: /$rbdir/$backdrop\n";
312 if($lineselectstart && $main_depth > 2) {
313 push @out, "line selector start color: $lineselectstart\n";
315 if($lineselectend && $main_depth > 2) {
316 push @out, "line selector end color: $lineselectend\n";
318 if($selecttype) {
319 push @out, "selector type: $selecttype\n";
321 if(defined($iconset)) {
322 if ($iconset eq '') {
323 push @out, "iconset: -\n";
324 } else {
325 push @out, "iconset: $iconset\n";
328 if(defined($viewericon)) {
329 if ($viewericon eq '') {
330 push @out, "viewers iconset: -\n";
331 } else {
332 push @out, "viewers iconset: $viewericon\n";
335 if($lineselecttextcolor && $main_depth > 2 ) {
336 push @out, "line selector text color: $lineselecttextcolor\n";
338 if($filetylecolor && $main_depth > 2) {
339 if ($filetylecolor eq '') {
340 push @out, "filetype colours: -\n";
341 } else {
342 push @out, "filetype colours: $filetylecolor\n";
345 if($rwps && $has_remote ) {
346 if ($rwps eq '') {
347 push @out, "rwps: -\n";
348 } else {
349 push @out, "rwps: /$rbdir/wps/$rwps\n";
352 if(defined($listviewport)) {
353 if ($listviewport eq '') {
354 push @out, "ui viewport: -\n";
355 } else {
356 push @out, "ui viewport: $listviewport\n";
359 if(defined($remotelistviewport) && $has_remote) {
360 if ($remotelistviewport eq '') {
361 push @out, "remote ui viewport: -\n";
362 } else {
363 push @out, "remote ui viewport: $listviewport\n";
366 if(-f "$rbdir/wps/$cfg") {
367 print STDERR "wpsbuild warning: wps/$cfg already exists!\n";
369 else {
370 open(CFG, ">$rbdir/themes/$cfg");
371 print CFG @out;
372 close(CFG);
376 # Get the LCD sizes first
377 ($main_height, $main_width, $main_depth) = getlcdsizes();
378 ($remote_height, $remote_width, $remote_depth) = getlcdsizes(1);
380 #print "LCD: ${main_width}x${main_height}x${main_depth}\n";
381 $has_remote = 1 if ($remote_height && $remote_width && $remote_depth);
383 my $isrwps;
384 my $within;
386 open(WPS, "<$wpslist");
387 while(<WPS>) {
388 my $l = $_;
390 # remove CR
391 $l =~ s/\r//g;
392 if($l =~ /^ *\#/) {
393 # skip comment
394 next;
396 if($l =~ /^ *<(r|)wps>/i) {
397 $isrwps = $1;
398 $within = 1;
399 # undef is a unary operator (!)
400 undef $wps;
401 undef $wps_prefix;
402 undef $rwps;
403 undef $sbs;
404 undef $rsbs;
405 undef $width;
406 undef $height;
407 undef $font;
408 undef $fgcolor;
409 undef $bgcolor;
410 undef $statusbar;
411 undef $author;
412 undef $req_g_wps;
413 undef $req_t_wps;
414 undef $backdrop;
415 undef $lineselectstart;
416 undef $lineselectend;
417 undef $selecttype;
418 undef $iconset;
419 undef $viewericon;
420 undef $lineselecttextcolor;
421 undef $filetylecolor;
422 undef $listviewport;
423 undef $remotelistviewport;
425 next;
427 if($within) {
428 if($l =~ /^ *<\/${isrwps}wps>/i) {
429 # Get the required width and height
430 my ($rheight, $rwidth, $rdepth);
431 if($isrwps) {
432 ($rheight, $rwidth, $rdepth) =
433 ($remote_height, $remote_width, $remote_depth);
435 else {
436 ($rheight, $rwidth, $rdepth) =
437 ($main_height, $main_width, $main_depth);
440 if(!$rheight || !$rwidth) {
441 #printf STDERR "wpsbuild notice: No %sLCD size, skipping $wps\n",
442 #$isrwps?"remote ":"";
443 $within = 0;
444 next;
446 $wpslist =~ /(.*)WPSLIST/;
447 my $wpsdir = $1;
448 # If this WPS installable on this platform, one of the following
449 # two files will be present
450 foreach my $d (@depthlist) {
451 next if ($d > $rdepth);
453 $req_size = $rwidth . "x" . $rheight . "x" . $d;
455 # check for model specific wps
456 $req_g_wps = $wps_prefix . "." . $req_size . "." . $modelname . ".wps";
457 last if (-e "$wpsdir/$req_g_wps");
459 # check for normal wps (with WIDTHxHEIGHTxDEPTH)
460 $req_g_wps = $wps_prefix . "." . $req_size . ".wps";
461 last if (-e "$wpsdir/$req_g_wps");
463 if ($isrwps) {
464 $req_size = $req_size . "." . $main_width . "x" . $main_height . "x" . "$main_depth";
466 $req_g_wps = $wps_prefix . "." . $req_size . ".wps";
467 last if (-e "$wpsdir/$req_g_wps");
470 $req_t_wps = $wps_prefix . ".txt" . ".wps";
472 #print "LCD: $wps wants $width x $height\n";
473 #print "LCD: is $rwidth x $rheight\n";
475 #print "gwps: $wpsdir/$req_g_wps" . "\n";
476 if (-e "$wpsdir/$req_g_wps" || -e "$wpsdir/$req_t_wps" ) {
478 # The target model has an LCD that is suitable for this
479 # WPS
481 #print "Size requirement is fine!\n";
482 mkdirs() if (-e "$wpsdir/$req_g_wps");
483 # Do the copying before building the .cfg - buildcfg()
484 # mangles some filenames
485 if ($backdrop) {
486 copybackdrop();
488 if ($iconset) {
489 copythemeicon();
491 if ($viewericon) {
492 copythemeviewericon();
494 if ($font) {
495 copythemefont();
497 if(!$isrwps) {
498 # We only make .cfg files for <wps> sections:
499 buildcfg();
501 copywps();
503 else {
504 #print "(${wps_prefix}-${rwidth}x${rheight}x$rdepth) ";
505 #print "Skip $wps due to size restraints\n";
507 $within = 0;
509 elsif($l =~ /^Name: *(.*)/i) {
510 # Note that in the case this is within <rwps>, $wps will contain the
511 # name of the rwps. Use $isrwps to figure out what type it is.
512 $wps = $wps_prefix = $1;
513 $wps_prefix =~ s/\.(r|)wps//;
514 #print $wps_prefix . "\n";
516 elsif($l =~ /^RWPS: *(.*)/i) {
517 $rwps = $1;
519 elsif($l =~ /^RWPS\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
520 $rwps = $1;
522 elsif($l =~ /^SBS: *(.*)/i) {
523 $sbs = $sbs_prefix = $1;
524 $sbs_prefix =~ s/\.(r|)sbs//;
526 elsif($l =~ /^SBS\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
527 $sbs = $sbs_prefix = $1;
528 $sbs_prefix =~ s/\.(r|)sbs//;
530 elsif($l =~ /^RSBS: *(.*)/i) {
531 $rsbs = $1;
533 elsif($l =~ /^RSBS\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
534 $rsbs = $1;
536 elsif($l =~ /^Author: *(.*)/i) {
537 $author = $1;
539 elsif($l =~ /^Width: *(.*)/i) {
540 $width = $1;
542 elsif($l =~ /^Width\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
543 $width = $1;
545 elsif($l =~ /^Height: *(.*)/i) {
546 $height = $1;
548 elsif($l =~ /^Height\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
549 $height = $1;
551 elsif($l =~ /^Font: *(.*)/i) {
552 $font = $1;
554 elsif($l =~ /^Font\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
555 $font = $1;
557 elsif($l =~ /^Foreground Color: *(.*)/i) {
558 $fgcolor = $1;
560 elsif($l =~ /^Background Color: *(.*)/i) {
561 $bgcolor = $1;
563 elsif($l =~ /^Statusbar: *(.*)/i) {
564 $statusbar = $1;
566 elsif($l =~ /^Statusbar\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
567 $statusbar = $1;
569 elsif($l =~ /^Backdrop: *(.*)/i) {
570 $backdrop = $1;
572 elsif($l =~ /^Backdrop\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
573 $backdrop = $1;
575 elsif($l =~ /^line selector start color: *(.*)/i) {
576 $lineselectstart = $1;
578 elsif($l =~ /^line selector end color: *(.*)/i) {
579 $lineselectend = $1;
581 elsif($l =~ /^selector type: *(.*)/i) {
582 $selecttype = $1;
584 elsif($l =~ /^selector type\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
585 $selecttype = $1;
587 elsif($l =~ /^iconset: *(.*)/i) {
588 $iconset = $1;
590 elsif($l =~ /^iconset\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
591 $iconset = $1;
593 elsif($l =~ /^viewers iconset: *(.*)/i) {
594 $viewericon = $1;
596 elsif($l =~ /^viewers iconset\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
597 $viewericon = $1;
599 elsif($l =~ /^line selector text color: *(.*)/i) {
600 $lineselecttextcolor = $1;
602 elsif($l =~ /^filetype colours: *(.*)/i) {
603 $filetylecolor = $1;
605 elsif($l =~ /^ui viewport: *(.*)/i) {
606 $listviewport = $1;
608 elsif($l =~ /^ui viewport\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
609 $listviewport = $1;
611 elsif($l =~ /^remote ui viewport: *(.*)/i) {
612 $remotelistviewport = $1;
614 elsif($l =~ /^remote ui viewport\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
615 $remotelistviewport = $1;
617 else{
618 #print "Unknown line: $l!\n";
623 close(WPS);