tg: include usage lines in `tg help tg` output
[topgit/pro.git] / Makefile
blobb916d68124f081b9efae719d64880237ccf983c0
1 # NOTE: Requires GNU make
3 all::
5 # This should give a reasonable hint that GNU make is required in non-GNU make
6 .error GNU_make_is_required:
8 # This should be fatal in non-GNU make
9 export MAKE
11 prefix ?= $(HOME)
12 bindir = $(prefix)/bin
13 cmddir = $(prefix)/libexec/topgit
14 sharedir = $(prefix)/share/topgit
15 hooksdir = $(cmddir)/hooks
17 commands_in := $(wildcard tg-*.sh)
18 hooks_in = hooks/pre-commit.sh
20 commands_out = $(patsubst %.sh,%,$(commands_in))
21 hooks_out = $(patsubst %.sh,%,$(hooks_in))
22 help_out = $(patsubst %.sh,%.txt,tg-help.sh $(commands_in))
23 html_out = $(patsubst %.sh,%.html,tg-help.sh tg-tg.sh $(commands_in))
25 ifndef SHELL_PATH
26 SHELL_PATH = /bin/sh
27 endif
28 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
30 version := $(shell test -d .git && git describe --match "topgit-[0-9]*" --abbrev=4 --dirty 2>/dev/null | sed -e 's/^topgit-//' )
32 -include config.mak
33 SHELL = $(SHELL_PATH)
35 ifneq ($(strip $(version)),)
36 version_arg = -e s/TG_VERSION=.*/TG_VERSION=$(version)/
37 endif
39 .PHONY: FORCE
41 all:: shell_compatibility_test precheck $(commands_out) $(hooks_out) $(help_out) tg-tg.txt
43 please_set_SHELL_PATH_to_a_more_modern_shell:
44 @$$(:)
46 shell_compatibility_test: please_set_SHELL_PATH_to_a_more_modern_shell
48 tg $(commands_out) $(hooks_out): % : %.sh Makefile TG-PREFIX
49 @echo "[SED] $@"
50 @sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
51 -e 's#@cmddir@#$(cmddir)#g;' \
52 -e 's#@hooksdir@#$(hooksdir)#g' \
53 -e 's#@bindir@#$(bindir)#g' \
54 -e 's#@sharedir@#$(sharedir)#g' \
55 -e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
56 $(version_arg) \
57 $@.sh >$@+ && \
58 chmod +x $@+ && \
59 mv $@+ $@
61 $(help_out): README create-help.sh
62 @CMD=`echo $@ | sed -e 's/tg-//' -e 's/\.txt//'` && \
63 echo '[HELP]' $$CMD && \
64 $(SHELL_PATH) ./create-help.sh $$CMD
66 .PHONY: doc install-doc html
68 doc:: html
70 install-doc:: install-html
72 html:: topgit.html $(html_out)
74 tg-tg.txt: README create-html-usage.pl $(wildcard tg-*.sh)
75 @echo '[HELP] tg'
76 @perl ./create-html-usage.pl --text < README > $@
78 topgit.html: README create-html-usage.pl $(wildcard tg-*.sh)
79 @echo '[HTML] topgit'
80 @perl ./create-html-usage.pl < README | rst2html.py - $@
82 $(html_out): create-html.sh
83 @CMD=`echo $@ | sed -e 's/tg-//' -e 's/\.html//'` && \
84 echo '[HTML]' $$CMD && \
85 $(SHELL_PATH) ./create-html.sh $$CMD
87 .PHONY: precheck
89 precheck:: tg
90 ifeq ($(DESTDIR),)
91 ./$+ precheck
92 else
93 @echo skipping precheck because DESTDIR is set
94 endif
96 .PHONY: install
98 install:: all
99 install -d -m 755 "$(DESTDIR)$(bindir)"
100 install tg "$(DESTDIR)$(bindir)"
101 install -d -m 755 "$(DESTDIR)$(cmddir)"
102 install $(commands_out) "$(DESTDIR)$(cmddir)"
103 install -d -m 755 "$(DESTDIR)$(hooksdir)"
104 install $(hooks_out) "$(DESTDIR)$(hooksdir)"
105 install -d -m 755 "$(DESTDIR)$(sharedir)"
106 install -m 644 $(help_out) tg-tg.txt "$(DESTDIR)$(sharedir)"
107 install -m 644 leaves.awk "$(DESTDIR)$(sharedir)"
109 .PHONY: install-html
111 install-html:: html
112 install -d -m 755 "$(DESTDIR)$(sharedir)"
113 install -m 644 topgit.html $(html_out) "$(DESTDIR)$(sharedir)"
115 .PHONY: clean
117 clean::
118 rm -f tg $(commands_out) $(hooks_out) $(help_out) topgit.html $(html_out)
119 rm -f TG-PREFIX
121 define TRACK_PREFIX
122 $(bindir):$(cmddir):$(hooksdir):$(sharedir):$(SHELL_PATH):$(version)
123 endef
124 export TRACK_PREFIX
126 TG-PREFIX: FORCE
127 @if test x"$$TRACK_PREFIX" != x"`cat TG-PREFIX 2>/dev/null`"; then \
128 echo "* new prefix flags"; \
129 echo "$$TRACK_PREFIX" >TG-PREFIX; \