X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/blobdiff_plain/3f98cd5a40321c18f87e4e732a75f56cc187cb1f..95c76d7c0c76081ab4f389aa1bb7667ee08c99eb:/mkfiles.pl diff --git a/mkfiles.pl b/mkfiles.pl index a107737..cefd365 100755 --- a/mkfiles.pl +++ b/mkfiles.pl @@ -130,8 +130,28 @@ readinput: while (1) { $i eq "[X]" or $i eq "[U]" or $i eq "[MX]") and defined $prog) { $type = substr($i,1,(length $i)-2); } else { - push @$listref, $i; - push @allobjs, $i; + if ($i =~ /\?$/) { + # Object files with a trailing question mark are optional: + # the build can proceed fine without them, so we only use + # them if their primary source files are present. + $i =~ s/\?$//; + $i = undef unless defined &finddep($i); + } elsif ($i =~ /\|/) { + # Object file descriptions containing a vertical bar are + # lists of choices: we use the _first_ one whose primary + # source file is present. + @options = split /\|/, $i; + $j = undef; + foreach $k (@options) { + $j=$k, last if defined &finddep($k); + } + die "no alternative found for $i\n" unless defined $j; + $i = $j; + } + if (defined $i) { + push @$listref, $i; + push @allobjs, $i; + } } } if ($prog and $type) { @@ -192,23 +212,8 @@ foreach $i (@prognames) { $programs{$i} = [@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". - # 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); + $file = &finddep($j); + if (defined $file) { $depends{$jj} = [$file]; push @scanlist, $file; } @@ -315,6 +320,32 @@ sub findfile { 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 { my ($prog, $otmpl, $rtmpl, $ltmpl, $prefix, $dirsep) = @_; my @ret; @@ -456,12 +487,13 @@ if (defined $makefiles{'cygwin'}) { "# RCINC = --include-dir c:\\cygwin\\include\\\n". "\n". &splitline("CFLAGS = -mno-cygwin -Wall -O2 -D_WINDOWS -DDEBUG -DWIN32S_COMPAT". - " -D_NO_OLDNAMES -DNO_MULTIMON " . + " -D_NO_OLDNAMES -DNO_MULTIMON -DNO_HTMLHELP " . (join " ", map {"-I$dirpfx$_"} @srcdirs)) . "\n". "LDFLAGS = -mno-cygwin -s\n". &splitline("RCFLAGS = \$(RCINC) --define WIN32=1 --define _WIN32=1". - " --define WINVER=0x0400 --define MINGW32_FIX=1")."\n". + " --define WINVER=0x0400 --define MINGW32_FIX=1 " . + (join " ", map {"--include $dirpfx$_"} @srcdirs) )."\n". "\n"; print &splitline("all:" . join "", map { " $_.exe" } &progrealnames("G:C")); print "\n\n"; @@ -655,7 +687,7 @@ if (defined $makefiles{'vc'}) { "\n"; if ($d->{obj} =~ /\.res$/) { print "\trc \$(FWHACK) \$(RCFL) -r -DWIN32 -D_WIN32 ". - "-DWINVER=0x0400 ".$d->{deps}->[0]."\n"; + "-DWINVER=0x0400 -fo".$d->{obj}." ".$d->{deps}->[0]."\n"; } else { $deflist = join "", map { " /D$_" } @{$d->{defs}}; print "\tcl \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist".