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

_realname=quantlib
_srcname=QuantLib
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.20
pkgrel=1
pkgdesc="QuantLib - A free/open-source library for quantitative finance (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://www.quantlib.org/"
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-boost")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
options=('staticlibs' 'strip')
source=("${_realname}-${pkgver}.tar.gz"::"https://dl.bintray.com/quantlib/releases/${_srcname}-${pkgver}.tar.gz"
        "no-undefined.patch")
sha256sums=('af51fe73b88be67536aca68ce8aaa30f523a95cc369652a6071d66beef8708ff'
            'e391fb490928fdf761c7dbb2ca4631d1ccbb092045de50b89fe37a1c5b9787e5')

prepare() {
  cd "${srcdir}/${_srcname}-${pkgver}"
  patch -p1 -i "${srcdir}/no-undefined.patch"

  ./autogen.sh
}

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

  ../${_srcname}-${pkgver}/configure \
    --disable-dependency-tracking \
    --enable-static \
    --enable-shared \
    --enable-intraday \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST}
  make
}

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