首页 > 代码库 > u-boot的Makefile分析之mkconfig
u-boot的Makefile分析之mkconfig
版本信息: u-boot-2010-06
[make smdk_2410]命令执行后,执行顶层Makefile的如下部分:
smdk2410_config : unconfig @$(MKCONFIG) $(@:_config=) arm arm920t smdk2410 samsung s3c24x0首先,确定下变量的值,这里以SMDK2410板为例:
$1 = smdk2410 $2 = arm $3 = arm920t $4 = smdk2410 $5 = samsung $6 = s3c24x0 CURDIR = ./ SRCTREE = ./ TOPDIR = ./ MKCONFIG= $(SRCTREE)/mkconfig = ./mkconfig BOARD_NAME = "$1" = smdk2410 ARCH= arm OBJTREE= $(if $(BUILD_DIR),$(BUILD_DIR),$(CURDIR)) = ./ LNPREFIX = 空 BOARDDIR = $5/$4 = samsung/smdk2410
其次,@$(MKCONFIG) $(@:_config=) arm arm920t smdk2410 samsung s3c24x0实际效果是:
./mkconfig smdk2410 arm arm920t smdk2410 samsung s3c24x0
那么,就来研究下顶层目录下的mkconfig文件。
注: mkconfig文件注释符改为/* 注释内容 */
/* Default: Create new config file */ APPEND=no /* Name to print in make output */ BOARD_NAME="" TARGETS="" /* $#: ./mkconfig smdk2410 arm arm920t smdk2410 samsung s3c24x0命令行参数的个数 * $0 $1 $2 $3 $4 $5 $6 * $符号总结: * $#: 代表后接的参数个数,以上为例这里为[6] * $@: 代表["$1" "$2" "$3" "$4"]之意,每个变量是独立的(用双引号括起来) * $*: 代表["$1c$2c$3c$4"],其中c为分割字符,默认为空格键,所以本例中代表["$1 $2 $3 $4"] * * -gt: great than; -lt: less than */ while [ $# -gt 0 ] ; do case "$1" in /* shift命令: * 变量号码偏移功能,简单来说就是移动变量 * 见[鸟哥的linux私房菜] */ --) shift ; break ;; -a) shift ; APPEND=yes ;; -n) shift ; BOARD_NAME="${1%%_config}" ; shift ;; -t) shift ; TARGETS="`echo $1 | sed 's:_: :g'` ${TARGETS}" ; shift ;; *) break ;; /* case条件不满足,故本循环中不做任何事 */ esac done /* BOARD_NAME = smdk2410 */ [ "${BOARD_NAME}" ] || BOARD_NAME="$1" /* 参数检查,不满足直接退出 */ [ $# -lt 4 ] && exit 1 [ $# -gt 6 ] && exit 1 if [ "${ARCH}" -a "${ARCH}" != "$2" ]; then echo "Failed: \$ARCH=${ARCH}, should be '$2' for ${BOARD_NAME}" 1>&2 exit 1 fi echo "Configuring for ${BOARD_NAME} board..." /* Create link to architecture specific headers */ if [ "$SRCTREE" != "$OBJTREE" ] ; then /* 在指定的${OBJTREE}目录下编译,可以保持源代码目录的干净,不执行该分支 */ mkdir -p ${OBJTREE}/include mkdir -p ${OBJTREE}/include2 cd ${OBJTREE}/include2 rm -f asm ln -s ${SRCTREE}/arch/$2/include/asm asm LNPREFIX=${SRCTREE}/arch/$2/include/asm/ cd ../include rm -f asm ln -s ${SRCTREE}/arch/$2/include/asm asm else cd ./include /* -f: 删除是不显示提示信息,对于不存在的文件,会忽略掉 * asm: 上次配置过程中建立的连接文件 */ rm -f asm /* -s: make symbolic links instead of hard links * asm -> /arch/arm/include/asm */ ln -s ../arch/$2/include/asm asm fi /* 即/arch/$2/include/asm/arch,为上次执行make smdk2410_config产生的连接文件,arch->arch/$2/include/asm/arch-s3c24x0 */ rm -f asm/arch /* -z STRING: 判断字符串STRING是否为0,若STRING为空字符串,则为true * -o: or或的意思 */ if [ -z "$6" -o "$6" = "NULL" ] ; then ln -s ${LNPREFIX}arch-$3 asm/arch else /* arch->arch/arm/include/asm/arch-s3c24x0 */ ln -s ${LNPREFIX}arch-$6 asm/arch fi if [ "$2" = "arm" ] ; then /* proc->arch/arm/include/asm/proc-armv */ rm -f asm/proc ln -s ${LNPREFIX}proc-armv asm/proc fi /* Create include file for Make * >: 定向输出到文件,若文件不存在创建空文件 * >>: 追加内容到指定的文件末尾 */ echo "ARCH = $2" > config.mk echo "CPU = $3" >> config.mk echo "BOARD = $4" >> config.mk [ "$5" ] && [ "$5" != "NULL" ] && echo "VENDOR = $5" >> config.mk [ "$6" ] && [ "$6" != "NULL" ] && echo "SOC = $6" >> config.mk /* Assign board directory to BOARDIR variable */ if [ -z "$5" -o "$5" = "NULL" ] ; then BOARDDIR=$4 else /* BOARDDIR = samsung/smdk2410 */ BOARDDIR=$5/$4 fi /* 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 for i in ${TARGETS} ; do echo "#define CONFIG_MK_${i} 1" >>config.h ; done cat << EOF >> config.h #define CONFIG_BOARDDIR board/$BOARDDIR #include <config_defaults.h> #include <configs/$1.h> #include <asm/config.h> EOF /* ./include/config.h文件内容 */ /* Automatically generated - do not edit */ #define CONFIG_BOARDDIR board/samsung/smdk2410 #include <config_defaults.h> #include <configs/smdk2410.h> #include <asm/config.h> exit 0
./include/config.mk文件内容:
注:此处hao2440为smdk2410
u-boot的Makefile分析之mkconfig
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。