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

_realname=libnice
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.1.23
pkgrel=1
pkgdesc="An implementation of the IETF's draft ICE (for p2p UDP data streams) (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://libnice.freedesktop.org/"
msys2_repository_url="https://gitlab.freedesktop.org/libnice/libnice"
license=("spdx:LGPL-2.1-only OR MPL-1.1")
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-gnutls"
         #"${MINGW_PACKAGE_PREFIX}-openssl"
        )
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-gstreamer"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-ninja")
optdepends=("${MINGW_PACKAGE_PREFIX}-gstreamer: nice GStreamer plugin")
source=("https://nice.freedesktop.org/releases/${_realname}-${pkgver}.tar.gz"
        "0001-disable-unix-test.patch")
sha256sums=('618fc4e8de393b719b1641c1d8eec01826d4d39d15ade92679d221c7f5e4e70d'
            '6e03e77cfacd1b59a2f6bb1e8071becf76c7db95a94fbd3f484131160f485a39')

prepare() {
  cd "${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/0001-disable-unix-test.patch"
}

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

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  meson setup \
    --prefix="${MINGW_PREFIX}" \
    --buildtype=plain \
    -Dintrospection=enabled \
    -Dgtk_doc=enabled \
    -Dcrypto-library=gnutls \
    "../${_realname}-${pkgver}"

  meson compile
}

check() {
  cd "build-${MSYSTEM}"
  meson test || warning "Tests failed"
}

package() {
  cd "build-${MSYSTEM}"
  meson install --destdir="${pkgdir}"

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING.LGPL" \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING.LGPL"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING.MPL" \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING.MPL"
}
