README: add merge strategy information
[topgit/pro.git] / Makefile
blob19375360cb4da08a0b5fc4afb7e2482c2c745c95
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 prefix ?= $(HOME)
15 bindir = $(prefix)/bin
16 cmddir = $(prefix)/libexec/topgit
17 sharedir = $(prefix)/share/topgit
18 hooksdir = $(cmddir)/hooks
20 commands_in := $(wildcard tg-[!-]*.sh)
21 utils_in := $(wildcard tg--*.sh)
22 hooks_in = hooks/pre-commit.sh
24 commands_out = $(patsubst %.sh,%,$(commands_in))
25 utils_out = $(patsubst %.sh,%,$(utils_in))
26 hooks_out = $(patsubst %.sh,%,$(hooks_in))
27 PROGRAMS = $(commands_out) $(utils_out)
28 help_out = $(patsubst %.sh,%.txt,tg-help.sh tg-status.sh $(commands_in))
29 html_out = $(patsubst %.sh,%.html,tg-help.sh tg-status.sh tg-tg.sh $(commands_in))
31 SHELL_PATH ?= /bin/sh
32 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
34 version := $(shell test -d .git && git describe --match "topgit-[0-9]*" --abbrev=4 --dirty 2>/dev/null | sed -e 's/^topgit-//' )
36 -include config.mak
37 SHELL = $(SHELL_PATH)
39 ifneq ($(strip $(version)),)
40 version_arg = -e s/TG_VERSION=.*/TG_VERSION=$(version)/
41 endif
43 .PHONY: FORCE
45 all:: shell_compatibility_test precheck $(commands_out) $(utils_out) $(hooks_out) bin-wrappers/tg $(help_out) tg-tg.txt
47 please_set_SHELL_PATH_to_a_more_modern_shell:
48 @$$(:)
50 shell_compatibility_test: please_set_SHELL_PATH_to_a_more_modern_shell
52 tg $(commands_out) $(utils_out) $(hooks_out): % : %.sh Makefile TG-BUILD-SETTINGS
53 @echo "[SED] $@"
54 @sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
55 -e 's#@cmddir@#$(cmddir)#g;' \
56 -e 's#@hooksdir@#$(hooksdir)#g' \
57 -e 's#@bindir@#$(bindir)#g' \
58 -e 's#@sharedir@#$(sharedir)#g' \
59 -e 's#@mingitver@#$(GIT_MINIMUM_VERSION)#g' \
60 -e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
61 $(version_arg) \
62 $@.sh >$@+ && \
63 chmod +x $@+ && \
64 mv $@+ $@
66 bin-wrappers/tg : $(commands_out) $(utils_out) $(hooks_out) tg
67 @echo "[WRAPPER] $@"
68 @[ -d bin-wrappers ] || mkdir bin-wrappers
69 @echo '#!$(SHELL_PATH_SQ)' >"$@"
70 @curdir="$$(pwd -P)"; \
71 echo "TG_INST_CMDDIR='$$curdir' && export TG_INST_CMDDIR" >>"$@"; \
72 echo "TG_INST_SHAREDIR='$$curdir' && export TG_INST_SHAREDIR" >>"$@"; \
73 echo "TG_INST_HOOKSDIR='$$curdir' && export TG_INST_HOOKSDIR" >>"$@"; \
74 echo "exec '$$curdir/tg' \"\$$@\"" >>"$@"
75 @chmod a+x "$@"
77 $(help_out): README create-help.sh
78 @CMD=`echo $@ | sed -e 's/tg-//' -e 's/\.txt//'` && \
79 echo '[HELP]' $$CMD && \
80 $(SHELL_PATH) ./create-help.sh $$CMD
82 .PHONY: doc install-doc html
84 doc:: html
86 install-doc:: install-html
88 html:: topgit.html $(html_out)
90 tg-tg.txt: README create-html-usage.pl $(commands_in)
91 @echo '[HELP] tg'
92 @perl ./create-html-usage.pl --text < README > $@
94 topgit.html: README create-html-usage.pl $(commands_in)
95 @echo '[HTML] topgit'
96 @perl ./create-html-usage.pl < README | rst2html.py - $@
98 $(html_out): create-html.sh
99 @CMD=`echo $@ | sed -e 's/tg-//' -e 's/\.html//'` && \
100 echo '[HTML]' $$CMD && \
101 $(SHELL_PATH) ./create-html.sh $$CMD
103 .PHONY: precheck
105 precheck:: tg
106 ifeq ($(DESTDIR),)
107 @./$+ precheck
108 else
109 @echo skipping precheck because DESTDIR is set
110 endif
112 .PHONY: install
114 install:: all
115 install -d -m 755 "$(DESTDIR)$(bindir)"
116 install tg "$(DESTDIR)$(bindir)"
117 install -d -m 755 "$(DESTDIR)$(cmddir)"
118 install $(commands_out) $(utils_out) "$(DESTDIR)$(cmddir)"
119 install -d -m 755 "$(DESTDIR)$(hooksdir)"
120 install $(hooks_out) "$(DESTDIR)$(hooksdir)"
121 install -d -m 755 "$(DESTDIR)$(sharedir)"
122 install -m 644 $(help_out) tg-tg.txt "$(DESTDIR)$(sharedir)"
123 install -m 644 leaves.awk "$(DESTDIR)$(sharedir)"
125 .PHONY: install-html
127 install-html:: html
128 install -d -m 755 "$(DESTDIR)$(sharedir)"
129 install -m 644 topgit.html $(html_out) "$(DESTDIR)$(sharedir)"
131 .PHONY: clean
133 clean::
134 rm -f tg $(commands_out) $(utils_out) $(hooks_out) $(help_out) topgit.html $(html_out)
135 rm -f TG-BUILD-SETTINGS
136 rm -rf bin-wrappers
137 +@$(MAKE) -C t clean
139 define BUILD_SETTINGS
140 TG_INST_BINDIR='$(bindir)'
141 TG_INST_CMDDIR='$(cmddir)'
142 TG_INST_HOOKSDIR='$(hooksdir)'
143 TG_INST_SHAREDIR='$(sharedir)'
144 SHELL_PATH='$(SHELL_PATH)'
145 TG_VERSION='$(version)'
146 TG_GIT_MINIMUM_VERSION='$(GIT_MINIMUM_VERSION)'
147 endef
148 export BUILD_SETTINGS
150 TG-BUILD-SETTINGS: FORCE
151 @if test x"$$BUILD_SETTINGS" != x"`cat $@ 2>/dev/null`"; then \
152 echo "* new build settings"; \
153 echo "$$BUILD_SETTINGS" >$@; \
156 test:: all
157 +@$(MAKE) -C t all