docs: better docs, mv doxygen to sphinx
[vpp.git] / docs / _scripts / Makefile
1 # Copyright (c) 2021 Comcast Cable Communications Management, LLC.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 #
16 # Build the documentation
17 #
18
19 # Default target
20 .PHONY: all
21 all: siphon
22
23 # These should be passed in by the root Makefile
24 WS_ROOT ?= $(CURDIR)/../..
25 BR ?= $(WS_ROOT)/build-root
26
27 # Tag used in github repository path.
28 # Change this when genearting for a release
29 VPP_TAG ?= master
30
31 REPOSITORY_URL ?= https://github.com/FDio/vpp/blob/$(VPP_TAG)/
32
33 # Doxygen configuration and our utility scripts
34 SCRIPTS_DIR ?= $(WS_ROOT)/docs/_scripts
35
36 # docs root directory
37 DOCS_DIR ?= ${BR}/docs/src
38
39 FEATURE_LIST_FILE = ${DOCS_DIR}/aboutvpp/featurelist.md
40
41 # Siphoned fragements are processed into here
42 DOCS_GENERATED_DIR ?= $(DOCS_DIR)/_generated
43
44 # Siphoned fragments end up in here
45 SIPHON_INPUT_DIR ?= $(DOCS_GENERATED_DIR)/fragments
46
47 DYNAMIC_RENDER_DIR ?= ${DOCS_GENERATED_DIR}/includes
48
49 # Primary source directories
50 SIPHON_SRC ?= $(WS_ROOT)/src
51 SIPHON_SRC_DIRECTORIES = \
52         $(shell find $(SIPHON_SRC) -name '*.md' -print | xargs dirname \
53         | sort | uniq) \
54         $(SIPHON_SRC)/vppinfra \
55         $(SIPHON_SRC)/svm \
56         $(SIPHON_SRC)/vlib \
57         $(SIPHON_SRC)/vlibapi \
58         $(SIPHON_SRC)/vlibmemory \
59         $(SIPHON_SRC)/vnet \
60         $(SIPHON_SRC)/vpp \
61         $(SIPHON_SRC)/vpp-api \
62         $(SIPHON_SRC)/examples
63
64 # Input directories and files
65 SIPHON_INPUT ?= \
66         $(wildcard $(WS_ROOT)/*.md) \
67         $(wildcard $(SCRIPTS_DIR)/*.md) \
68         $(SIPHON_SRC_DIRECTORIES) \
69         $(SIPHON_SRC)/plugins \
70         extras
71
72 # Strip leading workspace path from input names
73 SIPHON_INPUT := $(subst $(WS_ROOT)/,,$(SIPHON_INPUT))
74
75 # Files to exclude, from pre-Doxygen steps, eg because they're
76 # selectively compiled.
77 # Examples would be to exclude non-DPDK related sources when
78 # there's a DPDK equivalent that conflicts.
79 # These must be left-anchored paths for the regexp below to work.
80 SIPHON_EXCLUDE ?= \
81         $(SIPHON_SRC)/vpp-api/lua
82
83 # Generate a regexp for filenames to exclude
84 SIPHON_EXCLUDE_REGEXP = ($(subst .,\.,$(shell echo '$(strip $(SIPHON_EXCLUDE))' | sed -e 's/ /|/g')))
85
86 # Include all the normal source directories in the include file path
87 SIPHON_INCLUDE_PATH = $(SIPHON_SRC_DIRECTORIES)
88
89 # Find API header directories and include them in the header path.
90 # This is only useful if VPP and plugins are already built; nothing
91 # here depends on those targets. We don't build documentation for these
92 # header files, they're just added to the INCLUDE search path for Doxygen.
93 _vpp_br = $(shell find "$(BR)" -maxdepth 1 -type d \
94         '(' -name build-vpp_debug-native -o -name build-vpp-native ')' -print \
95         | sed -e 's@^$(WS_ROOT)/*@@' -e 1q)
96 ifneq ($(strip $(_vpp_br)),)
97 SIPHON_INCLUDE_PATH += \
98         $(_vpp_br)/vlib-api \
99         $(_vpp_br)/vpp
100 # Also include any plugin directories that exist
101 SIPHON_INCLUDE_PATH += \
102         $(shell find $(WS_ROOT)/$(_vpp_br)/plugins -maxdepth 1 -type d | sed -e 's@^$(WS_ROOT)/*@@')
103 endif
104
105 # Discover if we have CPP available
106 _cpp = $(shell which cpp)
107 ifneq ($(strip $(_cpp)),)
108 # Add whatever directories CPP normally includes to the header path
109 SIPHON_INCLUDE_PATH += $(shell set -e; $(_cpp) -v </dev/null 2>&1 | awk 'f&&/^ /{print $$1} /^\#include/{f=1}')
110 endif
111
112 # All the siphon types we know about
113 SIPHONS ?= clicmd syscfg
114
115 SIPHON_FILES = $(addprefix $(SIPHON_INPUT_DIR)/,$(addsuffix .siphon,$(SIPHONS)))
116 SIPHON_DOCS = $(addprefix $(DOCS_GENERATED_DIR)/,$(addsuffix .rst,$(SIPHONS)))
117
118 BUILT_ON = $(shell date '+%d %B %Y')
119 VPP_VERSION = $(shell ${WS_ROOT}/src/scripts/version)
120
121 .PHONY: featurelist
122 featurelist:
123         @( \
124           cd $(WS_ROOT) && \
125           find . -name FEATURE.yaml | \
126             ./src/scripts/fts.py \
127               --markdown \
128               --repolink $(REPOSITORY_URL) > \
129             $(FEATURE_LIST_FILE) ; \
130         )
131
132
133 .PHONY: includes-render
134 includes-render:
135         @mkdir -p "$(DYNAMIC_RENDER_DIR)"
136         @python3 $(SCRIPTS_DIR)/includes_renderer.py ${WS_ROOT} ${DYNAMIC_RENDER_DIR}
137
138 .PHONY: template-index
139 template-index:
140         @sed -ie "s/__VPP_VERSION__/${VPP_VERSION}/g" ${DOCS_DIR}/index.rst
141         @sed -ie "s/__BUILT_ON__/${BUILT_ON}/g" ${DOCS_DIR}/index.rst
142
143 .NOTPARALLEL: $(SIPHON_FILES)
144 $(SIPHON_FILES): $(SCRIPTS_DIR)/siphon-generate \
145                 $(addprefix,$(WSROOT),$(SIPHON_INPUT)) \
146                 $(wildcard $(SCRIPTS_DIR)/siphon/*.py)
147         @echo "Validating source tree..."
148         @set -e; for input in $(SIPHON_INPUT); do \
149                 if [ ! -e "$(WS_ROOT)/$$input" ]; then \
150                         echo "ERROR: Input path '$$input' does not exist." >&2; \
151                         exit 1; \
152                 fi; \
153         done
154         @rm -rf "$(SIPHON_INPUT_DIR)" "$(DOCS_GENERATED_DIR)"
155         @mkdir -p "$(SIPHON_INPUT_DIR)" "$(DOCS_GENERATED_DIR)"
156         @touch $(SIPHON_INPUT_DIR)/files
157         @echo "Collating source file list for siphoning..."
158         @for input in $(SIPHON_INPUT); do \
159                 cd "$(WS_ROOT)"; \
160                 find "$$input" -type f \
161                         \( -name '*.[ch]' -or -name '*.dox' \) -print \
162                         | grep -v -E '^src/examples/' \
163                         | grep -v -E '^$(SIPHON_EXCLUDE_REGEXP)' \
164                         >> $(SIPHON_INPUT_DIR)/files; \
165         done
166         @echo "Generating siphons..."
167         @set -e; \
168         cd "$(WS_ROOT)"; \
169         $(SCRIPTS_DIR)/siphon-generate \
170                 --output="$(SIPHON_INPUT_DIR)" \
171                 "@$(SIPHON_INPUT_DIR)/files"
172
173 # Evaluate this to build a siphon doc output target for each desired
174 # output type:
175 # $(eval $(call siphon-process,file_extension,output_type_name))
176 define siphon-process
177 $(DOCS_GENERATED_DIR)/%.$(1): $(SIPHON_INPUT_DIR)/%.siphon \
178                 $(SCRIPTS_DIR)/siphon-process \
179                 $(wildcard $(SCRIPTS_DIR)/siphon/*.py) \
180                 $(wildcard $(SCRIPTS_DIR)/siphon_templates/$(2)/*/*.$(1))
181         @echo "Processing siphon for $(2) from $$(notdir $$<)..."
182         @set -e; \
183         cd "$(WS_ROOT)"; \
184         mkdir -p $(DOCS_GENERATED_DIR)/$$(basename $$(notdir $$<)).$(1).dir; \
185         $(SCRIPTS_DIR)/siphon-process \
186                 --type=$$(basename $$(notdir $$<)) \
187                 --format=$(2) \
188                 --repolink=$(REPOSITORY_URL)/ \
189                 --outdir=$(DOCS_GENERATED_DIR)/$$(basename $$(notdir $$<)).$(1).dir \
190                 --output="$$@" \
191                 "$$<"
192 endef
193
194 # Process the .siphon source fragments and render them into siphon flavored
195 # markdown documentation
196 .DELETE_ON_ERROR: $(SIPHON_DOCS)
197 $(eval $(call siphon-process,rst,markdown))
198
199 # This target can be used just to generate the siphoned things
200 .PHONY: siphon
201 siphon: $(SIPHON_DOCS)
202         @cp $(DOCS_GENERATED_DIR)/clicmd.rst $(DOCS_DIR)/cli-reference/index.rst
203         @cp -r $(DOCS_GENERATED_DIR)/clicmd.rst.dir $(DOCS_DIR)/cli-reference/clis
204
205 .PHONY: generate
206 generate: siphon includes-render template-index featurelist
207
208 .PHONY: clean
209 clean:
210         @rm -rf $(BR)/.siphon.dep
211         @rm -rf $(SCRIPTS_DIR)/siphon/__pycache__
212