aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--install.bat144
1 files changed, 140 insertions, 4 deletions
diff --git a/install.bat b/install.bat
index f64d6783..8e3df4d9 100644
--- a/install.bat
+++ b/install.bat
@@ -30,11 +30,13 @@ vars.LUA_SHORTV = nil -- "51"
30vars.LUA_LIB_NAMES = "lua5.1.lib lua51.lib lua5.1.dll lua51.dll liblua.dll.a" 30vars.LUA_LIB_NAMES = "lua5.1.lib lua51.lib lua5.1.dll lua51.dll liblua.dll.a"
31vars.LUA_RUNTIME = nil 31vars.LUA_RUNTIME = nil
32vars.UNAME_M = nil 32vars.UNAME_M = nil
33vars.COMPILER_ENV_CMD = nil
33 34
34local FORCE = false 35local FORCE = false
35local FORCE_CONFIG = false 36local FORCE_CONFIG = false
36local INSTALL_LUA = false 37local INSTALL_LUA = false
37local USE_MINGW = false 38local USE_MINGW = false
39local USE_MSVC_MANUAL = false
38local REGISTRY = true 40local REGISTRY = true
39local NOADMIN = false 41local NOADMIN = false
40local PROMPT = true 42local PROMPT = true
@@ -167,7 +169,14 @@ Configuring the Lua interpreter:
167 (/LUA, /INC, /LIB, /BIN cannot be used with /L) 169 (/LUA, /INC, /LIB, /BIN cannot be used with /L)
168 170
169Compiler configuration: 171Compiler configuration:
170/MW Use mingw as build system instead of MSVC 172 By default the installer will try to determine the
173 Microsoft toolchain to use. And will automatically use
174 a setup command to initialize that toolchain when
175 LuaRocks is run. If it cannot find it, it will default
176 to the /MSVC switch.
177/MSVC Use MS toolchain, without a setup command (tools must
178 be in your path)
179/MW Use mingw as build system (tools must be in your path)
171 180
172Other options: 181Other options:
173/FORCECONFIG Use a single config location. Do not use the 182/FORCECONFIG Use a single config location. Do not use the
@@ -215,6 +224,8 @@ local function parse_options(args)
215 INSTALL_LUA = true 224 INSTALL_LUA = true
216 elseif name == "/MW" then 225 elseif name == "/MW" then
217 USE_MINGW = true 226 USE_MINGW = true
227 elseif name == "/MSVC" then
228 USE_MSVC_MANUAL = true
218 elseif name == "/LUA" then 229 elseif name == "/LUA" then
219 vars.LUA_PREFIX = option.value 230 vars.LUA_PREFIX = option.value
220 elseif name == "/LIB" then 231 elseif name == "/LIB" then
@@ -268,6 +279,9 @@ local function check_flags()
268 die("Bad argument: /LV must either be 5.1, 5.2, or 5.3") 279 die("Bad argument: /LV must either be 5.1, 5.2, or 5.3")
269 end 280 end
270 end 281 end
282 if USE_MSVC_MANUAL and USE_MINGW then
283 die("Cannot combine option /MSVC and /MW")
284 end
271end 285end
272 286
273-- *********************************************************** 287-- ***********************************************************
@@ -410,6 +424,117 @@ local function get_architecture()
410 return proc 424 return proc
411end 425end
412 426
427-- get a string value from windows registry.
428local function get_registry(key, value)
429 local keys = {key}
430 local key64, replaced = key:gsub("(%u+\\Software\\)", "\1Wow6432Node\\", 1)
431
432 if replaced == 1 then
433 keys = {key64, key}
434 end
435
436 for _, k in ipairs(keys) do
437 local h = io.popen('reg query "'..k..'" /v '..value..' 2>NUL')
438 local output = h:read("*a")
439 h:close()
440
441 local v = output:match("REG_SZ%s+([^\n]+)")
442 if v then
443 return v
444 end
445 end
446 return nil
447end
448
449local function get_visual_studio_directory()
450 assert(type(vars.LUA_RUNTIME)=="string", "requires vars.LUA_RUNTIME to be set before calling this function.")
451 local major, minor = vars.LUA_RUNTIME:match('VCR%u*(%d+)(%d)$') -- MSVCR<x><y> or VCRUNTIME<x><y>
452 if not major then
453 print(S[[ Cannot auto-detect Visual Studio version from $LUA_RUNTIME]])
454 return nil
455 end
456 local keys = {
457 "HKLM\\Software\\Microsoft\\VisualStudio\\%d.%d\\Setup\\VC",
458 "HKLM\\Software\\Microsoft\\VCExpress\\%d.%d\\Setup\\VS"
459 }
460 for _, key in ipairs(keys) do
461 local versionedkey = key:format(major, minor)
462 local vcdir = get_registry(versionedkey, "ProductDir")
463 print(" checking: "..versionedkey)
464 if vcdir then
465 print(" Found: "..vcdir)
466 return vcdir
467 end
468 end
469 return nil
470end
471
472local function get_windows_sdk_directory()
473 assert(type(vars.LUA_RUNTIME) == "string", "requires vars.LUA_RUNTIME to be set before calling this function.")
474 -- Only v7.1 and v6.1 shipped with compilers
475 -- Other versions requires a separate installation of Visual Studio.
476 -- see https://github.com/keplerproject/luarocks/pull/443#issuecomment-152792516
477 local wsdks = {
478 ["MSVCR100"] = "v7.1", -- shipped with Visual Studio 2010 compilers.
479 ["MSVCR100D"] = "v7.1", -- shipped with Visual Studio 2010 compilers.
480 ["MSVCR90"] = "v6.1", -- shipped with Visual Studio 2008 compilers.
481 ["MSVCR90D"] = "v6.1", -- shipped with Visual Studio 2008 compilers.
482 }
483 local wsdkver = wsdks[vars.LUA_RUNTIME]
484 if not wsdkver then
485 print(S[[ Cannot auto-detect Windows SDK version from $LUA_RUNTIME]])
486 return nil
487 end
488
489 local key = "HKLM\\Software\\Microsoft\\Microsoft SDKs\\Windows\\"..wsdkver
490 print(" checking: "..key)
491 local dir = get_registry(key, "InstallationFolder")
492 if dir then
493 print(" Found: "..dir)
494 return dir
495 end
496 print(" No SDK found")
497 return nil
498end
499
500-- returns the batch command to setup msvc compiler path.
501-- or an empty string (eg. "") if not found
502local function get_msvc_env_setup_cmd()
503 print(S[[Looking for Microsoft toolchain matching runtime $LUA_RUNTIME and architecture $UNAME_M]])
504
505 assert(type(vars.UNAME_M) == "string", "requires vars.UNAME_M to be set before calling this function.")
506 local x64 = vars.UNAME_M=="x86_64"
507
508 -- 1. try visual studio command line tools
509 local vcdir = get_visual_studio_directory()
510 if vcdir then
511 -- 1.1. try vcvarsall.bat
512 local vcvarsall = vcdir .. 'vcvarsall.bat'
513 if exists(vcvarsall) then
514 return ('call "%s"%s'):format(vcvarsall, x64 and ' amd64' or '')
515 end
516
517 -- 1.2. try vcvars32.bat / vcvars64.bat
518 local relative_path = x64 and "bin\\amd64\\vcvars64.bat" or "bin\\vcvars32.bat"
519 local full_path = vcdir .. relative_path
520 if exists(full_path) then
521 return ('call "%s"'):format(full_path)
522 end
523 end
524
525 -- 2. try for Windows SDKs command line tools.
526 local wsdkdir = get_windows_sdk_directory()
527 if wsdkdir then
528 local setenv = wsdkdir.."Bin\\SetEnv.cmd"
529 if exists(setenv) then
530 return ('call "%s" /%s'):format(setenv, x64 and "x64" or "x86")
531 end
532 end
533
534 -- finally, we can't detect more, just don't setup the msvc compiler in luarocks.bat.
535 return ""
536end
537
413local function look_for_lua_install () 538local function look_for_lua_install ()
414 print("Looking for Lua interpreter") 539 print("Looking for Lua interpreter")
415 local directories 540 local directories
@@ -656,6 +781,7 @@ if SELFCONTAINED then
656 vars.TREE_ROOT = vars.PREFIX..[[\systree]] 781 vars.TREE_ROOT = vars.PREFIX..[[\systree]]
657 REGISTRY = false 782 REGISTRY = false
658end 783end
784vars.COMPILER_ENV_CMD = (USE_MINGW and "") or (USE_MSVC_MANUAL and "") or get_msvc_env_setup_cmd()
659 785
660print(S[[ 786print(S[[
661 787
@@ -674,11 +800,20 @@ Lua interpreter : $LUA_BINDIR\$LUA_INTERPRETER
674 includes : $LUA_INCDIR 800 includes : $LUA_INCDIR
675 architecture: $UNAME_M 801 architecture: $UNAME_M
676 binary link : $LUA_LIBNAME with runtime $LUA_RUNTIME.dll 802 binary link : $LUA_LIBNAME with runtime $LUA_RUNTIME.dll
677
678]]) 803]])
679 804
805if USE_MINGW then
806 print("Compiler : MinGW (make sure it is in your path before using LuaRocks)")
807else
808 if vars.COMPILER_ENV_CMD == "" then
809 print("Compiler : Microsoft (make sure it is in your path before using LuaRocks)")
810 else
811 print(S[[Compiler : Microsoft, using; $COMPILER_ENV_CMD]])
812 end
813end
814
680if PROMPT then 815if PROMPT then
681 print("Press <ENTER> to start installing, or press <CTRL>+<C> to abort. Use install /? for installation options.") 816 print("\nPress <ENTER> to start installing, or press <CTRL>+<C> to abort. Use install /? for installation options.")
682 io.read() 817 io.read()
683end 818end
684 819
@@ -761,7 +896,8 @@ for _, c in ipairs{"luarocks", "luarocks-admin"} do
761 local f = io.open(vars.BINDIR.."\\"..c..".bat", "w") 896 local f = io.open(vars.BINDIR.."\\"..c..".bat", "w")
762 f:write(S[[ 897 f:write(S[[
763@ECHO OFF 898@ECHO OFF
764SETLOCAL 899SETLOCAL ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
900$COMPILER_ENV_CMD
765SET "LUA_PATH=$LUADIR\?.lua;$LUADIR\?\init.lua;%LUA_PATH%" 901SET "LUA_PATH=$LUADIR\?.lua;$LUADIR\?\init.lua;%LUA_PATH%"
766IF NOT "%LUA_PATH_5_2%"=="" ( 902IF NOT "%LUA_PATH_5_2%"=="" (
767 SET "LUA_PATH_5_2=$LUADIR\?.lua;$LUADIR\?\init.lua;%LUA_PATH_5_2%" 903 SET "LUA_PATH_5_2=$LUADIR\?.lua;$LUADIR\?\init.lua;%LUA_PATH_5_2%"