summaryrefslogtreecommitdiffstats
path: root/Makefile
diff options
context:
space:
mode:
authorAlejandro Colomar <alx.manpages@gmail.com>2022-05-09 23:33:23 +0200
committerAlejandro Colomar <alx.manpages@gmail.com>2022-05-09 23:33:23 +0200
commitbedc31eb4eee4552abdcdeb27dd543e0f939b544 (patch)
treef32fffb605424748e932909eb0aafe2e4a2b3315 /Makefile
parent7c8dffbe931b960f06ce99fbf51ee5b6c677cbc0 (diff)
.gitignore, Makefile: Add targets to create distribution tarballs
Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile47
1 files changed, 43 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index 33d52c0..9f72e7f 100644
--- a/Makefile
+++ b/Makefile
@@ -4,10 +4,13 @@ MAKEFLAGS += --no-print-directory
MAKEFLAGS += --warn-undefined-variables
-package := grepc
+package := grepc
+DISTVERSION := $(shell git describe 2>/dev/null)
+DISTNAME := $(package)-$(DISTVERSION)
srcdir := .
+builddir := tmp
DESTDIR :=
prefix := /usr/local
exec_prefix := $(prefix)
@@ -33,13 +36,15 @@ BINDIRS := $(sort $(shell find $(BINDIR) -type d))
DOCDIRS := $(sort $(shell find $(DOCDIR) -type d))
MANDIRS := $(sort $(shell find $(MANDIR) -type d))
+_DIRS := $(sort $(builddir))
+
_bindirs := $(patsubst $(srcdir)/%,$(_exec_prefix)/%,$(BINDIRS))
_docdirs := $(patsubst $(srcdir)/%,$(_prefix)/%,$(DOCDIRS))
_mandirs := $(patsubst $(srcdir)/%,$(_prefix)/%,$(MANDIRS))
-_dirs := $(sort $(_bindir) $(_docdir) $(_mandir))
-_alldirs := $(sort $(_bindirs) $(_docdirs) $(_mandirs))
-_subdirs := $(filter-out $(_dirs),$(_alldirs))
+_dirs := $(sort $(_bindir) $(_docdir) $(_mandir))
+_alldirs := $(sort $(_bindirs) $(_docdirs) $(_mandirs))
+_subdirs := $(filter-out $(_dirs),$(_alldirs))
BIN := $(sort $(shell find $(BINDIR) -type f))
@@ -61,6 +66,7 @@ INSTALL := install
INSTALL_DIR := $(INSTALL) -d
INSTALL_PROGRAM := $(INSTALL)
INSTALL_DATA := $(INSTALL) -m 644
+MKDIR := mkdir -p
RM := rm
@@ -70,6 +76,11 @@ installdirs := $(foreach x,$(modules),installdirs-$(x))
uninstall := $(addprefix un,$(install))
+DISTFILE := $(builddir)/$(DISTNAME).tar
+compression := gz xz
+dist := $(foreach x,$(compression),dist-$(x))
+
+
.PHONY: all
all:
@@ -77,6 +88,9 @@ all:
.PHONY: install $(install)
.PHONY: installdirs $(installdirs)
.PHONY: uninstall $(uninstall)
+.PHONY: dist $(dist)
+.PHONY: dist-tar
+.PHONY: clean
.SECONDEXPANSION:
@@ -87,6 +101,9 @@ installdirs: $(installdirs)
$(installdirs): installdirs-%: $$(_%dirs)
uninstall: $(uninstall)
$(uninstall): uninstall-%: $$(_%_rm)
+dist: $(dist)
+$(dist): dist-%: $(DISTFILE).%
+dist-tar: $(DISTFILE)
$(_prog): $(_exec_prefix)/%: $(srcdir)/% Makefile | $$(@D)
@@ -97,6 +114,20 @@ $(_data): $(_prefix)/%: $(srcdir)/% Makefile | $$(@D)
$(info INSTALL $@)
$(INSTALL_DATA) -T $< $@
+$(DISTFILE): $(shell git ls-files 2>/dev/null) Makefile | $$(@D)
+ $(info TAR $@)
+ tar cf $@ -T /dev/null
+ git ls-files \
+ | xargs tar rf $@
+
+$(DISTFILE).gz: %.gz: % Makefile
+ $(info GZIP $@)
+ gzip -knf $<
+
+$(DISTFILE).xz: %.xz: % Makefile
+ $(info XZ $@)
+ xz -kf $<
+
$(_subdirs): | $$(@D)
$(info INSTALL $@/)
$(INSTALL_DIR) $@
@@ -105,10 +136,18 @@ $(_dirs):
$(info INSTALL $@/)
$(INSTALL_DIR) $@
+$(_DIRS):
+ $(info MKDIR $@/)
+ $(MKDIR) $@
+
%-rm:
$(info RM $*)
$(RM) $*
+clean:
+ $(info RM -rf $(builddir))
+ $(RM) -rf $(builddir)
+
V :=
$(V).SILENT: