|
1 | | -.PHONY: build |
| 1 | +.DEFAULT_GOAL := help |
| 2 | + |
| 3 | +PYENV_PYTHON := $(shell if command -v pyenv >/dev/null 2>&1 && pyenv versions --bare | grep -qx '3.8.13'; then printf 'PYENV_VERSION=3.8.13 pyenv exec python'; fi) |
| 4 | +PYTHON ?= $(if $(PYENV_PYTHON),$(PYENV_PYTHON),python3) |
| 5 | +VENV ?= .venv |
| 6 | +PORT ?= 8005 |
| 7 | + |
| 8 | +VENV_BIN := $(VENV)/bin |
| 9 | +VENV_PYTHON := $(CURDIR)/$(VENV_BIN)/python |
| 10 | +SPHINXBUILD := $(CURDIR)/$(VENV_BIN)/sphinx-build |
| 11 | +BUILD_DIR := docs/_build |
| 12 | +INSTALL_STAMP := $(VENV)/.installed |
| 13 | +DOC_TARGETS := dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf latexpdfja text man texinfo info gettext changes linkcheck doctest xml pseudoxml netlify |
| 14 | + |
| 15 | +.PHONY: help install build html serve clean $(DOC_TARGETS) |
| 16 | + |
| 17 | +help: |
| 18 | + @echo "Please use \`make <target>' where <target> is one of" |
| 19 | + @echo " install create $(VENV) and install dependencies" |
| 20 | + @echo " html build standalone HTML files" |
| 21 | + @echo " serve build and serve docs at http://localhost:$(PORT)/" |
| 22 | + @echo " clean remove generated documentation files" |
| 23 | + @echo |
| 24 | + @echo "Other Sphinx targets are forwarded to docs/Makefile." |
| 25 | + |
| 26 | +install: $(INSTALL_STAMP) |
| 27 | + |
| 28 | +$(INSTALL_STAMP): requirements.txt |
| 29 | + @test -n "$(PYTHON)" || (echo "python3 is required" && exit 1) |
| 30 | + $(PYTHON) -m venv $(VENV) |
| 31 | + $(VENV_PYTHON) -m pip install --upgrade pip |
| 32 | + $(VENV_PYTHON) -m pip install -r requirements.txt |
| 33 | + @touch $(INSTALL_STAMP) |
| 34 | + |
2 | 35 | build: html |
3 | 36 |
|
4 | | -# this pattern rule lets you run "make build" (or any other target |
5 | | -# in docs/Makefile) in this directory as though you were in docs/ |
6 | | -%: |
7 | | - cd docs && make $@ |
| 37 | +html: install |
| 38 | + $(MAKE) -C docs html SPHINXBUILD=$(SPHINXBUILD) |
| 39 | + @touch $(BUILD_DIR)/html/.nojekyll |
| 40 | + |
| 41 | +serve: html |
| 42 | + cd $(BUILD_DIR)/html && $(VENV_PYTHON) -m http.server $(PORT) |
| 43 | + |
| 44 | +clean: |
| 45 | + rm -rf $(BUILD_DIR)/* |
| 46 | + |
| 47 | +# These targets let you run common docs/Makefile targets from the repository root. |
| 48 | +$(DOC_TARGETS): install |
| 49 | + $(MAKE) -C docs $@ SPHINXBUILD=$(SPHINXBUILD) |
0 commit comments