Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/sh
0002 # SPDX-License-Identifier: GPL-2.0
0003 #
0004 # Print the compiler name and its version in a 5 or 6-digit form.
0005 # Also, perform the minimum version check.
0006 
0007 set -e
0008 
0009 # Print the compiler name and some version components.
0010 get_compiler_info()
0011 {
0012         cat <<- EOF | "$@" -E -P -x c - 2>/dev/null
0013         #if defined(__clang__)
0014         Clang   __clang_major__  __clang_minor__  __clang_patchlevel__
0015         #elif defined(__INTEL_COMPILER)
0016         ICC     __INTEL_COMPILER  __INTEL_COMPILER_UPDATE
0017         #elif defined(__GNUC__)
0018         GCC     __GNUC__  __GNUC_MINOR__  __GNUC_PATCHLEVEL__
0019         #else
0020         unknown
0021         #endif
0022         EOF
0023 }
0024 
0025 # Convert the version string x.y.z to a canonical 5 or 6-digit form.
0026 get_canonical_version()
0027 {
0028         IFS=.
0029         set -- $1
0030         echo $((10000 * $1 + 100 * $2 + $3))
0031 }
0032 
0033 # $@ instead of $1 because multiple words might be given, e.g. CC="ccache gcc".
0034 orig_args="$@"
0035 set -- $(get_compiler_info "$@")
0036 
0037 name=$1
0038 
0039 min_tool_version=$(dirname $0)/min-tool-version.sh
0040 
0041 case "$name" in
0042 GCC)
0043         version=$2.$3.$4
0044         min_version=$($min_tool_version gcc)
0045         ;;
0046 Clang)
0047         version=$2.$3.$4
0048         min_version=$($min_tool_version llvm)
0049         ;;
0050 ICC)
0051         version=$(($2 / 100)).$(($2 % 100)).$3
0052         min_version=$($min_tool_version icc)
0053         ;;
0054 *)
0055         echo "$orig_args: unknown compiler" >&2
0056         exit 1
0057         ;;
0058 esac
0059 
0060 cversion=$(get_canonical_version $version)
0061 min_cversion=$(get_canonical_version $min_version)
0062 
0063 if [ "$cversion" -lt "$min_cversion" ]; then
0064         echo >&2 "***"
0065         echo >&2 "*** Compiler is too old."
0066         echo >&2 "***   Your $name version:    $version"
0067         echo >&2 "***   Minimum $name version: $min_version"
0068         echo >&2 "***"
0069         exit 1
0070 fi
0071 
0072 echo $name $cversion