app-text/sile: bump to 0.10.5
[lua-alt-overlay.git] / eclass / lua-utils-alt.eclass
blob342c24b9d16f150b8f2e70517cbc90cbdfae8244
1 # Copyright 1999-2020 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: lua-utils-alt.eclass
5 # @MAINTAINER:
6 # ???????
7 # @AUTHOR:
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.
13 # @DESCRIPTION:
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.
21 case "${EAPI:-0}" in
22         0|1|2|3|4|5)
23                 die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
24                 ;;
25         6|7)
26                 ;;
27         *)
28                 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
29                 ;;
30 esac
33 inherit multibuild
34 inherit toolchain-funcs
36 # @ECLASS-VARIABLE: LUA_COMPAT
37 # @REQUIRED
38 # @DESCRIPTION:
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
41 # an array.
43 # Example:
44 # @CODE
45 # LUA_COMPAT=( lua5_4 lua5_3 luajit2 )
46 # @CODE
48 # @ECLASS-VARIABLE: _LUA_ALL_IMPLS
49 # @INTERNAL
50 # @DESCRIPTION:
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
56 # @INTERNAL
57 # @DESCRIPTION:
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
68 # @INTERNAL
69 # DESCRIPTION:
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
80 # @INTERNAL
81 # @DESCRIPTION:
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.
84 #  Also set IUSE.
85 _lua_set_globals() {
86         debug-print-function ${FUNCNAME} "${@}"
87         local deps i
89         if ! declare -p LUA_COMPAT &>/dev/null; then
90                 die 'LUA_COMPAT not declared.'
91         fi
92         if [[ $(declare -p LUA_COMPAT) != "declare -a"* ]]; then
93                 die 'LUA_COMPAT must be an array.'
94         fi
96         _LUA_IMPLS=()
98         for i in "${_LUA_ALL_IMPLS[@]}"; do
99                 if has "${i}" "${LUA_COMPAT[@]}"; then
100                         _LUA_IMPLS+=( "${i}" )
101                 fi
102         done
104         if [[ ! ${_LUA_IMPLS[@]} ]]; then
105                 die "No supported implementation in LUA_COMPAT."
106         fi
108         for i in "${_LUA_IMPLS[@]}"; do
109                 deps+="lua_targets_${i}? ( $(_lua_package_from_target ${i}) ) "
110         done
112         local flags=( "${_LUA_ALL_IMPLS[@]/#/lua_targets_}" )
113         local requse="|| ( ${flags[*]} )"
115         local f=( )
116         for (( i = ${#_LUA_ALL_IMPLS[@]} - 1; i >= 0; i-- )); do
117                 f+=( "lua_targets_${_LUA_ALL_IMPLS[i]}" )
118         done
119         IUSE=${f[*]}
121         LUA_DEPS=${deps}
122         LUA_REQUIRED_USE=${requse}
123         readonly LUA_DEPS LUA_REQUIRED_USE
125 _lua_set_globals
126 unset -f _lua_set_globals