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