2
2
#
3
3
# This file detects the C/C++ compiler and exports it to the CC/CXX environment variables
4
4
#
5
- # NOTE: some scripts source this file and rely on stdout being empty, make sure to not output anything here!
5
+ # NOTE: some scripts source this file and rely on stdout being empty, make sure
6
+ # to not output *anything* here, unless it is an error message that fails the
7
+ # build.
6
8
7
9
if [ -z " $build_arch " ] || [ -z " $compiler " ]; then
8
10
echo " Usage..."
@@ -58,10 +60,25 @@ check_version_exists() {
58
60
echo " $desired_version "
59
61
}
60
62
63
+ set_compiler_version_from_CC () {
64
+ local patchVersion
65
+ version=" $( " $CC " -dumpversion) "
66
+ if [ " $version " = " " ]; then
67
+ echo " $CC -dumpversion didn't provide a version"
68
+ exit 1
69
+ fi
70
+ # gcc and clang often display 3 part versions. However, gcc can show only 1 part in some environments.
71
+ IFS=. read -r majorVersion minorVersion patchVersion << EOF
72
+ $version
73
+ EOF
74
+ unset patchVersion
75
+ }
76
+
61
77
if [ -z " $CLR_CC " ]; then
62
78
63
79
# Set default versions
64
80
if [ -z " $majorVersion " ]; then
81
+
65
82
# note: gcc (all versions) and clang versions higher than 6 do not have minor version in file name, if it is zero.
66
83
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"
67
84
elif [ " $compiler " = " gcc" ]; then versions=" 13 12 11 10 9 8 7 6 5 4.9" ; fi
@@ -75,11 +92,9 @@ if [ -z "$CLR_CC" ]; then
75
92
76
93
if [ -z " $majorVersion " ]; then
77
94
if command -v " $compiler " > /dev/null; then
78
- if [ " $( uname) " != " Darwin" ]; then
79
- echo " Warning: Specific version of $compiler not found, falling back to use the one in PATH."
80
- fi
81
95
CC=" $( command -v " $compiler " ) "
82
96
CXX=" $( command -v " $cxxCompiler " ) "
97
+ set_compiler_version_from_CC
83
98
else
84
99
echo " No usable version of $compiler found."
85
100
exit 1
@@ -88,9 +103,9 @@ if [ -z "$CLR_CC" ]; then
88
103
if [ " $compiler " = " clang" ] && [ " $majorVersion " -lt 5 ]; then
89
104
if [ " $build_arch " = " arm" ] || [ " $build_arch " = " armel" ]; then
90
105
if command -v " $compiler " > /dev/null; then
91
- echo " Warning: Found clang version $majorVersion which is not supported on arm/armel architectures, falling back to use clang from PATH."
92
106
CC=" $( command -v " $compiler " ) "
93
107
CXX=" $( command -v " $cxxCompiler " ) "
108
+ set_compiler_version_from_CC
94
109
else
95
110
echo " Found clang version $majorVersion which is not supported on arm/armel architectures, and there is no clang in PATH."
96
111
exit 1
@@ -110,6 +125,7 @@ if [ -z "$CLR_CC" ]; then
110
125
CC=" $( command -v " $compiler$desired_version " ) "
111
126
CXX=" $( command -v " $cxxCompiler$desired_version " ) "
112
127
if [ -z " $CXX " ]; then CXX=" $( command -v " $cxxCompiler " ) " ; fi
128
+ set_compiler_version_from_CC
113
129
fi
114
130
else
115
131
if [ ! -f " $CLR_CC " ]; then
118
134
fi
119
135
CC=" $CLR_CC "
120
136
CXX=" $CLR_CXX "
137
+ set_compiler_version_from_CC
121
138
fi
122
139
123
140
if [ -z " $CC " ]; then
0 commit comments