1#!/usr/bin/env bash
2#
3# SPDX-FileCopyrightText: Copyright 2022-2024 Arm Limited and/or its affiliates <open-source-office@arm.com>
4#
5# SPDX-License-Identifier: Apache-2.0
6#
7# Licensed under the Apache License, Version 2.0 (the License); you may
8# not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an AS IS BASIS, WITHOUT
15# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18#
19# Version: 3.0
20# Date: 2024-01-09
21# This bash script generates CMSIS-NN Documentation:
22#
23# Pre-requisites:
24# - bash shell (for Windows: install git for Windows)
25# - doxygen 1.9.6
26# - linkchecker (can be skipped with -s)
27
28set -o pipefail
29
30# Set version of gen pack library
31# For available versions see https://github.com/Open-CMSIS-Pack/gen-pack/tags.
32# Use the tag name without the prefix "v", e.g., 0.7.0
33REQUIRED_GEN_PACK_LIB="0.9.1"
34
35DIRNAME=$(dirname "$(readlink -f "$0")")
36GENDIR=../html
37REQ_DXY_VERSION="1.9.6"
38
39RUN_LINKCHECKER=1
40
41function usage() {
42  echo "Usage: $(basename "$0") [-h] [-s] [-c <comp>]"
43  echo " -h,--help               Show usage"
44  echo " -s,--no-linkcheck       Skip linkcheck"
45  echo "                         Can be given multiple times. Defaults to all components."
46}
47
48while [[ $# -gt 0 ]]; do
49  case $1 in
50    '-h'|'help')
51      usage
52      exit 1
53    ;;
54    '-s'|'--no-linkcheck')
55      RUN_LINKCHECKER=0
56    ;;
57    *)
58      echo "Invalid command line argument: $1" >&2
59      usage
60      exit 1
61    ;;
62  esac
63  shift # past argument
64done
65
66############ DO NOT EDIT BELOW ###########
67
68# Set GEN_PACK_LIB_PATH to use a specific gen-pack library root
69# ... instead of bootstrap based on REQUIRED_GEN_PACK_LIB
70if [[ -f "${GEN_PACK_LIB_PATH}/gen-pack" ]]; then
71  . "${GEN_PACK_LIB_PATH}/gen-pack"
72else
73  . <(curl -sL "https://raw.githubusercontent.com/Open-CMSIS-Pack/gen-pack/main/bootstrap")
74fi
75
76find_git
77find_doxygen "${REQ_DXY_VERSION}"
78[[ ${RUN_LINKCHECKER} != 0 ]] && find_linkchecker
79
80if [ -z "${VERSION_FULL}" ]; then
81  VERSION_FULL=$(git_describe "v")
82fi
83
84pushd "${DIRNAME}" > /dev/null || exit 1
85
86echo "Generating documentation ..."
87
88projectName=$(grep -E "PROJECT_NAME\s+=" nn.dxy.in | sed -r -e 's/[^"]*"([^"]+)".*/\1/')
89projectNumberFull="${VERSION_FULL}"
90projectNumber="${projectNumberFull%+*}"
91datetime=$(date -u +'%a %b %e %Y %H:%M:%S')
92year=$(date -u +'%Y')
93
94sed -e "s/{projectNumber}/${projectNumber}/" nn.dxy.in \
95  | sed -e "s/{cmsisProjectNumber}/${cmsisProjectNumber}/" \
96  > nn.dxy
97
98git_changelog -f html -p "v" > src/history.txt
99
100echo_log "\"${UTILITY_DOXYGEN}\" nn.dxy"
101"${UTILITY_DOXYGEN}" nn.dxy
102
103mkdir -p "${DIRNAME}/${GENDIR}/search/"
104cp -f "${DIRNAME}/style_template/search.css" "${DIRNAME}/${GENDIR}/search/"
105cp -f "${DIRNAME}/style_template/navtree.js" "${DIRNAME}/${GENDIR}/"
106cp -f "${DIRNAME}/style_template/resize.js" "${DIRNAME}/${GENDIR}/"
107
108sed -e "s/{datetime}/${datetime}/" "${DIRNAME}/style_template/footer.js.in" \
109  | sed -e "s/{year}/${year}/" \
110  | sed -e "s/{projectName}/${projectName}/" \
111  | sed -e "s/{projectNumber}/${projectNumber}/" \
112  | sed -e "s/{projectNumberFull}/${projectNumberFull}/" \
113  > "${DIRNAME}/${GENDIR}/footer.js"
114
115popd > /dev/null || exit 1
116
117[[ ${RUN_LINKCHECKER} != 0 ]] && check_links "${DIRNAME}/../html/index.html" "${DIRNAME}"
118
119
120exit 0
121