Merge pull request #119860 from alyssais/lua-bsd
lua: support non-Darwin non-Linux OSes; clean up
This commit is contained in:
commit
96fc9ccc54
@ -1,27 +1,10 @@
|
|||||||
# similar to interpreters/python/default.nix
|
# similar to interpreters/python/default.nix
|
||||||
{ stdenv, lib, callPackage, fetchurl, fetchpatch }:
|
{ stdenv, lib, callPackage, fetchurl, fetchpatch }:
|
||||||
let
|
|
||||||
dsoPatch51 = fetchurl {
|
|
||||||
url = "https://projects.archlinux.org/svntogit/packages.git/plain/trunk/lua-arch.patch?h=packages/lua51";
|
|
||||||
sha256 = "11fcyb4q55p4p7kdb8yp85xlw8imy14kzamp2khvcyxss4vw8ipw";
|
|
||||||
name = "lua-arch.patch";
|
|
||||||
};
|
|
||||||
|
|
||||||
dsoPatch52 = fetchurl {
|
rec {
|
||||||
url = "https://projects.archlinux.org/svntogit/packages.git/plain/trunk/liblua.so.patch?h=packages/lua52";
|
|
||||||
sha256 = "1by1dy4ql61f5c6njq9ibf9kaqm3y633g2q8j54iyjr4cxvqwqz9";
|
|
||||||
name = "lua-arch.patch";
|
|
||||||
};
|
|
||||||
|
|
||||||
in rec {
|
|
||||||
lua5_4 = callPackage ./interpreter.nix {
|
lua5_4 = callPackage ./interpreter.nix {
|
||||||
sourceVersion = { major = "5"; minor = "4"; patch = "2"; };
|
sourceVersion = { major = "5"; minor = "4"; patch = "2"; };
|
||||||
hash = "0ksj5zpj74n0jkamy3di1p6l10v4gjnd2zjnb453qc6px6bhsmqi";
|
hash = "0ksj5zpj74n0jkamy3di1p6l10v4gjnd2zjnb453qc6px6bhsmqi";
|
||||||
patches = [
|
|
||||||
# build lua as a shared library as well, MIT-licensed from
|
|
||||||
# https://github.com/archlinux/svntogit-packages/tree/packages/lua/trunk
|
|
||||||
./liblua.so.patch
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
lua5_4_compat = lua5_4.override({
|
lua5_4_compat = lua5_4.override({
|
||||||
@ -35,11 +18,6 @@ in rec {
|
|||||||
patches =
|
patches =
|
||||||
lib.optionals stdenv.isDarwin [ ./5.2.darwin.patch ];
|
lib.optionals stdenv.isDarwin [ ./5.2.darwin.patch ];
|
||||||
|
|
||||||
postConfigure = lib.optionalString (!stdenv.isDarwin) ''
|
|
||||||
cat ${./lua-5.3-dso.make} >> src/Makefile
|
|
||||||
sed -e 's/ALL_T *= */& $(LUA_SO)/' -i src/Makefile
|
|
||||||
'';
|
|
||||||
|
|
||||||
postBuild = lib.optionalString (!stdenv.isDarwin) ''
|
postBuild = lib.optionalString (!stdenv.isDarwin) ''
|
||||||
( cd src; make $makeFlags "''${makeFlagsArray[@]}" liblua.so )
|
( cd src; make $makeFlags "''${makeFlagsArray[@]}" liblua.so )
|
||||||
'';
|
'';
|
||||||
@ -53,7 +31,7 @@ in rec {
|
|||||||
lua5_2 = callPackage ./interpreter.nix {
|
lua5_2 = callPackage ./interpreter.nix {
|
||||||
sourceVersion = { major = "5"; minor = "2"; patch = "4"; };
|
sourceVersion = { major = "5"; minor = "2"; patch = "4"; };
|
||||||
hash = "0jwznq0l8qg9wh5grwg07b5cy3lzngvl5m2nl1ikp6vqssmf9qmr";
|
hash = "0jwznq0l8qg9wh5grwg07b5cy3lzngvl5m2nl1ikp6vqssmf9qmr";
|
||||||
patches = if stdenv.isDarwin then [ ./5.2.darwin.patch ] else [ dsoPatch52 ];
|
patches = lib.optional stdenv.isDarwin ./5.2.darwin.patch;
|
||||||
};
|
};
|
||||||
|
|
||||||
lua5_2_compat = lua5_2.override({
|
lua5_2_compat = lua5_2.override({
|
||||||
@ -64,7 +42,7 @@ in rec {
|
|||||||
lua5_1 = callPackage ./interpreter.nix {
|
lua5_1 = callPackage ./interpreter.nix {
|
||||||
sourceVersion = { major = "5"; minor = "1"; patch = "5"; };
|
sourceVersion = { major = "5"; minor = "1"; patch = "5"; };
|
||||||
hash = "2640fc56a795f29d28ef15e13c34a47e223960b0240e8cb0a82d9b0738695333";
|
hash = "2640fc56a795f29d28ef15e13c34a47e223960b0240e8cb0a82d9b0738695333";
|
||||||
patches = (if stdenv.isDarwin then [ ./5.1.darwin.patch ] else [ dsoPatch51 ])
|
patches = (lib.optional stdenv.isDarwin ./5.1.darwin.patch)
|
||||||
++ [ ./CVE-2014-5461.patch ];
|
++ [ ./CVE-2014-5461.patch ];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -11,6 +11,15 @@
|
|||||||
let
|
let
|
||||||
luaPackages = callPackage ../../lua-modules {lua=self; overrides=packageOverrides;};
|
luaPackages = callPackage ../../lua-modules {lua=self; overrides=packageOverrides;};
|
||||||
|
|
||||||
|
plat = if stdenv.isLinux then "linux"
|
||||||
|
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";
|
||||||
|
|
||||||
self = stdenv.mkDerivation rec {
|
self = stdenv.mkDerivation rec {
|
||||||
pname = "lua";
|
pname = "lua";
|
||||||
luaversion = with sourceVersion; "${major}.${minor}";
|
luaversion = with sourceVersion; "${major}.${minor}";
|
||||||
@ -29,6 +38,14 @@ self = stdenv.mkDerivation rec {
|
|||||||
|
|
||||||
inherit patches;
|
inherit patches;
|
||||||
|
|
||||||
|
postPatch = lib.optionalString (!stdenv.isDarwin) ''
|
||||||
|
# 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
|
||||||
|
'';
|
||||||
|
|
||||||
# see configurePhase for additional flags (with space)
|
# see configurePhase for additional flags (with space)
|
||||||
makeFlags = [
|
makeFlags = [
|
||||||
"INSTALL_TOP=${placeholder "out"}"
|
"INSTALL_TOP=${placeholder "out"}"
|
||||||
@ -36,21 +53,16 @@ self = stdenv.mkDerivation rec {
|
|||||||
"R=${version}"
|
"R=${version}"
|
||||||
"LDFLAGS=-fPIC"
|
"LDFLAGS=-fPIC"
|
||||||
"V=${luaversion}"
|
"V=${luaversion}"
|
||||||
] ++ (if stdenv.isDarwin then [
|
"PLAT=${plat}"
|
||||||
"PLAT=macosx"
|
"CC=${stdenv.cc.targetPrefix}cc"
|
||||||
] else [
|
"RANLIB=${stdenv.cc.targetPrefix}ranlib"
|
||||||
"PLAT=linux"
|
];
|
||||||
]) ++ (if stdenv.buildPlatform != stdenv.hostPlatform then [
|
|
||||||
"CC=${stdenv.hostPlatform.config}-gcc"
|
|
||||||
"RANLIB=${stdenv.hostPlatform.config}-ranlib"
|
|
||||||
] else [])
|
|
||||||
;
|
|
||||||
|
|
||||||
configurePhase = ''
|
configurePhase = ''
|
||||||
runHook preConfigure
|
runHook preConfigure
|
||||||
|
|
||||||
makeFlagsArray+=(CFLAGS="-DLUA_USE_LINUX -O2 -fPIC${if compat then " -DLUA_COMPAT_ALL" else ""}" )
|
makeFlagsArray+=(CFLAGS='-O2 -fPIC${lib.optionalString compat " -DLUA_COMPAT_ALL"} $(SYSCFLAGS)' )
|
||||||
makeFlagsArray+=(${lib.optionalString stdenv.isDarwin "CC=\"$CC\""}${lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) " 'AR=${stdenv.hostPlatform.config}-ar rcu'"})
|
makeFlagsArray+=(${lib.optionalString stdenv.isDarwin "CC=\"$CC\""}${lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) " 'AR=${stdenv.cc.targetPrefix}ar rcu'"})
|
||||||
|
|
||||||
installFlagsArray=( TO_BIN="lua luac" INSTALL_DATA='cp -d' \
|
installFlagsArray=( TO_BIN="lua luac" INSTALL_DATA='cp -d' \
|
||||||
TO_LIB="${if stdenv.isDarwin then "liblua.${version}.dylib" else "liblua.a liblua.so liblua.so.${luaversion} liblua.so.${version}"}" )
|
TO_LIB="${if stdenv.isDarwin then "liblua.${version}.dylib" else "liblua.a liblua.so liblua.so.${luaversion} liblua.so.${version}"}" )
|
||||||
|
@ -1,60 +0,0 @@
|
|||||||
diff --git a/Makefile b/Makefile
|
|
||||||
index 416f444..eeaff03 100644
|
|
||||||
--- a/Makefile
|
|
||||||
+++ b/Makefile
|
|
||||||
@@ -52,7 +52,7 @@ R= $V.0
|
|
||||||
all: $(PLAT)
|
|
||||||
|
|
||||||
$(PLATS) help test clean:
|
|
||||||
- @cd src && $(MAKE) $@
|
|
||||||
+ @cd src && $(MAKE) $@ V=$(V) R=$(R)
|
|
||||||
|
|
||||||
install: dummy
|
|
||||||
cd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD)
|
|
||||||
diff --git a/src/Makefile b/src/Makefile
|
|
||||||
index 514593d..372a6dc 100644
|
|
||||||
--- a/src/Makefile
|
|
||||||
+++ b/src/Makefile
|
|
||||||
@@ -33,6 +33,7 @@ CMCFLAGS= -Os
|
|
||||||
PLATS= guess aix bsd c89 freebsd generic linux linux-readline macosx mingw posix solaris
|
|
||||||
|
|
||||||
LUA_A= liblua.a
|
|
||||||
+LUA_SO= liblua.so
|
|
||||||
CORE_O= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o lundump.o lvm.o lzio.o
|
|
||||||
LIB_O= lauxlib.o lbaselib.o lcorolib.o ldblib.o liolib.o lmathlib.o loadlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o linit.o
|
|
||||||
BASE_O= $(CORE_O) $(LIB_O) $(MYOBJS)
|
|
||||||
@@ -44,7 +45,7 @@ LUAC_T= luac
|
|
||||||
LUAC_O= luac.o
|
|
||||||
|
|
||||||
ALL_O= $(BASE_O) $(LUA_O) $(LUAC_O)
|
|
||||||
-ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)
|
|
||||||
+ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T) $(LUA_SO)
|
|
||||||
ALL_A= $(LUA_A)
|
|
||||||
|
|
||||||
# Targets start here.
|
|
||||||
@@ -60,6 +61,12 @@ $(LUA_A): $(BASE_O)
|
|
||||||
$(AR) $@ $(BASE_O)
|
|
||||||
$(RANLIB) $@
|
|
||||||
|
|
||||||
+$(LUA_SO): $(CORE_O) $(LIB_O)
|
|
||||||
+ $(CC) -shared -ldl -Wl,-soname,$(LUA_SO).$(V) -o $@.$(R) $? -lm $(MYLDFLAGS)
|
|
||||||
+ ln -sf $(LUA_SO).$(R) $(LUA_SO).$(V)
|
|
||||||
+ ln -sf $(LUA_SO).$(R) $(LUA_SO)
|
|
||||||
+
|
|
||||||
+
|
|
||||||
$(LUA_T): $(LUA_O) $(LUA_A)
|
|
||||||
$(CC) -o $@ $(LDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)
|
|
||||||
|
|
||||||
diff --git a/src/luaconf.h b/src/luaconf.h
|
|
||||||
index bdf927e..7e15198 100644
|
|
||||||
--- a/src/luaconf.h
|
|
||||||
+++ b/src/luaconf.h
|
|
||||||
@@ -227,7 +227,7 @@
|
|
||||||
|
|
||||||
#else /* }{ */
|
|
||||||
|
|
||||||
-#define LUA_ROOT "/usr/local/"
|
|
||||||
+#define LUA_ROOT "/usr/"
|
|
||||||
#define LUA_LDIR LUA_ROOT "share/lua/" LUA_VDIR "/"
|
|
||||||
#define LUA_CDIR LUA_ROOT "lib/lua/" LUA_VDIR "/"
|
|
||||||
|
|
@ -1,8 +1,4 @@
|
|||||||
|
|
||||||
LUA_SO=liblua.so
|
|
||||||
|
|
||||||
$(LUA_SO): $(CORE_O) $(LIB_O)
|
$(LUA_SO): $(CORE_O) $(LIB_O)
|
||||||
$(CC) -shared -ldl -Wl,-soname,$(LUA_SO).$(V) -o $@.$(R) $? -lm $(MYLDFLAGS)
|
$(CC) -shared $(SYSLIBS) -Wl,-soname,$(LUA_SO).$(V) -o $@.$(R) $? $(MYLDFLAGS)
|
||||||
ln -sf $(LUA_SO).$(R) $(LUA_SO).$(V)
|
ln -sf $(LUA_SO).$(R) $(LUA_SO).$(V)
|
||||||
ln -sf $(LUA_SO).$(R) $(LUA_SO)
|
ln -sf $(LUA_SO).$(R) $(LUA_SO)
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user