summaryrefslogtreecommitdiff
path: root/binary
diff options
context:
space:
mode:
authorMike Vink <mike@pionative.com>2025-02-03 21:29:42 +0100
committerMike Vink <mike@pionative.com>2025-02-03 21:29:42 +0100
commit5155816b7b925dec5d5feb1568b1d7ceb00938b9 (patch)
treedeca28ea15e79f6f804c3d90d2ba757881638af5 /binary
fetch tarballHEADmaster
Diffstat (limited to 'binary')
-rw-r--r--binary/Makefile.windows76
-rwxr-xr-xbinary/all_in_one503
-rw-r--r--binary/lua-bz2-0.2.1-1.rockspec44
-rw-r--r--binary/lua-zlib-1.2-0.rockspec39
-rw-r--r--binary/luaposix-35.1-1.rockspec61
-rw-r--r--binary/luasec-1.3.2-1.rockspec98
-rw-r--r--binary/luasocket-3.1.0-1.rockspec135
-rwxr-xr-xbinary/static-gcc170
8 files changed, 1126 insertions, 0 deletions
diff --git a/binary/Makefile.windows b/binary/Makefile.windows
new file mode 100644
index 0000000..e749cb0
--- /dev/null
+++ b/binary/Makefile.windows
@@ -0,0 +1,76 @@
+
+# "i686-w64-mingw32" or "x86_64-w64-mingw32"
+MINGW_PREFIX?=i686-w64-mingw32
+# sysroot of your mingw-w64 installation
+MINGW_SYSROOT=/usr/lib/mingw-w64-sysroot/$(MINGW_PREFIX)
+# "mingw" or "mingw64"
+OPENSSL_PLATFORM=mingw
+# Versions of dependencies
+LIBLUA_VERSION=5.4.3
+OPENSSL_VERSION=1.0.2o
+ZLIB_VERSION=1.3.1
+BZIP2_VERSION=1.0.6
+
+WINDOWS_DEPS_DIR=windows-deps-$(MINGW_PREFIX)
+BUILD_WINDOWS_DEPS_DIR=build-windows-deps-$(MINGW_PREFIX)
+BUILD_WINDOWS_BINARY_DIR=build-windows-binary-$(MINGW_PREFIX)
+
+windows-binary: $(WINDOWS_DEPS_DIR)/lib/liblua.a $(WINDOWS_DEPS_DIR)/lib/libssl.a $(WINDOWS_DEPS_DIR)/lib/libz.a $(WINDOWS_DEPS_DIR)/lib/libbz2.a
+ STATIC_GCC_AR=$(MINGW_PREFIX)-ar \
+ STATIC_GCC_RANLIB=$(MINGW_PREFIX)-ranlib \
+ STATIC_GCC_CC=$(MINGW_PREFIX)-gcc \
+ LUAROCKS_CROSS_COMPILING=1 \
+ $(MAKE) binary LUA_DIR=$(CURDIR)/$(WINDOWS_DEPS_DIR) CC=$(MINGW_PREFIX)-gcc NM=$(MINGW_PREFIX)-nm BINARY_PLATFORM=windows buildbinarydir=$(BUILD_WINDOWS_BINARY_DIR) BINARY_SYSROOT=$(MINGW_SYSROOT)
+
+$(BUILD_WINDOWS_DEPS_DIR)/lua-$(LIBLUA_VERSION).tar.gz:
+ mkdir -p $(@D)
+ cd $(BUILD_WINDOWS_DEPS_DIR) && curl -OL https://www.lua.org/ftp/lua-$(LIBLUA_VERSION).tar.gz
+$(BUILD_WINDOWS_DEPS_DIR)/lua-$(LIBLUA_VERSION): $(BUILD_WINDOWS_DEPS_DIR)/lua-$(LIBLUA_VERSION).tar.gz
+ cd $(BUILD_WINDOWS_DEPS_DIR) && tar zxvpf lua-$(LIBLUA_VERSION).tar.gz
+$(WINDOWS_DEPS_DIR)/lib/liblua.a: $(BUILD_WINDOWS_DEPS_DIR)/lua-$(LIBLUA_VERSION)
+ $(MAKE) -C "$(BUILD_WINDOWS_DEPS_DIR)/lua-$(LIBLUA_VERSION)/src" LUA_A=liblua.a CC=$(MINGW_PREFIX)-gcc AR="$(MINGW_PREFIX)-ar rcu" RANLIB=$(MINGW_PREFIX)-ranlib SYSCFLAGS= SYSLIBS= SYSLDFLAGS= liblua.a
+ mkdir -p $(WINDOWS_DEPS_DIR)/include
+ cd $(BUILD_WINDOWS_DEPS_DIR)/lua-$(LIBLUA_VERSION)/src && cp lauxlib.h lua.h lua.hpp luaconf.h lualib.h ../../../$(WINDOWS_DEPS_DIR)/include
+ mkdir -p $(WINDOWS_DEPS_DIR)/lib
+ cd $(BUILD_WINDOWS_DEPS_DIR)/lua-$(LIBLUA_VERSION)/src && cp liblua.a ../../../$(WINDOWS_DEPS_DIR)/lib
+
+$(BUILD_WINDOWS_DEPS_DIR)/openssl-$(OPENSSL_VERSION).tar.gz:
+ mkdir -p $(@D)
+ cd $(BUILD_WINDOWS_DEPS_DIR) && curl -OL https://www.openssl.org/source/openssl-$(OPENSSL_VERSION).tar.gz
+$(BUILD_WINDOWS_DEPS_DIR)/openssl-$(OPENSSL_VERSION): $(BUILD_WINDOWS_DEPS_DIR)/openssl-$(OPENSSL_VERSION).tar.gz
+ cd $(BUILD_WINDOWS_DEPS_DIR) && tar zxvpf openssl-$(OPENSSL_VERSION).tar.gz
+$(WINDOWS_DEPS_DIR)/lib/libssl.a: $(BUILD_WINDOWS_DEPS_DIR)/openssl-$(OPENSSL_VERSION)
+ cd $(BUILD_WINDOWS_DEPS_DIR)/openssl-$(OPENSSL_VERSION) && ./Configure --prefix=$(CURDIR)/$(WINDOWS_DEPS_DIR) --cross-compile-prefix=$(MINGW_PREFIX)- $(OPENSSL_PLATFORM)
+ $(MAKE) -C "$(BUILD_WINDOWS_DEPS_DIR)/openssl-$(OPENSSL_VERSION)"
+ $(MAKE) -C "$(BUILD_WINDOWS_DEPS_DIR)/openssl-$(OPENSSL_VERSION)" install_sw
+
+$(BUILD_WINDOWS_DEPS_DIR)/zlib-$(ZLIB_VERSION).tar.gz:
+ mkdir -p $(@D)
+ cd $(BUILD_WINDOWS_DEPS_DIR) && curl -OL https://www.zlib.net/zlib-$(ZLIB_VERSION).tar.gz
+$(BUILD_WINDOWS_DEPS_DIR)/zlib-$(ZLIB_VERSION): $(BUILD_WINDOWS_DEPS_DIR)/zlib-$(ZLIB_VERSION).tar.gz
+ cd $(BUILD_WINDOWS_DEPS_DIR) && tar zxvpf zlib-$(ZLIB_VERSION).tar.gz
+$(WINDOWS_DEPS_DIR)/lib/libz.a: $(BUILD_WINDOWS_DEPS_DIR)/zlib-$(ZLIB_VERSION)
+ cd $(BUILD_WINDOWS_DEPS_DIR)/zlib-$(ZLIB_VERSION) && sed -ie "s,dllwrap,$(MINGW_PREFIX)-dllwrap," win32/Makefile.gcc
+ cd $(BUILD_WINDOWS_DEPS_DIR)/zlib-$(ZLIB_VERSION) && ./configure --prefix=$(CURDIR)/$(WINDOWS_DEPS_DIR) --static
+ cd $(BUILD_WINDOWS_DEPS_DIR)/zlib-$(ZLIB_VERSION) && $(MAKE) -f win32/Makefile.gcc CC=$(MINGW_PREFIX)-gcc AR=$(MINGW_PREFIX)-ar RC=$(MINGW_PREFIX)-windres STRIP=$(MINGW_PREFIX)-strip IMPLIB=libz.dll.a
+ mkdir -p $(WINDOWS_DEPS_DIR)/include
+ cd $(BUILD_WINDOWS_DEPS_DIR)/zlib-$(ZLIB_VERSION) && cp zlib.h zconf.h ../../$(WINDOWS_DEPS_DIR)/include
+ cd $(BUILD_WINDOWS_DEPS_DIR)/zlib-$(ZLIB_VERSION) && $(MINGW_PREFIX)-strip -g libz.a
+ mkdir -p $(@D)
+ cd $(BUILD_WINDOWS_DEPS_DIR)/zlib-$(ZLIB_VERSION) && cp libz.a ../../$(WINDOWS_DEPS_DIR)/lib
+
+$(BUILD_WINDOWS_DEPS_DIR)/bzip2-$(BZIP2_VERSION).tar.gz:
+ mkdir -p $(@D)
+ cd $(BUILD_WINDOWS_DEPS_DIR) && curl -OL http://downloads.sourceforge.net/project/bzip2/bzip2-$(BZIP2_VERSION).tar.gz
+$(BUILD_WINDOWS_DEPS_DIR)/bzip2-$(BZIP2_VERSION): $(BUILD_WINDOWS_DEPS_DIR)/bzip2-$(BZIP2_VERSION).tar.gz
+ cd $(BUILD_WINDOWS_DEPS_DIR) && tar zxvpf bzip2-$(BZIP2_VERSION).tar.gz
+$(WINDOWS_DEPS_DIR)/lib/libbz2.a: $(BUILD_WINDOWS_DEPS_DIR)/bzip2-$(BZIP2_VERSION)
+ $(MAKE) -C "$(BUILD_WINDOWS_DEPS_DIR)/bzip2-$(BZIP2_VERSION)" libbz2.a CC=$(MINGW_PREFIX)-gcc AR=$(MINGW_PREFIX)-ar RANLIB=$(MINGW_PREFIX)-ranlib
+ mkdir -p $(WINDOWS_DEPS_DIR)/include
+ cd $(BUILD_WINDOWS_DEPS_DIR)/bzip2-$(BZIP2_VERSION) && cp bzlib.h ../../$(WINDOWS_DEPS_DIR)/include
+ cd $(BUILD_WINDOWS_DEPS_DIR)/bzip2-$(BZIP2_VERSION) && $(MINGW_PREFIX)-strip -g libbz2.a
+ mkdir -p $(WINDOWS_DEPS_DIR)/lib
+ cd $(BUILD_WINDOWS_DEPS_DIR)/bzip2-$(BZIP2_VERSION) && cp libbz2.a ../../$(WINDOWS_DEPS_DIR)/lib
+
+windows-clean:
+ rm -rf $(WINDOWS_DEPS_DIR) $(BUILD_WINDOWS_BINARY_DIR)
diff --git a/binary/all_in_one b/binary/all_in_one
new file mode 100755
index 0000000..9b675eb
--- /dev/null
+++ b/binary/all_in_one
@@ -0,0 +1,503 @@
+#!/usr/bin/env lua
+--[[
+
+All-in-one packager for LuaRocks
+ * by Hisham Muhammad <hisham@gobolinux.org>
+ * licensed under the same terms as Lua (MIT license).
+
+Based on:
+
+* srlua.c - Lua interpreter for self-running programs
+ * by Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br>
+ * 03 Nov 2014 15:31:43
+ * srlua.c is placed in the public domain.
+* bin2c.lua - converts a binary to a C string that can be embedded
+ * by Mark Edgar
+ * http://lua-users.org/wiki/BinTwoCee
+ * bin2c.lua is licensed under the same terms as Lua (MIT license).
+* lua.c - Lua stand-alone interpreter
+ * by Luiz Henrique de Figueiredo, Waldemar Celes, Roberto Ierusalimschy
+ * lua.c is licensed under the same terms as Lua (MIT license).
+* luastatic - builds a standalone executable from a Lua program
+ * by Eric R. Schulz
+ * https://github.com/ers35/luastatic
+ * luastatic is licensed under the CC0 1.0 Universal license
+
+]]
+
+local MAIN_PROGRAM = arg[1] or "src/bin/luarocks"
+local LUA_DIR = arg[2] or "/usr"
+local EXCLUDE = arg[3] or "^src/luarocks/admin/"
+local SYSCONFDIR = arg[4] or "/etc/luarocks"
+local TARGET_DIR = arg[5] or "build-binary"
+local FORCE_CONFIG = (arg[6] == "yes")
+local MY_PLATFORM = arg[7] or "unix"
+local CC = arg[8] or "gcc"
+local NM = arg[9] or "nm"
+local CROSSCOMPILER_SYSROOT = arg[10] or "/usr/lib/mingw-w64-sysroot/i686-w64-mingw32"
+local TRIPLET = arg[11] or CROSSCOMPILER_SYSROOT:gsub(".*/", "")
+local PROCESSOR = arg[12] or TRIPLET:gsub("%-.*", "")
+if PROCESSOR == "i686" then
+ PROCESSOR = "x86"
+end
+
+local LUA_MODULES = TARGET_DIR .. "/lua_modules"
+local CONFIG_DIR = TARGET_DIR .. "/.luarocks"
+
+package.path = "./src/?.lua;" .. package.path
+
+local fs = require("luarocks.fs")
+local cfg = require("luarocks.core.cfg")
+local cmd = require("luarocks.cmd")
+local deps = require("luarocks.deps")
+local path = require("luarocks.path")
+local manif = require("luarocks.manif")
+local queries = require("luarocks.queries")
+local persist = require("luarocks.persist")
+local sysdetect = require("luarocks.core.sysdetect")
+
+--------------------------------------------------------------------------------
+
+local function if_platform(plat, val)
+ if MY_PLATFORM == plat then
+ return val
+ end
+end
+
+local function reindent_c(input)
+ local out = {}
+ local indent = 0
+ local previous_is_blank = true
+ for line in input:gmatch("([^\n]*)") do
+ line = line:match("^[ \t]*(.-)[ \t]*$")
+
+ local is_blank = (#line == 0)
+ local do_print =
+ (not is_blank) or
+ (not previous_is_blank and indent == 0)
+
+ if line:match("^[})]") then
+ indent = indent - 1
+ if indent < 0 then indent = 0 end
+ end
+ if do_print then
+ table.insert(out, string.rep(" ", indent))
+ table.insert(out, line)
+ table.insert(out, "\n")
+ end
+ if line:match("[{(]$") then
+ indent = indent + 1
+ end
+
+ previous_is_blank = is_blank
+ end
+ return table.concat(out)
+end
+
+local hexdump
+do
+ local numtab = {}
+ for i = 0, 255 do
+ numtab[string.char(i)] = ("%-3d,"):format(i)
+ end
+ function hexdump(str)
+ return (str:gsub(".", numtab):gsub(("."):rep(80), "%0\n"))
+ end
+end
+
+local c_preamble = [[
+
+#include <lua.h>
+#include <lualib.h>
+#include <lauxlib.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+/* portable alerts, from srlua */
+#ifdef _WIN32
+#include <windows.h>
+#define alert(message) MessageBox(NULL, message, progname, MB_ICONERROR | MB_OK)
+#define getprogname() char name[MAX_PATH]; argv[0]= GetModuleFileName(NULL,name,sizeof(name)) ? name : NULL;
+#else
+#define alert(message) fprintf(stderr,"%s: %s\n", progname, message)
+#define getprogname()
+#endif
+
+static int registry_key;
+
+/* fatal error, from srlua */
+static void fatal(const char* message) {
+ alert(message);
+ exit(EXIT_FAILURE);
+}
+
+]]
+
+local function bin2c_file(out, filename)
+ local fd = io.open(filename, "rb")
+ local content = fd:read("*a"):gsub("^#![^\n]+\n", "")
+ fd:close()
+ table.insert(out, ("static const unsigned char code[] = {"))
+ table.insert(out, hexdump(content))
+ table.insert(out, ("};"))
+end
+
+local function write_hardcoded_module(dir)
+
+ local system, processor
+ if if_platform("unix", true) then
+ system, processor = sysdetect.detect()
+ else
+ system, processor = "windows", PROCESSOR
+ end
+
+ local hardcoded = {
+ SYSTEM = system,
+ PROCESSOR = processor,
+ FORCE_CONFIG = FORCE_CONFIG,
+ IS_BINARY = true,
+
+ SYSCONFDIR = if_platform("unix", SYSCONFDIR),
+ }
+
+ local name = dir .. "/luarocks/core/hardcoded.lua"
+ persist.save_as_module(name, hardcoded)
+ return name
+end
+
+local function declare_modules(out, dirs, skip)
+ skip = skip or {}
+ table.insert(out, [[
+ static void declare_modules(lua_State* L) {
+ lua_settop(L, 0); /* */
+ lua_newtable(L); /* modules */
+ lua_pushlightuserdata(L, (void*) &registry_key); /* modules registry_key */
+ lua_pushvalue(L, 1); /* modules registry_key modules */
+ lua_rawset(L, LUA_REGISTRYINDEX); /* modules */
+ ]])
+ for _, dir in ipairs(dirs) do
+ for _, name in ipairs(fs.find(dir)) do
+ local run = true
+ for _, pat in ipairs(skip) do
+ if name:match(pat) then
+ run = false
+ break
+ end
+ end
+ if run then
+ local filename = dir .. "/" .. name
+ if fs.is_file(filename) then
+ print(name)
+ local modname = name:gsub("%.lua$", ""):gsub("/", ".")
+ table.insert(out, ("/* %s */"):format(modname))
+ table.insert(out, ("{"))
+ bin2c_file(out, filename)
+ table.insert(out, ("luaL_loadbuffer(L, code, sizeof(code), %q);"):format(filename))
+ table.insert(out, ("lua_setfield(L, 1, %q);"):format(modname))
+ table.insert(out, ("}"))
+ end
+ end
+ end
+ end
+ table.insert(out, [[
+ lua_settop(L, 0); /* */
+ }
+ ]])
+end
+
+local function nm(filename)
+ local pd = io.popen(NM .. " " .. filename)
+ local out = pd:read("*a")
+ pd:close()
+ return out
+end
+
+local function declare_libraries(out, dir)
+ local a_files = {}
+ local externs = {}
+ local fn = {}
+ table.insert(fn, [[
+ static void declare_libraries(lua_State* L) {
+ lua_getglobal(L, "package"); /* package */
+ lua_getfield(L, -1, "preload"); /* package package.preload */
+ ]])
+ for _, name in ipairs(fs.find(dir)) do
+ local filename = dir .. "/" .. name
+ if name:match("%.a$") then
+ table.insert(a_files, filename)
+ local nmout = nm(filename)
+ for luaopen in nmout:gmatch("[^dD] _?(luaopen_[%a%p%d]+)") do
+
+ -- FIXME what about module names with underscores?
+ local modname = luaopen:gsub("^_?luaopen_", ""):gsub("_", ".")
+
+ table.insert(externs, "extern int " .. luaopen .. "(lua_State* L);")
+ table.insert(fn, "lua_pushcfunction(L, " .. luaopen .. ");")
+ table.insert(fn, "lua_setfield(L, -2, \"" .. modname .. "\");")
+ end
+ end
+ end
+ local pd = io.popen("find " .. dir .. " -name '*.a'", "r")
+ for line in pd:lines() do
+ table.insert(a_files, line)
+ end
+ pd:close()
+ table.insert(fn, [[
+ lua_settop(L, 0); /* */
+ }
+ ]])
+
+ table.insert(out, "\n")
+ for _, line in ipairs(externs) do
+ table.insert(out, line)
+ end
+ table.insert(out, "\n")
+ for _, line in ipairs(fn) do
+ table.insert(out, line)
+ end
+ table.insert(out, "\n")
+
+ return a_files
+end
+
+local function load_main(out, main_program, program_name)
+ table.insert(out, [[static void load_main(lua_State* L) {]])
+ bin2c_file(out, main_program)
+ table.insert(out, ("if(luaL_loadbuffer(L, code, sizeof(code), %q) != LUA_OK) {"):format(program_name))
+ table.insert(out, (" fatal(lua_tostring(L, -1));"))
+ table.insert(out, ("}"))
+ table.insert(out, [[}]])
+ table.insert(out, [[]])
+end
+
+local c_main = [[
+
+/* custom package loader */
+static int pkg_loader(lua_State* L) {
+ lua_pushlightuserdata(L, (void*) &registry_key); /* modname ? registry_key */
+ lua_rawget(L, LUA_REGISTRYINDEX); /* modname ? modules */
+ lua_pushvalue(L, -1); /* modname ? modules modules */
+ lua_pushvalue(L, 1); /* modname ? modules modules modname */
+ lua_gettable(L, -2); /* modname ? modules mod */
+ if (lua_type(L, -1) == LUA_TNIL) {
+ lua_pop(L, 1); /* modname ? modules */
+ lua_pushvalue(L, 1); /* modname ? modules modname */
+ lua_pushliteral(L, ".init"); /* modname ? modules modname ".init" */
+ lua_concat(L, 2); /* modname ? modules modname..".init" */
+ lua_gettable(L, -2); /* modname ? mod */
+ }
+ return 1;
+}
+
+static void install_pkg_loader(lua_State* L) {
+ lua_settop(L, 0); /* */
+ lua_getglobal(L, "table"); /* table */
+ lua_getfield(L, -1, "insert"); /* table table.insert */
+ lua_getglobal(L, "package"); /* table table.insert package */
+ lua_getfield(L, -1, "searchers"); /* table table.insert package package.searchers */
+ if (lua_type(L, -1) == LUA_TNIL) {
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "loaders"); /* table table.insert package package.loaders */
+ }
+ lua_copy(L, 4, 3); /* table table.insert package.searchers */
+ lua_settop(L, 3); /* table table.insert package.searchers */
+ lua_pushnumber(L, 1); /* table table.insert package.searchers 1 */
+ lua_pushcfunction(L, pkg_loader); /* table table.insert package.searchers 1 pkg_loader */
+ lua_call(L, 3, 0); /* table */
+ lua_settop(L, 0); /* */
+}
+
+/* main script launcher, from srlua */
+static int pmain(lua_State *L) {
+ int argc = lua_tointeger(L, 1);
+ char** argv = lua_touserdata(L, 2);
+ int i;
+ load_main(L);
+ lua_createtable(L, argc, 0);
+ for (i = 0; i < argc; i++) {
+ lua_pushstring(L, argv[i]);
+ lua_rawseti(L, -2, i);
+ }
+ lua_setglobal(L, "arg");
+ luaL_checkstack(L, argc - 1, "too many arguments to script");
+ for (i = 1; i < argc; i++) {
+ lua_pushstring(L, argv[i]);
+ }
+ lua_call(L, argc - 1, 0);
+ return 0;
+}
+
+/* error handler, from luac */
+static int msghandler (lua_State *L) {
+ /* is error object not a string? */
+ const char *msg = lua_tostring(L, 1);
+ if (msg == NULL) {
+ /* does it have a metamethod that produces a string */
+ if (luaL_callmeta(L, 1, "__tostring") && lua_type(L, -1) == LUA_TSTRING) {
+ /* then that is the message */
+ return 1;
+ } else {
+ msg = lua_pushfstring(L, "(error object is a %s value)", luaL_typename(L, 1));
+ }
+ }
+ /* append a standard traceback */
+ luaL_traceback(L, L, msg, 1);
+ return 1;
+}
+
+/* main function, from srlua */
+int main(int argc, char** argv) {
+ lua_State* L;
+ getprogname();
+ if (argv[0] == NULL) {
+ fatal("cannot locate this executable");
+ }
+ L = luaL_newstate();
+ if (L == NULL) {
+ fatal("not enough memory for state");
+ }
+ luaL_openlibs(L);
+ install_pkg_loader(L);
+ declare_libraries(L);
+ declare_modules(L);
+ lua_pushcfunction(L, &msghandler);
+ lua_pushcfunction(L, &pmain);
+ lua_pushinteger(L, argc);
+ lua_pushlightuserdata(L, argv);
+ if (lua_pcall(L, 2, 0, -4) != 0) {
+ fatal(lua_tostring(L, -1));
+ }
+ lua_close(L);
+ return EXIT_SUCCESS;
+}
+
+]]
+
+local function filter_in(f, xs)
+ for i = #xs, 1, -1 do
+ if not f(xs[i]) then
+ table.remove(xs, i)
+ end
+ end
+ return xs
+end
+
+local function nonnull(x) return x ~= nil end
+
+local function generate(main_program, dir, skip)
+ local program_name = main_program:gsub(".*/", "")
+
+ local hardcoded = write_hardcoded_module(dir)
+
+ local out = {}
+ table.insert(out, ([[static const char* progname = %q;]]):format(program_name))
+ table.insert(out, c_preamble)
+ load_main(out, main_program, program_name)
+ local lua_modules = LUA_MODULES .. "/share/lua/" .. cfg.lua_version
+ declare_modules(out, { dir, lua_modules }, skip)
+ local a_files = declare_libraries(out, LUA_MODULES .. "/lib/lua/" .. cfg.lua_version)
+ table.insert(out, c_main)
+
+ os.remove(hardcoded)
+
+ local c_filename = TARGET_DIR .. "/" .. program_name .. ".exe.c"
+ local fd = io.open(c_filename, "w")
+ fd:write(reindent_c(table.concat(out, "\n")))
+ fd:close()
+
+ assert(deps.check_lua_incdir(cfg.variables))
+ assert(deps.check_lua_libdir(cfg.variables))
+
+ cmd = table.concat(filter_in(nonnull, {
+ CC, "-o", TARGET_DIR .. "/" .. program_name .. ".exe",
+ "-I", cfg.variables.LUA_INCDIR,
+ if_platform("unix", "-rdynamic"),
+ "-Os",
+ c_filename,
+ "-L", cfg.variables.LUA_LIBDIR,
+ table.concat(a_files, " "),
+ --if_platform("unix", cfg.variables.LUA_LIBDIR .. "/" .. cfg.variables.LUALIB:gsub("%.so.*$", ".a")),
+ --if_platform("windows", "mingw/liblua.a"), -- FIXME
+ cfg.variables.LUA_LIBDIR .. "/" .. cfg.variables.LUALIB:gsub("%.so.*$", ".a"),
+ if_platform("unix", "-ldl"),
+ if_platform("unix", "-lpthread"),
+ if_platform("windows", "-mconsole -mwindows"),
+ "-lm"
+ }), " ")
+ print(cmd)
+ os.execute(cmd)
+end
+
+--------------------------------------------------------------------------------
+
+local function main()
+
+ os.remove("src/luarocks/core/hardcoded.lua")
+ cfg.init()
+ cfg.variables.LUA_DIR = LUA_DIR
+ cfg.variables.LUA_INCDIR = nil -- let it autodetect later
+ cfg.variables.LUA_LIBDIR = nil -- let it autodetect later
+ fs.init()
+ path.use_tree(LUA_MODULES)
+
+ local CONFIG_FILE = CONFIG_DIR .. "/config-" .. cfg.lua_version .. ".lua"
+
+ fs.make_dir(CONFIG_DIR)
+
+ persist.save_from_table(CONFIG_FILE, {
+ lib_extension = "a",
+ external_lib_extension = "a",
+ variables = {
+ CC = fs.current_dir() .. "/binary/static-gcc",
+ LD = fs.current_dir() .. "/binary/static-gcc",
+ LIB_EXTENSION = "a",
+ LUA_DIR = LUA_DIR,
+ LIBFLAG = "-static",
+ PWD = "pwd",
+ MKDIR = "mkdir",
+ },
+ platforms = if_platform("windows", { "windows", "win32", "mingw32" }),
+ external_deps_dirs = if_platform("windows", { CROSSCOMPILER_SYSROOT, fs.current_dir() .. "/windows-deps-" .. TRIPLET }),
+ })
+
+ local dependencies = {
+ md5 = "md5",
+ luasocket = "./binary/luasocket-3.1.0-1.rockspec",
+ luasec = "./binary/luasec-1.3.2-1.rockspec",
+ ["lua-zlib"] = "./binary/lua-zlib-1.2-0.rockspec",
+ ["lua-bz2"] = "./binary/lua-bz2-0.2.1-1.rockspec",
+ luaposix = if_platform("unix", "./binary/luaposix-35.1-1.rockspec"),
+ luafilesystem = "luafilesystem",
+ }
+
+ local dependency_order = {
+ "md5",
+ "luasocket", "luasec",
+ "lua-zlib",
+ "lua-bz2",
+ "luaposix",
+ "luafilesystem",
+ }
+
+ fs.make_dir(LUA_MODULES)
+ for _, name in ipairs(dependency_order) do
+ local use = dependencies[name]
+ if use then
+ print("----------------------------------------------------------------")
+ print(name)
+ print("----------------------------------------------------------------")
+ local vers = manif.get_versions(queries.from_dep_string(name), "one")
+ if not next(vers) then
+ local ok = os.execute("LUAROCKS_CONFIG='" .. CONFIG_FILE .. "' ./luarocks install --no-project '--tree=" .. LUA_MODULES .. "' " .. use)
+ if ok ~= 0 and ok ~= true then
+ error("Failed building dependency: " .. name)
+ end
+ end
+ end
+ end
+
+ generate(MAIN_PROGRAM, "src", { EXCLUDE, "^bin/?" })
+end
+
+main()
diff --git a/binary/lua-bz2-0.2.1-1.rockspec b/binary/lua-bz2-0.2.1-1.rockspec
new file mode 100644
index 0000000..ec582b4
--- /dev/null
+++ b/binary/lua-bz2-0.2.1-1.rockspec
@@ -0,0 +1,44 @@
+package = "lua-bz2"
+version = "0.2.1-1"
+source = {
+ url = "git+https://github.com/hishamhm/lua-bz2.git",
+ tag = "0.2.1",
+}
+description = {
+ summary = "A Lua binding to Julian Seward's libbzip2",
+ detailed = [[
+ Support for reading and writing .bz2 files
+ and handling streams compressed in bzip2 format.
+ ]],
+ homepage = "https://github.com/harningt/lua-bz2",
+ license = "ISC"
+}
+external_dependencies = {
+ BZ2 = {
+ library = "bz2"
+ }
+}
+build = {
+ type = "builtin",
+ modules = {
+ bz2 = {
+ incdirs = {
+ "$(BZ2_INCDIR)"
+ },
+ libdirs = {
+ "$(BZ2_LIBDIR)"
+ },
+ libraries = {
+ "bz2"
+ },
+ sources = {
+ "lbz.c",
+ "lbz2_common.c",
+ "lbz2_file_reader.c",
+ "lbz2_file_writer.c",
+ "lbz2_stream.c",
+ }
+ },
+ ["bz2.ltn12"] = "bz2/ltn12.lua",
+ }
+}
diff --git a/binary/lua-zlib-1.2-0.rockspec b/binary/lua-zlib-1.2-0.rockspec
new file mode 100644
index 0000000..9d3adc8
--- /dev/null
+++ b/binary/lua-zlib-1.2-0.rockspec
@@ -0,0 +1,39 @@
+package = "lua-zlib"
+version = "1.2-0"
+source = {
+ url = "git+https://github.com/brimworks/lua-zlib.git",
+ tag = "v1.2",
+}
+description = {
+ summary = "Simple streaming interface to zlib for Lua.",
+ detailed = [[
+ Simple streaming interface to zlib for Lua.
+ Consists of two functions: inflate and deflate.
+ Both functions return "stream functions" (takes a buffer of input and returns a buffer of output).
+ This project is hosted on github.
+ ]],
+ homepage = "https://github.com/brimworks/lua-zlib",
+ license = "MIT"
+}
+dependencies = {
+ "lua >= 5.1, <= 5.4"
+}
+external_dependencies = {
+ ZLIB = {
+ header = "zlib.h",
+ library = "z",
+ }
+}
+
+build = {
+ type = "builtin",
+ modules = {
+ zlib = {
+ sources = { "lua_zlib.c" },
+ libraries = { "z" },
+ defines = { "LZLIB_COMPAT" },
+ incdirs = { "$(ZLIB_INCDIR)" },
+ libdirs = { "$(ZLIB_LIBDIR)" },
+ }
+ },
+}
diff --git a/binary/luaposix-35.1-1.rockspec b/binary/luaposix-35.1-1.rockspec
new file mode 100644
index 0000000..1940c75
--- /dev/null
+++ b/binary/luaposix-35.1-1.rockspec
@@ -0,0 +1,61 @@
+local _MODREV, _SPECREV = '35.1', '-1'
+
+package = 'luaposix'
+version = _MODREV .. _SPECREV
+
+description = {
+ summary = 'Lua bindings for POSIX',
+ detailed = [[
+ A library binding various POSIX APIs. POSIX is the IEEE Portable
+ Operating System Interface standard. luaposix is based on lposix.
+ ]],
+ homepage = 'http://github.com/luaposix/luaposix/',
+ license = 'MIT/X11',
+}
+
+dependencies = {
+ 'lua >= 5.1, < 5.5',
+}
+
+do
+ -- We only want to install a bit32 module for Lua 5.1.
+ local _ENV={package=nil, dependencies=dependencies}
+ if package then
+ dependencies[#dependencies + 1] = 'bit32'
+ end
+end
+
+source = {
+ url = 'http://github.com/luaposix/luaposix/archive/v' .. _MODREV .. '.zip',
+ dir = 'luaposix-' .. _MODREV,
+}
+
+build = {
+ type = 'command',
+ build_command = '$(LUA) build-aux/luke'
+ .. ' package="' .. package .. '"'
+ .. ' version="' .. _MODREV .. '"'
+ .. ' PREFIX="$(PREFIX)"'
+ .. ' LUA="$(LUA)"'
+ .. ' LUA_INCDIR="$(LUA_INCDIR)"'
+ .. ' CFLAGS="$(CFLAGS)"'
+ .. ' LIBFLAG="$(LIBFLAG)"'
+ .. ' LIB_EXTENSION="$(LIB_EXTENSION)"'
+ .. ' OBJ_EXTENSION="$(OBJ_EXTENSION)"'
+ .. ' INST_LIBDIR="$(LIBDIR)"'
+ .. ' INST_LUADIR="$(LUADIR)"'
+ ,
+ install_command = '$(LUA) build-aux/luke install --quiet'
+ .. ' INST_LIBDIR="$(LIBDIR)"'
+ .. ' LIB_EXTENSION="$(LIB_EXTENSION)"'
+ .. ' INST_LUADIR="$(LUADIR)"'
+ ,
+}
+
+if _MODREV == 'git' then
+ dependencies[#dependencies + 1] = 'ldoc'
+
+ source = {
+ url = 'git://github.com/luaposix/luaposix.git',
+ }
+end
diff --git a/binary/luasec-1.3.2-1.rockspec b/binary/luasec-1.3.2-1.rockspec
new file mode 100644
index 0000000..81cb31f
--- /dev/null
+++ b/binary/luasec-1.3.2-1.rockspec
@@ -0,0 +1,98 @@
+package = "LuaSec"
+version = "1.3.2-1"
+source = {
+ url = "git+https://github.com/brunoos/luasec",
+ tag = "v1.3.2",
+}
+description = {
+ summary = "A binding for OpenSSL library to provide TLS/SSL communication over LuaSocket.",
+ detailed = "This version delegates to LuaSocket the TCP connection establishment between the client and server. Then LuaSec uses this connection to start a secure TLS/SSL session.",
+ homepage = "https://github.com/brunoos/luasec/wiki",
+ license = "MIT"
+}
+dependencies = {
+ "lua >= 5.1", "luasocket"
+}
+external_dependencies = {
+ platforms = {
+ unix = {
+ OPENSSL = {
+ header = "openssl/ssl.h",
+ library = "ssl"
+ }
+ },
+ windows = {
+ OPENSSL = {
+ header = "openssl/ssl.h",
+ }
+ },
+ mingw32 = {
+ OPENSSL = {
+ library = "ssl",
+ }
+ },
+ }
+}
+build = {
+ type = "builtin",
+ copy_directories = {
+ "samples"
+ },
+ platforms = {
+ unix = {
+ modules = {
+ ['ssl.https'] = "src/https.lua",
+ ['ssl.init'] = "src/ssl.lua",
+ ssl = {
+ defines = {
+ "WITH_LUASOCKET", "LUASOCKET_DEBUG",
+ },
+ incdirs = {
+ "$(OPENSSL_INCDIR)", "src/", "src/luasocket",
+ },
+ libdirs = {
+ "$(OPENSSL_LIBDIR)"
+ },
+ libraries = {
+ "ssl", "crypto"
+ },
+ sources = {
+ "src/options.c", "src/config.c", "src/ec.c",
+ "src/x509.c", "src/context.c", "src/ssl.c",
+ "src/luasocket/buffer.c", "src/luasocket/io.c",
+ "src/luasocket/usocket.c" -- , "src/luasocket/timeout.c"
+ }
+ }
+ }
+ },
+ windows = {
+ modules = {
+ ['ssl.https'] = "src/https.lua",
+ ['ssl.init'] = "src/ssl.lua",
+ ssl = {
+ defines = {
+ "WIN32", "NDEBUG", "_WINDOWS", "_USRDLL", "LSEC_EXPORTS", "BUFFER_DEBUG", "LSEC_API=__declspec(dllexport)",
+ "WITH_LUASOCKET", "LUASOCKET_DEBUG",
+ "LUASEC_INET_NTOP", "WINVER=0x0501", "_WIN32_WINNT=0x0501", "NTDDI_VERSION=0x05010300"
+ },
+ libdirs = {
+ "$(OPENSSL_LIBDIR)",
+ "$(OPENSSL_BINDIR)",
+ },
+ libraries = {
+ "ssl", "crypto", "ws2_32"
+ },
+ incdirs = {
+ "$(OPENSSL_INCDIR)", "src/", "src/luasocket"
+ },
+ sources = {
+ "src/options.c", "src/config.c", "src/ec.c",
+ "src/x509.c", "src/context.c", "src/ssl.c",
+ "src/luasocket/buffer.c", "src/luasocket/io.c",
+ "src/luasocket/timeout.c", "src/luasocket/wsocket.c"
+ },
+ },
+ },
+ },
+ }
+}
diff --git a/binary/luasocket-3.1.0-1.rockspec b/binary/luasocket-3.1.0-1.rockspec
new file mode 100644
index 0000000..dd9e636
--- /dev/null
+++ b/binary/luasocket-3.1.0-1.rockspec
@@ -0,0 +1,135 @@
+package = "LuaSocket"
+version = "3.1.0-1"
+source = {
+ url = "git+https://github.com/lunarmodules/luasocket.git",
+ tag = "v3.1.0"
+}
+description = {
+ summary = "Network support for the Lua language",
+ detailed = [[
+ LuaSocket is a Lua extension library composed of two parts: a set of C
+ modules that provide support for the TCP and UDP transport layers, and a
+ set of Lua modules that provide functions commonly needed by applications
+ that deal with the Internet.
+ ]],
+ homepage = "https://github.com/lunarmodules/luasocket",
+ license = "MIT"
+}
+dependencies = {
+ "lua >= 5.1"
+}
+
+local function make_plat(plat)
+ local defines = {
+ unix = {
+ "LUASOCKET_DEBUG"
+ },
+ macosx = {
+ "LUASOCKET_DEBUG",
+ "UNIX_HAS_SUN_LEN"
+ },
+ win32 = {
+ "LUASOCKET_DEBUG",
+ "NDEBUG"
+ },
+ mingw32 = {
+ "LUASOCKET_DEBUG",
+ "LUASOCKET_INET_PTON",
+ "WINVER=0x0501"
+ }
+ }
+ local modules = {
+ ["socket.core"] = {
+ sources = {
+ "src/luasocket.c"
+ , "src/timeout.c"
+ , "src/buffer.c"
+ , "src/io.c"
+ , "src/auxiliar.c"
+ , "src/options.c"
+ , "src/inet.c"
+ , "src/except.c"
+ , "src/select.c"
+ , "src/tcp.c"
+ , "src/udp.c"
+ , "src/compat.c" },
+ defines = defines[plat],
+ incdir = "/src"
+ },
+ ["mime.core"] = {
+ sources = { "src/mime.c", "src/compat.c" },
+ defines = defines[plat],
+ incdir = "/src"
+ },
+ ["socket.http"] = "src/http.lua",
+ ["socket.url"] = "src/url.lua",
+ ["socket.tp"] = "src/tp.lua",
+ ["socket.ftp"] = "src/ftp.lua",
+ ["socket.headers"] = "src/headers.lua",
+ ["socket.smtp"] = "src/smtp.lua",
+ ltn12 = "src/ltn12.lua",
+ socket = "src/socket.lua",
+ mime = "src/mime.lua"
+ }
+ if plat == "unix"
+ or plat == "macosx"
+ or plat == "haiku"
+ then
+ modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/usocket.c"
+ if plat == "haiku" then
+ modules["socket.core"].libraries = {"network"}
+ end
+ modules["socket.unix"] = {
+ sources = {
+ "src/buffer.c"
+ , "src/compat.c"
+ , "src/auxiliar.c"
+ , "src/options.c"
+ , "src/timeout.c"
+ , "src/io.c"
+ , "src/usocket.c"
+ , "src/unix.c"
+ , "src/unixdgram.c"
+ , "src/unixstream.c" },
+ defines = defines[plat],
+ incdir = "/src"
+ }
+ modules["socket.serial"] = {
+ sources = {
+ "src/buffer.c"
+ , "src/compat.c"
+ , "src/auxiliar.c"
+ , "src/options.c"
+ , "src/timeout.c"
+ , "src/io.c"
+ , "src/usocket.c"
+ , "src/serial.c" },
+ defines = defines[plat],
+ incdir = "/src"
+ }
+ end
+ if plat == "win32"
+ or plat == "mingw32"
+ then
+ modules["socket.core"].sources[#modules["socket.core"].sources+1] = "src/wsocket.c"
+ modules["socket.core"].libraries = { "ws2_32" }
+ modules["socket.core"].libdirs = {}
+ end
+ return { modules = modules }
+end
+
+build = {
+ type = "builtin",
+ platforms = {
+ unix = make_plat("unix"),
+ macosx = make_plat("macosx"),
+ haiku = make_plat("haiku"),
+ win32 = make_plat("win32"),
+ mingw32 = make_plat("mingw32")
+ },
+ copy_directories = {
+ "docs"
+ , "samples"
+ , "etc"
+ , "test" }
+}
diff --git a/binary/static-gcc b/binary/static-gcc
new file mode 100755
index 0000000..1e4ad0e
--- /dev/null
+++ b/binary/static-gcc
@@ -0,0 +1,170 @@
+#!/usr/bin/env bash
+
+STATIC_GCC_AR=${STATIC_GCC_AR:-ar}
+STATIC_GCC_RANLIB=${STATIC_GCC_RANLIB:-ranlib}
+STATIC_GCC_CC=${STATIC_GCC_CC:-gcc}
+
+DIR="$( cd "$( dirname "$0" )" && pwd )"
+
+function log() { echo -- "$@" >> $DIR/log.txt; }
+
+function runlog() { log "$@"; "$@"; }
+
+log "---------------------------"
+log INP "$@"
+
+allargs=()
+sources=()
+objects=()
+etc=()
+libdirs=($("$STATIC_GCC_CC" -print-search-dirs | grep libraries | cut -d= -f2 | tr ':' '\n'))
+incdirs=()
+
+linking=0
+
+while [ "$1" ]
+do
+ allargs+=("$1")
+ if [ "$next_libdir" = "1" ]
+ then
+ libdirs+=("$1")
+ next_libdir=0
+ elif [ "$next_incdir" = "1" ]
+ then
+ incdirs+=("-I$1")
+ next_incdir=0
+ elif [ "$next_lib" = "1" ]
+ then
+ libs+=("$1")
+ next_lib=0
+ elif [ "$next_output" = "1" ]
+ then
+ output="$1"
+ next_output=0
+ else
+ case "$1" in
+ -*)
+ case "$1" in
+ -shared)
+ linking=1
+ ;;
+ -static)
+ linking=1
+ ;;
+ -o)
+ next_output=1
+ ;;
+ -c)
+ object=1
+ etc+=("$1")
+ ;;
+ -L)
+ next_libdir=1
+ ;;
+ -L*)
+ libdirs+=("${1:2}")
+ ;;
+ -I)
+ next_incdir=1
+ ;;
+ -I*)
+ incdirs+=("$1")
+ ;;
+ -l)
+ next_lib=1
+ ;;
+ -l*)
+ libs+=("${1:2}")
+ ;;
+ *)
+ etc+=("$1")
+ ;;
+ esac
+ ;;
+ *.c)
+ sources+=("$1")
+ ;;
+ *.o)
+ objects+=("$1")
+ ;;
+ *)
+ etc+=("$1")
+ ;;
+ esac
+ fi
+ shift
+done
+
+staticlibs=()
+for lib in "${libs[@]}"
+do
+ found=0
+ for libdir in "${libdirs[@]}"
+ do
+ staticlib="$libdir/lib$lib.a"
+ if [ -e "$staticlib" ]
+ then
+ staticlibs+=("$staticlib")
+ found=1
+ break
+ fi
+ done
+ if [ "$found" = 0 ]
+ then
+ log "STATICLIB not found for $lib"
+ runlog exit 1
+ fi
+done
+
+oflag=()
+if [ "$output" != "" ]
+then
+ oflag=("-o" "$output")
+fi
+
+if [ "$linking" = "1" ]
+then
+ log LINK
+ if [ "${#sources[@]}" -gt 0 ]
+ then
+ for source in "${sources[@]}"
+ do
+ object="${source%.c}.o"
+ runlog $STATIC_GCC_CC "${incdirs[@]}" "${etc[@]}" -c -o "$object" "$source"
+ [ "$?" = 0 ] || runlog exit $?
+ objects+=("$object")
+ done
+ fi
+
+ # runlog ar rcu "${oflag[@]}" "${objects[@]}" "${staticlibs[@]}"
+ echo "CREATE $output" > ar.script
+ for o in "${objects[@]}"
+ do
+ echo "ADDMOD $o" >> ar.script
+ done
+ for o in "${staticlibs[@]}"
+ do
+ echo "ADDLIB $o" >> ar.script
+ done
+ echo "SAVE" >> ar.script
+ echo "END" >> ar.script
+ cat ar.script >> "$DIR/log.txt"
+ cat ar.script | $STATIC_GCC_AR -M
+ [ "$?" = 0 ] || runlog exit $?
+
+ [ -e "$output" ] || {
+ exit 1
+ }
+
+ runlog $STATIC_GCC_RANLIB "$output"
+ runlog exit $?
+elif [ "$object" = 1 ]
+then
+ log OBJECT
+ runlog $STATIC_GCC_CC "${oflag[@]}" "${incdirs[@]}" "${etc[@]}" "${sources[@]}"
+ runlog exit $?
+else
+ log EXECUTABLE
+ runlog $STATIC_GCC_CC "${allargs[@]}"
+ runlog exit $?
+fi