1#!/usr/bin/env bash
2# Version: 3.0
3# Date: 2023-11-06
4# This bash script generates CMSIS-DSP Documentation:
5#
6# Pre-requisites:
7# - bash shell (for Windows: install git for Windows)
8# - doxygen 1.9.6
9# - linkchecker (can be skipped with -s)
10
11set -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
16REQUIRED_GEN_PACK_LIB="0.9.1"
17
18DIRNAME=$(dirname "$(readlink -f "$0")")
19GENDIR=../html
20REQ_DXY_VERSION="1.9.6"
21
22RUN_LINKCHECKER=1
23
24function usage() {
25  echo "Usage: $(basename "$0") [-h] [-s] [-c <comp>]"
26  echo " -h,--help               Show usage"
27  echo " -s,--no-linkcheck       Skip linkcheck"
28  echo "                         Can be given multiple times. Defaults to all components."
29}
30
31while [[ $# -gt 0 ]]; do
32  case $1 in
33    '-h'|'help')
34      usage
35      exit 1
36    ;;
37    '-s'|'--no-linkcheck')
38      RUN_LINKCHECKER=0
39    ;;
40    *)
41      echo "Invalid command line argument: $1" >&2
42      usage
43      exit 1
44    ;;
45  esac
46  shift # past argument
47done
48
49############ DO NOT EDIT BELOW ###########
50
51# Set GEN_PACK_LIB_PATH to use a specific gen-pack library root
52# ... instead of bootstrap based on REQUIRED_GEN_PACK_LIB
53if [[ -f "${GEN_PACK_LIB_PATH}/gen-pack" ]]; then
54  . "${GEN_PACK_LIB_PATH}/gen-pack"
55else
56  . <(curl -sL "https://raw.githubusercontent.com/Open-CMSIS-Pack/gen-pack/main/bootstrap")
57fi
58
59find_git
60find_doxygen "${REQ_DXY_VERSION}"
61[[ ${RUN_LINKCHECKER} != 0 ]] && find_linkchecker
62
63if [ -z "${VERSION_FULL}" ]; then
64  VERSION_FULL=$(git_describe "v")
65fi
66
67pushd "${DIRNAME}" > /dev/null || exit 1
68
69echo "Generating documentation ..."
70
71projectName=$(grep -E "PROJECT_NAME\s+=" dsp.dxy.in | sed -r -e 's/[^"]*"([^"]+)".*/\1/')
72projectNumberFull="${VERSION_FULL}"
73projectNumber="${projectNumberFull%+*}"
74datetime=$(date -u +'%a %b %e %Y %H:%M:%S')
75year=$(date -u +'%Y')
76
77sed -e "s/{projectNumber}/${projectNumber}/" dsp.dxy.in \
78  | sed -e "s/{cmsisProjectNumber}/${cmsisProjectNumber}/" \
79  > dsp.dxy
80
81git_changelog -f html -p "v" > src/history.txt
82
83echo_log "\"${UTILITY_DOXYGEN}\" dsp.dxy"
84"${UTILITY_DOXYGEN}" dsp.dxy
85
86mkdir -p "${DIRNAME}/${GENDIR}/search/"
87cp -f "${DIRNAME}/style_template/search.css" "${DIRNAME}/${GENDIR}/search/"
88cp -f "${DIRNAME}/style_template/navtree.js" "${DIRNAME}/${GENDIR}/"
89cp -f "${DIRNAME}/style_template/resize.js" "${DIRNAME}/${GENDIR}/"
90
91sed -e "s/{datetime}/${datetime}/" "${DIRNAME}/style_template/footer.js.in" \
92  | sed -e "s/{year}/${year}/" \
93  | sed -e "s/{projectName}/${projectName}/" \
94  | sed -e "s/{projectNumber}/${projectNumber}/" \
95  | sed -e "s/{projectNumberFull}/${projectNumberFull}/" \
96  > "${DIRNAME}/${GENDIR}/footer.js"
97
98popd > /dev/null || exit 1
99
100[[ ${RUN_LINKCHECKER} != 0 ]] && check_links "${DIRNAME}/../html/index.html" "${DIRNAME}"
101
102
103exit 0
104