From 64839b916e4ba9556be88258ed360187263fe393 Mon Sep 17 00:00:00 2001 From: cancel Date: Wed, 19 Dec 2018 23:30:51 +0900 Subject: [PATCH] Change compiler detection to use cpp macros --- tool | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/tool b/tool index 876a014..9870530 100755 --- a/tool +++ b/tool @@ -123,21 +123,15 @@ fi cc_id= cc_vers= lld_detected=0 -if cc_vers_string=$("$cc_exe" --version 2> /dev/null); then - if clang_vers_string=$(echo "$cc_vers_string" | grep clang | head -n1) && ! [[ -z $clang_vers_string ]]; then - cc_id=clang - # clang -dumpversion always pretends to be gcc 4.2.1 - # shellcheck disable=SC2001 - cc_vers=$(echo "$clang_vers_string" | sed 's/.*version \([0-9]*\.[0-9]*\.[0-9]*\).*/\1/') - if [[ $os != mac ]]; then - if command -v "lld" >/dev/null 2>&1; then - lld_detected=1 - fi +if cc_vers=$(echo -e '#ifndef __clang__\n#error Not found\n#endif\n__clang_major__.__clang_minor__.__clang_patchlevel__' | "$cc_exe" -E -xc - 2>/dev/null | tail -n 1 | tr -d '\040'); then + cc_id=clang + if [[ $os != mac ]]; then + if command -v "lld" >/dev/null 2>&1; then + lld_detected=1 fi - # Only gcc has -dumpfullversion - elif cc_vers=$("$cc_exe" -dumpfullversion 2> /dev/null); then - cc_id=gcc fi +elif cc_vers=$(echo -e '#ifndef __GNUC__\n#error Not found\n#endif\n__GNUC__.__GNUC_MINOR__.__GNUC_PATCHLEVEL__' | "$cc_exe" -E -xc - 2>/dev/null | tail -n 1 | tr -d '\040'); then + cc_id=gcc fi if [[ -z $cc_id ]]; then