#!bin/bash

# You must copy your iPhone directory to /usr/local/share/iphone-filesystem
# before using this script!
#
# usage: sudo script1.sh
#
# Post to http://kevinchiu.org/blog/archives/iphone-toolchain-030-install-script 
# if there are any problems.

svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm-svn -r 42498
pushd llvm-svn
./configure --enable-optimized
make ENABLE_OPTIMIZED=1
sudo make install
LLVMOBJDIR=`pwd`
popd

svn checkout http://iphone-dev.googlecode.com/svn/trunk/ iphone-dev
pushd iphone-dev

sudo mkdir /usr/local/arm-apple-darwin

mkdir -p build/odcctools
pushd build/odcctools
../../odcctools/configure --target=arm-apple-darwin --disable-ld64
make
sudo make install
popd

HEAVENLY=/usr/local/share/iphone-filesystem

pushd include
./configure --with-macosx-sdk=/Developer/SDKs/MacOSX10.4u.sdk
sudo bash install-headers.sh
popd

mkdir -p build/csu
pushd build/csu
../../csu/configure --host=arm-apple-darwin
sudo make install
popd

mkdir -p build/llvm-gcc-4.0-iphone
pushd build/llvm-gcc-4.0-iphone
../../llvm-gcc-4.0-iphone/configure --enable-llvm=`llvm-config --obj-root` --enable-languages=c,c++,objc,obj-c++ --target=arm-apple-darwin --enable-sjlj-exceptions --with-heavenly=$HEAVENLY --with-as=/usr/local/bin/arm-apple-darwin-as --with-ld=/usr/local/bin/arm-apple-darwin-ld
make LLVM_VERSION_INFO=2.0-svn-iphone-dev-0.3-svn 
sudo make install
popd
popd
