]>
Commit | Line | Data |
---|---|---|
aec6c60a MY |
1 | #!/bin/sh |
2 | # SPDX-License-Identifier: GPL-2.0 | |
3 | # | |
4 | # Print the compiler name and its version in a 5 or 6-digit form. | |
5 | # Also, perform the minimum version check. | |
6 | ||
7 | set -e | |
8 | ||
9 | # When you raise the minimum compiler version, please update | |
10 | # Documentation/process/changes.rst as well. | |
11 | gcc_min_version=4.9.0 | |
12 | clang_min_version=10.0.1 | |
13 | icc_min_version=16.0.3 # temporary | |
14 | ||
15 | # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63293 | |
16 | # https://lore.kernel.org/r/[email protected] | |
17 | if [ "$SRCARCH" = arm64 ]; then | |
18 | gcc_min_version=5.1.0 | |
19 | fi | |
20 | ||
21 | # Print the compiler name and some version components. | |
22 | get_compiler_info() | |
23 | { | |
24 | cat <<- EOF | "$@" -E -P -x c - 2>/dev/null | |
25 | #if defined(__clang__) | |
26 | Clang __clang_major__ __clang_minor__ __clang_patchlevel__ | |
27 | #elif defined(__INTEL_COMPILER) | |
28 | ICC __INTEL_COMPILER __INTEL_COMPILER_UPDATE | |
29 | #elif defined(__GNUC__) | |
30 | GCC __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ | |
31 | #else | |
32 | unknown | |
33 | #endif | |
34 | EOF | |
35 | } | |
36 | ||
37 | # Convert the version string x.y.z to a canonical 5 or 6-digit form. | |
38 | get_canonical_version() | |
39 | { | |
40 | IFS=. | |
41 | set -- $1 | |
42 | echo $((10000 * $1 + 100 * $2 + $3)) | |
43 | } | |
44 | ||
45 | # $@ instead of $1 because multiple words might be given, e.g. CC="ccache gcc". | |
46 | orig_args="$@" | |
47 | set -- $(get_compiler_info "$@") | |
48 | ||
49 | name=$1 | |
50 | ||
51 | case "$name" in | |
52 | GCC) | |
53 | version=$2.$3.$4 | |
54 | min_version=$gcc_min_version | |
55 | ;; | |
56 | Clang) | |
57 | version=$2.$3.$4 | |
58 | min_version=$clang_min_version | |
59 | ;; | |
60 | ICC) | |
61 | version=$(($2 / 100)).$(($2 % 100)).$3 | |
62 | min_version=$icc_min_version | |
63 | ;; | |
64 | *) | |
65 | echo "$orig_args: unknown compiler" >&2 | |
66 | exit 1 | |
67 | ;; | |
68 | esac | |
69 | ||
70 | cversion=$(get_canonical_version $version) | |
71 | min_cversion=$(get_canonical_version $min_version) | |
72 | ||
73 | if [ "$cversion" -lt "$min_cversion" ]; then | |
74 | echo >&2 "***" | |
75 | echo >&2 "*** Compiler is too old." | |
76 | echo >&2 "*** Your $name version: $version" | |
77 | echo >&2 "*** Minimum $name version: $min_version" | |
78 | echo >&2 "***" | |
79 | exit 1 | |
80 | fi | |
81 | ||
82 | echo $name $cversion |