5
5
setup_variables () {
6
6
while [[ ${# } -ge 1 ]]; do
7
7
case ${1} in
8
+ " AR=" * |" ARCH=" * |" CC=" * |" LD=" * |" REPO=" * ) export " ${1?} " ;;
8
9
" -c" |" --clean" ) cleanup=true ;;
9
10
" -j" |" --jobs" ) shift ; jobs=$1 ;;
10
11
" -j" * ) jobs=${1/ -j} ;;
@@ -139,14 +140,72 @@ setup_variables() {
139
140
}
140
141
141
142
check_dependencies () {
143
+ # Check for existence of needed binaries
142
144
command -v nproc
143
145
command -v " ${CROSS_COMPILE:- } " as
144
146
command -v ${qemu}
145
147
command -v timeout
146
148
command -v unbuffer
147
- command -v clang-9
148
- command -v llvm-ar-9
149
- command -v " ${LD:= " ${CROSS_COMPILE:- } " ld} "
149
+
150
+ # Check for LD, CC, and AR environmental variables
151
+ # and print the version string of each. If CC and AR
152
+ # don't exist, try to find them.
153
+ # lld isn't ready for all architectures so it's just
154
+ # simpler to fall back to GNU ld when LD isn't specified
155
+ # to avoid architecture specific selection logic.
156
+
157
+ " ${LD:= " ${CROSS_COMPILE:- } " ld} " --version
158
+
159
+ if [[ -z " ${CC:- } " ]]; then
160
+ for CC in clang-9 clang-8 clang-7 clang; do
161
+ command -v ${CC} & > /dev/null && break
162
+ done
163
+ fi
164
+ ${CC} --version 2> /dev/null || {
165
+ set +x
166
+ echo
167
+ echo " Looks like ${CC} could not be found in PATH!"
168
+ echo
169
+ echo " Please install as recent a version of clang as you can from your distro or"
170
+ echo " properly specify the CC variable to point to the correct clang binary."
171
+ echo
172
+ echo " If you don't want to install clang, you can either download AOSP's prebuilt"
173
+ echo " clang [1] or build it from source [2] then add the bin folder to your PATH."
174
+ echo
175
+ echo " [1]: https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/"
176
+ echo " [2]: https://github.com/ClangBuiltLinux/linux/wiki/Building-Clang-from-source"
177
+ echo
178
+ exit ;
179
+ }
180
+
181
+ if [[ -z " ${AR:- } " ]]; then
182
+ for AR in llvm-ar-9 llvm-ar-8 llvm-ar-7 llvm-ar " ${CROSS_COMPILE:- } " ar; do
183
+ command -v ${AR} 2> /dev/null && break
184
+ done
185
+ fi
186
+ check_ar_version
187
+ ${AR} --version
188
+ }
189
+
190
+ # Optimistically check to see that the user has a llvm-ar
191
+ # with https://reviews.llvm.org/rL354044. If they don't,
192
+ # fall back to GNU ar and let them know.
193
+ check_ar_version () {
194
+ if ${AR} --version | grep -q " LLVM" && \
195
+ [[ $( ${AR} --version | grep version | sed -e ' s/.*LLVM version //g' -e ' s/[[:blank:]]*$//' -e ' s/\.//g' ) -lt 900 ]]; then
196
+ set +x
197
+ echo
198
+ echo " ${AR} found but appears to be too old to build the kernel (needs to be at least 9.0.0)."
199
+ echo
200
+ echo " Please either update llvm-ar from your distro or build it from source!"
201
+ echo
202
+ echo " See https://github.com/ClangBuiltLinux/linux/issues/33 for more info."
203
+ echo
204
+ echo " Falling back to GNU ar..."
205
+ echo
206
+ AR=${CROSS_COMPILE:- } ar
207
+ set -x
208
+ fi
150
209
}
151
210
152
211
mako_reactor () {
@@ -155,11 +214,12 @@ mako_reactor() {
155
214
KBUILD_BUILD_TIMESTAMP=" Thu Jan 1 00:00:00 UTC 1970" \
156
215
KBUILD_BUILD_USER=driver \
157
216
KBUILD_BUILD_HOST=clangbuiltlinux \
158
- make -j" ${jobs:- $(nproc)} " CC=" ${CC} " HOSTCC=" ${CC} " LD=" ${LD} " HOSTLD=" ${HOSTLD:- ld} " AR=" llvm-ar-9 " " ${@ } "
217
+ make -j" ${jobs:- $(nproc)} " CC=" ${CC} " HOSTCC=" ${CC} " LD=" ${LD} " HOSTLD=" ${HOSTLD:- ld} " AR=" ${AR} " " ${@ } "
159
218
}
160
219
161
220
build_linux () {
162
- CC=" $( command -v ccache) $( command -v clang-9) "
221
+ # Wrap CC in ccache if it is available (it's not strictly required)
222
+ CC=" $( command -v ccache) ${CC} "
163
223
[[ ${LD} =~ lld ]] && HOSTLD=${LD}
164
224
165
225
if [[ -d ${tree} ]]; then
0 commit comments