[Feature]add MT2731_MP2_MR2_SVN388 baseline version
Change-Id: Ief04314834b31e27effab435d3ca8ba33b499059
diff --git a/meta/meta-clang/classes/clang.bbclass b/meta/meta-clang/classes/clang.bbclass
new file mode 100644
index 0000000..d6a4e9b
--- /dev/null
+++ b/meta/meta-clang/classes/clang.bbclass
@@ -0,0 +1,66 @@
+# Add the necessary override
+CC_toolchain-clang = "${CCACHE}${HOST_PREFIX}clang ${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}"
+CXX_toolchain-clang = "${CCACHE}${HOST_PREFIX}clang++ ${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}"
+CPP_toolchain-clang = "${CCACHE}${HOST_PREFIX}clang ${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS} -E"
+CCLD_toolchain-clang = "${CCACHE}${HOST_PREFIX}clang ${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}"
+CLANG_TIDY_EXE_toolchain-clang = "${CCACHE}${HOST_PREFIX}clang-tidy ${HOST_CC_ARCH}${TOOLCHAIN_OPTIONS}"
+RANLIB_toolchain-clang = "${HOST_PREFIX}llvm-ranlib"
+AR_toolchain-clang = "${HOST_PREFIX}llvm-ar"
+NM_toolchain-clang = "${HOST_PREFIX}llvm-nm"
+
+COMPILER_RT ??= "--rtlib=compiler-rt"
+LIBCPLUSPLUS ??= "--stdlib=libc++"
+
+COMPILER_RT_toolchain-gcc = ""
+LIBCPLUSPLUS_toolchain-gcc = ""
+
+TARGET_CXXFLAGS_append_toolchain-clang = " ${LIBCPLUSPLUS}"
+TUNE_CCARGS_append_toolchain-clang = " ${COMPILER_RT} ${LIBCPLUSPLUS}"
+
+THUMB_TUNE_CCARGS_remove_toolchain-clang = "-mthumb-interwork"
+TUNE_CCARGS_remove_toolchain-clang = "-meb"
+TUNE_CCARGS_remove_toolchain-clang = "-mel"
+TUNE_CCARGS_append_toolchain-clang = "${@bb.utils.contains("TUNE_FEATURES", "bigendian", " -mbig-endian", " -mlittle-endian", d)}"
+
+TUNE_CCARGS_remove_toolchain-clang_powerpc = "-mhard-float"
+TUNE_CCARGS_remove_toolchain-clang_powerpc = "-mno-spe"
+
+TUNE_CCARGS_append_toolchain-clang = " -Wno-error=unused-command-line-argument -Qunused-arguments"
+
+LDFLAGS_append_toolchain-clang_class-nativesdk_x86-64 = " -Wl,-dynamic-linker,${base_libdir}/ld-linux-x86-64.so.2"
+LDFLAGS_append_toolchain-clang_class-nativesdk_x86 = " -Wl,-dynamic-linker,${base_libdir}/ld-linux.so.2"
+LDFLAGS_append_toolchain-clang_class-nativesdk_aarch64 = " -Wl,-dynamic-linker,${base_libdir}/ld-linux-aarch64.so.1"
+
+LDFLAGS_toolchain-clang_class-nativesdk = "${BUILDSDK_LDFLAGS} \
+ -Wl,-rpath-link,${STAGING_LIBDIR}/.. \
+ -Wl,-rpath,${libdir}/.. "
+
+# Enable lld globally"
+LDFLAGS_append_toolchain-clang = "${@bb.utils.contains('DISTRO_FEATURES', 'ld-is-lld', ' -fuse-ld=lld', '', d)}"
+
+# choose between 'gcc' 'clang' an empty '' can be used as well
+TOOLCHAIN ??= "gcc"
+
+TOOLCHAIN_class-native = "gcc"
+TOOLCHAIN_class-nativesdk = "gcc"
+TOOLCHAIN_class-cross-canadian = "gcc"
+TOOLCHAIN_class-crosssdk = "gcc"
+TOOLCHAIN_class-cross = "gcc"
+
+OVERRIDES =. "${@['', 'toolchain-${TOOLCHAIN}:']['${TOOLCHAIN}' != '']}"
+OVERRIDES[vardepsexclude] += "TOOLCHAIN"
+
+#DEPENDS_append_toolchain-clang_class-target = " clang-cross-${TARGET_ARCH} "
+#DEPENDS_remove_toolchain-clang_allarch = "clang-cross-${TARGET_ARCH}"
+
+def clang_dep_prepend(d):
+ if not d.getVar('INHIBIT_DEFAULT_DEPS', False):
+ if not oe.utils.inherits(d, 'allarch') :
+ return " clang-cross-${TARGET_ARCH} compiler-rt libcxx"
+ return ""
+
+BASEDEPENDS_remove_toolchain-clang_class-target = "virtual/${TARGET_PREFIX}gcc virtual/${TARGET_PREFIX}compilerlibs"
+BASEDEPENDS_append_toolchain-clang_class-target = "${@clang_dep_prepend(d)}"
+
+PREFERRED_PROVIDER_libunwind = "libunwind"
+PREFERRED_PROVIDER_libunwind_mipsarch = "libunwind"
diff --git a/meta/meta-clang/classes/cmake-native.bbclass b/meta/meta-clang/classes/cmake-native.bbclass
new file mode 100644
index 0000000..7cdb89d
--- /dev/null
+++ b/meta/meta-clang/classes/cmake-native.bbclass
@@ -0,0 +1,51 @@
+# We need to unset CCACHE otherwise cmake gets too confused
+CCACHE = ""
+
+# Native C/C++ compiler (without cpu arch/tune arguments)
+OECMAKE_NATIVE_C_COMPILER ?= "`echo ${BUILD_CC} | sed 's/^\([^ ]*\).*/\1/'`"
+OECMAKE_NATIVE_CXX_COMPILER ?= "`echo ${BUILD_CXX} | sed 's/^\([^ ]*\).*/\1/'`"
+OECMAKE_NATIVE_AR ?= "${BUILD_AR}"
+OECMAKE_NATIVE_RANLIB ?= "${BUILD_RANLIB}"
+OECMAKE_NATIVE_NM ?= "${BUILD_NM}"
+
+# Native compiler flags
+OECMAKE_NATIVE_C_FLAGS ?= "${BUILD_CC_ARCH} ${BUILD_CFLAGS}"
+OECMAKE_NATIVE_CXX_FLAGS ?= "${BUILD_CC_ARCH} ${BUILD_CXXFLAGS}"
+OECMAKE_NATIVE_C_FLAGS_RELEASE ?= "-DNDEBUG"
+OECMAKE_NATIVE_CXX_FLAGS_RELEASE ?= "-DNDEBUG"
+OECMAKE_NATIVE_C_LINK_FLAGS ?= "${BUILD_CC_ARCH} ${BUILD_CPPFLAGS} ${BUILD_LDFLAGS}"
+OECMAKE_NATIVE_CXX_LINK_FLAGS ?= "${BUILD_CC_ARCH} ${BUILD_CXXFLAGS} ${BUILD_LDFLAGS}"
+BUILD_CXXFLAGS += "${BUILD_CC_ARCH}"
+BUILD_CFLAGS += "${BUILD_CC_ARCH}"
+
+do_generate_native_toolchain_file() {
+ cat > ${WORKDIR}/toolchain-native.cmake <<EOF
+set( CMAKE_SYSTEM_NAME `echo ${BUILD_OS} | sed -e 's/^./\u&/' -e 's/^\(Linux\).*/\1/'` )
+set( CMAKE_SYSTEM_PROCESSOR ${BUILD_ARCH} )
+set( CMAKE_C_COMPILER ${OECMAKE_NATIVE_C_COMPILER} )
+set( CMAKE_CXX_COMPILER ${OECMAKE_NATIVE_CXX_COMPILER} )
+set( CMAKE_ASM_COMPILER ${OECMAKE_NATIVE_C_COMPILER} )
+set( CMAKE_AR ${OECMAKE_NATIVE_AR} CACHE FILEPATH "Archiver" )
+set( CMAKE_RANLIB ${OECMAKE_NATIVE_RANLIB} CACHE FILEPATH "Archive Indexer" )
+set( CMAKE_NM ${OECMAKE_NATIVE_NM} CACHE FILEPATH "Symbol Lister" )
+set( CMAKE_C_FLAGS "${OECMAKE_NATIVE_C_FLAGS}" CACHE STRING "CFLAGS" )
+set( CMAKE_CXX_FLAGS "${OECMAKE_NATIVE_CXX_FLAGS}" CACHE STRING "CXXFLAGS" )
+set( CMAKE_ASM_FLAGS "${OECMAKE_NATIVE_C_FLAGS}" CACHE STRING "ASM FLAGS" )
+set( CMAKE_C_FLAGS_RELEASE "${OECMAKE_NATIVE_C_FLAGS_RELEASE}" CACHE STRING "Additional CFLAGS for release" )
+set( CMAKE_CXX_FLAGS_RELEASE "${OECMAKE_NATIVE_CXX_FLAGS_RELEASE}" CACHE STRING "Additional CXXFLAGS for release" )
+set( CMAKE_ASM_FLAGS_RELEASE "${OECMAKE_NATIVE_C_FLAGS_RELEASE}" CACHE STRING "Additional ASM FLAGS for release" )
+set( CMAKE_C_LINK_FLAGS "${OECMAKE_NATIVE_C_LINK_FLAGS}" CACHE STRING "LDFLAGS" )
+set( CMAKE_CXX_LINK_FLAGS "${OECMAKE_NATIVE_CXX_LINK_FLAGS}" CACHE STRING "LDFLAGS" )
+
+set( CMAKE_FIND_ROOT_PATH ${STAGING_DIR_NATIVE} )
+set( CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY )
+set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH )
+set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
+set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
+
+# Use native cmake modules
+list(APPEND CMAKE_MODULE_PATH "${STAGING_DATADIR_NATIVE}/cmake/Modules/")
+EOF
+}
+
+addtask generate_native_toolchain_file after do_patch before do_configure
diff --git a/meta/meta-clang/classes/lto.bbclass b/meta/meta-clang/classes/lto.bbclass
new file mode 100644
index 0000000..80a3d4d
--- /dev/null
+++ b/meta/meta-clang/classes/lto.bbclass
@@ -0,0 +1,7 @@
+# Enable LTO based on global distro settings
+TOOLCHAIN_OPTIONS_append_toolchain-clang = "${@bb.utils.contains('DISTRO_FEATURES', 'thin-lto', ' -flto=thin -fuse-ld=gold', '', d)}"
+TOOLCHAIN_OPTIONS_append_toolchain-clang = "${@bb.utils.contains('DISTRO_FEATURES', 'full-lto', ' -flto=full -fuse-ld=gold', '', d)}"
+RANLIB_toolchain-clang = "${STAGING_BINDIR_TOOLCHAIN}/${TARGET_PREFIX}llvm-ranlib"
+AR_toolchain-clang = "${STAGING_BINDIR_TOOLCHAIN}/${TARGET_PREFIX}llvm-ar"
+NM_toolchain-clang = "${STAGING_BINDIR_TOOLCHAIN}/${TARGET_PREFIX}llvm-nm"
+
diff --git a/meta/meta-clang/classes/scan-build.bbclass b/meta/meta-clang/classes/scan-build.bbclass
new file mode 100644
index 0000000..e0de56b
--- /dev/null
+++ b/meta/meta-clang/classes/scan-build.bbclass
@@ -0,0 +1,58 @@
+# Copyright (C) 2018 Khem Raj <raj.khem@gmail.com>
+# Released under the MIT license (see COPYING.MIT for the terms)
+
+CFLAGS =+ "${TARGET_CC_ARCH} ${TOOLCHAIN_OPTIONS}"
+CXXFLAGS =+ "${TARGET_CC_ARCH} ${TOOLCHAIN_OPTIONS}"
+
+#EXTRA_ANALYZER_OPTIONS ?= "-analyze-headers"
+CLANG_SCAN_ENABLED ??= "1"
+#CLANG_SCAN_SERVER_IP ??= "127.0.0.1"
+CLANG_SCAN_SERVER_IP ??= "10.0.0.10"
+CLANG_SCAN_PORT ??= "8181"
+SCAN_RESULTS_DIR ?= "${TMPDIR}/static-scan/${PN}"
+
+scanbuild_munge_cc_cxx() {
+ cc="`echo ${CC} | cut -f1 -d " "`"
+ cxx="`echo ${CXX} | cut -f1 -d " "`"
+ export CC="${cc}"
+ export CXX="${cxx}"
+}
+
+do_configure[prefuncs] += "scanbuild_munge_cc_cxx"
+
+do_scanbuild() {
+ cc="`echo ${CC} | cut -f1 -d " "`"
+ cxx="`echo ${CXX} | cut -f1 -d " "`"
+ #mk="scan-build --use-cc=${cc} --use-c++=${cxx} --analyzer-target=${HOST_SYS} --html-title="${BP}" -o ${SCAN_RESULTS_DIR} ${EXTRA_ANALYZER_OPTIONS} make"
+ #export MAKE="${mk}"
+ export CC="${cc}"
+ export CXX="${cxx}"
+ scan-build --use-cc=${cc} --use-c++=${cxx} --analyzer-target=${HOST_SYS} --html-title="${BP}" -o ${SCAN_RESULTS_DIR} ${EXTRA_ANALYZER_OPTIONS} ${MAKE} ${EXTRA_OEMAKE}
+}
+
+do_scanview() {
+ bbplain "================================================================"
+ bbplain "Stating scan-view server at: http://${CLANG_SCAN_SERVER_IP}:${CLANG_SCAN_PORT}"
+ bbplain "Use Ctrl-C to exit"
+ bbplain "================================================================"
+ scan-view --host ${CLANG_SCAN_SERVER_IP} --port ${CLANG_SCAN_PORT} --allow-all-hosts ${SCAN_RESULTS_DIR}/*/
+}
+
+do_scanview[depends] += "${PN}:do_scanbuild"
+do_scanbuild[cleandirs] += "${SCAN_RESULTS_DIR}"
+do_scanbuild[dirs] += "${B}"
+do_scanview[dirs] += "${SCAN_RESULTS_DIR}"
+#do_build[recrdeptask] += "do_scanbuild"
+
+do_scanbuild[doc] = "Build and scan static analysis data using clang"
+do_scanview[doc] = "Start a webserver to visualize static analysis data"
+
+addtask scanbuild after do_configure before do_compile
+addtask scanview
+
+python () {
+ # Remove scanbuild task when scanning is not enabled
+ if not(d.getVar('CLANG_SCAN_ENABLED') == "1"):
+ for i in ['do_scanbuild', 'do_scanview']:
+ bb.build.deltask(i, d)
+}