#!/bin/bash
export PATH=/usr/lib64/ccache:/opt/rh/devtoolset-4/root/usr/bin:/opt/casa/03/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/casa/02/bin:/usr/local/sbin:/usr/local/bin
pythonversion=$1
tools_target=$2
prefix="<bc2014>"
echo "$prefix pythonversion $pythonversion"
echo "$prefix tools_target $tools_target"
echo "$prefix Setting up ccache"
export CCACHE_DIR=/ccache
ccache -M 50G
echo "$prefix Creating virtual Python environment"
python$pythonversion -m venv ~/venv
source ~/venv/bin/activate
echo "$prefix Installing dependencies"
pip install --index-url=https://pypi.org/simple --upgrade pip wheel certifi auditwheel==5.1.2 numpy==1.18.5 matplotlib==3.3.3 scipy casaconfig
echo "$prefix Building casatools"
cd /source/casa6/casatools/
echo "$prefix autoconf"
/usr/bin/autoconf
echo "$prefix configure"
./configure
echo "$prefix setup.py"
python setup.py $tools_target
if [[ "$tools_target" == "genmake" ]]; then
echo "$prefix genmake"
cd /source/casa6/casatools/
make -j4
else
echo "$prefix auditwheel"
cd /source/casa6/casatools/dist && auditwheel repair --plat manylinux2014_x86_64 `ls -t *.whl | head -1`
fi
echo "$prefix Building casatasks"
ls /source/casa6/casatools/build/lib.linux-x86_64-$pythonversion
export PYTHONPATH=/source/casa6/casatools/build/lib.linux-x86_64-$pythonversion
cd /source/casa6/casatasks/
echo "Current dir"
echo `pwd`
ls
python setup.py bdist_wheel
echo "$prefix Building casashell"
export PYTHONPATH=/source/casa6/casatools/build/lib.linux-x86_64-$pythonversion:/source/casa6/casatasks/build/lib.linux-x86_64-$pythonversion
cd /source/casashell/
python setup.py bdist_wheel
mkdir /source/extralibs
cp /usr/lib64/libgfortran.so.3 /source/extralibs
echo "$prefix Building casatestutils"
cd /source/casa6/casatestutils
python setup.py bdist_wheel
cd /source
mkdir wheels
cp casa6/casatools/dist/wheelhouse/casatools*many*.whl /source/wheels
cp casa6/casatestutils/dist/casatestutils*.whl /source/wheels
cp casa6/casatasks/dist/casatasks*.whl /source/wheels
cp casashell/dist/casashell*.whl /source/wheels
cd /source/casa6
current_branch=`git symbolic-ref --short HEAD`
echo "$prefix current Casa6 branch $current_branch"
cd /source/casa-build-utils/casalith
shortversion=`echo $pythonversion | sed 's/[^a-zA-Z0-9]//g'`
deactivate
./dockerbuildcasalith.sh -w /source/wheels -b $current_branch -c $current_branch -p $pythonversion -d python-dependencies/requirements-manylinux2014-py38.txt