提交 8f3e745b 编写于 作者: C Caoruihong

feat: add support for gcc toolchain

Signed-off-by: NCaoruihong <crh.cao@huawei.com>
Change-Id: I021d034446f7440a7529ae2b34685752bb104763
上级 77ef1a46
...@@ -29,10 +29,10 @@ ...@@ -29,10 +29,10 @@
group("sysroot") { group("sysroot") {
print("ohos_build_compiler:", ohos_build_compiler) print("ohos_build_compiler:", ohos_build_compiler)
if (ohos_build_compiler == "clang") { print("ohos_kernel_type:", ohos_kernel_type)
if (ohos_kernel_type != "liteos_m") {
deps = [ "build" ] deps = [ "build" ]
} } else if (!ohos_kernel_is_prebuilt) {
if (ohos_kernel_type == "liteos_m" && !ohos_kernel_is_prebuilt) {
all_dependent_configs = [ "//kernel/liteos_m:public" ] all_dependent_configs = [ "//kernel/liteos_m:public" ]
} }
} }
...@@ -48,8 +48,12 @@ build_ext_component("build_sysroot") { ...@@ -48,8 +48,12 @@ build_ext_component("build_sysroot") {
if (!defined(board_configed_sysroot) || board_configed_sysroot == "") { if (!defined(board_configed_sysroot) || board_configed_sysroot == "") {
makefile = rebase_path("Makefile", exec_path) makefile = rebase_path("Makefile", exec_path)
command = "make TOPDIR=$ohos_root_path SYSROOTDIR=$sysroot_path TARGETS=$targets -f $makefile" command = "make TOPDIR=$ohos_root_path SYSROOTDIR=$sysroot_path TARGETS=$targets -f $makefile"
command += " ARCH=$arch TARGET=$target_triple ARCH_CFLAGS=\"$arch_cflags\"" command += " ARCH=$arch ARCH_CFLAGS=\"$arch_cflags\""
command += " BUILD_ALL_MULTILIB=false CLANG=\"$ohos_current_cc_command\"" if (ohos_build_compiler == "clang") {
command += " CLANG=\"$ohos_current_cc_command\" TARGET=$target_triple"
} else {
command += " GCC=\"$ohos_current_cc_command\""
}
if (ohos_build_type == "debug") { if (ohos_build_type == "debug") {
command += " BUILD_DEBUG=true" command += " BUILD_DEBUG=true"
} }
...@@ -63,26 +67,39 @@ build_ext_component("build_sysroot") { ...@@ -63,26 +67,39 @@ build_ext_component("build_sysroot") {
command = "true" command = "true"
} }
# copy standard libraries libc.so and libc++.so to lib out dir # copy C/C++ runtime libraries to lib out dir
libcpp = "\$($ohos_current_cxx_command --target=$target_triple --sysroot=$sysroot_path $arch_cflags -print-file-name=libc++.so)" if (ohos_build_compiler == "clang") {
libc = "\$($ohos_current_cc_command --target=$target_triple --sysroot=$sysroot_path $arch_cflags -print-file-name=libc.so)" libcpp = "\$($ohos_current_cxx_command --target=$target_triple --sysroot=$sysroot_path $arch_cflags -print-file-name=libc++.so)"
libc = "\$($ohos_current_cc_command --target=$target_triple --sysroot=$sysroot_path $arch_cflags -print-file-name=libc.so)"
libgcc = ""
} else {
libcpp = "\$($ohos_current_cxx_command --sysroot=$sysroot_path $arch_cflags -print-file-name=libstdc++.so.6)"
libc = "\$($ohos_current_cc_command --sysroot=$sysroot_path $arch_cflags -print-file-name=libc.so)"
libgcc = "\$($ohos_current_cc_command --sysroot=$sysroot_path $arch_cflags -print-file-name=libgcc_s.so)"
}
lib_out_dir = rebase_path("$root_out_dir/unstripped/usr/lib", exec_path) lib_out_dir = rebase_path("$root_out_dir/unstripped/usr/lib", exec_path)
command += command += " && mkdir -p $lib_out_dir && sh -c \"cp -f $libcpp $libc $libgcc $lib_out_dir\""
" && mkdir -p $lib_out_dir && sh -c \"cp -f $libcpp $libc $lib_out_dir\""
outputs = [ if (ohos_build_compiler == "clang") {
"$root_out_dir/unstripped/usr/lib/libc.so", outputs = [
"$root_out_dir/unstripped/usr/lib/libc++.so", "$root_out_dir/unstripped/usr/lib/libc.so",
] "$root_out_dir/unstripped/usr/lib/libc++.so",
]
} else {
outputs = [
"$root_out_dir/unstripped/usr/lib/libc.so",
"$root_out_dir/unstripped/usr/lib/libstdc++.so.6",
"$root_out_dir/unstripped/usr/lib/libgcc_s.so",
]
}
} }
action_foreach("strip") { action_foreach("strip") {
deps = [ ":build_sysroot" ] deps = [ ":build_sysroot" ]
script = "//build/lite/run_shell_cmd.py" script = "//build/lite/run_shell_cmd.py"
sources = [ set_sources_assignment_filter([ "*.txt" ])
"$root_out_dir/unstripped/usr/lib/libc++.so", sources = get_target_outputs(deps[0])
"$root_out_dir/unstripped/usr/lib/libc.so",
]
outputs = [ "$root_out_dir/libs/{{source_file_part}}" ] outputs = [ "$root_out_dir/libs/{{source_file_part}}" ]
args = [ args = [
"$ohos_current_strip_command", "$ohos_current_strip_command",
...@@ -93,10 +110,17 @@ action_foreach("strip") { ...@@ -93,10 +110,17 @@ action_foreach("strip") {
} }
config("sysroot_flags") { config("sysroot_flags") {
cflags = [ if (ohos_build_compiler == "clang") {
"--target=$target_triple", cflags = [
"--sysroot=$sysroot_path", "--target=$target_triple",
] "--sysroot=$sysroot_path",
]
} else {
cflags = [
"--sysroot=$sysroot_path",
"-specs=musl-gcc.specs",
]
}
cflags_cc = cflags cflags_cc = cflags
ldflags = cflags ldflags = cflags
asmflags = cflags asmflags = cflags
......
...@@ -28,15 +28,21 @@ ...@@ -28,15 +28,21 @@
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ARCH = arm ARCH = arm
ifneq ($(GCC),)
TARGET =
CROSS_COMPILE = $(GCC:%gcc=%)
CC = $(GCC) $(ARCH_CFLAGS)
MULTILIB = $(patsubst %.,%,$(shell $(CC) -print-multi-directory))
else
TARGET = $(ARCH)-liteos TARGET = $(ARCH)-liteos
CLANG ?= clang CLANG ?= clang
CROSS_COMPILE = $(CLANG:%clang=%)llvm- CROSS_COMPILE = $(CLANG:%clang=%llvm-)
CC = $(CLANG) --target=$(TARGET) $(ARCH_CFLAGS) CC = $(CLANG) --target=$(TARGET) $(ARCH_CFLAGS)
MULTILIB = $(patsubst $(shell $(CC) -print-file-name=)%/,%,$(dir $(shell $(CC) -print-libgcc-file-name))) MULTILIB = $(patsubst $(dir $(shell $(filter-out $(ARCH_CFLAGS),$(CC)) -print-libgcc-file-name))%,/%,$(dir $(shell $(CC) -print-libgcc-file-name)))
MUSLBUILDDIR = build_$(ARCH)_$(subst /,_,$(MULTILIB)) endif
MUSLBUILDDIR = build_$(or $(TARGET),$(ARCH))$(subst /,_,$(MULTILIB:%/=%))
HIDE = @ HIDE = @
BUILD_DEBUG = false BUILD_DEBUG = false
BUILD_ALL_MULTILIB = true
SED_ARGS = -e '/install-libs:/s/if/and/g' SED_ARGS = -e '/install-libs:/s/if/and/g'
TOPDIR = $(shell pwd)/../../../.. TOPDIR = $(shell pwd)/../../../..
...@@ -46,7 +52,7 @@ OPTRTDIR = $(TOPDIR)/third_party/optimized-routines ...@@ -46,7 +52,7 @@ OPTRTDIR = $(TOPDIR)/third_party/optimized-routines
NUTTXDIR = $(TOPDIR)/third_party/NuttX NUTTXDIR = $(TOPDIR)/third_party/NuttX
SYSROOTDIR = $(TOPDIR)/prebuilts/lite/sysroot SYSROOTDIR = $(TOPDIR)/prebuilts/lite/sysroot
LITEOSADIR = $(TOPDIR)/kernel/liteos_a LITEOSADIR = $(TOPDIR)/kernel/liteos_a
LINUXDIR = $(TOPDIR)/kernel/linux-4.19 LINUXDIR = $(TOPDIR)/kernel/linux/linux-4.19
LINUXHDRDIR = $(PREBUILTLINUXHDRDIR) LINUXHDRDIR = $(PREBUILTLINUXHDRDIR)
TARGETS = $(if $(wildcard $(LITEOSADIR)),liteos_a_user,) TARGETS = $(if $(wildcard $(LITEOSADIR)),liteos_a_user,)
...@@ -125,19 +131,23 @@ musl_patch_for_liteos_a_user_debug: musl_copy_for_liteos_a_user ...@@ -125,19 +131,23 @@ musl_patch_for_liteos_a_user_debug: musl_copy_for_liteos_a_user
$(HIDE) cp -rfp $(MUSLDIR)/porting/liteos_a/user_debug/* $</ $(HIDE) cp -rfp $(MUSLDIR)/porting/liteos_a/user_debug/* $</
ifeq ($(BUILD_DEBUG),true) ifeq ($(BUILD_DEBUG),true)
ifeq ($(GCC),)
musl_install_for_liteos_a_user: LDFLAGS = $(shell $(CC) -print-file-name=libunwind.a) -Wl,--no-dependent-libraries
musl_install_for_liteos_a_user: SED_ARGS += -e 's,$$(AR) rc $$@ $$(AOBJS)$$,cp $$(shell $$(CC) -print-file-name=libunwind.a) $$@ \&\& &,g' musl_install_for_liteos_a_user: SED_ARGS += -e 's,$$(AR) rc $$@ $$(AOBJS)$$,cp $$(shell $$(CC) -print-file-name=libunwind.a) $$@ \&\& &,g'
endif
musl_install_for_liteos_a_user: SED_ARGS += -e 's,CFLAGS_ALL += -DCRT$$,& -fno-unwind-tables -fno-asynchronous-unwind-tables,g' musl_install_for_liteos_a_user: SED_ARGS += -e 's,CFLAGS_ALL += -DCRT$$,& -fno-unwind-tables -fno-asynchronous-unwind-tables,g'
musl_install_for_liteos_a_user: CFLAGS += -funwind-tables -fasynchronous-unwind-tables -rdynamic -I $(shell $(CC) "-print-file-name=include") musl_install_for_liteos_a_user: CFLAGS += -funwind-tables -fasynchronous-unwind-tables -rdynamic -I $(shell $(CC) "-print-file-name=include")
musl_install_for_liteos_a_user: LDFLAGS = $(shell $(CC) -print-file-name=libunwind.a) -Wl,--no-dependent-libraries
musl_install_for_liteos_a_user: musl_patch_for_liteos_a_user_debug musl_install_for_liteos_a_user: musl_patch_for_liteos_a_user_debug
endif endif
musl_install_for_liteos_a_user: musl_patch_for_liteos_a_user musl_install_for_liteos_a_user: musl_patch_for_liteos_a_user
$(HIDE) cd musl_copy_for_liteos_a_user && mkdir -p $(MUSLBUILDDIR) && cd $(MUSLBUILDDIR) && \ $(HIDE) cd musl_copy_for_liteos_a_user && mkdir -p $(MUSLBUILDDIR) && cd $(MUSLBUILDDIR) && \
../configure --prefix=/usr --target=$(TARGET) --includedir=/usr/include/$(TARGET) --libdir=/usr/$(MULTILIB) \ ../configure --prefix=$(SYSROOTDIR)/usr --target=$(TARGET) \
--includedir=$(SYSROOTDIR)/usr/include/$(TARGET) \
--libdir=$(SYSROOTDIR)/usr/lib/$(TARGET)/$(MULTILIB) \
$(if $(LDFLAGS),LDFLAGS="$(LDFLAGS)",) \ $(if $(LDFLAGS),LDFLAGS="$(LDFLAGS)",) \
CC="$(CC)" CROSS_COMPILE="$(CROSS_COMPILE)" CFLAGS="$(CFLAGS)" >/dev/null && \ CC="$(CC)" CROSS_COMPILE="$(CROSS_COMPILE)" CFLAGS="$(CFLAGS)" >/dev/null && \
sed $(SED_ARGS) Makefile | make -f- -sj install-headers install-libs DESTDIR=$(SYSROOTDIR) sed $(SED_ARGS) Makefile | make -f- -sj install
ifeq ($(wildcard $(LINUXHDRDIR)),) ifeq ($(wildcard $(LINUXHDRDIR)),)
LINUXHDRDIR = $(shell pwd)/linux_header_install_for_linux_user/usr/include LINUXHDRDIR = $(shell pwd)/linux_header_install_for_linux_user/usr/include
...@@ -150,62 +160,19 @@ musl_patch_for_linux_user: musl_copy_for_linux_user ...@@ -150,62 +160,19 @@ musl_patch_for_linux_user: musl_copy_for_linux_user
$(HIDE) cp -rfp $(MUSLDIR)/porting/linux/user/* $</ $(HIDE) cp -rfp $(MUSLDIR)/porting/linux/user/* $</
musl_install_for_linux_user: CFLAGS += -I $(LINUXHDRDIR) musl_install_for_linux_user: CFLAGS += -I $(LINUXHDRDIR)
ifeq ($(GCC),)
musl_install_for_linux_user: TARGET = $(ARCH)-linux-ohosmusl musl_install_for_linux_user: TARGET = $(ARCH)-linux-ohosmusl
endif
musl_install_for_linux_user: musl_patch_for_linux_user musl_install_for_linux_user: musl_patch_for_linux_user
$(HIDE) cd musl_copy_for_linux_user && mkdir -p $(MUSLBUILDDIR) && cd $(MUSLBUILDDIR) && \ $(HIDE) cd musl_copy_for_linux_user && mkdir -p $(MUSLBUILDDIR) && cd $(MUSLBUILDDIR) && \
../configure --prefix=/usr --target=$(TARGET) --includedir=/usr/include/$(TARGET) --libdir=/usr/$(MULTILIB) \ ../configure --prefix=$(SYSROOTDIR)/usr --target=$(TARGET) \
--includedir=$(SYSROOTDIR)/usr/include/$(TARGET) \
--libdir=$(SYSROOTDIR)/usr/lib/$(TARGET)/$(MULTILIB) \
CC="$(CC)" CROSS_COMPILE="$(CROSS_COMPILE)" CFLAGS="$(CFLAGS)" >/dev/null && \ CC="$(CC)" CROSS_COMPILE="$(CROSS_COMPILE)" CFLAGS="$(CFLAGS)" >/dev/null && \
sed $(SED_ARGS) Makefile | make -f- -sj install-headers install-libs DESTDIR=$(SYSROOTDIR) sed $(SED_ARGS) Makefile | make -f- -sj install
$(HIDE) cp -rfp $(LINUXHDRDIR)/* $(SYSROOTDIR)/usr/include/$(TARGET) $(HIDE) cp -rfp $(LINUXHDRDIR)/* $(SYSROOTDIR)/usr/include/$(TARGET)
$(HIDE) if [ -d $(LINUXHDRDIR)/asm-$(ARCH)/asm ]; then ln -snf asm-$(ARCH)/asm $(SYSROOTDIR)/usr/include/$(TARGET)/; fi $(HIDE) if [ -d $(LINUXHDRDIR)/asm-$(ARCH)/asm ]; then ln -snf asm-$(ARCH)/asm $(SYSROOTDIR)/usr/include/$(TARGET)/; fi
ifeq ($(ARCH),arm)
ifeq ($(BUILD_ALL_MULTILIB),true)
ARCH_CFLAGS1 = -mfloat-abi=soft -march=armv7-a
ARCH_CFLAGS2 = -mfloat-abi=soft -mcpu=cortex-a7
ARCH_CFLAGS3 = -mfloat-abi=hard -mcpu=cortex-a7 -mfpu=neon-vfpv4
ARCH_CFLAGS4 = -mfloat-abi=softfp -mcpu=cortex-a7 -mfpu=neon-vfpv4
define multilib_template =
ifneq ($$(ARCH_CFLAGS),$$($(2)))
.PHONY: musl_install_for_linux_user$(1) musl_install_for_liteos_a_user$(1)
all: $$(if $$(filter linux_user,$$(TARGETS)),musl_install_for_linux_user$(1),)
all: $$(if $$(filter liteos_a_user,$$(TARGETS)),musl_install_for_liteos_a_user$(1),)
musl_install_for_linux_user$(1): CFLAGS += -I $$(LINUXHDRDIR)
musl_install_for_linux_user$(1): TARGET = $$(ARCH)-linux-ohosmusl
musl_install_for_linux_user$(1): override ARCH_CFLAGS = $$($(2))
musl_install_for_linux_user$(1): musl_install_for_linux_user
$$(HIDE) cd musl_copy_for_linux_user && mkdir -p $$(MUSLBUILDDIR) && cd $$(MUSLBUILDDIR) && \
../configure --prefix=/usr --target=$$(TARGET) --libdir=/usr/$$(MULTILIB) \
CC="$$(CC)" CROSS_COMPILE="$$(CROSS_COMPILE)" CFLAGS="$$(CFLAGS)" >/dev/null && \
sed $$(SED_ARGS) Makefile | make -f- -sj install-libs DESTDIR=$$(SYSROOTDIR)
ifeq ($$(BUILD_DEBUG),true)
musl_install_for_liteos_a_user$(1): SED_ARGS += -e 's,$$$$(AR) rc $$$$@ $$$$(AOBJS)$$$$,cp $$$$(shell $$$$(CC) -print-file-name=libunwind.a) $$$$@ \&\& &,g'
musl_install_for_liteos_a_user$(1): SED_ARGS += -e 's,CFLAGS_ALL += -DCRT$$$$,& -fno-unwind-tables -fno-asynchronous-unwind-tables,g'
musl_install_for_liteos_a_user$(1): CFLAGS += -funwind-tables -fasynchronous-unwind-tables -rdynamic -I $$(shell $$(CC) "-print-file-name=include")
musl_install_for_liteos_a_user$(1): LDFLAGS = $$(shell $$(CC) -print-file-name=libunwind.a) -Wl,--no-dependent-libraries
endif
musl_install_for_liteos_a_user$(1): override ARCH_CFLAGS = $$($(2))
musl_install_for_liteos_a_user$(1): musl_install_for_liteos_a_user
$$(HIDE) cd musl_copy_for_liteos_a_user && mkdir -p $$(MUSLBUILDDIR) && cd $$(MUSLBUILDDIR) && \
../configure --prefix=/usr --target=$$(TARGET) --libdir=/usr/$$(MULTILIB) \
$$(if $$(LDFLAGS),LDFLAGS="$$(LDFLAGS)",) \
CC="$$(CC)" CROSS_COMPILE="$$(CROSS_COMPILE)" CFLAGS="$$(CFLAGS)" >/dev/null && \
sed $$(SED_ARGS) Makefile | make -f- -sj install-libs DESTDIR=$$(SYSROOTDIR)
endif
endef
$(foreach flags,1 2 3 4,$(eval $(call multilib_template,$(flags),ARCH_CFLAGS$(flags))))
endif
endif
clean: clean:
$(HIDE) rm -rf musl_copy_for_* linux_header_install_for_* $(HIDE) rm -rf musl_copy_for_* linux_header_install_for_*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册