顶层Makefile分析
Posted 四季帆
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了顶层Makefile分析相关的知识,希望对你有一定的参考价值。
1. 顶层目录下的Makefile
OpenHarmony/kernel/liteos_a/Makefile
-include $(LITEOSTOPDIR)/tools/build/config.mk #包含 kernel/liteos_a/tools/build/config.mk
LITEOS_TARGET = liteos
LITEOS_PLATFORM_BASE = $(LITEOSTOPDIR)/platform
all: $(OUT) $(BUILD) $(LITEOS_TARGET) $(APPS) #顶层目录下Makefile中的第一个目标
#文件很长,所以删掉了很多内容,只留下了要分析内容的主干
$(OUT): $(LITEOS_MENUCONFIG_H)
$(HIDE)mkdir -p $(OUT)/lib #创建目录$(OUT)/lib
$(HIDE)$(CC) -I$(LITEOS_PLATFORM_BASE)/include -I$(LITEOSTOPDIR)/../../vendor/hisi/hi35xx/$(LITEOS_PLATFORM)/config/board \\
-E $(LITEOS_PLATFORM_BASE)/board.ld.S \\
-o $(LITEOS_PLATFORM_BASE)/board.ld -P #将kernel/liteos_a/platform/board.ld.S编译成board.ld
$(BUILD):
$(HIDE)mkdir -p $(BUILD) #创建目录$(BUILD)
$(LITEOS_TARGET): $(__LIBS)
$(HIDE)touch $(LOSCFG_ENTRY_SRC)
$(HIDE)for dir in $(LITEOS_SUBDIRS); \\ #遍历目录LITEOS_SUBDIRS
do $(MAKE) -C $$dir all || exit 1; \\ #进入目录并编译目录中Makefile的第一个目标all
done
#连接各种库和目标文件
$(LD) $(LITEOS_LDFLAGS) $(LITEOS_TABLES_LDFLAGS) $(LITEOS_DYNLDFLAGS) -Map=$(OUT)/$@.map -o $(OUT)/$@ --start-group $(LITEOS_LIBDEP) --end-group
# $(SIZE) -t --common $(OUT)/lib/*.a >$(OUT)/$@.objsize
$(OBJCOPY) -O binary $(OUT)/$@ $(LITEOS_TARGET_DIR)/$@.bin #生成bin文件
$(OBJDUMP) -t $(OUT)/$@ |sort >$(OUT)/$@.sym.sorted
$(OBJDUMP) -d $(OUT)/$@ >$(OUT)/$@.asm #反汇编生成汇编文件
# $(NM) -S --size-sort $(OUT)/$@ >$(OUT)/$@.size
$(ROOTFS): $(ROOTFSDIR)
$(HIDE)$(shell $(LITEOSTOPDIR)/tools/scripts/make_rootfs/rootfsimg.sh $(ROOTFS_DIR) $(FSTYPE) ${ROOTFS_SIZE})
$(HIDE)cd $(ROOTFS_DIR)/.. && zip -r $(ROOTFS_ZIP) $(ROOTFS)
ifneq ($(OUT), $(LITEOS_TARGET_DIR))
$(HIDE)mv $(ROOTFS_DIR) $(LITEOS_TARGET_DIR)rootfs
endif
1.1 kernel/liteos_a/tools/build/config.mk
-include $(LITEOSTOPDIR)/tools/build/mk/los_config.mk #即kernel/liteos_a/tools/build/mk/los_config.mk
TOP_LD_PATH = $(LITEOSTOPDIR)
SCRIPTS_PATH = $(LITEOS_SCRIPTPATH)
LITEOS_MK_PATH = $(MK_PATH)
LITEOS_SUBDIRS = $(LIB_SUBDIRS)
LIB_BIGODIR = $(LITEOS_LIB_BIGODIR)
##### liteos tables -u ldflags #####
-include $(LITEOS_MK_PATH)/liteos_tables_ldflags.mk
LITEOS_COPTS := $(LITEOS_COPTS_DEBUG) $(LITEOS_COPTS_BASE) \\
$(LITEOS_COPTS_EXTRA) $(LITEOS_CORE_COPTS)
LITEOS_CXXOPTS := $(LITEOS_CXXOPTS_BASE)
LITEOS_INCLUDE := $(LITEOS_KERNEL_INCLUDE) $(LITEOS_EXTKERNEL_INCLUDE) \\
$(LITEOS_COMPAT_INCLUDE) $(LITEOS_FS_INCLUDE) \\
$(LITEOS_NET_INCLUDE) $(LITEOS_LIB_INCLUDE) \\
$(LITEOS_DRIVERS_INCLUDE) $(LOSCFG_TOOLS_DEBUG_INCLUDE) \\
$(LITEOS_PLATFORM_INCLUDE)
LITEOS_LIBDEP := $(LITEOS_BASELIB)
LITEOS_ASFLAGS := $(LITEOS_ASOPTS) $(LITEOS_INCLUDE)
LITEOS_CFLAGS := $(LITEOS_COPTS) $(LITEOS_CMACRO) \\
$(LITEOS_CMACRO_TEST) $(LITEOS_IMAGE_MACRO) \\
$(LITEOS_INCLUDE)
LITEOS_CXXFLAGS := $(LITEOS_CXXOPTS) $(LITEOS_CXXMACRO) \\
$(LITEOS_CMACRO) $(LITEOS_CXXINCLUDE)
LITEOS_LDFLAGS := $(LITEOS_LD_OPTS) $(LITEOS_LD_PATH) \\
$(LITEOS_LD_SCRIPT)
1.2 kernel/liteos_a/tools/build/mk/los_config.mk
-include $(LITEOSTOPDIR)/.config
ifeq ($(LOSCFG_3RDPARTY), y)
-include $(LITEOSTOPDIR)/3rdParty/3rdParty.mk
endif
include $(LITEOSTOPDIR)/arch/cpu.mk
include $(LITEOSTOPDIR)/platform/bsp.mk
ifeq ($(LOSCFG_DRIVERS_HDF), y)
include $(LITEOSTOPDIR)/../../drivers/hdf/lite/hdf_lite.mk
endif
2. 总结
顶层目录下的主Makefile是LITEOS_SUBDIRS变量来控制是否编译相关子模块的,比如文件系统fat是否编译进kernel,在los_config.mk的296行向LITEOS_SUBDIRS追加了fs/fat,说明只要满足控制宏就回将fat编译进kernel。
config.mk:36:LITEOS_SUBDIRS = $(LIB_SUBDIRS)
tools/build/mk/los_config.mk:97:LIB_SUBDIRS :=
tools/build/mk/los_config.mk:157: LIB_SUBDIRS += $(LITEOSTOPDIR)/kernel/common
tools/build/mk/los_config.mk:163:LIB_SUBDIRS += kernel/base
tools/build/mk/los_config.mk:167:LIB_SUBDIRS += $(LITEOSTOPDIR)/../../vendor/hisi/hi35xx/$(LITEOS_PLATFORM)/config/board/
tools/build/mk/los_config.mk:214: LIB_SUBDIRS += kernel/extended/pipe
tools/build/mk/los_config.mk:221: LIB_SUBDIRS += lib/libc
tools/build/mk/los_config.mk:222: LIB_SUBDIRS += lib/libsec
tools/build/mk/los_config.mk:235: LIB_SUBDIRS += lib/libscrew
tools/build/mk/los_config.mk:246: LIB_SUBDIRS += kernel/extended/cppsupport
tools/build/mk/los_config.mk:252: LIB_SUBDIRS += lib/zlib
tools/build/mk/los_config.mk:260: LIB_SUBDIRS += compat/posix
tools/build/mk/los_config.mk:267: LIB_SUBDIRS += bsd
······
tools/build/mk/los_config.mk:296: LIB_SUBDIRS += fs/fat
······
tools/build/mk/los_config.mk:474: LIB_SUBDIRS += shell
tools/build/mk/los_config.mk:481: LIB_SUBDIRS += net/telnet
tools/build/mk/los_config.mk:495:LIB_SUBDIRS += syscall
tools/build/mk/los_config.mk:496:LIB_SUBDIRS += kernel/user
tools/build/mk/los_config.mk:515:LIB_SUBDIRS += security
以上是关于顶层Makefile分析的主要内容,如果未能解决你的问题,请参考以下文章
Linux系统移植:Kernel 顶层 Makefile(下)