Skip to content

Commit e4a020e

Browse files
committed
refactor(makefile): sphinx-build make mode
Refactor this to reduce some redundant logic, simplify and describe variable blocks, and use the sphinx-build make mode. Newer versions of sphinx-quickstart have started rolling out make mode. This provides a useful help note and allows users to try multiple builders very easily. I believe we should redirect most targets through this new mode. Unfortunately this mode appends the builder name to the output path. Given that our current software-dl.ti.com deployment scheme relies on a specific output path, I've added a "ti" target to provide the older behavior and made it the default. The normal "html" builder will use the standard sphinx-build output scheme with only one directory corresponding to the platform and os values. The version will be assumed to be unnecessary in this mode. Signed-off-by: Randolph Sapp <[email protected]>
1 parent 0ac1c54 commit e4a020e

File tree

1 file changed

+56
-62
lines changed

1 file changed

+56
-62
lines changed

Makefile

Lines changed: 56 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,70 @@
1-
# Makefile for Sphinx documentation
2-
#
3-
4-
default: html
5-
6-
# You can set these variables from the command line.
7-
SPHINXOPTS =
8-
SPHINXBUILD = sphinx-build
9-
PAPER =
10-
OS ?= linux
11-
12-
_UC = $(shell echo '$1' | tr '[:lower:]' '[:upper:]')
13-
_LC = $(shell echo '$1' | tr '[:upper:]' '[:lower:]')
14-
15-
DEVFAMILY_UP=$(call _UC,${DEVFAMILY})
16-
OS_LOW=$(call _LC,${OS})
17-
18-
mkfile_path = $(abspath $(lastword $(MAKEFILE_LIST)))
19-
export ROOTDIR = $(dir $(mkfile_path))
20-
$(info ROOTDIR is $(ROOTDIR))
21-
22-
$(info DEVFAMILY is $(DEVFAMILY_UP))
23-
24-
ifeq ($(OS_LOW), android)
25-
# For Android, AM67A and AM67 have their own device directories
26-
ifeq ($(DEVFAMILY_UP), $(filter $(DEVFAMILY_UP), J721E J7200 J721S2 J784S4 AM68 AM69 J722S J742S2 AM68A AM69A TDA4VM))
27-
CONFDIR = source/devices/J7_Family/${OS_LOW}
28-
else
29-
CONFDIR = source/devices/$(DEVFAMILY_UP)/${OS_LOW}
30-
endif
31-
else
32-
# For Linux and other OSes, use J7_Family grouping including AM67A and AM67
33-
ifeq ($(DEVFAMILY_UP), $(filter $(DEVFAMILY_UP), J721E J7200 J721S2 J784S4 AM68 AM69 J722S AM67 J742S2 AM68A AM67A AM69A TDA4VM))
34-
CONFDIR = source/devices/J7_Family/${OS_LOW}
35-
else
36-
CONFDIR = source/devices/$(DEVFAMILY_UP)/${OS_LOW}
1+
# User defined variables for Sphinx
2+
SPHINXOPTS ?=
3+
SPHINXBUILD ?= sphinx-build
4+
SOURCEDIR = source
5+
6+
# User defined variables for custom plugins
7+
DEVFAMILY ?= AM62X
8+
OS ?= linux
9+
10+
# Case modification functions, to assist with custom plugins
11+
_UC = $(shell printf '%s' '$(1)' | tr '[:lower:]' '[:upper:]')
12+
_LC = $(shell printf '%s' '$(1)' | tr '[:upper:]' '[:lower:]')
13+
14+
# Export variable overrides for custom plugins
15+
override DEVFAMILY := $(call _UC,$(DEVFAMILY))
16+
override OS := $(call _LC,$(OS))
17+
override ROOTDIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
18+
export DEVFAMILY OS ROOTDIR
19+
20+
# Configuration directory, complicated because of Jacinto
21+
CONFDIR = $(SOURCEDIR)/devices/$(DEVFAMILY)/$(OS)
22+
ifneq ($(filter $(DEVFAMILY), J721E J7200 J721S2 J784S4 AM68 AM69 J722S AM67 J742S2 AM68A AM67A AM69A TDA4VM),)
23+
# For Linux and other OSes, use J7_Family
24+
CONFDIR = $(SOURCEDIR)/devices/J7_Family/$(OS)
25+
ifeq ($(OS), android)
26+
# For Android, AM67A has their own device directories
27+
ifneq ($(filter $(DEVFAMILY), AM67 AM67A),)
28+
CONFDIR = $(SOURCEDIR)/devices/$(DEVFAMILY)/$(OS)
29+
endif
3730
endif
31+
# Print the new variable since this logic is likely to break
32+
$(info CONFDIR = "$(CONFDIR)")
3833
endif
3934

40-
$(info CONFDIR is $(CONFDIR))
35+
# These can be overridden if necessary
36+
VERSION = $(file <$(CONFDIR)/version.txt)
4137

42-
VERSION = $(shell cat ${CONFDIR}/version.txt)
43-
SOURCEDIR = source
44-
BUILDDIR = build/processor-sdk-${OS_LOW}-${DEVFAMILY_UP}/esd/docs/${VERSION}
38+
# TI specifc deployment variables
39+
BUILDDIR = build/processor-sdk-$(OS)-$(DEVFAMILY)
40+
ti : BUILDDIR = build/processor-sdk-$(OS)-$(DEVFAMILY)/esd/docs/$(VERSION)
4541

46-
# User-friendly check for sphinx-build
47-
ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
48-
$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from https://sphinx-doc.org/)
49-
endif
50-
51-
# Internal variables.
52-
PAPEROPT_a4 = -D latex_paper_size=a4
53-
PAPEROPT_letter = -D latex_paper_size=letter
42+
# Internal additions to SPHINXOPTS
5443
CONFLOC = -c $(ROOTDIR)
55-
VEROPTS = -D version=${VERSION} -D release=${VERSION}
44+
VEROPTS = -D version=$(VERSION) -D release=$(VERSION)
5645
GIT_HASH = -D html_context.commit="$(shell git rev-parse --short HEAD)"
57-
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) $(CONFLOC) $(VEROPTS) $(GIT_HASH)
58-
# the i18n builder cannot share the environment and doctrees with the others
59-
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
46+
DOCTREE = -d $(BUILDDIR)/doctrees
47+
SPHINXOPTS := $(strip $(CONFLOC) $(VEROPTS) $(GIT_HASH) $(DOCTREE) $(SPHINXOPTS))
6048

61-
.PHONY: help clean config html
49+
# Give some information on the command line about the build
50+
$(info DEVFAMILY = "$(DEVFAMILY)")
51+
$(info OS = "$(OS)")
52+
$(info ROOTDIR = "$(ROOTDIR)")
53+
$(info VERSION = "$(VERSION)")
54+
$(info BUILDDIR = "$(BUILDDIR)")
6255

63-
help:
64-
@echo "Please use \`make <target>' where <target> is one of"
65-
@echo " html to make standalone HTML files"
56+
.PHONY: default lint
6657

67-
clean:
68-
rm -rf "$(BUILDDIR)"
58+
default: ti
6959

7060
lint:
7161
rstcheck -r "$(SOURCEDIR)"
7262

73-
html:
74-
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) "$(SOURCEDIR)" "$(BUILDDIR)"
75-
@echo
76-
@echo "Build finished. The HTML pages are in $(BUILDDIR)."
63+
# Backwards compatible build target that preserves the old output path, for now
64+
ti:
65+
@$(SPHINXBUILD) -b html "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS)
66+
67+
# Pass everything else back to Sphinx, as they have their own "help" function to
68+
# list available builders, and their own "clean" function
69+
%::
70+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS)

0 commit comments

Comments
 (0)