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