# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.su>

_realname=pypng
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}"
         "${MINGW_PACKAGE_PREFIX}-python-${_realname}-docs")
pkgver=0.20250521.0
pkgrel=1
pkgdesc='Pure Python library for PNG image encoding/decoding (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://gitlab.com/drj11/pypng'
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx")
options=('!strip')
source=("${url}/-/archive/${_realname}-${pkgver}/${_realname}-${_realname}-${pkgver}.tar.gz")
sha256sums=('b5195e2aaf153afaeed4b47373785da91fe2f8264b298cfedb39d98f7c7629c2')

build() {
  cp -r "${_realname}-${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  python -m build --wheel --skip-dependency-check --no-isolation

  make -C man html
}

package_python-pypng() {
  cd "python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENCE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}

package_python-pypng-docs() {
  pkgdesc+=" (documentation)"
  depends=()

  mkdir -p "${pkgdir}${MINGW_PREFIX}/share/doc/python-${_realname}"
  cp -a "${srcdir}/python-build-${MSYSTEM}/man/_build/html" "${pkgdir}${MINGW_PREFIX}/share/doc/python-${_realname}/html"
}

# template start; name=mingw-w64-splitpkg-wrappers; version=1.0;
# vim: set ft=bash :

# generate wrappers
for _name in "${pkgname[@]}"; do
  _short="package_${_name#${MINGW_PACKAGE_PREFIX}-}"
  _func="$(declare -f "${_short}")"
  eval "${_func/#${_short}/package_${_name}}"
done
# template end;
