u-boot的Makefile分析之顶层config.mk

版本信息:
u-boot-2010-06

顶层目录下的config.mk文件主要完成如下功能的配置:

1、确定生成可执行文件过程中需要的各种工具,如编译器(arm-linux-gcc)、连接器(arm-linux-ld)、反汇编器(arm-linux-objdump)等

2、确定CPU、板相关的配置文件,存在于各个目录下的config.mk

3、确定编译、链接、转换等过程的操作选项

4、根据步骤3确定的编译连接选项生成需要的文件

config.mk完整内容及必要注释如下

:config.mk文件注释符改为/* 注释内容 */

ifneq ($(OBJTREE),$(SRCTREE))
	ifeq ($(CURDIR),$(SRCTREE))
		dir :=
	else
		dir := $(subst $(SRCTREE)/,,$(CURDIR))
	endif

	obj := $(if $(dir),$(OBJTREE)/$(dir)/,$(OBJTREE)/)
	src := $(if $(dir),$(SRCTREE)/$(dir)/,$(SRCTREE)/)

	$(shell mkdir -p $(obj))
else
	obj :=
	src :=
endif
/* obj = 空,src = 空
 * dir = 空
 */

/* clean the slate ... */
PLATFORM_RELFLAGS =
PLATFORM_CPPFLAGS =
PLATFORM_LDFLAGS =

/* HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
 * -Wall: 打印出编译时所有的错误或警告信息
 * -Wstrict-prototypes: 编译时,若产生与数据类型不相符的问题,打印出提示或警告信息。当在不同体系结构间移植时,加上该选项可避免很多错误
 * -O: 编译代码时的优化等级,共有五种:-O0、-O1、-O2、-O3和-Os
 * -fomit-frame-pointer: 对于不需要帧指针的函数,不要在寄存器中保存帧指针
 * 代码优化时打开-fomit-frame-pointer,函数调用时不保存frame指针,也就不能用backtrace()来查看函数栈调用
 * backtrace()系列函数见[http://blog.csdn.net/u013686019/article/details/42128771](Linux中backtrace()系列函数的应用实例)
 */
HOSTCFLAGS	= -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer 		  $(HOSTCPPFLAGS)
/* HOSTSTRIP = strip
 * strip能清除执行文件中不必要的标示符及调试信息,可减小文件大小而不影响正常使用,、
 * 与压缩不同的是,文件一旦strip后就不能恢复原样
 * strip后的文件不包含调试信息
 */
HOSTSTRIP	= strip

/*
 * Mac OS X / Darwin's C preprocessor is Apple specific.  It
 * generates numerous errors and warnings.  We want to bypass it
 * and use GNU C's cpp.  To do this we pass the -traditional-cpp
 * option to the compiler.  Note that the -traditional-cpp flag
 * DOES NOT have the same semantics as GNU C's flag, all it does
 * is invoke the GNU preprocessor in stock ANSI/ISO C fashion.
 *
 * Apple's linker is similar, thanks to the new 2 stage linking
 * multiple symbol definitions are treated as errors, hence the
 * -multiply_defined suppress option to turn off this error.
 */
ifeq ($(HOSTOS),darwin)
	......
else
	HOSTCC		= gcc
endif

ifeq ($(HOSTOS),cygwin)
	......
endif

/* We build some files with extra pedantic flags to try to minimize things
 * that won't build on some weird host compiler -- though there are lots of
 * exceptions for files that aren't complaint.
 */
HOSTCFLAGS_NOPED = $(filter-out -pedantic,$(HOSTCFLAGS))
/* -pedantic: 当GCC在编译不符合ANSI/ISO C语言标准的源代码时,如果在编译指令中加上了-pedantic选项
 * 那么源程序中使用了扩展语法的地方将产生相应的警告信息
 */
HOSTCFLAGS	+= -pedantic

#########################################################################
/* Option checker (courtesy linux kernel) to ensure
 * only supported compiler options are used
 * cc-option变量保存了一个测试编译选项的命令,其他地方会经常用call函数来调用它,测试编译选项
 * if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1;then
		echo "$(1)";
   else
		echo "$(2)";
   fi;
 * -S:编译后立即结束,不进行汇编等操作
 * -o /dev/null : 生成文件到/dev/null,即不生成任何编译结果,要编译的文件也为空
 * -xc: 指定按c语言编译
 * 用此语句如:call cc-option,-a,-b 则如果支持-a选项则返回-a否则返回-b
 */
cc-option = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null 		> /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)

/* 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	/* 列出object文件中的符号 */
LDR	= $(CROSS_COMPILE)ldr
STRIP	= $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy /* 转换可执行文件格式工具 */
OBJDUMP = $(CROSS_COMPILE)objdump /* 反汇编工具 */
RANLIB	= $(CROSS_COMPILE)RANLIB  /* 产生归档文件索引 */

#########################################################################
/* Load generated board configuration */
/* sinclude:
 * 在Makefile中可使用"sinclude"代替"include",用来忽略由于包含文件不存在或者无法创建时的错误
 */
sinclude $(OBJTREE)/include/autoconf.mk

/* Some architecture config.mk files need to know what CPUDIR is set to,
 * so calculate CPUDIR before including ARCH/SOC/CPU config.mk files.
 * Check if arch/$ARCH/cpu/$CPU exists, otherwise assume arch/$ARCH/cpu contains
 * CPU-specific code.
 */
CPUDIR=arch/$(ARCH)/cpu/$(CPU)
ifneq ($(SRCTREE)/$(CPUDIR),$(wildcard $(SRCTREE)/$(CPUDIR)))
CPUDIR=arch/$(ARCH)/cpu
endif
/* CPUDIR=arch/arm/cpu/arm920t */

/* include architecture dependend rules: arch/arm/config.mk */
sinclude $(TOPDIR)/arch/$(ARCH)/config.mk
/* include  CPU	specific rules: arch/arm/cpu/arm920t/config.mk */
sinclude $(TOPDIR)/$(CPUDIR)/config.mk
ifdef	SOC
	/* include  SoC	specific rules: arch/arm/cpu/arm920t/s3c24x0/config.mk */
	sinclude $(TOPDIR)/$(CPUDIR)/$(SOC)/config.mk
endif
ifdef	VENDOR
	BOARDDIR = $(VENDOR)/$(BOARD)
else
	BOARDDIR = $(BOARD)
endif
/* BOARDDIR = samsung/smdk2410 */

ifdef	BOARD
	/* include board specific rules: board/samsung/smdk2410/config.mk */
	sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk
endif

#########################################################################
ifneq (,$(findstring s,$(MAKEFLAGS)))
ARFLAGS = cr
else
ARFLAGS = crv
endif
RELFLAGS= $(PLATFORM_RELFLAGS)
DBGFLAGS= -g # -DDEBUG
OPTFLAGS= -Os #-fomit-frame-pointer

/* LDSCRIPT = arch/arm/cpu/arm920t/u-boot.lds,在在文件arch/arm/config.mk中赋值 */
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
/* 段之间的空隙用0xff填充 */
OBJCFLAGS += --gap-fill=0xff

gccincdir := $(shell $(CC) -print-file-name=include)

/* CPPFLAGS变量综合了DBGFLAGS,OPTFLAGS,RELFLAGS编译选项,并定义了__KERBEL__
 * -D: 设置宏定义__KERNEL__
 */
CPPFLAGS := $(DBGFLAGS) $(OPTFLAGS) $(RELFLAGS)			-D__KERNEL__
ifneq ($(TEXT_BASE),)
CPPFLAGS += -DTEXT_BASE=$(TEXT_BASE)
endif

ifneq ($(RESET_VECTOR_ADDRESS),)
CPPFLAGS += -DRESET_VECTOR_ADDRESS=$(RESET_VECTOR_ADDRESS)
endif

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)

ifdef BUILD_TAG
CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes 	-DBUILD_TAG='"$(BUILD_TAG)"'
else
CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes
endif

CFLAGS += $(call cc-option,-fno-stack-protector)

/* $(CPPFLAGS) sets -g, which causes gcc to pass a suitable -g<format> */
/* option to the assembler. */
AFLAGS_DEBUG :=

AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS)

LDFLAGS += -Bstatic -T $(obj)u-boot.lds $(PLATFORM_LDFLAGS)
ifneq ($(TEXT_BASE),)
LDFLAGS += -Ttext $(TEXT_BASE)
endif
/* LDFLAGS = -Bstatic -T u-boot.lds -Ttext 0x33F80000 */
/* 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 */

/* Location of a usable BFD library, where we define "usable" as
 * "built for ${HOST}, supports ${TARGET}".  Sensible values are
 * - When cross-compiling: the root of the cross-environment
 * - Linux/ppc (native): /usr
 * - NetBSD/ppc (native): you lose ... (must extract these from the
 *   binutils build directory, plus the native and U-Boot include
 *   files don't like each other)
 *
 * So far, this is used only by tools/gdb/Makefile.
 */
ifeq ($(HOSTOS),darwin)
	BFD_ROOT_DIR =		/usr/local/tools
else
	ifeq ($(HOSTARCH),$(ARCH))
		/* native */
		BFD_ROOT_DIR =		/usr
	else
		/* BFD_ROOT_DIR =		/LinuxPPC/CDK		# Linux/i386 */
		/* BFD_ROOT_DIR =		/usr/pkg/cross		# NetBSD/i386 */
		BFD_ROOT_DIR =		/opt/powerpc
	endif
endif

#########################################################################
export	HOSTCC HOSTCFLAGS HOSTLDFLAGS PEDCFLAGS HOSTSTRIP CROSS_COMPILE 	AS LD CC CPP AR NM STRIP OBJCOPY OBJDUMP MAKE
export	TEXT_BASE PLATFORM_CPPFLAGS PLATFORM_RELFLAGS CPPFLAGS CFLAGS AFLAGS

#########################################################################
/* 下面几行规定了各种文件的编译时用到的编译选项 */
/* Allow boards to use custom optimize flags on a per dir/file basis */
BCURDIR = $(subst $(SRCTREE)/,,$(CURDIR:$(obj)%=%))
/* BCURDIR = 顶层目录 */
$(obj)%.s:	%.S
	$(CPP) $(AFLAGS) $(AFLAGS_$(BCURDIR)/$(@F)) $(AFLAGS_$(BCURDIR)) 		-o [email protected] $<
$(obj)%.o:	%.S
	$(CC)  $(AFLAGS) $(AFLAGS_$(BCURDIR)/$(@F)) $(AFLAGS_$(BCURDIR)) 		-o [email protected] $< -c
$(obj)%.o:	%.c
	$(CC)  $(CFLAGS) $(CFLAGS_$(BCURDIR)/$(@F)) $(CFLAGS_$(BCURDIR)) 		-o [email protected] $< -c
$(obj)%.i:	%.c
	$(CPP) $(CFLAGS) $(CFLAGS_$(BCURDIR)/$(@F)) $(CFLAGS_$(BCURDIR)) 		-o [email protected] $< -c
$(obj)%.s:	%.c
	$(CC)  $(CFLAGS) $(CFLAGS_$(BCURDIR)/$(@F)) $(CFLAGS_$(BCURDIR)) 		-o [email protected] $< -c -S
时间: 2024-11-13 08:02:03

u-boot的Makefile分析之顶层config.mk的相关文章

uboot顶层config.mk分析

## (C) Copyright 2000-2006# Wolfgang Denk, DENX Software Engineering, [email protected]## See file CREDITS for list of people who contributed to this# project.## This program is free software; you can redistribute it and/or# modify it under the terms

u-boot顶层Makefile分析

1.u-boot制作命令 make forlinx_nand_ram256_config: make all; 2.顶层mkconfig分析,参考 U-BOOT顶层目录mkconfig分析 mkconfig脚本执行后会生成以下3个文件,这些文件中提供的变量会在Makefile中其它地方使用. 116 # load ARCH, BOARD, and CPU configuration 117 include $(OBJTREE)/include/config.mk 118 export ARCH

关于s5pv210的配置、编译过程中相关文件的分析(Makefile、config.mk、mkconfig)

uboot为用户提供两种编译方式,一种是在uboot当前目录下进行编译,第二种方式就是将编译生成的文件输出到指定的目录下. 1) Add O= to the make command line # 'make O=/tmp/build all' # # 2) Set environement variable BUILD_DIR to point to the desired location # 'export BUILD_DIR=/tmp/build' # 'make' # # The se

u-boot-2016.09顶层makefile分析

## SPDX-License-Identifier: GPL-2.0+# VERSION = 2016PATCHLEVEL = 09SUBLEVEL =EXTRAVERSION =NAME = # *DOCUMENTATION*# To see a list of typical targets execute "make help"# More info can be located in ./README# Comments in this file are targeted o

u-boot顶层目录config.mk分析

1. 设置obj与src ifneq ($(OBJTREE),$(SRCTREE)) ifeq ($(CURDIR),$(SRCTREE)) dir := else dir := $(subst $(SRCTREE)/,,$(CURDIR)) endif obj := $(if $(dir),$(OBJTREE)/$(dir)/,$(OBJTREE)/) src := $(if $(dir),$(SRCTREE)/$(dir)/,$(SRCTREE)/) $(shell mkdir -p $(o

嵌入式 Linux开发Kernel移植(三)——Kernel工程Makefile分析

嵌入式 Linux开发Kernel移植(三)--Kernel工程Makefile分析 本文选择三星发布的基于SMDKV210开发板的linux 2.6.35.7版本kernel. 一.Kernel Makefle体系简介 1.Kernel Makefile体系组成 Kernel Makefile体系包含Kconfig和Kbuild两个系统. Kconfig系统 Kconfig 对应的是内核配置阶段,make xxconfig就是在使用Kconfig系统.Kconfig由三部分组成: script

u-boot的Makefile分析

由顶层Makefile文件,梳理U-Boot的编译流程. 小技巧: 在大型Makefile中,很多时候需要确定某个变量的值,一个小方法就是: $(shell echo "VARIABLE0_VAL = $(VARIABLE0_VAL)" > v_file.txt ) $(shell echo "VARIABLE1_VAL = $(VARIABLE1_VAL)" >> v_file.txt ) 1.首先,确定make过程中需要的变量(Makefile

uboot总结:uboot配置和启动过程1(主Makefile分析)

说明:文件位置:在uboot的目录下,文件名为:Makefile 从文件的头部开始分析 1.24-29行,配置uboot的版本信息. VERSION = 1 PATCHLEVEL = 3 SUBLEVEL = 4 EXTRAVERSION = U_BOOT_VERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) VERSION_FILE = $(obj)include/version_autogenerated.h 2.主机的环

uboot移植之makefile分析

/* Name:uboot之makefile分析 Data:2015-3-3 Author:suj_un */ Uboot之makefile分析 编译uboot,内核或者其他软件只需要执行make命令就可以生成可执行文件.执行命令后是怎么工作的?要知道这个就要看makefile了.现在就来揭开这玩意神秘的面纱.其中会粘一些代码段来分析... VERSION = 2010 PATCHLEVEL = 03 SUBLEVEL = EXTRAVERSION = ifneq "$(SUBLEVEL)&qu