Use docbook to build manual.pdf; clean *.xml files
[tig] / Makefile
1 prefix  = $(HOME)
2 bindir= $(prefix)/bin
3 mandir = $(prefix)/man
4 docdir = $(prefix)/share/doc
5 # DESTDIR=
6
7 LDLIBS  = -lcurses
8 CFLAGS  = -Wall -O2
9 DFLAGS  = -g -DDEBUG -Werror
10 PROGS   = tig
11 DOCS    = tig.1.html tig.1 tigrc.5.html tigrc.5 \
12           manual.toc manual.html manual.html-chunked manual.pdf \
13           README.html
14
15 ifneq (,$(wildcard .git))
16 VERSION = $(shell git-describe)
17 WTDIRTY = $(shell git-diff-index --name-only HEAD 2>/dev/null)
18 CFLAGS += '-DVERSION="$(VERSION)$(if $(WTDIRTY),-dirty)"'
19 endif
20
21 all: $(PROGS)
22 all-debug: $(PROGS)
23 all-debug: CFLAGS += $(DFLAGS)
24 doc: $(DOCS)
25
26 install: all
27         for prog in $(PROGS); do \
28                 install $$prog $(DESTDIR)$(bindir); \
29         done
30
31 install-doc: doc
32         mkdir -p $(DESTDIR)$(mandir)/man1 \
33                  $(DESTDIR)$(mandir)/man5 \
34                  $(DESTDIR)$(docdir)/tig
35         for doc in $(DOCS); do \
36                 case "$$doc" in \
37                 *.1) install $$doc $(DESTDIR)$(mandir)/man1 ;; \
38                 *.5) install $$doc $(DESTDIR)$(mandir)/man5 ;; \
39                 *.html) install $$doc $(DESTDIR)$(docdir)/tig ;; \
40                 esac \
41         done
42
43 clean:
44         rm -rf manual.html-chunked
45         rm -f $(PROGS) $(DOCS) core *.xml
46
47 spell-check:
48         aspell --lang=en --check tig.1.txt tigrc.5.txt manual.txt
49
50 strip: all
51         strip $(PROGS)
52
53 .PHONY: all all-debug doc install install-doc clean spell-check
54
55 manual.toc: manual.txt
56         sed -n '/^\[\[/,/\(---\|~~~\)/p' < $< | while read line; do \
57                 case "$$line" in \
58                 "-----"*)  echo ". <<$$ref>>"; ref= ;; \
59                 "~~~~~"*)  echo "- <<$$ref>>"; ref= ;; \
60                 "[["*"]]") ref="$$line" ;; \
61                 *)         ref="$$ref, $$line" ;; \
62                 esac; done | sed 's/\[\[\(.*\)\]\]/\1/' > $@
63
64 tig: tig.c
65
66 README.html: README
67         asciidoc -b xhtml11 -d article -a readme $<
68
69 %.pdf : %.xml
70         docbook2pdf $<
71
72 %.1.html : %.1.txt
73         asciidoc -b xhtml11 -d manpage $<
74
75 %.1.xml : %.1.txt
76         asciidoc -b docbook -d manpage $<
77
78 %.1 : %.1.xml
79         xmlto man $<
80
81 %.5.html : %.5.txt
82         asciidoc -b xhtml11 -d manpage $<
83
84 %.5.xml : %.5.txt
85         asciidoc -b docbook -d manpage $<
86
87 %.5 : %.5.xml
88         xmlto man $<
89
90 %.html : %.txt
91         asciidoc -b xhtml11 -d article -n $<
92
93 %.xml : %.txt
94         asciidoc -b docbook -d article $<
95
96 %.html-chunked : %.xml
97         xmlto html -o $@ $<
98
99 # Maintainer stuff
100 sync-docs:
101         cg switch release
102         -cg merge -n master
103         cg commit -m "Merge with master"
104         make doc
105         cg commit -m "Sync docs"
106         cg switch master