uboot的Makefile分析之顶层config.mk
2015-04-27 14:30
591 查看
顶层目录下的config.mk文件主要完成如下功能的配置:
1、确定生成可执行文件过程中需要的各种工具,如编译器(arm-linux-gcc)、连接器(arm-linux-ld)、反汇编器(arm-linux-objdump)等
2、确定CPU、板相关的配置文件,存在于各个目录下的config.mk
3、确定编译、链接、转换等过程的操作选项
4、根据步骤3确定的编译连接选项生成需要的文件
config.mk完整内容及必要注释如下
注:config.mk文件注释符改为/* 注释内容 */
view
sourceprint?
1、确定生成可执行文件过程中需要的各种工具,如编译器(arm-linux-gcc)、连接器(arm-linux-ld)、反汇编器(arm-linux-objdump)等
2、确定CPU、板相关的配置文件,存在于各个目录下的config.mk
3、确定编译、链接、转换等过程的操作选项
4、根据步骤3确定的编译连接选项生成需要的文件
config.mk完整内容及必要注释如下
注:config.mk文件注释符改为/* 注释内容 */
view
sourceprint?
001.
ifneq ($(OBJTREE),$(SRCTREE))
002.
ifeq ($(CURDIR),$(SRCTREE))
003.
dir :=
004.
else
005.
dir := $(subst $(SRCTREE)/,,$(CURDIR))
006.
endif
007.
008.
obj := $(
if
$(dir),$(OBJTREE)/$(dir)/,$(OBJTREE)/)
009.
src := $(
if
$(dir),$(SRCTREE)/$(dir)/,$(SRCTREE)/)
010.
011.
$(shell mkdir -p $(obj))
012.
else
013.
obj :=
014.
src :=
015.
endif
016.
/* obj = 空,src = 空
017.
* dir = 空
018.
*/
019.
020.
/* clean the slate ... */
021.
PLATFORM_RELFLAGS =
022.
PLATFORM_CPPFLAGS =
023.
PLATFORM_LDFLAGS =
024.
025.
/* HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
026.
* -Wall: 打印出编译时所有的错误或警告信息
027.
* -Wstrict-prototypes: 编译时,若产生与数据类型不相符的问题,打印出提示或警告信息。当在不同体系结构间移植时,加上该选项可避免很多错误
028.
* -O: 编译代码时的优化等级,共有五种:-O0、-O1、-O2、-O3和-Os
029.
* -fomit-frame-pointer: 对于不需要帧指针的函数,不要在寄存器中保存帧指针
030.
* 代码优化时打开-fomit-frame-pointer,函数调用时不保存frame指针,也就不能用backtrace()来查看函数栈调用
031.
* backtrace()系列函数见[http://blog.csdn.net/u013686019/article/details/42128771](Linux中backtrace()系列函数的应用实例)
032.
*/
033.
HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer \
034.
$(HOSTCPPFLAGS)
035.
/* HOSTSTRIP = strip
036.
* strip能清除执行文件中不必要的标示符及调试信息,可减小文件大小而不影响正常使用,、
037.
* 与压缩不同的是,文件一旦strip后就不能恢复原样
038.
* strip后的文件不包含调试信息
039.
*/
040.
HOSTSTRIP = strip
041.
042.
/*
043.
* Mac OS X / Darwin's C preprocessor is Apple specific. It
044.
* generates numerous errors and warnings. We want to bypass it
045.
* and use GNU C's cpp. To do this we pass the -traditional-cpp
046.
* option to the compiler. Note that the -traditional-cpp flag
047.
* DOES NOT have the same semantics as GNU C's flag, all it does
048.
* is invoke the GNU preprocessor in stock ANSI/ISO C fashion.
049.
*
050.
* Apple's linker is similar, thanks to the new 2 stage linking
051.
* multiple symbol definitions are treated as errors, hence the
052.
* -multiply_defined suppress option to turn off this error.
053.
*/
054.
ifeq ($(HOSTOS),darwin)
055.
......
056.
else
057.
HOSTCC = gcc
058.
endif
059.
060.
ifeq ($(HOSTOS),cygwin)
061.
......
062.
endif
063.
064.
/* We build some files with extra pedantic flags to try to minimize things
065.
* that won't build on some weird host compiler -- though there are lots of
066.
* exceptions for files that aren't complaint.
067.
*/
068.
HOSTCFLAGS_NOPED = $(filter-out -pedantic,$(HOSTCFLAGS))
069.
/* -pedantic: 当GCC在编译不符合ANSI/ISO C语言标准的源代码时,如果在编译指令中加上了-pedantic选项
070.
* 那么源程序中使用了扩展语法的地方将产生相应的警告信息
071.
*/
072.
HOSTCFLAGS += -pedantic
073.
074.
#########################################################################
075.
/* Option checker (courtesy linux kernel) to ensure
076.
* only supported compiler options are used
077.
* cc-option变量保存了一个测试编译选项的命令,其他地方会经常用call函数来调用它,测试编译选项
078.
* if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null >/dev/null 2>&1;then
079.
echo "$(1)";
080.
else
081.
echo "$(2)";
082.
fi;
083.
* -S:编译后立即结束,不进行<a href="http://www.it165.net/pro/yysam/" target="_blank" class="keylink">汇编</a>等操作
084.
* -o /dev/null : 生成文件到/dev/null,即不生成任何编译结果,要编译的文件也为空
085.
* -xc: 指定按c语言编译
086.
* 用此语句如:call cc-option,-a,-b 则如果支持-a选项则返回-a否则返回-b
087.
*/
088.
cc-option = $(shell
if
$(CC) $(CFLAGS) $(
1
) -S -o /dev/
null
-xc /dev/
null
\
089.
> /dev/
null
2
>&
1
; then echo
"$(1)"
;
else
echo
"$(2)"
; fi ;)
090.
091.
/* Include the make variables (CC, etc...) */
092.
AS = $(CROSS_COMPILE)as
/* 汇编工具 */
093.
LD = $(CROSS_COMPILE)ld
/* 链接工具 */
094.
CC = $(CROSS_COMPILE)gcc
/* 编译工具 */
095.
CPP = $(CC) -E
/* 预处理 */
096.
AR = $(CROSS_COMPILE)ar
/* 归档工具 */
097.
NM = $(CROSS_COMPILE)nm
/* 列出object文件中的符号 */
098.
LDR = $(CROSS_COMPILE)ldr
099.
STRIP = $(CROSS_COMPILE)strip
100.
OBJCOPY = $(CROSS_COMPILE)objcopy
/* 转换可执行文件格式工具 */
101.
OBJDUMP = $(CROSS_COMPILE)objdump
/* 反汇编工具 */
102.
RANLIB = $(CROSS_COMPILE)RANLIB
/* 产生归档文件索引 */
103.
104.
#########################################################################
105.
/* Load generated board configuration */
106.
/* sinclude:
107.
* 在Makefile中可使用"sinclude"代替"include",用来忽略由于包含文件不存在或者无法创建时的错误
108.
*/
109.
sinclude $(OBJTREE)/include/autoconf.mk
110.
111.
/* Some architecture config.mk files need to know what CPUDIR is set to,
112.
* so calculate CPUDIR before including ARCH/SOC/CPU config.mk files.
113.
* Check if arch/$ARCH/cpu/$CPU exists, otherwise assume arch/$ARCH/cpu contains
114.
* CPU-specific code.
115.
*/
116.
CPUDIR=arch/$(ARCH)/cpu/$(CPU)
117.
ifneq ($(SRCTREE)/$(CPUDIR),$(wildcard $(SRCTREE)/$(CPUDIR)))
118.
CPUDIR=arch/$(ARCH)/cpu
119.
endif
120.
/* CPUDIR=arch/arm/cpu/arm920t */
121.
122.
/* include architecture dependend rules: arch/arm/config.mk */
123.
sinclude $(TOPDIR)/arch/$(ARCH)/config.mk
124.
/* include CPU specific rules: arch/arm/cpu/arm920t/config.mk */
125.
sinclude $(TOPDIR)/$(CPUDIR)/config.mk
126.
ifdef SOC
127.
/* include SoC specific rules: arch/arm/cpu/arm920t/s3c24x0/config.mk */
128.
sinclude $(TOPDIR)/$(CPUDIR)/$(SOC)/config.mk
129.
endif
130.
ifdef VENDOR
131.
BOARDDIR = $(VENDOR)/$(BOARD)
132.
else
133.
BOARDDIR = $(BOARD)
134.
endif
135.
/* BOARDDIR = samsung/smdk2410 */
136.
137.
ifdef BOARD
138.
/* include board specific rules: board/samsung/smdk2410/config.mk */
139.
sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk
140.
endif
141.
142.
#########################################################################
143.
ifneq (,$(findstring s,$(MAKEFLAGS)))
144.
ARFLAGS = cr
145.
else
146.
ARFLAGS = crv
147.
endif
148.
RELFLAGS= $(PLATFORM_RELFLAGS)
149.
DBGFLAGS= -g # -DDEBUG
150.
OPTFLAGS= -Os #-fomit-frame-pointer
151.
152.
/*
LDSCRIPT = arch/arm/cpu/arm920t/u-boot.lds,在在文件arch/arm/config.mk中赋值*/
153.
ifndef LDSCRIPT
154.
#LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds.debug
155.
ifeq ($(CONFIG_NAND_U_BOOT),y)
156.
LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot-nand.lds
157.
else
158.
LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds
159.
endif
160.
endif
161.
/* 段之间的空隙用0xff填充 */
162.
OBJCFLAGS += --gap-fill=
0xff
163.
164.
gccincdir := $(shell $(CC) -print-file-name=include)
165.
166.
/* CPPFLAGS变量综合了DBGFLAGS,OPTFLAGS,RELFLAGS编译选项,并定义了__KERBEL__
167.
* -D: 设置宏定义__KERNEL__
168.
*/
169.
CPPFLAGS := $(DBGFLAGS) $(OPTFLAGS) $(RELFLAGS) \
170.
-D__KERNEL__
171.
ifneq ($(TEXT_BASE),)
172.
CPPFLAGS += -DTEXT_BASE=$(TEXT_BASE)
173.
endif
174.
175.
ifneq ($(RESET_VECTOR_ADDRESS),)
176.
CPPFLAGS += -DRESET_VECTOR_ADDRESS=$(RESET_VECTOR_ADDRESS)
177.
endif
178.
179.
ifneq ($(OBJTREE),$(SRCTREE))
180.
CPPFLAGS += -I$(OBJTREE)/include2 -I$(OBJTREE)/include
181.
endif
182.
183.
CPPFLAGS += -I$(TOPDIR)/include
184.
CPPFLAGS += -fno-builtin -ffreestanding -nostdinc \
185.
-isystem $(gccincdir) -pipe $(PLATFORM_CPPFLAGS)
186.
187.
ifdef BUILD_TAG
188.
CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes \
189.
-DBUILD_TAG=
'"$(BUILD_TAG)"'
190.
else
191.
CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes
192.
endif
193.
194.
CFLAGS += $(call cc-option,-fno-stack-protector)
195.
196.
/*
$(CPPFLAGS) sets -g, which causes gcc to pass a suitable -g<format>*/
197.
/* option to the assembler. */
198.
AFLAGS_DEBUG :=
199.
200.
AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS)
201.
202.
LDFLAGS += -Bstatic -T $(obj)u-boot.lds $(PLATFORM_LDFLAGS)
203.
ifneq ($(TEXT_BASE),)
204.
LDFLAGS += -Ttext $(TEXT_BASE)
205.
endif
206.
/* LDFLAGS = -Bstatic -T u-boot.lds -Ttext 0x33F80000 */
207.
/* CFLAGS = -g -Os -fno-common -ffixed-r8 -msoft-float -D__KERNEL__ -DTEXT_BASE=0x33F80000 -I/u-boot-2010.06/include -fno-builtin -ffreestanding -nostdinc -isystem /usr/local/arm/4.2.2-eabi/usr/bin-ccache/../lib/gcc/arm-unknown-linux-gnueabi/4.2.2/include -pipe -DCONFIG_ARM -D__ARM__ -marm -mabi=aapcs-linux -mno-thumb-interwork -march=armv4 -Wall -Wstrict-prototypes -fno-stack-protector */
208.
209.
/* Location of a usable BFD library, where we define "usable" as
210.
* "built for ${HOST}, supports ${TARGET}". Sensible values are
211.
* - When cross-compiling: the root of the cross-environment
212.
* - Linux/ppc (native): /usr
213.
* - NetBSD/ppc (native): you lose ... (must extract these from the
214.
* binutils build directory, plus the native and U-Boot include
215.
* files don't like each other)
216.
*
217.
* So far, this is used only by tools/gdb/Makefile.
218.
*/
219.
ifeq ($(HOSTOS),darwin)
220.
BFD_ROOT_DIR = /usr/local/tools
221.
else
222.
ifeq ($(HOSTARCH),$(ARCH))
223.
/* native */
224.
BFD_ROOT_DIR = /usr
225.
else
226.
/* BFD_ROOT_DIR = /LinuxPPC/CDK # Linux/i386 */
227.
/* BFD_ROOT_DIR = /usr/pkg/cross # NetBSD/i386 */
228.
BFD_ROOT_DIR = /opt/powerpc
229.
endif
230.
endif
231.
232.
#########################################################################
233.
export HOSTCC HOSTCFLAGS HO<a href=
"http://www.it165.net/pro/"
target=
"_blank"
class
=
"keylink"
>STL</a>DFLAGS PEDCFLAGS HOSTSTRIP CROSS_COMPILE \
234.
AS LD CC CPP AR NM STRIP OBJCOPY OBJDUMP MAKE
235.
export TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS AFLAGS
236.
237.
#########################################################################
238.
/* 下面几行规定了各种文件的编译时用到的编译选项 */
239.
/* Allow boards to use custom optimize flags on a per dir/file basis */
240.
BCURDIR = $(subst $(SRCTREE)/,,$(CURDIR:$(obj)%=%))
241.
/* BCURDIR = 顶层目录 */
242.
$(obj)%.s: %.S
243.
$(CPP) $(AFLAGS) $(AFLAGS_$(BCURDIR)/$(
@F
)) $(AFLAGS_$(BCURDIR)) \
244.
-o $@ $<
245.
$(obj)%.o: %.S
246.
$(CC) $(AFLAGS) $(AFLAGS_$(BCURDIR)/$(
@F
)) $(AFLAGS_$(BCURDIR)) \
247.
-o $@ $<-c
248.
$(obj)%.o: %.c
249.
$(CC) $(CFLAGS) $(CFLAGS_$(BCURDIR)/$(
@F
)) $(CFLAGS_$(BCURDIR)) \
250.
-o $@ $<-c
251.
$(obj)%.i: %.c
252.
$(CPP) $(CFLAGS) $(CFLAGS_$(BCURDIR)/$(
@F
)) $(CFLAGS_$(BCURDIR)) \
253.
-o $@ $<-c
254.
$(obj)%.s: %.c
255.
$(CC) $(CFLAGS) $(CFLAGS_$(BCURDIR)/$(
@F
)) $(CFLAGS_$(BCURDIR)) \
256.
-o $@ $<-c -S
相关文章推荐
- u-boot的Makefile分析之顶层config.mk
- uboot系列之-----顶层Makefile分析(一)
- uboot 2011-06 之顶层Makefile分析
- 基于ar9331 mips架构AP121 uboot分析(2) 顶层Makefile,mkconfig
- uboot系列之-----顶层Makefile分析(一)
- itop4412 uboot 学习详细记录四丶Exynos4412 编译Makefile的配置文件config.mk分析)
- uboot makefile分析之 make xx_config
- 关于s5pv210的配置、编译过程中相关文件的分析(Makefile、config.mk、mkconfig)
- uboot系列之-----顶层Makefile分析(三)
- uboot系列之-----顶层Makefile分析(一)
- uboot 顶层makefile细节分析
- uboot makefile分析之 make xx_config
- uboot系列之-----顶层Makefile分析(二)
- uboot makefile 的完全分析
- uboot的Makefile分析
- android makefile 编译分析及 android.mk分析
- Uboot 2014.07 makefile分析
- uboot之Makefile分析
- U-boot根目录下的config.mk分析