diff options
author | Thijs Schreijer <thijs@thijsschreijer.nl> | 2013-11-12 16:14:21 +0100 |
---|---|---|
committer | Thijs Schreijer <thijs@thijsschreijer.nl> | 2013-11-12 16:14:21 +0100 |
commit | a726e45ec81e2cc8512f9e4c5b1459a86ab53098 (patch) | |
tree | 03b0125a96e9fadceb3b0d00c9927da1ad8b614d | |
parent | f3fae7c816bba9da85fbd42725933d94444aceef (diff) | |
download | luarocks-a726e45ec81e2cc8512f9e4c5b1459a86ab53098.tar.gz luarocks-a726e45ec81e2cc8512f9e4c5b1459a86ab53098.tar.bz2 luarocks-a726e45ec81e2cc8512f9e4c5b1459a86ab53098.zip |
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
-rw-r--r-- | install.bat | 69 |
1 files 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) | |||
41 | os.exit(1) | 41 | os.exit(1) |
42 | end | 42 | end |
43 | 43 | ||
44 | function split_string(str, delim, maxNb) | ||
45 | -- Eliminate bad cases... | ||
46 | if string.find(str, delim) == nil then | ||
47 | return { str } | ||
48 | end | ||
49 | if maxNb == nil or maxNb < 1 then | ||
50 | maxNb = 0 -- No limit | ||
51 | end | ||
52 | local result = {} | ||
53 | local pat = "(.-)" .. delim .. "()" | ||
54 | local nb = 0 | ||
55 | local lastPos | ||
56 | for part, pos in string.gmatch(str, pat) do | ||
57 | nb = nb + 1 | ||
58 | result[nb] = part | ||
59 | lastPos = pos | ||
60 | if nb == maxNb then break end | ||
61 | end | ||
62 | -- Handle the last field | ||
63 | if nb ~= maxNb then | ||
64 | result[nb + 1] = string.sub(str, lastPos) | ||
65 | end | ||
66 | return result | ||
67 | end | ||
68 | |||
69 | |||
44 | local function exec(cmd) | 70 | local function exec(cmd) |
45 | --print(cmd) | 71 | --print(cmd) |
46 | local status = os.execute(cmd) | 72 | local status = os.execute(cmd) |
@@ -180,6 +206,7 @@ end | |||
180 | -- *********************************************************** | 206 | -- *********************************************************** |
181 | local function look_for_interpreter (directory) | 207 | local function look_for_interpreter (directory) |
182 | if vars.LUA_BINDIR then | 208 | if vars.LUA_BINDIR then |
209 | -- if LUA_BINDIR is specified, it must be there, otherwise we fail | ||
183 | if exists( S"$LUA_BINDIR\\lua$LUA_VERSION.exe" ) then | 210 | if exists( S"$LUA_BINDIR\\lua$LUA_VERSION.exe" ) then |
184 | vars.LUA_INTERPRETER = S"lua$LUA_VERSION.exe" | 211 | vars.LUA_INTERPRETER = S"lua$LUA_VERSION.exe" |
185 | print(S" Found $LUA_BINDIR\\$LUA_INTERPRETER") | 212 | print(S" Found $LUA_BINDIR\\$LUA_INTERPRETER") |
@@ -309,9 +336,31 @@ end | |||
309 | 336 | ||
310 | local function look_for_lua_install () | 337 | local function look_for_lua_install () |
311 | print("Looking for Lua interpreter") | 338 | print("Looking for Lua interpreter") |
312 | local directories = { [[c:\lua5.1.2]], [[c:\lua]], [[c:\kepler\1.1]] } | 339 | local directories |
313 | if vars.LUA_PREFIX then | 340 | if vars.LUA_PREFIX then |
314 | table.insert(directories, 1, vars.LUA_PREFIX) | 341 | directories = { vars.LUA_PREFIX } |
342 | else | ||
343 | -- no prefix given, so use path | ||
344 | directories = (os.getenv("PATH",";") or "") | ||
345 | local i = 1 | ||
346 | while i ~= 0 do directories, i = directories:gsub(";;",";") end --remove all doubles | ||
347 | directories = split_string(directories,";") | ||
348 | -- if a path element ends with "\bin\" then remove it, as the searcher will check there anyway | ||
349 | for i, val in ipairs(directories) do | ||
350 | -- remove trailing backslash | ||
351 | while val:sub(-1,-1) == "\\" and val:sub(-2,-1) ~= ":\\" do | ||
352 | val = val:sub(1,-2) | ||
353 | end | ||
354 | -- remove trailing 'bin' | ||
355 | if val:upper():sub(-4,-1) == "\\BIN" or val:upper():sub(-4,-1) == ":BIN" then | ||
356 | val = val:sub(1,-5) | ||
357 | end | ||
358 | directories[i] = val | ||
359 | end | ||
360 | -- finaly add some other default paths | ||
361 | table.insert(directories, [[c:\lua5.1.2]]) | ||
362 | table.insert(directories, [[c:\lua]]) | ||
363 | table.insert(directories, [[c:\kepler\1.1]]) | ||
315 | end | 364 | end |
316 | if vars.LUA_BINDIR and vars.LUA_LIBDIR and vars.LUA_INCDIR then | 365 | if vars.LUA_BINDIR and vars.LUA_LIBDIR and vars.LUA_INCDIR then |
317 | if look_for_interpreter(vars.LUA_BINDIR) and | 366 | if look_for_interpreter(vars.LUA_BINDIR) and |
@@ -397,13 +446,10 @@ vars.LUADIR = S"$FULL_PREFIX\\lua" | |||
397 | vars.INCDIR = S"$FULL_PREFIX\\include" | 446 | vars.INCDIR = S"$FULL_PREFIX\\include" |
398 | vars.LUA_SHORTV = vars.LUA_VERSION:gsub("%.", "") | 447 | vars.LUA_SHORTV = vars.LUA_VERSION:gsub("%.", "") |
399 | 448 | ||
400 | if not look_for_lua_install() then | 449 | if INSTALL_LUA then |
401 | print("Could not find Lua. Will install its own copy.") | ||
402 | print("See /? for options for specifying the location of Lua.") | ||
403 | if vars.LUA_VERSION ~= "5.1" then | 450 | if vars.LUA_VERSION ~= "5.1" then |
404 | die("Cannot install own copy because no 5.2 version is bundled") | 451 | die("Cannot install own copy because no 5.2 version is bundled") |
405 | end | 452 | end |
406 | INSTALL_LUA = true | ||
407 | vars.LUA_INTERPRETER = "lua5.1" | 453 | vars.LUA_INTERPRETER = "lua5.1" |
408 | vars.LUA_BINDIR = vars.BINDIR | 454 | vars.LUA_BINDIR = vars.BINDIR |
409 | vars.LUA_LIBDIR = vars.LIBDIR | 455 | vars.LUA_LIBDIR = vars.LIBDIR |
@@ -412,8 +458,13 @@ if not look_for_lua_install() then | |||
412 | vars.LUA_RUNTIME = "MSVCR80" | 458 | vars.LUA_RUNTIME = "MSVCR80" |
413 | vars.UNAME_M = "x86" | 459 | vars.UNAME_M = "x86" |
414 | else | 460 | else |
415 | vars.UNAME_M = get_architecture() | 461 | if not look_for_lua_install() then |
416 | print(S[[ | 462 | die("Could not find Lua. See /? for options for specifying the location of Lua, or installing a bundled copy of Lua 5.1.") |
463 | end | ||
464 | vars.UNAME_M = get_architecture() -- can only do when installation was found | ||
465 | end | ||
466 | |||
467 | print(S[[ | ||
417 | 468 | ||
418 | Will configure LuaRocks with the following paths: | 469 | Will configure LuaRocks with the following paths: |
419 | LuaRocks : $FULL_PREFIX | 470 | LuaRocks : $FULL_PREFIX |
@@ -425,7 +476,7 @@ Binaries will be linked against: $LUA_LIBNAME with runtime $LUA_RUNTIME | |||
425 | System architecture detected as: $UNAME_M | 476 | System architecture detected as: $UNAME_M |
426 | 477 | ||
427 | ]]) | 478 | ]]) |
428 | end | 479 | |
429 | 480 | ||
430 | -- *********************************************************** | 481 | -- *********************************************************** |
431 | -- Install LuaRocks files | 482 | -- Install LuaRocks files |