Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/luajit-rocks.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'luarocks/install.bat')
-rw-r--r--luarocks/install.bat153
1 files changed, 147 insertions, 6 deletions
diff --git a/luarocks/install.bat b/luarocks/install.bat
index e362b31..5acfea6 100644
--- a/luarocks/install.bat
+++ b/luarocks/install.bat
@@ -6,8 +6,9 @@ local vars = {}
vars.PREFIX = nil
-vars.VERSION = "2.2"
+vars.VERSION = "2.3"
vars.SYSCONFDIR = nil
+vars.SYSCONFFORCE = nil
vars.CONFBACKUPDIR = nil
vars.SYSCONFFILENAME = nil
vars.CONFIG_FILE = nil
@@ -29,11 +30,13 @@ vars.LUA_SHORTV = nil -- "51"
vars.LUA_LIB_NAMES = "lua5.1.lib lua51.lib lua5.1.dll lua51.dll liblua.dll.a"
vars.LUA_RUNTIME = nil
vars.UNAME_M = nil
+vars.COMPILER_ENV_CMD = nil
local FORCE = false
local FORCE_CONFIG = false
local INSTALL_LUA = false
local USE_MINGW = false
+local USE_MSVC_MANUAL = false
local REGISTRY = true
local NOADMIN = false
local PROMPT = true
@@ -166,7 +169,14 @@ Configuring the Lua interpreter:
(/LUA, /INC, /LIB, /BIN cannot be used with /L)
Compiler configuration:
-/MW Use mingw as build system instead of MSVC
+ By default the installer will try to determine the
+ Microsoft toolchain to use. And will automatically use
+ a setup command to initialize that toolchain when
+ LuaRocks is run. If it cannot find it, it will default
+ to the /MSVC switch.
+/MSVC Use MS toolchain, without a setup command (tools must
+ be in your path)
+/MW Use mingw as build system (tools must be in your path)
Other options:
/FORCECONFIG Use a single config location. Do not use the
@@ -199,6 +209,7 @@ local function parse_options(args)
vars.PREFIX = option.value
elseif name == "/CONFIG" then
vars.SYSCONFDIR = option.value
+ vars.SYSCONFFORCE = true
elseif name == "/TREE" then
vars.TREE_ROOT = option.value
elseif name == "/SCRIPTS" then
@@ -213,6 +224,8 @@ local function parse_options(args)
INSTALL_LUA = true
elseif name == "/MW" then
USE_MINGW = true
+ elseif name == "/MSVC" then
+ USE_MSVC_MANUAL = true
elseif name == "/LUA" then
vars.LUA_PREFIX = option.value
elseif name == "/LIB" then
@@ -266,6 +279,9 @@ local function check_flags()
die("Bad argument: /LV must either be 5.1, 5.2, or 5.3")
end
end
+ if USE_MSVC_MANUAL and USE_MINGW then
+ die("Cannot combine option /MSVC and /MW")
+ end
end
-- ***********************************************************
@@ -408,6 +424,117 @@ local function get_architecture()
return proc
end
+-- get a string value from windows registry.
+local function get_registry(key, value)
+ local keys = {key}
+ local key64, replaced = key:gsub("(%u+\\Software\\)", "\1Wow6432Node\\", 1)
+
+ if replaced == 1 then
+ keys = {key64, key}
+ end
+
+ for _, k in ipairs(keys) do
+ local h = io.popen('reg query "'..k..'" /v '..value..' 2>NUL')
+ local output = h:read("*a")
+ h:close()
+
+ local v = output:match("REG_SZ%s+([^\n]+)")
+ if v then
+ return v
+ end
+ end
+ return nil
+end
+
+local function get_visual_studio_directory()
+ assert(type(vars.LUA_RUNTIME)=="string", "requires vars.LUA_RUNTIME to be set before calling this function.")
+ local major, minor = vars.LUA_RUNTIME:match('VCR%u*(%d+)(%d)$') -- MSVCR<x><y> or VCRUNTIME<x><y>
+ if not major then
+ print(S[[ Cannot auto-detect Visual Studio version from $LUA_RUNTIME]])
+ return nil
+ end
+ local keys = {
+ "HKLM\\Software\\Microsoft\\VisualStudio\\%d.%d\\Setup\\VC",
+ "HKLM\\Software\\Microsoft\\VCExpress\\%d.%d\\Setup\\VS"
+ }
+ for _, key in ipairs(keys) do
+ local versionedkey = key:format(major, minor)
+ local vcdir = get_registry(versionedkey, "ProductDir")
+ print(" checking: "..versionedkey)
+ if vcdir then
+ print(" Found: "..vcdir)
+ return vcdir
+ end
+ end
+ return nil
+end
+
+local function get_windows_sdk_directory()
+ assert(type(vars.LUA_RUNTIME) == "string", "requires vars.LUA_RUNTIME to be set before calling this function.")
+ -- Only v7.1 and v6.1 shipped with compilers
+ -- Other versions requires a separate installation of Visual Studio.
+ -- see https://github.com/keplerproject/luarocks/pull/443#issuecomment-152792516
+ local wsdks = {
+ ["MSVCR100"] = "v7.1", -- shipped with Visual Studio 2010 compilers.
+ ["MSVCR100D"] = "v7.1", -- shipped with Visual Studio 2010 compilers.
+ ["MSVCR90"] = "v6.1", -- shipped with Visual Studio 2008 compilers.
+ ["MSVCR90D"] = "v6.1", -- shipped with Visual Studio 2008 compilers.
+ }
+ local wsdkver = wsdks[vars.LUA_RUNTIME]
+ if not wsdkver then
+ print(S[[ Cannot auto-detect Windows SDK version from $LUA_RUNTIME]])
+ return nil
+ end
+
+ local key = "HKLM\\Software\\Microsoft\\Microsoft SDKs\\Windows\\"..wsdkver
+ print(" checking: "..key)
+ local dir = get_registry(key, "InstallationFolder")
+ if dir then
+ print(" Found: "..dir)
+ return dir
+ end
+ print(" No SDK found")
+ return nil
+end
+
+-- returns the batch command to setup msvc compiler path.
+-- or an empty string (eg. "") if not found
+local function get_msvc_env_setup_cmd()
+ print(S[[Looking for Microsoft toolchain matching runtime $LUA_RUNTIME and architecture $UNAME_M]])
+
+ assert(type(vars.UNAME_M) == "string", "requires vars.UNAME_M to be set before calling this function.")
+ local x64 = vars.UNAME_M=="x86_64"
+
+ -- 1. try visual studio command line tools
+ local vcdir = get_visual_studio_directory()
+ if vcdir then
+ -- 1.1. try vcvarsall.bat
+ local vcvarsall = vcdir .. 'vcvarsall.bat'
+ if exists(vcvarsall) then
+ return ('call "%s"%s'):format(vcvarsall, x64 and ' amd64' or '')
+ end
+
+ -- 1.2. try vcvars32.bat / vcvars64.bat
+ local relative_path = x64 and "bin\\amd64\\vcvars64.bat" or "bin\\vcvars32.bat"
+ local full_path = vcdir .. relative_path
+ if exists(full_path) then
+ return ('call "%s"'):format(full_path)
+ end
+ end
+
+ -- 2. try for Windows SDKs command line tools.
+ local wsdkdir = get_windows_sdk_directory()
+ if wsdkdir then
+ local setenv = wsdkdir.."Bin\\SetEnv.cmd"
+ if exists(setenv) then
+ return ('call "%s" /%s'):format(setenv, x64 and "x64" or "x86")
+ end
+ end
+
+ -- finally, we can't detect more, just don't setup the msvc compiler in luarocks.bat.
+ return ""
+end
+
local function look_for_lua_install ()
print("Looking for Lua interpreter")
local directories
@@ -650,9 +777,11 @@ vars.SYSCONFFILENAME = S"config-$LUA_VERSION.lua"
vars.CONFIG_FILE = vars.SYSCONFDIR.."\\"..vars.SYSCONFFILENAME
if SELFCONTAINED then
vars.SYSCONFDIR = vars.PREFIX
+ vars.SYSCONFFORCE = true
vars.TREE_ROOT = vars.PREFIX..[[\systree]]
REGISTRY = false
end
+vars.COMPILER_ENV_CMD = (USE_MINGW and "") or (USE_MSVC_MANUAL and "") or get_msvc_env_setup_cmd()
print(S[[
@@ -671,11 +800,20 @@ Lua interpreter : $LUA_BINDIR\$LUA_INTERPRETER
includes : $LUA_INCDIR
architecture: $UNAME_M
binary link : $LUA_LIBNAME with runtime $LUA_RUNTIME.dll
-
]])
+if USE_MINGW then
+ print("Compiler : MinGW (make sure it is in your path before using LuaRocks)")
+else
+ if vars.COMPILER_ENV_CMD == "" then
+ print("Compiler : Microsoft (make sure it is in your path before using LuaRocks)")
+ else
+ print(S[[Compiler : Microsoft, using; $COMPILER_ENV_CMD]])
+ end
+end
+
if PROMPT then
- print("Press <ENTER> to start installing, or press <CTRL>+<C> to abort. Use install /? for installation options.")
+ print("\nPress <ENTER> to start installing, or press <CTRL>+<C> to abort. Use install /? for installation options.")
io.read()
end
@@ -758,7 +896,8 @@ for _, c in ipairs{"luarocks", "luarocks-admin"} do
local f = io.open(vars.BINDIR.."\\"..c..".bat", "w")
f:write(S[[
@ECHO OFF
-SETLOCAL
+SETLOCAL ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS
+$COMPILER_ENV_CMD
SET "LUA_PATH=$LUADIR\?.lua;$LUADIR\?\init.lua;%LUA_PATH%"
IF NOT "%LUA_PATH_5_2%"=="" (
SET "LUA_PATH_5_2=$LUADIR\?.lua;$LUADIR\?\init.lua;%LUA_PATH_5_2%"
@@ -835,7 +974,6 @@ else
end
f:write(S[=[
site_config.LUAROCKS_UNAME_M=[[$UNAME_M]]
-site_config.LUAROCKS_SYSCONFIG=[[$CONFIG_FILE]]
site_config.LUAROCKS_ROCKS_TREE=[[$TREE_ROOT]]
site_config.LUAROCKS_PREFIX=[[$PREFIX]]
site_config.LUAROCKS_DOWNLOADER=[[wget]]
@@ -844,6 +982,9 @@ site_config.LUAROCKS_MD5CHECKER=[[md5sum]]
if FORCE_CONFIG then
f:write("site_config.LUAROCKS_FORCE_CONFIG=true\n")
end
+if vars.SYSCONFFORCE then -- only write this value when explcitly given, otherwise rely on defaults
+ f:write(S("site_config.LUAROCKS_SYSCONFIG=[[$CONFIG_FILE]]\n"))
+end
f:write("return site_config\n")
f:close()
print(S([[Created LuaRocks site-config file: $LUADIR\luarocks\]]..site_config..[[.lua]]))