![]() |
|
||||||||||||||
| | 首页 | 新闻 | 文库 | 方案 | 技术 | 独家 | 座谈 | 下载 | 图库 | 开发板 | 仿真器 | 邮购 | VIP会员 | 芯片代购 | 客户评价 | | ||
|
||
|
|||||
| bfin-xxx-gcc中tm.h的生成 | |||||
作者:快乐虾 文章来源:http://blog.csdn.net/lights_joy 点击数: 更新时间:2008-8-20 ![]() |
|||||
|
在Makefile.in中有这样的语句: tm.h: cs-tm.h ; @true cs-tm.h: Makefile TARGET_CPU_DEFAULT="$(target_cpu_default)" \ HEADERS="$(tm_include_list)" DEFINES="$(tm_defines)" \ $(SHELL) $(srcdir)/mkconfig.sh tm.h 即tm.h的生成是通过mkconfig.sh tm.h这个命令来实现的。 下面对照mkconfig.sh的内容生成tm.h文件。 1.1.1.1 调用参数判断# Generate gcc's various configuration headers: # config.h, tconfig.h, bconfig.h, tm.h, and tm_p.h. # $1 is the file to generate. DEFINES, HEADERS, and possibly # TARGET_CPU_DEFAULT are expected to be set in the environment. if [ -z "$1" ]; then echo "Usage: DEFINES='list' HEADERS='list' \\" >&2 echo " [TARGET_CPU_DEFAULT='default'] mkconfig.sh FILE" >&2 exit 1 fi 判断是否带参数执行,从Makefile调用命令来看$1 = “tm.h”。 1.1.1.2 删除临时文件output=$1 rm -f ${output}T 删除输出的临时文件。 1.1.1.3 输出保护性语句
# This converts a file name into header guard macro format. hg_sed_expr='y,abcdefghijklmnopqrstuvwxyz./,ABCDEFGHIJKLMNOPQRSTUVWXYZ__,' header_guard=GCC_`echo ${output} | sed -e ${hg_sed_expr}` # Add multiple inclusion protection guard, part one. echo "#ifndef ${header_guard}" >> ${output}T echo "#define ${header_guard}" >> ${output}T 这几句话其实就是在头文件中输出 #ifndef xxx #define xxx 这样的保护性语句。 1.1.1.4 错误判断
# A special test to ensure that build-time files don't blindly use # config.h. if test x"$output" = x"config.h"; then echo "#ifdef GENERATOR_FILE" >> ${output}T echo "#error config.h is for the host, not build, machine." >> ${output}T echo "#endif" >> ${output}T fi 因为我们需要生成的是tm.h,这段话将略过。 1.1.1.5 定义TARGET_CPU_DEFAULT
# Define TARGET_CPU_DEFAULT if the system wants one. # This substitutes for lots of *.h files. if [ "$TARGET_CPU_DEFAULT" != "" ]; then echo "#define TARGET_CPU_DEFAULT ($TARGET_CPU_DEFAULT)" >> ${output}T fi 对于tm.h来讲,TARGET_CPU_DEFAULT为空字符串,这段将不执行。 1.1.1.6 输出宏定义
# Provide defines for other macros set in config.gcc for this file. for def in $DEFINES; do echo "#ifndef $def" | sed 's/=.*//' >> ${output}T echo "# define $def" | sed 's/=/ /' >> ${output}T echo "#endif" >> ${output}T done 这段话的输出取决于调用时的DEFINES定义,而这一变量在Makefile.in中定义为tm_defines,在Makefile.in中查找这个变量的定义: tm_defines=@tm_defines@ 说明这个值的定义应该是从configure中来的,在config.gcc中有这样的定义: bfin*-uclinux*) tm_file="${tm_file} dbxelf.h elfos.h bfin/elf.h linux.h bfin/uclinux.h" tmake_file=bfin/t-bfin-uclinux tm_defines="${tm_defines} UCLIBC_DEFAULT=1" extra_options="${extra_options} linux.opt" use_collect2=no ;; 因而最后$tm_defines这个变量的值将为”UCLIBC_DEFAULT= 所以这段脚本将输出 #ifndef UCLIBC_DEFAULT #define UCLIBC_DEFAULT 1 #endif 1.1.1.7 输出include
# The first entry in HEADERS may be auto-FOO.h ; # it wants to be included even when not -DIN_GCC. if [ -n "$HEADERS" ]; then set $HEADERS case "$1" in auto-* ) echo "#include \"$1\"" >> ${output}T shift ;; esac if [ $# -ge 1 ]; then echo '#ifdef IN_GCC' >> ${output}T for file in "$@"; do echo "# include \"$file\"" >> ${output}T done echo '#endif' >> ${output}T fi fi 这段话将根据HEADERS的定义生成一些include语句。查找tm_include_list,可以发现以下定义: tm_include_list="options.h" for f in $tm_file; do case $f in ./* ) f=`echo $f | sed 's/^..//'` tm_file_list="${tm_file_list} $f" tm_include_list="${tm_include_list} $f" ;; defaults.h ) tm_file_list="${tm_file_list} \$(srcdir)/$f" tm_include_list="${tm_include_list} $f" ;; * ) tm_file_list="${tm_file_list} \$(srcdir)/config/$f" tm_include_list="${tm_include_list} config/$f" ;; esac done 再查一下tm_file的定义,在config.gcc中: tm_file=${cpu_type}/${cpu_type}.h bfin*-uclinux*) tm_file="${tm_file} dbxelf.h elfos.h bfin/elf.h linux.h bfin/uclinux.h" tmake_file=bfin/t-bfin-uclinux tm_defines="${tm_defines} UCLIBC_DEFAULT=1" extra_options="${extra_options} linux.opt" use_collect2=no ;; 经过这段脚本,tm_file的值成为: “options.h bfin/bfin.h dbxelf.h elfos.h bfin/elf.h linux.h bfin/uclinux.h” 回到mkconfig.sh的代码中来,上述代码段将生成如下输出: #ifdef IN_GCC #include "config/options.h" #include "config/bfin/bfin.h" #include "config/elfos.h" #include "config/bfin/elf.h" #include "config/linux.h" #include "bfin/uclinux.h” #endif 1.1.1.8 对tm.h做特殊处理
# If this is tm.h, now include insn-constants.h and insn-flags.h only # if IN_GCC is defined but neither GENERATOR_FILE nor USED_FOR_TARGET # is defined. (Much of this is temporary.) case $output in tm.h ) cat >> ${output}T <<EOF #if defined IN_GCC && !defined GENERATOR_FILE && !defined USED_FOR_TARGET # include "insn-constants.h" # include "insn-flags.h" #endif EOF ;; esac 这几行代码将对tm.h输出一些特定的语句: #if defined IN_GCC && !defined GENERATOR_FILE && !defined USED_FOR_TARGET # include "insn-constants.h" # include "insn-flags.h" #endif 1.1.1.9 #endif
# Add multiple inclusion protection guard, part two. echo "#endif /* ${header_guard} */" >> ${output}T 输出头文件末尾的#endif,与文件开头中的#ifndef对应。 1.1.1.10 文件后继处理
# Avoid changing the actual file if possible. if [ -f $output ] && cmp ${output}T $output >/dev/null 2>&1; then echo $output is unchanged >&2 rm -f ${output}T else mv -f ${output}T $output fi # Touch a stamp file for Make's benefit. rm -f cs-$output echo timestamp > cs-$output 没什么,最后就是把临时文件复制为正式的tm.h。 1.1.1.11 最终版本最后生成的tm.h如下: #ifndef __GCC_TM_H__ #define __GCC_TM_H__ #ifdef BFIN_UCLINUX_GCC #ifndef UCLIBC_DEFAULT #define UCLIBC_DEFAULT 1 #endif #ifdef IN_GCC #include "config/options.h" #include "config/bfin/bfin.h" #include "config/elfos.h" #include "config/bfin/elf.h" #include "config/linux.h" #include "bfin/uclinux.h” #endif #if defined IN_GCC && !defined GENERATOR_FILE && !defined USED_FOR_TARGET # include "insn-constants.h" # include "insn-flags.h" #endif #endif // BFIN_UCLINUX_GCC #endif //__GCC_TM_H__ |
|||||
| 文章录入:admin 责任编辑:admin | |||||
| 【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 | |||||
| 最新热点 | 最新推荐 | 相关文章 | ||
| 前置放大器在移动医疗服务系 便携式多通道大容量生理信号 防腐监测仪的设计与应用 基于AD1674的酶标仪的设计 基于C/S模式的JRTPLIB库的测 ffmpeg与jrtplib相结合应用 blackfin模拟摄像头驱动中的 可编程逻辑在数字信号处理系 发现VDSP4.5一个BUG:单步调 VDSP5.0双核工程下sml3中的变 |
| 网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!) |
| | 本站介绍 | 合作联络 | 欢迎投稿 | 广告业务 | 网站地图 | 设为首页 | 加入收藏 | 友情链接 | 网站公告 | 联系我们 | | |||
|