#!/bin/bash

set -o errexit	# Exit if any command fails
set -x		# Print commands executed

LLVM_SOURCE=$1
DRAGONEGG_SOURCE=$2
BUILD_DIR=$3

# Change the current directory to the build root. 
cd $BUILD_DIR

# Create links only if target directory or link does not exist.
if [ ! -d $BUILD_DIR/llvm ] ; then
   ln -sf $LLVM_SOURCE $BUILD_DIR/llvm
fi
if [ ! -d $BUILD_DIR/dragonegg ] ; then
   ln -sf $DRAGONEGG_SOURCE $BUILD_DIR/dragonegg
fi

export CPPFLAGS="-I/opt/cfarm/mpfr-2.4.1/include -I/opt/cfarm/gmp-4.2.4/include/ -I /opt/cfarm/mpc-0.8/include/"
export GCC_OPTIONS="--enable-languages=c,c++,fortran,objc,obj-c++ --with-mpfr=/opt/cfarm/mpfr-2.4.1 --with-gmp=/opt/cfarm/gmp-4.2.4 --with-mpc=/opt/cfarm/mpc-0.8 --with-libelf=/opt/cfarm/libelf-0.8.12"

if [ -e gcc ] ; then
	svn cleanup gcc # In case a previous run was interrupted while checking out gcc
fi
$DRAGONEGG_SOURCE/extras/do_self_strap
