dev-lang/lua: adjust prefix in .pc file for Prefix
[gentoo.git] / dev-lang / lua / lua-5.1.5-r2.ebuild
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI=5
6
7 inherit eutils multilib portability toolchain-funcs versionator
8
9 DESCRIPTION="A powerful light-weight programming language designed for extending applications"
10 HOMEPAGE="http://www.lua.org/"
11 SRC_URI="http://www.lua.org/ftp/${P}.tar.gz"
12
13 LICENSE="MIT"
14 SLOT="5.1"
15 KEYWORDS="~alpha ~amd64 ~arm ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~amd64-fbsd ~x86-fbsd ~arm-linux ~x86-linux"
16 IUSE="+deprecated emacs readline static"
17
18 RDEPEND="readline? ( sys-libs/readline )
19         app-eselect/eselect-lua
20         !dev-lang/lua:0"
21 DEPEND="${RDEPEND}
22         sys-devel/libtool"
23 PDEPEND="emacs? ( app-emacs/lua-mode )"
24
25 SAN_SLOT="${SLOT//.}"
26
27 src_prepare() {
28         local PATCH_PV=$(get_version_component_range 1-2)
29
30         epatch "${FILESDIR}"/${PN}-${PATCH_PV}-make-r2.patch
31         epatch "${FILESDIR}"/${PN}-${PATCH_PV}-module_paths.patch
32
33         #EPATCH_SOURCE="${FILESDIR}/${PV}" EPATCH_SUFFIX="upstream.patch" epatch
34
35         # correct lua versioning
36         sed -i -e 's/\(LIB_VERSION = \)6:1:1/\16:5:1/' src/Makefile
37
38         sed -i -e 's:\(/README\)\("\):\1.gz\2:g' doc/readme.html
39
40         if ! use deprecated ; then
41                 # patches from 5.1.4 still apply
42                 epatch "${FILESDIR}"/${PN}-5.1.4-deprecated.patch
43                 epatch "${FILESDIR}"/${PN}-5.1.4-test.patch
44         fi
45
46         if ! use readline ; then
47                 epatch "${FILESDIR}"/${PN}-${PATCH_PV}-readline.patch
48         fi
49
50         # Using dynamic linked lua is not recommended for performance
51         # reasons. http://article.gmane.org/gmane.comp.lang.lua.general/18519
52         # Mainly, this is of concern if your arch is poor with GPRs, like x86
53         # Note that this only affects the interpreter binary (named lua), not the lua
54         # compiler (built statically) nor the lua libraries (both shared and static
55         # are installed)
56         if use static ; then
57                 epatch "${FILESDIR}"/${PN}-${PATCH_PV}-make_static-r1.patch
58         fi
59
60         # We want packages to find our things...
61         sed -i \
62                 -e 's:/usr/local:'${EPREFIX}'/usr:' \
63                 -e "s:\([/\"]\)\<lib\>:\1$(get_libdir):g" \
64                 etc/lua.pc src/luaconf.h || die
65 }
66
67 # no need for a configure phase
68 src_configure() { true; }
69
70 src_compile() {
71         tc-export CC
72         myflags=
73         # what to link to liblua
74         liblibs="-lm"
75         liblibs="${liblibs} $(dlopen_lib)"
76
77         # what to link to the executables
78         mylibs=
79         if use readline; then
80                 mylibs="-lreadline"
81         fi
82
83         cd src
84         emake CC="${CC}" CFLAGS="-DLUA_USE_LINUX ${CFLAGS}" \
85                         RPATH="${EPREFIX}/usr/$(get_libdir)/" \
86                         LUA_LIBS="${mylibs}" \
87                         LIB_LIBS="${liblibs}" \
88                         V=$(get_version_component_range 1-2) \
89                         gentoo_all || die "emake failed"
90
91         mv lua_test ../test/lua.static
92 }
93
94 src_install() {
95         emake INSTALL_TOP="${ED}/usr" INSTALL_LIB="${ED}/usr/$(get_libdir)" \
96                         V=${SLOT} gentoo_install \
97         || die "emake install gentoo_install failed"
98
99         dodoc HISTORY README
100         dohtml doc/*.html doc/*.png doc/*.css doc/*.gif
101
102         doicon etc/lua.ico
103         insinto /usr/$(get_libdir)/pkgconfig
104         newins etc/lua.pc lua${SLOT}.pc
105
106         newman doc/lua.1 lua${SLOT}.1
107         newman doc/luac.1 luac${SLOT}.1
108 }
109
110 src_test() {
111         local positive="bisect cf echo env factorial fib fibfor hello printf sieve
112         sort trace-calls trace-globals"
113         local negative="readonly"
114         local test
115
116         cd "${S}"
117         for test in ${positive}; do
118                 test/lua.static test/${test}.lua || die "test $test failed"
119         done
120
121         for test in ${negative}; do
122                 test/lua.static test/${test}.lua && die "test $test failed"
123         done
124 }