# Maintainer: Integral <integral@member.fsf.org>
# Contributor: Frederik Schwan <freswa at archlinux dot org>
# Contributor: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: Josip Ponjavic <josipponjavic at gmail dot com>

pkgname=i3status-rust-git
_pkgname=${pkgname%-git}
pkgver=0.36.1.r31.g05b195e
pkgrel=1
pkgdesc='Resourcefriendly and feature-rich replacement for i3status, written in pure Rust'
arch=('x86_64' 'aarch64' 'riscv64')
url="https://github.com/greshake/${_pkgname}"
license=('GPL-3.0-or-later')
depends=('libpipewire' 'libpulse' 'lm_sensors' 'notmuch-runtime')
makedepends=('git' 'clang' 'cargo' 'pandoc')
optdepends=('alsa-utils: for the volume block'
	'bluez: for the bluetooth block'
	'fakeroot: for the pacman block to show pending updates'
	'kdeconnect: for the kdeconnect block'
	'powerline-fonts: for all themes using the Powerline arrow char'
	'pulseaudio: for the volume block'
	'speedtest-cli: for the speedtest block'
	'ttf-font-awesome: for the awesome icons'
	'upower: for the battery block')
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
	cargo xtask generate-manpage
}

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

package() {
	cd "${_pkgname}/"
	install -Dm755 "target/release/i3status-rs" -t "${pkgdir}/usr/bin/"
	install -Dm644 "man/i3status-rs.1" -t "${pkgdir}/usr/share/man/man1/"

	install -d "${pkgdir}/usr/share/${_pkgname}/"
	cp -r files/* "${pkgdir}/usr/share/${_pkgname}/"

	install -d "${pkgdir}/usr/share/doc/${_pkgname}/"
	cp -r doc/* "${pkgdir}/usr/share/doc/${_pkgname}/"
}
