# Maintainer (arch): Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Contributor: Jan de Groot <jgc@archlinux.org>
# Maintainer (artix): Nathan Owens <ndowens@artixlinux.org>
# Maintainer: Parabola Hackers <dev@lists.parabola.nu>


# parabola changes and rationale:
# - use upstream source-ball rather than VCS sources


pkgname=polkit
pkgver=123
pkgrel=1
pkgrel+=.nonsystemd1
pkgdesc="Application development toolkit for controlling system-wide privileges"
url="https://gitlab.freedesktop.org/polkit/polkit"
arch=(x86_64)
arch+=(armv7h i686)
license=(LGPL)
depends=(
  duktape
  elogind
  expat
  glib2
  pam
)
makedepends=(
  git
  gobject-introspection
  gtk-doc
  meson
)
makedepends=( ${makedepends[*]/git/} )
checkdepends=(python-dbusmock)
checkdepends_i686=(dbus-python) # FIXME: arch32 FS#252
provides=(libpolkit-{agent,gobject}-1.so)
backup=(etc/pam.d/polkit-1)
options=(debug)
# we use source-ball
source=(
  https://gitlab.freedesktop.org/polkit/polkit/-/archive/${pkgver}/${pkgname}-${pkgver}.tar.gz
  '99-artix.rules'
  '0001-remove-sysd.patch')
b2sums=('38a1afcc6d5da0d4bc572c83ac682a2946f4ce48905430d1f5dd76fd22b58b0dd1573d5dad2e82518852ab7f48919af0f0c601e3f6b03c9420efb9725b345a04'
        'd320d928b5480b5b8143717e6f88101912709020efc9583fbb233a2cc11aff51d36226b94cf69104db06f330e04d4dcfd6e4c7b027df75a3c72c43adec625fb2'
        'f7e2d94c79c8e1e5cf65c6c22f888f95ca9689137d30ff62759bb3ca91b43900c293afbb0cbd3954c889dc5cf3531a2a37c258b53fe0c0f866706376fcd6e37d')


prepare() {
  ln -s ${pkgname}-${pkgver} $pkgname # minimize diff

  cd polkit
  patch -Np1 -i ../0001-remove-sysd.patch
}

build() {
  artix-meson() { arch-meson "$@" ; } # minimize diff


  local meson_options=(
    -D examples=true
    -D gtk_doc=true
    -D man=true
    -D os_type=redhat
    -D session_tracking=libelogind
    -D tests=true
  )

  artix-meson polkit build "${meson_options[@]}"
  meson compile -C build
}

check() {
  meson test -C build --print-errorlogs -t 3
}

package() {
  meson install -C build --destdir "$pkgdir"

  install -d -o root -g 102 -m 750 "$pkgdir"/{etc,usr/share}/polkit-1/rules.d

  install -Dm644 /dev/stdin "$pkgdir/usr/lib/sysusers.d/$pkgname.conf" <<END
u polkitd 102 "PolicyKit daemon"
m polkitd proc
END

  install -m0644 "${srcdir}"/99-artix.rules "${pkgdir}"/etc/polkit-1/rules.d
}
