blob: 7893f92cf723dd37927686bff5410128703accf3 [file] [log] [blame]
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +02001# 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
21all: siphon
22
23# These should be passed in by the root Makefile
Nathan Skrzypczak1e167a42022-03-25 12:06:51 +010024WS_ROOT ?= $(CURDIR)/../..
25BR ?= $(WS_ROOT)/build-root
26BUILDDIR ?= ${BR}/docs
27BUILDDIR_SRC ?= ${BUILDDIR}/src
28DOCS_DIR ?= ${WS_ROOT}/docs
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020029
30# Tag used in github repository path.
31# Change this when genearting for a release
32VPP_TAG ?= master
33
34REPOSITORY_URL ?= https://github.com/FDio/vpp/blob/$(VPP_TAG)/
35
36# Doxygen configuration and our utility scripts
37SCRIPTS_DIR ?= $(WS_ROOT)/docs/_scripts
38
39# docs root directory
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020040
Nathan Skrzypczak1e167a42022-03-25 12:06:51 +010041FEATURE_LIST_FILE = ${BUILDDIR_SRC}/aboutvpp/featurelist.md
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020042
43# Siphoned fragements are processed into here
Nathan Skrzypczak1e167a42022-03-25 12:06:51 +010044DOCS_GENERATED_DIR ?= $(BUILDDIR_SRC)/_generated
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +020045
46# Siphoned fragments end up in here
47SIPHON_INPUT_DIR ?= $(DOCS_GENERATED_DIR)/fragments
48
49DYNAMIC_RENDER_DIR ?= ${DOCS_GENERATED_DIR}/includes
50
51# Primary source directories
52SIPHON_SRC ?= $(WS_ROOT)/src
53SIPHON_SRC_DIRECTORIES = \
54 $(shell find $(SIPHON_SRC) -name '*.md' -print | xargs dirname \
55 | sort | uniq) \
56 $(SIPHON_SRC)/vppinfra \
57 $(SIPHON_SRC)/svm \
58 $(SIPHON_SRC)/vlib \
59 $(SIPHON_SRC)/vlibapi \
60 $(SIPHON_SRC)/vlibmemory \
61 $(SIPHON_SRC)/vnet \
62 $(SIPHON_SRC)/vpp \
63 $(SIPHON_SRC)/vpp-api \
64 $(SIPHON_SRC)/examples
65
66# Input directories and files
67SIPHON_INPUT ?= \
68 $(wildcard $(WS_ROOT)/*.md) \
69 $(wildcard $(SCRIPTS_DIR)/*.md) \
70 $(SIPHON_SRC_DIRECTORIES) \
71 $(SIPHON_SRC)/plugins \
72 extras
73
74# Strip leading workspace path from input names
75SIPHON_INPUT := $(subst $(WS_ROOT)/,,$(SIPHON_INPUT))
76
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.
82SIPHON_EXCLUDE ?= \
83 $(SIPHON_SRC)/vpp-api/lua
84
85# Generate a regexp for filenames to exclude
86SIPHON_EXCLUDE_REGEXP = ($(subst .,\.,$(shell echo '$(strip $(SIPHON_EXCLUDE))' | sed -e 's/ /|/g')))
87
88# Include all the normal source directories in the include file path
89SIPHON_INCLUDE_PATH = $(SIPHON_SRC_DIRECTORIES)
90
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)
98ifneq ($(strip $(_vpp_br)),)
99SIPHON_INCLUDE_PATH += \
100 $(_vpp_br)/vlib-api \
101 $(_vpp_br)/vpp
102# Also include any plugin directories that exist
103SIPHON_INCLUDE_PATH += \
104 $(shell find $(WS_ROOT)/$(_vpp_br)/plugins -maxdepth 1 -type d | sed -e 's@^$(WS_ROOT)/*@@')
105endif
106
107# Discover if we have CPP available
108_cpp = $(shell which cpp)
109ifneq ($(strip $(_cpp)),)
110# Add whatever directories CPP normally includes to the header path
111SIPHON_INCLUDE_PATH += $(shell set -e; $(_cpp) -v </dev/null 2>&1 | awk 'f&&/^ /{print $$1} /^\#include/{f=1}')
112endif
113
114# All the siphon types we know about
115SIPHONS ?= clicmd syscfg
116
117SIPHON_FILES = $(addprefix $(SIPHON_INPUT_DIR)/,$(addsuffix .siphon,$(SIPHONS)))
118SIPHON_DOCS = $(addprefix $(DOCS_GENERATED_DIR)/,$(addsuffix .rst,$(SIPHONS)))
119
120BUILT_ON = $(shell date '+%d %B %Y')
121VPP_VERSION = $(shell ${WS_ROOT}/src/scripts/version)
122
Nathan Skrzypczak1e167a42022-03-25 12:06:51 +0100123$(DOCS_GENERATED_DIR)/.featurelist.done:
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +0200124 @( \
125 cd $(WS_ROOT) && \
126 find . -name FEATURE.yaml | \
127 ./src/scripts/fts.py \
128 --markdown \
129 --repolink $(REPOSITORY_URL) > \
130 $(FEATURE_LIST_FILE) ; \
131 )
Nathan Skrzypczak1e167a42022-03-25 12:06:51 +0100132 @touch $(DOCS_GENERATED_DIR)/.featurelist.done
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +0200133
134
Nathan Skrzypczak1e167a42022-03-25 12:06:51 +0100135$(DOCS_GENERATED_DIR)/.includes-render.done:
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +0200136 @mkdir -p "$(DYNAMIC_RENDER_DIR)"
137 @python3 $(SCRIPTS_DIR)/includes_renderer.py ${WS_ROOT} ${DYNAMIC_RENDER_DIR}
Nathan Skrzypczak1e167a42022-03-25 12:06:51 +0100138 @touch $(DOCS_GENERATED_DIR)/.includes-render.done
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +0200139
Nathan Skrzypczak1e167a42022-03-25 12:06:51 +0100140$(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
Nathan Skrzypczakcbb4e462021-10-13 12:40:42 +0200143 @( \
Nathan Skrzypczak1e167a42022-03-25 12:06:51 +0100144 for f in $$(grep -l -R __REPOSITORY_URL__ ${BUILDDIR_SRC} | grep -e '\.rst$$' -e '\.md$$' ) ;\
Nathan Skrzypczakcbb4e462021-10-13 12:40:42 +0200145 do \
146 if [ ! -z $${f} ]; then \
147 echo "TEMPLATING $${f}" ;\
148 sed -ie "s@__REPOSITORY_URL__@${REPOSITORY_URL}@g" $${f} ;\
149 fi ;\
150 done ; \
151 )
Nathan Skrzypczak1e167a42022-03-25 12:06:51 +0100152 @touch $(DOCS_GENERATED_DIR)/.template-index.done
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +0200153
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; \
162 exit 1; \
163 fi; \
164 done
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 \
170 cd "$(WS_ROOT)"; \
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; \
176 done
177 @echo "Generating siphons..."
178 @set -e; \
179 cd "$(WS_ROOT)"; \
180 $(SCRIPTS_DIR)/siphon-generate \
181 --output="$(SIPHON_INPUT_DIR)" \
182 "@$(SIPHON_INPUT_DIR)/files"
183
184# Evaluate this to build a siphon doc output target for each desired
185# output type:
186# $(eval $(call siphon-process,file_extension,output_type_name))
187define 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 $$<)..."
193 @set -e; \
194 cd "$(WS_ROOT)"; \
195 mkdir -p $(DOCS_GENERATED_DIR)/$$(basename $$(notdir $$<)).$(1).dir; \
196 $(SCRIPTS_DIR)/siphon-process \
197 --type=$$(basename $$(notdir $$<)) \
198 --format=$(2) \
199 --repolink=$(REPOSITORY_URL)/ \
200 --outdir=$(DOCS_GENERATED_DIR)/$$(basename $$(notdir $$<)).$(1).dir \
201 --output="$$@" \
202 "$$<"
203endef
204
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))
209
210# This target can be used just to generate the siphoned things
211.PHONY: siphon
Nathan Skrzypczak1e167a42022-03-25 12:06:51 +0100212$(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
217
218.PHONY: clean-siphons
219clean-siphons:
220 @( \
221 echo "find $(SIPHON_INPUT) -newer $(DOCS_GENERATED_DIR)/.siphon.done" ; \
222 cd $(WS_ROOT); \
223 if [ -f $(DOCS_GENERATED_DIR)/.siphon.done ] && \
224 [ $$(find $(SIPHON_INPUT) -type f -newer $(DOCS_GENERATED_DIR)/.siphon.done \
225 -not -name '*.md' \
226 -not -name '*.rst' | wc -l) -gt 0 ]; then \
227 rm -r $(DOCS_GENERATED_DIR); \
228 echo "removing... $(DOCS_GENERATED_DIR)"; \
229 fi; \
230 )
231
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
237
238.PHONY: copy-src
239copy-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
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +0200245
246.PHONY: generate
Nathan Skrzypczak1e167a42022-03-25 12:06:51 +0100247generate: 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
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +0200248
249.PHONY: clean
250clean:
Nathan Skrzypczak1e167a42022-03-25 12:06:51 +0100251 @rm -rf $(BUILDDIR)
Nathan Skrzypczak9ad39c02021-08-19 11:38:06 +0200252 @rm -rf $(SCRIPTS_DIR)/siphon/__pycache__
253