#!/bin/sh
#
# Installs optional Xcode helper components for crossclang
#

cd "$(dirname $0)"
pwd=$(pwd)

toolchainsPath="$HOME/Library/Developer/Toolchains"
echo "Toolchains path: $toolchainsPath"
if [[ ! -d "$toolchainsPath" ]]; then
    mkdir -pv "$toolchainsPath"
fi

for toolchain in $(ls -1 | grep '\.xctoolchain$'); do
    echo Installing "$toolchain" ... 
    ( cd "$toolchainsPath" ; ln -sf "$pwd/$toolchain" )
done
echo

if [ $? -eq 0 ]; then
    echo "Done. Now please restart XCode, set the Toolchain (Xcode->Toolchains..., or via the launch window) to \"crossclang\", then run \"Clean Build Folder\"."
else
    echo "There were errors." >&2
fi
