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