feat(make): optimize makefiles and remove some unused files

Signed-off-by: Caoruihong <crh.cao@huawei.com>
Change-Id: Ie2dfa7334417ccd55bd56a19a7882a982ce49cab
This commit is contained in:
Caoruihong
2021-08-03 00:35:23 +08:00
parent 752aa49018
commit 0e260949c9
34 changed files with 345 additions and 672 deletions

View File

@@ -28,51 +28,26 @@
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
LITEOSTOPDIR := $(realpath $(dir $(firstword $(MAKEFILE_LIST))))
LITEOSTHIRDPARTY := $(LITEOSTOPDIR)/../../third_party
export LITEOSTOPDIR
export LITEOSTHIRDPARTY
APPS = apps
ROOTFS = rootfs
LITEOS_TARGET = liteos
LITEOS_LIBS_TARGET = libs
KCONFIG_CMDS := $(notdir $(wildcard $(dir $(shell which menuconfig))*config))
# by the following eval, we would got some variables like these:
# ohos_root_path=/xx
# ohos_board=hispark_taurus
# ohos_kernel=liteos_a
# ohos_product=ipcamera_hispark_taurus
# ohos_product_path=/xx/vendor/hisilicon/hispark_taurus
# ohos_device_path=/xx/device/hisilicon/hispark_taurus/sdk_liteos
ohos_kernel ?= liteos_a
$(foreach line,$(shell hb env | sed 's/\[OHOS INFO\]/ohos/g;s/ /_/g;s/:_/=/g' || true),$(eval $(line)))
ifneq ($(ohos_kernel),liteos_a)
$(error The selected product ($(ohos_product)) is not a liteos_a kernel type product)
endif
export CONFIG_=LOSCFG_
export srctree=$(LITEOSTOPDIR)
SYSROOT_PATH ?= $(LITEOSTOPDIR)/../../prebuilts/lite/sysroot
export SYSROOT_PATH
LITEOS_MENUCONFIG_H ?= $(LITEOSTOPDIR)/config.h
export LITEOS_MENUCONFIG_H
CONFIG_FILE ?= $(LITEOSTOPDIR)/.config
export CONFIG_FILE
ifeq ($(PRODUCT_PATH),)
PRODUCT_PATH:=$(ohos_product_path)
endif
export PRODUCT_PATH
ifeq ($(DEVICE_PATH),)
DEVICE_PATH:=$(ohos_device_path)
endif
export DEVICE_PATH
ifeq ($(TEE:1=y),y)
tee = _tee
@@ -84,9 +59,25 @@ CONFIG ?= $(PRODUCT_PATH)/kernel_configs/debug$(tee).config
endif
KCONFIG_CONFIG ?= $(CONFIG)
export KCONFIG_CONFIG
SYSROOT_PATH ?= $(LITEOSTOPDIR)/../../prebuilts/lite/sysroot
LITEOS_MENUCONFIG_H ?= $(LITEOSTOPDIR)/config.h
LITEOS_CONFIG_FILE ?= $(LITEOSTOPDIR)/.config
-include $(LITEOSTOPDIR)/tools/build/config.mk
# export los_config.mk related environment variables
export LITEOSTOPDIR
export LITEOS_MENUCONFIG_H
export LITEOS_CONFIG_FILE
# export subdir Makefile related environment variables
export SYSROOT_PATH
export PRODUCT_PATH
export DEVICE_PATH
# export kconfig related environment variables
export CONFIG_=LOSCFG_
export srctree=$(LITEOSTOPDIR)
include $(LITEOSTOPDIR)/config.mk
ifeq ($(LOSCFG_STORAGE_SPINOR), y)
FSTYPE = jffs2
@@ -112,16 +103,19 @@ Targets:
clean: clean compiled objects
cleanall: clean all build outputs
all: make liteos kernel image and rootfs image (Default target)
rootfs: make a original rootfs image
$(APPS): build all apps
$(ROOTFS): make a original rootfs image
$(LITEOS_LIBS_TARGET): compile all kernel modules (libraries)
$(LITEOS_TARGET): make liteos kernel image
update_config: update product kernel config (use menuconfig)
xxconfig: invoke xxconfig command of kconfiglib (xxconfig is one of $(KCONFIG_CMDS))
Parameters:
FSTYPE: value should be one of (jffs2 vfat yaffs2)
TEE: boolean value(1 or y for true), enable tee
RELEASE: boolean value(1 or y for true), build release version
CONFIG: kernel config file to be use
args: arguments for xxconfig command
-------------------------------------------------------
endef
export HELP
@@ -139,27 +133,22 @@ endif
$(HIDE)echo "sysroot:" $(abspath $(SYSROOT_PATH))
endif
KCONFIG_CMDS := $(notdir $(wildcard $(dir $(shell which menuconfig))*config))
$(KCONFIG_CMDS):
$(HIDE)$@ $(args)
$(LITEOS_MENUCONFIG_H) $(CONFIG_FILE): $(KCONFIG_CONFIG)
$(HIDE)genconfig --config-out $(CONFIG_FILE) --header-path $(LITEOS_MENUCONFIG_H) $(args)
$(LITEOS_CONFIG_FILE): $(KCONFIG_CONFIG)
$(HIDE)env KCONFIG_CONFIG=$< genconfig --config-out $@ --header-path $(LITEOS_MENUCONFIG_H)
update_config:
$(HIDE)test -f "$(CONFIG)" && cp -v "$(CONFIG)" .config && menuconfig && savedefconfig --out "$(CONFIG)"
prepare: $(LITEOS_MENUCONFIG_H)
$(HIDE)mkdir -p $(OUT)/musl $(OUT)/lib $(BUILD)
$(LITEOS_LIBS_TARGET): prepare
$(HIDE)touch $(LOSCFG_ENTRY_SRC)
$(HIDE)for dir in $(LITEOS_SUBDIRS); do $(MAKE) -C $$dir all || exit 1; done
$(LITEOS_LIBS_TARGET):
$(HIDE)for dir in $(LIB_SUBDIRS); do $(MAKE) -C $$dir all || exit 1; done
$(LITEOS_TARGET): $(OUT)/$(LITEOS_TARGET)
$(LITEOS_TARGET): $(OUT)/$(LITEOS_TARGET).map
#$(LITEOS_TARGET): $(OUT)/$(LITEOS_TARGET).objsize
$(LITEOS_TARGET): $(LITEOS_TARGET_DIR)/$(LITEOS_TARGET).bin
$(LITEOS_TARGET): $(OUT)/$(LITEOS_TARGET).bin
$(LITEOS_TARGET): $(OUT)/$(LITEOS_TARGET).sym.sorted
$(LITEOS_TARGET): $(OUT)/$(LITEOS_TARGET).asm
#$(LITEOS_TARGET): $(OUT)/$(LITEOS_TARGET).size
@@ -169,7 +158,7 @@ $(OUT)/$(LITEOS_TARGET): $(LITEOS_LIBS_TARGET)
$(OUT)/$(LITEOS_TARGET).map: $(OUT)/$(LITEOS_TARGET)
$(OUT)/$(LITEOS_TARGET).objsize: $(LITEOS_LIBS_TARGET)
$(SIZE) -t --common $(OUT)/lib/*.a >$@
$(LITEOS_TARGET_DIR)/$(LITEOS_TARGET).bin: $(OUT)/$(LITEOS_TARGET)
$(OUT)/$(LITEOS_TARGET).bin: $(OUT)/$(LITEOS_TARGET)
$(OBJCOPY) -O binary $< $@
$(OUT)/$(LITEOS_TARGET).sym.sorted: $(OUT)/$(LITEOS_TARGET)
$(OBJDUMP) -t $< |sort >$@
@@ -178,10 +167,11 @@ $(OUT)/$(LITEOS_TARGET).asm: $(OUT)/$(LITEOS_TARGET)
$(OUT)/$(LITEOS_TARGET).size: $(OUT)/$(LITEOS_TARGET)
$(NM) -S --size-sort $< >$@
$(APPS): prepare
$(APPS):
$(HIDE)$(MAKE) -C apps all
$(ROOTFS): $(APPS)
$(HIDE)mkdir -p $(OUT)/musl
ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
$(HIDE)cp -fp $$($(CC) --target=$(LLVM_TARGET) --sysroot=$(SYSROOT_PATH) $(LITEOS_CFLAGS) -print-file-name=libc.so) $(OUT)/musl
$(HIDE)cp -fp $$($(GPP) --target=$(LLVM_TARGET) --sysroot=$(SYSROOT_PATH) $(LITEOS_CXXFLAGS) -print-file-name=libc++.so) $(OUT)/musl
@@ -190,23 +180,22 @@ 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
$(STRIP) $(OUT)/musl/*
$(HIDE)$(LITEOSTOPDIR)/tools/scripts/make_rootfs/rootfsdir.sh $(OUT) $(ROOTFS_DIR) $(LITEOS_TARGET_DIR)
$(HIDE)$(STRIP) $(OUT)/musl/*
$(HIDE)$(LITEOS_SCRIPTPATH)/make_rootfs/rootfsdir.sh $(OUT) $(ROOTFS_DIR)
ifneq ($(VERSION),)
$(HIDE)$(LITEOSTOPDIR)/tools/scripts/make_rootfs/releaseinfo.sh "$(VERSION)" $(ROOTFS_DIR) $(LITEOS_TARGET_DIR)
$(HIDE)$(LITEOS_SCRIPTPATH)/make_rootfs/releaseinfo.sh "$(VERSION)" $(ROOTFS_DIR)
endif
$(HIDE)$(LITEOSTOPDIR)/tools/scripts/make_rootfs/rootfsimg.sh $(ROOTFS_DIR) $(FSTYPE)
$(HIDE)$(LITEOS_SCRIPTPATH)/make_rootfs/rootfsimg.sh $(ROOTFS_DIR) $(FSTYPE)
$(HIDE)cd $(ROOTFS_DIR)/.. && zip -r $(ROOTFS_ZIP) $(ROOTFS)
clean:
$(HIDE)for dir in $(LITEOS_SUBDIRS); do $(MAKE) -C $$dir clean || exit 1; done
$(HIDE)$(MAKE) -C apps clean
$(HIDE)$(RM) $(LITEOS_MENUCONFIG_H) $(CONFIG_FILE)
$(HIDE)for dir in $(LIB_SUBDIRS) apps; do $(MAKE) -C $$dir clean || exit 1; done
$(HIDE)$(RM) $(LITEOS_MENUCONFIG_H)
$(HIDE)echo "clean $(LOSCFG_PLATFORM) finish"
cleanall: clean
$(HIDE)$(RM) $(LITEOSTOPDIR)/out
$(HIDE)$(RM) $(LITEOSTOPDIR)/out $(LITEOS_CONFIG_FILE)
$(HIDE)echo "clean all done"
.PHONY: all clean cleanall prepare sysroot help update_config
.PHONY: $(LITEOS_TARGET) $(ROOTFS) $(APPS) $(KCONFIG_CMDS) $(LITEOS_LIBS_TARGET)
.PHONY: all clean cleanall sysroot help update_config
.PHONY: $(LITEOS_TARGET) $(ROOTFS) $(APPS) $(KCONFIG_CMDS) $(LITEOS_LIBS_TARGET) $(KCONFIG_CONFIG)