3 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
12 use Getopt
::Long
qw(:config pass_through); # pass_through so not confused by -DTYPE_STUFF
17 my $tempdir=".rockbox";
23 GetOptions
( 'r|root=s' => \
$ROOT,
24 'm|modelname=s' => \
$modelname,
25 'v|verbose' => \
$verbose,
26 'rbdir=s' => \
$rbdir, # If we want to put in a different directory
27 'tempdir=s' => \
$tempdir, # override .rockbox temporary dir
30 ($wpslist, $target) = @ARGV;
32 my $firmdir="$ROOT/firmware";
34 my @depthlist = ( 16, 8, 4, 2, 1 );
36 # These parameters are filled in as we parse wpslist
63 my $lineselecttextcolor;
66 my $remotelistviewport;
69 my ($main_height, $main_width, $main_depth);
70 my ($remote_height, $remote_width, $remote_depth);
75 print "Usage: wpsbuilds.pl <WPSLIST> <target>\n",
76 "Run this script in the root of the target build, and it will put all the\n",
77 "stuff in $tempdir/wps/\n and build the cfg according to $rbdir";
85 open(GCC
, ">gcctemp");
87 # Get the remote LCD screen size
90 #ifdef HAVE_REMOTE_LCD
91 Height: LCD_REMOTE_HEIGHT
92 Width: LCD_REMOTE_WIDTH
93 Depth: LCD_REMOTE_DEPTH
109 my $c="cat gcctemp | gcc $cppdef -I. -I$firmdir/export -E -P -";
113 open(GETSIZE
, "$c|");
115 my ($height, $width, $depth);
117 if($_ =~ /^Height: (\d*)/) {
120 elsif($_ =~ /^Width: (\d*)/) {
123 elsif($_ =~ /^Depth: (\d*)/) {
126 if($height && $width && $depth) {
133 return ($height, $width, $depth);
139 $wpsdir =~ s/\.(r|)wps//;
140 mkdir "$tempdir/wps", 0777;
141 mkdir "$tempdir/themes", 0777;
143 if( -d
"$tempdir/wps/$wpsdir") {
144 #print STDERR "wpsbuild warning: directory wps/$wpsdir already exists!\n";
148 mkdir "$tempdir/wps/$wpsdir", 0777;
154 #copy the backdrop file into the build dir
155 if ($backdrop ne '') {
157 $dst =~ s/(\.[0-9]*x[0-9]*x[0-9]*)//;
158 my $cmd = "cp $ROOT/$backdrop $tempdir/$dst";
165 #copy the font specified by the theme
168 $o =~ s/\.fnt/\.bdf/;
169 mkdir "$tempdir/fonts";
170 my $cmd ="$ROOT/tools/convbdf -f -o \"$tempdir/fonts/$_[0]\" \"$ROOT/fonts/$o\" ";
176 #copy the icon specified by the theme
177 if ($iconset ne '') {
178 my $tempicon = $tempdir . "/" . $iconset;
179 $iconset = $rbdir . "/" . $iconset;
180 $tempicon =~ /\/.*icons\
/(.*)/i;
181 `cp $ROOT/icons/$1 $tempicon`;
185 sub copythemeviewericon
187 #copy the viewer icon specified by the theme
189 if ($viewericon ne '') {
190 my $tempviewericon = $tempdir . "/" . $viewericon;
191 $viewericon = $rbdir . "/" . $viewericon;
192 $tempviewericon =~ /\/.*icons\
/(.*)/i;
193 `cp $ROOT/icons/$1 $tempviewericon`;
199 # we assume that we copy the WPS files from the same dir the WPSLIST
206 if($wpslist =~ /(.*)WPSLIST/) {
208 $__sb = $sbs_prefix . "." . $req_size . ".sbs";
209 #print "$req_t_wps $req_g_wps $sbs_prefix\n";
210 #print "$dir/$__sb\n";
212 # system("cp $dir/$wps .rockbox/wps/");
213 # check for <name>.WIDTHxHEIGHTxDEPTH.sbs
214 if (-e
"$dir/$__sb") {
215 system("cp $dir/$__sb $tempdir/wps/$sbs");
217 # check for <name>.WIDTHxHEIGHTxDEPTH.<model>.sbs and overwrite the
218 # previous sb if needed
219 $__sb = $sbs_prefix . "." . $req_size . "." . $modelname . ".sbs";
220 if (-e
"$dir/$__sb") {
221 system("cp $dir/$__sb $tempdir/wps/$sbs");
224 if (-e
"$dir/$req_t_wps" ) {
225 system("cp $dir/$req_t_wps $tempdir/wps/$wps");
227 } elsif (-e
"$dir/$req_g_wps") {
228 system("cp $dir/$req_g_wps $tempdir/wps/$wps");
230 open(WPSFILE
, "$dir/$req_g_wps");
232 $filelist[$#filelist + 1] = $1 if (/[\(,]([^,]*?.bmp)[\),]/);
236 if ($#filelist >= 0) {
237 if (-e
"$dir/$wps_prefix/$req_size") {
238 foreach $file (@filelist) {
239 system("cp $dir/$wps_prefix/$req_size/$file $tempdir/wps/$wps_prefix/");
242 elsif (-e
"$dir/$wps_prefix") {
243 foreach $file (@filelist) {
244 system("cp $dir/$wps_prefix/$file $tempdir/wps/$wps_prefix/");
248 print STDERR
"beep, no dir to copy WPS from!\n";
253 print STDERR
"Skipping $wps - no matching resolution.\n";
256 print STDERR
"No source directory!\n";
264 $cfg =~ s/\.(r|)wps/.cfg/;
268 \# $cfg generated by wpsbuild.pl
269 \# $wps is made by $author
276 push @out, "sbs: -\n";
278 push @out, "sbs: $rbdir/wps/$sbs\n";
281 if(defined($rsbs) && $has_remote) {
283 push @out, "rsbs: -\n";
285 push @out, "rsbs: $rbdir/wps/$rsbs\n";
290 push @out, "font: -\n";
292 push @out, "font: $rbdir/fonts/$font\n";
295 if(defined($remotefont) && $has_remote) {
296 if ($remotefont eq '') {
297 push @out, "remote font: -\n";
299 push @out, "remote font: $rbdir/fonts/$remotefont\n";
302 if($fgcolor && $main_depth > 2) {
303 push @out, "foreground color: $fgcolor\n";
305 if($bgcolor && $main_depth > 2) {
306 push @out, "background color: $bgcolor\n";
309 if($rwps && $has_remote ) {
310 push @out, "remote statusbar: $statusbar\n";
312 push @out, "statusbar: $statusbar\n";
314 if(defined($backdrop)) {
315 if ($backdrop eq '') {
316 push @out, "backdrop: -\n";
318 # clip resolution from filename
319 $backdrop =~ s/(\.[0-9]*x[0-9]*x[0-9]*)//;
320 push @out, "backdrop: $rbdir/$backdrop\n";
323 if($lineselectstart && $main_depth > 2) {
324 push @out, "line selector start color: $lineselectstart\n";
326 if($lineselectend && $main_depth > 2) {
327 push @out, "line selector end color: $lineselectend\n";
330 push @out, "selector type: $selecttype\n";
332 if(defined($iconset)) {
333 if ($iconset eq '') {
334 push @out, "iconset: -\n";
336 push @out, "iconset: $iconset\n";
339 if(defined($viewericon)) {
340 if ($viewericon eq '') {
341 push @out, "viewers iconset: -\n";
343 push @out, "viewers iconset: $viewericon\n";
346 if($lineselecttextcolor && $main_depth > 2 ) {
347 push @out, "line selector text color: $lineselecttextcolor\n";
349 if($filetylecolor && $main_depth > 2) {
350 if ($filetylecolor eq '') {
351 push @out, "filetype colours: -\n";
353 push @out, "filetype colours: $filetylecolor\n";
356 if($rwps && $has_remote ) {
358 push @out, "rwps: -\n";
360 push @out, "rwps: $rbdir/wps/$rwps\n";
363 if(defined($listviewport)) {
364 if ($listviewport eq '') {
365 push @out, "ui viewport: -\n";
367 push @out, "ui viewport: $listviewport\n";
370 if(defined($remotelistviewport) && $has_remote) {
371 if ($remotelistviewport eq '') {
372 push @out, "remote ui viewport: -\n";
374 push @out, "remote ui viewport: $listviewport\n";
377 if(-f
"$tempdir/wps/$cfg") {
378 print STDERR
"wpsbuild warning: wps/$cfg already exists!\n";
381 open(CFG
, ">$tempdir/themes/$cfg");
387 # Get the LCD sizes first
388 ($main_height, $main_width, $main_depth) = getlcdsizes
();
389 ($remote_height, $remote_width, $remote_depth) = getlcdsizes
(1);
391 #print "LCD: ${main_width}x${main_height}x${main_depth}\n";
392 $has_remote = 1 if ($remote_height && $remote_width && $remote_depth);
397 open(WPS
, "<$wpslist");
408 # prefix $rbdir with / if needed (needed for the theme.cfg)
409 unless ($rbdir =~ m/^\/.*/) {
410 $rbdir = "/" . $rbdir;
413 if($l =~ /^ *<(r|)wps>/i) {
416 # undef is a unary operator (!)
433 undef $lineselectstart;
434 undef $lineselectend;
438 undef $lineselecttextcolor;
439 undef $filetylecolor;
441 undef $remotelistviewport;
446 if($l =~ /^ *<\/${isrwps
}wps
>/i
) {
447 # Get the required width and height
448 my ($rheight, $rwidth, $rdepth);
450 ($rheight, $rwidth, $rdepth) =
451 ($remote_height, $remote_width, $remote_depth);
454 ($rheight, $rwidth, $rdepth) =
455 ($main_height, $main_width, $main_depth);
458 if(!$rheight || !$rwidth) {
459 #printf STDERR "wpsbuild notice: No %sLCD size, skipping $wps\n",
460 #$isrwps?"remote ":"";
464 $wpslist =~ /(.*)WPSLIST/;
466 # If this WPS installable on this platform, one of the following
467 # two files will be present
468 foreach my $d (@depthlist) {
469 next if ($d > $rdepth);
471 $req_size = $rwidth . "x" . $rheight . "x" . $d;
473 # check for model specific wps
474 $req_g_wps = $wps_prefix . "." . $req_size . "." . $modelname . ".wps";
475 last if (-e
"$wpsdir/$req_g_wps");
477 # check for normal wps (with WIDTHxHEIGHTxDEPTH)
478 $req_g_wps = $wps_prefix . "." . $req_size . ".wps";
479 last if (-e
"$wpsdir/$req_g_wps");
482 $req_size = $req_size . "." . $main_width . "x" . $main_height . "x" . "$main_depth";
484 $req_g_wps = $wps_prefix . "." . $req_size . ".wps";
485 last if (-e
"$wpsdir/$req_g_wps");
488 $req_t_wps = $wps_prefix . ".txt" . ".wps";
490 #print "LCD: $wps wants $width x $height\n";
491 #print "LCD: is $rwidth x $rheight\n";
493 #print "gwps: $wpsdir/$req_g_wps" . "\n";
494 if (-e
"$wpsdir/$req_g_wps" || -e
"$wpsdir/$req_t_wps" ) {
496 # The target model has an LCD that is suitable for this
499 #print "Size requirement is fine!\n";
500 mkdirs
() if (-e
"$wpsdir/$req_g_wps");
501 # Do the copying before building the .cfg - buildcfg()
502 # mangles some filenames
510 copythemeviewericon
();
513 copythemefont
($font);
516 copythemefont
($remotefont);
519 # We only make .cfg files for <wps> sections:
525 #print "(${wps_prefix}-${rwidth}x${rheight}x$rdepth) ";
526 #print "Skip $wps due to size restraints\n";
530 elsif($l =~ /^Name: *(.*)/i) {
531 # Note that in the case this is within <rwps>, $wps will contain the
532 # name of the rwps. Use $isrwps to figure out what type it is.
533 $wps = $wps_prefix = $1;
534 $wps_prefix =~ s/\.(r|)wps//;
535 #print $wps_prefix . "\n";
537 elsif($l =~ /^RWPS: *(.*)/i) {
540 elsif($l =~ /^RWPS\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
543 elsif($l =~ /^SBS: *(.*)/i) {
544 $sbs = $sbs_prefix = $1;
545 $sbs_prefix =~ s/\.(r|)sbs//;
547 elsif($l =~ /^SBS\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
548 $sbs = $sbs_prefix = $1;
549 $sbs_prefix =~ s/\.(r|)sbs//;
551 elsif($l =~ /^RSBS: *(.*)/i) {
554 elsif($l =~ /^RSBS\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
557 elsif($l =~ /^Author: *(.*)/i) {
560 elsif($l =~ /^Width: *(.*)/i) {
563 elsif($l =~ /^Width\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
566 elsif($l =~ /^Height: *(.*)/i) {
569 elsif($l =~ /^Height\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
572 elsif($l =~ /^Font: *(.*)/i) {
575 elsif($l =~ /^Font\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
578 elsif($l =~ /^Remote Font\.${remote_width}x${remote_height}x$remote_depth: *(.*)/i) {
581 elsif($l =~ /^Remote Font: *(.*)/i) {
584 elsif($l =~ /^Foreground Color: *(.*)/i) {
587 elsif($l =~ /^Background Color: *(.*)/i) {
590 elsif($l =~ /^Statusbar: *(.*)/i) {
593 elsif($l =~ /^Statusbar\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
596 elsif($l =~ /^Backdrop: *(.*)/i) {
599 elsif($l =~ /^Backdrop\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
602 elsif($l =~ /^line selector start color: *(.*)/i) {
603 $lineselectstart = $1;
605 elsif($l =~ /^line selector end color: *(.*)/i) {
608 elsif($l =~ /^selector type: *(.*)/i) {
611 elsif($l =~ /^selector type\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
614 elsif($l =~ /^iconset: *(.*)/i) {
617 elsif($l =~ /^iconset\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
620 elsif($l =~ /^viewers iconset: *(.*)/i) {
623 elsif($l =~ /^viewers iconset\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
626 elsif($l =~ /^line selector text color: *(.*)/i) {
627 $lineselecttextcolor = $1;
629 elsif($l =~ /^filetype colours: *(.*)/i) {
632 elsif($l =~ /^ui viewport: *(.*)/i) {
635 elsif($l =~ /^ui viewport\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
638 elsif($l =~ /^remote ui viewport: *(.*)/i) {
639 $remotelistviewport = $1;
641 elsif($l =~ /^remote ui viewport\.${main_width}x${main_height}x$main_depth: *(.*)/i) {
642 $remotelistviewport = $1;
645 #print "Unknown line: $l!\n";