1- # SPDX-FileCopyrightText: 2026 Intel Corporation
21# SPDX-FileCopyrightText: 2021 Open Networking Foundation <info@opennetworking.org>
32# SPDX-License-Identifier: Apache-2.0
43
@@ -16,19 +15,7 @@ BUILDDIR ?= _build
1615# name of python virtualenv that is used to run commands
1716VENV_NAME := venv-docs
1817
19- # Git repository information for versioning
20- GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown")
21- GIT_TAG := $(shell git describe --tags --exact-match 2>/dev/null || echo "")
22- VERSION_TAGS := $(shell git tag --sort=-version:refname | head -3)
23-
24- # Temporary directory for git worktrees
25- WORKTREE_DIR := $(BUILDDIR ) /worktrees
26-
27- # Use variable for file location
28- VERSION_INDEX_TEMPLATE = _templates/version_index.html
29-
30- .PHONY : help Makefile test doc8 dict-check sort-dict license clean clean-all \
31- multiversion add-nojekyll create-version-index version-info clean-worktrees
18+ .PHONY : help Makefile test doc8 dict-check sort-dict license clean clean-all
3219
3320# Put it first so that "make" without argument is like "make help".
3421help : $(VENV_NAME )
@@ -71,106 +58,11 @@ clean:
7158clean-all : clean
7259 rm -rf $(VENV_NAME )
7360
74- # Clean up git worktrees
75- clean-worktrees :
76- @echo " Cleaning up git worktrees..."
77- @if [ -d " $( WORKTREE_DIR) " ]; then \
78- for worktree in $( WORKTREE_DIR) /* ; do \
79- if [ -d " $$ worktree" ]; then \
80- echo " Removing worktree: $$ worktree" ; \
81- git worktree remove " $$ worktree" 2> /dev/null || rm -rf " $$ worktree" ; \
82- fi ; \
83- done ; \
84- rmdir " $( WORKTREE_DIR) " 2> /dev/null || true ; \
85- fi
86-
87- # Ensure .nojekyll file exists for GitHub Pages
88- add-nojekyll :
89- @echo " Adding .nojekyll file for GitHub Pages..."
90- @if [ -d " $( BUILDDIR) /html" ]; then \
91- touch " $( BUILDDIR) /html/.nojekyll" ; \
92- echo " Created .nojekyll in $( BUILDDIR) /html/" ; \
93- fi
94- @if [ -d " $( BUILDDIR) /multiversion" ]; then \
95- touch " $( BUILDDIR) /multiversion/.nojekyll" ; \
96- echo " Created .nojekyll in $( BUILDDIR) /multiversion/" ; \
97- fi
98-
99- # Build single version (current branch/tag)
100- build : $(VENV_NAME ) Makefile
101- source $< /bin/activate ; set -u ; \
102- $(SPHINXBUILD ) -b html " $( SOURCEDIR) " " $( BUILDDIR) /html" $(SPHINXOPTS )
103- $(MAKE ) add-nojekyll
104- @echo " Documentation built successfully!"
105- @echo " Open $( BUILDDIR) /html/index.html in your browser"
106-
107- # Build multiple versions
108- multiversion : $(VENV_NAME ) Makefile clean-worktrees
109- @echo " Building multi-version documentation..."
110- @echo " Current branch: $( GIT_BRANCH) "
111- @echo " Available tags: $( VERSION_TAGS) "
112- rm -rf " $( BUILDDIR) /multiversion"
113- mkdir -p " $( BUILDDIR) /multiversion"
114- mkdir -p " $( WORKTREE_DIR) "
115- @echo " Building latest version from current working directory..."
61+ # build multiple versions
62+ multiversion : $(VENV_NAME ) Makefile
11663 source $< /bin/activate ; set -u ; \
117- $(SPHINXBUILD ) -b html " $( SOURCEDIR) " " $( BUILDDIR) /multiversion/latest" $(SPHINXOPTS )
118- @if [ -n " $( VERSION_TAGS) " ]; then \
119- for tag in $( VERSION_TAGS) ; do \
120- echo " Building documentation for tag: $$ tag using git worktree..." ; \
121- worktree_path=" $( WORKTREE_DIR) /$$ tag" ; \
122- if git worktree add " $$ worktree_path" " $$ tag" 2> /dev/null; then \
123- echo " Created worktree for $$ tag at $$ worktree_path" ; \
124- source $< /bin/activate ; set -u ; \
125- $(SPHINXBUILD ) -b html " $$ worktree_path" " $( BUILDDIR) /multiversion/$$ tag" $(SPHINXOPTS ) || echo " Warning: Failed to build $$ tag" ; \
126- git worktree remove " $$ worktree_path" 2> /dev/null || echo " Warning: Failed to remove worktree $$ worktree_path" ; \
127- else \
128- echo " Warning: Could not create worktree for tag $$ tag" ; \
129- fi ; \
130- done ; \
131- else \
132- echo " No version tags found, building only latest version" ; \
133- fi
134- $(MAKE ) create-version-index
135- $(MAKE ) add-nojekyll
136- $(MAKE ) clean-worktrees
137- @echo " Multi-version documentation built successfully!"
138- @echo " Open $( BUILDDIR) /multiversion/index.html in your browser"
139-
140- # Create version selection index page
141- create-version-index :
142- @echo " Creating version index page..."
143- @mkdir -p " $( BUILDDIR) /multiversion"
144- @if [ ! -f " $( VERSION_INDEX_TEMPLATE) " ]; then \
145- echo " Error: Template file $( VERSION_INDEX_TEMPLATE) not found" ; \
146- exit 1; \
147- fi
148- @cp " $( VERSION_INDEX_TEMPLATE) " " $( BUILDDIR) /multiversion/index.html"
149- @if [ -n " $( VERSION_TAGS) " ]; then \
150- version_cards=" " ; \
151- for tag in $( VERSION_TAGS) ; do \
152- version_cards=" $$ version_cards <a href=\" $$ tag/\" class=\" version-card\" >" $$ ' \n' ; \
153- version_cards=" $$ version_cards <div class=\" version-title\" >$$ tag</div>" $$ ' \n' ; \
154- version_cards=" $$ version_cards <div class=\" version-desc\" >Release $$ tag documentation</div>" $$ ' \n' ; \
155- version_cards=" $$ version_cards </a>" $$ ' \n' ; \
156- done ; \
157- sed -i.bak " s|{{VERSION_CARDS}}|$$ version_cards|g" " $( BUILDDIR) /multiversion/index.html" ; \
158- rm -f " $( BUILDDIR) /multiversion/index.html.bak" ; \
159- else \
160- sed -i.bak " s|{{VERSION_CARDS}}||g" " $( BUILDDIR) /multiversion/index.html" ; \
161- rm -f " $( BUILDDIR) /multiversion/index.html.bak" ; \
162- fi
163-
164- # Show current version information
165- version-info :
166- @echo " === Version Information ==="
167- @echo " Git Branch: $( GIT_BRANCH) "
168- @echo " Git Tag: $( GIT_TAG) "
169- @echo " Recent Tags: $( VERSION_TAGS) "
170- @if [ -f " VERSION" ]; then echo " Version File: $$ (cat VERSION)" ; fi
171- @echo " Build Directory: $( BUILDDIR) "
172- @echo " Worktree Directory: $( WORKTREE_DIR) "
173- @echo " =========================="
64+ sphinx-multiversion " $( SOURCEDIR) " " $( BUILDDIR) /multiversion" $(SPHINXOPTS )
65+ cp " $( SOURCEDIR) /_templates/meta_refresh.html" " $( BUILDDIR) /multiversion/index.html"
17466
17567# Catch-all target: route all unknown targets to Sphinx using the new
17668# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
0 commit comments