mkconfig.sh revision 90075
190075Sobrien#! /bin/sh
290075Sobrien
390075Sobrien# Generate gcc's config.h, which is not your normal autoconf-generated
490075Sobrien# config.h (that's auto-(host|build).h).  $1 is the file to generate.
590075Sobrien# HEADERS, DEFINES, and possibly TARGET_CPU_DEFAULT are expected to be
690075Sobrien# set in the environment.
790075Sobrien
890075Sobrienif [ -z "$1" ]; then
990075Sobrien    echo "Usage: HEADERS='list' DEFINES='list' mkconfig.sh FILE" >&2
1090075Sobrien    exit 1
1190075Sobrienfi
1290075Sobrien
1390075Sobrienoutput=$1
1490075Sobrienrm -f $output.T
1590075Sobrien
1690075Sobrien# We used to exec > $output.T but apparently this has bugs.
1790075Sobrien# Use a redirected subshell instead.
1890075Sobrien(
1990075Sobrien
2090075Sobrien# Define TARGET_CPU_DEFAULT if the system wants one.
2190075Sobrien# This substitutes for lots of *.h files.
2290075Sobrienif [ "$TARGET_CPU_DEFAULT" != "" ]; then
2390075Sobrien    echo "#define TARGET_CPU_DEFAULT ($TARGET_CPU_DEFAULT)"
2490075Sobrienfi
2590075Sobrien
2690075Sobrien# The first entry in HEADERS may be auto-host.h or auto-build.h;
2790075Sobrien# it wants to be included even when not -DIN_GCC.
2890075Sobrienif [ -n "$HEADERS" ]; then
2990075Sobrien    set $HEADERS; first=$1
3090075Sobrien    case $first in auto-* )
3190075Sobrien	echo "#include \"$first\""
3290075Sobrien	shift
3390075Sobrien	HEADERS=$*
3490075Sobrien	;;
3590075Sobrien    esac
3690075Sobrienfi
3790075Sobrien
3890075Sobrien# Provide three core typedefs used by everything, if we are compiling
3990075Sobrien# GCC.  These used to be found in rtl.h and tree.h, but this is no
4090075Sobrien# longer practical. Providing these in config.h/tconfig.h/hconfig.h
4190075Sobrien# rather than system.h allows the typedefs to be used anywhere in GCC.
4290075Sobriencase $output in 
4390075Sobrien    *config.h | *hconfig.h | *tconfig.h)
4490075Sobrien        echo "#ifdef IN_GCC"
4590075Sobrien        echo "/* Provide three core typedefs used by everything, if we are compiling"
4690075Sobrien        echo "   GCC.  These used to be found in rtl.h and tree.h, but this is no"
4790075Sobrien        echo "   longer practical.  Providing these here rather that system.h allows"
4890075Sobrien        echo "   the typedefs to be used everywhere within GCC. */"
4990075Sobrien        echo "struct rtx_def;"
5090075Sobrien        echo "typedef struct rtx_def *rtx;"
5190075Sobrien        echo "struct rtvec_def;"
5290075Sobrien        echo "typedef struct rtvec_def *rtvec;"
5390075Sobrien        echo "union tree_node;"
5490075Sobrien        echo "typedef union tree_node *tree;"
5590075Sobrien        echo "#endif"
5690075Sobrien        ;;
5790075Sobrienesac
5890075Sobrien
5990075Sobrienif [ -n "$HEADERS" ]; then
6090075Sobrien    echo '#ifdef IN_GCC'
6190075Sobrien    for file in $HEADERS; do
6290075Sobrien	echo "# include \"$file\""
6390075Sobrien    done
6490075Sobrien    echo '#endif'
6590075Sobrienfi
6690075Sobrien
6790075Sobrienfor def in $DEFINES; do
6890075Sobrien    echo "#ifndef $def" | sed 's/=.*//'
6990075Sobrien    echo "# define $def" | sed 's/=/ /'
7090075Sobrien    echo "#endif"
7190075Sobriendone
7290075Sobrien
7390075Sobrien# If this is tm_p.h, include tm-preds.h unconditionally.
7490075Sobrien# If this is tconfig.h or hconfig.h, include no more files.
7590075Sobrien# Otherwise, include insn-constants.h and insn-flags.h,
7690075Sobrien# but only if GENERATOR_FILE is not defined.
7790075Sobriencase $output in
7890075Sobrien    *tm_p.h)
7990075Sobrien	echo "#include \"tm-preds.h\""
8090075Sobrien    ;;
8190075Sobrien    *tconfig.h | *hconfig.h)
8290075Sobrien    ;;
8390075Sobrien    *)
8490075Sobrien	echo "#ifndef GENERATOR_FILE"
8590075Sobrien	echo "# include \"insn-constants.h\""
8690075Sobrien	echo "# include \"insn-flags.h\""
8790075Sobrien	echo "#endif"
8890075Sobrien    ;;
8990075Sobrienesac
9090075Sobrien
9190075Sobrien# Prevent obstack.c from thinking it can do i18n of its error message
9290075Sobrien# when it's being linked against a build-side program.
9390075Sobrienecho '#ifdef GENERATOR_FILE'
9490075Sobrienecho '# undef ENABLE_NLS'
9590075Sobrienecho '#endif'
9690075Sobrien
9790075Sobrien) > $output.T
9890075Sobrien
9990075Sobrien# Avoid changing the actual file if possible.
10090075Sobrienif [ -f $output ] && cmp $output.T $output >/dev/null 2>&1; then
10190075Sobrien    echo $output is unchanged >&2
10290075Sobrien    rm -f $output.T
10390075Sobrienelse
10490075Sobrien    mv -f $output.T $output
10590075Sobrienfi
10690075Sobrien
10790075Sobrien# Touch a stamp file for Make's benefit.
10890075Sobrienrm -f cs-$output
10990075Sobrienecho timestamp > cs-$output
110