diff options
author | Jonathan Gordon <rockbox@jdgordon.info> | 2010-06-03 12:18:20 +0000 |
---|---|---|
committer | Jonathan Gordon <rockbox@jdgordon.info> | 2010-06-03 12:18:20 +0000 |
commit | d68710e9fc96ebe551009f7d9f02fe1f481847e0 (patch) | |
tree | af8293ffab40a77b49df8f8a7aa95389677b4afe /tools | |
parent | f04c742f40029decf4960c30fcb8a3106d98f8d1 (diff) | |
download | rockbox-d68710e9fc96ebe551009f7d9f02fe1f481847e0.tar.gz rockbox-d68710e9fc96ebe551009f7d9f02fe1f481847e0.zip |
Add a new script to build the themes. WIP and heavily based on wpsbuild.pl
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26509 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/buildtheme.pl | 251 |
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 | |||
11 | use strict; | ||
12 | use Getopt::Long qw(:config pass_through); # pass_through so not confused by -DTYPE_STUFF | ||
13 | |||
14 | my $ROOT=".."; | ||
15 | my $verbose; | ||
16 | my $rbdir=".rockbox"; | ||
17 | my $wpslist; | ||
18 | my $target; | ||
19 | my $modelname; | ||
20 | |||
21 | # Get options | ||
22 | GetOptions ( '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 | |||
30 | my $firmdir="$ROOT/firmware"; | ||
31 | my $cppdef = $target; | ||
32 | my @depthlist = ( 16, 8, 4, 2, 1 ); | ||
33 | |||
34 | |||
35 | # LCD sizes | ||
36 | my ($main_height, $main_width, $main_depth); | ||
37 | my ($remote_height, $remote_width, $remote_depth); | ||
38 | my $has_remote; | ||
39 | |||
40 | |||
41 | if(!$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 | |||
48 | sub 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 | ||
58 | Height: LCD_REMOTE_HEIGHT | ||
59 | Width: LCD_REMOTE_WIDTH | ||
60 | Depth: LCD_REMOTE_DEPTH | ||
61 | #endif | ||
62 | STOP | ||
63 | ; | ||
64 | } | ||
65 | else { | ||
66 | print GCC <<STOP | ||
67 | \#include "config.h" | ||
68 | Height: LCD_HEIGHT | ||
69 | Width: LCD_WIDTH | ||
70 | Depth: LCD_DEPTH | ||
71 | STOP | ||
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 | |||
110 | my $isrwps; | ||
111 | my $within; | ||
112 | |||
113 | my %theme; | ||
114 | |||
115 | |||
116 | sub match { | ||
117 | my ($string, $pattern)=@_; | ||
118 | |||
119 | $pattern =~ s/\*/.*/g; | ||
120 | $pattern =~ s/\?/./g; | ||
121 | |||
122 | return ($string =~ /^$pattern\z/); | ||
123 | } | ||
124 | |||
125 | sub 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 | |||
131 | sub 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 | |||
147 | sub 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 | \# | ||
156 | MOO | ||
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 | |||
198 | open(WPS, "<$wpslist"); | ||
199 | while(<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 | |||
251 | close(WPS); | ||