#!/usr/bin/env bash

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

cd src

# Apply patch so that Sage reals and integers do not conflict
for patch in ../patches/*.patch; do
   patch -p1 <"$patch"
   if [ $? -ne 0 ]; then
       echo "Error applying '$patch'."
       exit 1
   fi
done

python setup.py build
if [ $? -ne 0 ]; then
   echo "Error building Brian."
   exit 1
fi

python setup.py install
if [ $? -ne 0 ]; then
   echo "Error installing Brian."
   exit 1
fi
