# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=mpdecimal
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.5.0
pkgrel=2
pkgdesc="Package for correctly-rounded arbitrary precision decimal floating point arithmetic (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://www.bytereef.org/mpdecimal/index.html"'
license=('custom')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
checkdepends=("wget")
source=("http://www.bytereef.org/software/${_realname}/releases/${_realname}-$pkgver.tar.gz"
        "mpdecimal-2.5.0-msys-mingw.patch")
sha256sums=('15417edc8e12a57d1d9d75fa7e3f22b158a3b98f44db9d694cfd2acde8dfa0ca'
            'b8e451931843d55e7ed51efcde183649ab29bc2ba177a6e709b22c05e3a72fde')

prepare() {
  cd $srcdir/${_realname}-${pkgver}
  patch -Nbp1 -i ${srcdir}/mpdecimal-2.5.0-msys-mingw.patch
  sed -i -e '/FLAGS_SHARED\s*=/ s/ -fPIC//' libmpdec{,++}/Makefile.in
  autoreconf -fiv
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  cp -R "$srcdir/${_realname}-${pkgver}" "${srcdir}"/build-${CARCH}
  cd "${srcdir}"/build-${CARCH}
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}

  make
}

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

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