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