Creating Universal Binaries with GNU autotools
If you’re a Unix hacker on Mac OS X, chances are
you’ll be using a very large number of open-source
projects that use GNU
autotools: these are the projects that you typically
compile with the ./configure script. It
turns out that building a Mac OS X “Universal Binary”
that runs on both PowerPC and Intel isn’t too hard at
all, with the appropriate magic incantations to the
./configure script:
CFLAGS="-isysroot /Developer/SDKs/MacOSX10.4u.sdk -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc" \
./configure
Notes about this:
- You will get a ton of warnings from the linker
during the compile that the
-syslibrootparameter was ignored since no linking was done. Just ignore them. (If you find out how to shut ld up, do email me!) - You may need to pass the
--disable-dependency-trackingto./configure, especially for projects that use GNU libtool. Yeah, this means you won’t get proper dependency tracking for your project, so (just like the Universal Binary Programming Guidelines suggests) I’d suggest you compile a universal binary only when you build a proper release package.
Update: Note that this is merely
a way to get autotools to build universal
binaries. It definitely does not mean that your
project will automagically work with on both PowerPC
and x86. (In particular, you’ll have to change
autoconf-supplied architecture and endian macros such
as AC_C_BIGENDIAN: see the autoconf
section of the
Universal Binary Programming Guidelines for more
details.)
Update (2): It seems that this
technique has officially been sanctioned by Apple:
technical note TN2137
uses the exact CFLAGS that I’ve
described here.