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,23 @@ check_version_exists() {
58
60
echo " $desired_version "
59
61
}
60
62
63
+ set_compiler_version_from_CC () {
64
+ version=" $( " $CC " -dumpversion) "
65
+ if [ " $version " = " " ]; then
66
+ echo " Error: $CC -dumpversion didn't provide a version"
67
+ exit 1
68
+ fi
69
+ # gcc and clang often display 3 part versions. However, gcc can show only 1 part in some environments.
70
+ IFS=. read -r majorVersion minorVersion _ << EOF
71
+ $version
72
+ EOF
73
+ }
74
+
61
75
if [ -z " $CLR_CC " ]; then
62
76
63
77
# Set default versions
64
78
if [ -z " $majorVersion " ]; then
79
+
65
80
# note: gcc (all versions) and clang versions higher than 6 do not have minor version in file name, if it is zero.
66
81
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
82
elif [ " $compiler " = " gcc" ]; then versions=" 13 12 11 10 9 8 7 6 5 4.9" ; fi
@@ -74,28 +89,30 @@ if [ -z "$CLR_CC" ]; then
74
89
done
75
90
76
91
if [ -z " $majorVersion " ]; then
77
- 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
- CC=" $( command -v " $compiler " ) "
82
- CXX=" $( command -v " $cxxCompiler " ) "
83
- else
84
- echo " No usable version of $compiler found."
92
+ if [ " $( uname) " != " Darwin" ]; then
93
+ echo " Error: Specific version of $compiler not found"
85
94
exit 1
86
95
fi
96
+
97
+ if ! command -v " $compiler " > /dev/null; then
98
+ echo " Error: No usable version of $compiler found."
99
+ exit 1
100
+ fi
101
+
102
+ CC=" $( command -v " $compiler " ) "
103
+ CXX=" $( command -v " $cxxCompiler " ) "
104
+ set_compiler_version_from_CC
87
105
else
88
- if [ " $compiler " = " clang" ] && [ " $majorVersion " -lt 5 ]; then
89
- if [ " $build_arch " = " arm" ] || [ " $build_arch " = " armel" ]; then
90
- 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
- CC=" $( command -v " $compiler " ) "
93
- CXX=" $( command -v " $cxxCompiler " ) "
94
- else
95
- echo " Found clang version $majorVersion which is not supported on arm/armel architectures, and there is no clang in PATH."
96
- exit 1
97
- fi
106
+ if ( [ " $compiler " = " clang" ] && [ " $majorVersion " -lt 5 ] ) && ( [ " $build_arch " = " arm" ] || [ " $build_arch " = " armel" ] ); then
107
+ # If a major version was provided explicitly, and it was too old, find a newer compiler instead
108
+ if ! command -v " $compiler " > /dev/null; then
109
+ echo " Found clang version $majorVersion which is not supported on arm/armel architectures, and there is no clang in PATH."
110
+ exit 1
98
111
fi
112
+
113
+ CC=" $( command -v " $compiler " ) "
114
+ CXX=" $( command -v " $cxxCompiler " ) "
115
+ set_compiler_version_from_CC
99
116
fi
100
117
fi
101
118
else
@@ -110,6 +127,7 @@ if [ -z "$CLR_CC" ]; then
110
127
CC=" $( command -v " $compiler$desired_version " ) "
111
128
CXX=" $( command -v " $cxxCompiler$desired_version " ) "
112
129
if [ -z " $CXX " ]; then CXX=" $( command -v " $cxxCompiler " ) " ; fi
130
+ set_compiler_version_from_CC
113
131
fi
114
132
else
115
133
if [ ! -f " $CLR_CC " ]; then
@@ -118,17 +136,22 @@ else
118
136
fi
119
137
CC=" $CLR_CC "
120
138
CXX=" $CLR_CXX "
139
+ set_compiler_version_from_CC
121
140
fi
122
141
123
142
if [ -z " $CC " ]; then
124
143
echo " Unable to find $compiler ."
125
144
exit 1
126
145
fi
127
146
128
- # Only lld version >= 9 can be considered stable. lld supports s390x starting from 18.0.
129
- if [ " $compiler " = " clang" ] && [ -n " $majorVersion " ] && [ " $majorVersion " -ge 9 ] && ([ " $build_arch " != " s390x" ] || [ " $majorVersion " -ge 18 ]); then
130
- if " $CC " -fuse-ld=lld -Wl,--version > /dev/null 2>&1 ; then
131
- LDFLAGS=" -fuse-ld=lld"
147
+ if [ " $( uname) " != " Darwin" ]; then
148
+ # On Darwin, we always want to use the Apple linker.
149
+
150
+ # Only lld version >= 9 can be considered stable. lld supports s390x starting from 18.0.
151
+ if [ " $compiler " = " clang" ] && [ -n " $majorVersion " ] && [ " $majorVersion " -ge 9 ] && ( [ " $build_arch " != " s390x" ] || [ " $majorVersion " -ge 18 ] ); then
152
+ if " $CC " -fuse-ld=lld -Wl,--version > /dev/null 2>&1 ; then
153
+ LDFLAGS=" -fuse-ld=lld"
154
+ fi
132
155
fi
133
156
fi
134
157
0 commit comments