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

本文详细介绍如何使用GCC 4.3.1进行配置文件生成的过程,包括如何从config.in生成auto-host.h,解释了配置文件中#define语句的作用,并提供了详细的步骤说明。

 

 

快乐虾

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

lights@hb165.com

   

 

本文适用于

gcc- 4.3.1

Blackfin系列DSP

Visual Studio 2005

   

 

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

 

 

cat >>$CONFIG_STATUS <</_ACEOF

 #

# CONFIG_HEADER section.

#

 

# These sed commands are passed to sed as "A NAME B NAME C VALUE D", where

# NAME is the cpp macro being defined and VALUE is the value it is being given.

#

# ac_d sets the value in "#define NAME VALUE" lines.

ac_dA='s,^/([ ]*/)#/([ ]*define[    ][  ]*/)'

ac_dB='[ ].*$,/1#/2'

ac_dC=' '

ac_dD=',;t'

# ac_u turns "#undef NAME" without trailing blanks into "#define NAME VALUE".

ac_uA='s,^/([ ]*/)#/([ ]*/)undef/([ ][  ]*/)'

ac_uB='$,/1#/2define/3'

ac_uC=' '

ac_uD=',;t'

 

for ac_file in : $CONFIG_HEADERS; do test "x$ac_file" = x: && continue

  # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in".

  case $ac_file in

  - | *:- | *:-:* ) # input from stdin

     cat >$tmp/stdin

     ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'`

     ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;

  *:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'`

     ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;

  * )   ac_file_in=$ac_file.in ;;

  esac

 

  test x"$ac_file" != x- && { echo "$as_me:$LINENO: creating $ac_file" >&5

echo "$as_me: creating $ac_file" >&6;}

 

  # First look for the input files in the build tree, otherwise in the

  # src tree.

  ac_file_inputs=`IFS=:

    for f in $ac_file_in; do

      case $f in

      -) echo $tmp/stdin ;;

      [///$]*)

      # Absolute (can't be DOS-style, as IFS=:)

      test -f "$f" || { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5

echo "$as_me: error: cannot find input file: $f" >&2;}

   { (exit 1); exit 1; }; }

      # Do quote $f, to prevent DOS paths from being IFS'd.

      echo "$f";;

      *) # Relative

      if test -f "$f"; then

        # Build tree

        echo "$f"

      elif test -f "$srcdir/$f"; then

        # Source tree

        echo "$srcdir/$f"

      else

        # /dev/null tree

        { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5

echo "$as_me: error: cannot find input file: $f" >&2;}

   { (exit 1); exit 1; }; }

      fi;;

      esac

    done` || { (exit 1); exit 1; }

  # Remove the trailing spaces.

  sed 's/[    ]*$//' $ac_file_inputs >$tmp/in

 

_ACEOF

 

# Transform confdefs.h into two sed scripts, `conftest.defines' and

# `conftest.undefs', that substitutes the proper values into

# config.h.in to produce config.h.  The first handles `#define'

# templates, and the second `#undef' templates.

# And first: Protect against being on the right side of a sed subst in

# config.status.  Protect against being in an unquoted here document

# in config.status.

rm -f conftest.defines conftest.undefs

# Using a here document instead of a string reduces the quoting nightmare.

# Putting comments in sed scripts is not portable.

#

# `end' is used to avoid that the second main sed command (meant for

# 0-ary CPP macros) applies to n-ary macro definitions.

# See the Autoconf documentation for `clear'.

cat >confdef2sed.sed <</_ACEOF

s/[//&,]///&/g

s,[//$`],//&,g

t clear

: clear

s,^[ ]*#[    ]*define[    ][  ]*/([^  (][^    (]*/)/(([^)]*)/)[ ]*/(.*/)$,${ac_dA}/1${ac_dB}/1/2${ac_dC}/3${ac_dD},gp

t end

s,^[ ]*#[    ]*define[    ][  ]*/([^  ][^ ]*/)[   ]*/(.*/)$,${ac_dA}/1${ac_dB}/1${ac_dC}/2${ac_dD},gp

: end

_ACEOF

# If some macros were called several times there might be several times

# the same #defines, which is useless.  Nevertheless, we may not want to

# sort them, since we want the *last* AC-DEFINE to be honored.

uniq confdefs.h | sed -n -f confdef2sed.sed >conftest.defines

sed 's/ac_d/ac_u/g' conftest.defines >conftest.undefs

rm -f confdef2sed.sed

 

# This sed command replaces #undef with comments.  This is necessary, for

# example, in the case of _POSIX_SOURCE, which is predefined and required

# on some systems where configure will not decide to define it.

cat >>conftest.undefs <</_ACEOF

s,^[ ]*#[    ]*undef[ ][  ]*[a-zA-Z_][a-zA-Z_0-9]*,/* & */,

_ACEOF

 

# Break up conftest.defines because some shells have a limit on the size

# of here documents, and old seds have small limits too (100 cmds).

echo '  # Handle all the #define templates only if necessary.' >>$CONFIG_STATUS

echo '  if grep "^[    ]*#[    ]*define" $tmp/in >/dev/null; then' >>$CONFIG_STATUS

echo '  # If there are no defines, we may have an empty if/fi' >>$CONFIG_STATUS

echo '  :' >>$CONFIG_STATUS

rm -f conftest.tail

while grep . conftest.defines >/dev/null

do

  # Write a limited-size here document to $tmp/defines.sed.

  echo '  cat >$tmp/defines.sed <<CEOF' >>$CONFIG_STATUS

  # Speed up: don't consider the non `#define' lines.

  echo '/^[   ]*#[    ]*define/!b' >>$CONFIG_STATUS

  # Work around the forget-to-reset-the-flag bug.

  echo 't clr' >>$CONFIG_STATUS

  echo ': clr' >>$CONFIG_STATUS

  sed ${ac_max_here_lines}q conftest.defines >>$CONFIG_STATUS

  echo 'CEOF

  sed -f $tmp/defines.sed $tmp/in >$tmp/out

  rm -f $tmp/in

  mv $tmp/out $tmp/in

' >>$CONFIG_STATUS

  sed 1,${ac_max_here_lines}d conftest.defines >conftest.tail

  rm -f conftest.defines

  mv conftest.tail conftest.defines

done

rm -f conftest.defines

echo '  fi # grep' >>$CONFIG_STATUS

echo >>$CONFIG_STATUS

 

# Break up conftest.undefs because some shells have a limit on the size

# of here documents, and old seds have small limits too (100 cmds).

echo '  # Handle all the #undef templates' >>$CONFIG_STATUS

rm -f conftest.tail

while grep . conftest.undefs >/dev/null

do

  # Write a limited-size here document to $tmp/undefs.sed.

  echo '  cat >$tmp/undefs.sed <<CEOF' >>$CONFIG_STATUS

  # Speed up: don't consider the non `#undef'

  echo '/^[   ]*#[    ]*undef/!b' >>$CONFIG_STATUS

  # Work around the forget-to-reset-the-flag bug.

  echo 't clr' >>$CONFIG_STATUS

  echo ': clr' >>$CONFIG_STATUS

  sed ${ac_max_here_lines}q conftest.undefs >>$CONFIG_STATUS

  echo 'CEOF

  sed -f $tmp/undefs.sed $tmp/in >$tmp/out

  rm -f $tmp/in

  mv $tmp/out $tmp/in

' >>$CONFIG_STATUS

  sed 1,${ac_max_here_lines}d conftest.undefs >conftest.tail

  rm -f conftest.undefs

  mv conftest.tail conftest.undefs

done

rm -f conftest.undefs

 

cat >>$CONFIG_STATUS <</_ACEOF

  # Let's still pretend it is `configure' which instantiates (i.e., don't

  # use $as_me), people would be surprised to read:

  #    /* config.h.  Generated by config.status.  */

  if test x"$ac_file" = x-; then

    echo "/* Generated by configure.  */" >$tmp/config.h

  else

    echo "/* $ac_file.  Generated by configure.  */" >$tmp/config.h

  fi

  cat $tmp/in >>$tmp/config.h

  rm -f $tmp/in

  if test x"$ac_file" != x-; then

    if diff $ac_file $tmp/config.h >/dev/null 2>&1; then

      { echo "$as_me:$LINENO: $ac_file is unchanged" >&5

echo "$as_me: $ac_file is unchanged" >&6;}

    else

      ac_dir=`(dirname "$ac_file") 2>/dev/null ||

$as_expr X"$ac_file" : 'X/(.*[^/]/)//*[^/][^/]*/*$' /| /

      X"$ac_file" : 'X/(///)[^/]' /| /

      X"$ac_file" : 'X/(///)$' /| /

      X"$ac_file" : 'X/(//)' /| /

      .     : '/(./)' 2>/dev/null ||

echo X"$ac_file" |

    sed '/^X/(.*[^/]/)////*[^/][^/]*//*$/{ s///1/; q; }

       /^X/(/////)[^/].*/{ s///1/; q; }

       /^X/(/////)$/{ s///1/; q; }

       /^X/(///).*/{ s///1/; q; }

       s/.*/./; q'`

      { if $as_mkdir_p; then

    mkdir -p "$ac_dir"

  else

    as_dir="$ac_dir"

    as_dirs=

    while test ! -d "$as_dir"; do

      as_dirs="$as_dir $as_dirs"

      as_dir=`(dirname "$as_dir") 2>/dev/null ||

$as_expr X"$as_dir" : 'X/(.*[^/]/)//*[^/][^/]*/*$' /| /

      X"$as_dir" : 'X/(///)[^/]' /| /

      X"$as_dir" : 'X/(///)$' /| /

      X"$as_dir" : 'X/(//)' /| /

      .     : '/(./)' 2>/dev/null ||

echo X"$as_dir" |

    sed '/^X/(.*[^/]/)////*[^/][^/]*//*$/{ s///1/; q; }

       /^X/(/////)[^/].*/{ s///1/; q; }

       /^X/(/////)$/{ s///1/; q; }

       /^X/(///).*/{ s///1/; q; }

       s/.*/./; q'`

    done

    test ! -n "$as_dirs" || mkdir $as_dirs

  fi || { { echo "$as_me:$LINENO: error: cannot create directory /"$ac_dir/"" >&5

echo "$as_me: error: cannot create directory /"$ac_dir/"" >&2;}

   { (exit 1); exit 1; }; }; }

 

      rm -f $ac_file

      mv $tmp/config.h $ac_file

    fi

  else

    cat $tmp/config.h

    rm -f $tmp/config.h

  fi

done

_ACEOF

这段代码的实际作用是完成$CONFIG_HEADERS变量中定义的文件替换,在此这个变量的值为:

    $CONFIG_HEADERS =" auto-host.h:config.in"

因而这一段的代码将从config.in生成auto-host.h

config.in文件中,实际上是一堆的#define语句,它用以定义编译器的一些参数,而这些参数的检测是在configure脚本中完成的,实际上可以手工修改auto-host.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 )

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

嵌云阁主

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

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

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

打赏作者

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

抵扣说明:

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

余额充值