# Maintainer: Alexey Pavlov <Alexpux@gmail.com>
# Contributor: Paul Moore <p.f.moore@gmail.com>

_realname=bc
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.08.2
pkgrel=1
pkgdesc='bc is an arbitrary precision numeric processing language (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://www.gnu.org/software/bc/'
msys2_references=(
  "cpe: cpe:2.3:a:gnu:bc"
)
license=('GPL3')
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc" "ed")
depends=("${MINGW_PACKAGE_PREFIX}-readline")
source=("https://mirrors.kernel.org/gnu/${_realname}/${_realname}-${pkgver}.tar.gz"
        "0001-use-rand-on-windows.patch"
        "0003-use-binary-io.patch"
        "0004-use-srand-on-windows.patch")
sha256sums=('ae470fec429775653e042015edc928d07c8c3b2fc59765172a330d3d87785f86'
            'd0203c9cbe9764ddb4ef50f5c2bda6f0b0483d01d2c5e8722be5826c28300f71'
            '1c796bb531b1d516e0170d4bd88ff8c6869d41132736eab27da4fcc9e6fdfad2'
            '353a15cd2ce2bf4e9c5c37af7cc0d2222e56d05347fd534baa2d2f9073cfe0cd')

prepare() {
  cd $srcdir/${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/0001-use-rand-on-windows.patch
  patch -p1 -i "${srcdir}"/0003-use-binary-io.patch
  patch -p1 -i "${srcdir}"/0004-use-srand-on-windows.patch
  autoreconf -fiv
}

build() {
  cd $srcdir/${_realname}-${pkgver}
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --with-readline

  make
}

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

  # Licenses
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/README" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/README"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
