# Maintainer (arch): Antonio Rojas <arojas@archlinux.org>
# Maintainer (arch): Felix Yan <felixonmars@archlinux.org>
# Contributor: Andrea Scarpino <andrea@archlinux.org>
# Contributor: Gustavo Alvarez <sl1pkn07@gmail.com>
# Contributor: Balló György <ballogyor+arch at gmail dot com>
# Contributor: bill-auger <bill-auger@programmer.net>
# Maintainer: Parabola Hackers <dev@lists.parabola.nu>


# parabola changes and rationale:
#  - replaced 'qt5-webengine' dependency with 'qt5-webkit'
#  - pin to 'marble-*' binaries to 'marble-common'
#    Note: This is done to prevent breakage.
#    Only 'marble-common' requires the change;
#    but then 'marble-common' would need to be pinned
#    to (require) it's clients, which is weird.
#    For that reason, we build all split-packages.


pkgbase=marble
pkgname=(marble-common marble-qt marble-maps marble)
pkgver=22.12.2
pkgrel=1
pkgrel+=.parabola1
pkgdesc='Desktop Globe'
arch=(x86_64)
arch+=(armv7h i686)
url='https://apps.kde.org/marble/'
license=(GPL)
makedepends=(extra-cmake-modules gpsd kdoctools kparts krunner libwlocate phonon-qt5
             plasma-workspace qt5-serialport qt5-tools qt5-webengine shapelib protobuf)
makedepends=( ${makedepends[@]/qt5-webengine/qt5-webkit} )
source=(https://download.kde.org/stable/release-service/$pkgver/src/$pkgbase-$pkgver.tar.xz{,.sig}
        no-knewstuff.patch)
sha256sums=('ed9a6aed3c5c5057cce25e28ac0e9eaf377d79d866375fa62a5ac072d4edda3a'
            'SKIP'
            '4718d89d5f0dc79969196ea7afc71bfd37ed9570c3e2718f0c54549bbb0991a1')
validpgpkeys=(CA262C6C83DE4D2FB28A332A3A6A4DB839EAA6D7  # Albert Astals Cid <aacid@kde.org>
              F23275E4BF10AFC1DF6914A6DBD2CE893E2D1C87  # Christoph Feck <cfeck@kde.org>
              D81C0CB38EB725EF6691C385BB463350D6EF31EF) # Heiko Becker <heiko.becker@kde.org>

prepare() {
  patch -d $pkgbase-$pkgver -p1 < no-knewstuff.patch # Drop unused dependency
}

build() {
  cmake -B build -S $pkgbase-$pkgver \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_INSTALL_SYSCONFDIR=/etc \
    -DQT_PLUGINS_DIR=lib/qt/plugins \
    -DBUILD_TESTING=OFF \
    -DBUILD_TOUCH=ON \
    -DBUILD_MARBLE_EXAMPLES=OFF \
    -DBUILD_MARBLE_TESTS=OFF \
    -DMOBILE=OFF
  cmake --build build
}

package_marble-common() {
  pkgdesc='Common libraries and plugins for Marble'
  depends=(qt5-svg qt5-webengine phonon-qt5 protobuf)
  depends=( ${depends[@]/qt5-webengine/qt5-webkit} )
  optdepends=('gpsd: GPS based geolocation'
              'libwlocate: WLAN based geolocation'
              'qt5-serialport: APRS plugin'
              'shapelib: SHP plugin')

  DESTDIR="$pkgdir" cmake --install build
  rm -r "$pkgdir"/usr/share/{config.kcfg,kxmlgui5,metainfo,plasma} \
        "$pkgdir"/usr/bin \
        "$pkgdir"/usr/lib/qt/{qml,plugins/*.so,plugins/kf5} \
        "$pkgdir"/usr/share/applications/{marble_geo.desktop,marble_worldwind.desktop,org.kde.marble*.desktop} \
        "$pkgdir"/usr/share/kservices5/{plasma-*,marble_part.desktop} \
        "$pkgdir"/usr/share/locale/*/LC_MESSAGES/*.mo
}

package_marble-qt() {
  pkgdesc+=' (Qt version)'
  depends=(marble-common)

  # pin to 'marble-common'
  depends=( ${depends[*]/marble-common/marble-common=$pkgver} )

  DESTDIR="$pkgdir" cmake --install build/src/apps/marble-qt
}

package_marble() {
  depends=(marble-common kparts)
  optdepends=('krunner: Krunner plugin')
  groups=(kde-applications kde-education)

  # pin to 'marble-common'
  depends=( ${depends[*]/marble-common/marble-common=$pkgver} )

  DESTDIR="$pkgdir" cmake --install build/src/apps/marble-kde
  DESTDIR="$pkgdir" cmake --install build/src/plasma
  DESTDIR="$pkgdir" cmake --install build/src/plasmarunner
  DESTDIR="$pkgdir" cmake --install build/src/thumbnailer
  rm -r "$pkgdir"/usr/share/{icons,doc}
}

package_marble-maps() {
  pkgdesc='OpenStreetMap Navigation'
  depends=(marble-common kirigami2)

  # pin to 'marble-common'
  depends=( ${depends[*]/marble-common/marble-common=$pkgver} )

  DESTDIR="$pkgdir" cmake --install build/src/apps/marble-maps
}
