How to build a universal matplotlib for MacOS X

Here are instructions for building a universal matplotlib for MacOS X
from source. The topic comes up once in awhile and having just fought
through it, I figured it was best to post instructions. Thanks to
Charlie Moad and mpsuzuki for their valuable assistance.

1) Install the prerequisites:

1.1) libz is included with MacOS X 10.4. If you ever installed a copy
yourself, get rid of it or make sure it's universal.

1.2) Install libpng. Get source, unpack and:

- Configure it for a universal build. On a PPC system (this should be
two lines; you may have to manually unwrap the first line):
$ CFLAGS="-O -g -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386
-arch ppc" \
   ./configure --disable-dependency-tracking

- On an Intel system use this simpler version:
$ CFLAGS="-arch i386 -arch ppc" \
   ./configure --disable-dependency-tracking

- Build and install as usual:
$ make
$ sudo make install

- If you plan to redistribute matplotlib, delete the dynamic library so
matplotlib statically links to libpng:
$ sudo rm /usr/local/lib/libpng*.dylib

1.3) Install freetype. Do *NOT* use version 2.2.1; it is broken on MacOS
X (but fixed in CVS). 2.1.10 works fine. Get source, unpack, and install
exactly as for libpng except:

- Before building, you may wish to modify
include/freetype/configure/ftoption.h to enable hinting:
  uncomment #define TT_CONFIG_OPTION_BYTECODE_INTERPRETER
  perhaps comment out #define TT_CONFIG_OPTION_UNPATENTED_HINTING

- After building, you *MUST* delete the dynamic library. At least for
version 2.1.10 and 2.2.1 it is *NOT* universal, only the static library
is universal.
$ sudo rm /usr/local/lib/libfreetype*.dylib

2) Make sure you have a universal python installed, e.g. MacPython from
<http://pythonmac.org/packages/>

3) Install matplotlib in the usual fashion:
$ python setup.py build
$ sudo python setup.py install
(I didn't try easy_install, but I suspect it works too)

-- Russell

P.S. The instructions for running configure to get a universal binary
are from Apple Tech Note 2137:
<http://developer.apple.com/technotes/tn2005/tn2137.html> with the
correction that LDFLAGS must *NOT* be defined (issue number 4387241 in
Apple Bug Reporter database). Fortunately it is not necessary, and
suggesting otherwise is a mistake in the tech note.

If you forget --disable-dependency-tracking you'll get error messages
saying you have an incompatible set of compiler flags.