Michael Schierl's patch to compile the puzzles as Java applets using
[sgt/puzzles] / mkfiles.pl
index b25d86c..8119f6c 100755 (executable)
@@ -284,7 +284,7 @@ sub mfval($) {
     # Returns true if the argument is a known makefile type. Otherwise,
     # prints a warning and returns false;
     if (grep { $type eq $_ }
-       ("vc","vcproj","cygwin","borland","lcc","gtk","mpw","osx","wce")) {
+       ("vc","vcproj","cygwin","borland","lcc","gtk","mpw","nestedvm","osx","wce")) {
            return 1;
        }
     warn "$.:unknown makefile type '$type'\n";
@@ -1348,9 +1348,63 @@ if (defined $makefiles{'lcc'}) {
     select STDOUT; close OUT;
 }
 
+if (defined $makefiles{'nestedvm'}) {
+    $mftyp = 'nestedvm';
+    $dirpfx = &dirpfx($makefiles{'nestedvm'}, "/");
+
+    ##-- NestedVM makefile
+    open OUT, ">$makefiles{'nestedvm'}"; select OUT;
+    print
+    "# Makefile for $project_name under NestedVM.\n".
+    "#\n# This file was created by `mkfiles.pl' from the `Recipe' file.\n".
+    "# DO NOT EDIT THIS FILE DIRECTLY; edit Recipe or mkfiles.pl instead.\n";
+    # gcc command line option is -D not /D
+    ($_ = $help) =~ s/=\/D/=-D/gs;
+    print $_;
+    print
+    "\n".
+    "# This path points at the nestedvm root directory\n".
+    "NESTEDVM = /opt/nestedvm\n".
+    "# You can define this path to point at your tools if you need to\n".
+    "TOOLPATH = \$(NESTEDVM)/upstream/install/bin\n".
+    "CC = \$(TOOLPATH)/mips-unknown-elf-gcc\n".
+    "\n".
+    &splitline("CFLAGS = -O2 -Wall -Werror -DSLOW_SYSTEM -g " .
+              (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
+    "\n";
+    print &splitline("all:" . join "", map { " $_.jar" } &progrealnames("X"));
+    print "\n\n";
+    foreach $p (&prognames("X")) {
+      ($prog, $type) = split ",", $p;
+      $objstr = &objects($p, "X.o", undef, undef);
+      $objstr =~ s/gtk\.o/nestedvm\.o/g;
+      print &splitline($prog . ".mips: " . $objstr), "\n";
+      $libstr = &objects($p, undef, undef, "-lX");
+      print &splitline("\t\$(CC)" . $mw . " \$(${type}LDFLAGS) -o \$@ " .
+                       $objstr . " $libstr -lm", 69), "\n\n";
+    }
+    foreach $d (&deps("X.o", undef, $dirpfx, "/")) {
+      $oobjs = $d->{obj};
+      $ddeps= join " ", @{$d->{deps}};
+      $oobjs =~ s/gtk/nestedvm/g;
+      $ddeps =~ s/gtk/nestedvm/g;
+      print &splitline(sprintf("%s: %s", $oobjs, $ddeps)),
+          "\n";
+      $deflist = join "", map { " -D$_" } @{$d->{defs}};
+      print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist" .
+         " -c \$< -o \$\@\n";
+    }
+    print "\n";
+    print $makefile_extra{'nestedvm'};
+    print "\nclean:\n".
+    "\trm -rf *.o *.mips *.class *.html *.jar org applet.manifest\n";
+    select STDOUT; close OUT;
+}
+
 if (defined $makefiles{'osx'}) {
     $mftyp = 'osx';
     $dirpfx = &dirpfx($makefiles{'osx'}, "/");
+    @osxarchs = ('ppc', 'i386');
 
     ##-- Mac OS X makefile
     open OUT, ">$makefiles{'osx'}"; select OUT;
@@ -1363,6 +1417,7 @@ if (defined $makefiles{'osx'}) {
     print $_;
     print
     "CC = \$(TOOLPATH)gcc\n".
+    "LIPO = \$(TOOLPATH)lipo\n".
     "\n".
     &splitline("CFLAGS = -O2 -Wall -Werror -g " .
               (join " ", map {"-I$dirpfx$_"} @srcdirs))."\n".
@@ -1376,7 +1431,6 @@ if (defined $makefiles{'osx'}) {
     print "\n\n";
     foreach $p (&prognames("MX")) {
       ($prog, $type) = split ",", $p;
-      $objstr = &objects($p, "X.o", undef, undef);
       $icon = &special($p, ".icns");
       $infoplist = &special($p, "info.plist");
       print "${prog}.app:\n\tmkdir -p \$\@\n";
@@ -1394,34 +1448,49 @@ if (defined $makefiles{'osx'}) {
       }
       $targets .= " \$(${prog}_extra)";
       print &splitline("${prog}: $targets", 69) . "\n\n";
-      print &splitline("${prog}.app/Contents/MacOS/$prog: ".
-                      "${prog}.app/Contents/MacOS " . $objstr), "\n";
       $libstr = &objects($p, undef, undef, "-lX");
-      print &splitline("\t\$(CC)" . $mw . " \$(LDFLAGS) -o \$@ " .
+      $archbins = "";
+      foreach $arch (@osxarchs) {
+       $objstr = &objects($p, "X.${arch}.o", undef, undef);
+       print &splitline("${prog}.${arch}.bin: " . $objstr), "\n";
+       print &splitline("\t\$(CC) -arch ${arch} -mmacosx-version-min=10.3 \$(LDFLAGS) -o \$@ " .
                        $objstr . " $libstr", 69), "\n\n";
+       $archbins .= " ${prog}.${arch}.bin";
+      }
+      print &splitline("${prog}.app/Contents/MacOS/$prog: ".
+                      "${prog}.app/Contents/MacOS" . $archbins), "\n";
+      print &splitline("\t\$(LIPO) -create $archbins -output \$@", 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";
+      $archbins = "";
+      foreach $arch (@osxarchs) {
+       $objstr = &objects($p, "X.${arch}.o", undef, undef);
+       print &splitline("${prog}.${arch}: " . $objstr), "\n";
+       print &splitline("\t\$(CC) -arch ${arch} -mmacosx-version-min=10.3 \$(ULDFLAGS) -o \$@ " .
+                       $objstr . " $libstr", 69), "\n\n";
+       $archbins .= " ${prog}.${arch}";
+      }
+      print &splitline("${prog}:" . $archbins), "\n";
+      print &splitline("\t\$(LIPO) -create $archbins -output \$@", 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) \$(CFLAGS)".
-           " \$(XFLAGS)$deflist -c \$< -o \$\@\n";
-      } else {
-       print "\t\$(CC) \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist" .
-           " -c \$< -o \$\@\n";
+    foreach $arch (@osxarchs) {
+      foreach $d (&deps("X.${arch}.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) -arch $arch -mmacosx-version-min=10.3 -x objective-c \$(COMPAT) \$(FWHACK) \$(CFLAGS)".
+             " \$(XFLAGS)$deflist -c \$< -o \$\@\n";
+        } else {
+         print "\t\$(CC) -arch $arch -mmacosx-version-min=10.3 \$(COMPAT) \$(FWHACK) \$(CFLAGS) \$(XFLAGS)$deflist" .
+             " -c \$< -o \$\@\n";
+        }
       }
     }
     print "\nclean:\n".
-    "\trm -f *.o *.dmg". (join "", map { " $_" } &progrealnames("U")) . "\n".
+    "\trm -f *.o *.dmg". (join "", map { my $a=$_; (" $a", map { " ${a}.$_" } @osxarchs) } &progrealnames("U")) . "\n".
     "\trm -rf *.app\n";
     select STDOUT; close OUT;
 }