help: make tg help tg work
[topgit/pro.git] / Makefile
blob8ea6a66bc7b95a30efa6cf4f24d030bbef67d34d
1 all::
3 prefix ?= $(HOME)
4 bindir = $(prefix)/bin
5 cmddir = $(prefix)/libexec/topgit
6 sharedir = $(prefix)/share/topgit
7 hooksdir = $(cmddir)/hooks
9 commands_in := $(wildcard tg-*.sh)
10 hooks_in = hooks/pre-commit.sh
12 commands_out = $(patsubst %.sh,%,$(commands_in))
13 hooks_out = $(patsubst %.sh,%,$(hooks_in))
14 help_out = $(patsubst %.sh,%.txt,$(commands_in))
16 version := $(shell test -d .git && git describe --match "topgit-[0-9]*" --abbrev=4 --dirty 2>/dev/null | sed -e 's/^topgit-//' )
18 -include config.mak
20 ifneq ($(strip $(version)),)
21 version_arg = -e s/TG_VERSION=.*/TG_VERSION=$(version)/
22 endif
24 .PHONY: FORCE
26 all:: precheck $(commands_out) $(hooks_out) $(help_out)
28 tg $(commands_out) $(hooks_out): % : %.sh Makefile TG-PREFIX
29 @echo "[SED] $@"
30 @sed -e 's#@cmddir@#$(cmddir)#g;' \
31 -e 's#@hooksdir@#$(hooksdir)#g' \
32 -e 's#@bindir@#$(bindir)#g' \
33 -e 's#@sharedir@#$(sharedir)#g' \
34 $(version_arg) \
35 $@.sh >$@+ && \
36 chmod +x $@+ && \
37 mv $@+ $@
39 $(help_out): README create-help.sh
40 @CMD=`echo $@ | sed -e 's/tg-//' -e 's/\.txt//'` && \
41 echo '[HELP]' $$CMD && \
42 ./create-help.sh $$CMD
44 precheck:: tg
45 ifeq ($(DESTDIR),)
46 ./$+ precheck
47 else
48 @echo skipping precheck because DESTDIR is set
49 endif
51 install:: all
52 install -d -m 755 "$(DESTDIR)$(bindir)"
53 install tg "$(DESTDIR)$(bindir)"
54 install -d -m 755 "$(DESTDIR)$(cmddir)"
55 install $(commands_out) "$(DESTDIR)$(cmddir)"
56 install -d -m 755 "$(DESTDIR)$(hooksdir)"
57 install $(hooks_out) "$(DESTDIR)$(hooksdir)"
58 install -d -m 755 "$(DESTDIR)$(sharedir)"
59 install -m 644 $(help_out) "$(DESTDIR)$(sharedir)"
60 install -m 644 README "$(DESTDIR)$(sharedir)/tg-tg.txt"
61 install -m 644 leaves.awk "$(DESTDIR)$(sharedir)"
63 clean::
64 rm -f tg $(commands_out) $(hooks_out) $(help_out)
65 rm -f TG-PREFIX
67 define TRACK_PREFIX
68 $(bindir):$(cmddir):$(hooksdir):$(sharedir):$(version)
69 endef
70 export TRACK_PREFIX
72 TG-PREFIX: FORCE
73 @if test x"$$TRACK_PREFIX" != x"`cat TG-PREFIX 2>/dev/null`"; then \
74 echo "* new prefix flags"; \
75 echo "$$TRACK_PREFIX" >TG-PREFIX; \