diff options
Diffstat (limited to 'install.bat')
-rw-r--r-- | install.bat | 151 |
1 files changed, 146 insertions, 5 deletions
diff --git a/install.bat b/install.bat index 42b01c43..8e3df4d9 100644 --- a/install.bat +++ b/install.bat | |||
@@ -8,6 +8,7 @@ local vars = {} | |||
8 | vars.PREFIX = nil | 8 | vars.PREFIX = nil |
9 | vars.VERSION = "2.2" | 9 | vars.VERSION = "2.2" |
10 | vars.SYSCONFDIR = nil | 10 | vars.SYSCONFDIR = nil |
11 | vars.SYSCONFFORCE = nil | ||
11 | vars.CONFBACKUPDIR = nil | 12 | vars.CONFBACKUPDIR = nil |
12 | vars.SYSCONFFILENAME = nil | 13 | vars.SYSCONFFILENAME = nil |
13 | vars.CONFIG_FILE = nil | 14 | vars.CONFIG_FILE = nil |
@@ -29,11 +30,13 @@ vars.LUA_SHORTV = nil -- "51" | |||
29 | vars.LUA_LIB_NAMES = "lua5.1.lib lua51.lib lua5.1.dll lua51.dll liblua.dll.a" | 30 | vars.LUA_LIB_NAMES = "lua5.1.lib lua51.lib lua5.1.dll lua51.dll liblua.dll.a" |
30 | vars.LUA_RUNTIME = nil | 31 | vars.LUA_RUNTIME = nil |
31 | vars.UNAME_M = nil | 32 | vars.UNAME_M = nil |
33 | vars.COMPILER_ENV_CMD = nil | ||
32 | 34 | ||
33 | local FORCE = false | 35 | local FORCE = false |
34 | local FORCE_CONFIG = false | 36 | local FORCE_CONFIG = false |
35 | local INSTALL_LUA = false | 37 | local INSTALL_LUA = false |
36 | local USE_MINGW = false | 38 | local USE_MINGW = false |
39 | local USE_MSVC_MANUAL = false | ||
37 | local REGISTRY = true | 40 | local REGISTRY = true |
38 | local NOADMIN = false | 41 | local NOADMIN = false |
39 | local PROMPT = true | 42 | local PROMPT = true |
@@ -166,7 +169,14 @@ Configuring the Lua interpreter: | |||
166 | (/LUA, /INC, /LIB, /BIN cannot be used with /L) | 169 | (/LUA, /INC, /LIB, /BIN cannot be used with /L) |
167 | 170 | ||
168 | Compiler configuration: | 171 | Compiler configuration: |
169 | /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) | ||
170 | 180 | ||
171 | Other options: | 181 | Other options: |
172 | /FORCECONFIG Use a single config location. Do not use the | 182 | /FORCECONFIG Use a single config location. Do not use the |
@@ -199,6 +209,7 @@ local function parse_options(args) | |||
199 | vars.PREFIX = option.value | 209 | vars.PREFIX = option.value |
200 | elseif name == "/CONFIG" then | 210 | elseif name == "/CONFIG" then |
201 | vars.SYSCONFDIR = option.value | 211 | vars.SYSCONFDIR = option.value |
212 | vars.SYSCONFFORCE = true | ||
202 | elseif name == "/TREE" then | 213 | elseif name == "/TREE" then |
203 | vars.TREE_ROOT = option.value | 214 | vars.TREE_ROOT = option.value |
204 | elseif name == "/SCRIPTS" then | 215 | elseif name == "/SCRIPTS" then |
@@ -213,6 +224,8 @@ local function parse_options(args) | |||
213 | INSTALL_LUA = true | 224 | INSTALL_LUA = true |
214 | elseif name == "/MW" then | 225 | elseif name == "/MW" then |
215 | USE_MINGW = true | 226 | USE_MINGW = true |
227 | elseif name == "/MSVC" then | ||
228 | USE_MSVC_MANUAL = true | ||
216 | elseif name == "/LUA" then | 229 | elseif name == "/LUA" then |
217 | vars.LUA_PREFIX = option.value | 230 | vars.LUA_PREFIX = option.value |
218 | elseif name == "/LIB" then | 231 | elseif name == "/LIB" then |
@@ -266,6 +279,9 @@ local function check_flags() | |||
266 | 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") |
267 | end | 280 | end |
268 | end | 281 | end |
282 | if USE_MSVC_MANUAL and USE_MINGW then | ||
283 | die("Cannot combine option /MSVC and /MW") | ||
284 | end | ||
269 | end | 285 | end |
270 | 286 | ||
271 | -- *********************************************************** | 287 | -- *********************************************************** |
@@ -408,6 +424,117 @@ local function get_architecture() | |||
408 | return proc | 424 | return proc |
409 | end | 425 | end |
410 | 426 | ||
427 | -- get a string value from windows registry. | ||
428 | local 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 | ||
447 | end | ||
448 | |||
449 | local 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 | ||
470 | end | ||
471 | |||
472 | local 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 | ||
498 | end | ||
499 | |||
500 | -- returns the batch command to setup msvc compiler path. | ||
501 | -- or an empty string (eg. "") if not found | ||
502 | local 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 "" | ||
536 | end | ||
537 | |||
411 | local function look_for_lua_install () | 538 | local function look_for_lua_install () |
412 | print("Looking for Lua interpreter") | 539 | print("Looking for Lua interpreter") |
413 | local directories | 540 | local directories |
@@ -650,9 +777,11 @@ vars.SYSCONFFILENAME = S"config-$LUA_VERSION.lua" | |||
650 | vars.CONFIG_FILE = vars.SYSCONFDIR.."\\"..vars.SYSCONFFILENAME | 777 | vars.CONFIG_FILE = vars.SYSCONFDIR.."\\"..vars.SYSCONFFILENAME |
651 | if SELFCONTAINED then | 778 | if SELFCONTAINED then |
652 | vars.SYSCONFDIR = vars.PREFIX | 779 | vars.SYSCONFDIR = vars.PREFIX |
780 | vars.SYSCONFFORCE = true | ||
653 | vars.TREE_ROOT = vars.PREFIX..[[\systree]] | 781 | vars.TREE_ROOT = vars.PREFIX..[[\systree]] |
654 | REGISTRY = false | 782 | REGISTRY = false |
655 | end | 783 | end |
784 | vars.COMPILER_ENV_CMD = (USE_MINGW and "") or (USE_MSVC_MANUAL and "") or get_msvc_env_setup_cmd() | ||
656 | 785 | ||
657 | print(S[[ | 786 | print(S[[ |
658 | 787 | ||
@@ -671,11 +800,20 @@ Lua interpreter : $LUA_BINDIR\$LUA_INTERPRETER | |||
671 | includes : $LUA_INCDIR | 800 | includes : $LUA_INCDIR |
672 | architecture: $UNAME_M | 801 | architecture: $UNAME_M |
673 | binary link : $LUA_LIBNAME with runtime $LUA_RUNTIME.dll | 802 | binary link : $LUA_LIBNAME with runtime $LUA_RUNTIME.dll |
674 | |||
675 | ]]) | 803 | ]]) |
676 | 804 | ||
805 | if USE_MINGW then | ||
806 | print("Compiler : MinGW (make sure it is in your path before using LuaRocks)") | ||
807 | else | ||
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 | ||
813 | end | ||
814 | |||
677 | if PROMPT then | 815 | if PROMPT then |
678 | 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.") |
679 | io.read() | 817 | io.read() |
680 | end | 818 | end |
681 | 819 | ||
@@ -758,7 +896,8 @@ for _, c in ipairs{"luarocks", "luarocks-admin"} do | |||
758 | local f = io.open(vars.BINDIR.."\\"..c..".bat", "w") | 896 | local f = io.open(vars.BINDIR.."\\"..c..".bat", "w") |
759 | f:write(S[[ | 897 | f:write(S[[ |
760 | @ECHO OFF | 898 | @ECHO OFF |
761 | SETLOCAL | 899 | SETLOCAL ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS |
900 | $COMPILER_ENV_CMD | ||
762 | SET "LUA_PATH=$LUADIR\?.lua;$LUADIR\?\init.lua;%LUA_PATH%" | 901 | SET "LUA_PATH=$LUADIR\?.lua;$LUADIR\?\init.lua;%LUA_PATH%" |
763 | IF NOT "%LUA_PATH_5_2%"=="" ( | 902 | IF NOT "%LUA_PATH_5_2%"=="" ( |
764 | 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%" |
@@ -835,7 +974,6 @@ else | |||
835 | end | 974 | end |
836 | f:write(S[=[ | 975 | f:write(S[=[ |
837 | site_config.LUAROCKS_UNAME_M=[[$UNAME_M]] | 976 | site_config.LUAROCKS_UNAME_M=[[$UNAME_M]] |
838 | site_config.LUAROCKS_SYSCONFIG=[[$CONFIG_FILE]] | ||
839 | site_config.LUAROCKS_ROCKS_TREE=[[$TREE_ROOT]] | 977 | site_config.LUAROCKS_ROCKS_TREE=[[$TREE_ROOT]] |
840 | site_config.LUAROCKS_PREFIX=[[$PREFIX]] | 978 | site_config.LUAROCKS_PREFIX=[[$PREFIX]] |
841 | site_config.LUAROCKS_DOWNLOADER=[[wget]] | 979 | site_config.LUAROCKS_DOWNLOADER=[[wget]] |
@@ -844,6 +982,9 @@ site_config.LUAROCKS_MD5CHECKER=[[md5sum]] | |||
844 | if FORCE_CONFIG then | 982 | if FORCE_CONFIG then |
845 | f:write("site_config.LUAROCKS_FORCE_CONFIG=true\n") | 983 | f:write("site_config.LUAROCKS_FORCE_CONFIG=true\n") |
846 | end | 984 | end |
985 | if vars.SYSCONFFORCE then -- only write this value when explcitly given, otherwise rely on defaults | ||
986 | f:write("site_config.LUAROCKS_SYSCONFIG=[[$CONFIG_FILE]]\n") | ||
987 | end | ||
847 | f:write("return site_config\n") | 988 | f:write("return site_config\n") |
848 | f:close() | 989 | f:close() |
849 | print(S([[Created LuaRocks site-config file: $LUADIR\luarocks\]]..site_config..[[.lua]])) | 990 | print(S([[Created LuaRocks site-config file: $LUADIR\luarocks\]]..site_config..[[.lua]])) |