]> begriffs open source - cmsis/blob - CMSIS/Documentation/Doxygen/gen_doc.sh
Doc: Varios alignment updates
[cmsis] / CMSIS / Documentation / Doxygen / gen_doc.sh
1 #!/usr/bin/env bash
2 # Version: 2.3
3 # Date: 2023-06-06
4 # This bash script generates CMSIS-Core documentation
5 #
6 # Pre-requisites:
7 # - bash shell (for Windows: install git for Windows)
8 # - doxygen 1.9.6
9 # - mscgen 0.20
10
11 set -o pipefail
12
13 # Set version of gen pack library
14 # For available versions see https://github.com/Open-CMSIS-Pack/gen-pack/tags.
15 # Use the tag name without the prefix "v", e.g., 0.7.0
16 REQUIRED_GEN_PACK_LIB="0.8.4"
17
18 DIRNAME=$(dirname $(readlink -f $0))
19 GENDIR=../html
20 REQ_DXY_VERSION="1.9.6"
21 REQ_MSCGEN_VERSION="0.20"
22
23 ############ DO NOT EDIT BELOW ###########
24
25 function install_lib() {
26   local URL="https://github.com/Open-CMSIS-Pack/gen-pack/archive/refs/tags/v$1.tar.gz"
27   local STATUS=$(curl -sLI "${URL}" | grep "^HTTP" | tail -n 1 | cut -d' ' -f2 || echo "$((600+$?))")
28   if [[ $STATUS -ge 400 ]]; then
29     echo "Wrong/unavailable gen-pack lib version '$1'!" >&2
30     echo "Check REQUIRED_GEN_PACK_LIB variable."  >&2
31     echo "For available versions see https://github.com/Open-CMSIS-Pack/gen-pack/tags." >&2
32     exit 1
33   fi
34   echo "Downloading gen-pack lib version '$1' to '$2' ..."
35   mkdir -p "$2"
36   curl -L "${URL}" -s | tar -xzf - --strip-components 1 -C "$2" || exit 1
37 }
38
39 function load_lib() {
40   if [[ -d ${GEN_PACK_LIB} ]]; then
41     . "${GEN_PACK_LIB}/gen-pack"
42     return 0
43   fi
44   local GLOBAL_LIB="/usr/local/share/gen-pack/${REQUIRED_GEN_PACK_LIB}"
45   local USER_LIB="${HOME}/.local/share/gen-pack/${REQUIRED_GEN_PACK_LIB}"
46   if [[ ! -d "${GLOBAL_LIB}" && ! -d "${USER_LIB}" ]]; then
47     echo "Required gen-pack lib not found!" >&2
48     install_lib "${REQUIRED_GEN_PACK_LIB}" "${USER_LIB}"
49   fi
50
51   if [[ -d "${GLOBAL_LIB}" ]]; then
52     . "${GLOBAL_LIB}/gen-pack"
53   elif [[ -d "${USER_LIB}" ]]; then
54     . "${USER_LIB}/gen-pack"
55   else
56     echo "Required gen-pack lib is not installed!" >&2
57     exit 1
58   fi
59 }
60
61 load_lib
62 find_git
63 find_doxygen "${REQ_DXY_VERSION}"
64 find_utility "mscgen" "-l | grep 'Mscgen version' | sed -r -e 's/Mscgen version ([^,]+),.*/\1/'" "${REQ_MSCGEN_VERSION}"
65
66 if [ -z "${VERSION_FULL}" ]; then
67   VERSION_FULL=$(git_describe "v")
68 fi
69
70 pushd "${DIRNAME}" > /dev/null
71
72 echo "Generating documentation ..."
73
74 function generate() {
75   pushd $1 > /dev/null
76   
77   projectName=$(grep -E "PROJECT_NAME\s+=" $1.dxy.in | sed -r -e 's/[^"]*"([^"]+)".*/\1/')
78   projectNumberFull="$2"
79   if [ -z "${projectNumberFull}" ]; then
80     projectNumberFull=$(grep -E "PROJECT_NUMBER\s+=" $1.dxy.in | sed -r -e 's/[^"]*"[^0-9]*(([0-9]+\.[0-9]+(\.[0-9]+)?(-.+)?)?)".*/\1/')
81   fi
82   if [ -z "${projectNumberFull}" ]; then
83     projectNumberFull="$(git rev-parse --short HEAD)"
84   fi
85   projectNumber="${projectNumberFull%+*}"
86   datetime=$(date -u +'%a %b %e %Y %H:%M:%S')
87   year=$(date -u +'%Y')
88
89   sed -e "s/{projectNumber}/${projectNumber}/" $1.dxy.in > $1.dxy
90
91   mkdir -p "${DIRNAME}/${GENDIR}/$1/"
92   # git_changelog -f html -p "v" > src/history.txt
93
94   echo "\"${UTILITY_DOXYGEN}\" $1.dxy"
95   "${UTILITY_DOXYGEN}" $1.dxy
96
97   mkdir -p "${DIRNAME}/${GENDIR}/$1/search/"
98   cp -f "${DIRNAME}/style_template/search.css" "${DIRNAME}/${GENDIR}/$1/search/"
99   cp -f "${DIRNAME}/style_template/navtree.js" "${DIRNAME}/${GENDIR}/$1/"
100   cp -f "${DIRNAME}/style_template/resize.js" "${DIRNAME}/${GENDIR}/$1/"
101
102   sed -e "s/{datetime}/${datetime}/" "${DIRNAME}/style_template/footer.js.in" \
103     | sed -e "s/{year}/${year}/" \
104     | sed -e "s/{projectName}/${projectName}/" \
105     | sed -e "s/{projectNumber}/${projectNumber}/" \
106     | sed -e "s/{projectNumberFull}/${projectNumberFull}/" \
107     > "${DIRNAME}/${GENDIR}/$1/footer.js"
108
109   popd > /dev/null
110 }
111
112 generate "General" "${VERSION_FULL}"
113 generate "Core"
114 generate "Core_A"
115 generate "Driver"
116 generate "RTOS2"
117 generate "DSP"
118 generate "NN"
119 generate "View"
120 generate "Compiler"
121 generate "Toolbox"
122 generate "Stream"
123 generate "DAP"
124 generate "Zone"
125
126 cp -f "${DIRNAME}/index.html" "${DIRNAME}/../html/"
127
128 popd > /dev/null
129
130 exit 0