1 ## Makefile for tig
3 all:
5 # Include setting from the configure script
6 -include config.make
8 prefix ?= $(HOME)
9 bindir ?= $(prefix)/bin
10 datarootdir ?= $(prefix)/share
11 sysconfdir ?= $(prefix)/etc
12 docdir ?= $(datarootdir)/doc
13 mandir ?= $(datarootdir)/man
14 # DESTDIR=
16 # Get version either via git or from VERSION file. Allow either
17 # to be overwritten by setting DIST_VERSION on the command line.
18 ifneq (,$(wildcard .git))
19 GITDESC = $(subst tig-,,$(shell git describe))
20 WTDIRTY = $(if $(shell git diff-index HEAD 2>/dev/null),-dirty)
21 VERSION = $(GITDESC)$(WTDIRTY)
22 else
23 VERSION = $(shell test -f VERSION && cat VERSION || echo "unknown-version")
24 endif
25 ifdef DIST_VERSION
26 VERSION = $(DIST_VERSION)
27 endif
29 # Split the version "TAG-OFFSET-gSHA1-DIRTY" into "TAG OFFSET"
30 # and append 0 as a fallback offset for "exact" tagged versions.
31 RPM_VERLIST = $(filter-out g% dirty,$(subst -, ,$(VERSION))) 0
32 RPM_VERSION = $(word 1,$(RPM_VERLIST))
33 RPM_RELEASE = $(word 2,$(RPM_VERLIST))$(if $(WTDIRTY),.dirty)
35 LDLIBS ?= -lcurses
36 CFLAGS ?= -Wall -O2
37 DFLAGS = -g -DDEBUG -Werror -O0
38 PROGS = tig test-graph
39 SOURCE = tig.c tig.h io.c io.h graph.c graph.h
40 TXTDOC = tig.1.txt tigrc.5.txt manual.txt NEWS README INSTALL BUGS TODO
41 MANDOC = tig.1 tigrc.5 tigmanual.7
42 HTMLDOC = tig.1.html tigrc.5.html manual.html README.html NEWS.html
43 ALLDOC = $(MANDOC) $(HTMLDOC) manual.html-chunked manual.pdf
45 # Never include the release number in the tarname for tagged
46 # versions.
47 ifneq ($(if $(DIST_VERSION),$(words $(RPM_VERLIST))),2)
48 TARNAME = tig-$(RPM_VERSION)-$(RPM_RELEASE)
49 else
50 TARNAME = tig-$(RPM_VERSION)
51 endif
53 override CPPFLAGS += '-DTIG_VERSION="$(VERSION)"'
54 override CPPFLAGS += '-DSYSCONFDIR="$(sysconfdir)"'
56 AUTORECONF ?= autoreconf
57 ASCIIDOC ?= asciidoc
58 ASCIIDOC_FLAGS = -aversion=$(VERSION) -asysconfdir=$(sysconfdir)
59 XMLTO ?= xmlto
60 DOCBOOK2PDF ?= docbook2pdf
62 all: $(PROGS)
63 all-debug: $(PROGS)
64 all-debug: CFLAGS += $(DFLAGS)
65 doc: $(ALLDOC)
66 doc-man: $(MANDOC)
67 doc-html: $(HTMLDOC)
69 install: all
70 mkdir -p $(DESTDIR)$(bindir) && \
71 for prog in $(PROGS); do \
72 install -p -m 0755 "$$prog" "$(DESTDIR)$(bindir)"; \
73 done
75 install-doc-man: doc-man
76 mkdir -p $(DESTDIR)$(mandir)/man1 \
77 $(DESTDIR)$(mandir)/man5 \
78 $(DESTDIR)$(mandir)/man7
79 for doc in $(MANDOC); do \
80 sed 's#++SYSCONFDIR++#$(sysconfdir)#' < "$$doc" > "$$doc+"; \
81 case "$$doc" in \
82 *.1) install -p -m 0644 "$$doc+" "$(DESTDIR)$(mandir)/man1/$$doc" ;; \
83 *.5) install -p -m 0644 "$$doc+" "$(DESTDIR)$(mandir)/man5/$$doc" ;; \
84 *.7) install -p -m 0644 "$$doc+" "$(DESTDIR)$(mandir)/man7/$$doc" ;; \
85 esac; \
86 $(RM) "$$doc+"; \
87 done
89 install-release-doc-man:
90 GIT_INDEX_FILE=.tmp-doc-index git read-tree origin/release
91 GIT_INDEX_FILE=.tmp-doc-index git checkout-index -f --prefix=./ $(MANDOC)
92 rm -f .tmp-doc-index
93 $(MAKE) install-doc-man
95 install-doc-html: doc-html
96 mkdir -p $(DESTDIR)$(docdir)/tig
97 for doc in $(HTMLDOC); do \
98 sed 's#++SYSCONFDIR++#$(sysconfdir)#' < "$$doc" > "$$doc+"; \
99 case "$$doc" in \
100 *.html) install -p -m 0644 "$$doc+" "$(DESTDIR)$(docdir)/tig/$$doc" ;; \
101 esac; \
102 $(RM) "$$doc+"; \
103 done
105 install-release-doc-html:
106 GIT_INDEX_FILE=.tmp-doc-index git read-tree origin/release
107 GIT_INDEX_FILE=.tmp-doc-index git checkout-index -f --prefix=./ $(HTMLDOC)
108 rm -f .tmp-doc-index
109 $(MAKE) install-doc-html
111 install-doc: install-doc-man install-doc-html
112 install-release-doc: install-release-doc-man install-release-doc-html
114 clean:
115 $(RM) -r $(TARNAME) *.spec tig-*.tar.gz tig-*.tar.gz.md5
116 $(RM) $(PROGS) core *.o *.xml
118 distclean: clean
119 $(RM) -r manual.html-chunked autom4te.cache
120 $(RM) *.toc $(ALLDOC) aclocal.m4 configure
121 $(RM) config.h config.log config.make config.status config.h.in
123 spell-check:
124 for file in $(TXTDOC) tig.c; do \
125 aspell --lang=en --dont-backup \
126 --personal=./contrib/aspell.dict check $$file; \
127 done
129 strip: $(PROGS)
130 strip $(PROGS)
132 dist: configure tig.spec
133 @mkdir -p $(TARNAME) && \
134 cp tig.spec configure config.h.in aclocal.m4 $(TARNAME) && \
135 echo $(VERSION) > $(TARNAME)/VERSION
136 git archive --format=tar --prefix=$(TARNAME)/ HEAD | \
137 tar --delete $(TARNAME)/VERSION > $(TARNAME).tar && \
138 tar rf $(TARNAME).tar `find $(TARNAME)/*` && \
139 gzip -f -9 $(TARNAME).tar && \
140 md5sum $(TARNAME).tar.gz > $(TARNAME).tar.gz.md5
141 @$(RM) -r $(TARNAME)
143 rpm: dist
144 rpmbuild -ta $(TARNAME).tar.gz
146 configure: configure.ac acinclude.m4
147 $(AUTORECONF) -v -I contrib
149 .PHONY: all all-debug doc doc-man doc-html install install-doc \
150 install-doc-man install-doc-html clean spell-check dist rpm
152 io.o: io.c io.h tig.h
153 graph.o: tig.h
154 tig.o: tig.c tig.h io.h
155 tig: tig.o io.o graph.o
156 test-graph.o: test-graph.c io.h tig.h graph.h
157 test-graph: io.o graph.o
159 tig.spec: contrib/tig.spec.in
160 sed -e 's/@@VERSION@@/$(RPM_VERSION)/g' \
161 -e 's/@@RELEASE@@/$(RPM_RELEASE)/g' < $< > $@
163 manual.html: manual.toc
164 manual.toc: manual.txt
165 sed -n '/^\[\[/,/\(---\|~~~\)/p' < $< | while read line; do \
166 case "$$line" in \
167 "-----"*) echo ". <<$$ref>>"; ref= ;; \
168 "~~~~~"*) echo "- <<$$ref>>"; ref= ;; \
169 "[["*"]]") ref="$$line" ;; \
170 *) ref="$$ref, $$line" ;; \
171 esac; done | sed 's/\[\[\(.*\)\]\]/\1/' > $@
173 README.html: README SITES INSTALL asciidoc.conf
174 $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d article -a readme $<
176 NEWS.html: NEWS asciidoc.conf
177 $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d article $<
179 tigmanual.7: manual.txt
181 %.1.html : %.1.txt asciidoc.conf
182 $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d manpage $<
184 %.1.xml : %.1.txt asciidoc.conf
185 $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b docbook -d manpage $<
187 %.5.html : %.5.txt asciidoc.conf
188 $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d manpage $<
190 %.5.xml : %.5.txt asciidoc.conf
191 $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b docbook -d manpage $<
193 %.7.xml : %.7.txt asciidoc.conf
194 $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b docbook -d manpage $<
196 %.html : %.txt asciidoc.conf
197 $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d article -n $<
199 %.xml : %.txt asciidoc.conf
200 $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b docbook -d article $<
202 % : %.xml
203 $(XMLTO) man $<
205 %.html-chunked : %.xml
206 $(XMLTO) html -o $@ $<
208 %.pdf : %.xml
209 $(DOCBOOK2PDF) $<