Minor tweak to the audio thread buffer filling logic
[Rockbox.git] / wps / wpsbuild.pl
blob46aa46eeb89d94cefc0b0114a28d35373479b811
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 copywps {
110 # we assume that we copy the WPS files from the same dir the WPSLIST
111 # file is located in
112 my $dir;
113 my @filelist;
114 my $file;
116 if($wpslist =~ /(.*)WPSLIST/) {
117 $dir = $1;
118 # system("cp $dir/$wps .rockbox/wps/");
119 # print "$req_t_wps $req_g_wps\n";
121 if (-e "$dir/$req_t_wps" ) {
122 system("cp $dir/$req_t_wps .rockbox/wps/$wps");
124 } elsif (-e "$dir/$req_g_wps") {
125 system("cp $dir/$req_g_wps .rockbox/wps/$wps");
127 open(WPSFILE, "$dir/$req_g_wps");
128 while (<WPSFILE>) {
129 $filelist[$#filelist + 1] = $1 if (/\|([^|]*?.bmp)\|/);
131 close(WPSFILE);
133 if ($#filelist >= 0) {
134 if (-e "$dir/$wps_prefix/$req_g") {
135 foreach $file (@filelist) {
136 system("cp $dir/$wps_prefix/$req_g/$file .rockbox/wps/$wps_prefix/");
139 elsif (-e "$dir/$wps_prefix") {
140 foreach $file (@filelist) {
141 system("cp $dir/$wps_prefix/$file .rockbox/wps/$wps_prefix/");
144 else {
145 print STDERR "beep, no dir to copy WPS from!\n";
149 } else {
150 print STDERR "Skipping $wps - no matching resolution.\n";
152 } else {
153 print STDERR "No source directory!\n";
157 sub buildcfg {
158 my $cfg = $wps;
159 my @out;
161 $cfg =~ s/\.(r|)wps/.cfg/;
163 push @out, <<MOO
165 \# $cfg generated by wpsbuild.pl
166 \# $wps is made by $author
168 wps: /.rockbox/wps/$wps
171 if($font) {
172 push @out, "font: /.rockbox/fonts/$font\n";
174 if($fgcolor) {
175 push @out, "foreground color: $fgcolor\n";
177 if($bgcolor) {
178 push @out, "background color: $bgcolor\n";
180 if($statusbar) {
181 push @out, "statusbar: $statusbar\n";
183 if($rwps && $has_remote ) {
184 push @out, "rwps: /.rockbox/wps/$rwps\n";
187 if(-f ".rockbox/wps/$cfg") {
188 print STDERR "wpsbuild warning: wps/$cfg already exists!\n";
190 else {
191 open(CFG, ">.rockbox/themes/$cfg");
192 print CFG @out;
193 close(CFG);
197 # Get the LCD sizes first
198 my ($main_height, $main_width, $main_depth) = getlcdsizes();
199 my ($remote_height, $remote_width, $remote_depth) = getlcdsizes(1);
201 #print "LCD: ${main_height}x${main_width}x${main_depth}\n";
202 $has_remote = 1 if ($remote_height && $remote_width && remote_depth);
204 open(WPS, "<$wpslist");
205 while(<WPS>) {
206 my $l = $_;
207 if($l =~ /^ *\#/) {
208 # skip comment
209 next;
211 if($l =~ /^ *<(r|)wps>/i) {
212 $isrwps = $1;
213 $within = 1;
214 # undef is a unary operator (!)
215 undef $wps;
216 undef $wps_prefix;
217 undef $rwps;
218 undef $width;
219 undef $height;
220 undef $font;
221 undef $fgcolor;
222 undef $bgcolor;
223 undef $statusbar;
224 undef $author;
225 undef $req_g_wps;
226 undef $req_t_wps;
227 next;
229 if($within) {
230 if($l =~ /^ *<\/${isrwps}wps>/i) {
231 # Get the required width and height
232 my ($rheight, $rwidth, $rdepth);
233 if($isrwps) {
234 ($rheight, $rwidth, $rdepth) =
235 ($remote_height, $remote_width, $remote_depth);
237 else {
238 ($rheight, $rwidth, $rdepth) =
239 ($main_height, $main_width, $main_depth);
242 if(!$rheight || !$rwidth) {
243 #printf STDERR "wpsbuild notice: No %sLCD size, skipping $wps\n",
244 #$isrwps?"remote ":"";
245 $within = 0;
246 next;
248 $wpslist =~ /(.*)WPSLIST/;
249 my $wpsdir = $1;
250 # If this WPS installable on this platform, one of the following
251 # two files will be present
252 foreach $d (@depthlist) {
253 next if ($d > $rdepth);
255 $req_g = $rwidth . "x" . $rheight . "x" . $d;
257 $req_g_wps = $wps_prefix . "." . $req_g . ".wps";
258 last if (-e "$wpsdir/$req_g_wps");
260 if ($isrwps) {
261 $req_g = $req_g . "." . $main_width . "x" . $main_height . "x" . "$main_depth";
263 $req_g_wps = $wps_prefix . "." . $req_g . ".wps";
264 last if (-e "$wpsdir/$req_g_wps");
267 $req_t_wps = $wps_prefix . ".txt" . ".wps";
269 #print "LCD: $wps wants $height x $width\n";
270 #print "LCD: is $rheight x $rwidth\n";
272 #print "gwps: $wpsdir/$req_g_wps" . "\n";
273 if (-e "$wpsdir/$req_g_wps" || -e "$wpsdir/$req_t_wps" ) {
275 # The target model has an LCD that is suitable for this
276 # WPS
278 #print "Size requirement is fine!\n";
279 mkdirs() if (-e "$wpsdir/$req_g_wps");
280 if(!$isrwps) {
281 # We only make .cfg files for <wps> sections:
282 buildcfg();
284 copywps();
286 else {
287 #print "(${wps_prefix}-${rwidth}x${rheight}x$rdepth) ";
288 #print "Skip $wps due to size restraints\n";
290 $within = 0;
292 elsif($l =~ /^Name: (.*)/i) {
293 # Note that in the case this is within <rwps>, $wps will contain the
294 # name of the rwps. Use $isrwps to figure out what type it is.
295 $wps = $wps_prefix = $1;
296 $wps_prefix =~ s/\.(r|)wps//;
297 # print $wps_prefix . "\n";
299 elsif($l =~ /^RWPS: (.*)/i) {
300 $rwps = $1;
302 elsif($l =~ /^RWPS\.${main_width}x${main_height}x$main_depth: (.*)/i) {
303 $rwps = $1;
305 elsif($l =~ /^Author: (.*)/i) {
306 $author = $1;
308 elsif($l =~ /^Width: (.*)/i) {
309 $width = $1;
311 elsif($l =~ /^Height: (.*)/i) {
312 $height = $1;
314 elsif($l =~ /^Font: (.*)/i) {
315 $font = $1;
317 elsif($l =~ /^Foreground Color: (.*)/i) {
318 $fgcolor = $1;
320 elsif($l =~ /^Background Color: (.*)/i) {
321 $bgcolor = $1;
323 elsif($l =~ /^Font\.${main_width}x${main_height}x$main_depth: (.*)/i) {
324 $font = $1;
326 elsif($l =~ /^Statusbar: (.*)/i) {
327 $statusbar = $1;
332 close(WPS);