快乐虾
http://blog.csdn.net/lights_joy/
lights@hb165.com
本文适用于
gcc-
Blackfin系列DSP
Visual Studio 2005
欢迎转载,但请保留作者信息
在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__
参考资料
无心插柳-在vs2005中编译GCC4(
gcc交叉编译的实现(
在vs2005下编译gcc:工程文件(
从asm_out_file看gcc汇编代码的生成(
gcc4.1中的machine_mode(
gcc 4.3 configure脚本学习(1):前言(
gcc 4.3 configure脚本学习(2):Be Bourne compatible(
gcc 4.3 configure脚本学习(3):NLS nuisances(
bfin-gcc-4.3.1中config.h的生成(
bfin-xxx-gcc-4.3.1中config.status的生成及运行(1):输出注释(
bfin-xxx-gcc-4.3.1中config.status的生成及运行(2):Shell检测(
bfin-xxx-gcc-4.3.1中config.status的生成及运行(3):文件配置(
bfin-xxx-gcc-4.3.1中config.status的生成及运行(4):帮助信息输出(
bfin-xxx-gcc-4.3.1中config.status的生成及运行(5):参数判断(
bfin-xxx-gcc-4.3.1中config.status的生成及运行(6):子目录获取(
bfin-xxx-gcc-4.3.1中config.status的生成及运行(7):创建临时目录(
bfin-xxx-gcc-4.3.1中config.status的生成及运行(8):配置文件生成(
bfin-xxx-gcc-4.3.1中config.status的生成及运行(9):头文件生成(
bfin-xxx-gcc-4.3.1中auto-host.h的生成(
bfin-xxx-gcc中multilib.h的生成(
bfin-xxx-gcc中tm.h的生成(
bfin-xxx-gcc中options.h的生成(