# Maintainer: Martell Malone <martellmalone@gmail.com>

_realname=onig
_fullname=oniguruma
pkgbase=mingw-w64-${_fullname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_fullname}"
pkgver=6.9.10
pkgrel=1
pkgdesc="A regular expressions library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
license=('spdx:BSD-2-Clause')
url="https://github.com/kkos/oniguruma"
msys2_references=(
  "cpe: cpe:/a:oniguruma_project:oniguruma"
)
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://github.com/kkos/${_fullname}/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        0001-onig-config-win-paths.patch)
sha256sums=('2a5cfc5ae259e4e97f86b68dfffc152cdaffe94e2060b770cb827238d769fc05'
            '0163df619698fc1a25733db63538a2e65bdfdc5b19383f1d8bca50d5bbfff0f1')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver%.1}"
  patch -p1 -i "${srcdir}/0001-onig-config-win-paths.patch"

  autoreconf -fiv
}

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

  ../${_realname}-${pkgver%.1}/configure \
      --prefix=${MINGW_PREFIX} \
      --build=${MINGW_CHOST} \
      --host=${MINGW_CHOST} \
      --target=${MINGW_CHOST} \
      --enable-shared \
      --enable-static \
      --enable-posix-api

  make
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"
  make check || true
}

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

  rm -fv "${pkgdir}${MINGW_PREFIX}/lib/libonig.def"

  install -vDm644 "${srcdir}/${_realname}-${pkgver%.1}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
