# Maintainer: <your name> <your email>
# Contributor: <your name> <your email>

pkgname=sjcopy
pkgver=0.1.0
pkgrel=1
pkgdesc='Copy terminal output to named, automatically expiring stores (copy) and read it back byte-exact (paste)'
arch=('x86_64')
# Set this to the actual repository URL.
url='https://example.org/sjcopy'
license=('MIT')
depends=('gcc-libs')
makedepends=('cargo')
checkdepends=()
source=("$pkgname-$pkgver.tar.gz::$url/archive/v$pkgver.tar.gz")
sha256sums=('# TODO: fill in with makepkg -g')
# Binaries must not be installed as "copy"/"paste": "paste" collides with
# GNU coreutils in /usr/bin. The sj prefix matches the README's naming advice.
_sjbin_prefix='sj'

prepare() {
	cd "$pkgname-$pkgver"
	cargo fetch --locked --target "$CARCH-unknown-linux-gnu"
}

build() {
	cd "$pkgname-$pkgver"
	export RUSTUP_TOOLCHAIN=stable
	export CARGO_TARGET_DIR="$srcdir/target"
	cargo build --frozen --release --target "$CARCH-unknown-linux-gnu"
}

check() {
	cd "$pkgname-$pkgver"
	export RUSTUP_TOOLCHAIN=stable
	export CARGO_TARGET_DIR="$srcdir/target"
	cargo test --frozen --release --target "$CARCH-unknown-linux-gnu"
}

package() {
	cd "$pkgname-$pkgver"

	install -Dt "$pkgdir/usr/bin" -m 0755 \
		"$srcdir/target/$CARCH-unknown-linux-gnu/release/copy"
	install -Dt "$pkgdir/usr/bin" -m 0755 \
		"$srcdir/target/$CARCH-unknown-linux-gnu/release/paste"

	mv "$pkgdir/usr/bin/copy" "$pkgdir/usr/bin/${_sjbin_prefix}copy"
	mv "$pkgdir/usr/bin/paste" "$pkgdir/usr/bin/${_sjbin_prefix}paste"

	# Only valid once a LICENSE file exists at the project root. With
	# license=('MIT') and no license file, makepkg/lint will complain.
	if [[ -f LICENSE ]]; then
		install -Dt "$pkgdir/usr/share/licenses/$pkgname" -m 0644 LICENSE
	fi
}
