'tig branch' opens tig in branch view
[tig] / Makefile
1 ## Makefile for tig
2
3 all:
4
5 # Include setting from the configure script
6 -include config.make
7
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=
15
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
28
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)
34
35 LDLIBS ?= -lcurses
36 CFLAGS ?= -Wall -O2
37 DFLAGS  = -g -DDEBUG -Werror -O0
38 PROGS   = tig
39 TXTDOC  = tig.1.txt tigrc.5.txt manual.txt NEWS README INSTALL BUGS TODO
40 MANDOC  = tig.1 tigrc.5
41 HTMLDOC = tig.1.html tigrc.5.html manual.html README.html NEWS.html
42 ALLDOC  = $(MANDOC) $(HTMLDOC) manual.html-chunked manual.pdf
43
44 # Never include the release number in the tarname for tagged
45 # versions.
46 ifneq ($(if $(DIST_VERSION),$(words $(RPM_VERLIST))),2)
47 TARNAME = tig-$(RPM_VERSION)-$(RPM_RELEASE)
48 else
49 TARNAME = tig-$(RPM_VERSION)
50 endif
51
52 override CPPFLAGS += '-DTIG_VERSION="$(VERSION)"'
53 override CPPFLAGS += '-DSYSCONFDIR="$(sysconfdir)"'
54
55 AUTORECONF ?= autoreconf
56 ASCIIDOC ?= asciidoc
57 ASCIIDOC_FLAGS = -aversion=$(VERSION) -asysconfdir=$(sysconfdir)
58 XMLTO ?= xmlto
59 DOCBOOK2PDF ?= docbook2pdf
60
61 all: $(PROGS)
62 all-debug: $(PROGS)
63 all-debug: CFLAGS += $(DFLAGS)
64 doc: $(ALLDOC)
65 doc-man: $(MANDOC)
66 doc-html: $(HTMLDOC)
67
68 install: all
69         mkdir -p $(DESTDIR)$(bindir) && \
70         for prog in $(PROGS); do \
71                 install -p -m 0755 "$$prog" "$(DESTDIR)$(bindir)"; \
72         done
73
74 install-doc-man: doc-man
75         mkdir -p $(DESTDIR)$(mandir)/man1 \
76                  $(DESTDIR)$(mandir)/man5
77         for doc in $(MANDOC); do \
78                 sed 's#++SYSCONFDIR++#$(sysconfdir)#' < "$$doc" > "$$doc+"; \
79                 case "$$doc" in \
80                 *.1) install -p -m 0644 "$$doc+" "$(DESTDIR)$(mandir)/man1/$$doc" ;; \
81                 *.5) install -p -m 0644 "$$doc+" "$(DESTDIR)$(mandir)/man5/$$doc" ;; \
82                 esac; \
83                 $(RM) "$$doc+"; \
84         done
85
86 install-doc-html: doc-html
87         mkdir -p $(DESTDIR)$(docdir)/tig
88         for doc in $(HTMLDOC); do \
89                 sed 's#++SYSCONFDIR++#$(sysconfdir)#' < "$$doc" > "$$doc+"; \
90                 case "$$doc" in \
91                 *.html) install -p -m 0644 "$$doc+" "$(DESTDIR)$(docdir)/tig/$$doc" ;; \
92                 esac; \
93                 $(RM) "$$doc+"; \
94         done
95
96 install-doc: install-doc-man install-doc-html
97
98 clean:
99         $(RM) -r $(TARNAME) *.spec tig-*.tar.gz tig-*.tar.gz.md5
100         $(RM) $(PROGS) core *.o *.xml
101
102 distclean: clean
103         $(RM) -r manual.html-chunked autom4te.cache
104         $(RM) *.toc $(ALLDOC) aclocal.m4 configure
105         $(RM) config.h config.log config.make config.status config.h.in
106
107 spell-check:
108         for file in $(TXTDOC) tig.c; do \
109                 aspell --lang=en --dont-backup \
110                        --personal=./contrib/aspell.dict check $$file; \
111         done
112
113 strip: $(PROGS)
114         strip $(PROGS)
115
116 dist: configure tig.spec
117         @mkdir -p $(TARNAME) && \
118         cp tig.spec configure config.h.in aclocal.m4 $(TARNAME) && \
119         echo $(VERSION) > $(TARNAME)/VERSION
120         git archive --format=tar --prefix=$(TARNAME)/ HEAD | \
121         tar --delete $(TARNAME)/VERSION > $(TARNAME).tar && \
122         tar rf $(TARNAME).tar `find $(TARNAME)/*` && \
123         gzip -f -9 $(TARNAME).tar && \
124         md5sum $(TARNAME).tar.gz > $(TARNAME).tar.gz.md5
125         @$(RM) -r $(TARNAME)
126
127 rpm: dist
128         rpmbuild -ta $(TARNAME).tar.gz
129
130 configure: configure.ac acinclude.m4
131         $(AUTORECONF) -v
132
133 .PHONY: all all-debug doc doc-man doc-html install install-doc \
134         install-doc-man install-doc-html clean spell-check dist rpm
135
136 tig.o: tig.c
137 tig: tig.o
138
139 tig.spec: contrib/tig.spec.in
140         sed -e 's/@@VERSION@@/$(RPM_VERSION)/g' \
141             -e 's/@@RELEASE@@/$(RPM_RELEASE)/g' < $< > $@
142
143 manual.html: manual.toc
144 manual.toc: manual.txt
145         sed -n '/^\[\[/,/\(---\|~~~\)/p' < $< | while read line; do \
146                 case "$$line" in \
147                 "-----"*)  echo ". <<$$ref>>"; ref= ;; \
148                 "~~~~~"*)  echo "- <<$$ref>>"; ref= ;; \
149                 "[["*"]]") ref="$$line" ;; \
150                 *)         ref="$$ref, $$line" ;; \
151                 esac; done | sed 's/\[\[\(.*\)\]\]/\1/' > $@
152
153 README.html: README asciidoc.conf
154         $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d article -a readme $<
155
156 NEWS.html: NEWS asciidoc.conf
157         $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d article $<
158
159 %.1.html : %.1.txt asciidoc.conf
160         $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d manpage $<
161
162 %.1.xml : %.1.txt asciidoc.conf
163         $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b docbook -d manpage $<
164
165 %.5.html : %.5.txt asciidoc.conf
166         $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d manpage $<
167
168 %.5.xml : %.5.txt asciidoc.conf
169         $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b docbook -d manpage $<
170
171 %.html : %.txt asciidoc.conf
172         $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d article -n $<
173
174 %.xml : %.txt asciidoc.conf
175         $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b docbook -d article $<
176
177 % : %.xml
178         $(XMLTO) man $<
179
180 %.html-chunked : %.xml
181         $(XMLTO) html -o $@ $<
182
183 %.pdf : %.xml
184         $(DOCBOOK2PDF) $<