vppctl: bash completion for vppctl commands
[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_MAC_BIN_DEPENDS = doxygen dot git
37 DOC_MAC_PY_DEPENDS = pyparsing jinja2
38
39 # Doxygen configuration and our utility scripts
40 DOXY_DIR ?= $(WS_ROOT)/doxygen
41
42 # Primary source directories
43 DOXY_SRC ?= src
44 DOXY_SRC_DIRECTORIES = \
45         $(DOXY_SRC)/vppinfra \
46         $(DOXY_SRC)/svm \
47         $(DOXY_SRC)/vlib \
48         $(DOXY_SRC)/vlibapi \
49         $(DOXY_SRC)/vlibmemory \
50         $(DOXY_SRC)/vlibsocket \
51         $(DOXY_SRC)/vnet \
52         $(DOXY_SRC)/vpp \
53         $(DOXY_SRC)/vpp-api
54
55 # Input directories and files
56 DOXY_INPUT ?= \
57         $(wildcard $(WS_ROOT)/*.md) \
58         $(wildcard $(DOXY_DIR)/*.md) \
59         $(DOXY_SRC_DIRECTORIES) \
60         $(DOXY_SRC)/plugins \
61         plugins
62
63 # Strip leading workspace path from input names
64 DOXY_INPUT := $(subst $(WS_ROOT)/,,$(DOXY_INPUT))
65
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.
71 DOXY_EXCLUDE ?= \
72         $(DOXY_SRC)/vlib/vlib/buffer.c \
73         $(DOXY_SRC)/vlib/example \
74         $(DOXY_SRC)/vpp-api/lua \
75         plugins/sample-plugin
76
77 # Generate a regexp for filenames to exclude
78 DOXY_EXCLUDE_REGEXP = ($(subst .,\.,$(shell echo '$(strip $(DOXY_EXCLUDE))' | sed -e 's/ /|/g')))
79
80 # Include all the normal source directories in the include file path
81 DOXY_INCLUDE_PATH = $(DOXY_SRC_DIRECTORIES)
82
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)/*@@')
86
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 += \
96         $(_vpp_br)/vlib-api \
97         $(_vpp_br)/vpp
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)/*@@')
101 endif
102
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}')
108 endif
109
110 # Target directory for doxygen output
111 DOXY_OUTPUT ?= $(BR)/docs
112
113 # Siphoned fragments end up in here
114 SIPHON_INPUT ?= $(DOXY_OUTPUT)/siphon_fragments
115
116 # Siphoned fragements are processed into here
117 SIPHON_OUTPUT ?= $(DOXY_OUTPUT)/siphon_docs
118
119 # Extra document inputs that are processed in addition to DOXY_INPUT
120 EXTRA_DOXY_INPUT += $(SIPHON_OUTPUT)
121
122 # All the siphon types we know about
123 SIPHONS ?= clicmd syscfg
124
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))))
128
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."; \
133                 sudo dot -c; \
134         fi
135 else ifeq ($(OS_ID),darwin)
136         @set -e; \
137         for bin in $(DOC_MAC_BIN_DEPENDS); do \
138                 which -s $${bin} || (\
139                         echo "Program '$${bin}' not found, please install it."; \
140                         false; \
141                 ); \
142         done
143         @set -e; \
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."; \
147                         false; \
148                 ); \
149         done
150 else
151         $(error "Building documentation currently works only on Ubuntu, CentOS or MacOS systems.")
152 endif
153         @touch $@
154
155 .PHONY: bootstrap-doxygen
156 bootstrap-doxygen: $(BR)/.doxygen-bootstrap.ok
157
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): /" \
168                         >> $@; \
169         done
170
171 # Include the source -> siphon dependencies
172 -include $(BR)/.doxygen-siphon.dep
173
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; \
184                         exit 1; \
185                 fi; \
186         done
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 \
192                 cd "$(WS_ROOT)"; \
193                 find "$$input" -type f \
194                         \( -name '*.[ch]' -or -name '*.dox' \) -print \
195                         | grep -v -E '^$(DOXY_EXCLUDE_REGEXP)' \
196                         >> $(SIPHON_INPUT)/files; \
197         done
198         @echo "Generating siphons..."
199         @set -e; \
200         cd "$(WS_ROOT)"; \
201         $(DOXY_DIR)/siphon-generate \
202                 --output="$(SIPHON_INPUT)" \
203                 "@$(SIPHON_INPUT)/files"
204
205 # Evaluate this to build a siphon doc output target for each desired
206 # output type:
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 $$<)..."
214         @set -e; \
215         cd "$(WS_ROOT)"; \
216         $(DOXY_DIR)/siphon-process \
217                 --type=$$(basename $$(notdir $$<)) \
218                 --format=$(2) \
219                 --output="$$@" \
220                 "$$<"
221 endef
222
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))
227
228 # Process the .siphon source fragments and render them into a list of cli
229 # commands.
230 .DELETE_ON_ERROR: $(SIPHON_ITEMLIST)
231 $(eval $(call siphon-process,itemlist,itemlist))
232
233 # This target can be used just to generate the siphoned things
234 .PHONY: doxygen-siphon
235 doxygen-siphon: $(SIPHON_DOCS)
236
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)
241
242 # Generate the doxygen docs
243 .PHONY: doxygen
244 doxygen: $(SIPHON_DOCS)
245         @mkdir -p "$(DOXY_OUTPUT)"
246         @echo "Running Doxygen..."
247         set -e; cd "$(WS_ROOT)"; \
248             ROOT="$(WS_ROOT)" \
249             BUILD_ROOT="$(BR)" \
250             INPUT="$(addprefix $(WS_ROOT)/,$(DOXY_INPUT)) $(EXTRA_DOXY_INPUT)" \
251             INCLUDE_PATH="$(DOXY_INCLUDE_PATH)" \
252             EXCLUDE="$(DOXY_EXCLUDE)" \
253             HTML=YES \
254             VERSION="`git describe --tags --dirty`" \
255             doxygen $(DOXY_DIR)/doxygen.cfg
256
257 .PHONY: wipe-doxygen
258 wipe-doxygen:
259         rm -rf "$(BR)/docs" "$(BR)/.doxygen-siphon.d"
260
261 .PHONY: clean
262 clean: wipe-doxygen