Explorar o código

Add BUILD_TARGET setting in makefile (#135)

wenyongh %!s(int64=6) %!d(string=hai) anos
pai
achega
28993946ad

+ 41 - 14
core/iwasm/products/darwin/CMakeLists.txt

@@ -22,32 +22,59 @@ set (PLATFORM "darwin")
 set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
 set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
 set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
 set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
 
 
-# Enable repl mode if want to test spec cases
-# add_definitions(-DWASM_ENABLE_REPL)
-
 if (NOT ("$ENV{VALGRIND}" STREQUAL "YES"))
 if (NOT ("$ENV{VALGRIND}" STREQUAL "YES"))
   add_definitions(-DNVALGRIND)
   add_definitions(-DNVALGRIND)
 endif ()
 endif ()
 
 
-# Currently build as 64-bit by default.
-set (BUILD_AS_64BIT_SUPPORT "YES")
+# Set BUILD_TARGET, currently values supported:
+# "X86_64", "AMD_64", "X86_32", "ARM_32", "MIPS_32", "XTENSA_32"
+if (NOT BUILD_TARGET)
+  if (CMAKE_SIZEOF_VOID_P EQUAL 8)
+    # Build as X86_64 by default in 64-bit platform
+    set (BUILD_TARGET "X86_64")
+  else ()
+    # Build as X86_32 by default in 32-bit platform
+    set (BUILD_TARGET "X86_32")
+  endif ()
+endif ()
 
 
-if (CMAKE_SIZEOF_VOID_P EQUAL 8)
-if (${BUILD_AS_64BIT_SUPPORT} STREQUAL "YES")
-  # Add -fPIC flag if build as 64-bit
-  set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
-  set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
+string(TOUPPER ${BUILD_TARGET} BUILD_TARGET)
+
+# Add definitions for the build target
+if (BUILD_TARGET STREQUAL "X86_64")
+  add_definitions(-DBUILD_TARGET_X86_64)
+elseif (BUILD_TARGET STREQUAL "AMD_64")
+  add_definitions(-DBUILD_TARGET_AMD_64)
+elseif (BUILD_TARGET STREQUAL "X86_32")
+  add_definitions(-DBUILD_TARGET_X86_32)
+elseif (BUILD_TARGET STREQUAL "ARM_32")
+  add_definitions(-DBUILD_TARGET_ARM_32)
+elseif (BUILD_TARGET STREQUAL "MIPS_32")
+  add_definitions(-DBUILD_TARGET_MIPS_32)
+elseif (BUILD_TARGET STREQUAL "XTENSA_32")
+  add_definitions(-DBUILD_TARGET_XTENSA_32)
 else ()
 else ()
-  add_definitions (-m32)
-  set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
-  set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
+  message (FATAL_ERROR "-- Build target isn't set")
 endif ()
 endif ()
+
+message ("-- Build as target ${BUILD_TARGET}")
+
+if (CMAKE_SIZEOF_VOID_P EQUAL 8)
+  if (BUILD_TARGET STREQUAL "X86_64" OR BUILD_TARGET STREQUAL "AMD_64")
+    # Add -fPIC flag if build as 64-bit
+    set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
+    set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
+  else ()
+    add_definitions (-m32)
+    set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
+    set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
+  endif ()
 endif ()
 endif ()
 
 
 if (NOT CMAKE_BUILD_TYPE)
 if (NOT CMAKE_BUILD_TYPE)
   set(CMAKE_BUILD_TYPE Release)
   set(CMAKE_BUILD_TYPE Release)
 endif (NOT CMAKE_BUILD_TYPE)
 endif (NOT CMAKE_BUILD_TYPE)
-message ("CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE})
+message ("-- CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE})
 
 
 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl")
 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl")
 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -Wno-pedantic")
 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -Wno-pedantic")

+ 33 - 15
core/iwasm/products/linux-sgx/CMakeLists.txt

@@ -28,32 +28,50 @@ add_definitions(-DOPS_UNSAFE_BUFFERS=0)
 add_definitions(-DWASM_ENABLE_LOG=0)
 add_definitions(-DWASM_ENABLE_LOG=0)
 add_definitions(-Dbh_printf=bh_printf_sgx)
 add_definitions(-Dbh_printf=bh_printf_sgx)
 
 
-# Enable repl mode if want to test spec cases
-# add_definitions(-DWASM_ENABLE_REPL)
-
 if (NOT ("$ENV{VALGRIND}" STREQUAL "YES"))
 if (NOT ("$ENV{VALGRIND}" STREQUAL "YES"))
   add_definitions(-DNVALGRIND)
   add_definitions(-DNVALGRIND)
 endif ()
 endif ()
 
 
-# Currently build as 64-bit by default.
-set (BUILD_AS_64BIT_SUPPORT "YES")
+# Set BUILD_TARGET, currently values supported:
+if (NOT BUILD_TARGET)
+  if (CMAKE_SIZEOF_VOID_P EQUAL 8)
+    # Build as X86_64 by default in 64-bit platform
+    set (BUILD_TARGET "X86_64")
+  else ()
+    # Build as X86_32 by default in 32-bit platform
+    set (BUILD_TARGET "X86_32")
+  endif ()
+endif ()
 
 
-if (CMAKE_SIZEOF_VOID_P EQUAL 8)
-if (${BUILD_AS_64BIT_SUPPORT} STREQUAL "YES")
-  # Add -fPIC flag if build as 64-bit
-  set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
-  set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
+string(TOUPPER ${BUILD_TARGET} BUILD_TARGET)
+
+# Add definitions for the build target
+if (BUILD_TARGET STREQUAL "X86_64")
+  add_definitions(-DBUILD_TARGET_X86_64)
+elseif (BUILD_TARGET STREQUAL "X86_32")
+  add_definitions(-DBUILD_TARGET_X86_32)
 else ()
 else ()
-  add_definitions (-m32)
-  set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
-  set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
-endif ()
+  message (FATAL_ERROR "-- Build target isn't set")
 endif ()
 endif ()
 
 
+message ("-- Build as target ${BUILD_TARGET}")
+
 if (NOT CMAKE_BUILD_TYPE)
 if (NOT CMAKE_BUILD_TYPE)
   set(CMAKE_BUILD_TYPE Release)
   set(CMAKE_BUILD_TYPE Release)
 endif (NOT CMAKE_BUILD_TYPE)
 endif (NOT CMAKE_BUILD_TYPE)
-message ("CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE})
+message ("-- CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE})
+
+if (CMAKE_SIZEOF_VOID_P EQUAL 8)
+  if (BUILD_TARGET STREQUAL "X86_64")
+    # Add -fPIC flag if build as 64-bit
+    set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
+    set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
+  else ()
+    add_definitions (-m32)
+    set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
+    set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
+  endif ()
+endif ()
 
 
 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -Wno-pedantic")
 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -Wno-pedantic")

+ 41 - 14
core/iwasm/products/linux/CMakeLists.txt

@@ -22,32 +22,59 @@ set (PLATFORM "linux")
 set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
 set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
 set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
 set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
 
 
-# Enable repl mode if want to test spec cases
-# add_definitions(-DWASM_ENABLE_REPL)
-
 if (NOT ("$ENV{VALGRIND}" STREQUAL "YES"))
 if (NOT ("$ENV{VALGRIND}" STREQUAL "YES"))
   add_definitions(-DNVALGRIND)
   add_definitions(-DNVALGRIND)
 endif ()
 endif ()
 
 
-# Currently build as 64-bit by default.
-set (BUILD_AS_64BIT_SUPPORT "YES")
+# Set BUILD_TARGET, currently values supported:
+# "X86_64", "AMD_64", "X86_32", "ARM_32", "MIPS_32", "XTENSA_32"
+if (NOT BUILD_TARGET)
+  if (CMAKE_SIZEOF_VOID_P EQUAL 8)
+    # Build as X86_64 by default in 64-bit platform
+    set (BUILD_TARGET "X86_64")
+  else ()
+    # Build as X86_32 by default in 32-bit platform
+    set (BUILD_TARGET "X86_32")
+  endif ()
+endif ()
 
 
-if (CMAKE_SIZEOF_VOID_P EQUAL 8)
-if (${BUILD_AS_64BIT_SUPPORT} STREQUAL "YES")
-  # Add -fPIC flag if build as 64-bit
-  set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
-  set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
+string(TOUPPER ${BUILD_TARGET} BUILD_TARGET)
+
+# Add definitions for the build target
+if (BUILD_TARGET STREQUAL "X86_64")
+  add_definitions(-DBUILD_TARGET_X86_64)
+elseif (BUILD_TARGET STREQUAL "AMD_64")
+  add_definitions(-DBUILD_TARGET_AMD_64)
+elseif (BUILD_TARGET STREQUAL "X86_32")
+  add_definitions(-DBUILD_TARGET_X86_32)
+elseif (BUILD_TARGET STREQUAL "ARM_32")
+  add_definitions(-DBUILD_TARGET_ARM_32)
+elseif (BUILD_TARGET STREQUAL "MIPS_32")
+  add_definitions(-DBUILD_TARGET_MIPS_32)
+elseif (BUILD_TARGET STREQUAL "XTENSA_32")
+  add_definitions(-DBUILD_TARGET_XTENSA_32)
 else ()
 else ()
-  add_definitions (-m32)
-  set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
-  set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
+  message (FATAL_ERROR "-- Build target isn't set")
 endif ()
 endif ()
+
+message ("-- Build as target ${BUILD_TARGET}")
+
+if (CMAKE_SIZEOF_VOID_P EQUAL 8)
+  if (BUILD_TARGET STREQUAL "X86_64" OR BUILD_TARGET STREQUAL "AMD_64")
+    # Add -fPIC flag if build as 64-bit
+    set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
+    set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
+  else ()
+    add_definitions (-m32)
+    set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
+    set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
+  endif ()
 endif ()
 endif ()
 
 
 if (NOT CMAKE_BUILD_TYPE)
 if (NOT CMAKE_BUILD_TYPE)
   set(CMAKE_BUILD_TYPE Release)
   set(CMAKE_BUILD_TYPE Release)
 endif (NOT CMAKE_BUILD_TYPE)
 endif (NOT CMAKE_BUILD_TYPE)
-message ("CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE})
+message ("-- CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE})
 
 
 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -Wno-pedantic")
 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -Wno-pedantic")

+ 41 - 14
core/iwasm/products/vxworks/CMakeLists.txt

@@ -27,32 +27,59 @@ SET(CMAKE_RANLIB vx-ranlib)
 set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
 set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
 set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
 set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
 
 
-# Enable repl mode if want to test spec cases
-# add_definitions(-DWASM_ENABLE_REPL)
-
 if (NOT ("$ENV{VALGRIND}" STREQUAL "YES"))
 if (NOT ("$ENV{VALGRIND}" STREQUAL "YES"))
   add_definitions(-DNVALGRIND)
   add_definitions(-DNVALGRIND)
 endif ()
 endif ()
 
 
-# Currently build as 64-bit by default.
-set (BUILD_AS_64BIT_SUPPORT "YES")
+# Set BUILD_TARGET, currently values supported:
+# "X86_64", "AMD_64", "X86_32", "ARM_32", "MIPS_32", "XTENSA_32"
+if (NOT BUILD_TARGET)
+  if (CMAKE_SIZEOF_VOID_P EQUAL 8)
+    # Build as X86_64 by default in 64-bit platform
+    set (BUILD_TARGET "X86_64")
+  else ()
+    # Build as X86_32 by default in 32-bit platform
+    set (BUILD_TARGET "X86_32")
+  endif ()
+endif ()
 
 
-if (CMAKE_SIZEOF_VOID_P EQUAL 8)
-if (${BUILD_AS_64BIT_SUPPORT} STREQUAL "YES")
-  # Add -fPIC flag if build as 64-bit
-  set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
-  set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
+string(TOUPPER ${BUILD_TARGET} BUILD_TARGET)
+
+# Add definitions for the build target
+if (BUILD_TARGET STREQUAL "X86_64")
+  add_definitions(-DBUILD_TARGET_X86_64)
+elseif (BUILD_TARGET STREQUAL "AMD_64")
+  add_definitions(-DBUILD_TARGET_AMD_64)
+elseif (BUILD_TARGET STREQUAL "X86_32")
+  add_definitions(-DBUILD_TARGET_X86_32)
+elseif (BUILD_TARGET STREQUAL "ARM_32")
+  add_definitions(-DBUILD_TARGET_ARM_32)
+elseif (BUILD_TARGET STREQUAL "MIPS_32")
+  add_definitions(-DBUILD_TARGET_MIPS_32)
+elseif (BUILD_TARGET STREQUAL "XTENSA_32")
+  add_definitions(-DBUILD_TARGET_XTENSA_32)
 else ()
 else ()
-  add_definitions (-m32)
-  set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
-  set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
+  message (FATAL_ERROR "-- Build target isn't set")
 endif ()
 endif ()
+
+message ("-- Build as target ${BUILD_TARGET}")
+
+if (CMAKE_SIZEOF_VOID_P EQUAL 8)
+  if (BUILD_TARGET STREQUAL "X86_64" OR BUILD_TARGET STREQUAL "AMD_64")
+    # Add -fPIC flag if build as 64-bit
+    set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
+    set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
+  else ()
+    add_definitions (-m32)
+    set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
+    set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
+  endif ()
 endif ()
 endif ()
 
 
 if (NOT CMAKE_BUILD_TYPE)
 if (NOT CMAKE_BUILD_TYPE)
   set(CMAKE_BUILD_TYPE Release)
   set(CMAKE_BUILD_TYPE Release)
 endif (NOT CMAKE_BUILD_TYPE)
 endif (NOT CMAKE_BUILD_TYPE)
-message ("CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE})
+message ("-- CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE})
 
 
 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -Wno-pedantic")
 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -Wno-pedantic")

+ 22 - 0
core/iwasm/products/zephyr/simple/CMakeLists.txt

@@ -21,6 +21,28 @@ enable_language (ASM)
 
 
 add_definitions (-DNVALGRIND)
 add_definitions (-DNVALGRIND)
 
 
+# Build as X86_32 by default, change to "ARM_32", "MIPS_32" or "XTENSA_32"
+# if we want to support arm, mips or xtensa
+if (NOT BUILD_TARGET)
+  set (BUILD_TARGET "X86_32")
+endif ()
+
+string(TOUPPER ${BUILD_TARGET} BUILD_TARGET)
+
+if (BUILD_TARGET STREQUAL "X86_32")
+  add_definitions(-DBUILD_TARGET_X86_32)
+elseif (BUILD_TARGET STREQUAL "ARM_32")
+  add_definitions(-DBUILD_TARGET_ARM_32)
+elseif (BUILD_TARGET STREQUAL "MIPS_32")
+  add_definitions(-DBUILD_TARGET_MIPS_32)
+elseif (BUILD_TARGET STREQUAL "XTENSA_32")
+  add_definitions(-DBUILD_TARGET_XTENSA_32)
+else ()
+  message (FATAL_ERROR "-- Build target isn't set")
+endif ()
+
+message ("-- Build as target ${BUILD_TARGET}")
+
 set (IWASM_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/iwasm)
 set (IWASM_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/iwasm)
 set (SHARED_LIB_ROOT ${IWASM_ROOT}/../shared-lib)
 set (SHARED_LIB_ROOT ${IWASM_ROOT}/../shared-lib)
 
 

+ 1 - 1
core/iwasm/runtime/utils/wasm_vector.c

@@ -52,7 +52,7 @@ extend_vector(Vector *vector, uint32 length)
     }
     }
 
 
     memcpy(data, vector->data, vector->size_elem * vector->max_elements);
     memcpy(data, vector->data, vector->size_elem * vector->max_elements);
-    free(vector->data);
+    wasm_free(vector->data);
     vector->data = data;
     vector->data = data;
     vector->max_elements = length;
     vector->max_elements = length;
     return true;
     return true;

+ 5 - 0
core/iwasm/runtime/vmcore-wasm/invokeNative_em64.s

@@ -15,9 +15,14 @@
  */
  */
     .text
     .text
     .align 2
     .align 2
+#ifndef OS_MACOSX
 .globl invokeNative
 .globl invokeNative
     .type    invokeNative, @function
     .type    invokeNative, @function
 invokeNative:
 invokeNative:
+#else
+.globl _invokeNative
+_invokeNative:
+#endif /* end of OS_MACOSX */
     /*  rdi - function ptr */
     /*  rdi - function ptr */
     /*  rsi - argv */
     /*  rsi - argv */
     /*  rdx - n_stacks */
     /*  rdx - n_stacks */

+ 5 - 0
core/iwasm/runtime/vmcore-wasm/invokeNative_ia32.s

@@ -16,9 +16,14 @@
 
 
     .text
     .text
     .align 2
     .align 2
+#ifndef OS_MACOSX
 .globl invokeNative
 .globl invokeNative
     .type   invokeNative, @function
     .type   invokeNative, @function
 invokeNative:
 invokeNative:
+#else
+.globl _invokeNative
+_invokeNative:
+#endif /* end of OS_MACOSX */
     push    %ebp
     push    %ebp
     movl    %esp, %ebp
     movl    %esp, %ebp
     movl    16(%ebp), %ecx          /* ecx = argc */
     movl    16(%ebp), %ecx          /* ecx = argc */

+ 11 - 3
core/iwasm/runtime/vmcore-wasm/vmcore.cmake

@@ -20,10 +20,18 @@ include_directories(${VMCORE_LIB_DIR}/../include)
 file (GLOB_RECURSE c_source_all ${VMCORE_LIB_DIR}/*.c)
 file (GLOB_RECURSE c_source_all ${VMCORE_LIB_DIR}/*.c)
 list (REMOVE_ITEM c_source_all ${VMCORE_LIB_DIR}/invokeNative_general.c)
 list (REMOVE_ITEM c_source_all ${VMCORE_LIB_DIR}/invokeNative_general.c)
 
 
-if (${BUILD_AS_64BIT_SUPPORT} STREQUAL "YES")
-set (source_all ${c_source_all} ${VMCORE_LIB_DIR}/invokeNative_em64.s)
+if (${BUILD_TARGET} STREQUAL "X86_64" OR ${BUILD_TARGET} STREQUAL "AMD_64")
+  set (source_all ${c_source_all} ${VMCORE_LIB_DIR}/invokeNative_em64.s)
+elseif (${BUILD_TARGET} STREQUAL "X86_32")
+  set (source_all ${c_source_all} ${VMCORE_LIB_DIR}/invokeNative_ia32.s)
+elseif (${BUILD_TARGET} STREQUAL "ARM_32")
+  set (source_all ${c_source_all} ${VMCORE_LIB_DIR}/invokeNative_arm.s)
+elseif (${BUILD_TARGET} STREQUAL "MIPS_32")
+  set (source_all ${c_source_all} ${VMCORE_LIB_DIR}/invokeNative_mips.s)
+elseif (${BUILD_TARGET} STREQUAL "XTENSA_32")
+  set (source_all ${c_source_all} ${VMCORE_LIB_DIR}/invokeNative_xtensa.s)
 else ()
 else ()
-set (source_all ${c_source_all} ${VMCORE_LIB_DIR}/invokeNative_ia32.s)
+  message (FATAL_ERROR "Build target isn't set")
 endif ()
 endif ()
 
 
 set (VMCORE_LIB_SOURCE ${source_all})
 set (VMCORE_LIB_SOURCE ${source_all})

+ 6 - 6
core/iwasm/runtime/vmcore-wasm/wasm_runtime.c

@@ -1458,7 +1458,7 @@ word_copy(uint32 *dest, uint32 *src, unsigned num)
     (addr)[1] = u.parts[1];                     \
     (addr)[1] = u.parts[1];                     \
   } while (0)
   } while (0)
 
 
-#if !defined(__x86_64__) && !defined(__amd_64__)
+#if !defined(BUILD_TARGET_X86_64) && !defined(BUILD_TARGET_AMD_64)
 
 
 typedef void (*GenericFunctionPointer)();
 typedef void (*GenericFunctionPointer)();
 int64 invokeNative(GenericFunctionPointer f, uint32 *args, uint32 sz);
 int64 invokeNative(GenericFunctionPointer f, uint32 *args, uint32 sz);
@@ -1483,7 +1483,7 @@ wasm_runtime_invoke_native(void *func_ptr, WASMType *func_type,
     uint32 argv_buf[32], *argv1 = argv_buf, argc1, i, j = 0;
     uint32 argv_buf[32], *argv1 = argv_buf, argc1, i, j = 0;
     uint64 size;
     uint64 size;
 
 
-#if !defined(__arm__) && !defined(__mips__)
+#if !defined(BUILD_TARGET_ARM_32) && !defined(BUILD_TARGET_MIPS_32)
     argc1 = argc + 2;
     argc1 = argc + 2;
 #else
 #else
     argc1 = func_type->param_count * 2 + 2;
     argc1 = func_type->param_count * 2 + 2;
@@ -1501,7 +1501,7 @@ wasm_runtime_invoke_native(void *func_ptr, WASMType *func_type,
     for (i = 0; i < sizeof(WASMModuleInstance*) / sizeof(uint32); i++)
     for (i = 0; i < sizeof(WASMModuleInstance*) / sizeof(uint32); i++)
         argv1[j++] = ((uint32*)&module_inst)[i];
         argv1[j++] = ((uint32*)&module_inst)[i];
 
 
-#if !defined(__arm__) && !defined(__mips__)
+#if !defined(BUILD_TARGET_ARM_32) && !defined(BUILD_TARGET_MIPS_32)
     word_copy(argv1 + j, argv, argc);
     word_copy(argv1 + j, argv, argc);
     j += argc;
     j += argc;
 #else
 #else
@@ -1526,7 +1526,7 @@ wasm_runtime_invoke_native(void *func_ptr, WASMType *func_type,
                 break;
                 break;
         }
         }
     }
     }
-#endif
+#endif /* end of !defined(BUILD_TARGET_ARM_32) && !defined(BUILD_TARGET_MIPS_32) */
 
 
     argc1 = j;
     argc1 = j;
     if (func_type->result_count == 0) {
     if (func_type->result_count == 0) {
@@ -1557,7 +1557,7 @@ wasm_runtime_invoke_native(void *func_ptr, WASMType *func_type,
     return true;
     return true;
 }
 }
 
 
-#else /* else of !defined(__x86_64__) && !defined(__amd_64__) */
+#else /* else of !defined(BUILD_TARGET_X86_64) && !defined(BUILD_TARGET_AMD_64) */
 
 
 typedef void (*GenericFunctionPointer)();
 typedef void (*GenericFunctionPointer)();
 int64 invokeNative(GenericFunctionPointer f, uint64 *args, uint64 n_stacks);
 int64 invokeNative(GenericFunctionPointer f, uint64 *args, uint64 n_stacks);
@@ -1675,5 +1675,5 @@ wasm_runtime_invoke_native(void *func_ptr, WASMType *func_type,
     return true;
     return true;
 }
 }
 
 
-#endif /* end of !defined(__x86_64__) && !defined(__amd_64__) */
+#endif /* end of !defined(BUILD_TARGET_X86_64) && !defined(BUILD_TARGET_AMD_64) */
 
 

+ 27 - 2
core/shared-lib/include/config.h

@@ -16,6 +16,29 @@
 
 
 #ifndef _CONFIG_H_
 #ifndef _CONFIG_H_
 
 
+#if !defined(BUILD_TARGET_X86_64) \
+    && !defined(BUILD_TARGET_AMD_64) \
+    && !defined(BUILD_TARGET_X86_32) \
+    && !defined(BUILD_TARGET_ARM_32) \
+    && !defined(BUILD_TARGET_MIPS_32) \
+    && !defined(BUILD_TARGET_XTENSA_32)
+#if defined(__x86_64__) || defined(__x86_64)
+#define BUILD_TARGET_X86_64
+#elif defined(__amd64__) || defined(__amd64)
+#define BUILD_TARGET_AMD_64
+#elif defined(__i386__) || defined(__i386) || defined(i386)
+#define BUILD_TARGET_X86_32
+#elif defined(__arm__)
+#define BUILD_TARGET_ARM_32
+#elif defined(__mips__) || defined(__mips) || defined(mips)
+#define BUILD_TARGET_MIPS_32
+#elif defined(__XTENSA__)
+#define BUILD_TARGET_XTENSA
+#else
+#error "Build target isn't set"
+#endif
+#endif
+
 /* Memory allocator ems */
 /* Memory allocator ems */
 #define MEM_ALLOCATOR_EMS 0
 #define MEM_ALLOCATOR_EMS 0
 
 
@@ -100,7 +123,7 @@
 #define APP_HEAP_SIZE_MAX (1024 * 1024)
 #define APP_HEAP_SIZE_MAX (1024 * 1024)
 
 
 /* Default wasm stack size of each app */
 /* Default wasm stack size of each app */
-#ifdef __x86_64__
+#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)
 #define DEFAULT_WASM_STACK_SIZE (12 * 1024)
 #define DEFAULT_WASM_STACK_SIZE (12 * 1024)
 #else
 #else
 #define DEFAULT_WASM_STACK_SIZE (8 * 1024)
 #define DEFAULT_WASM_STACK_SIZE (8 * 1024)
@@ -116,7 +139,6 @@
 #define APP_THREAD_STACK_SIZE_MIN (2 * 1024)
 #define APP_THREAD_STACK_SIZE_MIN (2 * 1024)
 #define APP_THREAD_STACK_SIZE_MAX (256 * 1024)
 #define APP_THREAD_STACK_SIZE_MAX (256 * 1024)
 #endif
 #endif
-#endif
 
 
 /* External memory space provided by user,
 /* External memory space provided by user,
    but not wasm memory space and app heap space */
    but not wasm memory space and app heap space */
@@ -134,3 +156,6 @@
 #ifndef WASM_ENABLE_GUI
 #ifndef WASM_ENABLE_GUI
 #define WASM_ENABLE_GUI 0
 #define WASM_ENABLE_GUI 0
 #endif
 #endif
+
+#endif /* end of _CONFIG_H_ */
+

+ 9 - 9
samples/gui/lvgl-native-ui-app/CMakeLists.txt

@@ -22,15 +22,15 @@ project (lvgl_native_ui_app)
 set (BUILD_AS_64BIT_SUPPORT "YES")
 set (BUILD_AS_64BIT_SUPPORT "YES")
 
 
 if (CMAKE_SIZEOF_VOID_P EQUAL 8)
 if (CMAKE_SIZEOF_VOID_P EQUAL 8)
-        if (${BUILD_AS_64BIT_SUPPORT} STREQUAL "YES")
-                # Add -fPIC flag if build as 64-bit
-                set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
-                set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
-        else ()
-                add_definitions (-m32)
-                set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
-                set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
-        endif ()
+   if (${BUILD_AS_64BIT_SUPPORT} STREQUAL "YES")
+     # Add -fPIC flag if build as 64-bit
+     set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
+     set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
+   else ()
+     add_definitions (-m32)
+     set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
+     set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
+   endif ()
 endif ()
 endif ()
 
 
 set(THIRDPARTY_DIR ../../../core/iwasm/lib/3rdparty)
 set(THIRDPARTY_DIR ../../../core/iwasm/lib/3rdparty)

+ 42 - 15
samples/gui/wasm-runtime-wgl/linux-build/CMakeLists.txt

@@ -18,37 +18,64 @@ set (TARGET_PLATFORM "linux")
 set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
 set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
 set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
 set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
 
 
-# Enable repl mode if want to test spec cases
-# add_definitions(-DWASM_ENABLE_REPL)
-
 if (NOT ("$ENV{VALGRIND}" STREQUAL "YES"))
 if (NOT ("$ENV{VALGRIND}" STREQUAL "YES"))
   add_definitions(-DNVALGRIND)
   add_definitions(-DNVALGRIND)
 endif ()
 endif ()
 
 
-# Currently build as 64-bit by default.
-set (BUILD_AS_64BIT_SUPPORT "YES")
+# Set BUILD_TARGET, currently values supported:
+# "X86_64", "AMD_64", "X86_32", "ARM_32", "MIPS_32", "XTENSA_32"
+if (NOT BUILD_TARGET)
+  if (CMAKE_SIZEOF_VOID_P EQUAL 8)
+    # Build as X86_64 by default in 64-bit platform
+    set (BUILD_TARGET "X86_64")
+  else ()
+    # Build as X86_32 by default in 32-bit platform
+    set (BUILD_TARGET "X86_32")
+  endif ()
+endif ()
 
 
-if (CMAKE_SIZEOF_VOID_P EQUAL 8)
-if (${BUILD_AS_64BIT_SUPPORT} STREQUAL "YES")
-  # Add -fPIC flag if build as 64-bit
-  set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
-  set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
+string(TOUPPER ${BUILD_TARGET} BUILD_TARGET)
+
+# Add definitions for the build target
+if (BUILD_TARGET STREQUAL "X86_64")
+  add_definitions(-DBUILD_TARGET_X86_64)
+elseif (BUILD_TARGET STREQUAL "AMD_64")
+  add_definitions(-DBUILD_TARGET_AMD_64)
+elseif (BUILD_TARGET STREQUAL "X86_32")
+  add_definitions(-DBUILD_TARGET_X86_32)
+elseif (BUILD_TARGET STREQUAL "ARM_32")
+  add_definitions(-DBUILD_TARGET_ARM_32)
+elseif (BUILD_TARGET STREQUAL "MIPS_32")
+  add_definitions(-DBUILD_TARGET_MIPS_32)
+elseif (BUILD_TARGET STREQUAL "XTENSA_32")
+  add_definitions(-DBUILD_TARGET_XTENSA_32)
 else ()
 else ()
-  add_definitions (-m32)
-  set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
-  set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
+  message (FATAL_ERROR "-- Build target isn't set")
 endif ()
 endif ()
+
+message ("-- Build as target ${BUILD_TARGET}")
+
+if (CMAKE_SIZEOF_VOID_P EQUAL 8)
+  if (BUILD_TARGET STREQUAL "X86_64" OR BUILD_TARGET STREQUAL "AMD_64")
+    # Add -fPIC flag if build as 64-bit
+    set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
+    set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
+  else ()
+    add_definitions (-m32)
+    set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
+    set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
+  endif ()
 endif ()
 endif ()
 
 
 if (NOT CMAKE_BUILD_TYPE)
 if (NOT CMAKE_BUILD_TYPE)
 SET(CMAKE_BUILD_TYPE Debug)
 SET(CMAKE_BUILD_TYPE Debug)
 endif (NOT CMAKE_BUILD_TYPE)
 endif (NOT CMAKE_BUILD_TYPE)
-message ("CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE})
+message ("-- CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE})
 
 
 if (NOT PLATFORM)
 if (NOT PLATFORM)
 SET(PLATFORM linux)
 SET(PLATFORM linux)
 endif (NOT PLATFORM)
 endif (NOT PLATFORM)
-message ("PLATFORM = " ${PLATFORM})
+message ("-- PLATFORM = " ${PLATFORM})
 
 
 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -Wno-pedantic")
 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -Wno-pedantic")

+ 22 - 0
samples/gui/wasm-runtime-wgl/zephyr-build/CMakeLists.txt

@@ -27,6 +27,28 @@ zephyr_compile_definitions (-DNVALGRIND
     -Dattr_container_free=bh_free
     -Dattr_container_free=bh_free
     -DWASM_ENABLE_GUI=1)
     -DWASM_ENABLE_GUI=1)
 
 
+# Build as ARM_32 by default, change to "X86_32", "MIPS_32" or "XTENSA_32"
+# if we want to support x86, mips or xtensa
+if (NOT BUILD_TARGET)
+  set (BUILD_TARGET "ARM_32")
+endif ()
+
+string(TOUPPER ${BUILD_TARGET} BUILD_TARGET)
+
+if (BUILD_TARGET STREQUAL "X86_32")
+  add_definitions(-DBUILD_TARGET_X86_32)
+elseif (BUILD_TARGET STREQUAL "ARM_32")
+  add_definitions(-DBUILD_TARGET_ARM_32)
+elseif (BUILD_TARGET STREQUAL "MIPS_32")
+  add_definitions(-DBUILD_TARGET_MIPS_32)
+elseif (BUILD_TARGET STREQUAL "XTENSA_32")
+  add_definitions(-DBUILD_TARGET_XTENSA_32)
+else ()
+  message (FATAL_ERROR "-- Build target isn't set")
+endif ()
+
+message ("-- Build as target ${BUILD_TARGET}")
+
 set (IWASM_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/core/iwasm)
 set (IWASM_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/core/iwasm)
 set (APP_MGR_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/core/app-mgr)
 set (APP_MGR_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/core/app-mgr)
 set (SHARED_LIB_ROOT ${IWASM_ROOT}/../shared-lib)
 set (SHARED_LIB_ROOT ${IWASM_ROOT}/../shared-lib)

+ 9 - 9
samples/littlevgl/vgl-native-ui-app/CMakeLists.txt

@@ -23,15 +23,15 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLV_CONF_INCLUDE_SIMPLE -DPLATFORM_NATIVE_L
 set (BUILD_AS_64BIT_SUPPORT "YES")
 set (BUILD_AS_64BIT_SUPPORT "YES")
 
 
 if (CMAKE_SIZEOF_VOID_P EQUAL 8)
 if (CMAKE_SIZEOF_VOID_P EQUAL 8)
-        if (${BUILD_AS_64BIT_SUPPORT} STREQUAL "YES")
-                # Add -fPIC flag if build as 64-bit
-                set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
-                set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
-        else ()
-                add_definitions (-m32)
-                set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
-                set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
-        endif ()
+  if (${BUILD_AS_64BIT_SUPPORT} STREQUAL "YES")
+    # Add -fPIC flag if build as 64-bit
+    set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
+    set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
+  else ()
+    add_definitions (-m32)
+    set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
+    set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
+  endif ()
 endif ()
 endif ()
 
 
 set(lv_name lvgl)
 set(lv_name lvgl)

+ 42 - 15
samples/littlevgl/vgl-wasm-runtime/CMakeLists.txt

@@ -8,37 +8,64 @@ set (TARGET_PLATFORM "linux")
 set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
 set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
 set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
 set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
 
 
-# Enable repl mode if want to test spec cases
-# add_definitions(-DWASM_ENABLE_REPL)
-
 if (NOT ("$ENV{VALGRIND}" STREQUAL "YES"))
 if (NOT ("$ENV{VALGRIND}" STREQUAL "YES"))
   add_definitions(-DNVALGRIND)
   add_definitions(-DNVALGRIND)
 endif ()
 endif ()
 
 
-# Currently build as 64-bit by default.
-set (BUILD_AS_64BIT_SUPPORT "YES")
+# Set BUILD_TARGET, currently values supported:
+# "X86_64", "AMD_64", "X86_32", "ARM_32", "MIPS_32", "XTENSA_32"
+if (NOT BUILD_TARGET)
+  if (CMAKE_SIZEOF_VOID_P EQUAL 8)
+    # Build as X86_64 by default in 64-bit platform
+    set (BUILD_TARGET "X86_64")
+  else ()
+    # Build as X86_32 by default in 32-bit platform
+    set (BUILD_TARGET "X86_32")
+  endif ()
+endif ()
 
 
-if (CMAKE_SIZEOF_VOID_P EQUAL 8)
-if (${BUILD_AS_64BIT_SUPPORT} STREQUAL "YES")
-  # Add -fPIC flag if build as 64-bit
-  set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
-  set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
+string(TOUPPER ${BUILD_TARGET} BUILD_TARGET)
+
+# Add definitions for the build target
+if (BUILD_TARGET STREQUAL "X86_64")
+  add_definitions(-DBUILD_TARGET_X86_64)
+elseif (BUILD_TARGET STREQUAL "AMD_64")
+  add_definitions(-DBUILD_TARGET_AMD_64)
+elseif (BUILD_TARGET STREQUAL "X86_32")
+  add_definitions(-DBUILD_TARGET_X86_32)
+elseif (BUILD_TARGET STREQUAL "ARM_32")
+  add_definitions(-DBUILD_TARGET_ARM_32)
+elseif (BUILD_TARGET STREQUAL "MIPS_32")
+  add_definitions(-DBUILD_TARGET_MIPS_32)
+elseif (BUILD_TARGET STREQUAL "XTENSA_32")
+  add_definitions(-DBUILD_TARGET_XTENSA_32)
 else ()
 else ()
-  add_definitions (-m32)
-  set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
-  set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
+  message (FATAL_ERROR "-- Build target isn't set")
 endif ()
 endif ()
+
+message ("-- Build as target ${BUILD_TARGET}")
+
+if (CMAKE_SIZEOF_VOID_P EQUAL 8)
+  if (BUILD_TARGET STREQUAL "X86_64" OR BUILD_TARGET STREQUAL "AMD_64")
+    # Add -fPIC flag if build as 64-bit
+    set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
+    set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
+  else ()
+    add_definitions (-m32)
+    set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
+    set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
+  endif ()
 endif ()
 endif ()
 
 
 if (NOT CMAKE_BUILD_TYPE)
 if (NOT CMAKE_BUILD_TYPE)
 SET(CMAKE_BUILD_TYPE Debug)
 SET(CMAKE_BUILD_TYPE Debug)
 endif (NOT CMAKE_BUILD_TYPE)
 endif (NOT CMAKE_BUILD_TYPE)
-message ("CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE})
+message ("-- CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE})
 
 
 if (NOT PLATFORM)
 if (NOT PLATFORM)
 SET(PLATFORM linux)
 SET(PLATFORM linux)
 endif (NOT PLATFORM)
 endif (NOT PLATFORM)
-message ("PLATFORM = " ${PLATFORM})
+message ("-- PLATFORM = " ${PLATFORM})
 
 
 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -Wno-pedantic")
 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -Wno-pedantic")

+ 21 - 0
samples/littlevgl/vgl-wasm-runtime/zephyr-build/CMakeLists.txt

@@ -26,6 +26,27 @@ zephyr_compile_definitions (-DNVALGRIND
     -Dattr_container_malloc=bh_malloc
     -Dattr_container_malloc=bh_malloc
     -Dattr_container_free=bh_free)
     -Dattr_container_free=bh_free)
 
 
+# Build as ARM_32 by default, change to "X86_32", "MIPS_32" or "XTENSA_32"
+# if we want to support x86, mips or xtensa
+if (NOT BUILD_TARGET)
+  set (BUILD_TARGET "ARM_32")
+endif ()
+
+string(TOUPPER ${BUILD_TARGET} BUILD_TARGET)
+
+if (BUILD_TARGET STREQUAL "X86_32")
+  add_definitions(-DBUILD_TARGET_X86_32)
+elseif (BUILD_TARGET STREQUAL "ARM_32")
+  add_definitions(-DBUILD_TARGET_ARM_32)
+elseif (BUILD_TARGET STREQUAL "MIPS_32")
+  add_definitions(-DBUILD_TARGET_MIPS_32)
+elseif (BUILD_TARGET STREQUAL "XTENSA_32")
+  add_definitions(-DBUILD_TARGET_XTENSA_32)
+else ()
+  message (FATAL_ERROR "-- Build target isn't set")
+endif ()
+
+message ("-- Build as target ${BUILD_TARGET}")
 set (IWASM_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/core/iwasm)
 set (IWASM_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/core/iwasm)
 set (APP_MGR_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/core/app-mgr)
 set (APP_MGR_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/core/app-mgr)
 set (SHARED_LIB_ROOT ${IWASM_ROOT}/../shared-lib)
 set (SHARED_LIB_ROOT ${IWASM_ROOT}/../shared-lib)

+ 1 - 1
samples/littlevgl/wasm-apps/Makefile_wasm_app

@@ -47,7 +47,7 @@ SRCS += lvgl/lv_misc/lv_task.c lvgl/lv_misc/lv_circ.c lvgl/lv_misc/lv_anim.c
 SRCS += lvgl/lv_misc/lv_color.c lvgl/lv_misc/lv_txt.c lvgl/lv_misc/lv_math.c
 SRCS += lvgl/lv_misc/lv_color.c lvgl/lv_misc/lv_txt.c lvgl/lv_misc/lv_math.c
 SRCS += lvgl/lv_misc/lv_mem.c lvgl/lv_misc/lv_font.c lvgl/lv_misc/lv_ll.c
 SRCS += lvgl/lv_misc/lv_mem.c lvgl/lv_misc/lv_font.c lvgl/lv_misc/lv_ll.c
 SRCS += lvgl/lv_misc/lv_area.c lvgl/lv_misc/lv_templ.c lvgl/lv_misc/lv_ufs.c
 SRCS += lvgl/lv_misc/lv_area.c lvgl/lv_misc/lv_templ.c lvgl/lv_misc/lv_ufs.c
-SRCS += lvgl/lv_misc/lv_area.c lvgl/lv_misc/lv_templ.c lvgl/lv_misc/lv_gc.c
+SRCS += lvgl/lv_misc/lv_gc.c
 SRCS += lvgl/lv_hal/lv_hal_tick.c lvgl/lv_hal/lv_hal_indev.c lvgl/lv_hal/lv_hal_disp.c
 SRCS += lvgl/lv_hal/lv_hal_tick.c lvgl/lv_hal/lv_hal_indev.c lvgl/lv_hal/lv_hal_disp.c
 SRCS += lvgl/lv_themes/lv_theme_mono.c lvgl/lv_themes/lv_theme_templ.c
 SRCS += lvgl/lv_themes/lv_theme_mono.c lvgl/lv_themes/lv_theme_templ.c
 SRCS += lvgl/lv_themes/lv_theme_material.c lvgl/lv_themes/lv_theme.c
 SRCS += lvgl/lv_themes/lv_theme_material.c lvgl/lv_themes/lv_theme.c

+ 47 - 14
samples/simple/CMakeLists.txt

@@ -8,37 +8,70 @@ set (TARGET_PLATFORM "linux")
 set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
 set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
 set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
 set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
 
 
-# Enable repl mode if want to test spec cases
-# add_definitions(-DWASM_ENABLE_REPL)
-
 if (NOT ("$ENV{VALGRIND}" STREQUAL "YES"))
 if (NOT ("$ENV{VALGRIND}" STREQUAL "YES"))
   add_definitions(-DNVALGRIND)
   add_definitions(-DNVALGRIND)
 endif ()
 endif ()
 
 
-# Currently build as 64-bit by default.
 set (BUILD_AS_64BIT_SUPPORT "YES")
 set (BUILD_AS_64BIT_SUPPORT "YES")
 
 
-if (CMAKE_SIZEOF_VOID_P EQUAL 8)
-if (${BUILD_AS_64BIT_SUPPORT} STREQUAL "YES")
-  # Add -fPIC flag if build as 64-bit
-  set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
-  set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
+# Set BUILD_TARGET, currently values supported:
+# "X86_64", "AMD_64", "X86_32", "ARM_32", "MIPS_32", "XTENSA_32"
+if (NOT BUILD_TARGET)
+  if (CMAKE_SIZEOF_VOID_P EQUAL 8)
+    if (BUILD_AS_64BIT_SUPPORT STREQUAL "YES")
+      # Build as X86_64 by default in 64-bit platform
+      set (BUILD_TARGET "X86_64")
+    else ()
+      set (BUILD_TARGET "X86_32")
+    endif ()
+  else ()
+    # Build as X86_32 by default in 32-bit platform
+    set (BUILD_TARGET "X86_32")
+  endif ()
+endif ()
+
+string(TOUPPER ${BUILD_TARGET} BUILD_TARGET)
+
+# Add definitions for the build target
+if (BUILD_TARGET STREQUAL "X86_64")
+  add_definitions(-DBUILD_TARGET_X86_64)
+elseif (BUILD_TARGET STREQUAL "AMD_64")
+  add_definitions(-DBUILD_TARGET_AMD_64)
+elseif (BUILD_TARGET STREQUAL "X86_32")
+  add_definitions(-DBUILD_TARGET_X86_32)
+elseif (BUILD_TARGET STREQUAL "ARM_32")
+  add_definitions(-DBUILD_TARGET_ARM_32)
+elseif (BUILD_TARGET STREQUAL "MIPS_32")
+  add_definitions(-DBUILD_TARGET_MIPS_32)
+elseif (BUILD_TARGET STREQUAL "XTENSA_32")
+  add_definitions(-DBUILD_TARGET_XTENSA_32)
 else ()
 else ()
-  add_definitions (-m32)
-  set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
-  set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
+  message (FATAL_ERROR "-- Build target isn't set")
 endif ()
 endif ()
+
+message ("-- Build as target ${BUILD_TARGET}")
+
+if (CMAKE_SIZEOF_VOID_P EQUAL 8)
+  if (BUILD_TARGET STREQUAL "X86_64" OR BUILD_TARGET STREQUAL "AMD_64")
+    # Add -fPIC flag if build as 64-bit
+    set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
+    set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
+  else ()
+    add_definitions (-m32)
+    set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
+    set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
+  endif ()
 endif ()
 endif ()
 
 
 if (NOT CMAKE_BUILD_TYPE)
 if (NOT CMAKE_BUILD_TYPE)
 SET(CMAKE_BUILD_TYPE Debug)
 SET(CMAKE_BUILD_TYPE Debug)
 endif (NOT CMAKE_BUILD_TYPE)
 endif (NOT CMAKE_BUILD_TYPE)
-message ("CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE})
+message ("-- CMAKE_BUILD_TYPE = " ${CMAKE_BUILD_TYPE})
 
 
 if (NOT PLATFORM)
 if (NOT PLATFORM)
 SET(PLATFORM linux)
 SET(PLATFORM linux)
 endif (NOT PLATFORM)
 endif (NOT PLATFORM)
-message ("PLATFORM = " ${PLATFORM})
+message ("-- PLATFORM = " ${PLATFORM})
 
 
 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -Wno-pedantic")
 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -Wno-pedantic")