Daniel Stenberg | 792c998 | 2005-11-14 14:24:17 +0000 | [diff] [blame] | 1 | #!/usr/bin/perl |
Daniel Stenberg | 8a91802 | 2005-11-14 15:05:53 +0000 | [diff] [blame] | 2 | # __________ __ ___. |
| 3 | # Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | # \/ \/ \/ \/ \/ |
| 8 | # $Id$ |
| 9 | # |
| 10 | |
| 11 | $ROOT=".."; |
| 12 | |
| 13 | if($ARGV[0] eq "-r") { |
| 14 | $ROOT=$ARGV[1]; |
| 15 | shift @ARGV; |
| 16 | shift @ARGV; |
| 17 | } |
| 18 | |
| 19 | my $verbose; |
| 20 | if($ARGV[0] eq "-v") { |
| 21 | $verbose =1; |
| 22 | shift @ARGV; |
| 23 | } |
| 24 | |
| 25 | my $firmdir="$ROOT/firmware"; |
Daniel Stenberg | 792c998 | 2005-11-14 14:24:17 +0000 | [diff] [blame] | 26 | |
| 27 | my $wpslist=$ARGV[0]; |
| 28 | |
Daniel Stenberg | 8a91802 | 2005-11-14 15:05:53 +0000 | [diff] [blame] | 29 | my $target = $ARGV[1]; |
| 30 | my $cppdef = $target; |
Christi Scarborough | cc9292f | 2006-05-11 14:27:12 +0000 | [diff] [blame] | 31 | my @depthlist = ( 16, 8, 4, 2, 1 ); |
Daniel Stenberg | 8a91802 | 2005-11-14 15:05:53 +0000 | [diff] [blame] | 32 | |
Daniel Stenberg | 792c998 | 2005-11-14 14:24:17 +0000 | [diff] [blame] | 33 | if(!$wpslist) { |
Daniel Stenberg | 8a91802 | 2005-11-14 15:05:53 +0000 | [diff] [blame] | 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"; |
Daniel Stenberg | 792c998 | 2005-11-14 14:24:17 +0000 | [diff] [blame] | 37 | exit; |
| 38 | } |
| 39 | |
Daniel Stenberg | 8a91802 | 2005-11-14 15:05:53 +0000 | [diff] [blame] | 40 | sub getlcdsizes { |
Daniel Stenberg | 2bace6a | 2005-11-17 22:39:26 +0000 | [diff] [blame] | 41 | my ($remote) = @_; |
| 42 | |
Daniel Stenberg | 8a91802 | 2005-11-14 15:05:53 +0000 | [diff] [blame] | 43 | open(GCC, ">gcctemp"); |
Daniel Stenberg | 2bace6a | 2005-11-17 22:39:26 +0000 | [diff] [blame] | 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 |
Christi Scarborough | cc9292f | 2006-05-11 14:27:12 +0000 | [diff] [blame] | 51 | Depth: LCD_REMOTE_DEPTH |
Daniel Stenberg | 2bace6a | 2005-11-17 22:39:26 +0000 | [diff] [blame] | 52 | #endif |
| 53 | STOP |
| 54 | ; |
| 55 | } |
| 56 | else { |
Daniel Stenberg | 8a91802 | 2005-11-14 15:05:53 +0000 | [diff] [blame] | 57 | print GCC <<STOP |
| 58 | \#include "config.h" |
Daniel Stenberg | 2624b55 | 2006-03-18 21:17:05 +0000 | [diff] [blame] | 59 | #ifdef HAVE_LCD_BITMAP |
Daniel Stenberg | 8a91802 | 2005-11-14 15:05:53 +0000 | [diff] [blame] | 60 | Height: LCD_HEIGHT |
| 61 | Width: LCD_WIDTH |
Christi Scarborough | cc9292f | 2006-05-11 14:27:12 +0000 | [diff] [blame] | 62 | Depth: LCD_DEPTH |
Daniel Stenberg | 2624b55 | 2006-03-18 21:17:05 +0000 | [diff] [blame] | 63 | #endif |
Daniel Stenberg | 8a91802 | 2005-11-14 15:05:53 +0000 | [diff] [blame] | 64 | STOP |
| 65 | ; |
Daniel Stenberg | 2bace6a | 2005-11-17 22:39:26 +0000 | [diff] [blame] | 66 | } |
Daniel Stenberg | 8a91802 | 2005-11-14 15:05:53 +0000 | [diff] [blame] | 67 | 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 Scarborough | cc9292f | 2006-05-11 14:27:12 +0000 | [diff] [blame] | 83 | elsif($_ =~ /^Depth: (\d*)/) { |
| 84 | $depth = $1; |
| 85 | } |
| 86 | if($height && $width && $depth) { |
Daniel Stenberg | 8a91802 | 2005-11-14 15:05:53 +0000 | [diff] [blame] | 87 | last; |
| 88 | } |
| 89 | } |
| 90 | close(GETSIZE); |
| 91 | unlink("gcctemp"); |
| 92 | |
Christi Scarborough | cc9292f | 2006-05-11 14:27:12 +0000 | [diff] [blame] | 93 | return ($height, $width, $depth); |
Daniel Stenberg | 8a91802 | 2005-11-14 15:05:53 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | sub mkdirs { |
| 97 | my $wpsdir = $wps; |
Daniel Stenberg | 2bace6a | 2005-11-17 22:39:26 +0000 | [diff] [blame] | 98 | $wpsdir =~ s/\.(r|)wps//; |
Daniel Stenberg | 8a91802 | 2005-11-14 15:05:53 +0000 | [diff] [blame] | 99 | mkdir ".rockbox/wps", 0777; |
Christi Scarborough | 32a43e2 | 2005-11-18 15:33:05 +0000 | [diff] [blame] | 100 | mkdir ".rockbox/themes", 0777; |
Daniel Stenberg | 2bace6a | 2005-11-17 22:39:26 +0000 | [diff] [blame] | 101 | |
| 102 | if( -d ".rockbox/wps/$wpsdir") { |
Daniel Stenberg | 88f359f | 2005-11-17 23:47:23 +0000 | [diff] [blame] | 103 | #print STDERR "wpsbuild warning: directory wps/$wpsdir already exists!\n"; |
Daniel Stenberg | 2bace6a | 2005-11-17 22:39:26 +0000 | [diff] [blame] | 104 | } |
Christi Scarborough | cc9292f | 2006-05-11 14:27:12 +0000 | [diff] [blame] | 105 | else |
| 106 | { |
| 107 | mkdir ".rockbox/wps/$wpsdir", 0777; |
Daniel Stenberg | 2bace6a | 2005-11-17 22:39:26 +0000 | [diff] [blame] | 108 | } |
Daniel Stenberg | 8a91802 | 2005-11-14 15:05:53 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 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; |
Christi Scarborough | cc9292f | 2006-05-11 14:27:12 +0000 | [diff] [blame] | 115 | my @filelist; |
| 116 | my $file; |
Daniel Stenberg | 8a91802 | 2005-11-14 15:05:53 +0000 | [diff] [blame] | 117 | |
| 118 | if($wpslist =~ /(.*)WPSLIST/) { |
| 119 | $dir = $1; |
Christi Scarborough | cc9292f | 2006-05-11 14:27:12 +0000 | [diff] [blame] | 120 | # system("cp $dir/$wps .rockbox/wps/"); |
| 121 | # print "$req_t_wps $req_g_wps\n"; |
Daniel Stenberg | 88f359f | 2005-11-17 23:47:23 +0000 | [diff] [blame] | 122 | |
Christi Scarborough | cc9292f | 2006-05-11 14:27:12 +0000 | [diff] [blame] | 123 | 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 Feltzing | 3b52485 | 2006-05-15 07:47:29 +0000 | [diff] [blame] | 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/"); |
| 138 | } |
| 139 | } |
| 140 | elsif (-e "$dir/$wps_prefix") { |
Christi Scarborough | cc9292f | 2006-05-11 14:27:12 +0000 | [diff] [blame] | 141 | 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 Stenberg | 8a91802 | 2005-11-14 15:05:53 +0000 | [diff] [blame] | 154 | } |
| 155 | } |
| 156 | |
Daniel Stenberg | 792c998 | 2005-11-14 14:24:17 +0000 | [diff] [blame] | 157 | sub buildcfg { |
| 158 | my $cfg = $wps; |
Daniel Stenberg | 8a91802 | 2005-11-14 15:05:53 +0000 | [diff] [blame] | 159 | my @out; |
Daniel Stenberg | 792c998 | 2005-11-14 14:24:17 +0000 | [diff] [blame] | 160 | |
Daniel Stenberg | 2bace6a | 2005-11-17 22:39:26 +0000 | [diff] [blame] | 161 | $cfg =~ s/\.(r|)wps/.cfg/; |
Daniel Stenberg | 792c998 | 2005-11-14 14:24:17 +0000 | [diff] [blame] | 162 | |
Daniel Stenberg | 8a91802 | 2005-11-14 15:05:53 +0000 | [diff] [blame] | 163 | push @out, <<MOO |
| 164 | \# |
Daniel Stenberg | 792c998 | 2005-11-14 14:24:17 +0000 | [diff] [blame] | 165 | \# $cfg generated by wpsbuild.pl |
Daniel Stenberg | 8a91802 | 2005-11-14 15:05:53 +0000 | [diff] [blame] | 166 | \# $wps is made by $author |
Daniel Stenberg | 792c998 | 2005-11-14 14:24:17 +0000 | [diff] [blame] | 167 | \# |
| 168 | wps: /.rockbox/wps/$wps |
Daniel Stenberg | 792c998 | 2005-11-14 14:24:17 +0000 | [diff] [blame] | 169 | MOO |
| 170 | ; |
Daniel Stenberg | 8a91802 | 2005-11-14 15:05:53 +0000 | [diff] [blame] | 171 | if($font) { |
| 172 | push @out, "font: /.rockbox/fonts/$font\n"; |
| 173 | } |
| 174 | if($statusbar) { |
| 175 | push @out, "statusbar: $statusbar\n"; |
| 176 | } |
Christi Scarborough | 32a43e2 | 2005-11-18 15:33:05 +0000 | [diff] [blame] | 177 | if($rwps && $has_remote ) { |
Daniel Stenberg | 2bace6a | 2005-11-17 22:39:26 +0000 | [diff] [blame] | 178 | push @out, "rwps: /.rockbox/wps/$rwps\n"; |
| 179 | } |
Daniel Stenberg | 8a91802 | 2005-11-14 15:05:53 +0000 | [diff] [blame] | 180 | |
Daniel Stenberg | 2bace6a | 2005-11-17 22:39:26 +0000 | [diff] [blame] | 181 | if(-f ".rockbox/wps/$cfg") { |
| 182 | print STDERR "wpsbuild warning: wps/$cfg already exists!\n"; |
| 183 | } |
| 184 | else { |
Christi Scarborough | 32a43e2 | 2005-11-18 15:33:05 +0000 | [diff] [blame] | 185 | open(CFG, ">.rockbox/themes/$cfg"); |
Daniel Stenberg | 2bace6a | 2005-11-17 22:39:26 +0000 | [diff] [blame] | 186 | print CFG @out; |
| 187 | close(CFG); |
| 188 | } |
Daniel Stenberg | 792c998 | 2005-11-14 14:24:17 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Daniel Stenberg | 2bace6a | 2005-11-17 22:39:26 +0000 | [diff] [blame] | 191 | # Get the LCD sizes first |
Christi Scarborough | cc9292f | 2006-05-11 14:27:12 +0000 | [diff] [blame] | 192 | my ($main_height, $main_width, $main_depth) = getlcdsizes(); |
| 193 | my ($remote_height, $remote_width, $remote_depth) = getlcdsizes(1); |
Daniel Stenberg | 2bace6a | 2005-11-17 22:39:26 +0000 | [diff] [blame] | 194 | |
Christi Scarborough | cc9292f | 2006-05-11 14:27:12 +0000 | [diff] [blame] | 195 | #print "LCD: ${main_height}x${main_width}x${main_depth}\n"; |
| 196 | $has_remote = true if ($remote_height && $remote_width && remote_depth); |
Christi Scarborough | 32a43e2 | 2005-11-18 15:33:05 +0000 | [diff] [blame] | 197 | |
Daniel Stenberg | 792c998 | 2005-11-14 14:24:17 +0000 | [diff] [blame] | 198 | open(WPS, "<$wpslist"); |
| 199 | while(<WPS>) { |
| 200 | my $l = $_; |
| 201 | if($l =~ /^ *\#/) { |
| 202 | # skip comment |
| 203 | next; |
| 204 | } |
Daniel Stenberg | 2bace6a | 2005-11-17 22:39:26 +0000 | [diff] [blame] | 205 | if($l =~ /^ *<(r|)wps>/i) { |
| 206 | $isrwps = $1; |
Daniel Stenberg | 792c998 | 2005-11-14 14:24:17 +0000 | [diff] [blame] | 207 | $within = 1; |
Christi Scarborough | 32a43e2 | 2005-11-18 15:33:05 +0000 | [diff] [blame] | 208 | # undef is a unary operator (!) |
| 209 | undef $wps; |
Christi Scarborough | cc9292f | 2006-05-11 14:27:12 +0000 | [diff] [blame] | 210 | undef $wps_prefix; |
Christi Scarborough | 32a43e2 | 2005-11-18 15:33:05 +0000 | [diff] [blame] | 211 | undef $rwps; |
| 212 | undef $width; |
| 213 | undef $height; |
| 214 | undef $font; |
| 215 | undef $statusbar; |
| 216 | undef $author; |
Christi Scarborough | cc9292f | 2006-05-11 14:27:12 +0000 | [diff] [blame] | 217 | undef $req_g_wps; |
| 218 | undef $req_t_wps; |
Daniel Stenberg | 792c998 | 2005-11-14 14:24:17 +0000 | [diff] [blame] | 219 | next; |
| 220 | } |
| 221 | if($within) { |
Daniel Stenberg | 2bace6a | 2005-11-17 22:39:26 +0000 | [diff] [blame] | 222 | if($l =~ /^ *<\/${isrwps}wps>/i) { |
| 223 | # Get the required width and height |
Christi Scarborough | cc9292f | 2006-05-11 14:27:12 +0000 | [diff] [blame] | 224 | my ($rheight, $rwidth, $rdepth); |
Daniel Stenberg | 2bace6a | 2005-11-17 22:39:26 +0000 | [diff] [blame] | 225 | if($isrwps) { |
Christi Scarborough | cc9292f | 2006-05-11 14:27:12 +0000 | [diff] [blame] | 226 | ($rheight, $rwidth, $rdepth) = |
| 227 | ($remote_height, $remote_width, $remote_depth); |
Daniel Stenberg | 2bace6a | 2005-11-17 22:39:26 +0000 | [diff] [blame] | 228 | } |
| 229 | else { |
Christi Scarborough | cc9292f | 2006-05-11 14:27:12 +0000 | [diff] [blame] | 230 | ($rheight, $rwidth, $rdepth) = |
| 231 | ($main_height, $main_width, $main_depth); |
Daniel Stenberg | 2bace6a | 2005-11-17 22:39:26 +0000 | [diff] [blame] | 232 | } |
Daniel Stenberg | 8a91802 | 2005-11-14 15:05:53 +0000 | [diff] [blame] | 233 | |
| 234 | if(!$rheight || !$rwidth) { |
Daniel Stenberg | 2624b55 | 2006-03-18 21:17:05 +0000 | [diff] [blame] | 235 | #printf STDERR "wpsbuild notice: No %sLCD size, skipping $wps\n", |
Daniel Stenberg | 2bace6a | 2005-11-17 22:39:26 +0000 | [diff] [blame] | 236 | $isrwps?"remote ":""; |
Christi Scarborough | 32a43e2 | 2005-11-18 15:33:05 +0000 | [diff] [blame] | 237 | $within = 0; |
Daniel Stenberg | 2bace6a | 2005-11-17 22:39:26 +0000 | [diff] [blame] | 238 | next; |
Daniel Stenberg | 8a91802 | 2005-11-14 15:05:53 +0000 | [diff] [blame] | 239 | } |
Christi Scarborough | cc9292f | 2006-05-11 14:27:12 +0000 | [diff] [blame] | 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); |
| 246 | |
Linus Nielsen Feltzing | 3b52485 | 2006-05-15 07:47:29 +0000 | [diff] [blame] | 247 | $req_g = $rwidth . "x" . $rheight . "x" . $d; |
| 248 | |
| 249 | $req_g_wps = $wps_prefix . "." . $req_g . ".wps"; |
Christi Scarborough | cc9292f | 2006-05-11 14:27:12 +0000 | [diff] [blame] | 250 | last if (-e "$wpsdir/$req_g_wps"); |
| 251 | } |
| 252 | $req_t_wps = $wps_prefix . ".txt" . ".wps"; |
Daniel Stenberg | 8a91802 | 2005-11-14 15:05:53 +0000 | [diff] [blame] | 253 | |
Daniel Stenberg | 5f9f9bc | 2005-11-14 15:10:40 +0000 | [diff] [blame] | 254 | #print "LCD: $wps wants $height x $width\n"; |
| 255 | #print "LCD: is $rheight x $rwidth\n"; |
Daniel Stenberg | 8a91802 | 2005-11-14 15:05:53 +0000 | [diff] [blame] | 256 | |
Christi Scarborough | cc9292f | 2006-05-11 14:27:12 +0000 | [diff] [blame] | 257 | #print "gwps: $wpsdir/$req_g_wps" . "\n"; |
| 258 | if (-e "$wpsdir/$req_g_wps" || -e "$wpsdir/$req_t_wps" ) { |
Daniel Stenberg | 8a91802 | 2005-11-14 15:05:53 +0000 | [diff] [blame] | 259 | # |
| 260 | # The target model has an LCD that is suitable for this |
| 261 | # WPS |
| 262 | # |
Daniel Stenberg | 5f9f9bc | 2005-11-14 15:10:40 +0000 | [diff] [blame] | 263 | #print "Size requirement is fine!\n"; |
Christi Scarborough | cc9292f | 2006-05-11 14:27:12 +0000 | [diff] [blame] | 264 | mkdirs() if (-e "$wpsdir/$req_g_wps"); |
Daniel Stenberg | 88f359f | 2005-11-17 23:47:23 +0000 | [diff] [blame] | 265 | if(!$isrwps) { |
| 266 | # We only make .cfg files for <wps> sections: |
| 267 | buildcfg(); |
| 268 | } |
Daniel Stenberg | 8a91802 | 2005-11-14 15:05:53 +0000 | [diff] [blame] | 269 | copywps(); |
| 270 | } |
Daniel Stenberg | 5f9f9bc | 2005-11-14 15:10:40 +0000 | [diff] [blame] | 271 | else { |
Christi Scarborough | cc9292f | 2006-05-11 14:27:12 +0000 | [diff] [blame] | 272 | #print "(${wps_prefix}-${rwidth}x${rheight}x$rdepth) "; |
| 273 | print "Skip $wps due to size restraints\n"; |
Daniel Stenberg | 5f9f9bc | 2005-11-14 15:10:40 +0000 | [diff] [blame] | 274 | } |
Daniel Stenberg | 792c998 | 2005-11-14 14:24:17 +0000 | [diff] [blame] | 275 | $within = 0; |
| 276 | } |
| 277 | elsif($l =~ /^Name: (.*)/i) { |
Daniel Stenberg | 88f359f | 2005-11-17 23:47:23 +0000 | [diff] [blame] | 278 | # 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 Scarborough | cc9292f | 2006-05-11 14:27:12 +0000 | [diff] [blame] | 280 | $wps = $wps_prefix = $1; |
| 281 | $wps_prefix =~ s/\.(r|)wps//; |
| 282 | # print $wps_prefix . "\n"; |
Daniel Stenberg | 792c998 | 2005-11-14 14:24:17 +0000 | [diff] [blame] | 283 | } |
Daniel Stenberg | 2bace6a | 2005-11-17 22:39:26 +0000 | [diff] [blame] | 284 | elsif($l =~ /^RWPS: (.*)/i) { |
| 285 | $rwps = $1; |
| 286 | } |
Daniel Stenberg | 8a91802 | 2005-11-14 15:05:53 +0000 | [diff] [blame] | 287 | 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 Stenberg | 792c998 | 2005-11-14 14:24:17 +0000 | [diff] [blame] | 296 | elsif($l =~ /^Font: (.*)/i) { |
| 297 | $font = $1; |
| 298 | } |
| 299 | elsif($l =~ /^Statusbar: (.*)/i) { |
| 300 | $statusbar = $1; |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | |
Christi Scarborough | cc9292f | 2006-05-11 14:27:12 +0000 | [diff] [blame] | 305 | close(WPS); |