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

_realname=distorm
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.5
pkgrel=2
pkgdesc="Powerful disassembler library for x86/AMD64 (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/gdabah/distorm"
license=('GPL3')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-python"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
optdepends=("${MINGW_PACKAGE_PREFIX}-python")
options=('strip' 'staticlibs')
source=(${_realname}-${pkgver}.tar.gz::https://github.com/gdabah/distorm/archive/v${pkgver}.tar.gz
        Makefile)
sha256sums=('fd9169871424965b159c9b273adaaa49650d7941776286a0e38ee340e6e1e06d'
            'ab6b1147ae861a256f8ee597cfc420acce8d4369a2ef83915afb48a83593ea02')

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

build() {
  cd ${srcdir}/${_realname}-${pkgver}
  make -C make/win32
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd ${srcdir}/${_realname}-${pkgver}

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

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX#\/} --root="${pkgdir}" --skip-build -O1

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