u-boot主makefile分析2
程序员文章站
2022-06-04 08:51:16
...
1.包含主目录的config.mk
# load other configuration
include $(TOPDIR)/config.mk
在config.mk中主要做了哪些工作呢?
1.编译工具定义
#
# Include the make variables (CC, etc...)
#
AS = $(CROSS_COMPILE)as
LD = $(CROSS_COMPILE)ld
CC = $(CROSS_COMPILE)gcc
CPP = $(CC) -E
AR = $(CROSS_COMPILE)ar
NM = $(CROSS_COMPILE)nm
STRIP = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
RANLIB = $(CROSS_COMPILE)RANLIB
2.包含开发板配置项目
ifdef ARCH
sinclude $(TOPDIR)/$(ARCH)_config.mk # include architecture dependend rules
endif
ifdef CPU
sinclude $(TOPDIR)/cpu/$(CPU)/config.mk # include CPU specific rules
endif
ifdef SOC
sinclude $(TOPDIR)/cpu/$(CPU)/$(SOC)/config.mk # include SoC specific rules
endif
ifdef VENDOR
BOARDDIR = $(VENDOR)/$(BOARD)
else
BOARDDIR = $(BOARD)
endif
ifdef BOARD
sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk # include board specific rules
endif
在/board/100ask24x0目录下的config.mk仅仅有一行代码:
TEXT_BASE = 0x33F80000
3.设置头文件搜寻路径
ifneq ($(OBJTREE),$(SRCTREE))
CPPFLAGS += -I$(OBJTREE)/include2 -I$(OBJTREE)/include
endif
CPPFLAGS += -I$(TOPDIR)/include
CPPFLAGS += -fno-builtin -ffreestanding -nostdinc \
-isystem $(gccincdir) -pipe $(PLATFORM_CPPFLAGS)
段设置了头文件的搜寻路径,添加了顶层目录下的include文件夹作为搜索路径。然后进行了一些其他设置(比如禁止标准的include路径)
这样,编译器在编译的时候就能正确的读取到include文件夹下的头文件(其实是配置阶段创建的符号链接)了
4.包含链接脚本
ifndef LDSCRIPT
#LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds.debug
ifeq ($(CONFIG_NAND_U_BOOT),y)
LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot-nand.lds
else
LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds
endif
endif
简单分析一下,就可以得知,我们包含的链接脚本是(TOPDIR)/board/$(BOARDDIR)/u-boot.lds。
5.设定LDFLAGS
LDFLAGS += -Bstatic -T $(LDSCRIPT) -Ttext $(TEXT_BASE) $(PLATFORM_LDFLAGS)
其中TEXT_BASE 在/board/100ask24x0目录下的config.mk中定义:
TEXT_BASE = 0x33F80000
LDSCRIPT就是(TOPDIR)/board/$(BOARDDIR)/u-boot.lds。
最终生成的LDFLAGS会在生成bin文件的时候用到。
6.导出若干换环境变量
export CONFIG_SHELL HPATH HOSTCC HOSTCFLAGS CROSS_COMPILE \
AS LD CC CPP AR NM STRIP OBJCOPY OBJDUMP \
MAKE
export TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS AFLAGS
7.设定自动推导规则
ifndef REMOTE_BUILD
%.s: %.S
$(CPP) $(AFLAGS) -o [email protected] $<
%.o: %.S
$(CC) $(AFLAGS) -c -o [email protected] $<
%.o: %.c
$(CC) $(CFLAGS) -c -o [email protected] $<
else
$(obj)%.s: %.S
$(CPP) $(AFLAGS) -o [email protected] $<
$(obj)%.o: %.S
$(CC) $(AFLAGS) -c -o [email protected] $<
$(obj)%.o: %.c
$(CC) $(CFLAGS) -c -o [email protected] $<
endif
makefile的自动推导规则,和顶层Makefile内的规则配合使用,就能实现众多文件的编译
上一篇: Android 打开指定程序