Flush queued voice clips when not playing audio
[Rockbox.git] / tools / buildzip.pl
blob23474162752a4b5671b068875941d8e52fcea975
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 my $c = 'find apps -name "*.codec" ! -empty -exec cp {} .rockbox/codecs/ \; 2>/dev/null';
134 `$c`;
136 system("$ROOT/tools/codepages");
137 my $c = 'find . -name "*.cp" ! -empty -exec mv {} .rockbox/codepages/ \; >/dev/null 2>&1';
138 `$c`;
140 my @call = `find .rockbox/codecs -type f 2>/dev/null`;
141 if(!$call[0]) {
142 # no codec was copied, remove directory again
143 rmdir(".rockbox/codecs");
148 $c= 'find apps "(" -name "*.rock" -o -name "*.ovl" ")" ! -empty -exec cp {} .rockbox/rocks/ \;';
149 print `$c`;
151 open VIEWERS, "$ROOT/apps/plugins/viewers.config" or
152 die "can't open viewers.config";
153 @viewers = <VIEWERS>;
154 close VIEWERS;
156 open VIEWERS, ">.rockbox/viewers.config" or
157 die "can't create .rockbox/viewers.config";
158 mkdir ".rockbox/viewers", 0777;
159 foreach my $line (@viewers) {
160 if ($line =~ /([^,]*),([^,]*),/) {
161 my ($ext, $plugin)=($1, $2);
162 my $r = "${plugin}.rock";
163 my $oname;
165 my $dir = $r;
166 my $name;
168 # strip off the last slash and file name part
169 $dir =~ s/(.*)\/(.*)/$1/;
170 # store the file name part
171 $name = $2;
173 # get .ovl name (file part only)
174 $oname = $name;
175 $oname =~ s/\.rock$/.ovl/;
177 # print STDERR "$ext $plugin $dir $name $r\n";
179 if(-e ".rockbox/rocks/$name") {
180 if($dir ne "rocks") {
181 # target is not 'rocks' but the plugins are always in that
182 # dir at first!
183 `mv .rockbox/rocks/$name .rockbox/$r`;
185 print VIEWERS $line;
187 elsif(-e ".rockbox/$r") {
188 # in case the same plugin works for multiple extensions, it
189 # was already moved to the viewers dir
190 print VIEWERS $line;
193 if(-e ".rockbox/rocks/$oname") {
194 # if there's an "overlay" file for the .rock, move that as
195 # well
196 `mv .rockbox/rocks/$oname .rockbox/$dir`;
200 close VIEWERS;
202 `cp $ROOT/apps/tagnavi.config .rockbox/`;
204 if($notplayer) {
205 `cp $ROOT/apps/plugins/sokoban.levels .rockbox/rocks/`; # sokoban levels
206 `cp $ROOT/apps/plugins/snake2.levels .rockbox/rocks/`; # snake2 levels
209 if($image) {
210 # image is blank when this is a simulator
211 if( filesize("rockbox.ucl") > 1000 ) {
212 `cp rockbox.ucl .rockbox/`; # UCL for flashing
214 if( filesize("rombox.ucl") > 1000) {
215 `cp rombox.ucl .rockbox/`; # UCL for flashing
219 mkdir ".rockbox/docs", 0777;
220 for(("COPYING",
221 "LICENSES",
222 )) {
223 `cp $ROOT/docs/$_ .rockbox/docs/$_.txt`;
226 # Now do the WPS dance
227 if(-d "$ROOT/wps") {
228 system("perl $ROOT/wps/wpsbuild.pl -r $ROOT $ROOT/wps/WPSLIST $target");
230 else {
231 print STDERR "No wps module present, can't do the WPS magic!\n";
234 # now copy the file made for reading on the unit:
235 #if($notplayer) {
236 # `cp $webroot/docs/Help-JBR.txt .rockbox/docs/`;
238 #else {
239 # `cp $webroot/docs/Help-Stu.txt .rockbox/docs/`;
242 buildlangs(".rockbox/langs");
246 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
247 localtime(time);
249 $mon+=1;
250 $year+=1900;
252 $date=sprintf("%04d%02d%02d", $year,$mon, $mday);
253 $shortdate=sprintf("%02d%02d%02d", $year%100,$mon, $mday);
255 # made once for all targets
256 sub runone {
257 my ($type, $target, $fonts)=@_;
259 # build a full install .rockbox directory
260 buildzip($output, $target,
261 ($type eq "player")?0:1, $fonts);
263 # create a zip file from the .rockbox dfir
265 `rm -f $output`;
266 if($verbose) {
267 print "find .rockbox | xargs $ziptool $output >/dev/null\n";
269 `find .rockbox | xargs $ziptool $output >/dev/null`;
271 if($target && ($fonts != 1)) {
272 if($verbose) {
273 print "$ziptool $output $target\n";
275 `$ziptool $output $target`;
278 # remove the .rockbox afterwards
279 `rm -rf .rockbox`;
282 if(!$exe) {
283 # not specified, guess!
284 if($target =~ /(recorder|ondio)/i) {
285 $exe = "ajbrec.ajz";
287 elsif($target =~ /iriver/i) {
288 $exe = "rockbox.iriver";
290 elsif($target =~ /gmini/i) {
291 $exe = "rockbox.gmini";
293 else {
294 $exe = "archos.mod";
297 elsif($exe =~ /rockboxui/) {
298 # simulator, exclude the exe file
299 $exe = "";
302 if($target =~ /player/i) {
303 runone("player", $exe, 0);
305 else {
306 runone("recorder", $exe, $incfonts);