tg-annihilate.sh: suppress `tg update` with --no-update
[topgit/pro.git] / Makefile
blob61e398ea1a338142d1a3dda1c4caa6d4bb135653
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 # Update if you add any code that requires a newer version of git
12 GIT_MINIMUM_VERSION ?= 1.8.5
14 prefix ?= $(HOME)
15 bindir = $(prefix)/bin
16 cmddir = $(prefix)/libexec/topgit
17 sharedir = $(prefix)/share/topgit
18 hooksdir = $(cmddir)/hooks
20 commands_in := $(wildcard tg-[!-]*.sh)
21 utils_in := $(wildcard tg--*.sh)
22 hooks_in = hooks/pre-commit.sh
24 commands_out = $(patsubst %.sh,%,$(commands_in))
25 utils_out = $(patsubst %.sh,%,$(utils_in))
26 hooks_out = $(patsubst %.sh,%,$(hooks_in))
27 help_out = $(patsubst %.sh,%.txt,tg-help.sh $(commands_in))
28 html_out = $(patsubst %.sh,%.html,tg-help.sh tg-tg.sh $(commands_in))
30 SHELL_PATH ?= /bin/sh
31 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
33 version := $(shell test -d .git && git describe --match "topgit-[0-9]*" --abbrev=4 --dirty 2>/dev/null | sed -e 's/^topgit-//' )
35 -include config.mak
36 SHELL = $(SHELL_PATH)
38 ifneq ($(strip $(version)),)
39 version_arg = -e s/TG_VERSION=.*/TG_VERSION=$(version)/
40 endif
42 .PHONY: FORCE
44 all:: shell_compatibility_test precheck $(commands_out) $(utils_out) $(hooks_out) bin-wrappers/tg $(help_out) tg-tg.txt
46 please_set_SHELL_PATH_to_a_more_modern_shell:
47 @$$(:)
49 shell_compatibility_test: please_set_SHELL_PATH_to_a_more_modern_shell
51 tg $(commands_out) $(utils_out) $(hooks_out): % : %.sh Makefile TG-BUILD-SETTINGS
52 @echo "[SED] $@"
53 @sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
54 -e 's#@cmddir@#$(cmddir)#g;' \
55 -e 's#@hooksdir@#$(hooksdir)#g' \
56 -e 's#@bindir@#$(bindir)#g' \
57 -e 's#@sharedir@#$(sharedir)#g' \
58 -e 's#@mingitver@#$(GIT_MINIMUM_VERSION)#g' \
59 -e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
60 $(version_arg) \
61 $@.sh >$@+ && \
62 chmod +x $@+ && \
63 mv $@+ $@
65 bin-wrappers/tg : $(commands_out) $(utils_out) $(hooks_out) tg
66 @echo "[WRAPPER] $@"
67 @[ -d bin-wrappers ] || mkdir bin-wrappers
68 @echo '#!$(SHELL_PATH_SQ)' >"$@"
69 @curdir="$$(pwd -P)"; \
70 echo "TG_INST_CMDDIR='$$curdir' && export TG_INST_CMDDIR" >>"$@"; \
71 echo "TG_INST_SHAREDIR='$$curdir' && export TG_INST_SHAREDIR" >>"$@"; \
72 echo "TG_INST_HOOKSDIR='$$curdir' && export TG_INST_HOOKSDIR" >>"$@"; \
73 echo "exec '$$curdir/tg' \"\$$@\"" >>"$@"
74 @chmod a+x "$@"
76 $(help_out): README create-help.sh
77 @CMD=`echo $@ | sed -e 's/tg-//' -e 's/\.txt//'` && \
78 echo '[HELP]' $$CMD && \
79 $(SHELL_PATH) ./create-help.sh $$CMD
81 .PHONY: doc install-doc html
83 doc:: html
85 install-doc:: install-html
87 html:: topgit.html $(html_out)
89 tg-tg.txt: README create-html-usage.pl $(wildcard tg-[!-]*.sh)
90 @echo '[HELP] tg'
91 @perl ./create-html-usage.pl --text < README > $@
93 topgit.html: README create-html-usage.pl $(wildcard tg-[!-]*.sh)
94 @echo '[HTML] topgit'
95 @perl ./create-html-usage.pl < README | rst2html.py - $@
97 $(html_out): create-html.sh
98 @CMD=`echo $@ | sed -e 's/tg-//' -e 's/\.html//'` && \
99 echo '[HTML]' $$CMD && \
100 $(SHELL_PATH) ./create-html.sh $$CMD
102 .PHONY: precheck
104 precheck:: tg
105 ifeq ($(DESTDIR),)
106 @./$+ precheck
107 else
108 @echo skipping precheck because DESTDIR is set
109 endif
111 .PHONY: install
113 install:: all
114 install -d -m 755 "$(DESTDIR)$(bindir)"
115 install tg "$(DESTDIR)$(bindir)"
116 install -d -m 755 "$(DESTDIR)$(cmddir)"
117 install $(commands_out) $(utils_out) "$(DESTDIR)$(cmddir)"
118 install -d -m 755 "$(DESTDIR)$(hooksdir)"
119 install $(hooks_out) "$(DESTDIR)$(hooksdir)"
120 install -d -m 755 "$(DESTDIR)$(sharedir)"
121 install -m 644 $(help_out) tg-tg.txt "$(DESTDIR)$(sharedir)"
122 install -m 644 leaves.awk "$(DESTDIR)$(sharedir)"
124 .PHONY: install-html
126 install-html:: html
127 install -d -m 755 "$(DESTDIR)$(sharedir)"
128 install -m 644 topgit.html $(html_out) "$(DESTDIR)$(sharedir)"
130 .PHONY: clean
132 clean::
133 rm -f tg $(commands_out) $(utils_out) $(hooks_out) $(help_out) topgit.html $(html_out)
134 rm -f TG-BUILD-SETTINGS
135 rm -rf bin-wrappers
136 +@$(MAKE) -C t clean
138 define BUILD_SETTINGS
139 TG_INST_BINDIR='$(bindir)'
140 TG_INST_CMDDIR='$(cmddir)'
141 TG_INST_HOOKSDIR='$(hooksdir)'
142 TG_INST_SHAREDIR='$(sharedir)'
143 SHELL_PATH='$(SHELL_PATH)'
144 TG_VERSION='$(version)'
145 TG_GIT_MINIMUM_VERSION='$(GIT_MINIMUM_VERSION)'
146 endef
147 export BUILD_SETTINGS
149 TG-BUILD-SETTINGS: FORCE
150 @if test x"$$BUILD_SETTINGS" != x"`cat $@ 2>/dev/null`"; then \
151 echo "* new build settings"; \
152 echo "$$BUILD_SETTINGS" >$@; \
155 test:: all
156 +@$(MAKE) -C t all