Makefile: add a dist target to generate a tarball

This commit is contained in:
Maxime Coste 2018-04-09 12:56:17 +10:00
parent 6686d5513e
commit fc86acd9f0

View File

@ -20,6 +20,8 @@ else
endif
endif
version ?= $(shell if [ -f .version ]; then cat .version; elif [ -d ../.git ]; then git rev-parse --short HEAD; else echo "unknown"; fi )
sources := $(sort $(wildcard *.cc))
objects := $(addprefix ., $(sources:.cc=$(suffix).o))
deps := $(addprefix ., $(sources:.cc=$(suffix).d))
@ -75,14 +77,21 @@ all : kak
kak : kak$(suffix)
ln -sf $< $@
kak$(suffix) : $(objects)
$(CXX) $(LDFLAGS) $(CXXFLAGS) $(objects) $(LIBS) -o $@
kak$(suffix) : $(objects) .version.o
$(CXX) $(LDFLAGS) $(CXXFLAGS) $(objects) .version.o $(LIBS) -o $@
-include $(deps)
.%$(suffix).o: %.cc
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -MD -MP -MF $(addprefix ., $(<:.cc=$(suffix).d)) -c -o $@ $<
.version.o: .version.cc
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
.version.cc: FORCE
@printf "%s" 'namespace Kakoune { const char* version = "$(version)"; }' > .version.cc.tmp
@if cmp -s .version.cc.tmp .version.cc; then rm .version.cc.tmp; else mv .version.cc.tmp .version.cc; fi
# Generate the man page
ifeq ($(gzip_man),yes)
../doc/kak.1.gz: ../doc/kak.1.asciidoc
@ -106,6 +115,16 @@ tags:
clean:
rm -f .*.o .*.d
dist:
@if ! [ -d ../.git ]; then echo "make dist can only run from a git repo"; false; fi
@if git status -s | grep -qEv '^\?\?'; then echo "working tree is not clean"; false; fi
cd ../; \
git archive --format=tar --prefix=kakoune-$(version)/ HEAD -o kakoune-$(version).tar; \
echo "$(version)" > src/.version; \
tar --transform "s,^,kakoune-$(version)/," -rf kakoune-$(version).tar src/.version; \
rm src/.version; \
bzip2 kakoune-$(version).tar;
distclean: clean
rm -f kak kak$(suffix)
find ../doc -type f \( -name \*\\.gz -o -name \*\\.1 \) -exec rm -f '{}' +
@ -146,5 +165,5 @@ uninstall:
$(mandir)/kak.1.gz \
$(mandir)/kak.1
.PHONY: check TAGS clean distclean installdirs install install-strip uninstall
.PHONY: tags test man kak
.PHONY: check TAGS clean dist distclean installdirs install install-strip uninstall
.PHONY: tags test man kak FORCE