# 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}" "breeze-icons"
pkgver=5.83.0
pkgrel=1
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
pkgdesc="Breeze icon themes (mingw-w64-qt5${_namesuff})"
license=('LGPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-extra-cmake-modules>=${pkgver}"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-python-lxml"
             "unzip")
depends=()
_kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-qt5${_namesuff}"
groups=("${MINGW_PACKAGE_PREFIX}-kf5")
source=("https://download.kde.org/stable/frameworks/${pkgver%.*}/${_basename}-${pkgver}.zip"
        01-mingw-python-script.patch)
sha256sums=('0014ebccd11a7bcd31389dafbefbb626e86935edd0f28d923f7c28d18ad8ded4'
            '2589efa413e5540668eaa6156d415b9e423cba566643aaef449392992bcb46c2')

prepare() {
  mkdir -p build-${CARCH}${_variant}
  cd ${_basename}-${pkgver}
  patch -p1 -i ${srcdir}/01-mingw-python-script.patch
}

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

  _kde_f5_build_env
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G "Ninja" \
    -DCMAKE_BUILD_TYPE=$(_kde_f5_CMAKE_BUILD_TYPE) \
    "${_kde_f5_KDE_INSTALL_DIRS[@]}" \
    -DBUILD_QCH=OFF \
    -DBUILD_TESTING=OFF \
    -DECM_DIR=${MINGW_PREFIX}/share/ECM \
    -DPython_EXECUTABLE=${MINGW_PREFIX}/bin/python.exe \
    -DPython_ROOT_DIR=${MINGW_PREFIX} \
    -DPython_FIND_REGISTRY=NEVER \
    "${extra_config[@]}" \
    ../${_basename}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake.exe --build ./
}

package() {
  cd build-${CARCH}${_variant}
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake.exe --build ./ --target install

  # KDE apps won't get an icon theme by default on Windows unless it's
  # provided via <QStandardPaths::GenericDataLocation>/icontheme.rcc
  # TODO: Make this better...
  _kde_f5_build_env
  install -Dm644 icons/breeze-icons.rcc "${pkgdir}/${QT5_PREFIX}"/bin/data/icontheme.rcc
}
