1 # Copyright 1999-2020 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: lua-utils-alt.eclass
8 # S. Gilles <sgilles@math.umd.edu>
9 # Based on work of: Michał Górny <mgorny@gentoo.org>
10 # Based on work of: Krzysztof Pawlik <nelchael@gentoo.org>
11 # @SUPPORTED_EAPIS: 6 7
12 # @BLURB: Utility functions for packages with Lua parts.
14 # A utility class providing functions to query Lua implementations
16 # This eclass does not export any phase functions.
18 # This eclass sets correct IUSE. Modification of REQUIRED_USE has
19 # to be done by the author of the ebuild.
23 die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
28 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
34 inherit toolchain-funcs
36 # @ECLASS-VARIABLE: LUA_COMPAT
39 # This variable contains a list of Lua implementations the package
40 # supports. It must be set before the `inherit' call. It has to be
45 # LUA_COMPAT=( lua5_4 lua5_3 luajit2 )
48 # @ECLASS-VARIABLE: _LUA_ALL_IMPLS
51 # All supported Lua implementations
52 _LUA_ALL_IMPLS=( luajit2 lua5_1 lua5_2 lua5_3 lua5_4 )
53 readonly _LUA_ALL_IMPLS
55 # @FUNCTION _lua_package_from_target
58 # Given "lua5_3", return "dev-lang/lua:5.3" or such
59 _lua_package_from_target() {
60 [ "$1" == "lua5_4" ] && echo "dev-lang/lua:5.4"
61 [ "$1" == "lua5_3" ] && echo "dev-lang/lua:5.3"
62 [ "$1" == "lua5_2" ] && echo "dev-lang/lua:5.2"
63 [ "$1" == "lua5_1" ] && echo "dev-lang/lua:5.1"
64 [ "$1" == "luajit2" ] && echo "dev-lang/luajit:2"
67 # @FUNCTION: _lua_pkgconfig_from_target
70 # Given a name from LUA_COMPAT, return the appropriate name for pkg-config
71 _lua_pkgconfig_from_target() {
72 [ "$1" == "lua5_4" ] && echo "lua5.4"
73 [ "$1" == "lua5_3" ] && echo "lua5.3"
74 [ "$1" == "lua5_2" ] && echo "lua5.2"
75 [ "$1" == "lua5_1" ] && echo "lua5.1"
76 [ "$1" == "luajit2" ] && echo "luajit"
79 # @FUNCTION: _lua_set_impls
82 # Check LUA_COMPAT for well-formedness and validity, then set
83 # _LUA_IMPLS to be the intersection of LUA_COMPAT and _LUA_ALL_IMPLS.
86 debug-print-function ${FUNCNAME} "${@}"
89 if ! declare -p LUA_COMPAT &>/dev/null; then
90 die 'LUA_COMPAT not declared.'
92 if [[ $(declare -p LUA_COMPAT) != "declare -a"* ]]; then
93 die 'LUA_COMPAT must be an array.'
98 for i in "${_LUA_ALL_IMPLS[@]}"; do
99 if has "${i}" "${LUA_COMPAT[@]}"; then
100 _LUA_IMPLS+=( "${i}" )
104 if [[ ! ${_LUA_IMPLS[@]} ]]; then
105 die "No supported implementation in LUA_COMPAT."
108 for i in "${_LUA_IMPLS[@]}"; do
109 deps+="lua_targets_${i}? ( $(_lua_package_from_target ${i}) ) "
112 local flags=( "${_LUA_ALL_IMPLS[@]/#/lua_targets_}" )
113 local requse="|| ( ${flags[*]} )"
116 for (( i = ${#_LUA_ALL_IMPLS[@]} - 1; i >= 0; i-- )); do
117 f+=( "lua_targets_${_LUA_ALL_IMPLS[i]}" )
122 LUA_REQUIRED_USE=${requse}
123 readonly LUA_DEPS LUA_REQUIRED_USE
126 unset -f _lua_set_globals