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: , ,

2 Comments:

  • From the GnuPG README file. No lipo needed.

    Building Universal Binaries on Apple OS X
    -----------------------------------------

    You can build a universal ("fat") binary that will work on both
    PPC and Intel Macs with something like:

    ./configure CFLAGS="-arch ppc -arch i386" --disable-endian-check \
    --disable-dependency-tracking --disable-asm

    If you are doing the build on a OS X 10.4 (Tiger) PPC machine you
    may need to add "-isysroot /Developer/SDKs/MacOSX10.4u.sdk" to
    those CFLAGS. This additional isysroot is not necessary on Intel
    Tiger boxes, or any OS X 10.5 (Leopard) or later boxes.

    Note that when building a universal binary, any third-party
    libraries you may link with need to be universal as well. All
    Apple-supplied libraries (even libraries not originally written by
    Apple like curl, zip, and BZ2) are universal.

    By Anonymous Anonymous, At 10/18/2008 9:12 AM  

  • Hey, good to know! Hopefully this post will still be useful to people.

    By Blogger James Hood, At 10/18/2008 12:25 PM  

Post a Comment

Subscribe to Post Comments [Atom]



<< Home