![]() |
|
||||||||||||||
| | 首页 | 新闻 | 文库 | 方案 | 技术 | 独家 | 座谈 | 下载 | 图库 | 开发板 | 仿真器 | 邮购 | VIP会员 | 芯片代购 | 客户评价 | | ||
|
||
|
|||||
| bfin-xxx-gcc中bconfig.h的生成 | |||||
作者:快乐虾 文章来源:http://blog.csdn.net/lights_joy 点击数: 更新时间:2008-8-20 ![]() |
|||||
|
在Makefile.in中这样定义规则: bconfig.h: cs-bconfig.h ; @true cs-bconfig.h: Makefile TARGET_CPU_DEFAULT="" \ HEADERS="$(build_xm_include_list)" DEFINES="$(build_xm_defines)" \ $(SHELL) $(srcdir)/mkconfig.sh bconfig.h 即bconfig.h的生成是通过mkconfig.sh bconfig.h这个命令来实现的。 下面对照mkconfig.sh的内容生成bconfig.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 = “bconfig.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 我们需要生成bconfig.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 对于bconfig.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中定义为build_xm_defines,在Makefile.in中查找这个变量的定义: build_xm_defines=@build_xm_defines@ 说明这个值的定义应该是从configure中来的,在configure中查找可以发现这个值的定义为空,所以mkconfig.sh中的这段话将不产生输出。 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语句。查找build_xm_include_list,可以发现以下定义: build_xm_file_list= for f in $build_xm_file; do case $f in ansidecl.h ) build_xm_file_list="${build_xm_file_list} \$(srcdir)/../include/$f" build_xm_include_list="${build_xm_include_list} $f" ;; auto-build.h | auto-host.h ) build_xm_file_list="${build_xm_file_list} $f" build_xm_include_list="${build_xm_include_list} $f" ;; * ) build_xm_file_list="${build_xm_file_list} \$(srcdir)/config/$f" build_xm_include_list="${build_xm_include_list} config/$f" ;; esac done 再查一下build_xm_file的定义,在config.build中: i[34567]86-*-cygwin* | i[34567]86-*-pe ) build_xm_file=i386/xm-cygwin.h build_exeext=.exe ;; 因为我们选择vs2005做为host的编译器,因此在系统中并不直接支持,为此仿照configs/i386/xm-cygwin.h建立一个xm-vs2005.h文件,其内容与xm-cygwin.h相同。 在configure脚本中还有这样的语句: build_xm_file="${build_auto} ansidecl.h ${build_xm_file}" 这里build_auto的定义为: # auto-host.h is the file containing items generated by autoconf and is # the first file included by config.h. # If host=build, it is correct to have bconfig include auto-host.h # as well. If host!=build, we are in error and need to do more # work to find out the build config parameters. if test x$host = x$build then build_auto=auto-host.h else ………….. fi 所以最后build_xm_include_list就变成了 “auto-host.h ansidecl.h config/i386/xm-vs2005.h” 回到mkconfig.sh的代码中来,上述代码段将生成如下输出: #include "auto-host.h" #ifdef IN_GCC # include "../include/ansidecl.h" # include "config/i386/xm-vs2005.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输出一些特定的语句,但我们生成的是bconfig.h,故略过。 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 没什么,最后就是把临时文件复制为正式的bconfig.h。 1.1.1.11 最终版本最后生成的bconfig.h如下: #ifndef __GCC_BCONFIG_H__ #define __GCC_BCONFIG_H__ #include "auto-host.h" #ifdef IN_GCC # include "../include/ansidecl.h" # include "config/i386/xm-vs2005.h" #endif #endif //__GCC_BCONFIG_H__ |
|||||
| 文章录入:admin 责任编辑:admin | |||||
| 【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 | |||||
| 最新热点 | 最新推荐 | 相关文章 | ||
| 前置放大器在移动医疗服务系 便携式多通道大容量生理信号 防腐监测仪的设计与应用 基于AD1674的酶标仪的设计 基于C/S模式的JRTPLIB库的测 ffmpeg与jrtplib相结合应用 blackfin模拟摄像头驱动中的 可编程逻辑在数字信号处理系 发现VDSP4.5一个BUG:单步调 VDSP5.0双核工程下sml3中的变 |
| 网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!) |
| | 本站介绍 | 合作联络 | 欢迎投稿 | 广告业务 | 网站地图 | 设为首页 | 加入收藏 | 友情链接 | 网站公告 | 联系我们 | | |||
|