1 # Copyright (c) 2016 Comcast Cable Communications Management, LLC.
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:
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 # Build the documentation
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')
24 # Package dependencies
25 DOC_DEB_DEPENDS = doxygen graphviz python-pyparsing
26 DOC_RPM_DEPENDS = doxygen graphviz pyparsing
28 # Doxygen configuration and our utility scripts
29 DOXY_DIR ?= $(WS_ROOT)/doxygen
31 # Input directories and files
43 # Files to exclude, from pre-Doxygen steps, eg because they're
44 # selectively compiled.
45 # Examples would be to exclude non-DPDK related sources when
46 # there's a DPDK equivalent that conflicts.
47 # This is specifically for the pre-Doxygen steps; Doxygen uses
48 # @cond for this instead.
52 # Generate a regexp for filenames to exclude
53 DOXY_PRE_EXCLUDE_REGEXP = ($(subst .,\.,$(shell echo '$(strip $(DOXY_PRE_EXCLUDE))' | sed -e 's/ /|/g')))
55 # Discover all the directories we might, possibly, maybe, have include files in
56 DOXY_INCLUDE_PATH = $(shell set -e; cd $(WS_ROOT); for item in $(DOXY_INPUT); do find $$item -type d; done)
58 # Discover if we have CPP available
59 CPP ?= $(shell which cpp)
60 ifneq ($(strip $(CPP)),)
61 # Add whatever directories CPP normally includes
62 DOXY_INCLUDE_PATH += $(shell set -e; $(CPP) -v </dev/null 2>&1 | grep -A 1000 '\#include' | awk '/^ /{print $$1}')
65 # Target directory for doxygen output
66 DOXY_OUTPUT ?= $(BR)/docs
68 # Siphoned fragments end up in here
69 SIPHON_INPUT ?= $(DOXY_OUTPUT)/siphon_fragments
71 # Siphoned fragements are processed into here
72 SIPHON_OUTPUT ?= $(DOXY_OUTPUT)/siphon_docs
74 # Extra document inputs that are processed in addition to DOXY_INPUT
75 EXTRA_DOXY_INPUT += $(SIPHON_OUTPUT)
77 # All the siphon types we know about
80 SIPHON_FILES = $(addprefix $(SIPHON_INPUT)/,$(addsuffix .siphon,$(SIPHONS)))
81 SIPHON_DOCS = $(addprefix $(SIPHON_OUTPUT)/,$(addsuffix .md,$(SIPHONS)))
83 $(BR)/.doxygen-bootstrap.ok:
84 ifeq ($(OS_ID),ubuntu)
86 for i in $(DOC_DEB_DEPENDS); do \
87 dpkg-query --show $$i >/dev/null 2>&1 || inst="$$inst $$i"; \
89 if [ "$$inst" ]; then sudo apt-get $(CONFIRM) $(FORCE) install $$inst; fi
90 else ifneq ("$(wildcard /etc/redhat-release)","")
91 @sudo yum install $(CONFIRM) $(DOC_RPM_DEPENDS)
93 $(error "This option currently works only on Ubuntu or Centos systems")
97 .PHONY: bootstrap-doxygen
98 bootstrap-doxygen: $(BR)/.doxygen-bootstrap.ok
100 .DELETE_ON_ERROR: $(BR)/.doxygen-siphon.dep
101 $(BR)/.doxygen-siphon.dep: Makefile
102 set -e; rm -f "$@"; for input in $(DOXY_INPUT); do \
103 find "$(WS_ROOT)/$$input" -type f \
104 \( -name '*.[ch]' -or -name '*.dox' \) -print \
105 | grep -v -E '^$(WS_ROOT)/$(DOXY_PRE_EXCLUDE_REGEXP)$$' \
106 | sed -e "s/^/\$$(SIPHON_FILES): /" \
110 # Include the source -> siphon dependencies
111 -include $(BR)/.doxygen-siphon.dep
113 .NOTPARALLEL: $(SIPHON_FILES)
114 $(SIPHON_FILES): $(DOXY_DIR)/siphon_generate.py $(BR)/.doxygen-bootstrap.ok
115 @rm -rf "$(SIPHON_INPUT)" "$(SIPHON_OUTPUT)"
116 @mkdir -p "$(SIPHON_INPUT)" "$(SIPHON_OUTPUT)"
117 @touch $(SIPHON_INPUT)/files
118 for input in $(DOXY_INPUT); do \
120 find "$$input" -type f \
121 \( -name '*.[ch]' -or -name '*.dox' \) -print \
122 | grep -v -E '^$(DOXY_PRE_EXCLUDE_REGEXP)$$' \
123 >> $(SIPHON_INPUT)/files; \
125 set -e; cd "$(WS_ROOT)"; $(DOXY_DIR)/siphon_generate.py \
126 --output="$(SIPHON_INPUT)" \
127 "@$(SIPHON_INPUT)/files"
130 .DELETE_ON_ERROR: $(SIPHON_DOCS)
131 $(SIPHON_OUTPUT)/%.md: $(SIPHON_INPUT)/%.siphon $(DOXY_DIR)/siphon_process.py
132 set -e; cd "$(WS_ROOT)"; \
133 $(DOXY_DIR)/siphon_process.py --type=$(basename $(notdir $<)) \
134 --output="$(SIPHON_OUTPUT)" $< > $@
136 # This target can be used just to generate the siphoned docs
137 .PHONY: doxygen-siphon
138 doxygen-siphon: $(SIPHON_DOCS)
140 # Generate the doxygen docs
141 doxygen: $(SIPHON_DOCS)
142 @mkdir -p "$(DOXY_OUTPUT)"
143 set -e; cd "$(WS_ROOT)"; \
146 INPUT="$(addprefix $(WS_ROOT)/,$(DOXY_INPUT)) $(EXTRA_DOXY_INPUT)" \
147 INCLUDE_PATH="$(DOXY_INCLUDE_PATH)" \
149 VERSION="`git describe --tags --dirty`" \
150 doxygen $(DOXY_DIR)/doxygen.cfg
153 rm -rf "$(BR)/docs" "$(BR)/.doxygen-siphon.d"