aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXpol Wan <xpolife@gmail.com>2015-10-27 00:19:19 +0800
committerXpol Wan <xpolife@gmail.com>2015-10-27 00:19:19 +0800
commitd4b2ec1aa1291ec2b06ba161bc960fb848b98132 (patch)
tree423735805013c2f15c1ae3100d9ee9757c0e0f59
parente5aa0e030f061d7bb9f7bd7f57d379619a9f4a4a (diff)
downloadluarocks-d4b2ec1aa1291ec2b06ba161bc960fb848b98132.tar.gz
luarocks-d4b2ec1aa1291ec2b06ba161bc960fb848b98132.tar.bz2
luarocks-d4b2ec1aa1291ec2b06ba161bc960fb848b98132.zip
Better msvc compiler setup compatibility.
1. Use vcvarsall.bat if exists. 2. Use vcvars32.bat / vcvars64.bat if exists. 3. Do no compiler env setup in luarocks.bat if 1 and 2 are both not exists.
-rw-r--r--install.bat54
1 files changed, 32 insertions, 22 deletions
diff --git a/install.bat b/install.bat
index 533a0700..d2ab2976 100644
--- a/install.bat
+++ b/install.bat
@@ -411,38 +411,48 @@ end
411 411
412-- get a string value from windows registry. 412-- get a string value from windows registry.
413local function get_registry(key, value) 413local function get_registry(key, value)
414 local h = io.popen('reg query "'..key..'" /v '..value..' 2>NUL') 414 local h = io.popen('reg query "'..key..'" /v '..value..' 2>NUL')
415 local output = h:read('*a') 415 local output = h:read('*a')
416 h:close() 416 h:close()
417 417
418 return output:match('REG_SZ%s+([^\n]+)') 418 return output:match('REG_SZ%s+([^\n]+)')
419end 419end
420 420
421local function visual_studio_registry_key(major, minor) 421local function visual_studio_registry_key(major, minor)
422 local key = "HKEY_LOCAL_MACHINE\\SOFTWARE%s\\Microsoft\\VisualStudio\\%d.%d\\Setup\\VC" 422 local key = "HKLM\\SOFTWARE%s\\Microsoft\\VisualStudio\\%d.%d\\Setup\\VC"
423 -- os.getenv('PROCESSOR_ARCHITECTURE') will always return 'x86' if lua interpreter is 32 bit. 423 -- os.getenv('PROCESSOR_ARCHITECTURE') will always return 'x86' if lua interpreter is 32 bit.
424 local hostarch64 = os.getenv("ProgramFiles(x86)")~=nil 424 local hostx64 = os.getenv("ProgramFiles(x86)")~=nil
425 return key:format(hostarch64 and "\\Wow6432Node" or "", major, minor) 425 return key:format(hostx64 and "\\Wow6432Node" or "", major, minor)
426end
427
428-- requires vars.LUA_RUNTIME to be set before calling this function.
429local function get_visual_studio_directory()
430 local major, minor = vars.LUA_RUNTIME:match('VCR%u*(%d+)(%d)$') -- MSVCR<x><y> or VCRUNTIME<x><y>
431 if not major then return "" end
432
433 return get_registry(visual_studio_registry_key(major, minor), 'ProductDir')
426end 434end
427 435
428-- returns the batch command to setup msvc compiler path. 436-- 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. 437-- requires vars.LUA_RUNTIME and vars.UNAME_M to be set before calling this function.
430local function get_vc_env_setup_cmd() 438local function get_msvc_env_setup_cmd()
431 -- 1. check installed lua runtime version 439 local product_dir = get_visual_studio_directory()
432 local major, minor = vars.LUA_RUNTIME:match('^MSVCR(%d+)(%d)$') 440 local x64 = vars.UNAME_M=="x86_64"
433 if not major then return "" end
434 441
435 -- 2. check if required VC version is in registry 442 -- 1. try vcvarsall.bat
436 local product_dir = get_registry(visual_studio_registry_key(major, minor), 'ProductDir') 443 local vcvarsall = product_dir .. 'vcvarsall.bat'
437 444 if exists(vcvarsall) then
438 if not product_dir then return "" end 445 return ('call "%s"%s'):format(vcvarsall, x64 and ' amd64' or '')
446 end
439 447
440 -- 4. check VC batch file exists 448 -- 2. try vcvars32.bat / vcvars64.bat
441 local relative_path = vars.UNAME_M=="x86_64" and "bin\\amd64\\vcvars64.bat" or "bin\\vcvars32.bat" 449 local relative_path = x64 and "bin\\amd64\\vcvars64.bat" or "bin\\vcvars32.bat"
442 local full_path = product_dir .. relative_path 450 local full_path = product_dir .. relative_path
443 if not exists(full_path) then return "" end 451 if exists(full_path) then
452 return ('call "%s"'):format(full_path)
453 end
444 454
445 return ('call "%s"'):format(full_path) 455 return ""
446end 456end
447 457
448local function look_for_lua_install () 458local function look_for_lua_install ()
@@ -663,7 +673,7 @@ if SELFCONTAINED then
663 vars.TREE_ROOT = vars.PREFIX..[[\systree]] 673 vars.TREE_ROOT = vars.PREFIX..[[\systree]]
664 REGISTRY = false 674 REGISTRY = false
665end 675end
666vars.COMPILER_ENV_CMD = get_vc_env_setup_cmd(vars.LUA_RUNTIME, vars.UNAME_M) 676vars.COMPILER_ENV_CMD = get_msvc_env_setup_cmd()
667 677
668print(S[[ 678print(S[[
669 679