diff --git a/BUILD.gn b/BUILD.gn index de886050e3264d0504e4c45ac97ee1087a9ced3c..36b14381ed0ebe2ff5599ba802ad15c0fcd338ad 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -378,7 +378,7 @@ group("liteos_a") { build_ext_component("make") { exec_path = rebase_path(".", root_build_dir) - outdir = rebase_path(get_path_info(".", "out_dir")) + outdir = rebase_path("$target_out_dir/${target_name}_out") sysroot_path = rebase_path(ohos_current_sysroot) arch_cflags = string_join(" ", target_arch_cflags) command = "./build.sh \"$board_name\" \"$ohos_build_compiler\" \"$root_build_dir\" \"$ohos_build_type\" \"$tee_enable\"" diff --git a/Makefile b/Makefile index 21013aaae2099e62bb4f5d888677c14be2ffef9f..cb86d5e81639b429d4dd77197c28ecff1abfcaf2 100644 --- a/Makefile +++ b/Makefile @@ -180,8 +180,8 @@ else $(HIDE)cp -fp $$($(CC) $(LITEOS_CFLAGS) -print-file-name=libgcc_s.so.1) $(OUT)/musl $(HIDE)cp -fp $$($(GPP) $(LITEOS_CXXFLAGS) -print-file-name=libstdc++.so.6) $(OUT)/musl endif - $(HIDE)$(STRIP) $(OUT)/musl/* $(HIDE)$(LITEOS_SCRIPTPATH)/make_rootfs/rootfsdir.sh $(OUT) $(ROOTFS_DIR) + $(HIDE)shopt -s nullglob && $(STRIP) $(ROOTFS_DIR)/bin/* $(ROOTFS_DIR)/lib/* ifneq ($(VERSION),) $(HIDE)$(LITEOS_SCRIPTPATH)/make_rootfs/releaseinfo.sh "$(VERSION)" $(ROOTFS_DIR) endif diff --git a/apps/config.mk b/apps/config.mk index dbb4ed58f7d1f610a6ed798c9990d5851d38ff58..7b6a7bba31d5a7afc5563bfdb360a6859834bd94 100644 --- a/apps/config.mk +++ b/apps/config.mk @@ -30,16 +30,24 @@ include $(LITEOSTOPDIR)/config.mk ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y) -LLVM_SYSROOT := --sysroot=$(SYSROOT_PATH) $(ARCH_CFLAGS) +LLVM_SYSROOT := --sysroot=$(SYSROOT_PATH) endif # common flags config -BASE_OPTS := -ffunction-sections -fdata-sections -fno-omit-frame-pointer -fno-common -fno-strict-aliasing -D_GNU_SOURCE \ - $(LITEOS_SSP) $(LITEOS_CORE_COPTS) $(WARNING_AS_ERROR) $(LLVM_EXTRA_OPTS) $(LLVM_SYSROOT) $(LITEOS_GCOV_OPTS) +BASE_OPTS := -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE +BASE_OPTS += -ffunction-sections -fdata-sections -fno-omit-frame-pointer -fno-common -fno-strict-aliasing +BASE_OPTS += -fstack-protector-strong -Wall -Werror -flto +BASE_OPTS += $(LITEOS_CORE_COPTS) $(LLVM_EXTRA_OPTS) $(LLVM_SYSROOT) $(LITEOS_GCOV_OPTS) -CFLAGS := -std=c99 -fPIE -fno-exceptions $(BASE_OPTS) $(LITEOS_COPTS_OPTMIZE) -CXXFLAGS := -std=c++11 -fPIE -fexceptions -fpermissive -frtti $(BASE_OPTS) $(LITEOS_COPTS_OPTMIZE) -LDFLAGS := -pie -s -Wl,-z,relro,-z,now $(BASE_OPTS) $(LLVM_EXTRA_LD_OPTS) +ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y) +OPTMIZE_OPTS = -Oz +else +OPTMIZE_OPTS = -O2 +endif + +CFLAGS := -std=c99 -fPIE -fno-exceptions $(BASE_OPTS) $(OPTMIZE_OPTS) +CXXFLAGS := -std=c++11 -fPIE -fexceptions -fpermissive -frtti $(BASE_OPTS) $(OPTMIZE_OPTS) +LDFLAGS := -pie -Wl,-z,relro,-z,now -O2 $(BASE_OPTS) $(LLVM_EXTRA_LD_OPTS) # alias variable config HIDE := @ @@ -55,8 +63,8 @@ APP_SUBDIRS := ifeq ($(LOSCFG_SHELL), y) APP_SUBDIRS += shell -#APP_SUBDIRS += mksh -#APP_SUBDIRS += toybox +APP_SUBDIRS += mksh +APP_SUBDIRS += toybox endif ifeq ($(LOSCFG_USER_INIT_DEBUG), y) diff --git a/apps/init/BUILD.gn b/apps/init/BUILD.gn index 3b8b4f5a8fb0767091a650ab0f47519cf86f4d30..a69e257efa425aa24af464d2b871bd15112ec340 100644 --- a/apps/init/BUILD.gn +++ b/apps/init/BUILD.gn @@ -32,22 +32,8 @@ import("//kernel/liteos_a/liteos.gni") executable("init") { sources = [ "src/init.c" ] - cflags = [ "-fPIE" ] - - if (defined(LOSCFG_COMPILER_CLANG_LLVM)) { - cflags += [ - "-Wno-shift-op-parentheses", - "-Wno-bitwise-op-parentheses", - "-Wnonnull", - ] - } - - ldflags = [ - "-pie", - "-s", - ] - if (defined(LOSCFG_QUICK_START)) { - ldflags += [ "--static" ] + ldflags = [ "--static" ] + defines = [ "LOSCFG_QUICK_START" ] } } diff --git a/apps/mksh/BUILD.gn b/apps/mksh/BUILD.gn index 77d2847111aea6b71ca15b27bb66138497a6a39a..30f2fb3919dc7b66b7ac6d0c7a1e350f6379c822 100644 --- a/apps/mksh/BUILD.gn +++ b/apps/mksh/BUILD.gn @@ -48,7 +48,6 @@ build_ext_component("build_mksh") { "-flto", "-fdata-sections", "-ffunction-sections", - "-Oz", "-fstack-protector-strong", "-D_FORTIFY_SOURCE=2", "-DMKSH_DISABLE_TTY_WARNING", @@ -62,6 +61,11 @@ build_ext_component("build_mksh") { "-DMKSH_NO_INITCOMS", "-DADAPT_FOR_LITEOS_A", ] + if (defined(LOSCFG_COMPILER_CLANG_LLVM)) { + cflags += [ "-Oz" ] + } else { + cflags += [ "-O2" ] + } cflags = string_join(" ", cflags) extra_flags = string_join(" ", target_arch_cflags) diff --git a/apps/mksh/Makefile b/apps/mksh/Makefile index 406d45d23c4208fcd851a300b10f974ebf1c470d..9bb177c96a26b34906f6d7fa70fef5a85e157bdb 100755 --- a/apps/mksh/Makefile +++ b/apps/mksh/Makefile @@ -29,50 +29,28 @@ include $(APPSTOPDIR)/config.mk -MKSH := mksh +BUILD_DIR := $(OUT)/mksh_build +BUILD_LOG := $(BUILD_DIR)/build.log -MKSH_DIR := $(shell pwd)/ +CFLAGS += -DMKSH_DISABLE_TTY_WARNING -DMKSH_SMALL=1 -DMKSH_ASSUME_UTF8=1 -DMKSH_SMALL_BUT_FAST=0 -DMKSH_S_NOVI=1 -DHAVE_CAN_FSTACKPROTECTORSTRONG=1 +CFLAGS += -DMKSH_LESS_CMDLINE_EDITING -DMKSH_LESS_BUILDINS -DMKSH_NO_INITCOMS -DADAPT_FOR_LITEOS_A +CFLAGS += -Wno-error +LDFLAGS += -Wl,--gc-sections -APPS_OUT := $(OUT)/bin -ETC_OUT := $(OUT)/etc -BUILD_DIR := $(MKSH_DIR)/build -BUILD_LOG := $(MKSH_DIR)/build.log -TARGET_OS := OpenHarmony - -LOCAL_CFLAGS := -flto -fdata-sections -ffunction-sections -fstack-protector-strong -D_FORTIFY_SOURCE=2 -LOCAL_CFLAGS += -DMKSH_DISABLE_TTY_WARNING -DMKSH_SMALL=1 -DMKSH_ASSUME_UTF8=1 -DMKSH_SMALL_BUT_FAST=0 -DMKSH_S_NOVI=1 -DHAVE_CAN_FSTACKPROTECTORSTRONG=1 -LOCAL_CFLAGS += -DMKSH_LESS_CMDLINE_EDITING -DMKSH_LESS_BUILDINS -DMKSH_NO_INITCOMS -DADAPT_FOR_LITEOS_A -LOCAL_LDFLAGS := -Wl,--gc-sections -flto -O2 - -ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y) -LOCAL_CFLAGS += -Oz --target=$(LLVM_TARGET) $(LLVM_SYSROOT) -else -LOCAL_CFLAGS += -O2 -endif - -all:$(MKSH) - -$(MKSH): +all: ifneq ($(wildcard $(BUILD_DIR)/Rebuild.sh),) $(HIDE)echo "not clean, rebuilding now" - $(HIDE)chmod +x $(BUILD_DIR)/Rebuild.sh - $(HIDE)cd $(BUILD_DIR) && ./Rebuild.sh > $(BUILD_LOG) 2>&1 + $(HIDE)cd $(BUILD_DIR) && sh ./Rebuild.sh > $(BUILD_LOG) 2>&1 else $(HIDE)mkdir -p $(BUILD_DIR) - $(HIDE)$(CP) $(LITEOSTHIRDPARTY)/$(MKSH)/. $(BUILD_DIR) - $(HIDE)chmod +x $(BUILD_DIR)/Build.sh - $(HIDE)cd $(BUILD_DIR) && CC=$(CC) TARGET_OS=$(TARGET_OS) CFLAGS="$(LOCAL_CFLAGS)" LDFLAGS="$(LOCAL_LDFLAGS)" ./Build.sh -r > $(BUILD_LOG) 2>&1 + $(HIDE)$(CP) $(LITEOSTHIRDPARTY)/mksh/. $(BUILD_DIR) + $(HIDE)cd $(BUILD_DIR) && CC="$(CC)" TARGET_OS=OpenHarmony CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" sh ./Build.sh -r > $(BUILD_LOG) 2>&1 endif - $(HIDE)$(CP) -rf $(BUILD_DIR)/$(MKSH) . - $(HIDE)$(STRIP) $(MKSH) - $(HIDE)mkdir -p $(APPS_OUT) - $(HIDE)$(CP) $(MKSH) $(APPS_OUT) - $(HIDE)mkdir -p $(ETC_OUT) - $(HIDE)$(CP) -rf $(BUILD_DIR)/.mkshrc $(ETC_OUT)/ - $(HIDE)$(RM) $(BUILD_DIR) $(BUILD_LOG) + $(HIDE)mkdir -p $(OUT)/bin/ $(OUT)/etc/ + $(HIDE)$(STRIP) $(BUILD_DIR)/mksh -o $(OUT)/bin/mksh + $(HIDE)$(CP) $(BUILD_DIR)/.mkshrc $(OUT)/etc/ clean: - $(HIDE)$(RM) $(MKSH) $(BUILD_DIR) $(BUILD_LOG) - + $(HIDE)$(RM) $(BUILD_DIR) -.PHONY: all $(MKSH) clean +.PHONY: all clean diff --git a/apps/shell/BUILD.gn b/apps/shell/BUILD.gn index 7afbbf6f16759be6feebae859aba72501f29a289..d7052575a88a60864c0ef36511cce48926dff17e 100644 --- a/apps/shell/BUILD.gn +++ b/apps/shell/BUILD.gn @@ -41,18 +41,4 @@ executable("shell") { deps = [ "$LITEOSTHIRDPARTY/bounds_checking_function:libsec_static" ] include_dirs = [ "include" ] - - cflags = [ "-fPIE" ] - - if (defined(LOSCFG_COMPILER_CLANG_LLVM)) { - cflags += [ - "-Wno-shift-op-parentheses", - "-Wno-bitwise-op-parentheses", - ] - } - - ldflags = [ - "-pie", - "-s", - ] } diff --git a/apps/tftp/BUILD.gn b/apps/tftp/BUILD.gn index eef0d82a9d2aaf3967448732e0f7119a5641d854..2c00ec028664befd781c330b1356c7ba83d39d1e 100644 --- a/apps/tftp/BUILD.gn +++ b/apps/tftp/BUILD.gn @@ -38,18 +38,4 @@ executable("tftp") { deps = [ "$LITEOSTHIRDPARTY/bounds_checking_function:libsec_static" ] include_dirs = [ "include" ] - - cflags = [ "-fPIE" ] - - if (defined(LOSCFG_COMPILER_CLANG_LLVM)) { - cflags += [ - "-Wno-shift-op-parentheses", - "-Wno-bitwise-op-parentheses", - ] - } - - ldflags = [ - "-pie", - "-s", - ] } diff --git a/apps/toybox/Makefile b/apps/toybox/Makefile index b73dbeabd6d1900787cdea10874a88d070cc5be2..6fd3d005d79ed2dab81b683f32f6092c34948271 100644 --- a/apps/toybox/Makefile +++ b/apps/toybox/Makefile @@ -29,40 +29,25 @@ include $(APPSTOPDIR)/config.mk -TOYBOX:= toybox +BUILD_DIR := $(OUT)/toybox_build +BUILD_LOG := $(BUILD_DIR)/build.log -TOYBOX_DIR := $(shell pwd) +CFLAGS += -Wno-error -APPS_OUT := $(OUT)/bin -BUILD_DIR := $(TOYBOX_DIR)/build -BUILD_LOG := $(TOYBOX_DIR)/build.log -OUTNAME := $(TOYBOX) - -CFLAGS := -D_FORTIFY_SOURCE=2 -fstack-protector-strong -LDFLAGS := -ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y) -CFLAGS += --target=$(LLVM_TARGET) $(LLVM_SYSROOT) -LDFLAGS += --target=$(LLVM_TARGET) $(LLVM_SYSROOT) -endif - -$(TOYBOX): +all: ifneq ($(wildcard $(BUILD_DIR)),) - $(HIDE)echo "not clean, rebuilding now"; + $(HIDE)echo "not clean, rebuilding now" else - $(HIDE)mkdir $(BUILD_DIR) - $(HIDE)$(CP) $(LITEOSTHIRDPARTY)/$(TOYBOX)/. $(BUILD_DIR) - $(HIDE)$(CP) -p $(LITEOSTHIRDPARTY)/$(TOYBOX)/porting/liteos_a/. $(BUILD_DIR) + $(HIDE)mkdir -p $(BUILD_DIR) + $(HIDE)$(CP) $(LITEOSTHIRDPARTY)/toybox/. $(BUILD_DIR) + $(HIDE)$(CP) $(LITEOSTHIRDPARTY)/toybox/porting/liteos_a/. $(BUILD_DIR) + $(HIDE)$(CP) liteos_a_custom.config $(BUILD_DIR)/../ endif - - $(HIDE)CFLAGS="$(CFLAGS)" CC="$(CC)" OUTNAME="$(OUTNAME)" \ - LDFLAGS="$(LDFLAGS)" STRIP="$(STRIP)" \ + $(HIDE)unset KCONFIG_CONFIG CROSS_COMPILE && \ + env CC="$(CC)" OUTNAME="$(OUT)/bin/toybox" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" STRIP="$(STRIP)" \ make -C $(BUILD_DIR) toybox -j> $(BUILD_LOG) 2>&1 - $(HIDE)$(CP) $(BUILD_DIR)/$(TOYBOX) . - $(HIDE)mkdir -p $(APPS_OUT) - $(HIDE)$(CP) $(TOYBOX) $(APPS_OUT) - $(HIDE)$(RM) $(BUILD_DIR) $(BUILD_LOG) clean: - $(HIDE)$(RM) $(TOYBOX) $(BUILD_DIR) $(BUILD_LOG) + $(HIDE)$(RM) $(BUILD_DIR) -.PHONY: all $(TOYBOX) clean +.PHONY: all clean diff --git a/tools/build/mk/los_config.mk b/tools/build/mk/los_config.mk index 4f5ea8bc96ad5ca7fa81f4be7c4993874ec4b537..266d058de7e34534f48328735994dff2b3ea8e11 100644 --- a/tools/build/mk/los_config.mk +++ b/tools/build/mk/los_config.mk @@ -595,12 +595,9 @@ LITEOS_LD_SCRIPT := -T$(LITEOSTOPDIR)/tools/build/liteos.ld endif ##compiler## -ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y) -_CC = $(CC) $(LLVM_EXTRA_OPTS) $(LLVM_EXTRA_LD_OPTS) $(LITEOS_CORE_COPTS) -LITEOS_BASELIB += $(shell $(_CC) "-print-file-name=libunwind.a") --no-dependent-libraries -else _CC = $(CC) $(LITEOS_CORE_COPTS) -LITEOS_BASELIB += $(shell $(_CC) "-print-file-name=libgcc_eh.a") +ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y) +_CC += $(LLVM_EXTRA_OPTS) $(LLVM_EXTRA_LD_OPTS) endif LITEOS_BASELIB += $(shell $(_CC) "-print-libgcc-file-name") LITEOS_LIB_INCLUDE += -isystem $(shell $(_CC) "-print-file-name=include")