Update Beast installation instructions to use beastpatcher and remove instructions...
[kugel-rb/myfork.git] / tools / buildzip.pl
blob7df6af3a363cbf5b9dcbde0ccc186483b4a6e6af
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 $sim;
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 's|sim' => \$sim,
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 Icon Width: CONFIG_DEFAULT_ICON_WIDTH
99 Icon Height: CONFIG_DEFAULT_ICON_HEIGHT
100 #endif
101 Codec: CONFIG_CODEC
102 #ifdef HAVE_REMOTE_LCD
103 Remote Depth: LCD_REMOTE_DEPTH
104 Remote Icon Width: CONFIG_REMOTE_DEFAULT_ICON_WIDTH
105 Remote Icon Height: CONFIG_REMOTE_DEFAULT_ICON_HEIGHT
106 #else
107 Remote Depth: 0
108 #endif
109 #ifdef HAVE_RECORDING
110 Recording: yes
111 #endif
112 STOP
114 close(GCC);
116 my $c="cat gcctemp | gcc $cppdef -I. -I$firmdir/export -E -P -";
118 # print STDERR "CMD $c\n";
120 open(TARGET, "$c|");
122 my ($bitmap, $depth, $swcodec, $icon_h, $icon_w);
123 my ($remote_depth, $remote_icon_h, $remote_icon_w);
124 my ($recording);
125 my $icon_count = 1;
126 while(<TARGET>) {
127 # print STDERR "DATA: $_";
128 if($_ =~ /^Bitmap: (.*)/) {
129 $bitmap = $1;
131 elsif($_ =~ /^Depth: (\d*)/) {
132 $depth = $1;
134 elsif($_ =~ /^Icon Width: (\d*)/) {
135 $icon_w = $1;
137 elsif($_ =~ /^Icon Height: (\d*)/) {
138 $icon_h = $1;
140 elsif($_ =~ /^Codec: (\d*)/) {
141 # SWCODEC is 1, the others are HWCODEC
142 $swcodec = ($1 == 1);
144 elsif($_ =~ /^Remote Depth: (\d*)/) {
145 $remote_depth = $1;
147 elsif($_ =~ /^Remote Icon Width: (\d*)/) {
148 $remote_icon_w = $1;
150 elsif($_ =~ /^Remote Icon Height: (\d*)/) {
151 $remote_icon_h = $1;
153 if($_ =~ /^Recording: (.*)/) {
154 $recording = $1;
157 close(TARGET);
158 unlink("gcctemp");
160 return ($bitmap, $depth, $icon_w, $icon_h, $recording,
161 $swcodec, $remote_depth, $remote_icon_w, $remote_icon_h);
164 sub filesize {
165 my ($filename)=@_;
166 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
167 $atime,$mtime,$ctime,$blksize,$blocks)
168 = stat($filename);
169 return $size;
172 sub buildzip {
173 my ($image, $fonts)=@_;
175 print "buildzip: image=$image fonts=$fonts\n" if $verbose;
177 my ($bitmap, $depth, $icon_w, $icon_h, $recording, $swcodec,
178 $remote_depth, $remote_icon_w, $remote_icon_h) = &gettargetinfo();
180 # print "Bitmap: $bitmap\nDepth: $depth\nSwcodec: $swcodec\n";
182 # remove old traces
183 rmtree($rbdir);
185 mkdir $rbdir, 0777;
187 if(!$bitmap) {
188 # always disable fonts on non-bitmap targets
189 $fonts = 0;
191 if($fonts) {
192 mkdir "$rbdir/fonts", 0777;
193 chdir "$rbdir/fonts";
194 my $cmd = "$ROOT/tools/convbdf -f $ROOT/fonts/*bdf >/dev/null 2>&1";
195 print($cmd."\n") if $verbose;
196 system($cmd);
197 chdir("../../");
199 if($fonts < 2) {
200 # fonts-only package, return
201 return;
205 # create the file so the database does not try indexing a folder
206 open(IGNORE, ">$rbdir/database.ignore") || die "can't open database.ignore";
207 close(IGNORE);
209 mkdir "$rbdir/langs", 0777;
210 mkdir "$rbdir/rocks", 0777;
211 mkdir "$rbdir/rocks/games", 0777;
212 mkdir "$rbdir/rocks/apps", 0777;
213 mkdir "$rbdir/rocks/demos", 0777;
214 mkdir "$rbdir/rocks/viewers", 0777;
216 if ($recording) {
217 mkdir "$rbdir/recpresets", 0777;
220 if($swcodec) {
221 mkdir "$rbdir/eqs", 0777;
223 glob_copy("$ROOT/apps/eqs/*.cfg", "$rbdir/eqs/"); # equalizer presets
226 mkdir "$rbdir/wps", 0777;
227 mkdir "$rbdir/themes", 0777;
228 if ($bitmap) {
229 open(THEME, ">$rbdir/themes/rockbox_default_icons.cfg");
230 print THEME <<STOP
231 # this config file was auto-generated to make it
232 # easy to reset the icons back to default
233 iconset: -
234 # taken from apps/gui/icon.c
235 viewers iconset: /$rbdir/icons/viewers.bmp
236 remote iconset: -
237 # taken from apps/gui/icon.c
238 remote viewers iconset: /$rbdir/icons/remote_viewers.bmp
240 STOP
242 close(THEME);
245 mkdir "$rbdir/codepages", 0777;
247 if($bitmap) {
248 system("$ROOT/tools/codepages");
250 else {
251 system("$ROOT/tools/codepages -m");
254 glob_move('*.cp', "$rbdir/codepages/");
256 if($bitmap) {
257 mkdir "$rbdir/codecs", 0777;
258 if($depth > 1) {
259 mkdir "$rbdir/backdrops", 0777;
262 find(find_copyfile(qr/.*\.codec/, abs_path("$rbdir/codecs/")), 'apps/codecs');
264 # remove directory again if no codec was copied
265 rmdir("$rbdir/codecs");
268 find(find_copyfile(qr/\.(rock|ovl)/, abs_path("$rbdir/rocks/")), 'apps/plugins');
270 open VIEWERS, "$ROOT/apps/plugins/viewers.config" or
271 die "can't open viewers.config";
272 my @viewers = <VIEWERS>;
273 close VIEWERS;
275 open VIEWERS, ">$rbdir/viewers.config" or
276 die "can't create $rbdir/viewers.config";
278 foreach my $line (@viewers) {
279 if ($line =~ /([^,]*),([^,]*),/) {
280 my ($ext, $plugin)=($1, $2);
281 my $r = "${plugin}.rock";
282 my $oname;
284 my $dir = $r;
285 my $name;
287 # strip off the last slash and file name part
288 $dir =~ s/(.*)\/(.*)/$1/;
289 # store the file name part
290 $name = $2;
292 # get .ovl name (file part only)
293 $oname = $name;
294 $oname =~ s/\.rock$/.ovl/;
296 # print STDERR "$ext $plugin $dir $name $r\n";
298 if(-e "$rbdir/rocks/$name") {
299 if($dir ne "rocks") {
300 # target is not 'rocks' but the plugins are always in that
301 # dir at first!
302 move("$rbdir/rocks/$name", "$rbdir/rocks/$r");
304 print VIEWERS $line;
306 elsif(-e "$rbdir/rocks/$r") {
307 # in case the same plugin works for multiple extensions, it
308 # was already moved to the viewers dir
309 print VIEWERS $line;
312 if(-e "$rbdir/rocks/$oname") {
313 # if there's an "overlay" file for the .rock, move that as
314 # well
315 move("$rbdir/rocks/$oname", "$rbdir/rocks/$dir");
319 close VIEWERS;
321 open CATEGORIES, "$ROOT/apps/plugins/CATEGORIES" or
322 die "can't open CATEGORIES";
323 my @rock_targetdirs = <CATEGORIES>;
324 close CATEGORIES;
325 foreach my $line (@rock_targetdirs) {
326 if ($line =~ /([^,]*),(.*)/) {
327 my ($plugin, $dir)=($1, $2);
328 move("$rbdir/rocks/${plugin}.rock", "$rbdir/rocks/$dir/${plugin}.rock");
332 if ($bitmap) {
333 mkdir "$rbdir/icons", 0777;
334 copy("$viewer_bmpdir/viewers.${icon_w}x${icon_h}x$depth.bmp", "$rbdir/icons/viewers.bmp");
335 if ($remote_depth) {
336 copy("$viewer_bmpdir/remote_viewers.${remote_icon_w}x${remote_icon_h}x$remote_depth.bmp", "$rbdir/icons/remote_viewers.bmp");
340 copy("$ROOT/apps/tagnavi.config", "$rbdir/");
341 copy("$ROOT/apps/plugins/disktidy.config", "$rbdir/rocks/apps/");
343 if($bitmap) {
344 copy("$ROOT/apps/plugins/sokoban.levels", "$rbdir/rocks/games/sokoban.levels"); # sokoban levels
345 copy("$ROOT/apps/plugins/snake2.levels", "$rbdir/rocks/games/snake2.levels"); # snake2 levels
348 if(-e "$rbdir/rocks/demos/pictureflow.rock") {
349 copy("$ROOT/apps/plugins/bitmaps/native/pictureflow_emptyslide.100x100x16.bmp", "$rbdir/rocks/demos/pictureflow_emptyslide.bmp");
352 if($image) {
353 # image is blank when this is a simulator
354 if( filesize("rockbox.ucl") > 1000 ) {
355 copy("rockbox.ucl", "$rbdir/rockbox.ucl"); # UCL for flashing
357 if( filesize("rombox.ucl") > 1000) {
358 copy("rombox.ucl", "$rbdir/rombox.ucl"); # UCL for flashing
361 # Check for rombox.target
362 if ($image=~/(.*)\.(\w+)$/)
364 my $romfile = "rombox.$2";
365 if (filesize($romfile) > 1000)
367 copy($romfile, "$rbdir/$romfile");
372 mkdir "$rbdir/docs", 0777;
373 for(("COPYING",
374 "LICENSES",
375 "KNOWN_ISSUES"
376 )) {
377 copy("$ROOT/docs/$_", "$rbdir/docs/$_.txt");
379 if ($fonts) {
380 copy("$ROOT/docs/profontdoc.txt", "$rbdir/docs/profontdoc.txt");
382 for(("sample.colours",
383 "sample.icons"
384 )) {
385 copy("$ROOT/docs/$_", "$rbdir/docs/$_");
388 # Now do the WPS dance
389 if(-d "$ROOT/wps") {
390 my $wps_build_cmd="perl $ROOT/wps/wpsbuild.pl ";
391 $wps_build_cmd=$wps_build_cmd."-v " if $verbose;
392 $wps_build_cmd=$wps_build_cmd." --rbdir=$rbdir -r $ROOT -m $modelname $ROOT/wps/WPSLIST $target";
393 print "wpsbuild: $wps_build_cmd\n" if $verbose;
394 system("$wps_build_cmd");
395 print "wps_build_cmd: done\n" if $verbose;
397 else {
398 print STDERR "No wps module present, can't do the WPS magic!\n";
401 # and the info file
402 copy("rockbox-info.txt", "$rbdir/rockbox-info.txt");
404 # copy the already built lng files
405 glob_copy('apps/lang/*lng', "$rbdir/langs/");
409 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
410 localtime(time);
412 $mon+=1;
413 $year+=1900;
415 #$date=sprintf("%04d%02d%02d", $year,$mon, $mday);
416 #$shortdate=sprintf("%02d%02d%02d", $year%100,$mon, $mday);
418 # made once for all targets
419 sub runone {
420 my ($target, $fonts)=@_;
422 # build a full install .rockbox ($rbdir) directory
423 buildzip($target, $fonts);
425 unlink($output);
427 if($fonts == 1) {
428 # Don't include image file in fonts-only package
429 undef $target;
431 if($target && ($target !~ /(mod|ajz|wma)\z/i)) {
432 # On some targets, the image goes into .rockbox.
433 copy("$target", "$rbdir/$target");
434 undef $target;
437 if($verbose) {
438 print "$ziptool $output $rbdir $target >/dev/null\n";
441 if($sim) {
442 system("cp -r $rbdir simdisk/ >/dev/null");
444 else {
445 system("$ziptool $output $rbdir $target >/dev/null");
448 # remove the $rbdir afterwards
449 rmtree($rbdir);
452 if(!$exe) {
453 # not specified, guess!
454 if($target =~ /(recorder|ondio)/i) {
455 $exe = "ajbrec.ajz";
457 elsif($target =~ /iriver/i) {
458 $exe = "rockbox.iriver";
460 else {
461 $exe = "archos.mod";
464 elsif($exe =~ /rockboxui/) {
465 # simulator, exclude the exe file
466 $exe = "";
469 runone($exe, $incfonts);