# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

# Note: This the last version that could be built on Windows
#       Newer version (>=3) requires some posix functions that are available on MinGW-w64.
#       see: https://feynarts.de/cuba

_realname=cuba
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.1
pkgrel=2
pkgdesc="A library for multidimensional numerical integration (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64')
url='https://feynarts.de/cuba'
license=('spdx:LGPL-3.0-or-later')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-fc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
source=("https://feynarts.de/cuba/Cuba-${pkgver}.tar.gz")
sha256sums=('4fc97551b519c3ea5f7ad9050c7355e049c3106f31a8cb82112828545977ab59')

prepare() {
  cd "Cuba-${pkgver}"

  autoreconf -fiv
}

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

  CFLAGS+=" -std=c17" \
  ../"Cuba-${pkgver}"/configure \
    --prefix="${MINGW_PREFIX}"

  make -j1
}

package() {
  cd "build-${MSYSTEM}"

  make -j1 install DESTDIR="${pkgdir}"

  install -Dm644 "${srcdir}"/Cuba-${pkgver}/COPYING \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
