# Maintainer: gym603 <gui_yuan_miao@163.com>

_realname=protobuf
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=3.16.0
pkgrel=1
pkgdesc="Protocol Buffers (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/protocolbuffers/protobuf"
license=('3-Clause BSD License')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-six"
         "${MINGW_PACKAGE_PREFIX}-python-setuptools")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-protobuf=${pkgver}")
_archive=${_realname/_/-}-${pkgver}
source=(${_archive}.tar.gz::https://github.com/protocolbuffers/protobuf/archive/v${pkgver}.tar.gz)
sha256sums=('7892a35d979304a404400a101c46ce90e85ec9e2a766a86041bb361f626247f5')
noextract=(${_archive}.tar.gz)

prepare() {
  bsdtar -xf ${_archive}.tar.gz || true
}

build() {
  cd "${srcdir}/${_archive}/python"
  ${MINGW_PREFIX}/bin/python setup.py --quiet build
}

package() {
  cd "${srcdir}/${_archive}/python"

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

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