提交 d4864a8a 编写于 作者: O openharmony_ci 提交者: Gitee

!70 添加对GCC工具链的支持

Merge pull request !70 from Caoruihong/support_gcc
......@@ -29,10 +29,10 @@
group("sysroot") {
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" ]
}
if (ohos_kernel_type == "liteos_m" && !ohos_kernel_is_prebuilt) {
} else if (!ohos_kernel_is_prebuilt) {
all_dependent_configs = [ "//kernel/liteos_m:public" ]
}
}
......@@ -48,8 +48,12 @@ build_ext_component("build_sysroot") {
if (!defined(board_configed_sysroot) || board_configed_sysroot == "") {
makefile = rebase_path("Makefile", exec_path)
command = "make TOPDIR=$ohos_root_path SYSROOTDIR=$sysroot_path TARGETS=$targets -f $makefile"
command += " ARCH=$arch TARGET=$target_triple ARCH_CFLAGS=\"$arch_cflags\""
command += " BUILD_ALL_MULTILIB=false CLANG=\"$ohos_current_cc_command\""
command += " ARCH=$arch ARCH_CFLAGS=\"$arch_cflags\""
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") {
command += " BUILD_DEBUG=true"
}
......@@ -63,26 +67,39 @@ build_ext_component("build_sysroot") {
command = "true"
}
# copy standard libraries libc.so and libc++.so to lib out dir
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)"
# copy C/C++ runtime libraries to lib out dir
if (ohos_build_compiler == "clang") {
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)
command +=
" && mkdir -p $lib_out_dir && sh -c \"cp -f $libcpp $libc $lib_out_dir\""
command += " && mkdir -p $lib_out_dir && sh -c \"cp -f $libcpp $libc $libgcc $lib_out_dir\""
outputs = [
"$root_out_dir/unstripped/usr/lib/libc.so",
"$root_out_dir/unstripped/usr/lib/libc++.so",
]
if (ohos_build_compiler == "clang") {
outputs = [
"$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") {
deps = [ ":build_sysroot" ]
script = "//build/lite/run_shell_cmd.py"
sources = [
"$root_out_dir/unstripped/usr/lib/libc++.so",
"$root_out_dir/unstripped/usr/lib/libc.so",
]
set_sources_assignment_filter([ "*.txt" ])
sources = get_target_outputs(deps[0])
outputs = [ "$root_out_dir/libs/{{source_file_part}}" ]
args = [
"$ohos_current_strip_command",
......@@ -93,10 +110,17 @@ action_foreach("strip") {
}
config("sysroot_flags") {
cflags = [
"--target=$target_triple",
"--sysroot=$sysroot_path",
]
if (ohos_build_compiler == "clang") {
cflags = [
"--target=$target_triple",
"--sysroot=$sysroot_path",
]
} else {
cflags = [
"--sysroot=$sysroot_path",
"-specs=musl-gcc.specs",
]
}
cflags_cc = cflags
ldflags = cflags
asmflags = cflags
......
......@@ -28,15 +28,21 @@
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ARCH = arm
ifneq ($(GCC),)
TARGET =
CROSS_COMPILE = $(GCC:%gcc=%)
CC = $(GCC) $(ARCH_CFLAGS)
MULTILIB = $(patsubst %.,%,$(shell $(CC) -print-multi-directory))
else
TARGET = $(ARCH)-liteos
CLANG ?= clang
CROSS_COMPILE = $(CLANG:%clang=%)llvm-
CROSS_COMPILE = $(CLANG:%clang=%llvm-)
CC = $(CLANG) --target=$(TARGET) $(ARCH_CFLAGS)
MULTILIB = $(patsubst $(shell $(CC) -print-file-name=)%/,%,$(dir $(shell $(CC) -print-libgcc-file-name)))
MUSLBUILDDIR = build_$(ARCH)_$(subst /,_,$(MULTILIB))
MULTILIB = $(patsubst $(dir $(shell $(filter-out $(ARCH_CFLAGS),$(CC)) -print-libgcc-file-name))%,/%,$(dir $(shell $(CC) -print-libgcc-file-name)))
endif
MUSLBUILDDIR = build_$(or $(TARGET),$(ARCH))$(subst /,_,$(MULTILIB:%/=%))
HIDE = @
BUILD_DEBUG = false
BUILD_ALL_MULTILIB = true
SED_ARGS = -e '/install-libs:/s/if/and/g'
TOPDIR = $(shell pwd)/../../../..
......@@ -46,7 +52,7 @@ OPTRTDIR = $(TOPDIR)/third_party/optimized-routines
NUTTXDIR = $(TOPDIR)/third_party/NuttX
SYSROOTDIR = $(TOPDIR)/prebuilts/lite/sysroot
LITEOSADIR = $(TOPDIR)/kernel/liteos_a
LINUXDIR = $(TOPDIR)/kernel/linux-4.19
LINUXDIR = $(TOPDIR)/kernel/linux/linux-4.19
LINUXHDRDIR = $(PREBUILTLINUXHDRDIR)
TARGETS = $(if $(wildcard $(LITEOSADIR)),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/* $</
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'
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: 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
endif
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) && \
../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)",) \
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)),)
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
$(HIDE) cp -rfp $(MUSLDIR)/porting/linux/user/* $</
musl_install_for_linux_user: CFLAGS += -I $(LINUXHDRDIR)
ifeq ($(GCC),)
musl_install_for_linux_user: TARGET = $(ARCH)-linux-ohosmusl
endif
musl_install_for_linux_user: musl_patch_for_linux_user
$(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 && \
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) 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:
$(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.
先完成此消息的编辑!
想要评论请 注册