1#!/bin/bash
2# Version: 1.0
3# Date: 2022-05-31
4# This bash script generates CMSIS-NN Documentation:
5#
6# Pre-requisites:
7# - bash shell (for Windows: install git for Windows)
8# - doxygen 1.9.2
9
10set -o pipefail
11
12DIRNAME=$(dirname $(readlink -f $0))
13DOXYGEN=$(which doxygen)
14DESCRIBE=$(readlink -f ${DIRNAME}/../Scripts/git/git_describe.sh)
15CHANGELOG=$(readlink -f ${DIRNAME}/../Scripts/git/gen_changelog.sh)
16
17
18if [[ ! -f "${DOXYGEN}" ]]; then
19  echo "Doxygen not found!" >&2
20  echo "Did you miss to add it to PATH?"
21  exit 1
22else
23  version=$("${DOXYGEN}" --version)
24  echo "DOXYGEN is ${DOXYGEN} at version ${version}"
25  if [[ "${version}" != "1.9.2" ]]; then
26    echo " >> Version is different from 1.9.2 !" >&2
27  fi
28fi
29
30if [ -z $VERSION ]; then
31  VERSION_FULL=$(/bin/bash ${DESCRIBE} "v")
32  VERSION=${VERSION_FULL%+*}
33fi
34
35echo "Generating documentation ..."
36
37pushd $DIRNAME > /dev/null
38
39rm -rf ${DIRNAME}/../Documentation/html
40sed -e "s/{projectNumber}/${VERSION}/" "${DIRNAME}/dsp.dxy.in" \
41  > "${DIRNAME}/dsp.dxy"
42
43echo "${CHANGELOG} -f html > history.txt"
44/bin/bash "${CHANGELOG}" -f html 1> history.txt 2>/dev/null
45
46echo "${DOXYGEN} dsp.dxy"
47"${DOXYGEN}" dsp.dxy
48popd > /dev/null
49
50if [[ $2 != 0 ]]; then
51  cp -f "${DIRNAME}/templates/search.css" "${DIRNAME}/../Documentation/html/search/"
52fi
53
54projectName=$(grep -E "PROJECT_NAME\s+=" "${DIRNAME}/dsp.dxy" | sed -r -e 's/[^"]*"([^"]+)"/\1/')
55datetime=$(date -u +'%a %b %e %Y %H:%M:%S')
56year=$(date -u +'%Y')
57if [[ "${year}" != "2022" ]]; then
58  year="2022-${year}"
59fi
60sed -e "s/{datetime}/${datetime}/" "${DIRNAME}/templates/footer.js.in" \
61  | sed -e "s/{year}/${year}/" \
62  | sed -e "s/{projectName}/${projectName}/" \
63  | sed -e "s/{projectNumber}/${VERSION}/" \
64  | sed -e "s/{projectNumberFull}/${VERSION_FULL}/" \
65  > "${DIRNAME}/../Documentation/html/footer.js"
66
67exit 0