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