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

pkgbase=librest
pkgname=(librest librest-docs librest-demos)
pkgver=0.9.1
pkgrel=2
pkgdesc="Library for accessing RESTful web services"
url="https://gitlab.gnome.org/GNOME/librest"
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
license=(LGPL)
depends=(glib2 libxml2 libsoup3 json-glib)
makedepends=(gobject-introspection git meson gi-docgen vala libadwaita
             gtksourceview5)
_commit=aa9e968e381ede159414c6338da24d61ad0b5d8b  # tags/0.9.1^0
source=("git+https://gitlab.gnome.org/GNOME/librest.git#commit=$_commit"
        30.patch)
b2sums=('SKIP'
        'a5e54797a758b67c7f9aa6e90cd7b6435dfa1f7abc86b9b88c0c98e78724b15308ca8af4ccb138d1d01948e54ed9bf930ee37a7d253e6c979846f93f92fef2c2')

pkgver() {
  cd librest
  git describe --tags | sed 's/[^-]*-g/r&/;s/-/+/g'
}

prepare() {
  cd librest

  # https://bugs.archlinux.org/task/76560
  # https://gitlab.gnome.org/GNOME/librest/-/merge_requests/30
  git apply -3 ../30.patch
}

build() {
  arch-meson librest build -D vapi=true
  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_librest() {
  depends+=(libg{lib,object,io}-2.0.so libxml2.so libsoup-3.0.so
            libjson-glib-1.0.so)
  provides+=(librest{,-extras}-1.0.so)

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

  cd "$pkgdir"

  _pick docs usr/share/doc

  _pick demo usr/bin/librest-demo
  _pick demo usr/share/applications/org.gnome.RestDemo.desktop
}

package_librest-docs() {
  pkgdesc+=" (documentation)"
  depends=()
  mv docs/* "$pkgdir"
}

package_librest-demos() {
  pkgdesc+=" (demo applications)"
  depends=(librest libadwaita gtksourceview5)
  mv demo/* "$pkgdir"
}

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