aboutsummaryrefslogtreecommitdiffstats
path: root/test/plugin_sphinx.mk
blob: 915bf8b6c077d9bd1964cb2f11b7248f7396d234 (plain) (blame)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# Sphinx plugin.

# Disable this test suite when sphinx is not installed.
ifeq ($(shell which sphinx-build),)
SPHINX_TARGETS =
else
SPHINX_TARGETS = $(call list_targets,sphinx)
endif

.PHONY: sphinx $(SPHINX_TARGETS)

sphinx: $(SPHINX_TARGETS)

sphinx-build: init

	$i "Bootstrap a new OTP application named $(APP)"
	$t mkdir $(APP)/
	$t cp ../erlang.mk $(APP)/
	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v

	$i "Generate Sphinx config"
	$(call sphinx-generate-doc-skeleton)

	$i "Run Sphinx"
	$t $(MAKE) -C $(APP) sphinx $v

	$i "Check that documentation was generated"
	$t test -f $(APP)/html/index.html
	$t test -f $(APP)/html/manpage.html

	$i "Distclean the application"
	$t $(MAKE) -C $(APP) distclean $v

	$i "Check that the generated documentation was removed"
	$t test ! -e $(APP)/html/index.html
	$t test ! -e $(APP)/html/manpage.html

	$i "Set 'today' macro with command-line options"
	$t echo "SPHINX_OPTS = -D 'today=erlang_mk_sphinx_today'" >> $(APP)/Makefile

	$i "Run Sphinx"
	$t $(MAKE) -C $(APP) sphinx $v

	$i "Check that the 'today' macro was defined"
	$t grep -q erlang_mk_sphinx_today $(APP)/html/manpage.html

sphinx-source-dir: init

	$i "Bootstrap a new OTP application named $(APP)"
	$t mkdir $(APP)/
	$t cp ../erlang.mk $(APP)/
	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v

	$i "Change documentation source directory"
	$t echo "SPHINX_SOURCE = documentation" >> $(APP)/Makefile

	$i "Generate Sphinx config"
	$(call sphinx-generate-doc-skeleton,documentation)

	$i "Run Sphinx (html)"
	$t $(MAKE) -C $(APP) sphinx $v

	$i "Check that documentation was generated"
	$t test -f $(APP)/html/index.html
	$t test -f $(APP)/html/manpage.html

sphinx-formats: init

	$i "Bootstrap a new OTP application named $(APP)"
	$t mkdir $(APP)/
	$t cp ../erlang.mk $(APP)/
	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v

	$i "Define formats generated by Sphinx"
	$t echo "SPHINX_FORMATS = html man" >> $(APP)/Makefile

	$i "Generate Sphinx config"
	$(call sphinx-generate-doc-skeleton)

	$i "Run Sphinx (html + man)"
	$t $(MAKE) -C $(APP) sphinx $v

	$i "Check that documentation was generated"
	$t test -f $(APP)/man/sphinx_$(APP).1
	$t test -f $(APP)/html/index.html
	$t test -f $(APP)/html/manpage.html

	$i "Distclean the application"
	$t $(MAKE) -C $(APP) distclean $v

	$i "Check that the generated documentation was removed"
	$t test ! -e $(APP)/man/sphinx_$(APP).1
	$t test ! -e $(APP)/html/index.html
	$t test ! -e $(APP)/html/manpage.html

	$i "Change documentation output directories"
	$t echo "sphinx_html_output = sphinx/html_output" >> $(APP)/Makefile
	$t echo "sphinx_man_output  = sphinx/man_output"  >> $(APP)/Makefile

	$i "Run Sphinx (html + man)"
	$t $(MAKE) -C $(APP) sphinx $v

	$i "Check that documentation was generated"
	$t test -f $(APP)/sphinx/man_output/sphinx_$(APP).1
	$t test -f $(APP)/sphinx/html_output/index.html
	$t test -f $(APP)/sphinx/html_output/manpage.html

	$i "Distclean the application"
	$t $(MAKE) -C $(APP) distclean $v

	$i "Check that the generated documentation was removed"
	$t test ! -e $(APP)/sphinx/man_output/sphinx_$(APP).1
	$t test ! -e $(APP)/sphinx/html_output/index.html
	$t test ! -e $(APP)/sphinx/html_output/manpage.html

sphinx-format-opts: init

	$i "Bootstrap a new OTP application named $(APP)"
	$t mkdir $(APP)/
	$t cp ../erlang.mk $(APP)/
	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v

	$i "Define formats generated by Sphinx"
	$t echo "SPHINX_FORMATS = html man" >> $(APP)/Makefile

	$i "Change format-specific options"
	$t echo "sphinx_html_opts = -D 'today=erlang_mk_sphinx_html_today'" >> $(APP)/Makefile
	$t echo "sphinx_man_opts  = -D 'today=erlang_mk_sphinx_man_today'"  >> $(APP)/Makefile

	$i "Generate Sphinx config"
	$(call sphinx-generate-doc-skeleton)

	$i "Run Sphinx (html + man)"
	$t $(MAKE) -C $(APP) sphinx $v

	$i "Check that the 'today' macro was defined correctly"
	$t grep -q erlang_mk_sphinx_html_today $(APP)/html/manpage.html
	$t grep -q erlang_mk_sphinx_man_today $(APP)/man/sphinx_$(APP).1

define sphinx-generate-doc-skeleton
$t mkdir $(APP)/$(if $1,$1,doc)/
$t printf "%s\n" \
	"project = '$(APP)'" \
	"master_doc = 'index'" \
	"source_suffix = '.rst'" \
	"man_pages = [('manpage', 'sphinx_$(APP)', 'Man Page', [], 1)]" \
	"" > $(APP)/$(if $1,$1,doc)/conf.py

$t printf "%s\n" \
	"***********" \
	"Sphinx Docs" \
	"***********" \
	"" \
	"ToC" \
	"===" \
	"" \
	".. toctree::" \
	"" \
	"   manpage" \
	"" \
	"Indices" \
	"=======" \
	"" \
	'* :ref:`genindex`' \
	'* :ref:`modindex`' \
	'* :ref:`search`' \
	"" > $(APP)/$(if $1,$1,doc)/index.rst

$t printf "%s\n" \
	"********" \
	"Man Page" \
	"********" \
	"" \
	"Synopsis" \
	"========" \
	"" \
	".. code-block:: none" \
	"" \
	"    erlang-sphinx-mk-man [--help]" \
	"" \
	"today = |today|" \
	"" > $(APP)/$(if $1,$1,doc)/manpage.rst
endef