Nathan Skrzypczak | 9ad39c0 | 2021-08-19 11:38:06 +0200 | [diff] [blame] | 1 | # Copyright (c) 2021 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 | # Default target |
| 20 | .PHONY: all |
| 21 | all: siphon |
| 22 | |
| 23 | # These should be passed in by the root Makefile |
| 24 | WS_ROOT ?= $(CURDIR)/../.. |
| 25 | BR ?= $(WS_ROOT)/build-root |
| 26 | |
| 27 | # Tag used in github repository path. |
| 28 | # Change this when genearting for a release |
| 29 | VPP_TAG ?= master |
| 30 | |
| 31 | REPOSITORY_URL ?= https://github.com/FDio/vpp/blob/$(VPP_TAG)/ |
| 32 | |
| 33 | # Doxygen configuration and our utility scripts |
| 34 | SCRIPTS_DIR ?= $(WS_ROOT)/docs/_scripts |
| 35 | |
| 36 | # docs root directory |
| 37 | DOCS_DIR ?= ${BR}/docs/src |
| 38 | |
| 39 | FEATURE_LIST_FILE = ${DOCS_DIR}/aboutvpp/featurelist.md |
| 40 | |
| 41 | # Siphoned fragements are processed into here |
| 42 | DOCS_GENERATED_DIR ?= $(DOCS_DIR)/_generated |
| 43 | |
| 44 | # Siphoned fragments end up in here |
| 45 | SIPHON_INPUT_DIR ?= $(DOCS_GENERATED_DIR)/fragments |
| 46 | |
| 47 | DYNAMIC_RENDER_DIR ?= ${DOCS_GENERATED_DIR}/includes |
| 48 | |
| 49 | # Primary source directories |
| 50 | SIPHON_SRC ?= $(WS_ROOT)/src |
| 51 | SIPHON_SRC_DIRECTORIES = \ |
| 52 | $(shell find $(SIPHON_SRC) -name '*.md' -print | xargs dirname \ |
| 53 | | sort | uniq) \ |
| 54 | $(SIPHON_SRC)/vppinfra \ |
| 55 | $(SIPHON_SRC)/svm \ |
| 56 | $(SIPHON_SRC)/vlib \ |
| 57 | $(SIPHON_SRC)/vlibapi \ |
| 58 | $(SIPHON_SRC)/vlibmemory \ |
| 59 | $(SIPHON_SRC)/vnet \ |
| 60 | $(SIPHON_SRC)/vpp \ |
| 61 | $(SIPHON_SRC)/vpp-api \ |
| 62 | $(SIPHON_SRC)/examples |
| 63 | |
| 64 | # Input directories and files |
| 65 | SIPHON_INPUT ?= \ |
| 66 | $(wildcard $(WS_ROOT)/*.md) \ |
| 67 | $(wildcard $(SCRIPTS_DIR)/*.md) \ |
| 68 | $(SIPHON_SRC_DIRECTORIES) \ |
| 69 | $(SIPHON_SRC)/plugins \ |
| 70 | extras |
| 71 | |
| 72 | # Strip leading workspace path from input names |
| 73 | SIPHON_INPUT := $(subst $(WS_ROOT)/,,$(SIPHON_INPUT)) |
| 74 | |
| 75 | # Files to exclude, from pre-Doxygen steps, eg because they're |
| 76 | # selectively compiled. |
| 77 | # Examples would be to exclude non-DPDK related sources when |
| 78 | # there's a DPDK equivalent that conflicts. |
| 79 | # These must be left-anchored paths for the regexp below to work. |
| 80 | SIPHON_EXCLUDE ?= \ |
| 81 | $(SIPHON_SRC)/vpp-api/lua |
| 82 | |
| 83 | # Generate a regexp for filenames to exclude |
| 84 | SIPHON_EXCLUDE_REGEXP = ($(subst .,\.,$(shell echo '$(strip $(SIPHON_EXCLUDE))' | sed -e 's/ /|/g'))) |
| 85 | |
| 86 | # Include all the normal source directories in the include file path |
| 87 | SIPHON_INCLUDE_PATH = $(SIPHON_SRC_DIRECTORIES) |
| 88 | |
| 89 | # Find API header directories and include them in the header path. |
| 90 | # This is only useful if VPP and plugins are already built; nothing |
| 91 | # here depends on those targets. We don't build documentation for these |
| 92 | # header files, they're just added to the INCLUDE search path for Doxygen. |
| 93 | _vpp_br = $(shell find "$(BR)" -maxdepth 1 -type d \ |
| 94 | '(' -name build-vpp_debug-native -o -name build-vpp-native ')' -print \ |
| 95 | | sed -e 's@^$(WS_ROOT)/*@@' -e 1q) |
| 96 | ifneq ($(strip $(_vpp_br)),) |
| 97 | SIPHON_INCLUDE_PATH += \ |
| 98 | $(_vpp_br)/vlib-api \ |
| 99 | $(_vpp_br)/vpp |
| 100 | # Also include any plugin directories that exist |
| 101 | SIPHON_INCLUDE_PATH += \ |
| 102 | $(shell find $(WS_ROOT)/$(_vpp_br)/plugins -maxdepth 1 -type d | sed -e 's@^$(WS_ROOT)/*@@') |
| 103 | endif |
| 104 | |
| 105 | # Discover if we have CPP available |
| 106 | _cpp = $(shell which cpp) |
| 107 | ifneq ($(strip $(_cpp)),) |
| 108 | # Add whatever directories CPP normally includes to the header path |
| 109 | SIPHON_INCLUDE_PATH += $(shell set -e; $(_cpp) -v </dev/null 2>&1 | awk 'f&&/^ /{print $$1} /^\#include/{f=1}') |
| 110 | endif |
| 111 | |
| 112 | # All the siphon types we know about |
| 113 | SIPHONS ?= clicmd syscfg |
| 114 | |
| 115 | SIPHON_FILES = $(addprefix $(SIPHON_INPUT_DIR)/,$(addsuffix .siphon,$(SIPHONS))) |
| 116 | SIPHON_DOCS = $(addprefix $(DOCS_GENERATED_DIR)/,$(addsuffix .rst,$(SIPHONS))) |
| 117 | |
| 118 | BUILT_ON = $(shell date '+%d %B %Y') |
| 119 | VPP_VERSION = $(shell ${WS_ROOT}/src/scripts/version) |
| 120 | |
| 121 | .PHONY: featurelist |
| 122 | featurelist: |
| 123 | @( \ |
| 124 | cd $(WS_ROOT) && \ |
| 125 | find . -name FEATURE.yaml | \ |
| 126 | ./src/scripts/fts.py \ |
| 127 | --markdown \ |
| 128 | --repolink $(REPOSITORY_URL) > \ |
| 129 | $(FEATURE_LIST_FILE) ; \ |
| 130 | ) |
| 131 | |
| 132 | |
| 133 | .PHONY: includes-render |
| 134 | includes-render: |
| 135 | @mkdir -p "$(DYNAMIC_RENDER_DIR)" |
| 136 | @python3 $(SCRIPTS_DIR)/includes_renderer.py ${WS_ROOT} ${DYNAMIC_RENDER_DIR} |
| 137 | |
| 138 | .PHONY: template-index |
| 139 | template-index: |
| 140 | @sed -ie "s/__VPP_VERSION__/${VPP_VERSION}/g" ${DOCS_DIR}/index.rst |
| 141 | @sed -ie "s/__BUILT_ON__/${BUILT_ON}/g" ${DOCS_DIR}/index.rst |
Nathan Skrzypczak | cbb4e46 | 2021-10-13 12:40:42 +0200 | [diff] [blame] | 142 | @( \ |
| 143 | for f in $$(grep -l -R __REPOSITORY_URL__ ${DOCS_DIR} | grep -e '\.rst$$' -e '\.md$$' ) ;\ |
| 144 | do \ |
| 145 | if [ ! -z $${f} ]; then \ |
| 146 | echo "TEMPLATING $${f}" ;\ |
| 147 | sed -ie "s@__REPOSITORY_URL__@${REPOSITORY_URL}@g" $${f} ;\ |
| 148 | fi ;\ |
| 149 | done ; \ |
| 150 | ) |
Nathan Skrzypczak | 9ad39c0 | 2021-08-19 11:38:06 +0200 | [diff] [blame] | 151 | |
| 152 | .NOTPARALLEL: $(SIPHON_FILES) |
| 153 | $(SIPHON_FILES): $(SCRIPTS_DIR)/siphon-generate \ |
| 154 | $(addprefix,$(WSROOT),$(SIPHON_INPUT)) \ |
| 155 | $(wildcard $(SCRIPTS_DIR)/siphon/*.py) |
| 156 | @echo "Validating source tree..." |
| 157 | @set -e; for input in $(SIPHON_INPUT); do \ |
| 158 | if [ ! -e "$(WS_ROOT)/$$input" ]; then \ |
| 159 | echo "ERROR: Input path '$$input' does not exist." >&2; \ |
| 160 | exit 1; \ |
| 161 | fi; \ |
| 162 | done |
| 163 | @rm -rf "$(SIPHON_INPUT_DIR)" "$(DOCS_GENERATED_DIR)" |
| 164 | @mkdir -p "$(SIPHON_INPUT_DIR)" "$(DOCS_GENERATED_DIR)" |
| 165 | @touch $(SIPHON_INPUT_DIR)/files |
| 166 | @echo "Collating source file list for siphoning..." |
| 167 | @for input in $(SIPHON_INPUT); do \ |
| 168 | cd "$(WS_ROOT)"; \ |
| 169 | find "$$input" -type f \ |
| 170 | \( -name '*.[ch]' -or -name '*.dox' \) -print \ |
| 171 | | grep -v -E '^src/examples/' \ |
| 172 | | grep -v -E '^$(SIPHON_EXCLUDE_REGEXP)' \ |
| 173 | >> $(SIPHON_INPUT_DIR)/files; \ |
| 174 | done |
| 175 | @echo "Generating siphons..." |
| 176 | @set -e; \ |
| 177 | cd "$(WS_ROOT)"; \ |
| 178 | $(SCRIPTS_DIR)/siphon-generate \ |
| 179 | --output="$(SIPHON_INPUT_DIR)" \ |
| 180 | "@$(SIPHON_INPUT_DIR)/files" |
| 181 | |
| 182 | # Evaluate this to build a siphon doc output target for each desired |
| 183 | # output type: |
| 184 | # $(eval $(call siphon-process,file_extension,output_type_name)) |
| 185 | define siphon-process |
| 186 | $(DOCS_GENERATED_DIR)/%.$(1): $(SIPHON_INPUT_DIR)/%.siphon \ |
| 187 | $(SCRIPTS_DIR)/siphon-process \ |
| 188 | $(wildcard $(SCRIPTS_DIR)/siphon/*.py) \ |
| 189 | $(wildcard $(SCRIPTS_DIR)/siphon_templates/$(2)/*/*.$(1)) |
| 190 | @echo "Processing siphon for $(2) from $$(notdir $$<)..." |
| 191 | @set -e; \ |
| 192 | cd "$(WS_ROOT)"; \ |
| 193 | mkdir -p $(DOCS_GENERATED_DIR)/$$(basename $$(notdir $$<)).$(1).dir; \ |
| 194 | $(SCRIPTS_DIR)/siphon-process \ |
| 195 | --type=$$(basename $$(notdir $$<)) \ |
| 196 | --format=$(2) \ |
| 197 | --repolink=$(REPOSITORY_URL)/ \ |
| 198 | --outdir=$(DOCS_GENERATED_DIR)/$$(basename $$(notdir $$<)).$(1).dir \ |
| 199 | --output="$$@" \ |
| 200 | "$$<" |
| 201 | endef |
| 202 | |
| 203 | # Process the .siphon source fragments and render them into siphon flavored |
| 204 | # markdown documentation |
| 205 | .DELETE_ON_ERROR: $(SIPHON_DOCS) |
| 206 | $(eval $(call siphon-process,rst,markdown)) |
| 207 | |
| 208 | # This target can be used just to generate the siphoned things |
| 209 | .PHONY: siphon |
| 210 | siphon: $(SIPHON_DOCS) |
| 211 | @cp $(DOCS_GENERATED_DIR)/clicmd.rst $(DOCS_DIR)/cli-reference/index.rst |
| 212 | @cp -r $(DOCS_GENERATED_DIR)/clicmd.rst.dir $(DOCS_DIR)/cli-reference/clis |
| 213 | |
| 214 | .PHONY: generate |
| 215 | generate: siphon includes-render template-index featurelist |
| 216 | |
| 217 | .PHONY: clean |
| 218 | clean: |
| 219 | @rm -rf $(BR)/.siphon.dep |
| 220 | @rm -rf $(SCRIPTS_DIR)/siphon/__pycache__ |
| 221 | |