various: use "command" instead of "subcommand"
[topgit/pro.git] / Makefile.mak
blobd2f880db8cf7941b38fae5684583ffae1edc1c0d
1 # Makefile.mak - POSIX Makefile.mak adjunct for TopGit
3 .POSIX:
6 ## Makefile variables
7 ##
8 ## V - set to 1 to get more verbose rule output
9 ## Default is empty
10 ## Any value other than empty or 0 will also activate verbose mode
12 ## DESTDIR - installation path prefix
13 ## Default is empty
14 ## The value is prefixed verbatim to the installation paths when
15 ## using any of the "install" targets but is otherwise ignored.
16 ## This allows the executables to be configured for one location
17 ## but installed to an alternate location before being moved to
18 ## their final location. The executables will not work correctly
19 ## until they are then relocated into their final location.
21 ## RST2HTML - location of rst2html.py
22 ## Default is "rst2html"
23 ## Only required to `make doc` aka `make html` (i.e. topgit.html)
24 ## If "rst2html" is not in $PATH this must be set
25 ## in order to successfully `make doc` (or `make html`)
27 ## SHELL_PATH path to POSIX sh, default is /bin/sh if not otherwise set
29 ## AWK_PATH path to awk, default is /usr/bin/awk if not otherwise set
32 # Default target is all
33 all:
35 # Makefile.sh sets many variables used by this Makefile.mak
37 include $(CONFIGMAK)
38 SHELL = $(SHELL_PATH)
40 all: \
41 shell_compatibility_test \
42 precheck \
43 tg $(commands_out) $(utils_out) $(awk_out) $(hooks_out) $(helpers_out) \
44 bin-wrappers/tg bin-wrappers/pre-commit $(help_out) tg-tg.txt
46 settings: TG-BUILD-SETTINGS FORCE
47 +$(Q)cd t && $(MAKE) settings
49 awk: $(awk_out)
50 hooks: $(hooks_out)
51 helpers: $(helpers_out)
53 please_set_SHELL_PATH_to_a_more_modern_shell: FORCE
54 @$$(:)
56 shell_compatibility_test: please_set_SHELL_PATH_to_a_more_modern_shell
58 # $(POUND) expands to a single '#' courtesy of Makefile.sh
59 AT = @
60 Q_ = $(AT)
61 Q_0 = $(Q_)
62 Q = $(Q_$(V))
63 QPOUND_ = $(AT)$(POUND)
64 QPOUND_0 = $(QPOUND_)
65 QPOUND = $(QPOUND_$(V))
66 QSED_ = $(AT)echo "[SED] $@" &&
67 QSED_0 = $(QSED_)
68 QSED = $(QSED_$(V))
69 QHELP_ = $(AT)CMD="$@" && CMD="$${CMD$(POUND)tg-}" && echo "[HELP] $${CMD%.txt}" &&
70 QHELP_0 = $(QHELP_)
71 QHELP = $(QHELP_$(V))
72 QHELPTG_ = $(AT)echo "[HELP] tg" &&
73 QHELPTG_0 = $(QHELPTG_)
74 QHELPTG = $(QHELPTG_$(V))
75 QHTML_ = $(AT)CMD="$@" && CMD="$${CMD$(POUND)tg-}" && echo "[HTML] $${CMD%.html}" &&
76 QHTML_0 = $(QHTML_)
77 QHTML = $(QHTML_$(V))
78 QHTMLTOPGIT_ = $(AT)echo "[HTML] topgit" &&
79 QHTMLTOPGIT_0 = $(QHTMLTOPGIT_)
80 QHTMLTOPGIT = $(QHTMLTOPGIT_$(V))
81 QWRAPPER_ = $(AT)echo "[WRAPPER] $@" &&
82 QWRAPPER_0 = $(QWRAPPER_)
83 QWRAPPER = $(QWRAPPER_$(V))
85 # Very important rule to avoid "accidents" caused by Makefile.sh's existence
86 # Some ridiculous "make" implementations will always implicitly "make Makefile"
87 # even though .POSIX: has been specified and that's definitely NOT POSIX!
88 Makefile Makefile.mak Makefile.mt Makefile.dep Makefile.sh config.mak config.sh:
89 -@true
91 # Clean out the standard six single suffix inference rules to avoid accidents
92 .SUFFIXES: .c .sh .f .c˜ .sh˜ .f˜
93 .c:;
94 .f:;
95 .sh:;
96 .c~:;
97 .f~:;
98 .sh~:;
99 .SUFFIXES:
101 # The fatal flaw with .SUFFIXES is that while it's possible to add dependencies
102 # without listing rule commands, doing so prevents use of an inference rule
103 # because the dependency-adding-rule-with-no-commands is still considered a rule.
104 # Of course that means the free automatic dependency created by an inference rule
105 # also can't be picked up but fortunately we have DEPFILE instead.
106 include $(DEPFILE)
108 tg $(commands_out) $(utils_out) $(hooks_out) $(helpers_out): Makefile Makefile.mak Makefile.sh TG-BUILD-SETTINGS
109 $(QSED)sed \
110 -e '1s|#!.*/sh|#!$(SHELL_PATH)|' \
111 -e '1s|#!.*/awk|#!$(AWK_PREFIX)$(AWK_PATH)|' \
112 -e 's#@cmddir@#$(cmddir)#g;' \
113 -e 's#@hooksdir@#$(hooksdir)#g' \
114 -e 's#@bindir@#$(bindir)#g' \
115 -e 's#@sharedir@#$(sharedir)#g' \
116 -e 's#@mingitver@#$(GIT_MINIMUM_VERSION)#g' \
117 -e 's#@tgsthelpusage@#$(TG_STATUS_HELP_USAGE)#g' \
118 -e 's#@SHELL_PATH@#$(SHELL_PATH_SQ)#g' \
119 -e 's#@AWK_PATH@#$(AWK_PATH_SQ)#g' \
120 $(version_arg) \
121 <"$@.sh" >"$@+" && \
122 chmod +x "$@+" && \
123 mv "$@+" "$@"
125 tg--awksome: $(awk_out)
126 $(awk_out): Makefile TG-BUILD-SETTINGS
127 $(QSED)sed \
128 -e '1s|#!.*/awk|#!$(AWK_PREFIX)$(AWK_PATH_SQ)|' \
129 <"$@.awk" >"$@+" && \
130 chmod +x "$@+" && \
131 mv "$@+" "$@"
133 bin-wrappers/tg : tg
134 $(QWRAPPER){ [ -d bin-wrappers ] || mkdir -p bin-wrappers; } && \
135 echo '#!$(SHELL_PATH_SQ)' >"$@" && \
136 curdir="$$(pwd -P)" && \
137 echo "TG_INST_BINDIR='$$curdir' && export TG_INST_BINDIR" >>"$@" && \
138 echo "TG_INST_CMDDIR='$$curdir' && export TG_INST_CMDDIR" >>"$@" && \
139 echo "TG_INST_SHAREDIR='$$curdir' && export TG_INST_SHAREDIR" >>"$@" && \
140 echo "TG_INST_HOOKSDIR='$$curdir/bin-wrappers' && export TG_INST_HOOKSDIR" >>"$@" && \
141 echo '[ -n "$$tg__include" ] || exec $(SHELL_PATH_SQ) -c '\''. "$$TG_INST_BINDIR/tg"'\'' "$$0" "$$@" || exit $$?' >>"$@" && \
142 echo ". '$$curdir/tg'" >>"$@" && sed <"$@" "/exec.* -c /s/ -c / -x -c /" >"$@x" && \
143 chmod a+x "$@" "$@x"
145 bin-wrappers/pre-commit : hooks/pre-commit
146 $(QWRAPPER){ [ -d bin-wrappers ] || mkdir -p bin-wrappers; } && \
147 echo '#!$(SHELL_PATH_SQ)' >"$@" && \
148 curdir="$$(pwd -P)" && \
149 echo "TG_INST_BINDIR='$$curdir' && export TG_INST_BINDIR" >>"$@" && \
150 echo "TG_INST_CMDDIR='$$curdir' && export TG_INST_CMDDIR" >>"$@" && \
151 echo "TG_INST_SHAREDIR='$$curdir' && export TG_INST_SHAREDIR" >>"$@" && \
152 echo "TG_INST_HOOKSDIR='$$curdir/bin-wrappers' && export TG_INST_HOOKSDIR" >>"$@" && \
153 echo ". '$$curdir/hooks/pre-commit'" >>"$@" && \
154 chmod a+x "$@"
156 $(help_out): README_DOCS.rst create-help.sh polish-help-txt.pl
157 $(QHELP)CMD="$@" && CMD="$${CMD#tg-}" && CMD="$${CMD%.txt}" && \
158 $(SHELL_PATH) ./create-help.sh "$$CMD"
160 doc: html
162 install-doc: install-html
164 html: topgit.html $(html_out)
166 tg-tg.txt: README_DOCS.rst create-html-usage.pl $(commands_in)
167 $(QHELPTG)perl ./create-html-usage.pl --text < README_DOCS.rst > $@
169 TOPGIT_HTML_SRCS = \
170 README_DOCS.rst \
171 rsrc/stub1.bin \
172 rsrc/stub2.bin \
173 Makefile.mt
174 #TOPGIT_HTML_SRCS
176 topgit.html: $(TOPGIT_HTML_SRCS) Makefile.mak create-html-usage.pl $(commands_in)
177 $(Q)command -v "$${RST2HTML:-rst2html}" >/dev/null || \
178 { echo "need $${RST2HTML:-rst2html} to make $@" >&2; exit 1; }
179 $(QPOUND)echo "# \$${RST2HTML:-rst2html} is \"$${RST2HTML:-rst2html}\""
180 $(QHTMLTOPGIT)perl ./create-html-usage.pl < README_DOCS.rst | \
181 "$${RST2HTML:-rst2html}" --stylesheet-path=Makefile.mt - $@.tmp && \
182 { cat rsrc/stub1.bin && \
183 LC_ALL=C sed -e 's/&nbsp;/\&#160;/g' -e 's/<th class=/<th align="left" class=/g' \
184 -e 's/ -- / \&#x2013; /g' -e 's/&amp;#160;/\&#160;/g' \
185 -e 's/<ol class="lowerroman/<ol type="i" class="lowerroman/g' \
186 -e 's/<ol class="loweralpha/<ol type="a" class="loweralpha/g' <$@.tmp | \
187 LC_ALL=C awk '/^<body/{p=1;next}/^<\/body/{p=0;next}p{print}' && \
188 cat rsrc/stub2.bin; } >$@ && rm -f $@.tmp
190 $(html_out): create-html.sh
191 $(QHTML)CMD="$@" && CMD="$${CMD#tg-}" && CMD="$${CMD%.html}" && \
192 $(SHELL_PATH) ./create-html.sh "$$CMD"
194 precheck: precheck_DESTDIR_$(DESTDIRBOOL)
196 precheck_DESTDIR_No: tg FORCE
197 $(Q)./tg precheck
198 precheck_DESTDIR_Yes: FORCE
199 $(Q)echo "skipping precheck because DESTDIR is set"
201 install: all FORCE
202 install -d -m 755 "$(DESTDIR)$(bindir)"
203 install tg "$(DESTDIR)$(bindir)"
204 install -d -m 755 "$(DESTDIR)$(cmddir)"
205 install $(commands_out) $(utils_out) "$(DESTDIR)$(cmddir)"
206 install -d -m 755 "$(DESTDIR)$(cmddir)/awk"
207 install $(awk_out) "$(DESTDIR)$(cmddir)/awk"
208 install -d -m 755 "$(DESTDIR)$(hooksdir)"
209 install $(hooks_out) "$(DESTDIR)$(hooksdir)"
210 install -d -m 755 "$(DESTDIR)$(sharedir)"
211 install -m 644 $(help_out) tg-tg.txt "$(DESTDIR)$(sharedir)"
213 install-html: html FORCE
214 install -d -m 755 "$(DESTDIR)$(sharedir)"
215 install -m 644 topgit.html $(html_out) "$(DESTDIR)$(sharedir)"
217 clean: FORCE
218 rm -f tg $(commands_out) $(utils_out) $(awk_out) $(hooks_out) $(helpers_out) $(help_out) tg-tg.txt topgit.html topgit.html.tmp $(html_out)
219 rm -f TG-BUILD-SETTINGS Makefile.dep Makefile.var
220 rm -rf bin-wrappers
221 +-$(Q)cd t && $(MAKE) clean
223 BUILD_SETTINGS = \
224 bs() { printf "%s\\n" \
225 "TG_INST_BINDIR='$(bindir)'" \
226 "TG_INST_CMDDIR='$(cmddir)'" \
227 "TG_INST_HOOKSDIR='$(hooksdir)'" \
228 "TG_INST_SHAREDIR='$(sharedir)'" \
229 "SHELL_PATH='$(SHELL_PATH)'" \
230 "AWK_PATH='$(AWK_PATH)'" \
231 "TG_VERSION='$(version)'" \
232 "TG_GIT_MINIMUM_VERSION='$(GIT_MINIMUM_VERSION)'" \
235 # Makefile.sh sets FORCE_SETTINGS_BUILD to FORCE and pre-runs
236 # make -f Makefile.mak TG-BUILD-SETTINGS thus avoiding this always
237 # causing the targets that depend on it to build while still forcing
238 # a rebuild if any settings actually change.
239 TG-BUILD-SETTINGS: $(CONFIGDEPS) $(FORCE_SETTINGS_BUILD)
240 $(Q)$(BUILD_SETTINGS);if test x"$$(bs)" != x"`cat \"$@\" 2>/dev/null`"; then \
241 echo "* new build settings"; \
242 bs >"$@"; \
243 elif test z"$(FORCE_SETTINGS_BUILD)" = z; then touch "$@"; fi
245 test-sha1: all FORCE
246 +$(Q)cd t && TESTLIB_GIT_DEFAULT_HASH=sha1 $(MAKE) all
248 test-sha256: all FORCE
249 +$(Q)cd t && TESTLIB_GIT_DEFAULT_HASH=sha256 $(MAKE) all
251 test: all FORCE
252 +$(Q)cd t && $(MAKE) settings && if helper/test_have_prereq GITSHA256; then \
253 echo "* running Git hash algorithm sha1 tests" && \
254 TESTLIB_GIT_DEFAULT_HASH=sha1 $(MAKE) all && \
255 echo "* running Git hash algorithm sha256 tests" && \
256 TESTLIB_GIT_DEFAULT_HASH=sha256 $(MAKE) all && \
257 echo "* both Git hash algorithm sha1 and Git hash algorithm sha256 tests passed"; \
258 else \
259 echo "* running Git hash algorithm sha1 tests only (Git version < 2.29.0)" && \
260 TESTLIB_GIT_DEFAULT_HASH=sha1 $(MAKE) all; \
263 FORCE: Makefile.mak/phony
265 # This "phony" target must have at least one command otherwise it will not
266 # actually run anything and so will not actually trigger the rules that depend
267 # on FORCE to run either. By using "true" instead of ":" "make"s that
268 # short-circuit directly to execvp should be able to run "true" directly.
269 Makefile.mak/phony:
270 -@true