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

_realname=libslirp
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.6.1
pkgrel=1
pkgdesc="General purpose TCP-IP emulator (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://gitlab.freedesktop.org/slirp/libslirp"
license=('BSD' 'MIT')
depends=("${MINGW_PACKAGE_PREFIX}-glib2")
makedepends=("${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-meson")
source=("https://gitlab.freedesktop.org/slirp/${_realname}/-/archive/v${pkgver}/${_realname}-v${pkgver}.tar.bz2")
sha256sums=('3ee27347764c629e10228f7002dd22104e9cc21623d565dc0e7e57ed1b63a70e')

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson \
    --prefix="${MINGW_PREFIX}" \
    --buildtype=plain \
    -Ddefault_library=both \
    "../${_realname}-v${pkgver}"

  ${MINGW_PREFIX}/bin/ninja
}

package() {
  cd build-${MINGW_CHOST}
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/ninja install

  install -Dm644 "${srcdir}/${_realname}-v${pkgver}/COPYRIGHT" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYRIGHT"
}
