VPP-540 : pbb tag rewrite details
[vpp.git] / doxygen / Makefile
1 # Copyright (c) 2016 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: doxygen
22
23 # These should be passed in by the root Makefile
24 WS_ROOT ?= $(CURDIR)/..
25 BR ?= $(WS_ROOT)/build-root
26
27 # We support MacOS for docs generation
28 ifeq ($(shell uname),Darwin)
29 OS_ID = darwin
30 endif
31
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')
34
35 # Package dependencies
36 DOC_DEB_DEPENDS = doxygen graphviz python-pyparsing python-jinja2
37 DOC_RPM_DEPENDS = doxygen graphviz pyparsing python-jinja2
38 DOC_SUSE_RPM_DEPENDS = doxygen graphviz python-pyparsing python-Jinja2
39 DOC_MAC_BIN_DEPENDS = doxygen dot git
40 DOC_MAC_PY_DEPENDS = pyparsing jinja2
41
42 # Doxygen configuration and our utility scripts
43 DOXY_DIR ?= $(WS_ROOT)/doxygen
44
45 # Primary source directories
46 DOXY_SRC ?= src
47 DOXY_SRC_DIRECTORIES = \
48         $(DOXY_SRC)/vppinfra \
49         $(DOXY_SRC)/svm \
50         $(DOXY_SRC)/vlib \
51         $(DOXY_SRC)/vlibapi \
52         $(DOXY_SRC)/vlibmemory \
53         $(DOXY_SRC)/vlibsocket \
54         $(DOXY_SRC)/vnet \
55         $(DOXY_SRC)/vpp \
56         $(DOXY_SRC)/vpp-api
57
58 # Input directories and files
59 DOXY_INPUT ?= \
60         $(wildcard $(WS_ROOT)/*.md) \
61         $(wildcard $(DOXY_DIR)/*.md) \
62         $(DOXY_SRC_DIRECTORIES) \
63         $(DOXY_SRC)/plugins
64
65 # Strip leading workspace path from input names
66 DOXY_INPUT := $(subst $(WS_ROOT)/,,$(DOXY_INPUT))
67
68 # Files to exclude, from pre-Doxygen steps, eg because they're
69 # selectively compiled.
70 # Examples would be to exclude non-DPDK related sources when
71 # there's a DPDK equivalent that conflicts.
72 # These must be left-anchored paths for the regexp below to work.
73 DOXY_EXCLUDE ?= \
74         $(DOXY_SRC)/vlib/vlib/buffer.c \
75         $(DOXY_SRC)/vlib/example \
76         $(DOXY_SRC)/vpp-api/lua \
77         plugins/sample-plugin
78
79 # Generate a regexp for filenames to exclude
80 DOXY_EXCLUDE_REGEXP = ($(subst .,\.,$(shell echo '$(strip $(DOXY_EXCLUDE))' | sed -e 's/ /|/g')))
81
82 # Include all the normal source directories in the include file path
83 DOXY_INCLUDE_PATH = $(DOXY_SRC_DIRECTORIES)
84
85 # Also include any plugin directories that exist
86 DOXY_INCLUDE_PATH += \
87         $(shell find $(WS_ROOT)/plugins -maxdepth 1 -type d | sed -e 's@^$(WS_ROOT)/*@@')
88
89 # Find API header directories and include them in the header path.
90 # This is only useful if VPP and plugins are already built; nothing
91 # here depends on those targets. We don't build documentation for these
92 # header files, they're just added to the INCLUDE search path for Doxygen.
93 _vpp_br = $(shell find "$(BR)" -maxdepth 1 -type d \
94         '(' -name build-vpp_debug-native -o -name build-vpp-native ')' -print \
95         | sed -e 's@^$(WS_ROOT)/*@@' -e 1q)
96 ifneq ($(strip $(_vpp_br)),)
97 DOXY_INCLUDE_PATH += \
98         $(_vpp_br)/vlib-api \
99         $(_vpp_br)/vpp
100 # Also include any plugin directories that exist
101 DOXY_INCLUDE_PATH += \
102         $(shell find $(WS_ROOT)/$(_vpp_br)/plugins -maxdepth 1 -type d | sed -e 's@^$(WS_ROOT)/*@@')
103 endif
104
105 # Discover if we have CPP available
106 _cpp = $(shell which cpp)
107 ifneq ($(strip $(_cpp)),)
108 # Add whatever directories CPP normally includes to the header path
109 DOXY_INCLUDE_PATH += $(shell set -e; $(_cpp) -v </dev/null 2>&1 | awk 'f&&/^ /{print $$1} /^\#include/{f=1}')
110 endif
111
112 # Target directory for doxygen output
113 DOXY_OUTPUT ?= $(BR)/docs
114
115 # Siphoned fragments end up in here
116 SIPHON_INPUT ?= $(DOXY_OUTPUT)/siphon_fragments
117
118 # Siphoned fragements are processed into here
119 SIPHON_OUTPUT ?= $(DOXY_OUTPUT)/siphon_docs
120
121 # Extra document inputs that are processed in addition to DOXY_INPUT
122 EXTRA_DOXY_INPUT += $(SIPHON_OUTPUT)
123
124 # All the siphon types we know about
125 SIPHONS ?= clicmd syscfg
126
127 SIPHON_FILES = $(addprefix $(SIPHON_INPUT)/,$(addsuffix .siphon,$(SIPHONS)))
128 SIPHON_DOCS = $(addprefix $(SIPHON_OUTPUT)/,$(addsuffix .md,$(SIPHONS)))
129 SIPHON_ITEMLIST = $(addprefix $(SIPHON_OUTPUT)/,$(addsuffix .itemlist,$(filter clicmd,$(SIPHONS))))
130
131 $(BR)/.doxygen-bootstrap.ok: Makefile
132         @echo "Checking whether dependencies for Doxygen are installed..."
133 ifeq ($(OS_ID),ubuntu)
134         @set -e; inst=; \
135                 for i in $(DOC_DEB_DEPENDS); do \
136                         dpkg-query --show $$i >/dev/null 2>&1 || inst="$$inst $$i"; \
137                 done; \
138                 if [ "$$inst" ]; then \
139                         sudo apt-get update; \
140                         sudo apt-get $(CONFIRM) $(FORCE) install $$inst; \
141                 fi
142         @if [ ! -s /usr/lib/graphviz/config6a ]; then \
143                 echo "Rebuidlding system Graphviz configuration."; \
144                 sudo dot -c; \
145         fi
146 else ifneq ("$(wildcard /etc/redhat-release)","")
147         @sudo yum install $(CONFIRM) $(DOC_RPM_DEPENDS)
148 else ifeq ($(OS_ID),darwin)
149         @set -e; \
150         for bin in $(DOC_MAC_BIN_DEPENDS); do \
151                 which -s $${bin} || (\
152                         echo "Program '$${bin}' not found, please install it."; \
153                         false; \
154                 ); \
155         done
156         @set -e; \
157         for py in $(DOC_MAC_PY_DEPENDS); do \
158                 python -c "import $${py}" >/dev/null 2>&1 || (\
159                         echo "Python package '$${py}' not found, please install it."; \
160                         false; \
161                 ); \
162         done
163 else ifeq ($(OS_ID),opensuse)
164         @sudo zypper install $(CONFIRM) $(DOC_SUSE_RPM_DEPENDS)
165 else
166         $(error "Building documentation currently works only on Ubuntu, CentOS, MacOS and OpenSUSE systems.")
167 endif
168         @touch $@
169
170 .PHONY: bootstrap-doxygen
171 bootstrap-doxygen: $(BR)/.doxygen-bootstrap.ok
172
173 .DELETE_ON_ERROR: $(BR)/.doxygen-siphon.dep
174 $(BR)/.doxygen-siphon.dep: Makefile \
175                 $(addprefix,$(WSROOT),$(DOXY_INPUT))
176         @echo "Building siphon dependencies..."
177         @rm -f "$@"; for input in $(DOXY_INPUT); do \
178                 [ -e "$(WS_ROOT)/$$input" ] && \
179                 find "$(WS_ROOT)/$$input" -type f \
180                         \( -name '*.[ch]' -or -name '*.dox' \) -print \
181                         | grep -v -E '^$(WS_ROOT)/$(DOXY_EXCLUDE_REGEXP)' \
182                         | sed -e "s/^/\$$(SIPHON_FILES): /" \
183                         >> $@; \
184         done
185
186 # Include the source -> siphon dependencies
187 -include $(BR)/.doxygen-siphon.dep
188
189 # Generate .siphon files that contain fragments of source file that
190 # relate to the siphons we support.
191 .NOTPARALLEL: $(SIPHON_FILES)
192 $(SIPHON_FILES): $(BR)/.doxygen-bootstrap.ok \
193                 $(DOXY_DIR)/siphon-generate \
194                 $(addprefix,$(WSROOT),$(DOXY_INPUT)) \
195                 $(wildcard $(DOXY_DIR)/siphon/*.py)
196         @echo "Validating source tree..."
197         @set -e; for input in $(DOXY_INPUT); do \
198                 if [ ! -e "$(WS_ROOT)/$$input" ]; then \
199                         echo "ERROR: Input path '$$input' does not exist." >&2; \
200                         exit 1; \
201                 fi; \
202         done
203         @rm -rf "$(SIPHON_INPUT)" "$(SIPHON_OUTPUT)"
204         @mkdir -p "$(SIPHON_INPUT)" "$(SIPHON_OUTPUT)"
205         @touch $(SIPHON_INPUT)/files
206         @echo "Collating source file list for siphoning..."
207         @for input in $(DOXY_INPUT); do \
208                 cd "$(WS_ROOT)"; \
209                 find "$$input" -type f \
210                         \( -name '*.[ch]' -or -name '*.dox' \) -print \
211                         | grep -v -E '^$(DOXY_EXCLUDE_REGEXP)' \
212                         >> $(SIPHON_INPUT)/files; \
213         done
214         @echo "Generating siphons..."
215         @set -e; \
216         cd "$(WS_ROOT)"; \
217         $(DOXY_DIR)/siphon-generate \
218                 --output="$(SIPHON_INPUT)" \
219                 "@$(SIPHON_INPUT)/files"
220
221 # Evaluate this to build a siphon doc output target for each desired
222 # output type:
223 # $(eval $(call siphon-process,file_extension,output_type_name))
224 define siphon-process
225 $(SIPHON_OUTPUT)/%.$(1): $(SIPHON_INPUT)/%.siphon \
226                 $(DOXY_DIR)/siphon-process \
227                 $(wildcard $(DOXY_DIR)/siphon/*.py) \
228                 $(wildcard $(DOXY_DIR)/siphon_templates/$(2)/*/*.$(1))
229         @echo "Processing siphon for $(2) from $$(notdir $$<)..."
230         @set -e; \
231         cd "$(WS_ROOT)"; \
232         $(DOXY_DIR)/siphon-process \
233                 --type=$$(basename $$(notdir $$<)) \
234                 --format=$(2) \
235                 --output="$$@" \
236                 "$$<"
237 endef
238
239 # Process the .siphon source fragments and render them into doxygen flavored
240 # markdown documentation
241 .DELETE_ON_ERROR: $(SIPHON_DOCS)
242 $(eval $(call siphon-process,md,markdown))
243
244 # Process the .siphon source fragments and render them into a list of cli
245 # commands.
246 .DELETE_ON_ERROR: $(SIPHON_ITEMLIST)
247 $(eval $(call siphon-process,itemlist,itemlist))
248
249 # This target can be used just to generate the siphoned things
250 .PHONY: doxygen-siphon
251 doxygen-siphon: $(SIPHON_DOCS) $(SIPHON_ITEMLIST)
252
253 # Generate the doxygen docs
254 .PHONY: doxygen
255 doxygen: $(SIPHON_DOCS)
256         @mkdir -p "$(DOXY_OUTPUT)"
257         @echo "Running Doxygen..."
258         set -e; cd "$(WS_ROOT)"; \
259             ROOT="$(WS_ROOT)" \
260             BUILD_ROOT="$(BR)" \
261             INPUT="$(addprefix $(WS_ROOT)/,$(DOXY_INPUT)) $(EXTRA_DOXY_INPUT)" \
262             INCLUDE_PATH="$(DOXY_INCLUDE_PATH)" \
263             EXCLUDE="$(DOXY_EXCLUDE)" \
264             HTML=YES \
265             VERSION="`git describe --tags --dirty`" \
266             doxygen $(DOXY_DIR)/doxygen.cfg
267
268 .PHONY: wipe-doxygen
269 wipe-doxygen:
270         rm -rf "$(BR)/docs" "$(BR)/.doxygen-siphon.d"
271
272 .PHONY: clean
273 clean: wipe-doxygen