1XEN_ROOT=$(CURDIR)/..
2include $(XEN_ROOT)/Config.mk
3-include $(XEN_ROOT)/config/Docs.mk
4
5VERSION		:= $(shell $(MAKE) -C $(XEN_ROOT)/xen --no-print-directory xenversion)
6DATE		:= $(shell date +%Y-%m-%d)
7
8DOC_ARCHES      := arm x86_32 x86_64
9MAN_SECTIONS    := 1 5 7 8
10
11# Documentation sources to build
12MAN-SRC-y := $(sort $(basename $(wildcard man/*.pod man/*.pandoc)))
13
14RST-SRC-y := $(sort $(filter-out %index.rst,$(shell find * -type f -name '*.rst' -print)))
15
16TXTSRC-y := $(sort $(shell find misc -name '*.txt' -print))
17
18PANDOCSRC-y := $(sort $(shell find designs/ features/ misc/ process/ specs/ \( -name '*.pandoc' -o -name '*.md' \) -print))
19
20# Documentation targets
21$(foreach i,$(MAN_SECTIONS), \
22  $(eval DOC_MAN$(i) := $(patsubst man/%.$(i),man$(i)/%.$(i), \
23                                   $(filter %.$(i),$(MAN-SRC-y)))))
24
25DOC_HTML := html/SUPPORT.html \
26            $(patsubst %.pandoc,html/%.html,$(PANDOCSRC-y)) \
27            $(patsubst %.md,html/%.html,$(PANDOCSRC-y)) \
28            $(patsubst %.rst,html/%.html,$(RST-SRC-y)) \
29            $(patsubst %,html/%.html,$(MAN-SRC-y)) \
30            $(patsubst %.txt,html/%.txt,$(TXTSRC-y)) \
31            $(patsubst %,html/hypercall/%/index.html,$(DOC_ARCHES))
32DOC_TXT  := $(patsubst %.txt,txt/%.txt,$(TXTSRC-y)) \
33            $(patsubst %.pandoc,txt/%.txt,$(PANDOCSRC-y)) \
34            $(patsubst %.md,txt/%.txt,$(PANDOCSRC-y)) \
35            $(patsubst %.rst,txt/%.txt,$(RST-SRC-y)) \
36            $(patsubst %,txt/%.txt,$(MAN-SRC-y))
37DOC_PDF  := $(patsubst %.pandoc,pdf/%.pdf,$(PANDOCSRC-y)) \
38            $(patsubst %.md,pdf/%.pdf,$(PANDOCSRC-y)) \
39            $(patsubst %.rst,pdf/%.pdf,$(RST-SRC-y))
40
41# Top level build targets
42.PHONY: all
43all: build
44
45.PHONY: build
46build: html txt pdf man-pages figs
47
48.PHONY: sphinx-html
49sphinx-html:
50	sphinx-build -b html . sphinx/html
51
52.PHONY: html
53html: $(DOC_HTML) html/index.html
54
55.PHONY: txt
56txt: $(DOC_TXT)
57
58.PHONY: figs
59figs:
60ifneq ($(FIG2DEV),)
61	$(MAKE) -C figs
62else
63	@echo "fig2dev (transfig) not installed; skipping figs."
64endif
65
66.PHONY: pdf
67pdf: $(DOC_PDF)
68
69.PHONY: clean
70clean: clean-man-pages
71	$(MAKE) -C figs clean
72	rm -rf .word_count *.aux *.dvi *.bbl *.blg *.glo *.idx *~
73	rm -rf *.ilg *.log *.ind *.toc *.bak *.tmp core
74	rm -rf html txt pdf sphinx/html
75
76.PHONY: distclean
77distclean: clean
78	rm -rf $(XEN_ROOT)/config/Docs.mk config.log config.status config.cache \
79		autom4te.cache
80
81# Top level install targets
82
83.PHONY: man-pages install-man-pages clean-man-pages uninstall-man-pages
84
85# Metarules for generating manpages.  Run with $(1) substitued for section
86define GENERATE_MANPAGE_RULES
87
88# Real manpages
89man$(1)/%.$(1): man/%.$(1).pod Makefile
90ifneq ($(POD2MAN),)
91	@$(INSTALL_DIR) $$(@D)
92	$(POD2MAN) --release=$(VERSION) --name=$$* -s $(1) -c "Xen" $$< $$@
93else
94	@echo "pod2man not installed; skipping $$@"
95endif
96
97man$(1)/%.$(1): man/%.$(1).pandoc Makefile
98ifneq ($(PANDOC),)
99	@$(INSTALL_DIR) $$(@D)
100	$(PANDOC) --standalone -V title=$$* -V section=$(1) \
101		      -V date="$(DATE)" -V footer="$(VERSION)" \
102			  -V header=Xen $$< -t man --output $$@
103else
104	@echo "pandoc not installed; skipping $$@"
105endif
106
107# HTML manpages
108# sed used to fix up links between man-pages
109# 1) L<xl(1)> -> L<xl(1)|relative:xl.1.html>
110# 2) <a href="relative:xl.1.html"> -> <a href="xl.1.html">
111html/man/%.$(1).html: man/%.$(1).pod Makefile
112ifneq ($(POD2HTML),)
113	@$(INSTALL_DIR) $$(@D)
114	sed -r -e 's%L<([^>]+)\(([1-9])\)>%L<\1(\2)|relative:\1.\2.html>%g' $$< | \
115		$(POD2HTML) | \
116		sed -r -e 's%( href=")relative:%\1%g' > $$@
117else
118	@echo "pod2html not installed; skipping $$@"
119endif
120
121html/man/%.$(1).html: man/%.$(1).pandoc Makefile
122ifneq ($(PANDOC),)
123	@$(INSTALL_DIR) $$(@D)
124	$(PANDOC) --standalone $$< -t html --toc --output $$@
125else
126	@echo "pandoc not installed; skipping $$@"
127endif
128
129# Text manpages
130txt/man/%.$(1).txt: man/%.$(1).pod Makefile
131ifneq ($(POD2TEXT),)
132	@$(INSTALL_DIR) $$(@D)
133	$(POD2TEXT) $$< $$@
134else
135	@echo "pod2text not installed; skipping $$@"
136endif
137
138txt/man/%.$(1).txt: man/%.$(1).pandoc Makefile
139ifneq ($(PANDOC),)
140	@$(INSTALL_DIR) $$(@D)
141	$(PANDOC) --standalone $$< -t plain --output $$@
142else
143	@echo "pandoc not installed; skipping $$@"
144endif
145
146# Build
147.PHONY: man$(1)-pages
148man$(1)-pages: $$(DOC_MAN$(1))
149
150# Install
151.PHONY: install-man$(1)-pages
152install-man$(1)-pages: man$(1)-pages
153	$(INSTALL_DIR) $(DESTDIR)$(mandir)
154	cp -r man$(1) $(DESTDIR)$(mandir)
155
156# Clean
157.PHONY: clean-man$(1)-pages
158clean-man$(1)-pages:
159	rm -rf man$(1)
160
161# Uninstall
162.PHONY: uninstall-man$(1)-pages
163uninstall-man$(1)-pages:
164	rm -f $(addprefix $(DESTDIR)$(mandir)/,$(DOC_MAN$(1)))
165
166# Link buld/install/clean to toplevel rules
167man-pages: man$(1)-pages
168install-man-pages: install-man$(1)-pages
169clean-man-pages: clean-man$(1)-pages
170uninstall-man-pages: uninstall-man$(1)-pages
171
172endef
173
174# Generate manpage rules for each section
175$(foreach i,$(MAN_SECTIONS),$(eval $(call GENERATE_MANPAGE_RULES,$(i))))
176
177.PHONY: install-html
178install-html: html txt figs
179	$(INSTALL_DIR) $(DESTDIR)$(docdir)
180	[ ! -d html ] || cp -R html $(DESTDIR)$(docdir)
181
182.PHONY: install
183install: install-man-pages install-html
184
185.PHONY: uninstall-html
186uninstall-html:
187	rm -rf $(DESTDIR)$(docdir)
188
189.PHONY: uninstall
190uninstall: uninstall-man-pages uninstall-html
191
192# Individual file build targets
193html/index.html: $(DOC_HTML) $(CURDIR)/gen-html-index INDEX
194	$(PERL) -w -- $(CURDIR)/gen-html-index -i INDEX html $(DOC_HTML)
195
196html/%.txt: %.txt
197	@$(INSTALL_DIR) $(@D)
198	$(INSTALL_DATA) $< $@
199
200
201# For non-x86 arches exclude the subarch whole x86 arch.
202$(foreach i,$(filter-out x86_32 x86_64,$(DOC_ARCHES)),html/hypercall/$(i)/index.html): EXTRA_EXCLUDE := -X arch-x86
203
204html/hypercall/%/index.html: $(CURDIR)/xen-headers Makefile
205	rm -rf $(@D)
206	$(INSTALL_DIR) $(@D)
207	$(PERL) -w $(CURDIR)/xen-headers -O $(@D) \
208		-T 'arch-$* - Xen public headers' \
209		$(patsubst %,-X arch-%,$(filter-out $*,$(DOC_ARCHES))) \
210		$(patsubst %,-X xen-%,$(filter-out $*,$(DOC_ARCHES))) \
211		$(EXTRA_EXCLUDE) \
212		$(XEN_ROOT)/xen include/public include/xen/errno.h
213
214-include $(wildcard html/hypercall/*/.deps)
215
216txt/%.txt: %.txt
217	@$(INSTALL_DIR) $(@D)
218	$(INSTALL_DATA) $< $@
219
220# Metarule for generating pandoc rules.
221define GENERATE_PANDOC_RULE_RAW
222$(1): $(2)
223ifneq ($(PANDOC),)
224	@$(INSTALL_DIR) $$(@D)
225	$(PANDOC) --number-sections --toc --standalone $$< --output $$@
226else
227	@echo "pandoc not installed; skipping $$@"
228endif
229endef
230define GENERATE_PANDOC_RULE
231# $(1) is the target documentation format. $(2) is the source format.
232$(call GENERATE_PANDOC_RULE_RAW,$(1)/%.$(1),%.$(2))
233endef
234
235$(foreach dst-fmt,pdf txt html,\
236$(foreach src-fmt,pandoc md rst,\
237$(eval $(call GENERATE_PANDOC_RULE,$(dst-fmt),$(src-fmt)))))
238
239$(eval $(call GENERATE_PANDOC_RULE_RAW,html/SUPPORT.html,$(XEN_ROOT)/SUPPORT.md))
240
241ifeq (,$(findstring clean,$(MAKECMDGOALS)))
242$(XEN_ROOT)/config/Docs.mk:
243	$(error You have to run ./configure before building docs)
244endif
245