.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.
srpm:
	mkdir -p "$(outdir)"
	nv=$$(rpmspec -q --qf '%{NAME}-%{VERSION}\n' "$(spec)" | head -n1); \
	tar --exclude-vcs --exclude=./target --transform "s,^\.,$$nv," -czf "$(outdir)/$$nv.tar.gz" .; \
	rpmbuild -bs \
		--define "_sourcedir $(outdir)" \
		--define "_srcrpmdir $(outdir)" \
		"$(spec)"
