summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtools/buildtheme.pl251
1 files changed, 251 insertions, 0 deletions
diff --git a/tools/buildtheme.pl b/tools/buildtheme.pl
new file mode 100755
index 0000000000..7f135fd121
--- /dev/null
+++ b/tools/buildtheme.pl
@@ -0,0 +1,251 @@
1#!/usr/bin/perl
2# __________ __ ___.
3# Open \______ \ ____ ____ | | _\_ |__ _______ ___
4# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7# \/ \/ \/ \/ \/
8# $Id: wpsbuild.pl 24813 2010-02-21 19:10:57Z kugel $
9#
10
11use strict;
12use Getopt::Long qw(:config pass_through); # pass_through so not confused by -DTYPE_STUFF
13
14my $ROOT="..";
15my $verbose;
16my $rbdir=".rockbox";
17my $wpslist;
18my $target;
19my $modelname;
20
21# Get options
22GetOptions ( 'r|root=s' => \$ROOT,
23 'm|modelname=s' => \$modelname,
24 'v|verbose' => \$verbose,
25 'rbdir=s' => \$rbdir, # If we want to put in a different directory
26 );
27
28($wpslist, $target) = @ARGV;
29
30my $firmdir="$ROOT/firmware";
31my $cppdef = $target;
32my @depthlist = ( 16, 8, 4, 2, 1 );
33
34
35# LCD sizes
36my ($main_height, $main_width, $main_depth);
37my ($remote_height, $remote_width, $remote_depth);
38my $has_remote;
39
40
41if(!$wpslist) {
42 print "Usage: wpsbuilds.pl <WPSLIST> <target>\n",
43 "Run this script in the root of the target build, and it will put all the\n",
44 "stuff in $rbdir/wps/\n";
45 exit;
46}
47
48sub getlcdsizes
49{
50 my ($remote) = @_;
51
52 open(GCC, ">gcctemp");
53 if($remote) {
54 # Get the remote LCD screen size
55 print GCC <<STOP
56\#include "config.h"
57#ifdef HAVE_REMOTE_LCD
58Height: LCD_REMOTE_HEIGHT
59Width: LCD_REMOTE_WIDTH
60Depth: LCD_REMOTE_DEPTH
61#endif
62STOP
63;
64 }
65 else {
66 print GCC <<STOP
67\#include "config.h"
68Height: LCD_HEIGHT
69Width: LCD_WIDTH
70Depth: LCD_DEPTH
71STOP
72;
73}
74 close(GCC);
75
76 my $c="cat gcctemp | gcc $cppdef -I. -I$firmdir/export -E -P -";
77
78 #print "CMD $c\n";
79
80 open(GETSIZE, "$c|");
81
82 my ($height, $width, $depth);
83 while(<GETSIZE>) {
84 if($_ =~ /^Height: (\d*)/) {
85 $height = $1;
86 }
87 elsif($_ =~ /^Width: (\d*)/) {
88 $width = $1;
89 }
90 elsif($_ =~ /^Depth: (\d*)/) {
91 $depth = $1;
92 }
93 if($height && $width && $depth) {
94 last;
95 }
96 }
97 close(GETSIZE);
98 unlink("gcctemp");
99
100 return ($height, $width, $depth);
101}
102
103# Get the LCD sizes first
104($main_height, $main_width, $main_depth) = (320,240,16);#getlcdsizes();
105($remote_height, $remote_width, $remote_depth) = ();#getlcdsizes(1);
106
107#print "LCD: ${main_width}x${main_height}x${main_depth}\n";
108$has_remote = 1 if ($remote_height && $remote_width && $remote_depth);
109
110my $isrwps;
111my $within;
112
113my %theme;
114
115
116sub match {
117 my ($string, $pattern)=@_;
118
119 $pattern =~ s/\*/.*/g;
120 $pattern =~ s/\?/./g;
121
122 return ($string =~ /^$pattern\z/);
123}
124
125sub matchdisplaystring {
126 my ($string)=@_;
127 return ($string =~ /${main_width}x${main_height}x${main_depth}/i) ||
128 ($string =~ /r${remote_width}x${remote_height}x${remote_depth}/i);
129}
130
131sub mkdirs
132{
133 my ($themename) = @_;
134 mkdir "$rbdir", 0777;
135 mkdir "$rbdir/wps", 0777;
136 mkdir "$rbdir/themes", 0777;
137
138 if( -d "$rbdir/wps/$themename") {
139 # print STDERR "wpsbuild warning: directory wps/$themename already exists!\n";
140 }
141 else
142 {
143 mkdir "$rbdir/wps/$themename", 0777;
144 }
145}
146
147sub buildcfg {
148 my ($themename) = @_;
149 my @out;
150
151 push @out, <<MOO
152\#
153\# generated by wpsbuild.pl
154\# $themename is made by $theme{"Author"}
155\#
156MOO
157;
158 my %configs = (
159 "Name" => "# Theme Name",
160 "WPS" => "wps", "RWPS" => "rwps",
161 "FMS" => "fms", "RFMS" => "rfms",
162 "SBS" => "sbs", "RSBS" => "rsbs",
163 "Font" => "font", "Remote Font" => "remote font",
164 "Statusbar" => "statusbar", "Remote Statusbar" => "remote statusbar",
165 "selector type" => "selector type", "Remote Selector Type" => "remote selector type",
166 "backdrop" => "backdrop", "iconset" => "iconset", "viewers iconset" => "viewers iconset",
167 "remote iconset" => "remote iconset", "remote viewers iconset" => "remote viewers iconset",
168 "Foreground Color" => "foreground color", "Background Color" => "background color",
169 "backdrop" => "backdrop"
170 );
171
172 while( my ($k, $v) = each %configs )
173 {
174 if ($k =~ "Name")
175 {
176 # do nothing
177 }
178 elsif ($k =~ "/WPS|RWPS|FMS|RFMF|SBS|RSBS/" && exists($theme{$k}))
179 {
180 push (@out, "$v: $themename.$v\n");
181 }
182 elsif (exists($theme{$k}))
183 {
184 push (@out, "$v: $theme{$k}\n");
185 }
186 }
187
188 # if(-f "$rbdir/themes/$themename.cfg") {
189 # print STDERR "wpsbuild warning: $themename.cfg already exists!\n";
190 # }
191 # else {
192 open(CFG, ">$rbdir/themes/$themename.cfg");
193 print CFG @out;
194 close(CFG);
195 # }
196}
197
198open(WPS, "<$wpslist");
199while(<WPS>) {
200 my $l = $_;
201
202 # remove CR
203 $l =~ s/\r//g;
204 if($l =~ /^ *\#/) {
205 # skip comment
206 next;
207 }
208 if($l =~ /^ *<(r|)wps>/i) {
209 $isrwps = $1;
210 $within = 1;
211 undef %theme;
212 next;
213 }
214 if($within) {
215 if($l =~ /^ *<\/${isrwps}wps>/i) {
216 #get the skin directory
217 $wpslist =~ /(.*)WPSLIST/;
218 my $wpsdir = $1;
219 $within = 0;
220
221 next if (!exists($theme{Name}));
222 mkdirs($theme{Name});
223 buildcfg($theme{Name});
224
225
226
227
228
229
230 }
231 elsif($l =~ /^([\w ]*)\.?(.*):\s*(.*)/) {
232 my $var = $1;
233 my $extra = $2;
234 my $value = $3;
235 if (!exists($theme{$var}))
236 {
237 if (!$extra ||
238 ($extra && (match($target, $extra) || matchdisplaystring($extra))))
239 {
240 $theme{$var} = $value;
241 # print "\'$var\': $value\n";
242 }
243 }
244 }
245 else{
246 #print "Unknown line: $l!\n";
247 }
248 }
249}
250
251close(WPS);