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

_realname=libplist
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.7.0
pkgrel=2
pkgdesc='A library to handle Apple Property List format in binary or XML (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://www.libimobiledevice.org/'
msys2_repository_url="https://github.com/libimobiledevice/libplist"
msys2_references=(
  "cpe: cpe:/a:libimobiledevice:libplist"
  "cpe: cpe:2.3:a:libplist_project:libplist"
)
license=('spdx:GPL-2.0-or-later AND spdx:LGPL-2.1-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cython")
optdepends=("${MINGW_PACKAGE_PREFIX}-python: Python bindings")
source=("https://github.com/libimobiledevice/libplist/releases/download/${pkgver}/libplist-${pkgver}.tar.bz2"
        003-fix-py-soext.patch)
sha256sums=('7ac42301e896b1ebe3c654634780c82baa7cb70df8554e683ff89f7c2643eb8b'
            'c9190d4697bc3d97fa20b66a54f2b9f8fe2527560376e2dae8d168e79cbd272c')

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Np1 -i "${srcdir}/$_patch"
  done
}

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

  apply_patch_with_msg \
    003-fix-py-soext.patch

  autoreconf -fiv
}

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

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

  make
}

check() {
  cd "${srcdir}"/build-${MSYSTEM}
  # || true because of FAIL: bigarraycmp .. File does not exists
  make check || true
}

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

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