maintainer="Hoang Nguyen <folliekazetani@protonmail.com>"
pkgname=lima
pkgver=1.0.7
pkgrel=2
pkgdesc="Linux virtual machine launcher focusing on running containers"
url="https://lima-vm.io/"
# The only supported binary builds.
# VM templates support x86_64, aarch64, armv7 and riscv64 architectures.
arch="x86_64 aarch64"
license="Apache-2.0"
makedepends="go"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	$pkgname-guestagent:_guestagent
	"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/lima-vm/lima/archive/refs/tags/v$pkgver.tar.gz
	vendor-$pkgver.tar.gz::https://github.com/lima-vm/lima/releases/download/v$pkgver/lima-$pkgver-go-mod-vendor.tar.gz
	"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

prepare() {
	default_prepare

	cp -r "$srcdir"/vendor "$builddir"/
}

build() {
	for binary in limactl lima-guestagent; do
		go build -v \
			-ldflags "-X github.com/lima-vm/lima/pkg/version.Version=v$pkgver" \
			./cmd/$binary/
	done

	for shell in bash fish zsh; do
		./limactl completion $shell > limactl.$shell
	done

	mkdir -p "$builddir"/man
	./limactl generate-doc man
}

check() {
	go test ./...
}

package() {
	install -Dm755 \
		-t "$pkgdir"/usr/bin/ \
		limactl \
		lima-guestagent \
		cmd/apptainer.lima \
		cmd/docker.lima \
		cmd/kubectl.lima \
		cmd/lima \
		cmd/nerdctl.lima \
		cmd/podman.lima

	install -Dm644 man/*.1 -t "$pkgdir"/usr/share/man/man1/

	install -d "$pkgdir"/usr/share/doc/lima
	cp -r templates/ "$pkgdir"/usr/share/doc/lima/

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

_guestagent() {
	pkgdesc="Lima guest agent"
	amove usr/bin/lima-guestagent
}

sha512sums="
4d59e2708fc4d19b1180e5e30cda4a54a8c6d09f7cdd8e3a7bd45e9f24028825acf721da5fa9186d111d576e787a9363cbf728c3296f4317d5c4f0147d043702  lima-1.0.7.tar.gz
7b92f0414dd20f97414af869d1478c8cab19a7a471a0ece375b479503f88b4b717ea7a9d4535c7aa2cb6650fe1d8dd251a33e32d96debf884f78e1d17c96d7b9  vendor-1.0.7.tar.gz
"
