@@ -19,19 +19,19 @@ case "$compiler" in
19
19
# clangx.y or clang-x.y
20
20
version=" $( echo " $compiler " | tr -d ' [:alpha:]-=' ) "
21
21
majorVersion=" ${version%% .* } "
22
+ [ -z " ${version##* .* } " ] && minorVersion=" ${version#* .} "
22
23
23
- # LLVM based on v18 released in early 2024, with two releases per year
24
- maxVersion=" $(( 18 + ((($(date +% Y) - 2024 ) * 12 + $(date +% m) - 3 ) / 6 )) )"
24
+ if [ -z " $minorVersion " ] && [ -n " $majorVersion " ] && [ " $majorVersion " -le 6 ]; then
25
+ minorVersion=0;
26
+ fi
25
27
compiler=clang
26
28
;;
27
29
28
30
gcc* |-gcc* |--gcc* )
29
31
# gccx.y or gcc-x.y
30
32
version=" $( echo " $compiler " | tr -d ' [:alpha:]-=' ) "
31
33
majorVersion=" ${version%% .* } "
32
-
33
- # GCC based on v14 released in early 2024, with one release per year
34
- maxVersion=" $(( 14 + ((($(date +% Y) - 2024 ) * 12 + $(date +% m) - 3 ) / 12 )) )"
34
+ [ -z " ${version##* .* } " ] && minorVersion=" ${version#* .} "
35
35
compiler=gcc
36
36
;;
37
37
esac
@@ -49,10 +49,12 @@ check_version_exists() {
49
49
desired_version=-1
50
50
51
51
# Set up the environment to be used for building with the desired compiler.
52
- if command -v " $compiler -$1 " > /dev/null; then
53
- desired_version=" -$1 "
54
- elif command -v " $compiler $1 " > /dev/null; then
55
- desired_version=" $1 "
52
+ if command -v " $compiler -$1 .$2 " > /dev/null; then
53
+ desired_version=" -$1 .$2 "
54
+ elif command -v " $compiler $1$2 " > /dev/null; then
55
+ desired_version=" $1$2 "
56
+ elif command -v " $compiler -$1$2 " > /dev/null; then
57
+ desired_version=" -$1$2 "
56
58
fi
57
59
58
60
echo " $desired_version "
@@ -73,7 +75,7 @@ set_compiler_version_from_CC() {
73
75
fi
74
76
75
77
# gcc and clang often display 3 part versions. However, gcc can show only 1 part in some environments.
76
- IFS=. read -r majorVersion _ << EOF
78
+ IFS=. read -r majorVersion minorVersion _ << EOF
77
79
$version
78
80
EOF
79
81
}
@@ -82,29 +84,43 @@ if [ -z "$CLR_CC" ]; then
82
84
83
85
# Set default versions
84
86
if [ -z " $majorVersion " ]; then
85
- minVersion=8
86
- maxVersion=" $(( maxVersion + 1 )) " # +1 for headspace
87
- i=" $maxVersion "
88
- while [ " $i " -ge $minVersion ]; do
89
- desired_version=" $( check_version_exists " $i " ) "
90
- if [ " $desired_version " != " -1" ]; then majorVersion=" $i " ; break ; fi
91
- i=$(( i - 1 ))
87
+ # note: gcc (all versions) and clang versions higher than 6 do not have minor version in file name, if it is zero.
88
+ if [ " $compiler " = " clang" ]; then versions=" 18 17 16 15 14 13 12 11 10 9 8 7 6.0 5.0 4.0 3.9 3.8 3.7 3.6 3.5"
89
+ elif [ " $compiler " = " gcc" ]; then versions=" 14 13 12 11 10 9 8 7 6 5 4.9" ; fi
90
+
91
+ for version in $versions ; do
92
+ _major=" ${version%% .* } "
93
+ [ -z " ${version##* .* } " ] && _minor=" ${version#* .} "
94
+ desired_version=" $( check_version_exists " $_major " " $_minor " ) "
95
+ if [ " $desired_version " != " -1" ]; then majorVersion=" $_major " ; break ; fi
92
96
done
93
97
94
98
if [ -z " $majorVersion " ]; then
95
99
if ! command -v " $compiler " > /dev/null; then
96
- echo " Error: No compatible version of $compiler was found within the range of $minVersion to $maxVersion . Please upgrade your toolchain or specify the compiler explicitly using CLR_CC and CLR_CXX environment variables ."
100
+ echo " Error: No usable version of $compiler found."
97
101
exit 1
98
102
fi
99
103
100
104
CC=" $( command -v " $compiler " 2> /dev/null) "
101
105
CXX=" $( command -v " $cxxCompiler " 2> /dev/null) "
102
106
set_compiler_version_from_CC
107
+ else
108
+ if [ " $compiler " = " clang" ] && [ " $majorVersion " -lt 5 ] && { [ " $build_arch " = " arm" ] || [ " $build_arch " = " armel" ]; }; then
109
+ # If a major version was provided explicitly, and it was too old, find a newer compiler instead
110
+ if ! command -v " $compiler " > /dev/null; then
111
+ echo " Error: Found clang version $majorVersion which is not supported on arm/armel architectures, and there is no clang in PATH."
112
+ exit 1
113
+ fi
114
+
115
+ CC=" $( command -v " $compiler " 2> /dev/null) "
116
+ CXX=" $( command -v " $cxxCompiler " 2> /dev/null) "
117
+ set_compiler_version_from_CC
118
+ fi
103
119
fi
104
120
else
105
- desired_version=" $( check_version_exists " $majorVersion " ) "
121
+ desired_version=" $( check_version_exists " $majorVersion " " $minorVersion " ) "
106
122
if [ " $desired_version " = " -1" ]; then
107
- echo " Error: Could not find specific version of $compiler : $majorVersion ."
123
+ echo " Error: Could not find specific version of $compiler : $majorVersion $minorVersion ."
108
124
exit 1
109
125
fi
110
126
fi
0 commit comments