Skip to content

Commit 42fb259

Browse files
authored
Refactor Makefile to re-use targets via variables (#1207)
* Refactor Makefile to re-use targets via variables * Move 'SOURCEDIR OUTPUTDIR' to new line after other options
1 parent cd06b15 commit 42fb259

File tree

1 file changed

+43
-64
lines changed

1 file changed

+43
-64
lines changed

Makefile

Lines changed: 43 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ VENVDIR = ./venv
77
BUILDDIR = _build
88
SPHINXOPTS = -W --keep-going
99
SPHINXBUILD = $(VENVDIR)/bin/sphinx-build
10+
BUILDER = html
1011
SPHINXLINT = $(VENVDIR)/bin/sphinx-lint
1112
PAPER =
1213

1314
# Internal variables.
1415
PAPEROPT_a4 = -D latex_paper_size=a4
1516
PAPEROPT_letter = -D latex_paper_size=letter
16-
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
17+
ALLSPHINXOPTS = -b $(BUILDER) \
18+
-d $(BUILDDIR)/doctrees \
19+
$(PAPEROPT_$(PAPER)) $(SPHINXOPTS) \
20+
. $(BUILDDIR)/$(BUILDER)
1721

1822
.PHONY: help
1923
help:
@@ -69,111 +73,86 @@ ensure-venv:
6973

7074
.PHONY: html
7175
html: ensure-venv versions
72-
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
73-
@echo
74-
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
76+
$(SPHINXBUILD) $(ALLSPHINXOPTS)
7577

7678
.PHONY: dirhtml
77-
dirhtml: ensure-venv versions
78-
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
79-
@echo
80-
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
79+
dirhtml: BUILDER = dirhtml
80+
dirhtml: html
8181

8282
.PHONY: singlehtml
83-
singlehtml: ensure-venv
84-
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
85-
@echo
86-
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
83+
singlehtml: BUILDER = singlehtml
84+
singlehtml: html
8785

8886
.PHONY: pickle
89-
pickle: ensure-venv
90-
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
87+
pickle: BUILDER = pickle
88+
pickle: html
9189
@echo
9290
@echo "Build finished; now you can process the pickle files."
9391

9492
.PHONY: json
95-
json: ensure-venv
96-
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
93+
json: BUILDER = json
94+
json: html
9795
@echo
9896
@echo "Build finished; now you can process the JSON files."
9997

10098
.PHONY: htmlhelp
101-
htmlhelp: ensure-venv
102-
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
99+
htmlhelp: BUILDER = htmlhelp
100+
htmlhelp: html
103101
@echo
104102
@echo "Build finished; now you can run HTML Help Workshop with the" \
105-
".hhp project file in $(BUILDDIR)/htmlhelp."
103+
".hhp project file in $(BUILDDIR)/$(BUILDER)."
106104

107105
.PHONY: qthelp
108-
qthelp: ensure-venv
109-
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
110-
@echo
111-
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
112-
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
113-
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/PythonDevelopersGuide.qhcp"
114-
@echo "To view the help file:"
115-
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/PythonDevelopersGuide.qhc"
106+
qthelp: BUILDER = qthelp
107+
qthelp: html
116108

117109
.PHONY: devhelp
118-
devhelp: ensure-venv
119-
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
120-
@echo
121-
@echo "Build finished."
122-
@echo "To view the help file:"
123-
@echo "# mkdir -p $$HOME/.local/share/devhelp/PythonDevelopersGuide"
124-
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/PythonDevelopersGuide"
125-
@echo "# devhelp"
110+
devhelp: BUILDER = devhelp
111+
devhelp: html
126112

127113
.PHONY: epub
128-
epub: ensure-venv
129-
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
114+
epub: BUILDER = epub
115+
epub: html
130116
@echo
131-
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
117+
@echo "Build finished. The epub file is in $(BUILDDIR)/$(BUILDER)."
132118

133119
.PHONY: latex
134-
latex: ensure-venv
135-
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
136-
@echo
137-
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
138-
@echo "Run \`make' in that directory to run these through (pdf)latex" \
139-
"(use \`make latexpdf' here to do that automatically)."
120+
latex: BUILDER = latex
121+
latex: html
140122

141123
.PHONY: latexpdf
142-
latexpdf: ensure-venv
143-
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
124+
latexpdf: BUILDER = latex
125+
latexpdf: html
144126
@echo "Running LaTeX files through pdflatex..."
145127
make -C $(BUILDDIR)/latex all-pdf
146-
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
128+
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/$(BUILDER)."
147129

148130
.PHONY: text
149-
text: ensure-venv
150-
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
151-
@echo
152-
@echo "Build finished. The text files are in $(BUILDDIR)/text."
131+
text: BUILDER = text
132+
text: html
153133

154134
.PHONY: man
155-
man: ensure-venv
156-
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
135+
man: BUILDER = man
136+
man: html
157137
@echo
158-
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
138+
@echo "Build finished. The manual pages are in $(BUILDDIR)/$(BUILDER)."
159139

160140
.PHONY: changes
161-
changes: ensure-venv
162-
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
163-
@echo
164-
@echo "The overview file is in $(BUILDDIR)/changes."
141+
changes: BUILDER = changes
142+
changes: html
165143

166-
linkcheck: ensure-venv
167-
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
144+
.PHONY: linkcheck
145+
linkcheck: BUILDER = linkcheck
146+
linkcheck: html
168147
@echo
169148
@echo "Link check complete; look for any errors in the above output " \
170-
"or in $(BUILDDIR)/linkcheck/output.txt."
149+
"or in $(BUILDDIR)/$(BUILDER)/output.txt."
171150

172151
.PHONY: doctest
173-
doctest: ensure-venv
174-
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
152+
doctest: BUILDER = doctest
153+
doctest: html
175154
@echo "Testing of doctests in the sources finished, look at the " \
176-
"results in $(BUILDDIR)/doctest/output.txt."
155+
"results in $(BUILDDIR)/$(BUILDER)/output.txt."
177156

178157
.PHONY: htmlview
179158
htmlview: html

0 commit comments

Comments
 (0)