die () {
    echo "$@" 1>&2
    exit 1
}

cd src

more_configure_options=

if [ `uname` = Darwin ]; then
    more_configure_options="$more_configure_options --without-fink"
fi

./configure --without-java \
            --without-javaview \
            --prefix="$SAGE_LOCAL" \
            --exec-prefix="$SAGE_LOCAL" \
            --includedir="$SAGE_LOCAL"/include \
            --bindir="$SAGE_LOCAL"/bin \
            --libdir="$SAGE_LOCAL"/lib \
            $more_configure_options || die "Error configuring Polymake"
make || die "Error building polymake"
# Remove old stuff. Polymake loads whatever it finds in
# its installation directory.
rm -Rf $SAGE_LOCAL/lib/polymake
make install || die "Error installing polymake"
# Reconfigure Polymake's rules.
# This modifies ~/.polymake/customize.pl
echo "exit;" | polymake --reconfigure - || die "Error calling 'polymake --reconfigure'"
