Correct added language file: add to sources and set keywords
[maemo-rb.git] / tools / buildzip.pl
blob4faa38ac54a38f7228eab1b03688dcab0830076d
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 buildzip {
158 my ($zip, $image, $fonts)=@_;
160 my ($bitmap, $depth, $icon_w, $icon_h, $recording, $swcodec,
161 $remote_depth, $remote_icon_w, $remote_icon_h) = &gettargetinfo();
163 # print "Bitmap: $bitmap\nDepth: $depth\nSwcodec: $swcodec\n";
165 # remove old traces
166 `rm -rf .rockbox`;
168 mkdir ".rockbox", 0777;
170 if(!$bitmap) {
171 # always disable fonts on non-bitmap targets
172 $fonts = 0;
174 # create the file so the database does not try indexing a folder
175 `touch .rockbox/database.ignore`;
177 if($fonts) {
178 mkdir ".rockbox/fonts", 0777;
180 opendir(DIR, "$ROOT/fonts") || die "can't open dir fonts";
181 my @fonts = grep { /\.bdf$/ && -f "$ROOT/fonts/$_" } readdir(DIR);
182 closedir DIR;
184 for(@fonts) {
185 my $f = $_;
187 print "FONT: $f\n" if($verbose);
188 my $o = $f;
189 $o =~ s/\.bdf/\.fnt/;
190 my $cmd ="$ROOT/tools/convbdf -f -o \".rockbox/fonts/$o\" \"$ROOT/fonts/$f\" >/dev/null 2>&1";
191 print "CMD: $cmd\n" if($verbose);
192 `$cmd`;
195 if($fonts < 2) {
196 # fonts-only package, return
197 return;
201 mkdir ".rockbox/langs", 0777;
202 mkdir ".rockbox/rocks", 0777;
203 mkdir ".rockbox/rocks/games", 0777;
204 mkdir ".rockbox/rocks/apps", 0777;
205 mkdir ".rockbox/rocks/demos", 0777;
206 mkdir ".rockbox/rocks/viewers", 0777;
208 if ($recording) {
209 mkdir ".rockbox/recpresets", 0777;
212 if($swcodec) {
213 mkdir ".rockbox/eqs", 0777;
215 `cp $ROOT/apps/eqs/*.cfg .rockbox/eqs/`; # equalizer presets
218 mkdir ".rockbox/wps", 0777;
219 mkdir ".rockbox/themes", 0777;
220 if ($bitmap) {
221 open(THEME, ">.rockbox/themes/rockbox_default_icons.cfg");
222 print THEME <<STOP
223 # this config file was auto-generated to make it
224 # easy to reset the icons back to default
225 iconset: -
226 # taken from apps/gui/icon.c
227 viewers iconset: /.rockbox/icons/viewers.bmp
228 remote iconset: -
229 # taken from apps/gui/icon.c
230 remote viewers iconset: /.rockbox/icons/remote_viewers.bmp
232 STOP
234 close(THEME);
237 mkdir ".rockbox/codepages", 0777;
239 if($bitmap) {
240 system("$ROOT/tools/codepages");
242 else {
243 system("$ROOT/tools/codepages -m");
245 $c = 'find . -name "*.cp" ! -empty -exec mv {} .rockbox/codepages/ \; >/dev/null 2>&1';
246 `$c`;
248 if($bitmap) {
249 mkdir ".rockbox/codecs", 0777;
250 if($depth > 1) {
251 mkdir ".rockbox/backdrops", 0777;
254 my $c = 'find apps -name "*.codec" ! -empty -exec cp {} .rockbox/codecs/ \; 2>/dev/null';
255 `$c`;
257 my @call = `find .rockbox/codecs -type f 2>/dev/null`;
258 if(!$call[0]) {
259 # no codec was copied, remove directory again
260 rmdir(".rockbox/codecs");
265 $c= 'find apps "(" -name "*.rock" -o -name "*.ovl" ")" ! -empty -exec cp {} .rockbox/rocks/ \;';
266 print `$c`;
268 open VIEWERS, "$ROOT/apps/plugins/viewers.config" or
269 die "can't open viewers.config";
270 @viewers = <VIEWERS>;
271 close VIEWERS;
273 open VIEWERS, ">.rockbox/viewers.config" or
274 die "can't create .rockbox/viewers.config";
276 foreach my $line (@viewers) {
277 if ($line =~ /([^,]*),([^,]*),/) {
278 my ($ext, $plugin)=($1, $2);
279 my $r = "${plugin}.rock";
280 my $oname;
282 my $dir = $r;
283 my $name;
285 # strip off the last slash and file name part
286 $dir =~ s/(.*)\/(.*)/$1/;
287 # store the file name part
288 $name = $2;
290 # get .ovl name (file part only)
291 $oname = $name;
292 $oname =~ s/\.rock$/.ovl/;
294 # print STDERR "$ext $plugin $dir $name $r\n";
296 if(-e ".rockbox/rocks/$name") {
297 if($dir ne "rocks") {
298 # target is not 'rocks' but the plugins are always in that
299 # dir at first!
300 `mv .rockbox/rocks/$name .rockbox/rocks/$r`;
302 print VIEWERS $line;
304 elsif(-e ".rockbox/rocks/$r") {
305 # in case the same plugin works for multiple extensions, it
306 # was already moved to the viewers dir
307 print VIEWERS $line;
310 if(-e ".rockbox/rocks/$oname") {
311 # if there's an "overlay" file for the .rock, move that as
312 # well
313 `mv .rockbox/rocks/$oname .rockbox/rocks/$dir`;
317 close VIEWERS;
319 open CATEGORIES, "$ROOT/apps/plugins/CATEGORIES" or
320 die "can't open CATEGORIES";
321 @rock_targetdirs = <CATEGORIES>;
322 close CATEGORIES;
323 foreach my $line (@rock_targetdirs) {
324 if ($line =~ /([^,]*),(.*)/) {
325 my ($plugin, $dir)=($1, $2);
326 `mv .rockbox/rocks/${plugin}.rock .rockbox/rocks/$dir 2> /dev/null`;
330 if ($bitmap) {
331 mkdir ".rockbox/icons", 0777;
332 `cp $viewer_bmpdir/viewers.${icon_w}x${icon_h}x$depth.bmp .rockbox/icons/viewers.bmp`;
333 if ($remote_depth) {
334 `cp $viewer_bmpdir/remote_viewers.${remote_icon_w}x${remote_icon_h}x$remote_depth.bmp .rockbox/icons/remote_viewers.bmp`;
338 `cp $ROOT/apps/tagnavi.config .rockbox/`;
340 if($bitmap) {
341 `cp $ROOT/apps/plugins/sokoban.levels .rockbox/rocks/games/`; # sokoban levels
342 `cp $ROOT/apps/plugins/snake2.levels .rockbox/rocks/games/`; # snake2 levels
345 if($image) {
346 # image is blank when this is a simulator
347 if( filesize("rockbox.ucl") > 1000 ) {
348 `cp rockbox.ucl .rockbox/`; # UCL for flashing
350 if( filesize("rombox.ucl") > 1000) {
351 `cp rombox.ucl .rockbox/`; # UCL for flashing
354 # Check for rombox.target
355 if ($image=~/(.*)\.(\w+)$/)
357 my $romfile = "rombox.$2";
358 if (filesize($romfile) > 1000)
360 `cp $romfile .rockbox/`;
365 mkdir ".rockbox/docs", 0777;
366 for(("COPYING",
367 "LICENSES",
368 "KNOWN_ISSUES"
369 )) {
370 `cp $ROOT/docs/$_ .rockbox/docs/$_.txt`;
372 if ($fonts) {
373 `cp $ROOT/docs/profontdoc.txt .rockbox/docs/`;
375 for(("sample.colours",
376 "sample.icons"
377 )) {
378 `cp $ROOT/docs/$_ .rockbox/docs/`;
381 # Now do the WPS dance
382 if(-d "$ROOT/wps") {
383 system("perl $ROOT/wps/wpsbuild.pl -r $ROOT $ROOT/wps/WPSLIST $target");
385 else {
386 print STDERR "No wps module present, can't do the WPS magic!\n";
389 # and the info file
390 system("cp rockbox-info.txt .rockbox/");
392 # copy the already built lng files
393 `cp apps/lang/*lng .rockbox/langs/`
397 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
398 localtime(time);
400 $mon+=1;
401 $year+=1900;
403 #$date=sprintf("%04d%02d%02d", $year,$mon, $mday);
404 #$shortdate=sprintf("%02d%02d%02d", $year%100,$mon, $mday);
406 # made once for all targets
407 sub runone {
408 my ($target, $fonts)=@_;
410 # build a full install .rockbox directory
411 buildzip($output, $target, $fonts);
413 # create a zip file from the .rockbox dfir
415 `rm -f $output`;
416 if($verbose) {
417 print "find .rockbox | xargs $ziptool $output >/dev/null\n";
419 `find .rockbox | xargs $ziptool $output >/dev/null`;
421 if($target && ($fonts != 1)) {
422 # On some targets, rockbox.* is inside .rockbox
423 if($target !~ /(mod|ajz|wma)\z/i) {
424 `cp $target .rockbox/$target`;
425 $target = ".rockbox/".$target;
428 if($verbose) {
429 print "$ziptool $output $target\n";
431 `$ziptool $output $target`;
434 # remove the .rockbox afterwards
435 `rm -rf .rockbox`;
438 if(!$exe) {
439 # not specified, guess!
440 if($target =~ /(recorder|ondio)/i) {
441 $exe = "ajbrec.ajz";
443 elsif($target =~ /iriver/i) {
444 $exe = "rockbox.iriver";
446 else {
447 $exe = "archos.mod";
450 elsif($exe =~ /rockboxui/) {
451 # simulator, exclude the exe file
452 $exe = "";
455 runone($exe, $incfonts);