gen_pack.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. src
  27. inc
  28. port
  29. "
  30. # Specify file names to be added to pack base directory
  31. # Default: empty
  32. #
  33. PACK_BASE_FILES="
  34. LICENSE
  35. flash_blob.c
  36. flash_blob.h
  37. README.md
  38. "
  39. # Specify file names to be deleted from pack build directory
  40. # Default: empty
  41. #
  42. # PACK_DELETE_FILES="
  43. # "
  44. # Specify patches to be applied
  45. # Default: empty
  46. #
  47. # PACK_PATCH_FILES="
  48. # <list patches here>
  49. # "
  50. # Specify addition argument to packchk
  51. # Default: empty
  52. #
  53. # PACKCHK_ARGS=()
  54. # Specify additional dependencies for packchk
  55. # Default: empty
  56. #
  57. # PACKCHK_DEPS="
  58. # <list pdsc files here>
  59. # "
  60. # Optional: restrict fallback modes for changelog generation
  61. # Default: full
  62. # Values:
  63. # - full Tag annotations, release descriptions, or commit messages (in order)
  64. # - release Tag annotations, or release descriptions (in order)
  65. # - tag Tag annotations only
  66. #
  67. # PACK_CHANGELOG_MODE="<full|release|tag>"
  68. #
  69. # custom pre-processing steps
  70. #
  71. # usage: preprocess <build>
  72. # <build> The build folder
  73. #
  74. function preprocess() {
  75. # add custom steps here to be executed
  76. # before populating the pack build folder
  77. return 0
  78. }
  79. #
  80. # custom post-processing steps
  81. #
  82. # usage: postprocess <build>
  83. # <build> The build folder
  84. #
  85. function postprocess() {
  86. # add custom steps here to be executed
  87. # after populating the pack build folder
  88. # but before archiving the pack into output folder
  89. return 0
  90. }
  91. ############ DO NOT EDIT BELOW ###########
  92. function install_lib() {
  93. local URL="https://github.com/Open-CMSIS-Pack/gen-pack/archive/refs/tags/v$1.tar.gz"
  94. local STATUS=$(curl -sLI "${URL}" | grep "^HTTP" | tail -n 1 | cut -d' ' -f2 || echo "$((600+$?))")
  95. if [[ $STATUS -ge 400 ]]; then
  96. echo "Wrong/unavailable gen-pack lib version '$1'!" >&2
  97. echo "Check REQUIRED_GEN_PACK_LIB variable." >&2
  98. echo "For available versions see https://github.com/Open-CMSIS-Pack/gen-pack/tags." >&2
  99. exit 1
  100. fi
  101. echo "Downloading gen-pack lib version '$1' to '$2' ..."
  102. mkdir -p "$2"
  103. curl -L "${URL}" -s | tar -xzf - --strip-components 1 -C "$2" || exit 1
  104. }
  105. function load_lib() {
  106. if [[ -d ${GEN_PACK_LIB} ]]; then
  107. . "${GEN_PACK_LIB}/gen-pack"
  108. return 0
  109. fi
  110. local GLOBAL_LIB="/usr/local/share/gen-pack/${REQUIRED_GEN_PACK_LIB}"
  111. local USER_LIB="${HOME}/.local/share/gen-pack/${REQUIRED_GEN_PACK_LIB}"
  112. if [[ ! -d "${GLOBAL_LIB}" && ! -d "${USER_LIB}" ]]; then
  113. echo "Required gen_pack lib not found!" >&2
  114. install_lib "${REQUIRED_GEN_PACK_LIB}" "${USER_LIB}"
  115. fi
  116. if [[ -d "${GLOBAL_LIB}" ]]; then
  117. . "${GLOBAL_LIB}/gen-pack"
  118. elif [[ -d "${USER_LIB}" ]]; then
  119. . "${USER_LIB}/gen-pack"
  120. else
  121. echo "Required gen-pack lib is not installed!" >&2
  122. exit 1
  123. fi
  124. }
  125. load_lib
  126. gen_pack "${DEFAULT_ARGS[@]}" "$@"
  127. exit 0