aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 1) #!/bin/sh
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 2) # SPDX-License-Identifier: GPL-2.0
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 3) #
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 4) # Print the compiler name and its version in a 5 or 6-digit form.
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 5) # Also, perform the minimum version check.
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 6)
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 7) set -e
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 8)
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 9) # Print the compiler name and some version components.
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 10) get_compiler_info()
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 11) {
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 12) cat <<- EOF | "$@" -E -P -x c - 2>/dev/null
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 13) #if defined(__clang__)
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 14) Clang __clang_major__ __clang_minor__ __clang_patchlevel__
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 15) #elif defined(__INTEL_COMPILER)
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 16) ICC __INTEL_COMPILER __INTEL_COMPILER_UPDATE
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 17) #elif defined(__GNUC__)
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 18) GCC __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 19) #else
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 20) unknown
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 21) #endif
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 22) EOF
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 23) }
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 24)
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 25) # Convert the version string x.y.z to a canonical 5 or 6-digit form.
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 26) get_canonical_version()
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 27) {
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 28) IFS=.
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 29) set -- $1
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 30) echo $((10000 * $1 + 100 * $2 + $3))
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 31) }
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 32)
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 33) # $@ instead of $1 because multiple words might be given, e.g. CC="ccache gcc".
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 34) orig_args="$@"
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 35) set -- $(get_compiler_info "$@")
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 36)
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 37) name=$1
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 38)
e24b3ffcf4216 (Masahiro Yamada 2021-03-16 01:12:55 +0900 39) min_tool_version=$(dirname $0)/min-tool-version.sh
e24b3ffcf4216 (Masahiro Yamada 2021-03-16 01:12:55 +0900 40)
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 41) case "$name" in
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 42) GCC)
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 43) version=$2.$3.$4
e24b3ffcf4216 (Masahiro Yamada 2021-03-16 01:12:55 +0900 44) min_version=$($min_tool_version gcc)
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 45) ;;
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 46) Clang)
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 47) version=$2.$3.$4
e24b3ffcf4216 (Masahiro Yamada 2021-03-16 01:12:55 +0900 48) min_version=$($min_tool_version llvm)
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 49) ;;
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 50) ICC)
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 51) version=$(($2 / 100)).$(($2 % 100)).$3
e24b3ffcf4216 (Masahiro Yamada 2021-03-16 01:12:55 +0900 52) min_version=$($min_tool_version icc)
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 53) ;;
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 54) *)
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 55) echo "$orig_args: unknown compiler" >&2
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 56) exit 1
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 57) ;;
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 58) esac
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 59)
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 60) cversion=$(get_canonical_version $version)
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 61) min_cversion=$(get_canonical_version $min_version)
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 62)
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 63) if [ "$cversion" -lt "$min_cversion" ]; then
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 64) echo >&2 "***"
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 65) echo >&2 "*** Compiler is too old."
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 66) echo >&2 "*** Your $name version: $version"
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 67) echo >&2 "*** Minimum $name version: $min_version"
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 68) echo >&2 "***"
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 69) exit 1
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 70) fi
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 71)
aec6c60a01d3a (Masahiro Yamada 2021-01-16 08:35:42 +0900 72) echo $name $cversion