1#! /bin/sh
2
3# Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc.
4# This file is part of GCC.
5
6# GCC is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2, or (at your option)
9# any later version.
10
11# GCC is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15
16# You should have received a copy of the GNU General Public License
17# along with GCC; see the file COPYING.  If not, write to
18# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
19# Boston MA 02110-1301, USA.
20
21
22# Generate gcc's various configuration headers:
23# config.h, tconfig.h, bconfig.h, tm.h, and tm_p.h.
24# $1 is the file to generate.  DEFINES, HEADERS, and possibly
25# TARGET_CPU_DEFAULT are expected to be set in the environment.
26
27if [ -z "$1" ]; then
28    echo "Usage: DEFINES='list' HEADERS='list' \\" >&2
29    echo "  [TARGET_CPU_DEFAULT='default'] mkconfig.sh FILE" >&2
30    exit 1
31fi
32
33output=$1
34rm -f ${output}T
35
36# This converts a file name into header guard macro format.
37hg_sed_expr='y,abcdefghijklmnopqrstuvwxyz./,ABCDEFGHIJKLMNOPQRSTUVWXYZ__,'
38header_guard=GCC_`echo ${output} | sed -e ${hg_sed_expr}`
39
40# Add multiple inclusion protection guard, part one.
41echo "#ifndef ${header_guard}" >> ${output}T
42echo "#define ${header_guard}" >> ${output}T
43
44# A special test to ensure that build-time files don't blindly use
45# config.h.
46if test x"$output" = x"config.h"; then
47  echo "#ifdef GENERATOR_FILE" >> ${output}T
48  echo "#error config.h is for the host, not build, machine." >> ${output}T
49  echo "#endif" >> ${output}T
50fi
51
52# Define TARGET_CPU_DEFAULT if the system wants one.
53# This substitutes for lots of *.h files.
54if [ "$TARGET_CPU_DEFAULT" != "" ]; then
55    echo "#define TARGET_CPU_DEFAULT ($TARGET_CPU_DEFAULT)" >> ${output}T
56fi
57
58# Provide defines for other macros set in config.gcc for this file.
59for def in $DEFINES; do
60    echo "#ifndef $def" | sed 's/=.*//' >> ${output}T
61    echo "# define $def" | sed 's/=/ /' >> ${output}T
62    echo "#endif" >> ${output}T
63done
64
65# The first entry in HEADERS may be auto-FOO.h ;
66# it wants to be included even when not -DIN_GCC.
67if [ -n "$HEADERS" ]; then
68    set $HEADERS
69    case "$1" in auto-* )
70	echo "#include \"$1\"" >> ${output}T
71	shift
72	;;
73    esac
74    if [ $# -ge 1 ]; then
75	echo '#ifdef IN_GCC' >> ${output}T
76	for file in "$@"; do
77	    echo "# include \"$file\"" >> ${output}T
78	done
79	echo '#endif' >> ${output}T
80    fi
81fi
82
83# If this is tm.h, now include insn-constants.h and insn-flags.h only
84# if IN_GCC is defined but neither GENERATOR_FILE nor USED_FOR_TARGET
85# is defined.  (Much of this is temporary.)
86
87case $output in
88    tm.h )
89        cat >> ${output}T <<EOF
90#if defined IN_GCC && !defined GENERATOR_FILE && !defined USED_FOR_TARGET
91# include "insn-constants.h"
92# include "insn-flags.h"
93#endif
94EOF
95    ;;
96esac
97
98# Add multiple inclusion protection guard, part two.
99echo "#endif /* ${header_guard} */" >> ${output}T
100
101# Avoid changing the actual file if possible.
102if [ -f $output ] && cmp ${output}T $output >/dev/null 2>&1; then
103    echo $output is unchanged >&2
104    rm -f ${output}T
105else
106    mv -f ${output}T $output
107fi
108
109# Touch a stamp file for Make's benefit.
110rm -f cs-$output
111echo timestamp > cs-$output
112