# # (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 of the GNU General Public License as # published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, # MA 02111-1307 USA # ######################################################################### # 假如$(OBJTREE)和$(SRCTREE)不相等。这里是相等 ifneq ($(OBJTREE),$(SRCTREE)) # 假如$(CURDIR)和$(SRCTREE)相等。这里是相等 ifeq ($(CURDIR),$(SRCTREE)) dir := else # 将$(CURDIR)中的$(SRCTREE)/替换为空。 # subst字符串处理函数。$(subst FROM,TO,TEXT),即将TEXT中的东西从FROM变为TO dir := $(subst $(SRCTREE)/,,$(CURDIR)) endif # 假如$(dir)存在且值不为空,则obj:=$(OBJTREE)/$(dir)/;则obj:=$(OBJTREE)/ # 这里,$(dir)未定义,因此这里: # obj:=$(OBJTREE)/ # src:=$(SRCTREE)/ obj := $(if $(dir),$(OBJTREE)/$(dir)/,$(OBJTREE)/) src := $(if $(dir),$(SRCTREE)/$(dir)/,$(SRCTREE)/) # 创建目录$(obj)。-p的意思是:假如目录已经存在,不产生错误;如果需要,创建父目录。 $(shell mkdir -p $(obj)) else obj := src := endif # clean the slate ... PLATFORM_RELFLAGS = PLATFORM_CPPFLAGS = PLATFORM_LDFLAGS = ######################################################################### # 假如存在$BASH则CONFIG_SHELL:=$BASH;否则假如存在/bin/bash则CONFIG_SHELL:=/bin/bash;否则CONFIG_SHELL:=sh # 这里CONFIG_SHELL:=$BASH CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \ else if [ -x /bin/bash ]; then echo /bin/bash; \ else echo sh; fi ; fi) HOSTCC = gcc # -Wall 打开所有警告 # -Wstrict-prototypes 假如函数声明或定义时没有指定参数类型,发出警告 # -O2 优化等级2 # -fomit-frame-pointer 函数不再需要就不保存frame pointer在寄存器。(去除函数框架) # FP(frame pointer,指向栈中一个函数的local 变量的首地址) HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer # strip函数:去掉字串中开头和结尾的空字符,字符串内部的连续多个空格替换为一个空格。 HOSTSTRIP = strip ######################################################################### # # Option checker (courtesy linux kernel) to ensure # only supported compiler options are used # # 执行$(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1命令 # 将$(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null的标准输出输出到/dev/null,2>&1是将标准错误输出重定向到标准输出,也就是输出到2>&1/dev/null。 # $(1) 这里是用在call函数里面,见后面使用此变量的位置。详情请查询call函数。 # $(call ,,,...) # 当make执行这个函数时,参数中的变量,如$(1),$(2),$(3)等,会被参数,,依次取代。而的返回值就是call函数的返回值。 # -S 仅仅编译,不组合或连接 # -o <file> 输出文件到<file> # -x <language> 指定输入文件的语言 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 # -E 仅仅预处理,不编译,组合或连接 CPP = $(CC) -E AR = $(CROSS_COMPILE)ar NM = $(CROSS_COMPILE)nm LDR = $(CROSS_COMPILE)ldr STRIP = $(CROSS_COMPILE)strip OBJCOPY = $(CROSS_COMPILE)objcopy OBJDUMP = $(CROSS_COMPILE)objdump RANLIB = $(CROSS_COMPILE)RANLIB ######################################################################### # Load generated board configuration # -include 对于任何不存在的 makefile 文件都不会产生错误(即使警告信息也不会产生) # 为保持兼容性所以使用sinclude,作用同-include sinclude $(OBJTREE)/include/autoconf.mk # 假如定义了$ARCH ifdef ARCH # sinclude arm_config.mk。里面预定义了CONFIG_ARM和__ARM__,默认值分别为1 sinclude $(TOPDIR)/$(ARCH)_config.mk # include architecture dependend rules endif ifdef CPU # sinclude cpu/s5pc11x/config.mk。 sinclude $(TOPDIR)/cpu/$(CPU)/config.mk # include CPU specific rules endif ifdef SOC # sinclude cpu/s5pc11x/$(SOC)/config.mk。没找到这个文件 sinclude $(TOPDIR)/cpu/$(CPU)/$(SOC)/config.mk # include SoC specific rules endif ifdef VENDOR # BOARDDIR = samsung/smdkc110 BOARDDIR = $(VENDOR)/$(BOARD) else BOARDDIR = $(BOARD) endif ifdef BOARD # sinclude board/samsung/smdkc110/config.mk。 sinclude $(TOPDIR)/board/$(BOARDDIR)/config.mk # include board specific rules # TEXT_BASE=0xc3e00000 endif ######################################################################### # 假如没有在$(MAKEFLAGS)中找到字符串“s” ifneq (,$(findstring s,$(MAKEFLAGS))) # c 假如库被创建,也不产生警告 # r 取代现有的或插入新文件到归档 ARFLAGS = cr else # v 输出详细信息 ARFLAGS = crv endif # RELFLAGS为空值 RELFLAGS= $(PLATFORM_RELFLAGS) # -g 以操作系统的本地格式(stabs, COFF, XCOFF,或DWARF)产生调试信息。GDB能够使用这些调试信息。 DBGFLAGS= -g # -DDEBUG # -Os OPTFLAGS= -Os #-fomit-frame-pointer # 这里,LDSCRIPT未定义 ifndef LDSCRIPT # LDSCRIPT去掉前面的顶层目录的路径后的值为:board/samsung/smdkc110/u-boot.lds #LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds.debug LDSCRIPT := $(TOPDIR)/board/$(BOARDDIR)/u-boot.lds endif # --gap-fill 用0xff填补空白部分 OBJCFLAGS += --gap-fill=0xff # -print-file-name=<lib> 显示<lib>库的全路径 gccincdir := $(shell $(CC) -print-file-name=include) # -D__KERNEL__预定义宏__KERNEL__,默认值1 CPPFLAGS := $(DBGFLAGS) $(OPTFLAGS) $(RELFLAGS) \ -D__KERNEL__ # 扩展开来后,即,预定义宏TEXT_BASE,值为0xc3e00000 CPPFLAGS += -DTEXT_BASE=$(TEXT_BASE) ifneq ($(OBJTREE),$(SRCTREE)) CPPFLAGS += -I$(OBJTREE)/include2 -I$(OBJTREE)/include endif # -I dir 添加dir目录到被搜索的头文件目录列表中 CPPFLAGS += -I$(TOPDIR)/include # -fno-builtin 不识别内置功能,不要一开始就用“__builtin_”作为前缀 # -ffreestanding 断言编译发生在一个独立的环境。 # -nostdinc 不要搜索标准系统目录中的头文件。 # -isystem dir 在dir中搜索头文件。 # -pipe 编译的各个阶段之间使用管道沟通,而不是使用临时文件。 CPPFLAGS += -fno-builtin -ffreestanding -nostdinc \ -isystem $(gccincdir) -pipe $(PLATFORM_CPPFLAGS) # 没有定义BUILD_TAG ifdef BUILD_TAG CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes \ -DBUILD_TAG='"$(BUILD_TAG)"' else # -Wall 打开所有警告 # -Wstrict-prototypes 假如一个函数申明或定义时没有指定参数类型则发出警告 CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes endif # -fno-stack-protector 不做栈保护 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 := # -D__ASSEMBLY__预订已宏__ASSEMBLY__,默认值1 AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS) # -Bstatic 这些选项传递给连接器。 # -T script 使用script作为连接器脚本 LDFLAGS += -Bstatic -T $(LDSCRIPT) $(PLATFORM_LDFLAGS) # 假如$(TEXT_BASE)不为空 ifneq ($(TEXT_BASE),) # -Ttext=org 在输出文件中定位一个段,由org给出绝对地址 LDFLAGS += -Ttext $(TEXT_BASE) endif # 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. # 假如$(PCI_CLOCK)等于PCI_66M。这里,PCI_CLOCK没有定义 ifeq ($(PCI_CLOCK),PCI_66M) CFLAGS := $(CFLAGS) -DPCI_66M endif ######################################################################### 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 ######################################################################### %.s: %.S # -o <file> 将输出写到<file> $(CPP) $(AFLAGS) -o $@ $< %.o: %.S # -c 编译和组合,但不连接 $(CC) $(AFLAGS) -c -o $@ $< %.o: %.c $(CC) $(CFLAGS) -c -o $@ $< #########################################################################
参考文档:来源于对应编译器的说明文档。
-Wall This enables all the warnings about constructions that some users consider questionable, and that are easy to avoid (or modify to prevent the warning), even in conjunction with macros. This also enables some language-specific warnings described in Section 3.5 [C++ Dialect Options], page 35 and Section 3.6 [Objective-C and Objective-C++ Dialect Options], page 45. ‘-Wall’ turns on the following warning flags: -Waddress -Warray-bounds (only with ‘-O2’) -Wc++11-compat -Wchar-subscripts -Wenum-compare (in C/Objc; this is on by default in C++) -Wimplicit-int (C and Objective-C only) -Wimplicit-function-declaration (C and Objective-C only) -Wcomment -Wformat -Wmain (only for C/ObjC and unless ‘-ffreestanding’) -Wmaybe-uninitialized -Wmissing-braces -Wnonnull -Wparentheses -Wpointer-sign -Wreorder -Wreturn-type -Wsequence-point -Wsign-compare (only in C++) -Wstrict-aliasing -Wstrict-overflow=1 -Wswitch -Wtrigraphs -Wuninitialized -Wunknown-pragmas -Wunused-function -Wunused-label -Wunused-value -Wunused-variable -Wvolatile-register-var Note that some warning flags are not implied by ‘-Wall’. Some of them warn about constructions that users generally do not consider questionable, but which occasionally you might wish to check for; others warn about constructions that are necessary or hard to avoid in some cases, and there is no simple way to mod- ify the code to suppress the warning. Some of them are enabled by ‘-Wextra’ but many of them must be enabled individually.
-Wstrict-prototypes (C and Objective-C only) Warn if a function is declared or defined without specifying the argument types. (An old-style function definition is permitted without a warning if preceded by a declaration that specifies the argument types.)
-O2 Optimize even more. GCC performs nearly all supported optimizations that do not involve a space-speed tradeoff. As compared to ‘-O’, this option increases both compilation time and the performance of the generated code. ‘-O2’ turns on all optimization flags specified by ‘-O’. It also turns on the following optimization flags: -fthread-jumps -falign-functions -falign-jumps -falign-loops -falign-labels -fcaller-saves -fcrossjumping -fcse-follow-jumps -fcse-skip-blocks -fdelete-null-pointer-checks -fdevirtualize -fexpensive-optimizations -fgcse -fgcse-lm -finline-small-functions -findirect-inlining -fipa-sra -foptimize-sibling-calls -fpartial-inlining -fpeephole2 -fregmove -freorder-blocks -freorder-functions -frerun-cse-after-loop -fsched-interblock -fsched-spec -fschedule-insns -fschedule-insns2 -fstrict-aliasing -fstrict-overflow -ftree-switch-conversion -ftree-tail-merge -ftree-pre -ftree-vrp Please note the warning under ‘-fgcse’ about invoking ‘-O2’ on programs that use computed gotos.
-fomit-frame-pointer Don’t keep the frame pointer in a register for functions that don’t need one. This avoids the instructions to save, set up and restore frame pointers; it also makes an extra register available in many functions. It also makes debugging impossible on some machines. On some machines, such as the VAX, this flag has no effect, because the stan- dard calling sequence automatically handles the frame pointer and nothing is saved by pretending it doesn’t exist. The machine-description macro FRAME_ POINTER_REQUIRED controls whether a target machine supports this flag. See Section “Register Usage” in GNU Compiler Collection (GCC) Internals. Starting with GCC version 4.6, the default setting (when not opti- mizing for size) for 32-bit Linux x86 and 32-bit Darwin x86 targets has been changed to ‘-fomit-frame-pointer’. The default can be reverted to ‘-fno-omit-frame-pointer’ by configuring GCC with the ‘--enable-frame-pointer’ configure option. Enabled at levels ‘-O’, ‘-O2’, ‘-O3’, ‘-Os’.
-S Compile only; do not assemble or link
-o <file> Place the output into <file>
-x <language> Specify the language of the following input files Permissible languages include: c c++ assembler none 'none' means revert to the default behavior of guessing the language based on the file's extension
-E Preprocess only; do not compile, assemble or link
[c] - do not warn if the library had to be created
r[ab][f][u] - replace existing or insert new file(s) into the archive
[v] - be verbose
-g Produce debugging information in the operating system’s native format (stabs, COFF, XCOFF, or DWARF 2). GDB can work with this debugging informa- tion. On most systems that use stabs format, ‘-g’ enables use of extra debugging information that only GDB can use; this extra information makes debugging work better in GDB but will probably make other debuggers crash or refuse to read the program. If you want to control for certain whether to generate the extra information, use ‘-gstabs+’, ‘-gstabs’, ‘-gxcoff+’, ‘-gxcoff’, or ‘-gvms’ (see below). GCC allows you to use ‘-g’ with ‘-O’. The shortcuts taken by optimized code may occasionally produce surprising results: some variables you declared may not exist at all; flow of control may briefly move where you did not expect it; some statements may not be executed because they compute constant results or their values were already at hand; some statements may execute in different places because they were moved out of loops. Nevertheless it proves possible to debug optimized output. This makes it rea- sonable to use the optimizer for programs that might have bugs. The following options are useful when GCC is generated with the capability for more than one debugging format.
-Os Optimize for size. ‘-Os’ enables all ‘-O2’ optimizations that do not typically increase code size. It also performs further optimizations designed to reduce code size. ‘-Os’ disables the following optimization flags: -falign-functions -falign-jumps -falign-loops -falign-labels -freorder-blocks -freorder-blocks-and-partition -fprefetch-loop-arrays -ftree-vect-loop-version
--gap-fill <val> Fill gaps between sections with <val>
-print-file-name=library Print the full absolute name of the library file library that would be used when linking—and don’t do anything else. With this option, GCC does not compile or link anything; it just prints the file name.
-D name Predefine name as a macro, with definition 1.
-I dir Add the directory dir to the list of directories to be searched for header files. Directories named by ‘-I’ are searched before the standard system include di- rectories. If the directory dir is a standard system include directory, the option is ignored to ensure that the default search order for system directories and the special treatment of system headers are not defeated . If dir begins with =, then the = will be replaced by the sysroot prefix; see ‘--sysroot’ and ‘-isysroot’.
-fno-builtin -fno-builtin-function Don’t recognize built-in functions that do not begin with ‘__builtin_’ as prefix. See Section 6.53 [Other built-in functions provided by GCC], page 405, for details of the functions affected, including those which are not built-in functions when ‘-ansi’ or ‘-std’ options for strict ISO C conformance are used because they do not have an ISO standard meaning. GCC normally generates special code to handle certain built-in functions more efficiently; for instance, calls to alloca may become single instructions that adjust the stack directly, and calls to memcpy may become inline copy loops. The resulting code is often both smaller and faster, but since the function calls no longer appear as such, you cannot set a breakpoint on those calls, nor can you change the behavior of the functions by linking with a different library. In addition, when a function is recognized as a built-in function, GCC may use information about that function to warn about problems with calls to that function, or to generate more efficient code, even if the resulting code still contains calls to that function. For example, warnings are given with ‘-Wformat’ for bad calls to printf, when printf is built in, and strlen is known not to modify global memory. With the ‘-fno-builtin-function ’ option only the built-in function function is disabled. function must not begin with ‘__builtin_’. If a function is named that is not built-in in this version of GCC, this option is ignored. There is no corresponding ‘-fbuiltin-function ’ option; if you wish to enable built-in functions selectively when using ‘-fno-builtin’ or ‘-ffreestanding’, you may define macros such as: #define abs(n) #define strcpy(d, s) __builtin_abs ((n)) __builtin_strcpy ((d), (s))
-ffreestanding Assert that compilation takes place in a freestanding environment. This implies ‘-fno-builtin’. A freestanding environment is one in which the standard library may not exist, and program startup may not necessarily be at main. The most obvious example is an OS kernel. This is equivalent to ‘-fno-hosted’. See Chapter 2 [Language Standards Supported by GCC], page 5, for details of freestanding and hosted environments.
-nostdinc Do not search the standard system directories for header files. Only the direc- tories you have specified with ‘-I’ options (and the directory of the current file, if appropriate) are searched.
-isystem dir Search dir for header files, after all directories specified by ‘-I’ but before the standard system directories. Mark it as a system directory, so that it gets the same special treatment as is applied to the standard system directories. If dir begins with =, then the = will be replaced by the sysroot prefix; see ‘--sysroot’ and ‘-isysroot’.
-pipe Use pipes rather than temporary files for communication between the various stages of compilation. This fails to work on some systems where the assembler is unable to read from a pipe; but the GNU assembler has no trouble.
-fstack-protector Emit extra code to check for buffer overflows, such as stack smashing attacks. This is done by adding a guard variable to functions with vulnerable objects. This includes functions that call alloca, and functions with buffers larger than 8 bytes. The guards are initialized when a function is entered and then checked when the function exits. If a guard check fails, an error message is printed and the program exits.
-Bstatic -Bdynamic These options are passed down to the linker. They are defined for compatibility with Diab.
-T script Use script as the linker script. This option is supported by most systems using the GNU linker. On some targets, such as bare-board targets without an oper- ating system, the ‘-T’ option may be required when linking to avoid references to undefined symbols.
-Ttext=org Same as ‘--section-start’, with .bss, .data or .text as the sectionname.
--section-start=sectionname =org Locate a section in the output file at the absolute address given by org. You may use this option as many times as necessary to locate multiple sections in the command line. org must be a single hexadecimal integer; for compatibility with other linkers, you may omit the leading ‘0x’ usually associated with hexadecimal values. Note: there should be no white space between sectionname, the equals sign (“=”), and org.
-o file Write output to file. This is the same as specifying file as the second non-option argument to cpp. gcc has a different interpretation of a second non-option argument, so you must use ‘-o’ to specify the output file.
-c Compile or assemble the source files, but do not link. The linking stage simply is not done. The ultimate output is in the form of an object file for each source file. By default, the object file name for a source file is made by replacing the suffix ‘.c’, ‘.i’, ‘.s’, etc., with ‘.o’. Unrecognized input files, not requiring compilation or assembly, are ignored.