Makefile: make sure topgit.html updates when out of date
[topgit/pro.git] / Makefile
blob2c77dc6b728213664fa8ac46eeccfc7ccf4dcb79
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 version := $(shell test -d .git && git describe --match "topgit-[0-9]*" --abbrev=4 --dirty 2>/dev/null | sed -e 's/^topgit-//' )
27 -include config.mak
29 ifneq ($(strip $(version)),)
30 version_arg = -e s/TG_VERSION=.*/TG_VERSION=$(version)/
31 endif
33 .PHONY: FORCE
35 all:: precheck $(commands_out) $(hooks_out) $(help_out)
37 tg $(commands_out) $(hooks_out): % : %.sh Makefile TG-PREFIX
38 @echo "[SED] $@"
39 @sed -e 's#@cmddir@#$(cmddir)#g;' \
40 -e 's#@hooksdir@#$(hooksdir)#g' \
41 -e 's#@bindir@#$(bindir)#g' \
42 -e 's#@sharedir@#$(sharedir)#g' \
43 $(version_arg) \
44 $@.sh >$@+ && \
45 chmod +x $@+ && \
46 mv $@+ $@
48 $(help_out): README create-help.sh
49 @CMD=`echo $@ | sed -e 's/tg-//' -e 's/\.txt//'` && \
50 echo '[HELP]' $$CMD && \
51 ./create-help.sh $$CMD
53 .PHONY: html doc
55 doc:: html
57 html:: topgit.html $(html_out)
59 topgit.html: README create-html-usage.pl $(wildcard tg-*.sh)
60 @echo '[HTML] topgit'
61 @perl ./create-html-usage.pl < README | rst2html.py - $@
63 $(html_out): create-html.sh
64 @CMD=`echo $@ | sed -e 's/tg-//' -e 's/\.html//'` && \
65 echo '[HTML]' $$CMD && \
66 ./create-html.sh $$CMD
68 .PHONY: precheck
70 precheck:: tg
71 ifeq ($(DESTDIR),)
72 ./$+ precheck
73 else
74 @echo skipping precheck because DESTDIR is set
75 endif
77 .PHONY: install
79 install:: all
80 install -d -m 755 "$(DESTDIR)$(bindir)"
81 install tg "$(DESTDIR)$(bindir)"
82 install -d -m 755 "$(DESTDIR)$(cmddir)"
83 install $(commands_out) "$(DESTDIR)$(cmddir)"
84 install -d -m 755 "$(DESTDIR)$(hooksdir)"
85 install $(hooks_out) "$(DESTDIR)$(hooksdir)"
86 install -d -m 755 "$(DESTDIR)$(sharedir)"
87 install -m 644 $(help_out) "$(DESTDIR)$(sharedir)"
88 install -m 644 README "$(DESTDIR)$(sharedir)/tg-tg.txt"
89 install -m 644 leaves.awk "$(DESTDIR)$(sharedir)"
91 .PHONY: install-html
93 install-html:: html
94 install -d -m 755 "$(DESTDIR)$(sharedir)"
95 install -m 644 topgit.html $(html_out) "$(DESTDIR)$(sharedir)"
97 .PHONY: clean
99 clean::
100 rm -f tg $(commands_out) $(hooks_out) $(help_out) topgit.html $(html_out)
101 rm -f TG-PREFIX
103 define TRACK_PREFIX
104 $(bindir):$(cmddir):$(hooksdir):$(sharedir):$(version)
105 endef
106 export TRACK_PREFIX
108 TG-PREFIX: FORCE
109 @if test x"$$TRACK_PREFIX" != x"`cat TG-PREFIX 2>/dev/null`"; then \
110 echo "* new prefix flags"; \
111 echo "$$TRACK_PREFIX" >TG-PREFIX; \