Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH v2] llvm.eclass: An eclass to handle dependencies on slotted LLVM
Date: Mon, 30 Jan 2017 22:19:58
Message-Id: 20170130221927.19076-1-mgorny@gentoo.org
In Reply to: [gentoo-dev] [PATCH] llvm.eclass: An eclass to handle dependencies on slotted LLVM by "Michał Górny"
1 ---
2 eclass/llvm.eclass | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++
3 1 file changed, 106 insertions(+)
4 create mode 100644 eclass/llvm.eclass
5
6 diff --git a/eclass/llvm.eclass b/eclass/llvm.eclass
7 new file mode 100644
8 index 000000000000..8c001fdbdb97
9 --- /dev/null
10 +++ b/eclass/llvm.eclass
11 @@ -0,0 +1,106 @@
12 +# Copyright 1999-2017 Gentoo Foundation
13 +# Distributed under the terms of the GNU General Public License v2
14 +# $Id$
15 +
16 +# @ECLASS: llvm.eclass
17 +# @MAINTAINER:
18 +# Michał Górny <mgorny@g.o>
19 +# @AUTHOR:
20 +# Michał Górny <mgorny@g.o>
21 +# @BLURB: Utility functions to build against slotted LLVM
22 +# @DESCRIPTION:
23 +# The llvm.eclass provides utility functions that can be used to build
24 +# against specific version of slotted LLVM (with fallback to :0 for old
25 +# versions).
26 +#
27 +# This eclass does not generate dependency strings. You need to write
28 +# a proper dependency string yourself to guarantee that appropriate
29 +# version of LLVM is installed.
30 +#
31 +# Example use for a package supporting LLVM 3.8 to 5:
32 +# @CODE
33 +# inherit cmake-utils llvm
34 +#
35 +# RDEPEND="
36 +# <sys-devel/llvm-6_rc:=
37 +# || (
38 +# sys-devel/llvm:5
39 +# sys-devel/llvm:4
40 +# >=sys-devel/llvm-3.8:0
41 +# )
42 +# "
43 +#
44 +# src_configure() {
45 +# local mycmakeargs=(
46 +# -DLLVM_CONFIG="$(get_llvm_config 5)"
47 +# )
48 +# cmake-utils_src_configure
49 +# }
50 +# @CODE
51 +
52 +if [[ ! ${_LLVM_ECLASS} ]]; then
53 +
54 +# @ECLASS-VARIABLE: _LLVM_KNOWN_SLOTS
55 +# @INTERNAL
56 +# @DESCRIPTION:
57 +# Correct values of LLVM slots, newest first.
58 +declare -g -r _LLVM_KNOWN_SLOTS=( 5 4 )
59 +
60 +# @FUNCTION: get_llvm_config
61 +# @USAGE: [<max_slot>]
62 +# @DESCRIPTION:
63 +# Prints path to llvm-config executable for the newest matching version
64 +# of LLVM. If <max_slot> is provided, then no version newer than
65 +# the specified slot will be used. If it is not, the newest installed
66 +# version will be used.
67 +#
68 +# Note that the function does not support lower-bound version, so you
69 +# need to set proper dependencies. Otherwise, the function can return
70 +# a lower LLVM version than required.
71 +get_llvm_config() {
72 + debug-print-function ${FUNCNAME} "${@}"
73 +
74 + local max_slot=${1}
75 + local slot
76 + for slot in "${_LLVM_KNOWN_SLOTS[@]}"; do
77 + # skip higher slots
78 + if [[ -n ${max_slot} ]]; then
79 + if [[ ${max_slot} == ${slot} ]]; then
80 + max_slot=
81 + else
82 + continue
83 + fi
84 + fi
85 +
86 + local p=${EPREFIX}/usr/lib/llvm/${slot}/bin
87 + if [[ -x ${p}/llvm-config ]]; then
88 + if [[ -n ${CHOST} && -x ${p}/${CHOST}-llvm-config ]]; then
89 + echo "${p}/${CHOST}-llvm-config"
90 + else
91 + echo "${p}/llvm-config"
92 + fi
93 + return
94 + fi
95 + done
96 +
97 + if [[ -n ${max_slot} ]]; then
98 + die "${FUNCNAME}: invalid max_slot=${max_slot}"
99 + fi
100 +
101 + # fallback to :0
102 + # assume it's always <= 4 (the lower max_slot allowed)
103 + p=${EPREFIX}/usr/bin
104 + if [[ -x ${p}/llvm-config ]]; then
105 + if [[ -n ${CHOST} && -x ${p}/${CHOST}-llvm-config ]]; then
106 + echo "${p}/${CHOST}-llvm-config"
107 + else
108 + echo "${p}/llvm-config"
109 + fi
110 + return
111 + fi
112 +
113 + die "No LLVM slot${1:+ <= ${1}} found in PATH!"
114 +}
115 +
116 +_LLVM_ECLASS=1
117 +fi
118 --
119 2.11.0