Revert "dev-lang/rust-bin: move app-eselect/eselect-rust to DEPEND"
[gentoo.git] / dev-lang / lua / lua-5.1.5-r101.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 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 SRC_URI="http://www.lua.org/ftp/${P}.tar.gz"
11
12 LICENSE="MIT"
13 SLOT="5.1"
14 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~ppc-aix ~amd64-fbsd ~x86-fbsd ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris"
15 IUSE="+deprecated emacs readline static"
16
17 RDEPEND="readline? ( >=sys-libs/readline-6.2_p5-r1:0=[${MULTILIB_USEDEP}] )
18         app-eselect/eselect-lua
19         !dev-lang/lua:0"
20 DEPEND="${RDEPEND}
21         sys-devel/libtool"
22 PDEPEND="emacs? ( app-emacs/lua-mode )"
23
24 SAN_SLOT="${SLOT//.}"
25
26 MULTILIB_WRAPPED_HEADERS=(
27         /usr/include/lua${SLOT}/luaconf.h
28 )
29
30 src_prepare() {
31         local PATCH_PV=$(get_version_component_range 1-2)
32
33         epatch "${FILESDIR}"/${PN}-${PATCH_PV}-make-r2.patch
34         epatch "${FILESDIR}"/${PN}-${PATCH_PV}-module_paths.patch
35
36         # use glibtool on Darwin (versus Apple libtool)
37         if [[ ${CHOST} == *-darwin* ]] ; then
38                 sed -i -e '/LIBTOOL = /s:libtool:glibtool:' \
39                         Makefile src/Makefile || die
40         fi
41
42         #EPATCH_SOURCE="${FILESDIR}/${PV}" EPATCH_SUFFIX="upstream.patch" epatch
43
44         # correct lua versioning
45         sed -i -e 's/\(LIB_VERSION = \)6:1:1/\16:5:1/' src/Makefile
46
47         sed -i -e 's:\(/README\)\("\):\1.gz\2:g' doc/readme.html
48
49         if ! use deprecated ; then
50                 # patches from 5.1.4 still apply
51                 epatch "${FILESDIR}"/${PN}-5.1.4-deprecated.patch
52                 epatch "${FILESDIR}"/${PN}-5.1.4-test.patch
53         fi
54
55         if ! use readline ; then
56                 epatch "${FILESDIR}"/${PN}-${PATCH_PV}-readline.patch
57         fi
58
59         # Using dynamic linked lua is not recommended for performance
60         # reasons. http://article.gmane.org/gmane.comp.lang.lua.general/18519
61         # Mainly, this is of concern if your arch is poor with GPRs, like x86
62         # Note that this only affects the interpreter binary (named lua), not the lua
63         # compiler (built statically) nor the lua libraries (both shared and static
64         # are installed)
65         if use static ; then
66                 epatch "${FILESDIR}"/${PN}-${PATCH_PV}-make_static-r1.patch
67         fi
68
69         # custom Makefiles
70         multilib_copy_sources
71
72         # A slotted Lua uses different directories for headers & names for
73         # libraries, and pkgconfig should reflect that.
74         sed -r -i \
75                 -e "/^Libs:/s,((-llua)($| )),\2${SLOT}\3," \
76                 -e "/^Cflags:/s,((-I..includedir.)($| )),\2/lua${SLOT}\3," \
77                 "${S}"/etc/lua.pc
78 }
79
80 multilib_src_configure() {
81         # We want packages to find our things...
82         sed -i \
83                 -e 's:/usr/local:'${EPREFIX}'/usr:' \
84                 -e "s:\([/\"]\)\<lib\>:\1$(get_libdir):g" \
85                 etc/lua.pc src/luaconf.h || die
86 }
87
88 multilib_src_compile() {
89         tc-export CC
90         myflags=
91         # what to link to liblua
92         liblibs="-lm"
93         liblibs="${liblibs} $(dlopen_lib)"
94
95         # what to link to the executables
96         mylibs=
97         if use readline; then
98                 mylibs="-lreadline"
99         fi
100
101         cd src
102         emake CC="${CC}" CFLAGS="-DLUA_USE_LINUX ${CFLAGS}" \
103                         RPATH="${EPREFIX}/usr/$(get_libdir)/" \
104                         LUA_LIBS="${mylibs}" \
105                         LIB_LIBS="${liblibs}" \
106                         V=$(get_version_component_range 1-2) \
107                         gentoo_all
108
109         mv lua_test ../test/lua.static
110 }
111
112 multilib_src_install() {
113         emake INSTALL_TOP="${ED}/usr" INSTALL_LIB="${ED}/usr/$(get_libdir)" \
114                         V=${SLOT} gentoo_install
115
116         insinto /usr/$(get_libdir)/pkgconfig
117         newins etc/lua.pc lua${SLOT}.pc
118 }
119
120 multilib_src_install_all() {
121         dodoc HISTORY README
122         dohtml doc/*.html doc/*.png doc/*.css doc/*.gif
123
124         doicon etc/lua.ico
125
126         newman doc/lua.1 lua${SLOT}.1
127         newman doc/luac.1 luac${SLOT}.1
128 }
129
130 multilib_src_test() {
131         local positive="bisect cf echo env factorial fib fibfor hello printf sieve
132         sort trace-calls trace-globals"
133         local negative="readonly"
134         local test
135
136         cd "${BUILD_DIR}" || die
137         for test in ${positive}; do
138                 test/lua.static test/${test}.lua || die "test $test failed"
139         done
140
141         for test in ${negative}; do
142                 test/lua.static test/${test}.lua && die "test $test failed"
143         done
144 }