1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 inherit eutils autotools multilib multilib-minimal portability toolchain-funcs versionator
8 DESCRIPTION="A powerful light-weight programming language designed for extending applications"
9 HOMEPAGE="http://www.lua.org/"
10 TEST_PV="5.2.2" # no 5.2.3-specific release yet
11 TEST_A="${PN}-${TEST_PV}-tests.tar.gz"
14 http://www.lua.org/ftp/${PKG_A}
15 test? ( https://www.lua.org/tests/${TEST_A} )"
19 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sparc ~x86 ~ppc-aix ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris"
20 IUSE="+deprecated emacs readline static test test-complete"
21 RESTRICT="!test? ( test )"
23 RDEPEND="readline? ( sys-libs/readline:0= )
24 app-eselect/eselect-lua
28 PDEPEND="emacs? ( app-emacs/lua-mode )"
30 MULTILIB_WRAPPED_HEADERS=(
31 /usr/include/lua${SLOT}/luaconf.h
35 local PATCH_PV=$(get_version_component_range 1-2)
37 epatch "${FILESDIR}"/${PN}-${PATCH_PV}-make-r1.patch
39 # use glibtool on Darwin (versus Apple libtool)
40 if [[ ${CHOST} == *-darwin* ]] ; then
41 sed -i -e '/LIBTOOL = /s:/libtool:/glibtool:' \
42 Makefile src/Makefile || die
45 [ -d "${FILESDIR}/${PV}" ] && \
46 EPATCH_SOURCE="${FILESDIR}/${PV}" EPATCH_SUFFIX="upstream.patch" epatch
48 # correct lua versioning
49 sed -i -e 's/\(LIB_VERSION = \)6:1:1/\10:0:0/' src/Makefile || die
51 sed -i -e 's:\(/README\)\("\):\1.gz\2:g' doc/readme.html || die
53 if ! use readline ; then
54 sed -i -e '/#define LUA_USE_READLINE/d' src/luaconf.h || die
57 # Using dynamic linked lua is not recommended for performance
58 # reasons. http://article.gmane.org/gmane.comp.lang.lua.general/18519
59 # Mainly, this is of concern if your arch is poor with GPRs, like x86
60 # Note that this only affects the interpreter binary (named lua), not the lua
61 # compiler (built statically) nor the lua libraries (both shared and static
64 sed -i -e 's:\(-export-dynamic\):-static \1:' src/Makefile || die
67 # upstream does not use libtool, but we do (see bug #336167)
68 cp "${FILESDIR}/configure.in" "${S}/configure.ac" || die
75 multilib_src_configure() {
77 -e 's:\(define LUA_ROOT\s*\).*:\1"'${EPREFIX}'/usr/":' \
78 -e "s:\(define LUA_CDIR\s*LUA_ROOT \"\)lib:\1$(get_libdir):" \
80 || die "failed patching luaconf.h"
85 multilib_src_compile() {
88 # what to link to liblua
90 liblibs="${liblibs} $(dlopen_lib)"
92 # what to link to the executables
94 use readline && mylibs="-lreadline"
99 use deprecated && myCFLAGS="-DLUA_COMPAT_ALL"
103 *) myCFLAGS+=" -DLUA_USE_LINUX" ;;
106 emake CC="${CC}" CFLAGS="${myCFLAGS} ${CFLAGS}" \
107 SYSLDFLAGS="${LDFLAGS}" \
108 RPATH="${EPREFIX}/usr/$(get_libdir)/" \
109 LUA_LIBS="${mylibs}" \
110 LIB_LIBS="${liblibs}" \
111 V=$(get_version_component_range 1-2) \
115 multilib_src_install() {
116 emake INSTALL_TOP="${ED}/usr" INSTALL_LIB="${ED}/usr/$(get_libdir)" \
117 V=${SLOT} gentoo_install
124 *) LIBNAME="lua${SLOT}"
125 INCLUDEDIR_SUFFIX="/lua${SLOT}"
129 # We want packages to find our things...
130 # A slotted Lua uses different directories for headers & names for
131 # libraries, and pkgconfig should reflect that.
132 local PATCH_PV=$(get_version_component_range 1-2)
133 cp "${FILESDIR}/lua.pc" "${WORKDIR}" || die
135 -e "s:^prefix= :prefix= ${EPREFIX}:" \
136 -e "s:^V=.*:V= ${PATCH_PV}:" \
137 -e "s:^R=.*:R= ${PV}:" \
138 -e "s:/,lib,:/$(get_libdir):g" \
139 -e "/^Libs:/s:( )(-llua)($| ):\1-l${LIBNAME}\3:" \
140 -e "/^includedir=/s:include$:include${INCLUDEDIR_SUFFIX}:" \
141 "${WORKDIR}/lua.pc" || die
143 insinto "/usr/$(get_libdir)/pkgconfig"
144 newins "${WORKDIR}/lua.pc" "lua${SLOT}.pc"
145 # Copy Debian's symlink support:
146 # https://salsa.debian.org/lua-team/lua5.3/blob/master/debian/rules#L19
147 # FreeBSD calls the pkgconfig 'lua-5.3.pc'
148 # Older systems called it 'lua53.pc'
149 dosym "lua${SLOT}.pc" "/usr/$(get_libdir)/pkgconfig/lua-${SLOT}.pc"
150 dosym "lua${SLOT}.pc" "/usr/$(get_libdir)/pkgconfig/lua${SLOT/.}.pc"
153 multilib_src_install_all() {
155 dohtml doc/*.html doc/*.png doc/*.css doc/*.gif
157 newman doc/lua.1 lua${SLOT}.1
158 newman doc/luac.1 luac${SLOT}.1
161 # Makefile contains a dummy target that doesn't do tests
162 # but causes issues with slotted lua (bug #510360)
164 debug-print-function ${FUNCNAME} "$@"
165 cd "${WORKDIR}/lua-${TEST_PV}-tests" || die
166 # https://www.lua.org/tests/
167 # There are two sets:
171 # The basic subset is selected by passing -e'_U=true'
172 # The complete set is noted to contain tests that may consume too much memory or have non-portable tests.
173 # attrib.lua for example needs some multilib customization (have to compile the stuff in libs/ for each ABI)
174 use test-complete || TEST_OPTS="-e_U=true"
175 TEST_MARKER="${T}/test.failed"
176 rm -f "${TEST_MARKER}"
178 # If we are failing, set the marker file, and only check it after done all ABIs
180 debug-print-function ${FUNCNAME} "$@"
181 TEST_LOG="${T}/test.${MULTIBUILD_ID}.log"
182 eval "${BUILD_DIR}"/src/lua${SLOT} ${TEST_OPTS} all.lua 2>&1 | tee "${TEST_LOG}" || die
183 grep -sq -e "final OK" "${TEST_LOG}" || echo "FAIL ${MULTIBUILD_ID}" >>"${TEST_MARKER}"
187 multilib_foreach_abi abi_src_test
189 if [ -e "${TEST_MARKER}" ]; then