httpget class: if a request is cancelled before a response is available give a hint...
[Rockbox.git] / wps / wpsbuild.pl
blobcb9ccbfc80365944b9ef3f70992a4c8f915d9e52
1 #!/usr/bin/perl
2 # __________ __ ___.
3 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 # \/ \/ \/ \/ \/
8 # $Id$
11 $ROOT="..";
13 if($ARGV[0] eq "-r") {
14 $ROOT=$ARGV[1];
15 shift @ARGV;
16 shift @ARGV;
19 my $verbose;
20 if($ARGV[0] eq "-v") {
21 $verbose =1;
22 shift @ARGV;
25 my $firmdir="$ROOT/firmware";
27 my $wpslist=$ARGV[0];
29 my $target = $ARGV[1];
30 my $cppdef = $target;
31 my @depthlist = ( 16, 8, 4, 2, 1 );
33 if(!$wpslist) {
34 print "Usage: wpsbuilds.pl <WPSLIST> <target>\n",
35 "Run this script in the root of the target build, and it will put all the\n",
36 "stuff in .rockbox/wps/\n";
37 exit;
40 sub getlcdsizes
42 my ($remote) = @_;
44 open(GCC, ">gcctemp");
45 if($remote) {
46 # Get the remote LCD screen size
47 print GCC <<STOP
48 \#include "config.h"
49 #ifdef HAVE_REMOTE_LCD
50 Height: LCD_REMOTE_HEIGHT
51 Width: LCD_REMOTE_WIDTH
52 Depth: LCD_REMOTE_DEPTH
53 #endif
54 STOP
57 else {
58 print GCC <<STOP
59 \#include "config.h"
60 Height: LCD_HEIGHT
61 Width: LCD_WIDTH
62 Depth: LCD_DEPTH
63 STOP
66 close(GCC);
68 my $c="cat gcctemp | gcc $cppdef -I. -I$firmdir/export -E -P -";
70 #print "CMD $c\n";
72 open(GETSIZE, "$c|");
74 my ($height, $width);
75 while(<GETSIZE>) {
76 if($_ =~ /^Height: (\d*)/) {
77 $height = $1;
79 elsif($_ =~ /^Width: (\d*)/) {
80 $width = $1;
82 elsif($_ =~ /^Depth: (\d*)/) {
83 $depth = $1;
85 if($height && $width && $depth) {
86 last;
89 close(GETSIZE);
90 unlink("gcctemp");
92 return ($height, $width, $depth);
95 sub mkdirs
97 my $wpsdir = $wps;
98 $wpsdir =~ s/\.(r|)wps//;
99 mkdir ".rockbox/wps", 0777;
100 mkdir ".rockbox/themes", 0777;
102 if( -d ".rockbox/wps/$wpsdir") {
103 #print STDERR "wpsbuild warning: directory wps/$wpsdir already exists!\n";
105 else
107 mkdir ".rockbox/wps/$wpsdir", 0777;
111 sub copybackdrop
113 #copy the backdrop file into the build dir
114 if ($backdrop ne '') {
115 $dst = $backdrop;
116 $dst =~ s/(\.[0-9]*x[0-9]*x[0-9]*)//;
117 $cmd = "cp $ROOT/$backdrop .rockbox/$dst";
118 `$cmd`;
122 sub copythemefont
124 #copy the font specified by the theme
126 $o=$font;
127 $o =~ s/\.fnt/\.bdf/;
128 `mkdir .rockbox/fonts/ >/dev/null 2>&1`;
129 $cmd ="$ROOT/tools/convbdf -f -o \".rockbox/fonts/$font\" \"$ROOT/fonts/$o\" ";
130 `$cmd`;
133 sub copythemeicon
135 #copy the icon specified by the theme
137 if ($iconset ne '') {
138 $iconset =~ /\/(.*icons\/(.*))/i;
139 `cp $ROOT/icons/$2 $1`;
143 sub copythemeviewericon
145 #copy the viewer icon specified by the theme
147 if ($viewericon ne '') {
148 $viewericon =~ /\/(.*icons\/(.*))/i;
149 `cp $ROOT/icons/$2 $1`;
153 sub copywps
155 # we assume that we copy the WPS files from the same dir the WPSLIST
156 # file is located in
157 my $dir;
158 my @filelist;
159 my $file;
161 if($wpslist =~ /(.*)WPSLIST/) {
162 $dir = $1;
163 # system("cp $dir/$wps .rockbox/wps/");
164 # print "$req_t_wps $req_g_wps\n";
166 if (-e "$dir/$req_t_wps" ) {
167 system("cp $dir/$req_t_wps .rockbox/wps/$wps");
169 } elsif (-e "$dir/$req_g_wps") {
170 system("cp $dir/$req_g_wps .rockbox/wps/$wps");
172 open(WPSFILE, "$dir/$req_g_wps");
173 while (<WPSFILE>) {
174 $filelist[$#filelist + 1] = $1 if (/\|([^|]*?.bmp)\|/);
176 close(WPSFILE);
178 if ($#filelist >= 0) {
179 if (-e "$dir/$wps_prefix/$req_g") {
180 foreach $file (@filelist) {
181 system("cp $dir/$wps_prefix/$req_g/$file .rockbox/wps/$wps_prefix/");
184 elsif (-e "$dir/$wps_prefix") {
185 foreach $file (@filelist) {
186 system("cp $dir/$wps_prefix/$file .rockbox/wps/$wps_prefix/");
189 else {
190 print STDERR "beep, no dir to copy WPS from!\n";
194 } else {
195 print STDERR "Skipping $wps - no matching resolution.\n";
197 } else {
198 print STDERR "No source directory!\n";
202 sub buildcfg {
203 my $cfg = $wps;
204 my @out;
206 $cfg =~ s/\.(r|)wps/.cfg/;
208 push @out, <<MOO
210 \# $cfg generated by wpsbuild.pl
211 \# $wps is made by $author
213 wps: /.rockbox/wps/$wps
216 if($font) {
217 push @out, "font: /.rockbox/fonts/$font\n";
219 if($fgcolor && $main_depth > 2) {
220 push @out, "foreground color: $fgcolor\n";
222 if($bgcolor && $main_depth > 2) {
223 push @out, "background color: $bgcolor\n";
225 if($statusbar) {
226 push @out, "statusbar: $statusbar\n";
228 if(defined($backdrop)) {
229 if ($backdrop eq '') {
230 push @out, "backdrop:\n";
231 } else {
232 # clip resolution from filename
233 $backdrop =~ s/(\.[0-9]*x[0-9]*x[0-9]*)//;
234 push @out, "backdrop: /.rockbox/$backdrop\n";
237 if($lineselectstart && $main_depth > 2) {
238 push @out, "line selector start color: $lineselectstart\n";
240 if($lineselectend && $main_depth > 2) {
241 push @out, "line selector end color: $lineselectend\n";
243 if($selecttype) {
244 push @out, "selector type: $selecttype\n";
246 if(defined($iconset)) {
247 push @out, "iconset: $iconset\n";
249 if(defined($viewericon)) {
250 push @out, "viewers iconset: $viewericon\n";
252 if($lineselecttextcolor && $main_depth > 2 ) {
253 push @out, "line selector text color: $lineselecttextcolor\n";
255 if($filetylecolor && $main_depth > 2) {
256 push @out, "filetype colours: $filetylecolor\n";
258 if($rwps && $has_remote ) {
259 push @out, "rwps: /.rockbox/wps/$rwps\n";
261 if(-f ".rockbox/wps/$cfg") {
262 print STDERR "wpsbuild warning: wps/$cfg already exists!\n";
264 else {
265 open(CFG, ">.rockbox/themes/$cfg");
266 print CFG @out;
267 close(CFG);
271 # Get the LCD sizes first
272 ($main_height, $main_width, $main_depth) = getlcdsizes();
273 ($remote_height, $remote_width, $remote_depth) = getlcdsizes(1);
275 #print "LCD: ${main_height}x${main_width}x${main_depth}\n";
276 $has_remote = 1 if ($remote_height && $remote_width && remote_depth);
278 open(WPS, "<$wpslist");
279 while(<WPS>) {
280 my $l = $_;
281 if($l =~ /^ *\#/) {
282 # skip comment
283 next;
285 if($l =~ /^ *<(r|)wps>/i) {
286 $isrwps = $1;
287 $within = 1;
288 # undef is a unary operator (!)
289 undef $wps;
290 undef $wps_prefix;
291 undef $rwps;
292 undef $width;
293 undef $height;
294 undef $font;
295 undef $fgcolor;
296 undef $bgcolor;
297 undef $statusbar;
298 undef $author;
299 undef $req_g_wps;
300 undef $req_t_wps;
301 undef $backdrop;
302 undef $lineselectstart;
303 undef $lineselectend;
304 undef $selecttype;
305 undef $iconset;
306 undef $viewericon;
307 undef $lineselecttextcolor;
308 undef $filetylecolor;
310 next;
312 if($within) {
313 if($l =~ /^ *<\/${isrwps}wps>/i) {
314 # Get the required width and height
315 my ($rheight, $rwidth, $rdepth);
316 if($isrwps) {
317 ($rheight, $rwidth, $rdepth) =
318 ($remote_height, $remote_width, $remote_depth);
320 else {
321 ($rheight, $rwidth, $rdepth) =
322 ($main_height, $main_width, $main_depth);
325 if(!$rheight || !$rwidth) {
326 #printf STDERR "wpsbuild notice: No %sLCD size, skipping $wps\n",
327 #$isrwps?"remote ":"";
328 $within = 0;
329 next;
331 $wpslist =~ /(.*)WPSLIST/;
332 my $wpsdir = $1;
333 # If this WPS installable on this platform, one of the following
334 # two files will be present
335 foreach $d (@depthlist) {
336 next if ($d > $rdepth);
338 $req_g = $rwidth . "x" . $rheight . "x" . $d;
340 $req_g_wps = $wps_prefix . "." . $req_g . ".wps";
341 last if (-e "$wpsdir/$req_g_wps");
343 if ($isrwps) {
344 $req_g = $req_g . "." . $main_width . "x" . $main_height . "x" . "$main_depth";
346 $req_g_wps = $wps_prefix . "." . $req_g . ".wps";
347 last if (-e "$wpsdir/$req_g_wps");
350 $req_t_wps = $wps_prefix . ".txt" . ".wps";
352 #print "LCD: $wps wants $height x $width\n";
353 #print "LCD: is $rheight x $rwidth\n";
355 #print "gwps: $wpsdir/$req_g_wps" . "\n";
356 if (-e "$wpsdir/$req_g_wps" || -e "$wpsdir/$req_t_wps" ) {
358 # The target model has an LCD that is suitable for this
359 # WPS
361 #print "Size requirement is fine!\n";
362 mkdirs() if (-e "$wpsdir/$req_g_wps");
363 if(!$isrwps) {
364 # We only make .cfg files for <wps> sections:
365 buildcfg();
367 copywps();
369 else {
370 #print "(${wps_prefix}-${rwidth}x${rheight}x$rdepth) ";
371 #print "Skip $wps due to size restraints\n";
373 $within = 0;
375 elsif($l =~ /^Name: *(.*)/i) {
376 # Note that in the case this is within <rwps>, $wps will contain the
377 # name of the rwps. Use $isrwps to figure out what type it is.
378 $wps = $wps_prefix = $1;
379 $wps_prefix =~ s/\.(r|)wps//;
380 # print $wps_prefix . "\n";
382 elsif($l =~ /^RWPS: *(.*)/i) {
383 $rwps = $1;
385 elsif($l =~ /^RWPS\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
386 $rwps = $1;
388 elsif($l =~ /^Author: *(.*)/i) {
389 $author = $1;
391 elsif($l =~ /^Width: *(.*)/i) {
392 $width = $1;
394 elsif($l =~ /^Width\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
395 $width = $1;
397 elsif($l =~ /^Height: *(.*)/i) {
398 $height = $1;
400 elsif($l =~ /^Height\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
401 $height = $1;
403 elsif($l =~ /^Font: *(.*)/i) {
404 $font = $1;
406 elsif($l =~ /^Foreground Color: *(.*)/i) {
407 $fgcolor = $1;
409 elsif($l =~ /^Background Color: *(.*)/i) {
410 $bgcolor = $1;
412 elsif($l =~ /^Font\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
413 $font = $1;
414 copythemefont();
416 elsif($l =~ /^Statusbar: *(.*)/i) {
417 $statusbar = $1;
419 elsif($l =~ /^Statusbar\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
420 $statusbar = $1;
422 elsif($l =~ /^Backdrop: *(.*)/i) {
423 $backdrop = $1;
424 copybackdrop();
426 elsif($l =~ /^Backdrop\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
427 $backdrop = $1;
428 copybackdrop();
430 elsif($l =~ /^line selector start color: *(.*)/i) {
431 $lineselectstart = $1;
433 elsif($l =~ /^line selector end color: *(.*)/i) {
434 $lineselectend = $1;
436 elsif($l =~ /^selector type: *(.*)/i) {
437 $selecttype = $1;
439 elsif($l =~ /^selector type\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
440 $selecttype = $1;
442 elsif($l =~ /^iconset: *(.*)/i) {
443 $iconset = $1;
444 copythemeicon();
446 elsif($l =~ /^iconset\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
447 $iconset = $1;
448 copythemeicon();
450 elsif($l =~ /^viewers iconset: *(.*)/i) {
451 $viewericon = $1;
452 copythemeviewericon();
454 elsif($l =~ /^viewers iconset\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
455 $viewericon = $1;
456 copythemeviewericon();
458 elsif($l =~ /^line selector text color: *(.*)/i) {
459 $lineselecttextcolor = $1;
461 elsif($l =~ /^filetype colours: *(.*)/i) {
462 $filetylecolor = $1;
464 else{
465 #print "Unknown line: $l!\n";
470 close(WPS);