chiark / gitweb /
Update the OS X Puzzles makefile so that it builds on Leopard and
authorSimon Tatham <anakin@pobox.com>
Tue, 11 Mar 2008 17:59:38 +0000 (17:59 +0000)
committerSimon Tatham <anakin@pobox.com>
Tue, 11 Mar 2008 17:59:38 +0000 (17:59 +0000)
generates PPC/Intel dual-architecture binaries.

This turns out not to be too painful: you compile and link your
programs using `gcc -arch ppc' or `gcc -arch i386', then you use a
command of the form `lipo -create ppc-binary i386-binary -output
binary' to construct a universal binary. It works equally well on
command-line standalone executable files and the executables within
application directories. Also added the -mmacosx-version-min option,
since otherwise the OS X build tools appear to default to building
binaries which will crash (without anything resembling a
comprehensible error message) on any earlier release.

The handling of version.o in this checkin is somewhat grotty. I'd
prefer a method more cleverly intertwingled with mkfiles.pl so I
didn't have to maintain the OS X architecture list in both
mkfiles.pl and Recipe. (Not that I anticipate Apple switching
architectures again in the immediate future, but it's the principle
of the thing.)

[originally from svn r7916]

Recipe
mkfiles.pl

diff --git a/Recipe b/Recipe
index 885b0d7845f938f5d405a7f8d170bba202c6ac41..2decb2fa9aba476dd1fbef68fc7564c16659b2fb 100644 (file)
--- a/Recipe
+++ b/Recipe
@@ -119,14 +119,23 @@ FORCE:
 # md5sum readily available. We do, however, have `md5 -r' which
 # generates _nearly_ the same output, but it has no check function.
 !begin osx
-version.o: FORCE;
+version.ppc.o: FORCE;
 FORCE:
        if test -z "$(VER)" && test -f manifest && (md5 -r `awk '{print $$2}' manifest` | diff -w manifest -); then \
-               $(CC) $(COMPAT) $(XFLAGS) $(CFLAGS) `cat version.def` -c version.c; \
+               $(CC) -arch ppc $(COMPAT) $(XFLAGS) $(CFLAGS) `cat version.def` -c version.c -o version.ppc.o; \
        elif test -z "$(VER)" && test -d .svn && svnversion . >/dev/null 2>&1; then \
-               $(CC) $(COMPAT) $(XFLAGS) $(CFLAGS) "-DREVISION=`svnversion .`" -c version.c; \
+               $(CC) -arch ppc $(COMPAT) $(XFLAGS) $(CFLAGS) "-DREVISION=`svnversion .`" -c version.c -o version.ppc.o; \
        else \
-               $(CC) $(COMPAT) $(XFLAGS) $(CFLAGS) $(VER) -c version.c; \
+               $(CC) -arch ppc $(COMPAT) $(XFLAGS) $(CFLAGS) $(VER) -c version.c -o version.ppc.o; \
+       fi
+version.i386.o: FORCE2;
+FORCE2:
+       if test -z "$(VER)" && test -f manifest && (md5 -r `awk '{print $$2}' manifest` | diff -w manifest -); then \
+               $(CC) -arch i386 $(COMPAT) $(XFLAGS) $(CFLAGS) `cat version.def` -c version.c -o version.i386.o; \
+       elif test -z "$(VER)" && test -d .svn && svnversion . >/dev/null 2>&1; then \
+               $(CC) -arch i386 $(COMPAT) $(XFLAGS) $(CFLAGS) "-DREVISION=`svnversion .`" -c version.c -o version.i386.o; \
+       else \
+               $(CC) -arch i386 $(COMPAT) $(XFLAGS) $(CFLAGS) $(VER) -c version.c -o version.i386.o; \
        fi
 !end
 !specialobj osx version
index b25d86ca72256d559f53a74f6bb7c8cb6543d0e6..376bf461edcbf8971a46d247b6ac226dc2573c65 100755 (executable)
@@ -1351,6 +1351,7 @@ if (defined $makefiles{'lcc'}) {
 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 +1364,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 +1378,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 +1395,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;
 }