summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtools/buildzip.pl213
1 files changed, 169 insertions, 44 deletions
diff --git a/tools/buildzip.pl b/tools/buildzip.pl
index 5d8fa43dfa..91bd66e89d 100755
--- a/tools/buildzip.pl
+++ b/tools/buildzip.pl
@@ -12,7 +12,7 @@ use strict;
12 12
13use File::Copy; # For move() and copy() 13use File::Copy; # For move() and copy()
14use File::Find; # For find() 14use File::Find; # For find()
15use File::Path; # For rmtree() 15use File::Path qw(mkpath rmtree); # For rmtree()
16use Cwd 'abs_path'; 16use Cwd 'abs_path';
17use Getopt::Long qw(:config pass_through); # pass_through so not confused by -DTYPE_STUFF 17use Getopt::Long qw(:config pass_through); # pass_through so not confused by -DTYPE_STUFF
18 18
@@ -28,8 +28,30 @@ my $modelname;
28my $incfonts; 28my $incfonts;
29my $target_id; # passed in, not currently used 29my $target_id; # passed in, not currently used
30my $rbdir=".rockbox"; # can be changed for special builds 30my $rbdir=".rockbox"; # can be changed for special builds
31my $app;
31 32
32 33
34sub glob_mkdir {
35 my ($dir) = @_;
36 mkpath ($dir, $verbose, 0777);
37 return 1;
38}
39
40sub glob_install {
41 my ($_src, $dest, $opts) = @_;
42
43 unless ($opts) {
44 $opts = "-m 0664";
45 }
46
47 foreach my $src (glob($_src)) {
48 unless ( -d $src || !(-e $src)) {
49 system("install $opts \"$src\" \"$dest\"");
50 print "install $opts \"$src\" -> \"$dest\"\n" if $verbose;
51 }
52 }
53 return 1;
54}
33 55
34sub glob_copy { 56sub glob_copy {
35 my ($pattern, $destination) = @_; 57 my ($pattern, $destination) = @_;
@@ -62,11 +84,118 @@ sub find_copyfile {
62 my $path = $_; 84 my $path = $_;
63 if ($path =~ $pattern && filesize($path) > 0 && !($path =~ /$rbdir/)) { 85 if ($path =~ $pattern && filesize($path) > 0 && !($path =~ /$rbdir/)) {
64 copy($path, $destination); 86 copy($path, $destination);
87 print "cp $path $destination\n" if $verbose;
65 chmod(0755, $destination.'/'.$path); 88 chmod(0755, $destination.'/'.$path);
66 } 89 }
67 } 90 }
68} 91}
69 92
93sub find_installfile {
94 my ($pattern, $destination) = @_;
95 print "find_installfile: $pattern -> $destination\n" if $verbose;
96 return sub {
97 my $path = $_;
98 if ($path =~ $pattern) {
99 print "FIND_INSTALLFILE: $path\n";
100 glob_install($path, $destination);
101 }
102 }
103}
104
105
106sub make_install {
107 my ($src, $dest) = @_;
108
109 my $bindir = $dest;
110 my $libdir = $dest;
111 my $userdir = $dest;
112
113 my @plugins = ( "games", "apps", "demos", "viewers" );
114 my @userstuff = ( "backdrops", "codepages", "docs", "fonts", "langs", "themes", "wps", "eqs", "icons" );
115 my @files = ();
116
117 if ($app) {
118 $bindir .= "/bin";
119 $libdir .= "/lib/rockbox";
120 $userdir .= "/share/rockbox";
121 } else {
122 # for non-app builds we expect the prefix to be the dir above .rockbox
123 $bindir .= "/.rockbox";
124 $libdir = $userdir = $bindir;
125 }
126 if ($dest =~ /\/dev\/null/) {
127 die "ERROR: No PREFIX given\n"
128 }
129
130 if ((!$app) && $src && (abs_path($dest) eq abs_path($src))) {
131 return 1;
132 }
133
134 # binary
135 unless ($exe eq "") {
136 unless (glob_mkdir($bindir)) {
137 return 0;
138 }
139 glob_install($exe, $bindir, "-m 0775");
140 }
141
142 # codecs
143 unless (glob_mkdir("$libdir/codecs")) {
144 return 0;
145 }
146 glob_install("$src/codecs/*", "$libdir/codecs");
147
148 # plugins
149 unless (glob_mkdir("$libdir/rocks")) {
150 return 0;
151 }
152 foreach my $t (@plugins) {
153 unless (glob_mkdir("$libdir/rocks/$t")) {
154 return 0;
155 }
156 glob_install("$src/rocks/$t/*", "$libdir/rocks/$t");
157 }
158
159 # rocks/viewers/lua
160 unless (glob_mkdir("$libdir/rocks/viewers/lua")) {
161 return 0;
162 }
163 glob_install("$src/rocks/viewers/lua/*", "$libdir/rocks/viewers/lua");
164
165 # all the rest directories
166 foreach my $t (@userstuff) {
167 unless (glob_mkdir("$userdir/$t")) {
168 return 0;
169 }
170 glob_install("$src/$t/*", "$userdir/$t");
171 }
172
173 # wps/ subfolders and bitmaps
174 opendir(DIR, $src . "/wps");
175 @files = readdir(DIR);
176 closedir(DIR);
177
178 foreach my $_dir (@files) {
179 my $dir = "wps/" . $_dir;
180 if ( -d "$src/$dir" && $_dir !~ /\.\.?/) {
181 unless (glob_mkdir("$userdir/$dir")) {
182 return 0;
183 }
184 glob_install("$src/$dir/*", "$userdir/$dir");
185 }
186 }
187
188 # rest of the files, excluding the binary
189 opendir(DIR,$src);
190 @files = readdir(DIR);
191 closedir(DIR);
192
193 foreach my $file (grep (/[a-zA-Z]+\.(txt|config|ignnore)/,@files)) {
194 glob_install("$src/$file", "$userdir/");
195 }
196 return 1;
197}
198
70# Get options 199# Get options
71GetOptions ( 'r|root=s' => \$ROOT, 200GetOptions ( 'r|root=s' => \$ROOT,
72 'z|ziptool=s' => \$ziptool, 201 'z|ziptool=s' => \$ziptool,
@@ -178,7 +307,9 @@ sub filesize {
178} 307}
179 308
180sub buildzip { 309sub buildzip {
181 my ($image, $fonts)=@_; 310 my ($image, $fonts)=@_;
311 my $libdir = $install;
312 my $rbdir = ".rockbox";
182 313
183 print "buildzip: image=$image fonts=$fonts\n" if $verbose; 314 print "buildzip: image=$image fonts=$fonts\n" if $verbose;
184 315
@@ -191,14 +322,14 @@ sub buildzip {
191 # remove old traces 322 # remove old traces
192 rmtree($rbdir); 323 rmtree($rbdir);
193 324
194 mkdir $rbdir, 0777; 325 glob_mkdir($rbdir);
195 326
196 if(!$bitmap) { 327 if(!$bitmap) {
197 # always disable fonts on non-bitmap targets 328 # always disable fonts on non-bitmap targets
198 $fonts = 0; 329 $fonts = 0;
199 } 330 }
200 if($fonts) { 331 if($fonts) {
201 mkdir "$rbdir/fonts", 0777; 332 glob_mkdir("$rbdir/fonts");
202 chdir "$rbdir/fonts"; 333 chdir "$rbdir/fonts";
203 my $cmd = "$ROOT/tools/convbdf -f $ROOT/fonts/*bdf >/dev/null 2>&1"; 334 my $cmd = "$ROOT/tools/convbdf -f $ROOT/fonts/*bdf >/dev/null 2>&1";
204 print($cmd."\n") if $verbose; 335 print($cmd."\n") if $verbose;
@@ -215,25 +346,25 @@ sub buildzip {
215 open(IGNORE, ">$rbdir/database.ignore") || die "can't open database.ignore"; 346 open(IGNORE, ">$rbdir/database.ignore") || die "can't open database.ignore";
216 close(IGNORE); 347 close(IGNORE);
217 348
218 mkdir "$rbdir/langs", 0777; 349 glob_mkdir("$rbdir/langs");
219 mkdir "$rbdir/rocks", 0777; 350 glob_mkdir("$rbdir/rocks");
220 mkdir "$rbdir/rocks/games", 0777; 351 glob_mkdir("$rbdir/rocks/games");
221 mkdir "$rbdir/rocks/apps", 0777; 352 glob_mkdir("$rbdir/rocks/apps");
222 mkdir "$rbdir/rocks/demos", 0777; 353 glob_mkdir("$rbdir/rocks/demos");
223 mkdir "$rbdir/rocks/viewers", 0777; 354 glob_mkdir("$rbdir/rocks/viewers");
224 355
225 if ($recording) { 356 if ($recording) {
226 mkdir "$rbdir/recpresets", 0777; 357 glob_mkdir("$rbdir/recpresets");
227 } 358 }
228 359
229 if($swcodec) { 360 if($swcodec) {
230 mkdir "$rbdir/eqs", 0777; 361 glob_mkdir("$rbdir/eqs");
231 362
232 glob_copy("$ROOT/apps/eqs/*.cfg", "$rbdir/eqs/"); # equalizer presets 363 glob_copy("$ROOT/apps/eqs/*.cfg", "$rbdir/eqs/"); # equalizer presets
233 } 364 }
234 365
235 mkdir "$rbdir/wps", 0777; 366 glob_mkdir("$rbdir/wps");
236 mkdir "$rbdir/themes", 0777; 367 glob_mkdir("$rbdir/themes");
237 if ($bitmap) { 368 if ($bitmap) {
238 open(THEME, ">$rbdir/themes/rockbox_default_icons.cfg"); 369 open(THEME, ">$rbdir/themes/rockbox_default_icons.cfg");
239 print THEME <<STOP 370 print THEME <<STOP
@@ -251,7 +382,7 @@ STOP
251 close(THEME); 382 close(THEME);
252 } 383 }
253 384
254 mkdir "$rbdir/codepages", 0777; 385 glob_mkdir("$rbdir/codepages");
255 386
256 if($bitmap) { 387 if($bitmap) {
257 system("$ROOT/tools/codepages"); 388 system("$ROOT/tools/codepages");
@@ -262,17 +393,16 @@ STOP
262 393
263 glob_move('*.cp', "$rbdir/codepages/"); 394 glob_move('*.cp', "$rbdir/codepages/");
264 395
265 if($bitmap) { 396 if($bitmap && $depth > 1) {
266 mkdir "$rbdir/codecs", 0777; 397 glob_mkdir("$rbdir/backdrops");
267 if($depth > 1) { 398 }
268 mkdir "$rbdir/backdrops", 0777;
269 }
270 399
271 find(find_copyfile(qr/.*\.codec/, abs_path("$rbdir/codecs/")), 'apps/codecs'); 400 glob_mkdir("$rbdir/codecs");
272 401
273 # remove directory again if no codec was copied 402 find(find_copyfile(qr/.*\.codec/, abs_path("$rbdir/codecs/")), 'apps/codecs');
274 rmdir("$rbdir/codecs"); 403
275 } 404 # remove directory again if no codec was copied
405 rmdir("$rbdir/codecs");
276 406
277 find(find_copyfile(qr/\.(rock|ovl|lua)/, abs_path("$rbdir/rocks/")), 'apps/plugins'); 407 find(find_copyfile(qr/\.(rock|ovl|lua)/, abs_path("$rbdir/rocks/")), 'apps/plugins');
278 408
@@ -350,7 +480,7 @@ STOP
350 glob_unlink("$rbdir/rocks/*.lua"); # Clean up unwanted *.lua files (e.g. actions.lua, buttons.lua) 480 glob_unlink("$rbdir/rocks/*.lua"); # Clean up unwanted *.lua files (e.g. actions.lua, buttons.lua)
351 481
352 if ($bitmap) { 482 if ($bitmap) {
353 mkdir "$rbdir/icons", 0777; 483 glob_mkdir("$rbdir/icons");
354 copy("$viewer_bmpdir/viewers.${icon_w}x${icon_h}x$depth.bmp", "$rbdir/icons/viewers.bmp"); 484 copy("$viewer_bmpdir/viewers.${icon_w}x${icon_h}x$depth.bmp", "$rbdir/icons/viewers.bmp");
355 if ($remote_depth) { 485 if ($remote_depth) {
356 copy("$viewer_bmpdir/remote_viewers.${remote_icon_w}x${remote_icon_h}x$remote_depth.bmp", "$rbdir/icons/remote_viewers.bmp"); 486 copy("$viewer_bmpdir/remote_viewers.${remote_icon_w}x${remote_icon_h}x$remote_depth.bmp", "$rbdir/icons/remote_viewers.bmp");
@@ -400,7 +530,7 @@ STOP
400 } 530 }
401 } 531 }
402 532
403 mkdir "$rbdir/docs", 0777; 533 glob_mkdir("$rbdir/docs");
404 for(("COPYING", 534 for(("COPYING",
405 "LICENSES", 535 "LICENSES",
406 "KNOWN_ISSUES" 536 "KNOWN_ISSUES"
@@ -458,7 +588,7 @@ STOP
458 glob_copy('apps/lang/*lng', "$rbdir/langs/"); 588 glob_copy('apps/lang/*lng', "$rbdir/langs/");
459 589
460 # copy the .lua files 590 # copy the .lua files
461 mkdir "$rbdir/rocks/viewers/lua/", 0777; 591 glob_mkdir("$rbdir/rocks/viewers/lua/");
462 glob_copy('apps/plugins/lua/*.lua', "$rbdir/rocks/viewers/lua/"); 592 glob_copy('apps/plugins/lua/*.lua', "$rbdir/rocks/viewers/lua/");
463} 593}
464 594
@@ -475,6 +605,8 @@ $year+=1900;
475sub runone { 605sub runone {
476 my ($target, $fonts)=@_; 606 my ($target, $fonts)=@_;
477 607
608 $app = ($modelname eq "application");
609
478 # build a full install .rockbox ($rbdir) directory 610 # build a full install .rockbox ($rbdir) directory
479 buildzip($target, $fonts); 611 buildzip($target, $fonts);
480 612
@@ -491,30 +623,23 @@ sub runone {
491 } 623 }
492 624
493 if($verbose) { 625 if($verbose) {
494 print "$ziptool $output $rbdir $target >/dev/null\n";
495 } 626 }
496 627
497 my $samedir = 0; # is the destination dir equal to source dir ? 628 my $samedir = 1; # is the destination dir equal to source dir ?
498 629
499 if($install) { 630 if($install) {
500 if ($install =~ /\/dev\/null/) { 631 make_install(".rockbox", $install) or die "MKDIRFAILED\n";
501 die "ERROR: No PREFIX given\n"
502 }
503
504 $samedir = abs_path("$install/$rbdir") eq abs_path($rbdir);
505
506 if (!$samedir) {
507 system("mkdir -p \"$install\" && cp -r $rbdir \"$install/\"");
508 }
509 } 632 }
510 else { 633 else {
634 unless (".rockbox" eq $rbdir) {
635 move(".rockbox", $rbdir);
636 print "mv .rockbox $rbdir\n" if $verbose;
637 }
511 system("$ziptool $output $rbdir $target >/dev/null"); 638 system("$ziptool $output $rbdir $target >/dev/null");
639 print "$ziptool $output $rbdir $target >/dev/null\n" if $verbose;
512 } 640 }
513 641 rmtree(".rockbox");
514 # remove the $rbdir afterwards 642 print "rm .rockbox\n" if $verbose;
515 if (!$samedir) {
516 rmtree($rbdir);
517 }
518}; 643};
519 644
520if(!$exe) { 645if(!$exe) {
@@ -529,7 +654,7 @@ if(!$exe) {
529 $exe = "archos.mod"; 654 $exe = "archos.mod";
530 } 655 }
531} 656}
532elsif($exe =~ /rockboxui/) { 657elsif(($exe =~ /rockboxui/)) {
533 # simulator, exclude the exe file 658 # simulator, exclude the exe file
534 $exe = ""; 659 $exe = "";
535} 660}