tg-revert.sh: convert any top-bases in TOPGIT REFS
[topgit/pro.git] / Makefile
blob3c3bea133fef52cb874bd146d63331363065e81d
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 hooks_in = hooks/pre-commit.sh
23 commands_out = $(patsubst %.sh,%,$(commands_in))
24 hooks_out = $(patsubst %.sh,%,$(hooks_in))
25 help_out = $(patsubst %.sh,%.txt,tg-help.sh $(commands_in))
26 html_out = $(patsubst %.sh,%.html,tg-help.sh tg-tg.sh $(commands_in))
28 SHELL_PATH ?= /bin/sh
29 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
31 version := $(shell test -d .git && git describe --match "topgit-[0-9]*" --abbrev=4 --dirty 2>/dev/null | sed -e 's/^topgit-//' )
33 -include config.mak
34 SHELL = $(SHELL_PATH)
36 ifneq ($(strip $(version)),)
37 version_arg = -e s/TG_VERSION=.*/TG_VERSION=$(version)/
38 endif
40 .PHONY: FORCE
42 all:: shell_compatibility_test precheck $(commands_out) $(hooks_out) bin-wrappers/tg $(help_out) tg-tg.txt
44 please_set_SHELL_PATH_to_a_more_modern_shell:
45 @$$(:)
47 shell_compatibility_test: please_set_SHELL_PATH_to_a_more_modern_shell
49 tg $(commands_out) $(hooks_out): % : %.sh Makefile TG-BUILD-SETTINGS
50 @echo "[SED] $@"
51 @sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \
52 -e 's#@cmddir@#$(cmddir)#g;' \
53 -e 's#@hooksdir@#$(hooksdir)#g' \
54 -e 's#@bindir@#$(bindir)#g' \
55 -e 's#@sharedir@#$(sharedir)#g' \
56 -e 's#@mingitver@#$(GIT_MINIMUM_VERSION)#g' \
57 -e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \
58 $(version_arg) \
59 $@.sh >$@+ && \
60 chmod +x $@+ && \
61 mv $@+ $@
63 bin-wrappers/tg : $(commands_out) $(hooks_out) tg
64 @echo "[WRAPPER] $@"
65 @[ -d bin-wrappers ] || mkdir bin-wrappers
66 @echo '#!$(SHELL_PATH_SQ)' >"$@"
67 @curdir="$$(pwd -P)"; \
68 echo "TG_INST_CMDDIR='$$curdir' && export TG_INST_CMDDIR" >>"$@"; \
69 echo "TG_INST_SHAREDIR='$$curdir' && export TG_INST_SHAREDIR" >>"$@"; \
70 echo "TG_INST_HOOKSDIR='$$curdir' && export TG_INST_HOOKSDIR" >>"$@"; \
71 echo "exec '$$curdir/tg' \"\$$@\"" >>"$@"
72 @chmod a+x "$@"
74 $(help_out): README create-help.sh
75 @CMD=`echo $@ | sed -e 's/tg-//' -e 's/\.txt//'` && \
76 echo '[HELP]' $$CMD && \
77 $(SHELL_PATH) ./create-help.sh $$CMD
79 .PHONY: doc install-doc html
81 doc:: html
83 install-doc:: install-html
85 html:: topgit.html $(html_out)
87 tg-tg.txt: README create-html-usage.pl $(wildcard tg-*.sh)
88 @echo '[HELP] tg'
89 @perl ./create-html-usage.pl --text < README > $@
91 topgit.html: README create-html-usage.pl $(wildcard tg-*.sh)
92 @echo '[HTML] topgit'
93 @perl ./create-html-usage.pl < README | rst2html.py - $@
95 $(html_out): create-html.sh
96 @CMD=`echo $@ | sed -e 's/tg-//' -e 's/\.html//'` && \
97 echo '[HTML]' $$CMD && \
98 $(SHELL_PATH) ./create-html.sh $$CMD
100 .PHONY: precheck
102 precheck:: tg
103 ifeq ($(DESTDIR),)
104 @./$+ precheck
105 else
106 @echo skipping precheck because DESTDIR is set
107 endif
109 .PHONY: install
111 install:: all
112 install -d -m 755 "$(DESTDIR)$(bindir)"
113 install tg "$(DESTDIR)$(bindir)"
114 install -d -m 755 "$(DESTDIR)$(cmddir)"
115 install $(commands_out) "$(DESTDIR)$(cmddir)"
116 install -d -m 755 "$(DESTDIR)$(hooksdir)"
117 install $(hooks_out) "$(DESTDIR)$(hooksdir)"
118 install -d -m 755 "$(DESTDIR)$(sharedir)"
119 install -m 644 $(help_out) tg-tg.txt "$(DESTDIR)$(sharedir)"
120 install -m 644 leaves.awk "$(DESTDIR)$(sharedir)"
122 .PHONY: install-html
124 install-html:: html
125 install -d -m 755 "$(DESTDIR)$(sharedir)"
126 install -m 644 topgit.html $(html_out) "$(DESTDIR)$(sharedir)"
128 .PHONY: clean
130 clean::
131 rm -f tg $(commands_out) $(hooks_out) $(help_out) topgit.html $(html_out)
132 rm -f TG-BUILD-SETTINGS
133 rm -rf bin-wrappers
134 +@$(MAKE) -C t clean
136 define BUILD_SETTINGS
137 TG_INST_BINDIR='$(bindir)'
138 TG_INST_CMDDIR='$(cmddir)'
139 TG_INST_HOOKSDIR='$(hooksdir)'
140 TG_INST_SHAREDIR='$(sharedir)'
141 SHELL_PATH='$(SHELL_PATH)'
142 TG_VERSION='$(version)'
143 TG_GIT_MINIMUM_VERSION='$(GIT_MINIMUM_VERSION)'
144 endef
145 export BUILD_SETTINGS
147 TG-BUILD-SETTINGS: FORCE
148 @if test x"$$BUILD_SETTINGS" != x"`cat $@ 2>/dev/null`"; then \
149 echo "* new build settings"; \
150 echo "$$BUILD_SETTINGS" >$@; \
153 test:: all
154 +@$(MAKE) -C t all