# Maintainer: Maksim Bondarenkov <maksapple2306@gmail.com>

_realname=nicotine+
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.3.10
pkgrel=2
pkgdesc="Graphical client for the Soulseek peer-to-peer network (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://nicotine-plus.org'
msys2_repository_url='https://github.com/Nicotine-Plus/nicotine-plus'
license=('spdx:GPL-3.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-gobject"
         "${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-gtk4"
         "${MINGW_PACKAGE_PREFIX}-gobject-introspection-runtime"
         "${MINGW_PACKAGE_PREFIX}-pango"
         "${MINGW_PACKAGE_PREFIX}-gettext-runtime")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-cx-freeze"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-gettext-tools")
options=('!strip')
source=("${msys2_repository_url}/archive/${pkgver}/${_realname}-${pkgver}.tar.gz"
        "pyscript2exe.py")
sha256sums=('3917ebc562f2d6a6b26b3d815d7cbdf1d11c058d994b1f47794bbb850489b35e'
            '3c65bc3dd7337877e14b19bc7c42918bde664a11a860cfc0b9db891f8a1052db')
noextract=("${_realname}-${pkgver}.tar.gz")

prepare() {
  tar -xf "${_realname}-${pkgver}.tar.gz" || true
}

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

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

package() {
  cd "python-build-${MSYSTEM}"

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

  python "${srcdir}/pyscript2exe.py" "${pkgdir}${MINGW_PREFIX}/bin/nicotine"

  install -Dm644 COPYING "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
