Refer to "disk" instead of "hard disk" for the dap as flash based daps don't have...
[Rockbox.git] / tools / buildzip.pl
blob83397c8e94dd1df8457e7c9c92814ff49e999574
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";
65 my $cppdef = $target;
67 sub gettargetinfo {
68 open(GCC, ">gcctemp");
69 # Get the LCD screen depth and graphical status
70 print GCC <<STOP
71 \#include "config.h"
72 #ifdef HAVE_LCD_BITMAP
73 Bitmap: yes
74 Depth: LCD_DEPTH
75 #endif
76 Codec: CONFIG_CODEC
77 STOP
79 close(GCC);
81 my $c="cat gcctemp | gcc $cppdef -I. -I$firmdir/export -E -P -";
83 # print STDERR "CMD $c\n";
85 open(TARGET, "$c|");
87 my ($bitmap, $depth, $swcodec);
88 while(<TARGET>) {
89 # print STDERR "DATA: $_";
90 if($_ =~ /^Bitmap: (.*)/) {
91 $bitmap = $1;
93 elsif($_ =~ /^Depth: (\d*)/) {
94 $depth = $1;
96 elsif($_ =~ /^Codec: (\d*)/) {
97 # SWCODEC is 1, the others are HWCODEC
98 $swcodec = ($1 == 1);
101 close(TARGET);
102 unlink("gcctemp");
104 return ($bitmap, $depth, $swcodec);
107 sub filesize {
108 my ($filename)=@_;
109 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
110 $atime,$mtime,$ctime,$blksize,$blocks)
111 = stat($filename);
112 return $size;
115 sub buildlangs {
116 my ($outputlang)=@_;
117 my $dir = "$ROOT/apps/lang";
118 opendir(DIR, $dir);
119 my @files = grep { /\.lang$/ } readdir(DIR);
120 closedir(DIR);
122 for(@files) {
123 my $output = $_;
124 $output =~ s/(.*)\.lang/$1.lng/;
125 print "$ROOT/tools/genlang -e=$dir/english.lang -t=$archos -b=$outputlang/$output $dir/$_\n" if($verbose);
126 system ("$ROOT/tools/genlang -e=$dir/english.lang -t=$archos -b=$outputlang/$output $dir/$_ >/dev/null 2>&1");
130 sub buildzip {
131 my ($zip, $image, $fonts)=@_;
133 my ($bitmap, $depth, $swcodec) = &gettargetinfo();
135 print "Bitmap: $bitmap\nDepth: $depth\nSwcodec: $swcodec\n";
137 # remove old traces
138 `rm -rf .rockbox`;
140 mkdir ".rockbox", 0777;
142 if(!$bitmap) {
143 # always disable fonts on non-bitmap targets
144 $fonts = 0;
147 if($fonts) {
148 mkdir ".rockbox/fonts", 0777;
150 opendir(DIR, "$ROOT/fonts") || die "can't open dir fonts";
151 my @fonts = grep { /\.bdf$/ && -f "$ROOT/fonts/$_" } readdir(DIR);
152 closedir DIR;
154 for(@fonts) {
155 my $f = $_;
157 print "FONT: $f\n" if($verbose);
158 my $o = $f;
159 $o =~ s/\.bdf/\.fnt/;
160 my $cmd ="$ROOT/tools/convbdf -f -o \".rockbox/fonts/$o\" \"$ROOT/fonts/$f\" >/dev/null 2>&1";
161 print "CMD: $cmd\n" if($verbose);
162 `$cmd`;
165 if($fonts < 2) {
166 # fonts-only package, return
167 return;
171 mkdir ".rockbox/langs", 0777;
172 mkdir ".rockbox/rocks", 0777;
174 if($swcodec) {
175 mkdir ".rockbox/eqs", 0777;
177 `cp $ROOT/apps/eqs/*.cfg .rockbox/eqs/`; # equalizer presets
180 mkdir ".rockbox/wps", 0777;
182 if($bitmap) {
183 mkdir ".rockbox/codepages", 0777;
184 mkdir ".rockbox/codecs", 0777;
185 mkdir ".rockbox/themes", 0777;
186 if($depth > 1) {
187 mkdir ".rockbox/backdrops", 0777;
190 my $c = 'find apps -name "*.codec" ! -empty -exec cp {} .rockbox/codecs/ \; 2>/dev/null';
191 `$c`;
193 system("$ROOT/tools/codepages");
194 $c = 'find . -name "*.cp" ! -empty -exec mv {} .rockbox/codepages/ \; >/dev/null 2>&1';
195 `$c`;
197 my @call = `find .rockbox/codecs -type f 2>/dev/null`;
198 if(!$call[0]) {
199 # no codec was copied, remove directory again
200 rmdir(".rockbox/codecs");
205 $c= 'find apps "(" -name "*.rock" -o -name "*.ovl" ")" ! -empty -exec cp {} .rockbox/rocks/ \;';
206 print `$c`;
208 open VIEWERS, "$ROOT/apps/plugins/viewers.config" or
209 die "can't open viewers.config";
210 @viewers = <VIEWERS>;
211 close VIEWERS;
213 open VIEWERS, ">.rockbox/viewers.config" or
214 die "can't create .rockbox/viewers.config";
215 mkdir ".rockbox/viewers", 0777;
216 foreach my $line (@viewers) {
217 if ($line =~ /([^,]*),([^,]*),/) {
218 my ($ext, $plugin)=($1, $2);
219 my $r = "${plugin}.rock";
220 my $oname;
222 my $dir = $r;
223 my $name;
225 # strip off the last slash and file name part
226 $dir =~ s/(.*)\/(.*)/$1/;
227 # store the file name part
228 $name = $2;
230 # get .ovl name (file part only)
231 $oname = $name;
232 $oname =~ s/\.rock$/.ovl/;
234 # print STDERR "$ext $plugin $dir $name $r\n";
236 if(-e ".rockbox/rocks/$name") {
237 if($dir ne "rocks") {
238 # target is not 'rocks' but the plugins are always in that
239 # dir at first!
240 `mv .rockbox/rocks/$name .rockbox/$r`;
242 print VIEWERS $line;
244 elsif(-e ".rockbox/$r") {
245 # in case the same plugin works for multiple extensions, it
246 # was already moved to the viewers dir
247 print VIEWERS $line;
250 if(-e ".rockbox/rocks/$oname") {
251 # if there's an "overlay" file for the .rock, move that as
252 # well
253 `mv .rockbox/rocks/$oname .rockbox/$dir`;
257 close VIEWERS;
259 `cp $ROOT/apps/tagnavi.config .rockbox/`;
261 if($bitmap) {
262 `cp $ROOT/apps/plugins/sokoban.levels .rockbox/rocks/`; # sokoban levels
263 `cp $ROOT/apps/plugins/snake2.levels .rockbox/rocks/`; # snake2 levels
266 if($image) {
267 # image is blank when this is a simulator
268 if( filesize("rockbox.ucl") > 1000 ) {
269 `cp rockbox.ucl .rockbox/`; # UCL for flashing
271 if( filesize("rombox.ucl") > 1000) {
272 `cp rombox.ucl .rockbox/`; # UCL for flashing
275 # Check for rombox.target
276 if ($image=~/(.*)\.(\w+)$/)
278 my $romfile = "rombox.$2";
279 if (filesize($romfile) > 1000)
281 `cp $romfile .rockbox/`;
286 mkdir ".rockbox/docs", 0777;
287 for(("COPYING",
288 "LICENSES",
289 )) {
290 `cp $ROOT/docs/$_ .rockbox/docs/$_.txt`;
293 # Now do the WPS dance
294 if(-d "$ROOT/wps") {
295 system("perl $ROOT/wps/wpsbuild.pl -r $ROOT $ROOT/wps/WPSLIST $target");
297 else {
298 print STDERR "No wps module present, can't do the WPS magic!\n";
301 # now copy the file made for reading on the unit:
302 #if($notplayer) {
303 # `cp $webroot/docs/Help-JBR.txt .rockbox/docs/`;
305 #else {
306 # `cp $webroot/docs/Help-Stu.txt .rockbox/docs/`;
309 buildlangs(".rockbox/langs");
313 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
314 localtime(time);
316 $mon+=1;
317 $year+=1900;
319 #$date=sprintf("%04d%02d%02d", $year,$mon, $mday);
320 #$shortdate=sprintf("%02d%02d%02d", $year%100,$mon, $mday);
322 # made once for all targets
323 sub runone {
324 my ($target, $fonts)=@_;
326 # build a full install .rockbox directory
327 buildzip($output, $target, $fonts);
329 # create a zip file from the .rockbox dfir
331 `rm -f $output`;
332 if($verbose) {
333 print "find .rockbox | xargs $ziptool $output >/dev/null\n";
335 `find .rockbox | xargs $ziptool $output >/dev/null`;
337 if($target && ($fonts != 1)) {
338 if($verbose) {
339 print "$ziptool $output $target\n";
341 `$ziptool $output $target`;
344 # remove the .rockbox afterwards
345 `rm -rf .rockbox`;
348 if(!$exe) {
349 # not specified, guess!
350 if($target =~ /(recorder|ondio)/i) {
351 $exe = "ajbrec.ajz";
353 elsif($target =~ /iriver/i) {
354 $exe = "rockbox.iriver";
356 else {
357 $exe = "archos.mod";
360 elsif($exe =~ /rockboxui/) {
361 # simulator, exclude the exe file
362 $exe = "";
365 runone($exe, $incfonts);