VPP-221 Improve doxygen dependency check
[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 # Input directories and files
32 DOXY_INPUT ?= \
33         README.md \
34         vppinfra \
35         svm \
36         vlib \
37         vlib-api \
38         vnet \
39         vpp \
40         vpp-api \
41         plugins
42
43 DOXY_INCLUDE_PATH = $(shell set -e; cd $(WS_ROOT); for item in $(DOXY_INPUT); do find $$item -type d; done)
44 DOXY_INCLUDE_PATH += $(shell set -e; cpp -v </dev/null 2>&1 | grep -A 1000 '\#include' | awk '/^ /{print $$1}')
45
46 # Target directory for doxygen output
47 DOXY_OUTPUT ?= $(BR)/docs
48
49 # Siphoned fragments end up in here
50 SIPHON_INPUT ?= $(DOXY_OUTPUT)/siphon_fragments
51
52 # Siphoned fragements are processed into here
53 SIPHON_OUTPUT ?= $(DOXY_OUTPUT)/siphon_docs
54
55 # Extra document inputs that are processed in addition to DOXY_INPUT
56 EXTRA_DOXY_INPUT += $(SIPHON_OUTPUT)
57
58 # All the siphon types we know about
59 SIPHONS ?= clicmd
60
61 SIPHON_FILES = $(addprefix $(SIPHON_INPUT)/,$(addsuffix .siphon,$(SIPHONS)))
62 SIPHON_DOCS = $(addprefix $(SIPHON_OUTPUT)/,$(addsuffix .md,$(SIPHONS)))
63
64 $(BR)/.doxygen-bootstrap.ok:
65 ifeq ($(OS_ID),ubuntu)
66         @set -e; inst=; \
67                 for i in $(DOC_DEB_DEPENDS); do \
68                         dpkg-query --show $$i >/dev/null 2>&1 || inst="$$inst $$i"; \
69                 done; \
70                 [ "$$inst" ] && sudo apt-get $(CONFIRM) $(FORCE) install $$inst
71 else ifneq ("$(wildcard /etc/redhat-release)","")
72         @sudo yum install $(CONFIRM) $(DOC_RPM_DEPENDS)
73 else
74         $(error "This option currently works only on Ubuntu or Centos systems")
75 endif
76         @touch $@
77
78 .PHONY: bootstrap-doxygen
79 bootstrap-doxygen: $(BR)/.doxygen-bootstrap.ok
80
81 .DELETE_ON_ERROR: $(BR)/.doxygen-siphon.dep
82 $(BR)/.doxygen-siphon.dep: Makefile
83         set -e; rm -f "$@"; for input in $(DOXY_INPUT); do \
84                 find "$(WS_ROOT)/$$input" -type f \
85                         \( -name '*.[ch]' -or -name '*.dox' \) \
86                         -print | sed -e "s/^/\$$(SIPHON_FILES): /" >> $@; \
87         done
88
89 # Include the source -> siphon dependencies
90 -include $(BR)/.doxygen-siphon.dep
91
92 .NOTPARALLEL: $(SIPHON_FILES)
93 $(SIPHON_FILES): $(DOXY_DIR)/siphon_generate.py $(BR)/.doxygen-bootstrap.ok
94         @rm -rf "$(SIPHON_INPUT)" "$(SIPHON_OUTPUT)"
95         @mkdir -p "$(SIPHON_INPUT)" "$(SIPHON_OUTPUT)"
96         set -e; for input in $(DOXY_INPUT); do \
97                 cd "$(WS_ROOT)"; \
98                 find "$$input" -type f \
99                         \( -name '*.[ch]' -or -name '*.dox' \) \
100                         -print >> $(SIPHON_INPUT)/files; \
101         done
102         set -e; cd "$(WS_ROOT)"; $(DOXY_DIR)/siphon_generate.py \
103                 --output="$(SIPHON_INPUT)" \
104                 "@$(SIPHON_INPUT)/files"
105
106
107 .DELETE_ON_ERROR: $(SIPHON_DOCS)
108 $(SIPHON_OUTPUT)/%.md: $(SIPHON_INPUT)/%.siphon $(DOXY_DIR)/siphon_process.py
109         set -e; cd "$(WS_ROOT)"; \
110                 $(DOXY_DIR)/siphon_process.py --type=$(basename $(notdir $<)) \
111                         --output="$(SIPHON_OUTPUT)" $< > $@
112
113 # This target can be used just to generate the siphoned docs
114 .PHONY: doxygen-siphon
115 doxygen-siphon: $(SIPHON_DOCS)
116
117 # Generate the doxygen docs
118 doxygen: $(SIPHON_DOCS)
119         @mkdir -p "$(DOXY_OUTPUT)"
120         set -e; cd "$(WS_ROOT)"; \
121             ROOT="$(WS_ROOT)" \
122             BUILD_ROOT="$(BR)" \
123             INPUT="$(addprefix $(WS_ROOT)/,$(DOXY_INPUT)) $(EXTRA_DOXY_INPUT)" \
124             INCLUDE_PATH="$(DOXY_INCLUDE_PATH)" \
125             HTML=YES \
126             VERSION="`git describe --tags --dirty`" \
127             doxygen $(DOXY_DIR)/doxygen.cfg
128
129 wipe-doxygen:
130         rm -rf "$(BR)/docs" "$(BR)/.doxygen-siphon.d"
131