# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Maintainer: Fabian Bornschein <fabiscafe@archlinux.org>
# Contributor: Ionut Biru <ibiru@archlinux.org>

pkgbase=gnome-online-accounts
pkgname=(
  gnome-online-accounts
  libgoa
)
pkgver=3.50.3
pkgrel=1
pkgdesc="Single sign-on framework for GNOME"
url="https://wiki.gnome.org/Projects/GnomeOnlineAccounts"
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
license=(LGPL-2.0-or-later)
depends=(
  dbus
  dconf
  gcc-libs
  gcr-4
  glib2
  glibc
  gtk4
  hicolor-icon-theme
  json-glib
  krb5
  libadwaita
  librest
  libsecret
  libsoup3
  libxml2
)
makedepends=(
  git
  glib2-devel
  gobject-introspection
  meson
  vala
)
source=(
  # GOA tags use SSH signatures which makepkg doesn't understand
  "git+https://gitlab.gnome.org/GNOME/gnome-online-accounts.git#tag=$pkgver"
)
b2sums=('323ecb4fd0a2d5e78cb2c0e17184c69f8d953f9015f8e74d547d8427dcbe94207164f363e6653263257f365a25452cc1f0c58c7f4218ea2009711d30b30b2c2e')

prepare() {
  cd $pkgname
}

build() {
  local meson_options=(
    -D gtk_doc=true
    -D man=true
  )

  arch-meson $pkgname build "${meson_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=(
    'epiphany: (or another modern browser): OAuth authentication'
    'gvfs-goa: Virtual file systems, e.g. OwnCloud'
    'gvfs-google: Google Drive'
    'gvfs-onedrive: Microsoft OneDrive'
  )
  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=(
    glibc
    libg{lib,object,io}-2.0.so
  )
  provides=(libgoa-1.0.so)

  mv goa/* "$pkgdir"
}

# vim:set sw=2 sts=-1 et:
