#!/bin/sh

[ "$1" = --version ] && exec /usr/bin/powerpc-linux-gnu-gcc-4.9 --version

flags="-Wall -fno-common -fno-diagnostics-show-caret -mregnames --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/bin/powerpc-linux-gnu-gcc-4.9 -$ONLY_STAGE $flags "$@" - -o -
		;;
	"")
		exec /usr/bin/powerpc-linux-gnu-gcc-4.9 $flags "$@" - -o /dev/stdout
		;;
	c)
		output_file="`mktemp -t gcc.XXXXXXXX.o`" || exit
		/usr/bin/powerpc-linux-gnu-gcc-4.9 -c $flags "$@" - -o "$output_file"
		r=$?
		if [ $r = 0 ]; then
			cat "$output_file" || r=1
		fi
		rm -f "$output_file"
		exit $r
		;;
esac
