1 # Copyright (c) 2021 Comcast Cable Communications Management, LLC.
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:
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 # Build the documentation
23 # These should be passed in by the root Makefile
24 WS_ROOT ?= $(CURDIR)/../..
25 BR ?= $(WS_ROOT)/build-root
26 BUILDDIR ?= ${BR}/docs
27 BUILDDIR_SRC ?= ${BUILDDIR}/src
28 DOCS_DIR ?= ${WS_ROOT}/docs
30 # Tag used in github repository path.
31 # Change this when genearting for a release
34 REPOSITORY_URL ?= https://github.com/FDio/vpp/blob/$(VPP_TAG)/
36 # Doxygen configuration and our utility scripts
37 SCRIPTS_DIR ?= $(WS_ROOT)/docs/_scripts
41 FEATURE_LIST_FILE = ${BUILDDIR_SRC}/aboutvpp/featurelist.md
43 # Siphoned fragements are processed into here
44 DOCS_GENERATED_DIR ?= $(BUILDDIR_SRC)/_generated
46 # Siphoned fragments end up in here
47 SIPHON_INPUT_DIR ?= $(DOCS_GENERATED_DIR)/fragments
49 DYNAMIC_RENDER_DIR ?= ${DOCS_GENERATED_DIR}/includes
51 # Primary source directories
52 SIPHON_SRC ?= $(WS_ROOT)/src
53 SIPHON_SRC_DIRECTORIES = \
54 $(shell find $(SIPHON_SRC) -name '*.md' -print | xargs dirname \
56 $(SIPHON_SRC)/vppinfra \
59 $(SIPHON_SRC)/vlibapi \
60 $(SIPHON_SRC)/vlibmemory \
63 $(SIPHON_SRC)/vpp-api \
64 $(SIPHON_SRC)/examples
66 # Input directories and files
68 $(wildcard $(WS_ROOT)/*.md) \
69 $(wildcard $(SCRIPTS_DIR)/*.md) \
70 $(SIPHON_SRC_DIRECTORIES) \
71 $(SIPHON_SRC)/plugins \
74 # Strip leading workspace path from input names
75 SIPHON_INPUT := $(subst $(WS_ROOT)/,,$(SIPHON_INPUT))
77 # Files to exclude, from pre-Doxygen steps, eg because they're
78 # selectively compiled.
79 # Examples would be to exclude non-DPDK related sources when
80 # there's a DPDK equivalent that conflicts.
81 # These must be left-anchored paths for the regexp below to work.
83 $(SIPHON_SRC)/vpp-api/lua
85 # Generate a regexp for filenames to exclude
86 SIPHON_EXCLUDE_REGEXP = ($(subst .,\.,$(shell echo '$(strip $(SIPHON_EXCLUDE))' | sed -e 's/ /|/g')))
88 # Include all the normal source directories in the include file path
89 SIPHON_INCLUDE_PATH = $(SIPHON_SRC_DIRECTORIES)
91 # Find API header directories and include them in the header path.
92 # This is only useful if VPP and plugins are already built; nothing
93 # here depends on those targets. We don't build documentation for these
94 # header files, they're just added to the INCLUDE search path for Doxygen.
95 _vpp_br = $(shell find "$(BR)" -maxdepth 1 -type d \
96 '(' -name build-vpp_debug-native -o -name build-vpp-native ')' -print \
97 | sed -e 's@^$(WS_ROOT)/*@@' -e 1q)
98 ifneq ($(strip $(_vpp_br)),)
99 SIPHON_INCLUDE_PATH += \
100 $(_vpp_br)/vlib-api \
102 # Also include any plugin directories that exist
103 SIPHON_INCLUDE_PATH += \
104 $(shell find $(WS_ROOT)/$(_vpp_br)/plugins -maxdepth 1 -type d | sed -e 's@^$(WS_ROOT)/*@@')
107 # Discover if we have CPP available
108 _cpp = $(shell which cpp)
109 ifneq ($(strip $(_cpp)),)
110 # Add whatever directories CPP normally includes to the header path
111 SIPHON_INCLUDE_PATH += $(shell set -e; $(_cpp) -v </dev/null 2>&1 | awk 'f&&/^ /{print $$1} /^\#include/{f=1}')
114 # All the siphon types we know about
115 SIPHONS ?= clicmd syscfg
117 SIPHON_FILES = $(addprefix $(SIPHON_INPUT_DIR)/,$(addsuffix .siphon,$(SIPHONS)))
118 SIPHON_DOCS = $(addprefix $(DOCS_GENERATED_DIR)/,$(addsuffix .rst,$(SIPHONS)))
120 BUILT_ON = $(shell date '+%d %B %Y')
121 VPP_VERSION = $(shell ${WS_ROOT}/src/scripts/version)
123 $(DOCS_GENERATED_DIR)/.featurelist.done:
126 find . -name FEATURE.yaml | \
127 ./src/scripts/fts.py \
129 --repolink $(REPOSITORY_URL) > \
130 $(FEATURE_LIST_FILE) ; \
132 @touch $(DOCS_GENERATED_DIR)/.featurelist.done
135 $(DOCS_GENERATED_DIR)/.includes-render.done:
136 @mkdir -p "$(DYNAMIC_RENDER_DIR)"
137 @python3 $(SCRIPTS_DIR)/includes_renderer.py ${WS_ROOT} ${DYNAMIC_RENDER_DIR}
138 @touch $(DOCS_GENERATED_DIR)/.includes-render.done
140 $(DOCS_GENERATED_DIR)/.template-index.done:
141 @sed -ie "s/__VPP_VERSION__/${VPP_VERSION}/g" ${BUILDDIR_SRC}/index.rst
142 @sed -ie "s/__BUILT_ON__/${BUILT_ON}/g" ${BUILDDIR_SRC}/index.rst
144 for f in $$(grep -l -R __REPOSITORY_URL__ ${BUILDDIR_SRC} | grep -e '\.rst$$' -e '\.md$$' ) ;\
146 if [ ! -z $${f} ]; then \
147 echo "TEMPLATING $${f}" ;\
148 sed -ie "s@__REPOSITORY_URL__@${REPOSITORY_URL}@g" $${f} ;\
152 @touch $(DOCS_GENERATED_DIR)/.template-index.done
154 .NOTPARALLEL: $(SIPHON_FILES)
155 $(SIPHON_FILES): $(SCRIPTS_DIR)/siphon-generate \
156 $(addprefix,$(WSROOT),$(SIPHON_INPUT)) \
157 $(wildcard $(SCRIPTS_DIR)/siphon/*.py)
158 @echo "Validating source tree..."
159 @set -e; for input in $(SIPHON_INPUT); do \
160 if [ ! -e "$(WS_ROOT)/$$input" ]; then \
161 echo "ERROR: Input path '$$input' does not exist." >&2; \
165 @rm -rf "$(SIPHON_INPUT_DIR)" "$(DOCS_GENERATED_DIR)"
166 @mkdir -p "$(SIPHON_INPUT_DIR)" "$(DOCS_GENERATED_DIR)"
167 @touch $(SIPHON_INPUT_DIR)/files
168 @echo "Collating source file list for siphoning..."
169 @for input in $(SIPHON_INPUT); do \
171 find "$$input" -type f \
172 \( -name '*.[ch]' -or -name '*.dox' \) -print \
173 | grep -v -E '^src/examples/' \
174 | grep -v -E '^$(SIPHON_EXCLUDE_REGEXP)' \
175 >> $(SIPHON_INPUT_DIR)/files; \
177 @echo "Generating siphons..."
180 $(SCRIPTS_DIR)/siphon-generate \
181 --output="$(SIPHON_INPUT_DIR)" \
182 "@$(SIPHON_INPUT_DIR)/files"
184 # Evaluate this to build a siphon doc output target for each desired
186 # $(eval $(call siphon-process,file_extension,output_type_name))
187 define siphon-process
188 $(DOCS_GENERATED_DIR)/%.$(1): $(SIPHON_INPUT_DIR)/%.siphon \
189 $(SCRIPTS_DIR)/siphon-process \
190 $(wildcard $(SCRIPTS_DIR)/siphon/*.py) \
191 $(wildcard $(SCRIPTS_DIR)/siphon_templates/$(2)/*/*.$(1))
192 @echo "Processing siphon for $(2) from $$(notdir $$<)..."
195 mkdir -p $(DOCS_GENERATED_DIR)/$$(basename $$(notdir $$<)).$(1).dir; \
196 $(SCRIPTS_DIR)/siphon-process \
197 --type=$$(basename $$(notdir $$<)) \
199 --repolink=$(REPOSITORY_URL)/ \
200 --outdir=$(DOCS_GENERATED_DIR)/$$(basename $$(notdir $$<)).$(1).dir \
205 # Process the .siphon source fragments and render them into siphon flavored
206 # markdown documentation
207 .DELETE_ON_ERROR: $(SIPHON_DOCS)
208 $(eval $(call siphon-process,rst,markdown))
210 # This target can be used just to generate the siphoned things
212 $(DOCS_GENERATED_DIR)/.siphon.done: $(SIPHON_DOCS)
213 @cp $(DOCS_GENERATED_DIR)/clicmd.rst $(BUILDDIR_SRC)/cli-reference/index.rst
214 @mkdir -p $(BUILDDIR_SRC)/cli-reference/clis
215 @cp -r $(DOCS_GENERATED_DIR)/clicmd.rst.dir/* $(BUILDDIR_SRC)/cli-reference/clis
216 @touch $(DOCS_GENERATED_DIR)/.siphon.done
218 .PHONY: clean-siphons
221 echo "find $(SIPHON_INPUT) -newer $(DOCS_GENERATED_DIR)/.siphon.done" ; \
223 if [ -f $(DOCS_GENERATED_DIR)/.siphon.done ] && \
224 [ $$(find $(SIPHON_INPUT) -type f -newer $(DOCS_GENERATED_DIR)/.siphon.done \
226 -not -name '*.rst' | wc -l) -gt 0 ]; then \
227 rm -r $(DOCS_GENERATED_DIR); \
228 echo "removing... $(DOCS_GENERATED_DIR)"; \
232 ${BUILDDIR}/.docsrc.sync.ok:
233 @echo "Copying docs files..."
234 @cp -r $(DOCS_DIR) ${BUILDDIR_SRC}
235 @cd ${BUILDDIR_SRC} && find . -type l -exec cp --remove-destination -L ${DOCS_DIR}/{} {} \;
236 @touch $(BUILDDIR)/.docsrc.sync.ok
239 copy-src: ${BUILDDIR}/.docsrc.sync.ok
240 @echo "Syncing changed files..."
241 @cd $(DOCS_DIR) && find . -type f -not -path '*/_scripts/*' -newer $(BUILDDIR)/.docsrc.sync.ok -exec cp {} ${BUILDDIR_SRC}/{} \;
242 @cd ${DOCS_DIR} && find . -type l -not -path '*/_scripts/*' -newer $(BUILDDIR)/.docsrc.sync.ok -exec cp --remove-destination -L ${DOCS_DIR}/{} ${BUILDDIR_SRC}/{} \;
243 @cd ${DOCS_DIR} && find -L . -type f -not -path '*/_scripts/*' -newer $(BUILDDIR)/.docsrc.sync.ok -exec cp --remove-destination -L ${DOCS_DIR}/{} ${BUILDDIR_SRC}/{} \;
244 @touch $(BUILDDIR)/.docsrc.sync.ok
247 generate: copy-src clean-siphons $(DOCS_GENERATED_DIR)/.siphon.done $(DOCS_GENERATED_DIR)/.includes-render.done $(DOCS_GENERATED_DIR)/.template-index.done $(DOCS_GENERATED_DIR)/.featurelist.done
252 @rm -rf $(SCRIPTS_DIR)/siphon/__pycache__