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