blob: 640acc26328e9ad7751fa39eef498cb4f8747b6d [file] [log] [blame]
Chris Luke54ccf222016-07-25 16:38:11 -04001# 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
Chris Luke90f52bf2016-09-12 08:55:13 -040019# Default target
20.PHONY: all
21all: doxygen
22
Chris Luke54ccf222016-07-25 16:38:11 -040023# These should be passed in by the root Makefile
24WS_ROOT ?= $(CURDIR)/..
25BR ?= $(WS_ROOT)/build-root
Chris Luke36d25062016-09-22 20:52:26 -040026
27# We support MacOS for docs generation
28ifeq ($(shell uname),Darwin)
29OS_ID = darwin
30endif
31
32# Work out the OS if we haven't already
Chris Lukee0d802b2016-08-31 10:04:58 -040033OS_ID ?= $(shell grep '^ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
Chris Luke54ccf222016-07-25 16:38:11 -040034
35# Package dependencies
Damjan Marion6bbf83a2017-01-10 10:39:21 +010036DOC_DEB_DEPENDS = doxygen graphviz python-pyparsing python-jinja2
37DOC_RPM_DEPENDS = doxygen graphviz pyparsing python-jinja2
Chris Luke36d25062016-09-22 20:52:26 -040038DOC_MAC_BIN_DEPENDS = doxygen dot git
39DOC_MAC_PY_DEPENDS = pyparsing jinja2
Chris Luke54ccf222016-07-25 16:38:11 -040040
41# Doxygen configuration and our utility scripts
42DOXY_DIR ?= $(WS_ROOT)/doxygen
43
Chris Luke3b480932016-09-07 13:28:59 -040044# Primary source directories
Chris Lukefdc62ab2016-12-28 09:44:47 -050045DOXY_SRC ?= src
Chris Luke3b480932016-09-07 13:28:59 -040046DOXY_SRC_DIRECTORIES = \
Chris Lukefdc62ab2016-12-28 09:44:47 -050047 $(DOXY_SRC)/vppinfra \
48 $(DOXY_SRC)/svm \
49 $(DOXY_SRC)/vlib \
50 $(DOXY_SRC)/vlibapi \
51 $(DOXY_SRC)/vlibmemory \
52 $(DOXY_SRC)/vlibsocket \
53 $(DOXY_SRC)/vnet \
54 $(DOXY_SRC)/vpp \
Damjan Marioncb034b92016-12-28 18:38:59 +010055 $(DOXY_SRC)/vpp-api
Chris Luke3b480932016-09-07 13:28:59 -040056
57# Input directories and files
58DOXY_INPUT ?= \
Chris Luke5ccbaa92016-09-14 12:42:54 -040059 $(wildcard $(WS_ROOT)/*.md) \
60 $(wildcard $(DOXY_DIR)/*.md) \
Chris Luke3b480932016-09-07 13:28:59 -040061 $(DOXY_SRC_DIRECTORIES) \
Damjan Marion1c5ee872017-01-10 17:07:38 +010062 $(DOXY_SRC)/plugins
Chris Luke54ccf222016-07-25 16:38:11 -040063
Chris Luke5ccbaa92016-09-14 12:42:54 -040064# Strip leading workspace path from input names
65DOXY_INPUT := $(subst $(WS_ROOT)/,,$(DOXY_INPUT))
66
Chris Luked4024f52016-09-06 09:32:36 -040067# Files to exclude, from pre-Doxygen steps, eg because they're
68# selectively compiled.
69# Examples would be to exclude non-DPDK related sources when
70# there's a DPDK equivalent that conflicts.
Chris Luke3b480932016-09-07 13:28:59 -040071# These must be left-anchored paths for the regexp below to work.
72DOXY_EXCLUDE ?= \
Chris Lukefdc62ab2016-12-28 09:44:47 -050073 $(DOXY_SRC)/vlib/vlib/buffer.c \
74 $(DOXY_SRC)/vlib/example \
Damjan Marioncb034b92016-12-28 18:38:59 +010075 $(DOXY_SRC)/vpp-api/lua \
76 plugins/sample-plugin
Chris Luked4024f52016-09-06 09:32:36 -040077
78# Generate a regexp for filenames to exclude
Chris Luke3b480932016-09-07 13:28:59 -040079DOXY_EXCLUDE_REGEXP = ($(subst .,\.,$(shell echo '$(strip $(DOXY_EXCLUDE))' | sed -e 's/ /|/g')))
Chris Luked4024f52016-09-06 09:32:36 -040080
Chris Luke3b480932016-09-07 13:28:59 -040081# Include all the normal source directories in the include file path
82DOXY_INCLUDE_PATH = $(DOXY_SRC_DIRECTORIES)
83
84# Also include any plugin directories that exist
85DOXY_INCLUDE_PATH += \
86 $(shell find $(WS_ROOT)/plugins -maxdepth 1 -type d | sed -e 's@^$(WS_ROOT)/*@@')
87
88# Find API header directories and include them in the header path.
89# This is only useful if VPP and plugins are already built; nothing
90# here depends on those targets. We don't build documentation for these
91# header files, they're just added to the INCLUDE search path for Doxygen.
92_vpp_br = $(shell find "$(BR)" -maxdepth 1 -type d \
93 '(' -name build-vpp_debug-native -o -name build-vpp-native ')' -print \
94 | sed -e 's@^$(WS_ROOT)/*@@' -e 1q)
95ifneq ($(strip $(_vpp_br)),)
96DOXY_INCLUDE_PATH += \
97 $(_vpp_br)/vlib-api \
98 $(_vpp_br)/vpp
99# Also include any plugin directories that exist
100DOXY_INCLUDE_PATH += \
101 $(shell find $(WS_ROOT)/$(_vpp_br)/plugins -maxdepth 1 -type d | sed -e 's@^$(WS_ROOT)/*@@')
102endif
Chris Luked4024f52016-09-06 09:32:36 -0400103
104# Discover if we have CPP available
Chris Luke3b480932016-09-07 13:28:59 -0400105_cpp = $(shell which cpp)
106ifneq ($(strip $(_cpp)),)
107# Add whatever directories CPP normally includes to the header path
108DOXY_INCLUDE_PATH += $(shell set -e; $(_cpp) -v </dev/null 2>&1 | awk 'f&&/^ /{print $$1} /^\#include/{f=1}')
Chris Luked4024f52016-09-06 09:32:36 -0400109endif
Chris Luke16bcf7d2016-09-01 14:31:46 -0400110
Chris Luke54ccf222016-07-25 16:38:11 -0400111# Target directory for doxygen output
112DOXY_OUTPUT ?= $(BR)/docs
113
114# Siphoned fragments end up in here
115SIPHON_INPUT ?= $(DOXY_OUTPUT)/siphon_fragments
116
117# Siphoned fragements are processed into here
118SIPHON_OUTPUT ?= $(DOXY_OUTPUT)/siphon_docs
119
120# Extra document inputs that are processed in addition to DOXY_INPUT
121EXTRA_DOXY_INPUT += $(SIPHON_OUTPUT)
122
123# All the siphon types we know about
Chris Luke90f52bf2016-09-12 08:55:13 -0400124SIPHONS ?= clicmd syscfg
Chris Luke54ccf222016-07-25 16:38:11 -0400125
126SIPHON_FILES = $(addprefix $(SIPHON_INPUT)/,$(addsuffix .siphon,$(SIPHONS)))
127SIPHON_DOCS = $(addprefix $(SIPHON_OUTPUT)/,$(addsuffix .md,$(SIPHONS)))
Chris Lukec3f92ad2016-10-05 15:45:19 -0400128SIPHON_ITEMLIST = $(addprefix $(SIPHON_OUTPUT)/,$(addsuffix .itemlist,$(filter clicmd,$(SIPHONS))))
Chris Luke54ccf222016-07-25 16:38:11 -0400129
Chris Luke90f52bf2016-09-12 08:55:13 -0400130$(BR)/.doxygen-bootstrap.ok: Makefile
Damjan Marion6bbf83a2017-01-10 10:39:21 +0100131 @echo "Checking whether dependencies for Doxygen are installed..."
Chris Luke54ccf222016-07-25 16:38:11 -0400132ifeq ($(OS_ID),ubuntu)
Damjan Marion6bbf83a2017-01-10 10:39:21 +0100133 @set -e; inst=; \
134 for i in $(DOC_DEB_DEPENDS); do \
135 dpkg-query --show $$i >/dev/null 2>&1 || inst="$$inst $$i"; \
136 done; \
137 if [ "$$inst" ]; then \
138 sudo apt-get update; \
139 sudo apt-get $(CONFIRM) $(FORCE) install $$inst; \
140 fi
Chris Luke35425142016-09-09 20:16:04 -0400141 @if [ ! -s /usr/lib/graphviz/config6a ]; then \
Damjan Marion6bbf83a2017-01-10 10:39:21 +0100142 echo "Rebuidlding system Graphviz configuration."; \
Chris Lukec87fa6d2016-09-09 17:51:42 -0400143 sudo dot -c; \
144 fi
Damjan Marion6bbf83a2017-01-10 10:39:21 +0100145else ifneq ("$(wildcard /etc/redhat-release)","")
146 @sudo yum install $(CONFIRM) $(DOC_RPM_DEPENDS)
Chris Luke36d25062016-09-22 20:52:26 -0400147else ifeq ($(OS_ID),darwin)
148 @set -e; \
149 for bin in $(DOC_MAC_BIN_DEPENDS); do \
150 which -s $${bin} || (\
151 echo "Program '$${bin}' not found, please install it."; \
152 false; \
153 ); \
154 done
155 @set -e; \
156 for py in $(DOC_MAC_PY_DEPENDS); do \
157 python -c "import $${py}" >/dev/null 2>&1 || (\
158 echo "Python package '$${py}' not found, please install it."; \
159 false; \
160 ); \
161 done
Chris Luke54ccf222016-07-25 16:38:11 -0400162else
Chris Luke36d25062016-09-22 20:52:26 -0400163 $(error "Building documentation currently works only on Ubuntu, CentOS or MacOS systems.")
Chris Luke54ccf222016-07-25 16:38:11 -0400164endif
165 @touch $@
166
167.PHONY: bootstrap-doxygen
168bootstrap-doxygen: $(BR)/.doxygen-bootstrap.ok
169
170.DELETE_ON_ERROR: $(BR)/.doxygen-siphon.dep
Chris Lukefdc62ab2016-12-28 09:44:47 -0500171$(BR)/.doxygen-siphon.dep: Makefile \
172 $(addprefix,$(WSROOT),$(DOXY_INPUT))
Chris Luke3b480932016-09-07 13:28:59 -0400173 @echo "Building siphon dependencies..."
Chris Lukefdc62ab2016-12-28 09:44:47 -0500174 @rm -f "$@"; for input in $(DOXY_INPUT); do \
175 [ -e "$(WS_ROOT)/$$input" ] && \
Chris Luke54ccf222016-07-25 16:38:11 -0400176 find "$(WS_ROOT)/$$input" -type f \
Chris Luked4024f52016-09-06 09:32:36 -0400177 \( -name '*.[ch]' -or -name '*.dox' \) -print \
Chris Luke3b480932016-09-07 13:28:59 -0400178 | grep -v -E '^$(WS_ROOT)/$(DOXY_EXCLUDE_REGEXP)' \
Chris Luked4024f52016-09-06 09:32:36 -0400179 | sed -e "s/^/\$$(SIPHON_FILES): /" \
180 >> $@; \
Chris Luke54ccf222016-07-25 16:38:11 -0400181 done
182
183# Include the source -> siphon dependencies
184-include $(BR)/.doxygen-siphon.dep
185
Chris Luke90f52bf2016-09-12 08:55:13 -0400186# Generate .siphon files that contain fragments of source file that
187# relate to the siphons we support.
Chris Luke54ccf222016-07-25 16:38:11 -0400188.NOTPARALLEL: $(SIPHON_FILES)
Damjan Marion6bbf83a2017-01-10 10:39:21 +0100189$(SIPHON_FILES): $(BR)/.doxygen-bootstrap.ok \
190 $(DOXY_DIR)/siphon-generate \
Chris Lukefdc62ab2016-12-28 09:44:47 -0500191 $(addprefix,$(WSROOT),$(DOXY_INPUT)) \
Chris Luke90f52bf2016-09-12 08:55:13 -0400192 $(wildcard $(DOXY_DIR)/siphon/*.py)
Chris Lukefdc62ab2016-12-28 09:44:47 -0500193 @echo "Validating source tree..."
194 @set -e; for input in $(DOXY_INPUT); do \
195 if [ ! -e "$(WS_ROOT)/$$input" ]; then \
196 echo "ERROR: Input path '$$input' does not exist." >&2; \
197 exit 1; \
198 fi; \
199 done
Chris Luke54ccf222016-07-25 16:38:11 -0400200 @rm -rf "$(SIPHON_INPUT)" "$(SIPHON_OUTPUT)"
201 @mkdir -p "$(SIPHON_INPUT)" "$(SIPHON_OUTPUT)"
Chris Luked4024f52016-09-06 09:32:36 -0400202 @touch $(SIPHON_INPUT)/files
Chris Luke3b480932016-09-07 13:28:59 -0400203 @echo "Collating source file list for siphoning..."
204 @for input in $(DOXY_INPUT); do \
Chris Luke54ccf222016-07-25 16:38:11 -0400205 cd "$(WS_ROOT)"; \
206 find "$$input" -type f \
Chris Luked4024f52016-09-06 09:32:36 -0400207 \( -name '*.[ch]' -or -name '*.dox' \) -print \
Chris Luke3b480932016-09-07 13:28:59 -0400208 | grep -v -E '^$(DOXY_EXCLUDE_REGEXP)' \
Chris Luked4024f52016-09-06 09:32:36 -0400209 >> $(SIPHON_INPUT)/files; \
Chris Luke54ccf222016-07-25 16:38:11 -0400210 done
Chris Luke3b480932016-09-07 13:28:59 -0400211 @echo "Generating siphons..."
Chris Luke90f52bf2016-09-12 08:55:13 -0400212 @set -e; \
213 cd "$(WS_ROOT)"; \
214 $(DOXY_DIR)/siphon-generate \
Chris Luke54ccf222016-07-25 16:38:11 -0400215 --output="$(SIPHON_INPUT)" \
216 "@$(SIPHON_INPUT)/files"
217
Chris Lukec3f92ad2016-10-05 15:45:19 -0400218# Evaluate this to build a siphon doc output target for each desired
219# output type:
220# $(eval $(call siphon-process,file_extension,output_type_name))
221define siphon-process
222$(SIPHON_OUTPUT)/%.$(1): $(SIPHON_INPUT)/%.siphon \
Chris Luke90f52bf2016-09-12 08:55:13 -0400223 $(DOXY_DIR)/siphon-process \
224 $(wildcard $(DOXY_DIR)/siphon/*.py) \
Chris Lukec3f92ad2016-10-05 15:45:19 -0400225 $(wildcard $(DOXY_DIR)/siphon_templates/$(2)/*/*.$(1))
226 @echo "Processing siphon for $(2) from $$(notdir $$<)..."
Chris Luke90f52bf2016-09-12 08:55:13 -0400227 @set -e; \
228 cd "$(WS_ROOT)"; \
229 $(DOXY_DIR)/siphon-process \
Chris Lukec3f92ad2016-10-05 15:45:19 -0400230 --type=$$(basename $$(notdir $$<)) \
231 --format=$(2) \
232 --output="$$@" \
233 "$$<"
234endef
Chris Luke54ccf222016-07-25 16:38:11 -0400235
Chris Lukec3f92ad2016-10-05 15:45:19 -0400236# Process the .siphon source fragments and render them into doxygen flavored
237# markdown documentation
238.DELETE_ON_ERROR: $(SIPHON_DOCS)
239$(eval $(call siphon-process,md,markdown))
240
241# Process the .siphon source fragments and render them into a list of cli
242# commands.
243.DELETE_ON_ERROR: $(SIPHON_ITEMLIST)
244$(eval $(call siphon-process,itemlist,itemlist))
245
246# This target can be used just to generate the siphoned things
Chris Luke54ccf222016-07-25 16:38:11 -0400247.PHONY: doxygen-siphon
Damjan Marion6bbf83a2017-01-10 10:39:21 +0100248doxygen-siphon: $(SIPHON_DOCS) $(SIPHON_ITEMLIST)
Chris Luke54ccf222016-07-25 16:38:11 -0400249
250# Generate the doxygen docs
Chris Luke90f52bf2016-09-12 08:55:13 -0400251.PHONY: doxygen
Chris Luke54ccf222016-07-25 16:38:11 -0400252doxygen: $(SIPHON_DOCS)
253 @mkdir -p "$(DOXY_OUTPUT)"
Chris Luke3b480932016-09-07 13:28:59 -0400254 @echo "Running Doxygen..."
Chris Luke54ccf222016-07-25 16:38:11 -0400255 set -e; cd "$(WS_ROOT)"; \
256 ROOT="$(WS_ROOT)" \
257 BUILD_ROOT="$(BR)" \
258 INPUT="$(addprefix $(WS_ROOT)/,$(DOXY_INPUT)) $(EXTRA_DOXY_INPUT)" \
Chris Luke16bcf7d2016-09-01 14:31:46 -0400259 INCLUDE_PATH="$(DOXY_INCLUDE_PATH)" \
Chris Luke3b480932016-09-07 13:28:59 -0400260 EXCLUDE="$(DOXY_EXCLUDE)" \
Chris Luke54ccf222016-07-25 16:38:11 -0400261 HTML=YES \
262 VERSION="`git describe --tags --dirty`" \
263 doxygen $(DOXY_DIR)/doxygen.cfg
264
Chris Luke90f52bf2016-09-12 08:55:13 -0400265.PHONY: wipe-doxygen
Chris Luke54ccf222016-07-25 16:38:11 -0400266wipe-doxygen:
267 rm -rf "$(BR)/docs" "$(BR)/.doxygen-siphon.d"
268
Chris Luke90f52bf2016-09-12 08:55:13 -0400269.PHONY: clean
270clean: wipe-doxygen