From e13ed563952168ee19c396759a9fbd025b8ffc77 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Tue, 30 Apr 2013 09:29:39 +0200 Subject: using objdump.exe to automatically detect the runtime dll to use for the chosen interpreter --- install.bat | 56 ++++++++++++++++++++++++++++++++++++++++++-------- win32/bin/objdump.exe | Bin 0 -> 2247694 bytes 2 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 win32/bin/objdump.exe diff --git a/install.bat b/install.bat index 2150d2c3..4e1ede31 100644 --- a/install.bat +++ b/install.bat @@ -18,6 +18,7 @@ vars.LUA_LIBNAME = nil vars.LUA_VERSION = "5.1" vars.LUA_SHORTV = nil vars.LUA_LIB_NAMES = "lua5.1.lib lua51.dll liblua.dll.a" +vars.LUA_RUNTIME = nil local P_SET = false local FORCE = false @@ -263,6 +264,39 @@ local function look_for_headers (directory) return false end +local function get_runtime() + local infile = vars.LUA_BINDIR .."\\"..vars.LUA_INTERPRETER + local outfile = "output.txt" + local content + -- analyze binary + if exec([[.\bin\objdump -x "]]..infile..[[" > ]]..outfile) then + -- read temp file + local fh = io.open(outfile) + content = fh:read("*a") + fh:close() + end + -- delete temp file + os.remove(outfile) + if not content then + print(" Failed to analyze "..infile.." for the runtime used") + return false + end + + -- lookup + content = content:upper() + local result = content:match('DLL NAME%: (MSVCR%d*)%.DLL') + if not result then + result = content:match('DLL NAME%: (MSVCRT)%.DLL') + end + + if result then + vars.LUA_RUNTIME = result + print(" "..vars.LUA_INTERPRETER.." uses "..tostring(result)..".DLL as runtime") + return true + end + return false +end + local function look_for_lua_install () print("Looking for Lua interpreter") local directories = { [[c:\lua5.1.2]], [[c:\lua]], [[c:\kepler\1.1]] } @@ -275,7 +309,7 @@ local function look_for_lua_install () look_for_headers(vars.LUA_INCDIR) then if exec(S"$LUA_BINDIR\\$LUA_INTERPRETER -v 2>NUL") then - print(" Ok") + print(" Ok") return true end end @@ -290,12 +324,15 @@ local function look_for_lua_install () if look_for_link_libraries(directory) then print("Link library found, now looking for headers...") if look_for_headers(directory) then - print("Headers found, now testing interpreter...") - if exec(S[[$LUA_BINDIR\$LUA_INTERPRETER -v 2>NUL]]) then - print(" Ok") - return true + print("Headers found, checking runtime to use...") + if get_runtime() then + print("Runtime found, now testing interpreter...") + if exec(S[[$LUA_BINDIR\$LUA_INTERPRETER -v 2>NUL]]) then + print(" Ok") + return true + end + print(" Interpreter returned an error, not ok") end - print(" Interpreter returned an error, not ok") end end end @@ -358,6 +395,7 @@ if not look_for_lua_install() then vars.LUA_LIBDIR = vars.LIBDIR vars.LUA_INCDIR = vars.INCDIR vars.LUA_LIBNAME = "lua5.1.lib" + vars.LUA_RUNTIME = "MSVCR80" else print(S[[ @@ -367,7 +405,7 @@ Lua interpreter: $LUA_BINDIR\$LUA_INTERPRETER Lua binaries : $LUA_BINDIR Lua libraries : $LUA_LIBDIR Lua includes : $LUA_INCDIR -Binaries will be linked against: $LUA_LIBNAME +Binaries will be linked against: $LUA_LIBNAME with runtime $LUA_RUNTIME ]]) end @@ -521,10 +559,10 @@ rocks_trees = { f:write(S"scripts_dir=[[$SCRIPTS_DIR]]\n") end f:write("variables = {\n") - if USE_MINGW then + if USE_MINGW and vars.LUA_RUNTIME == "MSVCRT" then f:write(" MSVCRT = 'm',\n") else - f:write(" MSVCRT = 'msvcr80',\n") + f:write(" MSVCRT = '"..vars.LUA_RUNTIME.."',\n") end f:write(S" LUALIB = '$LUA_LIBNAME'\n") f:write("}\n") diff --git a/win32/bin/objdump.exe b/win32/bin/objdump.exe new file mode 100644 index 00000000..4429d103 Binary files /dev/null and b/win32/bin/objdump.exe differ -- cgit v1.2.3-55-g6feb From 95233053d0fefc1234541f94a99e6c3ce1d807b5 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Tue, 30 Apr 2013 11:57:05 +0200 Subject: added comment --- install.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.bat b/install.bat index 4e1ede31..28236707 100644 --- a/install.bat +++ b/install.bat @@ -560,7 +560,7 @@ rocks_trees = { end f:write("variables = {\n") if USE_MINGW and vars.LUA_RUNTIME == "MSVCRT" then - f:write(" MSVCRT = 'm',\n") + f:write(" MSVCRT = 'm', -- make MinGW use MSVCRT.DLL as runtime\n") else f:write(" MSVCRT = '"..vars.LUA_RUNTIME.."',\n") end -- cgit v1.2.3-55-g6feb From 5d6292787b62bdb47516a50f2a983a631ccd08c1 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Thu, 2 May 2013 10:08:24 +0200 Subject: fix: if interpreter has no runtime, check link library for runtime used. --- install.bat | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/install.bat b/install.bat index 28236707..5bed6bbd 100644 --- a/install.bat +++ b/install.bat @@ -264,8 +264,8 @@ local function look_for_headers (directory) return false end -local function get_runtime() - local infile = vars.LUA_BINDIR .."\\"..vars.LUA_INTERPRETER +local function get_file_runtime(p,f) -- path, filename + local infile = p.."\\"..f local outfile = "output.txt" local content -- analyze binary @@ -279,7 +279,7 @@ local function get_runtime() os.remove(outfile) if not content then print(" Failed to analyze "..infile.." for the runtime used") - return false + return nil end -- lookup @@ -290,11 +290,21 @@ local function get_runtime() end if result then - vars.LUA_RUNTIME = result - print(" "..vars.LUA_INTERPRETER.." uses "..tostring(result)..".DLL as runtime") - return true + print(" "..f.." uses "..tostring(result)..".DLL as runtime") + else + print(" No runtime found for "..f) end - return false + return result +end + +local function get_runtime() + -- first check interpreter + vars.LUA_RUNTIME = get_file_runtime(vars.LUA_BINDIR, vars.LUA_INTERPRETER) + if not vars.LUA_RUNTIME then + -- not found, check link library + vars.LUA_RUNTIME = get_file_runtime(vars.LUA_LIBDIR, vars.LUA_LIBNAME) + end + return (vars.LUA_RUNTIME ~= nil) end local function look_for_lua_install () -- cgit v1.2.3-55-g6feb From 0d8edd1fe84f57cbbde28c3ae8dd94f5cd537834 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Thu, 2 May 2013 20:41:03 +0200 Subject: fix; no longer check link lib when interpreter has no runtime specified, but list all dll's interpreter depends upon and check those for the runtime (1 level deep only) --- install.bat | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/install.bat b/install.bat index 5bed6bbd..e1e7cb76 100644 --- a/install.bat +++ b/install.bat @@ -264,6 +264,9 @@ local function look_for_headers (directory) return false end +-- Checks a binary file for the runtime dll used by it. If nu runtime is found, it returns an +-- array of dll's is depends upon. +-- result: string = runtime used, table = list of dll's depended upon, nil = nothing found. local function get_file_runtime(p,f) -- path, filename local infile = p.."\\"..f local outfile = "output.txt" @@ -293,6 +296,12 @@ local function get_file_runtime(p,f) -- path, filename print(" "..f.." uses "..tostring(result)..".DLL as runtime") else print(" No runtime found for "..f) + -- so; create a list of dll's this file is depending upon, next level of the tree + result = {} + for name in content:gmatch("DLL NAME%: (.-%.DLL)") do + --print("found dll:", name) + table.insert(result, name) + end end return result end @@ -300,11 +309,19 @@ end local function get_runtime() -- first check interpreter vars.LUA_RUNTIME = get_file_runtime(vars.LUA_BINDIR, vars.LUA_INTERPRETER) - if not vars.LUA_RUNTIME then - -- not found, check link library - vars.LUA_RUNTIME = get_file_runtime(vars.LUA_LIBDIR, vars.LUA_LIBNAME) + if type(vars.LUA_RUNTIME) == "table" then + -- a table with dll's depended upon was returned, check this list + -- note: we only check 1 level deep + for _,dll in ipairs(vars.LUA_RUNTIME) do + local t = get_file_runtime(vars.LUA_BINDIR, dll) + if type(t) == "string" then + -- found it + vars.LUA_RUNTIME = t + break + end + end end - return (vars.LUA_RUNTIME ~= nil) + return (type(vars.LUA_RUNTIME) == "string") end local function look_for_lua_install () -- cgit v1.2.3-55-g6feb