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

_realname=libmowgli
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.1.3
pkgrel=6
pkgdesc="Performance and usability-oriented extensions to C (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/atheme/libmowgli-2"
license=('spdx:ISC')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs" "${MINGW_PACKAGE_PREFIX}-openssl")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-autotools")
source=(https://github.com/atheme/${_realname}-2/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz
        libmowgli-mingw-fix.patch)
sha256sums=('b7faab2fb9f46366a52b51443054a2ed4ecdd04774c65754bf807c5e9bdda477'
            '2a73bcc8df44197e95ad7add3b2845a21c033819bff361f5d8ce33e6561bba3f')

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

  # inet_pton & inet_ntop are already defined in ws2tcpip.h
  patch -p1 -i "${srcdir}"/libmowgli-mingw-fix.patch
}

build() {
  cp -rf ${_realname}-2-${pkgver} build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  CFLAGS+=" -Wno-incompatible-function-pointer-types -Wno-incompatible-pointer-types" \
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-shared \
    --enable-static \
    --with-openssl

  make
}

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

  install -Dm644 COPYING "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
