# Prerequisites: Developer tools INCLUDING the 10.5 SDK, an Intel mac.
# This will get you a i386 (32 bit) plugin.
mkdir /tmp/xap-parts

# Grab the X-Plane SDK and install it into /opt/x-plane
mkdir -p /opt/x-plane
cd /opt/x-plane
curl -O http://www.xsquawkbox.net/xpsdk/XPSDK200.zip
unzip XPSDK200.zip

# 1. Grab, build and install lua (from source!)
mkdir -p /tmp/xap-parts
cd /tmp/xap-parts
curl http://www.lua.org/ftp/lua-5.1.4.tar.gz | tar xfz -; cd lua-5.1.4
# Alter the macosx build target for lua so that it gives you 10.4 compatible libraries
# The line is in the src/Makefile for lua under macosx. Here is the explanation of what we need
# http://lua-users.org/lists/lua-l/2008-08/msg00553.html
cd src
make macosx CFLAGS="-DLUA_USE_POSIX -mmacosx-version-min=10.4 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc -universal" 
cd ../; sudo make install

# 2. Grab, build and install SDL (from source, not the framework version since we will be making a Mach-O dylib!)
cd /tmp/xap-parts
curl http://www.libsdl.org/release/SDL-1.2.14.tar.gz | tar xfz -
cd SDL-1.2.14
./configure CFLAGS="-mmacosx-version-min=10.4 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc" 

# 3. Install and build SOIL (from source)
cd /tmp/xap-parts
curl -O http://www.lonesock.net/files/soil.zip
unzip soil.zip
cd "Simple OpenGL Image Library/projects/makefile" # Obnoxious spaces in dirname
mkdir obj # The author has forgotten
# Now the same for SOIL - build for 10.4 and universal
make CXXFLAGS="-mmacosx-version-min=10.4 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc" && make install

# Now build libavionics, Slava and xap
cd libavionics; make -f Makefile.mac
cd ../slava; make -f Makefile.mac
cd ../xap; make -f Makefile.mac
