#!/bin/sh

SUNC_PREFIX="/media/f01a9cd1-2570-4619-b4cd-41a27bdcfbd3/Program Files/sunstudio12/prod"

if [ "$1" = --version ]; then
	"$SUNC_PREFIX/bin/f90" -V 2>&1
	exit 0
fi

flags=-m32
[ -n "$ONLY_STAGE" ] && flags="$flags -$ONLY_STAGE"
[ -n "$OPTIMIZATION" ] && flags="$flags -xO$OPTIMIZATION"
[ -n "$DEBUG" ] && flags="$flags -g"
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"
# sunf90(1) requires working directory being writable
[ -n "$TMPDIR" ] && cd "$TMPDIR" || cd /tmp || exit
# The source file suffix will determine the source layout to be free form
# It may be overrideen by using option '-fixed'
input_file="`mktemp -t sunf90.XXXXXXXX.f95`" || exit
trap 'rm -f "$input_file"' EXIT
cat > "$input_file" || exit
case "$ONLY_STAGE" in
	E|S)
		output_file=/dev/stdout
		;;
	*)
		output_file="`mktemp -t sunf90.XXXXXXXX`" || exit
		trap 'rm -f "$input_file" "$output_file"' EXIT
		;;
esac
"$SUNC_PREFIX/bin/f90" $flags "$@" "$input_file" -o "$output_file"
r=$?
rm -f "$input_file"
[ $r = 0 ] && [ "$output_file" != /dev/stdout ] && [ -f "$output_file" ] && cat "$output_file"
exit $r
