For build systems which must be pointed directly to the relevant files,
e.g. CMake.

Signed-off-by: Marek Szuba <mare...@gentoo.org>
---
 eclass/lua-utils.eclass | 52 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/eclass/lua-utils.eclass b/eclass/lua-utils.eclass
index 8f54e57dbd7..100be14cb08 100644
--- a/eclass/lua-utils.eclass
+++ b/eclass/lua-utils.eclass
@@ -190,6 +190,34 @@ _lua_wrapper_setup() {
 # /usr/bin/lua5.1
 # @CODE
 
+# @FUNCTION: _lua_get_library_file
+# @USAGE: <impl>
+# @INTERNAL
+# @DESCRIPTION:
+# Get the core part (i.e. without the extension) of the library name,
+# with path, of the given Lua implementation.
+# Used internally by _lua_export().
+_lua_get_library_file() {
+       local impl="${1}"
+       local libdir libname
+
+       case ${impl} in
+               luajit)
+                       libname=lib$($(tc-getPKG_CONFIG) --variable libname 
${impl}) || die
+                       ;;
+               lua*)
+                       libname=lib${impl}
+                       ;;
+               *)
+                       die "Invalid implementation: ${impl}"
+                       ;;
+       esac
+       libdir=$($(tc-getPKG_CONFIG) --variable libdir ${impl}) || die
+
+       debug-print "${FUNCNAME}: libdir = ${libdir}, libname = ${libname}"
+       echo "${libdir}/${libname}"
+}
+
 # @FUNCTION: _lua_export
 # @USAGE: [<impl>] <variables>...
 # @INTERNAL
@@ -296,6 +324,11 @@ _lua_export() {
                                export LUA_PKG_DEP
                                debug-print "${FUNCNAME}: LUA_PKG_DEP = 
${LUA_PKG_DEP}"
                                ;;
+                       LUA_SHARED_LIB)
+                               local val=$(_lua_get_library_file ${impl})
+                               export LUA_SHARED_LIB="${val}".so
+                               debug-print "${FUNCNAME}: LUA_SHARED_LIB = 
${LUA_SHARED_LIB}"
+                               ;;
                        LUA_VERSION)
                                local val
 
@@ -391,6 +424,25 @@ lua_get_lmod_dir() {
        echo "${LUA_LMOD_DIR}"
 }
 
+# @FUNCTION: lua_get_shared_lib
+# @USAGE: [<impl>]
+# @DESCRIPTION:
+# Obtain and print the expected name, with path, of the main shared library
+# of the given Lua implementation. If no implementation is provided,
+# ${ELUA} will be used.
+#
+# Note that it is up to the ebuild maintainer to ensure Lua actually
+# provides a shared library.
+#
+# Please note that this function requires Lua and pkg-config installed,
+# and therefore proper build-time dependencies need be added to the ebuild.
+lua_get_shared_lib() {
+       debug-print-function ${FUNCNAME} "${@}"
+
+       _lua_export "${@}" LUA_SHARED_LIB
+       echo "${LUA_SHARED_LIB}"
+}
+
 # @FUNCTION: lua_get_version
 # @USAGE: [<impl>]
 # @DESCRIPTION:
-- 
2.26.2


Reply via email to