t/.gitattributes: add some binary attributes
[topgit/pro.git] / Makefile.mak
blob1f6d9c94bdf80567f30971f0e51adbddbe386cce
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`)
28 # Default target is all
29 all:
31 # Makefile.sh sets many variables used by this Makefile.mak
33 include $(CONFIGMAK)
34 SHELL = $(SHELL_PATH)
36 all: \
37 shell_compatibility_test \
38 precheck \
39 tg $(commands_out) $(utils_out) $(awk_out) $(hooks_out) $(helpers_out) \
40 bin-wrappers/tg bin-wrappers/pre-commit $(help_out) tg-tg.txt
42 settings: TG-BUILD-SETTINGS FORCE
43 +$(Q)cd t && $(MAKE) settings
45 awk: $(awk_out)
46 hooks: $(hooks_out)
47 helpers: $(helpers_out)
49 please_set_SHELL_PATH_to_a_more_modern_shell: FORCE
50 @$$(:)
52 shell_compatibility_test: please_set_SHELL_PATH_to_a_more_modern_shell
54 # $(POUND) expands to a single '#' courtesy of Makefile.sh
55 AT = @
56 Q_ = $(AT)
57 Q_0 = $(Q_)
58 Q = $(Q_$(V))
59 QPOUND_ = $(AT)$(POUND)
60 QPOUND_0 = $(QPOUND_)
61 QPOUND = $(QPOUND_$(V))
62 QSED_ = $(AT)echo "[SED] $@" &&
63 QSED_0 = $(QSED_)
64 QSED = $(QSED_$(V))
65 QHELP_ = $(AT)CMD="$@" && CMD="$${CMD$(POUND)tg-}" && echo "[HELP] $${CMD%.txt}" &&
66 QHELP_0 = $(QHELP_)
67 QHELP = $(QHELP_$(V))
68 QHELPTG_ = $(AT)echo "[HELP] tg" &&
69 QHELPTG_0 = $(QHELPTG_)
70 QHELPTG = $(QHELPTG_$(V))
71 QHTML_ = $(AT)CMD="$@" && CMD="$${CMD$(POUND)tg-}" && echo "[HTML] $${CMD%.html}" &&
72 QHTML_0 = $(QHTML_)
73 QHTML = $(QHTML_$(V))
74 QHTMLTOPGIT_ = $(AT)echo "[HTML] topgit" &&
75 QHTMLTOPGIT_0 = $(QHTMLTOPGIT_)
76 QHTMLTOPGIT = $(QHTMLTOPGIT_$(V))
77 QWRAPPER_ = $(AT)echo "[WRAPPER] $@" &&
78 QWRAPPER_0 = $(QWRAPPER_)
79 QWRAPPER = $(QWRAPPER_$(V))
81 # Very important rule to avoid "accidents" caused by Makefile.sh's existence
82 # Some ridiculous "make" implementations will always implicitly "make Makefile"
83 # even though .POSIX: has been specified and that's definitely NOT POSIX!
84 Makefile:
85 @true
87 # Clean out the standard six single suffix inference rules to avoid accidents
88 .SUFFIXES: .c .sh .f .c˜ .sh˜ .f˜
89 .c:;
90 .f:;
91 .sh:;
92 .c~:;
93 .f~:;
94 .sh~:;
95 .SUFFIXES:
97 # The fatal flaw with .SUFFIXES is that while it's possible to add dependencies
98 # without listing rule commands, doing so prevents use of an inference rule
99 # because the dependency-adding-rule-with-no-commands is still considered a rule.
100 # Of course that means the free automatic dependency crated by an inference rule
101 # also can't be picked up but fortunately we have DEPFILE instead.
102 include $(DEPFILE)
104 tg $(commands_out) $(utils_out) $(hooks_out) $(helpers_out): Makefile Makefile.mak Makefile.sh TG-BUILD-SETTINGS
105 $(QSED)sed \
106 -e '1s|#!.*/sh|#!$(SHELL_PATH)|' \
107 -e '1s|#!.*/awk|#!$(AWK_PREFIX)$(AWK_PATH)|' \
108 -e 's#@cmddir@#$(cmddir)#g;' \
109 -e 's#@hooksdir@#$(hooksdir)#g' \
110 -e 's#@bindir@#$(bindir)#g' \
111 -e 's#@sharedir@#$(sharedir)#g' \
112 -e 's#@mingitver@#$(GIT_MINIMUM_VERSION)#g' \
113 -e 's#@tgsthelpusage@#$(TG_STATUS_HELP_USAGE)#g' \
114 -e 's#@SHELL_PATH@#$(SHELL_PATH_SQ)#g' \
115 -e 's#@AWK_PATH@#$(AWK_PATH_SQ)#g' \
116 $(version_arg) \
117 <"$@.sh" >"$@+" && \
118 chmod +x "$@+" && \
119 mv "$@+" "$@"
121 tg--awksome: $(awk_out)
122 $(awk_out): Makefile TG-BUILD-SETTINGS
123 $(QSED)sed \
124 -e '1s|#!.*/awk|#!$(AWK_PREFIX)$(AWK_PATH_SQ)|' \
125 <"$@.awk" >"$@+" && \
126 chmod +x "$@+" && \
127 mv "$@+" "$@"
129 bin-wrappers/tg : tg
130 $(QWRAPPER){ [ -d bin-wrappers ] || mkdir -p bin-wrappers; } && \
131 echo '#!$(SHELL_PATH_SQ)' >"$@" && \
132 curdir="$$(pwd -P)" && \
133 echo "TG_INST_BINDIR='$$curdir' && export TG_INST_BINDIR" >>"$@" && \
134 echo "TG_INST_CMDDIR='$$curdir' && export TG_INST_CMDDIR" >>"$@" && \
135 echo "TG_INST_SHAREDIR='$$curdir' && export TG_INST_SHAREDIR" >>"$@" && \
136 echo "TG_INST_HOOKSDIR='$$curdir/bin-wrappers' && export TG_INST_HOOKSDIR" >>"$@" && \
137 echo '[ -n "$$tg__include" ] || exec $(SHELL_PATH_SQ) -c '\''. "$$TG_INST_BINDIR/tg"'\'' "$$0" "$$@" || exit $$?' >>"$@" && \
138 echo ". '$$curdir/tg'" >>"$@" && sed <"$@" "/exec.* -c /s/ -c / -x -c /" >"$@x" && \
139 chmod a+x "$@" "$@x"
141 bin-wrappers/pre-commit : hooks/pre-commit
142 $(QWRAPPER){ [ -d bin-wrappers ] || mkdir -p bin-wrappers; } && \
143 echo '#!$(SHELL_PATH_SQ)' >"$@" && \
144 curdir="$$(pwd -P)" && \
145 echo "TG_INST_BINDIR='$$curdir' && export TG_INST_BINDIR" >>"$@" && \
146 echo "TG_INST_CMDDIR='$$curdir' && export TG_INST_CMDDIR" >>"$@" && \
147 echo "TG_INST_SHAREDIR='$$curdir' && export TG_INST_SHAREDIR" >>"$@" && \
148 echo "TG_INST_HOOKSDIR='$$curdir/bin-wrappers' && export TG_INST_HOOKSDIR" >>"$@" && \
149 echo ". '$$curdir/hooks/pre-commit'" >>"$@" && \
150 chmod a+x "$@"
152 $(help_out): README create-help.sh polish-help-txt.pl
153 $(QHELP)CMD="$@" && CMD="$${CMD#tg-}" && CMD="$${CMD%.txt}" && \
154 $(SHELL_PATH) ./create-help.sh "$$CMD"
156 doc: html
158 install-doc: install-html
160 html: topgit.html $(html_out)
162 tg-tg.txt: README create-html-usage.pl $(commands_in)
163 $(QHELPTG)perl ./create-html-usage.pl --text < README > $@
165 topgit.html: README create-html-usage.pl $(commands_in)
166 $(Q)command -v "$${RST2HTML:-rst2html}" >/dev/null || \
167 { echo "need $${RST2HTML:-rst2html} to make $@" >&2; exit 1; }
168 $(QPOUND)echo "# \$${RST2HTML:-rst2html} is \"$${RST2HTML:-rst2html}\""
169 $(QHTMLTOPGIT)perl ./create-html-usage.pl < README | "$${RST2HTML:-rst2html}" - $@ && \
170 perl -i -pe 's/&nbsp;/\&#160;/g' "$@"
172 $(html_out): create-html.sh
173 $(QHTML)CMD="$@" && CMD="$${CMD#tg-}" && CMD="$${CMD%.html}" && \
174 $(SHELL_PATH) ./create-html.sh "$$CMD"
176 precheck: precheck_DESTDIR_$(DESTDIRBOOL)
178 precheck_DESTDIR_No: tg FORCE
179 $(Q)./tg precheck
180 precheck_DESTDIR_Yes: FORCE
181 $(Q)echo "skipping precheck because DESTDIR is set"
183 install: all FORCE
184 install -d -m 755 "$(DESTDIR)$(bindir)"
185 install tg "$(DESTDIR)$(bindir)"
186 install -d -m 755 "$(DESTDIR)$(cmddir)"
187 install $(commands_out) $(utils_out) "$(DESTDIR)$(cmddir)"
188 install -d -m 755 "$(DESTDIR)$(cmddir)/awk"
189 install $(awk_out) "$(DESTDIR)$(cmddir)/awk"
190 install -d -m 755 "$(DESTDIR)$(hooksdir)"
191 install $(hooks_out) "$(DESTDIR)$(hooksdir)"
192 install -d -m 755 "$(DESTDIR)$(sharedir)"
193 install -m 644 $(help_out) tg-tg.txt "$(DESTDIR)$(sharedir)"
195 install-html: html FORCE
196 install -d -m 755 "$(DESTDIR)$(sharedir)"
197 install -m 644 topgit.html $(html_out) "$(DESTDIR)$(sharedir)"
199 clean: FORCE
200 rm -f tg $(commands_out) $(utils_out) $(awk_out) $(hooks_out) $(helpers_out) $(help_out) tg-tg.txt topgit.html $(html_out)
201 rm -f TG-BUILD-SETTINGS Makefile.dep Makefile.var
202 rm -rf bin-wrappers
203 +-$(Q)cd t && $(MAKE) clean
205 BUILD_SETTINGS = \
206 bs() { printf "%s\\n" \
207 "TG_INST_BINDIR='$(bindir)'" \
208 "TG_INST_CMDDIR='$(cmddir)'" \
209 "TG_INST_HOOKSDIR='$(hooksdir)'" \
210 "TG_INST_SHAREDIR='$(sharedir)'" \
211 "SHELL_PATH='$(SHELL_PATH)'" \
212 "AWK_PATH='$(AWK_PATH)'" \
213 "TG_VERSION='$(version)'" \
214 "TG_GIT_MINIMUM_VERSION='$(GIT_MINIMUM_VERSION)'" \
217 # Makefile.sh sets FORCE_SETTINGS_BUILD to FORCE and pre-runs
218 # make -f Makefile.mak TG-BUILD-SETTINGS thus avoiding this always
219 # causing the targets that depend on it to build while still forcing
220 # a rebuild if any settings actually change.
221 TG-BUILD-SETTINGS: $(CONFIGDEPS) $(FORCE_SETTINGS_BUILD)
222 $(Q)$(BUILD_SETTINGS);if test x"$$(bs)" != x"`cat \"$@\" 2>/dev/null`"; then \
223 echo "* new build settings"; \
224 bs >"$@"; \
225 elif test z"$(FORCE_SETTINGS_BUILD)" = z; then touch "$@"; fi
227 test: all FORCE
228 +$(Q)cd t && $(MAKE) all
230 FORCE: __file_which_should_not_exist
232 # This "phony" target must have at least one command otherwise it will not
233 # actually run anything and so will not actually trigger the rules that depend
234 # on FORCE to run either. By using "true" instead of ":" "make"s that
235 # short-circuit directly to execvp should be able to run "true" directly.
236 __file_which_should_not_exist:
237 -@true