#!/bin/sh

# edit: your c & c++ compilers (no path)
COMPILERS="gcc g++"

# edit: ccache masquerade directory
MASQUERADE_DIRECTORY=/usr/lib/ccache/bin

# edit: ccache path
CCACHE=../../../bin/ccache

# no need to edit past this point

if [ ! -d $MASQUERADE_DIRECTORY ]; then
  mkdir -p $MASQUERADE_DIRECTORY
else
  echo "the masquerade directory \"$MASQUERADE_DIRECTORY\" already exists."
  echo "remove or rename it, then run this script again."
  exit 1
fi

# simplest way to weed out bogus entries from above
COMPILERS=`which $COMPILERS 2> /dev/null`

LINKS=""
for COMPILER in $COMPILERS ; do
  COMPILER_DIRECTORY=`dirname $COMPILER`
  COMPILER_FILE=`basename $COMPILER`
  INODE=`find $COMPILER_DIRECTORY -name $COMPILER_FILE -follow -printf %i 2> /dev/null`
  LINKS=$LINKS`find $COMPILER_DIRECTORY -inum $INODE -follow -printf "%f " 2> /dev/null`
done

for LINK in $LINKS ; do
  echo $LINK
  ln -s $CCACHE $MASQUERADE_DIRECTORY/$LINK
done
