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

_realname=hidapi
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.10.1
pkgrel=2
pkgdesc="Library for communicating with USB and Bluetooth HID devices (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/libusb/hidapi"
license=("BSD" "GPLv3")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=('staticlibs' 'strip')
source=("https://github.com/libusb/hidapi/archive/${_realname}-${pkgver}.tar.gz"
        "001-fix-autoconf.patch")
sha256sums=('f71dd8a1f46979c17ee521bc2117573872bbf040f8a4750e492271fc141f2644'
            '5fa8abba99df2b4afaf11efef807f97b32ce371374290ce590ce549f2222538f')

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

  patch -Np1 -i "${srcdir}/001-fix-autoconf.patch"

  autoreconf -vif
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}
  ../${_realname}-${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --enable-static \
    --disable-testgui
  make
}

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

  mkdir -p ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}
  install -Dm644 ${srcdir}/${_realname}-${_realname}-${pkgver}/LICENSE{-bsd,-gpl3,-orig,}.txt ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/
}
