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