# Maintainer: Lubosz Sarnecki <lubosz@gmail.com>

_realname=gst-python
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-gst-python")
pkgver=1.18.4
pkgrel=1
pkgdesc="GStreamer GObject Introspection overrides for Python (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
license=('LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-gstreamer"
         "${MINGW_PACKAGE_PREFIX}-gst-plugins-base"
         "${MINGW_PACKAGE_PREFIX}-python-gobject")
makedepends=("${MINGW_PACKAGE_PREFIX}-python"
             "${MINGW_PACKAGE_PREFIX}-pygobject-devel"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja")
url='https://gstreamer.freedesktop.org/modules/gst-python.html'
source=(https://gstreamer.freedesktop.org/src/gst-python/${_realname}-${pkgver}.tar.xz)
sha256sums=('cb68e08a7e825e08b83a12a22dcd6e4f1b328a7b02a7ac84f42f68f4ddc7098e')

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

}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson.exe \
    --prefix="${MINGW_PREFIX}" \
    --buildtype plain \
    --wrap-mode=nofallback \
    -Dauto_features=enabled \
    -Dpython=${MINGW_PREFIX}/bin/python.exe \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/ninja.exe
}

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

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/ninja.exe install

  # The python plugin loader makes problems because it links against libpython
  # which might be in conflict one already used loading the plugin.
  # The overrides don't need it so just remove it for now.
  # https://github.com/Alexpux/MINGW-packages/issues/2034
  rm -r "${pkgdir}${MINGW_PREFIX}/lib/gstreamer-1.0"
}
