# Maintainer: Developer <dev@opalos.org>
# Maintainer: Developer <dev@opalos.org>

pkgbase=serd
pkgname=(serd serd-docs)
pkgver=%version%
pkgrel=%release%
pkgdesc="Lightweight C library for RDF syntax supporting reading/ writing Turtle and NTriples"
arch=(x86_64)
url="https://drobilla.net/software/serd.html"
license=(
  '0BSD OR ISC'
  BSD-3-Clause
  ISC
)
makedepends=(
  doxygen
  mandoc
  meson
  python-sphinx
  python-sphinxygen
)
source=(https://download.drobilla.net/$pkgname-$pkgver.tar.xz{,.sig})
sha512sums=('052f0765a9af6883a7ef1a31bd90eea3c57d93747dfb989eeda8c4dabbf2ae7d2e868d437aa2a510243f3a535e366739fe266cf82ef0d280472868c87055d50a'
            'SKIP')
b2sums=('5b2ad72ddced2edcb948d75e795c95dccc50ad5be4bf3100c34ead4ec43944647c4f8ff419cda2b7a005b9b69dbd6fa9a0733b2810ad95a9051df3d4253ddfe9'
        'SKIP')
validpgpkeys=('907D226E7E13FA337F014A083672782A9BF368F3') # David Robillard <d@drobilla.net>

_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
}

build() {
  arch-meson $pkgname-$pkgver build
  meson compile -C build
}

check() {
  meson test -C build
}

package_serd() {
  depends=(glibc)
  optdepends=('serd-docs: for developer documentation')
  provides=(libserd-0.so)

  meson install -C build --destdir "$pkgdir"
  install -vDm 644 $pkgbase-$pkgver/LICENSES/* -t "$pkgdir/usr/share/licenses/$pkgname/"

  (
    cd "$pkgdir"
    _pick $pkgname-docs usr/share/doc
  )

  install -vDm 644 $pkgname-$pkgver/COPYING -t "$pkgdir/usr/share/licenses/$pkgname/"
  install -vDm 644 $pkgname-$pkgver/{AUTHORS,NEWS,README.md} -t "$pkgdir/usr/share/doc/$pkgname/"
}

package_serd-docs() {
  pkgdesc+=" - documentation"

  mv -v $pkgname/* "$pkgdir"
  mv -v "$pkgdir/usr/share/doc/"serd{-0,}
  install -vDm 644 $pkgbase-$pkgver/LICENSES/* -t "$pkgdir/usr/share/licenses/$pkgname/"
}
