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

_realname=usrsctp
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.9.5.0
pkgrel=1
pkgdesc="A portable SCTP userland stack (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://github.com/sctplab/usrsctp'
license=('BSD3')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja")
depends=()
options=('strip' 'staticlibs')
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/sctplab/${_realname}/archive/${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

  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

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

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

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