mirror of
https://github.com/armbian/build
synced 2025-09-24 19:47:06 +07:00
armbian-next: bring find_toolchain() back from the dead; force SKIP_EXTERNAL_TOOLCHAINS=no to force use external toolchains
- handle a lot of corner cases, some toolchains are i386-only and won't run on modern x64 systems
This commit is contained in:
@@ -43,34 +43,79 @@ find_toolchain() {
|
||||
echo "/usr/bin"
|
||||
return
|
||||
}
|
||||
|
||||
local compiler=$1
|
||||
local expression=$2
|
||||
local dist=10
|
||||
|
||||
display_alert "SKIP_EXTERNAL_TOOLCHAINS=no, Searching for toolchain" "'${compiler}' '${expression}'" "warn"
|
||||
|
||||
local toolchain=""
|
||||
|
||||
# extract target major.minor version from expression
|
||||
local target_ver
|
||||
target_ver=$(grep -oE "[[:digit:]]+\.[[:digit:]]" <<< "$expression")
|
||||
display_alert "Searching for toolchain" "'${compiler}' '${expression}': target_ver: '${target_ver}'" "debug"
|
||||
|
||||
for dir in "${SRC}"/cache/toolchain/*/; do
|
||||
display_alert "Checking toolchain" "${dir}" "debug"
|
||||
local gcc_bin="${dir}bin/${compiler}gcc"
|
||||
# check if is a toolchain for current $ARCH
|
||||
[[ ! -f ${dir}bin/${compiler}gcc ]] && continue
|
||||
if [[ ! -f "${gcc_bin}" ]]; then
|
||||
display_alert "Can't find compiler" "'${dir}' :: '${gcc_bin}" "debug"
|
||||
continue
|
||||
else
|
||||
display_alert "Found compiler" "'${dir}' :: '${gcc_bin}" "debug"
|
||||
fi
|
||||
|
||||
declare gcc_bin_info
|
||||
gcc_bin_info="$(file "${gcc_bin}" || true)"
|
||||
|
||||
display_alert "Testing toolchain" "'${gcc_bin}': '${gcc_bin_info}'" "debug"
|
||||
|
||||
# get toolchain major.minor version
|
||||
local gcc_ver
|
||||
gcc_ver=$("${dir}bin/${compiler}gcc" -dumpversion | grep -oE "^[[:digit:]]+\.[[:digit:]]")
|
||||
declare gcc_ver_simple
|
||||
gcc_ver_simple="$("${gcc_bin}" -dumpversion 2>&1 || true)" # this might fail: toolchain can't run on current host
|
||||
|
||||
display_alert "Checking version" "'${gcc_ver_simple}' for '${gcc_bin}'" "debug"
|
||||
if [[ "x${gcc_ver_simple}x" == "xx" ]]; then
|
||||
display_alert "Can't obtain version" "'${gcc_bin}' for '${gcc_bin}': '${gcc_ver_simple}'" "debug"
|
||||
continue
|
||||
fi
|
||||
|
||||
declare gcc_ver
|
||||
gcc_ver="$(echo "${gcc_ver_simple}" | grep -oE "^[[:digit:]]+\.[[:digit:]]" || true)" # this might fail to parse
|
||||
if [[ "x${gcc_ver}x" == "xx" ]]; then
|
||||
display_alert "Can't parse version" "'${gcc_bin}' for '${gcc_bin}': '${gcc_ver_simple}': '${gcc_ver}'" "debug"
|
||||
continue
|
||||
fi
|
||||
|
||||
display_alert "Found working toolchain" "'${gcc_bin}' gcc_ver_simple:'${gcc_ver_simple}' gcc_ver:'${gcc_ver}'" "debug"
|
||||
|
||||
# check if toolchain version satisfies requirement
|
||||
awk "BEGIN{exit ! ($gcc_ver $expression)}" > /dev/null || continue
|
||||
if ! awk "BEGIN{exit ! ($gcc_ver $expression)}" > /dev/null; then
|
||||
display_alert "Toolchain version" "'${gcc_bin}' '${gcc_ver}' doesn't satisfy '${expression}'" "debug"
|
||||
continue
|
||||
fi
|
||||
|
||||
# check if found version is the closest to target
|
||||
# may need different logic here with more than 1 digit minor version numbers
|
||||
# numbers: 3.9 > 3.10; versions: 3.9 < 3.10
|
||||
# dpkg --compare-versions can be used here if operators are changed
|
||||
local d
|
||||
declare d
|
||||
d=$(awk '{x = $1 - $2}{printf "%.1f\n", (x > 0) ? x : -x}' <<< "$target_ver $gcc_ver")
|
||||
if awk "BEGIN{exit ! ($d < $dist)}" > /dev/null; then
|
||||
dist=$d
|
||||
toolchain=${dir}bin
|
||||
dist="$d"
|
||||
toolchain="${dir}bin"
|
||||
display_alert "Found toolchain" "'${gcc_bin}' ver:'${gcc_ver}' expression:'${expression}' dist:'${dist}'" "debug"
|
||||
fi
|
||||
done
|
||||
|
||||
display_alert "Using toolchain" "${toolchain}" "info"
|
||||
|
||||
echo "$toolchain"
|
||||
}
|
||||
|
||||
# overlayfs_wrapper <operation> <workdir> <description>
|
||||
#
|
||||
# <operation>: wrap|cleanup
|
||||
|
||||
Reference in New Issue
Block a user