Actually introduce the ability to build the Windows icons into the

Windows puzzle binaries. This checkin involves several distinct
changes:
 - mkfiles.pl now has an extra feature: if an object file is listed
   in Recipe with a trailing question mark, it will be considered
   optional, and silently dropped from the makefile if its primary
   source file isn't present at the time mkfiles.pl runs. This means
   people who check out the puzzles from Subversion and just run
   mkfiles.pl shouldn't get build failures; they just won't get the
   icons.
 - all the .R files now use this feature to include an optional
   Windows resource file.
 - the .rc resource source files are built by icons/Makefile.
 - windows.c finds the icon if present and uses it in place of the
   standard Windows application icon.

[originally from svn r7020]
This commit is contained in:
Simon Tatham
2006-12-27 11:05:20 +00:00
parent d07eb2ea3a
commit be8076a6e6
28 changed files with 78 additions and 49 deletions

2
Recipe
View File

@ -13,6 +13,8 @@
!makefile cygwin Makefile.cyg !makefile cygwin Makefile.cyg
!makefile osx Makefile.osx !makefile osx Makefile.osx
!srcdir icons/
WINDOWS = windows printing WINDOWS = windows printing
+ user32.lib gdi32.lib comctl32.lib comdlg32.lib winspool.lib + user32.lib gdi32.lib comctl32.lib comdlg32.lib winspool.lib
COMMON = midend drawing misc malloc random version COMMON = midend drawing misc malloc random version

View File

@ -2,7 +2,7 @@
blackbox : [X] GTK COMMON blackbox blackbox : [X] GTK COMMON blackbox
blackbox : [G] WINDOWS COMMON blackbox blackbox : [G] WINDOWS COMMON blackbox blackbox.res?
ALL += blackbox ALL += blackbox

View File

@ -4,7 +4,7 @@ BRIDGES = bridges dsf
bridges : [X] GTK COMMON BRIDGES bridges : [X] GTK COMMON BRIDGES
bridges : [G] WINDOWS COMMON BRIDGES bridges : [G] WINDOWS COMMON BRIDGES bridges.res?
ALL += BRIDGES ALL += BRIDGES

2
cube.R
View File

@ -2,7 +2,7 @@
cube : [X] GTK COMMON cube cube : [X] GTK COMMON cube
cube : [G] WINDOWS COMMON cube cube : [G] WINDOWS COMMON cube cube.res?
ALL += cube ALL += cube

View File

@ -2,7 +2,7 @@
dominosa : [X] GTK COMMON dominosa dominosa : [X] GTK COMMON dominosa
dominosa : [G] WINDOWS COMMON dominosa dominosa : [G] WINDOWS COMMON dominosa dominosa.res?
ALL += dominosa ALL += dominosa

View File

@ -2,7 +2,7 @@
fifteen : [X] GTK COMMON fifteen fifteen : [X] GTK COMMON fifteen
fifteen : [G] WINDOWS COMMON fifteen fifteen : [G] WINDOWS COMMON fifteen fifteen.res?
ALL += fifteen ALL += fifteen

2
flip.R
View File

@ -4,7 +4,7 @@ FLIP = flip tree234
flip : [X] GTK COMMON FLIP flip : [X] GTK COMMON FLIP
flip : [G] WINDOWS COMMON FLIP flip : [G] WINDOWS COMMON FLIP flip.res?
ALL += FLIP ALL += FLIP

View File

@ -2,7 +2,7 @@
guess : [X] GTK COMMON guess guess : [X] GTK COMMON guess
guess : [G] WINDOWS COMMON guess guess : [G] WINDOWS COMMON guess guess.res?
ALL += guess ALL += guess

View File

@ -19,6 +19,7 @@ P16D24 = $(patsubst %,%-16d24.png,$(PUZZLES))
P16D8 = $(patsubst %,%-16d8.png,$(PUZZLES)) P16D8 = $(patsubst %,%-16d8.png,$(PUZZLES))
P16D4 = $(patsubst %,%-16d4.png,$(PUZZLES)) P16D4 = $(patsubst %,%-16d4.png,$(PUZZLES))
ICONS = $(patsubst %,%.ico,$(PUZZLES)) ICONS = $(patsubst %,%.ico,$(PUZZLES))
RC = $(patsubst %,%.rc,$(PUZZLES))
BIN = ../ BIN = ../
PIC = ./ PIC = ./
@ -26,7 +27,7 @@ PIC = ./
base: $(BASE) base: $(BASE)
web: $(WEB) web: $(WEB)
pngicons: $(P48D24) $(P32D24) $(P16D24) pngicons: $(P48D24) $(P32D24) $(P16D24)
icons: $(ICONS) winicons: $(ICONS) $(RC)
# Build the base puzzle screenshots from which all the other images # Build the base puzzle screenshots from which all the other images
# are derived. Some of them involve showing a move animation # are derived. Some of them involve showing a move animation
@ -108,12 +109,16 @@ $(P16D4): %-16d4.png: %-ibase.png
convert -colors 16 -map $(PIC)win16pal.xpm tmp2.png $@ convert -colors 16 -map $(PIC)win16pal.xpm tmp2.png $@
rm -f tmp.png tmp2.png rm -f tmp.png tmp2.png
# And build the actual icons themselves, by feeding all those PNGs # Build the actual Windows icons themselves, by feeding all those
# to my icon builder script. # PNGs to my icon builder script.
$(ICONS): %.ico: %-48d24.png %-48d8.png %-48d4.png \ $(ICONS): %.ico: %-48d24.png %-48d8.png %-48d4.png \
%-32d24.png %-32d8.png %-32d4.png \ %-32d24.png %-32d8.png %-32d4.png \
%-16d24.png %-16d8.png %-16d4.png %-16d24.png %-16d8.png %-16d4.png
$(PIC)icon.pl $? > $@ $(PIC)icon.pl $? > $@
# Build the .RC files which bind the icons into the applications.
$(RC): %.rc:
echo '200 ICON "$*.ico"' > $@
clean: clean:
rm -f *.png *.ico rm -f *.png *.ico *.rc

View File

@ -2,7 +2,7 @@
inertia : [X] GTK COMMON inertia inertia : [X] GTK COMMON inertia
inertia : [G] WINDOWS COMMON inertia inertia : [G] WINDOWS COMMON inertia inertia.res?
ALL += inertia ALL += inertia

View File

@ -4,7 +4,7 @@ LIGHTUP = lightup combi
lightup : [X] GTK COMMON LIGHTUP lightup : [X] GTK COMMON LIGHTUP
lightup : [G] WINDOWS COMMON LIGHTUP lightup : [G] WINDOWS COMMON LIGHTUP lightup.res?
lightupsolver : [U] lightup[STANDALONE_SOLVER] combi STANDALONE lightupsolver : [U] lightup[STANDALONE_SOLVER] combi STANDALONE
lightupsolver : [C] lightup[STANDALONE_SOLVER] combi STANDALONE lightupsolver : [C] lightup[STANDALONE_SOLVER] combi STANDALONE

View File

@ -4,7 +4,7 @@ LOOPY = loopy tree234 dsf
loopy : [X] GTK COMMON LOOPY loopy : [X] GTK COMMON LOOPY
loopy : [G] WINDOWS COMMON LOOPY loopy : [G] WINDOWS COMMON LOOPY loopy.res?
ALL += LOOPY ALL += LOOPY

2
map.R
View File

@ -4,7 +4,7 @@ MAP = map dsf
map : [X] GTK COMMON MAP map : [X] GTK COMMON MAP
map : [G] WINDOWS COMMON MAP map : [G] WINDOWS COMMON MAP map.res?
mapsolver : [U] map[STANDALONE_SOLVER] dsf STANDALONE m.lib mapsolver : [U] map[STANDALONE_SOLVER] dsf STANDALONE m.lib
mapsolver : [C] map[STANDALONE_SOLVER] dsf STANDALONE mapsolver : [C] map[STANDALONE_SOLVER] dsf STANDALONE

View File

@ -4,7 +4,7 @@ MINES = mines tree234
mines : [X] GTK COMMON MINES mines : [X] GTK COMMON MINES
mines : [G] WINDOWS COMMON MINES mines : [G] WINDOWS COMMON MINES mines.res?
mineobfusc : [U] mines[STANDALONE_OBFUSCATOR] tree234 STANDALONE mineobfusc : [U] mines[STANDALONE_OBFUSCATOR] tree234 STANDALONE
mineobfusc : [C] mines[STANDALONE_OBFUSCATOR] tree234 STANDALONE mineobfusc : [C] mines[STANDALONE_OBFUSCATOR] tree234 STANDALONE

View File

@ -130,10 +130,19 @@ readinput: while (1) {
$i eq "[X]" or $i eq "[U]" or $i eq "[MX]") and defined $prog) { $i eq "[X]" or $i eq "[U]" or $i eq "[MX]") and defined $prog) {
$type = substr($i,1,(length $i)-2); $type = substr($i,1,(length $i)-2);
} else { } else {
if ($i =~ /\?$/) {
# Source files with a trailing question mark are optional:
# the build can proceed fine without them, so we only use
# them if they're present.
$i =~ s/\?$//;
$i = undef unless defined &finddep($i);
}
if (defined $i) {
push @$listref, $i; push @$listref, $i;
push @allobjs, $i; push @allobjs, $i;
} }
} }
}
if ($prog and $type) { if ($prog and $type) {
die "multiple program entries for $prog [$type]\n" die "multiple program entries for $prog [$type]\n"
if defined $programs{$prog . "," . $type}; if defined $programs{$prog . "," . $type};
@ -192,23 +201,8 @@ foreach $i (@prognames) {
$programs{$i} = [@list]; $programs{$i} = [@list];
foreach $jj (@list) { foreach $jj (@list) {
$j = $srcname{$jj}; $j = $srcname{$jj};
# Dependencies for "x" start with "x.c" or "x.m" (depending on $file = &finddep($j);
# which one exists). if (defined $file) {
# Dependencies for "x.res" start with "x.rc".
# Dependencies for "x.rsrc" start with "x.r".
# Both types of file are pushed on the list of files to scan.
# Libraries (.lib) don't have dependencies at all.
if ($j =~ /^(.*)\.res$/) {
$file = "$1.rc";
$depends{$jj} = [$file];
push @scanlist, $file;
} elsif ($j =~ /^(.*)\.rsrc$/) {
$file = "$1.r";
$depends{$jj} = [$file];
push @scanlist, $file;
} elsif ($j !~ /\./) {
$file = "$j.c";
$file = "$j.m" unless &findfile($file);
$depends{$jj} = [$file]; $depends{$jj} = [$file];
push @scanlist, $file; push @scanlist, $file;
} }
@ -315,6 +309,32 @@ sub findfile {
return $findfilecache{$name}; return $findfilecache{$name};
} }
sub finddep {
my $j = shift @_;
my $file;
# Find the first dependency of an object.
# Dependencies for "x" start with "x.c" or "x.m" (depending on
# which one exists).
# Dependencies for "x.res" start with "x.rc".
# Dependencies for "x.rsrc" start with "x.r".
# Both types of file are pushed on the list of files to scan.
# Libraries (.lib) don't have dependencies at all.
if ($j =~ /^(.*)\.res$/) {
$file = "$1.rc";
} elsif ($j =~ /^(.*)\.rsrc$/) {
$file = "$1.r";
} elsif ($j !~ /\./) {
$file = "$j.c";
$file = "$j.m" unless &findfile($file);
} else {
# For everything else, we assume it's its own dependency.
$file = $j;
}
$file = undef unless &findfile($file);
return $file;
}
sub objects { sub objects {
my ($prog, $otmpl, $rtmpl, $ltmpl, $prefix, $dirsep) = @_; my ($prog, $otmpl, $rtmpl, $ltmpl, $prefix, $dirsep) = @_;
my @ret; my @ret;
@ -655,7 +675,7 @@ if (defined $makefiles{'vc'}) {
"\n"; "\n";
if ($d->{obj} =~ /\.res$/) { if ($d->{obj} =~ /\.res$/) {
print "\trc \$(FWHACK) \$(RCFL) -r -DWIN32 -D_WIN32 ". print "\trc \$(FWHACK) \$(RCFL) -r -DWIN32 -D_WIN32 ".
"-DWINVER=0x0400 ".$d->{deps}->[0]."\n"; "-DWINVER=0x0400 -fo".$d->{obj}." ".$d->{deps}->[0]."\n";
} else { } else {
$deflist = join "", map { " /D$_" } @{$d->{defs}}; $deflist = join "", map { " /D$_" } @{$d->{defs}};
print "\tcl \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist". print "\tcl \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist".

2
net.R
View File

@ -6,7 +6,7 @@ net : [X] GTK COMMON NET
# The Windows Net shouldn't be called `net.exe' since Windows # The Windows Net shouldn't be called `net.exe' since Windows
# already has a reasonably important utility program by that name! # already has a reasonably important utility program by that name!
netgame : [G] WINDOWS COMMON NET netgame : [G] WINDOWS COMMON NET net.res?
ALL += NET ALL += NET

View File

@ -4,7 +4,7 @@ NETSLIDE = netslide tree234
netslide : [X] GTK COMMON NETSLIDE netslide : [X] GTK COMMON NETSLIDE
netslide : [G] WINDOWS COMMON NETSLIDE netslide : [G] WINDOWS COMMON NETSLIDE netslide.res?
ALL += NETSLIDE ALL += NETSLIDE

View File

@ -2,7 +2,7 @@
pattern : [X] GTK COMMON pattern pattern : [X] GTK COMMON pattern
pattern : [G] WINDOWS COMMON pattern pattern : [G] WINDOWS COMMON pattern pattern.res?
patternsolver : [U] pattern[STANDALONE_SOLVER] STANDALONE patternsolver : [U] pattern[STANDALONE_SOLVER] STANDALONE
patternsolver : [C] pattern[STANDALONE_SOLVER] STANDALONE patternsolver : [C] pattern[STANDALONE_SOLVER] STANDALONE

2
pegs.R
View File

@ -4,7 +4,7 @@ PEGS = pegs tree234
pegs : [X] GTK COMMON PEGS pegs : [X] GTK COMMON PEGS
pegs : [G] WINDOWS COMMON PEGS pegs : [G] WINDOWS COMMON PEGS pegs.res?
ALL += PEGS ALL += PEGS

2
rect.R
View File

@ -2,7 +2,7 @@
rect : [X] GTK COMMON rect rect : [X] GTK COMMON rect
rect : [G] WINDOWS COMMON rect rect : [G] WINDOWS COMMON rect rect.res?
ALL += rect ALL += rect

View File

@ -2,7 +2,7 @@
samegame : [X] GTK COMMON samegame samegame : [X] GTK COMMON samegame
samegame : [G] WINDOWS COMMON samegame samegame : [G] WINDOWS COMMON samegame samegame.res?
ALL += samegame ALL += samegame

View File

@ -2,7 +2,7 @@
sixteen : [X] GTK COMMON sixteen sixteen : [X] GTK COMMON sixteen
sixteen : [G] WINDOWS COMMON sixteen sixteen : [G] WINDOWS COMMON sixteen sixteen.res?
ALL += sixteen ALL += sixteen

View File

@ -4,7 +4,7 @@ SLANT = slant dsf
slant : [X] GTK COMMON SLANT slant : [X] GTK COMMON SLANT
slant : [G] WINDOWS COMMON SLANT slant : [G] WINDOWS COMMON SLANT slant.res?
slantsolver : [U] slant[STANDALONE_SOLVER] dsf STANDALONE slantsolver : [U] slant[STANDALONE_SOLVER] dsf STANDALONE
slantsolver : [C] slant[STANDALONE_SOLVER] dsf STANDALONE slantsolver : [C] slant[STANDALONE_SOLVER] dsf STANDALONE

2
solo.R
View File

@ -2,7 +2,7 @@
solo : [X] GTK COMMON solo solo : [X] GTK COMMON solo
solo : [G] WINDOWS COMMON solo solo : [G] WINDOWS COMMON solo solo.res?
solosolver : [U] solo[STANDALONE_SOLVER] STANDALONE solosolver : [U] solo[STANDALONE_SOLVER] STANDALONE
solosolver : [C] solo[STANDALONE_SOLVER] STANDALONE solosolver : [C] solo[STANDALONE_SOLVER] STANDALONE

View File

@ -4,7 +4,7 @@ TENTS = tents maxflow
tents : [X] GTK COMMON TENTS tents : [X] GTK COMMON TENTS
tents : [G] WINDOWS COMMON TENTS tents : [G] WINDOWS COMMON TENTS tents.res?
ALL += TENTS ALL += TENTS

View File

@ -2,7 +2,7 @@
twiddle : [X] GTK COMMON twiddle twiddle : [X] GTK COMMON twiddle
twiddle : [G] WINDOWS COMMON twiddle twiddle : [G] WINDOWS COMMON twiddle twiddle.res?
ALL += twiddle ALL += twiddle

View File

@ -4,7 +4,7 @@ UNTANGLE = untangle tree234
untangle : [X] GTK COMMON UNTANGLE untangle : [X] GTK COMMON UNTANGLE
untangle : [G] WINDOWS COMMON UNTANGLE untangle : [G] WINDOWS COMMON UNTANGLE untangle.res?
ALL += UNTANGLE ALL += UNTANGLE

View File

@ -2441,6 +2441,8 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
wndclass.cbClsExtra = 0; wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0; wndclass.cbWndExtra = 0;
wndclass.hInstance = inst; wndclass.hInstance = inst;
wndclass.hIcon = LoadIcon(inst, MAKEINTRESOURCE(200));
if (!wndclass.hIcon) /* in case resource file is absent */
wndclass.hIcon = LoadIcon(inst, IDI_APPLICATION); wndclass.hIcon = LoadIcon(inst, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = NULL; wndclass.hbrBackground = NULL;