blob: 6a67f7b51b458d3d2361804c7537448131b6a207 [file] [log] [blame]
Daniel Stenberg760b7b92004-05-21 19:05:27 +00001#!/usr/bin/perl
Daniel Stenberg51413e42005-11-14 15:06:51 +00002# __________ __ ___.
3# Open \______ \ ____ ____ | | _\_ |__ _______ ___
4# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7# \/ \/ \/ \/ \/
8# $Id$
9#
Daniel Stenberg760b7b92004-05-21 19:05:27 +000010
Linus Nielsen Feltzing7afbb492008-11-17 10:14:48 +000011use strict;
12
Jonas Häggqvist4077f232008-07-20 22:20:32 +000013use File::Copy; # For move() and copy()
14use File::Find; # For find()
Thomas Martitz35ac4072010-07-13 14:17:52 +000015use File::Path qw(mkpath rmtree); # For rmtree()
Michael Stummvoll1f06ca42010-12-28 10:30:46 +000016use Cwd;
Jonas Häggqvist4077f232008-07-20 22:20:32 +000017use Cwd 'abs_path';
Dave Chapmanefe556f2011-02-26 21:30:20 +000018use Getopt::Long qw(:config pass_through); # pass_through so not confused by -DTYPE_STUFF
Jonas Häggqvist4077f232008-07-20 22:20:32 +000019
Linus Nielsen Feltzing7afbb492008-11-17 10:14:48 +000020my $ROOT="..";
Daniel Stenbergd1851e32004-08-24 15:13:08 +000021
Thomas Martitz9321ce32010-11-14 15:29:11 +000022my $ziptool;
23my $output;
Daniel Stenberge07b0bb2005-12-13 10:20:23 +000024my $verbose;
Rafaël Carré80fa0ef2010-07-07 20:31:34 +000025my $install;
Daniel Stenberge07b0bb2005-12-13 10:20:23 +000026my $exe;
27my $target;
Bertrik Sikken31c8eee2009-01-31 12:23:35 +000028my $modelname;
Daniel Stenberga420dc32006-05-10 21:57:08 +000029my $incfonts;
Linus Nielsen Feltzing7afbb492008-11-17 10:14:48 +000030my $target_id; # passed in, not currently used
Thomas Martitz9321ce32010-11-14 15:29:11 +000031my $rbdir; # can be non-.rockbox for special builds
Thomas Martitz35ac4072010-07-13 14:17:52 +000032my $app;
Michael Stummvoll1f06ca42010-12-28 10:30:46 +000033my $mklinks;
Björn Stenbergad8d6032008-11-24 22:16:07 +000034
Thomas Martitz35ac4072010-07-13 14:17:52 +000035sub glob_mkdir {
36 my ($dir) = @_;
37 mkpath ($dir, $verbose, 0777);
38 return 1;
39}
40
41sub glob_install {
42 my ($_src, $dest, $opts) = @_;
43
44 unless ($opts) {
45 $opts = "-m 0664";
46 }
47
48 foreach my $src (glob($_src)) {
49 unless ( -d $src || !(-e $src)) {
Thomas Martitz19a21a22010-07-13 14:53:10 +000050 system("install $opts \"$src\" \"$dest\"");
Thomas Martitz35ac4072010-07-13 14:17:52 +000051 print "install $opts \"$src\" -> \"$dest\"\n" if $verbose;
52 }
53 }
54 return 1;
55}
Björn Stenbergad8d6032008-11-24 22:16:07 +000056
57sub glob_copy {
58 my ($pattern, $destination) = @_;
59 print "glob_copy: $pattern -> $destination\n" if $verbose;
60 foreach my $path (glob($pattern)) {
61 copy($path, $destination);
62 }
63}
64
65sub glob_move {
66 my ($pattern, $destination) = @_;
67 print "glob_move: $pattern -> $destination\n" if $verbose;
68 foreach my $path (glob($pattern)) {
69 move($path, $destination);
70 }
71}
72
73sub glob_unlink {
74 my ($pattern) = @_;
75 print "glob_unlink: $pattern\n" if $verbose;
76 foreach my $path (glob($pattern)) {
77 unlink($path);
78 }
79}
80
81sub find_copyfile {
82 my ($pattern, $destination) = @_;
83 print "find_copyfile: $pattern -> $destination\n" if $verbose;
84 return sub {
85 my $path = $_;
Michael Stummvoll1f06ca42010-12-28 10:30:46 +000086 my $source = getcwd();
Björn Stenbergad8d6032008-11-24 22:16:07 +000087 if ($path =~ $pattern && filesize($path) > 0 && !($path =~ /$rbdir/)) {
Michael Stummvoll1f06ca42010-12-28 10:30:46 +000088 if($mklinks) {
89 print "link $path $destination\n" if $verbose;
90 symlink($source.'/'.$path, $destination.'/'.$path);
91 } else {
92 print "cp $path $destination\n" if $verbose;
93 copy($path, $destination);
94 chmod(0755, $destination.'/'.$path);
95 }
Björn Stenbergad8d6032008-11-24 22:16:07 +000096 }
97 }
98}
Daniel Stenberge07b0bb2005-12-13 10:20:23 +000099
Thomas Martitz35ac4072010-07-13 14:17:52 +0000100sub find_installfile {
101 my ($pattern, $destination) = @_;
102 print "find_installfile: $pattern -> $destination\n" if $verbose;
103 return sub {
104 my $path = $_;
105 if ($path =~ $pattern) {
106 print "FIND_INSTALLFILE: $path\n";
107 glob_install($path, $destination);
108 }
109 }
110}
111
112
113sub make_install {
114 my ($src, $dest) = @_;
115
116 my $bindir = $dest;
117 my $libdir = $dest;
118 my $userdir = $dest;
119
120 my @plugins = ( "games", "apps", "demos", "viewers" );
121 my @userstuff = ( "backdrops", "codepages", "docs", "fonts", "langs", "themes", "wps", "eqs", "icons" );
122 my @files = ();
123
124 if ($app) {
125 $bindir .= "/bin";
126 $libdir .= "/lib/rockbox";
127 $userdir .= "/share/rockbox";
128 } else {
129 # for non-app builds we expect the prefix to be the dir above .rockbox
Teruaki Kawashima3c11c562010-09-25 14:47:11 +0000130 $bindir .= "/$rbdir";
Thomas Martitz35ac4072010-07-13 14:17:52 +0000131 $libdir = $userdir = $bindir;
132 }
133 if ($dest =~ /\/dev\/null/) {
134 die "ERROR: No PREFIX given\n"
135 }
136
Teruaki Kawashimab03b8912010-12-17 11:41:43 +0000137 if ((!$app) && -e $bindir && -e $src && (abs_path($bindir) eq abs_path($src))) {
Thomas Martitz35ac4072010-07-13 14:17:52 +0000138 return 1;
139 }
140
141 # binary
142 unless ($exe eq "") {
143 unless (glob_mkdir($bindir)) {
144 return 0;
145 }
146 glob_install($exe, $bindir, "-m 0775");
147 }
148
149 # codecs
150 unless (glob_mkdir("$libdir/codecs")) {
151 return 0;
152 }
Dominik Riebeling70b81e62011-05-31 21:26:18 +0000153 # Android has codecs installed as native libraries so they are not needed
154 # in the zip.
155 if ($modelname !~ /android/) {
156 glob_install("$src/codecs/*", "$libdir/codecs", "-m 0755");
157 }
Thomas Martitz35ac4072010-07-13 14:17:52 +0000158
159 # plugins
160 unless (glob_mkdir("$libdir/rocks")) {
161 return 0;
162 }
163 foreach my $t (@plugins) {
164 unless (glob_mkdir("$libdir/rocks/$t")) {
165 return 0;
166 }
Magnus Holmgren47c510b2010-08-29 12:29:34 +0000167 glob_install("$src/rocks/$t/*", "$libdir/rocks/$t", "-m 0755");
Thomas Martitz35ac4072010-07-13 14:17:52 +0000168 }
169
170 # rocks/viewers/lua
171 unless (glob_mkdir("$libdir/rocks/viewers/lua")) {
172 return 0;
173 }
174 glob_install("$src/rocks/viewers/lua/*", "$libdir/rocks/viewers/lua");
175
William Wilgus90118f12019-07-26 01:30:00 -0500176 #lua example scripts
177 if(-e "$ROOT/apps/plugins/lua_scripts") {
178 unless (glob_mkdir("$libdir/rocks/demos/lua_scripts")) {
179 return 0;
180 }
181 glob_install("$ROOT/apps/plugins/lua_scripts/*.lua", "$libdir/rocks/demos/lua_scripts");
182 #glob_mkdir("$temp_dir/rocks/demos/lua_scripts");
183 #glob_copy("$ROOT/apps/plugins/lua_scripts/*.lua", "$temp_dir/rocks/demos/lua_scripts/");
184 }
185
Thomas Martitz35ac4072010-07-13 14:17:52 +0000186 # all the rest directories
187 foreach my $t (@userstuff) {
188 unless (glob_mkdir("$userdir/$t")) {
189 return 0;
190 }
191 glob_install("$src/$t/*", "$userdir/$t");
192 }
193
194 # wps/ subfolders and bitmaps
195 opendir(DIR, $src . "/wps");
196 @files = readdir(DIR);
197 closedir(DIR);
198
199 foreach my $_dir (@files) {
200 my $dir = "wps/" . $_dir;
201 if ( -d "$src/$dir" && $_dir !~ /\.\.?/) {
202 unless (glob_mkdir("$userdir/$dir")) {
203 return 0;
204 }
205 glob_install("$src/$dir/*", "$userdir/$dir");
206 }
207 }
208
209 # rest of the files, excluding the binary
210 opendir(DIR,$src);
211 @files = readdir(DIR);
212 closedir(DIR);
213
Thomas Martitz249bba02011-12-24 11:56:46 +0000214 foreach my $file (grep (/[a-zA-Z]+\.(txt|config|ignore|sh)/,@files)) {
Thomas Martitz35ac4072010-07-13 14:17:52 +0000215 glob_install("$src/$file", "$userdir/");
216 }
217 return 1;
218}
219
Linus Nielsen Feltzing7afbb492008-11-17 10:14:48 +0000220# Get options
Dave Chapmanefe556f2011-02-26 21:30:20 +0000221GetOptions ( 'r|root=s' => \$ROOT,
222 'z|ziptool:s' => \$ziptool,
223 'm|modelname=s' => \$modelname, # The model name as used in ARCHOS in the root makefile
224 'i|id=s' => \$target_id, # The target id name as used in TARGET_ID in the root makefile
225 'o|output:s' => \$output,
226 'f|fonts=s' => \$incfonts, # 0 - no fonts, 1 - fonts only 2 - fonts and package
227 'v|verbose' => \$verbose,
228 'install=s' => \$install, # install destination
229 'rbdir:s' => \$rbdir, # If we want to put in a different directory
230 'l|link' => \$mklinks, # If we want to create links instead of copying files
Dave Chapman376c9f32011-02-27 11:37:39 +0000231 'a|app:s' => \$app, # Is this an Application build?
Björn Stenbergad8d6032008-11-24 22:16:07 +0000232 );
Daniel Stenberge07b0bb2005-12-13 10:20:23 +0000233
Thomas Martitz9321ce32010-11-14 15:29:11 +0000234# GetOptions() doesn't remove the params from @ARGV if their value was ""
235# Thus we use the ":" for those for which we use a default value in case of ""
236# and assign the default value afterwards
237if ($ziptool eq '') {
238 $ziptool = "zip -r9";
239}
240if ($output eq '') {
241 $output = "rockbox.zip"
242}
243if ($rbdir eq '') {
244 $rbdir = ".rockbox";
245}
246
247# Now @ARGV shuold be free of any left-overs GetOptions left
Linus Nielsen Feltzing7afbb492008-11-17 10:14:48 +0000248($target, $exe) = @ARGV;
Daniel Stenberge07b0bb2005-12-13 10:20:23 +0000249
Daniel Stenberg9990dec2005-08-04 18:11:46 +0000250my $firmdir="$ROOT/firmware";
Jonathan Gordon6a5cc0b2007-04-16 09:14:36 +0000251my $appsdir="$ROOT/apps";
252my $viewer_bmpdir="$ROOT/apps/plugins/bitmaps/viewer_defaults";
Daniel Stenberg9990dec2005-08-04 18:11:46 +0000253
Daniel Stenberg0f820d62005-08-03 21:31:51 +0000254my $cppdef = $target;
255
Daniel Stenberg19bba742007-03-12 10:51:08 +0000256sub gettargetinfo {
257 open(GCC, ">gcctemp");
258 # Get the LCD screen depth and graphical status
259 print GCC <<STOP
260\#include "config.h"
261#ifdef HAVE_LCD_BITMAP
262Bitmap: yes
263Depth: LCD_DEPTH
Andrew Mahone802ea462009-05-23 07:55:14 +0000264LCD Width: LCD_WIDTH
265LCD Height: LCD_HEIGHT
Jonathan Gordon6a5cc0b2007-04-16 09:14:36 +0000266Icon Width: CONFIG_DEFAULT_ICON_WIDTH
267Icon Height: CONFIG_DEFAULT_ICON_HEIGHT
Daniel Stenberg19bba742007-03-12 10:51:08 +0000268#endif
269Codec: CONFIG_CODEC
Jonathan Gordon6a5cc0b2007-04-16 09:14:36 +0000270#ifdef HAVE_REMOTE_LCD
271Remote Depth: LCD_REMOTE_DEPTH
272Remote Icon Width: CONFIG_REMOTE_DEFAULT_ICON_WIDTH
Jonathan Gordonbfa55772007-04-16 09:59:27 +0000273Remote Icon Height: CONFIG_REMOTE_DEFAULT_ICON_HEIGHT
Jonathan Gordon6a5cc0b2007-04-16 09:14:36 +0000274#else
275Remote Depth: 0
276#endif
Jonathan Gordonb2ecf1b2007-05-29 08:17:32 +0000277#ifdef HAVE_RECORDING
278Recording: yes
279#endif
Daniel Stenberg19bba742007-03-12 10:51:08 +0000280STOP
281;
Daniel Stenbergb46f1ac2007-03-12 12:56:35 +0000282 close(GCC);
Daniel Stenberg19bba742007-03-12 10:51:08 +0000283
284 my $c="cat gcctemp | gcc $cppdef -I. -I$firmdir/export -E -P -";
285
286 # print STDERR "CMD $c\n";
287
288 open(TARGET, "$c|");
289
Andrew Mahone802ea462009-05-23 07:55:14 +0000290 my ($bitmap, $width, $height, $depth, $swcodec, $icon_h, $icon_w);
Jonathan Gordon6a5cc0b2007-04-16 09:14:36 +0000291 my ($remote_depth, $remote_icon_h, $remote_icon_w);
Jonathan Gordonb2ecf1b2007-05-29 08:17:32 +0000292 my ($recording);
Linus Nielsen Feltzing7afbb492008-11-17 10:14:48 +0000293 my $icon_count = 1;
Daniel Stenberg19bba742007-03-12 10:51:08 +0000294 while(<TARGET>) {
295 # print STDERR "DATA: $_";
296 if($_ =~ /^Bitmap: (.*)/) {
297 $bitmap = $1;
298 }
299 elsif($_ =~ /^Depth: (\d*)/) {
300 $depth = $1;
301 }
Andrew Mahone802ea462009-05-23 07:55:14 +0000302 elsif($_ =~ /^LCD Width: (\d*)/) {
303 $width = $1;
304 }
305 elsif($_ =~ /^LCD Height: (\d*)/) {
306 $height = $1;
307 }
Jonathan Gordon6a5cc0b2007-04-16 09:14:36 +0000308 elsif($_ =~ /^Icon Width: (\d*)/) {
309 $icon_w = $1;
310 }
311 elsif($_ =~ /^Icon Height: (\d*)/) {
312 $icon_h = $1;
313 }
Daniel Stenberg19bba742007-03-12 10:51:08 +0000314 elsif($_ =~ /^Codec: (\d*)/) {
315 # SWCODEC is 1, the others are HWCODEC
316 $swcodec = ($1 == 1);
317 }
Jonathan Gordon6a5cc0b2007-04-16 09:14:36 +0000318 elsif($_ =~ /^Remote Depth: (\d*)/) {
319 $remote_depth = $1;
320 }
321 elsif($_ =~ /^Remote Icon Width: (\d*)/) {
322 $remote_icon_w = $1;
323 }
324 elsif($_ =~ /^Remote Icon Height: (\d*)/) {
325 $remote_icon_h = $1;
326 }
Jonathan Gordonb2ecf1b2007-05-29 08:17:32 +0000327 if($_ =~ /^Recording: (.*)/) {
328 $recording = $1;
329 }
Daniel Stenberg19bba742007-03-12 10:51:08 +0000330 }
331 close(TARGET);
332 unlink("gcctemp");
333
Andrew Mahone802ea462009-05-23 07:55:14 +0000334 return ($bitmap, $depth, $width, $height, $icon_w, $icon_h, $recording,
Jonathan Gordon6a5cc0b2007-04-16 09:14:36 +0000335 $swcodec, $remote_depth, $remote_icon_w, $remote_icon_h);
Daniel Stenberg19bba742007-03-12 10:51:08 +0000336}
Daniel Stenbergd1851e32004-08-24 15:13:08 +0000337
Daniel Stenbergc4d463b2004-08-24 09:38:26 +0000338sub filesize {
339 my ($filename)=@_;
340 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
341 $atime,$mtime,$ctime,$blksize,$blocks)
342 = stat($filename);
343 return $size;
344}
345
Jonathan Gordon9928e342010-09-14 11:56:50 +0000346
Daniel Stenberg760b7b92004-05-21 19:05:27 +0000347sub buildzip {
Thomas Martitz35ac4072010-07-13 14:17:52 +0000348 my ($image, $fonts)=@_;
349 my $libdir = $install;
Thomas Martitz67d61f22010-07-25 13:44:30 +0000350 my $temp_dir = ".rockbox";
Daniel Stenberg19bba742007-03-12 10:51:08 +0000351
Björn Stenbergad8d6032008-11-24 22:16:07 +0000352 print "buildzip: image=$image fonts=$fonts\n" if $verbose;
353
Andrew Mahone802ea462009-05-23 07:55:14 +0000354 my ($bitmap, $depth, $width, $height, $icon_w, $icon_h, $recording,
355 $swcodec, $remote_depth, $remote_icon_w, $remote_icon_h) =
356 &gettargetinfo();
Daniel Stenberg19bba742007-03-12 10:51:08 +0000357
Daniel Stenberga1d0ad92007-03-20 12:38:54 +0000358 # print "Bitmap: $bitmap\nDepth: $depth\nSwcodec: $swcodec\n";
Daniel Stenberg760b7b92004-05-21 19:05:27 +0000359
360 # remove old traces
Thomas Martitz67d61f22010-07-25 13:44:30 +0000361 rmtree($temp_dir);
Daniel Stenberg760b7b92004-05-21 19:05:27 +0000362
Thomas Martitz67d61f22010-07-25 13:44:30 +0000363 glob_mkdir($temp_dir);
Daniel Stenberga420dc32006-05-10 21:57:08 +0000364
Daniel Stenberg19bba742007-03-12 10:51:08 +0000365 if(!$bitmap) {
366 # always disable fonts on non-bitmap targets
367 $fonts = 0;
368 }
Daniel Stenberga420dc32006-05-10 21:57:08 +0000369 if($fonts) {
Thomas Martitz67d61f22010-07-25 13:44:30 +0000370 glob_mkdir("$temp_dir/fonts");
371 chdir "$temp_dir/fonts";
Linus Nielsen Feltzing7afbb492008-11-17 10:14:48 +0000372 my $cmd = "$ROOT/tools/convbdf -f $ROOT/fonts/*bdf >/dev/null 2>&1";
Jonas Häggqvist45290b42008-07-20 23:16:39 +0000373 print($cmd."\n") if $verbose;
Jonas Häggqvistca61b5b2008-07-20 23:12:03 +0000374 system($cmd);
375 chdir("../../");
Daniel Stenberga420dc32006-05-10 21:57:08 +0000376
Daniel Stenberga420dc32006-05-10 21:57:08 +0000377 if($fonts < 2) {
378 # fonts-only package, return
379 return;
380 }
381 }
382
Jens Arnold109a8672008-08-26 23:41:52 +0000383 # create the file so the database does not try indexing a folder
Thomas Martitz67d61f22010-07-25 13:44:30 +0000384 open(IGNORE, ">$temp_dir/database.ignore") || die "can't open database.ignore";
Jens Arnold109a8672008-08-26 23:41:52 +0000385 close(IGNORE);
Thomas Martitz249bba02011-12-24 11:56:46 +0000386
387 # the samsung ypr0 has a loader script that's needed in the zip
Lorenzo Miorie876f4d2013-09-10 22:48:34 +0200388 if ($modelname =~ /samsungypr[01]/) {
Thomas Martitz249bba02011-12-24 11:56:46 +0000389 glob_copy("$ROOT/utils/ypr0tools/rockbox.sh", "$temp_dir/");
390 }
Dominik Riebeling6eebdb32012-05-19 11:00:16 +0200391 # add .nomedia on Android
392 # in the zip.
393 if ($modelname =~ /android/) {
394 open(NOMEDIA, ">$temp_dir/.nomedia") || die "can't open .nomedia";
395 close(NOMEDIA);
396 }
397
Thomas Martitz67d61f22010-07-25 13:44:30 +0000398 glob_mkdir("$temp_dir/langs");
399 glob_mkdir("$temp_dir/rocks");
400 glob_mkdir("$temp_dir/rocks/games");
401 glob_mkdir("$temp_dir/rocks/apps");
402 glob_mkdir("$temp_dir/rocks/demos");
403 glob_mkdir("$temp_dir/rocks/viewers");
Jonathan Gordonfda7d722007-08-06 13:42:52 +0000404
Jonathan Gordonb2ecf1b2007-05-29 08:17:32 +0000405 if ($recording) {
Thomas Martitz67d61f22010-07-25 13:44:30 +0000406 glob_mkdir("$temp_dir/recpresets");
Jonathan Gordonb2ecf1b2007-05-29 08:17:32 +0000407 }
Daniel Stenberg19bba742007-03-12 10:51:08 +0000408
409 if($swcodec) {
Thomas Martitz67d61f22010-07-25 13:44:30 +0000410 glob_mkdir("$temp_dir/eqs");
Daniel Stenberg25bb98d2005-07-12 11:11:50 +0000411
Sean Bartellb5716df2011-06-24 01:25:21 -0400412 glob_copy("$ROOT/lib/rbcodec/dsp/eqs/*.cfg", "$temp_dir/eqs/"); # equalizer presets
Daniel Stenberg19bba742007-03-12 10:51:08 +0000413 }
414
Thomas Martitz67d61f22010-07-25 13:44:30 +0000415 glob_mkdir("$temp_dir/wps");
Thomas Martitz66b6fdb2012-06-10 20:28:36 +0200416 glob_mkdir("$temp_dir/icons");
Thomas Martitz67d61f22010-07-25 13:44:30 +0000417 glob_mkdir("$temp_dir/themes");
Thomas Martitz67d61f22010-07-25 13:44:30 +0000418 glob_mkdir("$temp_dir/codepages");
Daniel Stenberg19bba742007-03-12 10:51:08 +0000419
420 if($bitmap) {
Jens Arnold738c37c2007-04-01 13:09:22 +0000421 system("$ROOT/tools/codepages");
422 }
423 else {
424 system("$ROOT/tools/codepages -m");
425 }
Jonas Häggqvist4077f232008-07-20 22:20:32 +0000426
Thomas Martitz67d61f22010-07-25 13:44:30 +0000427 glob_move('*.cp', "$temp_dir/codepages/");
Jens Arnold738c37c2007-04-01 13:09:22 +0000428
Thomas Martitz35ac4072010-07-13 14:17:52 +0000429 if($bitmap && $depth > 1) {
Thomas Martitz67d61f22010-07-25 13:44:30 +0000430 glob_mkdir("$temp_dir/backdrops");
Daniel Stenberga52018c2005-08-11 20:48:34 +0000431 }
432
Thomas Martitz67d61f22010-07-25 13:44:30 +0000433 glob_mkdir("$temp_dir/codecs");
Thomas Martitz35ac4072010-07-13 14:17:52 +0000434
Dominik Riebeling70b81e62011-05-31 21:26:18 +0000435 # Android has codecs installed as native libraries so they are not needed
436 # in the zip.
437 if ($modelname !~ /android/) {
Sean Bartellf40bfc92011-06-25 21:32:25 -0400438 find(find_copyfile(qr/.*\.codec/, abs_path("$temp_dir/codecs/")), 'lib/rbcodec/codecs');
Dominik Riebeling70b81e62011-05-31 21:26:18 +0000439 }
Thomas Martitz35ac4072010-07-13 14:17:52 +0000440
441 # remove directory again if no codec was copied
Thomas Martitz67d61f22010-07-25 13:44:30 +0000442 rmdir("$temp_dir/codecs");
Thomas Martitz35ac4072010-07-13 14:17:52 +0000443
Thomas Martitz67d61f22010-07-25 13:44:30 +0000444 find(find_copyfile(qr/\.(rock|ovl|lua)/, abs_path("$temp_dir/rocks/")), 'apps/plugins');
Daniel Stenberg760b7b92004-05-21 19:05:27 +0000445
William Wilgus90118f12019-07-26 01:30:00 -0500446 #lua example scripts
447 if(-e "$ROOT/apps/plugins/lua_scripts") {
448 glob_mkdir("$temp_dir/rocks/demos/lua_scripts");
449 glob_copy("$ROOT/apps/plugins/lua_scripts/*.lua", "$temp_dir/rocks/demos/lua_scripts/");
450 }
451
Teruaki Kawashimae5b1a7d2010-11-21 13:47:56 +0000452 # exclude entries for the image file types not supported by the imageviewer for the target.
453 my $viewers = "$ROOT/apps/plugins/viewers.config";
454 my $c="cat $viewers | gcc $cppdef -I. -I$firmdir/export -E -P -include config.h -";
455
456 open VIEWERS, "$c|" or die "can't open viewers.config";
Linus Nielsen Feltzing7afbb492008-11-17 10:14:48 +0000457 my @viewers = <VIEWERS>;
Linus Nielsen Feltzing8287ce52004-07-13 09:45:39 +0000458 close VIEWERS;
Daniel Stenberg760b7b92004-05-21 19:05:27 +0000459
Thomas Martitz67d61f22010-07-25 13:44:30 +0000460 open VIEWERS, ">$temp_dir/viewers.config" or
461 die "can't create $temp_dir/viewers.config";
Jonathan Gordonfda7d722007-08-06 13:42:52 +0000462
Daniel Stenbergaf482602005-10-05 08:02:10 +0000463 foreach my $line (@viewers) {
464 if ($line =~ /([^,]*),([^,]*),/) {
465 my ($ext, $plugin)=($1, $2);
466 my $r = "${plugin}.rock";
Daniel Stenberg006d6c52005-11-02 07:32:16 +0000467 my $oname;
Daniel Stenbergaf482602005-10-05 08:02:10 +0000468
469 my $dir = $r;
470 my $name;
471
472 # strip off the last slash and file name part
473 $dir =~ s/(.*)\/(.*)/$1/;
474 # store the file name part
475 $name = $2;
476
Daniel Stenberg006d6c52005-11-02 07:32:16 +0000477 # get .ovl name (file part only)
478 $oname = $name;
479 $oname =~ s/\.rock$/.ovl/;
480
Daniel Stenbergaf482602005-10-05 08:02:10 +0000481 # print STDERR "$ext $plugin $dir $name $r\n";
482
Thomas Martitz67d61f22010-07-25 13:44:30 +0000483 if(-e "$temp_dir/rocks/$name") {
Daniel Stenbergaf482602005-10-05 08:02:10 +0000484 if($dir ne "rocks") {
485 # target is not 'rocks' but the plugins are always in that
486 # dir at first!
Thomas Martitz67d61f22010-07-25 13:44:30 +0000487 move("$temp_dir/rocks/$name", "$temp_dir/rocks/$r");
Daniel Stenbergaf482602005-10-05 08:02:10 +0000488 }
489 print VIEWERS $line;
Björn Stenberg0d53b482004-05-21 21:01:20 +0000490 }
Thomas Martitz67d61f22010-07-25 13:44:30 +0000491 elsif(-e "$temp_dir/rocks/$r") {
Daniel Stenbergefae7542005-03-03 22:09:41 +0000492 # in case the same plugin works for multiple extensions, it
493 # was already moved to the viewers dir
Daniel Stenbergaf482602005-10-05 08:02:10 +0000494 print VIEWERS $line;
Daniel Stenbergefae7542005-03-03 22:09:41 +0000495 }
Daniel Stenberg006d6c52005-11-02 07:32:16 +0000496
Thomas Martitz67d61f22010-07-25 13:44:30 +0000497 if(-e "$temp_dir/rocks/$oname") {
Daniel Stenbergdb44b292005-03-04 08:19:56 +0000498 # if there's an "overlay" file for the .rock, move that as
499 # well
Thomas Martitz67d61f22010-07-25 13:44:30 +0000500 move("$temp_dir/rocks/$oname", "$temp_dir/rocks/$dir");
Daniel Stenbergdb44b292005-03-04 08:19:56 +0000501 }
Björn Stenberg0d53b482004-05-21 21:01:20 +0000502 }
Linus Nielsen Feltzing8287ce52004-07-13 09:45:39 +0000503 }
504 close VIEWERS;
Linus Nielsen Feltzing7afbb492008-11-17 10:14:48 +0000505
Jonathan Gordonfda7d722007-08-06 13:42:52 +0000506 open CATEGORIES, "$ROOT/apps/plugins/CATEGORIES" or
507 die "can't open CATEGORIES";
Linus Nielsen Feltzing7afbb492008-11-17 10:14:48 +0000508 my @rock_targetdirs = <CATEGORIES>;
Jonathan Gordonfda7d722007-08-06 13:42:52 +0000509 close CATEGORIES;
510 foreach my $line (@rock_targetdirs) {
511 if ($line =~ /([^,]*),(.*)/) {
512 my ($plugin, $dir)=($1, $2);
Thomas Martitz67d61f22010-07-25 13:44:30 +0000513 move("$temp_dir/rocks/${plugin}.rock", "$temp_dir/rocks/$dir/${plugin}.rock");
514 if(-e "$temp_dir/rocks/${plugin}.ovl") {
Andrew Mahone5621fd32009-05-07 01:23:13 +0000515 # if there's an "overlay" file for the .rock, move that as
516 # well
Thomas Martitz67d61f22010-07-25 13:44:30 +0000517 move("$temp_dir/rocks/${plugin}.ovl", "$temp_dir/rocks/$dir");
Andrew Mahone5621fd32009-05-07 01:23:13 +0000518 }
Thomas Martitz67d61f22010-07-25 13:44:30 +0000519 if(-e "$temp_dir/rocks/${plugin}.lua") {
Maurus Cuelenaere78e98fd2009-10-28 23:05:02 +0000520 # if this is a lua script, move it to the appropriate dir
Thomas Martitz67d61f22010-07-25 13:44:30 +0000521 move("$temp_dir/rocks/${plugin}.lua", "$temp_dir/rocks/$dir/");
Maurus Cuelenaere78e98fd2009-10-28 23:05:02 +0000522 }
Jonathan Gordonfda7d722007-08-06 13:42:52 +0000523 }
524 }
Linus Nielsen Feltzing7afbb492008-11-17 10:14:48 +0000525
Thomas Martitz67d61f22010-07-25 13:44:30 +0000526 glob_unlink("$temp_dir/rocks/*.lua"); # Clean up unwanted *.lua files (e.g. actions.lua, buttons.lua)
Maurus Cuelenaere78e98fd2009-10-28 23:05:02 +0000527
Thomas Martitz67d61f22010-07-25 13:44:30 +0000528 copy("$ROOT/apps/tagnavi.config", "$temp_dir/");
529 copy("$ROOT/apps/plugins/disktidy.config", "$temp_dir/rocks/apps/");
Linus Nielsen Feltzing7afbb492008-11-17 10:14:48 +0000530
Daniel Stenberg19bba742007-03-12 10:51:08 +0000531 if($bitmap) {
Thomas Martitz67d61f22010-07-25 13:44:30 +0000532 copy("$ROOT/apps/plugins/sokoban.levels", "$temp_dir/rocks/games/sokoban.levels"); # sokoban levels
533 copy("$ROOT/apps/plugins/snake2.levels", "$temp_dir/rocks/games/snake2.levels"); # snake2 levels
534 copy("$ROOT/apps/plugins/rockbox-fonts.config", "$temp_dir/rocks/viewers/");
Jens Arnoldbdba1d02004-11-20 10:45:27 +0000535 }
536
Thomas Martitz67d61f22010-07-25 13:44:30 +0000537 if(-e "$temp_dir/rocks/demos/pictureflow.rock") {
Andrew Mahone802ea462009-05-23 07:55:14 +0000538 copy("$ROOT/apps/plugins/bitmaps/native/pictureflow_emptyslide.100x100x16.bmp",
Thomas Martitz67d61f22010-07-25 13:44:30 +0000539 "$temp_dir/rocks/demos/pictureflow_emptyslide.bmp");
Andrew Mahone802ea462009-05-23 07:55:14 +0000540 my ($pf_logo);
541 if ($width < 200) {
542 $pf_logo = "pictureflow_logo.100x18x16.bmp";
543 } else {
544 $pf_logo = "pictureflow_logo.193x34x16.bmp";
545 }
546 copy("$ROOT/apps/plugins/bitmaps/native/$pf_logo",
Thomas Martitz67d61f22010-07-25 13:44:30 +0000547 "$temp_dir/rocks/demos/pictureflow_splash.bmp");
Andrew Mahone802ea462009-05-23 07:55:14 +0000548
Andrew Mahone932f30d2008-12-27 00:26:15 +0000549 }
550
Jens Arnoldbdba1d02004-11-20 10:45:27 +0000551 if($image) {
552 # image is blank when this is a simulator
553 if( filesize("rockbox.ucl") > 1000 ) {
Thomas Martitz67d61f22010-07-25 13:44:30 +0000554 copy("rockbox.ucl", "$temp_dir/rockbox.ucl"); # UCL for flashing
Jens Arnoldbdba1d02004-11-20 10:45:27 +0000555 }
556 if( filesize("rombox.ucl") > 1000) {
Thomas Martitz67d61f22010-07-25 13:44:30 +0000557 copy("rombox.ucl", "$temp_dir/rombox.ucl"); # UCL for flashing
Daniel Stenbergb1563522004-06-14 15:04:46 +0000558 }
Miika Pekkarinenb1af4e62007-01-08 18:21:12 +0000559
560 # Check for rombox.target
561 if ($image=~/(.*)\.(\w+)$/)
562 {
563 my $romfile = "rombox.$2";
564 if (filesize($romfile) > 1000)
565 {
Thomas Martitz67d61f22010-07-25 13:44:30 +0000566 copy($romfile, "$temp_dir/$romfile");
Miika Pekkarinenb1af4e62007-01-08 18:21:12 +0000567 }
568 }
Daniel Stenberg760b7b92004-05-21 19:05:27 +0000569 }
570
Thomas Martitz67d61f22010-07-25 13:44:30 +0000571 glob_mkdir("$temp_dir/docs");
Daniel Stenberg50d40ea2006-03-25 22:52:28 +0000572 for(("COPYING",
Brandon Low05dccc32006-01-18 20:54:13 +0000573 "LICENSES",
Jonathan Gordon06797c22007-06-18 09:32:28 +0000574 "KNOWN_ISSUES"
Daniel Stenberg50d40ea2006-03-25 22:52:28 +0000575 )) {
Thomas Martitz67d61f22010-07-25 13:44:30 +0000576 copy("$ROOT/docs/$_", "$temp_dir/docs/$_.txt");
Daniel Stenberg760b7b92004-05-21 19:05:27 +0000577 }
Jonathan Gordon06797c22007-06-18 09:32:28 +0000578 if ($fonts) {
Thomas Martitz67d61f22010-07-25 13:44:30 +0000579 copy("$ROOT/docs/profontdoc.txt", "$temp_dir/docs/profontdoc.txt");
Jonathan Gordon06797c22007-06-18 09:32:28 +0000580 }
Paul Loudenf8b59132007-06-19 04:21:06 +0000581 for(("sample.colours",
Jonathan Gordon06797c22007-06-18 09:32:28 +0000582 "sample.icons"
583 )) {
Thomas Martitz67d61f22010-07-25 13:44:30 +0000584 copy("$ROOT/docs/$_", "$temp_dir/docs/$_");
Jonathan Gordon06797c22007-06-18 09:32:28 +0000585 }
Daniel Stenberg760b7b92004-05-21 19:05:27 +0000586
Daniel Stenberg51413e42005-11-14 15:06:51 +0000587 # Now do the WPS dance
588 if(-d "$ROOT/wps") {
Dave Chapmanefe556f2011-02-26 21:30:20 +0000589 my $wps_build_cmd="perl $ROOT/wps/wpsbuild.pl ";
590 $wps_build_cmd=$wps_build_cmd."-v " if $verbose;
591 $wps_build_cmd=$wps_build_cmd." --tempdir=$temp_dir --rbdir=$rbdir -r $ROOT -m $modelname $ROOT/wps/WPSLIST $target";
592 print "wpsbuild: $wps_build_cmd\n" if $verbose;
Björn Stenbergad8d6032008-11-24 22:16:07 +0000593 system("$wps_build_cmd");
Dave Chapmanefe556f2011-02-26 21:30:20 +0000594 print "wps_build_cmd: done\n" if $verbose;
Daniel Stenberg51413e42005-11-14 15:06:51 +0000595 }
596 else {
597 print STDERR "No wps module present, can't do the WPS magic!\n";
598 }
Jonathan Gordon3114f2c2009-11-16 03:53:49 +0000599
600 # until buildwps.pl is fixed, manually copy the classic_statusbar theme across
Thomas Martitz67d61f22010-07-25 13:44:30 +0000601 mkdir "$temp_dir/wps/classic_statusbar", 0777;
602 glob_copy("$ROOT/wps/classic_statusbar/*.bmp", "$temp_dir/wps/classic_statusbar");
Jonathan Gordon3114f2c2009-11-16 03:53:49 +0000603 if ($swcodec) {
Dave Chapmanefe556f2011-02-26 21:30:20 +0000604 if ($depth == 16) {
605 copy("$ROOT/wps/classic_statusbar.sbs", "$temp_dir/wps");
606 } elsif ($depth > 1) {
607 copy("$ROOT/wps/classic_statusbar.grey.sbs", "$temp_dir/wps/classic_statusbar.sbs");
608 } else {
609 copy("$ROOT/wps/classic_statusbar.mono.sbs", "$temp_dir/wps/classic_statusbar.sbs");
610 }
Jonathan Gordon3114f2c2009-11-16 03:53:49 +0000611 } else {
Thomas Martitz67d61f22010-07-25 13:44:30 +0000612 copy("$ROOT/wps/classic_statusbar.112x64x1.sbs", "$temp_dir/wps/classic_statusbar.sbs");
Jonathan Gordon3114f2c2009-11-16 03:53:49 +0000613 }
Jonathan Gordon6ec176c2009-11-20 07:05:22 +0000614 if ($remote_depth != $depth) {
Dave Chapmanefe556f2011-02-26 21:30:20 +0000615 copy("$ROOT/wps/classic_statusbar.mono.sbs", "$temp_dir/wps/classic_statusbar.rsbs");
616 } else {
617 copy("$temp_dir/wps/classic_statusbar.sbs", "$temp_dir/wps/classic_statusbar.rsbs");
618 }
Thomas Martitz67d61f22010-07-25 13:44:30 +0000619 copy("$temp_dir/wps/rockbox_none.sbs", "$temp_dir/wps/rockbox_none.rsbs");
Daniel Stenberg51413e42005-11-14 15:06:51 +0000620
Daniel Stenberg10d11ff2007-04-20 12:53:40 +0000621 # and the info file
Thomas Martitz67d61f22010-07-25 13:44:30 +0000622 copy("rockbox-info.txt", "$temp_dir/rockbox-info.txt");
Daniel Stenberg10d11ff2007-04-20 12:53:40 +0000623
Daniel Stenberg8ebbe992008-02-18 12:17:34 +0000624 # copy the already built lng files
Thomas Martitz67d61f22010-07-25 13:44:30 +0000625 glob_copy('apps/lang/*lng', "$temp_dir/langs/");
Dominik Riebelingd6ef5a02012-05-19 17:14:35 +0200626 glob_copy('apps/lang/*.zip', "$temp_dir/langs/");
Daniel Stenberg760b7b92004-05-21 19:05:27 +0000627
Maurus Cuelenaerebcfba082009-05-21 21:58:18 +0000628 # copy the .lua files
Thomas Martitz67d61f22010-07-25 13:44:30 +0000629 glob_mkdir("$temp_dir/rocks/viewers/lua/");
630 glob_copy('apps/plugins/lua/*.lua', "$temp_dir/rocks/viewers/lua/");
Daniel Stenberg760b7b92004-05-21 19:05:27 +0000631}
632
633my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
634 localtime(time);
635
636$mon+=1;
637$year+=1900;
638
Daniel Stenbergb46f1ac2007-03-12 12:56:35 +0000639#$date=sprintf("%04d%02d%02d", $year,$mon, $mday);
640#$shortdate=sprintf("%02d%02d%02d", $year%100,$mon, $mday);
Daniel Stenberg760b7b92004-05-21 19:05:27 +0000641
Daniel Stenberg760b7b92004-05-21 19:05:27 +0000642# made once for all targets
643sub runone {
Daniel Stenberg19bba742007-03-12 10:51:08 +0000644 my ($target, $fonts)=@_;
Rafaël Carréf984a652010-07-07 18:30:17 +0000645
Dave Chapmaneddf6242011-02-26 21:23:20 +0000646 # Strip the leading / from $rbdir unless we are installing an application
647 # build - the layout is different (no .rockbox, but bin/lib/share)
648 unless ($app && $install) {
Thomas Martitz9c0b2472010-08-01 16:15:27 +0000649 $rbdir = substr($rbdir, 1);
650 }
Thomas Martitz35ac4072010-07-13 14:17:52 +0000651
Björn Stenbergad8d6032008-11-24 22:16:07 +0000652 # build a full install .rockbox ($rbdir) directory
Antoine Cellerier32c65bb2008-08-26 22:00:37 +0000653 buildzip($target, $fonts);
Daniel Stenberga420dc32006-05-10 21:57:08 +0000654
Jonas Häggqvist4077f232008-07-20 22:20:32 +0000655 unlink($output);
Daniel Stenberga420dc32006-05-10 21:57:08 +0000656
Jens Arnold96aba332008-08-26 23:21:20 +0000657 if($fonts == 1) {
658 # Don't include image file in fonts-only package
659 undef $target;
Daniel Stenberga420dc32006-05-10 21:57:08 +0000660 }
Jens Arnold96aba332008-08-26 23:21:20 +0000661 if($target && ($target !~ /(mod|ajz|wma)\z/i)) {
662 # On some targets, the image goes into .rockbox.
Teruaki Kawashima3c11c562010-09-25 14:47:11 +0000663 copy("$target", ".rockbox/$target");
Jens Arnold96aba332008-08-26 23:21:20 +0000664 undef $target;
665 }
666
Thomas Martitz7ed1a5f2009-04-12 01:28:33 +0000667 if($install) {
Michael Stummvoll1f06ca42010-12-28 10:30:46 +0000668 if($mklinks) {
669 my $cwd = getcwd();
670 symlink("$cwd/.rockbox", "$install/.rockbox");
671 print "link .rockbox $install\n" if $verbose;
672 } else {
673 make_install(".rockbox", $install) or die "MKDIRFAILED\n";
674 rmtree(".rockbox");
675 print "rm .rockbox\n" if $verbose;
676 }
Nils Wallméniusc6ccf752008-11-04 10:47:48 +0000677 }
678 else {
Thomas Martitz35ac4072010-07-13 14:17:52 +0000679 unless (".rockbox" eq $rbdir) {
Thomas Martitz240923a2010-08-02 20:34:47 +0000680 mkpath($rbdir);
681 rmtree($rbdir);
Thomas Martitz35ac4072010-07-13 14:17:52 +0000682 move(".rockbox", $rbdir);
683 print "mv .rockbox $rbdir\n" if $verbose;
684 }
Björn Stenbergad8d6032008-11-24 22:16:07 +0000685 system("$ziptool $output $rbdir $target >/dev/null");
Thomas Martitz35ac4072010-07-13 14:17:52 +0000686 print "$ziptool $output $rbdir $target >/dev/null\n" if $verbose;
Teruaki Kawashima3c11c562010-09-25 14:47:11 +0000687 rmtree("$rbdir");
688 print "rm $rbdir\n" if $verbose;
Nils Wallméniusc6ccf752008-11-04 10:47:48 +0000689 }
Daniel Stenberg760b7b92004-05-21 19:05:27 +0000690};
691
Daniel Stenbergcdde25b2005-02-18 13:47:17 +0000692if(!$exe) {
693 # not specified, guess!
Daniel Stenberg43924632004-09-15 13:20:49 +0000694 if($target =~ /(recorder|ondio)/i) {
Daniel Stenbergb1563522004-06-14 15:04:46 +0000695 $exe = "ajbrec.ajz";
696 }
Daniel Stenberg6af4a6c2005-01-31 19:33:39 +0000697 elsif($target =~ /iriver/i) {
698 $exe = "rockbox.iriver";
699 }
Daniel Stenbergb1563522004-06-14 15:04:46 +0000700 else {
701 $exe = "archos.mod";
702 }
703}
Thomas Martitz35ac4072010-07-13 14:17:52 +0000704elsif(($exe =~ /rockboxui/)) {
Daniel Stenbergf9e18ae2005-03-03 22:31:30 +0000705 # simulator, exclude the exe file
706 $exe = "";
707}
Thomas Martitz43cdfde2010-09-26 10:32:43 +0000708elsif($exe eq "librockbox.so") {
709 # android, exclude the binary
710 $exe="";
711}
Daniel Stenbergb1563522004-06-14 15:04:46 +0000712
Daniel Stenberg19bba742007-03-12 10:51:08 +0000713runone($exe, $incfonts);