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

_realname=libjaylink
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}-git")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}-git")
pkgver=0.4.0
pkgrel=2
pkgdesc="Shared library written in C to access SEGGER J-Link and compatible devices (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://gitlab.zapb.de/libjaylink/libjaylink"
license=('spdx:GPL-2.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-libusb")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-autotools")
source=("https://gitlab.zapb.de/libjaylink/libjaylink/-/archive/${pkgver}/${_realname}-${pkgver}.tar.bz2"
        "010-socket.patch"
        "011-avoid-hidden-visibility.patch")
sha256sums=('492da550fe1093a9b2d958304deb386380abea13ef7ce694b2ef68bfdaec664d'
            '8b115661829842711c6060afebbf279e2c214a657c92e4a8426ee189ad0d91bd'
            '204e6082b8e55b4ee2d0b3196bf56193fca95e9e6b83ca36478a246b3de24afc')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/010-socket.patch
  patch -p1 -i "${srcdir}"/011-avoid-hidden-visibility.patch

  ./autogen.sh
}

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

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

  make
}

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

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