Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 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 | |
Chris Luke | 90f52bf | 2016-09-12 08:55:13 -0400 | [diff] [blame] | 19 | # Default target |
| 20 | .PHONY: all |
| 21 | all: doxygen |
| 22 | |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 23 | # These should be passed in by the root Makefile |
| 24 | WS_ROOT ?= $(CURDIR)/.. |
| 25 | BR ?= $(WS_ROOT)/build-root |
Chris Luke | 36d2506 | 2016-09-22 20:52:26 -0400 | [diff] [blame] | 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 |
Chris Luke | e0d802b | 2016-08-31 10:04:58 -0400 | [diff] [blame] | 33 | OS_ID ?= $(shell grep '^ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g') |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 34 | |
| 35 | # Package dependencies |
Chris Luke | 90f52bf | 2016-09-12 08:55:13 -0400 | [diff] [blame] | 36 | DOC_DEB_DEPENDS = doxygen graphviz python-pyparsing python-jinja2 |
| 37 | DOC_RPM_DEPENDS = doxygen graphviz pyparsing python-jinja2 |
Chris Luke | 36d2506 | 2016-09-22 20:52:26 -0400 | [diff] [blame] | 38 | DOC_MAC_BIN_DEPENDS = doxygen dot git |
| 39 | DOC_MAC_PY_DEPENDS = pyparsing jinja2 |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 40 | |
| 41 | # Doxygen configuration and our utility scripts |
| 42 | DOXY_DIR ?= $(WS_ROOT)/doxygen |
| 43 | |
Chris Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 44 | # Primary source directories |
| 45 | DOXY_SRC_DIRECTORIES = \ |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 46 | vppinfra \ |
| 47 | svm \ |
| 48 | vlib \ |
| 49 | vlib-api \ |
| 50 | vnet \ |
| 51 | vpp \ |
Chris Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 52 | vpp-api |
| 53 | |
| 54 | # Input directories and files |
| 55 | DOXY_INPUT ?= \ |
Chris Luke | 5ccbaa9 | 2016-09-14 12:42:54 -0400 | [diff] [blame] | 56 | $(wildcard $(WS_ROOT)/*.md) \ |
| 57 | $(wildcard $(DOXY_DIR)/*.md) \ |
Chris Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 58 | $(DOXY_SRC_DIRECTORIES) \ |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 59 | plugins |
| 60 | |
Chris Luke | 5ccbaa9 | 2016-09-14 12:42:54 -0400 | [diff] [blame] | 61 | # Strip leading workspace path from input names |
| 62 | DOXY_INPUT := $(subst $(WS_ROOT)/,,$(DOXY_INPUT)) |
| 63 | |
Chris Luke | d4024f5 | 2016-09-06 09:32:36 -0400 | [diff] [blame] | 64 | # 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 Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 68 | # These must be left-anchored paths for the regexp below to work. |
| 69 | DOXY_EXCLUDE ?= \ |
| 70 | vlib/vlib/buffer.c \ |
| 71 | vlib/example \ |
| 72 | plugins/sample-plugin |
Chris Luke | d4024f5 | 2016-09-06 09:32:36 -0400 | [diff] [blame] | 73 | |
| 74 | # Generate a regexp for filenames to exclude |
Chris Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 75 | DOXY_EXCLUDE_REGEXP = ($(subst .,\.,$(shell echo '$(strip $(DOXY_EXCLUDE))' | sed -e 's/ /|/g'))) |
Chris Luke | d4024f5 | 2016-09-06 09:32:36 -0400 | [diff] [blame] | 76 | |
Chris Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 77 | # Include all the normal source directories in the include file path |
| 78 | DOXY_INCLUDE_PATH = $(DOXY_SRC_DIRECTORIES) |
| 79 | |
| 80 | # Also include any plugin directories that exist |
| 81 | DOXY_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) |
| 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 |
Chris Luke | d4024f5 | 2016-09-06 09:32:36 -0400 | [diff] [blame] | 99 | |
| 100 | # Discover if we have CPP available |
Chris Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 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}') |
Chris Luke | d4024f5 | 2016-09-06 09:32:36 -0400 | [diff] [blame] | 105 | endif |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 106 | |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 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 |
Chris Luke | 90f52bf | 2016-09-12 08:55:13 -0400 | [diff] [blame] | 120 | SIPHONS ?= clicmd syscfg |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 121 | |
| 122 | SIPHON_FILES = $(addprefix $(SIPHON_INPUT)/,$(addsuffix .siphon,$(SIPHONS))) |
| 123 | SIPHON_DOCS = $(addprefix $(SIPHON_OUTPUT)/,$(addsuffix .md,$(SIPHONS))) |
Chris Luke | c3f92ad | 2016-10-05 15:45:19 -0400 | [diff] [blame] | 124 | SIPHON_ITEMLIST = $(addprefix $(SIPHON_OUTPUT)/,$(addsuffix .itemlist,$(filter clicmd,$(SIPHONS)))) |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 125 | |
Chris Luke | 90f52bf | 2016-09-12 08:55:13 -0400 | [diff] [blame] | 126 | $(BR)/.doxygen-bootstrap.ok: Makefile |
Chris Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 127 | @echo "Checking whether dependencies for Doxygen are installed..." |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 128 | ifeq ($(OS_ID),ubuntu) |
Chris Luke | ee4743a | 2016-09-01 09:04:01 -0400 | [diff] [blame] | 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; \ |
Chris Luke | 90f52bf | 2016-09-12 08:55:13 -0400 | [diff] [blame] | 133 | if [ "$$inst" ]; then \ |
| 134 | sudo apt-get update; \ |
| 135 | sudo apt-get $(CONFIRM) $(FORCE) install $$inst; \ |
| 136 | fi |
Chris Luke | 3542514 | 2016-09-09 20:16:04 -0400 | [diff] [blame] | 137 | @if [ ! -s /usr/lib/graphviz/config6a ]; then \ |
| 138 | echo "Rebuidlding system Graphviz configuration."; \ |
Chris Luke | c87fa6d | 2016-09-09 17:51:42 -0400 | [diff] [blame] | 139 | sudo dot -c; \ |
| 140 | fi |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 141 | else ifneq ("$(wildcard /etc/redhat-release)","") |
| 142 | @sudo yum install $(CONFIRM) $(DOC_RPM_DEPENDS) |
Chris Luke | 36d2506 | 2016-09-22 20:52:26 -0400 | [diff] [blame] | 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 |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 158 | else |
Chris Luke | 36d2506 | 2016-09-22 20:52:26 -0400 | [diff] [blame] | 159 | $(error "Building documentation currently works only on Ubuntu, CentOS or MacOS systems.") |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 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 |
Chris Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 168 | @echo "Building siphon dependencies..." |
| 169 | @set -e; rm -f "$@"; for input in $(DOXY_INPUT); do \ |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 170 | find "$(WS_ROOT)/$$input" -type f \ |
Chris Luke | d4024f5 | 2016-09-06 09:32:36 -0400 | [diff] [blame] | 171 | \( -name '*.[ch]' -or -name '*.dox' \) -print \ |
Chris Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 172 | | grep -v -E '^$(WS_ROOT)/$(DOXY_EXCLUDE_REGEXP)' \ |
Chris Luke | d4024f5 | 2016-09-06 09:32:36 -0400 | [diff] [blame] | 173 | | sed -e "s/^/\$$(SIPHON_FILES): /" \ |
| 174 | >> $@; \ |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 175 | done |
| 176 | |
| 177 | # Include the source -> siphon dependencies |
| 178 | -include $(BR)/.doxygen-siphon.dep |
| 179 | |
Chris Luke | 90f52bf | 2016-09-12 08:55:13 -0400 | [diff] [blame] | 180 | # Generate .siphon files that contain fragments of source file that |
| 181 | # relate to the siphons we support. |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 182 | .NOTPARALLEL: $(SIPHON_FILES) |
Chris Luke | 90f52bf | 2016-09-12 08:55:13 -0400 | [diff] [blame] | 183 | $(SIPHON_FILES): $(BR)/.doxygen-bootstrap.ok \ |
| 184 | $(DOXY_DIR)/siphon-generate \ |
| 185 | $(wildcard $(DOXY_DIR)/siphon/*.py) |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 186 | @rm -rf "$(SIPHON_INPUT)" "$(SIPHON_OUTPUT)" |
| 187 | @mkdir -p "$(SIPHON_INPUT)" "$(SIPHON_OUTPUT)" |
Chris Luke | d4024f5 | 2016-09-06 09:32:36 -0400 | [diff] [blame] | 188 | @touch $(SIPHON_INPUT)/files |
Chris Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 189 | @echo "Collating source file list for siphoning..." |
| 190 | @for input in $(DOXY_INPUT); do \ |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 191 | cd "$(WS_ROOT)"; \ |
| 192 | find "$$input" -type f \ |
Chris Luke | d4024f5 | 2016-09-06 09:32:36 -0400 | [diff] [blame] | 193 | \( -name '*.[ch]' -or -name '*.dox' \) -print \ |
Chris Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 194 | | grep -v -E '^$(DOXY_EXCLUDE_REGEXP)' \ |
Chris Luke | d4024f5 | 2016-09-06 09:32:36 -0400 | [diff] [blame] | 195 | >> $(SIPHON_INPUT)/files; \ |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 196 | done |
Chris Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 197 | @echo "Generating siphons..." |
Chris Luke | 90f52bf | 2016-09-12 08:55:13 -0400 | [diff] [blame] | 198 | @set -e; \ |
| 199 | cd "$(WS_ROOT)"; \ |
| 200 | $(DOXY_DIR)/siphon-generate \ |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 201 | --output="$(SIPHON_INPUT)" \ |
| 202 | "@$(SIPHON_INPUT)/files" |
| 203 | |
Chris Luke | c3f92ad | 2016-10-05 15:45:19 -0400 | [diff] [blame] | 204 | # Evaluate this to build a siphon doc output target for each desired |
| 205 | # output type: |
| 206 | # $(eval $(call siphon-process,file_extension,output_type_name)) |
| 207 | define siphon-process |
| 208 | $(SIPHON_OUTPUT)/%.$(1): $(SIPHON_INPUT)/%.siphon \ |
Chris Luke | 90f52bf | 2016-09-12 08:55:13 -0400 | [diff] [blame] | 209 | $(DOXY_DIR)/siphon-process \ |
| 210 | $(wildcard $(DOXY_DIR)/siphon/*.py) \ |
Chris Luke | c3f92ad | 2016-10-05 15:45:19 -0400 | [diff] [blame] | 211 | $(wildcard $(DOXY_DIR)/siphon_templates/$(2)/*/*.$(1)) |
| 212 | @echo "Processing siphon for $(2) from $$(notdir $$<)..." |
Chris Luke | 90f52bf | 2016-09-12 08:55:13 -0400 | [diff] [blame] | 213 | @set -e; \ |
| 214 | cd "$(WS_ROOT)"; \ |
| 215 | $(DOXY_DIR)/siphon-process \ |
Chris Luke | c3f92ad | 2016-10-05 15:45:19 -0400 | [diff] [blame] | 216 | --type=$$(basename $$(notdir $$<)) \ |
| 217 | --format=$(2) \ |
| 218 | --output="$$@" \ |
| 219 | "$$<" |
| 220 | endef |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 221 | |
Chris Luke | c3f92ad | 2016-10-05 15:45:19 -0400 | [diff] [blame] | 222 | # Process the .siphon source fragments and render them into doxygen flavored |
| 223 | # markdown documentation |
| 224 | .DELETE_ON_ERROR: $(SIPHON_DOCS) |
| 225 | $(eval $(call siphon-process,md,markdown)) |
| 226 | |
| 227 | # Process the .siphon source fragments and render them into a list of cli |
| 228 | # commands. |
| 229 | .DELETE_ON_ERROR: $(SIPHON_ITEMLIST) |
| 230 | $(eval $(call siphon-process,itemlist,itemlist)) |
| 231 | |
| 232 | # This target can be used just to generate the siphoned things |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 233 | .PHONY: doxygen-siphon |
Chris Luke | c3f92ad | 2016-10-05 15:45:19 -0400 | [diff] [blame] | 234 | doxygen-siphon: $(SIPHON_DOCS) $(SIPHON_ITEMLIST) |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 235 | |
| 236 | # Generate the doxygen docs |
Chris Luke | 90f52bf | 2016-09-12 08:55:13 -0400 | [diff] [blame] | 237 | .PHONY: doxygen |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 238 | doxygen: $(SIPHON_DOCS) |
| 239 | @mkdir -p "$(DOXY_OUTPUT)" |
Chris Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 240 | @echo "Running Doxygen..." |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 241 | set -e; cd "$(WS_ROOT)"; \ |
| 242 | ROOT="$(WS_ROOT)" \ |
| 243 | BUILD_ROOT="$(BR)" \ |
| 244 | INPUT="$(addprefix $(WS_ROOT)/,$(DOXY_INPUT)) $(EXTRA_DOXY_INPUT)" \ |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 245 | INCLUDE_PATH="$(DOXY_INCLUDE_PATH)" \ |
Chris Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 246 | EXCLUDE="$(DOXY_EXCLUDE)" \ |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 247 | HTML=YES \ |
| 248 | VERSION="`git describe --tags --dirty`" \ |
| 249 | doxygen $(DOXY_DIR)/doxygen.cfg |
| 250 | |
Chris Luke | 90f52bf | 2016-09-12 08:55:13 -0400 | [diff] [blame] | 251 | .PHONY: wipe-doxygen |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 252 | wipe-doxygen: |
| 253 | rm -rf "$(BR)/docs" "$(BR)/.doxygen-siphon.d" |
| 254 | |
Chris Luke | 90f52bf | 2016-09-12 08:55:13 -0400 | [diff] [blame] | 255 | .PHONY: clean |
| 256 | clean: wipe-doxygen |