#!/bin/sh

[ "$1" = --version ] && exec /usr/local/bin/gcc --version

flags="-Wall --pipe -x c"
[ -n "$DEBUG" ] && flags="$flags -g"
[ -n "$OPTIMIZATION" ] && flags="$flags -O$OPTIMIZATION"
for d in $DEFINE; do flags="-D $d $flags"; done
for d in $UNDEFINE; do flags="-U $d $flags"; done
[ -n "$VERBOSE" ] && flags="$flags -v"
case "$ONLY_STAGE" in
	E|S)
		exec /usr/local/bin/gcc -$ONLY_STAGE $flags "$@" - -o -
		;;
	"")
		exec /usr/local/bin/gcc $flags "$@" - -o /dev/stdout
		;;
	c)
		output_file="`mktemp -t gcc.XXXXXXXX.o`" || exit
		/usr/local/bin/gcc -c $flags "$@" - -o "$output_file"
		r=$?
		if [ $r = 0 ]; then
			cat "$output_file" || r=1
		fi
		rm -f "$output_file"
		exit $r
		;;
esac
