# Contributer: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=slim
pkgver=1.4.1
pkgrel=1
pkgdesc="Desktop-independent graphical login manager for X11"
url="https://sourceforge.net/projects/slim-fork"
arch="all"
license="GPL-2.0-or-later"
options="!check"
subpackages="$pkgname-doc $pkgname-openrc"
makedepends="libxmu-dev libpng-dev libjpeg-turbo-dev libxft-dev
	cmake libxrandr-dev samurai"
depends="dbus"
source="https://downloads.sourceforge.net/project/slim-fork/slim-$pkgver.tar.gz
	https://dev.alpinelinux.org/~clandmeter/sources/slim-alpinelinux-0.2.0.tar.gz
	$pkgname.logrotate
	$pkgname.initd

	fix-include-on-musl.patch
	"

prepare() {
	default_prepare
	sed -i -e 's|#xserver_arguments.*|xserver_arguments   -nolisten tcp vt07|'\
		-e 's|/var/run/slim.lock|/var/lock/slim.lock|' \
		-e 's|halt_cmd.*|halt_cmd            /sbin/poweroff|'\
		-e 's|reboot_cmd.*|reboot_cmd          /sbin/reboot|'\
		-e 's|console_cmd.*|console_cmd         /usr/bin/terminal|'\
		-e 's|login_cmd.*|login_cmd           exec /bin/sh -l /etc/X11/xinit/xinitrc|' \
		-e 's|screenshot_cmd.*|screenshot_cmd      scrot /slim.png|' \
		-e 's|imagemagick|scrot|' \
		-e 's|current_theme.*|current_theme       alpinelinux|' \
		slim.conf
}

build() {
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_SKIP_RPATH=ON \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DUSE_PAM=no \
		-DUSE_CONSOLEKIT=no

	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	install -D -m755 ../slim.initd "$pkgdir"/etc/init.d/slim
	install -D -m644 ../slim.logrotate "$pkgdir"/etc/logrotate.d/slim

	# remove unused systemd service
	rm -rf "$pkgdir"/lib/systemd

	# install our default theme
	cd "$srcdir"/slim-alpinelinux
	install -d "$pkgdir"/usr/share/slim/themes/alpinelinux
	cp background.png panel.png slim.theme \
		"$pkgdir"/usr/share/slim/themes/alpinelinux/
	rm -rf "$pkgdir"/usr/share/slim/themes/default
	rm -rf "$pkgdir"/usr/share/slim/themes/original
}

sha512sums="
23fd8b60567b89783072f0e76e07a24ef2d2d8462b8a51939045494ec5fd69c9be663d0d2e69079ee692114076a5b32821b727c2b30a667a3ccc90b5a725cb3e  slim-1.4.1.tar.gz
3cd3de67e5b1e122da05e02e0e6e8fe2c5a1ae07487e51068aa56ddf05d17854562350ef47c914a2c9fb2534b8f757a326cfed64f4b5ddbbeb18e48af43b46c6  slim-alpinelinux-0.2.0.tar.gz
e5f398ea58adbedea7ae40c7a907d2f926148ee6f3c51fc5761b84d1d119c091fa0cf34f908cd49300fcddea71c5c9b6f2ac21731808ce5d73ea65a65b19a55b  slim.logrotate
bb040b7d4ba0c8ba1e0892ce6f3edbf85a31c38fab7389658fc593ef50a28b02947c3b055d09de3e538626caa66de08cb6618bafb490c4c56d0c8b069839b3d6  slim.initd
c3e65b4d113c7e59acdb8ff9e34918942c9b752e2cc12271e24d9e2dd37dfa9114f4ed98c3b20d12fb0f0772cde8dd3f960896ae6d6a8f58aa67329a16527d21  fix-include-on-musl.patch
"
