dev-python/pytest: arm64 stable (bug #723996)
[gentoo.git] / dev-lang / lua / lua-5.2.4-r1.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=5
5
6 inherit eutils autotools multilib multilib-minimal portability toolchain-funcs versionator
7
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"
12 PKG_A="${P}.tar.gz"
13 SRC_URI="
14         http://www.lua.org/ftp/${PKG_A}
15         test? ( https://www.lua.org/tests/${TEST_A} )"
16
17 LICENSE="MIT"
18 SLOT="5.2"
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 )"
22
23 RDEPEND="readline? ( sys-libs/readline:0= )
24         app-eselect/eselect-lua
25         !dev-lang/lua:0"
26 DEPEND="${RDEPEND}
27         sys-devel/libtool"
28 PDEPEND="emacs? ( app-emacs/lua-mode )"
29
30 MULTILIB_WRAPPED_HEADERS=(
31         /usr/include/lua${SLOT}/luaconf.h
32 )
33
34 src_prepare() {
35         local PATCH_PV=$(get_version_component_range 1-2)
36
37         epatch "${FILESDIR}"/${PN}-${PATCH_PV}-make-r1.patch
38
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
43         fi
44
45         [ -d "${FILESDIR}/${PV}" ] && \
46                 EPATCH_SOURCE="${FILESDIR}/${PV}" EPATCH_SUFFIX="upstream.patch" epatch
47
48         # correct lua versioning
49         sed -i -e 's/\(LIB_VERSION = \)6:1:1/\10:0:0/' src/Makefile || die
50
51         sed -i -e 's:\(/README\)\("\):\1.gz\2:g' doc/readme.html || die
52
53         if ! use readline ; then
54                 sed -i -e '/#define LUA_USE_READLINE/d' src/luaconf.h || die
55         fi
56
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
62         # are installed)
63         if use static ; then
64                 sed -i -e 's:\(-export-dynamic\):-static \1:' src/Makefile || die
65         fi
66
67         # upstream does not use libtool, but we do (see bug #336167)
68         cp "${FILESDIR}/configure.in" "${S}/configure.ac" || die
69         eautoreconf
70
71         # custom Makefiles
72         multilib_copy_sources
73 }
74
75 multilib_src_configure() {
76         sed -i \
77                 -e 's:\(define LUA_ROOT\s*\).*:\1"'${EPREFIX}'/usr/":' \
78                 -e "s:\(define LUA_CDIR\s*LUA_ROOT \"\)lib:\1$(get_libdir):" \
79                 src/luaconf.h \
80         || die "failed patching luaconf.h"
81
82         econf
83 }
84
85 multilib_src_compile() {
86         tc-export CC
87
88         # what to link to liblua
89         liblibs="-lm"
90         liblibs="${liblibs} $(dlopen_lib)"
91
92         # what to link to the executables
93         mylibs=
94         use readline && mylibs="-lreadline"
95
96         cd src
97
98         local myCFLAGS=""
99         use deprecated && myCFLAGS="-DLUA_COMPAT_ALL"
100
101         case "${CHOST}" in
102                 *-mingw*) : ;;
103                 *) myCFLAGS+=" -DLUA_USE_LINUX" ;;
104         esac
105
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) \
112                         gentoo_all
113 }
114
115 multilib_src_install() {
116         emake INSTALL_TOP="${ED}/usr" INSTALL_LIB="${ED}/usr/$(get_libdir)" \
117                         V=${SLOT} gentoo_install
118
119         case $SLOT in
120                 0)
121                         LIBNAME="lua"
122                         INCLUDEDIR_SUFFIX=''
123                         ;;
124                 *)      LIBNAME="lua${SLOT}"
125                         INCLUDEDIR_SUFFIX="/lua${SLOT}"
126                         ;;
127         esac
128
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
134         sed -r -i \
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
142
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"
151 }
152
153 multilib_src_install_all() {
154         dodoc README
155         dohtml doc/*.html doc/*.png doc/*.css doc/*.gif
156
157         newman doc/lua.1 lua${SLOT}.1
158         newman doc/luac.1 luac${SLOT}.1
159 }
160
161 # Makefile contains a dummy target that doesn't do tests
162 # but causes issues with slotted lua (bug #510360)
163 src_test() {
164         debug-print-function ${FUNCNAME} "$@"
165         cd "${WORKDIR}/lua-${TEST_PV}-tests" || die
166         # https://www.lua.org/tests/
167         # There are two sets:
168         # basic
169         # complete.
170         #
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}"
177
178         # If we are failing, set the marker file, and only check it after done all ABIs
179         abi_src_test() {
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}"
184                 return 0
185         }
186
187         multilib_foreach_abi abi_src_test
188
189         if [ -e "${TEST_MARKER}" ]; then
190                 cat "${TEST_MARKER}"
191                 die "Tests failed"
192         fi
193 }