1 # Copyright 1999-2020 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: lua-alt.eclass
8 # S. Gilles <sgilles@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: A common, simple eclass for Lua packages.
14 # A common eclass providing helper functions to build and install
15 # packages supporting being installed for multiple Lua
18 # This eclass sets correct IUSE. Modification of REQUIRED_USE has
19 # to be done by the author of the ebuild. lua-alt also provides
20 # methods to easily run a command for each enabled Lua implementation
21 # and duplicate the sources for them.
25 die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
30 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
36 inherit toolchain-funcs
40 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
42 # @ECLASS-VARIABLE: LUA_INCLUDEDIR
44 # Usable in phase functions. Set to the "includedir" variable, as
45 # given by pkg-config, for the relevant lua target
47 # @ECLASS-VARIABLE: LUA_LIBDIR
49 # Usable in phase functions. Set to the "libdir" variable, as
50 # given by pkg-config, for the relevant lua target
52 # @ECLASS-VARIABLE: INSTALL_LMOD
54 # Usable in phase functions. Set to the "INSTALL_LMOD" variable, as
55 # given by pkg-config, for the relevant lua target
57 # @ECLASS-VARIABLE: INSTALL_CMOD
59 # Usable in phase functions. Set to the "INSTALL_CMOD" variable, as
60 # given by pkg-config, for the relevant lua target
62 # @FUNCTION: _lua_validate_useflags
65 # Enforce the proper setting of LUA_TARGETS
66 _lua_validate_useflags() {
67 debug-print-function ${FUNCNAME} "${@}"
71 for i in "${_LUA_ALL_IMPLS[@]}"; do
72 use "lua_targets_${i}" && return 0
75 eerror "No Lua implementation selected for the build. Please add one"
76 eerror "of the following values to your LUA_TARGETS (in make.conf):"
78 eerror "${LUA_COMPAT[@]}"
80 die "No supported Lua implementation in LUA_TARGETS."
83 # @ECLASS-VARIABLE: BUILD_DIR
85 # The current build directory. In global scope, it is supposed to
86 # contain an initial build directory; if unset, it defaults to ${S}.
88 # In functions run by lua_foreach_impl(), the BUILD_DIR is locally
89 # set to an implementation-specific build directory. That path is
90 # created through appending a hyphen and the implementation name
91 # to the final component of the initial BUILD_DIR.
95 # ${WORKDIR}/foo-1.3-lua5_3
98 # @FUNCTION: lua_copy_sources
100 # Create a single copy of the package sources for each enabled Lua
103 # The sources are always copied from initial BUILD_DIR (or S if unset)
104 # to implementation-specific build directory matching BUILD_DIR used by
107 debug-print-function ${FUNCNAME} "${@}"
111 local MULTIBUILD_VARIANTS
114 multibuild_copy_sources
118 # @FUNCTION: _lua_obtain_impls
121 # Set up the enabled implementation list.
122 _lua_obtain_impls() {
123 _lua_validate_useflags
125 MULTIBUILD_VARIANTS=()
128 for impl in "${_LUA_ALL_IMPLS[@]}"; do
129 has "${impl}" "${LUA_COMPAT[@]}" && \
130 use "lua_targets_${impl}" && MULTIBUILD_VARIANTS+=( "${impl}" )
134 # @FUNCTION: _lua_multibuild_wrapper
135 # @USAGE: <command> [<args>...]
138 # Initialize the environment for Lua implementation selected
140 _lua_multibuild_wrapper() {
141 debug-print-function ${FUNCNAME} "${@}"
142 local l=$(_lua_pkgconfig_from_target "${MULTIBUILD_VARIANT}")
144 local -x LUA_INCLUDEDIR=$($(tc-getPKG_CONFIG) --variable includedir "${l}")
145 local -x LUA_LIBDIR=$($(tc-getPKG_CONFIG) --variable libdir "${l}")
146 local -x LUA_V=$($(tc-getPKG_CONFIG) --variable V "${l}")
147 [ -z "${LUA_V}" ] && LUA_V=$($(tc-getPKG_CONFIG) --variable abiver "${l}")
148 local -x INSTALL_LMOD=$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD "${l}")
149 local -x INSTALL_CMOD=$($(tc-getPKG_CONFIG) --variable INSTALL_CMOD "${l}")
150 local -x CFLAGS="${CFLAGS} $($(tc-getPKG_CONFIG) --cflags ${l})"
151 local -x LDFLAGS="${LDFLAGS} $($(tc-getPKG_CONFIG) --libs ${l})"
152 local -x prefix="${ED}"
159 # @FUNCTION: lua_foreach_impl
160 # @USAGE: <command> [<args>...]
162 # Run the given command for each of the enabled Lua implementations.
163 # If additional parameters are passed, they will be passed through
166 # The function will return 0 status if all invocations succeed.
167 # Otherwise, the return code from first failing invocation will
170 # For each command being run, ELUA, LUA and BUILD_DIR are set
171 # locally, and the former two are exported to the command environment.
173 debug-print-function ${FUNCNAME} "${@}"
175 local MULTIBUILD_VARIANTS
178 multibuild_foreach_variant _lua_multibuild_wrapper "${@}"
183 lua-alt_src_prepare() {
184 debug-print-function ${FUNCNAME} "${@}"
187 lua_foreach_impl default
190 lua-alt_src_configure() {
191 debug-print-function ${FUNCNAME} "${@}"
192 lua_foreach_impl default
195 lua-alt_src_compile() {
196 debug-print-function ${FUNCNAME} "${@}"
197 lua_foreach_impl default
201 debug-print-function ${FUNCNAME} "${@}"
202 lua_foreach_impl default
205 lua-alt_src_install() {
206 debug-print-function ${FUNCNAME} "${@}"
207 lua_foreach_impl default