Chinaunix首页 | 论坛 | 博客
  • 博客访问: 626175
  • 博文数量: 144
  • 博客积分: 5037
  • 博客等级: 大校
  • 技术积分: 1581
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-30 21:49
文章存档

2010年(16)

2009年(128)

分类: LINUX

2009-06-23 11:43:57

 

#定义vivi版本信息,vivi版本号为0.1.4
VERSION = 0
PATCHLEVEL = 1
SUBLEVEL = 4

VIVIRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)

#定义目标平台体系结构,目标平台体系结构是ARM.
#"="":="都是给变量赋值,使用":="的作用是立即把定义中参考到的函数和变量都展开.如果使用"=",函数
#和变量参考会留在那里,就是说改变一个变量的值会导致其他变量的值也被改变.见教材P32.
ARCH := arm

#取得当前使用的shell命令解释器,保存在CONFIG_SHELL中,用来执行scripts文件夹中的配置脚本.
#这里用到了make的内建函数shell,该函数的作用是执行shell命令.
CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
    else if [ -x /bin/bash ]; then echo /bin/bash; \
    else echo sh; fi ; fi)

#取得vivi所在目录名,用到了make的内建函数shell.
TOPDIR    := $(shell /bin/pwd)

#保存头文件所在的目录.可以用Linux内核源码下的include目录,也可以用交叉编译器的include目录.
#例如/usr/local/arm/2.95.3/include
#
# change this to point to the Linux include directory
#
LINUX_INCLUDE_DIR    = /usr/local/arm/2.95.3/include


#vivi的头文件所在目录.
VIVIPATH = $(TOPDIR)/include

#本地编译器和编译参数
HOSTCC = gcc
HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer

#指定交叉编译器
CROSS_COMPILE = /usr/local/arm/2.95.3/bin/arm-linux-
#CROSS_COMPILE = /opt/host/armv4l/bin/armv4l-unknown-linux-

#
# 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
MAKEFILES = $(TOPDIR)/.config
MD5SUM        = md5sum
PERL = perl
AWK        = awk

#导出变量,使这些变量在子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:     do-it-all

#wildcard函数的结果是一列和格式匹配的且文件存在的文件名,文件名之间用一个空格隔开.
#wildcard函数的参数是一个文件名格式,典型的用法包含通配符.
#这里do-it-
ifeq (.config,$(wildcard .config))
include .config
else
CONFIGURATION = config
do-it-all:    config
endif
do-it-all:    Version vivi

#标准CFLAGS
#
# standard CFLAGS
#
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

# 增加驱动程序.drivers added by .config setup

# 如果 CONFIG_SERIAL=y 并且 CONFIG_MTD=y, DRIVERS 的结果为 "drivers/serial/serial.o drivers/mtd/mtd.o"

DRIVERS-y :=
DRIVERS-$(CONFIG_SERIAL) += drivers/serial/serial.o
DRIVERS-$(CONFIG_MTD) += drivers/mtd/mtd.o
DRIVERS := $(DRIVERS-y)


#执行make clean时要删除的文件
CLEAN_FILES = \
    vivi-elf \
    vivi \
    vivi.nm \
    vivi.map

#库文件所在的路径
#
# Location of the gcc arm libs.
#
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-unknown-linux/2.95.2
#ARM_GCC_LIBS    = /opt/host/armv4l/lib/gcc-lib/armv4l-redhat-linux/2.95.3

OBJCOPYFLAGS = -R .comment -R .stab -R .stabstr

CLIBS = -L$(ARM_GCC_LIBS) -lgcc -lc
LINKFLAGS = -Tarch/vivi.lds -Bstatic

 

#执行make distclean时要删除的文件
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

#执行make Version时要删除的文件
Version: dummy
 @rm -f include/compile.h

#执行make vivi时要执行的动作
vivi: include/version.h $(CONFIGURATION) init/main.o init/version.o linuxsubdirs
 $(LD) -v $(LINKFLAGS) \
  $(HEAD) \
  $(CORE_FILES) \
  $(DRIVERS) \
  $(LIBS) \
  -o vivi-elf $(CLIBS)
 $(NM) -v -l vivi-elf > vivi.map
 $(OBJCOPY) -O binary -S vivi-elf vivi $(OBJCOPYFLAGS)

#执行make oldconfig时要执行的动作
oldconfig:
 $(CONFIG_SHELL) scripts/Configure -d arch/config.in

#执行make config时要执行的动作
config:
 $(CONFIG_SHELL) scripts/Configure arch/config.in

#执行make menuconfig时要执行的动作
menuconfig: include/version.h
 $(MAKE) -C scripts/lxdialog all
 $(CONFIG_SHELL) scripts/Menuconfig arch/config.in

#执行make clean时要执行的动作
clean:
 find . \( -name '*.o' -o -name core -o -name ".*.flags" \) -type f -print \
 | grep -v lxdialog/ | xargs rm -f
 rm -f $(CLEAN_FILES)

#执行distclean时要执行的动作
distclean: clean
 rm -f $(DISTCLEAN_FILES)

linuxsubdirs: $(patsubst %, _dir_%, $(SUBDIRS))

$(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显示的三句话,可以看vivi源码目录include/version.h
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 $@

#产生两个.o文件.
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

阅读(1308) | 评论(0) | 转发(0) |
0

上一篇:vivi中bon和part的区别

下一篇:Linux信号signal

给主人留下些什么吧!~~