# Maintainer (arch): Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Contributor: Ionut Biru <ibiru@archlinux.org>
# Contributor: Andreas Grapentin <andreas@grapentin.org>
# Contributor: Márcio Silva <coadde@hyperbola.info>
# Contributor: Isaac David <isacdaavid@at@isacdaavid@dot@info>
# Maintainer: Parabola Hackers <dev@lists.parabola.nu>


# parabola changes and rationale:
# privacy:
#   - removed support for possibly unsafe protocols
# technical:
#   - build from versioned source-ball, rather than VCS sources


pkgbase=gnome-online-accounts
pkgname=(
  gnome-online-accounts
  libgoa
)
pkgver=3.48.0
pkgrel=2
pkgrel+=.nonprism1
pkgdesc="Single sign-on framework for GNOME"
pkgdesc+=", without support for unsafe and dangerous for privacy protocols"
url="https://wiki.gnome.org/Projects/GnomeOnlineAccounts"
arch=(x86_64)
arch+=(armv7h i686)
license=(LGPL)
depends=(
  gcr
  json-glib
  krb5
  libnotify
  librest
  libsecret
  webkit2gtk-4.1
)
makedepends=(
  git
  gobject-introspection
  gtk-doc
  meson
  vala
)
makedepends=( ${makedepends[*]/git/} )
source=(https://download.gnome.org/sources/gnome-online-accounts/3.48/gnome-online-accounts-3.48.0.tar.xz)
sha256sums=('418bb9fcffdbd72a98205ad365137617fc1e3551a54de74f6a98d45d266175bf')


prepare() {
  cd ${pkgname}-${pkgver}
}

build() {
  local meson_options=(
    -D gtk_doc=true
    -D man=true
    -D media_server=true
  )
  local privacy_options=( -D exchange=false              \
                          -D fedora=false                \
                          -D google=false                \
                          -D google_client_id=NONE       \
                          -D google_client_secret=NONE   \
                          -D imap_smtp=true              \
                          -D kerberos=true               \
                          -D lastfm=false                \
                          -D lastfm_client_id=NONE       \
                          -D lastfm_client_secret=NONE   \
                          -D media_server=false          \
                          -D owncloud=true               \
                          -D windows_live=false          \
                          -D windows_live_client_id=NONE )

  arch-meson ${pkgname}-${pkgver} build "${meson_options[@]}" "${privacy_options[@]}"
  meson compile -C build
}

check() {
  meson test -C build --print-errorlogs
}

_pick() {
  local p="$1" f d; shift
  for f; do
    d="$srcdir/$p/${f#$pkgdir/}"
    mkdir -p "$(dirname "$d")"
    mv "$f" "$d"
    rmdir -p --ignore-fail-on-non-empty "$(dirname "$f")"
  done
}

package_gnome-online-accounts() {
  depends+=("libgoa=$pkgver-$pkgrel")
  optdepends=(
    'gvfs-goa: Virtual file systems, e.g. OwnCloud'
    'gvfs-google: Google Drive'
  )
  provides=(libgoa-backend-1.0.so)

  meson install -C build --destdir "$pkgdir"

  cd "$pkgdir"

  _pick goa usr/include/goa-1.0/goa
  _pick goa usr/lib/libgoa-1.0.so*
  _pick goa usr/lib/girepository-1.0/Goa-1.0.typelib
  _pick goa usr/lib/goa-1.0/include
  _pick goa usr/lib/pkgconfig/goa-1.0.pc
  _pick goa usr/share/gir-1.0/Goa-1.0.gir
  _pick goa usr/share/vala/vapi/goa-1.0.*
  _pick goa usr/share/gtk-doc
}

package_libgoa() {
  pkgdesc+=" - client library"
  depends=(libg{lib,object,io}-2.0.so)
  provides=(libgoa-1.0.so)

  mv goa/* "$pkgdir"
}
