Make blame_draw check if the filename is NULL instead of empty
[tig.git] / Makefile
blob219b596208ab7fb252138e5ac1cf0b93960078c9
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 = 1.2.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 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))
26 WTDIRTY = $(if $(shell git diff-index HEAD 2>/dev/null),-dirty)
27 VERSION = $(GITDESC)$(WTDIRTY)
28 endif
29 ifdef DIST_VERSION
30 VERSION = $(DIST_VERSION)
31 endif
33 # Split the version "TAG-OFFSET-gSHA1-DIRTY" into "TAG OFFSET"
34 # and append 0 as a fallback offset for "exact" tagged versions.
35 RPM_VERLIST = $(filter-out g% dirty,$(subst -, ,$(VERSION))) 0
36 RPM_VERSION = $(word 1,$(RPM_VERLIST))
37 RPM_RELEASE = $(word 2,$(RPM_VERLIST))$(if $(WTDIRTY),.dirty)
39 LDLIBS ?= -lcurses
40 CFLAGS ?= -Wall -O2
41 DFLAGS = -g -DDEBUG -Werror -O0
42 EXE = tig
43 TOOLS = tools/test-graph
44 TXTDOC = doc/tig.1.asciidoc doc/tigrc.5.asciidoc doc/manual.asciidoc NEWS README INSTALL BUGS
45 MANDOC = doc/tig.1 doc/tigrc.5 doc/tigmanual.7
46 HTMLDOC = doc/tig.1.html doc/tigrc.5.html doc/manual.html README.html INSTALL.html NEWS.html
47 ALLDOC = $(MANDOC) $(HTMLDOC) doc/manual.html-chunked doc/manual.pdf
49 # Never include the release number in the tarname for tagged
50 # versions.
51 ifneq ($(if $(DIST_VERSION),$(words $(RPM_VERLIST))),2)
52 TARNAME = tig-$(RPM_VERSION)-$(RPM_RELEASE)
53 else
54 TARNAME = tig-$(RPM_VERSION)
55 endif
57 override CPPFLAGS += '-DTIG_VERSION="$(VERSION)"'
58 override CPPFLAGS += '-DSYSCONFDIR="$(sysconfdir)"'
60 ASCIIDOC ?= asciidoc
61 ASCIIDOC_FLAGS = -aversion=$(VERSION) -asysconfdir=$(sysconfdir) -f doc/asciidoc.conf
62 XMLTO ?= xmlto
63 DOCBOOK2PDF ?= docbook2pdf
65 all: $(EXE) $(TOOLS)
66 all-debug: $(EXE) $(TOOLS)
67 all-debug: CFLAGS += $(DFLAGS)
68 doc: $(ALLDOC)
69 doc-man: $(MANDOC)
70 doc-html: $(HTMLDOC)
72 install: all
73 @mkdir -p $(DESTDIR)$(bindir)
74 install -p -m 0755 $(EXE) "$(DESTDIR)$(bindir)"
76 install-doc-man: doc-man
77 mkdir -p $(DESTDIR)$(mandir)/man1 \
78 $(DESTDIR)$(mandir)/man5 \
79 $(DESTDIR)$(mandir)/man7
80 for doc in $(MANDOC); do \
81 sed 's#++SYSCONFDIR++#$(sysconfdir)#' < "$$doc" > "$$doc+"; \
82 bdoc=$$(basename $$doc); \
83 case "$$doc" in \
84 *.1) install -p -m 0644 "$$doc+" "$(DESTDIR)$(mandir)/man1/$$bdoc" ;; \
85 *.5) install -p -m 0644 "$$doc+" "$(DESTDIR)$(mandir)/man5/$$bdoc" ;; \
86 *.7) install -p -m 0644 "$$doc+" "$(DESTDIR)$(mandir)/man7/$$bdoc" ;; \
87 esac; \
88 $(RM) "$$doc+"; \
89 done
91 install-release-doc-man:
92 GIT_INDEX_FILE=.tmp-doc-index git read-tree origin/release
93 GIT_INDEX_FILE=.tmp-doc-index git checkout-index -f --prefix=./ $(MANDOC)
94 rm -f .tmp-doc-index
95 $(MAKE) install-doc-man
97 install-doc-html: doc-html
98 mkdir -p $(DESTDIR)$(docdir)/tig
99 for doc in $(HTMLDOC); do \
100 sed 's#++SYSCONFDIR++#$(sysconfdir)#' < "$$doc" > "$$doc+"; \
101 bdoc=$$(basename $$doc); \
102 case "$$doc" in \
103 *.html) install -p -m 0644 "$$doc+" "$(DESTDIR)$(docdir)/tig/$$bdoc" ;; \
104 esac; \
105 $(RM) "$$doc+"; \
106 done
108 install-release-doc-html:
109 GIT_INDEX_FILE=.tmp-doc-index git read-tree origin/release
110 GIT_INDEX_FILE=.tmp-doc-index git checkout-index -f --prefix=./ $(HTMLDOC)
111 rm -f .tmp-doc-index
112 $(MAKE) install-doc-html
114 install-doc: install-doc-man install-doc-html
115 install-release-doc: install-release-doc-man install-release-doc-html
117 clean:
118 $(RM) -r $(TARNAME) *.spec tig-*.tar.gz tig-*.tar.gz.md5 .deps
119 $(RM) $(EXE) $(TOOLS) $(OBJS) core *.xml
121 distclean: clean
122 $(RM) -r doc/manual.html-chunked autom4te.cache release-docs
123 $(RM) doc/*.toc $(ALLDOC) aclocal.m4 configure
124 $(RM) config.h config.log config.make config.status config.h.in
126 spell-check:
127 for file in $(TXTDOC) tig.c; do \
128 aspell --lang=en --dont-backup \
129 --personal=./tools/aspell.dict check $$file; \
130 done
132 strip: $(EXE)
133 strip $(EXE)
135 update-headers:
136 @for file in *.[ch]; do \
137 grep -q '/* Copyright' "$$file" && \
138 sed '0,/.*\*\//d' < "$$file" | \
139 grep -v '/* vim: set' > "$$file.tmp"; \
140 { cat tools/header.h "$$file.tmp"; \
141 echo "/* vim: set ts=8 sw=8 noexpandtab: */"; } > "$$file"; \
142 rm "$$file.tmp"; \
143 echo "Updated $$file"; \
144 done
146 dist: configure tig.spec
147 @mkdir -p $(TARNAME) && \
148 cp Makefile tig.spec configure config.h.in aclocal.m4 $(TARNAME) && \
149 sed -i "s/VERSION\s\+=\s\+[0-9]\+\([.][0-9]\+\)\+/VERSION = $(VERSION)/" $(TARNAME)/Makefile
150 git archive --format=tar --prefix=$(TARNAME)/ HEAD | \
151 tar --delete $(TARNAME)/Makefile > $(TARNAME).tar && \
152 tar rf $(TARNAME).tar `find $(TARNAME)/*` && \
153 gzip -f -9 $(TARNAME).tar && \
154 md5sum $(TARNAME).tar.gz > $(TARNAME).tar.gz.md5
155 @$(RM) -r $(TARNAME)
157 rpm: dist
158 rpmbuild -ta $(TARNAME).tar.gz
160 # Other autoconf-related rules are hidden in config.make.in so that
161 # they don't confuse Make when we aren't actually using ./configure
162 configure: configure.ac acinclude.m4 tools/*.m4
163 ./autogen.sh
165 .PHONY: all all-debug doc doc-man doc-html install install-doc \
166 install-doc-man install-doc-html clean spell-check dist rpm
168 ifdef NO_MKSTEMPS
169 COMPAT_CPPFLAGS += -DNO_MKSTEMPS
170 COMPAT_OBJS += compat/mkstemps.o
171 endif
173 ifdef NO_SETENV
174 COMPAT_CPPFLAGS += -DNO_SETENV
175 COMPAT_OBJS += compat/setenv.o
176 endif
178 override CPPFLAGS += $(COMPAT_CPPFLAGS)
180 TIG_OBJS = tig.o util.o io.o graph.o refs.o $(COMPAT_OBJS)
181 tig: $(TIG_OBJS)
183 TEST_GRAPH_OBJS = tools/test-graph.o util.o io.o graph.o
184 tools/test-graph: $(TEST_GRAPH_OBJS)
186 OBJS = $(sort $(TIG_OBJS) $(TEST_GRAPH_OBJS))
188 DEPS_CFLAGS ?= -MMD -MP -MF .deps/$*.d
190 %: %.o
191 $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@
193 %.o: %.c
194 @mkdir -p .deps/$(*D)
195 $(CC) $(CFLAGS) $(DEPS_CFLAGS) $(CPPFLAGS) -c -o $@ $<
197 -include $(OBJS:%.o=.deps/%.d)
199 tig.spec: contrib/tig.spec.in
200 sed -e 's/@@VERSION@@/$(RPM_VERSION)/g' \
201 -e 's/@@RELEASE@@/$(RPM_RELEASE)/g' < $< > $@
203 doc/manual.html: doc/manual.toc
204 doc/manual.html: ASCIIDOC_FLAGS += -ainclude-manual-toc
205 %.toc: %.asciidoc
206 sed -n '/^\[\[/,/\(---\|~~~\)/p' < $< | while read line; do \
207 case "$$line" in \
208 "----"*) echo ". <<$$ref>>"; ref= ;; \
209 "~~~~"*) echo "- <<$$ref>>"; ref= ;; \
210 "[["*"]]") ref="$$line" ;; \
211 *) ref="$$ref, $$line" ;; \
212 esac; done | sed 's/\[\[\(.*\)\]\]/\1/' > $@
214 README.html: README doc/asciidoc.conf
215 $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d article -a readme $<
217 INSTALL.html: INSTALL doc/asciidoc.conf
218 $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d article $<
220 NEWS.html: NEWS doc/asciidoc.conf
221 $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d article $<
223 doc/tigmanual.7: doc/manual.asciidoc
225 %.1.html : %.1.asciidoc doc/asciidoc.conf
226 $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d manpage $<
228 %.1.xml : %.1.asciidoc doc/asciidoc.conf
229 $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b docbook -d manpage $<
231 %.5.html : %.5.asciidoc doc/asciidoc.conf
232 $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d manpage $<
234 %.5.xml : %.5.asciidoc doc/asciidoc.conf
235 $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b docbook -d manpage $<
237 %.7.xml : %.7.asciidoc doc/asciidoc.conf
238 $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b docbook -d manpage $<
240 %.html : %.asciidoc doc/asciidoc.conf
241 $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d article -n $<
243 %.xml : %.asciidoc doc/asciidoc.conf
244 $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b docbook -d article $<
246 % : %.xml
247 $(XMLTO) man -o doc $<
249 %.html-chunked : %.xml
250 $(XMLTO) html -o $@ $<
252 %.pdf : %.xml
253 $(DOCBOOK2PDF) -o doc $<