1 |
This eclass should be to Lua what python-r1 is to Python. Indeed, most |
2 |
of the plumbing has been shamelessly stolen from that eclass. |
3 |
|
4 |
What works: |
5 |
- support for slotted dev-lang/lua |
6 |
- building and installing Lua modules, for multiple Lua implementations |
7 |
- dependencies on other Lua modules |
8 |
|
9 |
What doesn't work yet: |
10 |
- support for dev-lang/luajit (not in the least because the versions |
11 |
currently in the tree share module directories with dev-lang/lua) |
12 |
- proper support for building against a single Lua target |
13 |
|
14 |
Signed-off-by: Marek Szuba <marecki@g.o> |
15 |
--- |
16 |
eclass/lua.eclass | 710 ++++++++++++++++++++++++++++++++++++++++++++++ |
17 |
1 file changed, 710 insertions(+) |
18 |
create mode 100644 eclass/lua.eclass |
19 |
|
20 |
diff --git a/eclass/lua.eclass b/eclass/lua.eclass |
21 |
new file mode 100644 |
22 |
index 00000000000..1b104b31cda |
23 |
--- /dev/null |
24 |
+++ b/eclass/lua.eclass |
25 |
@@ -0,0 +1,710 @@ |
26 |
+# Copyright 1999-2020 Gentoo Authors |
27 |
+# Distributed under the terms of the GNU General Public License v2 |
28 |
+ |
29 |
+# @ECLASS: lua.eclass |
30 |
+# @MAINTAINER: |
31 |
+# Marek Szuba <marecki@g.o> |
32 |
+# @AUTHOR: |
33 |
+# Marek Szuba <marecki@g.o> |
34 |
+# Based on python{,-utils}-r1.eclass by Michał Górny <mgorny@g.o> et al. |
35 |
+# @SUPPORTED_EAPIS: 7 |
36 |
+# @BLURB: A common eclass for Lua packages |
37 |
+# @DESCRIPTION: |
38 |
+# A common eclass providing helper functions to build and install |
39 |
+# packages supporting being installed for multiple Lua implementations. |
40 |
+# |
41 |
+# This eclass sets correct IUSE. Modification of REQUIRED_USE has to |
42 |
+# be done by the author of the ebuild (but LUA_REQUIRED_USE is |
43 |
+# provided for convenience, see below). The eclass exports LUA_DEPS |
44 |
+# and LUA_USEDEP so you can create correct dependencies for your |
45 |
+# package easily. It also provides methods to easily run a command for |
46 |
+# each enabled Lua implementation and duplicate the sources for them. |
47 |
+# |
48 |
+# Please note that for the time being this eclass does NOT support luajit. |
49 |
+# |
50 |
+# @EXAMPLE: |
51 |
+# @CODE |
52 |
+# EAPI=7 |
53 |
+# |
54 |
+# LUA_COMPAT=( lua5-{1..3} ) |
55 |
+# |
56 |
+# inherit lua |
57 |
+# |
58 |
+# [...] |
59 |
+# |
60 |
+# REQUIRED_USE="${LUA_REQUIRED_USE}" |
61 |
+# DEPEND="${LUA_DEPS}" |
62 |
+# RDEPEND="${DEPEND} |
63 |
+# dev-lua/foo[${LUA_USEDEP}]" |
64 |
+# BDEPEND="virtual/pkgconfig" |
65 |
+# |
66 |
+# lua_src_install() { |
67 |
+# emake LUA_VERSION="$(lua_get_version)" install |
68 |
+# } |
69 |
+# |
70 |
+# src_install() { |
71 |
+# lua_foreach_impl lua_src_install |
72 |
+# } |
73 |
+# @CODE |
74 |
+ |
75 |
+case ${EAPI:-0} in |
76 |
+ 0|1|2|3|4|5|6) |
77 |
+ die "Unsupported EAPI=${EAPI} (too old) for ${ECLASS}" |
78 |
+ ;; |
79 |
+ 7) |
80 |
+ ;; |
81 |
+ *) |
82 |
+ die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}" |
83 |
+ ;; |
84 |
+esac |
85 |
+ |
86 |
+if [[ ! ${_LUA_R0} ]]; then |
87 |
+ |
88 |
+inherit multibuild toolchain-funcs |
89 |
+ |
90 |
+BDEPEND="virtual/pkgconfig" |
91 |
+ |
92 |
+fi |
93 |
+ |
94 |
+# @ECLASS-VARIABLE: LUA_COMPAT |
95 |
+# @REQUIRED |
96 |
+# @PRE_INHERIT |
97 |
+# @DESCRIPTION: |
98 |
+# This variable contains a list of Lua implementations the package |
99 |
+# supports. It must be set before the `inherit' call. It has to be |
100 |
+# an array. |
101 |
+# |
102 |
+# Example: |
103 |
+# @CODE |
104 |
+# LUA_COMPAT=( lua5-1 lua5-2 lua5-3 ) |
105 |
+# @CODE |
106 |
+# |
107 |
+# Please note that you can also use bash brace expansion if you like: |
108 |
+# @CODE |
109 |
+# LUA_COMPAT=( lua5_{1..3} ) |
110 |
+# @CODE |
111 |
+ |
112 |
+# @ECLASS-VARIABLE: LUA_COMPAT_OVERRIDE |
113 |
+# @USER_VARIABLE |
114 |
+# @DEFAULT_UNSET |
115 |
+# @DESCRIPTION: |
116 |
+# This variable can be used when working with ebuilds to override |
117 |
+# the in-ebuild LUA_COMPAT. It is a string listing all |
118 |
+# the implementations which package will be built for. It need be |
119 |
+# specified in the calling environment, and not in ebuilds. |
120 |
+# |
121 |
+# It should be noted that in order to preserve metadata immutability, |
122 |
+# LUA_COMPAT_OVERRIDE does not affect IUSE nor dependencies. |
123 |
+# The state of LUA_TARGETS is ignored, and all the implementations |
124 |
+# in LUA_COMPAT_OVERRIDE are built. Dependencies need to be satisfied |
125 |
+# manually. |
126 |
+# |
127 |
+# Example: |
128 |
+# @CODE |
129 |
+# LUA_COMPAT_OVERRIDE='lua5-2' emerge -1v dev-lua/foo |
130 |
+# @CODE |
131 |
+ |
132 |
+# @ECLASS-VARIABLE: LUA_REQ_USE |
133 |
+# @DEFAULT_UNSET |
134 |
+# @PRE_INHERIT |
135 |
+# @DESCRIPTION: |
136 |
+# The list of USE flags required to be enabled on the chosen Lua |
137 |
+# implementations, formed as a USE-dependency string. It should be valid |
138 |
+# for all implementations in LUA_COMPAT, so it may be necessary to |
139 |
+# use USE defaults. |
140 |
+# This must be set before calling `inherit'. |
141 |
+# |
142 |
+# Example: |
143 |
+# @CODE |
144 |
+# LUA_REQ_USE="deprecated" |
145 |
+# @CODE |
146 |
+# |
147 |
+# It will cause the Lua dependencies to look like: |
148 |
+# @CODE |
149 |
+# lua_targets_luaX-Y? ( dev-lang/lua:X.Y[deprecated] ) |
150 |
+# @CODE |
151 |
+ |
152 |
+# @ECLASS-VARIABLE: BUILD_DIR |
153 |
+# @OUTPUT_VARIABLE |
154 |
+# @DEFAULT_UNSET |
155 |
+# @DESCRIPTION: |
156 |
+# The current build directory. In global scope, it is supposed to |
157 |
+# contain an initial build directory; if unset, it defaults to ${S}. |
158 |
+# |
159 |
+# In functions run by lua_foreach_impl(), the BUILD_DIR is locally |
160 |
+# set to an implementation-specific build directory. That path is |
161 |
+# created through appending a hyphen and the implementation name |
162 |
+# to the final component of the initial BUILD_DIR. |
163 |
+# |
164 |
+# Example value: |
165 |
+# @CODE |
166 |
+# ${WORKDIR}/foo-1.3-lua5-1 |
167 |
+# @CODE |
168 |
+ |
169 |
+# @ECLASS-VARIABLE: ELUA |
170 |
+# @DEFAULT_UNSET |
171 |
+# @DESCRIPTION: |
172 |
+# The executable name of the current Lua interpreter. This variable is set |
173 |
+# automatically in functions called by lua_foreach_impl(). |
174 |
+# |
175 |
+# Example value: |
176 |
+# @CODE |
177 |
+# lua5.1 |
178 |
+# @CODE |
179 |
+ |
180 |
+# @ECLASS-VARIABLE: LUA |
181 |
+# @DEFAULT_UNSET |
182 |
+# @DESCRIPTION: |
183 |
+# The absolute path to the current Lua interpreter. This variable is set |
184 |
+# automatically in functions called by lua_foreach_impl(). |
185 |
+# |
186 |
+# Example value: |
187 |
+# @CODE |
188 |
+# /usr/bin/lua5.1 |
189 |
+# @CODE |
190 |
+ |
191 |
+# @ECLASS-VARIABLE: LUA_DEPS |
192 |
+# @OUTPUT_VARIABLE |
193 |
+# @DESCRIPTION: |
194 |
+# This is an eclass-generated Lua dependency string for all |
195 |
+# implementations listed in LUA_COMPAT. |
196 |
+# |
197 |
+# Example use: |
198 |
+# @CODE |
199 |
+# RDEPEND="${LUA_DEPS} |
200 |
+# dev-foo/mydep" |
201 |
+# DEPEND="${RDEPEND}" |
202 |
+# @CODE |
203 |
+# |
204 |
+# Example value: |
205 |
+# @CODE |
206 |
+# lua_targets_lua5-1? ( dev-lang/lua:5.1 ) |
207 |
+# lua_targets_lua5-2? ( dev-lang/lua:5.2 ) |
208 |
+# @CODE |
209 |
+ |
210 |
+# @ECLASS-VARIABLE: LUA_REQUIRED_USE |
211 |
+# @OUTPUT_VARIABLE |
212 |
+# @DESCRIPTION: |
213 |
+# This is an eclass-generated required-use expression which ensures at |
214 |
+# least one Lua implementation has been enabled. |
215 |
+# |
216 |
+# This expression should be utilized in an ebuild by including it in |
217 |
+# REQUIRED_USE, optionally behind a use flag. |
218 |
+# |
219 |
+# Example use: |
220 |
+# @CODE |
221 |
+# REQUIRED_USE="lua? ( ${LUA_REQUIRED_USE} )" |
222 |
+# @CODE |
223 |
+# |
224 |
+# Example value: |
225 |
+# @CODE |
226 |
+# || ( lua_targets_lua5-1 lua_targets_lua5-2 ) |
227 |
+# @CODE |
228 |
+ |
229 |
+# @ECLASS-VARIABLE: LUA_USEDEP |
230 |
+# @OUTPUT_VARIABLE |
231 |
+# @DESCRIPTION: |
232 |
+# This is an eclass-generated USE-dependency string which can be used to |
233 |
+# depend on another Lua package being built for the same Lua |
234 |
+# implementations. |
235 |
+# |
236 |
+# Example use: |
237 |
+# @CODE |
238 |
+# RDEPEND="dev-lua/foo[${LUA_USEDEP}]" |
239 |
+# @CODE |
240 |
+# |
241 |
+# Example value: |
242 |
+# @CODE |
243 |
+# lua_targets_lua5-1(-)?,lua_targets_lua5-2(-)? |
244 |
+# @CODE |
245 |
+ |
246 |
+if [[ ! ${_LUA_R0} ]]; then |
247 |
+ |
248 |
+# @FUNCTION: _lua_export |
249 |
+# @USAGE: [<impl>] <variables>... |
250 |
+# @INTERNAL |
251 |
+# @DESCRIPTION: |
252 |
+# Set and export the Lua implementation-relevant variables passed |
253 |
+# as parameters. |
254 |
+# |
255 |
+# The optional first parameter may specify the requested Lua |
256 |
+# implementation (either as LUA_TARGETS value, e.g. lua5-2, |
257 |
+# or an ELUA one, e.g. lua5.2). If no implementation passed, |
258 |
+# the current one will be obtained from ${ELUA}. |
259 |
+_lua_export() { |
260 |
+ debug-print-function ${FUNCNAME} "${@}" |
261 |
+ |
262 |
+ local impl var |
263 |
+ |
264 |
+ case "${1}" in |
265 |
+ lua*) |
266 |
+ impl=${1/-/.} |
267 |
+ shift |
268 |
+ ;; |
269 |
+ *) |
270 |
+ impl=${ELUA} |
271 |
+ if [[ -z ${impl} ]]; then |
272 |
+ die "_lua_export called without a Lua implementation and ELUA is unset" |
273 |
+ fi |
274 |
+ ;; |
275 |
+ esac |
276 |
+ debug-print "${FUNCNAME}: implementation: ${impl}" |
277 |
+ |
278 |
+ for var; do |
279 |
+ case "${var}" in |
280 |
+ ELUA) |
281 |
+ export ELUA=${impl} |
282 |
+ debug-print "${FUNCNAME}: ELUA = ${ELUA}" |
283 |
+ ;; |
284 |
+ LUA) |
285 |
+ export LUA="${EPREFIX}"/usr/bin/${impl} |
286 |
+ debug-print "${FUNCNAME}: LUA = ${LUA}" |
287 |
+ ;; |
288 |
+ LUA_CFLAGS) |
289 |
+ local val |
290 |
+ |
291 |
+ val=$($(tc-getPKG_CONFIG) --cflags ${impl}) || die |
292 |
+ |
293 |
+ export LUA_CFLAGS=${val} |
294 |
+ debug-print "${FUNCNAME}: LUA_CFLAGS = ${LUA_CFLAGS}" |
295 |
+ ;; |
296 |
+ LUA_CMOD_DIR) |
297 |
+ local val |
298 |
+ |
299 |
+ val=$($(tc-getPKG_CONFIG) --variable INSTALL_CMOD ${impl}) || die |
300 |
+ |
301 |
+ export LUA_CMOD_DIR=${val} |
302 |
+ debug-print "${FUNCNAME}: LUA_CMOD_DIR = ${LUA_CMOD_DIR}" |
303 |
+ ;; |
304 |
+ LUA_LIBS) |
305 |
+ local val |
306 |
+ |
307 |
+ val=$($(tc-getPKG_CONFIG) --libs ${impl}) || die |
308 |
+ |
309 |
+ export LUA_LIBS=${val} |
310 |
+ debug-print "${FUNCNAME}: LUA_LIBS = ${LUA_LIBS}" |
311 |
+ ;; |
312 |
+ LUA_LMOD_DIR) |
313 |
+ local val |
314 |
+ |
315 |
+ val=$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD ${impl}) || die |
316 |
+ |
317 |
+ export LUA_LMOD_DIR=${val} |
318 |
+ debug-print "${FUNCNAME}: LUA_LMOD_DIR = ${LUA_LMOD_DIR}" |
319 |
+ ;; |
320 |
+ LUA_PKG_DEP) |
321 |
+ local d |
322 |
+ case ${impl} in |
323 |
+ lua*) |
324 |
+ LUA_PKG_DEP="dev-lang/lua:${impl#lua}" |
325 |
+ ;; |
326 |
+ *) |
327 |
+ die "Invalid implementation: ${impl}" |
328 |
+ ;; |
329 |
+ esac |
330 |
+ |
331 |
+ # use-dep |
332 |
+ if [[ ${LUA_REQ_USE} ]]; then |
333 |
+ LUA_PKG_DEP+=[${LUA_REQ_USE}] |
334 |
+ fi |
335 |
+ |
336 |
+ export LUA_PKG_DEP |
337 |
+ debug-print "${FUNCNAME}: LUA_PKG_DEP = ${LUA_PKG_DEP}" |
338 |
+ ;; |
339 |
+ LUA_VERSION) |
340 |
+ local val |
341 |
+ |
342 |
+ val=$($(tc-getPKG_CONFIG) --modversion ${impl}) || die |
343 |
+ |
344 |
+ export LUA_VERSION=${val} |
345 |
+ debug-print "${FUNCNAME}: LUA_VERSION = ${LUA_VERSION}" |
346 |
+ ;; |
347 |
+ *) |
348 |
+ die "_lua_export: unknown variable ${var}" |
349 |
+ ;; |
350 |
+ esac |
351 |
+ done |
352 |
+} |
353 |
+ |
354 |
+# @FUNCTION: _lua_validate_useflags |
355 |
+# @INTERNAL |
356 |
+# @DESCRIPTION: |
357 |
+# Enforce the proper setting of LUA_TARGETS, if LUA_COMPAT_OVERRIDE |
358 |
+# is not in effect. If it is, just warn that the flags will be ignored. |
359 |
+_lua_validate_useflags() { |
360 |
+ debug-print-function ${FUNCNAME} "${@}" |
361 |
+ |
362 |
+ if [[ ${LUA_COMPAT_OVERRIDE} ]]; then |
363 |
+ if [[ ! ${_LUA_COMPAT_OVERRIDE_WARNED} ]]; then |
364 |
+ ewarn "WARNING: LUA_COMPAT_OVERRIDE in effect. The following Lua" |
365 |
+ ewarn "implementations will be enabled:" |
366 |
+ ewarn |
367 |
+ ewarn " ${LUA_COMPAT_OVERRIDE}" |
368 |
+ ewarn |
369 |
+ ewarn "Dependencies won't be satisfied, and LUA_TARGETS will be ignored." |
370 |
+ _LUA_COMPAT_OVERRIDE_WARNED=1 |
371 |
+ fi |
372 |
+ # we do not use flags with LCO |
373 |
+ return |
374 |
+ fi |
375 |
+ |
376 |
+ local i |
377 |
+ |
378 |
+ for i in "${_LUA_SUPPORTED_IMPLS[@]}"; do |
379 |
+ use "lua_targets_${i}" && return 0 |
380 |
+ done |
381 |
+ |
382 |
+ eerror "No Lua implementation selected for the build. Please add one" |
383 |
+ eerror "of the following values to your LUA_TARGETS (in make.conf):" |
384 |
+ eerror |
385 |
+ eerror "${LUA_COMPAT[@]}" |
386 |
+ echo |
387 |
+ die "No supported Lua implementation in LUA_TARGETS." |
388 |
+} |
389 |
+ |
390 |
+# @FUNCTION: _lua_obtain_impls |
391 |
+# @INTERNAL |
392 |
+# @DESCRIPTION: |
393 |
+# Set up the enabled implementation list. |
394 |
+_lua_obtain_impls() { |
395 |
+ _lua_validate_useflags |
396 |
+ |
397 |
+ if [[ ${LUA_COMPAT_OVERRIDE} ]]; then |
398 |
+ MULTIBUILD_VARIANTS=( ${LUA_COMPAT_OVERRIDE} ) |
399 |
+ return |
400 |
+ fi |
401 |
+ |
402 |
+ MULTIBUILD_VARIANTS=() |
403 |
+ |
404 |
+ local impl |
405 |
+ for impl in "${_LUA_SUPPORTED_IMPLS[@]}"; do |
406 |
+ has "${impl}" "${LUA_COMPAT[@]}" && \ |
407 |
+ use "lua_targets_${impl}" && MULTIBUILD_VARIANTS+=( "${impl}" ) |
408 |
+ done |
409 |
+} |
410 |
+ |
411 |
+ |
412 |
+# @FUNCTION: _lua_multibuild_wrapper |
413 |
+# @USAGE: <command> [<args>...] |
414 |
+# @INTERNAL |
415 |
+# @DESCRIPTION: |
416 |
+# Initialize the environment for the Lua implementation selected |
417 |
+# for multibuild. |
418 |
+_lua_multibuild_wrapper() { |
419 |
+ debug-print-function ${FUNCNAME} "${@}" |
420 |
+ |
421 |
+ local -x ELUA LUA |
422 |
+ _lua_export "${MULTIBUILD_VARIANT}" ELUA LUA |
423 |
+ local -x PATH=${PATH} PKG_CONFIG_PATH=${PKG_CONFIG_PATH} |
424 |
+ _lua_wrapper_setup |
425 |
+ |
426 |
+ "${@}" |
427 |
+} |
428 |
+ |
429 |
+# @FUNCTION: _lua_wrapper_setup |
430 |
+# @USAGE: [<path> [<impl>]] |
431 |
+# @INTERNAL |
432 |
+# @DESCRIPTION: |
433 |
+# Create proper 'lua' executable and pkg-config wrappers |
434 |
+# (if available) in the directory named by <path>. Set up PATH |
435 |
+# and PKG_CONFIG_PATH appropriately. <path> defaults to ${T}/${ELUA}. |
436 |
+# |
437 |
+# The wrappers will be created for implementation named by <impl>, |
438 |
+# or for one named by ${ELUA} if no <impl> passed. |
439 |
+# |
440 |
+# If the named directory contains a lua symlink already, it will |
441 |
+# be assumed to contain proper wrappers already and only environment |
442 |
+# setup will be done. If wrapper update is requested, the directory |
443 |
+# shall be removed first. |
444 |
+_lua_wrapper_setup() { |
445 |
+ debug-print-function ${FUNCNAME} "${@}" |
446 |
+ |
447 |
+ local workdir=${1:-${T}/${ELUA}} |
448 |
+ local impl=${2:-${ELUA}} |
449 |
+ |
450 |
+ [[ ${workdir} ]] || die "${FUNCNAME}: no workdir specified." |
451 |
+ [[ ${impl} ]] || die "${FUNCNAME}: no impl nor ELUA specified." |
452 |
+ |
453 |
+ if [[ ! -x ${workdir}/bin/lua ]]; then |
454 |
+ mkdir -p "${workdir}"/{bin,pkgconfig} || die |
455 |
+ |
456 |
+ # Clean up, in case we were supposed to do a cheap update |
457 |
+ rm -f "${workdir}"/bin/lua{,c} || die |
458 |
+ rm -f "${workdir}"/pkgconfig/lua.pc || die |
459 |
+ |
460 |
+ local ELUA LUA |
461 |
+ _lua_export "${impl}" ELUA LUA |
462 |
+ |
463 |
+ # Lua interpreter and compiler |
464 |
+ ln -s "${EPREFIX}"/usr/bin/${ELUA} "${workdir}"/bin/lua || die |
465 |
+ ln -s "${EPREFIX}"/usr/bin/${ELUA/a/ac} "${workdir}"/bin/luac || die |
466 |
+ |
467 |
+ # pkg-config |
468 |
+ ln -s "${EPREFIX}"/usr/$(get_libdir)/pkgconfig/${ELUA}.pc \ |
469 |
+ "${workdir}"/pkgconfig/lua.pc || die |
470 |
+ fi |
471 |
+ |
472 |
+ # Now, set the environment. |
473 |
+ # But note that ${workdir} may be shared with something else, |
474 |
+ # and thus already on top of PATH. |
475 |
+ if [[ ${PATH##:*} != ${workdir}/bin ]]; then |
476 |
+ PATH=${workdir}/bin${PATH:+:${PATH}} |
477 |
+ fi |
478 |
+ if [[ ${PKG_CONFIG_PATH##:*} != ${workdir}/pkgconfig ]]; then |
479 |
+ PKG_CONFIG_PATH=${workdir}/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}} |
480 |
+ fi |
481 |
+ export PATH PKG_CONFIG_PATH |
482 |
+} |
483 |
+ |
484 |
+# @FUNCTION: lua_copy_sources |
485 |
+# @DESCRIPTION: |
486 |
+# Create a single copy of the package sources for each enabled Lua |
487 |
+# implementation. |
488 |
+# |
489 |
+# The sources are always copied from initial BUILD_DIR (or S if unset) |
490 |
+# to implementation-specific build directory matching BUILD_DIR used by |
491 |
+# lua_foreach_abi(). |
492 |
+lua_copy_sources() { |
493 |
+ debug-print-function ${FUNCNAME} "${@}" |
494 |
+ |
495 |
+ local MULTIBUILD_VARIANTS |
496 |
+ _lua_obtain_impls |
497 |
+ |
498 |
+ multibuild_copy_sources |
499 |
+} |
500 |
+ |
501 |
+# @FUNCTION: lua_foreach_impl |
502 |
+# @USAGE: <command> [<args>...] |
503 |
+# @DESCRIPTION: |
504 |
+# Run the given command for each of the enabled Lua implementations. |
505 |
+# If additional parameters are passed, they will be passed through |
506 |
+# to the command. |
507 |
+# |
508 |
+# The function will return 0 status if all invocations succeed. |
509 |
+# Otherwise, the return code from first failing invocation will |
510 |
+# be returned. |
511 |
+# |
512 |
+# For each command being run, ELUA, LUA and BUILD_DIR are set |
513 |
+# locally, and the former two are exported to the command environment. |
514 |
+lua_foreach_impl() { |
515 |
+ debug-print-function ${FUNCNAME} "${@}" |
516 |
+ |
517 |
+ local MULTIBUILD_VARIANTS |
518 |
+ _lua_obtain_impls |
519 |
+ |
520 |
+ multibuild_foreach_variant _lua_multibuild_wrapper "${@}" |
521 |
+} |
522 |
+ |
523 |
+# @FUNCTION: lua_get_CFLAGS |
524 |
+# @USAGE: [<impl>] |
525 |
+# @DESCRIPTION: |
526 |
+# Obtain and print the compiler flags for building against Lua, |
527 |
+# for the given implementation. If no implementation is provided, |
528 |
+# ${ELUA} will be used. |
529 |
+# |
530 |
+# Please note that this function requires Lua and pkg-config installed, |
531 |
+# and therefore proper build-time dependencies need be added to the ebuild. |
532 |
+lua_get_CFLAGS() { |
533 |
+ debug-print-function ${FUNCNAME} "${@}" |
534 |
+ |
535 |
+ _lua_export "${@}" LUA_CFLAGS |
536 |
+ echo "${LUA_CFLAGS}" |
537 |
+} |
538 |
+ |
539 |
+# @FUNCTION: lua_get_cmod_dir |
540 |
+# @USAGE: [<impl>] |
541 |
+# @DESCRIPTION: |
542 |
+# Obtain and print the name of the directory into which compiled Lua |
543 |
+# modules are installed, for the given implementation. If no implementation |
544 |
+# is provided, ${ELUA} will be used. |
545 |
+# |
546 |
+# Please note that this function requires Lua and pkg-config installed, |
547 |
+# and therefore proper build-time dependencies need be added to the ebuild. |
548 |
+lua_get_cmod_dir() { |
549 |
+ debug-print-function ${FUNCNAME} "${@}" |
550 |
+ |
551 |
+ _lua_export "${@}" LUA_CMOD_DIR |
552 |
+ echo "${LUA_CMOD_DIR}" |
553 |
+} |
554 |
+ |
555 |
+# @FUNCTION: lua_get_LIBS |
556 |
+# @USAGE: [<impl>] |
557 |
+# @DESCRIPTION: |
558 |
+# Obtain and print the compiler flags for linking against Lua, |
559 |
+# for the given implementation. If no implementation is provided, |
560 |
+# ${ELUA} will be used. |
561 |
+# |
562 |
+# Please note that this function requires Lua and pkg-config installed, |
563 |
+# and therefore proper build-time dependencies need be added to the ebuild. |
564 |
+lua_get_LIBS() { |
565 |
+ debug-print-function ${FUNCNAME} "${@}" |
566 |
+ |
567 |
+ _lua_export "${@}" LUA_LIBS |
568 |
+ echo "${LUA_LIBS}" |
569 |
+} |
570 |
+ |
571 |
+# @FUNCTION: lua_get_lmod_dir |
572 |
+# @USAGE: [<impl>] |
573 |
+# @DESCRIPTION: |
574 |
+# Obtain and print the name of the directory into which native-Lua |
575 |
+# modules are installed, for the given implementation. If no implementation |
576 |
+# is provided, ${ELUA} will be used. |
577 |
+# |
578 |
+# Please note that this function requires Lua and pkg-config installed, |
579 |
+# and therefore proper build-time dependencies need be added to the ebuild. |
580 |
+lua_get_lmod_dir() { |
581 |
+ debug-print-function ${FUNCNAME} "${@}" |
582 |
+ |
583 |
+ _lua_export "${@}" LUA_LMOD_DIR |
584 |
+ echo "${LUA_LMOD_DIR}" |
585 |
+} |
586 |
+ |
587 |
+# @FUNCTION: lua_get_version |
588 |
+# @USAGE: [<impl>] |
589 |
+# @DESCRIPTION: |
590 |
+# Obtain and print the full version number of the given Lua implementation. |
591 |
+# If no implementation is provided, ${ELUA} will be used. |
592 |
+# |
593 |
+# Please note that this function requires Lua and pkg-config installed, |
594 |
+# and therefore proper build-time dependencies need be added to the ebuild. |
595 |
+lua_get_version() { |
596 |
+ debug-print-function ${FUNCNAME} "${@}" |
597 |
+ |
598 |
+ _lua_export "${@}" LUA_VERSION |
599 |
+ echo "${LUA_VERSION}" |
600 |
+} |
601 |
+ |
602 |
+_LUA_R0=1 |
603 |
+fi |
604 |
+ |
605 |
+# @ECLASS-VARIABLE: _LUA_ALL_IMPLS |
606 |
+# @INTERNAL |
607 |
+# @DESCRIPTION: |
608 |
+# All supported Lua implementations, most preferred last |
609 |
+_LUA_ALL_IMPLS=( |
610 |
+ lua5-1 |
611 |
+ lua5-2 |
612 |
+ lua5-3 |
613 |
+ lua5-4 |
614 |
+) |
615 |
+readonly _LUA_ALL_IMPLS |
616 |
+ |
617 |
+# @FUNCTION: _lua_set_impls |
618 |
+# @INTERNAL |
619 |
+# @DESCRIPTION: |
620 |
+# Check LUA_COMPAT for well-formedness and validity, then set |
621 |
+# two global variables: |
622 |
+# |
623 |
+# - _LUA_SUPPORTED_IMPLS containing valid implementations supported |
624 |
+# by the ebuild (LUA_COMPAT - dead implementations), |
625 |
+# |
626 |
+# - and _LUA_UNSUPPORTED_IMPLS containing valid implementations that |
627 |
+# are not supported by the ebuild. |
628 |
+# |
629 |
+# Implementations in both variables are ordered using the pre-defined |
630 |
+# eclass implementation ordering. |
631 |
+# |
632 |
+# This function must only be called once. |
633 |
+_lua_set_impls() { |
634 |
+ local i |
635 |
+ |
636 |
+ if ! declare -p LUA_COMPAT &>/dev/null; then |
637 |
+ die 'LUA_COMPAT not declared.' |
638 |
+ fi |
639 |
+ if [[ $(declare -p LUA_COMPAT) != "declare -a"* ]]; then |
640 |
+ die 'LUA_COMPAT must be an array.' |
641 |
+ fi |
642 |
+ |
643 |
+ local supp=() unsupp=() |
644 |
+ |
645 |
+ for i in "${_LUA_ALL_IMPLS[@]}"; do |
646 |
+ if has "${i}" "${LUA_COMPAT[@]}"; then |
647 |
+ supp+=( "${i}" ) |
648 |
+ else |
649 |
+ unsupp+=( "${i}" ) |
650 |
+ fi |
651 |
+ done |
652 |
+ |
653 |
+ if [[ ! ${supp[@]} ]]; then |
654 |
+ die "No supported implementation in LUA_COMPAT." |
655 |
+ fi |
656 |
+ |
657 |
+ if [[ ${_LUA_SUPPORTED_IMPLS[@]} ]]; then |
658 |
+ # set once already, verify integrity |
659 |
+ if [[ ${_LUA_SUPPORTED_IMPLS[@]} != ${supp[@]} ]]; then |
660 |
+ eerror "Supported impls (LUA_COMPAT) changed between inherits!" |
661 |
+ eerror "Before: ${_LUA_SUPPORTED_IMPLS[*]}" |
662 |
+ eerror "Now : ${supp[*]}" |
663 |
+ die "_LUA_SUPPORTED_IMPLS integrity check failed" |
664 |
+ fi |
665 |
+ if [[ ${_LUA_UNSUPPORTED_IMPLS[@]} != ${unsupp[@]} ]]; then |
666 |
+ eerror "Unsupported impls changed between inherits!" |
667 |
+ eerror "Before: ${_LUA_UNSUPPORTED_IMPLS[*]}" |
668 |
+ eerror "Now : ${unsupp[*]}" |
669 |
+ die "_LUA_UNSUPPORTED_IMPLS integrity check failed" |
670 |
+ fi |
671 |
+ else |
672 |
+ _LUA_SUPPORTED_IMPLS=( "${supp[@]}" ) |
673 |
+ _LUA_UNSUPPORTED_IMPLS=( "${unsupp[@]}" ) |
674 |
+ readonly _LUA_SUPPORTED_IMPLS _LUA_UNSUPPORTED_IMPLS |
675 |
+ fi |
676 |
+} |
677 |
+ |
678 |
+# @FUNCTION: _lua_set_globals |
679 |
+# @INTERNAL |
680 |
+# @DESCRIPTION: |
681 |
+# Sets all the global output variables provided by this eclass. |
682 |
+# This function must be called once, in global scope. |
683 |
+_lua_set_globals() { |
684 |
+ local deps i LUA_PKG_DEP |
685 |
+ |
686 |
+ _lua_set_impls |
687 |
+ |
688 |
+ for i in "${_LUA_SUPPORTED_IMPLS[@]}"; do |
689 |
+ _lua_export "${i}" LUA_PKG_DEP |
690 |
+ deps+="lua_targets_${i}? ( ${LUA_PKG_DEP} ) " |
691 |
+ done |
692 |
+ |
693 |
+ local flags=( "${_LUA_SUPPORTED_IMPLS[@]/#/lua_targets_}" ) |
694 |
+ local optflags=${flags[@]/%/(-)?} |
695 |
+ |
696 |
+ local requse="|| ( ${flags[*]} )" |
697 |
+ local usedep=${optflags// /,} |
698 |
+ |
699 |
+ if [[ ${LUA_DEPS+1} ]]; then |
700 |
+ # IUSE is magical, so we can't really check it |
701 |
+ # (but we verify LUA_COMPAT already) |
702 |
+ |
703 |
+ if [[ ${LUA_DEPS} != "${deps}" ]]; then |
704 |
+ eerror "LUA_DEPS have changed between inherits (LUA_REQ_USE?)!" |
705 |
+ eerror "Before: ${LUA_DEPS}" |
706 |
+ eerror "Now : ${deps}" |
707 |
+ die "LUA_DEPS integrity check failed" |
708 |
+ fi |
709 |
+ |
710 |
+ # these two are formality -- they depend on LUA_COMPAT only |
711 |
+ if [[ ${LUA_REQUIRED_USE} != ${requse} ]]; then |
712 |
+ eerror "LUA_REQUIRED_USE have changed between inherits!" |
713 |
+ eerror "Before: ${LUA_REQUIRED_USE}" |
714 |
+ eerror "Now : ${requse}" |
715 |
+ die "LUA_REQUIRED_USE integrity check failed" |
716 |
+ fi |
717 |
+ |
718 |
+ if [[ ${LUA_USEDEP} != "${usedep}" ]]; then |
719 |
+ eerror "LUA_USEDEP have changed between inherits!" |
720 |
+ eerror "Before: ${LUA_USEDEP}" |
721 |
+ eerror "Now : ${usedep}" |
722 |
+ die "LUA_USEDEP integrity check failed" |
723 |
+ fi |
724 |
+ else |
725 |
+ IUSE=${flags[*]} |
726 |
+ |
727 |
+ LUA_DEPS=${deps} |
728 |
+ LUA_REQUIRED_USE=${requse} |
729 |
+ LUA_USEDEP=${usedep} |
730 |
+ readonly LUA_DEPS LUA_REQUIRED_USE |
731 |
+ fi |
732 |
+} |
733 |
+ |
734 |
+_lua_set_globals |
735 |
+unset -f _lua_set_globals _lua_set_impls |
736 |
-- |
737 |
2.26.2 |