Fix wrong comments in tuner-clipplus.c
[maemo-rb.git] / wps / wpsbuild.pl
blobf07ad6dc01b0281e8f9e6242521ea326130d655b
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 $remotefont;
51 my $fgcolor;
52 my $bgcolor;
53 my $statusbar;
54 my $author;
55 my $backdrop;
56 my $lineselectstart;
57 my $lineselectend;
58 my $selecttype;
59 my $iconset;
60 my $viewericon;
61 my $lineselecttextcolor;
62 my $filetylecolor;
63 my $listviewport;
64 my $remotelistviewport;
66 # LCD sizes
67 my ($main_height, $main_width, $main_depth);
68 my ($remote_height, $remote_width, $remote_depth);
69 my $has_remote;
72 if(!$wpslist) {
73 print "Usage: wpsbuilds.pl <WPSLIST> <target>\n",
74 "Run this script in the root of the target build, and it will put all the\n",
75 "stuff in $rbdir/wps/\n";
76 exit;
79 sub getlcdsizes
81 my ($remote) = @_;
83 open(GCC, ">gcctemp");
84 if($remote) {
85 # Get the remote LCD screen size
86 print GCC <<STOP
87 \#include "config.h"
88 #ifdef HAVE_REMOTE_LCD
89 Height: LCD_REMOTE_HEIGHT
90 Width: LCD_REMOTE_WIDTH
91 Depth: LCD_REMOTE_DEPTH
92 #endif
93 STOP
96 else {
97 print GCC <<STOP
98 \#include "config.h"
99 Height: LCD_HEIGHT
100 Width: LCD_WIDTH
101 Depth: LCD_DEPTH
102 STOP
105 close(GCC);
107 my $c="cat gcctemp | gcc $cppdef -I. -I$firmdir/export -E -P -";
109 #print "CMD $c\n";
111 open(GETSIZE, "$c|");
113 my ($height, $width, $depth);
114 while(<GETSIZE>) {
115 if($_ =~ /^Height: (\d*)/) {
116 $height = $1;
118 elsif($_ =~ /^Width: (\d*)/) {
119 $width = $1;
121 elsif($_ =~ /^Depth: (\d*)/) {
122 $depth = $1;
124 if($height && $width && $depth) {
125 last;
128 close(GETSIZE);
129 unlink("gcctemp");
131 return ($height, $width, $depth);
134 sub mkdirs
136 my $wpsdir = $wps;
137 $wpsdir =~ s/\.(r|)wps//;
138 mkdir "$rbdir/wps", 0777;
139 mkdir "$rbdir/themes", 0777;
141 if( -d "$rbdir/wps/$wpsdir") {
142 #print STDERR "wpsbuild warning: directory wps/$wpsdir already exists!\n";
144 else
146 mkdir "$rbdir/wps/$wpsdir", 0777;
150 sub copybackdrop
152 #copy the backdrop file into the build dir
153 if ($backdrop ne '') {
154 my $dst = $backdrop;
155 $dst =~ s/(\.[0-9]*x[0-9]*x[0-9]*)//;
156 my $cmd = "cp $ROOT/$backdrop $rbdir/$dst";
157 `$cmd`;
161 sub copythemefont
163 #copy the font specified by the theme
164 my $o = $_[0];
166 $o =~ s/\.fnt/\.bdf/;
167 mkdir "$rbdir/fonts";
168 my $cmd ="$ROOT/tools/convbdf -f -o \"$rbdir/fonts/$_[0]\" \"$ROOT/fonts/$o\" ";
169 `$cmd`;
172 sub copythemeicon
174 #copy the icon specified by the theme
176 if ($iconset ne '') {
177 $iconset =~ s/.rockbox/$rbdir/;
178 $iconset =~ /\/(.*icons\/(.*))/i;
179 `cp $ROOT/icons/$2 $1`;
183 sub copythemeviewericon
185 #copy the viewer icon specified by the theme
187 if ($viewericon ne '') {
188 $viewericon =~ s/.rockbox/$rbdir/;
189 $viewericon =~ /\/(.*icons\/(.*))/i;
190 `cp $ROOT/icons/$2 $1`;
194 sub copywps
196 # we assume that we copy the WPS files from the same dir the WPSLIST
197 # file is located in
198 my $dir;
199 my @filelist;
200 my $file;
201 my $__sb;
203 if($wpslist =~ /(.*)WPSLIST/) {
204 $dir = $1;
205 $__sb = $sbs_prefix . "." . $req_size . ".sbs";
206 #print "$req_t_wps $req_g_wps $sbs_prefix\n";
207 #print "$dir/$__sb\n";
209 # system("cp $dir/$wps .rockbox/wps/");
210 # check for <name>.WIDTHxHEIGHTxDEPTH.sbs
211 if (-e "$dir/$__sb") {
212 system("cp $dir/$__sb $rbdir/wps/$sbs");
214 # check for <name>.WIDTHxHEIGHTxDEPTH.<model>.sbs and overwrite the
215 # previous sb if needed
216 $__sb = $sbs_prefix . "." . $req_size . "." . $modelname . ".sbs";
217 if (-e "$dir/$__sb") {
218 system("cp $dir/$__sb $rbdir/wps/$sbs");
221 if (-e "$dir/$req_t_wps" ) {
222 system("cp $dir/$req_t_wps $rbdir/wps/$wps");
224 } elsif (-e "$dir/$req_g_wps") {
225 system("cp $dir/$req_g_wps $rbdir/wps/$wps");
227 open(WPSFILE, "$dir/$req_g_wps");
228 while (<WPSFILE>) {
229 $filelist[$#filelist + 1] = $1 if (/[\(,]([^,]*?.bmp)[\),]/);
231 close(WPSFILE);
233 if ($#filelist >= 0) {
234 if (-e "$dir/$wps_prefix/$req_size") {
235 foreach $file (@filelist) {
236 system("cp $dir/$wps_prefix/$req_size/$file $rbdir/wps/$wps_prefix/");
239 elsif (-e "$dir/$wps_prefix") {
240 foreach $file (@filelist) {
241 system("cp $dir/$wps_prefix/$file $rbdir/wps/$wps_prefix/");
244 else {
245 print STDERR "beep, no dir to copy WPS from!\n";
249 } else {
250 print STDERR "Skipping $wps - no matching resolution.\n";
252 } else {
253 print STDERR "No source directory!\n";
257 sub buildcfg {
258 my $cfg = $wps;
259 my @out;
261 $cfg =~ s/\.(r|)wps/.cfg/;
263 push @out, <<MOO
265 \# $cfg generated by wpsbuild.pl
266 \# $wps is made by $author
268 wps: /$rbdir/wps/$wps
271 if(defined($sbs)) {
272 if ($sbs eq '') {
273 push @out, "sbs: -\n";
274 } else {
275 push @out, "sbs: /$rbdir/wps/$sbs\n";
278 if(defined($rsbs) && $has_remote) {
279 if ($rsbs eq '') {
280 push @out, "rsbs: -\n";
281 } else {
282 push @out, "rsbs: /$rbdir/wps/$rsbs\n";
285 if($font) {
286 if ($font eq '') {
287 push @out, "font: -\n";
288 } else {
289 push @out, "font: /$rbdir/fonts/$font\n";
292 if(defined($remotefont) && $has_remote) {
293 if ($remotefont eq '') {
294 push @out, "remote font: -\n";
295 } else {
296 push @out, "remote font: /$rbdir/fonts/$remotefont\n";
299 if($fgcolor && $main_depth > 2) {
300 push @out, "foreground color: $fgcolor\n";
302 if($bgcolor && $main_depth > 2) {
303 push @out, "background color: $bgcolor\n";
305 if($statusbar) {
306 if($rwps && $has_remote ) {
307 push @out, "remote statusbar: $statusbar\n";
309 push @out, "statusbar: $statusbar\n";
311 if(defined($backdrop)) {
312 if ($backdrop eq '') {
313 push @out, "backdrop: -\n";
314 } else {
315 # clip resolution from filename
316 $backdrop =~ s/(\.[0-9]*x[0-9]*x[0-9]*)//;
317 push @out, "backdrop: /$rbdir/$backdrop\n";
320 if($lineselectstart && $main_depth > 2) {
321 push @out, "line selector start color: $lineselectstart\n";
323 if($lineselectend && $main_depth > 2) {
324 push @out, "line selector end color: $lineselectend\n";
326 if($selecttype) {
327 push @out, "selector type: $selecttype\n";
329 if(defined($iconset)) {
330 if ($iconset eq '') {
331 push @out, "iconset: -\n";
332 } else {
333 push @out, "iconset: $iconset\n";
336 if(defined($viewericon)) {
337 if ($viewericon eq '') {
338 push @out, "viewers iconset: -\n";
339 } else {
340 push @out, "viewers iconset: $viewericon\n";
343 if($lineselecttextcolor && $main_depth > 2 ) {
344 push @out, "line selector text color: $lineselecttextcolor\n";
346 if($filetylecolor && $main_depth > 2) {
347 if ($filetylecolor eq '') {
348 push @out, "filetype colours: -\n";
349 } else {
350 push @out, "filetype colours: $filetylecolor\n";
353 if($rwps && $has_remote ) {
354 if ($rwps eq '') {
355 push @out, "rwps: -\n";
356 } else {
357 push @out, "rwps: /$rbdir/wps/$rwps\n";
360 if(defined($listviewport)) {
361 if ($listviewport eq '') {
362 push @out, "ui viewport: -\n";
363 } else {
364 push @out, "ui viewport: $listviewport\n";
367 if(defined($remotelistviewport) && $has_remote) {
368 if ($remotelistviewport eq '') {
369 push @out, "remote ui viewport: -\n";
370 } else {
371 push @out, "remote ui viewport: $listviewport\n";
374 if(-f "$rbdir/wps/$cfg") {
375 print STDERR "wpsbuild warning: wps/$cfg already exists!\n";
377 else {
378 open(CFG, ">$rbdir/themes/$cfg");
379 print CFG @out;
380 close(CFG);
384 # Get the LCD sizes first
385 ($main_height, $main_width, $main_depth) = getlcdsizes();
386 ($remote_height, $remote_width, $remote_depth) = getlcdsizes(1);
388 #print "LCD: ${main_width}x${main_height}x${main_depth}\n";
389 $has_remote = 1 if ($remote_height && $remote_width && $remote_depth);
391 my $isrwps;
392 my $within;
394 open(WPS, "<$wpslist");
395 while(<WPS>) {
396 my $l = $_;
398 # remove CR
399 $l =~ s/\r//g;
400 if($l =~ /^ *\#/) {
401 # skip comment
402 next;
404 if($l =~ /^ *<(r|)wps>/i) {
405 $isrwps = $1;
406 $within = 1;
407 # undef is a unary operator (!)
408 undef $wps;
409 undef $wps_prefix;
410 undef $rwps;
411 undef $sbs;
412 undef $rsbs;
413 undef $width;
414 undef $height;
415 undef $font;
416 undef $remotefont;
417 undef $fgcolor;
418 undef $bgcolor;
419 undef $statusbar;
420 undef $author;
421 undef $req_g_wps;
422 undef $req_t_wps;
423 undef $backdrop;
424 undef $lineselectstart;
425 undef $lineselectend;
426 undef $selecttype;
427 undef $iconset;
428 undef $viewericon;
429 undef $lineselecttextcolor;
430 undef $filetylecolor;
431 undef $listviewport;
432 undef $remotelistviewport;
434 next;
436 if($within) {
437 if($l =~ /^ *<\/${isrwps}wps>/i) {
438 # Get the required width and height
439 my ($rheight, $rwidth, $rdepth);
440 if($isrwps) {
441 ($rheight, $rwidth, $rdepth) =
442 ($remote_height, $remote_width, $remote_depth);
444 else {
445 ($rheight, $rwidth, $rdepth) =
446 ($main_height, $main_width, $main_depth);
449 if(!$rheight || !$rwidth) {
450 #printf STDERR "wpsbuild notice: No %sLCD size, skipping $wps\n",
451 #$isrwps?"remote ":"";
452 $within = 0;
453 next;
455 $wpslist =~ /(.*)WPSLIST/;
456 my $wpsdir = $1;
457 # If this WPS installable on this platform, one of the following
458 # two files will be present
459 foreach my $d (@depthlist) {
460 next if ($d > $rdepth);
462 $req_size = $rwidth . "x" . $rheight . "x" . $d;
464 # check for model specific wps
465 $req_g_wps = $wps_prefix . "." . $req_size . "." . $modelname . ".wps";
466 last if (-e "$wpsdir/$req_g_wps");
468 # check for normal wps (with WIDTHxHEIGHTxDEPTH)
469 $req_g_wps = $wps_prefix . "." . $req_size . ".wps";
470 last if (-e "$wpsdir/$req_g_wps");
472 if ($isrwps) {
473 $req_size = $req_size . "." . $main_width . "x" . $main_height . "x" . "$main_depth";
475 $req_g_wps = $wps_prefix . "." . $req_size . ".wps";
476 last if (-e "$wpsdir/$req_g_wps");
479 $req_t_wps = $wps_prefix . ".txt" . ".wps";
481 #print "LCD: $wps wants $width x $height\n";
482 #print "LCD: is $rwidth x $rheight\n";
484 #print "gwps: $wpsdir/$req_g_wps" . "\n";
485 if (-e "$wpsdir/$req_g_wps" || -e "$wpsdir/$req_t_wps" ) {
487 # The target model has an LCD that is suitable for this
488 # WPS
490 #print "Size requirement is fine!\n";
491 mkdirs() if (-e "$wpsdir/$req_g_wps");
492 # Do the copying before building the .cfg - buildcfg()
493 # mangles some filenames
494 if ($backdrop) {
495 copybackdrop();
497 if ($iconset) {
498 copythemeicon();
500 if ($viewericon) {
501 copythemeviewericon();
503 if ($font) {
504 copythemefont($font);
506 if ($remotefont) {
507 copythemefont($remotefont);
509 if(!$isrwps) {
510 # We only make .cfg files for <wps> sections:
511 buildcfg();
513 copywps();
515 else {
516 #print "(${wps_prefix}-${rwidth}x${rheight}x$rdepth) ";
517 #print "Skip $wps due to size restraints\n";
519 $within = 0;
521 elsif($l =~ /^Name: *(.*)/i) {
522 # Note that in the case this is within <rwps>, $wps will contain the
523 # name of the rwps. Use $isrwps to figure out what type it is.
524 $wps = $wps_prefix = $1;
525 $wps_prefix =~ s/\.(r|)wps//;
526 #print $wps_prefix . "\n";
528 elsif($l =~ /^RWPS: *(.*)/i) {
529 $rwps = $1;
531 elsif($l =~ /^RWPS\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
532 $rwps = $1;
534 elsif($l =~ /^SBS: *(.*)/i) {
535 $sbs = $sbs_prefix = $1;
536 $sbs_prefix =~ s/\.(r|)sbs//;
538 elsif($l =~ /^SBS\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
539 $sbs = $sbs_prefix = $1;
540 $sbs_prefix =~ s/\.(r|)sbs//;
542 elsif($l =~ /^RSBS: *(.*)/i) {
543 $rsbs = $1;
545 elsif($l =~ /^RSBS\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
546 $rsbs = $1;
548 elsif($l =~ /^Author: *(.*)/i) {
549 $author = $1;
551 elsif($l =~ /^Width: *(.*)/i) {
552 $width = $1;
554 elsif($l =~ /^Width\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
555 $width = $1;
557 elsif($l =~ /^Height: *(.*)/i) {
558 $height = $1;
560 elsif($l =~ /^Height\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
561 $height = $1;
563 elsif($l =~ /^Font: *(.*)/i) {
564 $font = $1;
566 elsif($l =~ /^Font\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
567 $font = $1;
569 elsif($l =~ /^Remote Font\.${remote_width}x${remote_height}x$remote_depth: *(.*)/i) {
570 $remotefont = $1;
572 elsif($l =~ /^Remote Font: *(.*)/i) {
573 $remotefont = $1;
575 elsif($l =~ /^Foreground Color: *(.*)/i) {
576 $fgcolor = $1;
578 elsif($l =~ /^Background Color: *(.*)/i) {
579 $bgcolor = $1;
581 elsif($l =~ /^Statusbar: *(.*)/i) {
582 $statusbar = $1;
584 elsif($l =~ /^Statusbar\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
585 $statusbar = $1;
587 elsif($l =~ /^Backdrop: *(.*)/i) {
588 $backdrop = $1;
590 elsif($l =~ /^Backdrop\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
591 $backdrop = $1;
593 elsif($l =~ /^line selector start color: *(.*)/i) {
594 $lineselectstart = $1;
596 elsif($l =~ /^line selector end color: *(.*)/i) {
597 $lineselectend = $1;
599 elsif($l =~ /^selector type: *(.*)/i) {
600 $selecttype = $1;
602 elsif($l =~ /^selector type\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
603 $selecttype = $1;
605 elsif($l =~ /^iconset: *(.*)/i) {
606 $iconset = $1;
608 elsif($l =~ /^iconset\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
609 $iconset = $1;
611 elsif($l =~ /^viewers iconset: *(.*)/i) {
612 $viewericon = $1;
614 elsif($l =~ /^viewers iconset\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
615 $viewericon = $1;
617 elsif($l =~ /^line selector text color: *(.*)/i) {
618 $lineselecttextcolor = $1;
620 elsif($l =~ /^filetype colours: *(.*)/i) {
621 $filetylecolor = $1;
623 elsif($l =~ /^ui viewport: *(.*)/i) {
624 $listviewport = $1;
626 elsif($l =~ /^ui viewport\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
627 $listviewport = $1;
629 elsif($l =~ /^remote ui viewport: *(.*)/i) {
630 $remotelistviewport = $1;
632 elsif($l =~ /^remote ui viewport\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
633 $remotelistviewport = $1;
635 else{
636 #print "Unknown line: $l!\n";
641 close(WPS);