# Maintainer: Ray Donnelly <mingw.android@gmail.com>

_realname=cvxopt
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=1.2.6
pkgrel=1
pkgdesc="Convex optimization based on the Python programming language (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url='https://cvxopt.org/'
license=('GPL v3')
validpgpkeys=('gpg_KEY')
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-openblas"
         "${MINGW_PACKAGE_PREFIX}-suitesparse"
         "${MINGW_PACKAGE_PREFIX}-gsl"
         "${MINGW_PACKAGE_PREFIX}-fftw"
         "${MINGW_PACKAGE_PREFIX}-dsdp"
         "${MINGW_PACKAGE_PREFIX}-glpk")
options=('staticlibs' 'strip' '!debug')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('a4c433706fd0ad9d47e7f222773a7f7601766fb8e74b633524b3c3fce29aa73e')

prepare() {
  cd "${srcdir}"
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
}

build() {
  cd "${srcdir}/python-build-${CARCH}"

  CVXOPT_BLAS_LIB='openblas'                          \
  CVXOPT_LAPACK_LIB='openblas'                        \
  CVXOPT_BUILD_GSL=1                                  \
  CVXOPT_BUILD_FFTW=1                                 \
  CVXOPT_BUILD_DSDP=1                                 \
  CVXOPT_BUILD_GLPK=1                                 \
  CVXOPT_GSL_LIB_DIR=${MINGW_PREFIX}/lib              \
  CVXOPT_GSL_INC_DIR=${MINGW_PREFIX}/include          \
  CVXOPT_FFTW_LIB_DIR=${MINGW_PREFIX}/lib             \
  CVXOPT_FFTW_INC_DIR=${MINGW_PREFIX}/include         \
  CVXOPT_GLPK_LIB_DIR=${MINGW_PREFIX}/lib             \
  CVXOPT_GLPK_INC_DIR=${MINGW_PREFIX}/include         \
  CVXOPT_DSDP_LIB_DIR=${MINGW_PREFIX}/lib             \
  CVXOPT_DSDP_INC_DIR=${MINGW_PREFIX}/include/dsdp    \
  CVXOPT_SUITESPARSE_LIB_DIR=${MINGW_PREFIX}/lib      \
  CVXOPT_SUITESPARSE_INC_DIR=${MINGW_PREFIX}/include  \
    ${MINGW_PREFIX}/bin/python3 setup.py build
}

check() {
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py check
}

package() {
  cd "${srcdir}/python-build-${CARCH}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/COPYING"
}
