#! /bin/bash

# Translated from the Haskell version at
# https://github.com/ghc-ios/ghc-ios-scripts/blob/master/clang-xcode5-wrapper.hs
# to bash by Thomas Hallgren
#
# For usage, see http://justtesting.org/post/64947952690/the-glasgow-haskell-compiler-ghc-on-os-x-10-9

E=""
undef=""
traditional=""

orig=( "$@" )
fixed=( )

while [ $# -gt 0 ] ; do
    a="$1"
    case "$a" in
	-E) E=y ;;
	-undef) undef=y ;;
	-traditional) traditional=y ;;
	-x)
	    case "$2" in
		c)
		    fixed=( "${fixed[@]}" "$a" )
		    shift
		    a="assembler-with-cpp"
	    esac
    esac
    fixed=( "${fixed[@]}" "$a" )
    shift
done

[ "$E$undef$traditional" = "yyy" ] || fixed=( "${orig[@]}" )

# Always add these flags?
flags="-Wno-invalid-pp-token -Wno-unicode -Wno-trigraphs"

exec /usr/bin/clang $flags "${fixed[@]}"
