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()
17 use Getopt
::Long
qw(:config pass_through); # pass_through so not confused by -DTYPE_STUFF
21 my $ziptool="zip -r9";
22 my $output="rockbox.zip";
29 my $target_id; # passed in, not currently used
30 my $rbdir=".rockbox"; # can be changed for special builds
35 mkpath
($dir, $verbose, 0777);
40 my ($_src, $dest, $opts) = @_;
46 foreach my $src (glob($_src)) {
47 unless ( -d
$src || !(-e
$src)) {
48 system("install $opts \"$src\" \"$dest\"");
49 print "install $opts \"$src\" -> \"$dest\"\n" if $verbose;
56 my ($pattern, $destination) = @_;
57 print "glob_copy: $pattern -> $destination\n" if $verbose;
58 foreach my $path (glob($pattern)) {
59 copy
($path, $destination);
64 my ($pattern, $destination) = @_;
65 print "glob_move: $pattern -> $destination\n" if $verbose;
66 foreach my $path (glob($pattern)) {
67 move
($path, $destination);
73 print "glob_unlink: $pattern\n" if $verbose;
74 foreach my $path (glob($pattern)) {
80 my ($pattern, $destination) = @_;
81 print "find_copyfile: $pattern -> $destination\n" if $verbose;
84 if ($path =~ $pattern && filesize
($path) > 0 && !($path =~ /$rbdir/)) {
85 copy
($path, $destination);
86 print "cp $path $destination\n" if $verbose;
87 chmod(0755, $destination.'/'.$path);
92 sub find_installfile
{
93 my ($pattern, $destination) = @_;
94 print "find_installfile: $pattern -> $destination\n" if $verbose;
97 if ($path =~ $pattern) {
98 print "FIND_INSTALLFILE: $path\n";
99 glob_install
($path, $destination);
106 my ($src, $dest) = @_;
112 my @plugins = ( "games", "apps", "demos", "viewers" );
113 my @userstuff = ( "backdrops", "codepages", "docs", "fonts", "langs", "themes", "wps", "eqs", "icons" );
118 $libdir .= "/lib/rockbox";
119 $userdir .= "/share/rockbox";
121 # for non-app builds we expect the prefix to be the dir above .rockbox
122 $bindir .= "/.rockbox";
123 $libdir = $userdir = $bindir;
125 if ($dest =~ /\/dev\
/null/) {
126 die "ERROR: No PREFIX given\n"
129 if ((!$app) && $src && (abs_path
($dest) eq abs_path
($src))) {
134 unless ($exe eq "") {
135 unless (glob_mkdir
($bindir)) {
138 glob_install
($exe, $bindir, "-m 0775");
142 unless (glob_mkdir
("$libdir/codecs")) {
145 glob_install
("$src/codecs/*", "$libdir/codecs");
148 unless (glob_mkdir
("$libdir/rocks")) {
151 foreach my $t (@plugins) {
152 unless (glob_mkdir
("$libdir/rocks/$t")) {
155 glob_install
("$src/rocks/$t/*", "$libdir/rocks/$t");
159 unless (glob_mkdir
("$libdir/rocks/viewers/lua")) {
162 glob_install
("$src/rocks/viewers/lua/*", "$libdir/rocks/viewers/lua");
164 # all the rest directories
165 foreach my $t (@userstuff) {
166 unless (glob_mkdir
("$userdir/$t")) {
169 glob_install
("$src/$t/*", "$userdir/$t");
172 # wps/ subfolders and bitmaps
173 opendir(DIR
, $src . "/wps");
174 @files = readdir(DIR
);
177 foreach my $_dir (@files) {
178 my $dir = "wps/" . $_dir;
179 if ( -d
"$src/$dir" && $_dir !~ /\
.\
.?
/) {
180 unless (glob_mkdir
("$userdir/$dir")) {
183 glob_install
("$src/$dir/*", "$userdir/$dir");
187 # rest of the files, excluding the binary
189 @files = readdir(DIR
);
192 foreach my $file (grep (/[a-zA-Z]+\.(txt|config|ignnore)/,@files)) {
193 glob_install
("$src/$file", "$userdir/");
199 GetOptions
( 'r|root=s' => \
$ROOT,
200 'z|ziptool=s' => \
$ziptool,
201 'm|modelname=s' => \
$modelname, # The model name as used in ARCHOS in the root makefile
202 'i|id=s' => \
$target_id, # The target id name as used in TARGET_ID in the root makefile
203 'o|output=s' => \
$output,
204 'f|fonts=s' => \
$incfonts, # 0 - no fonts, 1 - fonts only 2 - fonts and package
205 'v|verbose' => \
$verbose,
206 'install=s' => \
$install, # install destination
207 'rbdir=s' => \
$rbdir, # If we want to put in a different directory
210 ($target, $exe) = @ARGV;
212 my $firmdir="$ROOT/firmware";
213 my $appsdir="$ROOT/apps";
214 my $viewer_bmpdir="$ROOT/apps/plugins/bitmaps/viewer_defaults";
216 my $cppdef = $target;
219 open(GCC
, ">gcctemp");
220 # Get the LCD screen depth and graphical status
223 #ifdef HAVE_LCD_BITMAP
227 LCD Height: LCD_HEIGHT
228 Icon Width: CONFIG_DEFAULT_ICON_WIDTH
229 Icon Height: CONFIG_DEFAULT_ICON_HEIGHT
232 #ifdef HAVE_REMOTE_LCD
233 Remote Depth: LCD_REMOTE_DEPTH
234 Remote Icon Width: CONFIG_REMOTE_DEFAULT_ICON_WIDTH
235 Remote Icon Height: CONFIG_REMOTE_DEFAULT_ICON_HEIGHT
239 #ifdef HAVE_RECORDING
246 my $c="cat gcctemp | gcc $cppdef -I. -I$firmdir/export -E -P -";
248 # print STDERR "CMD $c\n";
252 my ($bitmap, $width, $height, $depth, $swcodec, $icon_h, $icon_w);
253 my ($remote_depth, $remote_icon_h, $remote_icon_w);
257 # print STDERR "DATA: $_";
258 if($_ =~ /^Bitmap: (.*)/) {
261 elsif($_ =~ /^Depth: (\d*)/) {
264 elsif($_ =~ /^LCD Width: (\d*)/) {
267 elsif($_ =~ /^LCD Height: (\d*)/) {
270 elsif($_ =~ /^Icon Width: (\d*)/) {
273 elsif($_ =~ /^Icon Height: (\d*)/) {
276 elsif($_ =~ /^Codec: (\d*)/) {
277 # SWCODEC is 1, the others are HWCODEC
278 $swcodec = ($1 == 1);
280 elsif($_ =~ /^Remote Depth: (\d*)/) {
283 elsif($_ =~ /^Remote Icon Width: (\d*)/) {
286 elsif($_ =~ /^Remote Icon Height: (\d*)/) {
289 if($_ =~ /^Recording: (.*)/) {
296 return ($bitmap, $depth, $width, $height, $icon_w, $icon_h, $recording,
297 $swcodec, $remote_depth, $remote_icon_w, $remote_icon_h);
302 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
303 $atime,$mtime,$ctime,$blksize,$blocks)
309 my ($image, $fonts)=@_;
310 my $libdir = $install;
311 my $temp_dir = ".rockbox";
313 print "buildzip: image=$image fonts=$fonts\n" if $verbose;
315 my ($bitmap, $depth, $width, $height, $icon_w, $icon_h, $recording,
316 $swcodec, $remote_depth, $remote_icon_w, $remote_icon_h) =
319 # print "Bitmap: $bitmap\nDepth: $depth\nSwcodec: $swcodec\n";
324 glob_mkdir
($temp_dir);
327 # always disable fonts on non-bitmap targets
331 glob_mkdir
("$temp_dir/fonts");
332 chdir "$temp_dir/fonts";
333 my $cmd = "$ROOT/tools/convbdf -f $ROOT/fonts/*bdf >/dev/null 2>&1";
334 print($cmd."\n") if $verbose;
339 # fonts-only package, return
344 # create the file so the database does not try indexing a folder
345 open(IGNORE
, ">$temp_dir/database.ignore") || die "can't open database.ignore";
348 glob_mkdir
("$temp_dir/langs");
349 glob_mkdir
("$temp_dir/rocks");
350 glob_mkdir
("$temp_dir/rocks/games");
351 glob_mkdir
("$temp_dir/rocks/apps");
352 glob_mkdir
("$temp_dir/rocks/demos");
353 glob_mkdir
("$temp_dir/rocks/viewers");
356 glob_mkdir
("$temp_dir/recpresets");
360 glob_mkdir
("$temp_dir/eqs");
362 glob_copy
("$ROOT/apps/eqs/*.cfg", "$temp_dir/eqs/"); # equalizer presets
365 glob_mkdir
("$temp_dir/wps");
366 glob_mkdir
("$temp_dir/themes");
368 open(THEME
, ">$temp_dir/themes/rockbox_default_icons.cfg");
370 # this config file was auto-generated to make it
371 # easy to reset the icons back to default
373 # taken from apps/gui/icon.c
374 viewers iconset: /$rbdir/icons/viewers.bmp
376 # taken from apps/gui/icon.c
377 remote viewers iconset: /$rbdir/icons/remote_viewers.bmp
384 glob_mkdir
("$temp_dir/codepages");
387 system("$ROOT/tools/codepages");
390 system("$ROOT/tools/codepages -m");
393 glob_move
('*.cp', "$temp_dir/codepages/");
395 if($bitmap && $depth > 1) {
396 glob_mkdir
("$temp_dir/backdrops");
399 glob_mkdir
("$temp_dir/codecs");
401 find
(find_copyfile
(qr/.*\.codec/, abs_path
("$temp_dir/codecs/")), 'apps/codecs');
403 # remove directory again if no codec was copied
404 rmdir("$temp_dir/codecs");
406 find
(find_copyfile
(qr/\.(rock|ovl|lua)/, abs_path
("$temp_dir/rocks/")), 'apps/plugins');
408 open VIEWERS
, "$ROOT/apps/plugins/viewers.config" or
409 die "can't open viewers.config";
410 my @viewers = <VIEWERS
>;
413 open VIEWERS
, ">$temp_dir/viewers.config" or
414 die "can't create $temp_dir/viewers.config";
416 foreach my $line (@viewers) {
417 if ($line =~ /([^,]*),([^,]*),/) {
418 my ($ext, $plugin)=($1, $2);
419 my $r = "${plugin}.rock";
425 # strip off the last slash and file name part
426 $dir =~ s/(.*)\/(.*)/$1/;
427 # store the file name part
430 # get .ovl name (file part only)
432 $oname =~ s/\.rock$/.ovl/;
434 # print STDERR "$ext $plugin $dir $name $r\n";
436 if(-e
"$temp_dir/rocks/$name") {
437 if($dir ne "rocks") {
438 # target is not 'rocks' but the plugins are always in that
440 move
("$temp_dir/rocks/$name", "$temp_dir/rocks/$r");
444 elsif(-e
"$temp_dir/rocks/$r") {
445 # in case the same plugin works for multiple extensions, it
446 # was already moved to the viewers dir
450 if(-e
"$temp_dir/rocks/$oname") {
451 # if there's an "overlay" file for the .rock, move that as
453 move
("$temp_dir/rocks/$oname", "$temp_dir/rocks/$dir");
459 open CATEGORIES
, "$ROOT/apps/plugins/CATEGORIES" or
460 die "can't open CATEGORIES";
461 my @rock_targetdirs = <CATEGORIES
>;
463 foreach my $line (@rock_targetdirs) {
464 if ($line =~ /([^,]*),(.*)/) {
465 my ($plugin, $dir)=($1, $2);
466 move
("$temp_dir/rocks/${plugin}.rock", "$temp_dir/rocks/$dir/${plugin}.rock");
467 if(-e
"$temp_dir/rocks/${plugin}.ovl") {
468 # if there's an "overlay" file for the .rock, move that as
470 move
("$temp_dir/rocks/${plugin}.ovl", "$temp_dir/rocks/$dir");
472 if(-e
"$temp_dir/rocks/${plugin}.lua") {
473 # if this is a lua script, move it to the appropriate dir
474 move
("$temp_dir/rocks/${plugin}.lua", "$temp_dir/rocks/$dir/");
479 glob_unlink
("$temp_dir/rocks/*.lua"); # Clean up unwanted *.lua files (e.g. actions.lua, buttons.lua)
482 glob_mkdir
("$temp_dir/icons");
483 copy
("$viewer_bmpdir/viewers.${icon_w}x${icon_h}x$depth.bmp", "$temp_dir/icons/viewers.bmp");
485 copy
("$viewer_bmpdir/remote_viewers.${remote_icon_w}x${remote_icon_h}x$remote_depth.bmp", "$temp_dir/icons/remote_viewers.bmp");
489 copy
("$ROOT/apps/tagnavi.config", "$temp_dir/");
490 copy
("$ROOT/apps/plugins/disktidy.config", "$temp_dir/rocks/apps/");
493 copy
("$ROOT/apps/plugins/sokoban.levels", "$temp_dir/rocks/games/sokoban.levels"); # sokoban levels
494 copy
("$ROOT/apps/plugins/snake2.levels", "$temp_dir/rocks/games/snake2.levels"); # snake2 levels
495 copy
("$ROOT/apps/plugins/rockbox-fonts.config", "$temp_dir/rocks/viewers/");
498 if(-e
"$temp_dir/rocks/demos/pictureflow.rock") {
499 copy
("$ROOT/apps/plugins/bitmaps/native/pictureflow_emptyslide.100x100x16.bmp",
500 "$temp_dir/rocks/demos/pictureflow_emptyslide.bmp");
503 $pf_logo = "pictureflow_logo.100x18x16.bmp";
505 $pf_logo = "pictureflow_logo.193x34x16.bmp";
507 copy
("$ROOT/apps/plugins/bitmaps/native/$pf_logo",
508 "$temp_dir/rocks/demos/pictureflow_splash.bmp");
513 # image is blank when this is a simulator
514 if( filesize
("rockbox.ucl") > 1000 ) {
515 copy
("rockbox.ucl", "$temp_dir/rockbox.ucl"); # UCL for flashing
517 if( filesize
("rombox.ucl") > 1000) {
518 copy
("rombox.ucl", "$temp_dir/rombox.ucl"); # UCL for flashing
521 # Check for rombox.target
522 if ($image=~/(.*)\.(\w+)$/)
524 my $romfile = "rombox.$2";
525 if (filesize
($romfile) > 1000)
527 copy
($romfile, "$temp_dir/$romfile");
532 glob_mkdir
("$temp_dir/docs");
537 copy
("$ROOT/docs/$_", "$temp_dir/docs/$_.txt");
540 copy
("$ROOT/docs/profontdoc.txt", "$temp_dir/docs/profontdoc.txt");
542 for(("sample.colours",
545 copy
("$ROOT/docs/$_", "$temp_dir/docs/$_");
548 # Now do the WPS dance
550 my $wps_build_cmd="perl $ROOT/wps/wpsbuild.pl ";
551 $wps_build_cmd=$wps_build_cmd."-v " if $verbose;
552 $wps_build_cmd=$wps_build_cmd." --tempdir=$temp_dir --rbdir=$rbdir -r $ROOT -m $modelname $ROOT/wps/WPSLIST $target";
553 print "wpsbuild: $wps_build_cmd\n" if $verbose;
554 system("$wps_build_cmd");
555 print "wps_build_cmd: done\n" if $verbose;
558 print STDERR
"No wps module present, can't do the WPS magic!\n";
561 # until buildwps.pl is fixed, manually copy the classic_statusbar theme across
562 mkdir "$temp_dir/wps/classic_statusbar", 0777;
563 glob_copy
("$ROOT/wps/classic_statusbar/*.bmp", "$temp_dir/wps/classic_statusbar");
566 copy
("$ROOT/wps/classic_statusbar.sbs", "$temp_dir/wps");
567 } elsif ($depth > 1) {
568 copy
("$ROOT/wps/classic_statusbar.grey.sbs", "$temp_dir/wps/classic_statusbar.sbs");
570 copy
("$ROOT/wps/classic_statusbar.mono.sbs", "$temp_dir/wps/classic_statusbar.sbs");
573 copy
("$ROOT/wps/classic_statusbar.112x64x1.sbs", "$temp_dir/wps/classic_statusbar.sbs");
575 system("touch $temp_dir/wps/rockbox_none.sbs");
576 if ($remote_depth != $depth) {
577 copy
("$ROOT/wps/classic_statusbar.mono.sbs", "$temp_dir/wps/classic_statusbar.rsbs");
579 copy
("$temp_dir/wps/classic_statusbar.sbs", "$temp_dir/wps/classic_statusbar.rsbs");
581 copy
("$temp_dir/wps/rockbox_none.sbs", "$temp_dir/wps/rockbox_none.rsbs");
584 copy
("rockbox-info.txt", "$temp_dir/rockbox-info.txt");
586 # copy the already built lng files
587 glob_copy
('apps/lang/*lng', "$temp_dir/langs/");
589 # copy the .lua files
590 glob_mkdir
("$temp_dir/rocks/viewers/lua/");
591 glob_copy
('apps/plugins/lua/*.lua', "$temp_dir/rocks/viewers/lua/");
594 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
600 #$date=sprintf("%04d%02d%02d", $year,$mon, $mday);
601 #$shortdate=sprintf("%02d%02d%02d", $year%100,$mon, $mday);
603 # made once for all targets
605 my ($target, $fonts)=@_;
607 # in the app the the layout is different (no .rockbox, but bin/lib/share)
608 $app = ($modelname eq "application");
610 #rbdir starts with '/', strip it
611 $rbdir = substr($rbdir, 1);
614 # build a full install .rockbox ($rbdir) directory
615 buildzip
($target, $fonts);
620 # Don't include image file in fonts-only package
623 if($target && ($target !~ /(mod|ajz|wma)\z/i)) {
624 # On some targets, the image goes into .rockbox.
625 copy
("$target", "$rbdir/$target");
630 make_install
(".rockbox", $install) or die "MKDIRFAILED\n";
633 unless (".rockbox" eq $rbdir) {
634 move
(".rockbox", $rbdir);
635 print "mv .rockbox $rbdir\n" if $verbose;
637 system("$ziptool $output $rbdir $target >/dev/null");
638 print "$ziptool $output $rbdir $target >/dev/null\n" if $verbose;
641 print "rm .rockbox\n" if $verbose;
645 # not specified, guess!
646 if($target =~ /(recorder|ondio)/i) {
649 elsif($target =~ /iriver/i) {
650 $exe = "rockbox.iriver";
656 elsif(($exe =~ /rockboxui/)) {
657 # simulator, exclude the exe file
661 runone
($exe, $incfonts);