aboutsummaryrefslogtreecommitdiff
path: root/binary/all_in_one
diff options
context:
space:
mode:
Diffstat (limited to 'binary/all_in_one')
-rwxr-xr-xbinary/all_in_one145
1 files changed, 97 insertions, 48 deletions
diff --git a/binary/all_in_one b/binary/all_in_one
index de545d04..9c7a690c 100755
--- a/binary/all_in_one
+++ b/binary/all_in_one
@@ -30,6 +30,10 @@ local LUA_DIR = arg[2] or "/usr"
30local EXCLUDE = arg[3] or "^src/luarocks/admin/" 30local EXCLUDE = arg[3] or "^src/luarocks/admin/"
31local SYSCONFDIR = arg[4] or "/etc/luarocks" 31local SYSCONFDIR = arg[4] or "/etc/luarocks"
32local TARGET = arg[5] or "binary-build" 32local TARGET = arg[5] or "binary-build"
33local MY_PLATFORM = arg[6] or "unix"
34local CC = arg[7] or "gcc"
35local NM = arg[8] or "nm"
36local CROSSCOMPILER_SYSROOT = arg[9] or "/usr/lib/mingw-w64-sysroot/i686-w64-mingw32"
33 37
34local LUA_MODULES = TARGET .. "/lua_modules" 38local LUA_MODULES = TARGET .. "/lua_modules"
35local CONFIG_DIR = TARGET .. "/.luarocks" 39local CONFIG_DIR = TARGET .. "/.luarocks"
@@ -48,6 +52,12 @@ local persist = require("luarocks.persist")
48 52
49-------------------------------------------------------------------------------- 53--------------------------------------------------------------------------------
50 54
55local function if_platform(plat, val)
56 if MY_PLATFORM == plat then
57 return val
58 end
59end
60
51local function reindent_c(input) 61local function reindent_c(input)
52 local out = {} 62 local out = {}
53 local indent = 0 63 local indent = 0
@@ -110,10 +120,18 @@ local c_preamble = [[
110 120
111static int registry_key; 121static int registry_key;
112 122
123/* fatal error, from srlua */
124static void fatal(const char* message) {
125 alert(message);
126 exit(EXIT_FAILURE);
127}
128
113]] 129]]
114 130
115local function bin2c_file(out, filename) 131local function bin2c_file(out, filename)
116 local content = string.dump(assert(loadfile(filename))) 132 local fd = io.open(filename, "rb")
133 local content = fd:read("*a"):gsub("^#![^\n]+\n", "")
134 fd:close()
117 table.insert(out, ("static const unsigned char code[] = {")) 135 table.insert(out, ("static const unsigned char code[] = {"))
118 table.insert(out, hexdump(content)) 136 table.insert(out, hexdump(content))
119 table.insert(out, ("};")) 137 table.insert(out, ("};"))
@@ -121,24 +139,32 @@ end
121 139
122local function write_hardcoded_module(dir) 140local function write_hardcoded_module(dir)
123 141
124 local system = util.popen_read("uname -s") 142 local system = if_platform("windows", "MINGW")
125 local processor = util.popen_read("uname -m") 143 local processor = if_platform("windows", "x86")
126 144
127 if processor:match("i[%d]86") then 145 if not system then
128 processor = "x86" 146 system = util.popen_read("uname -s")
129 elseif processor:match("amd64") or processor:match("x86_64") then 147 processor = util.popen_read("uname -m")
130 processor = "x86_64" 148
131 elseif processor:match("Power Macintosh") then 149 if processor:match("i[%d]86") then
132 processor = "powerpc" 150 processor = "x86"
151 elseif processor:match("amd64") or processor:match("x86_64") then
152 processor = "x86_64"
153 elseif processor:match("Power Macintosh") then
154 processor = "powerpc"
155 end
133 end 156 end
134 157
135 local hardcoded = { 158 local hardcoded = {
136 SYSTEM = system, 159 SYSTEM = system,
137 PROCESSOR = processor, 160 PROCESSOR = processor,
138 SYSCONFDIR = SYSCONFDIR, 161
139 LUA_DIR = cfg.variables.LUA_DIR, 162 SYSCONFDIR = if_platform("unix", SYSCONFDIR),
140 LUA_BINDIR = cfg.variables.LUA_BINDIR, 163
141 LUA_INTERPRETER = cfg.lua_interpreter, 164 LUA_DIR = if_platform("unix", cfg.variables.LUA_DIR),
165 LUA_BINDIR = if_platform("unix", cfg.variables.LUA_BINDIR)
166 or if_platform("windows", "."),
167 LUA_INTERPRETER = if_platform("unix", cfg.lua_interpreter),
142 } 168 }
143 169
144 local name = dir .. "/luarocks/core/hardcoded.lua" 170 local name = dir .. "/luarocks/core/hardcoded.lua"
@@ -187,7 +213,7 @@ local function declare_modules(out, dirs, skip)
187end 213end
188 214
189local function nm(filename) 215local function nm(filename)
190 local pd = io.popen("nm " .. filename) 216 local pd = io.popen(NM .. " " .. filename)
191 local out = pd:read("*a") 217 local out = pd:read("*a")
192 pd:close() 218 pd:close()
193 return out 219 return out
@@ -244,7 +270,9 @@ end
244local function load_main(out, main_program, program_name) 270local function load_main(out, main_program, program_name)
245 table.insert(out, [[static void load_main(lua_State* L) {]]) 271 table.insert(out, [[static void load_main(lua_State* L) {]])
246 bin2c_file(out, main_program) 272 bin2c_file(out, main_program)
247 table.insert(out, ("luaL_loadbuffer(L, code, sizeof(code), %q);"):format(program_name)) 273 table.insert(out, ("if(luaL_loadbuffer(L, code, sizeof(code), %q) != LUA_OK) {"):format(program_name))
274 table.insert(out, (" fatal(lua_tostring(L, -1));"))
275 table.insert(out, ("}"))
248 table.insert(out, [[}]]) 276 table.insert(out, [[}]])
249 table.insert(out, [[]]) 277 table.insert(out, [[]])
250end 278end
@@ -262,7 +290,7 @@ static int pkg_loader(lua_State* L) {
262 lua_pop(L, 1); /* modname ? modules */ 290 lua_pop(L, 1); /* modname ? modules */
263 lua_pushvalue(L, 1); /* modname ? modules modname */ 291 lua_pushvalue(L, 1); /* modname ? modules modname */
264 lua_pushliteral(L, ".init"); /* modname ? modules modname ".init" */ 292 lua_pushliteral(L, ".init"); /* modname ? modules modname ".init" */
265 lua_concat(L, 2); /* modname ? modules modname .. ".init" */ 293 lua_concat(L, 2); /* modname ? modules modname..".init" */
266 lua_gettable(L, -2); /* modname ? mod */ 294 lua_gettable(L, -2); /* modname ? mod */
267 } 295 }
268 return 1; 296 return 1;
@@ -306,12 +334,6 @@ static int pmain(lua_State *L) {
306 return 0; 334 return 0;
307} 335}
308 336
309/* fatal error, from srlua */
310static void fatal(const char* message) {
311 alert(message);
312 exit(EXIT_FAILURE);
313}
314
315/* error handler, from luac */ 337/* error handler, from luac */
316static int msghandler (lua_State *L) { 338static int msghandler (lua_State *L) {
317 /* is error object not a string? */ 339 /* is error object not a string? */
@@ -358,14 +380,25 @@ int main(int argc, char** argv) {
358 380
359]] 381]]
360 382
383local function filter_in(f, xs)
384 for i = #xs, 1, -1 do
385 if not f(xs[i]) then
386 table.remove(xs, i)
387 end
388 end
389 return xs
390end
391
392local function nonnull(x) return x ~= nil end
393
361local function generate(main_program, dir, skip) 394local function generate(main_program, dir, skip)
362 local program_name = main_program:gsub(".*/", "") 395 local program_name = main_program:gsub(".*/", "")
363 396
364 local hardcoded = write_hardcoded_module(dir) 397 local hardcoded = write_hardcoded_module(dir)
365 398
366 local out = {} 399 local out = {}
367 table.insert(out, c_preamble)
368 table.insert(out, ([[static const char* progname = %q;]]):format(program_name)) 400 table.insert(out, ([[static const char* progname = %q;]]):format(program_name))
401 table.insert(out, c_preamble)
369 load_main(out, main_program, program_name) 402 load_main(out, main_program, program_name)
370 local lua_modules = LUA_MODULES .. "/share/lua/" .. cfg.lua_version 403 local lua_modules = LUA_MODULES .. "/share/lua/" .. cfg.lua_version
371 declare_modules(out, { dir, lua_modules }, skip) 404 declare_modules(out, { dir, lua_modules }, skip)
@@ -378,17 +411,23 @@ local function generate(main_program, dir, skip)
378 local fd = io.open(c_filename, "w") 411 local fd = io.open(c_filename, "w")
379 fd:write(reindent_c(table.concat(out, "\n"))) 412 fd:write(reindent_c(table.concat(out, "\n")))
380 fd:close() 413 fd:close()
414
415 deps.check_lua(cfg.variables)
381 416
382 cmd = table.concat({ 417 cmd = table.concat(filter_in(nonnull, {
383 "gcc", "-o", TARGET .. "/" .. program_name .. ".exe", 418 CC, "-o", TARGET .. "/" .. program_name .. ".exe",
384 "-I", cfg.variables.LUA_INCDIR, 419 "-I", cfg.variables.LUA_INCDIR,
385 "-rdynamic", 420 if_platform("unix", "-rdynamic"),
386 "-Os", 421 "-Os",
387 c_filename, 422 c_filename,
388 "-L", cfg.variables.LUA_LIBDIR, 423 "-L", cfg.variables.LUA_LIBDIR,
389 table.concat(a_files, " "), 424 table.concat(a_files, " "),
425 --if_platform("unix", cfg.variables.LUA_LIBDIR .. "/" .. cfg.variables.LUALIB:gsub("%.so.*$", ".a")),
426 --if_platform("windows", "mingw/liblua.a"), -- FIXME
390 cfg.variables.LUA_LIBDIR .. "/" .. cfg.variables.LUALIB:gsub("%.so.*$", ".a"), 427 cfg.variables.LUA_LIBDIR .. "/" .. cfg.variables.LUALIB:gsub("%.so.*$", ".a"),
391 "-ldl", "-lm"}, " ") 428 if_platform("unix", "-ldl"),
429 "-lm"
430 }), " ")
392 print(cmd) 431 print(cmd)
393 os.execute(cmd) 432 os.execute(cmd)
394end 433end
@@ -397,46 +436,56 @@ end
397 436
398local function main() 437local function main()
399 438
400 cfg.init(cmd.find_lua(LUA_DIR)) 439 os.remove("src/luarocks/core/hardcoded.lua")
440 cfg.init()
441 cfg.variables.LUA_DIR = LUA_DIR
442 cfg.variables.LUA_INCDIR = nil -- let it autodetect later
443 cfg.variables.LUA_LIBDIR = nil -- let it autodetect later
401 fs.init() 444 fs.init()
402 deps.check_lua(cfg.variables)
403 path.use_tree("./" .. LUA_MODULES) 445 path.use_tree("./" .. LUA_MODULES)
404 446
405 local CONFIG_FILE = CONFIG_DIR .. "/config-" .. cfg.lua_version .. ".lua" 447 local CONFIG_FILE = CONFIG_DIR .. "/config-" .. cfg.lua_version .. ".lua"
406 448
407 fs.make_dir(CONFIG_DIR) 449 fs.make_dir(CONFIG_DIR)
408 local fd = io.open(CONFIG_FILE, "w") 450
409 fd:write([[ 451 persist.save_from_table(CONFIG_FILE, {
410 lib_extension = "a" 452 lib_extension = "a",
411 external_lib_extension = "a" 453 external_lib_extension = "a",
412 variables = { 454 variables = {
413 CC = "]] .. fs.current_dir() .. [[/static-gcc", 455 CC = fs.current_dir() .. "/binary/static-gcc",
414 LD = "]] .. fs.current_dir() .. [[/static-gcc", 456 LD = fs.current_dir() .. "/binary/static-gcc",
415 LIB_EXTENSION = "a", 457 LIB_EXTENSION = "a",
416 LIBFLAG = "-static", 458 LIBFLAG = "-static",
417 } 459 },
418 ]]) 460 platforms = if_platform("windows", { "windows", "win32", "mingw32" }),
419 fd:close() 461 external_deps_dirs = if_platform("windows", { CROSSCOMPILER_SYSROOT, fs.current_dir().."/windows-deps" }),
462 })
420 463
421 local dependencies = { 464 local dependencies = {
422 md5 = "md5", 465 md5 = "md5",
423 luazip = "luazip", 466 luazip = if_platform("unix", "luazip"),
424 luasec = "./luasec-0.7alpha-2.rockspec", 467 luasec = "./binary/luasec-0.7alpha-2.rockspec",
425 luaposix = "./luaposix-34.0.4-1.rockspec", 468 luaposix = if_platform("unix", "./binary/luaposix-34.0.4-1.rockspec"),
426 luasocket = "luasocket", 469 luasocket = "luasocket",
427 ["lua-zlib"] = "lua-zlib", 470 ["lua-zlib"] = "./binary/lua-zlib-1.2-0.rockspec",
428 luafilesystem = "luafilesystem", 471 luafilesystem = "luafilesystem",
429 } 472 }
430 473
431 fs.make_dir(LUA_MODULES) 474 fs.make_dir(LUA_MODULES)
432 for name, arg in pairs(dependencies) do 475 for name, arg in pairs(dependencies) do
476 print("----------------------------------------------------------------")
477 print(name)
478 print("----------------------------------------------------------------")
433 local vers = manif.get_versions(queries.from_dep_string(name), "one") 479 local vers = manif.get_versions(queries.from_dep_string(name), "one")
434 if not next(vers) then 480 if not next(vers) then
435 os.execute("LUAROCKS_CONFIG='" .. CONFIG_FILE .. "' ./luarocks install '--tree=" .. LUA_MODULES .. "' " .. arg) 481 local ok = os.execute("LUAROCKS_CONFIG='" .. CONFIG_FILE .. "' ./luarocks install '--tree=" .. LUA_MODULES .. "' " .. arg)
482 if ok ~= 0 and ok ~= true then
483 error("Failed building dependency: " .. name)
484 end
436 end 485 end
437 end 486 end
438 487
439 generate(MAIN_PROGRAM, "src", { EXCLUDE, "^bin/?" }) 488 generate(MAIN_PROGRAM, "src", { EXCLUDE, "core/site_config", "^bin/?" })
440end 489end
441 490
442main() 491main()