3 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
12 use Getopt
::Long
qw(:config pass_through); # pass_through so not confused by -DTYPE_STUFF
18 my $tempdir=".rockbox";
24 GetOptions
( 'r|root=s' => \
$ROOT,
25 'm|modelname=s' => \
$modelname,
26 'v|verbose' => \
$verbose,
27 'rbdir=s' => \
$rbdir, # If we want to put in a different directory
28 'tempdir=s' => \
$tempdir, # override .rockbox temporary dir
31 ($wpslist, $target) = @ARGV;
33 my $firmdir="$ROOT/firmware";
36 # These parameters are filled in as we parse wpslist
69 my $lineselecttextcolor;
72 my $remotelistviewport;
75 my ($main_height, $main_width, $main_depth);
76 my ($remote_height, $remote_width, $remote_depth);
81 print "Usage: wpsbuilds.pl <WPSLIST> <target>\n",
82 "Run this script in the root of the target build, and it will put all the\n",
83 "stuff in $tempdir/wps/\n and build the cfg according to $rbdir";
91 open(GCC
, ">gcctemp");
93 # Get the remote LCD screen size
96 #ifdef HAVE_REMOTE_LCD
97 Height: LCD_REMOTE_HEIGHT
98 Width: LCD_REMOTE_WIDTH
99 Depth: LCD_REMOTE_DEPTH
115 my $c="cat gcctemp | gcc $cppdef -I. -I$firmdir/export -E -P -";
119 open(GETSIZE
, "$c|");
121 my ($height, $width, $depth);
123 if($_ =~ /^Height: (\d*)/) {
126 elsif($_ =~ /^Width: (\d*)/) {
129 elsif($_ =~ /^Depth: (\d*)/) {
132 if($height && $width && $depth) {
139 return ($height, $width, $depth);
144 mkdir "$tempdir/wps", 0777;
145 mkdir "$tempdir/themes", 0777;
146 mkdir "$tempdir/icons", 0777;
148 if( -d
"$tempdir/wps/$theme") {
149 #print STDERR "wpsbuild warning: directory wps/$theme already exists!\n";
153 mkdir "$tempdir/wps/$theme", 0777;
161 $in =~ s/(\.[0-9]*x[0-9]*x[0-9]*)//;
167 #copy the backdrop file into the build dir
168 if ($backdrop ne '') {
169 my $dst = normalize
($backdrop);
170 system("cp $ROOT/$backdrop $tempdir/$dst");
176 #copy the font specified by the theme
179 $o =~ s/\.fnt/\.bdf/;
180 mkdir "$tempdir/fonts";
181 system("$ROOT/tools/convbdf -f -o \"$tempdir/fonts/$_[0]\" \"$ROOT/fonts/$o\" ");
187 #copy the icon specified by the theme
189 my $tempicon = $tempdir . "/" . $i;
190 $tempicon =~ /\/.*icons\
/(.*)/i;
191 system("cp $ROOT/icons/$1 $tempicon");
209 # we assume that we copy the WPS files from the same dir the WPSLIST
212 my %skinfiles = ("wps", $wps,
221 if($wpslist =~ /(.*)\/WPSLIST
/) {
224 # copy fully-fledged wps, sbs, etc. including graphics
225 foreach my $ext (keys %skinfiles) {
226 next unless ($skinfiles{$ext});
227 $file = $skinfiles{$ext};
228 system("cp $dir/$file $tempdir/wps/$theme.$ext");
229 open(SKIN
, "$dir/$file");
231 $filelist[$#filelist + 1] = $1 if (/[\(,]([^,]*?.bmp)[\),]/);
236 if ($#filelist >= 0) {
237 if (-e
"$dir/$theme") {
238 foreach $file (uniq
(@filelist)) {
239 system("cp $dir/$theme/$file $tempdir/wps/$theme/");
243 print STDERR
"beep, no dir to copy WPS from!\n";
247 print STDERR
"No source directory!\n";
252 my $cfg = $theme . ".cfg";
257 \# $cfg generated by wpsbuild.pl
258 \# $wps is made by $author
263 my %skinfiles = ("wps" => $wps,
269 for my $skin (keys %skinfiles) {
270 my $val = $skinfiles{$skin};
271 if (!defined($val)) {
272 # dont put value if not defined (e.g. rwps when there's no remote)
274 } elsif ($val eq '') {
275 # empty resets to built-in
276 push @out, "$skin: -\n";
278 # file name is always <theme>.{wps,rwps,...} (see copywps())
279 push @out, "$skin: $rbdir/wps/$theme.$skin\n";
283 push @out, "selector type: $selecttype\n" if (defined($selecttype));
284 push @out, "backdrop: $backdrop\n" if (defined($backdrop));
285 push @out, "filetype colours: $filetylecolor\n" if (defined($filetylecolor));
287 if ($main_depth > 2) {
288 push @out, "foreground color: $fgcolor\n" if($fgcolor);
289 push @out, "background color: $bgcolor\n" if($bgcolor);
290 push @out, "line selector start color: $lineselectstart\n" if($lineselectstart);
291 push @out, "line selector end color: $lineselectend\n" if($lineselectend);;
292 push @out, "line selector text color: $lineselecttextcolor\n" if($lineselecttextcolor);
295 push @out, "font: $font\n" if (defined($font));
296 push @out, "statusbar: $statusbar\n" if (defined($statusbar));
297 push @out, "iconset: $iconset\n" if (defined($iconset));
298 push @out, "viewers iconset: $viewericon\n" if (defined($viewericon));
299 push @out, "show icons: $showicons\n" if (defined($viewericon) && defined($showicons));
300 push @out, "ui viewport: $listviewport\n" if (defined($listviewport));
303 push @out, "remote font: $remotefont\n" if (defined($remotefont));
304 push @out, "remote statusbar: $remotestatusbar\n" if (defined($remotestatusbar));
305 push @out, "remote iconset: $remoteiconset\n" if (defined($remoteiconset));
306 push @out, "remote viewers iconset: $remoteviewericon\n" if (defined($remoteviewericon));
307 push @out, "remote ui viewport: $remotelistviewport\n" if (defined($remotelistviewport));
310 if(-f
"$tempdir/wps/$cfg") {
311 print STDERR
"wpsbuild warning: wps/$cfg already exists!\n";
314 open(CFG
, ">$tempdir/themes/$cfg");
320 # Get the LCD sizes first
321 ($main_height, $main_width, $main_depth) = getlcdsizes
();
322 ($remote_height, $remote_width, $remote_depth) = getlcdsizes
(1);
324 #print "LCD: ${main_width}x${main_height}x${main_depth}\n";
325 $has_remote = 1 if ($remote_height && $remote_width && $remote_depth);
328 # check if line matches the setting string or if it contains a regex
329 # that contains the targets resolution
331 my ($line, $string, $remote) = @_;
332 if ($line =~ /^${string}: *(.*)/i) {
335 elsif($line =~ /^${string}.(.*): *(.*)/i) {
336 # $1 is a resolution regex, $2 the filename incl. resolution
338 my $size_str = "${main_width}x${main_height}x${main_depth}";
340 $size_str = "${remote_width}x${remote_height}x${remote_depth}";
342 if ($size_str =~ /$1$/) {
349 # check if <theme>.<model>.<ext> exists. If not, check if <theme>.<ext> exists
352 my $req_skin = $theme . "." . $modelname . ".$ext";
353 if (-e
"$wpsdir/$req_skin") {
356 $req_skin = $theme . ".$ext";
357 if (-e
"$wpsdir/$req_skin") {
365 # Infer WPS (etc.) filename from the the if it wasnt given
366 $wpslist =~ /(.*)WPSLIST/;
369 open(WPS
, "<$wpslist");
380 # prefix $rbdir with / if needed (needed for the theme.cfg)
381 unless ($rbdir =~ m/^\/.*/) {
382 $rbdir = "/" . $rbdir;
385 if($l =~ /^ *<theme>/i) {
386 # undef is a unary operator (!)
407 undef $remotestatusbar;
410 undef $lineselectstart;
411 undef $lineselectend;
414 undef $remoteiconset;
417 undef $remoteviewericon;
418 undef $lineselecttextcolor;
419 undef $filetylecolor;
421 undef $remotelistviewport;
423 elsif($l =~ /^Name: *(.*)/i) {
426 elsif($l =~ /^Authors: *(.*)/i) {
429 elsif ($l =~ /^WPS: *(yes|no)/i) {
432 elsif ($l =~ /^RWPS: *(yes|no)/i) {
435 elsif ($l =~ /^SBS: *(yes|no)/i) {
438 elsif ($l =~ /^RSBS: *(yes|no)/i) {
441 elsif ($l =~ /^FMS: *(yes|no)/i) {
444 elsif ($l =~ /^RFMS: *(yes|no)/i) {
447 elsif($l =~ /^ *<main>/i) {
448 # parse main unit settings
451 if ($l =~ /^ *<\/main
>/i
) {
454 elsif($_ = check_res
($l, "wps")) {
457 elsif($_ = check_res
($l, "sbs")) {
460 elsif($_ = check_res
($l, "fms")) {
463 elsif($_ = check_res
($l, "Font")) {
466 elsif($_ = check_res
($l, "Statusbar")) {
469 elsif($_ = check_res
($l, "Backdrop")) {
472 elsif($l =~ /^Foreground Color: *(.*)/i) {
475 elsif($l =~ /^Background Color: *(.*)/i) {
478 elsif($l =~ /^line selector start color: *(.*)/i) {
479 $lineselectstart = $1;
481 elsif($l =~ /^line selector end color: *(.*)/i) {
484 elsif($_ = check_res
($l, "selector type")) {
487 elsif($_ = check_res
($l, "iconset")) {
490 elsif($_ = check_res
($l, "viewers iconset")) {
493 elsif($l =~ /^show icons: *(.*)/i) {
496 elsif($l =~ /^line selector text color: *(.*)/i) {
497 $lineselecttextcolor = $1;
499 elsif($l =~ /^filetype colours: *(.*)/i) {
502 elsif($_ = check_res
($l, "ui viewport")) {
507 elsif($l =~ /^ *<remote>/i) {
509 # parse remote settings
511 if ($l =~ /^ *<\/remote
>/i
) {
514 elsif(!$has_remote) {
515 next; # dont parse <remote> section
517 elsif($_ = check_res
($l, "rwps", 1)) {
520 elsif($_ = check_res
($l, "rsbs", 1)) {
523 elsif($_ = check_res
($l, "rfms", 1)) {
526 elsif($_ = check_res
($l, "Font", 1)) {
529 elsif($_ = check_res
($l, "iconset", 1)) {
532 elsif($_ = check_res
($l, "viewers iconset", 1)) {
533 $remoteviewericon = $_;
535 elsif($_ = check_res
($l, "statusbar", 1)) {
536 $remotestatusbar = $_;
538 elsif($_ = check_res
($l, "ui viewport", 1)) {
539 $remotelistviewport = $_;
543 elsif($l =~ /^ *<\/theme
>/i
) {
544 # for each wps,sbs,fms (+ remote variants) check if <theme>[.<model>].wps
545 # exists if no filename was specified in WPSLIST
548 if ($has_wps eq "yes" && !$wps) {
549 $wps = check_skinfile
("wps");
550 } elsif ($has_wps eq "no") {
554 if ($has_sbs eq "yes" && !$sbs) {
555 $sbs = check_skinfile
("sbs");
556 } elsif ($has_sbs eq "no") {
560 if ($has_fms eq "yes" && !$fms) {
561 $fms = check_skinfile
("fms");
562 } elsif ($has_fms eq "no") {
566 # now check for remote skin files (use main screen's extension)
568 if ($has_rwps eq "yes" && !$rwps) {
569 $rwps = check_skinfile
("wps");
570 } elsif ($has_rwps eq "no") {
574 if ($has_rsbs eq "yes" && !$rsbs) {
575 $rsbs = check_skinfile
("sbs");
576 } elsif ($has_rsbs eq "no") {
580 if ($has_rfms eq "yes" && !$rfms) {
581 $rfms = check_skinfile
("fms");
582 } elsif ($has_rfms eq "no") {
586 #print "LCD: $wps wants $width x $height\n";
589 # The target model has an LCD that is suitable for this
592 #print "Size requirement is fine!\n";
593 mkdirs
() if (-e
"$wpsdir/$theme");
594 # Do the copying before building the .cfg - buildcfg()
595 # mangles some filenames
596 if (defined($backdrop) && $backdrop ne "-") {
598 $backdrop = "$rbdir/" . normalize
($backdrop);
600 foreach my $i ($iconset, $viewericon, $remoteiconset, $remoteviewericon) {
601 if (defined($i) && $i ne "-") {
606 foreach my $i ($font, $remotefont) {
607 if (defined($i) && $i ne "-") {
609 $i = "$rbdir/fonts/$i";
616 #print "Unknown line: $l!\n";