summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBoris Nagaev <bnagaev@gmail.com>2015-12-06 02:44:54 (GMT)
committerBoris Nagaev <bnagaev@gmail.com>2015-12-06 02:44:54 (GMT)
commit99af3f72565c0e75e2115d8233e49d9b58a551f6 (patch)
tree31c175cf87629aed84aeec8be4fa7c906c428f33
parent9537e5c9d2f83fe11b8c328e5e142aa1822cbdcc (diff)
parente6f1f261149cb27b79344f6c7eb7a14737f11d88 (diff)
downloadmxe-99af3f72565c0e75e2115d8233e49d9b58a551f6.zip
mxe-99af3f72565c0e75e2115d8233e49d9b58a551f6.tar.gz
mxe-99af3f72565c0e75e2115d8233e49d9b58a551f6.tar.bz2
Merge pull request #1017 from LuaAndC/luarocks2
install native and cross lua executables & add LuaRocks plugin
-rw-r--r--plugins/luarocks/README.md94
-rw-r--r--plugins/luarocks/llthreads2-1-link-with-kernel32-on-mxe.patch33
-rw-r--r--plugins/luarocks/llthreads2.mk24
-rw-r--r--plugins/luarocks/lpeg-1-rockspec.patch55
-rw-r--r--plugins/luarocks/lpeg.mk25
-rw-r--r--plugins/luarocks/lua-rapidjson-1-fixes.patch82
-rw-r--r--plugins/luarocks/lua-rapidjson.mk23
-rw-r--r--plugins/luarocks/luarocks-1-platform-mxe.patch83
-rw-r--r--plugins/luarocks/luarocks.mk69
-rw-r--r--plugins/luarocks/luasocket-1-build-on-mxe.patch65
-rw-r--r--plugins/luarocks/luasocket-2-lual-checkint.patch56
-rw-r--r--plugins/luarocks/luasocket.mk23
-rw-r--r--plugins/luarocks/test.lua16
-rw-r--r--src/lua.mk23
14 files changed, 661 insertions, 10 deletions
diff --git a/plugins/luarocks/README.md b/plugins/luarocks/README.md
new file mode 100644
index 0000000..61b4656
--- /dev/null
+++ b/plugins/luarocks/README.md
@@ -0,0 +1,94 @@
+LuaRocks plugin
+===============
+
+Short description of LuaRocks
+-----------------------------
+
+Hundreds of [Lua][lua] packages are distributed via [LuaRocks][luarocks].
+LuaRocks is the package manager for Lua. It allows you to create and
+install Luamodules as self-contained packages called rocks. You can
+download and install LuaRocks on Unix and Windows.
+
+Lua rocks are similar to Ruby gems, Python eggs or JavaScript NPM. Command
+`luarocks install <rock>` downloads a rock from [luarocks.org][luarocks]
+(or other luarocks server), compiles C files (modules) to shared libraries
+and installs (copies) shared libraries and Lua files to the directory
+where luarocks is installed. Installed rocks can be loaded from Lua with
+function `require`.
+
+Example:
+```
+$ luarocks install luasocket
+$ lua -e 'http = require "socket.http"; print(http.request("http://mxe.cc"))'
+<!DOCTYPE html>
+....
+```
+
+LuaRocks can used with `make`, `cmake`, custom or builtin
+ [back-ends][backends].
+
+LuaRocks in MXE
+---------------
+
+LuaRocks and some popular rocks were ported to MXE as a plugin.
+LuaRocks can now be used in the same way as CMake or Make.
+
+Package `lua` installs native executable usr/bin/lua and
+cross-compiled lua executable usr/<target>/bin/lua.exe. Native
+executable is needed since LuaRocks is written in Lua. Cross-compiled
+one is needed to run Lua scripts loading cross-compiled lua modules.
+
+Package `luarocks` was added. Luarocks was patched to support new
+platform `mxe`, inherited from platform `unix`. It uses mix of system
+tools (e.g., `openssl`, `ln`, `mkdir`), MXE build chain
+(`i686-w64-mingw32.shared-gcc`, `i686-w64-mingw32.shared-cmake`) and some
+Windows variables (e.g., "dll" extension for shared libraries). The
+package is shared-only because Lua loads modules in runtime. It
+creates prefixed luarocks tool in `usr/bin`. It also creates prefixed
+wine+lua wrapper aware of locations of dll and lua files installed.
+This script can be used to test modules in Linux as if running them in
+Windows.
+
+There was a difficult choice if `mxe` platform of luarocks is inherited
+from `windows` or `unix` platform. I tried both and it is less patching
+for `unix`. For `windows` even build tools differ, while for `unix` a
+typical rock builds without patching or with minor patching
+(as other MXE packages).
+
+LuaRocks can be used to install rocks. With ideal rock it works as follows:
+
+```
+$ i686-w64-mingw32.shared-luarocks install <rock>
+```
+
+This command downloads rockspeck, downloads sources, verifies checksum
+(useless thing, because checksum is compared to the value from rockspec
+file, which itself is neither verified nor signed), builds and installs.
+
+LuaRocks is not used to download source tarballs (as said
+above, it doesn't verify checksums properly) using MXE's downloading
+and verifying facilities instead. Luarocks is used as builder,
+installer and Lua library (it installs Lua files to
+`usr/i686-w64-mingw32.shared/share/lua/5.3/luarocks/`).
+
+Build all rocks:
+```
+$ make all-luarocks MXE_PLUGIN_DIRS=plugins/luarocks MXE_TARGETS='i686-w64-mingw32.shared x86_64-w64-mingw32.shared'
+```
+
+Run tests (requires wine):
+```
+$ ./usr/bin/i686-w64-mingw32.shared-lua plugins/luarocks/test.lua
+```
+
+See also:
+
+ * [LuaRocks site][luarocks]
+ * [LuaRocks wiki][wiki]
+ * [the thread in MXE mailing list about LuaRocks in MXE][thread]
+
+[lua]:http://lua.org/
+[luarocks]:https://luarocks.org/
+[backends]:https://github.com/keplerproject/luarocks/wiki/Rockspec-format#Build_backends
+[wiki]:https://github.com/keplerproject/luarocks/wiki/
+[thread]:http://lists.nongnu.org/archive/html/mingw-cross-env-list/2015-10/msg00008.html
diff --git a/plugins/luarocks/llthreads2-1-link-with-kernel32-on-mxe.patch b/plugins/luarocks/llthreads2-1-link-with-kernel32-on-mxe.patch
new file mode 100644
index 0000000..7edd1f5
--- /dev/null
+++ b/plugins/luarocks/llthreads2-1-link-with-kernel32-on-mxe.patch
@@ -0,0 +1,33 @@
+This file is part of MXE.
+See index.html for further information.
+
+From 1d8e959ee39e7a46e150e722af12252448c7ac22 Mon Sep 17 00:00:00 2001
+From: Boris Nagaev <bnagaev@gmail.com>
+Date: Sun, 11 Oct 2015 01:56:36 +0100
+Subject: [PATCH] link with kernel32 on MXE
+
+---
+ rockspecs/lua-llthreads2-scm-0.rockspec | 7 +++++++
+ 1 file changed, 7 insertions(+)
+
+diff --git a/rockspecs/lua-llthreads2-scm-0.rockspec b/rockspecs/lua-llthreads2-scm-0.rockspec
+index 8f907b8..26d5b80 100644
+--- a/rockspecs/lua-llthreads2-scm-0.rockspec
++++ b/rockspecs/lua-llthreads2-scm-0.rockspec
+@@ -27,6 +27,13 @@ build = {
+ }
+ }
+ },
++ mxe = {
++ modules = {
++ llthreads2 = {
++ libraries = {"kernel32"},
++ }
++ }
++ },
+ windows = {
+ modules = {
+ llthreads2 = {
+--
+2.1.4
+
diff --git a/plugins/luarocks/llthreads2.mk b/plugins/luarocks/llthreads2.mk
new file mode 100644
index 0000000..0c9115e
--- /dev/null
+++ b/plugins/luarocks/llthreads2.mk
@@ -0,0 +1,24 @@
+# This file is part of MXE.
+# See index.html for further information.
+
+PKG := llthreads2
+$(PKG)_WEBSITE := https://github.com/moteus/lua-llthreads2
+$(PKG)_OWNER := https://github.com/starius
+$(PKG)_IGNORE :=
+$(PKG)_VERSION := 0.1.3
+$(PKG)_CHECKSUM := 8c6fc7966cdcc15ae2f89f66ae72f6727a985e7d254f139ecf75a50956a3e8e4
+$(PKG)_SUBDIR := lua-$(PKG)-$($(PKG)_VERSION)
+$(PKG)_FILE := $($(PKG)_SUBDIR).tar.gz
+$(PKG)_URL := https://github.com/moteus/lua-llthreads2/archive/v$($(PKG)_VERSION).tar.gz
+$(PKG)_DEPS := gcc luarocks
+
+define $(PKG)_UPDATE
+ $(call MXE_GET_GITHUB_TAGS, moteus/lua-llthreads2, v)
+endef
+
+# shared-only because luarocks is shared-only
+
+define $(PKG)_BUILD_SHARED
+ cd '$(1)' && '$(TARGET)-luarocks' make \
+ rockspecs/lua-llthreads2-scm-0.rockspec
+endef
diff --git a/plugins/luarocks/lpeg-1-rockspec.patch b/plugins/luarocks/lpeg-1-rockspec.patch
new file mode 100644
index 0000000..2d336e9
--- /dev/null
+++ b/plugins/luarocks/lpeg-1-rockspec.patch
@@ -0,0 +1,55 @@
+This file is part of MXE.
+See index.html for further information.
+
+From f271a094f8add34df3f31ac6fb12c9fe683f763a Mon Sep 17 00:00:00 2001
+From: Boris Nagaev <bnagaev@gmail.com>
+Date: Sat, 10 Oct 2015 16:40:35 +0100
+Subject: [PATCH] add rockspec
+
+Source:https://luarocks.org/modules/gvvaughan/lpeg/1.0.0-1
+---
+ lpeg-1.0.0-1.rockspec | 32 ++++++++++++++++++++++++++++++++
+ 1 file changed, 32 insertions(+)
+ create mode 100644 lpeg-1.0.0-1.rockspec
+
+diff --git a/lpeg-1.0.0-1.rockspec b/lpeg-1.0.0-1.rockspec
+new file mode 100644
+index 0000000..b4fdd27
+--- /dev/null
++++ b/lpeg-1.0.0-1.rockspec
+@@ -0,0 +1,32 @@
++package = "LPeg"
++version = "1.0.0-1"
++source = {
++ url = "http://www.inf.puc-rio.br/~roberto/lpeg/lpeg-1.0.0.tar.gz",
++ md5 = "0aec64ccd13996202ad0c099e2877ece",
++}
++description = {
++ summary = "Parsing Expression Grammars For Lua",
++ detailed = [[
++ LPeg is a new pattern-matching library for Lua, based on Parsing
++ Expression Grammars (PEGs). The nice thing about PEGs is that it
++ has a formal basis (instead of being an ad-hoc set of features),
++ allows an efficient and simple implementation, and does most things
++ we expect from a pattern-matching library (and more, as we can
++ define entire grammars).
++ ]],
++ homepage = "http://www.inf.puc-rio.br/~roberto/lpeg.html",
++ maintainer = "Gary V. Vaughan <gary@vaughan.pe>",
++ license = "MIT/X11"
++}
++dependencies = {
++ "lua >= 5.1"
++}
++build = {
++ type = "builtin",
++ modules = {
++ lpeg = {
++ "lpcap.c", "lpcode.c", "lpprint.c", "lptree.c", "lpvm.c"
++ },
++ re = "re.lua"
++ }
++}
+--
+2.1.4
+
diff --git a/plugins/luarocks/lpeg.mk b/plugins/luarocks/lpeg.mk
new file mode 100644
index 0000000..4d099db
--- /dev/null
+++ b/plugins/luarocks/lpeg.mk
@@ -0,0 +1,25 @@
+# This file is part of MXE.
+# See index.html for further information.
+
+PKG := lpeg
+$(PKG)_WEBSITE := http://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html
+$(PKG)_OWNER := https://github.com/starius
+$(PKG)_IGNORE :=
+$(PKG)_VERSION := 1.0.0
+$(PKG)_CHECKSUM := 10190ae758a22a16415429a9eb70344cf29cbda738a6962a9f94a732340abf8e
+$(PKG)_SUBDIR := lpeg-$($(PKG)_VERSION)
+$(PKG)_FILE := $($(PKG)_SUBDIR).tar.gz
+$(PKG)_URL := http://www.inf.puc-rio.br/~roberto/$(PKG)/$($(PKG)_FILE)
+$(PKG)_DEPS := gcc luarocks
+
+define $(PKG)_UPDATE
+ $(WGET) -q -O- 'http://www.inf.puc-rio.br/~roberto/lpeg/' | \
+ $(SED) -n 's,.*lpeg-\([0-9][^>]*\)\.tar.*,\1,p' | \
+ $(SORT) -h | tail -1
+endef
+
+# shared-only because luarocks is shared-only
+
+define $(PKG)_BUILD_SHARED
+ cd '$(1)' && '$(TARGET)-luarocks' make
+endef
diff --git a/plugins/luarocks/lua-rapidjson-1-fixes.patch b/plugins/luarocks/lua-rapidjson-1-fixes.patch
new file mode 100644
index 0000000..554d46c
--- /dev/null
+++ b/plugins/luarocks/lua-rapidjson-1-fixes.patch
@@ -0,0 +1,82 @@
+This file is part of MXE.
+See index.html for further information.
+
+From dbedfa6c3b350b6cb2c13d17790a17129ce28721 Mon Sep 17 00:00:00 2001
+From: Boris Nagaev <bnagaev@gmail.com>
+Date: Sun, 11 Oct 2015 22:47:50 +0200
+Subject: [PATCH 1/2] use Unix file functions on MinGW
+
+---
+ src/rapidjson.cpp | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/src/rapidjson.cpp b/src/rapidjson.cpp
+index 3b5b129..955009f 100644
+--- a/src/rapidjson.cpp
++++ b/src/rapidjson.cpp
+@@ -54,7 +54,7 @@ static void setfuncs(lua_State* L, const luaL_Reg *funcs)
+ FILE* openForRead(const char* filename)
+ {
+ FILE* fp = NULL;
+-#if WIN32
++#if WIN32 && !defined(__MINGW32__)
+ fopen_s(&fp, filename, "rb");
+ #else
+ fp = fopen(filename, "r");
+@@ -66,7 +66,7 @@ FILE* openForRead(const char* filename)
+ FILE* openForWrite(const char* filename)
+ {
+ FILE* fp = NULL;
+-#if WIN32
++#if WIN32 && !defined(__MINGW32__)
+ fopen_s(&fp, filename, "wb");
+ #else
+ fp = fopen(filename, "w");
+--
+1.7.10.4
+
+
+From ad7426ad156f90dcf2b051fe125900caf5b8b2da Mon Sep 17 00:00:00 2001
+From: Boris Nagaev <bnagaev@gmail.com>
+Date: Sun, 11 Oct 2015 22:48:26 +0200
+Subject: [PATCH 2/2] link with Lua libraries on MinGW and MXE
+
+---
+ rapidjson-0.2.2-1.rockspec | 15 ++++++++++-----
+ 1 file changed, 10 insertions(+), 5 deletions(-)
+
+diff --git a/rapidjson-0.2.2-1.rockspec b/rapidjson-0.2.2-1.rockspec
+index 9efe7e1..6ad9188 100644
+--- a/rapidjson-0.2.2-1.rockspec
++++ b/rapidjson-0.2.2-1.rockspec
+@@ -27,6 +27,13 @@ dependencies = {
+ "lua >= 5.1"
+ }
+
++-- windows DLL needs link with importlib.
++local link = {
++ variables = {
++ LUA_LIBRARIES = "$(LUA_LIBDIR)/$(LUALIB)",
++ }
++}
++
+ -- cmake -Bbuild -H. -DBUILD_SHARED_LIBS=ON
+ -- cmake --build build --target install --config Release
+ build = {
+@@ -39,10 +46,8 @@ build = {
+ },
+ -- Override default build options
+ platforms = {
+- windows = {
+- variables = {
+- LUA_LIBRARIES = "$(LUA_LIBDIR)/$(LUALIB)", -- windows DLL needs link with importlib.
+- }
+- }
++ windows = link,
++ mingw = link,
++ mxe = link,
+ }
+ }
+--
+1.7.10.4
+
diff --git a/plugins/luarocks/lua-rapidjson.mk b/plugins/luarocks/lua-rapidjson.mk
new file mode 100644
index 0000000..fa7ed1e
--- /dev/null
+++ b/plugins/luarocks/lua-rapidjson.mk
@@ -0,0 +1,23 @@
+# This file is part of MXE.
+# See index.html for further information.
+
+PKG := lua-rapidjson
+$(PKG)_WEBSITE := https://github.com/xpol/lua-rapidjson
+$(PKG)_OWNER := https://github.com/starius
+$(PKG)_IGNORE :=
+$(PKG)_VERSION := 0.2.2-1
+$(PKG)_CHECKSUM := 10783d8633df3f50b1ad33c7de89d2a94a7d9cf45e2ce5217d0d2d5e77396fd2
+$(PKG)_SUBDIR := $(PKG)-$($(PKG)_VERSION)
+$(PKG)_FILE := $($(PKG)_SUBDIR).tar.gz
+$(PKG)_URL := https://github.com/xpol/lua-rapidjson/archive/v$($(PKG)_VERSION).tar.gz
+$(PKG)_DEPS := gcc luarocks
+
+define $(PKG)_UPDATE
+ $(call MXE_GET_GITHUB_TAGS, xpol/lua-rapidjson, v)
+endef
+
+# shared-only because luarocks is shared-only
+
+define $(PKG)_BUILD_SHARED
+ cd '$(1)' && '$(TARGET)-luarocks' make
+endef
diff --git a/plugins/luarocks/luarocks-1-platform-mxe.patch b/plugins/luarocks/luarocks-1-platform-mxe.patch
new file mode 100644
index 0000000..127e06e
--- /dev/null
+++ b/plugins/luarocks/luarocks-1-platform-mxe.patch
@@ -0,0 +1,83 @@
+This file is part of MXE.
+See index.html for further information.
+
+From 5cd28e7a8f0de2539322ede15616904835a4dbe3 Mon Sep 17 00:00:00 2001
+From: Boris Nagaev <bnagaev@gmail.com>
+Date: Sat, 10 Oct 2015 17:45:24 +0100
+Subject: [PATCH] platform MXE
+
+diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua
+index 00fd09e..a4985e9 100644
+--- a/src/luarocks/build/builtin.lua
++++ b/src/luarocks/build/builtin.lua
+@@ -165,7 +165,7 @@ function builtin.run(rockspec)
+ add_flags(extras, "-Wl,-rpath,%s:", libdirs)
+ end
+ add_flags(extras, "-l%s", libraries)
+- if cfg.is_platform("cygwin") then
++ if cfg.is_platform("cygwin") or cfg.is_platform("mxe") then
+ add_flags(extras, "-l%s", {"lua"})
+ end
+ return execute(variables.LD.." "..variables.LIBFLAG, "-o", library, "-L"..variables.LUA_LIBDIR, unpack(extras))
+diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua
+index 99b4077..a17fbaa 100644
+--- a/src/luarocks/cfg.lua
++++ b/src/luarocks/cfg.lua
+@@ -118,6 +118,9 @@ elseif system and system:match("^Windows") then
+ elseif system and system:match("^MINGW") then
+ detected.windows = true
+ detected.mingw32 = true
++elseif system and system:match("^MXE") then
++ detected.unix = true
++ detected.mxe = true
+ else
+ detected.unix = true
+ -- Fall back to Unix in unknown systems.
+@@ -430,6 +433,44 @@ if detected.unix then
+ defaults.web_browser = "xdg-open"
+ end
+
++if detected.mxe then
++ local MXE_ROOT, MXE_TARGET =
++ assert(site_config.LUAROCKS_PREFIX:match('^(.*)/usr/([^/]+)$'))
++ defaults.lib_extension = "dll"
++ defaults.external_lib_extension = "dll"
++ defaults.obj_extension = "obj"
++ defaults.external_deps_dirs = { site_config.LUAROCKS_PREFIX }
++ defaults.arch = "mxe-" .. MXE_TARGET
++ defaults.platforms = {"unix", "mxe"}
++ -- LUA_INCDIR and LUA_LIBDIR are defined in site_config.lua
++ defaults.variables.LUA_BINDIR = site_config.LUAROCKS_PREFIX .. "/bin"
++ defaults.cmake_generator = "Unix Makefiles"
++ defaults.variables.MAKE = os.getenv("MAKE")
++ defaults.variables.CMAKE = MXE_ROOT .. "/usr/bin/" .. MXE_TARGET .. "-cmake"
++ defaults.variables.CC = MXE_ROOT .. "/usr/bin/" .. MXE_TARGET .. "-gcc"
++ defaults.variables.LD = defaults.variables.CC
++ defaults.variables.CFLAGS = "-O2"
++ defaults.variables.LIBFLAG = "-shared"
++ defaults.variables.LUALIB = "liblua.dll.a"
++
++ defaults.export_path = "SET PATH=%s"
++ defaults.export_path_separator = ";"
++ defaults.export_lua_path = "SET LUA_PATH=%s"
++ defaults.export_lua_cpath = "SET LUA_CPATH=%s"
++ defaults.wrapper_suffix = ".bat"
++
++ defaults.external_deps_patterns = {
++ bin = { "?.exe", "?.bat" },
++ lib = { "?.dll.a", "lib?.dll.a" },
++ include = { "?.h" }
++ }
++ defaults.runtime_external_deps_patterns = {
++ bin = { "?.exe", "?.bat" },
++ lib = { "?.dll", "lib?.dll" },
++ include = { "?.h" }
++ }
++end
++
+ if detected.cygwin then
+ defaults.lib_extension = "so" -- can be overridden in the config file for mingw builds
+ defaults.arch = "cygwin-"..proc
+--
+2.1.4
+
diff --git a/plugins/luarocks/luarocks.mk b/plugins/luarocks/luarocks.mk
new file mode 100644
index 0000000..a852c37
--- /dev/null
+++ b/plugins/luarocks/luarocks.mk
@@ -0,0 +1,69 @@
+# This file is part of MXE.
+# See index.html for further information.
+
+PKG := luarocks
+$(PKG)_WEBSITE := https://luarocks.org/
+$(PKG)_OWNER := https://github.com/starius
+$(PKG)_IGNORE :=
+$(PKG)_VERSION := 2.2.2
+$(PKG)_CHECKSUM := 4f0427706873f30d898aeb1dfb6001b8a3478e46a5249d015c061fe675a1f022
+$(PKG)_SUBDIR := luarocks-$($(PKG)_VERSION)
+$(PKG)_FILE := $($(PKG)_SUBDIR).tar.gz
+$(PKG)_URL := https://keplerproject.github.io/luarocks/releases/$($(PKG)_FILE)
+$(PKG)_DEPS := gcc lua
+
+define $(PKG)_UPDATE
+ $(WGET) -q -O- 'https://keplerproject.github.io/luarocks/releases/' | \
+ $(SED) -n 's,.*luarocks-\([0-9][^>]*\)\.tar.*,\1,p' | \
+ $(SORT) -h | tail -1
+endef
+
+# shared-only because Lua loads modules in runtime
+
+define $(PKG)_BUILD_SHARED
+ cd '$(1)' && ./configure \
+ --prefix='$(PREFIX)/$(TARGET)' \
+ --rocks-tree='$(PREFIX)/$(TARGET)' \
+ --lua-version='$(lua_SHORTVER)' \
+ --with-lua='$(PREFIX)/$(TARGET)' \
+ --with-lua-bin='$(PREFIX)/$(BUILD)/bin' \
+ --with-downloader='wget' \
+ --with-md5-checker='openssl'
+ $(MAKE) -C '$(1)' build \
+ LUAROCKS_UNAME_S="MXE" \
+ LUAROCKS_UNAME_M="$(TARGET)"
+ $(MAKE) -C '$(1)' install
+
+ # move installed lua file luarocks to luarocks.lua
+ mv '$(PREFIX)/$(TARGET)/bin/luarocks' '$(PREFIX)/$(TARGET)/bin/luarocks.lua'
+
+ # create bash wrapper adding inter-process mutex
+ # see https://github.com/mxe/mxe/pull/1017#issuecomment-161557440
+ $(INSTALL) -d '$(PREFIX)/$(TARGET)/lib/luarocks'
+ (echo '#!/usr/bin/env bash'; \
+ echo 'echo "== Using MXE wrapper: $(PREFIX)/$(TARGET)/bin/luarocks"'; \
+ echo '# Creating a directory is an atomic operation, that is why'; \
+ echo '# it can be used as a mutex.'; \
+ echo '# See http://wiki.bash-hackers.org/howto/mutex'; \
+ echo 'while ( ! mkdir "$(PREFIX)/$(TARGET)/lib/luarocks/lock.dir" ); do'; \
+ echo ' echo "Waiting for $(PREFIX)/$(TARGET)/lib/luarocks/lock.dir to lock"'; \
+ echo ' sleep 5'; \
+ echo 'done'; \
+ echo '"$(PREFIX)/$(TARGET)/bin/luarocks.lua" "$$@"'; \
+ echo 'rmdir "$(PREFIX)/$(TARGET)/lib/luarocks/lock.dir"'; \
+ ) \
+ > '$(PREFIX)/$(TARGET)/bin/luarocks'
+ chmod 0755 '$(PREFIX)/$(TARGET)/bin/luarocks'
+ # remove lock dir if it exists after previous failed installation
+ -rmdir "$(PREFIX)/$(TARGET)/lib/luarocks/lock.dir"
+
+ # symlink
+ ln -sf '$(PREFIX)/$(TARGET)/bin/luarocks' '$(PREFIX)/bin/$(TARGET)-luarocks'
+
+ # create wine wrapper for testing
+ echo 'LUA_PATH="$(PREFIX)/$(TARGET)/share/lua/$(lua_SHORTVER)/?.lua;$(PREFIX)/$(TARGET)/share/lua/$(lua_SHORTVER)/?/init.lua;$$LUA_PATH"' > '$(PREFIX)/bin/$(TARGET)-lua'
+ echo 'LUA_CPATH="$(PREFIX)/$(TARGET)/lib/lua/$(lua_SHORTVER)/?.dll;;$$LUA_CPATH"' >> '$(PREFIX)/bin/$(TARGET)-lua'
+ echo 'export LUA_PATH LUA_CPATH' >> '$(PREFIX)/bin/$(TARGET)-lua'
+ echo 'exec wine $(PREFIX)/$(TARGET)/bin/lua.exe "$$@"' >> '$(PREFIX)/bin/$(TARGET)-lua'
+ chmod +x '$(PREFIX)/bin/$(TARGET)-lua'
+endef
diff --git a/plugins/luarocks/luasocket-1-build-on-mxe.patch b/plugins/luarocks/luasocket-1-build-on-mxe.patch
new file mode 100644
index 0000000..c6e6db5
--- /dev/null
+++ b/plugins/luarocks/luasocket-1-build-on-mxe.patch
@@ -0,0 +1,65 @@
+This file is part of MXE.
+See index.html for further information.
+
+From 11c943734757cf703daa6768b3919b7a580fe8b0 Mon Sep 17 00:00:00 2001
+From: Boris Nagaev <bnagaev@gmail.com>
+Date: Sat, 10 Oct 2015 22:00:31 +0100
+Subject: [PATCH 1/2] build on MXE
+
+---
+ luasocket-scm-0.rockspec | 14 ++++++++++++--
+ src/usocket_dummy.lua | 1 +
+ 2 files changed, 13 insertions(+), 2 deletions(-)
+ create mode 100644 src/usocket_dummy.lua
+
+diff --git a/luasocket-scm-0.rockspec b/luasocket-scm-0.rockspec
+index f86567b..9b4da80 100644
+--- a/luasocket-scm-0.rockspec
++++ b/luasocket-scm-0.rockspec
+@@ -46,7 +46,14 @@ local function make_plat(plat)
+ "WINVER=0x0501",
+ "LUASOCKET_API=__declspec(dllexport)",
+ "MIME_API=__declspec(dllexport)"
+- }
++ },
++ mxe = {
++ "LUASOCKET_DEBUG",
++ "LUASOCKET_INET_PTON",
++ "WINVER=0x0501",
++ "LUASOCKET_API=__declspec(dllexport)",
++ "MIME_API=__declspec(dllexport)"
++ },
+ }
+ local modules = {
+ ["socket.core"] = {
+@@ -85,9 +92,11 @@ local function make_plat(plat)
+ incdir = "/src"
+ }
+ end
+- if plat == "win32" or plat == "mingw32" then
++ if plat == "win32" or plat == "mingw32" or plat == "mxe" then
+ modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/wsocket.c"
+ modules["socket.core"].libraries = { "ws2_32" }
++ modules["socket.unix"] = "src/usocket_dummy.lua"
++ modules["socket.serial"] = "src/usocket_dummy.lua"
+ end
+ return { modules = modules }
+ end
+@@ -95,6 +104,7 @@ end
+ build = {
+ type = "builtin",
+ platforms = {
++ mxe = make_plat("mxe"),
+ unix = make_plat("unix"),
+ macosx = make_plat("macosx"),
+ win32 = make_plat("win32"),
+diff --git a/src/usocket_dummy.lua b/src/usocket_dummy.lua
+new file mode 100644
+index 0000000..3cce676
+--- /dev/null
++++ b/src/usocket_dummy.lua
+@@ -0,0 +1 @@
++return error("This file was created to suppress build of usocket.c for MXE")
+--
+2.1.4
+
diff --git a/plugins/luarocks/luasocket-2-lual-checkint.patch b/plugins/luarocks/luasocket-2-lual-checkint.patch
new file mode 100644
index 0000000..27323e3
--- /dev/null
+++ b/plugins/luarocks/luasocket-2-lual-checkint.patch
@@ -0,0 +1,56 @@
+This file is part of MXE.
+See index.html for further information.
+
+From 25007fd7fed18926728b9a1249f827a27e1d03f1 Mon Sep 17 00:00:00 2001
+From: Boris Nagaev <bnagaev@gmail.com>
+Date: Sat, 10 Oct 2015 23:14:31 +0100
+Subject: [PATCH 2/2] luaL_checkint -> luaL_checkinteger
+
+---
+ gem/gem.c | 2 +-
+ src/luasocket.c | 2 +-
+ src/mime.c | 2 +-
+ 3 files changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/gem/gem.c b/gem/gem.c
+index 976f74d..40f33b0 100644
+--- a/gem/gem.c
++++ b/gem/gem.c
+@@ -24,7 +24,7 @@ static int pushchar(int c, int last, const char *marker,
+ }
+
+ static int eol(lua_State *L) {
+- int context = luaL_checkint(L, 1);
++ int context = luaL_checkinteger(L, 1);
+ size_t isize = 0;
+ const char *input = luaL_optlstring(L, 2, NULL, &isize);
+ const char *last = input + isize;
+diff --git a/src/luasocket.c b/src/luasocket.c
+index e6ee747..1bdfb13 100644
+--- a/src/luasocket.c
++++ b/src/luasocket.c
+@@ -64,7 +64,7 @@ static luaL_Reg func[] = {
+ * Skip a few arguments
+ \*-------------------------------------------------------------------------*/
+ static int global_skip(lua_State *L) {
+- int amount = luaL_checkint(L, 1);
++ int amount = luaL_checkinteger(L, 1);
+ int ret = lua_gettop(L) - amount - 1;
+ return ret >= 0 ? ret : 0;
+ }
+diff --git a/src/mime.c b/src/mime.c
+index dd37dcf..bd9a2a9 100644
+--- a/src/mime.c
++++ b/src/mime.c
+@@ -661,7 +661,7 @@ static int eolprocess(int c, int last, const char *marker,
+ \*-------------------------------------------------------------------------*/
+ static int mime_global_eol(lua_State *L)
+ {
+- int ctx = luaL_checkint(L, 1);
++ int ctx = luaL_checkinteger(L, 1);
+ size_t isize = 0;
+ const char *input = luaL_optlstring(L, 2, NULL, &isize);
+ const char *last = input + isize;
+--
+2.1.4
+
diff --git a/plugins/luarocks/luasocket.mk b/plugins/luarocks/luasocket.mk
new file mode 100644
index 0000000..5deac86
--- /dev/null
+++ b/plugins/luarocks/luasocket.mk
@@ -0,0 +1,23 @@
+# This file is part of MXE.
+# See index.html for further information.
+
+PKG := luasocket
+$(PKG)_WEBSITE := http://www.impa.br/~diego/software/luasocket
+$(PKG)_OWNER := https://github.com/starius
+$(PKG)_IGNORE :=
+$(PKG)_VERSION := 3.0-rc1
+$(PKG)_CHECKSUM := 8b67d9b5b545e1b694753dab7bd6cdbc24c290f2b21ba1e14c77b32817ea1249
+$(PKG)_SUBDIR := luasocket-$($(PKG)_VERSION)
+$(PKG)_FILE := $($(PKG)_SUBDIR).tar.gz
+$(PKG)_URL := https://github.com/diegonehab/luasocket/archive/v$($(PKG)_VERSION).tar.gz
+$(PKG)_DEPS := gcc luarocks
+
+define $(PKG)_UPDATE
+ $(call MXE_GET_GITHUB_TAGS, diegonehab/luasocket, v)
+endef
+
+# shared-only because luarocks is shared-only
+
+define $(PKG)_BUILD_SHARED
+ cd '$(1)' && '$(TARGET)-luarocks' make
+endef
diff --git a/plugins/luarocks/test.lua b/plugins/luarocks/test.lua
new file mode 100644
index 0000000..1016231
--- /dev/null
+++ b/plugins/luarocks/test.lua
@@ -0,0 +1,16 @@
+local lpeg = require 'lpeg'
+assert(((lpeg.R('AZ'))^1):match("TEXT") == 5)
+
+local http = require "socket.http"
+assert(http.request("http://mxe.cc"):match('MXE'))
+
+local ll = require 'llthreads2'
+local thread = ll.new("return 123")
+thread:start()
+local ok, result = thread:join()
+assert(ok)
+assert(result == 123)
+
+local rapidjson = require 'rapidjson'
+assert(rapidjson.encode(123) == '123')
+assert(rapidjson.decode('["xyz"]')[1] == "xyz")
diff --git a/src/lua.mk b/src/lua.mk
index 1fd4df9..7dfe326 100644
--- a/src/lua.mk
+++ b/src/lua.mk
@@ -10,7 +10,11 @@ $(PKG)_CHECKSUM := c740c7bb23a936944e1cc63b7c3c5351a8976d7867c5252c8854f7b2af9da
$(PKG)_SUBDIR := lua-$($(PKG)_VERSION)
$(PKG)_FILE := lua-$($(PKG)_VERSION).tar.gz
$(PKG)_URL := http://www.lua.org/ftp/$($(PKG)_FILE)
+$(PKG)_TARGETS := $(BUILD) $(MXE_TARGETS)
$(PKG)_DEPS := gcc
+$(PKG)_DEPS_$(BUILD) :=
+
+lua_SHORTVER := $(call SHORT_PKG_VERSION,lua)
define $(PKG)_UPDATE
$(WGET) -q -O- 'http://www.lua.org/download.html' | \
@@ -38,7 +42,7 @@ define $(PKG)_BUILD
CC='$(TARGET)-gcc' \
AR='$(TARGET)-ar rcu' \
RANLIB='$(TARGET)-ranlib' \
- a
+ a lua
# lua.h is installed to noinstall/ to avoid error when executing an empty
# 'install' command.
@@ -49,6 +53,7 @@ define $(PKG)_BUILD
TO_BIN='lua.h' \
INSTALL='$(INSTALL)' \
install
+ cp '$(1)/src/lua' '$(PREFIX)/$(TARGET)/bin/lua.exe'
$($(PKG)_BUILD_COMMON)
endef
@@ -60,7 +65,7 @@ define $(PKG)_BUILD_SHARED
RANLIB='echo skipped ranlib' \
SYSCFLAGS='-DLUA_BUILD_AS_DLL' \
LUA_A=lua$($(PKG)_SOVERS).dll \
- a
+ a lua
$(MAKE) -C '$(1)' -j 1 \
INSTALL_TOP='$(PREFIX)/$(TARGET)' \
INSTALL_MAN='$(1)/noinstall' \
@@ -68,17 +73,15 @@ define $(PKG)_BUILD_SHARED
INSTALL='$(INSTALL)' \
TO_LIB='liblua.dll.a' \
install
+ cp '$(1)/src/lua' '$(PREFIX)/$(TARGET)/bin/lua.exe'
$($(PKG)_BUILD_COMMON)
endef
-# disable native build temporarily
-define $(PKG)_BUILD_DISABLED
+define $(PKG)_BUILD_$(BUILD)
$(MAKE) -C '$(1)/src' -j '$(JOBS)' \
- INSTALL_TOP='$(PREFIX)/$(TARGET)' \
- INSTALL='$(INSTALL)' \
PLAT=$(shell ([ `uname -s` == Darwin ] && echo "macosx") || echo `uname -s` | tr '[:upper:]' '[:lower:]')
- $(MAKE) -C '$(1)' -j 1 \
- INSTALL_TOP='$(PREFIX)/$(TARGET)' \
- INSTALL='$(INSTALL)' \
- install
+ $(INSTALL) '$(1)/src/lua' '$(PREFIX)/bin/$(BUILD)-lua'
+ ln -sf '$(PREFIX)/bin/$(BUILD)-lua' '$(PREFIX)/$(BUILD)/bin/lua'
+ $(INSTALL) '$(1)/src/luac' '$(PREFIX)/bin/$(BUILD)-luac'
+ ln -sf '$(PREFIX)/bin/$(BUILD)-luac' '$(PREFIX)/$(BUILD)/bin/luac'
endef