Add a useful note regarding USB connection to the iAudio X5 installation chapter.
[Rockbox.git] / wps / wpsbuild.pl
blobf7d095268e806b4b81d746cf23697d600d891644
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 # remove CR
282 $l =~ s/\r//g;
283 if($l =~ /^ *\#/) {
284 # skip comment
285 next;
287 if($l =~ /^ *<(r|)wps>/i) {
288 $isrwps = $1;
289 $within = 1;
290 # undef is a unary operator (!)
291 undef $wps;
292 undef $wps_prefix;
293 undef $rwps;
294 undef $width;
295 undef $height;
296 undef $font;
297 undef $fgcolor;
298 undef $bgcolor;
299 undef $statusbar;
300 undef $author;
301 undef $req_g_wps;
302 undef $req_t_wps;
303 undef $backdrop;
304 undef $lineselectstart;
305 undef $lineselectend;
306 undef $selecttype;
307 undef $iconset;
308 undef $viewericon;
309 undef $lineselecttextcolor;
310 undef $filetylecolor;
312 next;
314 if($within) {
315 if($l =~ /^ *<\/${isrwps}wps>/i) {
316 # Get the required width and height
317 my ($rheight, $rwidth, $rdepth);
318 if($isrwps) {
319 ($rheight, $rwidth, $rdepth) =
320 ($remote_height, $remote_width, $remote_depth);
322 else {
323 ($rheight, $rwidth, $rdepth) =
324 ($main_height, $main_width, $main_depth);
327 if(!$rheight || !$rwidth) {
328 #printf STDERR "wpsbuild notice: No %sLCD size, skipping $wps\n",
329 #$isrwps?"remote ":"";
330 $within = 0;
331 next;
333 $wpslist =~ /(.*)WPSLIST/;
334 my $wpsdir = $1;
335 # If this WPS installable on this platform, one of the following
336 # two files will be present
337 foreach $d (@depthlist) {
338 next if ($d > $rdepth);
340 $req_g = $rwidth . "x" . $rheight . "x" . $d;
342 $req_g_wps = $wps_prefix . "." . $req_g . ".wps";
343 last if (-e "$wpsdir/$req_g_wps");
345 if ($isrwps) {
346 $req_g = $req_g . "." . $main_width . "x" . $main_height . "x" . "$main_depth";
348 $req_g_wps = $wps_prefix . "." . $req_g . ".wps";
349 last if (-e "$wpsdir/$req_g_wps");
352 $req_t_wps = $wps_prefix . ".txt" . ".wps";
354 #print "LCD: $wps wants $height x $width\n";
355 #print "LCD: is $rheight x $rwidth\n";
357 #print "gwps: $wpsdir/$req_g_wps" . "\n";
358 if (-e "$wpsdir/$req_g_wps" || -e "$wpsdir/$req_t_wps" ) {
360 # The target model has an LCD that is suitable for this
361 # WPS
363 #print "Size requirement is fine!\n";
364 mkdirs() if (-e "$wpsdir/$req_g_wps");
365 if(!$isrwps) {
366 # We only make .cfg files for <wps> sections:
367 buildcfg();
369 copywps();
371 else {
372 #print "(${wps_prefix}-${rwidth}x${rheight}x$rdepth) ";
373 #print "Skip $wps due to size restraints\n";
375 $within = 0;
377 elsif($l =~ /^Name: *(.*)/i) {
378 # Note that in the case this is within <rwps>, $wps will contain the
379 # name of the rwps. Use $isrwps to figure out what type it is.
380 $wps = $wps_prefix = $1;
381 $wps_prefix =~ s/\.(r|)wps//;
382 # print $wps_prefix . "\n";
384 elsif($l =~ /^RWPS: *(.*)/i) {
385 $rwps = $1;
387 elsif($l =~ /^RWPS\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
388 $rwps = $1;
390 elsif($l =~ /^Author: *(.*)/i) {
391 $author = $1;
393 elsif($l =~ /^Width: *(.*)/i) {
394 $width = $1;
396 elsif($l =~ /^Width\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
397 $width = $1;
399 elsif($l =~ /^Height: *(.*)/i) {
400 $height = $1;
402 elsif($l =~ /^Height\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
403 $height = $1;
405 elsif($l =~ /^Font: *(.*)/i) {
406 $font = $1;
408 elsif($l =~ /^Foreground Color: *(.*)/i) {
409 $fgcolor = $1;
411 elsif($l =~ /^Background Color: *(.*)/i) {
412 $bgcolor = $1;
414 elsif($l =~ /^Font\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
415 $font = $1;
416 copythemefont();
418 elsif($l =~ /^Statusbar: *(.*)/i) {
419 $statusbar = $1;
421 elsif($l =~ /^Statusbar\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
422 $statusbar = $1;
424 elsif($l =~ /^Backdrop: *(.*)/i) {
425 $backdrop = $1;
426 copybackdrop();
428 elsif($l =~ /^Backdrop\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
429 $backdrop = $1;
430 copybackdrop();
432 elsif($l =~ /^line selector start color: *(.*)/i) {
433 $lineselectstart = $1;
435 elsif($l =~ /^line selector end color: *(.*)/i) {
436 $lineselectend = $1;
438 elsif($l =~ /^selector type: *(.*)/i) {
439 $selecttype = $1;
441 elsif($l =~ /^selector type\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
442 $selecttype = $1;
444 elsif($l =~ /^iconset: *(.*)/i) {
445 $iconset = $1;
446 copythemeicon();
448 elsif($l =~ /^iconset\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
449 $iconset = $1;
450 copythemeicon();
452 elsif($l =~ /^viewers iconset: *(.*)/i) {
453 $viewericon = $1;
454 copythemeviewericon();
456 elsif($l =~ /^viewers iconset\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
457 $viewericon = $1;
458 copythemeviewericon();
460 elsif($l =~ /^line selector text color: *(.*)/i) {
461 $lineselecttextcolor = $1;
463 elsif($l =~ /^filetype colours: *(.*)/i) {
464 $filetylecolor = $1;
466 else{
467 #print "Unknown line: $l!\n";
472 close(WPS);