# Maintainer: Ray Donnelly <mingw.android@gmail.com>

_realname=libusbmuxd
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.0.2
pkgrel=1
pkgdesc='A client library to multiplex connections from and to iOS devices (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://www.libimobiledevice.org/'
license=('GPL2+')
options=('staticlibs')
source=(${_realname}-${pkgver}.tar.gz::"https://github.com/libimobiledevice/libusbmuxd/archive/${pkgver}.tar.gz"
        001-2.0.2-Fix-windows-build.patch)
depends=("${MINGW_PACKAGE_PREFIX}-libplist")
sha256sums=('8ae3e1d9340177f8f3a785be276435869363de79f491d05d8a84a59efc8a8fdc'
            '4728b4b1341febdf5b84f1743e98d6cf1c90ddb5cafc2db403b6513e2f1be4bf')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-2.0.2-Fix-windows-build.patch

  NOCONFIGURE=1 ./autogen.sh
}

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

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

  make
}

check() {
  cd "${srcdir}"/build-${CARCH}
  make check
}

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