#!/usr/bin/env bash

if [ -z "$SAGE_LOCAL" ]; then
    echo >&2 "SAGE_LOCAL undefined ... exiting"
    echo >&2 "Maybe run 'sage --sh'?"
    exit 1
fi

cd src

export CXXFLAGS="-fomit-frame-pointer -O3 -Wno-sign-compare -Wno-write-strings -I$SAGE_LOCAL/include $CXXFLAGS"

./configure \
    --libdir="$SAGE_LOCAL/lib" \
    --prefix="$SAGE_LOCAL"
if [ $? -ne 0 ]; then
    echo "Error configuring Quadratic Sieve"
    exit 1
fi

$MAKE
if [ $? -ne 0 ]; then
    echo "Error building Quadratic Sieve"
    exit 1
fi

$MAKE install
if [ $? -ne 0 ]; then
    echo "Error copying QuadraticSieve file"
    exit 1
fi
