chore: pass sysroot and arch related cflags by BUILD.gn

sysroot and arch related cflags are pass by BUILD.gn now.

Signed-off-by: Caoruihong <crh.cao@huawei.com>
Change-Id: Ia6000dd7ed8a8a37e935ace49d8460a919a16566
This commit is contained in:
Caoruihong 2021-06-24 02:24:58 +08:00
parent 43bdf2f1d3
commit 9e45086d19
8 changed files with 86 additions and 51 deletions

View File

@ -77,7 +77,8 @@ build_ext_component("make") {
if (board_name == "hi3516dv300" && enable_tee_ree) {
tee_enable = "tee"
}
prebuilts = "sh build.sh ${board_name} ${ohos_build_compiler} ${root_build_dir} ${ohos_build_type} ${tee_enable} \"${device_company}\" \"${product_path}\""
outdir = rebase_path(get_path_info(".", "out_dir"))
command = "make clean OUTDIR=$outdir PRODUCT_PATH=\"${product_path}\" && make rootfs VERSION=\"${ohos_version}\" PRODUCT_PATH=\"${product_path}\" -j 16 OUTDIR=$outdir"
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} \"${device_company}\" \"${product_path}\" $outdir \"${ohos_version}\" ${sysroot_path} \"${arch_cflags}\""
}

View File

@ -82,6 +82,9 @@ ROOTFS_DIR = $(OUT)/rootfs
ROOTFS_ZIP = $(OUT)/rootfs.zip
VERSION =
SYSROOT_PATH ?= $(LITEOSTOPDIR)/../../prebuilts/lite/sysroot
export SYSROOT_PATH
all: $(OUT) $(BUILD) $(LITEOS_TARGET) $(APPS)
lib: $(OUT) $(BUILD) $(LITEOS_LIBS_TARGET)
@ -165,11 +168,15 @@ $(LITEOS_TARGET): $(__LIBS)
$(APPS): $(LITEOS_TARGET)
$(HIDE)$(MAKE) -C apps all
ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
MULTILIB := $(patsubst $(shell $(CC) --target=$(LLVM_TARGET) $(ARCH_CFLAGS) -print-file-name=lib/$(LLVM_TARGET)/)%,%,$(dir $(shell $(CC) --target=$(LLVM_TARGET) $(ARCH_CFLAGS) -print-libgcc-file-name)))
endif
prepare:
$(HIDE)mkdir -p $(OUT)/musl
ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
$(HIDE)cp -f $(LITEOSTOPDIR)/../../prebuilts/lite/sysroot/usr/lib/$(LLVM_TARGET)/a7_softfp_neon-vfpv4/libc.so $(OUT)/musl
$(HIDE)cp -f $(LITEOS_COMPILER_PATH)/lib/$(LLVM_TARGET)/c++/a7_softfp_neon-vfpv4/libc++.so $(OUT)/musl
$(HIDE)cp -f $(SYSROOT_PATH)/usr/lib/$(LLVM_TARGET)/$(MULTILIB)/libc.so $(OUT)/musl
$(HIDE)cp -f $(LITEOS_COMPILER_PATH)/lib/$(LLVM_TARGET)/c++/$(MULTILIB)/libc++.so $(OUT)/musl
else
$(HIDE)cp -f $(LITEOS_COMPILER_PATH)/target/usr/lib/libc.so $(OUT)/musl
$(HIDE)cp -f $(LITEOS_COMPILER_PATH)/arm-linux-musleabi/lib/libstdc++.so.6 $(OUT)/musl

View File

@ -44,7 +44,7 @@ CFLAGS := -std=c99 -fno-exceptions $(BASE_OPTS) $(LITEOS_COPTS_OPTMIZE)
CXXFLAGS := -std=c++11 -fexceptions -fpermissive -frtti $(BASE_OPTS) $(LITEOS_COPTS_OPTMIZE)
LDCFLAGS := -lc
ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
LLVM_SYSROOT := --sysroot=$(LITEOSTOPDIR)/../../prebuilts/lite/sysroot/
LLVM_SYSROOT := --sysroot=$(SYSROOT_PATH) $(ARCH_CFLAGS)
LDCXXFLGS := -lc++ -lc++abi -lc
else
BASE_OPTS += -Wl,-z,relro,-z,now

View File

@ -38,11 +38,11 @@ BUILD_DIR := $(MKSH_DIR)/build
BUILD_LOG := $(MKSH_DIR)/build.log
TARGET_OS := OpenHarmony
LOCAL_CFLAGS := -flto -fdata-sections -ffunction-sections -Oz -fstack-protector-strong -D_FORTIFY_SOURCE=2 -mcpu=cortex-a7 -mfloat-abi=softfp -mfpu=neon-vfpv4
LOCAL_CFLAGS += --target=arm-liteos --sysroot=$(LITEOSTOPDIR)/../../prebuilts/lite/sysroot/
LOCAL_CFLAGS := -flto -fdata-sections -ffunction-sections -Oz -fstack-protector-strong -D_FORTIFY_SOURCE=2
LOCAL_CFLAGS += --target=arm-liteos $(LLVM_SYSROOT)
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
LOCAL_LDFLAGS := -Wl,--gc-sections -flto -O2 --target=arm-liteos $(LLVM_SYSROOT)
all:$(MKSH)

View File

@ -46,8 +46,8 @@ else
$(HIDE)$(CP) $(LITEOSTHIRDPARTY)/$(TOYBOX)/. $(BUILD_DIR)
$(HIDE)$(CP) -p $(LITEOSTHIRDPARTY)/$(TOYBOX)/porting/liteos_a/. $(BUILD_DIR)
endif
$(HIDE)CFLAGS="-D_FORTIFY_SOURCE=2 -fstack-protector-strong --target=arm-liteos \
--sysroot=$(LITEOSTOPDIR)/../../prebuilts/lite/sysroot/" CC="$(CC)" OUTNAME=$(OUTNAME) \
$(HIDE)CFLAGS="-D_FORTIFY_SOURCE=2 -fstack-protector-strong --target=arm-liteos $(LLVM_SYSROOT)" CC="$(CC)" OUTNAME=$(OUTNAME) \
LDFLAGS="--target=arm-liteos $(LLVM_SYSROOT)" \
make -C $(BUILD_DIR) toybox -j> $(BUILD_LOG) 2>&1
$(HIDE)$(CP) $(BUILD_DIR)/$(TOYBOX) .
$(HIDE)$(STRIP) $(TOYBOX)

View File

@ -65,7 +65,7 @@ LITEOS_FPU_OPTS := -mfpu=$(LOSCFG_ARCH_FPU)
LITEOS_GCCLIB := $(subst cortex-,,$(LOSCFG_ARCH_CPU))_softfp_$(LOSCFG_ARCH_FPU)
endif
LITEOS_CORE_COPTS = $(LITEOS_CPU_OPTS) $(LITEOS_FLOAT_OPTS) $(LITEOS_FPU_OPTS)
LITEOS_CORE_COPTS = $(or $(ARCH_CFLAGS),$(LITEOS_CPU_OPTS) $(LITEOS_FLOAT_OPTS) $(LITEOS_FPU_OPTS))
LITEOS_INTERWORK += $(LITEOS_CORE_COPTS)
LITEOS_NODEBUG += $(LITEOS_CORE_COPTS)
LITEOS_ASOPTS += $(LITEOS_CPU_OPTS)

105
build.sh
View File

@ -30,44 +30,71 @@
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
set -e
echo "sh param:$1,$2,$3,$4,$5,$6,$7"
destination=".config"
config_file=""
tee=""
outdir="../..$3/test_info/gen/kernel/test"
if [ "$5" = "tee" ]; then
tee="_tee"
fi
product_name="$(basename $7)"
source="tools/build/config/${product_name}_release.config"
if [ "$2" = "clang" ]; then
if [ "$4" = "debug" ]; then
config_file="${product_name}_$2$tee.config"
source="tools/build/config/debug/$config_file"
else
config_file="${product_name}_$2_release$tee.config"
source="tools/build/config/$config_file"
fi
elif [ "$2" = "gcc" ]; then
if [ "$4" = "debug" ]; then
config_file="${product_name}_debug_shell$tee.config"
source="tools/build/config/$config_file"
else
config_file="${product_name}_release$tee.config"
source="tools/build/config/$config_file"
fi
fi
if [ -d "./out" ]; then
rm -rf ./out
fi
if [ -f "$destination" ]; then
rm -rf $destination
fi
if [ ! -f "$source" ]; then
source="$7/config/sys/$config_file"
fi
cp $source $destination
board_name=${1}
ohos_build_compiler=${2}
root_build_dir=${3}
ohos_build_type=${4}
tee_enable=${5}
device_company=${6}
product_path=${7}
outdir=${8}
ohos_version=${9}
sysroot_path=${10}
arch_cflags=${11}
mkdir -p $outdir
cp kernel_test.sources $outdir
echo "${board_name}" "${device_company}"
echo "sh param:" "$@"
function main() {
destination=".config"
config_file=""
tee=""
if [ "${tee_enable}" = "tee" ]; then
tee="_tee"
fi
product_name=$(basename "${product_path}")
source="tools/build/config/${product_name}_release.config"
if [ "${ohos_build_compiler}" = "clang" ]; then
if [ "${ohos_build_type}" = "debug" ]; then
config_file="${product_name}_${ohos_build_compiler}${tee}.config"
source="tools/build/config/debug/${config_file}"
else
config_file="${product_name}_${ohos_build_compiler}_release${tee}.config"
source="tools/build/config/${config_file}"
fi
elif [ "${ohos_build_compiler}" = "gcc" ]; then
if [ "${ohos_build_type}" = "debug" ]; then
config_file="${product_name}_debug_shell${tee}.config"
source="tools/build/config/${config_file}"
else
config_file="${product_name}_release${tee}.config"
source="tools/build/config/${config_file}"
fi
fi
if [ -d "./out" ]; then
rm -rf ./out
fi
if [ -f "${destination}" ]; then
rm -rf ${destination}
fi
if [ ! -f "${source}" ]; then
source="${product_path}/config/sys/${config_file}"
fi
cp "${source}" ${destination}
test_info_outdir="../..${root_build_dir}/test_info/gen/kernel/test"
mkdir -p "${test_info_outdir}"
cp kernel_test.sources "${test_info_outdir}"
}
if [ "x" != "x${sysroot_path}" ]; then
export SYSROOT_PATH=${sysroot_path}
fi
if [ "x" != "x${arch_cflags}" ]; then
export ARCH_CFLAGS="${arch_cflags}"
fi
main && \
make clean OUTDIR="${outdir}" PRODUCT_PATH="${product_path}" && \
make -j rootfs VERSION="${ohos_version}" OUTDIR="${outdir}" PRODUCT_PATH="${product_path}"

View File

@ -40,7 +40,7 @@ VDSO_INCLUDE := -I $(LITEOSTOPDIR)/kernel/extended/vdso/include \
VDSO_CCFLAGS := -nostdlib -fPIC -fno-common -fno-strict-aliasing \
$(LITEOS_SSP) $(LITEOS_CORE_COPTS) $(WARNING_AS_ERROR) $(LITEOS_COPTS_OPTMIZE)
ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
VDSO_CCFLAGS += $(LLVM_EXTRA_OPTS) --sysroot=$(LITEOSTOPDIR)/../../prebuilts/lite/sysroot/
VDSO_CCFLAGS += $(LLVM_EXTRA_OPTS) --sysroot=$(SYSROOT_PATH) $(ARCH_CFLAGS)
endif
VDSO_LDFLAGS := -shared -s -Bsymbolic -T los_vdso.ld