Manual: Platform files - split out the button and action commands from the platform...
[kugel-rb.git] / tools / buildzip.pl
blob06bcf3bfe6b722cd72f3f55f60508cc6a391b2e1
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 $archos;
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 't|target=s' => \$archos, # The target 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 # Some basic sanity
85 die "No firmware found @ $exe" if !-f $exe;
87 my $firmdir="$ROOT/firmware";
88 my $appsdir="$ROOT/apps";
89 my $viewer_bmpdir="$ROOT/apps/plugins/bitmaps/viewer_defaults";
91 my $cppdef = $target;
93 sub gettargetinfo {
94 open(GCC, ">gcctemp");
95 # Get the LCD screen depth and graphical status
96 print GCC <<STOP
97 \#include "config.h"
98 #ifdef HAVE_LCD_BITMAP
99 Bitmap: yes
100 Depth: LCD_DEPTH
101 Icon Width: CONFIG_DEFAULT_ICON_WIDTH
102 Icon Height: CONFIG_DEFAULT_ICON_HEIGHT
103 #endif
104 Codec: CONFIG_CODEC
105 #ifdef HAVE_REMOTE_LCD
106 Remote Depth: LCD_REMOTE_DEPTH
107 Remote Icon Width: CONFIG_REMOTE_DEFAULT_ICON_WIDTH
108 Remote Icon Height: CONFIG_REMOTE_DEFAULT_ICON_HEIGHT
109 #else
110 Remote Depth: 0
111 #endif
112 #ifdef HAVE_RECORDING
113 Recording: yes
114 #endif
115 STOP
117 close(GCC);
119 my $c="cat gcctemp | gcc $cppdef -I. -I$firmdir/export -E -P -";
121 # print STDERR "CMD $c\n";
123 open(TARGET, "$c|");
125 my ($bitmap, $depth, $swcodec, $icon_h, $icon_w);
126 my ($remote_depth, $remote_icon_h, $remote_icon_w);
127 my ($recording);
128 my $icon_count = 1;
129 while(<TARGET>) {
130 # print STDERR "DATA: $_";
131 if($_ =~ /^Bitmap: (.*)/) {
132 $bitmap = $1;
134 elsif($_ =~ /^Depth: (\d*)/) {
135 $depth = $1;
137 elsif($_ =~ /^Icon Width: (\d*)/) {
138 $icon_w = $1;
140 elsif($_ =~ /^Icon Height: (\d*)/) {
141 $icon_h = $1;
143 elsif($_ =~ /^Codec: (\d*)/) {
144 # SWCODEC is 1, the others are HWCODEC
145 $swcodec = ($1 == 1);
147 elsif($_ =~ /^Remote Depth: (\d*)/) {
148 $remote_depth = $1;
150 elsif($_ =~ /^Remote Icon Width: (\d*)/) {
151 $remote_icon_w = $1;
153 elsif($_ =~ /^Remote Icon Height: (\d*)/) {
154 $remote_icon_h = $1;
156 if($_ =~ /^Recording: (.*)/) {
157 $recording = $1;
160 close(TARGET);
161 unlink("gcctemp");
163 return ($bitmap, $depth, $icon_w, $icon_h, $recording,
164 $swcodec, $remote_depth, $remote_icon_w, $remote_icon_h);
167 sub filesize {
168 my ($filename)=@_;
169 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
170 $atime,$mtime,$ctime,$blksize,$blocks)
171 = stat($filename);
172 return $size;
175 sub buildzip {
176 my ($image, $fonts)=@_;
178 print "buildzip: image=$image fonts=$fonts\n" if $verbose;
180 my ($bitmap, $depth, $icon_w, $icon_h, $recording, $swcodec,
181 $remote_depth, $remote_icon_w, $remote_icon_h) = &gettargetinfo();
183 # print "Bitmap: $bitmap\nDepth: $depth\nSwcodec: $swcodec\n";
185 # remove old traces
186 rmtree($rbdir);
188 mkdir $rbdir, 0777;
190 if(!$bitmap) {
191 # always disable fonts on non-bitmap targets
192 $fonts = 0;
194 if($fonts) {
195 mkdir "$rbdir/fonts", 0777;
196 chdir "$rbdir/fonts";
197 my $cmd = "$ROOT/tools/convbdf -f $ROOT/fonts/*bdf >/dev/null 2>&1";
198 print($cmd."\n") if $verbose;
199 system($cmd);
200 chdir("../../");
202 if($fonts < 2) {
203 # fonts-only package, return
204 return;
208 # create the file so the database does not try indexing a folder
209 open(IGNORE, ">$rbdir/database.ignore") || die "can't open database.ignore";
210 close(IGNORE);
212 mkdir "$rbdir/langs", 0777;
213 mkdir "$rbdir/rocks", 0777;
214 mkdir "$rbdir/rocks/games", 0777;
215 mkdir "$rbdir/rocks/apps", 0777;
216 mkdir "$rbdir/rocks/demos", 0777;
217 mkdir "$rbdir/rocks/viewers", 0777;
219 if ($recording) {
220 mkdir "$rbdir/recpresets", 0777;
223 if($swcodec) {
224 mkdir "$rbdir/eqs", 0777;
226 glob_copy("$ROOT/apps/eqs/*.cfg", "$rbdir/eqs/"); # equalizer presets
229 mkdir "$rbdir/wps", 0777;
230 mkdir "$rbdir/themes", 0777;
231 if ($bitmap) {
232 open(THEME, ">$rbdir/themes/rockbox_default_icons.cfg");
233 print THEME <<STOP
234 # this config file was auto-generated to make it
235 # easy to reset the icons back to default
236 iconset: -
237 # taken from apps/gui/icon.c
238 viewers iconset: /$rbdir/icons/viewers.bmp
239 remote iconset: -
240 # taken from apps/gui/icon.c
241 remote viewers iconset: /$rbdir/icons/remote_viewers.bmp
243 STOP
245 close(THEME);
248 mkdir "$rbdir/codepages", 0777;
250 if($bitmap) {
251 system("$ROOT/tools/codepages");
253 else {
254 system("$ROOT/tools/codepages -m");
257 glob_move('*.cp', "$rbdir/codepages/");
259 if($bitmap) {
260 mkdir "$rbdir/codecs", 0777;
261 if($depth > 1) {
262 mkdir "$rbdir/backdrops", 0777;
265 find(find_copyfile(qr/.*\.codec/, abs_path("$rbdir/codecs/")), 'apps/codecs');
267 # remove directory again if no codec was copied
268 rmdir("$rbdir/codecs");
271 find(find_copyfile(qr/\.(rock|ovl)/, abs_path("$rbdir/rocks/")), 'apps/plugins');
273 open VIEWERS, "$ROOT/apps/plugins/viewers.config" or
274 die "can't open viewers.config";
275 my @viewers = <VIEWERS>;
276 close VIEWERS;
278 open VIEWERS, ">$rbdir/viewers.config" or
279 die "can't create $rbdir/viewers.config";
281 foreach my $line (@viewers) {
282 if ($line =~ /([^,]*),([^,]*),/) {
283 my ($ext, $plugin)=($1, $2);
284 my $r = "${plugin}.rock";
285 my $oname;
287 my $dir = $r;
288 my $name;
290 # strip off the last slash and file name part
291 $dir =~ s/(.*)\/(.*)/$1/;
292 # store the file name part
293 $name = $2;
295 # get .ovl name (file part only)
296 $oname = $name;
297 $oname =~ s/\.rock$/.ovl/;
299 # print STDERR "$ext $plugin $dir $name $r\n";
301 if(-e "$rbdir/rocks/$name") {
302 if($dir ne "rocks") {
303 # target is not 'rocks' but the plugins are always in that
304 # dir at first!
305 move("$rbdir/rocks/$name", "$rbdir/rocks/$r");
307 print VIEWERS $line;
309 elsif(-e "$rbdir/rocks/$r") {
310 # in case the same plugin works for multiple extensions, it
311 # was already moved to the viewers dir
312 print VIEWERS $line;
315 if(-e "$rbdir/rocks/$oname") {
316 # if there's an "overlay" file for the .rock, move that as
317 # well
318 move("$rbdir/rocks/$oname", "$rbdir/rocks/$dir");
322 close VIEWERS;
324 open CATEGORIES, "$ROOT/apps/plugins/CATEGORIES" or
325 die "can't open CATEGORIES";
326 my @rock_targetdirs = <CATEGORIES>;
327 close CATEGORIES;
328 foreach my $line (@rock_targetdirs) {
329 if ($line =~ /([^,]*),(.*)/) {
330 my ($plugin, $dir)=($1, $2);
331 move("$rbdir/rocks/${plugin}.rock", "$rbdir/rocks/$dir/${plugin}.rock");
335 if ($bitmap) {
336 mkdir "$rbdir/icons", 0777;
337 copy("$viewer_bmpdir/viewers.${icon_w}x${icon_h}x$depth.bmp", "$rbdir/icons/viewers.bmp");
338 if ($remote_depth) {
339 copy("$viewer_bmpdir/remote_viewers.${remote_icon_w}x${remote_icon_h}x$remote_depth.bmp", "$rbdir/icons/remote_viewers.bmp");
343 copy("$ROOT/apps/tagnavi.config", "$rbdir/");
344 copy("$ROOT/apps/plugins/disktidy.config", "$rbdir/rocks/apps/");
346 if($bitmap) {
347 copy("$ROOT/apps/plugins/sokoban.levels", "$rbdir/rocks/games/sokoban.levels"); # sokoban levels
348 copy("$ROOT/apps/plugins/snake2.levels", "$rbdir/rocks/games/snake2.levels"); # snake2 levels
351 if($image) {
352 # image is blank when this is a simulator
353 if( filesize("rockbox.ucl") > 1000 ) {
354 copy("rockbox.ucl", "$rbdir/rockbox.ucl"); # UCL for flashing
356 if( filesize("rombox.ucl") > 1000) {
357 copy("rombox.ucl", "$rbdir/rombox.ucl"); # UCL for flashing
360 # Check for rombox.target
361 if ($image=~/(.*)\.(\w+)$/)
363 my $romfile = "rombox.$2";
364 if (filesize($romfile) > 1000)
366 copy($romfile, "$rbdir/$romfile");
371 mkdir "$rbdir/docs", 0777;
372 for(("COPYING",
373 "LICENSES",
374 "KNOWN_ISSUES"
375 )) {
376 copy("$ROOT/docs/$_", "$rbdir/docs/$_.txt");
378 if ($fonts) {
379 copy("$ROOT/docs/profontdoc.txt", "$rbdir/docs/profontdoc.txt");
381 for(("sample.colours",
382 "sample.icons"
383 )) {
384 copy("$ROOT/docs/$_", "$rbdir/docs/$_");
387 # Now do the WPS dance
388 if(-d "$ROOT/wps") {
389 my $wps_build_cmd="perl $ROOT/wps/wpsbuild.pl ";
390 $wps_build_cmd=$wps_build_cmd."-v " if $verbose;
391 $wps_build_cmd=$wps_build_cmd." --rbdir=$rbdir -r $ROOT $ROOT/wps/WPSLIST $target";
392 print "wpsbuild: $wps_build_cmd\n" if $verbose;
393 system("$wps_build_cmd");
394 print "wps_build_cmd: done\n" if $verbose;
396 else {
397 print STDERR "No wps module present, can't do the WPS magic!\n";
400 # and the info file
401 copy("rockbox-info.txt", "$rbdir/rockbox-info.txt");
403 # copy the already built lng files
404 glob_copy('apps/lang/*lng', "$rbdir/langs/");
408 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
409 localtime(time);
411 $mon+=1;
412 $year+=1900;
414 #$date=sprintf("%04d%02d%02d", $year,$mon, $mday);
415 #$shortdate=sprintf("%02d%02d%02d", $year%100,$mon, $mday);
417 # made once for all targets
418 sub runone {
419 my ($target, $fonts)=@_;
421 # build a full install .rockbox ($rbdir) directory
422 buildzip($target, $fonts);
424 unlink($output);
426 if($fonts == 1) {
427 # Don't include image file in fonts-only package
428 undef $target;
430 if($target && ($target !~ /(mod|ajz|wma)\z/i)) {
431 # On some targets, the image goes into .rockbox.
432 copy("$target", "$rbdir/$target");
433 undef $target;
436 if($verbose) {
437 print "$ziptool $output $rbdir $target >/dev/null\n";
440 if($sim) {
441 system("cp -r $rbdir simdisk/ >/dev/null");
443 else {
444 system("$ziptool $output $rbdir $target >/dev/null");
447 # remove the $rbdir afterwards
448 rmtree($rbdir);
451 if(!$exe) {
452 # not specified, guess!
453 if($target =~ /(recorder|ondio)/i) {
454 $exe = "ajbrec.ajz";
456 elsif($target =~ /iriver/i) {
457 $exe = "rockbox.iriver";
459 else {
460 $exe = "archos.mod";
463 elsif($exe =~ /rockboxui/) {
464 # simulator, exclude the exe file
465 $exe = "";
468 runone($exe, $incfonts);