1 # Copyright (c) 2016 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 # We support MacOS for docs generation
28 ifeq ($(shell uname),Darwin)
32 # Work out the OS if we haven't already
33 OS_ID ?= $(shell grep '^ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
35 # Package dependencies
36 DOC_DEB_DEPENDS = doxygen graphviz python-pyparsing python-jinja2
37 DOC_RPM_DEPENDS = doxygen graphviz pyparsing python-jinja2
38 DOC_MAC_BIN_DEPENDS = doxygen dot git
39 DOC_MAC_PY_DEPENDS = pyparsing jinja2
41 # Doxygen configuration and our utility scripts
42 DOXY_DIR ?= $(WS_ROOT)/doxygen
44 # Primary source directories
46 DOXY_SRC_DIRECTORIES = \
47 $(DOXY_SRC)/vppinfra \
51 $(DOXY_SRC)/vlibmemory \
52 $(DOXY_SRC)/vlibsocket \
57 # Input directories and files
59 $(wildcard $(WS_ROOT)/*.md) \
60 $(wildcard $(DOXY_DIR)/*.md) \
61 $(DOXY_SRC_DIRECTORIES) \
64 # Strip leading workspace path from input names
65 DOXY_INPUT := $(subst $(WS_ROOT)/,,$(DOXY_INPUT))
67 # Files to exclude, from pre-Doxygen steps, eg because they're
68 # selectively compiled.
69 # Examples would be to exclude non-DPDK related sources when
70 # there's a DPDK equivalent that conflicts.
71 # These must be left-anchored paths for the regexp below to work.
73 $(DOXY_SRC)/vlib/vlib/buffer.c \
74 $(DOXY_SRC)/vlib/example \
75 $(DOXY_SRC)/vpp-api/lua \
78 # Generate a regexp for filenames to exclude
79 DOXY_EXCLUDE_REGEXP = ($(subst .,\.,$(shell echo '$(strip $(DOXY_EXCLUDE))' | sed -e 's/ /|/g')))
81 # Include all the normal source directories in the include file path
82 DOXY_INCLUDE_PATH = $(DOXY_SRC_DIRECTORIES)
84 # Also include any plugin directories that exist
85 DOXY_INCLUDE_PATH += \
86 $(shell find $(WS_ROOT)/plugins -maxdepth 1 -type d | sed -e 's@^$(WS_ROOT)/*@@')
88 # Find API header directories and include them in the header path.
89 # This is only useful if VPP and plugins are already built; nothing
90 # here depends on those targets. We don't build documentation for these
91 # header files, they're just added to the INCLUDE search path for Doxygen.
92 _vpp_br = $(shell find "$(BR)" -maxdepth 1 -type d \
93 '(' -name build-vpp_debug-native -o -name build-vpp-native ')' -print \
94 | sed -e 's@^$(WS_ROOT)/*@@' -e 1q)
95 ifneq ($(strip $(_vpp_br)),)
96 DOXY_INCLUDE_PATH += \
99 # Also include any plugin directories that exist
100 DOXY_INCLUDE_PATH += \
101 $(shell find $(WS_ROOT)/$(_vpp_br)/plugins -maxdepth 1 -type d | sed -e 's@^$(WS_ROOT)/*@@')
104 # Discover if we have CPP available
105 _cpp = $(shell which cpp)
106 ifneq ($(strip $(_cpp)),)
107 # Add whatever directories CPP normally includes to the header path
108 DOXY_INCLUDE_PATH += $(shell set -e; $(_cpp) -v </dev/null 2>&1 | awk 'f&&/^ /{print $$1} /^\#include/{f=1}')
111 # Target directory for doxygen output
112 DOXY_OUTPUT ?= $(BR)/docs
114 # Siphoned fragments end up in here
115 SIPHON_INPUT ?= $(DOXY_OUTPUT)/siphon_fragments
117 # Siphoned fragements are processed into here
118 SIPHON_OUTPUT ?= $(DOXY_OUTPUT)/siphon_docs
120 # Extra document inputs that are processed in addition to DOXY_INPUT
121 EXTRA_DOXY_INPUT += $(SIPHON_OUTPUT)
123 # All the siphon types we know about
124 SIPHONS ?= clicmd syscfg
126 SIPHON_FILES = $(addprefix $(SIPHON_INPUT)/,$(addsuffix .siphon,$(SIPHONS)))
127 SIPHON_DOCS = $(addprefix $(SIPHON_OUTPUT)/,$(addsuffix .md,$(SIPHONS)))
128 SIPHON_ITEMLIST = $(addprefix $(SIPHON_OUTPUT)/,$(addsuffix .itemlist,$(filter clicmd,$(SIPHONS))))
130 $(BR)/.doxygen-bootstrap.ok: Makefile
131 @echo "Checking whether dependencies for Doxygen are installed..."
132 ifeq ($(OS_ID),ubuntu)
134 for i in $(DOC_DEB_DEPENDS); do \
135 dpkg-query --show $$i >/dev/null 2>&1 || inst="$$inst $$i"; \
137 if [ "$$inst" ]; then \
138 sudo apt-get update; \
139 sudo apt-get $(CONFIRM) $(FORCE) install $$inst; \
141 @if [ ! -s /usr/lib/graphviz/config6a ]; then \
142 echo "Rebuidlding system Graphviz configuration."; \
145 else ifneq ("$(wildcard /etc/redhat-release)","")
146 @sudo yum install $(CONFIRM) $(DOC_RPM_DEPENDS)
147 else ifeq ($(OS_ID),darwin)
149 for bin in $(DOC_MAC_BIN_DEPENDS); do \
150 which -s $${bin} || (\
151 echo "Program '$${bin}' not found, please install it."; \
156 for py in $(DOC_MAC_PY_DEPENDS); do \
157 python -c "import $${py}" >/dev/null 2>&1 || (\
158 echo "Python package '$${py}' not found, please install it."; \
163 $(error "Building documentation currently works only on Ubuntu, CentOS or MacOS systems.")
167 .PHONY: bootstrap-doxygen
168 bootstrap-doxygen: $(BR)/.doxygen-bootstrap.ok
170 .DELETE_ON_ERROR: $(BR)/.doxygen-siphon.dep
171 $(BR)/.doxygen-siphon.dep: Makefile \
172 $(addprefix,$(WSROOT),$(DOXY_INPUT))
173 @echo "Building siphon dependencies..."
174 @rm -f "$@"; for input in $(DOXY_INPUT); do \
175 [ -e "$(WS_ROOT)/$$input" ] && \
176 find "$(WS_ROOT)/$$input" -type f \
177 \( -name '*.[ch]' -or -name '*.dox' \) -print \
178 | grep -v -E '^$(WS_ROOT)/$(DOXY_EXCLUDE_REGEXP)' \
179 | sed -e "s/^/\$$(SIPHON_FILES): /" \
183 # Include the source -> siphon dependencies
184 -include $(BR)/.doxygen-siphon.dep
186 # Generate .siphon files that contain fragments of source file that
187 # relate to the siphons we support.
188 .NOTPARALLEL: $(SIPHON_FILES)
189 $(SIPHON_FILES): $(BR)/.doxygen-bootstrap.ok \
190 $(DOXY_DIR)/siphon-generate \
191 $(addprefix,$(WSROOT),$(DOXY_INPUT)) \
192 $(wildcard $(DOXY_DIR)/siphon/*.py)
193 @echo "Validating source tree..."
194 @set -e; for input in $(DOXY_INPUT); do \
195 if [ ! -e "$(WS_ROOT)/$$input" ]; then \
196 echo "ERROR: Input path '$$input' does not exist." >&2; \
200 @rm -rf "$(SIPHON_INPUT)" "$(SIPHON_OUTPUT)"
201 @mkdir -p "$(SIPHON_INPUT)" "$(SIPHON_OUTPUT)"
202 @touch $(SIPHON_INPUT)/files
203 @echo "Collating source file list for siphoning..."
204 @for input in $(DOXY_INPUT); do \
206 find "$$input" -type f \
207 \( -name '*.[ch]' -or -name '*.dox' \) -print \
208 | grep -v -E '^$(DOXY_EXCLUDE_REGEXP)' \
209 >> $(SIPHON_INPUT)/files; \
211 @echo "Generating siphons..."
214 $(DOXY_DIR)/siphon-generate \
215 --output="$(SIPHON_INPUT)" \
216 "@$(SIPHON_INPUT)/files"
218 # Evaluate this to build a siphon doc output target for each desired
220 # $(eval $(call siphon-process,file_extension,output_type_name))
221 define siphon-process
222 $(SIPHON_OUTPUT)/%.$(1): $(SIPHON_INPUT)/%.siphon \
223 $(DOXY_DIR)/siphon-process \
224 $(wildcard $(DOXY_DIR)/siphon/*.py) \
225 $(wildcard $(DOXY_DIR)/siphon_templates/$(2)/*/*.$(1))
226 @echo "Processing siphon for $(2) from $$(notdir $$<)..."
229 $(DOXY_DIR)/siphon-process \
230 --type=$$(basename $$(notdir $$<)) \
236 # Process the .siphon source fragments and render them into doxygen flavored
237 # markdown documentation
238 .DELETE_ON_ERROR: $(SIPHON_DOCS)
239 $(eval $(call siphon-process,md,markdown))
241 # Process the .siphon source fragments and render them into a list of cli
243 .DELETE_ON_ERROR: $(SIPHON_ITEMLIST)
244 $(eval $(call siphon-process,itemlist,itemlist))
246 # This target can be used just to generate the siphoned things
247 .PHONY: doxygen-siphon
248 doxygen-siphon: $(SIPHON_DOCS) $(SIPHON_ITEMLIST)
250 # Generate the doxygen docs
252 doxygen: $(SIPHON_DOCS)
253 @mkdir -p "$(DOXY_OUTPUT)"
254 @echo "Running Doxygen..."
255 set -e; cd "$(WS_ROOT)"; \
258 INPUT="$(addprefix $(WS_ROOT)/,$(DOXY_INPUT)) $(EXTRA_DOXY_INPUT)" \
259 INCLUDE_PATH="$(DOXY_INCLUDE_PATH)" \
260 EXCLUDE="$(DOXY_EXCLUDE)" \
262 VERSION="`git describe --tags --dirty`" \
263 doxygen $(DOXY_DIR)/doxygen.cfg
267 rm -rf "$(BR)/docs" "$(BR)/.doxygen-siphon.d"