#!/bin/bash

# Running this script, you will get scipy installed along with hscPipe
# To use the scipy installed by this script, you have to setup it. Thus:
#   [user@example ~]$ setup scipy

set -e

. "$(dirname "$0")"/../bashrc
setup-eups
setup numpy
setup openblas

# get $product_ver from this file name: add-$product_name-$product_ver.sh
product_ver="$(basename "$0")"
product_ver="${product_ver##*-}"
product_ver="${product_ver%.*}"
product_dir=$EUPS_PATH/$(eups flavor)/scipy/$product_ver

wget https://github.com/scipy/scipy/releases/download/v$product_ver/scipy-$product_ver.tar.xz \
    -O scipy-$product_ver.tar.xz

tar xaf scipy-$product_ver.tar.xz
cd scipy-$product_ver

cat > site.cfg <<EOF
[openblas]
library_dirs = $OPENBLAS_DIR/lib
libraries = openblas
EOF

python setup.py install --install-lib=$product_dir/python

mkdir -p $product_dir/ups
cat > $product_dir/ups/scipy.table << 'EOF'
setupRequired(openblas)
setupRequired(numpy)
pathPrepend(PYTHONPATH, ${PRODUCT_DIR}/python)
EOF

eups declare -r $product_dir scipy $product_ver
