# Contributor: Leo <thinkabit.ukim@gmail.com>
# Maintainer: team/alpine-desktop <pabloyoyoista@postmarketos.org>
pkgname=elogind
pkgver=252.24
pkgrel=1
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
	more-strerror_r.patch
	no-bash.patch
	sigfillset.patch
	statx.patch
	strerror_r.patch
	re-add_GNU_basename_macro_for_musl.patch
	rlimit-util-no-cast.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 \
		-Drootlibdir=/usr/lib \
		-Drootlibexecdir=/usr/libexec/elogind \
		-Dudevrulesdir=/usr/lib/udev/rules.d \
		-Dsplit-usr=false \
		build
	meson compile -C build
}

check() {
	meson test --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 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="
5f93ed305a4f946fdad821907909176edb71245ae7db39177d59f7fbad9a78acf6eb227b82e2e6fc17614b75ad9f785edb4c6006a2d2283a582b8318a73ed533  elogind-v252.24.tar.gz
d684b546762ca6a133e7b4395be514dfb1516c9e8e28c97ea216f4fa1bb66caa64db90cff19f68ac2cc2c5eb347ef813b9e030245c9fe1159f7d40ad8d63e666  getdents.patch
b69598c6ff56155b8f73bb4684bca6fd66011a9088e0007499617621d2f2b8b5683efabb414d1376a27f931d5372cfda845ad50e4e2efa498391529a22909108  gshadow.patch
d79d8fb6149299b24d6935d1e8feff194daf67318d45dd8e93087e715f08863a6152261ee2c0b5eff89b01c7189117605309be43184104ba571fbb8425e2f364  more-strerror_r.patch
b0157d43cafbd54c9af7ea5d11cf0f03e3aa9524b5f959457ac2c5a325d1d000f5c8d6e4bb6a5b4f7e7d55230d3ae0de033abd3fc6a8b6cf4bfb7cbe2230667b  no-bash.patch
28884612bee898c775f51a27ad26a5478ade3a1608cb528d7797a01ad3606a71379e7486a39246032d736810ad7c8e2925ba25d5f72d39473a14e6e23fcffe3e  sigfillset.patch
f7f22edfea8062c6bfaa2e7b706368ab87b026bc486a2f34627bb82cd362883279ccd9e8436208b0904b86e80b3fa977695ca79a19e1dd9e7218dbb1eb8610e0  statx.patch
6b60da7b045a7004da09b910a192c3e9a00ef7507cb108d9639e18cc81e8bb56e37d3c8db1efee37334c15cddaca480f0cf25d7532cf2381f9981e9d2033bc44  strerror_r.patch
3bbbe054759f5e911219a588168935d4b0ced6e92da85ac39a51f52893ac775c10b19819ead960380241be8a66ad55e71ebb7445ff835241e1162bbe0202d5fd  re-add_GNU_basename_macro_for_musl.patch
4e570289619f92d7b0da2cf1eae59f1a1ad18df4df46380c15a6b35f211dab5a14e8c4319f098e6042bf00f359bf236171552268236e31dfd5b88b5d2c653a85  rlimit-util-no-cast.patch
fe8855ffbb8149a8c3892791c4d179c8edf863e9641892c700637b352e8d9d31e406b1d6c5fed5c19e35eb9dcf33bfdb93f0b5a659aaef299ec10b442a878146  elogind.initd
"
