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

_realname=libimobiledevice
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.3.0
pkgrel=2
pkgdesc='A cross-platform protocol library to communicate with 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/libimobiledevice/archive/${pkgver}.tar.gz"
        001-1.3.0-Fix-windows-build.patch
        002-1.3.0-Link-Iphlpapi.patch
        003-1.3.0-PyString_AsString-now-PyBytes_AsString.patch
        004-clang.patch::https://github.com/libimobiledevice/libimobiledevice/commit/19f9a4c37122779ad23df4180da37cbaca1e520a.patch)
depends=("${MINGW_PACKAGE_PREFIX}-libusbmuxd"
         "${MINGW_PACKAGE_PREFIX}-libplist"
         "${MINGW_PACKAGE_PREFIX}-openssl")
makedepends=("${MINGW_PACKAGE_PREFIX}-cython")
sha256sums=('acbfb73eabee162e64c0d9de207d71c0a5f47c40cd5ad32a5097f734328ce10a'
            'c72055c417d6fd10106793fd193c64e0147240f584c9025561cb9cd28bee112d'
            '693d2df13fd344ef67e41c7a769c12843a60a7d89a825e118a40914ed407a4fb'
            '438469e5bfce0eca723ec597ae8e97cbaca22ee548559f2d65e1fd63aba46b4b'
            '09bdc054b1330293795c1b0459f34711a5aa84a4874a170c4b428b3796e9e9c8')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  # https://github.com/libimobiledevice/libimobiledevice/commit/52371bccdcb1b0fe98930e79ac2ab9bdad2700e2
  patch -p1 -i ${srcdir}/001-1.3.0-Fix-windows-build.patch
  patch -p1 -i ${srcdir}/002-1.3.0-Link-Iphlpapi.patch
  # https://github.com/libimobiledevice/libimobiledevice/commit/7044571b4f243d2fda4dd3aa491f2f279787ee19
  patch -p1 -i ${srcdir}/003-1.3.0-PyString_AsString-now-PyBytes_AsString.patch
  patch -p1 -i ${srcdir}/004-clang.patch

  NOCONFIGURE=1 ./autogen.sh
}

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

  PYTHON=${MINGW_PREFIX}/bin/python \
  ../${_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}"

  rm -f ${pkgdir}${MINGW_PREFIX}/lib/python*/site-packages/*.a
}
