TAB/whitespace policing - no functional changes
[Rockbox.git] / wps / wpsbuild.pl
blob6a963f9a7c820f1e75cc8154b2fc2efd764c921d
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 $dst = $backdrop;
115 $dst =~ s/(\.[0-9]*x[0-9]*x[0-9]*)//;
116 $cmd = "cp $ROOT/$backdrop .rockbox/$dst";
117 `$cmd`;
120 sub copythemefont
122 #copy the font specified by the theme
124 $o=$font;
125 $o =~ s/\.fnt/\.bdf/;
126 `mkdir .rockbox/fonts/ >/dev/null 2>&1`;
127 $cmd ="$ROOT/tools/convbdf -f -o \".rockbox/fonts/$font\" \"$ROOT/fonts/$o\" ";
128 `$cmd`;
131 sub copythemeicon
133 #copy the icon specified by the theme
135 $iconset =~ /\/(.*icons\/(.*))/i;
136 `cp $ROOT/icons/$2 $1`;
139 sub copythemeviewericon
141 #copy the viewer icon specified by the theme
143 $viewericon =~ /\/(.*icons\/(.*))/i;
144 `cp $ROOT/icons/$2 $1`;
147 sub copywps
149 # we assume that we copy the WPS files from the same dir the WPSLIST
150 # file is located in
151 my $dir;
152 my @filelist;
153 my $file;
155 if($wpslist =~ /(.*)WPSLIST/) {
156 $dir = $1;
157 # system("cp $dir/$wps .rockbox/wps/");
158 # print "$req_t_wps $req_g_wps\n";
160 if (-e "$dir/$req_t_wps" ) {
161 system("cp $dir/$req_t_wps .rockbox/wps/$wps");
163 } elsif (-e "$dir/$req_g_wps") {
164 system("cp $dir/$req_g_wps .rockbox/wps/$wps");
166 open(WPSFILE, "$dir/$req_g_wps");
167 while (<WPSFILE>) {
168 $filelist[$#filelist + 1] = $1 if (/\|([^|]*?.bmp)\|/);
170 close(WPSFILE);
172 if ($#filelist >= 0) {
173 if (-e "$dir/$wps_prefix/$req_g") {
174 foreach $file (@filelist) {
175 system("cp $dir/$wps_prefix/$req_g/$file .rockbox/wps/$wps_prefix/");
178 elsif (-e "$dir/$wps_prefix") {
179 foreach $file (@filelist) {
180 system("cp $dir/$wps_prefix/$file .rockbox/wps/$wps_prefix/");
183 else {
184 print STDERR "beep, no dir to copy WPS from!\n";
188 } else {
189 print STDERR "Skipping $wps - no matching resolution.\n";
191 } else {
192 print STDERR "No source directory!\n";
196 sub buildcfg {
197 my $cfg = $wps;
198 my @out;
200 $cfg =~ s/\.(r|)wps/.cfg/;
202 push @out, <<MOO
204 \# $cfg generated by wpsbuild.pl
205 \# $wps is made by $author
207 wps: /.rockbox/wps/$wps
210 if($font) {
211 push @out, "font: /.rockbox/fonts/$font\n";
213 if($fgcolor && $main_depth > 2) {
214 push @out, "foreground color: $fgcolor\n";
216 if($bgcolor && $main_depth > 2) {
217 push @out, "background color: $bgcolor\n";
219 if($statusbar) {
220 push @out, "statusbar: $statusbar\n";
222 if($backdrop) {
223 # clip resolution from filename
224 $backdrop =~ s/(\.[0-9]*x[0-9]*x[0-9]*)//;
225 push @out, "backdrop: /.rockbox/$backdrop\n";
227 if($lineselectstart && $main_depth > 2) {
228 push @out, "line selector start color: $lineselectstart\n";
230 if($lineselectend && $main_depth > 2) {
231 push @out, "line selector end color: $lineselectend\n";
233 if($selecttype) {
234 push @out, "selector type: $selecttype\n";
236 if($iconset) {
237 push @out, "iconset: $iconset\n";
239 if($viewericon) {
240 push @out, "viewers iconset: $viewericon\n";
242 if($lineselecttextcolor && $main_depth > 2 ) {
243 push @out, "line selector text color: $lineselecttextcolor\n";
245 if($filetylecolor && $main_depth > 2) {
246 push @out, "filetype colours: $filetylecolor\n";
248 if($rwps && $has_remote ) {
249 push @out, "rwps: /.rockbox/wps/$rwps\n";
251 if(-f ".rockbox/wps/$cfg") {
252 print STDERR "wpsbuild warning: wps/$cfg already exists!\n";
254 else {
255 open(CFG, ">.rockbox/themes/$cfg");
256 print CFG @out;
257 close(CFG);
261 # Get the LCD sizes first
262 ($main_height, $main_width, $main_depth) = getlcdsizes();
263 ($remote_height, $remote_width, $remote_depth) = getlcdsizes(1);
265 #print "LCD: ${main_height}x${main_width}x${main_depth}\n";
266 $has_remote = 1 if ($remote_height && $remote_width && remote_depth);
268 open(WPS, "<$wpslist");
269 while(<WPS>) {
270 my $l = $_;
271 if($l =~ /^ *\#/) {
272 # skip comment
273 next;
275 if($l =~ /^ *<(r|)wps>/i) {
276 $isrwps = $1;
277 $within = 1;
278 # undef is a unary operator (!)
279 undef $wps;
280 undef $wps_prefix;
281 undef $rwps;
282 undef $width;
283 undef $height;
284 undef $font;
285 undef $fgcolor;
286 undef $bgcolor;
287 undef $statusbar;
288 undef $author;
289 undef $req_g_wps;
290 undef $req_t_wps;
291 undef $backdrop;
292 undef $lineselectstart;
293 undef $lineselectend;
294 undef $selecttype;
295 undef $iconset;
296 undef $viewericon;
297 undef $lineselecttextcolor;
298 undef $filetylecolor;
300 next;
302 if($within) {
303 if($l =~ /^ *<\/${isrwps}wps>/i) {
304 # Get the required width and height
305 my ($rheight, $rwidth, $rdepth);
306 if($isrwps) {
307 ($rheight, $rwidth, $rdepth) =
308 ($remote_height, $remote_width, $remote_depth);
310 else {
311 ($rheight, $rwidth, $rdepth) =
312 ($main_height, $main_width, $main_depth);
315 if(!$rheight || !$rwidth) {
316 #printf STDERR "wpsbuild notice: No %sLCD size, skipping $wps\n",
317 #$isrwps?"remote ":"";
318 $within = 0;
319 next;
321 $wpslist =~ /(.*)WPSLIST/;
322 my $wpsdir = $1;
323 # If this WPS installable on this platform, one of the following
324 # two files will be present
325 foreach $d (@depthlist) {
326 next if ($d > $rdepth);
328 $req_g = $rwidth . "x" . $rheight . "x" . $d;
330 $req_g_wps = $wps_prefix . "." . $req_g . ".wps";
331 last if (-e "$wpsdir/$req_g_wps");
333 if ($isrwps) {
334 $req_g = $req_g . "." . $main_width . "x" . $main_height . "x" . "$main_depth";
336 $req_g_wps = $wps_prefix . "." . $req_g . ".wps";
337 last if (-e "$wpsdir/$req_g_wps");
340 $req_t_wps = $wps_prefix . ".txt" . ".wps";
342 #print "LCD: $wps wants $height x $width\n";
343 #print "LCD: is $rheight x $rwidth\n";
345 #print "gwps: $wpsdir/$req_g_wps" . "\n";
346 if (-e "$wpsdir/$req_g_wps" || -e "$wpsdir/$req_t_wps" ) {
348 # The target model has an LCD that is suitable for this
349 # WPS
351 #print "Size requirement is fine!\n";
352 mkdirs() if (-e "$wpsdir/$req_g_wps");
353 if(!$isrwps) {
354 # We only make .cfg files for <wps> sections:
355 buildcfg();
357 copywps();
359 else {
360 #print "(${wps_prefix}-${rwidth}x${rheight}x$rdepth) ";
361 #print "Skip $wps due to size restraints\n";
363 $within = 0;
365 elsif($l =~ /^Name: (.*)/i) {
366 # Note that in the case this is within <rwps>, $wps will contain the
367 # name of the rwps. Use $isrwps to figure out what type it is.
368 $wps = $wps_prefix = $1;
369 $wps_prefix =~ s/\.(r|)wps//;
370 # print $wps_prefix . "\n";
372 elsif($l =~ /^RWPS: (.*)/i) {
373 $rwps = $1;
375 elsif($l =~ /^RWPS\.${main_width}x${main_height}x$main_depth: (.*)/i) {
376 $rwps = $1;
378 elsif($l =~ /^Author: (.*)/i) {
379 $author = $1;
381 elsif($l =~ /^Width: (.*)/i) {
382 $width = $1;
384 elsif($l =~ /^Width\.${main_width}x${main_height}x$main_depth: (.*)/i) {
385 $width = $1;
387 elsif($l =~ /^Height: (.*)/i) {
388 $height = $1;
390 elsif($l =~ /^Height\.${main_width}x${main_height}x$main_depth: (.*)/i) {
391 $height = $1;
393 elsif($l =~ /^Font: (.*)/i) {
394 $font = $1;
396 elsif($l =~ /^Foreground Color: (.*)/i) {
397 $fgcolor = $1;
399 elsif($l =~ /^Background Color: (.*)/i) {
400 $bgcolor = $1;
402 elsif($l =~ /^Font\.${main_width}x${main_height}x$main_depth: (.*)/i) {
403 $font = $1;
404 copythemefont();
406 elsif($l =~ /^Statusbar: (.*)/i) {
407 $statusbar = $1;
409 elsif($l =~ /^Statusbar\.${main_width}x${main_height}x$main_depth: (.*)/i) {
410 $statusbar = $1;
412 elsif($l =~ /^Backdrop: (.*)/i) {
413 $backdrop = $1;
414 copybackdrop();
416 elsif($l =~ /^Backdrop\.${main_width}x${main_height}x$main_depth: (.*)/i) {
417 $backdrop = $1;
418 copybackdrop();
420 elsif($l =~ /^line selector start color: (.*)/i) {
421 $lineselectstart = $1;
423 elsif($l =~ /^line selector end color: (.*)/i) {
424 $lineselectend = $1;
426 elsif($l =~ /^selector type: (.*)/i) {
427 $selecttype = $1;
429 elsif($l =~ /^selector type\.${main_width}x${main_height}x$main_depth: (.*)/i) {
430 $selecttype = $1;
432 elsif($l =~ /^iconset: (.*)/i) {
433 $iconset = $1;
434 copythemeicon();
436 elsif($l =~ /^iconset\.${main_width}x${main_height}x$main_depth: (.*)/i) {
437 $iconset = $1;
438 copythemeicon();
440 elsif($l =~ /^viewers iconset: (.*)/i) {
441 $viewericon = $1;
442 copythemeviewericon();
444 elsif($l =~ /^viewers iconset\.${main_width}x${main_height}x$main_depth: (.*)/i) {
445 $viewericon = $1;
446 copythemeviewericon();
448 elsif($l =~ /^line selector text color: (.*)/i) {
449 $lineselecttextcolor = $1;
451 elsif($l =~ /^filetype colours: (.*)/i) {
452 $filetylecolor = $1;
454 else{
455 #print "Unknown line: $l!\n";
460 close(WPS);