aboutsummaryrefslogtreecommitdiff
path: root/install.bat
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2013-10-13 18:55:12 -0700
committerHisham Muhammad <hisham@gobolinux.org>2013-10-13 18:55:12 -0700
commita3c1394f7f1e0702e0d5cce89467eb0cb26388c9 (patch)
tree1884097b927a9ed9f4c829c6a23400d7e6c3f16f /install.bat
parentf9a24099c30c879a7d686fa5ea3f86ed2ab489b4 (diff)
parent23214ad83c36ca2d6f74e1532bcd7f1acd87db82 (diff)
downloadluarocks-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.bat106
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
35local pe = assert(loadfile(".\\bin\\pe-parser.lua"))()
36
34local function die(message) 37local 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
276end 279end
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.
281local 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
318end
319 281
320local function get_runtime() 282local 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
341end 293end
342 294
295local 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
308end
309
343local function look_for_lua_install () 310local 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
389end 356end
390 357
391local 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
409end
410
411--- 358---
412-- Poor man's command-line parsing 359-- Poor man's command-line parsing
413local config = {} 360local config = {}
@@ -449,7 +396,6 @@ vars.LIBDIR = vars.FULL_PREFIX
449vars.LUADIR = S"$FULL_PREFIX\\lua" 396vars.LUADIR = S"$FULL_PREFIX\\lua"
450vars.INCDIR = S"$FULL_PREFIX\\include" 397vars.INCDIR = S"$FULL_PREFIX\\include"
451vars.LUA_SHORTV = vars.LUA_VERSION:gsub("%.", "") 398vars.LUA_SHORTV = vars.LUA_VERSION:gsub("%.", "")
452vars.UNAME_M = get_architecture()
453 399
454if not look_for_lua_install() then 400if 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"
467else 414else
415 vars.UNAME_M = get_architecture()
468 print(S[[ 416 print(S[[
469 417
470Will configure LuaRocks with the following paths: 418Will 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" )
670end 618end
619
620-- ***********************************************************
621-- Cleanup
622-- ***********************************************************
671-- remove regsitry related files, no longer needed 623-- remove regsitry related files, no longer needed
672exec( S[[del "$FULL_PREFIX\LuaRocks.reg.*" > nul]] ) 624exec( S[[del "$FULL_PREFIX\LuaRocks.reg.*" > nul]] )
625-- remove pe-parser module
626exec( S[[del "$FULL_PREFIX\pe-parser.lua" > nul]] )
673 627
674-- *********************************************************** 628-- ***********************************************************
675-- Exit handlers 629-- Exit handlers