#!/bin/bash

INSTALLDIR=$HOME/llvm

CFLAGS="-isysroot /Developer/SDKs/MacOSX10.6.sdk -arch x86_64"
CCFLAGS="-isysroot /Developer/SDKs/MacOSX10.6.sdk -arch x86_64"
CXXFLAGS="-isysroot /Developer/SDKs/MacOSX10.6.sdk -arch x86_64"
CPPFLAGS="-isysroot /Developer/SDKs/MacOSX10.6.sdk -arch x86_64"
LDFLAGS="-arch x86_64"

EXTRALANGS=,objc,obj-c++
# To try...
#TARGETOPTIONS='--with-arch=core2 --with-tune=generic'
# What llvm.org says to put...
TARGETOPTIONS='--with-arch=nocona --with-tune=generic'
TRIPLE=x86_64-apple-darwin10

MAKEJOBS=1

pushd llvm-gcc-4.2
svn update
popd

mkdir -p obj-llvm-gcc
pushd obj-llvm-gcc

## Stop on first error
../llvm-gcc-4.2/configure --with-gxx-include-dir=/usr/include/c++/4.2.1 \
                          --build=$TRIPLE --host=$TRIPLE --target=$TRIPLE \
                          --prefix=$INSTALLDIR --program-prefix=llvm- \
                          --enable-llvm=$INSTALLDIR \
                          --enable-languages=c,c++$EXTRALANGS \
                          $TARGETOPTIONS &&
#                          --with-libintl-dir=/opt/local \
#                          --enable-libssp \
make -j$MAKEJOBS &&
make install -j$MAKEJOBS &&
ln -sf /usr/lib/libstdc++.6.dylib $INSTALLDIR/lib &&
ln -sf /usr/lib/libstdc++.6.dylib $INSTALLDIR/lib/libstdc++.dylib
ret=$?

popd
exit $ret

