gen_pack.sh 3.5 KB

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