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