1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
6 # Michał Górny <mgorny@gentoo.org>
8 # Michał Górny <mgorny@gentoo.org>
9 # @BLURB: Utility functions to build against slotted LLVM
11 # The llvm.eclass provides utility functions that can be used to build
12 # against specific version of slotted LLVM (with fallback to :0 for old
15 # This eclass does not generate dependency strings. You need to write
16 # a proper dependency string yourself to guarantee that appropriate
17 # version of LLVM is installed.
19 # Example use for a package supporting LLVM 3.8 to 5:
21 # inherit cmake-utils llvm
24 # <sys-devel/llvm-6_rc:=
28 # >=sys-devel/llvm-3.8:0
34 # # only if you need to define one explicitly
43 die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
48 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
52 EXPORT_FUNCTIONS pkg_setup
54 if [[ ! ${_LLVM_ECLASS} ]]; then
56 # @ECLASS-VARIABLE: LLVM_MAX_SLOT
59 # Highest LLVM slot supported by the package. Needs to be set before
60 # llvm_pkg_setup is called. If unset, no upper bound is assumed.
62 # @ECLASS-VARIABLE: _LLVM_KNOWN_SLOTS
65 # Correct values of LLVM slots, newest first.
66 declare -g -r _LLVM_KNOWN_SLOTS=( 5 4 )
68 # @FUNCTION: get_llvm_prefix
69 # @USAGE: [<max_slot>]
71 # Prints the absolute path to an LLVM install prefix corresponding to
72 # the newest installed version of LLVM that is not newer than
73 # <max_slot>. If no <max_slot> is specified, there is no upper limit.
75 # Note that the function does not support lower-bound version, so you
76 # need to provide correct dependencies to ensure that a new enough
77 # version will be always installed. Otherwise, the function could return
78 # a version lower than required.
80 debug-print-function ${FUNCNAME} "${@}"
84 for slot in "${_LLVM_KNOWN_SLOTS[@]}"; do
86 if [[ -n ${max_slot} ]]; then
87 if [[ ${max_slot} == ${slot} ]]; then
94 local p=${EPREFIX}/usr/lib/llvm/${slot}
95 if [[ -x ${p}/bin/llvm-config ]]; then
101 # max_slot should have been unset in the iteration
102 if [[ -n ${max_slot} ]]; then
103 die "${FUNCNAME}: invalid max_slot=${max_slot}"
107 # assume it's always <= 4 (the lower max_slot allowed)
109 if [[ -x ${p}/bin/llvm-config ]]; then
114 die "No LLVM slot${1:+ <= ${1}} found in PATH!"
117 # @FUNCTION: llvm_pkg_setup
119 # Prepend the executable directory corresponding to the newest
120 # installed LLVM version that is not newer than ${LLVM_MAX_SLOT}
121 # to PATH. If LLVM_MAX_SLOT is unset or empty, the newest installed
124 # The PATH manipulation is only done for source builds. The function
125 # is a no-op when installing a binary package.
127 # If any other behavior is desired, the contents of the function
128 # should be inlined into the ebuild and modified as necessary.
130 debug-print-function ${FUNCNAME} "${@}"
132 if [[ ${MERGE_TYPE} != binary ]]; then
133 export PATH=$(get_llvm_prefix ${LLVM_MAX_SLOT})/bin:${PATH}