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

_realname=libplist
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.6.0
pkgrel=3
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}-gcc-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"
        001-ax_python_devel.patch
        002-dont-include-winmain-in-static.patch
        003-fix-py-soext.patch)
sha256sums=('67be9ee3169366589c92dc7c22809b90f51911dd9de22520c39c9a64fb047c9c'
            'cb6837f5dafff50a4a367dc6c71c86b7d40c68a9e676d8b121977a0db13bfdaf'
            'c48f22728e25a78ee70eaf20f559d3119b7c2140ccd1863005214a7c508267e5'
            '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 \
    001-ax_python_devel.patch \
    002-dont-include-winmain-in-static.patch \
    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
}
