Formatting tweaks / index terms in Unequal docs.
[sgt/puzzles] / mkfiles.pl
index a107737..52c9a74 100755 (executable)
@@ -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;
@@ -383,6 +414,8 @@ sub deps {
       ($x = $otmpl) =~ s/X/$i/;
     }
     @deps = @{$depends{$ii}};
+    # Skip things which are their own dependency.
+    next if grep { $_ eq $i } @deps;
     @deps = map {
       $_ = &findfile($_);
       s/\//$dirsep/g;
@@ -456,12 +489,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 +689,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".