mirror of
https://github.com/JakeHillion/scx.git
synced 2026-12-04 02:30:50 +00:00
On systems which use clang, instead of GCC, as the main compiler, building any part of the Linux monorepo often requires passing `LLVM=1` in the `m̀ake` invocation. Otherwise it assumes that the system has GCC and ends up invoking `gcc` explicitly. That's the case with bpftool. To avoid such issues, check whether the default `cc` compiler is clang and if yes, set the `LLVM` parameter accordingly. Fixes #1143
36 lines
729 B
Bash
36 lines
729 B
Bash
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
out=$("$1" 'map(select(.["file"] | contains ("cc_cflags_probe.c"))) | first | .["command"]' < compile_commands.json)
|
|
out=${out#\"}
|
|
out=${out%\"}
|
|
args=($out)
|
|
|
|
idx=0
|
|
cc=${args[idx]}
|
|
if [ "$cc" = "ccache" -o "$cc" = "sccache" ]; then
|
|
idx=$((idx+1))
|
|
cc="$cc ${args[idx]}"
|
|
fi
|
|
|
|
declare -a cflags=()
|
|
|
|
for arg in ${args[@]:(idx+1)}; do
|
|
case $arg in
|
|
-I*|-M*|-o|-c) ;;
|
|
-*) cflags+="$arg ";;
|
|
esac
|
|
done
|
|
|
|
extra_args=()
|
|
# When using clang, `LLVM=1` needs to be passed as an argument. Otherwise some
|
|
# parts of the build system will attempt to invoke GCC.
|
|
if cc --version 2>&1 | grep clang; then
|
|
extra_args+="LLVM=1"
|
|
fi
|
|
|
|
cd $3
|
|
make_out=$(env CC="$cc" CFLAGS="$cflags" "$2" -j"$4" $extra_args)
|
|
exit $?
|