1#! /bin/sh
2
3# Generate gcc's config.h, which is not your normal autoconf-generated
4# config.h (that's auto-(host|build).h).  $1 is the file to generate.
5# TM_DEFINES, HEADERS, XM_DEFINES, and possibly TARGET_CPU_DEFAULT are
6# expected to be set in the environment.
7
8if [ -z "$1" ]; then
9    echo "Usage: TM_DEFINES='list' HEADERS='list' XM_DEFINES='list' mkconfig.sh FILE" >&2
10    exit 1
11fi
12
13output=$1
14rm -f ${output}T
15
16# Define TARGET_CPU_DEFAULT if the system wants one.
17# This substitutes for lots of *.h files.
18if [ "$TARGET_CPU_DEFAULT" != "" ]; then
19    echo "#define TARGET_CPU_DEFAULT ($TARGET_CPU_DEFAULT)" >> ${output}T
20fi
21
22# Provide defines for other target machine macros to be used everywhere.
23for def in $TM_DEFINES; do
24    echo "#ifndef $def" | sed 's/=.*//' >> ${output}T
25    echo "# define $def" | sed 's/=/ /' >> ${output}T
26    echo "#endif" >> ${output}T
27done
28
29# The first entry in HEADERS may be auto-host.h or auto-build.h;
30# it wants to be included even when not -DIN_GCC.
31if [ -n "$HEADERS" ]; then
32    set $HEADERS; first=$1
33    case $first in auto-* )
34	echo "#include \"$first\"" >> ${output}T
35	shift
36	HEADERS=$*
37	;;
38    esac
39fi
40
41# Provide three core typedefs used by everything, if we are compiling
42# GCC.  These used to be found in rtl.h and tree.h, but this is no
43# longer practical. Providing these in config.h/tconfig.h/hconfig.h
44# rather than system.h allows the typedefs to be used anywhere in GCC.
45case $output in
46    *config.h | *hconfig.h | *tconfig.h)
47        cat >> ${output}T <<EOF
48#ifdef IN_GCC
49/* Provide three core typedefs used by everything, if we are compiling
50   GCC.  These used to be found in rtl.h and tree.h, but this is no
51   longer practical.  Providing these here rather that system.h allows
52   the typedefs to be used everywhere within GCC. */
53struct rtx_def;
54typedef struct rtx_def *rtx;
55struct rtvec_def;
56typedef struct rtvec_def *rtvec;
57union tree_node;
58typedef union tree_node *tree;
59#endif
60#define GTY(x)
61EOF
62        ;;
63esac
64
65if [ -n "$HEADERS" ]; then
66    echo '#ifdef IN_GCC' >> ${output}T
67    for file in $HEADERS; do
68	echo "# include \"$file\"" >> ${output}T
69    done
70    echo '#endif' >> ${output}T
71fi
72
73for def in $XM_DEFINES; do
74    echo "#ifndef $def" | sed 's/=.*//' >> ${output}T
75    echo "# define $def" | sed 's/=/ /' >> ${output}T
76    echo "#endif" >> ${output}T
77done
78
79# If this is tm_p.h, include tm-preds.h unconditionally.
80# If this is tconfig.h or hconfig.h, include no more files.
81# Otherwise, include insn-constants.h and insn-flags.h,
82# but only if GENERATOR_FILE is not defined.
83case $output in
84    *tm_p.h)
85	echo "#include \"tm-preds.h\"" >> ${output}T
86    ;;
87    *tconfig.h | *hconfig.h)
88    ;;
89    *)
90        cat >> ${output}T <<EOF
91#ifndef GENERATOR_FILE
92# include "insn-constants.h"
93# include "insn-flags.h"
94#endif
95EOF
96    ;;
97esac
98
99# Avoid changing the actual file if possible.
100if [ -f $output ] && cmp ${output}T $output >/dev/null 2>&1; then
101    echo $output is unchanged >&2
102    rm -f ${output}T
103else
104    mv -f ${output}T $output
105fi
106
107# Touch a stamp file for Make's benefit.
108rm -f cs-$output
109echo timestamp > cs-$output
110