c3763deaf7954063a408b62969864cbe436d6085
[tig.git] / Makefile
blobc3763deaf7954063a408b62969864cbe436d6085
1 ## Makefile for tig
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.1.1
7 all:
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)
13 # Include setting from the configure script
14 -include config.make
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)
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=
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
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)
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
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
64 override CPPFLAGS += '-DTIG_VERSION="$(VERSION)"'
65 override CPPFLAGS += '-DSYSCONFDIR="$(sysconfdir)"'
66 ifdef TIG_USER_CONFIG
67 override CPPFLAGS += '-DTIG_USER_CONFIG="$(TIG_USER_CONFIG)"'
68 endif
70 ASCIIDOC ?= asciidoc
71 ASCIIDOC_FLAGS = -aversion=$(VERSION) -asysconfdir=$(sysconfdir) -f doc/asciidoc.conf
72 XMLTO ?= xmlto
73 DOCBOOK2PDF ?= docbook2pdf
75 LCOV ?= lcov
76 GENHTML ?= genhtml
78 all: $(EXE) $(TOOLS)
79 all-debug: all
80 all-debug: CFLAGS += $(DFLAGS)
81 doc: $(ALLDOC)
82 doc-man: $(MANDOC)
83 doc-html: $(HTMLDOC)
85 export sysconfdir
87 install: all
88 $(QUIET_INSTALL)tools/install.sh bin $(EXE) "$(DESTDIR)$(bindir)"
89 $(QUIET_INSTALL)tools/install.sh data tigrc "$(DESTDIR)$(sysconfdir)"
91 install-doc-man: doc-man
92 $(Q)$(foreach doc, $(filter %.1, $(MANDOC)), \
93 $(QUIET_INSTALL_EACH)tools/install.sh data $(doc) "$(DESTDIR)$(mandir)/man1";)
94 $(Q)$(foreach doc, $(filter %.5, $(MANDOC)), \
95 $(QUIET_INSTALL_EACH)tools/install.sh data $(doc) "$(DESTDIR)$(mandir)/man5";)
96 $(Q)$(foreach doc, $(filter %.7, $(MANDOC)), \
97 $(QUIET_INSTALL_EACH)tools/install.sh data $(doc) "$(DESTDIR)$(mandir)/man7";)
99 install-release-doc-man:
100 GIT_INDEX_FILE=.tmp-doc-index git read-tree origin/release
101 GIT_INDEX_FILE=.tmp-doc-index git checkout-index -f --prefix=./ $(MANDOC)
102 rm -f .tmp-doc-index
103 $(MAKE) install-doc-man
105 install-doc-html: doc-html
106 $(Q)$(foreach doc, $(HTMLDOC), \
107 $(QUIET_INSTALL_EACH)tools/install.sh data $(doc) "$(DESTDIR)$(docdir)/tig";)
109 install-release-doc-html:
110 GIT_INDEX_FILE=.tmp-doc-index git read-tree origin/release
111 GIT_INDEX_FILE=.tmp-doc-index git checkout-index -f --prefix=./ $(HTMLDOC)
112 rm -f .tmp-doc-index
113 $(MAKE) install-doc-html
115 install-doc: install-doc-man install-doc-html
116 install-release-doc: install-release-doc-man install-release-doc-html
118 uninstall:
119 $(QUIET_UNINSTALL)tools/uninstall.sh "$(DESTDIR)$(bindir)/$(EXE:src/%=%)"
120 $(QUIET_UNINSTALL)tools/uninstall.sh "$(DESTDIR)$(sysconfdir)/tigrc"
121 $(Q)$(foreach doc, $(filter %.1, $(MANDOC:doc/%=%)), \
122 $(QUIET_UNINSTALL_EACH)tools/uninstall.sh "$(DESTDIR)$(mandir)/man1/$(doc)";)
123 $(Q)$(foreach doc, $(filter %.5, $(MANDOC:doc/%=%)), \
124 $(QUIET_UNINSTALL_EACH)tools/uninstall.sh "$(DESTDIR)$(mandir)/man5/$(doc)";)
125 $(Q)$(foreach doc, $(filter %.7, $(MANDOC:doc/%=%)), \
126 $(QUIET_UNINSTALL_EACH)tools/uninstall.sh "$(DESTDIR)$(mandir)/man7/$(doc)";)
127 $(Q)$(foreach doc, $(HTMLDOC:doc/%=%), \
128 $(QUIET_UNINSTALL_EACH)tools/uninstall.sh "$(DESTDIR)$(docdir)/tig/$(doc)";)
130 clean: clean-test clean-coverage
131 $(Q)$(RM) -r $(TARNAME) *.spec tig-*.tar.gz tig-*.tar.gz.md5 .deps
132 $(Q)$(RM) $(EXE) $(TOOLS) $(OBJS) core doc/*.xml src/builtin-config.c
133 $(Q)$(RM) $(OBJS:%.o=%.gcda) $(OBJS:%.o=%.gcno)
135 distclean: clean
136 $(RM) -r doc/manual.html-chunked autom4te.cache release-docs
137 $(RM) doc/*.toc $(ALLDOC) aclocal.m4 configure
138 $(RM) config.h config.log config.make config.status config.h.in
140 spell-check:
141 for file in $(TXTDOC) src/tig.c; do \
142 aspell --lang=en --dont-backup \
143 --personal=./tools/aspell.dict check $$file; \
144 done
146 strip: $(EXE)
147 strip $(EXE)
149 update-headers:
150 @for file in include/tig/*.h src/*.c tools/*.c test/tools/*.c; do \
151 grep -q '/* Copyright' "$$file" && \
152 sed '0,/.*\*\//d' < "$$file" | \
153 grep -v '/* vim: set' > "$$file.tmp"; \
154 { cat tools/header.h "$$file.tmp"; \
155 echo "/* vim: set ts=8 sw=8 noexpandtab: */"; } > "$$file"; \
156 rm "$$file.tmp"; \
157 echo "Updated $$file"; \
158 done
160 update-docs: tools/doc-gen
161 doc="doc/tigrc.5.adoc"; \
162 sed -n '0,/ifndef::DOC_GEN_ACTIONS/p' < "$$doc" > "$$doc.gen"; \
163 ./tools/doc-gen actions >> "$$doc.gen"; \
164 sed -n '/endif::DOC_GEN_ACTIONS/,$$p' < "$$doc" >> "$$doc.gen" ; \
165 mv "$$doc.gen" "$$doc"
167 dist: configure tig.spec
168 $(Q)mkdir -p $(TARNAME) && \
169 cp Makefile tig.spec configure config.h.in aclocal.m4 $(TARNAME) && \
170 sed -i "s/VERSION\s\+=\s\+[0-9]\+\([.][0-9]\+\)\+/VERSION = $(VERSION)/" $(TARNAME)/Makefile
171 git archive --format=tar --prefix=$(TARNAME)/ HEAD | \
172 tar --delete $(TARNAME)/Makefile > $(TARNAME).tar && \
173 tar rf $(TARNAME).tar `find $(TARNAME)/*` && \
174 gzip -f -9 $(TARNAME).tar && \
175 md5sum $(TARNAME).tar.gz > $(TARNAME).tar.gz.md5
176 $(Q)$(RM) -r $(TARNAME)
178 rpm: dist
179 rpmbuild -ta $(TARNAME).tar.gz
181 COVERAGE_CFLAGS ?= -fprofile-arcs -ftest-coverage
182 all-coverage: all
183 all-coverage: CFLAGS += $(COVERAGE_CFLAGS)
185 COVERAGE_DIR ?= test/coverage
187 clean-coverage:
188 @$(RM) -rf $(COVERAGE_DIR)
190 reset-coverage: clean-coverage
191 $(LCOV) --reset-counters
193 test-coverage: clean-coverage all-coverage test $(COVERAGE_DIR)/index.html
195 $(COVERAGE_DIR)/trace:
196 @mkdir -p $(COVERAGE_DIR)
197 $(QUIET_LCOV)$(LCOV) $(Q:@=--quiet) --capture --no-external --directory . --output-file $@
199 $(COVERAGE_DIR)/index.html: $(COVERAGE_DIR)/trace
200 $(QUIET_GENHTML)$(GENHTML) $(Q:@=--quiet) --output-directory $(COVERAGE_DIR) $<
202 ADDRESS_SANITIZER_CFLAGS ?= -fsanitize=address -fno-omit-frame-pointer
203 all-address-sanitizer: all
204 all-address-sanitizer: CFLAGS += $(ADDRESS_SANITIZER_CFLAGS)
206 test-address-sanitizer: clean all-address-sanitizer test
207 test-address-sanitizer: export TIG_ADDRESS_SANITIZER_ENABLED=yes
209 TESTS = $(sort $(shell find test -type f -name '*-test'))
211 clean-test:
212 $(Q)$(RM) -r test/tmp
214 test: clean-test $(TESTS)
215 $(QUIET_SUMMARY)test/tools/show-results.sh
217 export TIG_TEST_OPTS = $(V:1=no-indent)
219 $(TESTS): PATH := $(CURDIR)/test/tools:$(CURDIR)/src:$(PATH)
220 $(TESTS): $(EXE) test/tools/test-graph
221 $(QUIET_TEST)$(TEST_SHELL) $@
223 # Other autoconf-related rules are hidden in config.make.in so that
224 # they don't confuse Make when we aren't actually using ./configure
225 configure: configure.ac acinclude.m4 tools/*.m4
226 $(QUIET_GEN)./autogen.sh
228 .PHONY: all all-coverage all-debug clean clean-coverage clean-test doc \
229 doc-man doc-html dist distclean install install-doc \
230 install-doc-man install-doc-html install-release-doc-html \
231 install-release-doc-man rpm spell-check strip test \
232 test-coverage update-docs update-headers $(TESTS)
234 ifdef NO_MKSTEMPS
235 COMPAT_CPPFLAGS += -DNO_MKSTEMPS
236 COMPAT_OBJS += compat/mkstemps.o
237 endif
239 ifdef NO_SETENV
240 COMPAT_CPPFLAGS += -DNO_SETENV
241 COMPAT_OBJS += compat/setenv.o
242 endif
244 ifdef NO_STRNDUP
245 COMPAT_CPPFLAGS += -DNO_STRNDUP
246 COMPAT_OBJS += compat/strndup.o
247 endif
249 COMPAT_OBJS += compat/hashtab.o
251 override CPPFLAGS += $(COMPAT_CPPFLAGS)
253 GRAPH_OBJS = src/graph.o src/graph-v1.o src/graph-v2.o
255 TIG_OBJS = \
256 src/tig.o \
257 src/types.o \
258 src/string.o \
259 src/util.o \
260 src/map.o \
261 src/argv.o \
262 src/io.o \
263 src/refdb.o \
264 src/builtin-config.o \
265 src/request.o \
266 src/line.o \
267 src/keys.o \
268 src/repo.o \
269 src/options.o \
270 src/draw.o \
271 src/prompt.o \
272 src/display.o \
273 src/view.o \
274 src/search.o \
275 src/parse.o \
276 src/watch.o \
277 src/pager.o \
278 src/log.o \
279 src/diff.o \
280 src/help.o \
281 src/tree.o \
282 src/blob.o \
283 src/blame.o \
284 src/refs.o \
285 src/status.o \
286 src/stage.o \
287 src/main.o \
288 src/stash.o \
289 src/grep.o \
290 src/ui.o \
291 $(GRAPH_OBJS) \
292 $(COMPAT_OBJS)
294 src/tig: $(TIG_OBJS)
296 TEST_GRAPH_OBJS = test/tools/test-graph.o src/string.o src/util.o src/io.o $(GRAPH_OBJS) $(COMPAT_OBJS)
297 test/tools/test-graph: $(TEST_GRAPH_OBJS)
299 DOC_GEN_OBJS = tools/doc-gen.o src/string.o src/types.o src/util.o src/request.o
300 tools/doc-gen: $(DOC_GEN_OBJS)
302 OBJS = $(sort $(TIG_OBJS) $(TEST_GRAPH_OBJS) $(DOC_GEN_OBJS))
304 DEPS_CFLAGS ?= -MMD -MP -MF .deps/$*.d
306 %: %.o
307 $(QUIET_LINK)$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@
309 %.o: %.c $(CONFIG_H)
310 @mkdir -p .deps/$(*D)
311 $(QUIET_CC)$(CC) -I. -Iinclude $(CFLAGS) $(DEPS_CFLAGS) $(CPPFLAGS) -c -o $@ $<
313 -include $(OBJS:%.o=.deps/%.d)
315 src/builtin-config.c: tigrc tools/make-builtin-config.sh
316 $(QUIET_GEN)tools/make-builtin-config.sh $< > $@
318 tig.spec: contrib/tig.spec.in
319 $(QUIET_GEN)sed -e 's/@@VERSION@@/$(RPM_VERSION)/g' \
320 -e 's/@@RELEASE@@/$(RPM_RELEASE)/g' < $< > $@
322 doc/manual.html: doc/manual.toc
323 doc/manual.html: ASCIIDOC_FLAGS += -ainclude-manual-toc
324 %.toc: %.adoc
325 $(QUIET_GEN)sed -n '/^\[\[/,/\(---\|~~~\)/p' < $< | while read line; do \
326 case "$$line" in \
327 "----"*) echo ". <<$$ref>>"; ref= ;; \
328 "~~~~"*) echo "- <<$$ref>>"; ref= ;; \
329 "[["*"]]") ref="$$line" ;; \
330 *) ref="$$ref, $$line" ;; \
331 esac; done | sed 's/\[\[\(.*\)\]\]/\1/' > $@
333 README.html: README.adoc doc/asciidoc.conf
334 $(QUIET_ASCIIDOC)$(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d article -a readme $<
336 INSTALL.html: INSTALL.adoc doc/asciidoc.conf
337 $(QUIET_ASCIIDOC)$(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d article $<
339 NEWS.html: NEWS.adoc doc/asciidoc.conf
340 $(QUIET_ASCIIDOC)$(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d article $<
342 doc/tigmanual.7: doc/manual.adoc
344 %.1.html : %.1.adoc doc/asciidoc.conf
345 $(QUIET_ASCIIDOC)$(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d manpage $<
347 %.1.xml : %.1.adoc doc/asciidoc.conf
348 $(QUIET_ASCIIDOC)$(ASCIIDOC) $(ASCIIDOC_FLAGS) -b docbook -d manpage $<
350 %.5.html : %.5.adoc doc/asciidoc.conf
351 $(QUIET_ASCIIDOC)$(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d manpage $<
353 %.5.xml : %.5.adoc doc/asciidoc.conf
354 $(QUIET_ASCIIDOC)$(ASCIIDOC) $(ASCIIDOC_FLAGS) -b docbook -d manpage $<
356 %.7.xml : %.7.adoc doc/asciidoc.conf
357 $(QUIET_ASCIIDOC)$(ASCIIDOC) $(ASCIIDOC_FLAGS) -b docbook -d manpage $<
359 %.html: ASCIIDOC_FLAGS += -adocext=html
360 %.html : %.adoc doc/asciidoc.conf
361 $(QUIET_ASCIIDOC)$(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d article -n $<
363 %.xml : %.adoc doc/asciidoc.conf
364 $(QUIET_ASCIIDOC)$(ASCIIDOC) $(ASCIIDOC_FLAGS) -b docbook -d article $<
366 % : %.xml
367 $(QUIET_XMLTO)$(XMLTO) man -o doc $<
369 %.html-chunked : %.xml
370 $(QUIET_XMLTO)$(XMLTO) html -o $@ $<
372 %.pdf : %.xml
373 $(QUIET_DB2PDF)$(DOCBOOK2PDF) -o doc $<
375 #############################################################################
376 # Quiet make
377 #############################################################################
379 ifneq ($(findstring $(MAKEFLAGS),s),s)
380 V = @
381 Q = $(V:1=)
382 QUIET_CC = $(Q:@=@echo ' CC '$@;)
383 QUIET_LINK = $(Q:@=@echo ' LINK '$@;)
384 QUIET_GEN = $(Q:@=@echo ' GEN '$@;)
385 QUIET_ASCIIDOC = $(Q:@=@echo ' ASCIIDOC '$@;)
386 QUIET_XMLTO = $(Q:@=@echo ' XMLTO '$@;)
387 QUIET_DB2PDF = $(Q:@=@echo ' DB2PDF '$@;)
388 # tools/install.sh will print 'file -> $install_dir/file'
389 QUIET_INSTALL = $(Q:@=@printf ' INSTALL ';)
390 QUIET_INSTALL_EACH = $(Q:@=printf ' INSTALL ';)
391 QUIET_UNINSTALL = $(Q:@=@printf ' UNINSTALL ';)
392 QUIET_UNINSTALL_EACH = $(Q:@=printf ' UNINSTALL ';)
393 QUIET_TEST = $(Q:@=@echo ' TEST '$@;)
394 QUIET_SUMMARY = $(Q:@=@printf ' SUMMARY ';)
395 QUIET_LCOV = $(Q:@=@echo ' LCOV '$@;)
396 QUIET_GENHTML = $(Q:@=@echo ' GENHTML '$@;)
398 export V
399 endif