# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.su>

_realname=luv
_pkgname=lib${_realname}
pkgbase=mingw-w64-${_pkgname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_pkgname}"
_pkgver=1.50.0-1
pkgver=${_pkgver/-/_}
pkgrel=1
pkgdesc='Bare libuv bindings for lua (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/luvit/luv'
license=('spdx:Apache-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-luajit"
         "${MINGW_PACKAGE_PREFIX}-libuv")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://github.com/luvit/luv/releases/download/${_pkgver}/luv-${_pkgver}.tar.gz")
sha256sums=('d867c3024d9c981d54f2edd83e13fd6dc1158f0608635f7b1c0f6b5586b5bc34')

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

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_SHARED_LIBS=ON \
    -DBUILD_MODULE=OFF \
    -DWITH_SHARED_LIBUV=ON \
    -DLUA_BUILD_TYPE=System \
    ../${_realname}-${_pkgver}

  ${MINGW_PREFIX}/bin/cmake --build ./
}

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

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install ./

  install -Dm644 "${srcdir}/${_realname}-${_pkgver}/LICENSE.txt" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_pkgname}/LICENSE.txt"
}
