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

_realname=SDL_net
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=1.2.8
pkgrel=4
pkgdesc="A small sample cross-platform networking library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://libsdl.org/projects/SDL_net"
license=('custom')
depends=("${MINGW_PACKAGE_PREFIX}-SDL")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-autotools")
source=(https://libsdl.org/projects/SDL_net/release/${_realname}-${pkgver}.tar.gz
        001-aarch64.patch)
sha256sums=('5f4a7a8bb884f793c278ac3f3713be41980c5eedccecff0260411347714facb4'
            '60048f2cc46720409b42f3b61e6544d24dca69870e059550115f04a842ab1617')

apply_patch_with_msg() {
  for _fname in "$@"
  do
    msg2 "Applying ${_fname}"
    patch -Nbp1 -i "${srcdir}"/${_fname}
  done
}

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

  apply_patch_with_msg \
    001-aarch64.patch
}

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

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --enable-static

  make
}

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

  make DESTDIR="${pkgdir}/" install
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
