From a726e45ec81e2cc8512f9e4c5b1459a86ab53098 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Tue, 12 Nov 2013 16:14:21 +0100 Subject: Several updates: 1) will search the system path for Lua interpreter if no location is found. Only then the ancient defaults will be checked. 2) if /LUA is provided, it will only look there, and fail if not found instead of falling back to the defaults 3) if no interpreter found, it is not automatically installed. Only with explicit /L switch the included interpreter is installed --- install.bat | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 9 deletions(-) diff --git a/install.bat b/install.bat index f6601aa8..c085de40 100644 --- a/install.bat +++ b/install.bat @@ -41,6 +41,32 @@ local function die(message) os.exit(1) end +function split_string(str, delim, maxNb) + -- Eliminate bad cases... + if string.find(str, delim) == nil then + return { str } + end + if maxNb == nil or maxNb < 1 then + maxNb = 0 -- No limit + end + local result = {} + local pat = "(.-)" .. delim .. "()" + local nb = 0 + local lastPos + for part, pos in string.gmatch(str, pat) do + nb = nb + 1 + result[nb] = part + lastPos = pos + if nb == maxNb then break end + end + -- Handle the last field + if nb ~= maxNb then + result[nb + 1] = string.sub(str, lastPos) + end + return result +end + + local function exec(cmd) --print(cmd) local status = os.execute(cmd) @@ -180,6 +206,7 @@ end -- *********************************************************** local function look_for_interpreter (directory) if vars.LUA_BINDIR then + -- if LUA_BINDIR is specified, it must be there, otherwise we fail if exists( S"$LUA_BINDIR\\lua$LUA_VERSION.exe" ) then vars.LUA_INTERPRETER = S"lua$LUA_VERSION.exe" print(S" Found $LUA_BINDIR\\$LUA_INTERPRETER") @@ -309,9 +336,31 @@ end local function look_for_lua_install () print("Looking for Lua interpreter") - local directories = { [[c:\lua5.1.2]], [[c:\lua]], [[c:\kepler\1.1]] } + local directories if vars.LUA_PREFIX then - table.insert(directories, 1, vars.LUA_PREFIX) + directories = { vars.LUA_PREFIX } + else + -- no prefix given, so use path + directories = (os.getenv("PATH",";") or "") + local i = 1 + while i ~= 0 do directories, i = directories:gsub(";;",";") end --remove all doubles + directories = split_string(directories,";") + -- if a path element ends with "\bin\" then remove it, as the searcher will check there anyway + for i, val in ipairs(directories) do + -- remove trailing backslash + while val:sub(-1,-1) == "\\" and val:sub(-2,-1) ~= ":\\" do + val = val:sub(1,-2) + end + -- remove trailing 'bin' + if val:upper():sub(-4,-1) == "\\BIN" or val:upper():sub(-4,-1) == ":BIN" then + val = val:sub(1,-5) + end + directories[i] = val + end + -- finaly add some other default paths + table.insert(directories, [[c:\lua5.1.2]]) + table.insert(directories, [[c:\lua]]) + table.insert(directories, [[c:\kepler\1.1]]) end if vars.LUA_BINDIR and vars.LUA_LIBDIR and vars.LUA_INCDIR then if look_for_interpreter(vars.LUA_BINDIR) and @@ -397,13 +446,10 @@ vars.LUADIR = S"$FULL_PREFIX\\lua" vars.INCDIR = S"$FULL_PREFIX\\include" vars.LUA_SHORTV = vars.LUA_VERSION:gsub("%.", "") -if not look_for_lua_install() then - print("Could not find Lua. Will install its own copy.") - print("See /? for options for specifying the location of Lua.") +if INSTALL_LUA then if vars.LUA_VERSION ~= "5.1" then die("Cannot install own copy because no 5.2 version is bundled") end - INSTALL_LUA = true vars.LUA_INTERPRETER = "lua5.1" vars.LUA_BINDIR = vars.BINDIR vars.LUA_LIBDIR = vars.LIBDIR @@ -412,8 +458,13 @@ if not look_for_lua_install() then vars.LUA_RUNTIME = "MSVCR80" vars.UNAME_M = "x86" else - vars.UNAME_M = get_architecture() - print(S[[ + if not look_for_lua_install() then + die("Could not find Lua. See /? for options for specifying the location of Lua, or installing a bundled copy of Lua 5.1.") + end + vars.UNAME_M = get_architecture() -- can only do when installation was found +end + +print(S[[ Will configure LuaRocks with the following paths: LuaRocks : $FULL_PREFIX @@ -425,7 +476,7 @@ Binaries will be linked against: $LUA_LIBNAME with runtime $LUA_RUNTIME System architecture detected as: $UNAME_M ]]) -end + -- *********************************************************** -- Install LuaRocks files -- cgit v1.2.3-55-g6feb