Small optimisation to the lcd_update_rect function - read the framebuffer data as...
[Rockbox.git] / tools / buildzip.pl
blob0694d1ace3944a3e3026ddff43ab21172d3b1c8b
1 #!/usr/bin/perl
2 # __________ __ ___.
3 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 # \/ \/ \/ \/ \/
8 # $Id$
11 $ROOT="..";
13 if($ARGV[0] eq "-r") {
14 $ROOT=$ARGV[1];
15 shift @ARGV;
16 shift @ARGV;
19 my $verbose;
20 if($ARGV[0] eq "-v") {
21 $verbose =1;
22 shift @ARGV;
25 my $firmdir="$ROOT/firmware";
27 my $target = $ARGV[0];
28 my $cppdef = $target;
30 my $exe = $ARGV[1];
32 sub filesize {
33 my ($filename)=@_;
34 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
35 $atime,$mtime,$ctime,$blksize,$blocks)
36 = stat($filename);
37 return $size;
40 sub buildlangs {
41 my ($outputlang)=@_;
42 my $dir = "$ROOT/apps/lang";
43 opendir(DIR, $dir);
44 my @files = grep { /\.lang$/ } readdir(DIR);
45 closedir(DIR);
47 for(@files) {
48 my $output = $_;
49 $output =~ s/(.*)\.lang/$1.lng/;
50 print "lang $_\n" if($verbose);
51 system ("$ROOT/tools/binlang $dir/english.lang $dir/$_ $outputlang/$output >/dev/null 2>&1");
55 sub buildzip {
56 my ($zip, $image, $notplayer)=@_;
58 # remove old traces
59 `rm -rf .rockbox`;
61 mkdir ".rockbox", 0777;
62 mkdir ".rockbox/langs", 0777;
63 mkdir ".rockbox/rocks", 0777;
64 mkdir ".rockbox/codecs", 0777;
65 mkdir ".rockbox/wps", 0777;
67 my $c = 'find apps -name "*.codec" ! -empty -exec cp {} .rockbox/codecs/ \;';
68 print `$c`;
70 my @call = `find .rockbox/codecs -type f`;
71 if(!$call[0]) {
72 # no codec was copied, remove directory again
73 rmdir(".rockbox/codecs");
77 $c= 'find apps "(" -name "*.rock" -o -name "*.ovl" ")" ! -empty -exec cp {} .rockbox/rocks/ \;';
78 print `$c`;
80 open VIEWERS, "$ROOT/apps/plugins/viewers.config" or
81 die "can't open viewers.config";
82 @viewers = <VIEWERS>;
83 close VIEWERS;
85 open VIEWERS, ">.rockbox/viewers.config" or
86 die "can't create .rockbox/viewers.config";
87 mkdir ".rockbox/viewers", 0777;
88 foreach my $line (@viewers) {
89 if ($line =~ /([^,]*),([^,]*),/) {
90 my ($ext, $plugin)=($1, $2);
91 my $r = "${plugin}.rock";
92 my $oname;
94 my $dir = $r;
95 my $name;
97 # strip off the last slash and file name part
98 $dir =~ s/(.*)\/(.*)/$1/;
99 # store the file name part
100 $name = $2;
102 # get .ovl name (file part only)
103 $oname = $name;
104 $oname =~ s/\.rock$/.ovl/;
106 # print STDERR "$ext $plugin $dir $name $r\n";
108 if(-e ".rockbox/rocks/$name") {
109 if($dir ne "rocks") {
110 # target is not 'rocks' but the plugins are always in that
111 # dir at first!
112 `mv .rockbox/rocks/$name .rockbox/$r`;
114 print VIEWERS $line;
116 elsif(-e ".rockbox/$r") {
117 # in case the same plugin works for multiple extensions, it
118 # was already moved to the viewers dir
119 print VIEWERS $line;
122 if(-e ".rockbox/rocks/$oname") {
123 # if there's an "overlay" file for the .rock, move that as
124 # well
125 `mv .rockbox/rocks/$oname .rockbox/$dir`;
129 close VIEWERS;
131 if($notplayer) {
132 `cp $ROOT/apps/plugins/sokoban.levels .rockbox/rocks/`; # sokoban levels
133 `cp $ROOT/apps/plugins/snake2.levels .rockbox/rocks/`; # snake2 levels
135 mkdir ".rockbox/fonts", 0777;
137 opendir(DIR, "$ROOT/fonts") || die "can't open dir fonts";
138 my @fonts = grep { /\.bdf$/ && -f "$ROOT/fonts/$_" } readdir(DIR);
139 closedir DIR;
141 my $maxfont;
143 open(SIZE, ">ziptemp");
144 print SIZE <<STOP
145 \#include "font.h"
146 Font Size We Want: MAX_FONT_SIZE
147 STOP
149 close(SIZE);
150 my $c="cat ziptemp | gcc $cppdef -I. -I$firmdir/export -E -P -";
151 # print STDERR "C: $c\n";
152 open(GETSIZE, "$c|");
154 while(<GETSIZE>) {
155 if($_ =~ /^Font Size We Want: (\d*)/) {
156 $maxfont = $1;
157 last;
160 close(GETSIZE);
161 unlink("ziptemp");
162 die "no decent max font size" if ($maxfont < 2000);
164 for(@fonts) {
165 my $f = $_;
167 print "FONT: $f\n" if($verbose);
168 my $o = $f;
169 $o =~ s/\.bdf/\.fnt/;
170 my $cmd ="$ROOT/tools/convbdf -s 32 -l 255 -f -o \".rockbox/fonts/$o\" \"$ROOT/fonts/$f\" >/dev/null 2>&1";
171 print "CMD: $cmd\n" if($verbose);
172 `$cmd`;
174 # no need to add fonts we cannot load anyway
175 my $fontsize = filesize(".rockbox/fonts/$o");
176 if($fontsize > $maxfont) {
177 unlink(".rockbox/fonts/$o");
183 if($image) {
184 # image is blank when this is a simulator
185 if( filesize("rockbox.ucl") > 1000 ) {
186 `cp rockbox.ucl .rockbox/`; # UCL for flashing
188 if( filesize("rombox.ucl") > 1000) {
189 `cp rombox.ucl .rockbox/`; # UCL for flashing
193 mkdir ".rockbox/docs", 0777;
194 for(("BATTERY-FAQ",
195 "CUSTOM_CFG_FORMAT",
196 "CUSTOM_WPS_FORMAT",
197 "FAQ",
198 "NODO",
199 "TECH")) {
200 `cp $ROOT/docs/$_ .rockbox/docs/$_.txt`;
203 # Now do the WPS dance
204 if(-d "$ROOT/wps") {
205 system("perl $ROOT/wps/wpsbuild.pl -r $ROOT $ROOT/wps/WPSLIST $target");
207 else {
208 print STDERR "No wps module present, can't do the WPS magic!\n";
211 # now copy the file made for reading on the unit:
212 #if($notplayer) {
213 # `cp $webroot/docs/Help-JBR.txt .rockbox/docs/`;
215 #else {
216 # `cp $webroot/docs/Help-Stu.txt .rockbox/docs/`;
219 buildlangs(".rockbox/langs");
221 `rm -f $zip`;
222 `find .rockbox | zip $zip -@ >/dev/null`;
224 if($image) {
225 `zip $zip $image`;
228 # remove the .rockbox afterwards
229 `rm -rf .rockbox`;
232 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
233 localtime(time);
235 $mon+=1;
236 $year+=1900;
238 $date=sprintf("%04d%02d%02d", $year,$mon, $mday);
239 $shortdate=sprintf("%02d%02d%02d", $year%100,$mon, $mday);
241 # made once for all targets
242 sub runone {
243 my ($type, $target)=@_;
245 # build a full install zip file
246 buildzip("rockbox.zip", $target,
247 ($type eq "player")?0:1);
250 if(!$exe) {
251 # not specified, guess!
252 if($target =~ /(recorder|ondio)/i) {
253 $exe = "ajbrec.ajz";
255 elsif($target =~ /iriver/i) {
256 $exe = "rockbox.iriver";
258 elsif($target =~ /gmini/i) {
259 $exe = "rockbox.gmini";
261 else {
262 $exe = "archos.mod";
265 elsif($exe =~ /rockboxui/) {
266 # simulator, exclude the exe file
267 $exe = "";
270 if($target =~ /player/i) {
271 runone("player", $exe);
273 else {
274 runone("recorder", $exe);