A patch by Robert Keevil that's been in the tracker way to long, fixes FS #6213:...
[Rockbox.git] / tools / buildzip.pl
blob8c78b82170a3a9bb076fd5b7c854e5eb0c1229cf
1 #!/usr/bin/perl
2 # __________ __ ___.
3 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 # \/ \/ \/ \/ \/
8 # $Id$
11 $ROOT="..";
13 my $ziptool="zip";
14 my $output="rockbox.zip";
15 my $verbose;
16 my $exe;
17 my $target;
18 my $archos;
19 my $incfonts;
21 while(1) {
22 if($ARGV[0] eq "-r") {
23 $ROOT=$ARGV[1];
24 shift @ARGV;
25 shift @ARGV;
28 elsif($ARGV[0] eq "-z") {
29 $ziptool=$ARGV[1];
30 shift @ARGV;
31 shift @ARGV;
34 elsif($ARGV[0] eq "-t") {
35 # The target name as used in ARCHOS in the root makefile
36 $archos=$ARGV[1];
37 shift @ARGV;
38 shift @ARGV;
40 elsif($ARGV[0] eq "-o") {
41 $output=$ARGV[1];
42 shift @ARGV;
43 shift @ARGV;
45 elsif($ARGV[0] eq "-f") {
46 $incfonts=$ARGV[1]; # 0 - no fonts, 1 - fonts only 2 - fonts and package
47 shift @ARGV;
48 shift @ARGV;
51 elsif($ARGV[0] eq "-v") {
52 $verbose =1;
53 shift @ARGV;
55 else {
56 $target = $ARGV[0];
57 $exe = $ARGV[1];
58 last;
63 my $firmdir="$ROOT/firmware";
64 my $appsdir="$ROOT/apps";
65 my $viewer_bmpdir="$ROOT/apps/plugins/bitmaps/viewer_defaults";
67 my $cppdef = $target;
69 sub gettargetinfo {
70 open(GCC, ">gcctemp");
71 # Get the LCD screen depth and graphical status
72 print GCC <<STOP
73 \#include "config.h"
74 #ifdef HAVE_LCD_BITMAP
75 Bitmap: yes
76 Depth: LCD_DEPTH
77 Icon Width: CONFIG_DEFAULT_ICON_WIDTH
78 Icon Height: CONFIG_DEFAULT_ICON_HEIGHT
79 #endif
80 Codec: CONFIG_CODEC
81 #ifdef HAVE_REMOTE_LCD
82 Remote Depth: LCD_REMOTE_DEPTH
83 Remote Icon Width: CONFIG_REMOTE_DEFAULT_ICON_WIDTH
84 Remote Icon Height: CONFIG_REMOTE_DEFAULT_ICON_HEIGHT
85 #else
86 Remote Depth: 0
87 #endif
88 #ifdef HAVE_RECORDING
89 Recording: yes
90 #endif
91 STOP
93 close(GCC);
95 my $c="cat gcctemp | gcc $cppdef -I. -I$firmdir/export -E -P -";
97 # print STDERR "CMD $c\n";
99 open(TARGET, "$c|");
101 my ($bitmap, $depth, $swcodec, $icon_h, $icon_w);
102 my ($remote_depth, $remote_icon_h, $remote_icon_w);
103 my ($recording);
104 $icon_count = 1;
105 while(<TARGET>) {
106 # print STDERR "DATA: $_";
107 if($_ =~ /^Bitmap: (.*)/) {
108 $bitmap = $1;
110 elsif($_ =~ /^Depth: (\d*)/) {
111 $depth = $1;
113 elsif($_ =~ /^Icon Width: (\d*)/) {
114 $icon_w = $1;
116 elsif($_ =~ /^Icon Height: (\d*)/) {
117 $icon_h = $1;
119 elsif($_ =~ /^Codec: (\d*)/) {
120 # SWCODEC is 1, the others are HWCODEC
121 $swcodec = ($1 == 1);
123 elsif($_ =~ /^Remote Depth: (\d*)/) {
124 $remote_depth = $1;
126 elsif($_ =~ /^Remote Icon Width: (\d*)/) {
127 $remote_icon_w = $1;
129 elsif($_ =~ /^Remote Icon Height: (\d*)/) {
130 $remote_icon_h = $1;
132 if($_ =~ /^Recording: (.*)/) {
133 $recording = $1;
136 close(TARGET);
137 unlink("gcctemp");
139 return ($bitmap, $depth, $icon_w, $icon_h, $recording,
140 $swcodec, $remote_depth, $remote_icon_w, $remote_icon_h);
143 sub filesize {
144 my ($filename)=@_;
145 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
146 $atime,$mtime,$ctime,$blksize,$blocks)
147 = stat($filename);
148 return $size;
151 sub buildlangs {
152 my ($outputlang)=@_;
153 my $dir = "$ROOT/apps/lang";
154 opendir(DIR, $dir);
155 my @files = grep { /\.lang$/ } readdir(DIR);
156 closedir(DIR);
158 for(@files) {
159 my $output = $_;
160 $output =~ s/(.*)\.lang/$1.lng/;
161 print "$ROOT/tools/genlang -e=$dir/english.lang -t=$archos -b=$outputlang/$output $dir/$_\n" if($verbose);
162 system ("$ROOT/tools/genlang -e=$dir/english.lang -t=$archos -b=$outputlang/$output $dir/$_ >/dev/null 2>&1");
166 sub buildzip {
167 my ($zip, $image, $fonts)=@_;
169 my ($bitmap, $depth, $icon_w, $icon_h, $recording, $swcodec,
170 $remote_depth, $remote_icon_w, $remote_icon_h) = &gettargetinfo();
172 # print "Bitmap: $bitmap\nDepth: $depth\nSwcodec: $swcodec\n";
174 # remove old traces
175 `rm -rf .rockbox`;
177 mkdir ".rockbox", 0777;
179 if(!$bitmap) {
180 # always disable fonts on non-bitmap targets
181 $fonts = 0;
184 if($fonts) {
185 mkdir ".rockbox/fonts", 0777;
187 opendir(DIR, "$ROOT/fonts") || die "can't open dir fonts";
188 my @fonts = grep { /\.bdf$/ && -f "$ROOT/fonts/$_" } readdir(DIR);
189 closedir DIR;
191 for(@fonts) {
192 my $f = $_;
194 print "FONT: $f\n" if($verbose);
195 my $o = $f;
196 $o =~ s/\.bdf/\.fnt/;
197 my $cmd ="$ROOT/tools/convbdf -f -o \".rockbox/fonts/$o\" \"$ROOT/fonts/$f\" >/dev/null 2>&1";
198 print "CMD: $cmd\n" if($verbose);
199 `$cmd`;
202 if($fonts < 2) {
203 # fonts-only package, return
204 return;
208 mkdir ".rockbox/langs", 0777;
209 mkdir ".rockbox/rocks", 0777;
210 if ($recording) {
211 mkdir ".rockbox/recpresets", 0777;
214 if($swcodec) {
215 mkdir ".rockbox/eqs", 0777;
217 `cp $ROOT/apps/eqs/*.cfg .rockbox/eqs/`; # equalizer presets
220 mkdir ".rockbox/wps", 0777;
221 mkdir ".rockbox/themes", 0777;
222 if ($bitmap) {
223 open(THEME, ">.rockbox/themes/rockbox_default_icons.cfg");
224 print THEME <<STOP
225 # this config file was auto-generated to make it
226 # easy to reset the icons back to default
227 iconset: -
228 # taken from apps/gui/icon.c
229 viewers iconset: /.rockbox/icons/viewers.bmp
230 remote iconset: -
231 # taken from apps/gui/icon.c
232 remote viewers iconset: /.rockbox/icons/remote_viewers.bmp
234 STOP
236 close(THEME);
239 mkdir ".rockbox/codepages", 0777;
241 if($bitmap) {
242 system("$ROOT/tools/codepages");
244 else {
245 system("$ROOT/tools/codepages -m");
247 $c = 'find . -name "*.cp" ! -empty -exec mv {} .rockbox/codepages/ \; >/dev/null 2>&1';
248 `$c`;
250 if($bitmap) {
251 mkdir ".rockbox/codecs", 0777;
252 if($depth > 1) {
253 mkdir ".rockbox/backdrops", 0777;
256 my $c = 'find apps -name "*.codec" ! -empty -exec cp {} .rockbox/codecs/ \; 2>/dev/null';
257 `$c`;
259 my @call = `find .rockbox/codecs -type f 2>/dev/null`;
260 if(!$call[0]) {
261 # no codec was copied, remove directory again
262 rmdir(".rockbox/codecs");
267 $c= 'find apps "(" -name "*.rock" -o -name "*.ovl" ")" ! -empty -exec cp {} .rockbox/rocks/ \;';
268 print `$c`;
270 open VIEWERS, "$ROOT/apps/plugins/viewers.config" or
271 die "can't open viewers.config";
272 @viewers = <VIEWERS>;
273 close VIEWERS;
275 open VIEWERS, ">.rockbox/viewers.config" or
276 die "can't create .rockbox/viewers.config";
277 mkdir ".rockbox/viewers", 0777;
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 ".rockbox/rocks/$name") {
299 if($dir ne "rocks") {
300 # target is not 'rocks' but the plugins are always in that
301 # dir at first!
302 `mv .rockbox/rocks/$name .rockbox/$r`;
304 print VIEWERS $line;
306 elsif(-e ".rockbox/$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 ".rockbox/rocks/$oname") {
313 # if there's an "overlay" file for the .rock, move that as
314 # well
315 `mv .rockbox/rocks/$oname .rockbox/$dir`;
319 close VIEWERS;
321 if ($bitmap) {
322 mkdir ".rockbox/icons", 0777;
323 `cp $viewer_bmpdir/viewers.${icon_w}x${icon_h}x$depth.bmp .rockbox/icons/viewers.bmp`;
324 if ($remote_depth) {
325 `cp $viewer_bmpdir/remote_viewers.${remote_icon_w}x${remote_icon_h}x$remote_depth.bmp .rockbox/icons/remote_viewers.bmp`;
329 `cp $ROOT/apps/tagnavi.config .rockbox/`;
331 if($bitmap) {
332 `cp $ROOT/apps/plugins/sokoban.levels .rockbox/rocks/`; # sokoban levels
333 `cp $ROOT/apps/plugins/snake2.levels .rockbox/rocks/`; # snake2 levels
336 if($image) {
337 # image is blank when this is a simulator
338 if( filesize("rockbox.ucl") > 1000 ) {
339 `cp rockbox.ucl .rockbox/`; # UCL for flashing
341 if( filesize("rombox.ucl") > 1000) {
342 `cp rombox.ucl .rockbox/`; # UCL for flashing
345 # Check for rombox.target
346 if ($image=~/(.*)\.(\w+)$/)
348 my $romfile = "rombox.$2";
349 if (filesize($romfile) > 1000)
351 `cp $romfile .rockbox/`;
356 mkdir ".rockbox/docs", 0777;
357 for(("COPYING",
358 "LICENSES",
359 "KNOWN_ISSUES"
360 )) {
361 `cp $ROOT/docs/$_ .rockbox/docs/$_.txt`;
363 if ($fonts) {
364 `cp $ROOT/docs/profontdoc.txt .rockbox/docs/`;
366 for(("sample.colours",
367 "sample.icons"
368 )) {
369 `cp $ROOT/docs/$_ .rockbox/docs/`;
372 # Now do the WPS dance
373 if(-d "$ROOT/wps") {
374 system("perl $ROOT/wps/wpsbuild.pl -r $ROOT $ROOT/wps/WPSLIST $target");
376 else {
377 print STDERR "No wps module present, can't do the WPS magic!\n";
380 # and the info file
381 system("cp rockbox-info.txt .rockbox/");
383 # now copy the file made for reading on the unit:
384 #if($notplayer) {
385 # `cp $webroot/docs/Help-JBR.txt .rockbox/docs/`;
387 #else {
388 # `cp $webroot/docs/Help-Stu.txt .rockbox/docs/`;
391 buildlangs(".rockbox/langs");
395 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
396 localtime(time);
398 $mon+=1;
399 $year+=1900;
401 #$date=sprintf("%04d%02d%02d", $year,$mon, $mday);
402 #$shortdate=sprintf("%02d%02d%02d", $year%100,$mon, $mday);
404 # made once for all targets
405 sub runone {
406 my ($target, $fonts)=@_;
408 # build a full install .rockbox directory
409 buildzip($output, $target, $fonts);
411 # create a zip file from the .rockbox dfir
413 `rm -f $output`;
414 if($verbose) {
415 print "find .rockbox | xargs $ziptool $output >/dev/null\n";
417 `find .rockbox | xargs $ziptool $output >/dev/null`;
419 if($target && ($fonts != 1)) {
420 # On some targets, rockbox.* is inside .rockbox
421 if($target !~ /(mod|ajz|wma)\z/i) {
422 `cp $target .rockbox/$target`;
423 $target = ".rockbox/".$target;
426 if($verbose) {
427 print "$ziptool $output $target\n";
429 `$ziptool $output $target`;
432 # remove the .rockbox afterwards
433 `rm -rf .rockbox`;
436 if(!$exe) {
437 # not specified, guess!
438 if($target =~ /(recorder|ondio)/i) {
439 $exe = "ajbrec.ajz";
441 elsif($target =~ /iriver/i) {
442 $exe = "rockbox.iriver";
444 else {
445 $exe = "archos.mod";
448 elsif($exe =~ /rockboxui/) {
449 # simulator, exclude the exe file
450 $exe = "";
453 runone($exe, $incfonts);