# Maintainer (MSYS2): Michael Hansen <zrax0111@gmail.com>
# Contributor: Zach Bacon <zachbacon@vba-m.com>

_variant=-${KF5_VARIANT:-shared}
source "$(dirname ${BASH_SOURCE[0]})"/../mingw-w64-PKGBUILD-common/kde-frameworks5
_kde_f5_init_package "${_variant}" "kio"
pkgver=5.75.0
pkgrel=1
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
pkgdesc="Resource and network access abstraction (mingw-w64-qt5${_namesuff})"
license=('LGPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-extra-cmake-modules>=${pkgver}")
depends=()
_kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-qt5${_namesuff}"
_kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-solid-qt5${_namesuff}>=${pkgver}"
_kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-kjobwidgets-qt5${_namesuff}>=${pkgver}"
_kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-kbookmarks-qt5${_namesuff}>=${pkgver}"
_kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-kwallet-qt5${_namesuff}>=${pkgver}"
_kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-libxslt"
groups=('kf5')
source=("https://download.kde.org/stable/frameworks/${pkgver%.*}/${_basename}-${pkgver}.tar.xz"
        001-disable-gssapi-mingw.patch)
sha256sums=('27af8d83d0ea6c68fc62675a0d0d34e94489e9e518c4a4c32fa9d4784510bc8e'
            '5fb47bdd8e6776755d9f3f466f765495a5aea314f3cb4909f015d7c7473c4bc1')

prepare() {
  cd ${_basename}-${pkgver}
  # Resolving conflict with MSYS heimdal package.
  # Some day we need to create heimdal for mingw-w64
  patch -p1 -i ${srcdir}/001-disable-gssapi-mingw.patch
  mkdir -p ${srcdir}/build-${CARCH}${_variant}
}

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

  _kde_f5_build_env
  cmake ../${_basename}-${pkgver} \
    -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 \
    "${extra_config[@]}" \
    -G'MSYS Makefiles'
  make
}

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