Enable SW tone control on gigabeat S, since HW tone controls for its DAC are not...
[kugel-rb.git] / tools / buildzip.pl
blobaa25e26b13b0cbcba90269fb3b52fce3930a0a54
1 #!/usr/bin/perl
2 # __________ __ ___.
3 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 # \/ \/ \/ \/ \/
8 # $Id$
11 use strict;
13 use File::Copy; # For move() and copy()
14 use File::Find; # For find()
15 use File::Path; # For rmtree()
16 use Cwd 'abs_path';
17 use Getopt::Long qw(:config pass_through); # pass_through so not confused by -DTYPE_STUFF
19 my $ROOT="..";
21 my $ziptool="zip -r9";
22 my $output="rockbox.zip";
23 my $verbose;
24 my $install=0;
25 my $exe;
26 my $target;
27 my $modelname;
28 my $incfonts;
29 my $target_id; # passed in, not currently used
30 my $rbdir=".rockbox"; # can be changed for special builds
34 sub glob_copy {
35 my ($pattern, $destination) = @_;
36 print "glob_copy: $pattern -> $destination\n" if $verbose;
37 foreach my $path (glob($pattern)) {
38 copy($path, $destination);
42 sub glob_move {
43 my ($pattern, $destination) = @_;
44 print "glob_move: $pattern -> $destination\n" if $verbose;
45 foreach my $path (glob($pattern)) {
46 move($path, $destination);
50 sub glob_unlink {
51 my ($pattern) = @_;
52 print "glob_unlink: $pattern\n" if $verbose;
53 foreach my $path (glob($pattern)) {
54 unlink($path);
58 sub find_copyfile {
59 my ($pattern, $destination) = @_;
60 print "find_copyfile: $pattern -> $destination\n" if $verbose;
61 return sub {
62 my $path = $_;
63 if ($path =~ $pattern && filesize($path) > 0 && !($path =~ /$rbdir/)) {
64 copy($path, $destination);
65 chmod(0755, $destination.'/'.$path);
70 # Get options
71 GetOptions ( 'r|root=s' => \$ROOT,
72 'z|ziptool=s' => \$ziptool,
73 'm|modelname=s' => \$modelname, # The model name as used in ARCHOS in the root makefile
74 'i|id=s' => \$target_id, # The target id name as used in TARGET_ID in the root makefile
75 'o|output=s' => \$output,
76 'f|fonts=s' => \$incfonts, # 0 - no fonts, 1 - fonts only 2 - fonts and package
77 'v|verbose' => \$verbose,
78 'install=s' => \$install, # install destination
79 'rbdir=s' => \$rbdir, # If we want to put in a different directory
82 ($target, $exe) = @ARGV;
84 my $firmdir="$ROOT/firmware";
85 my $appsdir="$ROOT/apps";
86 my $viewer_bmpdir="$ROOT/apps/plugins/bitmaps/viewer_defaults";
88 my $cppdef = $target;
90 sub gettargetinfo {
91 open(GCC, ">gcctemp");
92 # Get the LCD screen depth and graphical status
93 print GCC <<STOP
94 \#include "config.h"
95 #ifdef HAVE_LCD_BITMAP
96 Bitmap: yes
97 Depth: LCD_DEPTH
98 LCD Width: LCD_WIDTH
99 LCD Height: LCD_HEIGHT
100 Icon Width: CONFIG_DEFAULT_ICON_WIDTH
101 Icon Height: CONFIG_DEFAULT_ICON_HEIGHT
102 #endif
103 Codec: CONFIG_CODEC
104 #ifdef HAVE_REMOTE_LCD
105 Remote Depth: LCD_REMOTE_DEPTH
106 Remote Icon Width: CONFIG_REMOTE_DEFAULT_ICON_WIDTH
107 Remote Icon Height: CONFIG_REMOTE_DEFAULT_ICON_HEIGHT
108 #else
109 Remote Depth: 0
110 #endif
111 #ifdef HAVE_RECORDING
112 Recording: yes
113 #endif
114 STOP
116 close(GCC);
118 my $c="cat gcctemp | gcc $cppdef -I. -I$firmdir/export -E -P -";
120 # print STDERR "CMD $c\n";
122 open(TARGET, "$c|");
124 my ($bitmap, $width, $height, $depth, $swcodec, $icon_h, $icon_w);
125 my ($remote_depth, $remote_icon_h, $remote_icon_w);
126 my ($recording);
127 my $icon_count = 1;
128 while(<TARGET>) {
129 # print STDERR "DATA: $_";
130 if($_ =~ /^Bitmap: (.*)/) {
131 $bitmap = $1;
133 elsif($_ =~ /^Depth: (\d*)/) {
134 $depth = $1;
136 elsif($_ =~ /^LCD Width: (\d*)/) {
137 $width = $1;
139 elsif($_ =~ /^LCD Height: (\d*)/) {
140 $height = $1;
142 elsif($_ =~ /^Icon Width: (\d*)/) {
143 $icon_w = $1;
145 elsif($_ =~ /^Icon Height: (\d*)/) {
146 $icon_h = $1;
148 elsif($_ =~ /^Codec: (\d*)/) {
149 # SWCODEC is 1, the others are HWCODEC
150 $swcodec = ($1 == 1);
152 elsif($_ =~ /^Remote Depth: (\d*)/) {
153 $remote_depth = $1;
155 elsif($_ =~ /^Remote Icon Width: (\d*)/) {
156 $remote_icon_w = $1;
158 elsif($_ =~ /^Remote Icon Height: (\d*)/) {
159 $remote_icon_h = $1;
161 if($_ =~ /^Recording: (.*)/) {
162 $recording = $1;
165 close(TARGET);
166 unlink("gcctemp");
168 return ($bitmap, $depth, $width, $height, $icon_w, $icon_h, $recording,
169 $swcodec, $remote_depth, $remote_icon_w, $remote_icon_h);
172 sub filesize {
173 my ($filename)=@_;
174 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
175 $atime,$mtime,$ctime,$blksize,$blocks)
176 = stat($filename);
177 return $size;
180 sub buildzip {
181 my ($image, $fonts)=@_;
183 print "buildzip: image=$image fonts=$fonts\n" if $verbose;
185 my ($bitmap, $depth, $width, $height, $icon_w, $icon_h, $recording,
186 $swcodec, $remote_depth, $remote_icon_w, $remote_icon_h) =
187 &gettargetinfo();
189 # print "Bitmap: $bitmap\nDepth: $depth\nSwcodec: $swcodec\n";
191 # remove old traces
192 rmtree($rbdir);
194 mkdir $rbdir, 0777;
196 if(!$bitmap) {
197 # always disable fonts on non-bitmap targets
198 $fonts = 0;
200 if($fonts) {
201 mkdir "$rbdir/fonts", 0777;
202 chdir "$rbdir/fonts";
203 my $cmd = "$ROOT/tools/convbdf -f $ROOT/fonts/*bdf >/dev/null 2>&1";
204 print($cmd."\n") if $verbose;
205 system($cmd);
206 chdir("../../");
208 if($fonts < 2) {
209 # fonts-only package, return
210 return;
214 # create the file so the database does not try indexing a folder
215 open(IGNORE, ">$rbdir/database.ignore") || die "can't open database.ignore";
216 close(IGNORE);
218 mkdir "$rbdir/langs", 0777;
219 mkdir "$rbdir/rocks", 0777;
220 mkdir "$rbdir/rocks/games", 0777;
221 mkdir "$rbdir/rocks/apps", 0777;
222 mkdir "$rbdir/rocks/demos", 0777;
223 mkdir "$rbdir/rocks/viewers", 0777;
225 if ($recording) {
226 mkdir "$rbdir/recpresets", 0777;
229 if($swcodec) {
230 mkdir "$rbdir/eqs", 0777;
232 glob_copy("$ROOT/apps/eqs/*.cfg", "$rbdir/eqs/"); # equalizer presets
235 mkdir "$rbdir/wps", 0777;
236 mkdir "$rbdir/themes", 0777;
237 if ($bitmap) {
238 open(THEME, ">$rbdir/themes/rockbox_default_icons.cfg");
239 print THEME <<STOP
240 # this config file was auto-generated to make it
241 # easy to reset the icons back to default
242 iconset: -
243 # taken from apps/gui/icon.c
244 viewers iconset: /$rbdir/icons/viewers.bmp
245 remote iconset: -
246 # taken from apps/gui/icon.c
247 remote viewers iconset: /$rbdir/icons/remote_viewers.bmp
249 STOP
251 close(THEME);
254 mkdir "$rbdir/codepages", 0777;
256 if($bitmap) {
257 system("$ROOT/tools/codepages");
259 else {
260 system("$ROOT/tools/codepages -m");
263 glob_move('*.cp', "$rbdir/codepages/");
265 if($bitmap) {
266 mkdir "$rbdir/codecs", 0777;
267 if($depth > 1) {
268 mkdir "$rbdir/backdrops", 0777;
271 find(find_copyfile(qr/.*\.codec/, abs_path("$rbdir/codecs/")), 'apps/codecs');
273 # remove directory again if no codec was copied
274 rmdir("$rbdir/codecs");
277 find(find_copyfile(qr/\.(rock|ovl|lua)/, abs_path("$rbdir/rocks/")), 'apps/plugins');
279 open VIEWERS, "$ROOT/apps/plugins/viewers.config" or
280 die "can't open viewers.config";
281 my @viewers = <VIEWERS>;
282 close VIEWERS;
284 open VIEWERS, ">$rbdir/viewers.config" or
285 die "can't create $rbdir/viewers.config";
287 foreach my $line (@viewers) {
288 if ($line =~ /([^,]*),([^,]*),/) {
289 my ($ext, $plugin)=($1, $2);
290 my $r = "${plugin}.rock";
291 my $oname;
293 my $dir = $r;
294 my $name;
296 # strip off the last slash and file name part
297 $dir =~ s/(.*)\/(.*)/$1/;
298 # store the file name part
299 $name = $2;
301 # get .ovl name (file part only)
302 $oname = $name;
303 $oname =~ s/\.rock$/.ovl/;
305 # print STDERR "$ext $plugin $dir $name $r\n";
307 if(-e "$rbdir/rocks/$name") {
308 if($dir ne "rocks") {
309 # target is not 'rocks' but the plugins are always in that
310 # dir at first!
311 move("$rbdir/rocks/$name", "$rbdir/rocks/$r");
313 print VIEWERS $line;
315 elsif(-e "$rbdir/rocks/$r") {
316 # in case the same plugin works for multiple extensions, it
317 # was already moved to the viewers dir
318 print VIEWERS $line;
321 if(-e "$rbdir/rocks/$oname") {
322 # if there's an "overlay" file for the .rock, move that as
323 # well
324 move("$rbdir/rocks/$oname", "$rbdir/rocks/$dir");
328 close VIEWERS;
330 open CATEGORIES, "$ROOT/apps/plugins/CATEGORIES" or
331 die "can't open CATEGORIES";
332 my @rock_targetdirs = <CATEGORIES>;
333 close CATEGORIES;
334 foreach my $line (@rock_targetdirs) {
335 if ($line =~ /([^,]*),(.*)/) {
336 my ($plugin, $dir)=($1, $2);
337 move("$rbdir/rocks/${plugin}.rock", "$rbdir/rocks/$dir/${plugin}.rock");
338 if(-e "$rbdir/rocks/${plugin}.ovl") {
339 # if there's an "overlay" file for the .rock, move that as
340 # well
341 move("$rbdir/rocks/${plugin}.ovl", "$rbdir/rocks/$dir");
343 if(-e "$rbdir/rocks/${plugin}.lua") {
344 # if this is a lua script, move it to the appropriate dir
345 move("$rbdir/rocks/${plugin}.lua", "$rbdir/rocks/$dir/");
350 glob_unlink("$rbdir/rocks/*.lua"); # Clean up unwanted *.lua files (e.g. actions.lua, buttons.lua)
352 if ($bitmap) {
353 mkdir "$rbdir/icons", 0777;
354 copy("$viewer_bmpdir/viewers.${icon_w}x${icon_h}x$depth.bmp", "$rbdir/icons/viewers.bmp");
355 if ($remote_depth) {
356 copy("$viewer_bmpdir/remote_viewers.${remote_icon_w}x${remote_icon_h}x$remote_depth.bmp", "$rbdir/icons/remote_viewers.bmp");
360 copy("$ROOT/apps/tagnavi.config", "$rbdir/");
361 copy("$ROOT/apps/plugins/disktidy.config", "$rbdir/rocks/apps/");
363 if($bitmap) {
364 copy("$ROOT/apps/plugins/sokoban.levels", "$rbdir/rocks/games/sokoban.levels"); # sokoban levels
365 copy("$ROOT/apps/plugins/snake2.levels", "$rbdir/rocks/games/snake2.levels"); # snake2 levels
366 copy("$ROOT/apps/plugins/rockbox-fonts.config", "$rbdir/rocks/viewers/");
369 if(-e "$rbdir/rocks/demos/pictureflow.rock") {
370 copy("$ROOT/apps/plugins/bitmaps/native/pictureflow_emptyslide.100x100x16.bmp",
371 "$rbdir/rocks/demos/pictureflow_emptyslide.bmp");
372 my ($pf_logo);
373 if ($width < 200) {
374 $pf_logo = "pictureflow_logo.100x18x16.bmp";
375 } else {
376 $pf_logo = "pictureflow_logo.193x34x16.bmp";
378 copy("$ROOT/apps/plugins/bitmaps/native/$pf_logo",
379 "$rbdir/rocks/demos/pictureflow_splash.bmp");
383 if($image) {
384 # image is blank when this is a simulator
385 if( filesize("rockbox.ucl") > 1000 ) {
386 copy("rockbox.ucl", "$rbdir/rockbox.ucl"); # UCL for flashing
388 if( filesize("rombox.ucl") > 1000) {
389 copy("rombox.ucl", "$rbdir/rombox.ucl"); # UCL for flashing
392 # Check for rombox.target
393 if ($image=~/(.*)\.(\w+)$/)
395 my $romfile = "rombox.$2";
396 if (filesize($romfile) > 1000)
398 copy($romfile, "$rbdir/$romfile");
403 mkdir "$rbdir/docs", 0777;
404 for(("COPYING",
405 "LICENSES",
406 "KNOWN_ISSUES"
407 )) {
408 copy("$ROOT/docs/$_", "$rbdir/docs/$_.txt");
410 if ($fonts) {
411 copy("$ROOT/docs/profontdoc.txt", "$rbdir/docs/profontdoc.txt");
413 for(("sample.colours",
414 "sample.icons"
415 )) {
416 copy("$ROOT/docs/$_", "$rbdir/docs/$_");
419 # Now do the WPS dance
420 if(-d "$ROOT/wps") {
421 my $wps_build_cmd="perl $ROOT/wps/wpsbuild.pl ";
422 $wps_build_cmd=$wps_build_cmd."-v " if $verbose;
423 $wps_build_cmd=$wps_build_cmd." --rbdir=$rbdir -r $ROOT -m $modelname $ROOT/wps/WPSLIST $target";
424 print "wpsbuild: $wps_build_cmd\n" if $verbose;
425 system("$wps_build_cmd");
426 print "wps_build_cmd: done\n" if $verbose;
428 else {
429 print STDERR "No wps module present, can't do the WPS magic!\n";
432 # until buildwps.pl is fixed, manually copy the classic_statusbar theme across
433 mkdir "$rbdir/wps/classic_statusbar", 0777;
434 glob_copy("$ROOT/wps/classic_statusbar/*.bmp", "$rbdir/wps/classic_statusbar");
435 if ($swcodec) {
436 if ($depth == 16) {
437 copy("$ROOT/wps/classic_statusbar.sbs", "$rbdir/wps");
438 } elsif ($depth > 1) {
439 copy("$ROOT/wps/classic_statusbar.grey.sbs", "$rbdir/wps/classic_statusbar.sbs");
440 } else {
441 copy("$ROOT/wps/classic_statusbar.mono.sbs", "$rbdir/wps/classic_statusbar.sbs");
443 } else {
444 copy("$ROOT/wps/classic_statusbar.112x64x1.sbs", "$rbdir/wps/classic_statusbar.sbs");
446 system("touch $rbdir/wps/rockbox_none.sbs");
447 if ($remote_depth != $depth) {
448 copy("$ROOT/wps/classic_statusbar.mono.sbs", "$rbdir/wps/classic_statusbar.rsbs");
449 } else {
450 copy("$rbdir/wps/classic_statusbar.sbs", "$rbdir/wps/classic_statusbar.rsbs");
452 copy("$rbdir/wps/rockbox_none.sbs", "$rbdir/wps/rockbox_none.rsbs");
454 # and the info file
455 copy("rockbox-info.txt", "$rbdir/rockbox-info.txt");
457 # copy the already built lng files
458 glob_copy('apps/lang/*lng', "$rbdir/langs/");
460 # copy the .lua files
461 mkdir "$rbdir/rocks/viewers/lua/", 0777;
462 glob_copy('apps/plugins/lua/*.lua', "$rbdir/rocks/viewers/lua/");
465 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
466 localtime(time);
468 $mon+=1;
469 $year+=1900;
471 #$date=sprintf("%04d%02d%02d", $year,$mon, $mday);
472 #$shortdate=sprintf("%02d%02d%02d", $year%100,$mon, $mday);
474 # made once for all targets
475 sub runone {
476 my ($target, $fonts)=@_;
478 # build a full install .rockbox ($rbdir) directory
479 buildzip($target, $fonts);
481 unlink($output);
483 if($fonts == 1) {
484 # Don't include image file in fonts-only package
485 undef $target;
487 if($target && ($target !~ /(mod|ajz|wma)\z/i)) {
488 # On some targets, the image goes into .rockbox.
489 copy("$target", "$rbdir/$target");
490 undef $target;
493 if($verbose) {
494 print "$ziptool $output $rbdir $target >/dev/null\n";
497 if($install) {
498 if ($install =~ /\/dev\/null/) {
499 die "ERROR: No PREFIX given\n"
501 system("cp -r $rbdir \"$install\" >/dev/null");
503 else {
504 system("$ziptool $output $rbdir $target >/dev/null");
507 # remove the $rbdir afterwards
508 rmtree($rbdir);
511 if(!$exe) {
512 # not specified, guess!
513 if($target =~ /(recorder|ondio)/i) {
514 $exe = "ajbrec.ajz";
516 elsif($target =~ /iriver/i) {
517 $exe = "rockbox.iriver";
519 else {
520 $exe = "archos.mod";
523 elsif($exe =~ /rockboxui/) {
524 # simulator, exclude the exe file
525 $exe = "";
528 runone($exe, $incfonts);