#!/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


# --- PyPNG ---

cd pypng
python setup.py build
if [ $? -ne 0 ]; then
    echo >&2 "Error building PyPNG."
    exit 1
fi

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

# --- Plink ---

cd ../plink
python setup.py build
if [ $? -ne 0 ]; then
    echo >&2 "Error building Plink."
    exit 1
fi

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

# --- Spherogram ---

cd ../Spherogram
python setup.py build
if [ $? -ne 0 ]; then
    echo >&2 "Error building Spherogram."
    exit 1
fi

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

# --- SnapPy ---

cd ../SnapPy
python setup.py build
if [ $? -ne 0 ]; then
    echo >&2 "Error building SnapPy."
    exit 1
fi

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