diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2013-11-12 13:52:50 -0800 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2013-11-12 13:52:50 -0800 |
| commit | 0521c3d66d434d118efa38e3bfbae41bef820630 (patch) | |
| tree | ee2ec2585c914484d392c1902a611c10a8c71263 | |
| parent | 1078610241d5fe84733bc1094653b482dc64a8ac (diff) | |
| parent | f0f3f13d32a4de05cc5d0f4e2a62b600fbce09c7 (diff) | |
| download | luarocks-0521c3d66d434d118efa38e3bfbae41bef820630.tar.gz luarocks-0521c3d66d434d118efa38e3bfbae41bef820630.tar.bz2 luarocks-0521c3d66d434d118efa38e3bfbae41bef820630.zip | |
Merge pull request #181 from Tieske/win_install_checkpath
Search system path for Lua install instead of ancient defaults
| -rw-r--r-- | install.bat | 76 |
1 files changed, 65 insertions, 11 deletions
diff --git a/install.bat b/install.bat index 02a3f013..a4257be6 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) |
| @@ -80,6 +106,9 @@ Configuring the Lua interpreter: | |||
| 80 | /LV [version] Lua version to use; either 5.1 or 5.2. | 106 | /LV [version] Lua version to use; either 5.1 or 5.2. |
| 81 | Default is 5.1 | 107 | Default is 5.1 |
| 82 | /LUA [dir] Location where Lua is installed - e.g. c:\lua\5.1\ | 108 | /LUA [dir] Location where Lua is installed - e.g. c:\lua\5.1\ |
| 109 | If not provided, the installer will search the system | ||
| 110 | path and some default locations for a valid Lua | ||
| 111 | installation. | ||
| 83 | This is the base directory, the installer will look | 112 | This is the base directory, the installer will look |
| 84 | for subdirectories bin, lib, include. Alternatively | 113 | for subdirectories bin, lib, include. Alternatively |
| 85 | these can be specified explicitly using the /INC, | 114 | these can be specified explicitly using the /INC, |
| @@ -184,6 +213,7 @@ end | |||
| 184 | -- *********************************************************** | 213 | -- *********************************************************** |
| 185 | local function look_for_interpreter (directory) | 214 | local function look_for_interpreter (directory) |
| 186 | if vars.LUA_BINDIR then | 215 | if vars.LUA_BINDIR then |
| 216 | -- if LUA_BINDIR is specified, it must be there, otherwise we fail | ||
| 187 | if exists( S"$LUA_BINDIR\\lua$LUA_VERSION.exe" ) then | 217 | if exists( S"$LUA_BINDIR\\lua$LUA_VERSION.exe" ) then |
| 188 | vars.LUA_INTERPRETER = S"lua$LUA_VERSION.exe" | 218 | vars.LUA_INTERPRETER = S"lua$LUA_VERSION.exe" |
| 189 | print(S" Found $LUA_BINDIR\\$LUA_INTERPRETER") | 219 | print(S" Found $LUA_BINDIR\\$LUA_INTERPRETER") |
| @@ -313,9 +343,31 @@ end | |||
| 313 | 343 | ||
| 314 | local function look_for_lua_install () | 344 | local function look_for_lua_install () |
| 315 | print("Looking for Lua interpreter") | 345 | print("Looking for Lua interpreter") |
| 316 | local directories = { [[c:\lua5.1.2]], [[c:\lua]], [[c:\kepler\1.1]] } | 346 | local directories |
| 317 | if vars.LUA_PREFIX then | 347 | if vars.LUA_PREFIX then |
| 318 | table.insert(directories, 1, vars.LUA_PREFIX) | 348 | directories = { vars.LUA_PREFIX } |
| 349 | else | ||
| 350 | -- no prefix given, so use path | ||
| 351 | directories = (os.getenv("PATH",";") or "") | ||
| 352 | local i = 1 | ||
| 353 | while i ~= 0 do directories, i = directories:gsub(";;",";") end --remove all doubles | ||
| 354 | directories = split_string(directories,";") | ||
| 355 | -- if a path element ends with "\bin\" then remove it, as the searcher will check there anyway | ||
| 356 | for i, val in ipairs(directories) do | ||
| 357 | -- remove trailing backslash | ||
| 358 | while val:sub(-1,-1) == "\\" and val:sub(-2,-1) ~= ":\\" do | ||
| 359 | val = val:sub(1,-2) | ||
| 360 | end | ||
| 361 | -- remove trailing 'bin' | ||
| 362 | if val:upper():sub(-4,-1) == "\\BIN" or val:upper():sub(-4,-1) == ":BIN" then | ||
| 363 | val = val:sub(1,-5) | ||
| 364 | end | ||
| 365 | directories[i] = val | ||
| 366 | end | ||
| 367 | -- finaly add some other default paths | ||
| 368 | table.insert(directories, [[c:\lua5.1.2]]) | ||
| 369 | table.insert(directories, [[c:\lua]]) | ||
| 370 | table.insert(directories, [[c:\kepler\1.1]]) | ||
| 319 | end | 371 | end |
| 320 | if vars.LUA_BINDIR and vars.LUA_LIBDIR and vars.LUA_INCDIR then | 372 | if vars.LUA_BINDIR and vars.LUA_LIBDIR and vars.LUA_INCDIR then |
| 321 | if look_for_interpreter(vars.LUA_BINDIR) and | 373 | if look_for_interpreter(vars.LUA_BINDIR) and |
| @@ -425,13 +477,10 @@ vars.LUADIR = S"$FULL_PREFIX\\lua" | |||
| 425 | vars.INCDIR = S"$FULL_PREFIX\\include" | 477 | vars.INCDIR = S"$FULL_PREFIX\\include" |
| 426 | vars.LUA_SHORTV = vars.LUA_VERSION:gsub("%.", "") | 478 | vars.LUA_SHORTV = vars.LUA_VERSION:gsub("%.", "") |
| 427 | 479 | ||
| 428 | if not look_for_lua_install() then | 480 | if INSTALL_LUA then |
| 429 | print("Could not find Lua. Will install its own copy.") | ||
| 430 | print("See /? for options for specifying the location of Lua.") | ||
| 431 | if vars.LUA_VERSION ~= "5.1" then | 481 | if vars.LUA_VERSION ~= "5.1" then |
| 432 | die("Cannot install own copy because no 5.2 version is bundled") | 482 | die("Cannot install own copy of Lua because only 5.1 is bundled") |
| 433 | end | 483 | end |
| 434 | INSTALL_LUA = true | ||
| 435 | vars.LUA_INTERPRETER = "lua5.1" | 484 | vars.LUA_INTERPRETER = "lua5.1" |
| 436 | vars.LUA_BINDIR = vars.BINDIR | 485 | vars.LUA_BINDIR = vars.BINDIR |
| 437 | vars.LUA_LIBDIR = vars.LIBDIR | 486 | vars.LUA_LIBDIR = vars.LIBDIR |
| @@ -440,8 +489,13 @@ if not look_for_lua_install() then | |||
| 440 | vars.LUA_RUNTIME = "MSVCR80" | 489 | vars.LUA_RUNTIME = "MSVCR80" |
| 441 | vars.UNAME_M = "x86" | 490 | vars.UNAME_M = "x86" |
| 442 | else | 491 | else |
| 443 | vars.UNAME_M = get_architecture() | 492 | if not look_for_lua_install() then |
| 444 | print(S[[ | 493 | die("Could not find Lua. See /? for options for specifying the location of Lua, or installing a bundled copy of Lua 5.1.") |
| 494 | end | ||
| 495 | vars.UNAME_M = get_architecture() -- can only do when installation was found | ||
| 496 | end | ||
| 497 | |||
| 498 | print(S[[ | ||
| 445 | 499 | ||
| 446 | Will configure LuaRocks with the following paths: | 500 | Will configure LuaRocks with the following paths: |
| 447 | LuaRocks : $FULL_PREFIX | 501 | LuaRocks : $FULL_PREFIX |
| @@ -453,7 +507,7 @@ Binaries will be linked against: $LUA_LIBNAME with runtime $LUA_RUNTIME | |||
| 453 | System architecture detected as: $UNAME_M | 507 | System architecture detected as: $UNAME_M |
| 454 | 508 | ||
| 455 | ]]) | 509 | ]]) |
| 456 | end | 510 | |
| 457 | 511 | ||
| 458 | -- *********************************************************** | 512 | -- *********************************************************** |
| 459 | -- Install LuaRocks files | 513 | -- Install LuaRocks files |
| @@ -642,7 +696,7 @@ if REGISTRY then | |||
| 642 | print() | 696 | print() |
| 643 | print([[Loading registry information for ".rockspec" files]]) | 697 | print([[Loading registry information for ".rockspec" files]]) |
| 644 | exec( S[[lua5.1\bin\lua5.1.exe "$FULL_PREFIX\LuaRocks.reg.lua" "$FULL_PREFIX\LuaRocks.reg.template"]] ) | 698 | exec( S[[lua5.1\bin\lua5.1.exe "$FULL_PREFIX\LuaRocks.reg.lua" "$FULL_PREFIX\LuaRocks.reg.template"]] ) |
| 645 | exec( S"$FULL_PREFIX\\LuaRocks.reg" ) | 699 | exec( S[["$FULL_PREFIX\\LuaRocks.reg"]] ) |
| 646 | end | 700 | end |
| 647 | 701 | ||
| 648 | -- *********************************************************** | 702 | -- *********************************************************** |
