aboutsummaryrefslogtreecommitdiff
path: root/install.bat
diff options
context:
space:
mode:
authorHisham <hisham@gobolinux.org>2016-10-14 16:38:51 -0700
committerHisham <hisham@gobolinux.org>2016-10-14 16:38:51 -0700
commit075196e8b5d315888a8ae110fa9a18089044ae3b (patch)
treeeca3eb78c23f8d85dbe625564a2d66966d6281f1 /install.bat
parentdbca97cdcc15e386554b2631a0ae7aca02500abf (diff)
parent1fea0e3a0972bcc6b4319cd3d9e79834562486bc (diff)
downloadluarocks-075196e8b5d315888a8ae110fa9a18089044ae3b.tar.gz
luarocks-075196e8b5d315888a8ae110fa9a18089044ae3b.tar.bz2
luarocks-075196e8b5d315888a8ae110fa9a18089044ae3b.zip
Merge branch 'master' into luarocks-3
Diffstat (limited to 'install.bat')
-rw-r--r--install.bat290
1 files changed, 132 insertions, 158 deletions
diff --git a/install.bat b/install.bat
index 3deb3d14..7c0f8b73 100644
--- a/install.bat
+++ b/install.bat
@@ -24,10 +24,6 @@ vars.LUA_LIBDIR = nil
24vars.LUA_LIBNAME = nil 24vars.LUA_LIBNAME = nil
25vars.LUA_VERSION = "5.1" 25vars.LUA_VERSION = "5.1"
26vars.LUA_SHORTV = nil -- "51" 26vars.LUA_SHORTV = nil -- "51"
27-- MinGW does not generate .lib, nor needs it to link, but MSVC does
28-- so .lib must be listed first to ensure they are found first if present.
29-- To prevent MSVC trying to link to a .dll, which won't work.
30vars.LUA_LIB_NAMES = "lua5.1.lib lua51.lib lua5.1.dll lua51.dll liblua.dll.a"
31vars.LUA_RUNTIME = nil 27vars.LUA_RUNTIME = nil
32vars.UNAME_M = nil 28vars.UNAME_M = nil
33vars.COMPILER_ENV_CMD = nil 29vars.COMPILER_ENV_CMD = nil
@@ -42,6 +38,8 @@ local NOADMIN = false
42local PROMPT = true 38local PROMPT = true
43local SELFCONTAINED = false 39local SELFCONTAINED = false
44 40
41local lua_version_set = false
42
45--- 43---
46-- Some helpers 44-- Some helpers
47-- 45--
@@ -55,32 +53,6 @@ local function die(message)
55 os.exit(1) 53 os.exit(1)
56end 54end
57 55
58local function split_string(str, delim, maxNb)
59 -- Eliminate bad cases...
60 if string.find(str, delim) == nil then
61 return { str }
62 end
63 if maxNb == nil or maxNb < 1 then
64 maxNb = 0 -- No limit
65 end
66 local result = {}
67 local pat = "(.-)" .. delim .. "()"
68 local nb = 0
69 local lastPos
70 for part, pos in string.gmatch(str, pat) do
71 nb = nb + 1
72 result[nb] = part
73 lastPos = pos
74 if nb == maxNb then break end
75 end
76 -- Handle the last field
77 if nb ~= maxNb then
78 result[nb + 1] = string.sub(str, lastPos)
79 end
80 return result
81end
82
83
84local function exec(cmd) 56local function exec(cmd)
85 --print(cmd) 57 --print(cmd)
86 local status = os.execute("type NUL && "..cmd) 58 local status = os.execute("type NUL && "..cmd)
@@ -149,7 +121,7 @@ Configuring the destinations:
149 121
150Configuring the Lua interpreter: 122Configuring the Lua interpreter:
151/LV [version] Lua version to use; either 5.1, 5.2, or 5.3. 123/LV [version] Lua version to use; either 5.1, 5.2, or 5.3.
152 Default is 5.1 124 Default is auto-detected.
153/LUA [dir] Location where Lua is installed - e.g. c:\lua\5.1\ 125/LUA [dir] Location where Lua is installed - e.g. c:\lua\5.1\
154 If not provided, the installer will search the system 126 If not provided, the installer will search the system
155 path and some default locations for a valid Lua 127 path and some default locations for a valid Lua
@@ -220,6 +192,7 @@ local function parse_options(args)
220 vars.TREE_CMODULE = option.value 192 vars.TREE_CMODULE = option.value
221 elseif name == "/LV" then 193 elseif name == "/LV" then
222 vars.LUA_VERSION = option.value 194 vars.LUA_VERSION = option.value
195 lua_version_set = true
223 elseif name == "/L" then 196 elseif name == "/L" then
224 INSTALL_LUA = true 197 INSTALL_LUA = true
225 elseif name == "/MW" then 198 elseif name == "/MW" then
@@ -270,14 +243,8 @@ local function check_flags()
270 die("Bundled Lua version is 5.1, cannot install "..vars.LUA_VERSION) 243 die("Bundled Lua version is 5.1, cannot install "..vars.LUA_VERSION)
271 end 244 end
272 end 245 end
273 if vars.LUA_VERSION ~= "5.1" then 246 if not vars.LUA_VERSION:match("^5%.[123]$") then
274 if vars.LUA_VERSION == "5.2" then 247 die("Bad argument: /LV must either be 5.1, 5.2, or 5.3")
275 vars.LUA_LIB_NAMES = vars.LUA_LIB_NAMES:gsub("5([%.]?)1", "5%12")
276 elseif vars.LUA_VERSION == "5.3" then
277 vars.LUA_LIB_NAMES = vars.LUA_LIB_NAMES:gsub("5([%.]?)1", "5%13")
278 else
279 die("Bad argument: /LV must either be 5.1, 5.2, or 5.3")
280 end
281 end 248 end
282 if USE_MSVC_MANUAL and USE_MINGW then 249 if USE_MSVC_MANUAL and USE_MINGW then
283 die("Cannot combine option /MSVC and /MW") 250 die("Cannot combine option /MSVC and /MW")
@@ -287,111 +254,130 @@ end
287-- *********************************************************** 254-- ***********************************************************
288-- Detect Lua 255-- Detect Lua
289-- *********************************************************** 256-- ***********************************************************
290local function look_for_interpreter (directory) 257local function detect_lua_version(interpreter_path)
291 if vars.LUA_BINDIR then 258 local handler = io.popen(('type NUL && "%s" -e "io.stdout:write(_VERSION)" 2>NUL'):format(interpreter_path), "r")
292 -- if LUA_BINDIR is specified, it must be there, otherwise we fail 259 if not handler then
293 if exists( S"$LUA_BINDIR\\lua$LUA_VERSION.exe" ) then 260 return nil, "interpreter does not work"
294 vars.LUA_INTERPRETER = S"lua$LUA_VERSION.exe"
295 print(S" Found $LUA_BINDIR\\$LUA_INTERPRETER")
296 return true
297 elseif exists( S"$LUA_BINDIR\\lua$LUA_SHORTV.exe" ) then
298 vars.LUA_INTERPRETER = S"lua$LUA_SHORTV.exe"
299 print(S" Found $LUA_BINDIR\\$LUA_INTERPRETER")
300 return true
301 elseif exists(S"$LUA_BINDIR\\lua.exe") then
302 vars.LUA_INTERPRETER = "lua.exe"
303 print(S" Found $LUA_BINDIR\\$LUA_INTERPRETER")
304 return true
305 elseif exists(S"$LUA_BINDIR\\luajit.exe") then
306 vars.LUA_INTERPRETER = "luajit.exe"
307 print(S" Found $LUA_BINDIR\\$LUA_INTERPRETER")
308 return true
309 end
310 die(S"Lua executable lua.exe, luajit.exe, lua$LUA_SHORTV.exe or lua$LUA_VERSION.exe not found in $LUA_BINDIR")
311 end 261 end
262 local full_version = handler:read("*a")
263 handler:close()
312 264
313 for _, e in ipairs{ [[\]], [[\bin\]] } do 265 local version = full_version:match("^Lua (5%.[123])$")
314 if exists(directory..e.."\\lua"..vars.LUA_VERSION..".exe") then 266 if not version then
315 vars.LUA_INTERPRETER = S"lua$LUA_VERSION.exe" 267 return nil, "unknown interpreter version '" .. full_version .. "'"
316 vars.LUA_BINDIR = directory .. e 268 end
317 print(" Found ."..e..vars.LUA_INTERPRETER) 269 return version
318 return true 270end
319 271
320 elseif exists(directory..e.."\\lua"..vars.LUA_SHORTV..".exe") then 272local function look_for_interpreter(directory)
321 vars.LUA_INTERPRETER = S"lua$LUA_SHORTV.exe" 273 local names
322 vars.LUA_BINDIR = directory .. e 274 if lua_version_set then
323 print(" Found ."..e..vars.LUA_INTERPRETER) 275 names = {S"lua$LUA_VERSION.exe", S"lua$LUA_SHORTV.exe"}
324 return true 276 else
277 names = {"lua5.3.exe", "lua53.exe", "lua5.2.exe", "lua52.exe", "lua5.1.exe", "lua51.exe"}
278 end
279 table.insert(names, "lua.exe")
280 table.insert(names, "luajit.exe")
325 281
326 elseif exists(directory..e.."\\lua.exe") then 282 local directories
327 vars.LUA_INTERPRETER = "lua.exe" 283 if vars.LUA_BINDIR then
328 vars.LUA_BINDIR = directory..e 284 -- If LUA_BINDIR is specified, look only in that directory.
329 print(" Found ."..e..vars.LUA_INTERPRETER) 285 directories = {vars.LUA_BINDIR}
330 return true 286 else
287 -- Try candidate directory and its `bin` subdirectory.
288 directories = {directory, directory .. "\\bin"}
289 end
331 290
332 elseif exists(directory..e.."\\luajit.exe") then 291 for _, dir in ipairs(directories) do
333 vars.LUA_INTERPRETER = "luajit.exe" 292 for _, name in ipairs(names) do
334 vars.LUA_BINDIR = directory..e 293 local full_name = dir .. "\\" .. name
335 print(" Found ."..e..vars.LUA_INTERPRETER) 294 if exists(full_name) then
336 return true 295 print(" Found " .. name .. ", testing it...")
296 local version, err = detect_lua_version(full_name)
297 if not version then
298 print(" Error: " .. err)
299 else
300 if version ~= vars.LUA_VERSION then
301 if lua_version_set then
302 die("Version of interpreter clashes with the value of /LV. Please check your configuration.")
303 else
304 vars.LUA_VERSION = version
305 vars.LUA_SHORTV = version:gsub("%.", "")
306 end
307 end
308
309 vars.LUA_INTERPRETER = name
310 vars.LUA_BINDIR = dir
311 return true
312 end
313 end
337 end 314 end
338 end 315 end
339 --print(" No Lua interpreter found") 316
317 if vars.LUA_BINDIR then
318 die(("Working Lua executable (one of %s) not found in %s"):format(table.concat(names, ", "), vars.LUA_BINDIR))
319 end
340 return false 320 return false
341end 321end
342 322
343local function look_for_link_libraries (directory) 323local function look_for_link_libraries(directory)
324 -- MinGW does not generate .lib, nor needs it to link, but MSVC does,
325 -- so .lib must be listed first to ensure they are found first if present,
326 -- to prevent MSVC trying to link to a .dll, which won't work.
327 local names = {S"lua$LUA_VERSION.lib", S"lua$LUA_SHORTV.lib", S"lua$LUA_VERSION.dll", S"lua$LUA_SHORTV.dll", "liblua.dll.a"}
328 local directories
344 if vars.LUA_LIBDIR then 329 if vars.LUA_LIBDIR then
345 for name in vars.LUA_LIB_NAMES:gmatch("[^%s]+") do 330 directories = {vars.LUA_LIBDIR}
346 print(S" checking for $LUA_LIBDIR\\"..name) 331 else
347 if exists(vars.LUA_LIBDIR.."\\"..name) then 332 directories = {directory, directory .. "\\lib", directory .. "\\bin"}
348 vars.LUA_LIBNAME = name
349 print(" Found "..name)
350 return true
351 end
352 end
353 die(S"link library (one of; $LUA_LIB_NAMES) not found in $LUA_LIBDIR")
354 end 333 end
355 334
356 for _, e in ipairs{ [[\]], [[\lib\]], [[\bin\]]} do 335 for _, dir in ipairs(directories) do
357 for name in vars.LUA_LIB_NAMES:gmatch("[^%s]+") do 336 for _, name in ipairs(names) do
358 print(" checking for "..directory..e.."\\"..name) 337 local full_name = dir .. "\\" .. name
359 if exists(directory..e.."\\"..name) then 338 print(" checking for " .. full_name)
360 vars.LUA_LIBDIR = directory .. e 339 if exists(full_name) then
340 vars.LUA_LIBDIR = dir
361 vars.LUA_LIBNAME = name 341 vars.LUA_LIBNAME = name
362 print(" Found "..name) 342 print(" Found " .. name)
363 return true 343 return true
364 end 344 end
365 end 345 end
366 end 346 end
347
348 if vars.LUA_LIBDIR then
349 die(("Link library (one of %s) not found in %s"):format(table.concat(names, ", "), vars.LUA_LIBDIR))
350 end
367 return false 351 return false
368end 352end
369 353
370local function look_for_headers (directory) 354local function look_for_headers(directory)
355 local directories
371 if vars.LUA_INCDIR then 356 if vars.LUA_INCDIR then
372 print(S" checking for $LUA_INCDIR\\lua.h") 357 directories = {vars.LUA_INCDIR}
373 if exists(S"$LUA_INCDIR\\lua.h") then 358 else
374 print(" Found lua.h") 359 directories = {
375 return true 360 directory .. S"\\include\\lua\\$LUA_VERSION",
376 end 361 directory .. S"\\include\\lua$LUA_SHORTV",
377 die(S"lua.h not found in $LUA_INCDIR") 362 directory .. S"\\include\\lua$LUA_VERSION",
363 directory .. "\\include",
364 directory
365 }
378 end 366 end
379 367
380 for _, e in ipairs{ 368 for _, dir in ipairs(directories) do
381 S([[\include\lua\$LUA_VERSION]]), 369 local full_name = dir .. "\\lua.h"
382 S([[\include\lua$LUA_SHORTV]]), 370 print(" checking for " .. full_name)
383 S([[\include\lua$LUA_VERSION]]), 371 if exists(full_name) then
384 S([[\include\$LUA_VERSION]]), 372 vars.LUA_INCDIR = dir
385 [[\include\]],
386 [[\]],
387 } do
388 print(" checking for "..directory..e.."\\lua.h")
389 if exists(directory..e.."\\lua.h") then
390 vars.LUA_INCDIR = directory..e
391 print(" Found lua.h") 373 print(" Found lua.h")
392 return true 374 return true
393 end 375 end
394 end 376 end
377
378 if vars.LUA_INCDIR then
379 die(S"lua.h not found in $LUA_INCDIR")
380 end
395 return false 381 return false
396end 382end
397 383
@@ -548,51 +534,46 @@ local function get_msvc_env_setup_cmd()
548 return "" 534 return ""
549end 535end
550 536
551local function look_for_lua_install () 537local function get_possible_lua_directories()
552 print("Looking for Lua interpreter")
553 local directories
554 if vars.LUA_PREFIX then 538 if vars.LUA_PREFIX then
555 directories = { vars.LUA_PREFIX } 539 return {vars.LUA_PREFIX}
556 else 540 end
557 -- no prefix given, so use path 541
558 directories = (os.getenv("PATH",";") or "") 542 -- No prefix given, so use PATH.
559 directories = directories:gsub(";+", ";") --remove all doubles 543 local path = os.getenv("PATH") or ""
560 directories = split_string(directories,";") 544 local directories = {}
561 -- if a path element ends with "\bin\" then remove it, as the searcher will check there anyway 545 for dir in path:gmatch("[^;]+") do
562 for i, val in ipairs(directories) do 546 -- Remove trailing backslashes, but not from a drive letter like `C:\`.
563 -- remove trailing backslash 547 dir = dir:gsub("([^:])\\+$", "%1")
564 while val:sub(-1,-1) == "\\" and val:sub(-2,-1) ~= ":\\" do 548 -- Remove trailing `bin` subdirectory, the searcher will check there anyway.
565 val = val:sub(1,-2) 549 if dir:upper():match("[:\\]BIN$") then
566 end 550 dir = dir:sub(1, -5)
567 -- remove trailing 'bin'
568 if val:upper():sub(-4,-1) == "\\BIN" or val:upper():sub(-4,-1) == ":BIN" then
569 val = val:sub(1,-5)
570 end
571 directories[i] = val
572 end 551 end
573 -- finaly add some other default paths 552 table.insert(directories, dir)
574 table.insert(directories, [[c:\lua5.1.2]])
575 table.insert(directories, [[c:\lua]])
576 table.insert(directories, [[c:\kepler\1.1]])
577 end 553 end
554 -- Finally add some other default paths.
555 table.insert(directories, [[c:\lua5.1.2]])
556 table.insert(directories, [[c:\lua]])
557 table.insert(directories, [[c:\kepler\1.1]])
558 return directories
559end
560
561local function look_for_lua_install ()
562 print("Looking for Lua interpreter")
578 if vars.LUA_BINDIR and vars.LUA_LIBDIR and vars.LUA_INCDIR then 563 if vars.LUA_BINDIR and vars.LUA_LIBDIR and vars.LUA_INCDIR then
579 if look_for_interpreter(vars.LUA_BINDIR) and 564 if look_for_interpreter(vars.LUA_BINDIR) and
580 look_for_link_libraries(vars.LUA_LIBDIR) and 565 look_for_link_libraries(vars.LUA_LIBDIR) and
581 look_for_headers(vars.LUA_INCDIR) 566 look_for_headers(vars.LUA_INCDIR)
582 then 567 then
583 if get_runtime() then 568 if get_runtime() then
584 print("Runtime check completed, now testing interpreter...") 569 print("Runtime check completed.")
585 if exec(S[["$LUA_BINDIR\$LUA_INTERPRETER" -v 2>NUL]]) then 570 return true
586 print(" Ok")
587 return true
588 end
589 print(" Interpreter returned an error, not ok")
590 end 571 end
591 end 572 end
592 return false 573 return false
593 end 574 end
594 575
595 for _, directory in ipairs(directories) do 576 for _, directory in ipairs(get_possible_lua_directories()) do
596 print(" checking " .. directory) 577 print(" checking " .. directory)
597 if exists(directory) then 578 if exists(directory) then
598 if look_for_interpreter(directory) then 579 if look_for_interpreter(directory) then
@@ -602,12 +583,8 @@ local function look_for_lua_install ()
602 if look_for_headers(directory) then 583 if look_for_headers(directory) then
603 print("Headers found, checking runtime to use...") 584 print("Headers found, checking runtime to use...")
604 if get_runtime() then 585 if get_runtime() then
605 print("Runtime check completed, now testing interpreter...") 586 print("Runtime check completed.")
606 if exec(S[["$LUA_BINDIR\$LUA_INTERPRETER" -v 2>NUL]]) then 587 return true
607 print(" Ok")
608 return true
609 end
610 print(" Interpreter returned an error, not ok")
611 end 588 end
612 end 589 end
613 end 590 end
@@ -752,9 +729,6 @@ vars.INCDIR = S"$PREFIX\\include"
752vars.LUA_SHORTV = vars.LUA_VERSION:gsub("%.", "") 729vars.LUA_SHORTV = vars.LUA_VERSION:gsub("%.", "")
753 730
754if INSTALL_LUA then 731if INSTALL_LUA then
755 if vars.LUA_VERSION ~= "5.1" then
756 die("Cannot install own copy of Lua because only 5.1 is bundled")
757 end
758 vars.LUA_INTERPRETER = "lua5.1" 732 vars.LUA_INTERPRETER = "lua5.1"
759 vars.LUA_BINDIR = vars.BINDIR 733 vars.LUA_BINDIR = vars.BINDIR
760 vars.LUA_LIBDIR = vars.LIBDIR 734 vars.LUA_LIBDIR = vars.LIBDIR
@@ -993,7 +967,7 @@ if FORCE_CONFIG then
993 f:write("site_config.LUAROCKS_FORCE_CONFIG=true\n") 967 f:write("site_config.LUAROCKS_FORCE_CONFIG=true\n")
994end 968end
995if vars.SYSCONFFORCE then -- only write this value when explcitly given, otherwise rely on defaults 969if vars.SYSCONFFORCE then -- only write this value when explcitly given, otherwise rely on defaults
996 f:write(S("site_config.LUAROCKS_SYSCONFIG=[[$CONFIG_FILE]]\n")) 970 f:write(S("site_config.LUAROCKS_SYSCONFDIR=[[$SYSCONFDIR]]\n"))
997end 971end
998f:write("return site_config\n") 972f:write("return site_config\n")
999f:close() 973f:close()