FS#8961 - Anti-Aliased Fonts.
[kugel-rb.git] / wps / wpsbuild.pl
blobe9e5c29a30f676bf2abfaf02a1e600c38ab67b1f
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 $wps;
36 my $wps_prefix;
37 my $rwps;
38 my $width;
39 my $height;
40 my $font;
41 my $fgcolor;
42 my $bgcolor;
43 my $statusbar;
44 my $author;
45 my $req_g;
46 my $req_g_wps;
47 my $req_t_wps;
48 my $backdrop;
49 my $lineselectstart;
50 my $lineselectend;
51 my $selecttype;
52 my $iconset;
53 my $viewericon;
54 my $lineselecttextcolor;
55 my $filetylecolor;
56 my $listviewport;
57 my $remotelistviewport;
59 # LCD sizes
60 my ($main_height, $main_width, $main_depth);
61 my ($remote_height, $remote_width, $remote_depth);
62 my $has_remote;
65 if(!$wpslist) {
66 print "Usage: wpsbuilds.pl <WPSLIST> <target>\n",
67 "Run this script in the root of the target build, and it will put all the\n",
68 "stuff in $rbdir/wps/\n";
69 exit;
72 sub getlcdsizes
74 my ($remote) = @_;
76 open(GCC, ">gcctemp");
77 if($remote) {
78 # Get the remote LCD screen size
79 print GCC <<STOP
80 \#include "config.h"
81 #ifdef HAVE_REMOTE_LCD
82 Height: LCD_REMOTE_HEIGHT
83 Width: LCD_REMOTE_WIDTH
84 Depth: LCD_REMOTE_DEPTH
85 #endif
86 STOP
89 else {
90 print GCC <<STOP
91 \#include "config.h"
92 Height: LCD_HEIGHT
93 Width: LCD_WIDTH
94 Depth: LCD_DEPTH
95 STOP
98 close(GCC);
100 my $c="cat gcctemp | gcc $cppdef -I. -I$firmdir/export -E -P -";
102 #print "CMD $c\n";
104 open(GETSIZE, "$c|");
106 my ($height, $width, $depth);
107 while(<GETSIZE>) {
108 if($_ =~ /^Height: (\d*)/) {
109 $height = $1;
111 elsif($_ =~ /^Width: (\d*)/) {
112 $width = $1;
114 elsif($_ =~ /^Depth: (\d*)/) {
115 $depth = $1;
117 if($height && $width && $depth) {
118 last;
121 close(GETSIZE);
122 unlink("gcctemp");
124 return ($height, $width, $depth);
127 sub mkdirs
129 my $wpsdir = $wps;
130 $wpsdir =~ s/\.(r|)wps//;
131 mkdir "$rbdir/wps", 0777;
132 mkdir "$rbdir/themes", 0777;
134 if( -d "$rbdir/wps/$wpsdir") {
135 #print STDERR "wpsbuild warning: directory wps/$wpsdir already exists!\n";
137 else
139 mkdir "$rbdir/wps/$wpsdir", 0777;
143 sub copybackdrop
145 #copy the backdrop file into the build dir
146 if ($backdrop ne '') {
147 my $dst = $backdrop;
148 $dst =~ s/(\.[0-9]*x[0-9]*x[0-9]*)//;
149 my $cmd = "cp $ROOT/$backdrop $rbdir/$dst";
150 `$cmd`;
154 sub copythemefont
156 #copy the font specified by the theme
158 my $o=$font;
159 $o =~ s/\.fnt/\.bdf/;
160 mkdir "$rbdir/fonts";
161 my $cmd ="$ROOT/tools/convbdf -f -o \"$rbdir/fonts/$font\" \"$ROOT/fonts/$o\" ";
162 `$cmd`;
165 sub copythemeicon
167 #copy the icon specified by the theme
169 if ($iconset ne '') {
170 $iconset =~ s/.rockbox/$rbdir/;
171 $iconset =~ /\/(.*icons\/(.*))/i;
172 `cp $ROOT/icons/$2 $1`;
176 sub copythemeviewericon
178 #copy the viewer icon specified by the theme
180 if ($viewericon ne '') {
181 $viewericon =~ s/.rockbox/$rbdir/;
182 $viewericon =~ /\/(.*icons\/(.*))/i;
183 `cp $ROOT/icons/$2 $1`;
187 sub copywps
189 # we assume that we copy the WPS files from the same dir the WPSLIST
190 # file is located in
191 my $dir;
192 my @filelist;
193 my $file;
195 if($wpslist =~ /(.*)WPSLIST/) {
196 $dir = $1;
197 # system("cp $dir/$wps .rockbox/wps/");
198 #print "$req_t_wps $req_g_wps\n";
200 if (-e "$dir/$req_t_wps" ) {
201 system("cp $dir/$req_t_wps $rbdir/wps/$wps");
203 } elsif (-e "$dir/$req_g_wps") {
204 system("cp $dir/$req_g_wps $rbdir/wps/$wps");
206 open(WPSFILE, "$dir/$req_g_wps");
207 while (<WPSFILE>) {
208 $filelist[$#filelist + 1] = $1 if (/\|([^|]*?.bmp)\|/);
210 close(WPSFILE);
212 if ($#filelist >= 0) {
213 if (-e "$dir/$wps_prefix/$req_g") {
214 foreach $file (@filelist) {
215 system("cp $dir/$wps_prefix/$req_g/$file $rbdir/wps/$wps_prefix/");
218 elsif (-e "$dir/$wps_prefix") {
219 foreach $file (@filelist) {
220 system("cp $dir/$wps_prefix/$file $rbdir/wps/$wps_prefix/");
223 else {
224 print STDERR "beep, no dir to copy WPS from!\n";
228 } else {
229 print STDERR "Skipping $wps - no matching resolution.\n";
231 } else {
232 print STDERR "No source directory!\n";
236 sub buildcfg {
237 my $cfg = $wps;
238 my @out;
240 $cfg =~ s/\.(r|)wps/.cfg/;
242 push @out, <<MOO
244 \# $cfg generated by wpsbuild.pl
245 \# $wps is made by $author
247 wps: /$rbdir/wps/$wps
250 if($font) {
251 push @out, "font: /$rbdir/fonts/$font\n";
253 if($fgcolor && $main_depth > 2) {
254 push @out, "foreground color: $fgcolor\n";
256 if($bgcolor && $main_depth > 2) {
257 push @out, "background color: $bgcolor\n";
259 if($statusbar) {
260 if($rwps && $has_remote ) {
261 push @out, "remote statusbar: $statusbar\n";
263 push @out, "statusbar: $statusbar\n";
265 if(defined($backdrop)) {
266 if ($backdrop eq '') {
267 push @out, "backdrop:\n";
268 } else {
269 # clip resolution from filename
270 $backdrop =~ s/(\.[0-9]*x[0-9]*x[0-9]*)//;
271 push @out, "backdrop: /$rbdir/$backdrop\n";
274 if($lineselectstart && $main_depth > 2) {
275 push @out, "line selector start color: $lineselectstart\n";
277 if($lineselectend && $main_depth > 2) {
278 push @out, "line selector end color: $lineselectend\n";
280 if($selecttype) {
281 push @out, "selector type: $selecttype\n";
283 if(defined($iconset)) {
284 push @out, "iconset: $iconset\n";
286 if(defined($viewericon)) {
287 push @out, "viewers iconset: $viewericon\n";
289 if($lineselecttextcolor && $main_depth > 2 ) {
290 push @out, "line selector text color: $lineselecttextcolor\n";
292 if($filetylecolor && $main_depth > 2) {
293 push @out, "filetype colours: $filetylecolor\n";
295 if($rwps && $has_remote ) {
296 push @out, "rwps: /$rbdir/wps/$rwps\n";
298 if(defined($listviewport)) {
299 push @out, "ui viewport: $listviewport\n";
301 if(defined($remotelistviewport) && $has_remote) {
302 push @out, "remote ui viewport: $listviewport\n";
304 if(-f "$rbdir/wps/$cfg") {
305 print STDERR "wpsbuild warning: wps/$cfg already exists!\n";
307 else {
308 open(CFG, ">$rbdir/themes/$cfg");
309 print CFG @out;
310 close(CFG);
314 # Get the LCD sizes first
315 ($main_height, $main_width, $main_depth) = getlcdsizes();
316 ($remote_height, $remote_width, $remote_depth) = getlcdsizes(1);
318 #print "LCD: ${main_width}x${main_height}x${main_depth}\n";
319 $has_remote = 1 if ($remote_height && $remote_width && $remote_depth);
321 my $isrwps;
322 my $within;
324 open(WPS, "<$wpslist");
325 while(<WPS>) {
326 my $l = $_;
328 # remove CR
329 $l =~ s/\r//g;
330 if($l =~ /^ *\#/) {
331 # skip comment
332 next;
334 if($l =~ /^ *<(r|)wps>/i) {
335 $isrwps = $1;
336 $within = 1;
337 # undef is a unary operator (!)
338 undef $wps;
339 undef $wps_prefix;
340 undef $rwps;
341 undef $width;
342 undef $height;
343 undef $font;
344 undef $fgcolor;
345 undef $bgcolor;
346 undef $statusbar;
347 undef $author;
348 undef $req_g_wps;
349 undef $req_t_wps;
350 undef $backdrop;
351 undef $lineselectstart;
352 undef $lineselectend;
353 undef $selecttype;
354 undef $iconset;
355 undef $viewericon;
356 undef $lineselecttextcolor;
357 undef $filetylecolor;
358 undef $listviewport;
359 undef $remotelistviewport;
361 next;
363 if($within) {
364 if($l =~ /^ *<\/${isrwps}wps>/i) {
365 # Get the required width and height
366 my ($rheight, $rwidth, $rdepth);
367 if($isrwps) {
368 ($rheight, $rwidth, $rdepth) =
369 ($remote_height, $remote_width, $remote_depth);
371 else {
372 ($rheight, $rwidth, $rdepth) =
373 ($main_height, $main_width, $main_depth);
376 if(!$rheight || !$rwidth) {
377 #printf STDERR "wpsbuild notice: No %sLCD size, skipping $wps\n",
378 #$isrwps?"remote ":"";
379 $within = 0;
380 next;
382 $wpslist =~ /(.*)WPSLIST/;
383 my $wpsdir = $1;
384 # If this WPS installable on this platform, one of the following
385 # two files will be present
386 foreach my $d (@depthlist) {
387 next if ($d > $rdepth);
389 $req_g = $rwidth . "x" . $rheight . "x" . $d;
391 # check for model specific wps
392 $req_g_wps = $wps_prefix . "." . $req_g . "." . $modelname . ".wps";
393 last if (-e "$wpsdir/$req_g_wps");
395 $req_g_wps = $wps_prefix . "." . $req_g . ".wps";
396 last if (-e "$wpsdir/$req_g_wps");
398 if ($isrwps) {
399 $req_g = $req_g . "." . $main_width . "x" . $main_height . "x" . "$main_depth";
401 $req_g_wps = $wps_prefix . "." . $req_g . ".wps";
402 last if (-e "$wpsdir/$req_g_wps");
405 $req_t_wps = $wps_prefix . ".txt" . ".wps";
407 #print "LCD: $wps wants $width x $height\n";
408 #print "LCD: is $rwidth x $rheight\n";
410 #print "gwps: $wpsdir/$req_g_wps" . "\n";
411 if (-e "$wpsdir/$req_g_wps" || -e "$wpsdir/$req_t_wps" ) {
413 # The target model has an LCD that is suitable for this
414 # WPS
416 #print "Size requirement is fine!\n";
417 mkdirs() if (-e "$wpsdir/$req_g_wps");
418 # Do the copying before building the .cfg - buildcfg()
419 # mangles some filenames
420 if ($backdrop) {
421 copybackdrop();
423 if ($iconset) {
424 copythemeicon();
426 if ($viewericon) {
427 copythemeviewericon();
429 if ($font) {
430 copythemefont();
432 if(!$isrwps) {
433 # We only make .cfg files for <wps> sections:
434 buildcfg();
436 copywps();
438 else {
439 #print "(${wps_prefix}-${rwidth}x${rheight}x$rdepth) ";
440 #print "Skip $wps due to size restraints\n";
442 $within = 0;
444 elsif($l =~ /^Name: *(.*)/i) {
445 # Note that in the case this is within <rwps>, $wps will contain the
446 # name of the rwps. Use $isrwps to figure out what type it is.
447 $wps = $wps_prefix = $1;
448 $wps_prefix =~ s/\.(r|)wps//;
449 #print $wps_prefix . "\n";
451 elsif($l =~ /^RWPS: *(.*)/i) {
452 $rwps = $1;
454 elsif($l =~ /^RWPS\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
455 $rwps = $1;
457 elsif($l =~ /^Author: *(.*)/i) {
458 $author = $1;
460 elsif($l =~ /^Width: *(.*)/i) {
461 $width = $1;
463 elsif($l =~ /^Width\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
464 $width = $1;
466 elsif($l =~ /^Height: *(.*)/i) {
467 $height = $1;
469 elsif($l =~ /^Height\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
470 $height = $1;
472 elsif($l =~ /^Font: *(.*)/i) {
473 $font = $1;
475 elsif($l =~ /^Font\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
476 $font = $1;
478 elsif($l =~ /^Foreground Color: *(.*)/i) {
479 $fgcolor = $1;
481 elsif($l =~ /^Background Color: *(.*)/i) {
482 $bgcolor = $1;
484 elsif($l =~ /^Statusbar: *(.*)/i) {
485 $statusbar = $1;
487 elsif($l =~ /^Statusbar\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
488 $statusbar = $1;
490 elsif($l =~ /^Backdrop: *(.*)/i) {
491 $backdrop = $1;
493 elsif($l =~ /^Backdrop\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
494 $backdrop = $1;
496 elsif($l =~ /^line selector start color: *(.*)/i) {
497 $lineselectstart = $1;
499 elsif($l =~ /^line selector end color: *(.*)/i) {
500 $lineselectend = $1;
502 elsif($l =~ /^selector type: *(.*)/i) {
503 $selecttype = $1;
505 elsif($l =~ /^selector type\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
506 $selecttype = $1;
508 elsif($l =~ /^iconset: *(.*)/i) {
509 $iconset = $1;
511 elsif($l =~ /^iconset\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
512 $iconset = $1;
514 elsif($l =~ /^viewers iconset: *(.*)/i) {
515 $viewericon = $1;
517 elsif($l =~ /^viewers iconset\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
518 $viewericon = $1;
520 elsif($l =~ /^line selector text color: *(.*)/i) {
521 $lineselecttextcolor = $1;
523 elsif($l =~ /^filetype colours: *(.*)/i) {
524 $filetylecolor = $1;
526 elsif($l =~ /^ui viewport: *(.*)/i) {
527 $listviewport = $1;
529 elsif($l =~ /^remote ui viewport: *(.*)/i) {
530 $remotelistviewport = $1;
532 else{
533 #print "Unknown line: $l!\n";
538 close(WPS);