leopard

Adding support for the GD graphic library on OS X 10.5 Leopard

I play around with a number of Drupal locally and today I finally caved in and decided to add GD support to OS X's webserver. Although I've heard great things about the Entropy PHP packages, I did not want to replace OS X's integrated php installation so my remaining option was to grab a copy of PHP 5.2.8 (the version bundled with Leopard) and compile the module myself. I know there must be quite a few other people who are looking do to the same thing, so I here's a step-by-step guide on how I did it:

(Please note that I assume you have Xcode installed, and that all downloads are saved in the "Downloads" folder in your home. If this is not the case, please move the downloads there first before executing any of the listed commands)

  1. Visit the libpng and libjpeg homepages and download the latest release available for both. As of writing, the most recent releases are libjpeg 7 and libpng 1.2.37 - the commands below will need to be adjusted slightly if you are compiling a more recent version.
  2. Download PHP 5.2.8, available here
  3. Extract PHP and prepare to compile libpng and libjpeg statically:
    cd ~/Downloads
    tar xfj php-5.2.8.tar.bz2
    cd php-5.2.8/ext/gd
    mv ~/Downloads/libpng-1.2.37.tar.gz ~/Downloads/jpegsrc.v7.tar.gz .
  4. Compile libpng without shared libraries:
    tar xfz libpng-1.2.37.tar.gz && cd libpng-1.2.37
    ./configure --disable-shared --enable-static
    make && make install DESTDIR=`pwd`/localinstall
    cd ../
  5. Compile libjpeg without shared libraries:
    tar xfz jpegsrc.v7.tar.gz && cd jpeg-7
    cp /usr/share/libtool/config.* .
    ./configure --disable-shared --enable-static
    make && make install DESTDIR=`pwd`/localinstall
    cd ../
  6. Compile the GD extension and point to our newly compiled libpng and libjpeg static libraries:
    cd ~/Downloads/php-5.2.8/ext/gd
    phpize
    MACOSX_DEPLOYMENT_TARGET=10.5 \
    CFLAGS="-O3 -fno-common -arch i686" \
    LDFLAGS="-O3 -arch i686" \
    CXXFLAGS="-O3 -fno-common -arch i686" \
    ./configure --with-zlib-dir=/usr \
    --with-png-dir=`pwd`/libpng-1.2.37/localinstall/usr/local \
    --with-jpeg-dir=`pwd`/jpeg-7/localinstall/usr/local \
    --with-freetype-dir=/usr/X11R6 \
    --with-xpm-dir=/usr/X11R6
    make
    sudo make install
  7. Copy /private/etc/php.ini.default to /private/etc/php.ini
    • Change the default 'extension_dir' (./) to /usr/lib/php/extensions/no-debug-non-zts-20060613/
    • Add extension=gd.so a bit below extension_dir to enable the gd extension
  8. sudo nano /System/Library/LaunchDaemons/org.apache.httpd.plist
    Change the part between <array> and </array> so that it looks like this:
    <array>
    <string>/usr/bin/arch</string>
    <string>-i386</string>
            <string>/usr/sbin/httpd</string>
            <string>-D</string>
            <string>FOREGROUND</string>
    </array>

    This will ensure that Apache starts in 32 bit mode, which is needed as the gd extension was compiled for i686.
  9. That's all! After a reboot (or toggle Web sharing in the System Preferences), everything should be working. phpinfo() should now confirm that GD library is indeed loaded. If it isn't or if apache refuses to start, try opening Console to check /var/log/apache2/error_log for some useful pointers as to what's wrong.

    Helpful source I used for writing this tutorial: HOWTO: Install Habari on Mac OS X Leopard, From Scratch

Rating: 

Installing GIMP on OS X

GIMP is a great program, but I always found it was a bit annoying to use on OS X (Leopard). First of all, whenever X11 starts, a new xterm window along with it. Besides that, when switching windows you need two clicks before GIMP (or any other program, really) registers the click and actually does something - the first click just switches the active window. Seeing as GIMP has it's tool palette in a separate window, this quickly became extremely irritating.

After a quick google, I found many sources saying that to disable xterm, I needed to copy /private/etc/X11/xinit/xinitrc to ~/.xinitrc and edit out the "xterm &" line inside. That's easy enough, but the only problem is that on Leopard with the latest X11 from XQuartz (2.3.2.1 at the time of writing) installed, /private/etc/X11/xinit/xinitrc doesn't exist! Although /usr/X11/lib/X11/xinit/xinitrc does, editing out all references to xterm doesn't work anyways. Instead, the app_to_run preference needs to be modified:

defaults write org.x.X11 app_to_run /usr/bin/true

/usr/bin/true is a command that does nothing (literally), so this essentially tells X11 to autostart nothing. I moved onto my next problem and found that to solve the two-clicks problem, the solution was to enable the "focus follows mouse" option like this:

defaults write org.x.x11 FocusFollowsMouse -string YES

I've been using that for a few months and I find it's still pretty annoying, but it's still less annoying than having to click twice on everything. Fortunately, I recently discovered the "wm_click_through" preference which is exactly what I had been looking for all along:

defaults write org.x.x11 FocusFollowsMouse -string NO
defaults write org.x.X11 wm_click_through -bool true

Now X11's window focus is back to normal, and clicking on inactive windows works as expected; it switches the window and activates the widget you clicked on. Problems solved!

Rating: