--- eclass/llvm.eclass | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 eclass/llvm.eclass
diff --git a/eclass/llvm.eclass b/eclass/llvm.eclass new file mode 100644 index 000000000000..8c001fdbdb97 --- /dev/null +++ b/eclass/llvm.eclass @@ -0,0 +1,106 @@ +# Copyright 1999-2017 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id$ + +# @ECLASS: llvm.eclass +# @MAINTAINER: +# Michał Górny <mgo...@gentoo.org> +# @AUTHOR: +# Michał Górny <mgo...@gentoo.org> +# @BLURB: Utility functions to build against slotted LLVM +# @DESCRIPTION: +# The llvm.eclass provides utility functions that can be used to build +# against specific version of slotted LLVM (with fallback to :0 for old +# versions). +# +# This eclass does not generate dependency strings. You need to write +# a proper dependency string yourself to guarantee that appropriate +# version of LLVM is installed. +# +# Example use for a package supporting LLVM 3.8 to 5: +# @CODE +# inherit cmake-utils llvm +# +# RDEPEND=" +# <sys-devel/llvm-6_rc:= +# || ( +# sys-devel/llvm:5 +# sys-devel/llvm:4 +# >=sys-devel/llvm-3.8:0 +# ) +# " +# +# src_configure() { +# local mycmakeargs=( +# -DLLVM_CONFIG="$(get_llvm_config 5)" +# ) +# cmake-utils_src_configure +# } +# @CODE + +if [[ ! ${_LLVM_ECLASS} ]]; then + +# @ECLASS-VARIABLE: _LLVM_KNOWN_SLOTS +# @INTERNAL +# @DESCRIPTION: +# Correct values of LLVM slots, newest first. +declare -g -r _LLVM_KNOWN_SLOTS=( 5 4 ) + +# @FUNCTION: get_llvm_config +# @USAGE: [<max_slot>] +# @DESCRIPTION: +# Prints path to llvm-config executable for the newest matching version +# of LLVM. If <max_slot> is provided, then no version newer than +# the specified slot will be used. If it is not, the newest installed +# version will be used. +# +# Note that the function does not support lower-bound version, so you +# need to set proper dependencies. Otherwise, the function can return +# a lower LLVM version than required. +get_llvm_config() { + debug-print-function ${FUNCNAME} "${@}" + + local max_slot=${1} + local slot + for slot in "${_LLVM_KNOWN_SLOTS[@]}"; do + # skip higher slots + if [[ -n ${max_slot} ]]; then + if [[ ${max_slot} == ${slot} ]]; then + max_slot= + else + continue + fi + fi + + local p=${EPREFIX}/usr/lib/llvm/${slot}/bin + if [[ -x ${p}/llvm-config ]]; then + if [[ -n ${CHOST} && -x ${p}/${CHOST}-llvm-config ]]; then + echo "${p}/${CHOST}-llvm-config" + else + echo "${p}/llvm-config" + fi + return + fi + done + + if [[ -n ${max_slot} ]]; then + die "${FUNCNAME}: invalid max_slot=${max_slot}" + fi + + # fallback to :0 + # assume it's always <= 4 (the lower max_slot allowed) + p=${EPREFIX}/usr/bin + if [[ -x ${p}/llvm-config ]]; then + if [[ -n ${CHOST} && -x ${p}/${CHOST}-llvm-config ]]; then + echo "${p}/${CHOST}-llvm-config" + else + echo "${p}/llvm-config" + fi + return + fi + + die "No LLVM slot${1:+ <= ${1}} found in PATH!" +} + +_LLVM_ECLASS=1 +fi -- 2.11.0