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
26 OS_ID ?= $(shell grep '^ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
28 # Package dependencies
29 DOC_DEB_DEPENDS = doxygen graphviz python-pyparsing python-jinja2
30 DOC_RPM_DEPENDS = doxygen graphviz pyparsing python-jinja2
32 # Doxygen configuration and our utility scripts
33 DOXY_DIR ?= $(WS_ROOT)/doxygen
35 # Primary source directories
36 DOXY_SRC_DIRECTORIES = \
45 # Input directories and files
47 $(wildcard $(WS_ROOT)/*.md) \
48 $(wildcard $(DOXY_DIR)/*.md) \
49 $(DOXY_SRC_DIRECTORIES) \
52 # Strip leading workspace path from input names
53 DOXY_INPUT := $(subst $(WS_ROOT)/,,$(DOXY_INPUT))
55 # Files to exclude, from pre-Doxygen steps, eg because they're
56 # selectively compiled.
57 # Examples would be to exclude non-DPDK related sources when
58 # there's a DPDK equivalent that conflicts.
59 # These must be left-anchored paths for the regexp below to work.
65 # Generate a regexp for filenames to exclude
66 DOXY_EXCLUDE_REGEXP = ($(subst .,\.,$(shell echo '$(strip $(DOXY_EXCLUDE))' | sed -e 's/ /|/g')))
68 # Include all the normal source directories in the include file path
69 DOXY_INCLUDE_PATH = $(DOXY_SRC_DIRECTORIES)
71 # Also include any plugin directories that exist
72 DOXY_INCLUDE_PATH += \
73 $(shell find $(WS_ROOT)/plugins -maxdepth 1 -type d | sed -e 's@^$(WS_ROOT)/*@@')
75 # Find API header directories and include them in the header path.
76 # This is only useful if VPP and plugins are already built; nothing
77 # here depends on those targets. We don't build documentation for these
78 # header files, they're just added to the INCLUDE search path for Doxygen.
79 _vpp_br = $(shell find "$(BR)" -maxdepth 1 -type d \
80 '(' -name build-vpp_debug-native -o -name build-vpp-native ')' -print \
81 | sed -e 's@^$(WS_ROOT)/*@@' -e 1q)
82 ifneq ($(strip $(_vpp_br)),)
83 DOXY_INCLUDE_PATH += \
86 # Also include any plugin directories that exist
87 DOXY_INCLUDE_PATH += \
88 $(shell find $(WS_ROOT)/$(_vpp_br)/plugins -maxdepth 1 -type d | sed -e 's@^$(WS_ROOT)/*@@')
91 # Discover if we have CPP available
92 _cpp = $(shell which cpp)
93 ifneq ($(strip $(_cpp)),)
94 # Add whatever directories CPP normally includes to the header path
95 DOXY_INCLUDE_PATH += $(shell set -e; $(_cpp) -v </dev/null 2>&1 | awk 'f&&/^ /{print $$1} /^\#include/{f=1}')
98 # Target directory for doxygen output
99 DOXY_OUTPUT ?= $(BR)/docs
101 # Siphoned fragments end up in here
102 SIPHON_INPUT ?= $(DOXY_OUTPUT)/siphon_fragments
104 # Siphoned fragements are processed into here
105 SIPHON_OUTPUT ?= $(DOXY_OUTPUT)/siphon_docs
107 # Extra document inputs that are processed in addition to DOXY_INPUT
108 EXTRA_DOXY_INPUT += $(SIPHON_OUTPUT)
110 # All the siphon types we know about
111 SIPHONS ?= clicmd syscfg
113 SIPHON_FILES = $(addprefix $(SIPHON_INPUT)/,$(addsuffix .siphon,$(SIPHONS)))
114 SIPHON_DOCS = $(addprefix $(SIPHON_OUTPUT)/,$(addsuffix .md,$(SIPHONS)))
116 $(BR)/.doxygen-bootstrap.ok: Makefile
117 @echo "Checking whether dependencies for Doxygen are installed..."
118 ifeq ($(OS_ID),ubuntu)
120 for i in $(DOC_DEB_DEPENDS); do \
121 dpkg-query --show $$i >/dev/null 2>&1 || inst="$$inst $$i"; \
123 if [ "$$inst" ]; then \
124 sudo apt-get update; \
125 sudo apt-get $(CONFIRM) $(FORCE) install $$inst; \
127 @if [ ! -s /usr/lib/graphviz/config6a ]; then \
128 echo "Rebuidlding system Graphviz configuration."; \
131 else ifneq ("$(wildcard /etc/redhat-release)","")
132 @sudo yum install $(CONFIRM) $(DOC_RPM_DEPENDS)
134 $(error "This option currently works only on Ubuntu or Centos systems")
138 .PHONY: bootstrap-doxygen
139 bootstrap-doxygen: $(BR)/.doxygen-bootstrap.ok
141 .DELETE_ON_ERROR: $(BR)/.doxygen-siphon.dep
142 $(BR)/.doxygen-siphon.dep: Makefile
143 @echo "Building siphon dependencies..."
144 @set -e; rm -f "$@"; for input in $(DOXY_INPUT); do \
145 find "$(WS_ROOT)/$$input" -type f \
146 \( -name '*.[ch]' -or -name '*.dox' \) -print \
147 | grep -v -E '^$(WS_ROOT)/$(DOXY_EXCLUDE_REGEXP)' \
148 | sed -e "s/^/\$$(SIPHON_FILES): /" \
152 # Include the source -> siphon dependencies
153 -include $(BR)/.doxygen-siphon.dep
155 # Generate .siphon files that contain fragments of source file that
156 # relate to the siphons we support.
157 .NOTPARALLEL: $(SIPHON_FILES)
158 $(SIPHON_FILES): $(BR)/.doxygen-bootstrap.ok \
159 $(DOXY_DIR)/siphon-generate \
160 $(wildcard $(DOXY_DIR)/siphon/*.py)
161 @rm -rf "$(SIPHON_INPUT)" "$(SIPHON_OUTPUT)"
162 @mkdir -p "$(SIPHON_INPUT)" "$(SIPHON_OUTPUT)"
163 @touch $(SIPHON_INPUT)/files
164 @echo "Collating source file list for siphoning..."
165 @for input in $(DOXY_INPUT); do \
167 find "$$input" -type f \
168 \( -name '*.[ch]' -or -name '*.dox' \) -print \
169 | grep -v -E '^$(DOXY_EXCLUDE_REGEXP)' \
170 >> $(SIPHON_INPUT)/files; \
172 @echo "Generating siphons..."
175 $(DOXY_DIR)/siphon-generate \
176 --output="$(SIPHON_INPUT)" \
177 "@$(SIPHON_INPUT)/files"
179 # Process the .siphon source fragments and render them into doxygen flavored
180 # markdown documentation
181 .DELETE_ON_ERROR: $(SIPHON_DOCS)
182 $(SIPHON_OUTPUT)/%.md: $(SIPHON_INPUT)/%.siphon \
183 $(DOXY_DIR)/siphon-process \
184 $(wildcard $(DOXY_DIR)/siphon/*.py) \
185 $(wildcard $(DOXY_DIR)/siphon_templates/*/*.md)
186 @echo "Processing siphon from $(notdir $<)..."
189 $(DOXY_DIR)/siphon-process \
190 --type=$(basename $(notdir $<)) \
194 # This target can be used just to generate the siphoned docs
195 .PHONY: doxygen-siphon
196 doxygen-siphon: $(SIPHON_DOCS)
198 # Generate the doxygen docs
200 doxygen: $(SIPHON_DOCS)
201 @mkdir -p "$(DOXY_OUTPUT)"
202 @echo "Running Doxygen..."
203 set -e; cd "$(WS_ROOT)"; \
206 INPUT="$(addprefix $(WS_ROOT)/,$(DOXY_INPUT)) $(EXTRA_DOXY_INPUT)" \
207 INCLUDE_PATH="$(DOXY_INCLUDE_PATH)" \
208 EXCLUDE="$(DOXY_EXCLUDE)" \
210 VERSION="`git describe --tags --dirty`" \
211 doxygen $(DOXY_DIR)/doxygen.cfg
215 rm -rf "$(BR)/docs" "$(BR)/.doxygen-siphon.d"