nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
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 = "http://www.lua.org/ftp/${name}.tar.gz";
17 sha1 = "926b7907bc8d274e063d42804666b40a3f3c124c";
18 };
19
20 nativeBuildInputs = [ 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} )
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} )
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 crossAttrs = let
58 isMingw = stdenv.cross.libc == "msvcrt";
59 isDarwin = stdenv.cross.libc == "libSystem";
60 in {
61 configurePhase = ''
62 makeFlagsArray=(
63 INSTALL_TOP=$out
64 INSTALL_MAN=$out/share/man/man1
65 CC=${stdenv.cross.config}-gcc
66 STRIP=:
67 RANLIB=${stdenv.cross.config}-ranlib
68 V=${luaversion}
69 R=${version}
70 ${if isMingw then "mingw" else stdenv.lib.optionalString isDarwin ''
71 AR="${stdenv.cross.config}-ar rcu"
72 macosx
73 ''}
74 )
75 '' + stdenv.lib.optionalString isMingw ''
76 installFlagsArray=(
77 TO_BIN="lua.exe luac.exe"
78 TO_LIB="liblua.a lua52.dll"
79 INSTALL_DATA="cp -d"
80 )
81 '';
82 } // stdenv.lib.optionalAttrs isDarwin {
83 postPatch = ''
84 sed -i -e 's/-Wl,-soname[^ ]* *//' src/Makefile
85 '';
86 };
87
88 meta = {
89 homepage = "http://www.lua.org";
90 description = "Powerful, fast, lightweight, embeddable scripting language";
91 longDescription = ''
92 Lua combines simple procedural syntax with powerful data
93 description constructs based on associative arrays and extensible
94 semantics. Lua is dynamically typed, runs by interpreting bytecode
95 for a register-based virtual machine, and has automatic memory
96 management with incremental garbage collection, making it ideal
97 for configuration, scripting, and rapid prototyping.
98 '';
99 license = stdenv.lib.licenses.mit;
100 platforms = stdenv.lib.platforms.unix;
101 };
102}