# Maintainer: Marcelo Duarte https://github.com/marcelotduarte
# Maintainer: Frode Solheim <frode@fs-uae.net>
# Contributor: Duong Pham <dthpham@gmail.com>
# Contributor: Lara Maia <dev@lara.click>

_realname=cx-freeze
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-cx_Freeze"
          "${MINGW_PACKAGE_PREFIX}-python-cx_Freeze")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-cx_Freeze"
           "${MINGW_PACKAGE_PREFIX}-python-cx_Freeze")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-cx_Freeze"
          "${MINGW_PACKAGE_PREFIX}-python-cx_Freeze")
pkgver=6.7
pkgrel=1
pkgdesc="Creates standalone executables from Python scripts, with the same performance (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
license=('PSF')
url="https://github.com/marcelotduarte/cx_Freeze/"
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-cx-logging"
         "${MINGW_PACKAGE_PREFIX}-python-importlib-metadata")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
options=('staticlibs' 'strip' '!debug')
source=(cx_Freeze-${pkgver}.tar.gz::https://pypi.io/packages/source/c/cx_Freeze/cx_Freeze-${pkgver}.tar.gz)
sha256sums=('050f1dd133a04810bd7f38ac7ae3b290054acb2ff4f6e73f7a286266d153495d')

prepare() {
  rm -Rf python-${_realname}-${CARCH}
  cp -a cx_Freeze-${pkgver} python-${_realname}-${CARCH}
}

build() {
  echo "Building for Python"
  cd python-${_realname}-${CARCH}
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  local _mingw_prefix=$(cygpath -wm ${MINGW_PREFIX})
  cd python-${_realname}-${CARCH}
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  # fix python command in files
  for filename in "${pkgdir}${MINGW_PREFIX}/bin/cxfreeze*script.py"; do
    sed -e "s|${_mingw_prefix}/bin/||g" -i ${filename}
  done
}
