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 | |
| 19 | # These should be passed in by the root Makefile |
| 20 | WS_ROOT ?= $(CURDIR)/.. |
| 21 | BR ?= $(WS_ROOT)/build-root |
Chris Luke | e0d802b | 2016-08-31 10:04:58 -0400 | [diff] [blame] | 22 | 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] | 23 | |
| 24 | # Package dependencies |
| 25 | DOC_DEB_DEPENDS = doxygen graphviz python-pyparsing |
| 26 | DOC_RPM_DEPENDS = doxygen graphviz pyparsing |
| 27 | |
| 28 | # Doxygen configuration and our utility scripts |
| 29 | DOXY_DIR ?= $(WS_ROOT)/doxygen |
| 30 | |
Chris Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 31 | # Primary source directories |
| 32 | DOXY_SRC_DIRECTORIES = \ |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 33 | vppinfra \ |
| 34 | svm \ |
| 35 | vlib \ |
| 36 | vlib-api \ |
| 37 | vnet \ |
| 38 | vpp \ |
Chris Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 39 | vpp-api |
| 40 | |
| 41 | # Input directories and files |
| 42 | DOXY_INPUT ?= \ |
| 43 | README.md \ |
| 44 | $(DOXY_SRC_DIRECTORIES) \ |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 45 | plugins |
| 46 | |
Chris Luke | d4024f5 | 2016-09-06 09:32:36 -0400 | [diff] [blame] | 47 | # Files to exclude, from pre-Doxygen steps, eg because they're |
| 48 | # selectively compiled. |
| 49 | # Examples would be to exclude non-DPDK related sources when |
| 50 | # there's a DPDK equivalent that conflicts. |
Chris Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 51 | # These must be left-anchored paths for the regexp below to work. |
| 52 | DOXY_EXCLUDE ?= \ |
| 53 | vlib/vlib/buffer.c \ |
| 54 | vlib/example \ |
| 55 | plugins/sample-plugin |
Chris Luke | d4024f5 | 2016-09-06 09:32:36 -0400 | [diff] [blame] | 56 | |
| 57 | # Generate a regexp for filenames to exclude |
Chris Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 58 | 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] | 59 | |
Chris Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 60 | # Include all the normal source directories in the include file path |
| 61 | DOXY_INCLUDE_PATH = $(DOXY_SRC_DIRECTORIES) |
| 62 | |
| 63 | # Also include any plugin directories that exist |
| 64 | DOXY_INCLUDE_PATH += \ |
| 65 | $(shell find $(WS_ROOT)/plugins -maxdepth 1 -type d | sed -e 's@^$(WS_ROOT)/*@@') |
| 66 | |
| 67 | # Find API header directories and include them in the header path. |
| 68 | # This is only useful if VPP and plugins are already built; nothing |
| 69 | # here depends on those targets. We don't build documentation for these |
| 70 | # header files, they're just added to the INCLUDE search path for Doxygen. |
| 71 | _vpp_br = $(shell find "$(BR)" -maxdepth 1 -type d \ |
| 72 | '(' -name build-vpp_debug-native -o -name build-vpp-native ')' -print \ |
| 73 | | sed -e 's@^$(WS_ROOT)/*@@' -e 1q) |
| 74 | ifneq ($(strip $(_vpp_br)),) |
| 75 | DOXY_INCLUDE_PATH += \ |
| 76 | $(_vpp_br)/vlib-api \ |
| 77 | $(_vpp_br)/vpp |
| 78 | # Also include any plugin directories that exist |
| 79 | DOXY_INCLUDE_PATH += \ |
| 80 | $(shell find $(WS_ROOT)/$(_vpp_br)/plugins -maxdepth 1 -type d | sed -e 's@^$(WS_ROOT)/*@@') |
| 81 | endif |
Chris Luke | d4024f5 | 2016-09-06 09:32:36 -0400 | [diff] [blame] | 82 | |
| 83 | # Discover if we have CPP available |
Chris Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 84 | _cpp = $(shell which cpp) |
| 85 | ifneq ($(strip $(_cpp)),) |
| 86 | # Add whatever directories CPP normally includes to the header path |
| 87 | 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] | 88 | endif |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 89 | |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 90 | # Target directory for doxygen output |
| 91 | DOXY_OUTPUT ?= $(BR)/docs |
| 92 | |
| 93 | # Siphoned fragments end up in here |
| 94 | SIPHON_INPUT ?= $(DOXY_OUTPUT)/siphon_fragments |
| 95 | |
| 96 | # Siphoned fragements are processed into here |
| 97 | SIPHON_OUTPUT ?= $(DOXY_OUTPUT)/siphon_docs |
| 98 | |
| 99 | # Extra document inputs that are processed in addition to DOXY_INPUT |
| 100 | EXTRA_DOXY_INPUT += $(SIPHON_OUTPUT) |
| 101 | |
| 102 | # All the siphon types we know about |
| 103 | SIPHONS ?= clicmd |
| 104 | |
| 105 | SIPHON_FILES = $(addprefix $(SIPHON_INPUT)/,$(addsuffix .siphon,$(SIPHONS))) |
| 106 | SIPHON_DOCS = $(addprefix $(SIPHON_OUTPUT)/,$(addsuffix .md,$(SIPHONS))) |
| 107 | |
| 108 | $(BR)/.doxygen-bootstrap.ok: |
Chris Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 109 | @echo "Checking whether dependencies for Doxygen are installed..." |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 110 | ifeq ($(OS_ID),ubuntu) |
Chris Luke | ee4743a | 2016-09-01 09:04:01 -0400 | [diff] [blame] | 111 | @set -e; inst=; \ |
| 112 | for i in $(DOC_DEB_DEPENDS); do \ |
| 113 | dpkg-query --show $$i >/dev/null 2>&1 || inst="$$inst $$i"; \ |
| 114 | done; \ |
Chris Luke | d4024f5 | 2016-09-06 09:32:36 -0400 | [diff] [blame] | 115 | if [ "$$inst" ]; then sudo apt-get $(CONFIRM) $(FORCE) install $$inst; fi |
Chris Luke | 3542514 | 2016-09-09 20:16:04 -0400 | [diff] [blame^] | 116 | @if [ ! -s /usr/lib/graphviz/config6a ]; then \ |
| 117 | echo "Rebuidlding system Graphviz configuration."; \ |
Chris Luke | c87fa6d | 2016-09-09 17:51:42 -0400 | [diff] [blame] | 118 | sudo dot -c; \ |
| 119 | fi |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 120 | else ifneq ("$(wildcard /etc/redhat-release)","") |
| 121 | @sudo yum install $(CONFIRM) $(DOC_RPM_DEPENDS) |
| 122 | else |
| 123 | $(error "This option currently works only on Ubuntu or Centos systems") |
| 124 | endif |
| 125 | @touch $@ |
| 126 | |
| 127 | .PHONY: bootstrap-doxygen |
| 128 | bootstrap-doxygen: $(BR)/.doxygen-bootstrap.ok |
| 129 | |
| 130 | .DELETE_ON_ERROR: $(BR)/.doxygen-siphon.dep |
| 131 | $(BR)/.doxygen-siphon.dep: Makefile |
Chris Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 132 | @echo "Building siphon dependencies..." |
| 133 | @set -e; rm -f "$@"; for input in $(DOXY_INPUT); do \ |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 134 | find "$(WS_ROOT)/$$input" -type f \ |
Chris Luke | d4024f5 | 2016-09-06 09:32:36 -0400 | [diff] [blame] | 135 | \( -name '*.[ch]' -or -name '*.dox' \) -print \ |
Chris Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 136 | | grep -v -E '^$(WS_ROOT)/$(DOXY_EXCLUDE_REGEXP)' \ |
Chris Luke | d4024f5 | 2016-09-06 09:32:36 -0400 | [diff] [blame] | 137 | | sed -e "s/^/\$$(SIPHON_FILES): /" \ |
| 138 | >> $@; \ |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 139 | done |
| 140 | |
| 141 | # Include the source -> siphon dependencies |
| 142 | -include $(BR)/.doxygen-siphon.dep |
| 143 | |
| 144 | .NOTPARALLEL: $(SIPHON_FILES) |
| 145 | $(SIPHON_FILES): $(DOXY_DIR)/siphon_generate.py $(BR)/.doxygen-bootstrap.ok |
| 146 | @rm -rf "$(SIPHON_INPUT)" "$(SIPHON_OUTPUT)" |
| 147 | @mkdir -p "$(SIPHON_INPUT)" "$(SIPHON_OUTPUT)" |
Chris Luke | d4024f5 | 2016-09-06 09:32:36 -0400 | [diff] [blame] | 148 | @touch $(SIPHON_INPUT)/files |
Chris Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 149 | @echo "Collating source file list for siphoning..." |
| 150 | @for input in $(DOXY_INPUT); do \ |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 151 | cd "$(WS_ROOT)"; \ |
| 152 | find "$$input" -type f \ |
Chris Luke | d4024f5 | 2016-09-06 09:32:36 -0400 | [diff] [blame] | 153 | \( -name '*.[ch]' -or -name '*.dox' \) -print \ |
Chris Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 154 | | grep -v -E '^$(DOXY_EXCLUDE_REGEXP)' \ |
Chris Luke | d4024f5 | 2016-09-06 09:32:36 -0400 | [diff] [blame] | 155 | >> $(SIPHON_INPUT)/files; \ |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 156 | done |
Chris Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 157 | @echo "Generating siphons..." |
| 158 | @set -e; cd "$(WS_ROOT)"; $(DOXY_DIR)/siphon_generate.py \ |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 159 | --output="$(SIPHON_INPUT)" \ |
| 160 | "@$(SIPHON_INPUT)/files" |
| 161 | |
| 162 | |
| 163 | .DELETE_ON_ERROR: $(SIPHON_DOCS) |
| 164 | $(SIPHON_OUTPUT)/%.md: $(SIPHON_INPUT)/%.siphon $(DOXY_DIR)/siphon_process.py |
Chris Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 165 | @echo "Processing siphon from $(notdir $<)..." |
| 166 | @set -e; cd "$(WS_ROOT)"; \ |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 167 | $(DOXY_DIR)/siphon_process.py --type=$(basename $(notdir $<)) \ |
| 168 | --output="$(SIPHON_OUTPUT)" $< > $@ |
| 169 | |
| 170 | # This target can be used just to generate the siphoned docs |
| 171 | .PHONY: doxygen-siphon |
| 172 | doxygen-siphon: $(SIPHON_DOCS) |
| 173 | |
| 174 | # Generate the doxygen docs |
| 175 | doxygen: $(SIPHON_DOCS) |
| 176 | @mkdir -p "$(DOXY_OUTPUT)" |
Chris Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 177 | @echo "Running Doxygen..." |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 178 | set -e; cd "$(WS_ROOT)"; \ |
| 179 | ROOT="$(WS_ROOT)" \ |
| 180 | BUILD_ROOT="$(BR)" \ |
| 181 | INPUT="$(addprefix $(WS_ROOT)/,$(DOXY_INPUT)) $(EXTRA_DOXY_INPUT)" \ |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 182 | INCLUDE_PATH="$(DOXY_INCLUDE_PATH)" \ |
Chris Luke | 3b48093 | 2016-09-07 13:28:59 -0400 | [diff] [blame] | 183 | EXCLUDE="$(DOXY_EXCLUDE)" \ |
Chris Luke | 54ccf22 | 2016-07-25 16:38:11 -0400 | [diff] [blame] | 184 | HTML=YES \ |
| 185 | VERSION="`git describe --tags --dirty`" \ |
| 186 | doxygen $(DOXY_DIR)/doxygen.cfg |
| 187 | |
| 188 | wipe-doxygen: |
| 189 | rm -rf "$(BR)/docs" "$(BR)/.doxygen-siphon.d" |
| 190 | |