#!/usr/bin/env bash

cd src

cd src
for patch in ../../patches/*.patch; do
    patch -p1 <"$patch"
    if [ $? -ne 0 ]; then
        echo >&2 "Error applying '$patch'"
        exit 1
    fi
done
cd ..

./configure --prefix="$SAGE_LOCAL" \
            --libdir="$SAGE_LOCAL/lib" \
            --with-lisp=ecl

if [ $? -ne 0 ]; then
    echo >&2 "Error configuring fricas."
    exit 1
fi

$MAKE
if [ $? -ne 0 ]; then
    echo >&2 "Error building fricas."
    exit 1
fi

$MAKE -j1 install
if [ $? -ne 0 ]; then
    echo >&2 "Error installing fricas."
    exit 1
fi
