launch.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. # Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. # All rights reserved.
  3. #
  4. # This software is supplied "AS IS" without any warranties.
  5. # RDA assumes no responsibility or liability for the use of the software,
  6. # conveys no license or title under any patent, copyright, or mask work
  7. # right to the product. RDA reserves the right to make changes in the
  8. # software without notification. RDA also make no representation or
  9. # warranty that such application will be suitable for the specified use
  10. # without further testing or modification.
  11. export PROJECT_ROOT=$PWD
  12. function remove_from_var
  13. {
  14. local VAR=$1
  15. local VAL="$2"
  16. if test -n "$VAL"; then
  17. export $VAR="$(echo "${!VAR}" | tr ':' '\n' | grep -v "$VAL" | paste -d: -s)"
  18. fi
  19. }
  20. function prepend_var
  21. {
  22. local VAR=$1
  23. local VAL="$2"
  24. if test -n "$VAL"; then
  25. remove_from_var $VAR "$VAL"
  26. if test -n "${!VAR}"; then
  27. export $VAR="$VAL:${!VAR}"
  28. else
  29. export $VAR="$VAL"
  30. fi
  31. fi
  32. }
  33. case `uname` in
  34. Linux)
  35. prepend_var PATH $PROJECT_ROOT/prebuilts/linux/bin
  36. prepend_var PATH $PROJECT_ROOT/prebuilts/linux/cmake/bin
  37. prepend_var PATH $PROJECT_ROOT/prebuilts/linux/nanopb
  38. prepend_var PATH $PROJECT_ROOT/tools
  39. prepend_var PATH $PROJECT_ROOT/tools/linux
  40. COMPLIER_PATH=$PROJECT_ROOT/prebuilts/linux/gcc-arm-none-eabi
  41. ;;
  42. *_NT*)
  43. prepend_var PATH $PROJECT_ROOT/prebuilts/win32/bin
  44. prepend_var PATH $PROJECT_ROOT/prebuilts/win32/cmake/bin
  45. prepend_var PATH $PROJECT_ROOT/prebuilts/win32/python3
  46. prepend_var PATH $PROJECT_ROOT/prebuilts/win32/nanopb
  47. prepend_var PATH $PROJECT_ROOT/tools
  48. prepend_var PATH $PROJECT_ROOT/tools/win32
  49. COMPLIER_PATH=$PROJECT_ROOT/prebuilts/win32/gcc-arm-none-eabi
  50. ;;
  51. esac
  52. function project_select_from
  53. {
  54. local BAR="$1"
  55. local ITEMS="$2"
  56. local DEF=$3
  57. local VAR=$4
  58. echo
  59. echo "$BAR"
  60. local MENUS
  61. local i=0
  62. local item
  63. for item in $ITEMS; do
  64. echo " $i. $item"
  65. i=$(($i+1))
  66. MENUS=(${MENUS[@]} $item)
  67. done
  68. echo -n "which would you like? [$DEF] "
  69. local answer
  70. read answer
  71. local choice=$DEF
  72. if test -n "$answer"; then
  73. if (echo -n $answer | grep -q -e "^[0-9][0-9]*$"); then
  74. if [ $answer -lt ${#MENUS[@]} ]; then
  75. choice=${MENUS[$(($answer))]}
  76. fi
  77. fi
  78. fi
  79. export $VAR=$choice
  80. }
  81. function project_select
  82. {
  83. local target
  84. local TARGETS=
  85. for target in $(cd target; /bin/ls); do
  86. if test -f target/$target/target.config; then
  87. TARGETS="$TARGETS $target"
  88. fi
  89. done
  90. project_select_from "build target:" "$TARGETS" "" BUILD_TARGET
  91. }
  92. function release_type_select
  93. {
  94. local release_type
  95. local RELEASE_TYPES="debug release"
  96. project_select_from "build release type:" "$RELEASE_TYPES" "debug" BUILD_RELEASE_TYPE
  97. }
  98. function compiler_select
  99. {
  100. local compiler_version
  101. local COMPILER_VERSIONS=
  102. for compiler_version in $(cd $COMPLIER_PATH; /bin/ls); do
  103. COMPILER_VERSIONS="$COMPILER_VERSIONS $compiler_version"
  104. done
  105. if [[ $BUILD_TARGET =~ "8850" ]] || [[ $BUILD_TARGET =~ "8860" ]]; then
  106. COMPLIER_DEFAULT=gcc-arm-none-eabi-10.2.1
  107. else
  108. COMPLIER_DEFAULT=gcc-arm-none-eabi-9.2.1
  109. fi
  110. project_select_from "build compiler version:" "$COMPILER_VERSIONS" "$COMPLIER_DEFAULT" BUILD_COMPILER_VERSION
  111. }
  112. function tfm_depends_build
  113. {
  114. if [[ $BUILD_TARGET =~ "TFM" ]]; then
  115. echo
  116. echo "TFM build"
  117. mkdir -p $PROJECT_OUT && cd $PROJECT_OUT
  118. cmake ../.. -G Ninja
  119. cd $PROJECT_ROOT
  120. echo "cmake ../.. -G Ninja"
  121. else
  122. echo "no TFM build"
  123. fi
  124. }
  125. function project_show
  126. {
  127. echo
  128. echo "=========================="
  129. echo "PATH=$PATH"
  130. echo "PROJECT_ROOT=$PROJECT_ROOT"
  131. echo "PROJECT_OUT=$PROJECT_OUT"
  132. echo "BUILD_TARGET=$BUILD_TARGET"
  133. echo "BUILD_RELEASE_TYPE"="$BUILD_RELEASE_TYPE"
  134. echo "BUILD_COMPILER_VERSION"="$BUILD_COMPILER_VERSION"
  135. echo "KCONFIG_CONFIG=$KCONFIG_CONFIG"
  136. }
  137. if [ -z "$1" ]; then
  138. project_select
  139. release_type_select
  140. compiler_select
  141. else
  142. export BUILD_TARGET=$1
  143. if [[ $BUILD_TARGET =~ "8850" ]]; then
  144. COMPLIER_DEFAULT=gcc-arm-none-eabi-10.2.1
  145. else
  146. COMPLIER_DEFAULT=gcc-arm-none-eabi-9.2.1
  147. fi
  148. if [ -z "$2" ]; then
  149. export BUILD_RELEASE_TYPE=debug
  150. export BUILD_COMPILER_VERSION=$COMPLIER_DEFAULT
  151. else
  152. export BUILD_RELEASE_TYPE=$2
  153. if [ -z "$3" ]; then
  154. export BUILD_COMPILER_VERSION=$COMPLIER_DEFAULT
  155. else
  156. export BUILD_COMPILER_VERSION=$3
  157. fi
  158. fi
  159. fi
  160. export KCONFIG_CONFIG=$PROJECT_ROOT/target/$BUILD_TARGET/target.config
  161. export PROJECT_OUT=$PROJECT_ROOT/out/${BUILD_TARGET}_${BUILD_RELEASE_TYPE}
  162. prepend_var PATH $COMPLIER_PATH/$BUILD_COMPILER_VERSION/bin
  163. tfm_depends_build
  164. project_show
  165. unset -f project_select
  166. unset -f project_select_from
  167. unset -f release_type_select
  168. unset -f compiler_select
  169. unset -f tfm_depends_build
  170. cout() {
  171. mkdir -p $PROJECT_OUT && cd $PROJECT_OUT
  172. }
  173. croot() {
  174. cd $PROJECT_ROOT
  175. }