#!/usr/bin/env bash

set -e -x

#src=${GITHUB_WORKSPACE:-/src/pyscf}
src=$1
#dst=${GITHUB_WORKSPACE:-/src/pyscf}/linux-wheels
dst=$src/linux-wheels
mkdir -p /root/wheelhouse $src/linux-wheels

#if [ "$#" -gt 0 ]; then
#  export CMAKE_CONFIGURE_ARGS="-DWITH_F12=OFF -DBUILD_LIBXC=OFF -DBUILD_XCFUN=OFF -DBUILD_LIBCINT=OFF"
#  curl -L $1 | tar -C $src/pyscf/lib -xzf -
#else
#  export CMAKE_CONFIGURE_ARGS="-DWITH_F12=OFF"
#fi


# In certain versions of auditwheel, some .so files was excluded.
sed -i '/            if basename(fn) not in needed_libs:/s/basename.*libs/1/' /opt/_internal/pipx/venvs/auditwheel/lib/python3.9/site-packages/auditwheel/wheel_abi.py

# Compile wheels
#for PYVERSION in cp37-cp37m cp38-cp38 cp39-cp39 ; do
for PYVERSION in cp39-cp39 ; do
    PYBIN=/opt/python/$PYVERSION/bin
    "${PYBIN}/pip" install numpy
    F2PY=${PYBIN}/f2py "${PYBIN}/pip" wheel -v --no-deps --no-clean -w /root/wheelhouse $src

    # Bundle external shared libraries into the wheels
    whl=`ls /root/wheelhouse/mokit-*-$PYVERSION-linux*_x86_64.whl`
    auditwheel -v repair "$whl" --lib-sdir /lib -w $dst
    auditwheel -v repair "$whl" --lib-sdir /../bin -w $dst
done
