.PHONY: srpm

# Invoked by Copr (srpm_build_method = make_srpm) as:
#   make -f .copr/Makefile srpm outdir=<resultdir> spec=<path-to-spec>
# There is no dist-git lookaside cache here, so we build the source
# tarball straight from the checkout instead of downloading it. Plain
# tar rather than `git archive`: Copr's srpm-build chroot has no git.
#
# *.png is tracked via Git LFS (see .gitattributes). Copr's outer git
# clone (done before this Makefile runs) has no git-lfs, so it only
# checks out the LFS pointer stubs. We fetch the real objects here.
srpm:
	mkdir -p "$(outdir)"
	command -v git >/dev/null 2>&1 || dnf install -y git
	command -v git-lfs >/dev/null 2>&1 || dnf install -y git-lfs
	git lfs install --local
	git lfs pull
	nv=$$(rpmspec -q --qf '%{NAME}-%{VERSION}\n' "$(spec)" | head -n1); \
	tar --exclude-vcs --transform "s,^\.,$$nv," -czf "$(outdir)/$$nv.tar.gz" .; \
	rpmbuild -bs \
		--define "_sourcedir $(outdir)" \
		--define "_srcrpmdir $(outdir)" \
		"$(spec)"
