#!/bin/sh
#
# This is a wrapper to use 'unproto' together with the MWC C compiler
# distributed with Coherent 4.x. Unfortunately the design of this
# compiler doesn't allow to substitute the cpp pass with an alternate
# one, which makes this hack here necessary :(
#
# Copyright (C) 1995 Udo Munk (udo@umunk.GUN.de)

USAGE="usage: ansicc [usual C compiler options] source"
COPTIONS=""
POPTIONS=""

tempfile=unp$$

set -- `getopt I:D:U:OgcfaKpQVo:L:l:T: $* 2>/dev/null`
if [ $? != 0 ]
then
  echo $USAGE
  exit 1
fi

for i in $*
do
  case $i in
    -I) POPTIONS=$POPTIONS"-I"$2" "; shift 2;;
    -D) POPTIONS=$POPTIONS"-D"$2" "; shift 2;;
    -U) POPTIONS=$POPTIONS"-U"$2" "; shift 2;;
    -O) COPTIONS=$COPTIONS"-O "; shift;;
    -g) COPTIONS=$COPTIONS"-g "; shift;;
    -c) COPTIONS=$COPTIONS"-c "; shift;;
    -f) COPTIONS=$COPTIONS"-f "; shift;;
    -a) COPTIONS=$COPTIONS"-a "; shift;;
    -K) COPTIONS=$COPTIONS"-K "; shift;;
    -p) COPTIONS=$COPTIONS"-p "; shift;;
    -Q) COPTIONS=$COPTIONS"-Q "; shift;;
    -V) COPTIONS=$COPTIONS"-V "; shift;;
    -o) COPTIONS=$COPTIONS"-o "$2" "; shift 2;;
    -L) COPTIONS=$COPTIONS"-L"$2" "; shift 2;;
    -l) COPTIONS=$COPTIONS"-l"$2" "; shift 2;;
    -T) COPTIONS=$COPTIONS"-T"$2" "; shift 2;;
    --) shift; break;;
    -*) echo $USAGE; exit 1;;
  esac
done

if [ $# -lt 1 ]
then
  echo "no source file given"
  exit 1
fi

case $1 in
  *.c)
	/usr/local/bin/unproto $POPTIONS $1 >/tmp/$tempfile.c
	/bin/cc $COPTIONS /tmp/$tempfile.c
	if [ -f $tempfile.o ]
	then
	  /bin/mv $tempfile.o `basename $1 .c`.o
	fi
	/bin/rm -f /tmp/$tempfile.c
	;;
  *.o | *.s | *.a)
	/bin/cc $POTIONS $COPTIONS $*
	;;
  *)
	echo "source file with unkown extension, don't know how to handle it"
	exit 1
	;;
esac

exit 0
