gen_pack.sh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #!/bin/bash
  2. # Version: 1.1
  3. # Date: 2020-04-29
  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. ############### EDIT BELOW ###############
  16. # Extend Path environment variable locally
  17. #
  18. if [ `uname -s` = "Linux" ]
  19. then
  20. CMSIS_PACK_PATH="/home/$USER/.arm/Packs/ARM/CMSIS/5.7.0/"
  21. PATH_TO_ADD="$CMSIS_PACK_PATH/CMSIS/Utilities/Linux64/"
  22. else
  23. CMSIS_PACK_PATH="$LOCALAPPDATA/Arm/Packs/ARM/CMSIS/5.7.0"
  24. PATH_TO_ADD="/C/Program Files/7-Zip/:$CMSIS_PACK_PATH/CMSIS/Utilities/Win32/:/C/xmllint/"
  25. fi
  26. [[ ":$PATH:" != *":$PATH_TO_ADD}:"* ]] && PATH="${PATH}:${PATH_TO_ADD}"
  27. echo $PATH_TO_ADD appended to PATH
  28. echo " "
  29. # Pack warehouse directory - destination
  30. PACK_WAREHOUSE=output/
  31. # Temporary pack build directory
  32. PACK_BUILD=build/
  33. # Specify directories included in pack relative to base directory
  34. # All directories:
  35. PACK_DIRS=`ls -d */`
  36. # Do not include the build directory if it is local
  37. PACK_DIRS=${PACK_DIRS//$PACK_BUILD/}
  38. PACK_DIRS=${PACK_DIRS//$PACK_WAREHOUSE/}
  39. # alternative: specify directory names to be added to pack base directory
  40. # PACK_DIRS="
  41. # Source
  42. # Include
  43. #"
  44. # Specify file names to be added to pack base directory
  45. PACK_BASE_FILES="
  46. License.txt
  47. README.md
  48. "
  49. ############ DO NOT EDIT BELOW ###########
  50. echo Starting CMSIS-Pack Generation: `date`
  51. # Zip utility check
  52. ZIP=7z
  53. type -a $ZIP
  54. errorlevel=$?
  55. if [ $errorlevel -gt 0 ]
  56. then
  57. echo "Error: No 7zip Utility found"
  58. echo "Action: Add 7zip to your path"
  59. echo " "
  60. exit
  61. fi
  62. # Pack checking utility check
  63. PACKCHK=PackChk
  64. type -a $PACKCHK
  65. errorlevel=$?
  66. if [ $errorlevel != 0 ]
  67. then
  68. echo "Error: No PackChk Utility found"
  69. echo "Action: Add PackChk to your path"
  70. echo "Hint: Included in CMSIS Pack:"
  71. echo "<pack_root_dir>/ARM/CMSIS/<version>/CMSIS/Utilities/<os>/"
  72. echo " "
  73. exit
  74. fi
  75. echo " "
  76. # XML syntax checking utility check
  77. XMLLINT=xmllint
  78. type -a $XMLLINT
  79. errorlevel=$?
  80. if [ $errorlevel != 0 ]
  81. then
  82. echo "Error: No xmllint found"
  83. echo "Action: Add xmllint to your path"
  84. echo " "
  85. exit
  86. fi
  87. echo " "
  88. # Locate Package Description file
  89. # check whether there is more than one pdsc file
  90. NUM_PDSCS=`ls -1 *.pdsc | wc -l`
  91. PACK_DESCRIPTION_FILE=`ls *.pdsc`
  92. if [ $NUM_PDSCS -lt 1 ]
  93. then
  94. echo "Error: No *.pdsc file found in current directory"
  95. echo " "
  96. elif [ $NUM_PDSCS -gt 1 ]
  97. then
  98. echo "Error: Only one PDSC file allowed in directory structure:"
  99. echo "Found:"
  100. echo "$PACK_DESCRIPTION_FILE"
  101. echo "Action: Delete unused pdsc files"
  102. echo " "
  103. exit
  104. fi
  105. SAVEIFS=$IFS
  106. IFS=.
  107. set $PACK_DESCRIPTION_FILE
  108. # Pack Vendor
  109. PACK_VENDOR=$1
  110. # Pack Name
  111. PACK_NAME=$2
  112. echo Generating Pack Version: for $PACK_VENDOR.$PACK_NAME
  113. echo " "
  114. IFS=$SAVEIFS
  115. #if $PACK_BUILD directory does not exist, create it.
  116. if [ ! -d $PACK_BUILD ]; then
  117. mkdir -p $PACK_BUILD
  118. fi
  119. # Copy files into build base directory: $PACK_BUILD
  120. # pdsc file is mandatory in base directory:
  121. cp -f ./$PACK_VENDOR.$PACK_NAME.pdsc ${PACK_BUILD}
  122. # directories
  123. echo Adding directories to pack:
  124. echo $PACK_DIRS
  125. echo " "
  126. for d in ${PACK_DIRS}
  127. do
  128. cp -r "$d" ${PACK_BUILD}
  129. done
  130. # files for base directory
  131. echo Adding files to pack:
  132. echo $PACK_BASE_FILES
  133. echo " "
  134. for f in $PACK_BASE_FILES
  135. do
  136. cp -f "$f" $PACK_BUILD/
  137. done
  138. # Run Schema Check (for Linux only):
  139. # sudo apt-get install libxml2-utils
  140. echo Running schema check for $PACK_VENDOR.$PACK_NAME.pdsc
  141. $XMLLINT --noout --schema ${CMSIS_PACK_PATH}/CMSIS/Utilities/PACK.xsd $PACK_BUILD/$PACK_VENDOR.$PACK_NAME.pdsc
  142. errorlevel=$?
  143. if [ $errorlevel -ne 0 ]; then
  144. echo "build aborted: Schema check of $PACK_VENDOR.$PACK_NAME.pdsc against PACK.xsd failed"
  145. echo " "
  146. exit
  147. fi
  148. # Run Pack Check and generate PackName file with version
  149. $PACKCHK $PACK_BUILD/$PACK_VENDOR.$PACK_NAME.pdsc -n PackName.txt -x M362
  150. errorlevel=$?
  151. if [ $errorlevel -ne 0 ]; then
  152. echo "build aborted: pack check failed"
  153. echo " "
  154. exit
  155. fi
  156. PACKNAME=`cat PackName.txt`
  157. rm -rf PackName.txt
  158. # Archiving
  159. # $ZIP a $PACKNAME
  160. echo creating pack file $PACKNAME
  161. #if $PACK_WAREHOUSE directory does not exist create it
  162. if [ ! -d $PACK_WAREHOUSE ]; then
  163. mkdir -p $PACK_WAREHOUSE
  164. fi
  165. pushd $PACK_WAREHOUSE
  166. PACK_WAREHOUSE=`pwd`
  167. popd
  168. pushd $PACK_BUILD
  169. "$ZIP" a $PACK_WAREHOUSE/$PACKNAME -tzip
  170. popd
  171. errorlevel=$?
  172. if [ $errorlevel -ne 0 ]; then
  173. echo "build aborted: archiving failed"
  174. exit
  175. fi
  176. echo "build of pack succeeded"
  177. # Clean up
  178. echo "cleaning up ..."
  179. rm -rf $PACK_BUILD
  180. echo " "
  181. echo Completed CMSIS-Pack Generation: `date`