*/*: [QA] Fix trivial cases of MissingTestRestrict
[gentoo.git] / dev-lang / lua / lua-5.3.5.ebuild
1 # Copyright 1999-2019 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.3.4" # no 5.3.5-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.3"
19 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sh ~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         # A slotted Lua uses different directories for headers & names for
72         # libraries, and pkgconfig should reflect that.
73         sed -r -i \
74                 -e "/^Libs:/s,((-llua)($| )),\2${SLOT}\3," \
75                 -e "/^Cflags:/s,((-I..includedir.)($| )),\2/lua${SLOT}\3," \
76                 "${S}"/etc/lua.pc
77
78         # custom Makefiles
79         multilib_copy_sources
80 }
81
82 multilib_src_configure() {
83         sed -i \
84                 -e 's:\(define LUA_ROOT\s*\).*:\1"'${EPREFIX}'/usr/":' \
85                 -e "s:\(define LUA_CDIR\s*LUA_ROOT \"\)lib:\1$(get_libdir):" \
86                 src/luaconf.h \
87         || die "failed patching luaconf.h"
88
89         econf
90 }
91
92 multilib_src_compile() {
93         tc-export CC
94
95         # what to link to liblua
96         liblibs="-lm"
97         liblibs="${liblibs} $(dlopen_lib)"
98
99         # what to link to the executables
100         mylibs=
101         use readline && mylibs="-lreadline"
102
103         cd src
104
105         local myCFLAGS=""
106         use deprecated && myCFLAGS="-DLUA_COMPAT_ALL"
107
108         case "${CHOST}" in
109                 *-mingw*) : ;;
110                 *) myCFLAGS+=" -DLUA_USE_LINUX" ;;
111         esac
112
113         emake CC="${CC}" CFLAGS="${myCFLAGS} ${CFLAGS}" \
114                         SYSLDFLAGS="${LDFLAGS}" \
115                         RPATH="${EPREFIX}/usr/$(get_libdir)/" \
116                         LUA_LIBS="${mylibs}" \
117                         LIB_LIBS="${liblibs}" \
118                         V=$(get_version_component_range 1-2) \
119                         gentoo_all
120 }
121
122 multilib_src_install() {
123         emake INSTALL_TOP="${ED}/usr" INSTALL_LIB="${ED}/usr/$(get_libdir)" \
124                         V=${SLOT} gentoo_install
125
126         # We want packages to find our things...
127         cp "${FILESDIR}/lua.pc" "${WORKDIR}"
128         sed -i \
129                 -e "s:^prefix= :prefix= ${EPREFIX}:" \
130                 -e "s:^V=.*:V= ${PATCH_PV}:" \
131                 -e "s:^R=.*:R= ${PV}:" \
132                 -e "s:/,lib,:/$(get_libdir):g" \
133                 "${WORKDIR}/lua.pc"
134
135         insinto "/usr/$(get_libdir)/pkgconfig"
136         newins "${WORKDIR}/lua.pc" "lua${SLOT}.pc"
137 }
138
139 multilib_src_install_all() {
140         dodoc README
141         dohtml doc/*.html doc/*.png doc/*.css doc/*.gif
142
143         newman doc/lua.1 lua${SLOT}.1
144         newman doc/luac.1 luac${SLOT}.1
145 }
146
147 # Makefile contains a dummy target that doesn't do tests
148 # but causes issues with slotted lua (bug #510360)
149 src_test() {
150         debug-print-function ${FUNCNAME} "$@"
151         cd "${WORKDIR}/lua-${TEST_PV}-tests" || die
152         # https://www.lua.org/tests/
153         # There are two sets:
154         # basic
155         # complete.
156         #
157         # The basic subset is selected by passing -e'_U=true'
158         # The complete set is noted to contain tests that may consume too much memory or have non-portable tests.
159         # attrib.lua for example needs some multilib customization (have to compile the stuff in libs/ for each ABI)
160         use test-complete || TEST_OPTS="-e_U=true"
161         TEST_MARKER="${T}/test.failed"
162         rm -f "${TEST_MARKER}"
163
164         # If we are failing, set the marker file, and only check it after done all ABIs
165         abi_src_test() {
166                 debug-print-function ${FUNCNAME} "$@"
167                 TEST_LOG="${T}/test.${MULTIBUILD_ID}.log"
168                 eval "${BUILD_DIR}"/src/lua${SLOT} ${TEST_OPTS} all.lua 2>&1 | tee "${TEST_LOG}" || die
169                 grep -sq -e "final OK" "${TEST_LOG}" || echo "FAIL ${MULTIBUILD_ID}" >>"${TEST_MARKER}"
170                 return 0
171         }
172
173         multilib_foreach_abi abi_src_test
174
175         if [ -e "${TEST_MARKER}" ]; then
176                 cat "${TEST_MARKER}"
177                 die "Tests failed"
178         fi
179 }