compat53-0.14.3.ebuild 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. # Copyright 2024 Gentoo Authors
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI=8
  4. MY_PN="lua-compat-5.3"
  5. LUA_COMPAT=(lua5-{1..4} luajit)
  6. inherit edo flag-o-matic lua toolchain-funcs
  7. DESCRIPTION="Compatibility module providing Lua-5.3-style APIs for Lua 5.2 and 5.1"
  8. HOMEPAGE="
  9. https://luarocks.org/modules/lunarmodules/compat53
  10. https://github.com/lunarmodules/lua-compat-5.3
  11. "
  12. SRC_URI="https://github.com/lunarmodules/${MY_PN}/archive/v${PV}.tar.gz -> lua-${P}.tar.gz"
  13. S="${WORKDIR}/${MY_PN}-${PV}"
  14. LICENSE="MIT"
  15. SLOT="0"
  16. KEYWORDS="amd64"
  17. DEPEND="${LUA_DEPS}"
  18. RDEPEND="${DEPEND}"
  19. ROCKSPEC="rockspecs/${P}-1.rockspec"
  20. src_prepare() {
  21. default
  22. lua_copy_sources
  23. }
  24. rockspec_foreach_build_module() {
  25. local rockspec="${1:?}"
  26. local func="${2:?}"
  27. [ -f "${rockspec}" ] || die "'${rockspec}' file does not exist"
  28. local old_IFS="${IFS}"
  29. IFS=$'\n'
  30. local lines=($(
  31. edo "${LUA}" -e '
  32. dofile("'"${rockspec}"'");
  33. for dst, src in pairs(build.modules) do
  34. print(dst, src)
  35. end
  36. '
  37. ))
  38. IFS="${old_IFS}"
  39. local line=''
  40. for line in "${lines[@]}"; do
  41. IFS=$'\t'
  42. set -- ${line}
  43. IFS="${old_IFS}"
  44. "${func}" "${1:?}" "${2:?}" || die "${func} failed: ${?}"
  45. done
  46. }
  47. rockspec_compile_c_module() {
  48. local dst="${1:?}"
  49. local src="${2:?}"
  50. case "${src}" in
  51. *.c)
  52. edo "${CC}" -shared -o "${dst#*.}.so" \
  53. ${CPPFLAGS} \
  54. ${CFLAGS} $(lua_get_CFLAGS) \
  55. "${src}" \
  56. ${LDFLAGS} $(lua_get_LIBS)
  57. ;;
  58. esac
  59. }
  60. lua_src_compile() {
  61. (
  62. cd "${BUILD_DIR}" || die
  63. filter-flags -ffinite-math-only
  64. rockspec_foreach_build_module "${ROCKSPEC}" rockspec_compile_c_module ||
  65. die "rockspec_foreach_build_module failed"
  66. )
  67. }
  68. src_compile() {
  69. lua_foreach_impl tc-env_build lua_src_compile
  70. }
  71. rockspec_install_module() {
  72. local dst="${1:?}"
  73. local src="${2:?}"
  74. case "${src}" in
  75. *.c)
  76. doexe "${dst#*.}.so"
  77. ;;
  78. *.lua)
  79. doins "${src}"
  80. ;;
  81. *)
  82. die "unexpected rockspec module: '${dst}' -> '${src}'"
  83. ;;
  84. esac
  85. }
  86. lua_src_install() {
  87. (
  88. cd "${BUILD_DIR}" || die
  89. exeinto "$(lua_get_cmod_dir)/${PN}"
  90. insinto "$(lua_get_lmod_dir)/${PN}"
  91. rockspec_foreach_build_module "${ROCKSPEC}" rockspec_install_module ||
  92. die "rockspec_foreach_build_module failed"
  93. )
  94. }
  95. src_install() {
  96. lua_foreach_impl lua_src_install
  97. }