2006-05-30

Building Universal Binaries from "configure"-based Open Source Projects

Apple has a technical note TN2137 entitled "Building Universal Binaries from "configure"-based Open Source Projects". It has instructions for building a ppc/i386 "universal" binary given an OSS project that uses autoconf, and it seems like it would be really handy. The trouble is, the instructions have never worked for me.

I always have failures like this:

checking for C compiler default output file name... configure: error: C compiler cannot create executables

Which looks like this in config.log:

configure:1798: checking for C compiler default output file name
configure:1801: gcc -O -g -isysroot /Developer/SDKs/MacOSX10.4u.sdk
-arch i386 -arch ppc -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk conftest.c >&5
/usr/bin/ld: -syslibroot: multiply specified
collect2: ld returned 1 exit status
/usr/bin/ld: -syslibroot: multiply specified
collect2: ld returned 1 exit status
lipo: can't open input file: /var/tmp//ccBImgUy.out (No such file or directory)
configure:1804: $? = 1

One of the many problems with autoconf is that it doesn't make it easy for a vendor to offer fixed testlets (I don't know what they're really called) to fix existing configure scripts. The versions on the maintainers' machines are hard-coded into the configure script, so even when a test is improved, each project's maintainer has to regenerate their configure script before you feel the benefit.

So, while we wait for that to happen, here's the work-around I've been using:

  1. Run ./configure as normal.

  2. Add -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc to the CFLAGS line in the generated Makefile.

  3. Add -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc to the LDFLAGS line.

  4. Run make(1).

  5. Use file(1) to check that you got what you wanted.


Obviously, since we lied to the configure script, we might get bitten. But this has worked for me so far, and Apple's cleaner method never has. (Presumably there are some OSS projects out there where it does work, but I haven't needed to build any of them.)