# Maintainer: LIU Hao <lh_mouse@126.com>

_realname=testu01
_srcname=TestU01
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.2.3
pkgrel=1
pkgdesc="Empirical testing of random number generators (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://simul.iro.umontreal.ca/testu01/tu01.html'
msys2_repository_url='https://github.com/umontreal-simul/TestU01-2009'
license=('spdx:Apache-2.0')
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://simul.iro.umontreal.ca/testu01/${_srcname}-${pkgver}.zip"
        "0001-various-fixes.patch")
sha256sums=('bc1d1dd2aea7ed3b3d28eaad2c8ee55913f11ce67aec8fe4f643c1c0d2ed1cac'
            'ff82b40a2d2ff82bd22f7e87a4477d2c1698dc0e9d766344c77ef3914e1b64d9')

prepare() {
  cd "${_srcname}-${pkgver}"

  patch -p1 -i "${srcdir}/0001-various-fixes.patch"

  # They use Autoconf 2.61 and Automake 1.10 which are not provided by MSYS2.
  aclocal && autoupdate && autoreconf -ifv
}

build() {
  mkdir -p "build-${MSYSTEM}" && cd "build-${MSYSTEM}"

  ../"${_srcname}-${pkgver}"/configure \
    --prefix="${MINGW_PREFIX}" \
    --build="${MINGW_CHOST}" \
    --host="${MINGW_CHOST}" \
    --enable-static \
    --enable-shared

  make
}

check() {
  cd "build-${MSYSTEM}"

  make check
}

package() {
  cd "build-${MSYSTEM}"

  make install DESTDIR="${pkgdir}"

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