# Contributor: Leo <thinkabit.ukim@gmail.com>
# Maintainer: team/alpine-desktop <ablocorrea@hotmail.com>
pkgname=elogind
pkgver=252.9
pkgrel=5
pkgdesc="Standalone fork of systemd's elogind"
url="https://github.com/elogind/elogind"
arch="all"
license="GPL-2.0-or-later LGPL-2.1-or-later"
depends="dbus shadow busctl=$pkgver-r$pkgrel"
options="!check" # Tests fail on builders
makedepends="
	acl-dev
	coreutils
	dbus-dev
	docbook-xsl
	eudev-dev
	gettext-dev
	glib-dev
	gperf
	libcap-dev
	libseccomp-dev
	libxslt-dev
	linux-pam-dev
	m4
	meson
	pcre2-dev
	py3-jinja2
	"
subpackages="
	$pkgname-common:_common
	$pkgname-dev
	$pkgname-doc
	$pkgname-lang
	$pkgname-openrc
	lib$pkgname:libs
	$pkgname-zsh-completion
	$pkgname-bash-completion
	busctl:_busctl
	"
source="https://github.com/elogind/elogind/archive/v$pkgver/elogind-v$pkgver.tar.gz
	getdents.patch
	gshadow.patch
	lfs64.patch
	more-strerror_r.patch
	no-bash.patch
	rlim-max.patch
	rpath.patch
	sigfillset.patch
	statx.patch
	strerror_r.patch
	re-add_GNU_basename_macro_for_musl.patch
	elogind.initd
	"

build() {
	export LDFLAGS="$LDFLAGS -lintl"
	abuild-meson \
		-Db_lto=true \
		-Dcgroup-controller=elogind \
		-Ddefault-hierarchy=unified \
		-Ddefault-kill-user-processes=false \
		-Dhalt-path=/sbin/halt \
		-Dman=true \
		-Dpolkit=true \
		-Dreboot-path=/sbin/reboot \
		-Dtests="$(want_check && echo true || echo false)" \
		\
		-Dpamconfdir=/etc/pam.d \
		-Dpamlibdir=/lib/security \
		-Drootlibdir=/usr/lib \
		-Drootlibexecdir=/usr/libexec/elogind \
		build
	meson compile -C build
}

check() {
	meson test --no-rebuild --print-errorlogs -C build
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C build

	# Claim compatiblity with systemd and systemd-logind
	ln -s libelogind.pc "$pkgdir"/usr/lib/pkgconfig/libsystemd.pc
	ln -s libelogind.pc "$pkgdir"/usr/lib/pkgconfig/libsystemd-logind.pc
	ln -s /usr/include/elogind "$pkgdir"/usr/include/systemd

	# Install headers from elogind
	install -Dm644 src/systemd/sd-id128.h usr/include/sd-id128.h
	install -Dm644 src/systemd/_sd-common.h usr/include/_sd-common.h

	# Install openrc service
	install -Dm755 "$srcdir"/elogind.initd "$pkgdir"/etc/init.d/elogind
}

_common() {
	pkgdesc="common components for elogind and related tools"
	depends=
	amove usr/lib/elogind/libelogind-shared-*.so
}

_busctl() {
	pkgdesc="tool for monitoring and introspecting the D-Bus bus"
	depends=
	amove usr/bin/busctl
}

sha512sums="
eed620cbc2f03bfeae6a80c9a421c21d3293fa40adffb96c7e4d86508c06712041f6623fb2bac15ecbb85faca4b5674ea6423b3067840809fb27d023fd9e5ffd  elogind-v252.9.tar.gz
d684b546762ca6a133e7b4395be514dfb1516c9e8e28c97ea216f4fa1bb66caa64db90cff19f68ac2cc2c5eb347ef813b9e030245c9fe1159f7d40ad8d63e666  getdents.patch
b69598c6ff56155b8f73bb4684bca6fd66011a9088e0007499617621d2f2b8b5683efabb414d1376a27f931d5372cfda845ad50e4e2efa498391529a22909108  gshadow.patch
898d3e7b6eb51ee668d18bbdeaeca40df81512d171fccf1510bc181f6f0432252d48f20bb10aade3fc80bb3f91149db6065c003edc2b5abf24c929aadaa0528b  lfs64.patch
d79d8fb6149299b24d6935d1e8feff194daf67318d45dd8e93087e715f08863a6152261ee2c0b5eff89b01c7189117605309be43184104ba571fbb8425e2f364  more-strerror_r.patch
b0157d43cafbd54c9af7ea5d11cf0f03e3aa9524b5f959457ac2c5a325d1d000f5c8d6e4bb6a5b4f7e7d55230d3ae0de033abd3fc6a8b6cf4bfb7cbe2230667b  no-bash.patch
aca575a32e3bb209a5ddd20055b667c92fb4c1e70954a589243db4b145764b35c0067d0a9569b67ff707f85c0a8bea7c86da4b3813fec48e5267bd653b642e81  rlim-max.patch
984739e1c33018453ea139b2d91800fa1d87c3c594de6a08a1c512364e8903ea53233b571bf9ec45bb715baab32f0648022c6c5f3afac7ddbcbf8b1c790203a8  rpath.patch
28884612bee898c775f51a27ad26a5478ade3a1608cb528d7797a01ad3606a71379e7486a39246032d736810ad7c8e2925ba25d5f72d39473a14e6e23fcffe3e  sigfillset.patch
f7f22edfea8062c6bfaa2e7b706368ab87b026bc486a2f34627bb82cd362883279ccd9e8436208b0904b86e80b3fa977695ca79a19e1dd9e7218dbb1eb8610e0  statx.patch
6b60da7b045a7004da09b910a192c3e9a00ef7507cb108d9639e18cc81e8bb56e37d3c8db1efee37334c15cddaca480f0cf25d7532cf2381f9981e9d2033bc44  strerror_r.patch
3bbbe054759f5e911219a588168935d4b0ced6e92da85ac39a51f52893ac775c10b19819ead960380241be8a66ad55e71ebb7445ff835241e1162bbe0202d5fd  re-add_GNU_basename_macro_for_musl.patch
fe8855ffbb8149a8c3892791c4d179c8edf863e9641892c700637b352e8d9d31e406b1d6c5fed5c19e35eb9dcf33bfdb93f0b5a659aaef299ec10b442a878146  elogind.initd
"
