# Maintainer: TransIP <support@transip.nl>
# See: https://git.archlinux.org/svntogit/community.git/tree/trunk/PKGBUILD?h=packages/nextcloud-client#n45

pkgname=stack-client
pkgver=%VERSION%
pkgrel=0
pkgdesc='STACK desktop client'
arch=(x86_64)
url='https://transip.nl/stack'
license=(GPL)
depends=(openssl sqlite qtkeychain qt5-svg qt5-webengine xdg-utils libcloudproviders)
makedepends=(doxygen extra-cmake-modules kio python-sphinx qt5-tools git cmocka libffi)
optdepends=(
  'kio: integration with Dolphin'
  'nemo-python: integration with Nemo'
  'python-nautilus: integration with Nautilus'
  'python2-caja: integration with Caja'
)
source=($pkgname-pull1909.patch::https://github.com/nextcloud/desktop/pull/1909.patch)
backup=('etc/stack/sync-exclude.lst')
validpgpkeys=("66A0D3C26029EC5F4ECEAC74930768AFD69BD465")
sha256sums=('572ed5eddad3a3de38d744b3470a2461a1838198686660fc2a52b57ac7e1003c')

prepare() {
  cd %CLIENTDIR%

  # Nothing to do
}

build() {
  patch -Np1 --directory "%CLIENTDIR%" -i $pkgname-pull1909.patch

  cd %CLIENTDIR%

  # Use system GNUInstallDirs.cmake so that we can benefit from
  # https://gitlab.kitware.com/cmake/cmake/merge_requests/3735
  rm -v cmake/modules/GNUInstallDirs.cmake

  # bundled breakpad in libcrashreporter-qt submodule is too old and does not build with glibc >= 2.26
  # Upstream fix: https://github.com/google/breakpad/commit/bddcc58860f522a0d4cbaa7e9d04058caee0db9d
  cmake \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DNO_SHIBBOLETH=1 \
    -DWITH_CRASHREPORTER=OFF \
    -DMIRALL_VERSION_BUILD=%BUILDID% \
    -DOEM_THEME_DIR=%THEMEDIR% \
    -DMIRALL_VERSION_SUFFIX= \
    %CLIENTDIR%

  make
}

check() {
  cd %CLIENTDIR%

  # Tests fail if $TMPDIR is too small; specify an alternative for machines
  # with a small /tmp partition.
  # TMPDIR="$srcdir/tmpdir" make test ARGS="-V"
}

package() {
  cd %CLIENTDIR%

  make DESTDIR="$pkgdir" install

  # Move files to the proper directory for Arch, see: https://www.freedesktop.org/wiki/Software/systemd/TheCaseForTheUsrMerge/
  if [ -d "$pkgdir/lib" ]; then
    mkdir -p $pkgdir/usr/lib
    mv $pkgdir/lib/* $pkgdir/usr/lib
    rm -rf $pkgdir/lib
  fi

  if [ -d "$pkgdir/lib64" ]; then
    mkdir -p $pkgdir/usr/lib64
    mv $pkgdir/lib64/* $pkgdir/usr/lib64
    rm -rf $pkgdir/lib64
  fi
}
