d6cdbf548e80f29c6858157de9a8b4de1832d9cd
[tig.git] / Makefile
1 ## Makefile for tig
2
3 # The last tagged version. Can be overridden either by the version from
4 # git or from the value of the DIST_VERSION environment variable.
5 VERSION = 2.0.3
6
7 all:
8
9 # Include kernel specific configuration
10 kernel_name := $(shell sh -c 'uname -s 2>/dev/null || echo unknown')
11 -include contrib/config.make-$(kernel_name)
12
13 # Include setting from the configure script
14 -include config.make
15
16 # Optional defaults.
17 # TIG_ variables are set by contrib/config.make-$(kernel_name).
18 TIG_NCURSES ?= -lcurses
19 LDFLAGS ?= $(TIG_LDFLAGS)
20 CPPFLAGS ?= $(TIG_CPPFLAGS)
21 LDLIBS ?= $(TIG_NCURSES) $(TIG_LDLIBS)
22 CFLAGS ?= -Wall -O2 $(TIG_CFLAGS)
23
24 prefix ?= $(HOME)
25 bindir ?= $(prefix)/bin
26 datarootdir ?= $(prefix)/share
27 sysconfdir ?= $(prefix)/etc
28 docdir ?= $(datarootdir)/doc
29 mandir ?= $(datarootdir)/man
30 # DESTDIR=
31
32 ifneq (,$(wildcard .git))
33 GITDESC = $(subst tig-,,$(shell git describe 2>/dev/null))
34 COMMIT := $(if $(GITDESC),$(GITDESC),$(VERSION)-g$(shell git describe --always))
35 WTDIRTY = $(if $(shell git diff-index HEAD 2>/dev/null),-dirty)
36 VERSION = $(COMMIT)$(WTDIRTY)
37 endif
38 ifdef DIST_VERSION
39 VERSION = $(DIST_VERSION)
40 endif
41
42 # Split the version "TAG-OFFSET-gSHA1-DIRTY" into "TAG OFFSET"
43 # and append 0 as a fallback offset for "exact" tagged versions.
44 RPM_VERLIST = $(filter-out g% dirty,$(subst -, ,$(VERSION))) 0
45 RPM_VERSION = $(word 1,$(RPM_VERLIST))
46 RPM_RELEASE = $(word 2,$(RPM_VERLIST))$(if $(WTDIRTY),.dirty)
47
48 DFLAGS = -g -DDEBUG -Werror -O0
49 EXE = src/tig
50 TOOLS = test/tools/test-graph tools/doc-gen
51 TXTDOC = doc/tig.1.adoc doc/tigrc.5.adoc doc/manual.adoc NEWS.adoc README.adoc INSTALL.adoc
52 MANDOC = doc/tig.1 doc/tigrc.5 doc/tigmanual.7
53 HTMLDOC = doc/tig.1.html doc/tigrc.5.html doc/manual.html README.html INSTALL.html NEWS.html
54 ALLDOC = $(MANDOC) $(HTMLDOC) doc/manual.html-chunked doc/manual.pdf
55
56 # Never include the release number in the tarname for tagged
57 # versions.
58 ifneq ($(if $(DIST_VERSION),$(words $(RPM_VERLIST))),2)
59 TARNAME = tig-$(RPM_VERSION)-$(RPM_RELEASE)
60 else
61 TARNAME = tig-$(RPM_VERSION)
62 endif
63
64 override CPPFLAGS += '-DTIG_VERSION="$(VERSION)"'
65 override CPPFLAGS += '-DSYSCONFDIR="$(sysconfdir)"'
66
67 ASCIIDOC ?= asciidoc
68 ASCIIDOC_FLAGS = -aversion=$(VERSION) -asysconfdir=$(sysconfdir) -f doc/asciidoc.conf
69 XMLTO ?= xmlto
70 DOCBOOK2PDF ?= docbook2pdf
71
72 all: $(EXE) $(TOOLS)
73 all-debug: $(EXE) $(TOOLS)
74 all-debug: CFLAGS += $(DFLAGS)
75 doc: $(ALLDOC)
76 doc-man: $(MANDOC)
77 doc-html: $(HTMLDOC)
78
79 export sysconfdir
80
81 install: all
82 $(QUIET_INSTALL)tools/install.sh bin $(EXE) "$(DESTDIR)$(bindir)"
83 $(QUIET_INSTALL)tools/install.sh data tigrc "$(DESTDIR)$(sysconfdir)"
84
85 install-doc-man: doc-man
86 $(Q)$(foreach doc, $(filter %.1, $(MANDOC)), \
87 $(QUIET_INSTALL_EACH)tools/install.sh data $(doc) "$(DESTDIR)$(mandir)/man1";)
88 $(Q)$(foreach doc, $(filter %.5, $(MANDOC)), \
89 $(QUIET_INSTALL_EACH)tools/install.sh data $(doc) "$(DESTDIR)$(mandir)/man5";)
90 $(Q)$(foreach doc, $(filter %.7, $(MANDOC)), \
91 $(QUIET_INSTALL_EACH)tools/install.sh data $(doc) "$(DESTDIR)$(mandir)/man7";)
92
93 install-release-doc-man:
94 GIT_INDEX_FILE=.tmp-doc-index git read-tree origin/release
95 GIT_INDEX_FILE=.tmp-doc-index git checkout-index -f --prefix=./ $(MANDOC)
96 rm -f .tmp-doc-index
97 $(MAKE) install-doc-man
98
99 install-doc-html: doc-html
100 $(Q)$(foreach doc, $(HTMLDOC), \
101 $(QUIET_INSTALL_EACH)tools/install.sh data $(doc) "$(DESTDIR)$(docdir)/tig";)
102
103 install-release-doc-html:
104 GIT_INDEX_FILE=.tmp-doc-index git read-tree origin/release
105 GIT_INDEX_FILE=.tmp-doc-index git checkout-index -f --prefix=./ $(HTMLDOC)
106 rm -f .tmp-doc-index
107 $(MAKE) install-doc-html
108
109 install-doc: install-doc-man install-doc-html
110 install-release-doc: install-release-doc-man install-release-doc-html
111
112 clean: clean-test
113 $(RM) -r $(TARNAME) *.spec tig-*.tar.gz tig-*.tar.gz.md5 .deps
114 $(RM) $(EXE) $(TOOLS) $(OBJS) core doc/*.xml src/builtin-config.c
115
116 distclean: clean
117 $(RM) -r doc/manual.html-chunked autom4te.cache release-docs
118 $(RM) doc/*.toc $(ALLDOC) aclocal.m4 configure
119 $(RM) config.h config.log config.make config.status config.h.in
120
121 spell-check:
122 for file in $(TXTDOC) src/tig.c; do \
123 aspell --lang=en --dont-backup \
124 --personal=./tools/aspell.dict check $$file; \
125 done
126
127 strip: $(EXE)
128 strip $(EXE)
129
130 update-headers:
131 @for file in include/tig/*.h src/*.c tools/*.c test/tools/*.c; do \
132 grep -q '/* Copyright' "$$file" && \
133 sed '0,/.*\*\//d' < "$$file" | \
134 grep -v '/* vim: set' > "$$file.tmp"; \
135 { cat tools/header.h "$$file.tmp"; \
136 echo "/* vim: set ts=8 sw=8 noexpandtab: */"; } > "$$file"; \
137 rm "$$file.tmp"; \
138 echo "Updated $$file"; \
139 done
140
141 update-docs: tools/doc-gen
142 doc="doc/tigrc.5.adoc"; \
143 sed -n '0,/ifndef::DOC_GEN_ACTIONS/p' < "$$doc" > "$$doc.gen"; \
144 ./tools/doc-gen actions >> "$$doc.gen"; \
145 sed -n '/endif::DOC_GEN_ACTIONS/,$$p' < "$$doc" >> "$$doc.gen" ; \
146 mv "$$doc.gen" "$$doc"
147
148 dist: configure tig.spec
149 $(Q)mkdir -p $(TARNAME) && \
150 cp Makefile tig.spec configure config.h.in aclocal.m4 $(TARNAME) && \
151 sed -i "s/VERSION\s\+=\s\+[0-9]\+\([.][0-9]\+\)\+/VERSION = $(VERSION)/" $(TARNAME)/Makefile
152 git archive --format=tar --prefix=$(TARNAME)/ HEAD | \
153 tar --delete $(TARNAME)/Makefile > $(TARNAME).tar && \
154 tar rf $(TARNAME).tar `find $(TARNAME)/*` && \
155 gzip -f -9 $(TARNAME).tar && \
156 md5sum $(TARNAME).tar.gz > $(TARNAME).tar.gz.md5
157 $(Q)$(RM) -r $(TARNAME)
158
159 rpm: dist
160 rpmbuild -ta $(TARNAME).tar.gz
161
162 TESTS = $(sort $(shell find test -type f -name '*-test'))
163
164 clean-test:
165 $(Q)$(RM) -r test/tmp
166
167 test: clean-test $(TESTS)
168 $(QUIET_SUMMARY)test/tools/show-results.sh
169
170 export TEST_OPTS ?= $(V:1=no-indent)
171
172 $(TESTS): PATH := $(CURDIR)/test/tools:$(CURDIR)/src:$(PATH)
173 $(TESTS): $(EXE) test/tools/test-graph
174 $(QUIET_TEST)$(TEST_SHELL) $@
175
176 # Other autoconf-related rules are hidden in config.make.in so that
177 # they don't confuse Make when we aren't actually using ./configure
178 configure: configure.ac acinclude.m4 tools/*.m4
179 ./autogen.sh
180
181 .PHONY: all all-debug doc doc-man doc-html install install-doc $(TESTS) \
182 install-doc-man install-doc-html clean spell-check dist rpm test
183
184 ifdef NO_MKSTEMPS
185 COMPAT_CPPFLAGS += -DNO_MKSTEMPS
186 COMPAT_OBJS += compat/mkstemps.o
187 endif
188
189 ifdef NO_SETENV
190 COMPAT_CPPFLAGS += -DNO_SETENV
191 COMPAT_OBJS += compat/setenv.o
192 endif
193
194 ifdef NO_STRNDUP
195 COMPAT_CPPFLAGS += -DNO_STRNDUP
196 COMPAT_OBJS += compat/strndup.o
197 endif
198
199 COMPAT_OBJS += compat/hashtab.o
200
201 override CPPFLAGS += $(COMPAT_CPPFLAGS)
202
203 GRAPH_OBJS = src/graph.o src/graph-v1.o src/graph-v2.o
204
205 TIG_OBJS = \
206 src/tig.o \
207 src/types.o \
208 src/string.o \
209 src/util.o \
210 src/map.o \
211 src/argv.o \
212 src/io.o \
213 src/refdb.o \
214 src/builtin-config.o \
215 src/request.o \
216 src/line.o \
217 src/keys.o \
218 src/repo.o \
219 src/options.o \
220 src/draw.o \
221 src/prompt.o \
222 src/display.o \
223 src/view.o \
224 src/parse.o \
225 src/watch.o \
226 src/pager.o \
227 src/log.o \
228 src/diff.o \
229 src/help.o \
230 src/tree.o \
231 src/blob.o \
232 src/blame.o \
233 src/refs.o \
234 src/status.o \
235 src/stage.o \
236 src/main.o \
237 src/stash.o \
238 src/grep.o \
239 $(GRAPH_OBJS) \
240 $(COMPAT_OBJS)
241
242 src/tig: $(TIG_OBJS)
243
244 TEST_GRAPH_OBJS = test/tools/test-graph.o src/string.o src/util.o src/io.o $(GRAPH_OBJS) $(COMPAT_OBJS)
245 test/tools/test-graph: $(TEST_GRAPH_OBJS)
246
247 DOC_GEN_OBJS = tools/doc-gen.o src/string.o src/types.o src/util.o src/request.o
248 tools/doc-gen: $(DOC_GEN_OBJS)
249
250 OBJS = $(sort $(TIG_OBJS) $(TEST_GRAPH_OBJS) $(DOC_GEN_OBJS))
251
252 DEPS_CFLAGS ?= -MMD -MP -MF .deps/$*.d
253
254 %: %.o
255 $(QUIET_LINK)$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@
256
257 %.o: %.c $(CONFIG_H)
258 @mkdir -p .deps/$(*D)
259 $(QUIET_CC)$(CC) -I. -Iinclude $(CFLAGS) $(DEPS_CFLAGS) $(CPPFLAGS) -c -o $@ $<
260
261 -include $(OBJS:%.o=.deps/%.d)
262
263 src/builtin-config.c: tigrc tools/make-builtin-config.sh
264 $(QUIET_GEN)tools/make-builtin-config.sh $< > $@
265
266 tig.spec: contrib/tig.spec.in
267 $(QUIET_GEN)sed -e 's/@@VERSION@@/$(RPM_VERSION)/g' \
268 -e 's/@@RELEASE@@/$(RPM_RELEASE)/g' < $< > $@
269
270 doc/manual.html: doc/manual.toc
271 doc/manual.html: ASCIIDOC_FLAGS += -ainclude-manual-toc
272 %.toc: %.adoc
273 $(QUIET_GEN)sed -n '/^\[\[/,/\(---\|~~~\)/p' < $< | while read line; do \
274 case "$$line" in \
275 "----"*) echo ". <<$$ref>>"; ref= ;; \
276 "~~~~"*) echo "- <<$$ref>>"; ref= ;; \
277 "[["*"]]") ref="$$line" ;; \
278 *) ref="$$ref, $$line" ;; \
279 esac; done | sed 's/\[\[\(.*\)\]\]/\1/' > $@
280
281 README.html: README.adoc doc/asciidoc.conf
282 $(QUIET_ASCIIDOC)$(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d article -a readme $<
283
284 INSTALL.html: INSTALL.adoc doc/asciidoc.conf
285 $(QUIET_ASCIIDOC)$(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d article $<
286
287 NEWS.html: NEWS.adoc doc/asciidoc.conf
288 $(QUIET_ASCIIDOC)$(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d article $<
289
290 doc/tigmanual.7: doc/manual.adoc
291
292 %.1.html : %.1.adoc doc/asciidoc.conf
293 $(QUIET_ASCIIDOC)$(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d manpage $<
294
295 %.1.xml : %.1.adoc doc/asciidoc.conf
296 $(QUIET_ASCIIDOC)$(ASCIIDOC) $(ASCIIDOC_FLAGS) -b docbook -d manpage $<
297
298 %.5.html : %.5.adoc doc/asciidoc.conf
299 $(QUIET_ASCIIDOC)$(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d manpage $<
300
301 %.5.xml : %.5.adoc doc/asciidoc.conf
302 $(QUIET_ASCIIDOC)$(ASCIIDOC) $(ASCIIDOC_FLAGS) -b docbook -d manpage $<
303
304 %.7.xml : %.7.adoc doc/asciidoc.conf
305 $(QUIET_ASCIIDOC)$(ASCIIDOC) $(ASCIIDOC_FLAGS) -b docbook -d manpage $<
306
307 %.html: ASCIIDOC_FLAGS += -adocext=html
308 %.html : %.adoc doc/asciidoc.conf
309 $(QUIET_ASCIIDOC)$(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d article -n $<
310
311 %.xml : %.adoc doc/asciidoc.conf
312 $(QUIET_ASCIIDOC)$(ASCIIDOC) $(ASCIIDOC_FLAGS) -b docbook -d article $<
313
314 % : %.xml
315 $(QUIET_XMLTO)$(XMLTO) man -o doc $<
316
317 %.html-chunked : %.xml
318 $(QUIET_XMLTO)$(XMLTO) html -o $@ $<
319
320 %.pdf : %.xml
321 $(QUIET_DB2PDF)$(DOCBOOK2PDF) -o doc $<
322
323 #############################################################################
324 # Quiet make
325 #############################################################################
326
327 ifneq ($(findstring $(MAKEFLAGS),s),s)
328 V = @
329 Q = $(V:1=)
330 QUIET_CC = $(Q:@=@echo ' CC '$@;)
331 QUIET_LINK = $(Q:@=@echo ' LINK '$@;)
332 QUIET_GEN = $(Q:@=@echo ' GEN '$@;)
333 QUIET_ASCIIDOC = $(Q:@=@echo ' ASCIIDOC '$@;)
334 QUIET_XMLTO = $(Q:@=@echo ' XMLTO '$@;)
335 QUIET_DB2PDF = $(Q:@=@echo ' DB2PDF '$@;)
336 # tools/install.sh will print 'file -> $install_dir/file'
337 QUIET_INSTALL = $(Q:@=@printf ' INSTALL ';)
338 QUIET_INSTALL_EACH = $(Q:@=printf ' INSTALL ';)
339 QUIET_TEST = $(Q:@=@echo ' TEST '$@;)
340 QUIET_SUMMARY = $(Q:@=@printf ' SUMMARY ';)
341
342 export V
343 endif