3 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
13 use File
::Copy
; # For move() and copy()
14 use File
::Find
; # For find()
15 use File
::Path
qw(mkpath rmtree); # For rmtree()
18 use Getopt
::Long
qw(:config pass_through); # pass_through so not confused by -DTYPE_STUFF
30 my $target_id; # passed in, not currently used
31 my $rbdir; # can be non-.rockbox for special builds
37 mkpath
($dir, $verbose, 0777);
42 my ($_src, $dest, $opts) = @_;
48 foreach my $src (glob($_src)) {
49 unless ( -d
$src || !(-e
$src)) {
50 system("install $opts \"$src\" \"$dest\"");
51 print "install $opts \"$src\" -> \"$dest\"\n" if $verbose;
58 my ($pattern, $destination) = @_;
59 print "glob_copy: $pattern -> $destination\n" if $verbose;
60 foreach my $path (glob($pattern)) {
61 copy
($path, $destination);
66 my ($pattern, $destination) = @_;
67 print "glob_move: $pattern -> $destination\n" if $verbose;
68 foreach my $path (glob($pattern)) {
69 move
($path, $destination);
75 print "glob_unlink: $pattern\n" if $verbose;
76 foreach my $path (glob($pattern)) {
82 my ($pattern, $destination) = @_;
83 print "find_copyfile: $pattern -> $destination\n" if $verbose;
86 my $source = getcwd
();
87 if ($path =~ $pattern && filesize
($path) > 0 && !($path =~ /$rbdir/)) {
89 print "link $path $destination\n" if $verbose;
90 symlink($source.'/'.$path, $destination.'/'.$path);
92 print "cp $path $destination\n" if $verbose;
93 copy
($path, $destination);
94 chmod(0755, $destination.'/'.$path);
100 sub find_installfile
{
101 my ($pattern, $destination) = @_;
102 print "find_installfile: $pattern -> $destination\n" if $verbose;
105 if ($path =~ $pattern) {
106 print "FIND_INSTALLFILE: $path\n";
107 glob_install
($path, $destination);
114 my ($src, $dest) = @_;
120 my @plugins = ( "games", "apps", "demos", "viewers" );
121 my @userstuff = ( "backdrops", "codepages", "docs", "fonts", "langs", "themes", "wps", "eqs", "icons" );
126 $libdir .= "/lib/rockbox";
127 $userdir .= "/share/rockbox";
129 # for non-app builds we expect the prefix to be the dir above .rockbox
130 $bindir .= "/$rbdir";
131 $libdir = $userdir = $bindir;
133 if ($dest =~ /\/dev\
/null/) {
134 die "ERROR: No PREFIX given\n"
137 if ((!$app) && -e
$bindir && -e
$src && (abs_path
($bindir) eq abs_path
($src))) {
142 unless ($exe eq "") {
143 unless (glob_mkdir
($bindir)) {
146 glob_install
($exe, $bindir, "-m 0775");
150 unless (glob_mkdir
("$libdir/codecs")) {
153 glob_install
("$src/codecs/*", "$libdir/codecs", "-m 0755");
156 unless (glob_mkdir
("$libdir/rocks")) {
159 foreach my $t (@plugins) {
160 unless (glob_mkdir
("$libdir/rocks/$t")) {
163 glob_install
("$src/rocks/$t/*", "$libdir/rocks/$t", "-m 0755");
167 unless (glob_mkdir
("$libdir/rocks/viewers/lua")) {
170 glob_install
("$src/rocks/viewers/lua/*", "$libdir/rocks/viewers/lua");
172 # all the rest directories
173 foreach my $t (@userstuff) {
174 unless (glob_mkdir
("$userdir/$t")) {
177 glob_install
("$src/$t/*", "$userdir/$t");
180 # wps/ subfolders and bitmaps
181 opendir(DIR
, $src . "/wps");
182 @files = readdir(DIR
);
185 foreach my $_dir (@files) {
186 my $dir = "wps/" . $_dir;
187 if ( -d
"$src/$dir" && $_dir !~ /\
.\
.?
/) {
188 unless (glob_mkdir
("$userdir/$dir")) {
191 glob_install
("$src/$dir/*", "$userdir/$dir");
195 # rest of the files, excluding the binary
197 @files = readdir(DIR
);
200 foreach my $file (grep (/[a-zA-Z]+\.(txt|config|ignnore)/,@files)) {
201 glob_install
("$src/$file", "$userdir/");
207 GetOptions
( 'r|root=s' => \
$ROOT,
208 'z|ziptool:s' => \
$ziptool,
209 'm|modelname=s' => \
$modelname, # The model name as used in ARCHOS in the root makefile
210 'i|id=s' => \
$target_id, # The target id name as used in TARGET_ID in the root makefile
211 'o|output:s' => \
$output,
212 'f|fonts=s' => \
$incfonts, # 0 - no fonts, 1 - fonts only 2 - fonts and package
213 'v|verbose' => \
$verbose,
214 'install=s' => \
$install, # install destination
215 'rbdir:s' => \
$rbdir, # If we want to put in a different directory
216 'l|link' => \
$mklinks, # If we want to create links instead of copying files
217 'a|app:s' => \
$app, # Is this an Application build?
220 # GetOptions() doesn't remove the params from @ARGV if their value was ""
221 # Thus we use the ":" for those for which we use a default value in case of ""
222 # and assign the default value afterwards
223 if ($ziptool eq '') {
224 $ziptool = "zip -r9";
227 $output = "rockbox.zip"
233 # Now @ARGV shuold be free of any left-overs GetOptions left
234 ($target, $exe) = @ARGV;
236 my $firmdir="$ROOT/firmware";
237 my $appsdir="$ROOT/apps";
238 my $viewer_bmpdir="$ROOT/apps/plugins/bitmaps/viewer_defaults";
240 my $cppdef = $target;
243 open(GCC
, ">gcctemp");
244 # Get the LCD screen depth and graphical status
247 #ifdef HAVE_LCD_BITMAP
251 LCD Height: LCD_HEIGHT
252 Icon Width: CONFIG_DEFAULT_ICON_WIDTH
253 Icon Height: CONFIG_DEFAULT_ICON_HEIGHT
256 #ifdef HAVE_REMOTE_LCD
257 Remote Depth: LCD_REMOTE_DEPTH
258 Remote Icon Width: CONFIG_REMOTE_DEFAULT_ICON_WIDTH
259 Remote Icon Height: CONFIG_REMOTE_DEFAULT_ICON_HEIGHT
263 #ifdef HAVE_RECORDING
270 my $c="cat gcctemp | gcc $cppdef -I. -I$firmdir/export -E -P -";
272 # print STDERR "CMD $c\n";
276 my ($bitmap, $width, $height, $depth, $swcodec, $icon_h, $icon_w);
277 my ($remote_depth, $remote_icon_h, $remote_icon_w);
281 # print STDERR "DATA: $_";
282 if($_ =~ /^Bitmap: (.*)/) {
285 elsif($_ =~ /^Depth: (\d*)/) {
288 elsif($_ =~ /^LCD Width: (\d*)/) {
291 elsif($_ =~ /^LCD Height: (\d*)/) {
294 elsif($_ =~ /^Icon Width: (\d*)/) {
297 elsif($_ =~ /^Icon Height: (\d*)/) {
300 elsif($_ =~ /^Codec: (\d*)/) {
301 # SWCODEC is 1, the others are HWCODEC
302 $swcodec = ($1 == 1);
304 elsif($_ =~ /^Remote Depth: (\d*)/) {
307 elsif($_ =~ /^Remote Icon Width: (\d*)/) {
310 elsif($_ =~ /^Remote Icon Height: (\d*)/) {
313 if($_ =~ /^Recording: (.*)/) {
320 return ($bitmap, $depth, $width, $height, $icon_w, $icon_h, $recording,
321 $swcodec, $remote_depth, $remote_icon_w, $remote_icon_h);
326 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
327 $atime,$mtime,$ctime,$blksize,$blocks)
332 sub create_failsafefiles
{
333 my ($dir, $remote_depth) = @_;
334 my $text = "# Dummy file to allow Rockbox to reset to the default skin config.
335 # Do not edit this file. It's never actually loaded by Rockbox.";
336 open (FOO
, ">$dir/wps/rockbox_failsafe.wps");
339 open (FOO
, ">$dir/wps/rockbox_failsafe.sbs");
342 open (FOO
, ">$dir/wps/rockbox_failsafe.fms");
346 open (FOO
, ">$dir/wps/rockbox_failsafe.rwps");
349 open (FOO
, ">$dir/wps/rockbox_failsafe.rsbs");
352 open (FOO
, ">$dir/wps/rockbox_failsafe.rfms");
356 open (FOO
, ">$dir/themes/rockbox_failsafe.cfg");
358 # This config has been autogenerated to reload the failsafe setup
359 wps: $dir/wps/rockbox_failsafe.wps
360 sbs: $dir/wps/rockbox_failsafe.sbs
361 fms: $dir/wps/rockbox_failsafe.fms
366 rwps: $dir/wps/rockbox_failsafe.rwps
367 rsbs: $dir/wps/rockbox_failsafe.rsbs
368 rfms: $dir/wps/rockbox_failsafe.rfms
374 font: 08-Schumacher-Clean.fnt
375 foreground color: 000000
376 background color: B6C6E5
377 selector type: bar (inverse)
384 my ($image, $fonts)=@_;
385 my $libdir = $install;
386 my $temp_dir = ".rockbox";
388 print "buildzip: image=$image fonts=$fonts\n" if $verbose;
390 my ($bitmap, $depth, $width, $height, $icon_w, $icon_h, $recording,
391 $swcodec, $remote_depth, $remote_icon_w, $remote_icon_h) =
394 # print "Bitmap: $bitmap\nDepth: $depth\nSwcodec: $swcodec\n";
399 glob_mkdir
($temp_dir);
402 # always disable fonts on non-bitmap targets
406 glob_mkdir
("$temp_dir/fonts");
407 chdir "$temp_dir/fonts";
408 my $cmd = "$ROOT/tools/convbdf -f $ROOT/fonts/*bdf >/dev/null 2>&1";
409 print($cmd."\n") if $verbose;
414 # fonts-only package, return
419 # create the file so the database does not try indexing a folder
420 open(IGNORE
, ">$temp_dir/database.ignore") || die "can't open database.ignore";
423 glob_mkdir
("$temp_dir/langs");
424 glob_mkdir
("$temp_dir/rocks");
425 glob_mkdir
("$temp_dir/rocks/games");
426 glob_mkdir
("$temp_dir/rocks/apps");
427 glob_mkdir
("$temp_dir/rocks/demos");
428 glob_mkdir
("$temp_dir/rocks/viewers");
431 glob_mkdir
("$temp_dir/recpresets");
435 glob_mkdir
("$temp_dir/eqs");
437 glob_copy
("$ROOT/apps/eqs/*.cfg", "$temp_dir/eqs/"); # equalizer presets
440 glob_mkdir
("$temp_dir/wps");
441 glob_mkdir
("$temp_dir/themes");
443 open(THEME
, ">$temp_dir/themes/rockbox_default_icons.cfg");
445 # this config file was auto-generated to make it
446 # easy to reset the icons back to default
448 # taken from apps/gui/icon.c
449 viewers iconset: /$rbdir/icons/viewers.bmp
451 # taken from apps/gui/icon.c
452 remote viewers iconset: /$rbdir/icons/remote_viewers.bmp
459 glob_mkdir
("$temp_dir/codepages");
462 system("$ROOT/tools/codepages");
465 system("$ROOT/tools/codepages -m");
468 glob_move
('*.cp', "$temp_dir/codepages/");
470 if($bitmap && $depth > 1) {
471 glob_mkdir
("$temp_dir/backdrops");
474 glob_mkdir
("$temp_dir/codecs");
476 find
(find_copyfile
(qr/.*\.codec/, abs_path
("$temp_dir/codecs/")), 'apps/codecs');
478 # remove directory again if no codec was copied
479 rmdir("$temp_dir/codecs");
481 find
(find_copyfile
(qr/\.(rock|ovl|lua)/, abs_path
("$temp_dir/rocks/")), 'apps/plugins');
483 # exclude entries for the image file types not supported by the imageviewer for the target.
484 my $viewers = "$ROOT/apps/plugins/viewers.config";
485 my $c="cat $viewers | gcc $cppdef -I. -I$firmdir/export -E -P -include config.h -";
487 open VIEWERS
, "$c|" or die "can't open viewers.config";
488 my @viewers = <VIEWERS
>;
491 open VIEWERS
, ">$temp_dir/viewers.config" or
492 die "can't create $temp_dir/viewers.config";
494 foreach my $line (@viewers) {
495 if ($line =~ /([^,]*),([^,]*),/) {
496 my ($ext, $plugin)=($1, $2);
497 my $r = "${plugin}.rock";
503 # strip off the last slash and file name part
504 $dir =~ s/(.*)\/(.*)/$1/;
505 # store the file name part
508 # get .ovl name (file part only)
510 $oname =~ s/\.rock$/.ovl/;
512 # print STDERR "$ext $plugin $dir $name $r\n";
514 if(-e
"$temp_dir/rocks/$name") {
515 if($dir ne "rocks") {
516 # target is not 'rocks' but the plugins are always in that
518 move
("$temp_dir/rocks/$name", "$temp_dir/rocks/$r");
522 elsif(-e
"$temp_dir/rocks/$r") {
523 # in case the same plugin works for multiple extensions, it
524 # was already moved to the viewers dir
528 if(-e
"$temp_dir/rocks/$oname") {
529 # if there's an "overlay" file for the .rock, move that as
531 move
("$temp_dir/rocks/$oname", "$temp_dir/rocks/$dir");
537 open CATEGORIES
, "$ROOT/apps/plugins/CATEGORIES" or
538 die "can't open CATEGORIES";
539 my @rock_targetdirs = <CATEGORIES
>;
541 foreach my $line (@rock_targetdirs) {
542 if ($line =~ /([^,]*),(.*)/) {
543 my ($plugin, $dir)=($1, $2);
544 move
("$temp_dir/rocks/${plugin}.rock", "$temp_dir/rocks/$dir/${plugin}.rock");
545 if(-e
"$temp_dir/rocks/${plugin}.ovl") {
546 # if there's an "overlay" file for the .rock, move that as
548 move
("$temp_dir/rocks/${plugin}.ovl", "$temp_dir/rocks/$dir");
550 if(-e
"$temp_dir/rocks/${plugin}.lua") {
551 # if this is a lua script, move it to the appropriate dir
552 move
("$temp_dir/rocks/${plugin}.lua", "$temp_dir/rocks/$dir/");
557 glob_unlink
("$temp_dir/rocks/*.lua"); # Clean up unwanted *.lua files (e.g. actions.lua, buttons.lua)
560 glob_mkdir
("$temp_dir/icons");
561 copy
("$viewer_bmpdir/viewers.${icon_w}x${icon_h}x$depth.bmp", "$temp_dir/icons/viewers.bmp");
563 copy
("$viewer_bmpdir/remote_viewers.${remote_icon_w}x${remote_icon_h}x$remote_depth.bmp", "$temp_dir/icons/remote_viewers.bmp");
567 copy
("$ROOT/apps/tagnavi.config", "$temp_dir/");
568 copy
("$ROOT/apps/plugins/disktidy.config", "$temp_dir/rocks/apps/");
571 copy
("$ROOT/apps/plugins/sokoban.levels", "$temp_dir/rocks/games/sokoban.levels"); # sokoban levels
572 copy
("$ROOT/apps/plugins/snake2.levels", "$temp_dir/rocks/games/snake2.levels"); # snake2 levels
573 copy
("$ROOT/apps/plugins/rockbox-fonts.config", "$temp_dir/rocks/viewers/");
576 if(-e
"$temp_dir/rocks/demos/pictureflow.rock") {
577 copy
("$ROOT/apps/plugins/bitmaps/native/pictureflow_emptyslide.100x100x16.bmp",
578 "$temp_dir/rocks/demos/pictureflow_emptyslide.bmp");
581 $pf_logo = "pictureflow_logo.100x18x16.bmp";
583 $pf_logo = "pictureflow_logo.193x34x16.bmp";
585 copy
("$ROOT/apps/plugins/bitmaps/native/$pf_logo",
586 "$temp_dir/rocks/demos/pictureflow_splash.bmp");
589 create_failsafefiles
($temp_dir, $remote_depth);
592 # image is blank when this is a simulator
593 if( filesize
("rockbox.ucl") > 1000 ) {
594 copy
("rockbox.ucl", "$temp_dir/rockbox.ucl"); # UCL for flashing
596 if( filesize
("rombox.ucl") > 1000) {
597 copy
("rombox.ucl", "$temp_dir/rombox.ucl"); # UCL for flashing
600 # Check for rombox.target
601 if ($image=~/(.*)\.(\w+)$/)
603 my $romfile = "rombox.$2";
604 if (filesize
($romfile) > 1000)
606 copy
($romfile, "$temp_dir/$romfile");
611 glob_mkdir
("$temp_dir/docs");
616 copy
("$ROOT/docs/$_", "$temp_dir/docs/$_.txt");
619 copy
("$ROOT/docs/profontdoc.txt", "$temp_dir/docs/profontdoc.txt");
621 for(("sample.colours",
624 copy
("$ROOT/docs/$_", "$temp_dir/docs/$_");
627 # Now do the WPS dance
629 my $wps_build_cmd="perl $ROOT/wps/wpsbuild.pl ";
630 $wps_build_cmd=$wps_build_cmd."-v " if $verbose;
631 $wps_build_cmd=$wps_build_cmd." --tempdir=$temp_dir --rbdir=$rbdir -r $ROOT -m $modelname $ROOT/wps/WPSLIST $target";
632 print "wpsbuild: $wps_build_cmd\n" if $verbose;
633 system("$wps_build_cmd");
634 print "wps_build_cmd: done\n" if $verbose;
637 print STDERR
"No wps module present, can't do the WPS magic!\n";
640 # until buildwps.pl is fixed, manually copy the classic_statusbar theme across
641 mkdir "$temp_dir/wps/classic_statusbar", 0777;
642 glob_copy
("$ROOT/wps/classic_statusbar/*.bmp", "$temp_dir/wps/classic_statusbar");
645 copy
("$ROOT/wps/classic_statusbar.sbs", "$temp_dir/wps");
646 } elsif ($depth > 1) {
647 copy
("$ROOT/wps/classic_statusbar.grey.sbs", "$temp_dir/wps/classic_statusbar.sbs");
649 copy
("$ROOT/wps/classic_statusbar.mono.sbs", "$temp_dir/wps/classic_statusbar.sbs");
652 copy
("$ROOT/wps/classic_statusbar.112x64x1.sbs", "$temp_dir/wps/classic_statusbar.sbs");
654 if ($remote_depth != $depth) {
655 copy
("$ROOT/wps/classic_statusbar.mono.sbs", "$temp_dir/wps/classic_statusbar.rsbs");
657 copy
("$temp_dir/wps/classic_statusbar.sbs", "$temp_dir/wps/classic_statusbar.rsbs");
659 copy
("$temp_dir/wps/rockbox_none.sbs", "$temp_dir/wps/rockbox_none.rsbs");
662 copy
("rockbox-info.txt", "$temp_dir/rockbox-info.txt");
664 # copy the already built lng files
665 glob_copy
('apps/lang/*lng', "$temp_dir/langs/");
667 # copy the .lua files
668 glob_mkdir
("$temp_dir/rocks/viewers/lua/");
669 glob_copy
('apps/plugins/lua/*.lua', "$temp_dir/rocks/viewers/lua/");
672 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
678 #$date=sprintf("%04d%02d%02d", $year,$mon, $mday);
679 #$shortdate=sprintf("%02d%02d%02d", $year%100,$mon, $mday);
681 # made once for all targets
683 my ($target, $fonts)=@_;
685 # Strip the leading / from $rbdir unless we are installing an application
686 # build - the layout is different (no .rockbox, but bin/lib/share)
687 unless ($app && $install) {
688 $rbdir = substr($rbdir, 1);
691 # build a full install .rockbox ($rbdir) directory
692 buildzip
($target, $fonts);
697 # Don't include image file in fonts-only package
700 if($target && ($target !~ /(mod|ajz|wma)\z/i)) {
701 # On some targets, the image goes into .rockbox.
702 copy
("$target", ".rockbox/$target");
709 symlink("$cwd/.rockbox", "$install/.rockbox");
710 print "link .rockbox $install\n" if $verbose;
712 make_install
(".rockbox", $install) or die "MKDIRFAILED\n";
714 print "rm .rockbox\n" if $verbose;
718 unless (".rockbox" eq $rbdir) {
721 move
(".rockbox", $rbdir);
722 print "mv .rockbox $rbdir\n" if $verbose;
724 system("$ziptool $output $rbdir $target >/dev/null");
725 print "$ziptool $output $rbdir $target >/dev/null\n" if $verbose;
727 print "rm $rbdir\n" if $verbose;
732 # not specified, guess!
733 if($target =~ /(recorder|ondio)/i) {
736 elsif($target =~ /iriver/i) {
737 $exe = "rockbox.iriver";
743 elsif(($exe =~ /rockboxui/)) {
744 # simulator, exclude the exe file
747 elsif($exe eq "librockbox.so") {
748 # android, exclude the binary
752 runone
($exe, $incfonts);