Replace the manpage XSL workarounds with AsciiDoc conf workarounds
[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 XMLTO ?= xmlto
55 DOCBOOK2PDF ?= docbook2pdf
56
57 all: $(PROGS)
58 all-debug: $(PROGS)
59 all-debug: CFLAGS += $(DFLAGS)
60 doc: $(ALLDOC)
61 doc-man: $(MANDOC)
62 doc-html: $(HTMLDOC)
63
64 install: all
65         mkdir -p $(DESTDIR)$(bindir) && \
66         for prog in $(PROGS); do \
67                 install -p -m 0755 $$prog $(DESTDIR)$(bindir); \
68         done
69
70 install-doc-man: doc-man
71         mkdir -p $(DESTDIR)$(mandir)/man1 \
72                  $(DESTDIR)$(mandir)/man5
73         for doc in $(MANDOC); do \
74                 case "$$doc" in \
75                 *.1) install -p -m 0644 $$doc $(DESTDIR)$(mandir)/man1 ;; \
76                 *.5) install -p -m 0644 $$doc $(DESTDIR)$(mandir)/man5 ;; \
77                 esac \
78         done
79
80 install-doc-html: doc-html
81         mkdir -p $(DESTDIR)$(docdir)/tig
82         for doc in $(HTMLDOC); do \
83                 case "$$doc" in \
84                 *.html) install -p -m 0644 $$doc $(DESTDIR)$(docdir)/tig ;; \
85                 esac \
86         done
87
88 install-doc: install-doc-man install-doc-html
89
90 clean:
91         $(RM) -r $(TARNAME) *.spec tig-*.tar.gz tig-*.tar.gz.md5
92         $(RM) $(PROGS) core *.o *.xml
93
94 distclean: clean
95         $(RM) -r manual.html-chunked *.toc $(ALLDOC)
96         $(RM) -r autom4te.cache aclocal.m4 config.{h,log,make,status} config.h.in configure
97
98 spell-check:
99         aspell --lang=en --check tig.1.txt tigrc.5.txt manual.txt
100
101 strip: $(PROGS)
102         strip $(PROGS)
103
104 dist: configure tig.spec
105         @mkdir -p $(TARNAME) && \
106         cp tig.spec configure config.h.in aclocal.m4 $(TARNAME) && \
107         echo $(VERSION) > $(TARNAME)/VERSION
108         git archive --format=tar --prefix=$(TARNAME)/ HEAD | \
109         tar --delete $(TARNAME)/VERSION > $(TARNAME).tar && \
110         tar rf $(TARNAME).tar `find $(TARNAME)/*` && \
111         gzip -f -9 $(TARNAME).tar && \
112         md5sum $(TARNAME).tar.gz > $(TARNAME).tar.gz.md5
113         @rm -rf $(TARNAME)
114
115 rpm: dist
116         rpmbuild -ta $(TARNAME).tar.gz
117
118 configure: configure.ac acinclude.m4
119         $(AUTORECONF) -v
120
121 # Maintainer stuff
122 release-doc:
123         git checkout release && \
124         git merge master && \
125         $(MAKE) distclean doc-man doc-html && \
126         git add -f $(MANDOC) $(HTMLDOC) && \
127         git commit -m "Sync docs" && \
128         git checkout master
129
130 release-dist: release-doc
131         git checkout release && \
132         $(MAKE) dist && \
133         git checkout master
134
135 .PHONY: all all-debug doc doc-man doc-html install install-doc \
136         install-doc-man install-doc-html clean spell-check dist rpm
137
138 tig.o: tig.c
139 tig: tig.o
140
141 tig.spec: contrib/tig.spec.in
142         sed -e 's/@@VERSION@@/$(RPM_VERSION)/g' \
143             -e 's/@@RELEASE@@/$(RPM_RELEASE)/g' < $< > $@
144
145 manual.html: manual.toc
146 manual.toc: manual.txt
147         sed -n '/^\[\[/,/\(---\|~~~\)/p' < $< | while read line; do \
148                 case "$$line" in \
149                 "-----"*)  echo ". <<$$ref>>"; ref= ;; \
150                 "~~~~~"*)  echo "- <<$$ref>>"; ref= ;; \
151                 "[["*"]]") ref="$$line" ;; \
152                 *)         ref="$$ref, $$line" ;; \
153                 esac; done | sed 's/\[\[\(.*\)\]\]/\1/' > $@
154
155 README.html: README
156         $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d article -a readme $<
157
158 %.pdf : %.xml
159         $(DOCBOOK2PDF) $<
160
161 %.1.html : %.1.txt
162         $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d manpage $<
163
164 %.1.xml : %.1.txt
165         $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b docbook -d manpage -aversion=$(VERSION) $<
166
167 %.1 : %.1.xml
168         $(XMLTO) man $<
169
170 %.5.html : %.5.txt
171         $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d manpage $<
172
173 %.5.xml : %.5.txt
174         $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b docbook -d manpage -aversion=$(VERSION) $<
175
176 %.5 : %.5.xml
177         $(XMLTO) man $<
178
179 %.html : %.txt
180         $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b xhtml11 -d article -n $<
181
182 %.xml : %.txt
183         $(ASCIIDOC) $(ASCIIDOC_FLAGS) -b docbook -d article $<
184
185 %.html-chunked : %.xml
186         $(XMLTO) html -o $@ $<