uboot的Makefile

来源:互联网 发布:游戏辅助编程 编辑:程序博客网 时间:2024/05/20 07:16

参考的韦东山老师的嵌入式完全开发手册。

分析Makefile配置过程:

make 100ask24x0_config  //为什么是这样配置的呢?
在makefile查找100ask24x0_config  
可以查到如下的内容:
100ask24x0_config :unconfig
@$(MKCONFIG) $(@:_config=) arm arm920t 100ask24x0 NULL s3c24x0
#  mkconfig    100ask24x0   
#  MKCONFIG := $(SRCTREE)/mkconfig
#  SRCTREE := $(CURDIR)
#  $(@:_config=)就是将100ask24x0_config中的_config替换为空!得到100ask24x0,这里使用了Makefile中的替换引用规则,
#  类似常看到的例子 obj=$(srcfiles:%.c=%.o),由.c得到对应的.o文件.这里是一样的道理。
#  于是我们执行make 100ask24x0_config的时候就相当于:
#  mkconfig  100ask24x0 arm arm920t 100ask24x0 NULL s3c24x0


接下来打开mkconfig文件继续操作:
#!/bin/sh -e
# Script to create header files and links to configure
# U-Boot for a specific board.
#
# Parameters:  Target  Architecture  CPU  Board [VENDOR] [SOC]
#
# (C) 2002-2006 DENX Software Engineering, Wolfgang Denk <wd@denx.de>

#mkconfig  100ask24x0 arm arm920t 100ask24x0 NULL s3c24x0
   $0                     $1            $2        $3              $4             $5       $6
APPEND=no # Default: Create new config file
BOARD_NAME="" # Name to print in make output

# -gt 检测左边的数是否大于右边的,如果是,则返回 true。
# $# 传递给脚本或函数的参数个数。
# 我们的命令行没有-- 、- 、*、break。
while [ $# -gt 0 ] ; do
case "$1" in
--) shift ; break ;;
-a) shift ; APPEND=yes ;;
-n) shift ; BOARD_NAME="${1%%_config}" ; shift ;;
*)  break ;;
esac
done

[ "${BOARD_NAME}" ] || BOARD_NAME="$1"
# 执行完上一句相当于 BOARD_NAME=100ask24x0 

# -lt 检测左边的数是否小于右边的,如果是,则返回 true。
# 以下两句判断 参数个数是否小于4 大于 6 ,是的话退出。显然不满足。
[ $# -lt 4 ] && exit 1
[ $# -gt 6 ] && exit 1

echo "Configuring for ${BOARD_NAME} board..."
#
# Create link to architecture specific headers
#

#SRCTREE 在Makefile中查找,可以找到那么一段:

#OBJTREE := $(if $(BUILD_DIR),$(BUILD_DIR),$(CURDIR))  #如果定义了BUILD_DIR 那么OBJTREE等于BUILD_DIR ,否则OBJTREE等于CURDIR,查看BUILD_DIR

#知道他在Makefile中没有定义。
#SRCTREE := $(CURDIR)
#TOPDIR := $(SRCTREE)
#LNDIR := $(OBJTREE)
#export TOPDIR SRCTREE OBJTREE

#经过分析Makefile知道以下的不执行转而执行else。

if [ "$SRCTREE" != "$OBJTREE" ] ; then
mkdir -p ${OBJTREE}/include
mkdir -p ${OBJTREE}/include2
cd ${OBJTREE}/include2
rm -f asm
ln -s ${SRCTREE}/include/asm-$2 asm
LNPREFIX="../../include2/asm/"
cd ../include
rm -rf asm-$2
rm -f asm
mkdir asm-$2
ln -s asm-$2 asm


else
cd ./include
rm -f asm
ln -s asm-$2 asm  #ln -s asm-arm  asm  //asm 指向 asm-arm的文件。
fi
rm -f asm-$2/arch
if [ -z "$6" -o "$6" = "NULL" ] ; then    #如果 第六个参数检测字符串是否为0或者是否为空,在我们这里为s3c24x0 ,下面这句不执行。
ln -s ${LNPREFIX}arch-$3 asm-$2/arch


else
ln -s ${LNPREFIX}arch-$6 asm-$2/arch #LNPREFIX 没人定义它,这句话相当于ln -s arch-s3c24x0  asm-arm/arch
fi

#这句分析跟前面一样的
if [ "$2" = "arm" ] ; then
rm -f asm-$2/proc
ln -s ${LNPREFIX}proc-armv asm-$2/proc
fi
#
# Create include file for Make
#


echo "ARCH   = $2" >  config.mk   # > 表示新建一个文件
echo "CPU    = $3" >> config.mk  # >> 表示把这个内容追加到config.mk 文件当中。
echo "BOARD  = $4" >> config.mk
[ "$5" ] && [ "$5" != "NULL" ] && echo "VENDOR = $5" >> config.mk
[ "$6" ] && [ "$6" != "NULL" ] && echo "SOC    = $6" >> config.mk

# config.mk文件的内容为:

# ARCH   = arm

# CPU     = arm920t

# BOARD  = 100ask24x0

# SOC     = s3c240x

# Create board specific header file
#
if [ "$APPEND" = "yes" ] # Append to existing config file
then
echo >> config.h
else
> config.h # Create new config file
fi
echo "/* Automatically generated - do not edit */" >>config.h
echo "#include <configs/$1.h>" >>config.h
exit 0

看看Makefile中的一些内容:

# load ARCH, BOARD, and CPU configuration
include $(OBJTREE)/include/config.mk
export ARCH CPU BOARD VENDOR SOC

我们可以看到在这里前面配置的内容在Makefile中就这样用上了。


0 0
原创粉丝点击