# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Contributor: Ionut Biru <ibiru@archlinux.org>

pkgbase=colord
pkgname=(colord colord-sane libcolord)
pkgver=1.4.6
pkgrel=1
pkgdesc="System daemon for managing color devices"
url="https://www.freedesktop.org/software/colord"
arch=(x86_64)
license=(GPL2)
depends=(lcms2 libgusb polkit sqlite dconf dbus libgudev shared-mime-info systemd)
makedepends=(gobject-introspection vala sane bash-completion argyllcms git meson gtk-doc
             docbook-xsl)
options=(!emptydirs)
_commit=43c19fd019da5f69d2ebc00a9908b1dd83129485  # tags/1.4.6^0
source=("git+https://github.com/hughsie/colord#commit=$_commit")
sha256sums=('SKIP')
validpgpkeys=('163EB50119225DB3DF8F49EA17ACBA8DFA970E17')  # Richard Hughes

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

prepare() {
  cd colord
}

build() {
  arch-meson colord build \
    -D libcolordcompat=true \
    -D sane=true \
    -D vapi=true \
    -D print_profiles=true \
    -D daemon_user=colord
  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_colord() {
  depends+=("libcolord=$pkgver-$pkgrel")
  optdepends=('argyllcms: color profiling'
              'colord-sane: SANE support')
  provides=(libcolorhug.so)
  replaces=(shared-color-profiles)

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

  echo 'u colord - "Color management daemon" /var/lib/colord' |
    install -Dm644 /dev/stdin "$pkgdir/usr/lib/sysusers.d/colord.conf"

  cd "$pkgdir"

  _pick sane usr/lib/colord-sane
  _pick sane usr/lib/colord-plugins/libcolord_sensor_sane.so

  _pick lib usr/include/colord-1/colord{,.h}
  _pick lib usr/lib/libcolord{,compat}.so*
  _pick lib usr/lib/girepository-1.0/Colord-1.0.typelib
  _pick lib usr/lib/pkgconfig/colord.pc
  _pick lib usr/share/gir-1.0/Colord-1.0.gir
}

package_colord-sane() {
  pkgdesc+=" (SANE support)"
  depends=("colord=$pkgver-$pkgrel" sane)
  mv sane/* "$pkgdir"
}

package_libcolord() {
  pkgdesc+=" (client library)"
  depends=(glib2 lcms2 systemd)
  provides=(libcolord.so)
  mv lib/* "$pkgdir"
}

# vim:set sw=2 et:
