Move yearday_to_daymonth() to usb_storage.c. It's the only user, this function is...
[kugel-rb.git] / wps / wpsbuild.pl
blob735a63830a3f5f72b65788830aa72bfd8fc0f9ec
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 if($rwps && $has_remote ) {
259 push @out, "remote statusbar: $statusbar\n";
261 push @out, "statusbar: $statusbar\n";
263 if(defined($backdrop)) {
264 if ($backdrop eq '') {
265 push @out, "backdrop:\n";
266 } else {
267 # clip resolution from filename
268 $backdrop =~ s/(\.[0-9]*x[0-9]*x[0-9]*)//;
269 push @out, "backdrop: /$rbdir/$backdrop\n";
272 if($lineselectstart && $main_depth > 2) {
273 push @out, "line selector start color: $lineselectstart\n";
275 if($lineselectend && $main_depth > 2) {
276 push @out, "line selector end color: $lineselectend\n";
278 if($selecttype) {
279 push @out, "selector type: $selecttype\n";
281 if(defined($iconset)) {
282 push @out, "iconset: $iconset\n";
284 if(defined($viewericon)) {
285 push @out, "viewers iconset: $viewericon\n";
287 if($lineselecttextcolor && $main_depth > 2 ) {
288 push @out, "line selector text color: $lineselecttextcolor\n";
290 if($filetylecolor && $main_depth > 2) {
291 push @out, "filetype colours: $filetylecolor\n";
293 if($rwps && $has_remote ) {
294 push @out, "rwps: /$rbdir/wps/$rwps\n";
296 if(-f "$rbdir/wps/$cfg") {
297 print STDERR "wpsbuild warning: wps/$cfg already exists!\n";
299 else {
300 open(CFG, ">$rbdir/themes/$cfg");
301 print CFG @out;
302 close(CFG);
306 # Get the LCD sizes first
307 ($main_height, $main_width, $main_depth) = getlcdsizes();
308 ($remote_height, $remote_width, $remote_depth) = getlcdsizes(1);
310 #print "LCD: ${main_width}x${main_height}x${main_depth}\n";
311 $has_remote = 1 if ($remote_height && $remote_width && $remote_depth);
313 my $isrwps;
314 my $within;
316 open(WPS, "<$wpslist");
317 while(<WPS>) {
318 my $l = $_;
320 # remove CR
321 $l =~ s/\r//g;
322 if($l =~ /^ *\#/) {
323 # skip comment
324 next;
326 if($l =~ /^ *<(r|)wps>/i) {
327 $isrwps = $1;
328 $within = 1;
329 # undef is a unary operator (!)
330 undef $wps;
331 undef $wps_prefix;
332 undef $rwps;
333 undef $width;
334 undef $height;
335 undef $font;
336 undef $fgcolor;
337 undef $bgcolor;
338 undef $statusbar;
339 undef $author;
340 undef $req_g_wps;
341 undef $req_t_wps;
342 undef $backdrop;
343 undef $lineselectstart;
344 undef $lineselectend;
345 undef $selecttype;
346 undef $iconset;
347 undef $viewericon;
348 undef $lineselecttextcolor;
349 undef $filetylecolor;
351 next;
353 if($within) {
354 if($l =~ /^ *<\/${isrwps}wps>/i) {
355 # Get the required width and height
356 my ($rheight, $rwidth, $rdepth);
357 if($isrwps) {
358 ($rheight, $rwidth, $rdepth) =
359 ($remote_height, $remote_width, $remote_depth);
361 else {
362 ($rheight, $rwidth, $rdepth) =
363 ($main_height, $main_width, $main_depth);
366 if(!$rheight || !$rwidth) {
367 #printf STDERR "wpsbuild notice: No %sLCD size, skipping $wps\n",
368 #$isrwps?"remote ":"";
369 $within = 0;
370 next;
372 $wpslist =~ /(.*)WPSLIST/;
373 my $wpsdir = $1;
374 # If this WPS installable on this platform, one of the following
375 # two files will be present
376 foreach my $d (@depthlist) {
377 next if ($d > $rdepth);
379 $req_g = $rwidth . "x" . $rheight . "x" . $d;
381 # check for model specific wps
382 $req_g_wps = $wps_prefix . "." . $req_g . "." . $modelname . ".wps";
383 last if (-e "$wpsdir/$req_g_wps");
385 $req_g_wps = $wps_prefix . "." . $req_g . ".wps";
386 last if (-e "$wpsdir/$req_g_wps");
388 if ($isrwps) {
389 $req_g = $req_g . "." . $main_width . "x" . $main_height . "x" . "$main_depth";
391 $req_g_wps = $wps_prefix . "." . $req_g . ".wps";
392 last if (-e "$wpsdir/$req_g_wps");
395 $req_t_wps = $wps_prefix . ".txt" . ".wps";
397 #print "LCD: $wps wants $width x $height\n";
398 #print "LCD: is $rwidth x $rheight\n";
400 #print "gwps: $wpsdir/$req_g_wps" . "\n";
401 if (-e "$wpsdir/$req_g_wps" || -e "$wpsdir/$req_t_wps" ) {
403 # The target model has an LCD that is suitable for this
404 # WPS
406 #print "Size requirement is fine!\n";
407 mkdirs() if (-e "$wpsdir/$req_g_wps");
408 # Do the copying before building the .cfg - buildcfg()
409 # mangles some filenames
410 if ($backdrop) {
411 copybackdrop();
413 if ($iconset) {
414 copythemeicon();
416 if ($viewericon) {
417 copythemeviewericon();
419 if ($font) {
420 copythemefont();
422 if(!$isrwps) {
423 # We only make .cfg files for <wps> sections:
424 buildcfg();
426 copywps();
428 else {
429 #print "(${wps_prefix}-${rwidth}x${rheight}x$rdepth) ";
430 #print "Skip $wps due to size restraints\n";
432 $within = 0;
434 elsif($l =~ /^Name: *(.*)/i) {
435 # Note that in the case this is within <rwps>, $wps will contain the
436 # name of the rwps. Use $isrwps to figure out what type it is.
437 $wps = $wps_prefix = $1;
438 $wps_prefix =~ s/\.(r|)wps//;
439 #print $wps_prefix . "\n";
441 elsif($l =~ /^RWPS: *(.*)/i) {
442 $rwps = $1;
444 elsif($l =~ /^RWPS\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
445 $rwps = $1;
447 elsif($l =~ /^Author: *(.*)/i) {
448 $author = $1;
450 elsif($l =~ /^Width: *(.*)/i) {
451 $width = $1;
453 elsif($l =~ /^Width\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
454 $width = $1;
456 elsif($l =~ /^Height: *(.*)/i) {
457 $height = $1;
459 elsif($l =~ /^Height\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
460 $height = $1;
462 elsif($l =~ /^Font: *(.*)/i) {
463 $font = $1;
465 elsif($l =~ /^Font\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
466 $font = $1;
468 elsif($l =~ /^Foreground Color: *(.*)/i) {
469 $fgcolor = $1;
471 elsif($l =~ /^Background Color: *(.*)/i) {
472 $bgcolor = $1;
474 elsif($l =~ /^Statusbar: *(.*)/i) {
475 $statusbar = $1;
477 elsif($l =~ /^Statusbar\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
478 $statusbar = $1;
480 elsif($l =~ /^Backdrop: *(.*)/i) {
481 $backdrop = $1;
483 elsif($l =~ /^Backdrop\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
484 $backdrop = $1;
486 elsif($l =~ /^line selector start color: *(.*)/i) {
487 $lineselectstart = $1;
489 elsif($l =~ /^line selector end color: *(.*)/i) {
490 $lineselectend = $1;
492 elsif($l =~ /^selector type: *(.*)/i) {
493 $selecttype = $1;
495 elsif($l =~ /^selector type\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
496 $selecttype = $1;
498 elsif($l =~ /^iconset: *(.*)/i) {
499 $iconset = $1;
501 elsif($l =~ /^iconset\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
502 $iconset = $1;
504 elsif($l =~ /^viewers iconset: *(.*)/i) {
505 $viewericon = $1;
507 elsif($l =~ /^viewers iconset\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
508 $viewericon = $1;
510 elsif($l =~ /^line selector text color: *(.*)/i) {
511 $lineselecttextcolor = $1;
513 elsif($l =~ /^filetype colours: *(.*)/i) {
514 $filetylecolor = $1;
516 else{
517 #print "Unknown line: $l!\n";
522 close(WPS);