# Forked from Alpine to enable systemd support
maintainer="Bart Ribbers <bribbers@disroot.org>"
pkgname=dsme
_pkgver=0.84.8
pkgver=9999$_pkgver
pkgrel=0
_commit_dbusglib="d42176ae4763e5288ef37ea314fe58387faf2005"
pkgdesc="Device State Management Entity"
url="https://github.com/sailfishos/dsme"
# armhf: pmb#2618
arch="all !armhf"
license="LGPL-2.1-only"
depends_dev="
	cryptsetup-dev
	libiphb-dev
	libngf-dev
	"
makedepends="$depends_dev
	autoconf
	automake
	libtool
	systemd-dev
	"
subpackages="$pkgname-dev $pkgname-openrc $pkgname-systemd"
source="https://github.com/sailfishos/dsme/archive/$_pkgver/dsme-$_pkgver.tar.gz
	https://github.com/sailfishos-mirror/dbus-glib/archive/$_commit_dbusglib/dbus-glib-$_commit_dbusglib.tar.gz
	0001-correct-paths.patch
	0002-disable-werror.patch
	dsme.initd
	dsme.confd
	"
options="!check" # Only test comes from dbus-glib and fails

builddir="$srcdir/$pkgname-$_pkgver"

prepare() {
	default_prepare

	rmdir dbus-gmain
	mv "$srcdir/dbus-glib-$_commit_dbusglib" dbus-gmain
}

build() {
	./autogen.sh
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--exec_prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--disable-static \
		--disable-poweron-timer \
		--disable-upstart \
		--disable-validatorlistener \
		--enable-pwrkeymonitor \
		--enable-abootsettings \
		--enable-usewheel \
		--enable-systemd
	make
}

package() {
	make DESTDIR="$pkgdir" install
	install -Dm644 reboot-via-dsme.sh -t "$pkgdir"/etc/profile.d/

	install -Dm755 "$srcdir"/dsme.initd "$pkgdir"/etc/init.d/dsme
	install -Dm644 "$srcdir"/dsme.confd "$pkgdir"/etc/conf.d/dsme

	# Remove installed tests
	rm -r "$pkgdir"/opt

	mkdir -p "$pkgdir"/usr/share/dbus-1/system.d/
	mv "$pkgdir"/etc/dbus-1/system.d/* "$pkgdir"/usr/share/dbus-1/system.d/

	mkdir -p "$pkgdir"/usr/lib/systemd/system
	sed -e "s|@LIBDIR@|/usr/lib|g" rpm/dsme.service.in > "$pkgdir"/usr/lib/systemd/system/dsme.service
}

sha512sums="
eb9b93ca23d0fb295f590a85c8ea301c74088bca50ef8788070e21b7c668fde36c763bf88aa48c33117fa6a5bedf65667c014830f6e1fd4ba10b314f75ffc44c  dsme-0.84.8.tar.gz
665cd6395ee0ea14086ba30188c62a72697b3f63484681e18fc7f54109c9aca162f2e33aa2fa4d45287c6c0b590e81ca310c143dac0232cd5887692cdaf51256  dbus-glib-d42176ae4763e5288ef37ea314fe58387faf2005.tar.gz
063ce9f2bd13fb2bd05ab9cd11544265eb5378562ee1fbed1cfa65d2345d092cfcff69f57589d3914005c31a00a58f3993cc13b59615ebe0f48458ba478d8772  0001-correct-paths.patch
2b18c6affaefa786358c07480968fd744370c48452c05e969cc8b26cba5307279ce51f782f42778fbd597bf29ec3d90b7b1ee4d182e8ab41675d1070be2f1954  0002-disable-werror.patch
786971b4a8f9cff0b66db658d9b8a2c4ceaaf1c5baa4b62346b9e0a2ab6f46ff3225a60678cb7ddd78e4e9e70fbe41432581e32ebccfa4174375dc79fea49a84  dsme.initd
b841282b96110ec59a7aa539db0737327b09549d55c78dc4b2c3b28b4a6ad1facf015b3175cb6d3a38f13e47aa6314ef3dc1514a4e60dd653a97409ec54ba706  dsme.confd
"
