# Maintainer: Marcin Sielski <marcin.sielski@motorolasolutions.com>

_realname=usrsctp
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.9.5.0
pkgrel=2
pkgdesc="A portable SCTP userland stack (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/sctplab/usrsctp'
msys2_references=(
  'aur: libusrsctp'
  "cpe: cpe:/a:usrsctp_project:usrsctp"
)
license=('spdx:BSD-3-Clause')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("https://github.com/sctplab/${_realname}/archive/${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('260107caf318650a57a8caa593550e39bca6943e93f970c80d6c17e59d62cd92')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
}

build() {
  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-Dsctp_debug=true")
  else
    extra_config+=("")
  fi

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

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  meson \
    --prefix="${MINGW_PREFIX}" \
    "${extra_config[@]}" \
    "../${_realname}-${pkgver}"
  meson compile
}

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

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE.md" \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.md"
}
