# Maintainer: Alexey Pavlov <Alexpux@gmail.com>
# Contributor: Karlson2k (Evgeny Grin) <k2k@narod.ru>

_realname=mpfr
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
_pkgver=4.1.0
_patchlevel=
pkgver=${_pkgver}
if [ -n "${_patchlevel}" ]; then
  pkgver+=.${_patchlevel}
fi
pkgrel=3
pkgdesc="Multiple-precision floating-point library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('LGPL')
options=('staticlibs')
depends=("${MINGW_PACKAGE_PREFIX}-gmp")
makedepends=("${MINGW_PACKAGE_PREFIX}-gmp")
source=(https://ftp.gnu.org/gnu/mpfr/${_realname}-${_pkgver}.tar.xz{,.sig}
        #https://www.mpfr.org/mpfr-current/${_realname}-${_pkgver}.tar.xz{,.asc}
        #mpfr-${_pkgver}-${_patchlevel}.patch
        )
sha256sums=('0c98a3f1732ff6ca4ea690552079da9c597872d30e96ec28414ee23c95558a7f'
            'SKIP')
validpgpkeys=('07F3DBBECC1A39605078094D980C197698C3739D')

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

  if [ -n "${_patchlevel}" ]; then
    patch -p1 -i ${srcdir}/${_realname}-${_pkgver}-${_patchlevel}.patch
  fi
}

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

  ../${_realname}-${_pkgver}/configure \
    --build=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --enable-static \
    --disable-shared \
    --with-gmp=${MINGW_PREFIX}

  make
}

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

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