Tetrox renamed to Rockblox -- remove old screenshots and add updated ones for Rockblox
[Rockbox.git] / wps / wpsbuild.pl
blob4f92b876ac57843f33b9858f1bb6b7a6e0b26f74
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 #ifdef HAVE_LCD_BITMAP
60 Height: LCD_HEIGHT
61 Width: LCD_WIDTH
62 Depth: LCD_DEPTH
63 #endif
64 STOP
67 close(gcc);
69 my $c="cat gcctemp | gcc $cppdef -I. -I$firmdir/export -E -P -";
71 #print "CMD $c\n";
73 open(GETSIZE, "$c|");
75 my ($height, $width);
76 while(<GETSIZE>) {
77 if($_ =~ /^Height: (\d*)/) {
78 $height = $1;
80 elsif($_ =~ /^Width: (\d*)/) {
81 $width = $1;
83 elsif($_ =~ /^Depth: (\d*)/) {
84 $depth = $1;
86 if($height && $width && $depth) {
87 last;
90 close(GETSIZE);
91 unlink("gcctemp");
93 return ($height, $width, $depth);
96 sub mkdirs {
97 my $wpsdir = $wps;
98 $wpsdir =~ s/\.(r|)wps//;
99 mkdir ".rockbox/wps", 0777;
100 mkdir ".rockbox/themes", 0777;
102 if( -d ".rockbox/wps/$wpsdir") {
103 #print STDERR "wpsbuild warning: directory wps/$wpsdir already exists!\n";
105 else
107 mkdir ".rockbox/wps/$wpsdir", 0777;
111 sub copywps {
112 # we assume that we copy the WPS files from the same dir the WPSLIST
113 # file is located in
114 my $dir;
115 my @filelist;
116 my $file;
118 if($wpslist =~ /(.*)WPSLIST/) {
119 $dir = $1;
120 # system("cp $dir/$wps .rockbox/wps/");
121 # print "$req_t_wps $req_g_wps\n";
123 if (-e "$dir/$req_t_wps" ) {
124 system("cp $dir/$req_t_wps .rockbox/wps/$wps");
126 } elsif (-e "$dir/$req_g_wps") {
127 system("cp $dir/$req_g_wps .rockbox/wps/$wps");
129 open(WPSFILE, "$dir/$req_g_wps");
130 while (<WPSFILE>) {
131 $filelist[$#filelist + 1] = $1 if (/\|([^|]*?.bmp)\|/);
133 close(WPSFILE);
135 if (-e "$dir/$wps_prefix/$req_g") {
136 foreach $file (@filelist) {
137 system("cp $dir/$wps_prefix/$req_g/$file .rockbox/wps/$wps_prefix/");
140 elsif (-e "$dir/$wps_prefix") {
141 foreach $file (@filelist) {
142 system("cp $dir/$wps_prefix/$file .rockbox/wps/$wps_prefix/");
145 else {
146 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($statusbar) {
175 push @out, "statusbar: $statusbar\n";
177 if($rwps && $has_remote ) {
178 push @out, "rwps: /.rockbox/wps/$rwps\n";
181 if(-f ".rockbox/wps/$cfg") {
182 print STDERR "wpsbuild warning: wps/$cfg already exists!\n";
184 else {
185 open(CFG, ">.rockbox/themes/$cfg");
186 print CFG @out;
187 close(CFG);
191 # Get the LCD sizes first
192 my ($main_height, $main_width, $main_depth) = getlcdsizes();
193 my ($remote_height, $remote_width, $remote_depth) = getlcdsizes(1);
195 #print "LCD: ${main_height}x${main_width}x${main_depth}\n";
196 $has_remote = true if ($remote_height && $remote_width && remote_depth);
198 open(WPS, "<$wpslist");
199 while(<WPS>) {
200 my $l = $_;
201 if($l =~ /^ *\#/) {
202 # skip comment
203 next;
205 if($l =~ /^ *<(r|)wps>/i) {
206 $isrwps = $1;
207 $within = 1;
208 # undef is a unary operator (!)
209 undef $wps;
210 undef $wps_prefix;
211 undef $rwps;
212 undef $width;
213 undef $height;
214 undef $font;
215 undef $statusbar;
216 undef $author;
217 undef $req_g_wps;
218 undef $req_t_wps;
219 next;
221 if($within) {
222 if($l =~ /^ *<\/${isrwps}wps>/i) {
223 # Get the required width and height
224 my ($rheight, $rwidth, $rdepth);
225 if($isrwps) {
226 ($rheight, $rwidth, $rdepth) =
227 ($remote_height, $remote_width, $remote_depth);
229 else {
230 ($rheight, $rwidth, $rdepth) =
231 ($main_height, $main_width, $main_depth);
234 if(!$rheight || !$rwidth) {
235 #printf STDERR "wpsbuild notice: No %sLCD size, skipping $wps\n",
236 $isrwps?"remote ":"";
237 $within = 0;
238 next;
240 $wpslist =~ /(.*)WPSLIST/;
241 my $wpsdir = $1;
242 # If this WPS installable on this platform, one of the following
243 # two files will be present
244 foreach $d (@depthlist) {
245 next if ($d > $rdepth);
247 $req_g = $rwidth . "x" . $rheight . "x" . $d;
249 $req_g_wps = $wps_prefix . "." . $req_g . ".wps";
250 last if (-e "$wpsdir/$req_g_wps");
252 if ($isrwps) {
253 $req_g = $req_g . "." . $main_width . "x" . $main_height . "x" . "$main_depth";
255 $req_g_wps = $wps_prefix . "." . $req_g . ".wps";
256 last if (-e "$wpsdir/$req_g_wps");
259 $req_t_wps = $wps_prefix . ".txt" . ".wps";
261 #print "LCD: $wps wants $height x $width\n";
262 #print "LCD: is $rheight x $rwidth\n";
264 #print "gwps: $wpsdir/$req_g_wps" . "\n";
265 if (-e "$wpsdir/$req_g_wps" || -e "$wpsdir/$req_t_wps" ) {
267 # The target model has an LCD that is suitable for this
268 # WPS
270 #print "Size requirement is fine!\n";
271 mkdirs() if (-e "$wpsdir/$req_g_wps");
272 if(!$isrwps) {
273 # We only make .cfg files for <wps> sections:
274 buildcfg();
276 copywps();
278 else {
279 #print "(${wps_prefix}-${rwidth}x${rheight}x$rdepth) ";
280 print "Skip $wps due to size restraints\n";
282 $within = 0;
284 elsif($l =~ /^Name: (.*)/i) {
285 # Note that in the case this is within <rwps>, $wps will contain the
286 # name of the rwps. Use $isrwps to figure out what type it is.
287 $wps = $wps_prefix = $1;
288 $wps_prefix =~ s/\.(r|)wps//;
289 # print $wps_prefix . "\n";
291 elsif($l =~ /^RWPS: (.*)/i) {
292 $rwps = $1;
294 elsif($l =~ /^RWPS\.${main_width}x${main_height}x$main_depth: (.*)/i) {
295 $rwps = $1;
297 elsif($l =~ /^Author: (.*)/i) {
298 $author = $1;
300 elsif($l =~ /^Width: (.*)/i) {
301 $width = $1;
303 elsif($l =~ /^Height: (.*)/i) {
304 $height = $1;
306 elsif($l =~ /^Font: (.*)/i) {
307 $font = $1;
309 elsif($l =~ /^Font\.${main_width}x${main_height}x$main_depth: (.*)/i) {
310 $font = $1;
312 elsif($l =~ /^Statusbar: (.*)/i) {
313 $statusbar = $1;
318 close(WPS);