190075Sobrien#! /bin/sh
290075Sobrien
3169689Skan# Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc.
4132718Skan# This file is part of GCC.
590075Sobrien
6132718Skan# GCC is free software; you can redistribute it and/or modify
7132718Skan# it under the terms of the GNU General Public License as published by
8132718Skan# the Free Software Foundation; either version 2, or (at your option)
9132718Skan# any later version.
10132718Skan
11132718Skan# GCC is distributed in the hope that it will be useful,
12132718Skan# but WITHOUT ANY WARRANTY; without even the implied warranty of
13132718Skan# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14132718Skan# GNU General Public License for more details.
15132718Skan
16132718Skan# You should have received a copy of the GNU General Public License
17132718Skan# along with GCC; see the file COPYING.  If not, write to
18169689Skan# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
19169689Skan# Boston MA 02110-1301, USA.
20132718Skan
21132718Skan
22132718Skan# Generate gcc's various configuration headers:
23132718Skan# config.h, tconfig.h, bconfig.h, tm.h, and tm_p.h.
24132718Skan# $1 is the file to generate.  DEFINES, HEADERS, and possibly
25132718Skan# TARGET_CPU_DEFAULT are expected to be set in the environment.
26132718Skan
2790075Sobrienif [ -z "$1" ]; then
28132718Skan    echo "Usage: DEFINES='list' HEADERS='list' \\" >&2
29132718Skan    echo "  [TARGET_CPU_DEFAULT='default'] mkconfig.sh FILE" >&2
3090075Sobrien    exit 1
3190075Sobrienfi
3290075Sobrien
3390075Sobrienoutput=$1
3496263Sobrienrm -f ${output}T
3590075Sobrien
36132718Skan# This converts a file name into header guard macro format.
37132718Skanhg_sed_expr='y,abcdefghijklmnopqrstuvwxyz./,ABCDEFGHIJKLMNOPQRSTUVWXYZ__,'
38132718Skanheader_guard=GCC_`echo ${output} | sed -e ${hg_sed_expr}`
39132718Skan
40132718Skan# Add multiple inclusion protection guard, part one.
41132718Skanecho "#ifndef ${header_guard}" >> ${output}T
42132718Skanecho "#define ${header_guard}" >> ${output}T
43132718Skan
44169689Skan# A special test to ensure that build-time files don't blindly use
45169689Skan# config.h.
46169689Skanif test x"$output" = x"config.h"; then
47169689Skan  echo "#ifdef GENERATOR_FILE" >> ${output}T
48169689Skan  echo "#error config.h is for the host, not build, machine." >> ${output}T
49169689Skan  echo "#endif" >> ${output}T
50169689Skanfi
51169689Skan
5290075Sobrien# Define TARGET_CPU_DEFAULT if the system wants one.
5390075Sobrien# This substitutes for lots of *.h files.
5490075Sobrienif [ "$TARGET_CPU_DEFAULT" != "" ]; then
5596263Sobrien    echo "#define TARGET_CPU_DEFAULT ($TARGET_CPU_DEFAULT)" >> ${output}T
5690075Sobrienfi
5790075Sobrien
58132718Skan# Provide defines for other macros set in config.gcc for this file.
59132718Skanfor def in $DEFINES; do
60117395Skan    echo "#ifndef $def" | sed 's/=.*//' >> ${output}T
61117395Skan    echo "# define $def" | sed 's/=/ /' >> ${output}T
62117395Skan    echo "#endif" >> ${output}T
63117395Skandone
64117395Skan
65169689Skan# The first entry in HEADERS may be auto-FOO.h ;
6690075Sobrien# it wants to be included even when not -DIN_GCC.
6790075Sobrienif [ -n "$HEADERS" ]; then
68132718Skan    set $HEADERS
69132718Skan    case "$1" in auto-* )
70132718Skan	echo "#include \"$1\"" >> ${output}T
7190075Sobrien	shift
7290075Sobrien	;;
7390075Sobrien    esac
74132718Skan    if [ $# -ge 1 ]; then
75132718Skan	echo '#ifdef IN_GCC' >> ${output}T
76132718Skan	for file in "$@"; do
77132718Skan	    echo "# include \"$file\"" >> ${output}T
78132718Skan	done
79132718Skan	echo '#endif' >> ${output}T
80132718Skan    fi
8190075Sobrienfi
8290075Sobrien
83169689Skan# If this is tm.h, now include insn-constants.h and insn-flags.h only
84169689Skan# if IN_GCC is defined but neither GENERATOR_FILE nor USED_FOR_TARGET
85169689Skan# is defined.  (Much of this is temporary.)
8690075Sobrien
8790075Sobriencase $output in
88132718Skan    tm.h )
8996263Sobrien        cat >> ${output}T <<EOF
90132718Skan#if defined IN_GCC && !defined GENERATOR_FILE && !defined USED_FOR_TARGET
9196263Sobrien# include "insn-constants.h"
9296263Sobrien# include "insn-flags.h"
9396263Sobrien#endif
9496263SobrienEOF
9590075Sobrien    ;;
9690075Sobrienesac
9790075Sobrien
98132718Skan# Add multiple inclusion protection guard, part two.
99132718Skanecho "#endif /* ${header_guard} */" >> ${output}T
100132718Skan
10190075Sobrien# Avoid changing the actual file if possible.
10296263Sobrienif [ -f $output ] && cmp ${output}T $output >/dev/null 2>&1; then
10390075Sobrien    echo $output is unchanged >&2
10496263Sobrien    rm -f ${output}T
10590075Sobrienelse
10696263Sobrien    mv -f ${output}T $output
10790075Sobrienfi
10890075Sobrien
10990075Sobrien# Touch a stamp file for Make's benefit.
11090075Sobrienrm -f cs-$output
11190075Sobrienecho timestamp > cs-$output
112