# Maintainer: Rafal Brzegowy <rafal.brzegowy@yahoo.com>

_realname=moab
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=5.2.1
pkgrel=4
pkgdesc='The Mesh-Oriented datABase MOAB is a component for representing and evaluating mesh data (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
depends=("${MINGW_PACKAGE_PREFIX}-msmpi")
makedepends=("${MINGW_PACKAGE_PREFIX}-openblas"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cmake")
license=('LGPL 2.1')
url='https://sigma.mcs.anl.gov/moab-library/'
source=(https://ftp.mcs.anl.gov/pub/fathom/${_realname}-${pkgver}.tar.gz
        0000-fix.patch)
sha256sums=('60D31762BE3F0E5C89416C764E844EC88DAC294169B59A5EAD3C316B50F85C29'
            '25179DEA14CB54F292C12FB7D9705AFDE018A38459A0E658920FE1945ECBC59F')

prepare() {  
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i ${srcdir}/0000-fix.patch
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -DCMAKE_BUILD_TYPE=Release \
      -DBUILD_SHARED_LIBS=OFF \
      -DENABLE_MPI=ON \
      -DENABLE_TESTING=ON \
      ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  DESTDIR=${pkgdir} cmake --build . --target install
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/LICENSE ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
