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

Alejandro Colomar
2022-04-15T23:31:04Z

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>
---
Makefile | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)

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

+########################################################################
+# dist
+#
+# Do NOT use `make -j` with dist targets:
+# <https://www.gnu.org/software/make/manual/html_node/Archive-Pitfalls.html#Archive-Pitfalls>.
+
+PKGNAME := man-pages
+DISTVERSION := $(shell git describe | sed 's/^man-pages-//')
+DISTNAME := $(PKGNAME)-$(DISTVERSION)
+DISTSRC := $(sort $(shell git ls-files $(srcdir)))
+DISTFILE := $(builddir)/$(DISTNAME).tar
+compression := gz xz
+dist := $(sort $(foreach x,$(compression),dist-$(x)))
+
+
+$(DISTFILE): $(DISTSRC) | $$(@D)/.
+ $(info TAR $@)
+ tar cf $@ -T /dev/null
+
+$(DISTFILE)($(DISTSRC)): $% $(DISTFILE) | $$(@D)/.
+ $(info TAR $@($%))
+ tar rf $@ $%
+
+$(DISTFILE).gz: $(DISTFILE)($(DISTSRC)) | $$(@D)/.
+ $(info GZIP $@)
+ gzip -kn $<
+
+$(DISTFILE).xz: $(DISTFILE)($(DISTSRC)) | $$(@D)/.
+ $(info XZ $@)
+ xz -k $<
+
+
+.PHONY: dist-tar
+dist-tar: $(DISTFILE)($(DISTSRC)) | builddirs-dist
+ @:
+
+.PHONY: $(dist)
+$(dist): dist-%: $(DISTFILE).% | builddirs-dist
+ @:
+
+.PHONY: builddirs-dist
+builddirs-dist: $(builddir)/.
+ @:
+
+.PHONY: dist
+dist: $(dist)
+ @:
+
+
########################################################################
# src

--
2.30.2