maintainer="Hoang Nguyen <folliekazetani@protonmail.com>"
pkgname=stacker
pkgver=1.0.0
pkgrel=5
pkgdesc="Tool for building OCI images natively via declarative YAML format"
url="https://stackerbuild.io/"
# 32-bit platforms: machinerun.io/atomfs/squashfs module fails to build
# s390x: fails to build stackerbuild.io/stacker/pkg/stacker (cast st.Type of type uint32 to int64)
arch="all !x86 !armhf !armv7 !s390x"
license="Apache-2.0"
makedepends="
	go
	acl-dev
	cryptsetup-dev
	lxc-dev
	zstd-dev
	"
checkdepends="
	cryptsetup
	squashfs-tools
	"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/project-stacker/stacker/archive/refs/tags/v$pkgver.tar.gz
	update-go-modules.patch
	basename_patch
	memfd_patch
	"
options="net" # download Go modules

prepare() {
	default_prepare

	go mod vendor -v
	patch -p1 -i "$srcdir"/basename_patch
	patch -p1 -i "$srcdir"/memfd_patch
}

build() {
	make -C cmd/stacker/lxc-wrapper LDLIBS="$(pkg-config --libs lxc) -lpthread -ldl" lxc-wrapper

	go build -v \
		-tags exclude_graphdriver_btrfs,exclude_graphdriver_devicemapper,containers_image_openpgp,osusergo,netgo,external_libzstd \
		-ldflags "-X stackerbuild.io/stacker/pkg/lib.StackerVersion=v$pkgver -X stackerbuild.io/stacker/pkg/lib.LXCVersion=$(pkg-config --modversion lxc)" \
		./cmd/stacker
}

check() {
	go test \
		-tags exclude_graphdriver_btrfs,exclude_graphdriver_devicemapper,containers_image_openpgp,osusergo,netgo,skipembed \
		./pkg/... ./cmd/...
}

package() {
	install -Dm755 stacker -t "$pkgdir"/usr/bin/
	install -Dm644 doc/*.md -t "$pkgdir"/usr/share/doc/$pkgname/
}

sha512sums="
22b764d9a3fc20fcd10dd0dc4fd5a49b65d20e32a9d47a66d122e0cc61fe680ddefc9f9ebdfefcf7dca964c497a18239f4b59121a3038aae1c246629639271d4  stacker-1.0.0.tar.gz
1086ad907c3c4a4d6f96354679aa25970d6ca0315ac1308ebedef017335ec844098bd02ff5e09c73cedfed915bef618ea51fb33b4e710ca079afd7e7059649b5  update-go-modules.patch
244683637d8fa5a8bd100f12d8d19cdd566b95e7742f28fc8a2ada3a2408f4dd18ab18666e86e25ee6a38f99d7821af366eaefedec866423cbf386cc1fc43f69  basename_patch
67d9e5a25608334d6ebb6c00afa3878b82cd68c0230cc22d427b17aa7681177383ec54c9a8022fb7c764a87756a8edbac25aa64004d01ab899afce2cf2b2f2c6  memfd_patch
"
