blob: 03a1f664d580a1bf75c85e8cadeae86a589a826f [file] [log] [blame]
Daniel Stenberg792c9982005-11-14 14:24:17 +00001#!/usr/bin/perl
Daniel Stenberg8a918022005-11-14 15:05:53 +00002# __________ __ ___.
3# Open \______ \ ____ ____ | | _\_ |__ _______ ___
4# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7# \/ \/ \/ \/ \/
8# $Id$
9#
10
11$ROOT="..";
12
13if($ARGV[0] eq "-r") {
14 $ROOT=$ARGV[1];
15 shift @ARGV;
16 shift @ARGV;
17}
18
19my $verbose;
20if($ARGV[0] eq "-v") {
21 $verbose =1;
22 shift @ARGV;
23}
24
25my $firmdir="$ROOT/firmware";
Daniel Stenberg792c9982005-11-14 14:24:17 +000026
27my $wpslist=$ARGV[0];
28
Daniel Stenberg8a918022005-11-14 15:05:53 +000029my $target = $ARGV[1];
30my $cppdef = $target;
Christi Scarboroughcc9292f2006-05-11 14:27:12 +000031my @depthlist = ( 16, 8, 4, 2, 1 );
Daniel Stenberg8a918022005-11-14 15:05:53 +000032
Daniel Stenberg792c9982005-11-14 14:24:17 +000033if(!$wpslist) {
Daniel Stenberg8a918022005-11-14 15:05:53 +000034 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";
Daniel Stenberg792c9982005-11-14 14:24:17 +000037 exit;
38}
39
Daniel Stenberg8a918022005-11-14 15:05:53 +000040sub getlcdsizes {
Daniel Stenberg2bace6a2005-11-17 22:39:26 +000041 my ($remote) = @_;
42
Daniel Stenberg8a918022005-11-14 15:05:53 +000043 open(GCC, ">gcctemp");
Daniel Stenberg2bace6a2005-11-17 22:39:26 +000044 if($remote) {
45 # Get the remote LCD screen size
46 print GCC <<STOP
47\#include "config.h"
48#ifdef HAVE_REMOTE_LCD
49Height: LCD_REMOTE_HEIGHT
50Width: LCD_REMOTE_WIDTH
Christi Scarboroughcc9292f2006-05-11 14:27:12 +000051Depth: LCD_REMOTE_DEPTH
Daniel Stenberg2bace6a2005-11-17 22:39:26 +000052#endif
53STOP
54;
55 }
56 else {
Daniel Stenberg8a918022005-11-14 15:05:53 +000057 print GCC <<STOP
58\#include "config.h"
Daniel Stenberg2624b552006-03-18 21:17:05 +000059#ifdef HAVE_LCD_BITMAP
Daniel Stenberg8a918022005-11-14 15:05:53 +000060Height: LCD_HEIGHT
61Width: LCD_WIDTH
Christi Scarboroughcc9292f2006-05-11 14:27:12 +000062Depth: LCD_DEPTH
Daniel Stenberg2624b552006-03-18 21:17:05 +000063#endif
Daniel Stenberg8a918022005-11-14 15:05:53 +000064STOP
65;
Daniel Stenberg2bace6a2005-11-17 22:39:26 +000066}
Daniel Stenberg8a918022005-11-14 15:05:53 +000067 close(gcc);
68
69 my $c="cat gcctemp | gcc $cppdef -I. -I$firmdir/export -E -P -";
70
71 #print "CMD $c\n";
72
73 open(GETSIZE, "$c|");
74
75 my ($height, $width);
76 while(<GETSIZE>) {
77 if($_ =~ /^Height: (\d*)/) {
78 $height = $1;
79 }
80 elsif($_ =~ /^Width: (\d*)/) {
81 $width = $1;
82 }
Christi Scarboroughcc9292f2006-05-11 14:27:12 +000083 elsif($_ =~ /^Depth: (\d*)/) {
84 $depth = $1;
85 }
86 if($height && $width && $depth) {
Daniel Stenberg8a918022005-11-14 15:05:53 +000087 last;
88 }
89 }
90 close(GETSIZE);
91 unlink("gcctemp");
92
Christi Scarboroughcc9292f2006-05-11 14:27:12 +000093 return ($height, $width, $depth);
Daniel Stenberg8a918022005-11-14 15:05:53 +000094}
95
96sub mkdirs {
97 my $wpsdir = $wps;
Daniel Stenberg2bace6a2005-11-17 22:39:26 +000098 $wpsdir =~ s/\.(r|)wps//;
Daniel Stenberg8a918022005-11-14 15:05:53 +000099 mkdir ".rockbox/wps", 0777;
Christi Scarborough32a43e22005-11-18 15:33:05 +0000100 mkdir ".rockbox/themes", 0777;
Daniel Stenberg2bace6a2005-11-17 22:39:26 +0000101
102 if( -d ".rockbox/wps/$wpsdir") {
Daniel Stenberg88f359f2005-11-17 23:47:23 +0000103 #print STDERR "wpsbuild warning: directory wps/$wpsdir already exists!\n";
Daniel Stenberg2bace6a2005-11-17 22:39:26 +0000104 }
Christi Scarboroughcc9292f2006-05-11 14:27:12 +0000105 else
106 {
107 mkdir ".rockbox/wps/$wpsdir", 0777;
Daniel Stenberg2bace6a2005-11-17 22:39:26 +0000108 }
Daniel Stenberg8a918022005-11-14 15:05:53 +0000109}
110
111sub copywps {
112 # we assume that we copy the WPS files from the same dir the WPSLIST
113 # file is located in
114 my $dir;
Christi Scarboroughcc9292f2006-05-11 14:27:12 +0000115 my @filelist;
116 my $file;
Daniel Stenberg8a918022005-11-14 15:05:53 +0000117
118 if($wpslist =~ /(.*)WPSLIST/) {
119 $dir = $1;
Christi Scarboroughcc9292f2006-05-11 14:27:12 +0000120# system("cp $dir/$wps .rockbox/wps/");
121 # print "$req_t_wps $req_g_wps\n";
Daniel Stenberg88f359f2005-11-17 23:47:23 +0000122
Christi Scarboroughcc9292f2006-05-11 14:27:12 +0000123 if (-e "$dir/$req_t_wps" ) {
124 system("cp $dir/$req_t_wps .rockbox/wps/$wps");
125
126 } elsif (-e "$dir/$req_g_wps") {
127 system("cp $dir/$req_g_wps .rockbox/wps/$wps");
128
129 open(WPSFILE, "$dir/$req_g_wps");
130 while (<WPSFILE>) {
131 $filelist[$#filelist + 1] = $1 if (/\|([^|]*?.bmp)\|/);
132 }
133 close(WPSFILE);
134
Linus Nielsen Feltzing3b524852006-05-15 07:47:29 +0000135 if (-e "$dir/$wps_prefix/$req_g") {
136 foreach $file (@filelist) {
137 system("cp $dir/$wps_prefix/$req_g/$file .rockbox/wps/$wps_prefix/");
138 }
139 }
140 elsif (-e "$dir/$wps_prefix") {
Christi Scarboroughcc9292f2006-05-11 14:27:12 +0000141 foreach $file (@filelist) {
142 system("cp $dir/$wps_prefix/$file .rockbox/wps/$wps_prefix/");
143 }
144 }
145 else {
146 print STDERR "beep, no dir to copy WPS from!\n";
147 }
148
149 } else {
150 print STDERR "Skipping $wps - no matching resolution.\n";
151 }
152 } else {
153 print STDERR "No source directory!\n";
Daniel Stenberg8a918022005-11-14 15:05:53 +0000154 }
155}
156
Daniel Stenberg792c9982005-11-14 14:24:17 +0000157sub buildcfg {
158 my $cfg = $wps;
Daniel Stenberg8a918022005-11-14 15:05:53 +0000159 my @out;
Daniel Stenberg792c9982005-11-14 14:24:17 +0000160
Daniel Stenberg2bace6a2005-11-17 22:39:26 +0000161 $cfg =~ s/\.(r|)wps/.cfg/;
Daniel Stenberg792c9982005-11-14 14:24:17 +0000162
Daniel Stenberg8a918022005-11-14 15:05:53 +0000163 push @out, <<MOO
164\#
Daniel Stenberg792c9982005-11-14 14:24:17 +0000165\# $cfg generated by wpsbuild.pl
Daniel Stenberg8a918022005-11-14 15:05:53 +0000166\# $wps is made by $author
Daniel Stenberg792c9982005-11-14 14:24:17 +0000167\#
168wps: /.rockbox/wps/$wps
Daniel Stenberg792c9982005-11-14 14:24:17 +0000169MOO
170;
Daniel Stenberg8a918022005-11-14 15:05:53 +0000171 if($font) {
172 push @out, "font: /.rockbox/fonts/$font\n";
173 }
174 if($statusbar) {
175 push @out, "statusbar: $statusbar\n";
176 }
Christi Scarborough32a43e22005-11-18 15:33:05 +0000177 if($rwps && $has_remote ) {
Daniel Stenberg2bace6a2005-11-17 22:39:26 +0000178 push @out, "rwps: /.rockbox/wps/$rwps\n";
179 }
Daniel Stenberg8a918022005-11-14 15:05:53 +0000180
Daniel Stenberg2bace6a2005-11-17 22:39:26 +0000181 if(-f ".rockbox/wps/$cfg") {
182 print STDERR "wpsbuild warning: wps/$cfg already exists!\n";
183 }
184 else {
Christi Scarborough32a43e22005-11-18 15:33:05 +0000185 open(CFG, ">.rockbox/themes/$cfg");
Daniel Stenberg2bace6a2005-11-17 22:39:26 +0000186 print CFG @out;
187 close(CFG);
188 }
Daniel Stenberg792c9982005-11-14 14:24:17 +0000189}
190
Daniel Stenberg2bace6a2005-11-17 22:39:26 +0000191# Get the LCD sizes first
Christi Scarboroughcc9292f2006-05-11 14:27:12 +0000192my ($main_height, $main_width, $main_depth) = getlcdsizes();
193my ($remote_height, $remote_width, $remote_depth) = getlcdsizes(1);
Daniel Stenberg2bace6a2005-11-17 22:39:26 +0000194
Christi Scarboroughcc9292f2006-05-11 14:27:12 +0000195#print "LCD: ${main_height}x${main_width}x${main_depth}\n";
196$has_remote = true if ($remote_height && $remote_width && remote_depth);
Christi Scarborough32a43e22005-11-18 15:33:05 +0000197
Daniel Stenberg792c9982005-11-14 14:24:17 +0000198open(WPS, "<$wpslist");
199while(<WPS>) {
200 my $l = $_;
201 if($l =~ /^ *\#/) {
202 # skip comment
203 next;
204 }
Daniel Stenberg2bace6a2005-11-17 22:39:26 +0000205 if($l =~ /^ *<(r|)wps>/i) {
206 $isrwps = $1;
Daniel Stenberg792c9982005-11-14 14:24:17 +0000207 $within = 1;
Christi Scarborough32a43e22005-11-18 15:33:05 +0000208 # undef is a unary operator (!)
209 undef $wps;
Christi Scarboroughcc9292f2006-05-11 14:27:12 +0000210 undef $wps_prefix;
Christi Scarborough32a43e22005-11-18 15:33:05 +0000211 undef $rwps;
212 undef $width;
213 undef $height;
214 undef $font;
215 undef $statusbar;
216 undef $author;
Christi Scarboroughcc9292f2006-05-11 14:27:12 +0000217 undef $req_g_wps;
218 undef $req_t_wps;
Daniel Stenberg792c9982005-11-14 14:24:17 +0000219 next;
220 }
221 if($within) {
Daniel Stenberg2bace6a2005-11-17 22:39:26 +0000222 if($l =~ /^ *<\/${isrwps}wps>/i) {
223 # Get the required width and height
Christi Scarboroughcc9292f2006-05-11 14:27:12 +0000224 my ($rheight, $rwidth, $rdepth);
Daniel Stenberg2bace6a2005-11-17 22:39:26 +0000225 if($isrwps) {
Christi Scarboroughcc9292f2006-05-11 14:27:12 +0000226 ($rheight, $rwidth, $rdepth) =
227 ($remote_height, $remote_width, $remote_depth);
Daniel Stenberg2bace6a2005-11-17 22:39:26 +0000228 }
229 else {
Christi Scarboroughcc9292f2006-05-11 14:27:12 +0000230 ($rheight, $rwidth, $rdepth) =
231 ($main_height, $main_width, $main_depth);
Daniel Stenberg2bace6a2005-11-17 22:39:26 +0000232 }
Daniel Stenberg8a918022005-11-14 15:05:53 +0000233
234 if(!$rheight || !$rwidth) {
Daniel Stenberg2624b552006-03-18 21:17:05 +0000235 #printf STDERR "wpsbuild notice: No %sLCD size, skipping $wps\n",
Daniel Stenberg2bace6a2005-11-17 22:39:26 +0000236 $isrwps?"remote ":"";
Christi Scarborough32a43e22005-11-18 15:33:05 +0000237 $within = 0;
Daniel Stenberg2bace6a2005-11-17 22:39:26 +0000238 next;
Daniel Stenberg8a918022005-11-14 15:05:53 +0000239 }
Christi Scarboroughcc9292f2006-05-11 14:27:12 +0000240 $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);
246
Linus Nielsen Feltzing3b524852006-05-15 07:47:29 +0000247 $req_g = $rwidth . "x" . $rheight . "x" . $d;
248
249 $req_g_wps = $wps_prefix . "." . $req_g . ".wps";
Christi Scarboroughcc9292f2006-05-11 14:27:12 +0000250 last if (-e "$wpsdir/$req_g_wps");
251 }
252 $req_t_wps = $wps_prefix . ".txt" . ".wps";
Daniel Stenberg8a918022005-11-14 15:05:53 +0000253
Daniel Stenberg5f9f9bc2005-11-14 15:10:40 +0000254 #print "LCD: $wps wants $height x $width\n";
255 #print "LCD: is $rheight x $rwidth\n";
Daniel Stenberg8a918022005-11-14 15:05:53 +0000256
Christi Scarboroughcc9292f2006-05-11 14:27:12 +0000257 #print "gwps: $wpsdir/$req_g_wps" . "\n";
258 if (-e "$wpsdir/$req_g_wps" || -e "$wpsdir/$req_t_wps" ) {
Daniel Stenberg8a918022005-11-14 15:05:53 +0000259 #
260 # The target model has an LCD that is suitable for this
261 # WPS
262 #
Daniel Stenberg5f9f9bc2005-11-14 15:10:40 +0000263 #print "Size requirement is fine!\n";
Christi Scarboroughcc9292f2006-05-11 14:27:12 +0000264 mkdirs() if (-e "$wpsdir/$req_g_wps");
Daniel Stenberg88f359f2005-11-17 23:47:23 +0000265 if(!$isrwps) {
266 # We only make .cfg files for <wps> sections:
267 buildcfg();
268 }
Daniel Stenberg8a918022005-11-14 15:05:53 +0000269 copywps();
270 }
Daniel Stenberg5f9f9bc2005-11-14 15:10:40 +0000271 else {
Christi Scarboroughcc9292f2006-05-11 14:27:12 +0000272 #print "(${wps_prefix}-${rwidth}x${rheight}x$rdepth) ";
273 print "Skip $wps due to size restraints\n";
Daniel Stenberg5f9f9bc2005-11-14 15:10:40 +0000274 }
Daniel Stenberg792c9982005-11-14 14:24:17 +0000275 $within = 0;
276 }
277 elsif($l =~ /^Name: (.*)/i) {
Daniel Stenberg88f359f2005-11-17 23:47:23 +0000278 # Note that in the case this is within <rwps>, $wps will contain the
279 # name of the rwps. Use $isrwps to figure out what type it is.
Christi Scarboroughcc9292f2006-05-11 14:27:12 +0000280 $wps = $wps_prefix = $1;
281 $wps_prefix =~ s/\.(r|)wps//;
282 # print $wps_prefix . "\n";
Daniel Stenberg792c9982005-11-14 14:24:17 +0000283 }
Daniel Stenberg2bace6a2005-11-17 22:39:26 +0000284 elsif($l =~ /^RWPS: (.*)/i) {
285 $rwps = $1;
286 }
Daniel Stenberg8a918022005-11-14 15:05:53 +0000287 elsif($l =~ /^Author: (.*)/i) {
288 $author = $1;
289 }
290 elsif($l =~ /^Width: (.*)/i) {
291 $width = $1;
292 }
293 elsif($l =~ /^Height: (.*)/i) {
294 $height = $1;
295 }
Daniel Stenberg792c9982005-11-14 14:24:17 +0000296 elsif($l =~ /^Font: (.*)/i) {
297 $font = $1;
298 }
299 elsif($l =~ /^Statusbar: (.*)/i) {
300 $statusbar = $1;
301 }
302 }
303}
304
Christi Scarboroughcc9292f2006-05-11 14:27:12 +0000305close(WPS);