Corrected copyright year
[kugel-rb.git] / tools / buildzip.pl
blob568799ff9f3938599c7be41f370a2fb40c39349c
1 #!/usr/bin/perl
3 $ROOT="..";
5 if($ARGV[0] eq "-r") {
6 $ROOT=$ARGV[1];
7 shift @ARGV;
8 shift @ARGV;
11 my $verbose;
12 if($ARGV[0] eq "-v") {
13 $verbose =1;
14 shift @ARGV;
18 sub filesize {
19 my ($filename)=@_;
20 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
21 $atime,$mtime,$ctime,$blksize,$blocks)
22 = stat($filename);
23 return $size;
26 sub buildlangs {
27 my ($outputlang)=@_;
28 my $dir = "$ROOT/apps/lang";
29 opendir(DIR, $dir);
30 my @files = grep { /\.lang$/ } readdir(DIR);
31 closedir(DIR);
33 for(@files) {
34 my $output = $_;
35 $output =~ s/(.*)\.lang/$1.lng/;
36 print "lang $_\n" if($verbose);
37 system ("$ROOT/tools/binlang $dir/english.lang $dir/$_ $outputlang/$output >/dev/null 2>&1");
41 sub buildzip {
42 my ($zip, $image, $notplayer)=@_;
44 # remove old traces
45 `rm -rf .rockbox`;
47 mkdir ".rockbox", 0777;
48 mkdir ".rockbox/langs", 0777;
49 mkdir ".rockbox/rocks", 0777;
50 `find . -name "*.rock" ! -empty | xargs --replace=foo cp foo .rockbox/rocks/`;
52 open VIEWERS, "$ROOT/apps/plugins/viewers.config" or
53 die "can't open viewers.config";
54 @viewers = <VIEWERS>;
55 close VIEWERS;
57 open VIEWERS, ">.rockbox/viewers.config" or
58 die "can't create .rockbox/viewers.config";
59 mkdir ".rockbox/viewers", 0777;
60 for (@viewers) {
61 if (/,(.+),/) {
62 if(-e ".rockbox/rocks/$1") {
63 `mv .rockbox/rocks/$1 .rockbox/viewers`;
64 print VIEWERS $_;
68 close VIEWERS;
70 if($notplayer) {
71 `cp $ROOT/apps/plugins/sokoban.levels .rockbox/`; # sokoban levels
72 `cp $ROOT/apps/plugins/snake2.levels .rockbox/`; # snake2 levels
74 mkdir ".rockbox/fonts", 0777;
76 opendir(DIR, "$ROOT/fonts") || die "can't open dir fonts";
77 my @fonts = grep { /\.bdf$/ && -f "$ROOT/fonts/$_" } readdir(DIR);
78 closedir DIR;
80 my $maxfont;
81 open(HEADER, "<$ROOT/firmware/export/font.h");
82 while(<HEADER>) {
83 if(/^\#define MAX_FONT_SIZE[ \t]*(\d+)/) {
84 $maxfont = $1;
87 close(HEADER);
88 die "no decent max font size" if ($maxfont < 2000);
90 for(@fonts) {
91 my $f = $_;
93 print "FONT: $f\n" if($verbose);
94 my $o = $f;
95 $o =~ s/\.bdf/\.fnt/;
96 my $cmd ="$ROOT/tools/convbdf -s 32 -l 255 -f -o \".rockbox/fonts/$o\" \"$ROOT/fonts/$f\" >/dev/null 2>&1";
97 print "CMD: $cmd\n" if($verbose);
98 `$cmd`;
100 # no need to add fonts we cannot load anyway
101 my $fontsize = filesize(".rockbox/fonts/$o");
102 if($fontsize > $maxfont) {
103 unlink(".rockbox/fonts/$o");
109 if($image) {
110 # image is blank when this is a simulator
111 if( filesize("rockbox.ucl") > 1000 ) {
112 `cp rockbox.ucl .rockbox/`; # UCL for flashing
114 if( filesize("rombox.ucl") > 1000) {
115 `cp rombox.ucl .rockbox/`; # UCL for flashing
119 mkdir ".rockbox/docs", 0777;
120 for(("BATTERY-FAQ",
121 "CUSTOM_CFG_FORMAT",
122 "CUSTOM_WPS_FORMAT",
123 "FAQ",
124 "NODO",
125 "TECH")) {
126 `cp $ROOT/docs/$_ .rockbox/docs/$_.txt`;
129 # now copy the file made for reading on the unit:
130 #if($notplayer) {
131 # `cp $webroot/docs/Help-JBR.txt .rockbox/docs/`;
133 #else {
134 # `cp $webroot/docs/Help-Stu.txt .rockbox/docs/`;
137 buildlangs(".rockbox/langs");
139 `find .rockbox | zip $zip -@ >/dev/null`;
141 if($image) {
142 `zip $zip $image`;
145 # remove the .rockbox afterwards
146 `rm -rf .rockbox`;
149 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
150 localtime(time);
152 $mon+=1;
153 $year+=1900;
155 $date=sprintf("%04d%02d%02d", $year,$mon, $mday);
156 $shortdate=sprintf("%02d%02d%02d", $year%100,$mon, $mday);
158 # made once for all targets
159 sub runone {
160 my ($type, $target)=@_;
162 # build a full install zip file
163 buildzip("rockbox.zip", $target,
164 ($type eq "player")?0:1);
167 my $target = $ARGV[0];
169 my $exe = "";
171 if($target !~ /sim/i) {
172 # not a simulator
173 if($target =~ /(recorder|ondio)/i) {
174 $exe = "ajbrec.ajz";
176 else {
177 $exe = "archos.mod";
181 if($target =~ /player/i) {
182 runone("player", $exe);
184 else {
185 runone("recorder", $exe);