1#!/bin/bash 2# Version: 1.1 3# Date: 2022-01-11 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 in path with execute permission 11# (see CMSIS-Pack: CMSIS/Utilities/<os>/PackChk) 12# - xmllint in path (XML schema validation) 13# e.g. Ubuntu: sudo apt-get install libxml2-utils 14# Windows: download from https://www.zlatkovic.com/pub/libxml/ 15 16############### EDIT BELOW ############### 17# Extend Path environment variable locally 18# 19if [ `uname -s` = "Linux" ] 20 then 21 CMSIS_PACK_PATH="/home/$USER/.arm/Packs/ARM/CMSIS/5.7.0/" 22 PATH_TO_ADD="$CMSIS_PACK_PATH/CMSIS/Utilities/Linux64/" 23else 24 CMSIS_PACK_PATH="/C/Users/$USER/AppData/Local/Arm/Packs/ARM/CMSIS/5.7.0" 25 PATH_TO_ADD="/C/Program Files (x86)/7-Zip/:/C/Program Files/7-Zip/:$CMSIS_PACK_PATH/CMSIS/Utilities/Win32/:/C/xmllint/" 26fi 27[[ ":$PATH:" != *":$PATH_TO_ADD}:"* ]] && PATH="${PATH}:${PATH_TO_ADD}" 28echo $PATH_TO_ADD appended to PATH 29echo " " 30 31# Pack warehouse directory - destination 32PACK_WAREHOUSE=./ 33 34# Temporary pack build directory 35PACK_BUILD=build/ 36 37# Specify directories included in pack relative to base directory 38# All directories: 39# PACK_DIRS=`ls -d */` 40# Do not include the build directory if it is local 41# PACK_DIRS=${PACK_DIRS//$PACK_BUILD/} 42# PACK_DIRS=${PACK_DIRS//$PACK_WAREHOUSE/} 43 44# alternative: specify directory names to be added to pack base directory 45PACK_DIRS=" 46 ../../src 47 ../../docs 48 ../../demos 49" 50 51 52# Specify file names to be added to pack base directory 53PACK_BASE_FILES=" 54 ../../LICENCE.txt 55 ../../README.md 56 ../../README_zh.md 57 ../../lvgl.h 58 lv_conf_cmsis.h 59 lv_cmsis_pack.txt 60" 61 62############ DO NOT EDIT BELOW ########### 63echo Starting CMSIS-Pack Generation: `date` 64# Zip utility check 65ZIP=7z 66type -a $ZIP 67errorlevel=$? 68if [ $errorlevel -gt 0 ] 69 then 70 echo "Error: No 7zip Utility found" 71 echo "Action: Add 7zip to your path" 72 echo " " 73 exit 74fi 75 76# Pack checking utility check 77PACKCHK=PackChk 78type -a $PACKCHK 79errorlevel=$? 80if [ $errorlevel != 0 ] 81 then 82 echo "Error: No PackChk Utility found" 83 echo "Action: Add PackChk to your path" 84 echo "Hint: Included in CMSIS Pack:" 85 echo "<pack_root_dir>/ARM/CMSIS/<version>/CMSIS/Utilities/<os>/" 86 echo " " 87 exit 88fi 89echo " " 90 91# XML syntax checking utility check 92XMLLINT=xmllint 93type -a $XMLLINT 94errorlevel=$? 95if [ $errorlevel != 0 ] 96 then 97 echo "Error: No xmllint found" 98 echo "Action: Add xmllint to your path" 99 echo " " 100 exit 101fi 102echo " " 103 104# Locate Package Description file 105# check whether there is more than one pdsc file 106NUM_PDSCS=`ls -1 *.pdsc | wc -l` 107PACK_DESCRIPTION_FILE=`ls *.pdsc` 108if [ $NUM_PDSCS -lt 1 ] 109 then 110 echo "Error: No *.pdsc file found in current directory" 111 echo " " 112elif [ $NUM_PDSCS -gt 1 ] 113 then 114 echo "Error: Only one PDSC file allowed in directory structure:" 115 echo "Found:" 116 echo "$PACK_DESCRIPTION_FILE" 117 echo "Action: Delete unused pdsc files" 118 echo " " 119 exit 120fi 121 122SAVEIFS=$IFS 123IFS=. 124set $PACK_DESCRIPTION_FILE 125# Pack Vendor 126PACK_VENDOR=$1 127# Pack Name 128PACK_NAME=$2 129echo Generating Pack Version: for $PACK_VENDOR.$PACK_NAME 130echo " " 131IFS=$SAVEIFS 132 133#if $PACK_BUILD directory does not exist, create it. 134if [ ! -d $PACK_BUILD ]; then 135 mkdir -p $PACK_BUILD 136fi 137 138mkdir -p ${PACK_BUILD}/examples 139mkdir -p ${PACK_BUILD}/examples/porting 140 141# Copy files into build base directory: $PACK_BUILD 142# pdsc file is mandatory in base directory: 143cp -f ./$PACK_VENDOR.$PACK_NAME.pdsc ${PACK_BUILD} 144cp -f ../../examples/porting/* ${PACK_BUILD}/examples/porting 145 146 147# directories 148echo Adding directories to pack: 149echo $PACK_DIRS 150echo " " 151for d in ${PACK_DIRS} 152do 153 cp -r "$d" ${PACK_BUILD} 154done 155 156# files for base directory 157echo Adding files to pack: 158echo $PACK_BASE_FILES 159echo " " 160for f in $PACK_BASE_FILES 161do 162 cp -f "$f" $PACK_BUILD/ 163done 164 165mv "${PACK_BUILD}/lv_cmsis_pack.txt" "${PACK_BUILD}/lv_cmsis_pack.c" 166 167# Run Schema Check (for Linux only): 168# sudo apt-get install libxml2-utils 169 170echo Running schema check for $PACK_VENDOR.$PACK_NAME.pdsc 171$XMLLINT --noout --schema ${CMSIS_PACK_PATH}/CMSIS/Utilities/PACK.xsd $PACK_BUILD/$PACK_VENDOR.$PACK_NAME.pdsc 172errorlevel=$? 173if [ $errorlevel -ne 0 ]; then 174 echo "build aborted: Schema check of $PACK_VENDOR.$PACK_NAME.pdsc against PACK.xsd failed" 175 echo " " 176 exit 177fi 178 179# Run Pack Check and generate PackName file with version 180$PACKCHK $PACK_BUILD/$PACK_VENDOR.$PACK_NAME.pdsc -n PackName.txt -x M362 181errorlevel=$? 182if [ $errorlevel -ne 0 ]; then 183 echo "build aborted: pack check failed" 184 echo " " 185 exit 186fi 187 188PACKNAME=`cat PackName.txt` 189rm -rf PackName.txt 190 191echo remove unrequired files and folders... 192rm -rf $PACK_BUILD/demos/keypad_encoder 193rm -rf $PACK_BUILD/demos/music 194rm -rf $PACK_BUILD/demos/stress 195rm -rf $PACK_BUILD/demos/widgets/screenshot1.gif 196 197# echo apply patches... 198# rm -rf $PACK_BUILD/demos/lv_demos.h 199# cp -f ./lv_demos.h $PACK_BUILD/demos/ 200 201# Archiving 202# $ZIP a $PACKNAME 203echo creating pack file $PACKNAME 204#if $PACK_WAREHOUSE directory does not exist create it 205if [ ! -d $PACK_WAREHOUSE ]; then 206 mkdir -p $PACK_WAREHOUSE 207fi 208pushd $PACK_WAREHOUSE 209PACK_WAREHOUSE=`pwd` 210popd 211pushd $PACK_BUILD 212"$ZIP" a $PACK_WAREHOUSE/$PACKNAME -tzip 213popd 214errorlevel=$? 215if [ $errorlevel -ne 0 ]; then 216 echo "build aborted: archiving failed" 217 exit 218fi 219 220# cp -f ./$PACK_VENDOR.$PACK_NAME.pdsc ${PACK_WAREHOUSE} 221 222 223echo "build of pack succeeded" 224# Clean up 225echo "cleaning up ..." 226 227rm -rf $PACK_BUILD 228 229echo " " 230 231echo Completed CMSIS-Pack Generation: `date`