Compile ImageMagick on OS X

Because of the missing TIFF support in the binary distribution of ImageMagick for OS X, i had to compile my own version of ImageMagick. Since it took my quite some time to do that, i want to share here my results.

I wanted my version of ImageMagick to work without installation. That's why i had to compiled all necessary libraries myself. My resulting version supports all default formats as well as JPEG, PNG and TIFF.

WARNING: You have to adjust the user-path (here username) in the following lines. You can run all the following commands with your normal user rights.

mkdir /Users/username/sandbox
cd /Users/username/sandbox
 
curl -O ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-1.2.18.tar.bz2
tar -xjf libpng-1.2.18.tar.bz2
cd libpng-1.2.18
./configure \
	CFLAGS="-isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386" \
	CPPFLAGS="-I/Users/username/sandbox/ImageMagick/include" \
	LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386 -L/Users/username/sandbox/ImageMagick/lib" \
	--prefix=/Users/username/sandbox/ImageMagick --enable-shared --disable-dependency-tracking
make
make install
cd ..
 
curl -O ftp://ftp.imagemagick.org/pub/ImageMagick/delegates/libjpeg-6b.tar.gz
tar -xzf libjpeg-6b.tar.gz
cd libjpeg-6b
./configure \
	CFLAGS="-isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386" \
	CPPFLAGS="-I/Users/username/sandbox/ImageMagick/include" \
	LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386 -L/Users/username/sandbox/ImageMagick/lib" \
	--prefix=/Users/username/sandbox/ImageMagick --enable-shared --disable-dependency-tracking
make
make install
cd ..

You can't compile the current version of libtiff as a universal binary. The reason for that is the configure script, witch detects the byte ordering on your machine. To avoid this, you have to make some manual corrections to the source code. First we decompress libtiff as usual and run configure:

curl -O http://dl.maptools.org/dl/libtiff/tiff-3.8.2.tar.gz
tar -xzf tiff-3.8.2.tar.gz
cd tiff-3.8.2
autoconf
./configure \
	CFLAGS="-isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386" \
	CPPFLAGS="-I/Users/username/sandbox/ImageMagick/include" \
	LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386 -L/Users/username/sandbox/ImageMagick/lib" \
	--prefix=/Users/username/sandbox/ImageMagick --enable-shared --disable-dependency-tracking \
	--disable-cxx --without-x --with-apple-opengl-framework

Now we apply the following changes:

You have to comment out all occurrences of HOST_BIGENDIAN, HOST_FILLORDER and WORDS_BIGENDIAN in libtiff/tif_config.h. Then we insert the following lines:

#ifdef __BIG_ENDIAN__
#define HOST_BIGENDIAN 1
#define HOST_FILLORDER FILLORDER_MSB2LSB
#define WORDS_BIGENDIAN 1
#else
#define HOST_BIGENDIAN 0
#define HOST_FILLORDER FILLORDER_LSB2MSB
#undef WORDS_BIGENDIAN
#endif

In libtiff/tifconf.h we comment out all occurrences of HOST_BIGENDIAN and HOST_FILLORDER and insert the following:

#ifdef __BIG_ENDIAN__
#define HOST_BIGENDIAN 1
#define HOST_FILLORDER FILLORDER_MSB2LSB
#else
#define HOST_BIGENDIAN 0
#define HOST_FILLORDER FILLORDER_LSB2MSB
#endif

Now we can compile libtiff an install it as usual:

make
make install
cd ..

The remaining libraries can be compiled without further problems.

curl -O ftp://xmlsoft.org/libxml2/libxml2-2.6.28.tar.gz
tar -xzf libxml2-2.6.28.tar.gz
cd libxml2-2.6.28
./configure \
	CFLAGS="-isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386" \
	CPPFLAGS="-I/Users/username/sandbox/ImageMagick/include" \
	LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386 -L/Users/username/sandbox/ImageMagick/lib" \
	--prefix=/Users/username/sandbox/ImageMagick --enable-shared --disable-dependency-tracking \
	--without-python
make
make install
cd ..
 
curl -O ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz
tar -xzf ImageMagick.tar.gz
cd ImageMagick-6.3.4
./configure \
	CFLAGS="-isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386" \
	CPPFLAGS="-I/Users/username/sandbox/ImageMagick/include" \
	LDFLAGS="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386 -L/Users/username/sandbox/ImageMagick/lib" \
	--prefix=/Users/username/sandbox/ImageMagick \
	--enable-shared --disable-dependency-tracking --disable-installed --without-magick-plus-plus --without-perl --without-x
make
make install

You can now copy the ImageMagick folder to any location you want. Just adjust the environment variables MAGICK_HOME and DYLD_LIBRARY_PATH accordingly:

export MAGICK_HOME=/Users/username/sandbox/ImageMagick/
export DYLD_LIBRARY_PATH=/Users/username/sandbox/ImageMagick/lib/
 
/Users/username/sandbox/ImageMagick/bin/convert
Version: ImageMagick 6.3.4 05/10/07 Q16 http://www.imagemagick.org
...
 
π