chiark / gitweb /
Added a framework for putting things other than the binary into a
authorSimon Tatham <anakin@pobox.com>
Sun, 23 Jan 2005 11:20:31 +0000 (11:20 +0000)
committerSimon Tatham <anakin@pobox.com>
Sun, 23 Jan 2005 11:20:31 +0000 (11:20 +0000)
Mac OS X application bundle, and provided an icon for Puzzles.

Also renamed the OS X source file from macosx.m to osx.m, so that it
can sit beside other things such as osx-info.plist and not cause
enormously long filenames.

[originally from svn r5179]

Recipe
mkfiles.pl
osx-info.plist [new file with mode: 0644]
osx.icns [new file with mode: 0644]
osx.m [moved from macosx.m with 99% similarity]

diff --git a/Recipe b/Recipe
index 99c800b6aa3f0cc9cf8c6762bd9003b5139818ae..36143a923de3cce48ad485dd6b1ceb0c0d0ac395 100644 (file)
--- a/Recipe
+++ b/Recipe
@@ -39,7 +39,7 @@ rect     : [G] WINDOWS COMMON rect
 pattern  : [G] WINDOWS COMMON pattern
 
 # Mac OS X unified application containing all the puzzles.
-Puzzles  : [MX] macosx COMMON ALL
+Puzzles  : [MX] osx osx.icns osx-info.plist COMMON ALL
 
 # The `nullgame' source file is a largely blank one, which contains
 # all the correct function definitions to compile and link, but
index 382a40bbaceed0d32e293d73535aaae8146f1a55..8af1939a3d93a717688dc5a391630186b2c9a243 100755 (executable)
@@ -135,9 +135,7 @@ foreach $i (@prognames) {
       $file = "$1.r";
       $depends{$j} = [$file];
       push @scanlist, $file;
-    } elsif ($j =~ /\.lib$/) {
-      # libraries don't have dependencies
-    } else {
+    } elsif ($j !~ /\./) {
       $file = "$j.c";
       $file = "$j.m" unless &findfile($file);
       $depends{$j} = [$file];
@@ -259,7 +257,7 @@ sub objects {
     } elsif ($i =~ /^(.*)\.lib/) {
       $y = $1;
       ($x = $ltmpl) =~ s/X/$y/;
-    } else {
+    } elsif ($i !~ /\./) {
       ($x = $otmpl) =~ s/X/$i/;
     }
     push @ret, $x if $x ne "";
@@ -267,6 +265,19 @@ sub objects {
   return join " ", @ret;
 }
 
+sub special {
+  my ($prog, $suffix) = @_;
+  my @ret;
+  my ($i, $x, $y);
+  @ret = ();
+  foreach $i (@{$programs{$prog}}) {
+    if (substr($i, (length $i) - (length $suffix)) eq $suffix) {
+      push @ret, $i;
+    }
+  }
+  return join " ", @ret;
+}
+
 sub splitline {
   my ($line, $width, $splitchar) = @_;
   my ($result, $len);
@@ -1133,10 +1144,22 @@ if (defined $makefiles{'osx'}) {
     foreach $p (&prognames("MX")) {
       ($prog, $type) = split ",", $p;
       $objstr = &objects($p, "X.o", undef, undef);
-      print "${prog}: ${prog}.app/Contents/MacOS/$prog\n\n";
-      print "${prog}.app:\n\tmkdir \$\@\n";
-      print "${prog}.app/Contents: ${prog}.app\n\tmkdir \$\@\n";
-      print "${prog}.app/Contents/MacOS: ${prog}.app/Contents\n\tmkdir \$\@\n";
+      $icon = &special($p, ".icns");
+      $infoplist = &special($p, "info.plist");
+      print "${prog}.app:\n\tmkdir -p \$\@\n";
+      print "${prog}.app/Contents: ${prog}.app\n\tmkdir -p \$\@\n";
+      print "${prog}.app/Contents/MacOS: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
+      $targets = "${prog}.app/Contents/MacOS/$prog";
+      if (defined $icon) {
+       print "${prog}.app/Contents/Resources: ${prog}.app/Contents\n\tmkdir -p \$\@\n";
+       print "${prog}.app/Contents/Resources/${prog}.icns: ${prog}.app/Contents/Resources $icon\n\tcp $icon \$\@\n";
+       $targets .= " ${prog}.app/Contents/Resources/${prog}.icns";
+      }
+      if (defined $infoplist) {
+       print "${prog}.app/Contents/Info.plist: ${prog}.app/Contents/Resources $infoplist\n\tcp $infoplist \$\@\n";
+       $targets .= " ${prog}.app/Contents/Info.plist";
+      }
+      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");
diff --git a/osx-info.plist b/osx-info.plist
new file mode 100644 (file)
index 0000000..54e8af3
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+       <key>CFBundleIconFile</key>
+       <string>Puzzles.icns</string>
+</dict>
+</plist>
diff --git a/osx.icns b/osx.icns
new file mode 100644 (file)
index 0000000..b4346a0
Binary files /dev/null and b/osx.icns differ
diff --git a/macosx.m b/osx.m
similarity index 99%
rename from macosx.m
rename to osx.m
index 52a70ef6457844eca765f90103c5d96ba8e95cb6..2fad086256105a9c13bdfec200881e812625266f 100644 (file)
--- a/macosx.m
+++ b/osx.m
@@ -8,8 +8,6 @@
  *  - configurability. Will no doubt involve learning all about the
  *    dialog control side of Cocoa.
  *
- *  - needs an icon.
- *
  *  - not sure what I should be doing about default window
  *    placement. Centring new windows is a bit feeble, but what's
  *    better? Is there a standard way to tell the OS "here's the
@@ -744,9 +742,13 @@ int main(int argc, char **argv)
     NSMenu *menu;
     NSMenuItem *item;
     AppController *controller;
+    NSImage *icon;
 
     pool = [[NSAutoreleasePool alloc] init];
+
+    icon = [NSImage imageNamed:@"NSApplicationIcon"];
     [NSApplication sharedApplication];
+    [NSApp setApplicationIconImage:icon];
 
     controller = [[[AppController alloc] init] autorelease];