提交 6e886d42 编写于 作者: C Caoruihong

feat(build): support gcc toolchain

Signed-off-by: NCaoruihong <crh.cao@huawei.com>
Change-Id: I6f2dea19cbd2e5b562bb51e30592205a2bb4fbdb
上级 67e31f7b
......@@ -29,17 +29,14 @@
import("//build/lite/config/component/lite_component.gni")
LITEOS_MENUCONFIG_H = rebase_path("$root_out_dir/config.h")
declare_args() {
tee_enable = false
liteos_name = "OHOS_Image"
liteos_skip_make = false
}
cmd = "if [ -f $device_path/BUILD.gn ]; then echo true; else echo false; fi"
HAVE_DEVICE_SDK = exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
LITEOS_MENUCONFIG_H = rebase_path("$root_out_dir/config.h")
tee = ""
if (tee_enable) {
tee = "_tee"
......@@ -68,6 +65,8 @@ import("liteos.gni")
assert(ARCH != "", "ARCH not set!")
assert(ARCH == arch, "ARCH not match! details: $ARCH != $arch")
assert(tee_enable == defined(LOSCFG_TEE_ENABLE), "TEE switch not match!")
assert(ohos_build_compiler == "clang" == defined(LOSCFG_COMPILER_CLANG_LLVM),
"compiler not match!")
generate_notice_file("kernel_notice_file") {
module_name = "kernel"
......@@ -83,6 +82,8 @@ generate_notice_file("kernel_notice_file") {
]
}
visibility = [ ":*" ]
liteos_arch_cflags = []
if (defined(LOSCFG_ARCH_ARM)) {
mcpu = LOSCFG_ARCH_CPU
......@@ -175,7 +176,7 @@ config("optimize_config") {
if (defined(LOSCFG_COMPILER_CLANG_LLVM)) {
cflags += [ "-flto=thin" ]
} else {
cflags += [ "-flto" ]
#cflags += [ "-flto" ]
}
}
cflags += [ optimization_cflag ]
......@@ -197,8 +198,10 @@ config("warn_config") {
"-Wpointer-arith",
"-Wstrict-prototypes",
"-Winvalid-pch",
"-Wno-address-of-packed-member",
]
if (defined(LOSCFG_COMPILER_CLANG_LLVM)) {
cflags += [ "-Wno-address-of-packed-member" ]
}
asmflags = cflags
}
......@@ -209,6 +212,7 @@ config("dialect_config") {
config("misc_config") {
defines = [ "__LITEOS__" ]
defines += [ "__LITEOS_A__" ]
if (!defined(LOSCFG_DEBUG_VERSION)) {
defines += [ "NDEBUG" ]
}
......@@ -248,62 +252,8 @@ config("los_config") {
]
}
executable("liteos") {
configs = [] # clear default configs
configs += [ ":arch_config" ]
configs += [ ":public" ]
ldflags = [
"-static",
"-nostdlib",
"-Wl,--gc-sections",
"-Wl,-Map=$liteos_name.map",
"-Wl,--no-eh-frame-hdr",
]
libgcc = exec_script("//build/lite/run_shell_cmd.py",
[ "$cc -print-libgcc-file-name" ],
"trim string")
libs = [ libgcc ]
if (defined(LOSCFG_COMPILER_CLANG_LLVM)) {
ldflags +=
[ "-Wl,-T" + rebase_path("tools/build/liteos_llvm.ld", root_build_dir) ]
inputs = [ "tools/build/liteos_llvm.ld" ]
} else {
ldflags +=
[ "-Wl,-T" + rebase_path("tools/build/liteos.ld", root_build_dir) ]
ldflags += [ "-Wl,-nostartfiles" ]
inputs = [ "tools/build/liteos.ld" ]
}
inputs += [ "$root_out_dir/board.ld" ]
output_dir = target_out_dir
deps = [
":modules",
"platform:copy_board.ld",
]
}
copy("copy_liteos") {
deps = [ ":liteos" ]
sources = [ "$target_out_dir/unstripped/bin/liteos" ]
outputs = [ "$root_out_dir/$liteos_name" ]
}
build_ext_component("build_kernel_image") {
deps = [ ":copy_liteos" ]
exec_path = rebase_path(root_out_dir)
objcopy = "${compile_prefix}objcopy$toolchain_cmd_suffix"
objdump = "${compile_prefix}objdump$toolchain_cmd_suffix"
command = "$objcopy -O binary $liteos_name $liteos_name.bin"
command +=
" && sh -c '$objdump -t $liteos_name | sort >$liteos_name.sym.sorted'"
command += " && sh -c '$objdump -d $liteos_name >$liteos_name.asm'"
}
cmd = "if [ -f $device_path/BUILD.gn ]; then echo true; else echo false; fi"
HAVE_DEVICE_SDK = exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
config("public") {
configs = [
......@@ -364,16 +314,69 @@ group("tests") {
group("kernel") {
deps = [ ":build_kernel_image" ]
visibility += [ "//build/lite:ohos" ]
}
group("liteos_a") {
}
executable("liteos") {
configs = [] # clear default configs
configs += [ ":arch_config" ]
configs += [ ":public" ]
ldflags = [
"-static",
"-nostdlib",
"-Wl,--gc-sections",
"-Wl,-Map=$liteos_name.map",
"-Wl,--no-eh-frame-hdr",
]
libgcc = exec_script("//build/lite/run_shell_cmd.py",
[ "$cc -print-libgcc-file-name" ],
"trim string")
libs = [ libgcc ]
if (defined(LOSCFG_COMPILER_CLANG_LLVM)) {
ldflags +=
[ "-Wl,-T" + rebase_path("tools/build/liteos_llvm.ld", root_build_dir) ]
inputs = [ "tools/build/liteos_llvm.ld" ]
} else {
ldflags +=
[ "-Wl,-T" + rebase_path("tools/build/liteos.ld", root_build_dir) ]
ldflags += [ "-Wl,-nostartfiles" ]
inputs = [ "tools/build/liteos.ld" ]
}
inputs += [ "$root_out_dir/board.ld" ]
output_dir = target_out_dir
deps = [
":apps",
":kernel",
":tests",
":modules",
"platform:copy_board.ld",
]
}
copy("copy_liteos") {
deps = [ ":liteos" ]
sources = [ "$target_out_dir/unstripped/bin/liteos" ]
outputs = [ "$root_out_dir/$liteos_name" ]
}
build_ext_component("build_kernel_image") {
deps = [ ":copy_liteos" ]
exec_path = rebase_path(root_out_dir)
objcopy = "${compile_prefix}objcopy$toolchain_cmd_suffix"
objdump = "${compile_prefix}objdump$toolchain_cmd_suffix"
command = "$objcopy -O binary $liteos_name $liteos_name.bin"
command +=
" && sh -c '$objdump -t $liteos_name | sort >$liteos_name.sym.sorted'"
command += " && sh -c '$objdump -d $liteos_name >$liteos_name.asm'"
}
build_ext_component("make") {
exec_path = rebase_path(".", root_build_dir)
outdir = rebase_path("$target_out_dir/${target_name}_out")
......
......@@ -61,12 +61,6 @@ endif
KCONFIG_CONFIG ?= $(CONFIG)
SYSROOT_PATH ?= $(OUT)/sysroot
LITEOS_MENUCONFIG_H ?= $(LITEOSTOPDIR)/config.h
LITEOS_CONFIG_FILE ?= $(LITEOSTOPDIR)/.config
# export los_config.mk related environment variables
export LITEOS_MENUCONFIG_H
export LITEOS_CONFIG_FILE
# export subdir Makefile related environment variables
export SYSROOT_PATH
......@@ -125,7 +119,6 @@ help:
sysroot:
$(HIDE)echo "sysroot:" $(abspath $(SYSROOT_PATH))
ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
ifeq ($(origin SYSROOT_PATH),file)
$(HIDE)mkdir -p $(SYSROOT_PATH)/build && cd $(SYSROOT_PATH)/build && \
ln -snf $(LITEOSTOPDIR)/../../prebuilts/lite/sysroot/build/Makefile && \
......@@ -135,11 +128,9 @@ ifeq ($(origin SYSROOT_PATH),file)
ARCH_CFLAGS="$(LITEOS_CORE_COPTS) -w" \
TOPDIR="$(LITEOSTOPDIR)/../.." \
SYSROOTDIR="$(SYSROOT_PATH)" \
CLANG="$(LITEOS_COMPILER_PATH)clang" \
BUILD_ALL_MULTILIB=false \
$(if $(LOSCFG_COMPILER_CLANG_LLVM),CLANG="$(LITEOS_COMPILER_PATH)clang",GCC="$(CC)") \
BUILD_DEBUG=$(if $(patsubst y,,$(or $(RELEASE:1=y),n)),true,false)
endif
endif
$(filter-out menuconfig,$(KCONFIG_CMDS)):
$(HIDE)$@ $(args)
......
......@@ -34,14 +34,7 @@ export APPSTOPDIR
include $(APPSTOPDIR)/config.mk
all:
ifneq ($(APP_SUBDIRS), )
$(HIDE) for dir in $(APP_SUBDIRS); do $(MAKE) -C $$dir all || exit 1; done
endif
clean:
ifneq ($(APP_SUBDIRS), )
$(HIDE) for dir in $(APP_SUBDIRS); do $(MAKE) -C $$dir clean || exit 1; done
endif
all clean:
$(HIDE) for dir in $(APP_SUBDIRS); do $(MAKE) -C $$dir $@ || exit 1; done
.PHONY: all clean
......@@ -38,7 +38,7 @@ LITEOS_CXXOPTS := $(LITEOS_CXXOPTS_BASE)
LITEOS_INCLUDE := $(LITEOS_KERNEL_INCLUDE) $(LITEOS_EXTKERNEL_INCLUDE) \
$(LITEOS_COMPAT_INCLUDE) $(LITEOS_FS_INCLUDE) \
$(LITEOS_NET_INCLUDE) $(LITEOS_LIB_INCLUDE) \
$(LITEOS_DRIVERS_INCLUDE) $(LOSCFG_TOOLS_DEBUG_INCLUDE) \
$(LITEOS_DRIVERS_INCLUDE) $(LITEOS_TOOLS_DEBUG_INCLUDE) \
$(LITEOS_PLATFORM_INCLUDE) $(LITEOS_DFX_INCLUDE) \
$(LITEOS_SECURITY_INCLUDE)
LITEOS_LIBDEP := $(LITEOS_BASELIB)
......
......@@ -29,29 +29,10 @@
import("//kernel/liteos_a/liteos.gni")
group("drivers") {
deps = [
"block/disk",
"char/bch",
"char/mem",
"char/perf",
"char/quickstart",
"char/random",
"char/trace",
"char/video",
"mtd/multi_partition",
]
}
config("public") {
configs = [
"block/disk:public",
"char/bch:public",
"char/mem:public",
"char/quickstart:public",
"char/random:public",
"char/video:public",
"char/trace:public",
"mtd/multi_partition:public",
module_group("drivers") {
modules = [
"block",
"char",
"mtd",
]
}
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_a/liteos.gni")
module_group("block") {
modules = [ "disk" ]
}
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_a/liteos.gni")
module_group("char") {
modules = [
"bch",
"mem",
"perf",
"quickstart",
"random",
"trace",
"video",
]
}
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
# to endorse or promote products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import("//kernel/liteos_a/liteos.gni")
module_group("mtd") {
modules = [ "multi_partition" ]
}
......@@ -41,28 +41,58 @@ if (defined(LOSCFG_ARCH_ARM_AARCH32)) {
}
template("kernel_module") {
build_gn = rebase_path("BUILD.gn")
cmd = "grep -c '^\s*\(kernel_module\|hdf_driver\)\s*(\s*\S*\s*)\s*{\s*\$' $build_gn"
modules_count = exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
if (modules_count == 1) {
auto_config = true
}
cmd = "if grep -q '^\s*\(config\s*(\s*\"public\"\s*)\|module_group\s*(\s*\"\S*\"\s*)\)\s*{\s*\$' $build_gn; then echo true; else echo false; fi"
has_public_config =
exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
if (!has_public_config && defined(auto_config)) {
config("public") {
configs = []
}
}
current_dir_name = get_path_info(rebase_path("."), "file")
if (target_name != current_dir_name) {
build_gn = rebase_path("BUILD.gn")
cmd = "if grep -q '^\s*group\s*(\s*\"$current_dir_name\"\s*)\s*{\s*\$' $build_gn; then echo true; else echo false; fi"
cmd = "if grep -q '^\s*\(module_group\|group\)\s*(\s*\"$current_dir_name\"\s*)\s*{\s*\$' $build_gn; then echo true; else echo false; fi"
has_current_dir_group =
exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
if (!has_current_dir_group) {
if (!has_current_dir_group && defined(auto_config)) {
module_name = target_name
group(current_dir_name) {
public_deps = [ ":$module_name" ]
}
}
}
if (defined(invoker.module_switch) && !invoker.module_switch) {
group(target_name) {
not_needed(invoker, "*")
}
} else {
source_set(target_name) {
public_configs = []
forward_variables_from(invoker, "*")
if (has_public_config) {
included_public_config = false
foreach(cfg, public_configs) {
what = "label_no_toolchain"
if (get_label_info(cfg, what) == get_label_info(":public", what)) {
included_public_config = true
}
}
if (!included_public_config) {
public_configs += [ ":public" ]
}
}
}
}
not_needed([ "auto_config" ])
}
template("config") {
......@@ -77,9 +107,37 @@ template("config") {
}
}
template("module_group") {
assert(defined(invoker.modules), "modules are must")
group(target_name) {
deps = []
foreach(m, invoker.modules) {
deps += [ m ]
}
if (defined(invoker.deps)) {
deps += invoker.deps
}
}
config("public") {
configs = []
foreach(m, invoker.modules) {
configs += [ "$m:public" ]
}
if (defined(invoker.configs)) {
configs += invoker.configs
}
}
}
set_defaults("kernel_module") {
configs = [
"$LITEOSTOPDIR:public",
"$LITEOSTOPDIR:los_config",
]
visibility = [
"$LITEOSTOPDIR:*",
":*",
"..:*",
"../..:*",
]
}
......@@ -27,6 +27,9 @@
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
LITEOS_MENUCONFIG_H ?= $(LITEOSTOPDIR)/config.h
LITEOS_CONFIG_FILE ?= $(LITEOSTOPDIR)/.config
-include $(LITEOS_CONFIG_FILE)
ifeq ($(ARCH),)
......@@ -46,7 +49,7 @@ get_compiler_path = $(or $(wildcard $(1)),$(dir $(shell which $(CROSS_COMPILE)as
ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
CROSS_COMPILE ?= llvm-
LITEOS_COMPILER_PATH ?= $(call get_compiler_path,$(LITEOSTOPDIR)/../../prebuilts/clang/ohos/linux-x86_64/llvm/bin/)
LLVM_TARGET = $(if $(LOSCFG_LLVM_TARGET),-target $(LOSCFG_LLVM_TARGET),)
LLVM_TARGET = $(if $(LOSCFG_LLVM_TARGET:"%"=%),--target=$(LOSCFG_LLVM_TARGET:"%"=%),)
LLVM_SYSROOT = $(if $(SYSROOT_PATH),--sysroot=$(SYSROOT_PATH),)
CC = $(LITEOS_COMPILER_PATH)clang $(LLVM_TARGET) $(LLVM_SYSROOT)
AS = $(LITEOS_COMPILER_PATH)$(CROSS_COMPILE)as
......@@ -59,7 +62,7 @@ SIZE = $(LITEOS_COMPILER_PATH)$(CROSS_COMPILE)size
NM = $(LITEOS_COMPILER_PATH)$(CROSS_COMPILE)nm
STRIP = $(LITEOS_COMPILER_PATH)$(CROSS_COMPILE)strip
else ifeq ($(LOSCFG_COMPILER_GCC), y)
CROSS_COMPILE ?= $(LOSCFG_CROSS_COMPILE)
CROSS_COMPILE ?= $(LOSCFG_CROSS_COMPILE:"%"=%)
LITEOS_COMPILER_PATH ?= $(call get_compiler_path,$(LITEOSTOPDIR)/../../prebuilts/gcc/linux-x86/arm/arm-linux-ohoseabi-gcc/bin/)
CC = $(LITEOS_COMPILER_PATH)$(CROSS_COMPILE)gcc
AS = $(LITEOS_COMPILER_PATH)$(CROSS_COMPILE)as
......@@ -542,7 +545,7 @@ LITEOS_DFX_INCLUDE := $(LITEOS_HILOG_INCLUDE) \
$(LITEOS_HIDUMPER_INCLUDE)
LITEOS_SECURITY_INCLUDE := $(LITEOS_SECURITY_CAP_INC) $(LITEOS_SECURITY_VID_INC)
LOSCFG_TOOLS_DEBUG_INCLUDE := $(LITEOS_SHELL_INCLUDE) $(LITEOS_UART_INCLUDE) \
LITEOS_TOOLS_DEBUG_INCLUDE := $(LITEOS_SHELL_INCLUDE) $(LITEOS_UART_INCLUDE) \
$(LITEOS_TELNET_INCLUDE)
LITEOS_COMMON_OPTS := -fno-pic -fno-builtin -nostdinc -nostdlib -Wall -Werror -fms-extensions -fno-omit-frame-pointer -Wno-address-of-packed-member -Winvalid-pch
......
......@@ -37,7 +37,7 @@ LOCAL_OBJS = $(addprefix $(OBJOUT)/,$(addsuffix .o,$(basename $(subst $(TOPDIR)/
all : $(TARGET)
ifeq ($(HIDE),@)
ECHO = $1 = echo " $1" $$(patsubst $$(OUT)/%,%,$$@) && $($1)
ECHO = $1 = echo " $1" $$(patsubst $$(OUT)/%,%,$$@) && $1(){ if ! $($1) "$$$$@"; then echo command details: $($1) "$$$$@"; false; fi;};$1
$(foreach cmd,CC GPP AS AR LD,$(eval $(call ECHO,$(cmd))))
endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册