[RFC v3 3/3] Makefile: dist: Add target to create distribution archives

Alejandro Colomar
2022-04-16T13:04:02Z

Other subtargets are also created, with the obvious results:
dist-tar, dist-gz, and dist-xz.

Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
---

v2: Fix some accidents (forgot to send this one to the list)
v3: Simplify

Makefile | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)

diff --git a/Makefile b/Makefile
index 38ea89c69..889e356b3 100644
--- a/Makefile
+++ b/Makefile
@@ -316,6 +316,47 @@ uninstall-man: $(_mandir_rmdir) $(uninstall_manX)
@:

+########################################################################
+# dist
+
+DISTNAME := $(shell git describe 2>/dev/null)
+DISTFILE := $(builddir)/$(DISTNAME).tar
+compression := gz xz
+dist := $(foreach x,$(compression),dist-$(x))
+
+
+$(DISTFILE): $(shell git ls-files) | $$(@D)/.
+ $(info TAR $@)
+ tar cf $@ -T /dev/null
+ git ls-files \
+ | xargs tar rf $@
+
+$(DISTFILE).gz: %.gz: % | $$(@D)/.
+ $(info GZIP $@)
+ gzip -knf $<
+
+$(DISTFILE).xz: %.xz: % | $$(@D)/.
+ $(info XZ $@)
+ xz -kf $<
+
+
+.PHONY: dist-tar
+dist-tar: $(DISTFILE) | builddirs-dist
+ @:
+
+.PHONY: $(dist)
+$(dist): dist-%: $(DISTFILE).% | builddirs-dist
+ @:
+
+.PHONY: builddirs-dist
+builddirs-dist: $(builddir)/.
+ @:
+
+.PHONY: dist
+dist: $(dist)
+ @:
+
+
########################################################################
# src

--
2.30.2