hs-test: fix LDPreloadIperfVppTest
[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 BUILDDIR          ?= ${BR}/docs
27 BUILDDIR_SRC      ?= ${BUILDDIR}/src
28 DOCS_DIR          ?= ${WS_ROOT}/docs
29
30 # Tag used in github repository path.
31 # Change this when genearting for a release
32 VPP_TAG ?= master
33
34 REPOSITORY_URL ?= https://github.com/FDio/vpp/blob/$(VPP_TAG)/
35
36 # Doxygen configuration and our utility scripts
37 SCRIPTS_DIR ?= $(WS_ROOT)/docs/_scripts
38
39 # docs root directory
40
41 FEATURE_LIST_FILE = ${BUILDDIR_SRC}/aboutvpp/featurelist.md
42
43 # Siphoned fragements are processed into here
44 DOCS_GENERATED_DIR ?= $(BUILDDIR_SRC)/_generated
45
46 # Siphoned fragments end up in here
47 SIPHON_INPUT_DIR ?= $(DOCS_GENERATED_DIR)/fragments
48
49 DYNAMIC_RENDER_DIR ?= ${DOCS_GENERATED_DIR}/includes
50
51 # Primary source directories
52 SIPHON_SRC ?= $(WS_ROOT)/src
53 SIPHON_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
67 SIPHON_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
75 SIPHON_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.
82 SIPHON_EXCLUDE ?= \
83         $(SIPHON_SRC)/vpp-api/lua
84
85 # Generate a regexp for filenames to exclude
86 SIPHON_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
89 SIPHON_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)
98 ifneq ($(strip $(_vpp_br)),)
99 SIPHON_INCLUDE_PATH += \
100         $(_vpp_br)/vlib-api \
101         $(_vpp_br)/vpp
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)/*@@')
105 endif
106
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}')
112 endif
113
114 # All the siphon types we know about
115 SIPHONS ?= clicmd syscfg
116
117 SIPHON_FILES = $(addprefix $(SIPHON_INPUT_DIR)/,$(addsuffix .siphon,$(SIPHONS)))
118 SIPHON_DOCS = $(addprefix $(DOCS_GENERATED_DIR)/,$(addsuffix .rst,$(SIPHONS)))
119
120 BUILT_ON = $(shell date '+%d %B %Y')
121 VPP_VERSION = $(shell ${WS_ROOT}/src/scripts/version)
122
123 $(DOCS_GENERATED_DIR)/.featurelist.done:
124         @( \
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         )
132         @touch $(DOCS_GENERATED_DIR)/.featurelist.done
133
134
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
139
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
143         @( \
144           for f in $$(grep -l -R __REPOSITORY_URL__ ${BUILDDIR_SRC} | grep -e '\.rst$$' -e '\.md$$' ) ;\
145           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         )
152         @touch $(DOCS_GENERATED_DIR)/.template-index.done
153
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))
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 $$<)..."
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                 "$$<"
203 endef
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
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
217
218 .PHONY: clean-siphons
219 clean-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
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
245
246 .PHONY: generate
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
248
249 .PHONY: clean
250 clean:
251         @rm -rf $(BUILDDIR)
252         @rm -rf $(SCRIPTS_DIR)/siphon/__pycache__
253