#!/usr/bin/env sh

echo "$@" >> /tmp/xcodebuild-$$.log

# We could not care less, luckily this always comes first
if [[ ${1} == --sdk || ${1} == -sdk ]]; then
  shift;
  shift;
elif [[ ${1} == -version ]]; then
  # If Qt uses this to determine C++ features then we need to
  # pretend to be a very recent Xcode.
  echo "Xcode 8.3.3" >> /tmp/xcodebuild-$$.log
  echo "Build version 8E3004b" >> /tmp/xcodebuild-$$.log
  echo "Xcode 8.3.3"
  echo "Build version 8E3004b"
  exit 0
fi

case ${1} in

  -version)
    shift
    if [[ ${1} == Path ]]; then
      if [[ -n ${CONDA_BUILD_SYSROOT} ]]; then
        echo ${CONDA_BUILD_SYSROOT} >> /tmp/xcodebuild-$$.log
        echo ${CONDA_BUILD_SYSROOT}
        exit 0
      fi
      echo "TODO :: Implement fallback for xcodebuild --show-sdk-path" >> /tmp/xcodebuild-$$.log
      echo "TODO :: Implement fallback for xcodebuild --show-sdk-path"
      exit 1
    elif [[ ${1} == SDKVersion ]]; then
      echo "10.9" >> /tmp/xcodebuild-$$.log
      echo "10.9"
      exit 0
    elif [[ ${1} == PlatformPath ]]; then
      echo "Making this one up entirely, you may need a real Xcode" >> /tmp/xcodebuild-$$.log
      echo "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/" >> /tmp/xcodebuild-$$.log
      echo "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/"
      exit 0
    fi
    ;;

  *)
    echo "ERROR :: Unimplemented xcodebuild mode ${1}" >> /tmp/xcodebuild-$$.log
    echo "ERROR :: Unimplemented xcodebuild mode ${1}"
    exit 1
    ;;

esac
