# Maintainer: Integral <integral@member.fsf.org>
# Contributor: Grzegorz Koperwas <admin@grzegorzkoperwas.site>

pkgname=swww-git
_pkgname=${pkgname%-git}
pkgver=0.11.2.r59.g8a3b1bf
pkgrel=1
pkgdesc="Efficient animated wallpaper daemon for wayland, controlled at runtime."
arch=('x86_64' 'aarch64' 'riscv64')
url="https://github.com/LGFae/${_pkgname}"
license=('GPL-3.0-or-later')
depends=('gcc-libs' 'lz4' 'dav1d')
makedepends=('git' 'cargo' 'scdoc' 'wayland' 'wayland-protocols')
conflicts=("${_pkgname}")
provides=("${_pkgname}")
source=("git+${url}.git")
sha256sums=('SKIP')
options=(!lto)

pkgver() {
	cd "${_pkgname}/"
	git describe --long --tags --abbrev=7 | sed 's/\([^-]*-g\)/r\1/;s/-/./g;s/v//'
}

prepare() {
	cd "${_pkgname}/"
	cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
	cd "${_pkgname}/"
	cargo build --frozen --release --all-features

	# manpages
	./doc/gen.sh
	for page in $(ls ./doc/generated/*.1); do
		gzip -f "${page}"
	done
}

check() {
	cd "${_pkgname}/"
	cargo test --frozen --all-features
}

package() {
	cd "${_pkgname}/"

	install -Dm755 target/release/{swww,swww-daemon} -t "${pkgdir}/usr/bin/"
	install -Dm644 "completions/swww.bash" "${pkgdir}/usr/share/bash-completion/completions/swww"
	install -Dm644 "completions/swww.fish" -t "${pkgdir}/usr/share/fish/vendor_completions.d/"
	install -Dm644 "completions/_swww" -t "${pkgdir}/usr/share/zsh/site-functions/"
	install -Dm644 "README.md" -t "${pkgdir}/usr/share/doc/${_pkgname}/"

	# manpages
	cd ./doc/generated
	for page in $(ls *.1.gz); do
		install -Dm644 "${page}" "${pkgdir}/usr/share/man/man1/${page}"
	done
}
