]> begriffs open source - cmsis/blob - gen_pack.sh
CMSIS-Driver: Added GPIO Driver API 1.0.0
[cmsis] / gen_pack.sh
1 #!/usr/bin/env bash
2 # Version: 2.7
3 # Date: 2023-05-23
4 # This bash script generates a CMSIS Software Pack:
5 #
6
7 set -o pipefail
8
9 # Set version of gen pack library
10 # For available versions see https://github.com/Open-CMSIS-Pack/gen-pack/tags.
11 # Use the tag name without the prefix "v", e.g., 0.7.0
12 REQUIRED_GEN_PACK_LIB="0.8.3"
13
14 # Set default command line arguments
15 DEFAULT_ARGS=(-c "v")
16
17 # Pack warehouse directory - destination
18 # Default: ./output
19 #
20 # PACK_OUTPUT=./output
21
22 # Temporary pack build directory,
23 # Default: ./build
24 #
25 # PACK_BUILD=./build
26
27 # Specify directory names to be added to pack base directory
28 # An empty list defaults to all folders next to this script.
29 # Default: empty (all folders)
30 #
31 PACK_DIRS="
32   CMSIS/Core
33   CMSIS/Core_A
34   CMSIS/Documentation
35   CMSIS/Driver
36   CMSIS/RTOS2
37 "
38
39 # Specify file names to be added to pack base directory
40 # Default: empty
41 #
42 PACK_BASE_FILES="
43   LICENSE.txt
44 "
45
46 # Specify file names to be deleted from pack build directory
47 # Default: empty
48 #
49 # PACK_DELETE_FILES=""
50
51 # Specify patches to be applied
52 # Default: empty
53 #
54 # PACK_PATCH_FILES=""
55
56 # Specify addition argument to packchk
57 # Default: empty
58 #
59 PACKCHK_ARGS=(-x M336)
60
61 # Specify additional dependencies for packchk
62 # Default: empty
63 #
64 PACKCHK_DEPS=" "
65
66 # Optional: restrict fallback modes for changelog generation
67 # Default: full
68 # Values:
69 # - full      Tag annotations, release descriptions, or commit messages (in order)
70 # - release   Tag annotations, or release descriptions (in order)
71 # - tag       Tag annotations only
72 #
73 PACK_CHANGELOG_MODE="tag"
74
75 #
76 # custom pre-processing steps
77 #
78 # usage: preprocess <build>
79 #   <build>  The build folder
80 #
81 function preprocess() {
82   # add custom steps here to be executed
83   # before populating the pack build folder
84   ./CMSIS/DoxyGen/gen_doc.sh
85   return 0
86 }
87
88 #
89 # custom post-processing steps
90 #
91 # usage: postprocess <build>
92 #   <build>  The build folder
93 #
94 function postprocess() {
95   # add custom steps here to be executed
96   # after populating the pack build folder
97   # but before archiving the pack into output folder
98   return 0
99 }
100
101 ############ DO NOT EDIT BELOW ###########
102
103 function install_lib() {
104   local URL="https://github.com/Open-CMSIS-Pack/gen-pack/archive/refs/tags/v$1.tar.gz"
105   local STATUS=$(curl -sLI "${URL}" | grep "^HTTP" | tail -n 1 | cut -d' ' -f2 || echo "$((600+$?))")
106   if [[ $STATUS -ge 400 ]]; then
107     echo "Wrong/unavailable gen-pack lib version '$1'!" >&2
108     echo "Check REQUIRED_GEN_PACK_LIB variable."  >&2
109     echo "For available versions see https://github.com/Open-CMSIS-Pack/gen-pack/tags." >&2
110     exit 1
111   fi
112   echo "Downloading gen-pack lib version '$1' to '$2' ..."
113   mkdir -p "$2"
114   curl -L "${URL}" -s | tar -xzf - --strip-components 1 -C "$2" || exit 1
115 }
116
117 function load_lib() {
118   if [[ -d ${GEN_PACK_LIB} ]]; then
119     . "${GEN_PACK_LIB}/gen-pack"
120     return 0
121   fi
122   local GLOBAL_LIB="/usr/local/share/gen-pack/${REQUIRED_GEN_PACK_LIB}"
123   local USER_LIB="${HOME}/.local/share/gen-pack/${REQUIRED_GEN_PACK_LIB}"
124   if [[ ! -d "${GLOBAL_LIB}" && ! -d "${USER_LIB}" ]]; then
125     echo "Required gen_pack lib not found!" >&2
126     install_lib "${REQUIRED_GEN_PACK_LIB}" "${USER_LIB}"
127   fi
128
129   if [[ -d "${GLOBAL_LIB}" ]]; then
130     . "${GLOBAL_LIB}/gen-pack"
131   elif [[ -d "${USER_LIB}" ]]; then
132     . "${USER_LIB}/gen-pack"
133   else
134     echo "Required gen-pack lib is not installed!" >&2
135     exit 1
136   fi
137 }
138
139 load_lib
140 gen_pack "${DEFAULT_ARGS[@]}" "$@"
141
142 exit 0