# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=ensmallen
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.22.2
pkgrel=1
pkgdesc='flexible C++ library for efficient mathematical optimization (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://www.ensmallen.org/'
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-armadillo"
         "${MINGW_PACKAGE_PREFIX}-openblas")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-doxygen")
source=("https://www.ensmallen.org/files/ensmallen-${pkgver}.tar.gz")
sha256sums=('da9ce4bdd07f2c8d950e3797456da3152dfa5d1b0f5987a489fbe224f52e7e4f')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  # Tests seek for hdf5 but failed even if avaiable

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe -Wno-dev \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_TESTS=OFF \
    ../${_realname}-${pkgver}

  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install

  pushd "${pkgdir}${MINGW_PREFIX}" > /dev/null
    install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE.txt" "share/licenses/${_realname}/LICENSE.txt"
  popd > /dev/null
}
