Simplify documentation building and fix asciidoc.conf dependency
[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 docdir ?= $(datarootdir)/doc
12 mandir ?= $(datarootdir)/man
13 # DESTDIR=
14
15 # Get version either via git or from VERSION file. Allow either
16 # to be overwritten by setting DIST_VERSION on the command line.
17 ifneq (,$(wildcard .git))
18 GITDESC = $(subst tig-,,$(shell git describe))
19 WTDIRTY = $(if $(shell git diff-index HEAD 2>/dev/null),-dirty)
20 VERSION = $(GITDESC)$(WTDIRTY)
21 else
22 VERSION = $(shell test -f VERSION && cat VERSION || echo "unknown-version")
23 endif
24 ifdef DIST_VERSION
25 VERSION = $(DIST_VERSION)
26 endif
27
28 # Split the version "TAG-OFFSET-gSHA1-DIRTY" into "TAG OFFSET"
29 # and append 0 as a fallback offset for "exact" tagged versions.
30 RPM_VERLIST = $(filter-out g% dirty,$(subst -, ,$(VERSION))) 0
31 RPM_VERSION = $(word 1,$(RPM_VERLIST))
32 RPM_RELEASE = $(word 2,$(RPM_VERLIST))$(if $(WTDIRTY),.dirty)
33
34 LDLIBS ?= -lcurses
35 CFLAGS ?= -Wall -O2
36 DFLAGS  = -g -DDEBUG -Werror
37 PROGS   = tig
38 MANDOC  = tig.1 tigrc.5
39 HTMLDOC = tig.1.html tigrc.5.html manual.html README.html
40 ALLDOC  = $(MANDOC) $(HTMLDOC) manual.html-chunked manual.pdf
41
42 # Never include the release number in the tarname for tagged
43 # versions.
44 ifneq ($(if $(DIST_VERSION),$(words $(RPM_VERLIST))),2)
45 TARNAME = tig-$(RPM_VERSION)-$(RPM_RELEASE)
46 else
47 TARNAME = tig-$(RPM_VERSION)
48 endif
49
50 override CFLAGS += '-DTIG_VERSION="$(VERSION)"'
51
52 AUTORECONF ?= autoreconf
53 ASCIIDOC ?= asciidoc
54 ASCIIDOC_FLAGS = -aversion=$(VERSION)
55 XMLTO ?= xmlto
56 DOCBOOK2PDF ?= docbook2pdf
57
58 all: $(PROGS)
59 all-debug: $(PROGS)
60 all-debug: CFLAGS += $(DFLAGS)
61 doc: $(ALLDOC)
62 doc-man: $(MANDOC)
63 doc-html: $(HTMLDOC)
64
65 install: all
66         mkdir -p $(DESTDIR)$(bindir) && \
67         for prog in $(PROGS); do \
68                 install -p -m 0755 $$prog $(DESTDIR)$(bindir); \
69         done
70
71 install-doc-man: doc-man
72         mkdir -p $(DESTDIR)$(mandir)/man1 \
73                  $(DESTDIR)$(mandir)/man5
74         for doc in $(MANDOC); do \
75                 case "$$doc" in \
76                 *.1) install -p -m 0644 $$doc $(DESTDIR)$(mandir)/man1 ;; \
77                 *.5) install -p -m 0644 $$doc $(DESTDIR)$(mandir)/man5 ;; \
78                 esac \
79         done
80
81 install-doc-html: doc-html
82         mkdir -p $(DESTDIR)$(docdir)/tig
83         for doc in $(HTMLDOC); do \
84                 case "$$doc" in \
85                 *.html) install -p -m 0644 $$doc $(DESTDIR)$(docdir)/tig ;; \
86                 esac \
87         done
88
89 install-doc: install-doc-man install-doc-html
90
91 clean:
92         $(RM) -r $(TARNAME) *.spec tig-*.tar.gz tig-*.tar.gz.md5
93         $(RM) $(PROGS) core *.o *.xml
94
95 distclean: clean
96         $(RM) -r manual.html-chunked *.toc $(ALLDOC)
97         $(RM) -r autom4te.cache aclocal.m4 config.{h,log,make,status} config.h.in configure
98
99 spell-check:
100         aspell --lang=en --check tig.1.txt tigrc.5.txt manual.txt
101
102 strip: $(PROGS)
103         strip $(PROGS)
104
105 dist: configure tig.spec
106         @mkdir -p $(TARNAME) && \
107         cp tig.spec configure config.h.in aclocal.m4 $(TARNAME) && \
108         echo $(VERSION) > $(TARNAME)/VERSION
109         git archive --format=tar --prefix=$(TARNAME)/ HEAD | \
110         tar --delete $(TARNAME)/VERSION > $(TARNAME).tar && \
111         tar rf $(TARNAME).tar `find $(TARNAME)/*` && \
112         gzip -f -9 $(TARNAME).tar && \
113         md5sum $(TARNAME).tar.gz > $(TARNAME).tar.gz.md5
114         @rm -rf $(TARNAME)
115
116 rpm: dist
117         rpmbuild -ta $(TARNAME).tar.gz
118
119 configure: configure.ac acinclude.m4
120         $(AUTORECONF) -v
121
122 # Maintainer stuff
123 release-doc:
124         git checkout release && \
125         git merge master && \
126         $(MAKE) distclean doc-man doc-html && \
127         git add -f $(MANDOC) $(HTMLDOC) && \
128         git commit -m "Sync docs" && \
129         git checkout master
130
131 release-dist: release-doc
132         git checkout release && \
133         $(MAKE) dist && \
134         git checkout master
135
136 .PHONY: all all-debug doc doc-man doc-html install install-doc \
137         install-doc-man install-doc-html clean spell-check dist rpm
138
139 tig.o: tig.c
140 tig: tig.o
141
142 tig.spec: contrib/tig.spec.in
143         sed -e 's/@@VERSION@@/$(RPM_VERSION)/g' \
144             -e 's/@@RELEASE@@/$(RPM_RELEASE)/g' < $< > $@
145
146 manual.html: manual.toc
147 manual.toc: manual.txt
148         sed -n '/^\[\[/,/\(---\|~~~\)/p' < $< | while read line; do \
149                 case "$$line" in \
150                 "-----"*)  echo ". <<$$ref>>"; ref= ;; \
151                 "~~~~~"*)  echo "- <<$$ref>>"; ref= ;; \
152                 "[["*"]]") ref="$$line" ;; \
153                 *)         ref="$$ref, $$line" ;; \
154                 esac; done | sed 's/\[\[\(.*\)\]\]/\1/' > $@
155
156 README.html: README asciidoc.conf
157         $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d article -a readme $<
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) $<