# Forked to build against elogind
pkgname=dbus-elogind
pkgver=1.12.16
pkgrel=0
pkgdesc="Freedesktop.org message bus system"
options="!check" # Introduces circular dependency with xorg-server (xvfb-run -> xvfb)
url="https://www.freedesktop.org/Software/dbus"
pkggroups="messagebus"
arch="all"
license="AFL-2.1 OR GPL-2.0-or-later"
subpackages="$pkgname-dev $pkgname-doc $pkgname-libs $pkgname-x11 $pkgname-openrc"
triggers="$pkgname.trigger=/etc/dbus-1/system.d"
depends_dev="util-linux-dev"
makedepends="$depends_dev expat-dev libx11-dev autoconf autoconf-archive automake libtool xmlto
	libsm-dev glib-dev elogind-dev"
checkdepends="xvfb-run"
install="$pkgname.pre-install $pkgname.post-install"
provides="dbus"
source="https://dbus.freedesktop.org/releases/dbus/dbus-$pkgver.tar.gz
	$pkgname.initd
	elogind_support.patch
	"
builddir="$srcdir/dbus-$pkgver"

# secfixes:
#   1.12.16-r0:
#   - CVE-2019-12749

prepare() {
	default_prepare

	autoreconf -fi
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--localstatedir=/var \
		--with-xml=expat \
		--with-dbus-user=messagebus \
		--with-system-pid-file=/var/run/dbus.pid \
		--disable-verbose-mode \
		--disable-static \
		--enable-inotify \
		--disable-dnotify \
		--enable-modular-tests=yes \
		--disable-asserts \
		--enable-user-session \
		--enable-xml-docs \
		--with-session-socket-dir=/tmp \
		--with-x \
		--enable-elogind
	make
}

check() {
	cd "$builddir"
	xvfb-run make check
}

package() {
	make -j1 DESTDIR="$pkgdir" install
	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/dbus
	rm -rf "$pkgdir"/usr/lib/systemd
}

dev() {
	provides="dbus-dev"

	default_dev
}

doc() {
	provides="dbus-doc"

	default_doc
}

libs() {
	pkgdesc="D-BUS access libraries"
	replaces="dbus"
	provides="dbus-libs"
	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/lib*.so.* "$subpkgdir"/usr/lib/
}

openrc() {
	provides="dbus-openrc"

	default_openrc
}

x11() {
	pkgdesc="X11 add-ons for D-BUS"
	depends="dbus=$pkgver-r$pkgrel"
	provides="dbus-x11"
	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/dbus-launch "$subpkgdir"/usr/bin/
}

sha512sums="27ae805170e9515a8bb0fba5f29d414edc70e3b6b28b7b65bbea47035b8eafa9ac4820cdc92645be6035f6748f8aa45679e1ffc84ba74a64859a3056d318b9bb  dbus-1.12.16.tar.gz
4c6beba2382416e60a3adfa85ef843d90d93ca5f38c23f573e058ffca6d4fc3850d11d40938c74383bba61599569b7fdfb1fcf3b9d2f1463e6b2e2cc81097c84  dbus-elogind.initd
113ce264dab48a303664fac54127b97be5167ab8096941299257034cdb6dbe0fd57890a66a42c985ab34c0f2af95cac9bb2d6b0e249d0a61d894631129dfc5a8  elogind_support.patch"
