diff options
author | Xpol Wan <xpolife@gmail.com> | 2015-11-01 13:35:33 +0800 |
---|---|---|
committer | Xpol Wan <xpolife@gmail.com> | 2015-11-01 13:35:33 +0800 |
commit | 4c3b41e765cf42afecfba8e32965e5c057c96870 (patch) | |
tree | fc3c2c4b3dbfbbad6531ae50e2ee3ea1703568fb | |
parent | 00184f35d70af9b2cf746e8a2de156d06c88101b (diff) | |
download | luarocks-4c3b41e765cf42afecfba8e32965e5c057c96870.tar.gz luarocks-4c3b41e765cf42afecfba8e32965e5c057c96870.tar.bz2 luarocks-4c3b41e765cf42afecfba8e32965e5c057c96870.zip |
Add support for Windows SDK v7.1 and v6.1.
Other Windows SDK versions requires a separate installation of Visual Studio.
-rw-r--r-- | install.bat | 84 |
1 files changed, 60 insertions, 24 deletions
diff --git a/install.bat b/install.bat index cfc5f074..0514af1b 100644 --- a/install.bat +++ b/install.bat | |||
@@ -411,48 +411,84 @@ end | |||
411 | 411 | ||
412 | -- get a string value from windows registry. | 412 | -- get a string value from windows registry. |
413 | local function get_registry(key, value) | 413 | local function get_registry(key, value) |
414 | local h = io.popen('reg query "'..key..'" /v '..value..' 2>NUL') | 414 | local keys = {key} |
415 | local output = h:read('*a') | 415 | local key64, replaces = key:gsub("(%u+\\SOFTWARE\\)", "\1Wow6432Node\\", 1) |
416 | h:close() | 416 | if replaces == 0 then |
417 | key64, replaces = key:gsub("(%u+\\Software\\)", "\1Wow6432Node\\", 1) | ||
418 | end | ||
417 | 419 | ||
418 | return output:match('REG_SZ%s+([^\n]+)') | 420 | if replaces == 1 then |
419 | end | 421 | table.insert(keys, 1, key64) |
422 | end | ||
423 | |||
424 | for _, k in ipairs(keys) do | ||
425 | local h = io.popen('reg query "'..k..'" /v '..value..' 2>NUL') | ||
426 | local output = h:read('*a') | ||
427 | h:close() | ||
420 | 428 | ||
421 | local function visual_studio_registry_key(major, minor) | 429 | local v = output:match('REG_SZ%s+([^\n]+)') |
422 | local key = "HKLM\\SOFTWARE%s\\Microsoft\\VisualStudio\\%d.%d\\Setup\\VC" | 430 | if v then |
423 | -- os.getenv('PROCESSOR_ARCHITECTURE') will always return 'x86' if lua interpreter is 32 bit. | 431 | return v |
424 | local hostx64 = os.getenv("ProgramFiles(x86)")~=nil | 432 | end |
425 | return key:format(hostx64 and "\\Wow6432Node" or "", major, minor) | 433 | end |
434 | return nil | ||
426 | end | 435 | end |
427 | 436 | ||
428 | -- requires vars.LUA_RUNTIME to be set before calling this function. | 437 | -- requires vars.LUA_RUNTIME to be set before calling this function. |
429 | local function get_visual_studio_directory() | 438 | local function get_visual_studio_directory() |
430 | local major, minor = vars.LUA_RUNTIME:match('VCR%u*(%d+)(%d)$') -- MSVCR<x><y> or VCRUNTIME<x><y> | 439 | 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 | 440 | if not major then return "" end |
432 | 441 | local key = ("HKLM\\SOFTWARE\\Microsoft\\VisualStudio\\%d.%d\\Setup\\VC"):format(major, minor) | |
433 | return get_registry(visual_studio_registry_key(major, minor), 'ProductDir') | 442 | return get_registry(key, 'ProductDir') |
434 | end | 443 | end |
435 | 444 | ||
445 | -- requires vars.LUA_RUNTIME to be set before calling this function. | ||
446 | local function get_windows_sdk_directory() | ||
447 | -- Only v7.1 and v6.1 shipped with compilers | ||
448 | -- Other versions requires a separate installation of Visual Studio. | ||
449 | -- see https://github.com/keplerproject/luarocks/pull/443#issuecomment-152792516 | ||
450 | local wsdks = { | ||
451 | ["MSVCR100"] = "v7.1", -- shipped with Visual Studio 2010 compilers. | ||
452 | ["MSVCR90"] = "v6.1", -- shipped with Visual Studio 2008 compilers. | ||
453 | } | ||
454 | local wsdkver = wsdks[vars.LUA_RUNTIME] | ||
455 | if not wsdkver then | ||
456 | return nil | ||
457 | end | ||
458 | |||
459 | local key = "HKLM\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\"..wsdkver | ||
460 | return get_registry(key, 'InstallationFolder') | ||
461 | end | ||
436 | -- returns the batch command to setup msvc compiler path. | 462 | -- returns the batch command to setup msvc compiler path. |
437 | -- requires vars.LUA_RUNTIME and vars.UNAME_M to be set before calling this function. | 463 | -- requires vars.LUA_RUNTIME and vars.UNAME_M to be set before calling this function. |
438 | local function get_msvc_env_setup_cmd() | 464 | local function get_msvc_env_setup_cmd() |
439 | local product_dir = get_visual_studio_directory() | ||
440 | local x64 = vars.UNAME_M=="x86_64" | 465 | local x64 = vars.UNAME_M=="x86_64" |
441 | 466 | ||
442 | -- 1. try vcvarsall.bat | 467 | -- 1. try visual studio command line tools |
443 | local vcvarsall = product_dir .. 'vcvarsall.bat' | 468 | local vcdir = get_visual_studio_directory() |
444 | if exists(vcvarsall) then | 469 | if vcdir then |
445 | return ('call "%s"%s'):format(vcvarsall, x64 and ' amd64' or '') | 470 | -- 1.1. try vcvarsall.bat |
446 | end | 471 | local vcvarsall = vcdir .. 'vcvarsall.bat' |
472 | if exists(vcvarsall) then | ||
473 | return ('call "%s"%s'):format(vcvarsall, x64 and ' amd64' or '') | ||
474 | end | ||
447 | 475 | ||
448 | -- 2. try vcvars32.bat / vcvars64.bat | 476 | -- 1.2. try vcvars32.bat / vcvars64.bat |
449 | local relative_path = x64 and "bin\\amd64\\vcvars64.bat" or "bin\\vcvars32.bat" | 477 | local relative_path = x64 and "bin\\amd64\\vcvars64.bat" or "bin\\vcvars32.bat" |
450 | local full_path = product_dir .. relative_path | 478 | local full_path = vcdir .. relative_path |
451 | if exists(full_path) then | 479 | if exists(full_path) then |
452 | return ('call "%s"'):format(full_path) | 480 | return ('call "%s"'):format(full_path) |
481 | end | ||
453 | end | 482 | end |
454 | 483 | ||
455 | -- 3. TODO: add support for Windows SDKs here. | 484 | -- 2. try for Windows SDKs command line tools. |
485 | local wsdkdir = get_windows_sdk_directory() | ||
486 | if wsdkdir then | ||
487 | local setenv = wsdkdir.."Bin\\SetEnv.cmd" | ||
488 | if exists(setenv) then | ||
489 | return ("call \"%s\" /Release /%s"):format(setenv, x64 and "x64" or "x86") | ||
490 | end | ||
491 | end | ||
456 | 492 | ||
457 | -- finaly, we can't detect more, just don't setup the msvc compiler in luarocks.bat. | 493 | -- finaly, we can't detect more, just don't setup the msvc compiler in luarocks.bat. |
458 | return "" | 494 | return "" |