#!/bin/sh
#
# Synthesize limits.h to be installed in the the system.  It is
# basically glimits.h with some additional stuff in front.
#
# This script is only called from the top-level GNUmakefile.  It
# is called as follows:
#
# synthesize_limits $(SRCROOT) file
#
# i.e., it will add some stuff to $(SRCROOT)/gcc/glimits.h and
# output the header into the file.
#
cat <<EOF >"$2"
/* limits.h */
#ifndef _LIMITS_H___
#define _LIMITS_H___

/* APPLE LOCAL begin MW compatibility */
/* Define the maximum values of built-in integral types, if needed.  */
#ifdef __MWERKS__
#ifndef __CHAR_BIT__ 
#define __CHAR_BIT__ 8
#endif
#ifndef __SCHAR_MAX__ 
#define __SCHAR_MAX__ 127
#endif
#ifndef __SHRT_MAX__ 
#define __SHRT_MAX__ 32767
#endif
#ifndef __INT_MAX__ 
#define __INT_MAX__ 2147483647
#endif
#ifndef __LONG_MAX__
#define __LONG_MAX__ 2147483647L
#endif
#ifndef __LONG_LONG_MAX__
#define __LONG_LONG_MAX__ 9223372036854775807LL
#endif
#endif /* __MWERKS__ */
/* APPLE LOCAl end MW compatibility */

#if defined (__ppc__)
#include <ppc/limits.h>
#elif defined (__i386__)
#include <i386/limits.h>
#else
#error architecture not supported
#endif

#undef MB_LEN_MAX
#define MB_LEN_MAX 6

EOF

cat "$1"/gcc/glimits.h | grep -v _LIMITS_H___  >>"$2"

cat <<EOF >>"$2"
#endif /* _LIMITS_H___ */
EOF
