blob: 0661fc9ec843b4fd9b8a4f3cfca6999932e39a99 [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
Marco Varlese85bb9172017-02-02 21:33:09 +010038DOC_SUSE_RPM_DEPENDS = doxygen graphviz python-pyparsing python-Jinja2
Chris Luke36d25062016-09-22 20:52:26 -040039DOC_MAC_BIN_DEPENDS = doxygen dot git
40DOC_MAC_PY_DEPENDS = pyparsing jinja2
Chris Luke54ccf222016-07-25 16:38:11 -040041
42# Doxygen configuration and our utility scripts
43DOXY_DIR ?= $(WS_ROOT)/doxygen
44
Chris Luke3b480932016-09-07 13:28:59 -040045# Primary source directories
Chris Lukefdc62ab2016-12-28 09:44:47 -050046DOXY_SRC ?= src
Chris Luke3b480932016-09-07 13:28:59 -040047DOXY_SRC_DIRECTORIES = \
Chris Lukefdc62ab2016-12-28 09:44:47 -050048 $(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 \
Pablo Camarillo4521afa2017-03-16 10:43:05 +010056 $(DOXY_SRC)/vpp-api \
57 $(DOXY_SRC)/examples
Chris Luke3b480932016-09-07 13:28:59 -040058
59# Input directories and files
60DOXY_INPUT ?= \
Chris Luke5ccbaa92016-09-14 12:42:54 -040061 $(wildcard $(WS_ROOT)/*.md) \
62 $(wildcard $(DOXY_DIR)/*.md) \
Chris Luke3b480932016-09-07 13:28:59 -040063 $(DOXY_SRC_DIRECTORIES) \
Chris Luke64ebb5f2017-09-27 15:09:48 -040064 $(DOXY_SRC)/plugins \
65 extras
Chris Luke54ccf222016-07-25 16:38:11 -040066
Chris Luke5ccbaa92016-09-14 12:42:54 -040067# Strip leading workspace path from input names
68DOXY_INPUT := $(subst $(WS_ROOT)/,,$(DOXY_INPUT))
69
Chris Luked4024f52016-09-06 09:32:36 -040070# 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.
Chris Luke3b480932016-09-07 13:28:59 -040074# These must be left-anchored paths for the regexp below to work.
75DOXY_EXCLUDE ?= \
Ray Kinsella583dc8d2017-06-08 15:54:19 +010076 $(DOXY_SRC)/vpp-api/lua
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
Chris Luke3b480932016-09-07 13:28:59 -040084# 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)
91ifneq ($(strip $(_vpp_br)),)
92DOXY_INCLUDE_PATH += \
93 $(_vpp_br)/vlib-api \
94 $(_vpp_br)/vpp
95# Also include any plugin directories that exist
96DOXY_INCLUDE_PATH += \
97 $(shell find $(WS_ROOT)/$(_vpp_br)/plugins -maxdepth 1 -type d | sed -e 's@^$(WS_ROOT)/*@@')
98endif
Chris Luked4024f52016-09-06 09:32:36 -040099
100# Discover if we have CPP available
Chris Luke3b480932016-09-07 13:28:59 -0400101_cpp = $(shell which cpp)
102ifneq ($(strip $(_cpp)),)
103# Add whatever directories CPP normally includes to the header path
104DOXY_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 -0400105endif
Chris Luke16bcf7d2016-09-01 14:31:46 -0400106
Chris Luke54ccf222016-07-25 16:38:11 -0400107# Target directory for doxygen output
108DOXY_OUTPUT ?= $(BR)/docs
109
110# Siphoned fragments end up in here
111SIPHON_INPUT ?= $(DOXY_OUTPUT)/siphon_fragments
112
113# Siphoned fragements are processed into here
114SIPHON_OUTPUT ?= $(DOXY_OUTPUT)/siphon_docs
115
116# Extra document inputs that are processed in addition to DOXY_INPUT
117EXTRA_DOXY_INPUT += $(SIPHON_OUTPUT)
118
119# All the siphon types we know about
Chris Luke90f52bf2016-09-12 08:55:13 -0400120SIPHONS ?= clicmd syscfg
Chris Luke54ccf222016-07-25 16:38:11 -0400121
122SIPHON_FILES = $(addprefix $(SIPHON_INPUT)/,$(addsuffix .siphon,$(SIPHONS)))
123SIPHON_DOCS = $(addprefix $(SIPHON_OUTPUT)/,$(addsuffix .md,$(SIPHONS)))
Chris Lukec3f92ad2016-10-05 15:45:19 -0400124SIPHON_ITEMLIST = $(addprefix $(SIPHON_OUTPUT)/,$(addsuffix .itemlist,$(filter clicmd,$(SIPHONS))))
Chris Luke54ccf222016-07-25 16:38:11 -0400125
Chris Luke90f52bf2016-09-12 08:55:13 -0400126$(BR)/.doxygen-bootstrap.ok: Makefile
Damjan Marion6bbf83a2017-01-10 10:39:21 +0100127 @echo "Checking whether dependencies for Doxygen are installed..."
Chris Luke54ccf222016-07-25 16:38:11 -0400128ifeq ($(OS_ID),ubuntu)
Damjan Marion6bbf83a2017-01-10 10:39:21 +0100129 @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
Chris Luke35425142016-09-09 20:16:04 -0400137 @if [ ! -s /usr/lib/graphviz/config6a ]; then \
Dave Wallacec8c53352017-02-17 00:10:53 -0500138 echo "Rebuilding system Graphviz configuration."; \
Chris Lukec87fa6d2016-09-09 17:51:42 -0400139 sudo dot -c; \
140 fi
Damjan Marion6bbf83a2017-01-10 10:39:21 +0100141else ifneq ("$(wildcard /etc/redhat-release)","")
142 @sudo yum install $(CONFIRM) $(DOC_RPM_DEPENDS)
Chris Luke36d25062016-09-22 20:52:26 -0400143else 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
Marco Varlese85bb9172017-02-02 21:33:09 +0100158else ifeq ($(OS_ID),opensuse)
159 @sudo zypper install $(CONFIRM) $(DOC_SUSE_RPM_DEPENDS)
Chris Luke54ccf222016-07-25 16:38:11 -0400160else
Marco Varlese85bb9172017-02-02 21:33:09 +0100161 $(error "Building documentation currently works only on Ubuntu, CentOS, MacOS and OpenSUSE systems.")
Chris Luke54ccf222016-07-25 16:38:11 -0400162endif
163 @touch $@
164
165.PHONY: bootstrap-doxygen
166bootstrap-doxygen: $(BR)/.doxygen-bootstrap.ok
167
168.DELETE_ON_ERROR: $(BR)/.doxygen-siphon.dep
Chris Lukefdc62ab2016-12-28 09:44:47 -0500169$(BR)/.doxygen-siphon.dep: Makefile \
170 $(addprefix,$(WSROOT),$(DOXY_INPUT))
Chris Luke3b480932016-09-07 13:28:59 -0400171 @echo "Building siphon dependencies..."
Chris Lukefdc62ab2016-12-28 09:44:47 -0500172 @rm -f "$@"; for input in $(DOXY_INPUT); do \
173 [ -e "$(WS_ROOT)/$$input" ] && \
Chris Luke54ccf222016-07-25 16:38:11 -0400174 find "$(WS_ROOT)/$$input" -type f \
Chris Luked4024f52016-09-06 09:32:36 -0400175 \( -name '*.[ch]' -or -name '*.dox' \) -print \
Chris Luke3b480932016-09-07 13:28:59 -0400176 | grep -v -E '^$(WS_ROOT)/$(DOXY_EXCLUDE_REGEXP)' \
Chris Luked4024f52016-09-06 09:32:36 -0400177 | sed -e "s/^/\$$(SIPHON_FILES): /" \
178 >> $@; \
Chris Luke54ccf222016-07-25 16:38:11 -0400179 done
180
181# Include the source -> siphon dependencies
182-include $(BR)/.doxygen-siphon.dep
183
Chris Luke90f52bf2016-09-12 08:55:13 -0400184# Generate .siphon files that contain fragments of source file that
185# relate to the siphons we support.
Chris Luke54ccf222016-07-25 16:38:11 -0400186.NOTPARALLEL: $(SIPHON_FILES)
Damjan Marion6bbf83a2017-01-10 10:39:21 +0100187$(SIPHON_FILES): $(BR)/.doxygen-bootstrap.ok \
188 $(DOXY_DIR)/siphon-generate \
Chris Lukefdc62ab2016-12-28 09:44:47 -0500189 $(addprefix,$(WSROOT),$(DOXY_INPUT)) \
Chris Luke90f52bf2016-09-12 08:55:13 -0400190 $(wildcard $(DOXY_DIR)/siphon/*.py)
Chris Lukefdc62ab2016-12-28 09:44:47 -0500191 @echo "Validating source tree..."
192 @set -e; for input in $(DOXY_INPUT); do \
193 if [ ! -e "$(WS_ROOT)/$$input" ]; then \
194 echo "ERROR: Input path '$$input' does not exist." >&2; \
195 exit 1; \
196 fi; \
197 done
Chris Luke54ccf222016-07-25 16:38:11 -0400198 @rm -rf "$(SIPHON_INPUT)" "$(SIPHON_OUTPUT)"
199 @mkdir -p "$(SIPHON_INPUT)" "$(SIPHON_OUTPUT)"
Chris Luked4024f52016-09-06 09:32:36 -0400200 @touch $(SIPHON_INPUT)/files
Chris Luke3b480932016-09-07 13:28:59 -0400201 @echo "Collating source file list for siphoning..."
202 @for input in $(DOXY_INPUT); do \
Chris Luke54ccf222016-07-25 16:38:11 -0400203 cd "$(WS_ROOT)"; \
204 find "$$input" -type f \
Chris Luked4024f52016-09-06 09:32:36 -0400205 \( -name '*.[ch]' -or -name '*.dox' \) -print \
Chris Luke33356932017-05-10 11:40:27 -0400206 | grep -v -E '^src/examples/' \
Chris Luke3b480932016-09-07 13:28:59 -0400207 | grep -v -E '^$(DOXY_EXCLUDE_REGEXP)' \
Chris Luked4024f52016-09-06 09:32:36 -0400208 >> $(SIPHON_INPUT)/files; \
Chris Luke54ccf222016-07-25 16:38:11 -0400209 done
Chris Luke3b480932016-09-07 13:28:59 -0400210 @echo "Generating siphons..."
Chris Luke90f52bf2016-09-12 08:55:13 -0400211 @set -e; \
212 cd "$(WS_ROOT)"; \
213 $(DOXY_DIR)/siphon-generate \
Chris Luke54ccf222016-07-25 16:38:11 -0400214 --output="$(SIPHON_INPUT)" \
215 "@$(SIPHON_INPUT)/files"
216
Chris Lukec3f92ad2016-10-05 15:45:19 -0400217# Evaluate this to build a siphon doc output target for each desired
218# output type:
219# $(eval $(call siphon-process,file_extension,output_type_name))
220define siphon-process
221$(SIPHON_OUTPUT)/%.$(1): $(SIPHON_INPUT)/%.siphon \
Chris Luke90f52bf2016-09-12 08:55:13 -0400222 $(DOXY_DIR)/siphon-process \
223 $(wildcard $(DOXY_DIR)/siphon/*.py) \
Chris Lukec3f92ad2016-10-05 15:45:19 -0400224 $(wildcard $(DOXY_DIR)/siphon_templates/$(2)/*/*.$(1))
225 @echo "Processing siphon for $(2) from $$(notdir $$<)..."
Chris Luke90f52bf2016-09-12 08:55:13 -0400226 @set -e; \
227 cd "$(WS_ROOT)"; \
228 $(DOXY_DIR)/siphon-process \
Chris Lukec3f92ad2016-10-05 15:45:19 -0400229 --type=$$(basename $$(notdir $$<)) \
230 --format=$(2) \
231 --output="$$@" \
232 "$$<"
233endef
Chris Luke54ccf222016-07-25 16:38:11 -0400234
Chris Lukec3f92ad2016-10-05 15:45:19 -0400235# Process the .siphon source fragments and render them into doxygen flavored
236# markdown documentation
237.DELETE_ON_ERROR: $(SIPHON_DOCS)
238$(eval $(call siphon-process,md,markdown))
239
240# Process the .siphon source fragments and render them into a list of cli
241# commands.
242.DELETE_ON_ERROR: $(SIPHON_ITEMLIST)
243$(eval $(call siphon-process,itemlist,itemlist))
244
245# This target can be used just to generate the siphoned things
Chris Luke54ccf222016-07-25 16:38:11 -0400246.PHONY: doxygen-siphon
Damjan Marion6bbf83a2017-01-10 10:39:21 +0100247doxygen-siphon: $(SIPHON_DOCS) $(SIPHON_ITEMLIST)
Chris Luke54ccf222016-07-25 16:38:11 -0400248
249# Generate the doxygen docs
Chris Luke90f52bf2016-09-12 08:55:13 -0400250.PHONY: doxygen
Chris Luke54ccf222016-07-25 16:38:11 -0400251doxygen: $(SIPHON_DOCS)
252 @mkdir -p "$(DOXY_OUTPUT)"
Chris Luke3b480932016-09-07 13:28:59 -0400253 @echo "Running Doxygen..."
Chris Luke54ccf222016-07-25 16:38:11 -0400254 set -e; cd "$(WS_ROOT)"; \
255 ROOT="$(WS_ROOT)" \
256 BUILD_ROOT="$(BR)" \
257 INPUT="$(addprefix $(WS_ROOT)/,$(DOXY_INPUT)) $(EXTRA_DOXY_INPUT)" \
Chris Luke16bcf7d2016-09-01 14:31:46 -0400258 INCLUDE_PATH="$(DOXY_INCLUDE_PATH)" \
Chris Luke3b480932016-09-07 13:28:59 -0400259 EXCLUDE="$(DOXY_EXCLUDE)" \
Chris Luke54ccf222016-07-25 16:38:11 -0400260 HTML=YES \
261 VERSION="`git describe --tags --dirty`" \
262 doxygen $(DOXY_DIR)/doxygen.cfg
263
Chris Luke90f52bf2016-09-12 08:55:13 -0400264.PHONY: wipe-doxygen
Chris Luke54ccf222016-07-25 16:38:11 -0400265wipe-doxygen:
266 rm -rf "$(BR)/docs" "$(BR)/.doxygen-siphon.d"
267
Chris Luke90f52bf2016-09-12 08:55:13 -0400268.PHONY: clean
269clean: wipe-doxygen