# Maintainer: fossdd <fossdd@pwned.life>

pkgname=redlib-git
_pkgname=${pkgname%-git}
pkgver=0.36.0.r56.ga4d36e9
pkgrel=1
pkgdesc="Private front-end for Reddit"
url="https://github.com/${_pkgname}-org/${_pkgname}"
license=('AGPL-3.0-or-later')
arch=('x86_64' 'aarch64' 'riscv64')
makedepends=('git' 'cargo' 'clang' 'cmake')
provides=("${_pkgname}")
conflicts=("${_pkgname}")
backup=("etc/${_pkgname}.conf")
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 --target "$(rustc -vV | sed -n 's/host: //p')"
}

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

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

	install -Dm755 "target/release/${_pkgname}" -t "${pkgdir}/usr/bin/"

	install -Dm644 LICENSE -t "${pkgdir}/usr/share/licenses/${_pkgname}/"
	install -Dm644 README.md -t "${pkgdir}/usr/share/doc/${_pkgname}/"

	install -Dm644 "contrib/${_pkgname}.service" -t "${pkgdir}/usr/lib/systemd/system/"
	install -Dm644 "contrib/${_pkgname}.conf" -t "${pkgdir}/etc/"
}
