blob: 7031e84d523452da8710e5a8fd29762d31420324 [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
Chris Luke90f52bf2016-09-12 08:55:13 -040036DOC_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
45DOXY_SRC_DIRECTORIES = \
Chris Luke54ccf222016-07-25 16:38:11 -040046 vppinfra \
47 svm \
48 vlib \
49 vlib-api \
50 vnet \
51 vpp \
Chris Luke3b480932016-09-07 13:28:59 -040052 vpp-api
53
54# Input directories and files
55DOXY_INPUT ?= \
Chris Luke5ccbaa92016-09-14 12:42:54 -040056 $(wildcard $(WS_ROOT)/*.md) \
57 $(wildcard $(DOXY_DIR)/*.md) \
Chris Luke3b480932016-09-07 13:28:59 -040058 $(DOXY_SRC_DIRECTORIES) \
Chris Luke54ccf222016-07-25 16:38:11 -040059 plugins
60
Chris Luke5ccbaa92016-09-14 12:42:54 -040061# Strip leading workspace path from input names
62DOXY_INPUT := $(subst $(WS_ROOT)/,,$(DOXY_INPUT))
63
Chris Luked4024f52016-09-06 09:32:36 -040064# Files to exclude, from pre-Doxygen steps, eg because they're
65# selectively compiled.
66# Examples would be to exclude non-DPDK related sources when
67# there's a DPDK equivalent that conflicts.
Chris Luke3b480932016-09-07 13:28:59 -040068# These must be left-anchored paths for the regexp below to work.
69DOXY_EXCLUDE ?= \
70 vlib/vlib/buffer.c \
71 vlib/example \
72 plugins/sample-plugin
Chris Luked4024f52016-09-06 09:32:36 -040073
74# Generate a regexp for filenames to exclude
Chris Luke3b480932016-09-07 13:28:59 -040075DOXY_EXCLUDE_REGEXP = ($(subst .,\.,$(shell echo '$(strip $(DOXY_EXCLUDE))' | sed -e 's/ /|/g')))
Chris Luked4024f52016-09-06 09:32:36 -040076
Chris Luke3b480932016-09-07 13:28:59 -040077# Include all the normal source directories in the include file path
78DOXY_INCLUDE_PATH = $(DOXY_SRC_DIRECTORIES)
79
80# Also include any plugin directories that exist
81DOXY_INCLUDE_PATH += \
82 $(shell find $(WS_ROOT)/plugins -maxdepth 1 -type d | sed -e 's@^$(WS_ROOT)/*@@')
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)
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)))
124
Chris Luke90f52bf2016-09-12 08:55:13 -0400125$(BR)/.doxygen-bootstrap.ok: Makefile
Chris Luke3b480932016-09-07 13:28:59 -0400126 @echo "Checking whether dependencies for Doxygen are installed..."
Chris Luke54ccf222016-07-25 16:38:11 -0400127ifeq ($(OS_ID),ubuntu)
Chris Lukeee4743a2016-09-01 09:04:01 -0400128 @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; \
Chris Luke90f52bf2016-09-12 08:55:13 -0400132 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 \
137 echo "Rebuidlding system Graphviz configuration."; \
Chris Lukec87fa6d2016-09-09 17:51:42 -0400138 sudo dot -c; \
139 fi
Chris Luke54ccf222016-07-25 16:38:11 -0400140else 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
Chris Luke54ccf222016-07-25 16:38:11 -0400157else
Chris Luke36d25062016-09-22 20:52:26 -0400158 $(error "Building documentation currently works only on Ubuntu, CentOS or MacOS systems.")
Chris Luke54ccf222016-07-25 16:38:11 -0400159endif
160 @touch $@
161
162.PHONY: bootstrap-doxygen
163bootstrap-doxygen: $(BR)/.doxygen-bootstrap.ok
164
165.DELETE_ON_ERROR: $(BR)/.doxygen-siphon.dep
166$(BR)/.doxygen-siphon.dep: Makefile
Chris Luke3b480932016-09-07 13:28:59 -0400167 @echo "Building siphon dependencies..."
168 @set -e; rm -f "$@"; for input in $(DOXY_INPUT); do \
Chris Luke54ccf222016-07-25 16:38:11 -0400169 find "$(WS_ROOT)/$$input" -type f \
Chris Luked4024f52016-09-06 09:32:36 -0400170 \( -name '*.[ch]' -or -name '*.dox' \) -print \
Chris Luke3b480932016-09-07 13:28:59 -0400171 | grep -v -E '^$(WS_ROOT)/$(DOXY_EXCLUDE_REGEXP)' \
Chris Luked4024f52016-09-06 09:32:36 -0400172 | sed -e "s/^/\$$(SIPHON_FILES): /" \
173 >> $@; \
Chris Luke54ccf222016-07-25 16:38:11 -0400174 done
175
176# Include the source -> siphon dependencies
177-include $(BR)/.doxygen-siphon.dep
178
Chris Luke90f52bf2016-09-12 08:55:13 -0400179# Generate .siphon files that contain fragments of source file that
180# relate to the siphons we support.
Chris Luke54ccf222016-07-25 16:38:11 -0400181.NOTPARALLEL: $(SIPHON_FILES)
Chris Luke90f52bf2016-09-12 08:55:13 -0400182$(SIPHON_FILES): $(BR)/.doxygen-bootstrap.ok \
183 $(DOXY_DIR)/siphon-generate \
184 $(wildcard $(DOXY_DIR)/siphon/*.py)
Chris Luke54ccf222016-07-25 16:38:11 -0400185 @rm -rf "$(SIPHON_INPUT)" "$(SIPHON_OUTPUT)"
186 @mkdir -p "$(SIPHON_INPUT)" "$(SIPHON_OUTPUT)"
Chris Luked4024f52016-09-06 09:32:36 -0400187 @touch $(SIPHON_INPUT)/files
Chris Luke3b480932016-09-07 13:28:59 -0400188 @echo "Collating source file list for siphoning..."
189 @for input in $(DOXY_INPUT); do \
Chris Luke54ccf222016-07-25 16:38:11 -0400190 cd "$(WS_ROOT)"; \
191 find "$$input" -type f \
Chris Luked4024f52016-09-06 09:32:36 -0400192 \( -name '*.[ch]' -or -name '*.dox' \) -print \
Chris Luke3b480932016-09-07 13:28:59 -0400193 | grep -v -E '^$(DOXY_EXCLUDE_REGEXP)' \
Chris Luked4024f52016-09-06 09:32:36 -0400194 >> $(SIPHON_INPUT)/files; \
Chris Luke54ccf222016-07-25 16:38:11 -0400195 done
Chris Luke3b480932016-09-07 13:28:59 -0400196 @echo "Generating siphons..."
Chris Luke90f52bf2016-09-12 08:55:13 -0400197 @set -e; \
198 cd "$(WS_ROOT)"; \
199 $(DOXY_DIR)/siphon-generate \
Chris Luke54ccf222016-07-25 16:38:11 -0400200 --output="$(SIPHON_INPUT)" \
201 "@$(SIPHON_INPUT)/files"
202
Chris Luke90f52bf2016-09-12 08:55:13 -0400203# Process the .siphon source fragments and render them into doxygen flavored
204# markdown documentation
Chris Luke54ccf222016-07-25 16:38:11 -0400205.DELETE_ON_ERROR: $(SIPHON_DOCS)
Chris Luke90f52bf2016-09-12 08:55:13 -0400206$(SIPHON_OUTPUT)/%.md: $(SIPHON_INPUT)/%.siphon \
207 $(DOXY_DIR)/siphon-process \
208 $(wildcard $(DOXY_DIR)/siphon/*.py) \
209 $(wildcard $(DOXY_DIR)/siphon_templates/*/*.md)
Chris Luke3b480932016-09-07 13:28:59 -0400210 @echo "Processing siphon from $(notdir $<)..."
Chris Luke90f52bf2016-09-12 08:55:13 -0400211 @set -e; \
212 cd "$(WS_ROOT)"; \
213 $(DOXY_DIR)/siphon-process \
214 --type=$(basename $(notdir $<)) \
215 --output="$@" \
216 "$<"
Chris Luke54ccf222016-07-25 16:38:11 -0400217
218# This target can be used just to generate the siphoned docs
219.PHONY: doxygen-siphon
220doxygen-siphon: $(SIPHON_DOCS)
221
222# Generate the doxygen docs
Chris Luke90f52bf2016-09-12 08:55:13 -0400223.PHONY: doxygen
Chris Luke54ccf222016-07-25 16:38:11 -0400224doxygen: $(SIPHON_DOCS)
225 @mkdir -p "$(DOXY_OUTPUT)"
Chris Luke3b480932016-09-07 13:28:59 -0400226 @echo "Running Doxygen..."
Chris Luke54ccf222016-07-25 16:38:11 -0400227 set -e; cd "$(WS_ROOT)"; \
228 ROOT="$(WS_ROOT)" \
229 BUILD_ROOT="$(BR)" \
230 INPUT="$(addprefix $(WS_ROOT)/,$(DOXY_INPUT)) $(EXTRA_DOXY_INPUT)" \
Chris Luke16bcf7d2016-09-01 14:31:46 -0400231 INCLUDE_PATH="$(DOXY_INCLUDE_PATH)" \
Chris Luke3b480932016-09-07 13:28:59 -0400232 EXCLUDE="$(DOXY_EXCLUDE)" \
Chris Luke54ccf222016-07-25 16:38:11 -0400233 HTML=YES \
234 VERSION="`git describe --tags --dirty`" \
235 doxygen $(DOXY_DIR)/doxygen.cfg
236
Chris Luke90f52bf2016-09-12 08:55:13 -0400237.PHONY: wipe-doxygen
Chris Luke54ccf222016-07-25 16:38:11 -0400238wipe-doxygen:
239 rm -rf "$(BR)/docs" "$(BR)/.doxygen-siphon.d"
240
Chris Luke90f52bf2016-09-12 08:55:13 -0400241.PHONY: clean
242clean: wipe-doxygen