2021-01-23 13:15:07 +00:00
|
|
|
{ lib, stdenv, fetchurl, readline
|
2019-04-27 13:00:12 +00:00
|
|
|
, compat ? false
|
2019-01-30 14:13:15 +00:00
|
|
|
, callPackage
|
2021-09-11 22:01:49 +00:00
|
|
|
, makeWrapper
|
2022-08-26 03:17:06 +00:00
|
|
|
, self
|
2021-09-11 22:01:49 +00:00
|
|
|
, packageOverrides ? (final: prev: {})
|
2022-08-26 03:17:06 +00:00
|
|
|
, pkgsBuildBuild
|
|
|
|
, pkgsBuildHost
|
|
|
|
, pkgsBuildTarget
|
|
|
|
, pkgsHostHost
|
|
|
|
, pkgsTargetTarget
|
2019-04-27 13:00:12 +00:00
|
|
|
, sourceVersion
|
|
|
|
, hash
|
2022-08-26 03:17:06 +00:00
|
|
|
, passthruFun
|
2019-04-27 13:00:12 +00:00
|
|
|
, patches ? []
|
2019-04-27 18:28:54 +00:00
|
|
|
, postConfigure ? null
|
|
|
|
, postBuild ? null
|
2021-06-18 22:37:00 +00:00
|
|
|
, staticOnly ? stdenv.hostPlatform.isStatic
|
2022-08-26 03:17:06 +00:00
|
|
|
, luaAttr ? "lua${sourceVersion.major}_${sourceVersion.minor}"
|
|
|
|
} @ inputs:
|
2019-01-30 14:13:15 +00:00
|
|
|
let
|
2022-08-26 03:17:06 +00:00
|
|
|
luaPackages = self.pkgs;
|
2022-08-22 22:45:37 +00:00
|
|
|
|
2022-08-26 03:17:06 +00:00
|
|
|
luaversion = with sourceVersion; "${major}.${minor}";
|
2019-04-27 13:00:12 +00:00
|
|
|
|
2021-10-15 17:38:37 +00:00
|
|
|
plat = if (stdenv.isLinux && lib.versionOlder self.luaversion "5.4") then "linux"
|
|
|
|
else if (stdenv.isLinux && lib.versionAtLeast self.luaversion "5.4") then "linux-readline"
|
2021-04-19 11:02:16 +00:00
|
|
|
else if stdenv.isDarwin then "macosx"
|
|
|
|
else if stdenv.hostPlatform.isMinGW then "mingw"
|
|
|
|
else if stdenv.isFreeBSD then "freebsd"
|
|
|
|
else if stdenv.isSunOS then "solaris"
|
|
|
|
else if stdenv.hostPlatform.isBSD then "bsd"
|
|
|
|
else if stdenv.hostPlatform.isUnix then "posix"
|
|
|
|
else "generic";
|
2022-08-26 03:17:06 +00:00
|
|
|
in
|
2021-04-19 11:02:16 +00:00
|
|
|
|
2022-08-26 03:17:06 +00:00
|
|
|
stdenv.mkDerivation rec {
|
2019-04-27 13:00:12 +00:00
|
|
|
pname = "lua";
|
|
|
|
version = "${luaversion}.${sourceVersion.patch}";
|
2015-06-02 17:31:34 +00:00
|
|
|
|
|
|
|
src = fetchurl {
|
2020-02-01 02:00:45 +00:00
|
|
|
url = "https://www.lua.org/ftp/${pname}-${version}.tar.gz";
|
2019-04-27 13:00:12 +00:00
|
|
|
sha256 = hash;
|
2015-06-02 17:31:34 +00:00
|
|
|
};
|
|
|
|
|
2022-08-22 22:45:37 +00:00
|
|
|
LuaPathSearchPaths = luaPackages.luaLib.luaPathList;
|
|
|
|
LuaCPathSearchPaths = luaPackages.luaLib.luaCPathList;
|
2019-01-30 14:13:15 +00:00
|
|
|
setupHook = luaPackages.lua-setup-hook LuaPathSearchPaths LuaCPathSearchPaths;
|
|
|
|
|
2021-09-11 22:01:49 +00:00
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
2018-03-21 21:05:39 +00:00
|
|
|
buildInputs = [ readline ];
|
2015-06-02 17:31:34 +00:00
|
|
|
|
2019-04-27 13:00:12 +00:00
|
|
|
inherit patches;
|
2015-06-02 17:31:34 +00:00
|
|
|
|
2021-09-11 22:01:49 +00:00
|
|
|
# we can't pass flags to the lua makefile because for portability, everything is hardcoded
|
|
|
|
postPatch = ''
|
|
|
|
{
|
|
|
|
echo -e '
|
|
|
|
#undef LUA_PATH_DEFAULT
|
|
|
|
#define LUA_PATH_DEFAULT "./share/lua/${luaversion}/?.lua;./?.lua;./?/init.lua"
|
|
|
|
#undef LUA_CPATH_DEFAULT
|
|
|
|
#define LUA_CPATH_DEFAULT "./lib/lua/${luaversion}/?.so;./?.so;./lib/lua/${luaversion}/loadall.so"
|
|
|
|
'
|
|
|
|
} >> src/luaconf.h
|
|
|
|
'' + lib.optionalString (!stdenv.isDarwin && !staticOnly) ''
|
2021-04-19 11:38:01 +00:00
|
|
|
# Add a target for a shared library to the Makefile.
|
|
|
|
sed -e '1s/^/LUA_SO = liblua.so/' \
|
|
|
|
-e 's/ALL_T *= */&$(LUA_SO) /' \
|
|
|
|
-i src/Makefile
|
|
|
|
cat ${./lua-dso.make} >> src/Makefile
|
2021-09-11 22:01:49 +00:00
|
|
|
'' ;
|
2021-04-19 11:38:01 +00:00
|
|
|
|
2019-04-27 13:00:12 +00:00
|
|
|
# see configurePhase for additional flags (with space)
|
|
|
|
makeFlags = [
|
|
|
|
"INSTALL_TOP=${placeholder "out"}"
|
|
|
|
"INSTALL_MAN=${placeholder "out"}/share/man/man1"
|
|
|
|
"R=${version}"
|
|
|
|
"LDFLAGS=-fPIC"
|
|
|
|
"V=${luaversion}"
|
2021-04-19 11:02:16 +00:00
|
|
|
"PLAT=${plat}"
|
2021-04-19 11:09:36 +00:00
|
|
|
"CC=${stdenv.cc.targetPrefix}cc"
|
|
|
|
"RANLIB=${stdenv.cc.targetPrefix}ranlib"
|
2021-06-18 22:37:00 +00:00
|
|
|
# Lua links with readline wich depends on ncurses. For some reason when
|
|
|
|
# building pkgsStatic.lua it fails because symbols from ncurses are not
|
|
|
|
# found. Adding ncurses here fixes the problem.
|
|
|
|
"MYLIBS=-lncurses"
|
2021-04-19 11:09:36 +00:00
|
|
|
];
|
2019-04-27 13:00:12 +00:00
|
|
|
|
|
|
|
configurePhase = ''
|
|
|
|
runHook preConfigure
|
2015-06-02 17:31:34 +00:00
|
|
|
|
2021-05-14 20:08:38 +00:00
|
|
|
makeFlagsArray+=(CFLAGS='-O2 -fPIC${lib.optionalString compat " -DLUA_COMPAT_ALL"} $(${
|
|
|
|
if lib.versionAtLeast luaversion "5.2" then "SYSCFLAGS" else "MYCFLAGS"})' )
|
2021-04-19 11:09:36 +00:00
|
|
|
makeFlagsArray+=(${lib.optionalString stdenv.isDarwin "CC=\"$CC\""}${lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) " 'AR=${stdenv.cc.targetPrefix}ar rcu'"})
|
2019-04-27 13:00:12 +00:00
|
|
|
|
|
|
|
installFlagsArray=( TO_BIN="lua luac" INSTALL_DATA='cp -d' \
|
2021-06-18 22:37:00 +00:00
|
|
|
TO_LIB="${if stdenv.isDarwin then "liblua.${version}.dylib"
|
|
|
|
else ("liblua.a" + lib.optionalString (!staticOnly) " liblua.so liblua.so.${luaversion} liblua.so.${version}" )}" )
|
2019-04-27 13:00:12 +00:00
|
|
|
|
|
|
|
runHook postConfigure
|
2015-06-02 17:31:34 +00:00
|
|
|
'';
|
2019-04-27 18:28:54 +00:00
|
|
|
inherit postConfigure;
|
|
|
|
|
|
|
|
inherit postBuild;
|
2015-06-02 17:31:34 +00:00
|
|
|
|
|
|
|
postInstall = ''
|
|
|
|
mkdir -p "$out/share/doc/lua" "$out/lib/pkgconfig"
|
|
|
|
mv "doc/"*.{gif,png,css,html} "$out/share/doc/lua/"
|
|
|
|
rmdir $out/{share,lib}/lua/${luaversion} $out/{share,lib}/lua
|
|
|
|
mkdir -p "$out/lib/pkgconfig"
|
2019-04-27 13:00:12 +00:00
|
|
|
|
2015-06-02 17:31:34 +00:00
|
|
|
cat >"$out/lib/pkgconfig/lua.pc" <<EOF
|
|
|
|
prefix=$out
|
|
|
|
libdir=$out/lib
|
|
|
|
includedir=$out/include
|
|
|
|
INSTALL_BIN=$out/bin
|
|
|
|
INSTALL_INC=$out/include
|
|
|
|
INSTALL_LIB=$out/lib
|
|
|
|
INSTALL_MAN=$out/man/man1
|
|
|
|
|
|
|
|
Name: Lua
|
|
|
|
Description: An Extensible Extension Language
|
|
|
|
Version: ${version}
|
|
|
|
Requires:
|
2021-05-15 14:40:26 +00:00
|
|
|
Libs: -L$out/lib -llua
|
2015-06-02 17:31:34 +00:00
|
|
|
Cflags: -I$out/include
|
|
|
|
EOF
|
2021-01-23 18:38:54 +00:00
|
|
|
ln -s "$out/lib/pkgconfig/lua.pc" "$out/lib/pkgconfig/lua-${luaversion}.pc"
|
2018-06-24 02:25:48 +00:00
|
|
|
ln -s "$out/lib/pkgconfig/lua.pc" "$out/lib/pkgconfig/lua${luaversion}.pc"
|
2021-01-23 18:38:54 +00:00
|
|
|
ln -s "$out/lib/pkgconfig/lua.pc" "$out/lib/pkgconfig/lua${lib.replaceStrings [ "." ] [ "" ] luaversion}.pc"
|
2015-06-02 17:31:34 +00:00
|
|
|
'';
|
|
|
|
|
2022-08-26 03:17:06 +00:00
|
|
|
# copied from python
|
|
|
|
passthru = let
|
|
|
|
# When we override the interpreter we also need to override the spliced versions of the interpreter
|
|
|
|
inputs' = lib.filterAttrs (n: v: ! lib.isDerivation v && n != "passthruFun") inputs;
|
|
|
|
override = attr: let lua = attr.override (inputs' // { self = lua; }); in lua;
|
|
|
|
in passthruFun rec {
|
|
|
|
inherit self luaversion packageOverrides luaAttr sourceVersion;
|
|
|
|
executable = "lua";
|
|
|
|
luaOnBuildForBuild = override pkgsBuildBuild.${luaAttr};
|
|
|
|
luaOnBuildForHost = override pkgsBuildHost.${luaAttr};
|
|
|
|
luaOnBuildForTarget = override pkgsBuildTarget.${luaAttr};
|
|
|
|
luaOnHostForHost = override pkgsHostHost.${luaAttr};
|
|
|
|
luaOnTargetForTarget = if lib.hasAttr luaAttr pkgsTargetTarget then (override pkgsTargetTarget.${luaAttr}) else {};
|
2019-01-30 14:13:15 +00:00
|
|
|
};
|
|
|
|
|
2015-06-02 17:31:34 +00:00
|
|
|
meta = {
|
2020-04-01 01:11:51 +00:00
|
|
|
homepage = "http://www.lua.org";
|
2015-06-02 17:31:34 +00:00
|
|
|
description = "Powerful, fast, lightweight, embeddable scripting language";
|
|
|
|
longDescription = ''
|
|
|
|
Lua combines simple procedural syntax with powerful data
|
|
|
|
description constructs based on associative arrays and extensible
|
|
|
|
semantics. Lua is dynamically typed, runs by interpreting bytecode
|
|
|
|
for a register-based virtual machine, and has automatic memory
|
|
|
|
management with incremental garbage collection, making it ideal
|
|
|
|
for configuration, scripting, and rapid prototyping.
|
|
|
|
'';
|
2021-01-23 13:15:07 +00:00
|
|
|
license = lib.licenses.mit;
|
|
|
|
platforms = lib.platforms.unix;
|
2015-06-02 17:31:34 +00:00
|
|
|
};
|
2022-08-26 03:17:06 +00:00
|
|
|
}
|