向自己汇报一下从上周五到今天的学习情况,现在试着学习平台的一些东西,虽然有点涩涩的感觉,但还是有收获和感悟的,首先读了vivi的Makefile 大体上明白了Makefile机制,主makefiel通过SUBDIRS变量来进入哪个目录,由于Rules.make 文件依次进到各个目录的最深目录,执行完make all再一层层回到主makefile。
#版本好号(0.1.4)
VERSION = 0
PATCHLEVEL = 1
SUBLEVEL = 4
VIVIRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)#vivi version 0.1.4
# 系统平台
ARCH := arm
#shell 是一个函数,函数参数为一个shell命令,返回是此命令在shell中执行的结果
#将CONFIG_SHELL变量赋值为系统所使用的命令解释器。(-x 判断可执行文件)
CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
else if [ -x /bin/bash ]; then echo /bin/bash; \
else echo sh; fi ; fi)
#得到顶层目录
TOPDIR := $(shell /bin/pwd)
#
# change this to point to the Linux include directory
#
#多余的定义,这是在linux 内核用的
#LINUX_INCLUDE_DIR = /opt/host/armv4l/include/
LINUX_INCLUDE_DIR = /usr/local/arm/2.95.3/include/
#头文件搜索路径
VIVIPATH = $(TOPDIR)/include
#这不用说了
HOSTCC = gcc
HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
#CROSS_COMPILE = /opt/host/armv4l/bin/armv4l-unknown-linux-
#CROSS_COMPILE = /opt/host/armv4l/bin/armv4l-redhat-linux-
#编译路径
CROSS_COMPILE = /usr/local/arm/2.95.3/bin/arm-linux-
#
# Include the make variables (CC, etc...)
#
# 定义编译过程中使用的工具as:生成汇编代码,ld:连接,gcc:编译,cpp:预处理ar和nm,objdump都是对象文件分析工具,配合不同的参数能实现不同功能,他可以讲c代码反汇编,也可次像ar一样查去库文件信息,
#ar主要能让你查看函数库里的详细情况,和用多个对象文件生成一个库文件(*lib.a),
#nm可以列出目标文件的所有符号清单和目标文件的属性,如果没有目标文件作为参数传给nm,其目标文件为a.out,strip可以除去一些调试信息,objcopy 是将一种格式的目标文件转换成另一种格式的目标文件,这里是转换成了二进制的文件了
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
MAKEFILES = $(TOPDIR)/.config
MD5SUM = md5sum
PERL = perl
AWK = awk
#export将上面的变量导出给子makefile(??)
export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE \
CONFIG_SHELL TOPDIR VIVIPATH HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC \
CPP AR NM STRIP OBJCOPY OBJDUMP MAKE MAKEFILES MD5SUM PERL AWK
#第一个目标文件all,如果.config配置文件存在,则将其包含,do-it-all依赖与Version和vivi,否则do-it-all依赖于config,Version和vivi;wildcard是make内置函数,其作用是列出当前目录下所有复合参数的模式的文件,返回值就是该复合的文件
all: do-it-all
ifeq (.config,$(wildcard .config))
include .config
else
CONFIGURATION = config
do-it-all: config
endif
do-it-all: Version vivi
#
# standard CFLAGS
#
# -I 包含头文件搜索路径
CPPFLAGS := -I$(VIVIPATH) -I$(LINUX_INCLUDE_DIR)
#CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes -Wno-trigraphs -O2 \
# -fomit-frame-pointer -fno-strict-aliasing -fno-common
# 编译的参数
CFLAGS := $(CPPFLAGS) -Wall -Wstrict-prototypes -O2 -fPIC -fomit-frame-pointer
AFLAGS := -D__ASSEMBLY__ $(CPPFLAGS)
#定义了核心文件,库,和子路径
CORE_FILES = init/main.o init/version.o lib/lib.o
LIBS := lib/priv_data/priv_data.o
SUBDIRS = drivers lib
#+=追加,将驱动加上串口驱动和mtd驱动设备(只有CONFIG_SERIAL和CONFIG_MTD 的返回值是y才能追加,这取决与.config(系统配置文件)文件)
DRIVERS-y :=
DRIVERS-$(CONFIG_SERIAL) += drivers/serial/serial.o
DRIVERS-$(CONFIG_MTD) += drivers/mtd/mtd.o
DRIVERS := $(DRIVERS-y)
#删除中间生成的文件
CLEAN_FILES = \
vivi-elf \
vivi \
vivi.nm \
vivi.map
#
# Location of the gcc arm libs.
#定义arm-linux-gcc库位置,如果用的是mizi ftp站下来的镜像就不用改了,否则是要改的
#ARM_GCC_LIBS = /opt/host/armv4l/lib/gcc-lib/armv4l-unknown-linux/2.95.2
ARM_GCC_LIBS = /usr/local/arm/2.95.3/lib/gcc-lib/arm-linux/2.95.3
#ARM_GCC_LIBS = /opt/host/armv4l/lib/gcc-lib/armv4l-redhat-linux/2.95.3
OBJCOPYFLAGS = -R .comment -R .stab -R .stabstr
#连接gcc库和c库
CLIBS = -L$(ARM_GCC_LIBS) -lgcc -lc
#vivi stage1启动程序
LINKFLAGS = -Tarch/vivi.lds -Bstatic
#定义要删除的文件的变量
DISTCLEAN_FILES = \
include/autoconf.h include/version.h \
scripts/lxdialog/*.o scripts/lxdialog/lxdialog \
.menuconfig.log \
.config .config.old TAGS tags
include arch/Makefile#这只是展开,不是进入
#导出变量(具体干什么用不知道?)
export CPPFLAGS CFLAGS AFLAGS
export DRIVERS LDFLAGS
#删除一个文件
Version: dummy
@rm -f include/compile.h
#连接一些文件生成vivi
#CONFIURATION=config上文定义的
vivi: include/version.h $(CONFIGURATION) init/main.o init/version.o linuxsubdirs
$(LD) -v $(LINKFLAGS) \
$(HEAD) \#在artch目录下的makfile中定义的,给出连接文件的列表
$(CORE_FILES) \
$(DRIVERS) \
$(LIBS) \ //link create vivi-elf
-o vivi-elf $(CLIBS)
$(NM) -v -l vivi-elf > vivi.map //use nm tools creat vivi.map(fu hao ying she kuan xi)
$(OBJCOPY) -O binary -S vivi-elf vivi $(OBJCOPYFLAGS)//use objcopy shengcheng vivi convert into binary
oldconfig:
$(CONFIG_SHELL) scripts/Configure -d arch/config.in
config:
$(CONFIG_SHELL) scripts/Configure arch/config.in
#当执行make menuconfig时执行这,-C改变目录,首先进入script/lxdialog目录再执行make all
menuconfig: include/version.h
$(MAKE) -C scripts/lxdialog all
$(CONFIG_SHELL) scripts/Menuconfig arch/config.in
clean:
find . \( -name '*.o' -o -name core -o -name ".*.flags" \) -type f -print \
| grep -v lxdialog/ | xargs rm -f
rm -f $(CLEAN_FILES)
distclean: clean
rm -f $(DISTCLEAN_FILES)
#patsubst 模式替换函数,这里就是成为_dir_drivers,_dir_lib(SUBDIRS=drivers lib)
linuxsubdirs: $(patsubst %, _dir_%, $(SUBDIRS))
#先跳转,在执行make命令,这里patsubst是去掉_dir_这个前缀,为什么要这么做主要原因是在当前目录下有个文件夹叫drivers
$(patsubst %, _dir_%, $(SUBDIRS)) : include/version.h
$(MAKE) CFLAGS="$(CFLAGS) $(CFLAGS_KERNEL)" -C $(patsubst _dir_%, %, $@)
$(TOPDIR)/include/version.h: include/version.h
$(TOPDIR)/include/compile.h: include/compile.h
#下面都是简单的编译规则
include/compile.h: $(CONFIGURATION) include/version.h
@echo -n \#define UTS_VERSION \"\#$(VIVIRELEASE) > .ver
@if [ -f .name ]; then echo -n \-`cat .name` >> .ver; fi
@echo ' '`date`'"' >> .ver
@echo \#define VIVI_COMPILE_TIME \"`date +%T`\" >> .ver
@echo \#define VIVI_COMPILE_BY \"`whoami`\" >> .ver
@echo \#define VIVI_COMPILE_HOST \"`hostname`\" >> .ver
@if [ -x /bin/dnsdomainname ]; then \
echo \#define VIVI_COMPILE_DOMAIN \"`dnsdomainname`\"; \
elif [ -x /bin/domainname ]; then \
echo \#define VIVI_COMPILE_DOMAIN \"`domainname`\"; \
else \
echo \#define VIVI_COMPILE_DOMAIN ; \
fi >> .ver
@echo \#define VIVI_COMPILER \"`$(CC) $(CFLAGS) -v 2>&1 | tail -1`\" >> .ver
@mv -f .ver $@
include/version.h:
@echo \#define VIVI_RELEASE \"$(VIVIRELEASE)\" > .ver
@echo \#define VIVI_VERSION_CODE `expr $(VERSION) \\* 65536 + $(PATCHLEVEL) \\* 256 + $(SUBLEVEL)` >> .ver
@echo '#define VIVI_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))' >>.ver
@mv -f .ver $@
init/version.o: init/version.c include/compile.h
$(CC) $(CFLAGS) -DUTS_MACHINE='"$(ARCH)"' -c -o init/version.o init/version.c
init/main.o: init/main.c
$(CC) $(CFLAGS) $(CFLAGS_KERNEL) $(PROFILING) -c -o $*.o $<
TAGS: dummy
etags `find include -name '*.h'`
find $(SUBDIRS) init -name '*.[ch]' | xargs etags -a
# Exuberant ctags works better with -I
tags: dummy
CTAGSF=`ctags --version | grep -i exuberant >/dev/null && echo "-I __initdata,__exitdata,EXPORT_SYMBOL,EXPORT_SYMBOL_NOVERS"`; \
ctags $$CTAGSF `find include -name '*.h'` && \
find $(SUBDIRS) init -name '*.[ch]' | xargs ctags $$CTAGSF -a
%: ./arch/def-configs/%
$(MAKE) distclean
cp arch/def-configs/$* ./.config -f
$(MAKE) oldconfig
$(MAKE)
ifdef CONFIGURATION
..$(CONFIGURATION):
@echo
@echo "You have a bad or nonexistent" .$(CONFIGURATION) ": running 'make" $(CONFIGURATION)"'"
@echo
$(MAKE) $(CONFIGURATION)
@echo
@echo "Successful. Try re-making (ignore the error that follows)"
@echo
exit 1
dummy:
else
dummy:
endif
include Rules.make
阅读(589) | 评论(0) | 转发(1) |