gen_pack.sh 4.6 KB

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