I think there's a lot of duplication here: could it be like:

```sh
if [ $(uname -s) = Darwin ]
then
    chk_cc () {
        $1 --version 2> /dev/null | grep -q $2
    }
    # check that gcc, cc and g++ all point to the same compiler.
    if !((chk_cc gcc clang && chk_cc cc clang && chk_cc g++ clang++) ||
         (chk_cc gcc gcc   && chk_cc cc gcc   && chk_cc g++ g++)) then
        echo ...
    fi
fi
```