#!/bin/sh

[ "$1" = --version ] && exec /usr/bin/x86_64-linux-gnu-g++-4.6 --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/bin/x86_64-linux-gnu-g++-4.6 $flags "$@" - -o -
		;;
	"")
		exec /usr/bin/x86_64-linux-gnu-g++-4.6 $flags "$@" - -o /dev/stdout
		;;
	c)
		output_file="`mktemp -t gcc.XXXXXXXX.o`" || exit
		/usr/bin/x86_64-linux-gnu-g++-4.6 -c $flags "$@" - -o "$output_file"
		r=$?
		if [ $r = 0 ]; then
			cat "$output_file" || r=1
		fi
		rm -f "$output_file"
		exit $r
		;;
esac
