mkconfig.sh revision 90075
1212793Sdim#! /bin/sh
2212793Sdim
3212793Sdim# Generate gcc's config.h, which is not your normal autoconf-generated
4212793Sdim# config.h (that's auto-(host|build).h).  $1 is the file to generate.
5212793Sdim# HEADERS, DEFINES, and possibly TARGET_CPU_DEFAULT are expected to be
6212793Sdim# set in the environment.
7212793Sdim
8212793Sdimif [ -z "$1" ]; then
9212793Sdim    echo "Usage: HEADERS='list' DEFINES='list' mkconfig.sh FILE" >&2
10212793Sdim    exit 1
11212793Sdimfi
12212793Sdim
13212793Sdimoutput=$1
14212793Sdimrm -f $output.T
15218893Sdim
16212793Sdim# We used to exec > $output.T but apparently this has bugs.
17212793Sdim# Use a redirected subshell instead.
18221345Sdim(
19212793Sdim
20234353Sdim# Define TARGET_CPU_DEFAULT if the system wants one.
21218893Sdim# This substitutes for lots of *.h files.
22212793Sdimif [ "$TARGET_CPU_DEFAULT" != "" ]; then
23226633Sdim    echo "#define TARGET_CPU_DEFAULT ($TARGET_CPU_DEFAULT)"
24212793Sdimfi
25212793Sdim
26212793Sdim# The first entry in HEADERS may be auto-host.h or auto-build.h;
27212793Sdim# it wants to be included even when not -DIN_GCC.
28212793Sdimif [ -n "$HEADERS" ]; then
29212793Sdim    set $HEADERS; first=$1
30212793Sdim    case $first in auto-* )
31212793Sdim	echo "#include \"$first\""
32221345Sdim	shift
33221345Sdim	HEADERS=$*
34223017Sdim	;;
35223017Sdim    esac
36223017Sdimfi
37212793Sdim
38212793Sdim# Provide three core typedefs used by everything, if we are compiling
39212793Sdim# GCC.  These used to be found in rtl.h and tree.h, but this is no
40212793Sdim# longer practical. Providing these in config.h/tconfig.h/hconfig.h
41212793Sdim# rather than system.h allows the typedefs to be used anywhere in GCC.
42218893Sdimcase $output in 
43212793Sdim    *config.h | *hconfig.h | *tconfig.h)
44212793Sdim        echo "#ifdef IN_GCC"
45218893Sdim        echo "/* Provide three core typedefs used by everything, if we are compiling"
46218893Sdim        echo "   GCC.  These used to be found in rtl.h and tree.h, but this is no"
47218893Sdim        echo "   longer practical.  Providing these here rather that system.h allows"
48218893Sdim        echo "   the typedefs to be used everywhere within GCC. */"
49218893Sdim        echo "struct rtx_def;"
50221345Sdim        echo "typedef struct rtx_def *rtx;"
51221345Sdim        echo "struct rtvec_def;"
52212793Sdim        echo "typedef struct rtvec_def *rtvec;"
53212793Sdim        echo "union tree_node;"
54218893Sdim        echo "typedef union tree_node *tree;"
55221345Sdim        echo "#endif"
56221345Sdim        ;;
57218893Sdimesac
58223017Sdim
59212793Sdimif [ -n "$HEADERS" ]; then
60212793Sdim    echo '#ifdef IN_GCC'
61221345Sdim    for file in $HEADERS; do
62221345Sdim	echo "# include \"$file\""
63221345Sdim    done
64221345Sdim    echo '#endif'
65234353Sdimfi
66221345Sdim
67221345Sdimfor def in $DEFINES; do
68221345Sdim    echo "#ifndef $def" | sed 's/=.*//'
69221345Sdim    echo "# define $def" | sed 's/=/ /'
70221345Sdim    echo "#endif"
71221345Sdimdone
72234353Sdim
73221345Sdim# If this is tm_p.h, include tm-preds.h unconditionally.
74221345Sdim# If this is tconfig.h or hconfig.h, include no more files.
75221345Sdim# Otherwise, include insn-constants.h and insn-flags.h,
76221345Sdim# but only if GENERATOR_FILE is not defined.
77221345Sdimcase $output in
78221345Sdim    *tm_p.h)
79221345Sdim	echo "#include \"tm-preds.h\""
80221345Sdim    ;;
81224145Sdim    *tconfig.h | *hconfig.h)
82224145Sdim    ;;
83224145Sdim    *)
84234353Sdim	echo "#ifndef GENERATOR_FILE"
85221345Sdim	echo "# include \"insn-constants.h\""
86221345Sdim	echo "# include \"insn-flags.h\""
87221345Sdim	echo "#endif"
88224145Sdim    ;;
89221345Sdimesac
90221345Sdim
91221345Sdim# Prevent obstack.c from thinking it can do i18n of its error message
92221345Sdim# when it's being linked against a build-side program.
93234353Sdimecho '#ifdef GENERATOR_FILE'
94221345Sdimecho '# undef ENABLE_NLS'
95234353Sdimecho '#endif'
96234353Sdim
97234353Sdim) > $output.T
98234353Sdim
99234353Sdim# Avoid changing the actual file if possible.
100234353Sdimif [ -f $output ] && cmp $output.T $output >/dev/null 2>&1; then
101234353Sdim    echo $output is unchanged >&2
102234353Sdim    rm -f $output.T
103234353Sdimelse
104234353Sdim    mv -f $output.T $output
105234353Sdimfi
106234353Sdim
107234353Sdim# Touch a stamp file for Make's benefit.
108234353Sdimrm -f cs-$output
109234353Sdimecho timestamp > cs-$output
110234353Sdim