# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>

pkgbase=libportal
pkgname=(
  libportal
  libportal-docs
  libportal-gtk3
  libportal-gtk4
  libportal-qt5
  libportal-qt6
)
pkgver=0.8.1
pkgrel=1
pkgdesc="GIO-style async APIs for most Flatpak portals"
url="https://github.com/flatpak/libportal"
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
license=(LGPL-3.0-only)
makedepends=(
  gcc-libs
  gi-docgen
  git
  gjs
  glib2
  glib2-devel
  glibc
  gobject-introspection
  gtk3
  gtk4
  meson
  qt5-base
  qt5-tools
  qt5-x11extras
  qt6-base
  qt6-tools
  vala
)
checkdepends=(
  python-dbusmock
  python-pytest
  xorg-server-xvfb
)
source=("git+https://github.com/flatpak/libportal#tag=$pkgver")
b2sums=('025e1423d6f6f4645bfd8dbfc911daf51c6f6d06d1989b49cbeee201eece7cb3b7f693439c36bc70c87e3dee0d64f062f5b8f574acae24bc36a7df8d90cb99f5')

prepare() {
  cd libportal
}

build() {
  arch-meson libportal build
  meson compile -C build
}

check() {
  xvfb-run -s '-nolisten local' \
    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_libportal() {
  depends=(
    gcc-libs
    glib2
    glibc
    libg{lib,object,io}-2.0.so
  )
  optdepends=(
    'libportal-docs: API documentation'
    'libportal-gtk3: GTK 3 backend'
    'libportal-gtk4: GTK 4 backend'
    'libportal-qt5: Qt 5 backend'
    'libportal-qt6: Qt 6 backend'
    'xdg-desktop-portal: Portal service'
  )
  provides=(libportal.so)

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

  cd "$pkgdir"

  _pick docs usr/share/doc

  local x
  for x in gtk3 gtk4 qt5 qt6; do
    _pick $x usr/include/libportal-$x
    _pick $x usr/lib{,/pkgconfig}/libportal-$x.*

    if [[ $x == gtk* ]]; then
      _pick $x {usr/lib/girepository-1.0,usr/share/gir-1.0}/Xdp${x^}-1.0.*
      _pick $x usr/share/vala/vapi/libportal-$x.*
    fi
  done
}

package_libportal-docs() {
  pkgdesc+=" - API documentation"

  mv docs/* "$pkgdir"
}

package_libportal-gtk3() {
  pkgdesc+=" - GTK 3 backend"
  depends=(
    gcc-libs
    glib2
    libg{d,t}k-3.so
    libportal
  )
  provides=(libportal-gtk3.so)

  mv gtk3/* "$pkgdir"
}

package_libportal-gtk4() {
  pkgdesc+=" - GTK 4 backend"
  depends=(
    gcc-libs
    glib2
    libgtk-4.so
    libportal
  )
  provides=(libportal-gtk4.so)

  mv gtk4/* "$pkgdir"
}

package_libportal-qt5() {
  pkgdesc+=" - Qt 5 backend"
  depends=(
    gcc-libs
    glib2
    glibc
    libportal
    qt5-base
    qt5-x11extras
  )
  provides=(libportal-qt5.so)

  mv qt5/* "$pkgdir"
}

package_libportal-qt6() {
  pkgdesc+=" - Qt 6 backend"
  depends=(
    gcc-libs
    glib2
    glibc
    libportal
    qt6-base
  )
  provides=(libportal-qt6.so)

  mv qt6/* "$pkgdir"
}

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