Jonathan Gordon | d68710e | 2010-06-03 12:18:20 +0000 | [diff] [blame] | 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) { |
Jonathan Gordon | 30804e5 | 2010-06-03 13:44:41 +0000 | [diff] [blame] | 42 | print "Usage: buildtheme.pl <WPSLIST> <target>\n", |
Jonathan Gordon | d68710e | 2010-06-03 12:18:20 +0000 | [diff] [blame] | 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 |
Jonathan Gordon | 30804e5 | 2010-06-03 13:44:41 +0000 | [diff] [blame] | 104 | ($main_height, $main_width, $main_depth) = getlcdsizes(); |
| 105 | ($remote_height, $remote_width, $remote_depth) = getlcdsizes(1); |
Jonathan Gordon | d68710e | 2010-06-03 12:18:20 +0000 | [diff] [blame] | 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; |
Jonathan Gordon | 30804e5 | 2010-06-03 13:44:41 +0000 | [diff] [blame] | 137 | mkdir "$rbdir/icons", 0777; |
| 138 | mkdir "$rbdir/backdrops", 0777; |
Jonathan Gordon | d68710e | 2010-06-03 12:18:20 +0000 | [diff] [blame] | 139 | |
| 140 | if( -d "$rbdir/wps/$themename") { |
| 141 | # print STDERR "wpsbuild warning: directory wps/$themename already exists!\n"; |
| 142 | } |
| 143 | else |
| 144 | { |
| 145 | mkdir "$rbdir/wps/$themename", 0777; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | sub buildcfg { |
| 150 | my ($themename) = @_; |
| 151 | my @out; |
| 152 | |
| 153 | push @out, <<MOO |
| 154 | \# |
Jonathan Gordon | 30804e5 | 2010-06-03 13:44:41 +0000 | [diff] [blame] | 155 | \# generated by buildtheme.pl |
Jonathan Gordon | d68710e | 2010-06-03 12:18:20 +0000 | [diff] [blame] | 156 | \# $themename is made by $theme{"Author"} |
| 157 | \# |
| 158 | MOO |
| 159 | ; |
| 160 | my %configs = ( |
| 161 | "Name" => "# Theme Name", |
| 162 | "WPS" => "wps", "RWPS" => "rwps", |
| 163 | "FMS" => "fms", "RFMS" => "rfms", |
| 164 | "SBS" => "sbs", "RSBS" => "rsbs", |
| 165 | "Font" => "font", "Remote Font" => "remote font", |
| 166 | "Statusbar" => "statusbar", "Remote Statusbar" => "remote statusbar", |
| 167 | "selector type" => "selector type", "Remote Selector Type" => "remote selector type", |
| 168 | "backdrop" => "backdrop", "iconset" => "iconset", "viewers iconset" => "viewers iconset", |
| 169 | "remote iconset" => "remote iconset", "remote viewers iconset" => "remote viewers iconset", |
| 170 | "Foreground Color" => "foreground color", "Background Color" => "background color", |
| 171 | "backdrop" => "backdrop" |
| 172 | ); |
| 173 | |
| 174 | while( my ($k, $v) = each %configs ) |
| 175 | { |
| 176 | if ($k =~ "Name") |
| 177 | { |
| 178 | # do nothing |
| 179 | } |
Jonathan Gordon | 30804e5 | 2010-06-03 13:44:41 +0000 | [diff] [blame] | 180 | elsif ($k =~ /WPS|RWPS|FMS|RFMS|SBS|RSBS/ && exists($theme{$k})) |
Jonathan Gordon | d68710e | 2010-06-03 12:18:20 +0000 | [diff] [blame] | 181 | { |
| 182 | push (@out, "$v: $themename.$v\n"); |
| 183 | } |
Jonathan Gordon | 30804e5 | 2010-06-03 13:44:41 +0000 | [diff] [blame] | 184 | elsif ($k =~ /backdrop/ ) |
| 185 | { |
| 186 | if (exists($theme{$k})) |
| 187 | { |
| 188 | my $dst = $theme{$k}; |
| 189 | $dst =~ s/(\.[0-9]*x[0-9]*x[0-9]*)//; |
| 190 | push (@out, "$v: $theme{$k}\n"); |
| 191 | } |
| 192 | else |
| 193 | { |
| 194 | push (@out, "$v: -\n"); |
| 195 | } |
| 196 | } |
Jonathan Gordon | d68710e | 2010-06-03 12:18:20 +0000 | [diff] [blame] | 197 | elsif (exists($theme{$k})) |
| 198 | { |
| 199 | push (@out, "$v: $theme{$k}\n"); |
| 200 | } |
Jonathan Gordon | 30804e5 | 2010-06-03 13:44:41 +0000 | [diff] [blame] | 201 | else |
| 202 | { |
| 203 | push (@out, "$v: -\n"); |
| 204 | } |
Jonathan Gordon | d68710e | 2010-06-03 12:18:20 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | # if(-f "$rbdir/themes/$themename.cfg") { |
| 208 | # print STDERR "wpsbuild warning: $themename.cfg already exists!\n"; |
| 209 | # } |
| 210 | # else { |
| 211 | open(CFG, ">$rbdir/themes/$themename.cfg"); |
| 212 | print CFG @out; |
| 213 | close(CFG); |
| 214 | # } |
| 215 | } |
| 216 | |
Jonathan Gordon | 30804e5 | 2010-06-03 13:44:41 +0000 | [diff] [blame] | 217 | |
| 218 | sub copythemefont |
| 219 | { |
| 220 | my ($font) = @_; |
| 221 | #copy the font specified by the theme |
| 222 | |
| 223 | my $o=$font; |
| 224 | $o =~ s/\.fnt/\.bdf/; |
| 225 | mkdir "$rbdir/fonts"; |
| 226 | my $cmd ="$ROOT/tools/convbdf -f -o \"$rbdir/fonts/$font\" \"$ROOT/fonts/$o\" "; |
| 227 | # print "$cmd\n"; |
| 228 | `$cmd`; |
| 229 | } |
| 230 | |
| 231 | sub copyiconset |
| 232 | { |
| 233 | my ($iconset) = @_; |
| 234 | #copy the icon specified by the theme |
| 235 | |
| 236 | if ($iconset ne '') { |
| 237 | $iconset =~ s/.rockbox/$rbdir/; |
| 238 | $iconset =~ /\/(.*icons\/(.*))/i; |
| 239 | `cp $ROOT/icons/$2 $1`; |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | sub copybackdrop |
| 244 | { |
| 245 | my ($backdrop) = @_; |
| 246 | #copy the backdrop file into the build dir |
| 247 | if ($backdrop ne '') |
| 248 | { |
| 249 | my $dst = $backdrop; |
| 250 | $dst =~ s/(\.[0-9]*x[0-9]*x[0-9]*)//; |
| 251 | my $cmd = "cp $ROOT/$backdrop $rbdir/$dst"; |
| 252 | # print "$cmd\n"; |
| 253 | `$cmd`; |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | |
| 258 | sub copyskin |
| 259 | { |
| 260 | my ($themename, $skin, $ext) = @_; |
| 261 | # we assume that we copy the WPS files from the same dir the WPSLIST |
| 262 | # file is located in |
| 263 | my $dir; |
| 264 | my @filelist; |
| 265 | my $src; |
| 266 | my $dest; |
Jonathan Gordon | a5555c0 | 2010-06-03 13:59:32 +0000 | [diff] [blame] | 267 | my $sizestring; |
Jonathan Gordon | 30804e5 | 2010-06-03 13:44:41 +0000 | [diff] [blame] | 268 | |
Jonathan Gordon | a5555c0 | 2010-06-03 13:59:32 +0000 | [diff] [blame] | 269 | if($wpslist =~ /(.*)WPSFILE/) { |
Jonathan Gordon | 30804e5 | 2010-06-03 13:44:41 +0000 | [diff] [blame] | 270 | $dir = $1; |
| 271 | |
| 272 | # first try the actual filename given to us |
| 273 | # then $skin.widthxheightxdepths.ext |
| 274 | # then $skin.ext |
| 275 | $src = "${dir}$skin.$ext"; |
| 276 | if ( -e $src ) |
| 277 | { |
Jonathan Gordon | a5555c0 | 2010-06-03 13:59:32 +0000 | [diff] [blame] | 278 | if ($skin =~ /\w\.(\d*x\d*x\d*).*/) |
| 279 | { |
| 280 | $sizestring = $1; |
| 281 | } |
Jonathan Gordon | 30804e5 | 2010-06-03 13:44:41 +0000 | [diff] [blame] | 282 | my $cmd = "cp $src $rbdir/wps/$themename.$ext"; |
| 283 | `$cmd`; |
| 284 | } |
| 285 | else |
| 286 | { |
| 287 | my $is_remote = ($ext =~ /^r.../i); |
| 288 | my $width = $is_remote ? $remote_width : $main_width; |
| 289 | my $height = $is_remote ? $remote_height : $main_height; |
| 290 | my $depth = $is_remote ? $remote_depth : $main_depth; |
| 291 | |
| 292 | foreach my $d (@depthlist) |
| 293 | { |
| 294 | next if ($d > $depth); |
Jonathan Gordon | a5555c0 | 2010-06-03 13:59:32 +0000 | [diff] [blame] | 295 | $sizestring = "${width}x${height}x${d}"; |
| 296 | $src = "${dir}$skin.${sizestring}.$ext"; |
Jonathan Gordon | 30804e5 | 2010-06-03 13:44:41 +0000 | [diff] [blame] | 297 | last if (-e $src); |
| 298 | } |
| 299 | if (-e $src) |
| 300 | { |
| 301 | my $cmd = "cp $src $rbdir/wps/$themename.$ext"; |
Jonathan Gordon | 30804e5 | 2010-06-03 13:44:41 +0000 | [diff] [blame] | 302 | `$cmd`; |
| 303 | } |
| 304 | elsif (-e "${dir}$skin.$ext") |
| 305 | { |
| 306 | my $cmd = "cp ${dir}$skin.$ext $rbdir/wps/$themename.$ext"; |
| 307 | `$cmd`; |
| 308 | } |
| 309 | else |
| 310 | { |
| 311 | #print STDERR "buildtheme warning: No suitable skin file for $ext\n"; |
Jonathan Gordon | a5555c0 | 2010-06-03 13:59:32 +0000 | [diff] [blame] | 312 | return; |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | open(WPSFILE, "$rbdir/wps/$themename.$ext"); |
| 317 | while (<WPSFILE>) { |
| 318 | $filelist[$#filelist + 1] = $1 if (/\|([^|]*?.bmp)\|/); |
| 319 | } |
| 320 | close(WPSFILE); |
| 321 | if ($#filelist >= 0) |
| 322 | { |
| 323 | my $file; |
| 324 | if ($sizestring && -e "$dir/$themename/$sizestring") |
| 325 | { |
| 326 | foreach $file (@filelist) |
| 327 | { |
| 328 | system("cp $dir/$themename/$sizestring/$file $rbdir/wps/$themename/"); |
| 329 | } |
| 330 | } |
| 331 | elsif (-e "$dir/$themename") |
| 332 | { |
| 333 | foreach $file (@filelist) |
| 334 | { |
| 335 | system("cp $dir/$themename/$file $rbdir/wps/$themename/"); |
| 336 | } |
| 337 | } |
| 338 | else |
| 339 | { |
| 340 | print STDERR "beep, no dir to copy WPS from!\n"; |
Jonathan Gordon | 30804e5 | 2010-06-03 13:44:41 +0000 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | } |
| 344 | } |
| 345 | |
Jonathan Gordon | d68710e | 2010-06-03 12:18:20 +0000 | [diff] [blame] | 346 | open(WPS, "<$wpslist"); |
| 347 | while(<WPS>) { |
| 348 | my $l = $_; |
| 349 | |
| 350 | # remove CR |
| 351 | $l =~ s/\r//g; |
| 352 | if($l =~ /^ *\#/) { |
| 353 | # skip comment |
| 354 | next; |
| 355 | } |
| 356 | if($l =~ /^ *<(r|)wps>/i) { |
| 357 | $isrwps = $1; |
| 358 | $within = 1; |
| 359 | undef %theme; |
| 360 | next; |
| 361 | } |
| 362 | if($within) { |
| 363 | if($l =~ /^ *<\/${isrwps}wps>/i) { |
| 364 | #get the skin directory |
| 365 | $wpslist =~ /(.*)WPSLIST/; |
| 366 | my $wpsdir = $1; |
| 367 | $within = 0; |
| 368 | |
| 369 | next if (!exists($theme{Name})); |
| 370 | mkdirs($theme{Name}); |
| 371 | buildcfg($theme{Name}); |
| 372 | |
Jonathan Gordon | 30804e5 | 2010-06-03 13:44:41 +0000 | [diff] [blame] | 373 | copyskin($theme{"Name"}, $theme{"WPS"}, "wps") if exists($theme{"WPS"}); |
| 374 | copyskin($theme{"Name"}, $theme{"RWPS"}, "rwps") if exists($theme{"RWPS"}); |
| 375 | copyskin($theme{"Name"}, $theme{"FMS"}, "fms") if exists($theme{"FMS"}); |
| 376 | copyskin($theme{"Name"}, $theme{"RFMS"}, "rfms") if exists($theme{"RFMS"}); |
| 377 | copyskin($theme{"Name"}, $theme{"SBS"}, "sbs") if exists($theme{"SBS"}); |
| 378 | copyskin($theme{"Name"}, $theme{"RSBS"}, "rsbs") if exists($theme{"RSBS"}); |
Jonathan Gordon | d68710e | 2010-06-03 12:18:20 +0000 | [diff] [blame] | 379 | |
Jonathan Gordon | 30804e5 | 2010-06-03 13:44:41 +0000 | [diff] [blame] | 380 | copyiconset($theme{"iconset"}) if exists($theme{"iconset"}); |
| 381 | copyiconset($theme{"remote iconset"}) if exists($theme{"remote iconset"}); |
| 382 | copyiconset($theme{"viewers iconset"}) if exists($theme{"viewers iconset"}); |
| 383 | copyiconset($theme{"remote viewers iconset"}) if exists($theme{"remote viewers iconset"}); |
Jonathan Gordon | d68710e | 2010-06-03 12:18:20 +0000 | [diff] [blame] | 384 | |
Jonathan Gordon | 30804e5 | 2010-06-03 13:44:41 +0000 | [diff] [blame] | 385 | copythemefont($theme{"Font"}) if exists($theme{"Font"}); |
| 386 | copythemefont($theme{"Remote Font"}) if exists($theme{"Remote Font"}); |
| 387 | |
| 388 | copybackdrop($theme{"backdrop"}) if exists($theme{"backdrop"}); |
Jonathan Gordon | d68710e | 2010-06-03 12:18:20 +0000 | [diff] [blame] | 389 | |
| 390 | |
| 391 | |
| 392 | } |
| 393 | elsif($l =~ /^([\w ]*)\.?(.*):\s*(.*)/) { |
| 394 | my $var = $1; |
| 395 | my $extra = $2; |
| 396 | my $value = $3; |
| 397 | if (!exists($theme{$var})) |
| 398 | { |
| 399 | if (!$extra || |
| 400 | ($extra && (match($target, $extra) || matchdisplaystring($extra)))) |
| 401 | { |
| 402 | $theme{$var} = $value; |
Jonathan Gordon | 30804e5 | 2010-06-03 13:44:41 +0000 | [diff] [blame] | 403 | #print "\'$var\': $value\n"; |
Jonathan Gordon | d68710e | 2010-06-03 12:18:20 +0000 | [diff] [blame] | 404 | } |
| 405 | } |
| 406 | } |
| 407 | else{ |
| 408 | #print "Unknown line: $l!\n"; |
| 409 | } |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | close(WPS); |