xref: /aosp_15_r20/external/flashrom/doc/sphinx-wrapper.sh (revision 0d6140be3aa665ecc836e8907834fcd3e3b018fc)
1#!/bin/sh
2
3OUTPUT_HOME="$1"
4MAN_OUTPUTS="$2"
5SPHINXBUILD="$3"
6shift 3
7
8"${SPHINXBUILD}" "$@" || exit $?
9
10SPHINXBUILD_MAJOR="$("${SPHINXBUILD}" --version | cut -d' ' -f2 | cut -d'.' -f1)"
11if [ "${SPHINXBUILD_MAJOR}" -ge 4 ]; then
12	exit 0
13fi
14
15# sphinx-build 3.x outputs man pages to "8" directory instead of expected "man8".
16# The following block checks for "man8" (and other output paths in ${MAN_OUTPUTS})
17# and, if that is missing, but "8" dir exists instead, it renames "8" to "man8"
18# and creates a symlink named "8" that points to "man8", so that anyone is happy
19# during the rest of current build and subsequent builds as well.
20
21for MAN_OUTPUT in ${MAN_OUTPUTS}; do
22	PATH_TARGET="${OUTPUT_HOME}/${MAN_OUTPUT}"
23	PATH_ACTUAL="${OUTPUT_HOME}/${MAN_OUTPUT#man}"
24	if [ -d "${PATH_ACTUAL}" -a ! -L "${PATH_ACTUAL}" ]; then
25		rm -rf "${PATH_TARGET}"
26		mv "${PATH_ACTUAL}" "${PATH_TARGET}"
27		ln -s "${MAN_OUTPUT}" "${PATH_ACTUAL}"
28	fi
29done
30