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
27 # Tag used in github repository path.
28 # Change this when genearting for a release
31 REPOSITORY_URL ?= https://github.com/FDio/vpp/blob/$(VPP_TAG)/
33 # Doxygen configuration and our utility scripts
34 SCRIPTS_DIR ?= $(WS_ROOT)/docs/_scripts
37 DOCS_DIR ?= ${BR}/docs/src
39 FEATURE_LIST_FILE = ${DOCS_DIR}/aboutvpp/featurelist.md
41 # Siphoned fragements are processed into here
42 DOCS_GENERATED_DIR ?= $(DOCS_DIR)/_generated
44 # Siphoned fragments end up in here
45 SIPHON_INPUT_DIR ?= $(DOCS_GENERATED_DIR)/fragments
47 DYNAMIC_RENDER_DIR ?= ${DOCS_GENERATED_DIR}/includes
49 # Primary source directories
50 SIPHON_SRC ?= $(WS_ROOT)/src
51 SIPHON_SRC_DIRECTORIES = \
52 $(shell find $(SIPHON_SRC) -name '*.md' -print | xargs dirname \
54 $(SIPHON_SRC)/vppinfra \
57 $(SIPHON_SRC)/vlibapi \
58 $(SIPHON_SRC)/vlibmemory \
61 $(SIPHON_SRC)/vpp-api \
62 $(SIPHON_SRC)/examples
64 # Input directories and files
66 $(wildcard $(WS_ROOT)/*.md) \
67 $(wildcard $(SCRIPTS_DIR)/*.md) \
68 $(SIPHON_SRC_DIRECTORIES) \
69 $(SIPHON_SRC)/plugins \
72 # Strip leading workspace path from input names
73 SIPHON_INPUT := $(subst $(WS_ROOT)/,,$(SIPHON_INPUT))
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.
81 $(SIPHON_SRC)/vpp-api/lua
83 # Generate a regexp for filenames to exclude
84 SIPHON_EXCLUDE_REGEXP = ($(subst .,\.,$(shell echo '$(strip $(SIPHON_EXCLUDE))' | sed -e 's/ /|/g')))
86 # Include all the normal source directories in the include file path
87 SIPHON_INCLUDE_PATH = $(SIPHON_SRC_DIRECTORIES)
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 += \
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)/*@@')
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}')
112 # All the siphon types we know about
113 SIPHONS ?= clicmd syscfg
115 SIPHON_FILES = $(addprefix $(SIPHON_INPUT_DIR)/,$(addsuffix .siphon,$(SIPHONS)))
116 SIPHON_DOCS = $(addprefix $(DOCS_GENERATED_DIR)/,$(addsuffix .rst,$(SIPHONS)))
118 BUILT_ON = $(shell date '+%d %B %Y')
119 VPP_VERSION = $(shell ${WS_ROOT}/src/scripts/version)
125 find . -name FEATURE.yaml | \
126 ./src/scripts/fts.py \
128 --repolink $(REPOSITORY_URL) > \
129 $(FEATURE_LIST_FILE) ; \
133 .PHONY: includes-render
135 @mkdir -p "$(DYNAMIC_RENDER_DIR)"
136 @python3 $(SCRIPTS_DIR)/includes_renderer.py ${WS_ROOT} ${DYNAMIC_RENDER_DIR}
138 .PHONY: 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
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; \
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 \
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; \
166 @echo "Generating siphons..."
169 $(SCRIPTS_DIR)/siphon-generate \
170 --output="$(SIPHON_INPUT_DIR)" \
171 "@$(SIPHON_INPUT_DIR)/files"
173 # Evaluate this to build a siphon doc output target for each desired
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 $$<)..."
184 mkdir -p $(DOCS_GENERATED_DIR)/$$(basename $$(notdir $$<)).$(1).dir; \
185 $(SCRIPTS_DIR)/siphon-process \
186 --type=$$(basename $$(notdir $$<)) \
188 --repolink=$(REPOSITORY_URL)/ \
189 --outdir=$(DOCS_GENERATED_DIR)/$$(basename $$(notdir $$<)).$(1).dir \
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))
199 # This target can be used just to generate the siphoned things
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
206 generate: siphon includes-render template-index featurelist
210 @rm -rf $(BR)/.siphon.dep
211 @rm -rf $(SCRIPTS_DIR)/siphon/__pycache__