Fix a bug introduced r16373 - the .cfg files for the bundled themes no longer include...
[Rockbox.git] / wps / wpsbuild.pl
blobbcabb234f830b9f17f99b52ccce3d4c9bf06ea49
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 {
41 my ($remote) = @_;
43 open(GCC, ">gcctemp");
44 if($remote) {
45 # Get the remote LCD screen size
46 print GCC <<STOP
47 \#include "config.h"
48 #ifdef HAVE_REMOTE_LCD
49 Height: LCD_REMOTE_HEIGHT
50 Width: LCD_REMOTE_WIDTH
51 Depth: LCD_REMOTE_DEPTH
52 #endif
53 STOP
56 else {
57 print GCC <<STOP
58 \#include "config.h"
59 Height: LCD_HEIGHT
60 Width: LCD_WIDTH
61 Depth: LCD_DEPTH
62 STOP
65 close(GCC);
67 my $c="cat gcctemp | gcc $cppdef -I. -I$firmdir/export -E -P -";
69 #print "CMD $c\n";
71 open(GETSIZE, "$c|");
73 my ($height, $width);
74 while(<GETSIZE>) {
75 if($_ =~ /^Height: (\d*)/) {
76 $height = $1;
78 elsif($_ =~ /^Width: (\d*)/) {
79 $width = $1;
81 elsif($_ =~ /^Depth: (\d*)/) {
82 $depth = $1;
84 if($height && $width && $depth) {
85 last;
88 close(GETSIZE);
89 unlink("gcctemp");
91 return ($height, $width, $depth);
94 sub mkdirs {
95 my $wpsdir = $wps;
96 $wpsdir =~ s/\.(r|)wps//;
97 mkdir ".rockbox/wps", 0777;
98 mkdir ".rockbox/themes", 0777;
100 if( -d ".rockbox/wps/$wpsdir") {
101 #print STDERR "wpsbuild warning: directory wps/$wpsdir already exists!\n";
103 else
105 mkdir ".rockbox/wps/$wpsdir", 0777;
109 sub copybackdrop {
110 #copy the backdrop file into the build dir
111 $dst = $backdrop;
112 $dst =~ s/(\.[0-9]*x[0-9]*x[0-9]*)//;
113 $cmd = "cp $ROOT/$backdrop .rockbox/$dst";
114 `$cmd`;
117 sub copythemefont {
118 #copy the font specified by the theme
120 $o=$font;
121 $o =~ s/\.fnt/\.bdf/;
122 `mkdir .rockbox/fonts/ >/dev/null 2>&1`;
123 $cmd ="$ROOT/tools/convbdf -f -o \".rockbox/fonts/$font\" \"$ROOT/fonts/$o\" ";
124 `$cmd`;
127 sub copythemeicon {
128 #copy the icon specified by the theme
130 $iconset =~ /\/(.*icons\/(.*))/i;
131 `cp $ROOT/icons/$2 $1`;
134 sub copythemeviewericon {
135 #copy the viewer icon specified by the theme
137 $viewericon =~ /\/(.*icons\/(.*))/i;
138 `cp $ROOT/icons/$2 $1`;
142 sub copywps {
143 # we assume that we copy the WPS files from the same dir the WPSLIST
144 # file is located in
145 my $dir;
146 my @filelist;
147 my $file;
149 if($wpslist =~ /(.*)WPSLIST/) {
150 $dir = $1;
151 # system("cp $dir/$wps .rockbox/wps/");
152 # print "$req_t_wps $req_g_wps\n";
154 if (-e "$dir/$req_t_wps" ) {
155 system("cp $dir/$req_t_wps .rockbox/wps/$wps");
157 } elsif (-e "$dir/$req_g_wps") {
158 system("cp $dir/$req_g_wps .rockbox/wps/$wps");
160 open(WPSFILE, "$dir/$req_g_wps");
161 while (<WPSFILE>) {
162 $filelist[$#filelist + 1] = $1 if (/\|([^|]*?.bmp)\|/);
164 close(WPSFILE);
166 if ($#filelist >= 0) {
167 if (-e "$dir/$wps_prefix/$req_g") {
168 foreach $file (@filelist) {
169 system("cp $dir/$wps_prefix/$req_g/$file .rockbox/wps/$wps_prefix/");
172 elsif (-e "$dir/$wps_prefix") {
173 foreach $file (@filelist) {
174 system("cp $dir/$wps_prefix/$file .rockbox/wps/$wps_prefix/");
177 else {
178 print STDERR "beep, no dir to copy WPS from!\n";
182 } else {
183 print STDERR "Skipping $wps - no matching resolution.\n";
185 } else {
186 print STDERR "No source directory!\n";
190 sub buildcfg {
191 my $cfg = $wps;
192 my @out;
194 $cfg =~ s/\.(r|)wps/.cfg/;
196 push @out, <<MOO
198 \# $cfg generated by wpsbuild.pl
199 \# $wps is made by $author
201 wps: /.rockbox/wps/$wps
204 if($font) {
205 push @out, "font: /.rockbox/fonts/$font\n";
207 if($fgcolor && $main_depth > 2) {
208 push @out, "foreground color: $fgcolor\n";
210 if($bgcolor && $main_depth > 2) {
211 push @out, "background color: $bgcolor\n";
213 if($statusbar) {
214 push @out, "statusbar: $statusbar\n";
216 if($backdrop) {
217 #clip resolution from filename
218 $backdrop =~ s/(\.[0-9]*x[0-9]*x[0-9]*)//;
219 push @out, "backdrop: /.rockbox/$backdrop\n";
221 if($lineselectstart && $main_depth > 2) {
222 push @out, "line selector start color: $lineselectstart\n";
224 if($lineselectend && $main_depth > 2) {
225 push @out, "line selector end color: $lineselectend\n";
227 if($selecttype) {
228 push @out, "selector type: $selecttype\n";
230 if($iconset) {
231 push @out, "iconset: $iconset\n";
233 if($viewericon) {
234 push @out, "viewers iconset: $viewericon\n";
236 if($lineselecttextcolor && $main_depth > 2 ) {
237 push @out, "line selector text color: $lineselecttextcolor\n";
239 if($filetylecolor && $main_depth > 2) {
240 push @out, "filetype colours: $filetylecolor\n";
242 if($rwps && $has_remote ) {
243 push @out, "rwps: /.rockbox/wps/$rwps\n";
245 if(-f ".rockbox/wps/$cfg") {
246 print STDERR "wpsbuild warning: wps/$cfg already exists!\n";
248 else {
249 open(CFG, ">.rockbox/themes/$cfg");
250 print CFG @out;
251 close(CFG);
255 # Get the LCD sizes first
256 ($main_height, $main_width, $main_depth) = getlcdsizes();
257 ($remote_height, $remote_width, $remote_depth) = getlcdsizes(1);
259 #print "LCD: ${main_height}x${main_width}x${main_depth}\n";
260 $has_remote = 1 if ($remote_height && $remote_width && remote_depth);
262 open(WPS, "<$wpslist");
263 while(<WPS>) {
264 my $l = $_;
265 if($l =~ /^ *\#/) {
266 # skip comment
267 next;
269 if($l =~ /^ *<(r|)wps>/i) {
270 $isrwps = $1;
271 $within = 1;
272 # undef is a unary operator (!)
273 undef $wps;
274 undef $wps_prefix;
275 undef $rwps;
276 undef $width;
277 undef $height;
278 undef $font;
279 undef $fgcolor;
280 undef $bgcolor;
281 undef $statusbar;
282 undef $author;
283 undef $req_g_wps;
284 undef $req_t_wps;
285 undef $backdrop;
286 undef $lineselectstart;
287 undef $lineselectend;
288 undef $selecttype;
289 undef $iconset;
290 undef $viewericon;
291 undef $lineselecttextcolor;
292 undef $filetylecolor;
294 next;
296 if($within) {
297 if($l =~ /^ *<\/${isrwps}wps>/i) {
298 # Get the required width and height
299 my ($rheight, $rwidth, $rdepth);
300 if($isrwps) {
301 ($rheight, $rwidth, $rdepth) =
302 ($remote_height, $remote_width, $remote_depth);
304 else {
305 ($rheight, $rwidth, $rdepth) =
306 ($main_height, $main_width, $main_depth);
309 if(!$rheight || !$rwidth) {
310 #printf STDERR "wpsbuild notice: No %sLCD size, skipping $wps\n",
311 #$isrwps?"remote ":"";
312 $within = 0;
313 next;
315 $wpslist =~ /(.*)WPSLIST/;
316 my $wpsdir = $1;
317 # If this WPS installable on this platform, one of the following
318 # two files will be present
319 foreach $d (@depthlist) {
320 next if ($d > $rdepth);
322 $req_g = $rwidth . "x" . $rheight . "x" . $d;
324 $req_g_wps = $wps_prefix . "." . $req_g . ".wps";
325 last if (-e "$wpsdir/$req_g_wps");
327 if ($isrwps) {
328 $req_g = $req_g . "." . $main_width . "x" . $main_height . "x" . "$main_depth";
330 $req_g_wps = $wps_prefix . "." . $req_g . ".wps";
331 last if (-e "$wpsdir/$req_g_wps");
334 $req_t_wps = $wps_prefix . ".txt" . ".wps";
336 #print "LCD: $wps wants $height x $width\n";
337 #print "LCD: is $rheight x $rwidth\n";
339 #print "gwps: $wpsdir/$req_g_wps" . "\n";
340 if (-e "$wpsdir/$req_g_wps" || -e "$wpsdir/$req_t_wps" ) {
342 # The target model has an LCD that is suitable for this
343 # WPS
345 #print "Size requirement is fine!\n";
346 mkdirs() if (-e "$wpsdir/$req_g_wps");
347 if(!$isrwps) {
348 # We only make .cfg files for <wps> sections:
349 buildcfg();
351 copywps();
353 else {
354 #print "(${wps_prefix}-${rwidth}x${rheight}x$rdepth) ";
355 #print "Skip $wps due to size restraints\n";
357 $within = 0;
359 elsif($l =~ /^Name: (.*)/i) {
360 # Note that in the case this is within <rwps>, $wps will contain the
361 # name of the rwps. Use $isrwps to figure out what type it is.
362 $wps = $wps_prefix = $1;
363 $wps_prefix =~ s/\.(r|)wps//;
364 # print $wps_prefix . "\n";
366 elsif($l =~ /^RWPS: (.*)/i) {
367 $rwps = $1;
369 elsif($l =~ /^RWPS\.${main_width}x${main_height}x$main_depth: (.*)/i) {
370 $rwps = $1;
372 elsif($l =~ /^Author: (.*)/i) {
373 $author = $1;
375 elsif($l =~ /^Width: (.*)/i) {
376 $width = $1;
378 elsif($l =~ /^Width\.${main_width}x${main_height}x$main_depth: (.*)/i) {
379 $width = $1;
381 elsif($l =~ /^Height: (.*)/i) {
382 $height = $1;
384 elsif($l =~ /^Height\.${main_width}x${main_height}x$main_depth: (.*)/i) {
385 $height = $1;
387 elsif($l =~ /^Font: (.*)/i) {
388 $font = $1;
390 elsif($l =~ /^Foreground Color: (.*)/i) {
391 $fgcolor = $1;
393 elsif($l =~ /^Background Color: (.*)/i) {
394 $bgcolor = $1;
396 elsif($l =~ /^Font\.${main_width}x${main_height}x$main_depth: (.*)/i) {
397 $font = $1;
398 copythemefont();
400 elsif($l =~ /^Statusbar: (.*)/i) {
401 $statusbar = $1;
403 elsif($l =~ /^Statusbar\.${main_width}x${main_height}x$main_depth: (.*)/i) {
404 $statusbar = $1;
406 elsif($l =~ /^Backdrop: (.*)/i) {
407 $backdrop = $1;
408 copybackdrop();
410 elsif($l =~ /^Backdrop\.${main_width}x${main_height}x$main_depth: (.*)/i) {
411 $backdrop = $1;
412 copybackdrop();
414 elsif($l =~ /^line selector start color: (.*)/i) {
415 $lineselectstart = $1;
417 elsif($l =~ /^line selector end color: (.*)/i) {
418 $lineselectend = $1;
420 elsif($l =~ /^selector type: (.*)/i) {
421 $selecttype = $1;
423 elsif($l =~ /^selector type\.${main_width}x${main_height}x$main_depth: (.*)/i) {
424 $selecttype = $1;
426 elsif($l =~ /^iconset: (.*)/i) {
427 $iconset = $1;
428 copythemeicon();
430 elsif($l =~ /^iconset\.${main_width}x${main_height}x$main_depth: (.*)/i) {
431 $iconset = $1;
432 copythemeicon();
434 elsif($l =~ /^viewers iconset: (.*)/i) {
435 $viewericon = $1;
436 copythemeviewericon();
438 elsif($l =~ /^viewers iconset\.${main_width}x${main_height}x$main_depth: (.*)/i) {
439 $viewericon = $1;
440 copythemeviewericon();
442 elsif($l =~ /^line selector text color: (.*)/i) {
443 $lineselecttextcolor = $1;
445 elsif($l =~ /^filetype colours: (.*)/i) {
446 $filetylecolor = $1;
448 else{
449 #print "Unknown line: $l!\n";
457 close(WPS);