mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-23 14:41:31 +02:00
eclass/llvm: Sync with Gentoo
It's from Gentoo commit 118145de3992a8249131bd0eb30ea89ad0bd0bdf.
This commit is contained in:
parent
acbdd65ca9
commit
e80a4506c1
@ -7,6 +7,7 @@
|
|||||||
# @AUTHOR:
|
# @AUTHOR:
|
||||||
# Michał Górny <mgorny@gentoo.org>
|
# Michał Górny <mgorny@gentoo.org>
|
||||||
# @SUPPORTED_EAPIS: 7 8
|
# @SUPPORTED_EAPIS: 7 8
|
||||||
|
# @PROVIDES: llvm-utils
|
||||||
# @BLURB: Utility functions to build against slotted LLVM
|
# @BLURB: Utility functions to build against slotted LLVM
|
||||||
# @DESCRIPTION:
|
# @DESCRIPTION:
|
||||||
# The llvm.eclass provides utility functions that can be used to build
|
# The llvm.eclass provides utility functions that can be used to build
|
||||||
@ -64,6 +65,8 @@ esac
|
|||||||
if [[ ! ${_LLVM_ECLASS} ]]; then
|
if [[ ! ${_LLVM_ECLASS} ]]; then
|
||||||
_LLVM_ECLASS=1
|
_LLVM_ECLASS=1
|
||||||
|
|
||||||
|
inherit llvm-utils
|
||||||
|
|
||||||
# make sure that the versions installing straight into /usr/bin
|
# make sure that the versions installing straight into /usr/bin
|
||||||
# are uninstalled
|
# are uninstalled
|
||||||
DEPEND="!!sys-devel/llvm:0"
|
DEPEND="!!sys-devel/llvm:0"
|
||||||
@ -174,95 +177,6 @@ get_llvm_prefix() {
|
|||||||
echo "${prefix}/usr/lib/llvm/$(get_llvm_slot "${@}")"
|
echo "${prefix}/usr/lib/llvm/$(get_llvm_slot "${@}")"
|
||||||
}
|
}
|
||||||
|
|
||||||
# @FUNCTION: llvm_tuple_to_target
|
|
||||||
# @USAGE: [<tuple>]
|
|
||||||
# @DESCRIPTION:
|
|
||||||
# Translate a tuple into a target suitable for LLVM_TARGETS.
|
|
||||||
# Defaults to ${CHOST} if not specified.
|
|
||||||
llvm_tuple_to_target() {
|
|
||||||
debug-print-function ${FUNCNAME} "${@}"
|
|
||||||
|
|
||||||
case ${1:-${CHOST}} in
|
|
||||||
aarch64*) echo "AArch64";;
|
|
||||||
amdgcn*) echo "AMDGPU";;
|
|
||||||
arc*) echo "ARC";;
|
|
||||||
arm*) echo "ARM";;
|
|
||||||
avr*) echo "AVR";;
|
|
||||||
bpf*) echo "BPF";;
|
|
||||||
csky*) echo "CSKY";;
|
|
||||||
loong*) echo "LoongArch";;
|
|
||||||
m68k*) echo "M68k";;
|
|
||||||
mips*) echo "Mips";;
|
|
||||||
msp430*) echo "MSP430";;
|
|
||||||
nvptx*) echo "NVPTX";;
|
|
||||||
powerpc*) echo "PowerPC";;
|
|
||||||
riscv*) echo "RISCV";;
|
|
||||||
sparc*) echo "Sparc";;
|
|
||||||
s390*) echo "SystemZ";;
|
|
||||||
x86_64*|i?86*) echo "X86";;
|
|
||||||
xtensa*) echo "Xtensa";;
|
|
||||||
*) die "Unknown LLVM target for tuple ${1:-${CHOST}}"
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
# @FUNCTION: llvm_fix_clang_version
|
|
||||||
# @USAGE: <variable-name>...
|
|
||||||
# @DESCRIPTION:
|
|
||||||
# Fix the clang compiler name in specified variables to include
|
|
||||||
# the major version, to prevent PATH alterations from forcing an older
|
|
||||||
# clang version being used.
|
|
||||||
llvm_fix_clang_version() {
|
|
||||||
debug-print-function ${FUNCNAME} "${@}"
|
|
||||||
|
|
||||||
local shopt_save=$(shopt -p -o noglob)
|
|
||||||
set -f
|
|
||||||
local var
|
|
||||||
for var; do
|
|
||||||
local split=( ${!var} )
|
|
||||||
case ${split[0]} in
|
|
||||||
*clang|*clang++|*clang-cpp)
|
|
||||||
local version=()
|
|
||||||
read -r -a version < <("${split[0]}" --version)
|
|
||||||
local major=${version[-1]%%.*}
|
|
||||||
if [[ -n ${major//[0-9]} ]]; then
|
|
||||||
die "${var}=${!var} produced invalid --version: ${version[*]}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
split[0]+=-${major}
|
|
||||||
if ! type -P "${split[0]}" &>/dev/null; then
|
|
||||||
die "${split[0]} does not seem to exist"
|
|
||||||
fi
|
|
||||||
declare -g "${var}=${split[*]}"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
${shopt_save}
|
|
||||||
}
|
|
||||||
|
|
||||||
# @FUNCTION: llvm_fix_tool_path
|
|
||||||
# @USAGE: <variable-name>...
|
|
||||||
# @DESCRIPTION:
|
|
||||||
# Fix the LLVM tools referenced in the specified variables to their
|
|
||||||
# current location, to prevent PATH alterations from forcing older
|
|
||||||
# versions being used.
|
|
||||||
llvm_fix_tool_path() {
|
|
||||||
debug-print-function ${FUNCNAME} "${@}"
|
|
||||||
|
|
||||||
local shopt_save=$(shopt -p -o noglob)
|
|
||||||
set -f
|
|
||||||
local var
|
|
||||||
for var; do
|
|
||||||
local split=( ${!var} )
|
|
||||||
local path=$(type -P ${split[0]} 2>/dev/null)
|
|
||||||
# if it resides in one of the LLVM prefixes, it's an LLVM tool!
|
|
||||||
if [[ ${path} == "${BROOT}/usr/lib/llvm"* ]]; then
|
|
||||||
split[0]=${path}
|
|
||||||
declare -g "${var}=${split[*]}"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
${shopt_save}
|
|
||||||
}
|
|
||||||
|
|
||||||
# @FUNCTION: llvm_pkg_setup
|
# @FUNCTION: llvm_pkg_setup
|
||||||
# @DESCRIPTION:
|
# @DESCRIPTION:
|
||||||
# Prepend the appropriate executable directory for the newest
|
# Prepend the appropriate executable directory for the newest
|
||||||
@ -298,30 +212,7 @@ llvm_pkg_setup() {
|
|||||||
llvm_fix_tool_path LLVM_CONFIG
|
llvm_fix_tool_path LLVM_CONFIG
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local prefix=${ESYSROOT}
|
llvm_prepend_path "${LLVM_SLOT}"
|
||||||
local llvm_path=${prefix}/usr/lib/llvm/${LLVM_SLOT}/bin
|
|
||||||
local IFS=:
|
|
||||||
local split_path=( ${PATH} )
|
|
||||||
local new_path=()
|
|
||||||
local x added=
|
|
||||||
|
|
||||||
# prepend new path before first LLVM version found
|
|
||||||
for x in "${split_path[@]}"; do
|
|
||||||
if [[ ${x} == */usr/lib/llvm/*/bin ]]; then
|
|
||||||
if [[ ${x} != ${llvm_path} ]]; then
|
|
||||||
new_path+=( "${llvm_path}" )
|
|
||||||
elif [[ ${added} && ${x} == ${llvm_path} ]]; then
|
|
||||||
# deduplicate
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
added=1
|
|
||||||
fi
|
|
||||||
new_path+=( "${x}" )
|
|
||||||
done
|
|
||||||
# ...or to the end of PATH
|
|
||||||
[[ ${added} ]] || new_path+=( "${llvm_path}" )
|
|
||||||
|
|
||||||
export PATH=${new_path[*]}
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user