test-lib-functions-tg.sh: introduce TopGit-specific test functions library
[topgit/pro.git] / Makefile
blobb8f4e10630c96569c685b4e97633e8dec695b2f2
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 # This avoids having this in no less than three different places!
15 TG_STATUS_HELP_USAGE = st[atus] [-v] [--exit-code]
16 export TG_STATUS_HELP_USAGE
18 prefix ?= $(HOME)
19 bindir = $(prefix)/bin
20 cmddir = $(prefix)/libexec/topgit
21 sharedir = $(prefix)/share/topgit
22 hooksdir = $(cmddir)/hooks
24 commands_in := $(wildcard tg-[!-]*.sh)
25 utils_in := $(wildcard tg--*.sh)
26 hooks_in = hooks/pre-commit.sh
27 helpers_in = $(wildcard t/helper/*.sh)
29 commands_out = $(patsubst %.sh,%,$(commands_in))
30 utils_out = $(patsubst %.sh,%,$(utils_in))
31 hooks_out = $(patsubst %.sh,%,$(hooks_in))
32 helpers_out = $(patsubst %.sh,%,$(helpers_in))
33 PROGRAMS = $(commands_out) $(utils_out)
34 help_out = $(patsubst %.sh,%.txt,tg-help.sh tg-status.sh $(commands_in))
35 html_out = $(patsubst %.sh,%.html,tg-help.sh tg-status.sh tg-tg.sh $(commands_in))
37 SHELL_PATH ?= /bin/sh
38 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
40 version := $(shell test -d .git && git describe --match "topgit-[0-9]*" --abbrev=4 --dirty 2>/dev/null | sed -e 's/^topgit-//' )
42 -include config.mak
43 SHELL = $(SHELL_PATH)
45 ifneq ($(strip $(version)),)
46 version_arg = -e s/TG_VERSION=.*/TG_VERSION=$(version)/
47 endif
49 .PHONY: FORCE
51 all:: shell_compatibility_test precheck $(commands_out) $(utils_out) $(hooks_out) $(helpers_out) bin-wrappers/tg $(help_out) tg-tg.txt
53 please_set_SHELL_PATH_to_a_more_modern_shell:
54 @$$(:)
56 shell_compatibility_test: please_set_SHELL_PATH_to_a_more_modern_shell
58 define POUND
60 endef
61 AT = @
62 Q_ = $(AT)
63 Q_0 = $(Q_)
64 Q = $(Q_$(V))
65 QSED_ = $(AT)echo "[SED] $@" &&
66 QSED_0 = $(QSED_)
67 QSED = $(QSED_$(V))
68 QHELP_ = $(AT)CMD="$@" CMD="$${CMD$(POUND)tg-}" && echo "[HELP] $${CMD%.txt}" &&
69 QHELP_0 = $(QHELP_)
70 QHELP = $(QHELP_$(V))
71 QHELPTG_ = $(AT)echo "[HELP] tg" &&
72 QHELPTG_0 = $(QHELPTG_)
73 QHELPTG = $(QHELPTG_$(V))
74 QHTML_ = $(AT)CMD="$@" CMD="$${CMD$(POUND)tg-}" && echo "[HTML] $${CMD%.html}" &&
75 QHTML_0 = $(QHTML_)
76 QHTML = $(QHTML_$(V))
77 QHTMLTOPGIT_ = $(AT)echo "[HTML] topgit" &&
78 QHTMLTOPGIT_0 = $(QHTMLTOPGIT_)
79 QHTMLTOPGIT = $(QHTMLTOPGIT_$(V))
80 QWRAPPER_ = $(AT)echo "[WRAPPER] $@" &&
81 QWRAPPER_0 = $(QWRAPPER_)
82 QWRAPPER = $(QWRAPPER_$(V))
84 tg $(commands_out) $(utils_out) $(hooks_out) $(helpers_out): % : %.sh Makefile TG-BUILD-SETTINGS
85 $(QSED)sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
86 -e 's#@cmddir@#$(cmddir)#g;' \
87 -e 's#@hooksdir@#$(hooksdir)#g' \
88 -e 's#@bindir@#$(bindir)#g' \
89 -e 's#@sharedir@#$(sharedir)#g' \
90 -e 's#@mingitver@#$(GIT_MINIMUM_VERSION)#g' \
91 -e 's#@tgsthelpusage@#$(TG_STATUS_HELP_USAGE)#g' \
92 -e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
93 $(version_arg) \
94 $@.sh >$@+ && \
95 chmod +x $@+ && \
96 mv $@+ $@
98 bin-wrappers/tg : $(commands_out) $(utils_out) $(hooks_out) $(helpers_out) tg
99 $(QWRAPPER){ [ -d bin-wrappers ] || mkdir bin-wrappers; } && \
100 echo '#!$(SHELL_PATH_SQ)' >"$@" && \
101 curdir="$$(pwd -P)" && \
102 echo "TG_INST_CMDDIR='$$curdir' && export TG_INST_CMDDIR" >>"$@" && \
103 echo "TG_INST_SHAREDIR='$$curdir' && export TG_INST_SHAREDIR" >>"$@" && \
104 echo "TG_INST_HOOKSDIR='$$curdir' && export TG_INST_HOOKSDIR" >>"$@" && \
105 echo "[ -n \"\$$tg__include\" ] || exec '$$curdir/tg' \"\$$@\" || exit" >>"$@" && \
106 echo ". '$$curdir/tg'" >>"$@" && \
107 chmod a+x "$@"
109 $(help_out): README create-help.sh
110 $(QHELP)CMD="$@" CMD="$${CMD#tg-}" CMD="$${CMD%.txt}" && \
111 $(SHELL_PATH) ./create-help.sh "$$CMD"
113 .PHONY: doc install-doc html
115 doc:: html
117 install-doc:: install-html
119 html:: topgit.html $(html_out)
121 tg-tg.txt: README create-html-usage.pl $(commands_in)
122 $(QHELPTG)perl ./create-html-usage.pl --text < README > $@
124 topgit.html: README create-html-usage.pl $(commands_in)
125 $(QHTMLTOPGIT)perl ./create-html-usage.pl < README | rst2html.py - $@
127 $(html_out): create-html.sh
128 $(QHTML)CMD="$@" CMD="$${CMD#tg-}" CMD="$${CMD%.html}" && \
129 $(SHELL_PATH) ./create-html.sh "$$CMD"
131 .PHONY: precheck
133 precheck:: tg
134 ifeq ($(DESTDIR),)
135 $(Q)./$+ precheck
136 else
137 $(Q)echo skipping precheck because DESTDIR is set
138 endif
140 .PHONY: install
142 install:: all
143 install -d -m 755 "$(DESTDIR)$(bindir)"
144 install tg "$(DESTDIR)$(bindir)"
145 install -d -m 755 "$(DESTDIR)$(cmddir)"
146 install $(commands_out) $(utils_out) "$(DESTDIR)$(cmddir)"
147 install -d -m 755 "$(DESTDIR)$(hooksdir)"
148 install $(hooks_out) "$(DESTDIR)$(hooksdir)"
149 install -d -m 755 "$(DESTDIR)$(sharedir)"
150 install -m 644 $(help_out) tg-tg.txt "$(DESTDIR)$(sharedir)"
151 install -m 644 leaves.awk "$(DESTDIR)$(sharedir)"
153 .PHONY: install-html
155 install-html:: html
156 install -d -m 755 "$(DESTDIR)$(sharedir)"
157 install -m 644 topgit.html $(html_out) "$(DESTDIR)$(sharedir)"
159 .PHONY: clean
161 clean::
162 rm -f tg $(commands_out) $(utils_out) $(hooks_out) $(helpers_out) $(help_out) topgit.html $(html_out)
163 rm -f TG-BUILD-SETTINGS
164 rm -rf bin-wrappers
165 +$(Q)$(MAKE) -C t clean
167 define BUILD_SETTINGS
168 TG_INST_BINDIR='$(bindir)'
169 TG_INST_CMDDIR='$(cmddir)'
170 TG_INST_HOOKSDIR='$(hooksdir)'
171 TG_INST_SHAREDIR='$(sharedir)'
172 SHELL_PATH='$(SHELL_PATH)'
173 TG_VERSION='$(version)'
174 TG_GIT_MINIMUM_VERSION='$(GIT_MINIMUM_VERSION)'
175 endef
176 export BUILD_SETTINGS
178 TG-BUILD-SETTINGS: FORCE
179 $(Q)if test x"$$BUILD_SETTINGS" != x"`cat $@ 2>/dev/null`"; then \
180 echo "* new build settings"; \
181 echo "$$BUILD_SETTINGS" >$@; \
184 test:: all
185 +$(Q)$(MAKE) -C t all