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

_realname=gst-plugins-base
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.18.4
pkgrel=3
pkgdesc="GStreamer Multimedia Framework Base Plugins (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://gstreamer.freedesktop.org/"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-gtk-doc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja")
depends=("${MINGW_PACKAGE_PREFIX}-graphene"
         "${MINGW_PACKAGE_PREFIX}-gstreamer"
         "${MINGW_PACKAGE_PREFIX}-libogg"
         "${MINGW_PACKAGE_PREFIX}-libtheora"
         "${MINGW_PACKAGE_PREFIX}-libvorbis"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-libjpeg"
         "${MINGW_PACKAGE_PREFIX}-opus"
         "${MINGW_PACKAGE_PREFIX}-orc"
         "${MINGW_PACKAGE_PREFIX}-pango"
         "${MINGW_PACKAGE_PREFIX}-iso-codes"
         "${MINGW_PACKAGE_PREFIX}-zlib")
conflicts=("${MINGW_PACKAGE_PREFIX}-gst-plugins-bad<1.16.0")
source=(${url}/src/${_realname}/${_realname}-${pkgver}.tar.xz
        "fix-gl-mkenums.patch")
sha256sums=('29e53229a84d01d722f6f6db13087231cdf6113dd85c25746b9b58c3d68e8323'
            '28ff9bca8c1087d5634b902298d06d567aca73d799e96927a8dff73e417589ba')

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

  patch -Np1 -i "${srcdir}/fix-gl-mkenums.patch"
}

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 \
    -Dpackage-origin='https://www.msys2.org' \
    -Dtests=disabled \
    -Dexamples=disabled \
    -Dx11=disabled \
    -Dxshm=disabled \
    -Dxvideo=disabled \
    -Dalsa=disabled \
    -Dcdparanoia=disabled \
    -Dlibvisual=disabled \
    -Dtremor=disabled \
    -Ddoc=disabled \
    -Dgl_winsys=win32 \
    -Dgl_api=opengl \
    -Dgl_platform=wgl \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/ninja.exe
}

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

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

  rm -f ${pkgdir}${MINGW_PREFIX}/lib/gstreamer*/*.a
}
