# Maintainer (MSYS2): Michael Hansen <zrax0111@gmail.com>

_variant=-${KF5_VARIANT:-shared}
source "$(dirname ${BASH_SOURCE[0]})"/../mingw-w64-PKGBUILD-common/kde-frameworks5
_kde_f5_init_package "${_variant}" "phonon"
pkgver=4.11.1
pkgrel=1
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
pkgdesc="Multimedia framework for KF5 (mingw-w64-qt5${_namesuff})"
url="https://phonon.kde.org"
license=('LGPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-extra-cmake-modules")
depends=()
_kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-qt5${_namesuff}"
_kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-glib2"
source=("https://download.kde.org/stable/${_basename}/${pkgver}/${_basename}-${pkgver}.tar.xz"
        '001-gnu-dirs.patch')
sha256sums=('b4431ea2600df8137a717741ad9ebc7f7ec1649fa3e138541d8f42597144de2d'
            '77849ecb26d72a82fefe6522ce5025c674748ecce91f9465d2d1bf28a0f0eb82')

prepare() {
  mkdir -p build-${CARCH}${_variant}

  # Phonon hard-codes plugin install paths unnecessarily.  As far as I can
  # tell, the default QPluginLoader search paths should just work as-is.
  cd ${_basename}-${pkgver}
  patch -p1 -i "${srcdir}/001-gnu-dirs.patch"
}

build() {
  mkdir -p ${srcdir}/build-${MINGW_CHOST}${_variant}
  cd ${srcdir}/build-${MINGW_CHOST}${_variant}
  
  local -a extra_config
  if [ "${_variant}" = "-static" ]; then
    extra_config+=( -DBUILD_SHARED_LIBS=NO )
  fi

  _kde_f5_build_env
  ${MINGW_PREFIX}/bin/cmake \
      -G'MSYS Makefiles' \
      -DCMAKE_BUILD_TYPE=$(_kde_f5_CMAKE_BUILD_TYPE) \
      "${_kde_f5_KDE_INSTALL_DIRS[@]}" \
      "${extra_config[@]}" \
      -DBUILD_TESTING=OFF \
      -DECM_DIR=${MINGW_PREFIX}/share/ECM \
      "${extra_config[@]}" \
      ../${_basename}-${pkgver}
  make
}

package() {
  cd build-${MINGW_CHOST}${_variant}
  make DESTDIR="${pkgdir}" install
}
