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