Skip to content
This repository was archived by the owner on Apr 13, 2024. It is now read-only.

Commit e532e15

Browse files
authored
Merge pull request #128 from nathanchance/find-binaries
driver: Improvements around binary locating
2 parents b7b4c6c + 305279f commit e532e15

File tree

2 files changed

+77
-8
lines changed

2 files changed

+77
-8
lines changed

driver.sh

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ set -eu
55
setup_variables() {
66
while [[ ${#} -ge 1 ]]; do
77
case ${1} in
8+
"AR="*|"ARCH="*|"CC="*|"LD="*|"REPO="*) export "${1?}" ;;
89
"-c"|"--clean") cleanup=true ;;
910
"-j"|"--jobs") shift; jobs=$1 ;;
1011
"-j"*) jobs=${1/-j} ;;
@@ -139,14 +140,72 @@ setup_variables() {
139140
}
140141

141142
check_dependencies() {
143+
# Check for existence of needed binaries
142144
command -v nproc
143145
command -v "${CROSS_COMPILE:-}"as
144146
command -v ${qemu}
145147
command -v timeout
146148
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
150209
}
151210

152211
mako_reactor() {
@@ -155,11 +214,12 @@ mako_reactor() {
155214
KBUILD_BUILD_TIMESTAMP="Thu Jan 1 00:00:00 UTC 1970" \
156215
KBUILD_BUILD_USER=driver \
157216
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}" "${@}"
159218
}
160219

161220
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}"
163223
[[ ${LD} =~ lld ]] && HOSTLD=${LD}
164224

165225
if [[ -d ${tree} ]]; then

usage.txt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,23 @@ Script description: Build a Linux kernel image with Clang and boot it
44

55
Environment variables:
66
The script can take into account specific environment variables, mostly used
7-
with Travis. They can be invoked either via 'export VAR=<value>;
8-
./driver.sh' OR 'VAR=value ./driver.sh'
7+
with Travis. They can be invoked in one of three ways:
8+
$ export VAR=<value> && ./driver.sh
9+
$ VAR=value ./driver.sh
10+
$ ./driver.sh VAR=value
911

12+
AR:
13+
If no AR value is specified, the script will attempt to set AR to
14+
llvm-ar-9, llvm-ar-8, llvm-ar-7, llvm-ar, then ${CROSS_COMPILE}ar
15+
if they are found in PATH.
1016
ARCH:
1117
If no ARCH value is specified, arm64 is the default. Currently, arm32_v7,
1218
arm32_v6, arm32_v5, arm64, ppc64le and x86_64 are supported.
19+
CC:
20+
If no CC value is specified, the script will attempt to set CC to
21+
clang-9, clang-8, clang-7, then clang if they are found in PATH.
1322
LD:
14-
If no LD value is specified, ${CROSS_COMPILE}-ld is used. arm64 only.
23+
If no LD value is specified, ${CROSS_COMPILE}ld is used. arm64 only.
1524
REPO:
1625
Nicknames for trees:
1726
linux (default)

0 commit comments

Comments
 (0)