tg-checkout.sh: make "goto" optional
[topgit/pro.git] / Makefile
blob8ffb55bc5b20b844ca88284fac6c31be03eec9e9
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)
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: html doc
68 doc:: html
70 html:: topgit.html $(html_out)
72 topgit.html: README create-html-usage.pl $(wildcard tg-*.sh)
73 @echo '[HTML] topgit'
74 @perl ./create-html-usage.pl < README | rst2html.py - $@
76 $(html_out): create-html.sh
77 @CMD=`echo $@ | sed -e 's/tg-//' -e 's/\.html//'` && \
78 echo '[HTML]' $$CMD && \
79 $(SHELL_PATH) ./create-html.sh $$CMD
81 .PHONY: precheck
83 precheck:: tg
84 ifeq ($(DESTDIR),)
85 ./$+ precheck
86 else
87 @echo skipping precheck because DESTDIR is set
88 endif
90 .PHONY: install
92 install:: all
93 install -d -m 755 "$(DESTDIR)$(bindir)"
94 install tg "$(DESTDIR)$(bindir)"
95 install -d -m 755 "$(DESTDIR)$(cmddir)"
96 install $(commands_out) "$(DESTDIR)$(cmddir)"
97 install -d -m 755 "$(DESTDIR)$(hooksdir)"
98 install $(hooks_out) "$(DESTDIR)$(hooksdir)"
99 install -d -m 755 "$(DESTDIR)$(sharedir)"
100 install -m 644 $(help_out) "$(DESTDIR)$(sharedir)"
101 install -m 644 README "$(DESTDIR)$(sharedir)/tg-tg.txt"
102 install -m 644 leaves.awk "$(DESTDIR)$(sharedir)"
104 .PHONY: install-html
106 install-html:: html
107 install -d -m 755 "$(DESTDIR)$(sharedir)"
108 install -m 644 topgit.html $(html_out) "$(DESTDIR)$(sharedir)"
110 .PHONY: clean
112 clean::
113 rm -f tg $(commands_out) $(hooks_out) $(help_out) topgit.html $(html_out)
114 rm -f TG-PREFIX
116 define TRACK_PREFIX
117 $(bindir):$(cmddir):$(hooksdir):$(sharedir):$(SHELL_PATH):$(version)
118 endef
119 export TRACK_PREFIX
121 TG-PREFIX: FORCE
122 @if test x"$$TRACK_PREFIX" != x"`cat TG-PREFIX 2>/dev/null`"; then \
123 echo "* new prefix flags"; \
124 echo "$$TRACK_PREFIX" >TG-PREFIX; \