
_variant=-${KF5_VARIANT:-shared}
source "$(dirname ${BASH_SOURCE[0]})"/../mingw-w64-PKGBUILD-common/kde-frameworks5
_kde_f5_init_package "${_variant}" "purpose"
pkgver=5.116.0
pkgrel=1
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'archlinux: purpose5'
)
pkgdesc="Framework for providing abstractions to get the developers purposes fulfilled (mingw-w64)"
license=('LGPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-extra-cmake-modules>=${pkgver}"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "intltool")
depends=()
if [ "${_variant}" = "-static" ]; then
  _kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-qt5${_namesuff}"
else
  makedepends+=("${MINGW_PACKAGE_PREFIX}-qt5-tools")
  depends+=("${MINGW_PACKAGE_PREFIX}-cc-libs"
            "${MINGW_PACKAGE_PREFIX}-qt5-base")
fi
_kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-kconfig-qt5${_namesuff}>=${pkgver}"
_kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-kcoreaddons-qt5${_namesuff}>=${pkgver}"
_kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-ki18n-qt5${_namesuff}>=${pkgver}"
_kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-kio-qt5${_namesuff}>=${pkgver}"
_kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-kirigami2-qt5${_namesuff}>=${pkgver}"
_kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-knotifications-qt5${_namesuff}>=${pkgver}"
_kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-kservice-qt5${_namesuff}>=${pkgver}"
_kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-kio-qt5${_namesuff}>=${pkgver}"
groups=("${MINGW_PACKAGE_PREFIX}-kf5")
source=(https://download.kde.org/stable/frameworks/${pkgver%.*}/$_basename-$pkgver.tar.xz{,.sig}
        0001-purpose-qt5-workaround-kf6-conflict.patch)
sha256sums=('62d66c1a32b614971a52d385be1ea5d218a95b9e65a0b547b7913238c38d1dbc'
            'SKIP'
            '095627294c69ba9b15b07d9a8205682ab26d093b3a8ac5e19da5e3ea59a96fbf')
validpgpkeys=(53E6B47B45CEA3E0D5B7457758D0EE648A48B3BB) # David Faure <faure@kde.org>

prepare() {
  mkdir -p build-${MSYSTEM}${_variant}
  cd "${_basename}-${pkgver}"
  patch -p1 -i "${srcdir}/0001-purpose-qt5-workaround-kf6-conflict.patch"
}

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

  _kde_f5_build_env
  ${MINGW_PREFIX}/bin/cmake.exe ../${_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'Ninja'
  ${MINGW_PREFIX}/bin/cmake.exe --build ./
}

package() {
  cd build-${MSYSTEM}${_variant}

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

  install -vDm 644 "${srcdir}"/${_basename}-${pkgver}/LICENSES/* -t "${pkgdir}${MINGW_PREFIX}/share/licenses/$_realname/"
}
