#!/bin/sh

build_dir="${HOME}/tmp/build_gcc"

if test -d ${build_dir} ; then
    echo "removing ${build_dir}"
    rm -fr ${build_dir}
fi
mkdir -p ${build_dir}

pushd ${build_dir}

PREFIX="${HOME}/sw"

export CFLAGS="${CFLAGS} -m64 -fPIC -I${PREFIX}/include"
export CPPFLAGS="${CPPFLAGS} -I${PREFIX}/include"
export CXXFLAGS="${CXXFLAGS} -m64 -fPIC -I${PREFIX}/include"
export LDFLAGS="${LDFLAGS} -m64 -L${PREFIX}/lib64 -L${PREFIX}/lib"

# Most of these are copied from /usr/bin/gcc -v ;)
../gcc-trunk/configure \
    CFLAGS="${CFLAGS}" \
    CPPFLAGS="${CPPFLAGS} -I${PREFIX}/include" \
    LDFLAGS="${LDFLAGS} -m64 -L${PREFIX}/lib64 -L${PREFIX}/lib" \
    --enable-threads=posix \
    --prefix=${HOME}/sw    \
    --enable-languages=c++ \
    --enable-checking=release \
    --with-gxx-include-dir=${HOME}/sw/include/c++/gcc-vcs \
    --enable-libssp \
    --disable-libgcj \
    --disable-werror \
    --with-system-zlib \
    --enable-shared \
    --enable-__cxa_atexit \
    --enable-libstdcxx-allocator=new \
    --disable-libstdcxx-pch \
    --program-suffix=-vcs \
    --enable-version-specific-runtime-libs \
    --without-system-libunwind \
    --disable-multilib \
    --with-mpfr=${PREFIX} \
    $@

nice -n 18 make
