# Maintainer: Rosen Penev <rosenp@gmail.com>

_realname=libirecovery
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.0.0
pkgrel=3
pkgdesc='The libirecovery library allows communication with iBoot/iBSS of iOS devices via USB (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://www.libimobiledevice.org/'
license=('GPL2+')
options=('staticlibs')
source=(https://github.com/libimobiledevice/${_realname}/releases/download/${pkgver}/${_realname}-${pkgver}.tar.bz2
        010-clang.patch
        020-Iphlpapi.patch)
depends=("${MINGW_PACKAGE_PREFIX}-libusbmuxd")
sha256sums=('cda0aba10a5b6fc2e1d83946b009e3e64d0be36912a986e35ad6d34b504ad9b4'
            '63b1e59ca64fd03360d033059063c84fbf3b960d6da75df48d810caab17db39b'
            '2e9a2f53147746dfee62735aed94c725eb3a64fa348b05e8d11806f83575e274')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/010-clang.patch"
  patch -Np1 -i "${srcdir}/020-Iphlpapi.patch"

  autoreconf -fi
}

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}"
}
