Wang Xin 6 лет назад
Родитель
Сommit
de47e72284
2 измененных файлов с 154 добавлено и 31 удалено
  1. 30 30
      wamr-sdk/build_sdk.sh
  2. 124 1
      wamr-sdk/menuconfig.sh

+ 30 - 30
wamr-sdk/build_sdk.sh

@@ -27,7 +27,7 @@ usage ()
 }
 
 
-while getopts "e:x:n:t:m:l:awgicg" opt
+while getopts "e:x:n:ic" opt
 do
     case $opt in
         n)
@@ -39,15 +39,9 @@ do
         e)
         CMAKE_DEXTRA_SDK_INCLUDE_PATH="-DEXTRA_SDK_INCLUDE_PATH=${OPTARG}"
         ;;
-        a)
-        APP="TRUE"
-        ;;
         c)
         CLEAN="TRUE"
         ;;
-        w)
-        LIBC_SUPPORT="WASI"
-        ;;
         i)
         MENUCONFIG="TRUE"
         ;;
@@ -59,10 +53,29 @@ do
     esac
 done
 
+
+if [ ! -f "/opt/wasi-sdk/bin/clang" ]; then
+        echo "Can't find wasi-sdk under /opt/wasi-sdk"
+        echo "You can download wasi-sdk from here:"
+        echo ""
+        echo "https://github.com/CraneStation/wasi-sdk/releases/tag/wasi-sdk-7"
+        echo ""
+        echo "please install it to the default path for your convenience"
+        echo ""
+        exit 1
+fi
+
+
+
 if [ ! -d "${out_dir}" ]; then
     mkdir -p ${out_dir}
 fi
 
+curr_profile_dir=${out_dir}/${PROFILE}
+wamr_app_out_dir=${curr_profile_dir}/app-sdk/wamr-app-framework
+sysroot_dir=${curr_profile_dir}/app-sdk/libc-builtin-sysroot
+
+
 echo "CMAKE_DEXTRA_SDK_INCLUDE_PATH=${CMAKE_DEXTRA_SDK_INCLUDE_PATH}"
 
 
@@ -71,25 +84,28 @@ if [ -z "$PROFILE" ]; then
     echo "PROFILE argument not set, using DEFAULT"
 fi
 
-curr_profile_dir=${out_dir}/${PROFILE}
-wamr_app_out_dir=${curr_profile_dir}/app-sdk/wamr-app-framework
-sysroot_dir=${curr_profile_dir}/app-sdk/libc-builtin-sysroot
-
 if [[ "$CLEAN" = "TRUE" ]]; then
     rm -rf ${curr_profile_dir}
 fi
 
+
+
 # cmake config file for wamr runtime:
 # 1. use the users provided the config cmake file path.
-# 2. if user set MENU CONFIG, enter menu config to generate menu_config.cmake in the profile output folder
+# 2. if user set MENU CONFIG, enter menu config to generate 
+#    menu_config.cmake in the profile output folder
 # 3. If the menu_config.cmake is already in the profile folder, use it
 # 4. Use the default config cmake file
+#
 if [[ -n "$wamr_config_cmake_file" ]]; then
 	echo "User config file: [${wamr_config_cmake_file}]"
 else
 	wamr_config_cmake_file=${curr_profile_dir}/wamr_config_menu.cmake
-	if [[ "$MENUCONFIG" = "TRUE" ]] || [[ "$FROM_GUI_MENU" = "TRUE" ]]; then
-		echo "MENUCONFIG: user config file: [${wamr_config_cmake_file}]"
+	if [[ "$MENUCONFIG" = "TRUE" ]]; then
+		echo "MENUCONFIG: [${wamr_config_cmake_file}]"
+		./menuconfig.sh -x ${wamr_config_cmake_file}
+		[ $? -eq 0 ] || exit $?
+		
 	elif  [[ -f $wamr_config_cmake_file ]]; then
 		echo "use existing config file: [$wamr_config_cmake_file]"
  	else
@@ -98,22 +114,6 @@ else
     fi
 fi
 
-# if called by gui menuconfig, overwrite the exist profile
-if [ "${FROM_GUI_MENU}" != "TRUE" ]; then
-    if [[ "$PROFILE" != "default" ]] && [[ -d "$curr_profile_dir" ]]; then
-        echo "#########################################################"
-        echo "profile ${curr_profile_dir} already exists"
-        echo "  skip the build process and use the previous settings: [y]"
-        echo "  or delete the profile and generate a new one:          n"
-        read -a erase_exist
-        if [[ "$erase_exist" != "n" ]] && [[ "$erase_exist" != "N" ]]; then
-            exit 0
-        fi
-
-        rm -rf ${curr_profile_dir}
-    fi
-fi
-
 
 mkdir -p ${curr_profile_dir}
 mkdir -p ${curr_profile_dir}/app-sdk

+ 124 - 1
wamr-sdk/menuconfig.sh

@@ -3,6 +3,118 @@
 # Copyright (C) 2019 Intel Corporation.  All rights reserved.
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
+
+usage ()
+{
+    echo "menuconfig.sh [options]"
+    echo " -x [config file path name]"
+    exit 1
+}
+
+
+while getopts "x:" opt
+do
+    case $opt in
+        x)
+        wamr_config_cmake_file=$OPTARG
+        ;;
+        ?)
+        echo "Unknown arg: $arg"
+        usage
+        exit 1
+        ;;
+    esac
+done
+
+
+
+
+function set_build_target () {
+    target=$1
+
+    if [[ "${target}" = "X86_64" ]]; then
+        echo -e "set (WAMR_BUILD_TARGET \"X86_64\")" >> ${wamr_config_cmake_file}
+    elif [[ "${target}" = "X86_32" ]]; then
+        echo -e "set (WAMR_BUILD_TARGET \"X86_32\")" >> ${wamr_config_cmake_file}
+    else
+        echo "unknown build target."
+        exit 1
+    fi
+}
+
+function set_build_platform () {
+    platform=$1
+
+    if [[ "${platform}" = "linux" ]]; then
+        echo -e "set (WAMR_BUILD_PLATFORM \"linux\")" >> ${wamr_config_cmake_file}
+    # TODO: add other platforms
+    else
+        echo "${platform} platform currently not supported"
+        exit 1
+    fi
+}
+
+# input: array of selected exec modes [aot jit interp]
+function set_exec_mode () {
+    modes=($1)
+
+    for mode in ${modes[@]}
+    do
+        if [[ "$mode" = "aot" ]]; then
+            echo "set (WAMR_BUILD_AOT 1)" >> ${wamr_config_cmake_file}
+        elif [[ "$mode" = "jit" ]]; then
+            echo "set (WAMR_BUILD_JIT 1)" >> ${wamr_config_cmake_file}
+            BUILD_LLVM="TRUE"
+        elif [[ "$mode" = "interp" ]]; then
+            echo "set (WAMR_BUILD_INTERP 1)" >> ${wamr_config_cmake_file}
+        else
+            echo "unknown execute mode."
+            exit 1
+        fi
+    done
+}
+
+function set_libc_support () {
+    libc=$1
+
+    if [ "$libc" = "WASI" ]; then
+        echo "set (WAMR_BUILD_LIBC_WASI 1)" >> ${wamr_config_cmake_file}
+    else
+        echo "set (WAMR_BUILD_LIBC_BUILTIN 1)" >> ${wamr_config_cmake_file}
+    fi
+}
+
+function set_app_framework () {
+    app_support=$1
+
+    if [ "$app_support" = "TRUE" ]; then
+        echo "set (WAMR_BUILD_APP_FRAMEWORK 1)" >> ${wamr_config_cmake_file}
+    fi
+}
+
+# input: array of selected app modules
+function set_app_module () {
+    modules=($1)
+
+    for module in ${modules[*]}
+    do
+        if [ "${module}" = "all" ]; then
+            cmake_app_list="WAMR_APP_BUILD_ALL"
+            break
+        fi
+
+        cmake_app_list="${cmake_app_list} WAMR_APP_BUILD_${module^^}"
+    done
+
+    # APP module list
+    if [ -n "${cmake_app_list}" ]; then
+        echo "set (WAMR_BUILD_APP_LIST ${cmake_app_list# })" >> ${wamr_config_cmake_file}
+    fi
+}
+
+
+
+
 sdk_root=$(cd "$(dirname "$0")/" && pwd)
 wamr_root=${sdk_root}/..
 
@@ -123,4 +235,15 @@ if [ -n "${extra_path}" ]; then
 fi
 
 args="-g ${args}"
-./build_sdk.sh ${args}
+
+
+if  [[ -f $wamr_config_cmake_file ]]; then
+    rm  $wamr_config_cmake_file
+fi
+
+set_build_target        ${TARGET}
+set_build_platform      ${PLATFORM}
+set_exec_mode           "${MODES[*]}"
+set_libc_support        ${LIBC_SUPPORT}
+set_app_module          "${APP_LIST[*]}"
+set_app_framework       ${APP}