diff options
Diffstat (limited to 'binary/all_in_one')
-rwxr-xr-x | binary/all_in_one | 145 |
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" | |||
30 | local EXCLUDE = arg[3] or "^src/luarocks/admin/" | 30 | local EXCLUDE = arg[3] or "^src/luarocks/admin/" |
31 | local SYSCONFDIR = arg[4] or "/etc/luarocks" | 31 | local SYSCONFDIR = arg[4] or "/etc/luarocks" |
32 | local TARGET = arg[5] or "binary-build" | 32 | local TARGET = arg[5] or "binary-build" |
33 | local MY_PLATFORM = arg[6] or "unix" | ||
34 | local CC = arg[7] or "gcc" | ||
35 | local NM = arg[8] or "nm" | ||
36 | local CROSSCOMPILER_SYSROOT = arg[9] or "/usr/lib/mingw-w64-sysroot/i686-w64-mingw32" | ||
33 | 37 | ||
34 | local LUA_MODULES = TARGET .. "/lua_modules" | 38 | local LUA_MODULES = TARGET .. "/lua_modules" |
35 | local CONFIG_DIR = TARGET .. "/.luarocks" | 39 | local CONFIG_DIR = TARGET .. "/.luarocks" |
@@ -48,6 +52,12 @@ local persist = require("luarocks.persist") | |||
48 | 52 | ||
49 | -------------------------------------------------------------------------------- | 53 | -------------------------------------------------------------------------------- |
50 | 54 | ||
55 | local function if_platform(plat, val) | ||
56 | if MY_PLATFORM == plat then | ||
57 | return val | ||
58 | end | ||
59 | end | ||
60 | |||
51 | local function reindent_c(input) | 61 | local 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 | ||
111 | static int registry_key; | 121 | static int registry_key; |
112 | 122 | ||
123 | /* fatal error, from srlua */ | ||
124 | static void fatal(const char* message) { | ||
125 | alert(message); | ||
126 | exit(EXIT_FAILURE); | ||
127 | } | ||
128 | |||
113 | ]] | 129 | ]] |
114 | 130 | ||
115 | local function bin2c_file(out, filename) | 131 | local 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 | ||
122 | local function write_hardcoded_module(dir) | 140 | local 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) | |||
187 | end | 213 | end |
188 | 214 | ||
189 | local function nm(filename) | 215 | local 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 | |||
244 | local function load_main(out, main_program, program_name) | 270 | local 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, [[]]) |
250 | end | 278 | end |
@@ -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 */ | ||
310 | static void fatal(const char* message) { | ||
311 | alert(message); | ||
312 | exit(EXIT_FAILURE); | ||
313 | } | ||
314 | |||
315 | /* error handler, from luac */ | 337 | /* error handler, from luac */ |
316 | static int msghandler (lua_State *L) { | 338 | static 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 | ||
383 | local 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 | ||
390 | end | ||
391 | |||
392 | local function nonnull(x) return x ~= nil end | ||
393 | |||
361 | local function generate(main_program, dir, skip) | 394 | local 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) |
394 | end | 433 | end |
@@ -397,46 +436,56 @@ end | |||
397 | 436 | ||
398 | local function main() | 437 | local 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/?" }) |
440 | end | 489 | end |
441 | 490 | ||
442 | main() | 491 | main() |