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

pkgname=('mpfr' 'mpfr-devel')
_pkgver=4.1.0
_patchlevel=
pkgver=${_pkgver}
if [ -n "${_patchlevel}" ]; then
  pkgver+=.${_patchlevel}
fi
#pkgver=${_pkgver}
pkgrel=1
pkgdesc="Multiple-precision floating-point library"
arch=('i686' 'x86_64')
url="https://www.mpfr.org/"
license=('LGPL')
depends=('gmp>=5.0')
makedepends=('gmp-devel>=5.0')
source=(https://www.mpfr.org/mpfr-current/mpfr-${_pkgver}.tar.xz{,.asc}
        mpfr-4.1.0-msysize.patch
        mpfr-4.0.0-add-ax_thread_m4.patch)
validpgpkeys=('07F3DBBECC1A39605078094D980C197698C3739D')
sha256sums=('0c98a3f1732ff6ca4ea690552079da9c597872d30e96ec28414ee23c95558a7f'
            'SKIP'
            'f2ebf0816cbeef0d1ee3fbbf524850fdcf87cded148856ba5b2f5968c6224329'
            '20e1297e222e8736ff06d7ea671abf528437f8ccf4648bb1838d2ff620c0842d')

prepare() {
  cd "${srcdir}/${pkgname}-${_pkgver}"
  patch -p1 -i ${srcdir}/mpfr-4.1.0-msysize.patch
  patch -p1 -i ${srcdir}/mpfr-4.0.0-add-ax_thread_m4.patch

  autoreconf -fi
}

build() {
  cd "${srcdir}/${pkgname}-${_pkgver}"
  ./configure --build=${CHOST} \
    --prefix=/usr \
    --enable-shared \
    --disable-static
  make
  make DESTDIR="${srcdir}/dest" install
}

check() {
  cd "${srcdir}/${pkgname}-${_pkgver}"
  make check
}

package_mpfr() {
  groups=('libraries')
  install=mpfr.install

  mkdir -p ${pkgdir}/usr

  cp -rf ${srcdir}/dest/usr/bin ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/share ${pkgdir}/usr/
}

package_mpfr-devel() {
  groups=('development')
  options=('staticlibs')
  depends=("mpfr=${pkgver}" 'gmp-devel')
  pkgdesc="MPFR headers and libraries"

  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
}
