Minor cleanup
[Rockbox.git] / tools / buildzip.pl
blobe384eb8bd73c7272098de93783c2aa4726124ee0
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 "-i") {
41 # The target id name as used in TARGET_ID in the root makefile
42 $target_id=$ARGV[1];
43 shift @ARGV;
44 shift @ARGV;
46 elsif($ARGV[0] eq "-o") {
47 $output=$ARGV[1];
48 shift @ARGV;
49 shift @ARGV;
51 elsif($ARGV[0] eq "-f") {
52 $incfonts=$ARGV[1]; # 0 - no fonts, 1 - fonts only 2 - fonts and package
53 shift @ARGV;
54 shift @ARGV;
57 elsif($ARGV[0] eq "-v") {
58 $verbose =1;
59 shift @ARGV;
61 else {
62 $target = $ARGV[0];
63 $exe = $ARGV[1];
64 last;
69 my $firmdir="$ROOT/firmware";
70 my $appsdir="$ROOT/apps";
71 my $viewer_bmpdir="$ROOT/apps/plugins/bitmaps/viewer_defaults";
73 my $cppdef = $target;
75 sub gettargetinfo {
76 open(GCC, ">gcctemp");
77 # Get the LCD screen depth and graphical status
78 print GCC <<STOP
79 \#include "config.h"
80 #ifdef HAVE_LCD_BITMAP
81 Bitmap: yes
82 Depth: LCD_DEPTH
83 Icon Width: CONFIG_DEFAULT_ICON_WIDTH
84 Icon Height: CONFIG_DEFAULT_ICON_HEIGHT
85 #endif
86 Codec: CONFIG_CODEC
87 #ifdef HAVE_REMOTE_LCD
88 Remote Depth: LCD_REMOTE_DEPTH
89 Remote Icon Width: CONFIG_REMOTE_DEFAULT_ICON_WIDTH
90 Remote Icon Height: CONFIG_REMOTE_DEFAULT_ICON_HEIGHT
91 #else
92 Remote Depth: 0
93 #endif
94 #ifdef HAVE_RECORDING
95 Recording: yes
96 #endif
97 STOP
99 close(GCC);
101 my $c="cat gcctemp | gcc $cppdef -I. -I$firmdir/export -E -P -";
103 # print STDERR "CMD $c\n";
105 open(TARGET, "$c|");
107 my ($bitmap, $depth, $swcodec, $icon_h, $icon_w);
108 my ($remote_depth, $remote_icon_h, $remote_icon_w);
109 my ($recording);
110 $icon_count = 1;
111 while(<TARGET>) {
112 # print STDERR "DATA: $_";
113 if($_ =~ /^Bitmap: (.*)/) {
114 $bitmap = $1;
116 elsif($_ =~ /^Depth: (\d*)/) {
117 $depth = $1;
119 elsif($_ =~ /^Icon Width: (\d*)/) {
120 $icon_w = $1;
122 elsif($_ =~ /^Icon Height: (\d*)/) {
123 $icon_h = $1;
125 elsif($_ =~ /^Codec: (\d*)/) {
126 # SWCODEC is 1, the others are HWCODEC
127 $swcodec = ($1 == 1);
129 elsif($_ =~ /^Remote Depth: (\d*)/) {
130 $remote_depth = $1;
132 elsif($_ =~ /^Remote Icon Width: (\d*)/) {
133 $remote_icon_w = $1;
135 elsif($_ =~ /^Remote Icon Height: (\d*)/) {
136 $remote_icon_h = $1;
138 if($_ =~ /^Recording: (.*)/) {
139 $recording = $1;
142 close(TARGET);
143 unlink("gcctemp");
145 return ($bitmap, $depth, $icon_w, $icon_h, $recording,
146 $swcodec, $remote_depth, $remote_icon_w, $remote_icon_h);
149 sub filesize {
150 my ($filename)=@_;
151 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
152 $atime,$mtime,$ctime,$blksize,$blocks)
153 = stat($filename);
154 return $size;
157 sub buildlangs {
158 my ($outputlang)=@_;
159 my $dir = "$ROOT/apps/lang";
160 opendir(DIR, $dir);
161 my @files = grep { /\.lang$/ } readdir(DIR);
162 closedir(DIR);
164 for(@files) {
165 my $output = $_;
166 $output =~ s/(.*)\.lang/$1.lng/;
167 print "$ROOT/tools/genlang -e=$dir/english.lang -t=$archos -i=$target_id -b=$outputlang/$output $dir/$_\n" if($verbose);
168 system ("$ROOT/tools/genlang -e=$dir/english.lang -t=$archos -i=$target_id -b=$outputlang/$output $dir/$_ >/dev/null 2>&1");
172 sub buildzip {
173 my ($zip, $image, $fonts)=@_;
175 my ($bitmap, $depth, $icon_w, $icon_h, $recording, $swcodec,
176 $remote_depth, $remote_icon_w, $remote_icon_h) = &gettargetinfo();
178 # print "Bitmap: $bitmap\nDepth: $depth\nSwcodec: $swcodec\n";
180 # remove old traces
181 `rm -rf .rockbox`;
183 mkdir ".rockbox", 0777;
185 if(!$bitmap) {
186 # always disable fonts on non-bitmap targets
187 $fonts = 0;
190 if($fonts) {
191 mkdir ".rockbox/fonts", 0777;
193 opendir(DIR, "$ROOT/fonts") || die "can't open dir fonts";
194 my @fonts = grep { /\.bdf$/ && -f "$ROOT/fonts/$_" } readdir(DIR);
195 closedir DIR;
197 for(@fonts) {
198 my $f = $_;
200 print "FONT: $f\n" if($verbose);
201 my $o = $f;
202 $o =~ s/\.bdf/\.fnt/;
203 my $cmd ="$ROOT/tools/convbdf -f -o \".rockbox/fonts/$o\" \"$ROOT/fonts/$f\" >/dev/null 2>&1";
204 print "CMD: $cmd\n" if($verbose);
205 `$cmd`;
208 if($fonts < 2) {
209 # fonts-only package, return
210 return;
214 mkdir ".rockbox/langs", 0777;
215 mkdir ".rockbox/rocks", 0777;
216 mkdir ".rockbox/rocks/games", 0777;
217 mkdir ".rockbox/rocks/apps", 0777;
218 mkdir ".rockbox/rocks/demos", 0777;
219 mkdir ".rockbox/rocks/viewers", 0777;
221 if ($recording) {
222 mkdir ".rockbox/recpresets", 0777;
225 if($swcodec) {
226 mkdir ".rockbox/eqs", 0777;
228 `cp $ROOT/apps/eqs/*.cfg .rockbox/eqs/`; # equalizer presets
231 mkdir ".rockbox/wps", 0777;
232 mkdir ".rockbox/themes", 0777;
233 if ($bitmap) {
234 open(THEME, ">.rockbox/themes/rockbox_default_icons.cfg");
235 print THEME <<STOP
236 # this config file was auto-generated to make it
237 # easy to reset the icons back to default
238 iconset: -
239 # taken from apps/gui/icon.c
240 viewers iconset: /.rockbox/icons/viewers.bmp
241 remote iconset: -
242 # taken from apps/gui/icon.c
243 remote viewers iconset: /.rockbox/icons/remote_viewers.bmp
245 STOP
247 close(THEME);
250 mkdir ".rockbox/codepages", 0777;
252 if($bitmap) {
253 system("$ROOT/tools/codepages");
255 else {
256 system("$ROOT/tools/codepages -m");
258 $c = 'find . -name "*.cp" ! -empty -exec mv {} .rockbox/codepages/ \; >/dev/null 2>&1';
259 `$c`;
261 if($bitmap) {
262 mkdir ".rockbox/codecs", 0777;
263 if($depth > 1) {
264 mkdir ".rockbox/backdrops", 0777;
267 my $c = 'find apps -name "*.codec" ! -empty -exec cp {} .rockbox/codecs/ \; 2>/dev/null';
268 `$c`;
270 my @call = `find .rockbox/codecs -type f 2>/dev/null`;
271 if(!$call[0]) {
272 # no codec was copied, remove directory again
273 rmdir(".rockbox/codecs");
278 $c= 'find apps "(" -name "*.rock" -o -name "*.ovl" ")" ! -empty -exec cp {} .rockbox/rocks/ \;';
279 print `$c`;
281 open VIEWERS, "$ROOT/apps/plugins/viewers.config" or
282 die "can't open viewers.config";
283 @viewers = <VIEWERS>;
284 close VIEWERS;
286 open VIEWERS, ">.rockbox/viewers.config" or
287 die "can't create .rockbox/viewers.config";
289 foreach my $line (@viewers) {
290 if ($line =~ /([^,]*),([^,]*),/) {
291 my ($ext, $plugin)=($1, $2);
292 my $r = "${plugin}.rock";
293 my $oname;
295 my $dir = $r;
296 my $name;
298 # strip off the last slash and file name part
299 $dir =~ s/(.*)\/(.*)/$1/;
300 # store the file name part
301 $name = $2;
303 # get .ovl name (file part only)
304 $oname = $name;
305 $oname =~ s/\.rock$/.ovl/;
307 # print STDERR "$ext $plugin $dir $name $r\n";
309 if(-e ".rockbox/rocks/$name") {
310 if($dir ne "rocks") {
311 # target is not 'rocks' but the plugins are always in that
312 # dir at first!
313 `mv .rockbox/rocks/$name .rockbox/rocks/$r`;
315 print VIEWERS $line;
317 elsif(-e ".rockbox/rocks/$r") {
318 # in case the same plugin works for multiple extensions, it
319 # was already moved to the viewers dir
320 print VIEWERS $line;
323 if(-e ".rockbox/rocks/$oname") {
324 # if there's an "overlay" file for the .rock, move that as
325 # well
326 `mv .rockbox/rocks/$oname .rockbox/rocks/$dir`;
330 close VIEWERS;
332 open CATEGORIES, "$ROOT/apps/plugins/CATEGORIES" or
333 die "can't open CATEGORIES";
334 @rock_targetdirs = <CATEGORIES>;
335 close CATEGORIES;
336 foreach my $line (@rock_targetdirs) {
337 if ($line =~ /([^,]*),(.*)/) {
338 my ($plugin, $dir)=($1, $2);
339 `mv .rockbox/rocks/${plugin}.rock .rockbox/rocks/$dir 2> /dev/null`;
343 if ($bitmap) {
344 mkdir ".rockbox/icons", 0777;
345 `cp $viewer_bmpdir/viewers.${icon_w}x${icon_h}x$depth.bmp .rockbox/icons/viewers.bmp`;
346 if ($remote_depth) {
347 `cp $viewer_bmpdir/remote_viewers.${remote_icon_w}x${remote_icon_h}x$remote_depth.bmp .rockbox/icons/remote_viewers.bmp`;
351 `cp $ROOT/apps/tagnavi.config .rockbox/`;
353 if($bitmap) {
354 `cp $ROOT/apps/plugins/sokoban.levels .rockbox/rocks/games/`; # sokoban levels
355 `cp $ROOT/apps/plugins/snake2.levels .rockbox/rocks/games/`; # snake2 levels
358 if($image) {
359 # image is blank when this is a simulator
360 if( filesize("rockbox.ucl") > 1000 ) {
361 `cp rockbox.ucl .rockbox/`; # UCL for flashing
363 if( filesize("rombox.ucl") > 1000) {
364 `cp rombox.ucl .rockbox/`; # UCL for flashing
367 # Check for rombox.target
368 if ($image=~/(.*)\.(\w+)$/)
370 my $romfile = "rombox.$2";
371 if (filesize($romfile) > 1000)
373 `cp $romfile .rockbox/`;
378 mkdir ".rockbox/docs", 0777;
379 for(("COPYING",
380 "LICENSES",
381 "KNOWN_ISSUES"
382 )) {
383 `cp $ROOT/docs/$_ .rockbox/docs/$_.txt`;
385 if ($fonts) {
386 `cp $ROOT/docs/profontdoc.txt .rockbox/docs/`;
388 for(("sample.colours",
389 "sample.icons"
390 )) {
391 `cp $ROOT/docs/$_ .rockbox/docs/`;
394 # Now do the WPS dance
395 if(-d "$ROOT/wps") {
396 system("perl $ROOT/wps/wpsbuild.pl -r $ROOT $ROOT/wps/WPSLIST $target");
398 else {
399 print STDERR "No wps module present, can't do the WPS magic!\n";
402 # and the info file
403 system("cp rockbox-info.txt .rockbox/");
405 # now copy the file made for reading on the unit:
406 #if($notplayer) {
407 # `cp $webroot/docs/Help-JBR.txt .rockbox/docs/`;
409 #else {
410 # `cp $webroot/docs/Help-Stu.txt .rockbox/docs/`;
413 buildlangs(".rockbox/langs");
417 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
418 localtime(time);
420 $mon+=1;
421 $year+=1900;
423 #$date=sprintf("%04d%02d%02d", $year,$mon, $mday);
424 #$shortdate=sprintf("%02d%02d%02d", $year%100,$mon, $mday);
426 # made once for all targets
427 sub runone {
428 my ($target, $fonts)=@_;
430 # build a full install .rockbox directory
431 buildzip($output, $target, $fonts);
433 # create a zip file from the .rockbox dfir
435 `rm -f $output`;
436 if($verbose) {
437 print "find .rockbox | xargs $ziptool $output >/dev/null\n";
439 `find .rockbox | xargs $ziptool $output >/dev/null`;
441 if($target && ($fonts != 1)) {
442 # On some targets, rockbox.* is inside .rockbox
443 if($target !~ /(mod|ajz|wma)\z/i) {
444 `cp $target .rockbox/$target`;
445 $target = ".rockbox/".$target;
448 if($verbose) {
449 print "$ziptool $output $target\n";
451 `$ziptool $output $target`;
454 # remove the .rockbox afterwards
455 `rm -rf .rockbox`;
458 if(!$exe) {
459 # not specified, guess!
460 if($target =~ /(recorder|ondio)/i) {
461 $exe = "ajbrec.ajz";
463 elsif($target =~ /iriver/i) {
464 $exe = "rockbox.iriver";
466 else {
467 $exe = "archos.mod";
470 elsif($exe =~ /rockboxui/) {
471 # simulator, exclude the exe file
472 $exe = "";
475 runone($exe, $incfonts);