# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=distorm
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.5.2
pkgrel=6
pkgdesc="Powerful disassembler library for x86/AMD64 (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/gdabah/distorm"
msys2_references=(
  'purl: pkg:pypi/distorm3'
)
license=('spdx:BSD-3-Clause')
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-cc")
optdepends=("${MINGW_PACKAGE_PREFIX}-python")
source=(https://github.com/gdabah/distorm/archive/${pkgver}/${_realname}-${pkgver}.tar.gz
        Makefile)
sha256sums=('ef858f430d16156dea2edc910750cabf2a21154b24cfa7edf714a8ea8799f1d9'
            '35ef18fd815abe1b03b7b264ae517cd8d1564665cb5a34604b0b624ac820a4c4')

prepare() {
  cd ${_realname}-${pkgver}
  cp -f "${srcdir}"/Makefile make/win32/
}

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  make -C make/win32
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

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

  make -C make/win32 DESTDIR="${pkgdir}" INSTALL_PREFIX=${MINGW_PREFIX} install

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

  install -Dm 644 include/*.h -t "${pkgdir}${MINGW_PREFIX}/include"
  install -Dm 644 COPYING "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
