diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2013-10-13 18:55:12 -0700 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2013-10-13 18:55:12 -0700 |
commit | a3c1394f7f1e0702e0d5cce89467eb0cb26388c9 (patch) | |
tree | 1884097b927a9ed9f4c829c6a23400d7e6c3f16f /install.bat | |
parent | f9a24099c30c879a7d686fa5ea3f86ed2ab489b4 (diff) | |
parent | 23214ad83c36ca2d6f74e1532bcd7f1acd87db82 (diff) | |
download | luarocks-a3c1394f7f1e0702e0d5cce89467eb0cb26388c9.tar.gz luarocks-a3c1394f7f1e0702e0d5cce89467eb0cb26388c9.tar.bz2 luarocks-a3c1394f7f1e0702e0d5cce89467eb0cb26388c9.zip |
Merge pull request #165 from Tieske/pe-parser
enhanced parsing of binaries on Windows when installing LR
Diffstat (limited to 'install.bat')
-rw-r--r-- | install.bat | 106 |
1 files changed, 30 insertions, 76 deletions
diff --git a/install.bat b/install.bat index 0f34276d..f6601aa8 100644 --- a/install.bat +++ b/install.bat | |||
@@ -31,6 +31,9 @@ local REGISTRY = false | |||
31 | --- | 31 | --- |
32 | -- Some helpers | 32 | -- Some helpers |
33 | -- | 33 | -- |
34 | |||
35 | local pe = assert(loadfile(".\\bin\\pe-parser.lua"))() | ||
36 | |||
34 | local function die(message) | 37 | local function die(message) |
35 | if message then print(message) end | 38 | if message then print(message) end |
36 | print() | 39 | print() |
@@ -275,71 +278,35 @@ local function look_for_headers (directory) | |||
275 | return false | 278 | return false |
276 | end | 279 | end |
277 | 280 | ||
278 | -- Checks a binary file for the runtime dll used by it. If nu runtime is found, it returns an | ||
279 | -- array of dll's is depends upon. | ||
280 | -- result: string = runtime used, table = list of dll's depended upon, nil = nothing found. | ||
281 | local function get_file_runtime(p,f) -- path, filename | ||
282 | local infile = p.."\\"..f | ||
283 | local outfile = "output.txt" | ||
284 | local content | ||
285 | -- analyze binary | ||
286 | if exec([[.\bin\bin\objdump -x "]]..infile..[[" > ]]..outfile..[[ 2<&1]]) then | ||
287 | -- read temp file | ||
288 | local fh = io.open(outfile) | ||
289 | content = fh:read("*a") | ||
290 | fh:close() | ||
291 | end | ||
292 | -- delete temp file | ||
293 | os.remove(outfile) | ||
294 | if not content then | ||
295 | print(" Failed to analyze "..infile.." for the runtime used") | ||
296 | return nil | ||
297 | end | ||
298 | |||
299 | -- lookup | ||
300 | content = content:upper() | ||
301 | local result = content:match('DLL NAME%: (MSVCR%d*)%.DLL') | ||
302 | if not result then | ||
303 | result = content:match('DLL NAME%: (MSVCRT)%.DLL') | ||
304 | end | ||
305 | |||
306 | if result then | ||
307 | print(" "..f.." uses "..tostring(result)..".DLL as runtime") | ||
308 | else | ||
309 | print(" No runtime found for "..f) | ||
310 | -- so; create a list of dll's this file is depending upon, next level of the tree | ||
311 | result = {} | ||
312 | for name in content:gmatch("DLL NAME%: (.-%.DLL)") do | ||
313 | --print("found dll:", name) | ||
314 | table.insert(result, name) | ||
315 | end | ||
316 | end | ||
317 | return result | ||
318 | end | ||
319 | 281 | ||
320 | local function get_runtime() | 282 | local function get_runtime() |
321 | -- first check interpreter | 283 | local f |
322 | vars.LUA_RUNTIME = get_file_runtime(vars.LUA_BINDIR, vars.LUA_INTERPRETER) | 284 | vars.LUA_RUNTIME, f = pe.msvcrt(vars.LUA_BINDIR.."\\"..vars.LUA_INTERPRETER) |
323 | if type(vars.LUA_RUNTIME) == "table" then | ||
324 | -- a table with dll's depended upon was returned, check this list | ||
325 | -- note: we only check 1 level deep | ||
326 | for _,dll in ipairs(vars.LUA_RUNTIME) do | ||
327 | local t = get_file_runtime(vars.LUA_BINDIR, dll) | ||
328 | if type(t) == "string" then | ||
329 | -- found it | ||
330 | vars.LUA_RUNTIME = t | ||
331 | break | ||
332 | end | ||
333 | end | ||
334 | end | ||
335 | if type(vars.LUA_RUNTIME) ~= "string" then | 285 | if type(vars.LUA_RUNTIME) ~= "string" then |
336 | -- analysis failed, issue a warning | 286 | -- analysis failed, issue a warning |
337 | vars.LUA_RUNTIME = "MSVCR80" | 287 | vars.LUA_RUNTIME = "MSVCR80" |
338 | print("*** WARNING ***: could not analyse the runtime used, defaulting to "..vars.LUA_RUNTIME) | 288 | print("*** WARNING ***: could not analyse the runtime used, defaulting to "..vars.LUA_RUNTIME) |
289 | else | ||
290 | print(" "..f.." uses "..vars.LUA_RUNTIME..".DLL as runtime") | ||
339 | end | 291 | end |
340 | return true | 292 | return true |
341 | end | 293 | end |
342 | 294 | ||
295 | local function get_architecture() | ||
296 | -- detect processor arch interpreter was compiled for | ||
297 | local proc = (pe.parse(vars.LUA_BINDIR.."\\"..vars.LUA_INTERPRETER) or {}).Machine | ||
298 | if not proc then | ||
299 | die("Could not detect processor architecture used in "..vars.LUA_INTERPRETER) | ||
300 | end | ||
301 | proc = pe.const.Machine[proc] -- collect name from constant value | ||
302 | if proc == "IMAGE_FILE_MACHINE_I386" then | ||
303 | proc = "x86" | ||
304 | else | ||
305 | proc = "x86_64" | ||
306 | end | ||
307 | return proc | ||
308 | end | ||
309 | |||
343 | local function look_for_lua_install () | 310 | local function look_for_lua_install () |
344 | print("Looking for Lua interpreter") | 311 | print("Looking for Lua interpreter") |
345 | local directories = { [[c:\lua5.1.2]], [[c:\lua]], [[c:\kepler\1.1]] } | 312 | local directories = { [[c:\lua5.1.2]], [[c:\lua]], [[c:\kepler\1.1]] } |
@@ -388,26 +355,6 @@ local function look_for_lua_install () | |||
388 | return false | 355 | return false |
389 | end | 356 | end |
390 | 357 | ||
391 | local function get_architecture() | ||
392 | -- detect processor arch | ||
393 | local tmpname = [[.\_architect_temp.txt]] | ||
394 | local cmd = [[REG.exe Query HKLM\Hardware\Description\System\CentralProcessor\0 >"]]..tmpname.. [["]] | ||
395 | if not exec(cmd) then | ||
396 | die("Could not detect processor architecture") | ||
397 | end | ||
398 | local f = io.open(tmpname, "r") | ||
399 | local proc = f:read('*a') | ||
400 | f:close() | ||
401 | os.remove(tmpname) | ||
402 | |||
403 | if proc:match("x86") then | ||
404 | proc = "x86" | ||
405 | else | ||
406 | proc = "x86_64" | ||
407 | end | ||
408 | return proc | ||
409 | end | ||
410 | |||
411 | --- | 358 | --- |
412 | -- Poor man's command-line parsing | 359 | -- Poor man's command-line parsing |
413 | local config = {} | 360 | local config = {} |
@@ -449,7 +396,6 @@ vars.LIBDIR = vars.FULL_PREFIX | |||
449 | vars.LUADIR = S"$FULL_PREFIX\\lua" | 396 | vars.LUADIR = S"$FULL_PREFIX\\lua" |
450 | vars.INCDIR = S"$FULL_PREFIX\\include" | 397 | vars.INCDIR = S"$FULL_PREFIX\\include" |
451 | vars.LUA_SHORTV = vars.LUA_VERSION:gsub("%.", "") | 398 | vars.LUA_SHORTV = vars.LUA_VERSION:gsub("%.", "") |
452 | vars.UNAME_M = get_architecture() | ||
453 | 399 | ||
454 | if not look_for_lua_install() then | 400 | if not look_for_lua_install() then |
455 | print("Could not find Lua. Will install its own copy.") | 401 | print("Could not find Lua. Will install its own copy.") |
@@ -464,7 +410,9 @@ if not look_for_lua_install() then | |||
464 | vars.LUA_INCDIR = vars.INCDIR | 410 | vars.LUA_INCDIR = vars.INCDIR |
465 | vars.LUA_LIBNAME = "lua5.1.lib" | 411 | vars.LUA_LIBNAME = "lua5.1.lib" |
466 | vars.LUA_RUNTIME = "MSVCR80" | 412 | vars.LUA_RUNTIME = "MSVCR80" |
413 | vars.UNAME_M = "x86" | ||
467 | else | 414 | else |
415 | vars.UNAME_M = get_architecture() | ||
468 | print(S[[ | 416 | print(S[[ |
469 | 417 | ||
470 | Will configure LuaRocks with the following paths: | 418 | Will configure LuaRocks with the following paths: |
@@ -668,8 +616,14 @@ if REGISTRY then | |||
668 | exec( S[[lua5.1\bin\lua5.1.exe "$FULL_PREFIX\LuaRocks.reg.lua" "$FULL_PREFIX\LuaRocks.reg.template"]] ) | 616 | exec( S[[lua5.1\bin\lua5.1.exe "$FULL_PREFIX\LuaRocks.reg.lua" "$FULL_PREFIX\LuaRocks.reg.template"]] ) |
669 | exec( S"$FULL_PREFIX\\LuaRocks.reg" ) | 617 | exec( S"$FULL_PREFIX\\LuaRocks.reg" ) |
670 | end | 618 | end |
619 | |||
620 | -- *********************************************************** | ||
621 | -- Cleanup | ||
622 | -- *********************************************************** | ||
671 | -- remove regsitry related files, no longer needed | 623 | -- remove regsitry related files, no longer needed |
672 | exec( S[[del "$FULL_PREFIX\LuaRocks.reg.*" > nul]] ) | 624 | exec( S[[del "$FULL_PREFIX\LuaRocks.reg.*" > nul]] ) |
625 | -- remove pe-parser module | ||
626 | exec( S[[del "$FULL_PREFIX\pe-parser.lua" > nul]] ) | ||
673 | 627 | ||
674 | -- *********************************************************** | 628 | -- *********************************************************** |
675 | -- Exit handlers | 629 | -- Exit handlers |