ref: 968828283b7a0aacd71d4868846291b381884eb1
parent: 4763b712fd0709a08b8e00144095df68cb37fcb1
author: Simon Tatham <anakin@pobox.com>
date: Tue Jul 5 15:40:32 EDT 2005
Enhancements to mkfiles.pl and Recipe to arrange for the auxiliary command-line programs (solosolver, patternsolver, mineobfusc) to be built as part of the normal Makefiles. This means mkfiles.pl now has the capability to compile a source file more than once with different #defines. Also, fixes for those auxiliary programs and one fix in midend.c which the Borland compiler objected to while I was testing its makefile generation. [originally from svn r6066]
--- a/Recipe
+++ b/Recipe
@@ -39,6 +39,15 @@
guess : [X] gtk COMMON guess
pegs : [X] gtk COMMON PEGS
+# Auxiliary command-line programs.
+solosolver : [U] solo[STANDALONE_SOLVER] malloc
+patternsolver : [U] pattern[STANDALONE_SOLVER] malloc
+mineobfusc : [U] mines[STANDALONE_OBFUSCATOR] malloc random tree234 misc
+
+solosolver : [C] solo[STANDALONE_SOLVER] malloc
+patternsolver : [C] pattern[STANDALONE_SOLVER] malloc
+mineobfusc : [C] mines[STANDALONE_OBFUSCATOR] malloc random tree234 misc
+
# The Windows Net shouldn't be called `net.exe' since Windows
# already has a reasonably important utility program by that name!
netgame : [G] WINDOWS COMMON NET
--- a/midend.c
+++ b/midend.c
@@ -381,7 +381,7 @@
void midend_stop_anim(midend_data *me)
{
- if (me->oldstate || me->anim_time) {
+ if (me->oldstate || me->anim_time != 0) {
midend_finish_move(me);
midend_redraw(me);
}
--- a/mines.c
+++ b/mines.c
@@ -3070,7 +3070,7 @@
* $ ./mineobfusc 9x9:4,4,004000007c00010022080
* 9x9:4,4,mb071b49fbd1cb6a0d5868
*
- * gcc -DSTANDALONE_OBFUSCATOR -o mineobfusc mines.c malloc.c random.c tree234.c
+ * gcc -DSTANDALONE_OBFUSCATOR -o mineobfusc mines.c malloc.c random.c tree234.c misc.c
*/
#include <stdarg.h>
@@ -3087,7 +3087,7 @@
void start_draw(frontend *fe) {}
void draw_update(frontend *fe, int x, int y, int w, int h) {}
void end_draw(frontend *fe) {}
-void midend_supersede_game_desc(midend_data *me, char *desc) {}
+void midend_supersede_game_desc(midend_data *me, char *desc, char *privdesc) {}
void status_bar(frontend *fe, char *text) {}
void fatal(char *fmt, ...)
@@ -3108,15 +3108,13 @@
{
game_params *p;
game_state *s;
- int recurse = TRUE;
char *id = NULL, *desc, *err;
int y, x;
- int grade = FALSE;
while (--argc > 0) {
char *p = *++argv;
if (*p == '-') {
- fprintf(stderr, "%s: unrecognised option `%s'\n", argv[0]);
+ fprintf(stderr, "%s: unrecognised option `%s'\n", argv[0], p);
return 1;
} else {
id = p;
--- a/mkfiles.pl
+++ b/mkfiles.pl
@@ -13,6 +13,10 @@
# mainly because I was too scared to go anywhere near it.
# - sbcsgen.pl is still run at startup.
+# Other things undone:
+# - special-define objects (foo.o[PREPROCSYMBOL]) are not
+# supported in the mac or vcproj makefiles.
+
use FileHandle;
use Cwd;
@@ -39,6 +43,8 @@
%programs = (); # maps prog name + type letter to listref of objects/resources
%groups = (); # maps group name to listref of objects/resources
+@allobjs = (); # all object file names
+
while (<IN>) {
# Skip comments (unless the comments belong, for example because
# they're part of a diversion).
@@ -96,6 +102,7 @@
$type = substr($i,1,(length $i)-2);
} else {
push @$listref, $i;
+ push @allobjs, $i;
}
}
if ($prog and $type) {
@@ -108,6 +115,35 @@
close IN;
+# Find object file names with predefines (in square brackets after
+# the module name), and decide on actual object names for them.
+foreach $i (@allobjs) {
+ if ($i !~ /\[/) {
+ $objname{$i} = $i;
+ $srcname{$i} = $i;
+ $usedobjname{$i} = 1;
+ }
+}
+foreach $i (@allobjs) {
+ if ($i =~ /^(.*)\[([^\]]*)/) {
+ $defs{$i} = [ split ",",$2 ];
+ $srcname{$i} = $s = $1;
+ $index = 1;
+ while (1) {
+ $maxlen = length $s;
+ $maxlen = 8 if $maxlen < 8;
+ $chop = $maxlen - length $index;
+ $chop = length $s if $chop > length $s;
+ $chop = 0 if $chop < 0;
+ $name = substr($s, 0, $chop) . $index;
+ $index++, next if $usedobjname{$name};
+ $objname{$i} = $name;
+ $usedobjname{$name} = 1;
+ last;
+ }
+ }
+}
+
# Now retrieve the complete list of objects and resource files, and
# construct dependency data for them. While we're here, expand the
# object list for each program, and complain if its type isn't set.
@@ -121,7 +157,8 @@
@list = grep { $status = ($prev ne $_); $prev=$_; $status }
sort @{$programs{$i}};
$programs{$i} = [@list];
- foreach $j (@list) {
+ foreach $jj (@list) {
+ $j = $srcname{$jj};
# Dependencies for "x" start with "x.c" or "x.m" (depending on
# which one exists).
# Dependencies for "x.res" start with "x.rc".
@@ -130,16 +167,16 @@
# Libraries (.lib) don't have dependencies at all.
if ($j =~ /^(.*)\.res$/) {
$file = "$1.rc";
- $depends{$j} = [$file];
+ $depends{$jj} = [$file];
push @scanlist, $file;
} elsif ($j =~ /^(.*)\.rsrc$/) {
$file = "$1.r";
- $depends{$j} = [$file];
+ $depends{$jj} = [$file];
push @scanlist, $file;
} elsif ($j !~ /\./) {
$file = "$j.c";
$file = "$j.m" unless &findfile($file);
- $depends{$j} = [$file];
+ $depends{$jj} = [$file];
push @scanlist, $file;
}
}
@@ -250,7 +287,8 @@
my @ret;
my ($i, $x, $y);
@ret = ();
- foreach $i (@{$programs{$prog}}) {
+ foreach $ii (@{$programs{$prog}}) {
+ $i = $objname{$ii};
$x = "";
if ($i =~ /^(.*)\.(res|rsrc)/) {
$y = $1;
@@ -271,7 +309,8 @@
my @ret;
my ($i, $x, $y);
@ret = ();
- foreach $i (@{$programs{$prog}}) {
+ foreach $ii (@{$programs{$prog}}) {
+ $i = $objname{$ii};
if (substr($i, (length $i) - (length $suffix)) eq $suffix) {
push @ret, $i;
}
@@ -299,7 +338,8 @@
my @deps, @ret;
@ret = ();
$depchar ||= ':';
- foreach $i (sort keys %depends) {
+ foreach $ii (sort keys %depends) {
+ $i = $objname{$ii};
next if $specialobj{$mftyp}->{$i};
if ($i =~ /^(.*)\.(res|rsrc)/) {
next if !defined $rtmpl;
@@ -308,13 +348,13 @@
} else {
($x = $otmpl) =~ s/X/$i/;
}
- @deps = @{$depends{$i}};
+ @deps = @{$depends{$ii}};
@deps = map {
$_ = &findfile($_);
s/\//$dirsep/g;
$_ = $prefix . $_;
} @deps;
- push @ret, {obj => $x, deps => [@deps]};
+ push @ret, {obj => $x, deps => [@deps], defs => $defs{$ii}};
}
return @ret;
}
@@ -356,6 +396,7 @@
# Now we're ready to output the actual Makefiles.
if (defined $makefiles{'cygwin'}) {
+ $mftyp = 'cygwin';
$dirpfx = &dirpfx($makefiles{'cygwin'}, "/");
##-- CygWin makefile
@@ -411,6 +452,13 @@
foreach $d (&deps("X.o", "X.res.o", $dirpfx, "/")) {
print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
"\n";
+ if ($d->{obj} =~ /\.res\.o$/) {
+ print "\t\$(RC) \$(FWHACK) \$(RCFL) \$(RCFLAGS) \$< \$\@\n";
+ } else {
+ $deflist = join "", map { " -D$_" } @{$d->{defs}};
+ print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS)" .
+ " \$(CFLAGS)$deflist -c \$< -o \$\@\n";
+ }
}
print "\n";
print $makefile_extra{'cygwin'};
@@ -423,6 +471,7 @@
##-- Borland makefile
if (defined $makefiles{'borland'}) {
+ $mftyp = 'borland';
$dirpfx = &dirpfx($makefiles{'borland'}, "\\");
%stdlibs = ( # Borland provides many Win32 API libraries intrinsically
@@ -458,15 +507,6 @@
"!if !\$d(BCB)\n".
"BCB = \$(MAKEDIR)\\..\n".
"!endif\n".
- "\n".
- ".c.obj:\n".
- &splitline("\tbcc32 -w-aus -w-ccc -w-par -w-pia \$(COMPAT) \$(FWHACK)".
- " \$(XFLAGS) \$(CFLAGS) ".
- (join " ", map {"-I$dirpfx$_"} @srcdirs) .
- " /c \$*.c",69)."\n".
- ".rc.res:\n".
- &splitline("\tbrcc32 \$(FWHACK) \$(RCFL) -i \$(BCB)\\include -r".
- " -DNO_WINRESRC_H -DWIN32 -D_WIN32 -DWINVER=0x0401 \$*.rc",69)."\n".
"\n";
print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
print "\n\n";
@@ -508,6 +548,17 @@
foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
"\n";
+ if ($d->{obj} =~ /\.res$/) {
+ print &splitline("\tbrcc32 \$(FWHACK) \$(RCFL) " .
+ "-i \$(BCB)\\include -r -DNO_WINRESRC_H -DWIN32".
+ " -D_WIN32 -DWINVER=0x0401 \$*.rc",69)."\n";
+ } else {
+ $deflist = join "", map { " -D$_" } @{$d->{defs}};
+ print &splitline("\tbcc32 -w-aus -w-ccc -w-par -w-pia \$(COMPAT)" .
+ " \$(FWHACK) \$(XFLAGS) \$(CFLAGS)$deflist ".
+ (join " ", map {"-I$dirpfx$_"} @srcdirs) .
+ " /o$d->{obj} /c ".$d->{deps}->[0],69)."\n";
+ }
}
print "\n";
print $makefile_extra{'borland'};
@@ -526,6 +577,7 @@
}
if (defined $makefiles{'vc'}) {
+ $mftyp = 'vc';
$dirpfx = &dirpfx($makefiles{'vc'}, "\\");
##-- Visual C++ makefile
@@ -544,11 +596,6 @@
"# C compilation flags\n".
"CFLAGS = /nologo /W3 /O1 /D_WINDOWS /D_WIN32_WINDOWS=0x401 /DWINVER=0x401\n".
"LFLAGS = /incremental:no /fixed\n".
- "\n".
- ".c.obj:\n".
- "\tcl \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) /c \$*.c\n".
- ".rc.res:\n".
- "\trc \$(FWHACK) \$(RCFL) -r -DWIN32 -D_WIN32 -DWINVER=0x0400 \$*.rc\n".
"\n";
print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
print "\n\n";
@@ -580,6 +627,14 @@
foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
"\n";
+ if ($d->{obj} =~ /\.res$/) {
+ print "\trc \$(FWHACK) \$(RCFL) -r -DWIN32 -D_WIN32 ".
+ "-DWINVER=0x0400 ".$d->{deps}->[0]."\n";
+ } else {
+ $deflist = join "", map { " /D$_" } @{$d->{defs}};
+ print "\tcl \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS)$deflist".
+ " /c ".$d->{deps}->[0]." /Fo$d->{obj}\n";
+ }
}
print "\n";
print $makefile_extra{'vc'};
@@ -605,6 +660,7 @@
}
if (defined $makefiles{'vcproj'}) {
+ $mftyp = 'vcproj';
$orig_dir = cwd;
@@ -860,6 +916,7 @@
}
if (defined $makefiles{'gtk'}) {
+ $mftyp = 'gtk';
$dirpfx = &dirpfx($makefiles{'gtk'}, "/");
##-- X/GTK/Unix makefile
@@ -897,11 +954,6 @@
"gamesdir=\$(exec_prefix)/games\n",
"mandir=\$(prefix)/man\n",
"man1dir=\$(mandir)/man1\n",
- "\n".
- ".SUFFIXES:\n".
- "\n".
- "%.o:\n".
- "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n".
"\n";
print &splitline("all:" . join "", map { " $_" } &progrealnames("X:U"));
print "\n\n";
@@ -916,6 +968,9 @@
foreach $d (&deps("X.o", undef, $dirpfx, "/")) {
print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
"\n";
+ $deflist = join "", map { " -D$_" } @{$d->{defs}};
+ print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS)$deflist" .
+ " -c \$< -o \$\@\n";
}
print "\n";
print $makefile_extra{'gtk'};
@@ -925,6 +980,7 @@
}
if (defined $makefiles{'mpw'}) {
+ $mftyp = 'mpw';
##-- MPW Makefile
open OUT, ">$makefiles{'mpw'}"; select OUT;
@@ -1065,6 +1121,7 @@
}
if (defined $makefiles{'lcc'}) {
+ $mftyp = 'lcc';
$dirpfx = &dirpfx($makefiles{'lcc'}, "\\");
##-- lcc makefile
@@ -1088,12 +1145,6 @@
"\n".
"\n".
"# Get include directory for resource compiler\n".
- "\n".
- ".c.obj:\n".
- &splitline("\tlcc -O -p6 \$(COMPAT) \$(FWHACK)".
- " \$(XFLAGS) \$(CFLAGS) \$*.c",69)."\n".
- ".rc.res:\n".
- &splitline("\tlrc \$(FWHACK) \$(RCFL) -r \$*.rc",69)."\n".
"\n";
print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C"));
print "\n\n";
@@ -1111,6 +1162,13 @@
foreach $d (&deps("X.obj", "X.res", $dirpfx, "\\")) {
print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
"\n";
+ if ($d->{obj} =~ /\.res$/) {
+ print &splitline("\tlrc \$(FWHACK) \$(RCFL) -r \$*.rc",69)."\n";
+ } else {
+ $deflist = join "", map { " -D$_" } @{$d->{defs}};
+ print &splitline("\tlcc -O -p6 \$(COMPAT) \$(FWHACK) \$(XFLAGS)".
+ " \$(CFLAGS)$deflist ".$d->{deps}->[0]." -o \$\@",69)."\n";
+ }
}
print "\n";
print $makefile_extra{'lcc'};
@@ -1123,6 +1181,7 @@
}
if (defined $makefiles{'osx'}) {
+ $mftyp = 'osx';
$dirpfx = &dirpfx($makefiles{'osx'}, "/");
##-- Mac OS X makefile
@@ -1140,16 +1199,11 @@
&splitline("CFLAGS = -O2 -Wall -Werror -g " .
(join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
"LDFLAGS = -framework Cocoa\n".
- &splitline("all:" . join "", map { " $_" } &progrealnames("MX")) .
+ &splitline("all:" . join "", map { " $_" } &progrealnames("MX:U")) .
"\n" .
$makefile_extra{'osx'} .
"\n".
".SUFFIXES: .o .c .m\n".
- "\n".
- ".c.o:\n".
- "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n".
- ".m.o:\n".
- "\t\$(CC) -x objective-c \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS) -c \$<\n".
"\n";
print "\n\n";
foreach $p (&prognames("MX")) {
@@ -1178,12 +1232,28 @@
print &splitline("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " .
$objstr . " $libstr", 69), "\n\n";
}
+ foreach $p (&prognames("U")) {
+ ($prog, $type) = split ",", $p;
+ $objstr = &objects($p, "X.o", undef, undef);
+ print &splitline($prog . ": " . $objstr), "\n";
+ $libstr = &objects($p, undef, undef, "-lX");
+ print &splitline("\t\$(CC)" . $mw . " \$(ULDFLAGS) -o \$@ " .
+ $objstr . " $libstr", 69), "\n\n";
+ }
foreach $d (&deps("X.o", undef, $dirpfx, "/")) {
print &splitline(sprintf("%s: %s", $d->{obj}, join " ", @{$d->{deps}})),
"\n";
+ $deflist = join "", map { " -D$_" } @{$d->{defs}};
+ if ($d->{deps}->[0] =~ /\.m$/) {
+ print "\t\$(CC) -x objective-c \$(COMPAT) \$(FWHACK) \$(XFLAGS)".
+ " \$(CFLAGS)$deflist -c \$< -o \$\@\n";
+ } else {
+ print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(XFLAGS) \$(CFLAGS)$deflist" .
+ " -c \$< -o \$\@\n";
+ }
}
print "\nclean:\n".
- "\trm -f *.o *.dmg\n".
+ "\trm -f *.o *.dmg". (join "", map { " $_" } &progrealnames("U")) . "\n".
"\trm -rf *.app\n";
select STDOUT; close OUT;
}
--- a/pattern.c
+++ b/pattern.c
@@ -1243,15 +1243,12 @@
{
game_params *p;
game_state *s;
- int recurse = TRUE;
char *id = NULL, *desc, *err;
- int y, x;
- int grade = FALSE;
while (--argc > 0) {
char *p = *++argv;
if (*p == '-') {
- fprintf(stderr, "%s: unrecognised option `%s'\n", argv[0]);
+ fprintf(stderr, "%s: unrecognised option `%s'\n", argv[0], p);
return 1;
} else {
id = p;
--- a/solo.c
+++ b/solo.c
@@ -2470,7 +2470,6 @@
game_state *s;
int recurse = TRUE;
char *id = NULL, *desc, *err;
- int y, x;
int grade = FALSE;
while (--argc > 0) {
@@ -2486,7 +2485,7 @@
grade = TRUE;
recurse = FALSE;
} else if (*p == '-') {
- fprintf(stderr, "%s: unrecognised option `%s'\n", argv[0]);
+ fprintf(stderr, "%s: unrecognised option `%s'\n", argv[0], p);
return 1;
} else {
id = p;