1 |
--- |
2 |
eclass/llvm.eclass | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
3 |
1 file changed, 98 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..a0ce616d5b92 |
9 |
--- /dev/null |
10 |
+++ b/eclass/llvm.eclass |
11 |
@@ -0,0 +1,98 @@ |
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/llvm-config |
87 |
+ if [[ -x ${p} ]]; then |
88 |
+ echo "${p}" |
89 |
+ return |
90 |
+ fi |
91 |
+ done |
92 |
+ |
93 |
+ if [[ -n ${max_slot} ]]; then |
94 |
+ die "${FUNCNAME}: invalid max_slot=${max_slot}" |
95 |
+ fi |
96 |
+ |
97 |
+ # fallback to :0 |
98 |
+ # assume it's always <= 4 (the lower max_slot allowed) |
99 |
+ p=${EPREFIX}/usr/bin/llvm-config |
100 |
+ if [[ -x ${p} ]]; then |
101 |
+ echo "${p}" |
102 |
+ return |
103 |
+ fi |
104 |
+ |
105 |
+ die "No LLVM slot${max_slot:+ <= ${max_slot}} found in PATH!" |
106 |
+} |
107 |
+ |
108 |
+_LLVM_ECLASS=1 |
109 |
+fi |
110 |
-- |
111 |
2.11.0 |