Mac OS X Server
Mac OS X Server
Compiling Open Source products with multi architecture support
Saturday, 22 August 2009
Recently I posted about how to build Perl modules with support for multiple architectures. But what do you do if you need to use a library that Apple haven’t prebuilt for us?
Well fortunately this can be quite an easy process if the library uses configure nicely.
I wanted to build the GD library with PNG support.
First I downloaded the libpng and libgd sources.
The process of building is only slightly different to the usual configure; make; make install process.
Before we get into the usual process we need to set a couple of environment variables.
CFLAGS=”-O -g -isysroot /Developer/SDKs/MacOSX10.5.sdk -arch i386 -arch ppc -arch x86_64”
LDFLAGS=”-arch i386 -arch ppc -arch x86_64”
export CFLAGS LDFLAGS
Note that /Develper/SDKs/MacOSX10.5.sdk should point to the current SDK version installed.
Now we can go and run the configure script. This again has an extra option in addition to anything that you wish to add.
./configure --disable-dependency-tracking
According to Apple GCC’s dependancy checking can get confused when working with multiple architectures. The --disable-dependency-tracking tells GCC not to worry about it.
Now run make and the library will be built.
To check that it has all the desired architectures, check with the file command.
file .libs/libpng.3.dylib .libs/libpng12.0.dylib
.libs/libpng.3.dylib: Mach-O universal binary with 3 architectures
.libs/libpng.3.dylib (for architecture i386):Mach-O dynamically linked shared library i386
.libs/libpng.3.dylib (for architecture ppc7400):Mach-O dynamically linked shared library ppc
.libs/libpng.3.dylib (for architecture x86_64):Mach-O 64-bit dynamically linked shared library x86_64
.libs/libpng12.0.dylib: Mach-O universal binary with 3 architectures
.libs/libpng12.0.dylib (for architecture i386):Mach-O dynamically linked shared library i386
.libs/libpng12.0.dylib (for architecture ppc7400):Mach-O dynamically linked shared library ppc
.libs/libpng12.0.dylib (for architecture x86_64):Mach-O 64-bit dynamically linked shared library x86_64
Now all that remains is to run make install to install the library.