lol
1{ stdenv, fetchurl, readline, compat ? false }:
2
3let
4 dsoPatch = fetchurl {
5 url = "https://projects.archlinux.org/svntogit/packages.git/plain/trunk/liblua.so.patch?h=packages/lua52";
6 sha256 = "1by1dy4ql61f5c6njq9ibf9kaqm3y633g2q8j54iyjr4cxvqwqz9";
7 name = "lua-arch.patch";
8 };
9in
10stdenv.mkDerivation rec {
11 name = "lua-${version}";
12 luaversion = "5.2";
13 version = "${luaversion}.3";
14
15 src = fetchurl {
16 url = "https://www.lua.org/ftp/${name}.tar.gz";
17 sha256 = "0b8034v1s82n4dg5rzcn12067ha3nxaylp2vdp8gg08kjsbzphhk";
18 };
19
20 buildInputs = [ readline ];
21
22 patches = if stdenv.isDarwin then [ ./5.2.darwin.patch ] else [ dsoPatch ];
23
24 configurePhase =
25 if stdenv.isDarwin
26 then ''
27 makeFlagsArray=( INSTALL_TOP=$out INSTALL_MAN=$out/share/man/man1 PLAT=macosx CFLAGS="-DLUA_USE_LINUX -fno-common -O2 -fPIC${if compat then " -DLUA_COMPAT_ALL" else ""}" LDFLAGS="-fPIC" V=${luaversion} R=${version} CC="$CC" )
28 installFlagsArray=( TO_BIN="lua luac" TO_LIB="liblua.${version}.dylib" INSTALL_DATA='cp -d' )
29 '' else ''
30 makeFlagsArray=( INSTALL_TOP=$out INSTALL_MAN=$out/share/man/man1 PLAT=linux CFLAGS="-DLUA_USE_LINUX -O2 -fPIC${if compat then " -DLUA_COMPAT_ALL" else ""}" LDFLAGS="-fPIC" V=${luaversion} R=${version} CC="$CC" AR="$AR q" RANLIB="$RANLIB" )
31 installFlagsArray=( TO_BIN="lua luac" TO_LIB="liblua.a liblua.so liblua.so.${luaversion} liblua.so.${version}" INSTALL_DATA='cp -d' )
32 '';
33
34 postInstall = ''
35 mkdir -p "$out/share/doc/lua" "$out/lib/pkgconfig"
36 mv "doc/"*.{gif,png,css,html} "$out/share/doc/lua/"
37 rmdir $out/{share,lib}/lua/${luaversion} $out/{share,lib}/lua
38 mkdir -p "$out/lib/pkgconfig"
39 cat >"$out/lib/pkgconfig/lua.pc" <<EOF
40 prefix=$out
41 libdir=$out/lib
42 includedir=$out/include
43 INSTALL_BIN=$out/bin
44 INSTALL_INC=$out/include
45 INSTALL_LIB=$out/lib
46 INSTALL_MAN=$out/man/man1
47
48 Name: Lua
49 Description: An Extensible Extension Language
50 Version: ${version}
51 Requires:
52 Libs: -L$out/lib -llua -lm
53 Cflags: -I$out/include
54 EOF
55 '';
56
57 meta = {
58 homepage = http://www.lua.org;
59 description = "Powerful, fast, lightweight, embeddable scripting language";
60 longDescription = ''
61 Lua combines simple procedural syntax with powerful data
62 description constructs based on associative arrays and extensible
63 semantics. Lua is dynamically typed, runs by interpreting bytecode
64 for a register-based virtual machine, and has automatic memory
65 management with incremental garbage collection, making it ideal
66 for configuration, scripting, and rapid prototyping.
67 '';
68 license = stdenv.lib.licenses.mit;
69 platforms = stdenv.lib.platforms.unix;
70 };
71}