aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXpol Wan <xpolife@gmail.com>2015-10-24 14:41:50 +0800
committerXpol Wan <xpolife@gmail.com>2015-10-24 14:41:50 +0800
commite5aa0e030f061d7bb9f7bd7f57d379619a9f4a4a (patch)
treedff2763374ea1e749edb9e3fd5969ed4c3a8f664
parent7235ad9f40fbbf27b9fd1097817587e892690556 (diff)
downloadluarocks-e5aa0e030f061d7bb9f7bd7f57d379619a9f4a4a.tar.gz
luarocks-e5aa0e030f061d7bb9f7bd7f57d379619a9f4a4a.tar.bz2
luarocks-e5aa0e030f061d7bb9f7bd7f57d379619a9f4a4a.zip
Better setup vc compiler, should compatible with Windows SDK.
1. Use reg: HKEY_LOCAL_MACHINE\SOFTWARE[\Wow6432Node]\Microsoft\VisualStudio\<version>\Setup\VC:ProductDir 2. Use bin\vcvars32.bat and bin\amd64\vcvars64.bat instead of vcvarsall.bat.
-rw-r--r--install.bat43
1 files changed, 30 insertions, 13 deletions
diff --git a/install.bat b/install.bat
index 90e9b8d4..533a0700 100644
--- a/install.bat
+++ b/install.bat
@@ -409,23 +409,40 @@ local function get_architecture()
409 return proc 409 return proc
410end 410end
411 411
412-- uses vars.LUA_RUNTIME and vars.UNAME_M 412-- get a string value from windows registry.
413local function get_compiler_env_cmd() 413local function get_registry(key, value)
414 local h = io.popen('reg query "'..key..'" /v '..value..' 2>NUL')
415 local output = h:read('*a')
416 h:close()
417
418 return output:match('REG_SZ%s+([^\n]+)')
419end
420
421local function visual_studio_registry_key(major, minor)
422 local key = "HKEY_LOCAL_MACHINE\\SOFTWARE%s\\Microsoft\\VisualStudio\\%d.%d\\Setup\\VC"
423 -- os.getenv('PROCESSOR_ARCHITECTURE') will always return 'x86' if lua interpreter is 32 bit.
424 local hostarch64 = os.getenv("ProgramFiles(x86)")~=nil
425 return key:format(hostarch64 and "\\Wow6432Node" or "", major, minor)
426end
427
428-- returns the batch command to setup msvc compiler path.
429-- requires vars.LUA_RUNTIME and vars.UNAME_M to be set before calling this function.
430local function get_vc_env_setup_cmd()
431 -- 1. check installed lua runtime version
414 local major, minor = vars.LUA_RUNTIME:match('^MSVCR(%d+)(%d)$') 432 local major, minor = vars.LUA_RUNTIME:match('^MSVCR(%d+)(%d)$')
415 if not major then return "" end 433 if not major then return "" end
416 local key = "HKEY_LOCAL_MACHINE\\SOFTWARE%s\\Microsoft\\VisualStudio\\%d.%d"
417 local hostarch64 = os.getenv("ProgramFiles(x86)")~=nil -- 'PROCESSOR_ARCHITECTURE' will always return 'x86' if interpreter is 32 bit.
418 key = key:format(hostarch64 and "\\Wow6432Node" or "", major, minor)
419 434
420 local h = io.popen('reg query "'..key..'" /v InstallDir 2>NUL') 435 -- 2. check if required VC version is in registry
421 local output = h:read('*a') 436 local product_dir = get_registry(visual_studio_registry_key(major, minor), 'ProductDir')
422 h:close() 437
438 if not product_dir then return "" end
423 439
424 local msvcdir = output:match("REG_SZ%s+(.+)\\Common7\\IDE") 440 -- 4. check VC batch file exists
425 if not msvcdir then return "" end 441 local relative_path = vars.UNAME_M=="x86_64" and "bin\\amd64\\vcvars64.bat" or "bin\\vcvars32.bat"
426 local msvcarch = vars.UNAME_M=="x86_64" and " x86_amd64" or "" 442 local full_path = product_dir .. relative_path
443 if not exists(full_path) then return "" end
427 444
428 return ('call "%s\\VC\\vcvarsall.bat"%s'):format(msvcdir, msvcarch) 445 return ('call "%s"'):format(full_path)
429end 446end
430 447
431local function look_for_lua_install () 448local function look_for_lua_install ()
@@ -646,7 +663,7 @@ if SELFCONTAINED then
646 vars.TREE_ROOT = vars.PREFIX..[[\systree]] 663 vars.TREE_ROOT = vars.PREFIX..[[\systree]]
647 REGISTRY = false 664 REGISTRY = false
648end 665end
649vars.COMPILER_ENV_CMD = get_compiler_env_cmd(vars.LUA_RUNTIME, vars.UNAME_M) 666vars.COMPILER_ENV_CMD = get_vc_env_setup_cmd(vars.LUA_RUNTIME, vars.UNAME_M)
650 667
651print(S[[ 668print(S[[
652 669