sansapatcher needs _LARGEFILE64_SOURCE, so add this to the rbutil Makefile too.
[Rockbox.git] / tools / buildzip.pl
blob4beade77394070eddd83cf1a2a09841e3a1457e0
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 STOP
90 close(GCC);
92 my $c="cat gcctemp | gcc $cppdef -I. -I$firmdir/export -E -P -";
94 # print STDERR "CMD $c\n";
96 open(TARGET, "$c|");
98 my ($bitmap, $depth, $swcodec, $icon_h, $icon_w);
99 my ($remote_depth, $remote_icon_h, $remote_icon_w);
100 $icon_count = 1;
101 while(<TARGET>) {
102 # print STDERR "DATA: $_";
103 if($_ =~ /^Bitmap: (.*)/) {
104 $bitmap = $1;
106 elsif($_ =~ /^Depth: (\d*)/) {
107 $depth = $1;
109 elsif($_ =~ /^Icon Width: (\d*)/) {
110 $icon_w = $1;
112 elsif($_ =~ /^Icon Height: (\d*)/) {
113 $icon_h = $1;
115 elsif($_ =~ /^Codec: (\d*)/) {
116 # SWCODEC is 1, the others are HWCODEC
117 $swcodec = ($1 == 1);
119 elsif($_ =~ /^Remote Depth: (\d*)/) {
120 $remote_depth = $1;
122 elsif($_ =~ /^Remote Icon Width: (\d*)/) {
123 $remote_icon_w = $1;
125 elsif($_ =~ /^Remote Icon Height: (\d*)/) {
126 $remote_icon_h = $1;
129 close(TARGET);
130 unlink("gcctemp");
132 return ($bitmap, $depth, $icon_w, $icon_h,
133 $swcodec, $remote_depth, $remote_icon_w, $remote_icon_h);
136 sub filesize {
137 my ($filename)=@_;
138 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
139 $atime,$mtime,$ctime,$blksize,$blocks)
140 = stat($filename);
141 return $size;
144 sub buildlangs {
145 my ($outputlang)=@_;
146 my $dir = "$ROOT/apps/lang";
147 opendir(DIR, $dir);
148 my @files = grep { /\.lang$/ } readdir(DIR);
149 closedir(DIR);
151 for(@files) {
152 my $output = $_;
153 $output =~ s/(.*)\.lang/$1.lng/;
154 print "$ROOT/tools/genlang -e=$dir/english.lang -t=$archos -b=$outputlang/$output $dir/$_\n" if($verbose);
155 system ("$ROOT/tools/genlang -e=$dir/english.lang -t=$archos -b=$outputlang/$output $dir/$_ >/dev/null 2>&1");
159 sub buildzip {
160 my ($zip, $image, $fonts)=@_;
162 my ($bitmap, $depth, $icon_w, $icon_h, $swcodec,
163 $remote_depth, $remote_icon_w, $remote_icon_h) = &gettargetinfo();
165 # print "Bitmap: $bitmap\nDepth: $depth\nSwcodec: $swcodec\n";
167 # remove old traces
168 `rm -rf .rockbox`;
170 mkdir ".rockbox", 0777;
172 if(!$bitmap) {
173 # always disable fonts on non-bitmap targets
174 $fonts = 0;
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;
204 if($swcodec) {
205 mkdir ".rockbox/eqs", 0777;
207 `cp $ROOT/apps/eqs/*.cfg .rockbox/eqs/`; # equalizer presets
210 mkdir ".rockbox/wps", 0777;
211 mkdir ".rockbox/themes", 0777;
212 if ($bitmap) {
213 open(THEME, ">.rockbox/themes/rockbox_default_icons.cfg");
214 print THEME <<STOP
215 # this config file was auto-generated to make it
216 # easy to reset the icons back to default
217 iconset: -
218 # taken from apps/gui/icon.c
219 viewers iconset: /.rockbox/icons/viewers.bmp
220 remote iconset: -
221 # taken from apps/gui/icon.c
222 remote viewers iconset: /.rockbox/icons/remote_viewers.bmp
224 STOP
226 close(THEME);
229 mkdir ".rockbox/codepages", 0777;
231 if($bitmap) {
232 system("$ROOT/tools/codepages");
234 else {
235 system("$ROOT/tools/codepages -m");
237 $c = 'find . -name "*.cp" ! -empty -exec mv {} .rockbox/codepages/ \; >/dev/null 2>&1';
238 `$c`;
240 if($bitmap) {
241 mkdir ".rockbox/codecs", 0777;
242 if($depth > 1) {
243 mkdir ".rockbox/backdrops", 0777;
246 my $c = 'find apps -name "*.codec" ! -empty -exec cp {} .rockbox/codecs/ \; 2>/dev/null';
247 `$c`;
249 my @call = `find .rockbox/codecs -type f 2>/dev/null`;
250 if(!$call[0]) {
251 # no codec was copied, remove directory again
252 rmdir(".rockbox/codecs");
257 $c= 'find apps "(" -name "*.rock" -o -name "*.ovl" ")" ! -empty -exec cp {} .rockbox/rocks/ \;';
258 print `$c`;
260 open VIEWERS, "$ROOT/apps/plugins/viewers.config" or
261 die "can't open viewers.config";
262 @viewers = <VIEWERS>;
263 close VIEWERS;
265 open VIEWERS, ">.rockbox/viewers.config" or
266 die "can't create .rockbox/viewers.config";
267 mkdir ".rockbox/viewers", 0777;
268 foreach my $line (@viewers) {
269 if ($line =~ /([^,]*),([^,]*),/) {
270 my ($ext, $plugin)=($1, $2);
271 my $r = "${plugin}.rock";
272 my $oname;
274 my $dir = $r;
275 my $name;
277 # strip off the last slash and file name part
278 $dir =~ s/(.*)\/(.*)/$1/;
279 # store the file name part
280 $name = $2;
282 # get .ovl name (file part only)
283 $oname = $name;
284 $oname =~ s/\.rock$/.ovl/;
286 # print STDERR "$ext $plugin $dir $name $r\n";
288 if(-e ".rockbox/rocks/$name") {
289 if($dir ne "rocks") {
290 # target is not 'rocks' but the plugins are always in that
291 # dir at first!
292 `mv .rockbox/rocks/$name .rockbox/$r`;
294 print VIEWERS $line;
296 elsif(-e ".rockbox/$r") {
297 # in case the same plugin works for multiple extensions, it
298 # was already moved to the viewers dir
299 print VIEWERS $line;
302 if(-e ".rockbox/rocks/$oname") {
303 # if there's an "overlay" file for the .rock, move that as
304 # well
305 `mv .rockbox/rocks/$oname .rockbox/$dir`;
309 close VIEWERS;
311 if ($bitmap) {
312 mkdir ".rockbox/icons", 0777;
313 `cp $viewer_bmpdir/viewers.${icon_w}x${icon_h}x$depth.bmp .rockbox/icons/viewers.bmp`;
314 if ($remote_depth) {
315 `cp $viewer_bmpdir/remote_viewers.${remote_icon_w}x${remote_icon_h}x$remote_depth.bmp .rockbox/icons/remote_viewers.bmp`;
319 `cp $ROOT/apps/tagnavi.config .rockbox/`;
321 if($bitmap) {
322 `cp $ROOT/apps/plugins/sokoban.levels .rockbox/rocks/`; # sokoban levels
323 `cp $ROOT/apps/plugins/snake2.levels .rockbox/rocks/`; # snake2 levels
326 if($image) {
327 # image is blank when this is a simulator
328 if( filesize("rockbox.ucl") > 1000 ) {
329 `cp rockbox.ucl .rockbox/`; # UCL for flashing
331 if( filesize("rombox.ucl") > 1000) {
332 `cp rombox.ucl .rockbox/`; # UCL for flashing
335 # Check for rombox.target
336 if ($image=~/(.*)\.(\w+)$/)
338 my $romfile = "rombox.$2";
339 if (filesize($romfile) > 1000)
341 `cp $romfile .rockbox/`;
346 mkdir ".rockbox/docs", 0777;
347 for(("COPYING",
348 "LICENSES",
349 )) {
350 `cp $ROOT/docs/$_ .rockbox/docs/$_.txt`;
353 # Now do the WPS dance
354 if(-d "$ROOT/wps") {
355 system("perl $ROOT/wps/wpsbuild.pl -r $ROOT $ROOT/wps/WPSLIST $target");
357 else {
358 print STDERR "No wps module present, can't do the WPS magic!\n";
361 # and the info file
362 system("cp rockbox-info.txt .rockbox/");
364 # now copy the file made for reading on the unit:
365 #if($notplayer) {
366 # `cp $webroot/docs/Help-JBR.txt .rockbox/docs/`;
368 #else {
369 # `cp $webroot/docs/Help-Stu.txt .rockbox/docs/`;
372 buildlangs(".rockbox/langs");
376 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
377 localtime(time);
379 $mon+=1;
380 $year+=1900;
382 #$date=sprintf("%04d%02d%02d", $year,$mon, $mday);
383 #$shortdate=sprintf("%02d%02d%02d", $year%100,$mon, $mday);
385 # made once for all targets
386 sub runone {
387 my ($target, $fonts)=@_;
389 # build a full install .rockbox directory
390 buildzip($output, $target, $fonts);
392 # create a zip file from the .rockbox dfir
394 `rm -f $output`;
395 if($verbose) {
396 print "find .rockbox | xargs $ziptool $output >/dev/null\n";
398 `find .rockbox | xargs $ziptool $output >/dev/null`;
400 if($target && ($fonts != 1)) {
401 # On some targets, rockbox.* is inside .rockbox
402 if($target !~ /(mod|ajz|wma)\z/i) {
403 `cp $target .rockbox/$target`;
404 $target = ".rockbox/".$target;
407 if($verbose) {
408 print "$ziptool $output $target\n";
410 `$ziptool $output $target`;
413 # remove the .rockbox afterwards
414 `rm -rf .rockbox`;
417 if(!$exe) {
418 # not specified, guess!
419 if($target =~ /(recorder|ondio)/i) {
420 $exe = "ajbrec.ajz";
422 elsif($target =~ /iriver/i) {
423 $exe = "rockbox.iriver";
425 else {
426 $exe = "archos.mod";
429 elsif($exe =~ /rockboxui/) {
430 # simulator, exclude the exe file
431 $exe = "";
434 runone($exe, $incfonts);