# Contributor: guddaff <guddaff@protonmail.com>
# Maintainer: guddaff <guddaff@protonmail.com>
pkgname=ouch
pkgver=0.6.1
pkgrel=0
pkgdesc="Painless compression and decompression"
url="https://github.com/ouch-org/ouch"
arch="all"
license="MIT"
makedepends="
	bzip2-dev
	cargo
	cargo-auditable
	clang-libclang
	xz-dev
	zlib-dev
	zstd-dev
	"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/ouch-org/ouch/archive/refs/tags/$pkgver.tar.gz
	use-system-libs.patch
	"

prepare() {
	default_prepare
	cargo fetch --target="$CTARGET" --locked
}

build() {
	OUCH_ARTIFACTS_FOLDER=artifacts \
		cargo auditable build --frozen --release
}

check() {
	case "$CARCH" in
	x86)
		# GCC 14.2.0 internal error while building unrar_sys
		# may be fixed in later versions, but Clang is fine.
		cargo test --frozen --release
		;;
	*)
		cargo test --frozen
		;;
	esac
}

package() {
	install -Dm755 target/release/ouch -t "$pkgdir"/usr/bin/

	cd artifacts/
	install -Dm644 ouch.1 ouch-list.1 ouch-compress.1 ouch-decompress.1 \
		-t "$pkgdir"/usr/share/man/man1/

	install -Dm644 ouch.bash \
		"$pkgdir"/usr/share/bash-completion/completions/ouch
	install -Dm644 ouch.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/ouch.fish
	install -Dm644 _ouch \
		"$pkgdir"/usr/share/zsh/site-functions/_ouch
}

sha512sums="
53bd164230739640de9c79deb6d34c72daf80908eaf1040c69f92af8c3d247dfeee3e2f3daaecfc027f3df21d36ad82e6f8cc9a2ec8d7f2290bbdbeb350fe60b  ouch-0.6.1.tar.gz
20762726d612a607f2e2cacfc34d87a7cf2e80e1d812798613e38869e5cc2ab5c6e54a70a6f35b5def4fce8ae4c789ec456b23118ccf75fd33b50ae2898cb8c7  use-system-libs.patch
"
