Memoirs of Fls'Zen

Friday, October 17, 2008

Merging Architecture Trees for Building Universal Binaries on OS X

While building a universal binary of GnuPG, I have come across the problem of merging two architectures. Due to design, GnuPG is not able to build binaries with multiple architectures. It is easy to build GnuPG for just i386 or just ppc, however, the trick is lipoing them both together without too much trouble. The following script assumes that an environment variable BUILD_PATH has been set. This path should be the root for your architectures (this should be the output specified by --prefix during configure), in this case it contains the "i386" and "ppc" directories. (Each architecture contains lib, bin, etc.)

Here's the script to merge these architectures together:

cp -R $BUILD_PATH/i386 $BUILD_PATH/universal
cd $BUILD_PATH/universal
find . -perm -0001 -type f -exec lipo -create $BUILD_PATH/i386/{} $BUILD_PATH/ppc/{} -output $BUILD_PATH/universal/{} \;

The script starts by creating the "universal" directory from a copy of "i386", so the entire tree is present. Then, find is used in conjunction with lipo to merge the architectures together into the universal directory.

Pretty spiffy, eh?

UPDATE: GnuPG indeed builds universal, I just neglected to read the readme. See the first comment.

Labels: , ,