OS X SDL Development Command Line Setup

Building the libraries

Libraries on OS X are typically distributed as Frameworks and these will be used with Xcode. For the command-line build system I will install most of the libraries from source. A basic understanding of how to use Apple’s Terminal App (bash shell) is necessary to complete this setup procedure.

The following was performed on an Intel based iMac using OS X Snow Leopard (10.6.8).

If you are looking for the old page which covered OS X Leopard (10.5.6) it is still available here OS X (Leopard 10.5.6) SDL Development Command Line Setup.

I will install all the libraries needed to compile the Classic Invaders source.

  • SDL
  • zlib
  • libpng
  • SDL_image
  • libogg
  • libvorbis
  • SDL_mixer
  • Freetype2
  • SDL_ttf
  • boost C++ libraries (header files only)

Note: by default we install everything here into /usr/local so you will need Administrator privileges on the machine you are installing on.

The basic procedure is to download and decompress the source archive, configure the source tree, then compile and install with make.

For example:

$ curl -O http://www.libsdl.org/release/SDL-1.2.14.tar.gz
$ tar zxvf SDL-1.2.14.tar.gz
$ cd SDL-1.2.14
$ ./configure
$ make
$ sudo make install

Since this is done for each library it is best to automate it with a script.

Download the script (677 bytes) that’s listed below, open Terminal, change to the directory you downloaded it in and execute these commands:

$ unzip osx_sdl_setup.zip
$ ./osx_sdl_setup

You will have to enter your password at the first — sudo make install — and perhaps others depending on how long the compile takes on your machine.

#!/bin/bash
 
# create dir with assigned value if it does not exist and cd in
dir=src
if [ ! -d $dir ]; then
mkdir -m 775 $dir
fi
cd $dir
 
SDL=SDL-1.2.14
curl -O http://www.libsdl.org/release/${SDL}.tar.gz
tar zxvf ${SDL}.tar.gz
cd ${SDL}
./configure
make
sudo make install
cd ..
 
zlib=zlib-1.2.5
curl -O http://www.zlib.net/${zlib}.tar.gz
tar zxvf ${zlib}.tar.gz
cd ${zlib}
./configure
make
sudo make install
cd ..
 
libpng=libpng-1.5.4
curl -O ftp://ftp.simplesystems.org/pub/libpng/png/src/${libpng}.tar.gz
tar zxvf ${libpng}.tar.gz
cd ${libpng}
./configure
make
sudo make install
cd ..
 
SDL_image=SDL_image-1.2.10
curl -O http://www.libsdl.org/projects/SDL_image/release/${SDL_image}.tar.gz
tar zxvf ${SDL_image}.tar.gz
cd ${SDL_image}
./configure
make
sudo make install
cd ..
 
libogg=libogg-1.2.2
curl -O http://downloads.xiph.org/releases/ogg/${libogg}.tar.gz
tar zxvf ${libogg}.tar.gz
cd ${libogg}
./configure
make
sudo make install
cd ..
 
libvorbis=libvorbis-1.3.2
curl -O http://downloads.xiph.org/releases/vorbis/${libvorbis}.tar.gz
tar zxvf ${libvorbis}.tar.gz
cd ${libvorbis}
./configure
make
sudo make install
cd ..
 
SDL_mixer=SDL_mixer-1.2.11
curl -O http://www.libsdl.org/projects/SDL_mixer/release/${SDL_mixer}.tar.gz
tar zxvf ${SDL_mixer}.tar.gz
cd ${SDL_mixer}
./configure
make
sudo make install
cd ..
 
Freetype2=freetype-2.3.12
curl -O http://download-mirror.savannah.gnu.org/releases/freetype/${Freetype2}.tar.gz
tar zxvf ${Freetype2}.tar.gz
cd ${Freetype2}
./configure
make
sudo make install
cd ..
 
SDL_ttf=SDL_ttf-2.0.9
curl -O http://www.libsdl.org/projects/SDL_ttf/release/${SDL_ttf}.tar.gz
tar zxvf ${SDL_ttf}.tar.gz
cd ${SDL_ttf}
./configure
make
sudo make install
cd ..

The script above should save you some time, but it doesn’t do any error checking and the paths of these archives can change. If after completion, one or more of the libs is not installed you’ll have to troubleshoot it manually. Check the script output in Terminal and look in /usr/local.

The last thing needed for this setup are the boost C++ libraries. Once downloaded, cd to the location then execute:

$ tar zxf boost_1_47_0.tar.gz
$ cd boost_1_47_0
$ sudo mv boost /usr/local/include/

The boost libraries used here are header-only, so copying the boost folder to the include directory is all that is needed.