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_MAC_BIN_DEPENDS = doxygen dot git
37 DOC_MAC_PY_DEPENDS = pyparsing jinja2
39 # Doxygen configuration and our utility scripts
40 DOXY_DIR ?= $(WS_ROOT)/doxygen
42 # Primary source directories
44 DOXY_SRC_DIRECTORIES = \
45 $(DOXY_SRC)/vppinfra \
49 $(DOXY_SRC)/vlibmemory \
50 $(DOXY_SRC)/vlibsocket \
55 # Input directories and files
57 $(wildcard $(WS_ROOT)/*.md) \
58 $(wildcard $(DOXY_DIR)/*.md) \
59 $(DOXY_SRC_DIRECTORIES) \
63 # Strip leading workspace path from input names
64 DOXY_INPUT := $(subst $(WS_ROOT)/,,$(DOXY_INPUT))
66 # Files to exclude, from pre-Doxygen steps, eg because they're
67 # selectively compiled.
68 # Examples would be to exclude non-DPDK related sources when
69 # there's a DPDK equivalent that conflicts.
70 # These must be left-anchored paths for the regexp below to work.
72 $(DOXY_SRC)/vlib/vlib/buffer.c \
73 $(DOXY_SRC)/vlib/example \
74 $(DOXY_SRC)/vpp-api/lua \
77 # Generate a regexp for filenames to exclude
78 DOXY_EXCLUDE_REGEXP = ($(subst .,\.,$(shell echo '$(strip $(DOXY_EXCLUDE))' | sed -e 's/ /|/g')))
80 # Include all the normal source directories in the include file path
81 DOXY_INCLUDE_PATH = $(DOXY_SRC_DIRECTORIES)
83 # Also include any plugin directories that exist
84 DOXY_INCLUDE_PATH += \
85 $(shell find $(WS_ROOT)/plugins -maxdepth 1 -type d | sed -e 's@^$(WS_ROOT)/*@@')
87 # Find API header directories and include them in the header path.
88 # This is only useful if VPP and plugins are already built; nothing
89 # here depends on those targets. We don't build documentation for these
90 # header files, they're just added to the INCLUDE search path for Doxygen.
91 _vpp_br = $(shell find "$(BR)" -maxdepth 1 -type d \
92 '(' -name build-vpp_debug-native -o -name build-vpp-native ')' -print \
93 | sed -e 's@^$(WS_ROOT)/*@@' -e 1q)
94 ifneq ($(strip $(_vpp_br)),)
95 DOXY_INCLUDE_PATH += \
98 # Also include any plugin directories that exist
99 DOXY_INCLUDE_PATH += \
100 $(shell find $(WS_ROOT)/$(_vpp_br)/plugins -maxdepth 1 -type d | sed -e 's@^$(WS_ROOT)/*@@')
103 # Discover if we have CPP available
104 _cpp = $(shell which cpp)
105 ifneq ($(strip $(_cpp)),)
106 # Add whatever directories CPP normally includes to the header path
107 DOXY_INCLUDE_PATH += $(shell set -e; $(_cpp) -v </dev/null 2>&1 | awk 'f&&/^ /{print $$1} /^\#include/{f=1}')
110 # Target directory for doxygen output
111 DOXY_OUTPUT ?= $(BR)/docs
113 # Siphoned fragments end up in here
114 SIPHON_INPUT ?= $(DOXY_OUTPUT)/siphon_fragments
116 # Siphoned fragements are processed into here
117 SIPHON_OUTPUT ?= $(DOXY_OUTPUT)/siphon_docs
119 # Extra document inputs that are processed in addition to DOXY_INPUT
120 EXTRA_DOXY_INPUT += $(SIPHON_OUTPUT)
122 # All the siphon types we know about
123 SIPHONS ?= clicmd syscfg
125 SIPHON_FILES = $(addprefix $(SIPHON_INPUT)/,$(addsuffix .siphon,$(SIPHONS)))
126 SIPHON_DOCS = $(addprefix $(SIPHON_OUTPUT)/,$(addsuffix .md,$(SIPHONS)))
127 SIPHON_ITEMLIST = $(addprefix $(SIPHON_OUTPUT)/,$(addsuffix .itemlist,$(filter clicmd,$(SIPHONS))))
129 $(BR)/.doxygen-bootstrap.ok: Makefile
130 ifeq ($(OS_ID),ubuntu)
131 @if [ ! -s /usr/lib/graphviz/config6a ]; then \
132 echo "Rebuilding system Graphviz configuration."; \
135 else ifeq ($(OS_ID),darwin)
137 for bin in $(DOC_MAC_BIN_DEPENDS); do \
138 which -s $${bin} || (\
139 echo "Program '$${bin}' not found, please install it."; \
144 for py in $(DOC_MAC_PY_DEPENDS); do \
145 python -c "import $${py}" >/dev/null 2>&1 || (\
146 echo "Python package '$${py}' not found, please install it."; \
151 $(error "Building documentation currently works only on Ubuntu, CentOS or MacOS systems.")
155 .PHONY: bootstrap-doxygen
156 bootstrap-doxygen: $(BR)/.doxygen-bootstrap.ok
158 .DELETE_ON_ERROR: $(BR)/.doxygen-siphon.dep
159 $(BR)/.doxygen-siphon.dep: Makefile \
160 $(addprefix,$(WSROOT),$(DOXY_INPUT))
161 @echo "Building siphon dependencies..."
162 @rm -f "$@"; for input in $(DOXY_INPUT); do \
163 [ -e "$(WS_ROOT)/$$input" ] && \
164 find "$(WS_ROOT)/$$input" -type f \
165 \( -name '*.[ch]' -or -name '*.dox' \) -print \
166 | grep -v -E '^$(WS_ROOT)/$(DOXY_EXCLUDE_REGEXP)' \
167 | sed -e "s/^/\$$(SIPHON_FILES): /" \
171 # Include the source -> siphon dependencies
172 -include $(BR)/.doxygen-siphon.dep
174 # Generate .siphon files that contain fragments of source file that
175 # relate to the siphons we support.
176 .NOTPARALLEL: $(SIPHON_FILES)
177 $(SIPHON_FILES):$(DOXY_DIR)/siphon-generate \
178 $(addprefix,$(WSROOT),$(DOXY_INPUT)) \
179 $(wildcard $(DOXY_DIR)/siphon/*.py)
180 @echo "Validating source tree..."
181 @set -e; for input in $(DOXY_INPUT); do \
182 if [ ! -e "$(WS_ROOT)/$$input" ]; then \
183 echo "ERROR: Input path '$$input' does not exist." >&2; \
187 @rm -rf "$(SIPHON_INPUT)" "$(SIPHON_OUTPUT)"
188 @mkdir -p "$(SIPHON_INPUT)" "$(SIPHON_OUTPUT)"
189 @touch $(SIPHON_INPUT)/files
190 @echo "Collating source file list for siphoning..."
191 @for input in $(DOXY_INPUT); do \
193 find "$$input" -type f \
194 \( -name '*.[ch]' -or -name '*.dox' \) -print \
195 | grep -v -E '^$(DOXY_EXCLUDE_REGEXP)' \
196 >> $(SIPHON_INPUT)/files; \
198 @echo "Generating siphons..."
201 $(DOXY_DIR)/siphon-generate \
202 --output="$(SIPHON_INPUT)" \
203 "@$(SIPHON_INPUT)/files"
205 # Evaluate this to build a siphon doc output target for each desired
207 # $(eval $(call siphon-process,file_extension,output_type_name))
208 define siphon-process
209 $(SIPHON_OUTPUT)/%.$(1): $(SIPHON_INPUT)/%.siphon \
210 $(DOXY_DIR)/siphon-process \
211 $(wildcard $(DOXY_DIR)/siphon/*.py) \
212 $(wildcard $(DOXY_DIR)/siphon_templates/$(2)/*/*.$(1))
213 @echo "Processing siphon for $(2) from $$(notdir $$<)..."
216 $(DOXY_DIR)/siphon-process \
217 --type=$$(basename $$(notdir $$<)) \
223 # Process the .siphon source fragments and render them into doxygen flavored
224 # markdown documentation
225 .DELETE_ON_ERROR: $(SIPHON_DOCS)
226 $(eval $(call siphon-process,md,markdown))
228 # Process the .siphon source fragments and render them into a list of cli
230 .DELETE_ON_ERROR: $(SIPHON_ITEMLIST)
231 $(eval $(call siphon-process,itemlist,itemlist))
233 # This target can be used just to generate the siphoned things
234 .PHONY: doxygen-siphon
235 doxygen-siphon: $(SIPHON_DOCS)
237 # This target is used generate list of cli commands for use with
238 # the bash completion element for vppctl
239 .PHONY: doxygen-siphon-list
240 doxygen-siphon-list: $(SIPHON_ITEMLIST)
242 # Generate the doxygen docs
244 doxygen: $(SIPHON_DOCS)
245 @mkdir -p "$(DOXY_OUTPUT)"
246 @echo "Running Doxygen..."
247 set -e; cd "$(WS_ROOT)"; \
250 INPUT="$(addprefix $(WS_ROOT)/,$(DOXY_INPUT)) $(EXTRA_DOXY_INPUT)" \
251 INCLUDE_PATH="$(DOXY_INCLUDE_PATH)" \
252 EXCLUDE="$(DOXY_EXCLUDE)" \
254 VERSION="`git describe --tags --dirty`" \
255 doxygen $(DOXY_DIR)/doxygen.cfg
259 rm -rf "$(BR)/docs" "$(BR)/.doxygen-siphon.d"