# Contributor/Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=wwrando
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.9.0
pkgrel=1
pkgdesc="Wind Waker Randomizer (mingw-w64)"
arch=('any')
url="https://github.com/LagoLunatic/wwrando"
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-pyside2-qt5" "${MINGW_PACKAGE_PREFIX}-python-yaml" "${MINGW_PACKAGE_PREFIX}-python-pillow")
makedepends=("${MINGW_PACKAGE_PREFIX}-pyside2-tools-qt5")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-tinyaes" "${MINGW_PACKAGE_PREFIX}-python-pyfastbti" "${MINGW_PACKAGE_PREFIX}-python-pyfasttextureutils")
options=('staticlibs' 'strip' '!debug')
source=("https://github.com/LagoLunatic/wwrando/archive/refs/tags/$pkgver.tar.gz")
sha256sums=('2479f340ffa581b21367e3cdbb596129b668dec122a98d23f7e0fc28fb632a85')

prepare() {
  cd "${srcdir}"

  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
}

build() {
  msg "Python build for ${CARCH}"
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python -m compileall .
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  find . -type f -exec install -Dm644 {} "${pkgdir}${MINGW_PREFIX}/lib/python3.8/site-packages/wwrando/"{} \;

  mkdir -p "${pkgdir}${MINGW_PREFIX}/bin"
  printf "#!/bin/sh\npython ${MINGW_PREFIX}/lib/python3.8/site-packages/wwrando/wwrando.py \$@\n" >> "${pkgdir}${MINGW_PREFIX}/bin/wwrando"
  chmod +x "${pkgdir}${MINGW_PREFIX}/bin/wwrando"
  install -Dm644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.txt"
}
