summaryrefslogtreecommitdiff
path: root/common/doc/template/doc.mk
blob: 84ea77fbd2d327432a402aa4e39e74ac6f6c9955 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
TEMPLATE_DIR := $(BASE)/common/doc/template
HEADERS := header.rst
GEN_HEADERS := $(if $(GLOSSARY),glossary.rst)
GLOSSARIES := $(TEMPLATE_DIR)/glossary/glossary

.PHONY: all pdf html clean

# To change default build rule, before including this file, use:
# all: the_default_rule

html: $(DOCS:%=%.html)
pdf: $(DOCS:%=%.pdf)

RST_DEPS += $(HEADERS) $(GEN_HEADERS) $(DEPS)

# Prevent make to remove our intermediary files, HTML still points to them.
.SECONDARY: $(DEPS)

%.html: %.rst $(TEMPLATE_DIR)/mstar/rst2html-mstar $(RST_DEPS) $(HTML_DEPS)
	$(TEMPLATE_DIR)/mstar/rst2html-mstar $< $@

%.pdf: %.tex $(TEMPLATE_DIR)/mstar/mstar.sty $(PDF_DEPS)
	for i in $$(seq 5); do \
		TEXINPUTS=$(TEMPLATE_DIR)/mstar: xelatex $<; \
		grep -q Rerun $(<:%.tex=%.log) || break; \
	done

%.tex: %.rst $(TEMPLATE_DIR)/mstar/rst2xetex-mstar $(RST_DEPS)
	$(TEMPLATE_DIR)/mstar/rst2xetex-mstar $< $@

# There is no inclusion path in reStructuredText, link to current directory.
$(HEADERS):
	test -f $@ || ln -s $(TEMPLATE_DIR)/mstar/$@

glossary.rst: $(DOCS:%=%.rst) $(GLOSSARIES)
	$(TEMPLATE_DIR)/glossary/make_glossary $(GLOSSARIES:%=-b%) \
		$(DOCS:%=%.rst) -t Glossary > $@

%.depend: %.rst
	echo -n "$*.tex $*.html: " > $@
	awk '/^.. include:: /{printf "%s ", $$3}' $< | \
	sed 's/$(HEADERS) //g' | sed 's/$(GEN_HEADERS) //g' >> $@

clean:
	rm -f $(EXTRA_CLEAN_FILES) $(GEN_HEADERS)
	rm -f $(DOCS:%=%.html) $(DOCS:%=%.pdf) $(DOCS:%=%.tex) \
		$(DOCS:%=%.aux) $(DOCS:%=%.log) $(DOCS:%=%.out) \
		$(DOCS:%=%.toc) $(DOCS:%=%.depend)
	for header in $(HEADERS); do \
		if [ "$$(readlink $$header)" = "$(TEMPLATE_DIR)/mstar/$$header" ]; then rm $$header; fi; \
	done

help:
	@echo "available targets:"
	@echo " - html, pdf: generate HTML or PDF document"
	@echo " - clean: clean after ourself"

-include $(DOCS:%=%.depend)