#!/bin/bash
#       GetClangVersion CC [-i]
#       Outputs string with version string (e.g.) and exit 0
#       If argument compiler NOT clang, outputs "" and exit non-zero
#       -i means return integer version#
CC=$1
INTEGERONLY=0
for i in "$@" ; do
    if [[ $i == "-i" ]] ; then
        INTEGERONLY=1
        break
    fi
done

### @todo better than this check is to CC --version | grep clang
if [[ "$CC" =~ clang.* ]]; then
    true;
elif [[ "$CC" =~ clang\+\+.* ]]; then
    true;
else
    exit 1;
fi
VER_=`($CC --version 2>/dev/null) | head -1 | awk '{print \$4;}'`
if [ "$VER_" == "" ] ; then
    exit 1;
fi
if [ "1" == "$INTEGERONLY" ] ; then
    echo $VER_ | awk  '{printf("%d\n", $1)}'
else
    echo $VER_
fi
exit 0
