# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

source "$(dirname ${BASH_SOURCE[0]})"/../mingw-w64-PKGBUILD-common/kde-frameworks
_realname=ark
pkgbase="mingw-w64-${_realname}"
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=25.08.3
pkgrel=1
pkgdesc="Archiving Tool (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'archlinux: ark'
)
msys2_repository_url="https://invent.kde.org/utilities/ark/"
url="https://apps.kde.org/ark/"
license=('spdx:LGPL-2.0-or-later')
depends=(
  "${MINGW_PACKAGE_PREFIX}-breeze-icons"
  "${MINGW_PACKAGE_PREFIX}-cc-libs"
  "${MINGW_PACKAGE_PREFIX}-kcolorscheme"
  "${MINGW_PACKAGE_PREFIX}-kcompletion"
  "${MINGW_PACKAGE_PREFIX}-kconfig"
  "${MINGW_PACKAGE_PREFIX}-kconfigwidgets"
  "${MINGW_PACKAGE_PREFIX}-kcoreaddons"
  "${MINGW_PACKAGE_PREFIX}-kcrash"
  "${MINGW_PACKAGE_PREFIX}-kdbusaddons"
  "${MINGW_PACKAGE_PREFIX}-kfilemetadata"
  "${MINGW_PACKAGE_PREFIX}-ki18n"
  "${MINGW_PACKAGE_PREFIX}-kio"
  "${MINGW_PACKAGE_PREFIX}-kjobwidgets"
  "${MINGW_PACKAGE_PREFIX}-kparts"
  "${MINGW_PACKAGE_PREFIX}-kservice"
  "${MINGW_PACKAGE_PREFIX}-kwidgetsaddons"
  "${MINGW_PACKAGE_PREFIX}-kwindowsystem"
  "${MINGW_PACKAGE_PREFIX}-kxmlgui"
  "${MINGW_PACKAGE_PREFIX}-libarchive"
  "${MINGW_PACKAGE_PREFIX}-libzip"
  "${MINGW_PACKAGE_PREFIX}-qt6-base"
  "${MINGW_PACKAGE_PREFIX}-zlib"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-cmake"
  "${MINGW_PACKAGE_PREFIX}-extra-cmake-modules"
  "${MINGW_PACKAGE_PREFIX}-gettext-tools"
  "${MINGW_PACKAGE_PREFIX}-icoutils"
  "${MINGW_PACKAGE_PREFIX}-kdoctools"
  "${MINGW_PACKAGE_PREFIX}-ninja"
  "${MINGW_PACKAGE_PREFIX}-pkgconf"
)
optdepends=(
  "${MINGW_PACKAGE_PREFIX}-p7zip: 7Z format support"
  "${MINGW_PACKAGE_PREFIX}-unrar: RAR decompression support"
  "lzop: LZO format support"
)
groups=(
  "${MINGW_PACKAGE_PREFIX}-kde-applications"
  "${MINGW_PACKAGE_PREFIX}-kde-utilities"
)
source=(
  "https://download.kde.org/stable/release-service/${pkgver}/src/${_realname}-${pkgver}.tar.xz"{,.sig}
  "0001-ark-define-QT_STAT_LNK-macro.patch"
  "0002-ark-disable-zip-plugin.patch"
)
sha256sums=('ca4fb7295f090280df02d24b64f113e10c6f618138b387bc1fd7a2c561de554f'
            'SKIP'
            'ad2dd0f258b1258df779a69ee629fdd3c34d95dc34539b0c70020a27ea995036'
            '06df815353f73edbde4edbdc945118f52cd849041f61bae142dccdae9a091442')
validpgpkeys=(CA262C6C83DE4D2FB28A332A3A6A4DB839EAA6D7  # Albert Astals Cid <aacid@kde.org>
              F23275E4BF10AFC1DF6914A6DBD2CE893E2D1C87  # Christoph Feck <cfeck@kde.org>
              D81C0CB38EB725EF6691C385BB463350D6EF31EF) # Heiko Becker <heiko.becker@kde.org>

prepare() {
  cd "${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/0001-ark-define-QT_STAT_LNK-macro.patch"

  if [[ "${CC}" == clang ]] ; then
    patch -p1 -i "${srcdir}/0002-ark-disable-zip-plugin.patch"
  fi
}

build() {
  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    _extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  _kde_build_env
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    "${MINGW_PREFIX}"/bin/cmake.exe \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      "${_KDE_INSTALL_DIRS[@]}" \
      -DBUILD_TESTING=OFF \
      "${_extra_config[@]}" \
      -S "${_realname}-${pkgver}" \
      -B "build-${MSYSTEM}"

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

package() {
  DESTDIR="${pkgdir}" "${MINGW_PREFIX}"/bin/cmake.exe --install "build-${MSYSTEM}"
}
