# Maintainer: Marcelo Duarte https://github.com/marcelotduarte

_realname=cx-logging
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=3.2.1
pkgrel=2
pkgdesc="Python and C interfaces for logging (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'purl: pkg:pypi/cx-logging'
)
license=('spdx:BSD-3-Clause')
url="https://github.com/anthony-tuininga/cx_Logging"
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname/-/_}/${_realname/-/_}-${pkgver}.tar.gz"
        0001-setup-remove-compiler-option.patch)
sha256sums=('812665ae5012680a6fe47095c3772bce638e47cf05b2c3483db3bdbe6b06da44'
            'efd048e8cfee16056fd783e94f33d70281ae0b335713d6c1ba50c9941b61b6c6')

prepare() {
  cd "${srcdir}/${_realname/-/_}-${pkgver}"

  # For clang
  if [[ ${MINGW_PACKAGE_PREFIX} == *-clang-* ]]; then
    patch -p1 -i "${srcdir}/0001-setup-remove-compiler-option.patch"
  fi
}

build() {
  cp -r "${_realname/-/_}-${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

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