Accept FS#8469 by Bryan Childs with a few adjustments: Remove duplicate strip_extensi...
[Rockbox.git] / wps / wpsbuild.pl
blobecc2993353db8022b9310f2e21ab52aebe75a480
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 $wpslist=$ARGV[0];
29 my $target = $ARGV[1];
30 my $cppdef = $target;
31 my @depthlist = ( 16, 8, 4, 2, 1 );
33 if(!$wpslist) {
34 print "Usage: wpsbuilds.pl <WPSLIST> <target>\n",
35 "Run this script in the root of the target build, and it will put all the\n",
36 "stuff in .rockbox/wps/\n";
37 exit;
40 sub getlcdsizes {
41 my ($remote) = @_;
43 open(GCC, ">gcctemp");
44 if($remote) {
45 # Get the remote LCD screen size
46 print GCC <<STOP
47 \#include "config.h"
48 #ifdef HAVE_REMOTE_LCD
49 Height: LCD_REMOTE_HEIGHT
50 Width: LCD_REMOTE_WIDTH
51 Depth: LCD_REMOTE_DEPTH
52 #endif
53 STOP
56 else {
57 print GCC <<STOP
58 \#include "config.h"
59 Height: LCD_HEIGHT
60 Width: LCD_WIDTH
61 Depth: LCD_DEPTH
62 STOP
65 close(GCC);
67 my $c="cat gcctemp | gcc $cppdef -I. -I$firmdir/export -E -P -";
69 #print "CMD $c\n";
71 open(GETSIZE, "$c|");
73 my ($height, $width);
74 while(<GETSIZE>) {
75 if($_ =~ /^Height: (\d*)/) {
76 $height = $1;
78 elsif($_ =~ /^Width: (\d*)/) {
79 $width = $1;
81 elsif($_ =~ /^Depth: (\d*)/) {
82 $depth = $1;
84 if($height && $width && $depth) {
85 last;
88 close(GETSIZE);
89 unlink("gcctemp");
91 return ($height, $width, $depth);
94 sub mkdirs {
95 my $wpsdir = $wps;
96 $wpsdir =~ s/\.(r|)wps//;
97 mkdir ".rockbox/wps", 0777;
98 mkdir ".rockbox/themes", 0777;
100 if( -d ".rockbox/wps/$wpsdir") {
101 #print STDERR "wpsbuild warning: directory wps/$wpsdir already exists!\n";
103 else
105 mkdir ".rockbox/wps/$wpsdir", 0777;
109 sub copybackdrop {
110 #copy the backdrop file into the build dir
112 $backdrop =~ /\/(.*backdrops\/(.*))/i;
113 `cp $ROOT/backdrops/$2 $1`;
116 sub copywps {
117 # we assume that we copy the WPS files from the same dir the WPSLIST
118 # file is located in
119 my $dir;
120 my @filelist;
121 my $file;
123 if($wpslist =~ /(.*)WPSLIST/) {
124 $dir = $1;
125 # system("cp $dir/$wps .rockbox/wps/");
126 # print "$req_t_wps $req_g_wps\n";
128 if (-e "$dir/$req_t_wps" ) {
129 system("cp $dir/$req_t_wps .rockbox/wps/$wps");
131 } elsif (-e "$dir/$req_g_wps") {
132 system("cp $dir/$req_g_wps .rockbox/wps/$wps");
134 open(WPSFILE, "$dir/$req_g_wps");
135 while (<WPSFILE>) {
136 $filelist[$#filelist + 1] = $1 if (/\|([^|]*?.bmp)\|/);
138 close(WPSFILE);
140 if ($#filelist >= 0) {
141 if (-e "$dir/$wps_prefix/$req_g") {
142 foreach $file (@filelist) {
143 system("cp $dir/$wps_prefix/$req_g/$file .rockbox/wps/$wps_prefix/");
146 elsif (-e "$dir/$wps_prefix") {
147 foreach $file (@filelist) {
148 system("cp $dir/$wps_prefix/$file .rockbox/wps/$wps_prefix/");
151 else {
152 print STDERR "beep, no dir to copy WPS from!\n";
156 } else {
157 print STDERR "Skipping $wps - no matching resolution.\n";
159 } else {
160 print STDERR "No source directory!\n";
164 sub buildcfg {
165 my $cfg = $wps;
166 my @out;
168 $cfg =~ s/\.(r|)wps/.cfg/;
170 push @out, <<MOO
172 \# $cfg generated by wpsbuild.pl
173 \# $wps is made by $author
175 wps: /.rockbox/wps/$wps
178 if($font) {
179 push @out, "font: /.rockbox/fonts/$font\n";
181 if($fgcolor) {
182 push @out, "foreground color: $fgcolor\n";
184 if($bgcolor) {
185 push @out, "background color: $bgcolor\n";
187 if($statusbar) {
188 push @out, "statusbar: $statusbar\n";
190 if($backdrop) {
191 push @out, "backdrop: $backdrop\n";
193 if($lineselectstart) {
194 push @out, "line selector start color: $lineselectstart\n";
196 if($lineselectend) {
197 push @out, "line selector end color: $lineselectend\n";
199 if($selecttype) {
200 push @out, "selector type: $selecttype\n";
202 if($iconset) {
203 push @out, "iconset: $iconset\n";
205 if($viewericon) {
206 push @out, "viewers iconset: $viewericon\n";
208 if($lineselecttextcolor) {
209 push @out, "line selector text color: $lineselecttextcolor\n";
211 if($filetylecolor) {
212 push @out, "filetype colours: $filetylecolor\n";
214 if($rwps && $has_remote ) {
215 push @out, "rwps: /.rockbox/wps/$rwps\n";
217 if(-f ".rockbox/wps/$cfg") {
218 print STDERR "wpsbuild warning: wps/$cfg already exists!\n";
220 else {
221 open(CFG, ">.rockbox/themes/$cfg");
222 print CFG @out;
223 close(CFG);
227 # Get the LCD sizes first
228 my ($main_height, $main_width, $main_depth) = getlcdsizes();
229 my ($remote_height, $remote_width, $remote_depth) = getlcdsizes(1);
231 #print "LCD: ${main_height}x${main_width}x${main_depth}\n";
232 $has_remote = 1 if ($remote_height && $remote_width && remote_depth);
234 open(WPS, "<$wpslist");
235 while(<WPS>) {
236 my $l = $_;
237 if($l =~ /^ *\#/) {
238 # skip comment
239 next;
241 if($l =~ /^ *<(r|)wps>/i) {
242 $isrwps = $1;
243 $within = 1;
244 # undef is a unary operator (!)
245 undef $wps;
246 undef $wps_prefix;
247 undef $rwps;
248 undef $width;
249 undef $height;
250 undef $font;
251 undef $fgcolor;
252 undef $bgcolor;
253 undef $statusbar;
254 undef $author;
255 undef $req_g_wps;
256 undef $req_t_wps;
257 undef $backdrop;
258 undef $lineselectstart;
259 undef $lineselectend;
260 undef $selecttype;
261 undef $iconset;
262 undef $viewericon;
263 undef $lineselecttextcolor;
264 undef $filetylecolor;
266 next;
268 if($within) {
269 if($l =~ /^ *<\/${isrwps}wps>/i) {
270 # Get the required width and height
271 my ($rheight, $rwidth, $rdepth);
272 if($isrwps) {
273 ($rheight, $rwidth, $rdepth) =
274 ($remote_height, $remote_width, $remote_depth);
276 else {
277 ($rheight, $rwidth, $rdepth) =
278 ($main_height, $main_width, $main_depth);
281 if(!$rheight || !$rwidth) {
282 #printf STDERR "wpsbuild notice: No %sLCD size, skipping $wps\n",
283 #$isrwps?"remote ":"";
284 $within = 0;
285 next;
287 $wpslist =~ /(.*)WPSLIST/;
288 my $wpsdir = $1;
289 # If this WPS installable on this platform, one of the following
290 # two files will be present
291 foreach $d (@depthlist) {
292 next if ($d > $rdepth);
294 $req_g = $rwidth . "x" . $rheight . "x" . $d;
296 $req_g_wps = $wps_prefix . "." . $req_g . ".wps";
297 last if (-e "$wpsdir/$req_g_wps");
299 if ($isrwps) {
300 $req_g = $req_g . "." . $main_width . "x" . $main_height . "x" . "$main_depth";
302 $req_g_wps = $wps_prefix . "." . $req_g . ".wps";
303 last if (-e "$wpsdir/$req_g_wps");
306 $req_t_wps = $wps_prefix . ".txt" . ".wps";
308 #print "LCD: $wps wants $height x $width\n";
309 #print "LCD: is $rheight x $rwidth\n";
311 #print "gwps: $wpsdir/$req_g_wps" . "\n";
312 if (-e "$wpsdir/$req_g_wps" || -e "$wpsdir/$req_t_wps" ) {
314 # The target model has an LCD that is suitable for this
315 # WPS
317 #print "Size requirement is fine!\n";
318 mkdirs() if (-e "$wpsdir/$req_g_wps");
319 if(!$isrwps) {
320 # We only make .cfg files for <wps> sections:
321 buildcfg();
323 copywps();
325 else {
326 #print "(${wps_prefix}-${rwidth}x${rheight}x$rdepth) ";
327 #print "Skip $wps due to size restraints\n";
329 $within = 0;
331 elsif($l =~ /^Name: (.*)/i) {
332 # Note that in the case this is within <rwps>, $wps will contain the
333 # name of the rwps. Use $isrwps to figure out what type it is.
334 $wps = $wps_prefix = $1;
335 $wps_prefix =~ s/\.(r|)wps//;
336 # print $wps_prefix . "\n";
338 elsif($l =~ /^RWPS: (.*)/i) {
339 $rwps = $1;
341 elsif($l =~ /^RWPS\.${main_width}x${main_height}x$main_depth: (.*)/i) {
342 $rwps = $1;
344 elsif($l =~ /^Author: (.*)/i) {
345 $author = $1;
347 elsif($l =~ /^Width: (.*)/i) {
348 $width = $1;
350 elsif($l =~ /^Width\.${main_width}x${main_height}x$main_depth: (.*)/i) {
351 $width = $1;
353 elsif($l =~ /^Height: (.*)/i) {
354 $height = $1;
356 elsif($l =~ /^Height\.${main_width}x${main_height}x$main_depth: (.*)/i) {
357 $height = $1;
359 elsif($l =~ /^Font: (.*)/i) {
360 $font = $1;
362 elsif($l =~ /^Foreground Color: (.*)/i) {
363 $fgcolor = $1;
365 elsif($l =~ /^Background Color: (.*)/i) {
366 $bgcolor = $1;
368 elsif($l =~ /^Font\.${main_width}x${main_height}x$main_depth: (.*)/i) {
369 $font = $1;
371 elsif($l =~ /^Statusbar: (.*)/i) {
372 $statusbar = $1;
374 elsif($l =~ /^Statusbar\.${main_width}x${main_height}x$main_depth: (.*)/i) {
375 $statusbar = $1;
377 elsif($l =~ /^Backdrop: (.*)/i) {
378 $backdrop = $1;
379 copybackdrop();
381 elsif($l =~ /^Backdrop\.${main_width}x${main_height}x$main_depth: (.*)/i) {
382 $backdrop = $1;
383 copybackdrop();
385 elsif($l =~ /^line selector start color: (.*)/i) {
386 $lineselectstart = $1;
388 elsif($l =~ /^line selector end color: (.*)/i) {
389 $lineselectend = $1;
391 elsif($l =~ /^selector type: (.*)/i) {
392 $selecttype = $1;
394 elsif($l =~ /^iconset: (.*)/i) {
395 $iconset = $1;
397 elsif($l =~ /^viewers iconset: (.*)/i) {
398 $viewericon = $1;
400 elsif($l =~ /^line selector text color: (.*)/i) {
401 $lineselecttextcolor = $1;
403 elsif($l =~ /^filetype colours: (.*)/i) {
404 $filetylecolor = $1;
406 else{
407 #print "Unknown line: $l!\n";
415 close(WPS);