#!/bin/sh -

cc='cc -DNO_SC'
cconfig="${CCONFIG-$HOME/libp/cconfig.c}"

# cconfig - list the configuration for the given C compiler command
# Steve Kinzler, steve@kinzler.com, Mar 94
# https://kinzler.com/me/home.html#unix

opts=; bad=

while :
do
	case $# in
	0)	break;;
	*)	case "$1" in
		-e)	;;
		-[flv])	opts="$opts $1";;

		--)	shift; break;;
		-h)	bad=t; break;;
		-*)	bad=t; echo "$0: unknown option ($1)" 1>&2;;
		*)	break;;
		esac
		shift;;
	esac
done

case "$bad" in
?*)	cat << EOF 1>&2
usage: $0 [ -e | -f | -l ] [ -v ] [ compiler ]
	-e	output English text (default)
	-f	output float.h file
	-l	output limits.h file
	-v	output .h file with verbose comments
Exit status is the number of problems encountered.
The default compiler is "$cc".  Compiler options are allowed.
See $cconfig for compiler options that may need
to be specified and for further information.
EOF
	exit 1;;
esac

tmp=/tmp/cconf$$
status=1
trap 'cd /tmp; rm -fr $tmp; exit $status' 0 1 2 13 15

mkdir $tmp
cd $tmp || exit $?

host=${HOST-${HOSTNAME-`(hostname) 2> /dev/null`}}
case "$host" in
'')	host=`uname -n`;;
esac
case "$host" in
'')	host=UNKNOWN_HOST;;
esac

case $# in
0)	set x $cc; shift;;
esac

"$@" -DID=\""$host"\" -o cconfig $cconfig
./cconfig $opts
status=$?
