A few minor fixes (typos, accuracy in the Ondio manual).
[kugel-rb.git] / tools / buildzip.pl
bloba30eb28e6708ac462d80a364277a5415a7498b12
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;
68 sub filesize {
69 my ($filename)=@_;
70 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
71 $atime,$mtime,$ctime,$blksize,$blocks)
72 = stat($filename);
73 return $size;
76 sub buildlangs {
77 my ($outputlang)=@_;
78 my $dir = "$ROOT/apps/lang";
79 opendir(DIR, $dir);
80 my @files = grep { /\.lang$/ } readdir(DIR);
81 closedir(DIR);
83 for(@files) {
84 my $output = $_;
85 $output =~ s/(.*)\.lang/$1.lng/;
86 print "$ROOT/tools/genlang -e=$dir/english.lang -t=$archos -b=$outputlang/$output $dir/$_\n" if($verbose);
87 system ("$ROOT/tools/genlang -e=$dir/english.lang -t=$archos -b=$outputlang/$output $dir/$_ >/dev/null 2>&1");
91 sub buildzip {
92 my ($zip, $image, $notplayer, $fonts)=@_;
94 # remove old traces
95 `rm -rf .rockbox`;
97 mkdir ".rockbox", 0777;
99 if($fonts) {
100 mkdir ".rockbox/fonts", 0777;
102 opendir(DIR, "$ROOT/fonts") || die "can't open dir fonts";
103 my @fonts = grep { /\.bdf$/ && -f "$ROOT/fonts/$_" } readdir(DIR);
104 closedir DIR;
106 for(@fonts) {
107 my $f = $_;
109 print "FONT: $f\n" if($verbose);
110 my $o = $f;
111 $o =~ s/\.bdf/\.fnt/;
112 my $cmd ="$ROOT/tools/convbdf -f -o \".rockbox/fonts/$o\" \"$ROOT/fonts/$f\" >/dev/null 2>&1";
113 print "CMD: $cmd\n" if($verbose);
114 `$cmd`;
117 if($fonts < 2) {
118 # fonts-only package, return
119 return;
123 mkdir ".rockbox/langs", 0777;
124 mkdir ".rockbox/rocks", 0777;
125 if($notplayer) {
126 mkdir ".rockbox/codepages", 0777;
127 mkdir ".rockbox/codecs", 0777;
128 mkdir ".rockbox/wps", 0777;
129 mkdir ".rockbox/themes", 0777;
130 mkdir ".rockbox/backdrops", 0777;
131 mkdir ".rockbox/eqs", 0777;
133 `cp $ROOT/apps/eqs/*.cfg .rockbox/eqs/`; # equalizer presets
135 my $c = 'find apps -name "*.codec" ! -empty -exec cp {} .rockbox/codecs/ \; 2>/dev/null';
136 `$c`;
138 system("$ROOT/tools/codepages");
139 my $c = 'find . -name "*.cp" ! -empty -exec mv {} .rockbox/codepages/ \; >/dev/null 2>&1';
140 `$c`;
142 my @call = `find .rockbox/codecs -type f 2>/dev/null`;
143 if(!$call[0]) {
144 # no codec was copied, remove directory again
145 rmdir(".rockbox/codecs");
150 $c= 'find apps "(" -name "*.rock" -o -name "*.ovl" ")" ! -empty -exec cp {} .rockbox/rocks/ \;';
151 print `$c`;
153 open VIEWERS, "$ROOT/apps/plugins/viewers.config" or
154 die "can't open viewers.config";
155 @viewers = <VIEWERS>;
156 close VIEWERS;
158 open VIEWERS, ">.rockbox/viewers.config" or
159 die "can't create .rockbox/viewers.config";
160 mkdir ".rockbox/viewers", 0777;
161 foreach my $line (@viewers) {
162 if ($line =~ /([^,]*),([^,]*),/) {
163 my ($ext, $plugin)=($1, $2);
164 my $r = "${plugin}.rock";
165 my $oname;
167 my $dir = $r;
168 my $name;
170 # strip off the last slash and file name part
171 $dir =~ s/(.*)\/(.*)/$1/;
172 # store the file name part
173 $name = $2;
175 # get .ovl name (file part only)
176 $oname = $name;
177 $oname =~ s/\.rock$/.ovl/;
179 # print STDERR "$ext $plugin $dir $name $r\n";
181 if(-e ".rockbox/rocks/$name") {
182 if($dir ne "rocks") {
183 # target is not 'rocks' but the plugins are always in that
184 # dir at first!
185 `mv .rockbox/rocks/$name .rockbox/$r`;
187 print VIEWERS $line;
189 elsif(-e ".rockbox/$r") {
190 # in case the same plugin works for multiple extensions, it
191 # was already moved to the viewers dir
192 print VIEWERS $line;
195 if(-e ".rockbox/rocks/$oname") {
196 # if there's an "overlay" file for the .rock, move that as
197 # well
198 `mv .rockbox/rocks/$oname .rockbox/$dir`;
202 close VIEWERS;
204 `cp $ROOT/apps/tagnavi.config .rockbox/`;
206 if($notplayer) {
207 `cp $ROOT/apps/plugins/sokoban.levels .rockbox/rocks/`; # sokoban levels
208 `cp $ROOT/apps/plugins/snake2.levels .rockbox/rocks/`; # snake2 levels
211 if($image) {
212 # image is blank when this is a simulator
213 if( filesize("rockbox.ucl") > 1000 ) {
214 `cp rockbox.ucl .rockbox/`; # UCL for flashing
216 if( filesize("rombox.ucl") > 1000) {
217 `cp rombox.ucl .rockbox/`; # UCL for flashing
221 mkdir ".rockbox/docs", 0777;
222 for(("COPYING",
223 "LICENSES",
224 )) {
225 `cp $ROOT/docs/$_ .rockbox/docs/$_.txt`;
228 # Now do the WPS dance
229 if(-d "$ROOT/wps") {
230 system("perl $ROOT/wps/wpsbuild.pl -r $ROOT $ROOT/wps/WPSLIST $target");
232 else {
233 print STDERR "No wps module present, can't do the WPS magic!\n";
236 # now copy the file made for reading on the unit:
237 #if($notplayer) {
238 # `cp $webroot/docs/Help-JBR.txt .rockbox/docs/`;
240 #else {
241 # `cp $webroot/docs/Help-Stu.txt .rockbox/docs/`;
244 buildlangs(".rockbox/langs");
248 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
249 localtime(time);
251 $mon+=1;
252 $year+=1900;
254 $date=sprintf("%04d%02d%02d", $year,$mon, $mday);
255 $shortdate=sprintf("%02d%02d%02d", $year%100,$mon, $mday);
257 # made once for all targets
258 sub runone {
259 my ($type, $target, $fonts)=@_;
261 # build a full install .rockbox directory
262 buildzip($output, $target,
263 ($type eq "player")?0:1, $fonts);
265 # create a zip file from the .rockbox dfir
267 `rm -f $output`;
268 if($verbose) {
269 print "find .rockbox | xargs $ziptool $output >/dev/null\n";
271 `find .rockbox | xargs $ziptool $output >/dev/null`;
273 if($target && ($fonts != 1)) {
274 if($verbose) {
275 print "$ziptool $output $target\n";
277 `$ziptool $output $target`;
280 # remove the .rockbox afterwards
281 `rm -rf .rockbox`;
284 if(!$exe) {
285 # not specified, guess!
286 if($target =~ /(recorder|ondio)/i) {
287 $exe = "ajbrec.ajz";
289 elsif($target =~ /iriver/i) {
290 $exe = "rockbox.iriver";
292 else {
293 $exe = "archos.mod";
296 elsif($exe =~ /rockboxui/) {
297 # simulator, exclude the exe file
298 $exe = "";
301 if($target =~ /player/i) {
302 runone("player", $exe, 0);
304 else {
305 runone("recorder", $exe, $incfonts);