Fix manuals, some of them were broken by r18469, by using the correct button macros...
[kugel-rb.git] / tools / buildzip.pl
blobe6ddab9b3dc46aab62ce8dfcb0d7852f1574f9a1
1 #!/usr/bin/perl
2 # __________ __ ___.
3 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 # \/ \/ \/ \/ \/
8 # $Id$
11 use File::Copy; # For move() and copy()
12 use File::Find; # For find()
13 use File::Path; # For rmtree()
14 use Cwd 'abs_path';
16 sub glob_copy {
17 my ($pattern, $destination) = @_;
18 foreach my $path (glob($pattern)) {
19 copy($path, $destination);
23 sub glob_move {
24 my ($pattern, $destination) = @_;
25 foreach my $path (glob($pattern)) {
26 move($path, $destination);
30 sub glob_unlink {
31 my ($pattern) = @_;
32 foreach my $path (glob($pattern)) {
33 unlink($path);
37 sub find_copyfile {
38 my ($pattern, $destination) = @_;
39 return sub {
40 $path = $_;
41 if ($path =~ $pattern && filesize($path) > 0 && !($path =~ /\.rockbox/)) {
42 copy($path, $destination);
43 chmod(0755, $destination.'/'.$path);
48 $ROOT="..";
50 my $ziptool="zip -r9";
51 my $output="rockbox.zip";
52 my $verbose;
53 my $exe;
54 my $target;
55 my $archos;
56 my $incfonts;
58 while(1) {
59 if($ARGV[0] eq "-r") {
60 $ROOT=$ARGV[1];
61 shift @ARGV;
62 shift @ARGV;
65 elsif($ARGV[0] eq "-z") {
66 $ziptool=$ARGV[1];
67 shift @ARGV;
68 shift @ARGV;
71 elsif($ARGV[0] eq "-t") {
72 # The target name as used in ARCHOS in the root makefile
73 $archos=$ARGV[1];
74 shift @ARGV;
75 shift @ARGV;
77 elsif($ARGV[0] eq "-i") {
78 # The target id name as used in TARGET_ID in the root makefile
79 $target_id=$ARGV[1];
80 shift @ARGV;
81 shift @ARGV;
83 elsif($ARGV[0] eq "-o") {
84 $output=$ARGV[1];
85 shift @ARGV;
86 shift @ARGV;
88 elsif($ARGV[0] eq "-f") {
89 $incfonts=$ARGV[1]; # 0 - no fonts, 1 - fonts only 2 - fonts and package
90 shift @ARGV;
91 shift @ARGV;
94 elsif($ARGV[0] eq "-v") {
95 $verbose =1;
96 shift @ARGV;
98 else {
99 $target = $ARGV[0];
100 $exe = $ARGV[1];
101 last;
106 my $firmdir="$ROOT/firmware";
107 my $appsdir="$ROOT/apps";
108 my $viewer_bmpdir="$ROOT/apps/plugins/bitmaps/viewer_defaults";
110 my $cppdef = $target;
112 sub gettargetinfo {
113 open(GCC, ">gcctemp");
114 # Get the LCD screen depth and graphical status
115 print GCC <<STOP
116 \#include "config.h"
117 #ifdef HAVE_LCD_BITMAP
118 Bitmap: yes
119 Depth: LCD_DEPTH
120 Icon Width: CONFIG_DEFAULT_ICON_WIDTH
121 Icon Height: CONFIG_DEFAULT_ICON_HEIGHT
122 #endif
123 Codec: CONFIG_CODEC
124 #ifdef HAVE_REMOTE_LCD
125 Remote Depth: LCD_REMOTE_DEPTH
126 Remote Icon Width: CONFIG_REMOTE_DEFAULT_ICON_WIDTH
127 Remote Icon Height: CONFIG_REMOTE_DEFAULT_ICON_HEIGHT
128 #else
129 Remote Depth: 0
130 #endif
131 #ifdef HAVE_RECORDING
132 Recording: yes
133 #endif
134 STOP
136 close(GCC);
138 my $c="cat gcctemp | gcc $cppdef -I. -I$firmdir/export -E -P -";
140 # print STDERR "CMD $c\n";
142 open(TARGET, "$c|");
144 my ($bitmap, $depth, $swcodec, $icon_h, $icon_w);
145 my ($remote_depth, $remote_icon_h, $remote_icon_w);
146 my ($recording);
147 $icon_count = 1;
148 while(<TARGET>) {
149 # print STDERR "DATA: $_";
150 if($_ =~ /^Bitmap: (.*)/) {
151 $bitmap = $1;
153 elsif($_ =~ /^Depth: (\d*)/) {
154 $depth = $1;
156 elsif($_ =~ /^Icon Width: (\d*)/) {
157 $icon_w = $1;
159 elsif($_ =~ /^Icon Height: (\d*)/) {
160 $icon_h = $1;
162 elsif($_ =~ /^Codec: (\d*)/) {
163 # SWCODEC is 1, the others are HWCODEC
164 $swcodec = ($1 == 1);
166 elsif($_ =~ /^Remote Depth: (\d*)/) {
167 $remote_depth = $1;
169 elsif($_ =~ /^Remote Icon Width: (\d*)/) {
170 $remote_icon_w = $1;
172 elsif($_ =~ /^Remote Icon Height: (\d*)/) {
173 $remote_icon_h = $1;
175 if($_ =~ /^Recording: (.*)/) {
176 $recording = $1;
179 close(TARGET);
180 unlink("gcctemp");
182 return ($bitmap, $depth, $icon_w, $icon_h, $recording,
183 $swcodec, $remote_depth, $remote_icon_w, $remote_icon_h);
186 sub filesize {
187 my ($filename)=@_;
188 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
189 $atime,$mtime,$ctime,$blksize,$blocks)
190 = stat($filename);
191 return $size;
194 sub buildzip {
195 my ($image, $fonts)=@_;
197 my ($bitmap, $depth, $icon_w, $icon_h, $recording, $swcodec,
198 $remote_depth, $remote_icon_w, $remote_icon_h) = &gettargetinfo();
200 # print "Bitmap: $bitmap\nDepth: $depth\nSwcodec: $swcodec\n";
202 # remove old traces
203 rmtree('.rockbox');
205 mkdir ".rockbox", 0777;
207 if(!$bitmap) {
208 # always disable fonts on non-bitmap targets
209 $fonts = 0;
211 if($fonts) {
212 mkdir ".rockbox/fonts", 0777;
213 chdir(".rockbox/fonts");
214 $cmd = "$ROOT/tools/convbdf -f $ROOT/fonts/*bdf >/dev/null 2>&1";
215 print($cmd."\n") if $verbose;
216 system($cmd);
217 chdir("../../");
219 if($fonts < 2) {
220 # fonts-only package, return
221 return;
225 # create the file so the database does not try indexing a folder
226 open(IGNORE, ">.rockbox/database.ignore") || die "can't open database.ignore";
227 close(IGNORE);
229 mkdir ".rockbox/langs", 0777;
230 mkdir ".rockbox/rocks", 0777;
231 mkdir ".rockbox/rocks/games", 0777;
232 mkdir ".rockbox/rocks/apps", 0777;
233 mkdir ".rockbox/rocks/demos", 0777;
234 mkdir ".rockbox/rocks/viewers", 0777;
236 if ($recording) {
237 mkdir ".rockbox/recpresets", 0777;
240 if($swcodec) {
241 mkdir ".rockbox/eqs", 0777;
243 glob_copy("$ROOT/apps/eqs/*.cfg", '.rockbox/eqs/'); # equalizer presets
246 mkdir ".rockbox/wps", 0777;
247 mkdir ".rockbox/themes", 0777;
248 if ($bitmap) {
249 open(THEME, ">.rockbox/themes/rockbox_default_icons.cfg");
250 print THEME <<STOP
251 # this config file was auto-generated to make it
252 # easy to reset the icons back to default
253 iconset: -
254 # taken from apps/gui/icon.c
255 viewers iconset: /.rockbox/icons/viewers.bmp
256 remote iconset: -
257 # taken from apps/gui/icon.c
258 remote viewers iconset: /.rockbox/icons/remote_viewers.bmp
260 STOP
262 close(THEME);
265 mkdir ".rockbox/codepages", 0777;
267 if($bitmap) {
268 system("$ROOT/tools/codepages");
270 else {
271 system("$ROOT/tools/codepages -m");
274 glob_move('*.cp', '.rockbox/codepages/');
276 if($bitmap) {
277 mkdir ".rockbox/codecs", 0777;
278 if($depth > 1) {
279 mkdir ".rockbox/backdrops", 0777;
282 find(find_copyfile(qr/.*\.codec/, abs_path('.rockbox/codecs/')), 'apps/codecs');
284 # remove directory again if no codec was copied
285 rmdir(".rockbox/codecs");
288 find(find_copyfile(qr/\.(rock|ovl)/, abs_path('.rockbox/rocks/')), 'apps/plugins');
290 open VIEWERS, "$ROOT/apps/plugins/viewers.config" or
291 die "can't open viewers.config";
292 @viewers = <VIEWERS>;
293 close VIEWERS;
295 open VIEWERS, ">.rockbox/viewers.config" or
296 die "can't create .rockbox/viewers.config";
298 foreach my $line (@viewers) {
299 if ($line =~ /([^,]*),([^,]*),/) {
300 my ($ext, $plugin)=($1, $2);
301 my $r = "${plugin}.rock";
302 my $oname;
304 my $dir = $r;
305 my $name;
307 # strip off the last slash and file name part
308 $dir =~ s/(.*)\/(.*)/$1/;
309 # store the file name part
310 $name = $2;
312 # get .ovl name (file part only)
313 $oname = $name;
314 $oname =~ s/\.rock$/.ovl/;
316 # print STDERR "$ext $plugin $dir $name $r\n";
318 if(-e ".rockbox/rocks/$name") {
319 if($dir ne "rocks") {
320 # target is not 'rocks' but the plugins are always in that
321 # dir at first!
322 move(".rockbox/rocks/$name", ".rockbox/rocks/$r");
324 print VIEWERS $line;
326 elsif(-e ".rockbox/rocks/$r") {
327 # in case the same plugin works for multiple extensions, it
328 # was already moved to the viewers dir
329 print VIEWERS $line;
332 if(-e ".rockbox/rocks/$oname") {
333 # if there's an "overlay" file for the .rock, move that as
334 # well
335 move(".rockbox/rocks/$oname", ".rockbox/rocks/$dir");
339 close VIEWERS;
341 open CATEGORIES, "$ROOT/apps/plugins/CATEGORIES" or
342 die "can't open CATEGORIES";
343 @rock_targetdirs = <CATEGORIES>;
344 close CATEGORIES;
345 foreach my $line (@rock_targetdirs) {
346 if ($line =~ /([^,]*),(.*)/) {
347 my ($plugin, $dir)=($1, $2);
348 move(".rockbox/rocks/${plugin}.rock", ".rockbox/rocks/$dir/${plugin}.rock");
352 if ($bitmap) {
353 mkdir ".rockbox/icons", 0777;
354 copy("$viewer_bmpdir/viewers.${icon_w}x${icon_h}x$depth.bmp", ".rockbox/icons/viewers.bmp");
355 if ($remote_depth) {
356 copy("$viewer_bmpdir/remote_viewers.${remote_icon_w}x${remote_icon_h}x$remote_depth.bmp", ".rockbox/icons/remote_viewers.bmp");
360 copy("$ROOT/apps/tagnavi.config", ".rockbox/");
361 copy("$ROOT/apps/plugins/disktidy.config", ".rockbox/rocks/apps/");
363 if($bitmap) {
364 copy("$ROOT/apps/plugins/sokoban.levels", ".rockbox/rocks/games/sokoban.levels"); # sokoban levels
365 copy("$ROOT/apps/plugins/snake2.levels", ".rockbox/rocks/games/snake2.levels"); # snake2 levels
368 if($image) {
369 # image is blank when this is a simulator
370 if( filesize("rockbox.ucl") > 1000 ) {
371 copy("rockbox.ucl", ".rockbox/rockbox.ucl"); # UCL for flashing
373 if( filesize("rombox.ucl") > 1000) {
374 copy("rombox.ucl", ".rockbox/rombox.ucl"); # UCL for flashing
377 # Check for rombox.target
378 if ($image=~/(.*)\.(\w+)$/)
380 my $romfile = "rombox.$2";
381 if (filesize($romfile) > 1000)
383 copy($romfile, ".rockbox/$romfile");
388 mkdir ".rockbox/docs", 0777;
389 for(("COPYING",
390 "LICENSES",
391 "KNOWN_ISSUES"
392 )) {
393 copy("$ROOT/docs/$_", ".rockbox/docs/$_.txt");
395 if ($fonts) {
396 copy("$ROOT/docs/profontdoc.txt", ".rockbox/docs/profontdoc.txt");
398 for(("sample.colours",
399 "sample.icons"
400 )) {
401 copy("$ROOT/docs/$_", ".rockbox/docs/$_");
404 # Now do the WPS dance
405 if(-d "$ROOT/wps") {
406 system("perl $ROOT/wps/wpsbuild.pl -r $ROOT $ROOT/wps/WPSLIST $target");
408 else {
409 print STDERR "No wps module present, can't do the WPS magic!\n";
412 # and the info file
413 copy("rockbox-info.txt", ".rockbox/rockbox-info.txt");
415 # copy the already built lng files
416 glob_copy('apps/lang/*lng', '.rockbox/langs/');
420 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
421 localtime(time);
423 $mon+=1;
424 $year+=1900;
426 #$date=sprintf("%04d%02d%02d", $year,$mon, $mday);
427 #$shortdate=sprintf("%02d%02d%02d", $year%100,$mon, $mday);
429 # made once for all targets
430 sub runone {
431 my ($target, $fonts)=@_;
433 # build a full install .rockbox directory
434 buildzip($target, $fonts);
436 unlink($output);
438 if($fonts == 1) {
439 # Don't include image file in fonts-only package
440 undef $target;
442 if($target && ($target !~ /(mod|ajz|wma)\z/i)) {
443 # On some targets, the image goes into .rockbox.
444 copy("$target", ".rockbox/$target");
445 undef $target;
448 if($verbose) {
449 print "$ziptool $output .rockbox $target >/dev/null\n";
451 system("$ziptool $output .rockbox $target >/dev/null");
453 # remove the .rockbox afterwards
454 rmtree('.rockbox');
457 if(!$exe) {
458 # not specified, guess!
459 if($target =~ /(recorder|ondio)/i) {
460 $exe = "ajbrec.ajz";
462 elsif($target =~ /iriver/i) {
463 $exe = "rockbox.iriver";
465 else {
466 $exe = "archos.mod";
469 elsif($exe =~ /rockboxui/) {
470 # simulator, exclude the exe file
471 $exe = "";
474 runone($exe, $incfonts);