# Packager = Tuxcore <dev@tuxcore.org> 
pkgbase=colord
pkgname=(
  colord
  colord-sane
  libcolord
)
pkgver=1.4.7
pkgrel=2
pkgdesc="System daemon for managing color devices"
url="https://www.freedesktop.org/software/colord"
arch=(x86_64)
license=(GPL-2.0-or-later)
depends=(
  dbus
  dconf
  lcms2
  libgudev
  libgusb
  polkit
  shared-mime-info
  sqlite
  systemd
)
makedepends=(
  argyllcms
  bash-completion
  docbook-xsl
  git
  gobject-introspection
  gtk-doc
  meson
  sane
  vala
)
options=(!emptydirs)
_commit=1f55f64bbcdbf2283fbf2b3eed3966893870285a  # tags/1.4.7^0
source=("git+https://github.com/hughsie/colord#commit=$_commit")
b2sums=('SKIP')
  163EB50119225DB3DF8F49EA17ACBA8DFA970E17  # Richard Hughes
)

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

prepare() {
  cd colord

  # Fix writing to database
  git cherry-pick -n 08a32b2379fb5582f4312e59bf51a2823df56276

  # Fix colord-sane with hplip
  # https://gitlab.archlinux.org/archlinux/packaging/packages/colord/-/issues/3
  git cherry-pick -n 9283abd9c00468edb94d2a06d6fa3681cae2700d
}

build() {
  local meson_options=(
    -D daemon_user=colord
    -D libcolordcompat=true
    -D print_profiles=true
    -D sane=true
    -D vapi=true
  )

  arch-meson colord 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_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 sts=-1 et:
