Added cyrillic glyphs to 10-Artwiz-Snap; also added the default char
[kugel-rb.git] / wps / wpsbuild.pl
blobaf4c7c411f87a9d8368d775b85059601f16effab
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;
57 # LCD sizes
58 my ($main_height, $main_width, $main_depth);
59 my ($remote_height, $remote_width, $remote_depth);
60 my $has_remote;
63 if(!$wpslist) {
64 print "Usage: wpsbuilds.pl <WPSLIST> <target>\n",
65 "Run this script in the root of the target build, and it will put all the\n",
66 "stuff in $rbdir/wps/\n";
67 exit;
70 sub getlcdsizes
72 my ($remote) = @_;
74 open(GCC, ">gcctemp");
75 if($remote) {
76 # Get the remote LCD screen size
77 print GCC <<STOP
78 \#include "config.h"
79 #ifdef HAVE_REMOTE_LCD
80 Height: LCD_REMOTE_HEIGHT
81 Width: LCD_REMOTE_WIDTH
82 Depth: LCD_REMOTE_DEPTH
83 #endif
84 STOP
87 else {
88 print GCC <<STOP
89 \#include "config.h"
90 Height: LCD_HEIGHT
91 Width: LCD_WIDTH
92 Depth: LCD_DEPTH
93 STOP
96 close(GCC);
98 my $c="cat gcctemp | gcc $cppdef -I. -I$firmdir/export -E -P -";
100 #print "CMD $c\n";
102 open(GETSIZE, "$c|");
104 my ($height, $width, $depth);
105 while(<GETSIZE>) {
106 if($_ =~ /^Height: (\d*)/) {
107 $height = $1;
109 elsif($_ =~ /^Width: (\d*)/) {
110 $width = $1;
112 elsif($_ =~ /^Depth: (\d*)/) {
113 $depth = $1;
115 if($height && $width && $depth) {
116 last;
119 close(GETSIZE);
120 unlink("gcctemp");
122 return ($height, $width, $depth);
125 sub mkdirs
127 my $wpsdir = $wps;
128 $wpsdir =~ s/\.(r|)wps//;
129 mkdir "$rbdir/wps", 0777;
130 mkdir "$rbdir/themes", 0777;
132 if( -d "$rbdir/wps/$wpsdir") {
133 #print STDERR "wpsbuild warning: directory wps/$wpsdir already exists!\n";
135 else
137 mkdir "$rbdir/wps/$wpsdir", 0777;
141 sub copybackdrop
143 #copy the backdrop file into the build dir
144 if ($backdrop ne '') {
145 my $dst = $backdrop;
146 $dst =~ s/(\.[0-9]*x[0-9]*x[0-9]*)//;
147 my $cmd = "cp $ROOT/$backdrop $rbdir/$dst";
148 `$cmd`;
152 sub copythemefont
154 #copy the font specified by the theme
156 my $o=$font;
157 $o =~ s/\.fnt/\.bdf/;
158 mkdir "$rbdir/fonts";
159 my $cmd ="$ROOT/tools/convbdf -f -o \"$rbdir/fonts/$font\" \"$ROOT/fonts/$o\" ";
160 `$cmd`;
163 sub copythemeicon
165 #copy the icon specified by the theme
167 if ($iconset ne '') {
168 $iconset =~ s/.rockbox/$rbdir/;
169 $iconset =~ /\/(.*icons\/(.*))/i;
170 `cp $ROOT/icons/$2 $1`;
174 sub copythemeviewericon
176 #copy the viewer icon specified by the theme
178 if ($viewericon ne '') {
179 $viewericon =~ s/.rockbox/$rbdir/;
180 $viewericon =~ /\/(.*icons\/(.*))/i;
181 `cp $ROOT/icons/$2 $1`;
185 sub copywps
187 # we assume that we copy the WPS files from the same dir the WPSLIST
188 # file is located in
189 my $dir;
190 my @filelist;
191 my $file;
193 if($wpslist =~ /(.*)WPSLIST/) {
194 $dir = $1;
195 # system("cp $dir/$wps .rockbox/wps/");
196 #print "$req_t_wps $req_g_wps\n";
198 if (-e "$dir/$req_t_wps" ) {
199 system("cp $dir/$req_t_wps $rbdir/wps/$wps");
201 } elsif (-e "$dir/$req_g_wps") {
202 system("cp $dir/$req_g_wps $rbdir/wps/$wps");
204 open(WPSFILE, "$dir/$req_g_wps");
205 while (<WPSFILE>) {
206 $filelist[$#filelist + 1] = $1 if (/\|([^|]*?.bmp)\|/);
208 close(WPSFILE);
210 if ($#filelist >= 0) {
211 if (-e "$dir/$wps_prefix/$req_g") {
212 foreach $file (@filelist) {
213 system("cp $dir/$wps_prefix/$req_g/$file $rbdir/wps/$wps_prefix/");
216 elsif (-e "$dir/$wps_prefix") {
217 foreach $file (@filelist) {
218 system("cp $dir/$wps_prefix/$file $rbdir/wps/$wps_prefix/");
221 else {
222 print STDERR "beep, no dir to copy WPS from!\n";
226 } else {
227 print STDERR "Skipping $wps - no matching resolution.\n";
229 } else {
230 print STDERR "No source directory!\n";
234 sub buildcfg {
235 my $cfg = $wps;
236 my @out;
238 $cfg =~ s/\.(r|)wps/.cfg/;
240 push @out, <<MOO
242 \# $cfg generated by wpsbuild.pl
243 \# $wps is made by $author
245 wps: /$rbdir/wps/$wps
248 if($font) {
249 push @out, "font: /$rbdir/fonts/$font\n";
251 if($fgcolor && $main_depth > 2) {
252 push @out, "foreground color: $fgcolor\n";
254 if($bgcolor && $main_depth > 2) {
255 push @out, "background color: $bgcolor\n";
257 if($statusbar) {
258 push @out, "statusbar: $statusbar\n";
260 if(defined($backdrop)) {
261 if ($backdrop eq '') {
262 push @out, "backdrop:\n";
263 } else {
264 # clip resolution from filename
265 $backdrop =~ s/(\.[0-9]*x[0-9]*x[0-9]*)//;
266 push @out, "backdrop: /$rbdir/$backdrop\n";
269 if($lineselectstart && $main_depth > 2) {
270 push @out, "line selector start color: $lineselectstart\n";
272 if($lineselectend && $main_depth > 2) {
273 push @out, "line selector end color: $lineselectend\n";
275 if($selecttype) {
276 push @out, "selector type: $selecttype\n";
278 if(defined($iconset)) {
279 push @out, "iconset: $iconset\n";
281 if(defined($viewericon)) {
282 push @out, "viewers iconset: $viewericon\n";
284 if($lineselecttextcolor && $main_depth > 2 ) {
285 push @out, "line selector text color: $lineselecttextcolor\n";
287 if($filetylecolor && $main_depth > 2) {
288 push @out, "filetype colours: $filetylecolor\n";
290 if($rwps && $has_remote ) {
291 push @out, "rwps: /$rbdir/wps/$rwps\n";
293 if(-f "$rbdir/wps/$cfg") {
294 print STDERR "wpsbuild warning: wps/$cfg already exists!\n";
296 else {
297 open(CFG, ">$rbdir/themes/$cfg");
298 print CFG @out;
299 close(CFG);
303 # Get the LCD sizes first
304 ($main_height, $main_width, $main_depth) = getlcdsizes();
305 ($remote_height, $remote_width, $remote_depth) = getlcdsizes(1);
307 #print "LCD: ${main_width}x${main_height}x${main_depth}\n";
308 $has_remote = 1 if ($remote_height && $remote_width && $remote_depth);
310 my $isrwps;
311 my $within;
313 open(WPS, "<$wpslist");
314 while(<WPS>) {
315 my $l = $_;
317 # remove CR
318 $l =~ s/\r//g;
319 if($l =~ /^ *\#/) {
320 # skip comment
321 next;
323 if($l =~ /^ *<(r|)wps>/i) {
324 $isrwps = $1;
325 $within = 1;
326 # undef is a unary operator (!)
327 undef $wps;
328 undef $wps_prefix;
329 undef $rwps;
330 undef $width;
331 undef $height;
332 undef $font;
333 undef $fgcolor;
334 undef $bgcolor;
335 undef $statusbar;
336 undef $author;
337 undef $req_g_wps;
338 undef $req_t_wps;
339 undef $backdrop;
340 undef $lineselectstart;
341 undef $lineselectend;
342 undef $selecttype;
343 undef $iconset;
344 undef $viewericon;
345 undef $lineselecttextcolor;
346 undef $filetylecolor;
348 next;
350 if($within) {
351 if($l =~ /^ *<\/${isrwps}wps>/i) {
352 # Get the required width and height
353 my ($rheight, $rwidth, $rdepth);
354 if($isrwps) {
355 ($rheight, $rwidth, $rdepth) =
356 ($remote_height, $remote_width, $remote_depth);
358 else {
359 ($rheight, $rwidth, $rdepth) =
360 ($main_height, $main_width, $main_depth);
363 if(!$rheight || !$rwidth) {
364 #printf STDERR "wpsbuild notice: No %sLCD size, skipping $wps\n",
365 #$isrwps?"remote ":"";
366 $within = 0;
367 next;
369 $wpslist =~ /(.*)WPSLIST/;
370 my $wpsdir = $1;
371 # If this WPS installable on this platform, one of the following
372 # two files will be present
373 foreach my $d (@depthlist) {
374 next if ($d > $rdepth);
376 $req_g = $rwidth . "x" . $rheight . "x" . $d;
378 # check for model specific wps
379 $req_g_wps = $wps_prefix . "." . $req_g . "." . $modelname . ".wps";
380 last if (-e "$wpsdir/$req_g_wps");
382 $req_g_wps = $wps_prefix . "." . $req_g . ".wps";
383 last if (-e "$wpsdir/$req_g_wps");
385 if ($isrwps) {
386 $req_g = $req_g . "." . $main_width . "x" . $main_height . "x" . "$main_depth";
388 $req_g_wps = $wps_prefix . "." . $req_g . ".wps";
389 last if (-e "$wpsdir/$req_g_wps");
392 $req_t_wps = $wps_prefix . ".txt" . ".wps";
394 #print "LCD: $wps wants $width x $height\n";
395 #print "LCD: is $rwidth x $rheight\n";
397 #print "gwps: $wpsdir/$req_g_wps" . "\n";
398 if (-e "$wpsdir/$req_g_wps" || -e "$wpsdir/$req_t_wps" ) {
400 # The target model has an LCD that is suitable for this
401 # WPS
403 #print "Size requirement is fine!\n";
404 mkdirs() if (-e "$wpsdir/$req_g_wps");
405 # Do the copying before building the .cfg - buildcfg()
406 # mangles some filenames
407 if ($backdrop) {
408 copybackdrop();
410 if ($iconset) {
411 copythemeicon();
413 if ($viewericon) {
414 copythemeviewericon();
416 if ($font) {
417 copythemefont();
419 if(!$isrwps) {
420 # We only make .cfg files for <wps> sections:
421 buildcfg();
423 copywps();
425 else {
426 #print "(${wps_prefix}-${rwidth}x${rheight}x$rdepth) ";
427 #print "Skip $wps due to size restraints\n";
429 $within = 0;
431 elsif($l =~ /^Name: *(.*)/i) {
432 # Note that in the case this is within <rwps>, $wps will contain the
433 # name of the rwps. Use $isrwps to figure out what type it is.
434 $wps = $wps_prefix = $1;
435 $wps_prefix =~ s/\.(r|)wps//;
436 #print $wps_prefix . "\n";
438 elsif($l =~ /^RWPS: *(.*)/i) {
439 $rwps = $1;
441 elsif($l =~ /^RWPS\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
442 $rwps = $1;
444 elsif($l =~ /^Author: *(.*)/i) {
445 $author = $1;
447 elsif($l =~ /^Width: *(.*)/i) {
448 $width = $1;
450 elsif($l =~ /^Width\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
451 $width = $1;
453 elsif($l =~ /^Height: *(.*)/i) {
454 $height = $1;
456 elsif($l =~ /^Height\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
457 $height = $1;
459 elsif($l =~ /^Font: *(.*)/i) {
460 $font = $1;
462 elsif($l =~ /^Font\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
463 $font = $1;
465 elsif($l =~ /^Foreground Color: *(.*)/i) {
466 $fgcolor = $1;
468 elsif($l =~ /^Background Color: *(.*)/i) {
469 $bgcolor = $1;
471 elsif($l =~ /^Statusbar: *(.*)/i) {
472 $statusbar = $1;
474 elsif($l =~ /^Statusbar\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
475 $statusbar = $1;
477 elsif($l =~ /^Backdrop: *(.*)/i) {
478 $backdrop = $1;
480 elsif($l =~ /^Backdrop\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
481 $backdrop = $1;
483 elsif($l =~ /^line selector start color: *(.*)/i) {
484 $lineselectstart = $1;
486 elsif($l =~ /^line selector end color: *(.*)/i) {
487 $lineselectend = $1;
489 elsif($l =~ /^selector type: *(.*)/i) {
490 $selecttype = $1;
492 elsif($l =~ /^selector type\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
493 $selecttype = $1;
495 elsif($l =~ /^iconset: *(.*)/i) {
496 $iconset = $1;
498 elsif($l =~ /^iconset\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
499 $iconset = $1;
501 elsif($l =~ /^viewers iconset: *(.*)/i) {
502 $viewericon = $1;
504 elsif($l =~ /^viewers iconset\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
505 $viewericon = $1;
507 elsif($l =~ /^line selector text color: *(.*)/i) {
508 $lineselecttextcolor = $1;
510 elsif($l =~ /^filetype colours: *(.*)/i) {
511 $filetylecolor = $1;
513 else{
514 #print "Unknown line: $l!\n";
519 close(WPS);