#
# Make gcc-4.8 the default compiler
#	brew installs gcc-4.8, but does not create symlinks for it to be used
#	without the version number.
#	This script:
#		1. Generate symlinks for all gcc tools installed by brew
#		2. Make brew-installed software the first in path
#

BREW_CMD="brew"
BREW_BIN="$(brew --prefix)/bin"
LN_APPS="c++-4.8 cpp-4.8 g++-4.8 gcc-4.8 gcc-ar-4.8 gcc-nm-4.8 gcc-ranlib-4.8 gcov-4.8"
OLD_PWD=$(PWD)

#Make sure brew is installed
type -P $BREW_CMD &>/dev/null || { echo "$BREW_CMD is not installed."; exit 1; }

#Generate Symlinks 
cd $BREW_BIN
for app in $LN_APPS
do
	LN_NAME=$(echo $app | sed 's/\(.*\)-4.8/\1/')
	ln -s $app $LN_NAME
done

#Prepend brew's path to $PATH
echo '#Making brew apps the first in your path' >> ~/.bash_profile
echo 'PATH=$(brew --prefix)/bin:$PATH' >> ~/.bash_profile

cd $OLD_PWD