1 # NOTE: Requires GNU make
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
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
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 awk_in
:= $(wildcard awk
/*.awk
)
27 hooks_in
= hooks
/pre-commit.sh
28 helpers_in
= $(wildcard t
/helper
/*.sh
)
30 commands_out
= $(patsubst %.sh
,%,$(commands_in
))
31 utils_out
= $(patsubst %.sh
,%,$(utils_in
))
32 awk_out
= $(patsubst %.awk
,%,$(awk_in
))
33 hooks_out
= $(patsubst %.sh
,%,$(hooks_in
))
34 helpers_out
= $(patsubst %.sh
,%,$(helpers_in
))
35 PROGRAMS
= $(commands_out
) $(utils_out
)
36 help_out
= $(patsubst %.sh
,%.txt
,tg-help.sh tg-status.sh
$(commands_in
))
37 html_out
= $(patsubst %.sh
,%.html
,tg-help.sh tg-status.sh tg-tg.sh
$(commands_in
))
40 SHELL_PATH_SQ
= $(subst ','\'',$(SHELL_PATH))
43 AWK_PATH_SQ = $(subst ','\'',$(AWK_PATH
))
45 version
:= $(shell test -d .git
&& git describe
--match
"topgit-[0-9]*" --abbrev
=4 --dirty
2>/dev
/null | sed
-e
's/^topgit-//' )
49 ifeq ($(subst /,,$(AWK_PATH
)),$(AWK_PATH
))
50 AWK_PREFIX
= /usr
/bin
/
55 ifneq ($(strip $(version
)),)
56 version_arg
= -e s
/TG_VERSION
=.
*/TG_VERSION
=$(version
)/
61 all:: shell_compatibility_test precheck
$(commands_out
) $(utils_out
) $(awk_out
) $(hooks_out
) $(helpers_out
) bin-wrappers
/tg
$(help_out
) tg-tg.txt
63 please_set_SHELL_PATH_to_a_more_modern_shell
:
66 shell_compatibility_test
: please_set_SHELL_PATH_to_a_more_modern_shell
75 QSED_
= $(AT
)echo
"[SED] $@" &&
78 QHELP_
= $(AT
)CMD
="$@" CMD
="$${CMD$(POUND)tg-}" && echo
"[HELP] $${CMD%.txt}" &&
81 QHELPTG_
= $(AT
)echo
"[HELP] tg" &&
82 QHELPTG_0
= $(QHELPTG_
)
83 QHELPTG
= $(QHELPTG_
$(V
))
84 QHTML_
= $(AT
)CMD
="$@" CMD
="$${CMD$(POUND)tg-}" && echo
"[HTML] $${CMD%.html}" &&
87 QHTMLTOPGIT_
= $(AT
)echo
"[HTML] topgit" &&
88 QHTMLTOPGIT_0
= $(QHTMLTOPGIT_
)
89 QHTMLTOPGIT
= $(QHTMLTOPGIT_
$(V
))
90 QWRAPPER_
= $(AT
)echo
"[WRAPPER] $@" &&
91 QWRAPPER_0
= $(QWRAPPER_
)
92 QWRAPPER
= $(QWRAPPER_
$(V
))
94 tg
$(commands_out
) $(utils_out
) $(hooks_out
) $(helpers_out
): % : %.sh Makefile TG-BUILD-SETTINGS
96 -e
'1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
97 -e
'1s|#!.*/awk|#!$(AWK_PREFIX)$(AWK_PATH_SQ)|' \
98 -e
's#@cmddir@#$(cmddir)#g;' \
99 -e
's#@hooksdir@#$(hooksdir)#g' \
100 -e
's#@bindir@#$(bindir)#g' \
101 -e
's#@sharedir@#$(sharedir)#g' \
102 -e
's#@mingitver@#$(GIT_MINIMUM_VERSION)#g' \
103 -e
's#@tgsthelpusage@#$(TG_STATUS_HELP_USAGE)#g' \
104 -e
's#@SHELL_PATH@#$(SHELL_PATH_SQ)#g' \
105 -e
's#@AWK_PATH@#$(AWK_PATH_SQ)#g' \
111 tg--awksome
: $(awk_out
)
112 $(awk_out
): % : %.awk Makefile TG-BUILD-SETTINGS
114 -e
'1s|#!.*/awk|#!$(AWK_PREFIX)$(AWK_PATH_SQ)|' \
119 bin-wrappers
/tg
: $(commands_out
) $(utils_out
) $(awk_out
) $(hooks_out
) $(helpers_out
) tg
120 $(QWRAPPER
){ [ -d bin-wrappers
] || mkdir bin-wrappers
; } && \
121 echo
'#!$(SHELL_PATH_SQ)' >"$@" && \
122 curdir
="$$(pwd -P)" && \
123 echo
"TG_INST_CMDDIR='$$curdir' && export TG_INST_CMDDIR" >>"$@" && \
124 echo
"TG_INST_SHAREDIR='$$curdir' && export TG_INST_SHAREDIR" >>"$@" && \
125 echo
"TG_INST_HOOKSDIR='$$curdir' && export TG_INST_HOOKSDIR" >>"$@" && \
126 echo
'[ -n "$$tg__include" ] || exec $(SHELL_PATH_SQ) -c '\''. "$$TG_INST_CMDDIR/tg"'\'' tg "$$@" || exit' >>"$@" && \
127 echo
". '$$curdir/tg'" >>"$@" && \
130 $(help_out
): README create-help.sh
131 $(QHELP
)CMD
="$@" CMD
="$${CMD#tg-}" CMD
="$${CMD%.txt}" && \
132 $(SHELL_PATH
) .
/create-help.sh
"$$CMD"
134 .PHONY
: doc install-doc html
138 install-doc
:: install-html
140 html
:: topgit.html
$(html_out
)
142 tg-tg.txt
: README create-html-usage.pl
$(commands_in
)
143 $(QHELPTG
)perl .
/create-html-usage.pl
--text
< README
> $@
145 topgit.html
: README create-html-usage.pl
$(commands_in
)
146 $(QHTMLTOPGIT
)perl .
/create-html-usage.pl
< README | rst2html.py
- $@
148 $(html_out
): create-html.sh
149 $(QHTML
)CMD
="$@" CMD
="$${CMD#tg-}" CMD
="$${CMD%.html}" && \
150 $(SHELL_PATH
) .
/create-html.sh
"$$CMD"
158 $(Q
)echo skipping precheck because DESTDIR is set
164 install -d
-m
755 "$(DESTDIR)$(bindir)"
165 install tg
"$(DESTDIR)$(bindir)"
166 install -d
-m
755 "$(DESTDIR)$(cmddir)"
167 install $(commands_out
) $(utils_out
) "$(DESTDIR)$(cmddir)"
168 install -d
-m
755 "$(DESTDIR)$(cmddir)/awk"
169 install $(awk_out
) "$(DESTDIR)$(cmddir)/awk"
170 install -d
-m
755 "$(DESTDIR)$(hooksdir)"
171 install $(hooks_out
) "$(DESTDIR)$(hooksdir)"
172 install -d
-m
755 "$(DESTDIR)$(sharedir)"
173 install -m
644 $(help_out
) tg-tg.txt
"$(DESTDIR)$(sharedir)"
178 install -d
-m
755 "$(DESTDIR)$(sharedir)"
179 install -m
644 topgit.html
$(html_out
) "$(DESTDIR)$(sharedir)"
184 rm -f tg
$(commands_out
) $(utils_out
) $(awk_out
) $(hooks_out
) $(helpers_out
) $(help_out
) tg-tg.txt topgit.html
$(html_out
)
185 rm -f TG-BUILD-SETTINGS
187 +$(Q
)$(MAKE
) -C t
clean
189 define BUILD_SETTINGS
190 TG_INST_BINDIR
='$(bindir)'
191 TG_INST_CMDDIR
='$(cmddir)'
192 TG_INST_HOOKSDIR
='$(hooksdir)'
193 TG_INST_SHAREDIR
='$(sharedir)'
194 SHELL_PATH
='$(SHELL_PATH)'
195 TG_VERSION
='$(version)'
196 TG_GIT_MINIMUM_VERSION
='$(GIT_MINIMUM_VERSION)'
198 export BUILD_SETTINGS
200 TG-BUILD-SETTINGS
: FORCE
201 $(Q
)if
test x
"$$BUILD_SETTINGS" != x
"`cat $@ 2>/dev/null`"; then \
202 echo
"* new build settings"; \
203 echo
"$$BUILD_SETTINGS" >$@
; \
207 +$(Q
)$(MAKE
) -C t
all