]> begriffs open source - cmsis-freertos/blob - DoxyGen/gen_doc.sh
Update documentation and add support Open-CMSIS-Pack/gen-pack
[cmsis-freertos] / DoxyGen / gen_doc.sh
1 #!/bin/bash
2 # Version: 1.0
3 # Date: 2022-12-14
4 # This bash script generates CMSIS-FreeRTOS documentation
5 #
6 # Pre-requisites:
7 # - bash shell (for Windows: install git for Windows)
8 # - doxygen 1.9.2
9
10 set -o pipefail
11
12 # Set version of gen pack library
13 REQUIRED_GEN_PACK_LIB="0.6.0"
14
15 DIRNAME=$(dirname $(readlink -f $0))
16 DOXYGEN=$(which doxygen 2>/dev/null)
17 REQ_DXY_VERSION="1.9.2"
18
19 if [[ ! -f "${DOXYGEN}" ]]; then
20     echo "Doxygen not found!" >&2
21     echo "Did you miss to add it to PATH?"
22     exit 1
23 else
24     version=$("${DOXYGEN}" --version | sed -E 's/.*([0-9]+\.[0-9]+\.[0-9]+).*/\1/')
25     echo "Doxygen is ${DOXYGEN} at version ${version}"
26     if [[ "${version}" != "${REQ_DXY_VERSION}" ]]; then
27         echo "Doxygen required to be at version ${REQ_DXY_VERSION}!" >&2
28         exit 1
29     fi
30 fi
31
32 ############ DO NOT EDIT BELOW ###########
33
34 function install_lib() {
35   local URL="https://github.com/Open-CMSIS-Pack/gen-pack/archive/refs/tags/v$1.tar.gz"
36   echo "Downloading gen_pack lib to '$2'"
37   mkdir -p "$2"
38   curl -L "${URL}" -s | tar -xzf - --strip-components 1 -C "$2" || exit 1
39 }
40
41 function load_lib() {
42   if [[ -d ${GEN_PACK_LIB} ]]; then
43     . "${GEN_PACK_LIB}/gen-pack"
44     return 0
45   fi
46   local GLOBAL_LIB="/usr/local/share/gen-pack/${REQUIRED_GEN_PACK_LIB}"
47   local USER_LIB="${HOME}/.local/share/gen-pack/${REQUIRED_GEN_PACK_LIB}"
48   if [[ ! -d "${GLOBAL_LIB}" && ! -d "${USER_LIB}" ]]; then
49     echo "Required gen-pack lib not found!" >&2
50     install_lib "${REQUIRED_GEN_PACK_LIB}" "${USER_LIB}"
51   fi
52
53   if [[ -d "${GLOBAL_LIB}" ]]; then
54     . "${GLOBAL_LIB}/gen-pack"
55   elif [[ -d "${USER_LIB}" ]]; then
56     . "${USER_LIB}/gen-pack"
57   else
58     echo "Required gen-pack lib is not installed!" >&2
59     exit 1
60   fi
61 }
62
63 load_lib
64 find_git
65
66 if [ -z $VERSION ]; then
67   VERSION_FULL=$(git_describe "v")
68   VERSION=${VERSION_FULL%+*}
69 fi
70
71 pushd "${DIRNAME}" > /dev/null
72
73 echo "Generating documentation ..."
74
75 sed -e "s/{projectNumber}/${VERSION}/" freertos.dxy.in > freertos.dxy
76
77 git_changelog -f html -p "v" > src/history.txt
78
79 echo "\"${DOXYGEN}\" freertos.dxy"
80 "${DOXYGEN}" freertos.dxy
81
82 if [[ $2 != 0 ]]; then
83   mkdir -p "${DIRNAME}/../Documentation/html/search/"
84   cp -f "${DIRNAME}/templates/search.css" "${DIRNAME}/../Documentation/html/search/"
85 fi
86
87 projectName=$(grep -E "PROJECT_NAME\s+=" freertos.dxy | sed -r -e 's/[^"]*"([^"]+)".*/\1/')
88 datetime=$(date -u +'%a %b %e %Y %H:%M:%S')
89 year=$(date -u +'%Y')
90 sed -e "s/{datetime}/${datetime}/" "${DIRNAME}/templates/footer.js.in" \
91   | sed -e "s/{year}/${year}/" \
92   | sed -e "s/{projectName}/${projectName}/" \
93   | sed -e "s/{projectNumber}/${VERSION}/" \
94   | sed -e "s/{projectNumberFull}/${VERSION_FULL}/" \
95   > "${DIRNAME}/../Documentation/html/footer.js"
96
97 popd  > /dev/null
98
99 exit 0