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 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
))
38 SHELL_PATH_SQ
= $(subst ','\'',$(SHELL_PATH))
41 AWK_PATH_SQ = $(subst ','\'',$(AWK_PATH
))
43 version
:= $(shell test -d .git
&& git describe
--match
"topgit-[0-9]*" --abbrev
=4 --dirty
2>/dev
/null | sed
-e
's/^topgit-//' )
47 ifeq ($(subst /,,$(AWK_PATH
)),$(AWK_PATH
))
48 AWK_PREFIX
= /usr
/bin
/
53 ifneq ($(strip $(version
)),)
54 version_arg
= -e s
/TG_VERSION
=.
*/TG_VERSION
=$(version
)/
59 all:: shell_compatibility_test precheck
$(commands_out
) $(utils_out
) $(hooks_out
) $(helpers_out
) bin-wrappers
/tg
$(help_out
) tg-tg.txt
61 please_set_SHELL_PATH_to_a_more_modern_shell
:
64 shell_compatibility_test
: please_set_SHELL_PATH_to_a_more_modern_shell
73 QSED_
= $(AT
)echo
"[SED] $@" &&
76 QHELP_
= $(AT
)CMD
="$@" CMD
="$${CMD$(POUND)tg-}" && echo
"[HELP] $${CMD%.txt}" &&
79 QHELPTG_
= $(AT
)echo
"[HELP] tg" &&
80 QHELPTG_0
= $(QHELPTG_
)
81 QHELPTG
= $(QHELPTG_
$(V
))
82 QHTML_
= $(AT
)CMD
="$@" CMD
="$${CMD$(POUND)tg-}" && echo
"[HTML] $${CMD%.html}" &&
85 QHTMLTOPGIT_
= $(AT
)echo
"[HTML] topgit" &&
86 QHTMLTOPGIT_0
= $(QHTMLTOPGIT_
)
87 QHTMLTOPGIT
= $(QHTMLTOPGIT_
$(V
))
88 QWRAPPER_
= $(AT
)echo
"[WRAPPER] $@" &&
89 QWRAPPER_0
= $(QWRAPPER_
)
90 QWRAPPER
= $(QWRAPPER_
$(V
))
92 tg
$(commands_out
) $(utils_out
) $(hooks_out
) $(helpers_out
): % : %.sh Makefile TG-BUILD-SETTINGS
94 -e
'1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
95 -e
'1s|#!.*/awk|#!$(AWK_PREFIX)$(AWK_PATH_SQ)|' \
96 -e
's#@cmddir@#$(cmddir)#g;' \
97 -e
's#@hooksdir@#$(hooksdir)#g' \
98 -e
's#@bindir@#$(bindir)#g' \
99 -e
's#@sharedir@#$(sharedir)#g' \
100 -e
's#@mingitver@#$(GIT_MINIMUM_VERSION)#g' \
101 -e
's#@tgsthelpusage@#$(TG_STATUS_HELP_USAGE)#g' \
102 -e
's#@SHELL_PATH@#$(SHELL_PATH_SQ)#g' \
103 -e
's#@AWK_PATH@#$(AWK_PATH_SQ)#g' \
109 bin-wrappers
/tg
: $(commands_out
) $(utils_out
) $(hooks_out
) $(helpers_out
) tg
110 $(QWRAPPER
){ [ -d bin-wrappers
] || mkdir bin-wrappers
; } && \
111 echo
'#!$(SHELL_PATH_SQ)' >"$@" && \
112 curdir
="$$(pwd -P)" && \
113 echo
"TG_INST_CMDDIR='$$curdir' && export TG_INST_CMDDIR" >>"$@" && \
114 echo
"TG_INST_SHAREDIR='$$curdir' && export TG_INST_SHAREDIR" >>"$@" && \
115 echo
"TG_INST_HOOKSDIR='$$curdir' && export TG_INST_HOOKSDIR" >>"$@" && \
116 echo
'[ -n "$$tg__include" ] || exec $(SHELL_PATH_SQ) -c '\''. "$$TG_INST_CMDDIR/tg"'\'' tg "$$@" || exit' >>"$@" && \
117 echo
". '$$curdir/tg'" >>"$@" && \
120 $(help_out
): README create-help.sh
121 $(QHELP
)CMD
="$@" CMD
="$${CMD#tg-}" CMD
="$${CMD%.txt}" && \
122 $(SHELL_PATH
) .
/create-help.sh
"$$CMD"
124 .PHONY
: doc install-doc html
128 install-doc
:: install-html
130 html
:: topgit.html
$(html_out
)
132 tg-tg.txt
: README create-html-usage.pl
$(commands_in
)
133 $(QHELPTG
)perl .
/create-html-usage.pl
--text
< README
> $@
135 topgit.html
: README create-html-usage.pl
$(commands_in
)
136 $(QHTMLTOPGIT
)perl .
/create-html-usage.pl
< README | rst2html.py
- $@
138 $(html_out
): create-html.sh
139 $(QHTML
)CMD
="$@" CMD
="$${CMD#tg-}" CMD
="$${CMD%.html}" && \
140 $(SHELL_PATH
) .
/create-html.sh
"$$CMD"
148 $(Q
)echo skipping precheck because DESTDIR is set
154 install -d
-m
755 "$(DESTDIR)$(bindir)"
155 install tg
"$(DESTDIR)$(bindir)"
156 install -d
-m
755 "$(DESTDIR)$(cmddir)"
157 install $(commands_out
) $(utils_out
) "$(DESTDIR)$(cmddir)"
158 install -d
-m
755 "$(DESTDIR)$(hooksdir)"
159 install $(hooks_out
) "$(DESTDIR)$(hooksdir)"
160 install -d
-m
755 "$(DESTDIR)$(sharedir)"
161 install -m
644 $(help_out
) tg-tg.txt
"$(DESTDIR)$(sharedir)"
162 install -m
644 leaves.awk
"$(DESTDIR)$(sharedir)"
167 install -d
-m
755 "$(DESTDIR)$(sharedir)"
168 install -m
644 topgit.html
$(html_out
) "$(DESTDIR)$(sharedir)"
173 rm -f tg
$(commands_out
) $(utils_out
) $(hooks_out
) $(helpers_out
) $(help_out
) topgit.html
$(html_out
)
174 rm -f TG-BUILD-SETTINGS
176 +$(Q
)$(MAKE
) -C t
clean
178 define BUILD_SETTINGS
179 TG_INST_BINDIR
='$(bindir)'
180 TG_INST_CMDDIR
='$(cmddir)'
181 TG_INST_HOOKSDIR
='$(hooksdir)'
182 TG_INST_SHAREDIR
='$(sharedir)'
183 SHELL_PATH
='$(SHELL_PATH)'
184 TG_VERSION
='$(version)'
185 TG_GIT_MINIMUM_VERSION
='$(GIT_MINIMUM_VERSION)'
187 export BUILD_SETTINGS
189 TG-BUILD-SETTINGS
: FORCE
190 $(Q
)if
test x
"$$BUILD_SETTINGS" != x
"`cat $@ 2>/dev/null`"; then \
191 echo
"* new build settings"; \
192 echo
"$$BUILD_SETTINGS" >$@
; \
196 +$(Q
)$(MAKE
) -C t
all