Sansa AMS: ignore buttons when hold switch is on
[kugel-rb.git] / wps / wpsbuild.pl
blobbb229dfebfd28641853d51412407e3dce7b8e05c
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;
20 # Get options
21 GetOptions ( 'r|root=s' => \$ROOT,
22 'v|verbose' => \$verbose,
23 'rbdir=s' => \$rbdir, # If we want to put in a different directory
26 ($wpslist, $target) = @ARGV;
28 my $firmdir="$ROOT/firmware";
29 my $cppdef = $target;
30 my @depthlist = ( 16, 8, 4, 2, 1 );
32 # These parameters are filled in as we parse wpslist
33 my $wps;
34 my $wps_prefix;
35 my $rwps;
36 my $width;
37 my $height;
38 my $font;
39 my $fgcolor;
40 my $bgcolor;
41 my $statusbar;
42 my $author;
43 my $req_g;
44 my $req_g_wps;
45 my $req_t_wps;
46 my $backdrop;
47 my $lineselectstart;
48 my $lineselectend;
49 my $selecttype;
50 my $iconset;
51 my $viewericon;
52 my $lineselecttextcolor;
53 my $filetylecolor;
55 # LCD sizes
56 my ($main_height, $main_width, $main_depth);
57 my ($remote_height, $remote_width, $remote_depth);
58 my $has_remote;
61 if(!$wpslist) {
62 print "Usage: wpsbuilds.pl <WPSLIST> <target>\n",
63 "Run this script in the root of the target build, and it will put all the\n",
64 "stuff in $rbdir/wps/\n";
65 exit;
68 sub getlcdsizes
70 my ($remote) = @_;
72 open(GCC, ">gcctemp");
73 if($remote) {
74 # Get the remote LCD screen size
75 print GCC <<STOP
76 \#include "config.h"
77 #ifdef HAVE_REMOTE_LCD
78 Height: LCD_REMOTE_HEIGHT
79 Width: LCD_REMOTE_WIDTH
80 Depth: LCD_REMOTE_DEPTH
81 #endif
82 STOP
85 else {
86 print GCC <<STOP
87 \#include "config.h"
88 Height: LCD_HEIGHT
89 Width: LCD_WIDTH
90 Depth: LCD_DEPTH
91 STOP
94 close(GCC);
96 my $c="cat gcctemp | gcc $cppdef -I. -I$firmdir/export -E -P -";
98 #print "CMD $c\n";
100 open(GETSIZE, "$c|");
102 my ($height, $width, $depth);
103 while(<GETSIZE>) {
104 if($_ =~ /^Height: (\d*)/) {
105 $height = $1;
107 elsif($_ =~ /^Width: (\d*)/) {
108 $width = $1;
110 elsif($_ =~ /^Depth: (\d*)/) {
111 $depth = $1;
113 if($height && $width && $depth) {
114 last;
117 close(GETSIZE);
118 unlink("gcctemp");
120 return ($height, $width, $depth);
123 sub mkdirs
125 my $wpsdir = $wps;
126 $wpsdir =~ s/\.(r|)wps//;
127 mkdir "$rbdir/wps", 0777;
128 mkdir "$rbdir/themes", 0777;
130 if( -d "$rbdir/wps/$wpsdir") {
131 #print STDERR "wpsbuild warning: directory wps/$wpsdir already exists!\n";
133 else
135 mkdir "$rbdir/wps/$wpsdir", 0777;
139 sub copybackdrop
141 #copy the backdrop file into the build dir
142 if ($backdrop ne '') {
143 my $dst = $backdrop;
144 $dst =~ s/(\.[0-9]*x[0-9]*x[0-9]*)//;
145 my $cmd = "cp $ROOT/$backdrop $rbdir/$dst";
146 `$cmd`;
150 sub copythemefont
152 #copy the font specified by the theme
154 my $o=$font;
155 $o =~ s/\.fnt/\.bdf/;
156 mkdir "$rbdir/fonts";
157 my $cmd ="$ROOT/tools/convbdf -f -o \"$rbdir/fonts/$font\" \"$ROOT/fonts/$o\" ";
158 `$cmd`;
161 sub copythemeicon
163 #copy the icon specified by the theme
165 if ($iconset ne '') {
166 $iconset =~ s/.rockbox/$rbdir/;
167 $iconset =~ /\/(.*icons\/(.*))/i;
168 `cp $ROOT/icons/$2 $1`;
172 sub copythemeviewericon
174 #copy the viewer icon specified by the theme
176 if ($viewericon ne '') {
177 $viewericon =~ s/.rockbox/$rbdir/;
178 $viewericon =~ /\/(.*icons\/(.*))/i;
179 `cp $ROOT/icons/$2 $1`;
183 sub copywps
185 # we assume that we copy the WPS files from the same dir the WPSLIST
186 # file is located in
187 my $dir;
188 my @filelist;
189 my $file;
191 if($wpslist =~ /(.*)WPSLIST/) {
192 $dir = $1;
193 # system("cp $dir/$wps .rockbox/wps/");
194 # print "$req_t_wps $req_g_wps\n";
196 if (-e "$dir/$req_t_wps" ) {
197 system("cp $dir/$req_t_wps $rbdir/wps/$wps");
199 } elsif (-e "$dir/$req_g_wps") {
200 system("cp $dir/$req_g_wps $rbdir/wps/$wps");
202 open(WPSFILE, "$dir/$req_g_wps");
203 while (<WPSFILE>) {
204 $filelist[$#filelist + 1] = $1 if (/\|([^|]*?.bmp)\|/);
206 close(WPSFILE);
208 if ($#filelist >= 0) {
209 if (-e "$dir/$wps_prefix/$req_g") {
210 foreach $file (@filelist) {
211 system("cp $dir/$wps_prefix/$req_g/$file $rbdir/wps/$wps_prefix/");
214 elsif (-e "$dir/$wps_prefix") {
215 foreach $file (@filelist) {
216 system("cp $dir/$wps_prefix/$file $rbdir/wps/$wps_prefix/");
219 else {
220 print STDERR "beep, no dir to copy WPS from!\n";
224 } else {
225 print STDERR "Skipping $wps - no matching resolution.\n";
227 } else {
228 print STDERR "No source directory!\n";
232 sub buildcfg {
233 my $cfg = $wps;
234 my @out;
236 $cfg =~ s/\.(r|)wps/.cfg/;
238 push @out, <<MOO
240 \# $cfg generated by wpsbuild.pl
241 \# $wps is made by $author
243 wps: /$rbdir/wps/$wps
246 if($font) {
247 push @out, "font: /$rbdir/fonts/$font\n";
249 if($fgcolor && $main_depth > 2) {
250 push @out, "foreground color: $fgcolor\n";
252 if($bgcolor && $main_depth > 2) {
253 push @out, "background color: $bgcolor\n";
255 if($statusbar) {
256 push @out, "statusbar: $statusbar\n";
258 if(defined($backdrop)) {
259 if ($backdrop eq '') {
260 push @out, "backdrop:\n";
261 } else {
262 # clip resolution from filename
263 $backdrop =~ s/(\.[0-9]*x[0-9]*x[0-9]*)//;
264 push @out, "backdrop: /$rbdir/$backdrop\n";
267 if($lineselectstart && $main_depth > 2) {
268 push @out, "line selector start color: $lineselectstart\n";
270 if($lineselectend && $main_depth > 2) {
271 push @out, "line selector end color: $lineselectend\n";
273 if($selecttype) {
274 push @out, "selector type: $selecttype\n";
276 if(defined($iconset)) {
277 push @out, "iconset: $iconset\n";
279 if(defined($viewericon)) {
280 push @out, "viewers iconset: $viewericon\n";
282 if($lineselecttextcolor && $main_depth > 2 ) {
283 push @out, "line selector text color: $lineselecttextcolor\n";
285 if($filetylecolor && $main_depth > 2) {
286 push @out, "filetype colours: $filetylecolor\n";
288 if($rwps && $has_remote ) {
289 push @out, "rwps: /$rbdir/wps/$rwps\n";
291 if(-f "$rbdir/wps/$cfg") {
292 print STDERR "wpsbuild warning: wps/$cfg already exists!\n";
294 else {
295 open(CFG, ">$rbdir/themes/$cfg");
296 print CFG @out;
297 close(CFG);
301 # Get the LCD sizes first
302 ($main_height, $main_width, $main_depth) = getlcdsizes();
303 ($remote_height, $remote_width, $remote_depth) = getlcdsizes(1);
305 #print "LCD: ${main_height}x${main_width}x${main_depth}\n";
306 $has_remote = 1 if ($remote_height && $remote_width && $remote_depth);
308 my $isrwps;
309 my $within;
311 open(WPS, "<$wpslist");
312 while(<WPS>) {
313 my $l = $_;
315 # remove CR
316 $l =~ s/\r//g;
317 if($l =~ /^ *\#/) {
318 # skip comment
319 next;
321 if($l =~ /^ *<(r|)wps>/i) {
322 $isrwps = $1;
323 $within = 1;
324 # undef is a unary operator (!)
325 undef $wps;
326 undef $wps_prefix;
327 undef $rwps;
328 undef $width;
329 undef $height;
330 undef $font;
331 undef $fgcolor;
332 undef $bgcolor;
333 undef $statusbar;
334 undef $author;
335 undef $req_g_wps;
336 undef $req_t_wps;
337 undef $backdrop;
338 undef $lineselectstart;
339 undef $lineselectend;
340 undef $selecttype;
341 undef $iconset;
342 undef $viewericon;
343 undef $lineselecttextcolor;
344 undef $filetylecolor;
346 next;
348 if($within) {
349 if($l =~ /^ *<\/${isrwps}wps>/i) {
350 # Get the required width and height
351 my ($rheight, $rwidth, $rdepth);
352 if($isrwps) {
353 ($rheight, $rwidth, $rdepth) =
354 ($remote_height, $remote_width, $remote_depth);
356 else {
357 ($rheight, $rwidth, $rdepth) =
358 ($main_height, $main_width, $main_depth);
361 if(!$rheight || !$rwidth) {
362 #printf STDERR "wpsbuild notice: No %sLCD size, skipping $wps\n",
363 #$isrwps?"remote ":"";
364 $within = 0;
365 next;
367 $wpslist =~ /(.*)WPSLIST/;
368 my $wpsdir = $1;
369 # If this WPS installable on this platform, one of the following
370 # two files will be present
371 foreach my $d (@depthlist) {
372 next if ($d > $rdepth);
374 $req_g = $rwidth . "x" . $rheight . "x" . $d;
376 $req_g_wps = $wps_prefix . "." . $req_g . ".wps";
377 last if (-e "$wpsdir/$req_g_wps");
379 if ($isrwps) {
380 $req_g = $req_g . "." . $main_width . "x" . $main_height . "x" . "$main_depth";
382 $req_g_wps = $wps_prefix . "." . $req_g . ".wps";
383 last if (-e "$wpsdir/$req_g_wps");
386 $req_t_wps = $wps_prefix . ".txt" . ".wps";
388 #print "LCD: $wps wants $height x $width\n";
389 #print "LCD: is $rheight x $rwidth\n";
391 #print "gwps: $wpsdir/$req_g_wps" . "\n";
392 if (-e "$wpsdir/$req_g_wps" || -e "$wpsdir/$req_t_wps" ) {
394 # The target model has an LCD that is suitable for this
395 # WPS
397 #print "Size requirement is fine!\n";
398 mkdirs() if (-e "$wpsdir/$req_g_wps");
399 if(!$isrwps) {
400 # We only make .cfg files for <wps> sections:
401 buildcfg();
403 copywps();
405 else {
406 #print "(${wps_prefix}-${rwidth}x${rheight}x$rdepth) ";
407 #print "Skip $wps due to size restraints\n";
409 $within = 0;
411 elsif($l =~ /^Name: *(.*)/i) {
412 # Note that in the case this is within <rwps>, $wps will contain the
413 # name of the rwps. Use $isrwps to figure out what type it is.
414 $wps = $wps_prefix = $1;
415 $wps_prefix =~ s/\.(r|)wps//;
416 # print $wps_prefix . "\n";
418 elsif($l =~ /^RWPS: *(.*)/i) {
419 $rwps = $1;
421 elsif($l =~ /^RWPS\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
422 $rwps = $1;
424 elsif($l =~ /^Author: *(.*)/i) {
425 $author = $1;
427 elsif($l =~ /^Width: *(.*)/i) {
428 $width = $1;
430 elsif($l =~ /^Width\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
431 $width = $1;
433 elsif($l =~ /^Height: *(.*)/i) {
434 $height = $1;
436 elsif($l =~ /^Height\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
437 $height = $1;
439 elsif($l =~ /^Font: *(.*)/i) {
440 $font = $1;
442 elsif($l =~ /^Foreground Color: *(.*)/i) {
443 $fgcolor = $1;
445 elsif($l =~ /^Background Color: *(.*)/i) {
446 $bgcolor = $1;
448 elsif($l =~ /^Font\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
449 $font = $1;
450 copythemefont();
452 elsif($l =~ /^Statusbar: *(.*)/i) {
453 $statusbar = $1;
455 elsif($l =~ /^Statusbar\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
456 $statusbar = $1;
458 elsif($l =~ /^Backdrop: *(.*)/i) {
459 $backdrop = $1;
460 copybackdrop();
462 elsif($l =~ /^Backdrop\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
463 $backdrop = $1;
464 copybackdrop();
466 elsif($l =~ /^line selector start color: *(.*)/i) {
467 $lineselectstart = $1;
469 elsif($l =~ /^line selector end color: *(.*)/i) {
470 $lineselectend = $1;
472 elsif($l =~ /^selector type: *(.*)/i) {
473 $selecttype = $1;
475 elsif($l =~ /^selector type\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
476 $selecttype = $1;
478 elsif($l =~ /^iconset: *(.*)/i) {
479 $iconset = $1;
480 copythemeicon();
482 elsif($l =~ /^iconset\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
483 $iconset = $1;
484 copythemeicon();
486 elsif($l =~ /^viewers iconset: *(.*)/i) {
487 $viewericon = $1;
488 copythemeviewericon();
490 elsif($l =~ /^viewers iconset\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
491 $viewericon = $1;
492 copythemeviewericon();
494 elsif($l =~ /^line selector text color: *(.*)/i) {
495 $lineselecttextcolor = $1;
497 elsif($l =~ /^filetype colours: *(.*)/i) {
498 $filetylecolor = $1;
500 else{
501 #print "Unknown line: $l!\n";
506 close(WPS);