# Contributor: TBK <alpine@jjtc.eu>
maintainer="lauren n. liberda <lauren@selfisekai.rocks>"
pkgname=gn
pkgver=0_git20250527
pkgrel=0
_commit=a84e399f9999003472192286abc03d752c9cb1f0
pkgdesc="Meta-build system that generates build files for Ninja"
arch="all"
url="https://gn.googlesource.com/gn"
license="BSD-3-Clause"
depends="samurai"
makedepends="python3 zstd"
# gitiles has no clones
source="https://ab-sn.lnl.gay/gn-$_commit.tar.zst
	"
builddir="$srcdir/gn"

_distbucket="sakamoto/lnl-aports-snapshots/"
snapshot() {
	clean
	deps
	mkdir -p "$srcdir" && cd "$srcdir"
	git clone https://gn.googlesource.com/gn
	(
		cd gn
		git checkout -q $_commit
		python3 ./build/gen.py
	)
	rm -rf gn/.git
	tar cf gn-$_commit.tar gn
	zstd --auto-threads=logical --ultra --long -22 -T"${ZSTD_LIMIT:-0}" -vv gn-$_commit.tar \
		-o "$SRCDEST"/gn-$_commit.tar.zst
	mcli cp "$SRCDEST"/gn-$_commit.tar.zst "$_distbucket"
}

build() {
	unset CFLAGS # all sources C++ but passes both
	# Breaks build since upstream passes -Wno-format,
	# annotated: "Use of %llx, which is supported by _UCRT, false positive"
	CXXFLAGS="${CXXFLAGS/-Werror=format-security} -flto=auto" \
	python3 ./build/gen.py \
		--no-last-commit-position \
		--no-static-libstdc++ \
		--no-strip \
		--allow-warnings
	ninja -C out
}

check() {
	./out/gn_unittests
}

package() {
	install -Dm755 out/gn "$pkgdir"/usr/bin/gn
}

sha512sums="
cfd9e0fb43ecd682d2ec88c86da13ba4ec7a99bd6cbe4034956af4c7e0fcfb981edd61775b18c2c75434d638388063190419df1e416d3652c2fac10cb717901d  gn-a84e399f9999003472192286abc03d752c9cb1f0.tar.zst
"
