menuconfig.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #!/bin/bash
  2. # Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. usage ()
  5. {
  6. echo "menuconfig.sh [options]"
  7. echo " -x [config file path name]"
  8. exit 1
  9. }
  10. while getopts "x:" opt
  11. do
  12. case $opt in
  13. x)
  14. wamr_config_cmake_file=$OPTARG
  15. ;;
  16. ?)
  17. echo "Unknown arg: $arg"
  18. usage
  19. exit 1
  20. ;;
  21. esac
  22. done
  23. if [ -z $wamr_config_cmake_file ]; then
  24. usage
  25. exit
  26. fi
  27. function set_build_target () {
  28. target=$1
  29. if [[ "${target}" = "X86_64" ]]; then
  30. echo -e "set (WAMR_BUILD_TARGET \"X86_64\")" >> ${wamr_config_cmake_file}
  31. elif [[ "${target}" = "X86_32" ]]; then
  32. echo -e "set (WAMR_BUILD_TARGET \"X86_32\")" >> ${wamr_config_cmake_file}
  33. else
  34. echo "unknown build target."
  35. exit 1
  36. fi
  37. }
  38. function set_build_platform () {
  39. platform=$1
  40. if [[ "${platform}" = "linux" ]]; then
  41. echo -e "set (WAMR_BUILD_PLATFORM \"linux\")" >> ${wamr_config_cmake_file}
  42. # TODO: add other platforms
  43. else
  44. echo "${platform} platform currently not supported"
  45. exit 1
  46. fi
  47. }
  48. # input: array of selected exec modes [aot jit interp]
  49. function set_exec_mode () {
  50. modes=($1)
  51. for mode in ${modes[@]}
  52. do
  53. if [[ "$mode" = "aot" ]]; then
  54. echo "set (WAMR_BUILD_AOT 1)" >> ${wamr_config_cmake_file}
  55. elif [[ "$mode" = "jit" ]]; then
  56. echo "set (WAMR_BUILD_JIT 1)" >> ${wamr_config_cmake_file}
  57. BUILD_LLVM="TRUE"
  58. elif [[ "$mode" = "interp" ]]; then
  59. echo "set (WAMR_BUILD_INTERP 1)" >> ${wamr_config_cmake_file}
  60. else
  61. echo "unknown execute mode."
  62. exit 1
  63. fi
  64. done
  65. }
  66. function set_libc_support () {
  67. libc=$1
  68. if [ "$libc" = "WASI" ]; then
  69. echo "set (WAMR_BUILD_LIBC_WASI 1)" >> ${wamr_config_cmake_file}
  70. else
  71. echo "set (WAMR_BUILD_LIBC_BUILTIN 1)" >> ${wamr_config_cmake_file}
  72. fi
  73. }
  74. function set_app_framework () {
  75. app_support=$1
  76. if [ "$app_support" = "TRUE" ]; then
  77. echo "set (WAMR_BUILD_APP_FRAMEWORK 1)" >> ${wamr_config_cmake_file}
  78. fi
  79. }
  80. # input: array of selected app modules
  81. function set_app_module () {
  82. modules=($1)
  83. for module in ${modules[*]}
  84. do
  85. if [ "${module}" = "all" ]; then
  86. cmake_app_list="WAMR_APP_BUILD_ALL"
  87. break
  88. fi
  89. cmake_app_list="${cmake_app_list} WAMR_APP_BUILD_${module^^}"
  90. done
  91. # APP module list
  92. if [ -n "${cmake_app_list}" ]; then
  93. echo "set (WAMR_BUILD_APP_LIST ${cmake_app_list# })" >> ${wamr_config_cmake_file}
  94. fi
  95. }
  96. sdk_root=$(cd "$(dirname "$0")/" && pwd)
  97. wamr_root=${sdk_root}/..
  98. if [ ! `command -v menuconfig` ]; then
  99. echo "Can't find kconfiglib python lib on this computer"
  100. echo "Downloading it through pip"
  101. echo "If this fails, you can try `pip install kconfiglib` to install it manually"
  102. echo "Or download the repo from https://github.com/ulfalizer/Kconfiglib"
  103. pip install kconfiglib
  104. fi
  105. if [ -f ".wamr_modules" ]; then
  106. rm -f .wamr_modules
  107. fi
  108. # get all modules under core/app-framework
  109. for module in `ls ${wamr_root}/core/app-framework -F | grep "/$" | grep -v "base" | grep -v "app-native-shared" | grep -v "template"`
  110. do
  111. module=${module%*/}
  112. echo "config APP_BUILD_${module^^}" >> .wamr_modules
  113. echo " bool \"enable ${module}\"" >> .wamr_modules
  114. done
  115. menuconfig Kconfig
  116. [ $? -eq 0 ] || exit $?
  117. if [ ! -e ".config" ]; then
  118. exit 0
  119. fi
  120. # parse platform
  121. platform=`cat .config | grep "^CONFIG_PLATFORM"`
  122. platform=${platform%*=y}
  123. platform=${platform,,}
  124. platform=${platform#config_platform_}
  125. # parse target
  126. target=`cat .config | grep "^CONFIG_TARGET"`
  127. target=${target%*=y}
  128. target=${target#CONFIG_TARGET_}
  129. # parse execution mode
  130. modes=`cat .config | grep "^CONFIG_EXEC"`
  131. mode_list=""
  132. for mode in ${modes}
  133. do
  134. mode=${mode%*=y}
  135. mode=${mode#CONFIG_EXEC_}
  136. mode_list="${mode_list} ${mode,,}"
  137. done
  138. if [ -z "${mode_list}" ]; then
  139. echo "execution mode are not selected"
  140. exit 1
  141. fi
  142. # parse libc support
  143. libc=`cat .config | grep "^CONFIG_LIBC"`
  144. libc=${libc%*=y}
  145. if [ "${libc}" = "CONFIG_LIBC_WASI" ]; then
  146. libc_support="WASI"
  147. else
  148. libc_support="BUILTIN"
  149. fi
  150. # parse application framework options
  151. app_option=`cat .config | grep "^CONFIG_APP_FRAMEWORK"`
  152. app_option=${app_option%*=y}
  153. app_option=${app_option#CONFIG_APP_FRAMEWORK_}
  154. if [ "${app_option}" != "DISABLE" ]; then
  155. app_enable="TRUE"
  156. # Default components
  157. if [ "${app_option}" = "DEFAULT" ]; then
  158. app_list="base connection sensor"
  159. # All components
  160. elif [ "${app_option}" = "ALL" ]; then
  161. app_list="all"
  162. # Customize
  163. elif [ "${app_option}" = "CUSTOM" ]; then
  164. app_option=`cat .config | grep "^CONFIG_APP_BUILD"`
  165. app_list="base"
  166. for app in ${app_option}
  167. do
  168. app=${app%*=y}
  169. app=${app#CONFIG_APP_BUILD_}
  170. app_list="${app_list} ${app,,}"
  171. done
  172. fi
  173. fi
  174. if [[ -f $wamr_config_cmake_file ]]; then
  175. rm $wamr_config_cmake_file
  176. fi
  177. set_build_target ${target}
  178. set_build_platform ${platform}
  179. set_exec_mode "${mode_list[*]}"
  180. set_libc_support ${libc_support}
  181. set_app_module "${app_list[*]}"
  182. set_app_framework ${app_enable}