# Template file for 'atuin'
pkgname=atuin
version=18.13.3
revision=1
build_style=cargo
build_helper=qemu
make_check_args="--
 --skip registration
 --skip sync
 --skip change_password
 --skip multi_user_test"
make_install_args="--path crates/atuin"
hostmakedepends="pkg-config sqlite-devel"
makedepends="sqlite-devel"
short_desc="Magical shell history"
maintainer="Orphaned <orphan@voidlinux.org>"
license="MIT"
homepage="https://atuin.sh"
changelog="https://raw.githubusercontent.com/atuinsh/atuin/main/CHANGELOG.md"
distfiles="https://github.com/atuinsh/atuin/archive/refs/tags/v${version}.tar.gz"
checksum=f16f43e373808e58b9645772359de662f082757e6ae350d767e360dc2a420e75

_setup_env() {
	# workaround the cc-rs mixing CFLAGS for host and target.
	# https://github.com/rust-lang/cc-rs/issues/1469
	export CFLAGS_${RUST_BUILD//-/_}="${CFLAGS_host}" \
			CXXFLAGS_${RUST_BUILD//-/_}="${CXXFLAGS_host}" \
			LDFLAGS_${RUST_BUILD//-/_}="${LDFLAGS_host}" \
			CFLAGS_${RUST_TARGET//-/_}="${CFLAGS}" \
			CXXFLAGS_${RUST_TARGET//-/_}="${CXXFLAGS}" \
			LDFLAGS_${RUST_TARGET//-/_}="${LDFLAGS}" \
			CFLAGS="" CXXFLAGS="" LDFLAGS=""
}

pre_build() {
	_setup_env
}

pre_install() {
	_setup_env
}

post_install() {
	vlicense LICENSE

	for shell in bash fish zsh; do
		vtargetrun "${DESTDIR}/usr/bin/atuin" gen-completion --shell ${shell} > atuin.${shell}
		vcompletion atuin.${shell} ${shell}
	done
}
