bfin-xxx-gcc中tm.h的生成

本文详细解析了GCC中tm.h文件的生成过程,包括Makefile.in中的依赖定义、mkconfig.sh脚本的具体执行流程,以及最终tm.h文件的内容。

快乐虾

http://blog.youkuaiyun.com/lights_joy/

lights@hb165.com

   

本文适用于

gcc- 4.3.1

Blackfin系列DSP

Visual Studio 2005

   

欢迎转载,但请保留作者信息

 

 

 

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= 1

所以这段脚本将输出

#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__

 

 

 

 

 

 

 

参考资料

无心插柳-在vs2005中编译GCC4( 2008-1-13 )

gcc交叉编译的实现( 2008-1-25 )

vs2005下编译gcc:工程文件( 2008-1-30 )

asm_out_filegcc汇编代码的生成( 2008-1-30 )

gcc4.1中的machine_mode( 2008-2-1 )

gcc 4.3 configure脚本学习(1):前言( 2008-4-23 )

gcc 4.3 configure脚本学习(2):Be Bourne compatible( 2008-4-24 )

gcc 4.3 configure脚本学习(3):NLS nuisances( 2008-4-24 )

bfin-gcc-4.3.1config.h的生成( 2008-8-5 )

bfin-xxx-gcc-4.3.1config.status的生成及运行(1):输出注释( 2008-8-5 )

bfin-xxx-gcc-4.3.1config.status的生成及运行(2):Shell检测( 2008-8-5 )

bfin-xxx-gcc-4.3.1config.status的生成及运行(3):文件配置( 2008-8-6 )

bfin-xxx-gcc-4.3.1config.status的生成及运行(4):帮助信息输出( 2008-8-6 )

bfin-xxx-gcc-4.3.1config.status的生成及运行(5):参数判断( 2008-8-6 )

bfin-xxx-gcc-4.3.1config.status的生成及运行(6):子目录获取( 2008-8-6 )

bfin-xxx-gcc-4.3.1config.status的生成及运行(7):创建临时目录( 2008-8-6 )

bfin-xxx-gcc-4.3.1config.status的生成及运行(8):配置文件生成( 2008-8-6 )

bfin-xxx-gcc-4.3.1config.status的生成及运行(9):头文件生( 2008-8-6 )

bfin-xxx-gcc-4.3.1auto-host.h的生成( 2008-8-6 )

bfin-xxx-gccmultilib.h的生成( 2008-8-7 )

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

嵌云阁主

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值