blob: 32504874d4a1cec507530528b2ed11afd7b98b3e [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 \
Chris Lukefdc62ab2016-12-28 09:44:47 -050053 $(DOXY_SRC)/vnet \
54 $(DOXY_SRC)/vpp \
Pablo Camarillo4521afa2017-03-16 10:43:05 +010055 $(DOXY_SRC)/vpp-api \
56 $(DOXY_SRC)/examples
Chris Luke3b480932016-09-07 13:28:59 -040057
58# Input directories and files
59DOXY_INPUT ?= \
Chris Luke5ccbaa92016-09-14 12:42:54 -040060 $(wildcard $(WS_ROOT)/*.md) \
61 $(wildcard $(DOXY_DIR)/*.md) \
Chris Luke3b480932016-09-07 13:28:59 -040062 $(DOXY_SRC_DIRECTORIES) \
Chris Luke64ebb5f2017-09-27 15:09:48 -040063 $(DOXY_SRC)/plugins \
64 extras
Chris Luke54ccf222016-07-25 16:38:11 -040065
Chris Luke5ccbaa92016-09-14 12:42:54 -040066# Strip leading workspace path from input names
67DOXY_INPUT := $(subst $(WS_ROOT)/,,$(DOXY_INPUT))
68
Chris Luked4024f52016-09-06 09:32:36 -040069# 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.
Chris Luke3b480932016-09-07 13:28:59 -040073# These must be left-anchored paths for the regexp below to work.
74DOXY_EXCLUDE ?= \
Ray Kinsella583dc8d2017-06-08 15:54:19 +010075 $(DOXY_SRC)/vpp-api/lua
Chris Luked4024f52016-09-06 09:32:36 -040076
77# Generate a regexp for filenames to exclude
Chris Luke3b480932016-09-07 13:28:59 -040078DOXY_EXCLUDE_REGEXP = ($(subst .,\.,$(shell echo '$(strip $(DOXY_EXCLUDE))' | sed -e 's/ /|/g')))
Chris Luked4024f52016-09-06 09:32:36 -040079
Chris Luke3b480932016-09-07 13:28:59 -040080# Include all the normal source directories in the include file path
81DOXY_INCLUDE_PATH = $(DOXY_SRC_DIRECTORIES)
82
Chris Luke3b480932016-09-07 13:28:59 -040083# 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)
90ifneq ($(strip $(_vpp_br)),)
91DOXY_INCLUDE_PATH += \
92 $(_vpp_br)/vlib-api \
93 $(_vpp_br)/vpp
94# Also include any plugin directories that exist
95DOXY_INCLUDE_PATH += \
96 $(shell find $(WS_ROOT)/$(_vpp_br)/plugins -maxdepth 1 -type d | sed -e 's@^$(WS_ROOT)/*@@')
97endif
Chris Luked4024f52016-09-06 09:32:36 -040098
99# Discover if we have CPP available
Chris Luke3b480932016-09-07 13:28:59 -0400100_cpp = $(shell which cpp)
101ifneq ($(strip $(_cpp)),)
102# Add whatever directories CPP normally includes to the header path
103DOXY_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 -0400104endif
Chris Luke16bcf7d2016-09-01 14:31:46 -0400105
Chris Luke54ccf222016-07-25 16:38:11 -0400106# Target directory for doxygen output
107DOXY_OUTPUT ?= $(BR)/docs
108
109# Siphoned fragments end up in here
110SIPHON_INPUT ?= $(DOXY_OUTPUT)/siphon_fragments
111
112# Siphoned fragements are processed into here
113SIPHON_OUTPUT ?= $(DOXY_OUTPUT)/siphon_docs
114
115# Extra document inputs that are processed in addition to DOXY_INPUT
116EXTRA_DOXY_INPUT += $(SIPHON_OUTPUT)
117
118# All the siphon types we know about
Chris Luke90f52bf2016-09-12 08:55:13 -0400119SIPHONS ?= clicmd syscfg
Chris Luke54ccf222016-07-25 16:38:11 -0400120
121SIPHON_FILES = $(addprefix $(SIPHON_INPUT)/,$(addsuffix .siphon,$(SIPHONS)))
122SIPHON_DOCS = $(addprefix $(SIPHON_OUTPUT)/,$(addsuffix .md,$(SIPHONS)))
Chris Lukec3f92ad2016-10-05 15:45:19 -0400123SIPHON_ITEMLIST = $(addprefix $(SIPHON_OUTPUT)/,$(addsuffix .itemlist,$(filter clicmd,$(SIPHONS))))
Chris Luke54ccf222016-07-25 16:38:11 -0400124
Chris Luke90f52bf2016-09-12 08:55:13 -0400125$(BR)/.doxygen-bootstrap.ok: Makefile
Damjan Marion6bbf83a2017-01-10 10:39:21 +0100126 @echo "Checking whether dependencies for Doxygen are installed..."
Chris Luke54ccf222016-07-25 16:38:11 -0400127ifeq ($(OS_ID),ubuntu)
Damjan Marion6bbf83a2017-01-10 10:39:21 +0100128 @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
Chris Luke35425142016-09-09 20:16:04 -0400136 @if [ ! -s /usr/lib/graphviz/config6a ]; then \
Dave Wallacec8c53352017-02-17 00:10:53 -0500137 echo "Rebuilding system Graphviz configuration."; \
Chris Lukec87fa6d2016-09-09 17:51:42 -0400138 sudo dot -c; \
139 fi
Damjan Marion6bbf83a2017-01-10 10:39:21 +0100140else ifneq ("$(wildcard /etc/redhat-release)","")
141 @sudo yum install $(CONFIRM) $(DOC_RPM_DEPENDS)
Chris Luke36d25062016-09-22 20:52:26 -0400142else 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
Marco Varlese85bb9172017-02-02 21:33:09 +0100157else ifeq ($(OS_ID),opensuse)
158 @sudo zypper install $(CONFIRM) $(DOC_SUSE_RPM_DEPENDS)
Chris Luke54ccf222016-07-25 16:38:11 -0400159else
Marco Varlese85bb9172017-02-02 21:33:09 +0100160 $(error "Building documentation currently works only on Ubuntu, CentOS, MacOS and OpenSUSE systems.")
Chris Luke54ccf222016-07-25 16:38:11 -0400161endif
162 @touch $@
163
164.PHONY: bootstrap-doxygen
165bootstrap-doxygen: $(BR)/.doxygen-bootstrap.ok
166
167.DELETE_ON_ERROR: $(BR)/.doxygen-siphon.dep
Chris Lukefdc62ab2016-12-28 09:44:47 -0500168$(BR)/.doxygen-siphon.dep: Makefile \
169 $(addprefix,$(WSROOT),$(DOXY_INPUT))
Chris Luke3b480932016-09-07 13:28:59 -0400170 @echo "Building siphon dependencies..."
Chris Lukefdc62ab2016-12-28 09:44:47 -0500171 @rm -f "$@"; for input in $(DOXY_INPUT); do \
172 [ -e "$(WS_ROOT)/$$input" ] && \
Chris Luke54ccf222016-07-25 16:38:11 -0400173 find "$(WS_ROOT)/$$input" -type f \
Chris Luked4024f52016-09-06 09:32:36 -0400174 \( -name '*.[ch]' -or -name '*.dox' \) -print \
Chris Luke3b480932016-09-07 13:28:59 -0400175 | grep -v -E '^$(WS_ROOT)/$(DOXY_EXCLUDE_REGEXP)' \
Chris Luked4024f52016-09-06 09:32:36 -0400176 | sed -e "s/^/\$$(SIPHON_FILES): /" \
177 >> $@; \
Chris Luke54ccf222016-07-25 16:38:11 -0400178 done
179
180# Include the source -> siphon dependencies
181-include $(BR)/.doxygen-siphon.dep
182
Chris Luke90f52bf2016-09-12 08:55:13 -0400183# Generate .siphon files that contain fragments of source file that
184# relate to the siphons we support.
Chris Luke54ccf222016-07-25 16:38:11 -0400185.NOTPARALLEL: $(SIPHON_FILES)
Damjan Marion6bbf83a2017-01-10 10:39:21 +0100186$(SIPHON_FILES): $(BR)/.doxygen-bootstrap.ok \
187 $(DOXY_DIR)/siphon-generate \
Chris Lukefdc62ab2016-12-28 09:44:47 -0500188 $(addprefix,$(WSROOT),$(DOXY_INPUT)) \
Chris Luke90f52bf2016-09-12 08:55:13 -0400189 $(wildcard $(DOXY_DIR)/siphon/*.py)
Chris Lukefdc62ab2016-12-28 09:44:47 -0500190 @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
Chris Luke54ccf222016-07-25 16:38:11 -0400197 @rm -rf "$(SIPHON_INPUT)" "$(SIPHON_OUTPUT)"
198 @mkdir -p "$(SIPHON_INPUT)" "$(SIPHON_OUTPUT)"
Chris Luked4024f52016-09-06 09:32:36 -0400199 @touch $(SIPHON_INPUT)/files
Chris Luke3b480932016-09-07 13:28:59 -0400200 @echo "Collating source file list for siphoning..."
201 @for input in $(DOXY_INPUT); do \
Chris Luke54ccf222016-07-25 16:38:11 -0400202 cd "$(WS_ROOT)"; \
203 find "$$input" -type f \
Chris Luked4024f52016-09-06 09:32:36 -0400204 \( -name '*.[ch]' -or -name '*.dox' \) -print \
Chris Luke33356932017-05-10 11:40:27 -0400205 | grep -v -E '^src/examples/' \
Chris Luke3b480932016-09-07 13:28:59 -0400206 | grep -v -E '^$(DOXY_EXCLUDE_REGEXP)' \
Chris Luked4024f52016-09-06 09:32:36 -0400207 >> $(SIPHON_INPUT)/files; \
Chris Luke54ccf222016-07-25 16:38:11 -0400208 done
Chris Luke3b480932016-09-07 13:28:59 -0400209 @echo "Generating siphons..."
Chris Luke90f52bf2016-09-12 08:55:13 -0400210 @set -e; \
211 cd "$(WS_ROOT)"; \
212 $(DOXY_DIR)/siphon-generate \
Chris Luke54ccf222016-07-25 16:38:11 -0400213 --output="$(SIPHON_INPUT)" \
214 "@$(SIPHON_INPUT)/files"
215
Chris Lukec3f92ad2016-10-05 15:45:19 -0400216# 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))
219define siphon-process
220$(SIPHON_OUTPUT)/%.$(1): $(SIPHON_INPUT)/%.siphon \
Chris Luke90f52bf2016-09-12 08:55:13 -0400221 $(DOXY_DIR)/siphon-process \
222 $(wildcard $(DOXY_DIR)/siphon/*.py) \
Chris Lukec3f92ad2016-10-05 15:45:19 -0400223 $(wildcard $(DOXY_DIR)/siphon_templates/$(2)/*/*.$(1))
224 @echo "Processing siphon for $(2) from $$(notdir $$<)..."
Chris Luke90f52bf2016-09-12 08:55:13 -0400225 @set -e; \
226 cd "$(WS_ROOT)"; \
227 $(DOXY_DIR)/siphon-process \
Chris Lukec3f92ad2016-10-05 15:45:19 -0400228 --type=$$(basename $$(notdir $$<)) \
229 --format=$(2) \
230 --output="$$@" \
231 "$$<"
232endef
Chris Luke54ccf222016-07-25 16:38:11 -0400233
Chris Lukec3f92ad2016-10-05 15:45:19 -0400234# 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
Chris Luke54ccf222016-07-25 16:38:11 -0400245.PHONY: doxygen-siphon
Damjan Marion6bbf83a2017-01-10 10:39:21 +0100246doxygen-siphon: $(SIPHON_DOCS) $(SIPHON_ITEMLIST)
Chris Luke54ccf222016-07-25 16:38:11 -0400247
248# Generate the doxygen docs
Chris Luke90f52bf2016-09-12 08:55:13 -0400249.PHONY: doxygen
Chris Luke54ccf222016-07-25 16:38:11 -0400250doxygen: $(SIPHON_DOCS)
251 @mkdir -p "$(DOXY_OUTPUT)"
Chris Luke3b480932016-09-07 13:28:59 -0400252 @echo "Running Doxygen..."
Chris Luke54ccf222016-07-25 16:38:11 -0400253 set -e; cd "$(WS_ROOT)"; \
254 ROOT="$(WS_ROOT)" \
255 BUILD_ROOT="$(BR)" \
256 INPUT="$(addprefix $(WS_ROOT)/,$(DOXY_INPUT)) $(EXTRA_DOXY_INPUT)" \
Chris Luke16bcf7d2016-09-01 14:31:46 -0400257 INCLUDE_PATH="$(DOXY_INCLUDE_PATH)" \
Chris Luke3b480932016-09-07 13:28:59 -0400258 EXCLUDE="$(DOXY_EXCLUDE)" \
Chris Luke54ccf222016-07-25 16:38:11 -0400259 HTML=YES \
260 VERSION="`git describe --tags --dirty`" \
261 doxygen $(DOXY_DIR)/doxygen.cfg
262
Chris Luke90f52bf2016-09-12 08:55:13 -0400263.PHONY: wipe-doxygen
Chris Luke54ccf222016-07-25 16:38:11 -0400264wipe-doxygen:
265 rm -rf "$(BR)/docs" "$(BR)/.doxygen-siphon.d"
266
Chris Luke90f52bf2016-09-12 08:55:13 -0400267.PHONY: clean
268clean: wipe-doxygen