blob: b330feb3bf4d343d7a1e852346d5a6be056812e0 [file] [log] [blame]
Robert Rostohar8efa9d92020-04-16 16:12:16 +02001#!/bin/bash
2# Version: 1.1
3# Date: 2020-05-14
4# This bash script generates a CMSIS Software Pack:
5#
6# Pre-requisites:
7# - bash shell (for Windows: install git for Windows)
8# - 7z in path (zip archiving utility)
9# e.g. Ubuntu: sudo apt-get install p7zip-full p7zip-rar)
10# - PackChk is taken from latest install CMSIS Pack installed in $CMSIS_PACK_ROOT
11# - xmllint in path (XML schema validation; available only for Linux)
12
13############### EDIT BELOW ###############
14# Extend Path environment variable locally
15#
16
17OS=$(uname -s)
18case $OS in
19 'Linux')
20 if [ -z ${CMSIS_PACK_ROOT+x} ] ; then
21 CMSIS_PACK_ROOT="/home/$USER/.arm/Packs"
22 fi
23 CMSIS_TOOLSDIR="$(ls -drv ${CMSIS_PACK_ROOT}/ARM/CMSIS/* | head -1)/CMSIS/Utilities/Linux64"
24 ;;
25 'WindowsNT'|MINGW*|CYGWIN*)
26 if [ -z ${CMSIS_PACK_ROOT+x} ] ; then
27 CMSIS_PACK_ROOT="$LOCALAPPDATA/Arm/Packs"
28 fi
29 CMSIS_PACK_ROOT="/$(echo ${CMSIS_PACK_ROOT} | sed -e 's/\\/\//g' -e 's/://g' -e 's/\"//g')"
30 CMSIS_TOOLSDIR="$(ls -drv ${CMSIS_PACK_ROOT}/ARM/CMSIS/* | head -1)/CMSIS/Utilities/Win32"
31 ;;
32 'Darwin')
33 echo "Error: CMSIS Tools not available for Mac at present."
34 exit 1
35 ;;
36 *)
37 echo "Error: unrecognized OS $OS"
38 exit 1
39 ;;
40esac
41
42PATH_TO_ADD="$CMSIS_TOOLSDIR"
43
44[[ ":$PATH:" != *":$PATH_TO_ADD}:"* ]] && PATH="${PATH}:${PATH_TO_ADD}"
45echo $PATH_TO_ADD appended to PATH
46echo " "
47
48# Pack warehouse directory - destination
49PACK_WAREHOUSE=./output
50
51# Temporary pack build directory
52PACK_BUILD=./build
53
54# Specify directories included in pack relative to base directory
55# All directories:
56PACK_DIRS=`ls -d */`
57# Do not include the build directory if it is local
58PACK_DIRS=${PACK_DIRS//$PACK_BUILD/}
59PACK_DIRS=${PACK_DIRS//$PACK_WAREHOUSE/}
60
61# alternative: specify directory names to be added to pack base directory
62# PACK_DIRS="
63# Source
64# Include
65#"
66
67# Specify file names to be added to pack base directory
68PACK_BASE_FILES="
69 BuildMbedCrypto.cmake
70 CMakeLists.txt
71 CommonConfig.cmake
72 dco.txt
73 license.rst
74 readme.rst
75"
76
77############ DO NOT EDIT BELOW ###########
78echo Starting CMSIS-Pack Generation: `date`
79# Zip utility check
80ZIP=7z
81type -a "${ZIP}"
82errorlevel=$?
83if [ $errorlevel -gt 0 ]
84 then
85 echo "Error: No 7zip Utility found"
86 echo "Action: Add 7zip to your path"
87 echo " "
88 exit
89fi
90
91# Pack checking utility check
92PACKCHK=PackChk
93type -a ${PACKCHK}
94errorlevel=$?
95if [ $errorlevel != 0 ]
96 then
97 echo "Error: No PackChk Utility found"
98 echo "Action: Add PackChk to your path"
99 echo "Hint: Included in CMSIS Pack:"
100 echo "$CMSIS_PACK_ROOT/ARM/CMSIS/<version>/CMSIS/Utilities/<os>/"
101 echo " "
102 exit
103fi
104echo " "
105
106# Locate Package Description file
107# check whether there is more than one pdsc file
108NUM_PDSCS=`ls -1 *.pdsc | wc -l`
109PACK_DESCRIPTION_FILE=`ls *.pdsc`
110if [ ${NUM_PDSCS} -lt 1 ]
111 then
112 echo "Error: No *.pdsc file found in current directory"
113 echo " "
114elif [ ${NUM_PDSCS} -gt 1 ]
115 then
116 echo "Error: Only one PDSC file allowed in directory structure:"
117 echo "Found:"
118 echo "$PACK_DESCRIPTION_FILE"
119 echo "Action: Delete unused pdsc files"
120 echo " "
121 exit
122fi
123
124SAVEIFS=$IFS
125IFS=.
126set ${PACK_DESCRIPTION_FILE}
127# Pack Vendor
128PACK_VENDOR=$1
129# Pack Name
130PACK_NAME=$2
131echo "Generating Pack Version: for $PACK_VENDOR.$PACK_NAME"
132echo " "
133IFS=$SAVEIFS
134
135#if $PACK_BUILD directory does not exist, create it.
136if [ ! -d "$PACK_BUILD" ]; then
137 mkdir -p "$PACK_BUILD"
138fi
139
140# Copy files into build base directory: $PACK_BUILD
141# pdsc file is mandatory in base directory:
142cp -f "./${PACK_VENDOR}.${PACK_NAME}.pdsc" "${PACK_BUILD}"
143
144# directories
145echo Adding directories to pack:
146echo "${PACK_DIRS}"
147echo " "
148for d in ${PACK_DIRS}
149do
150 cp -r "$d" "${PACK_BUILD}"
151done
152
153# files for base directory
154echo Adding files to pack:
155echo "${PACK_BASE_FILES}"
156echo " "
157if [ ! -x ${PACK_BASE_FILES+x} ]; then
158 for f in ${PACK_BASE_FILES}
159 do
160 cp -f "$f" $PACK_BUILD/
161 done
162fi
163
164# Run Schema Check (for Linux only):
165# sudo apt-get install libxml2-utils
166
167if [ $(uname -s) = "Linux" ]
168 then
169 echo "Running schema check for ${PACK_VENDOR}.${PACK_NAME}.pdsc"
170 xmllint --noout --schema "${CMSIS_TOOLSDIR}/../PACK.xsd" "${PACK_BUILD}/${PACK_VENDOR}.${PACK_NAME}.pdsc"
171 errorlevel=$?
172 if [ $errorlevel -ne 0 ]; then
173 echo "build aborted: Schema check of $PACK_VENDOR.$PACK_NAME.pdsc against PACK.xsd failed"
174 echo " "
175 exit
176 fi
177else
178 echo "Use MDK PackInstaller to run schema validation for $PACK_VENDOR.$PACK_NAME.pdsc"
179fi
180
181# Run Pack Check and generate PackName file with version
182"${PACKCHK}" "${PACK_BUILD}/${PACK_VENDOR}.${PACK_NAME}.pdsc" -i "${CMSIS_PACK_ROOT}/.Web/ARM.mbedCrypto.pdsc" -n PackName.txt -x M362
183errorlevel=$?
184if [ $errorlevel -ne 0 ]; then
185 echo "build aborted: pack check failed"
186 echo " "
187 exit
188fi
189
190PACKNAME=$(cat PackName.txt)
191rm -rf PackName.txt
192
193# Archiving
194# $ZIP a $PACKNAME
195echo "creating pack file $PACKNAME"
196#if $PACK_WAREHOUSE directory does not exist create it
197if [ ! -d "$PACK_WAREHOUSE" ]; then
198 mkdir -p "$PACK_WAREHOUSE"
199fi
200pushd "$PACK_WAREHOUSE"
201PACK_WAREHOUSE=$(pwd)
202popd
203pushd "$PACK_BUILD"
204PACK_BUILD=$(pwd)
205"$ZIP" a "$PACK_WAREHOUSE/$PACKNAME" -tzip
206popd
207errorlevel=$?
208if [ $errorlevel -ne 0 ]; then
209 echo "build aborted: archiving failed"
210 exit
211fi
212
213echo "build of pack succeeded"
214# Clean up
215echo "cleaning up ..."
216
217rm -rf "$PACK_BUILD"
218echo " "
219
220echo Completed CMSIS-Pack Generation: $(date)