diff options
-rw-r--r-- | install.bat | 241 |
1 files changed, 126 insertions, 115 deletions
diff --git a/install.bat b/install.bat index cc4a5257..e28734dc 100644 --- a/install.bat +++ b/install.bat | |||
@@ -42,6 +42,8 @@ local NOADMIN = false | |||
42 | local PROMPT = true | 42 | local PROMPT = true |
43 | local SELFCONTAINED = false | 43 | local SELFCONTAINED = false |
44 | 44 | ||
45 | local lua_version_set = false | ||
46 | |||
45 | --- | 47 | --- |
46 | -- Some helpers | 48 | -- Some helpers |
47 | -- | 49 | -- |
@@ -149,7 +151,7 @@ Configuring the destinations: | |||
149 | 151 | ||
150 | Configuring the Lua interpreter: | 152 | Configuring the Lua interpreter: |
151 | /LV [version] Lua version to use; either 5.1, 5.2, or 5.3. | 153 | /LV [version] Lua version to use; either 5.1, 5.2, or 5.3. |
152 | Default is 5.1 | 154 | Default is auto-detected. |
153 | /LUA [dir] Location where Lua is installed - e.g. c:\lua\5.1\ | 155 | /LUA [dir] Location where Lua is installed - e.g. c:\lua\5.1\ |
154 | If not provided, the installer will search the system | 156 | If not provided, the installer will search the system |
155 | path and some default locations for a valid Lua | 157 | path and some default locations for a valid Lua |
@@ -220,6 +222,7 @@ local function parse_options(args) | |||
220 | vars.TREE_CMODULE = option.value | 222 | vars.TREE_CMODULE = option.value |
221 | elseif name == "/LV" then | 223 | elseif name == "/LV" then |
222 | vars.LUA_VERSION = option.value | 224 | vars.LUA_VERSION = option.value |
225 | lua_version_set = true | ||
223 | elseif name == "/L" then | 226 | elseif name == "/L" then |
224 | INSTALL_LUA = true | 227 | INSTALL_LUA = true |
225 | elseif name == "/MW" then | 228 | elseif name == "/MW" then |
@@ -287,111 +290,127 @@ end | |||
287 | -- *********************************************************** | 290 | -- *********************************************************** |
288 | -- Detect Lua | 291 | -- Detect Lua |
289 | -- *********************************************************** | 292 | -- *********************************************************** |
290 | local function look_for_interpreter (directory) | 293 | local function detect_lua_version(interpreter_path) |
291 | if vars.LUA_BINDIR then | 294 | 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 | 295 | if not handler then |
293 | if exists( S"$LUA_BINDIR\\lua$LUA_VERSION.exe" ) then | 296 | 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 | 297 | end |
298 | local full_version = handler:read("*a") | ||
299 | handler:close() | ||
312 | 300 | ||
313 | for _, e in ipairs{ [[\]], [[\bin\]] } do | 301 | local version = full_version:match("^Lua (5%.[123])$") |
314 | if exists(directory..e.."\\lua"..vars.LUA_VERSION..".exe") then | 302 | if not version then |
315 | vars.LUA_INTERPRETER = S"lua$LUA_VERSION.exe" | 303 | return nil, "unknown interpreter version '" .. full_version .. "'" |
316 | vars.LUA_BINDIR = directory .. e | 304 | end |
317 | print(" Found ."..e..vars.LUA_INTERPRETER) | 305 | return version |
318 | return true | 306 | end |
319 | 307 | ||
320 | elseif exists(directory..e.."\\lua"..vars.LUA_SHORTV..".exe") then | 308 | local function look_for_interpreter(directory) |
321 | vars.LUA_INTERPRETER = S"lua$LUA_SHORTV.exe" | 309 | local names |
322 | vars.LUA_BINDIR = directory .. e | 310 | if lua_version_set then |
323 | print(" Found ."..e..vars.LUA_INTERPRETER) | 311 | names = {S"lua$LUA_VERSION.exe", S"lua$LUA_SHORTV.exe"} |
324 | return true | 312 | else |
313 | names = {"lua5.3.exe", "lua53.exe", "lua5.2.exe", "lua52.exe", "lua5.1.exe", "lua51.exe"} | ||
314 | end | ||
315 | table.insert(names, "lua.exe") | ||
316 | table.insert(names, "luajit.exe") | ||
325 | 317 | ||
326 | elseif exists(directory..e.."\\lua.exe") then | 318 | local directories |
327 | vars.LUA_INTERPRETER = "lua.exe" | 319 | if vars.LUA_BINDIR then |
328 | vars.LUA_BINDIR = directory..e | 320 | -- If LUA_BINDIR is specified, look only in that directory. |
329 | print(" Found ."..e..vars.LUA_INTERPRETER) | 321 | directories = {vars.LUA_BINDIR} |
330 | return true | 322 | else |
323 | -- Try candidate directory and its `bin` subdirectory. | ||
324 | directories = {directory, directory .. "\\bin"} | ||
325 | end | ||
331 | 326 | ||
332 | elseif exists(directory..e.."\\luajit.exe") then | 327 | for _, dir in ipairs(directories) do |
333 | vars.LUA_INTERPRETER = "luajit.exe" | 328 | for _, name in ipairs(names) do |
334 | vars.LUA_BINDIR = directory..e | 329 | local full_name = dir .. "\\" .. name |
335 | print(" Found ."..e..vars.LUA_INTERPRETER) | 330 | if exists(full_name) then |
336 | return true | 331 | print(" Found " .. name .. ", testing it...") |
332 | local version, err = detect_lua_version(full_name) | ||
333 | if not version then | ||
334 | print(" Error: " .. err) | ||
335 | else | ||
336 | if version ~= vars.LUA_VERSION then | ||
337 | if lua_version_set then | ||
338 | die("Version of interpreter clashes with the value of /LV. Please check your configuration.") | ||
339 | else | ||
340 | vars.LUA_VERSION = version | ||
341 | vars.LUA_SHORTV = version:gsub("%.", "") | ||
342 | vars.LUA_LIB_NAMES = vars.LUA_LIB_NAMES:gsub("5([%.]?)[123]", "5%1" .. version:sub(-1)) | ||
343 | end | ||
344 | end | ||
345 | |||
346 | vars.LUA_INTERPRETER = name | ||
347 | vars.LUA_BINDIR = dir | ||
348 | return true | ||
349 | end | ||
350 | end | ||
337 | end | 351 | end |
338 | end | 352 | end |
339 | --print(" No Lua interpreter found") | 353 | |
354 | if vars.LUA_BINDIR then | ||
355 | die(("Working Lua executable (one of %s) not found in %s"):format(table.concat(names, ", "), vars.LUA_BINDIR)) | ||
356 | end | ||
340 | return false | 357 | return false |
341 | end | 358 | end |
342 | 359 | ||
343 | local function look_for_link_libraries (directory) | 360 | local function look_for_link_libraries(directory) |
361 | local directories | ||
344 | if vars.LUA_LIBDIR then | 362 | if vars.LUA_LIBDIR then |
345 | for name in vars.LUA_LIB_NAMES:gmatch("[^%s]+") do | 363 | directories = {vars.LUA_LIBDIR} |
346 | print(S" checking for $LUA_LIBDIR\\"..name) | 364 | else |
347 | if exists(vars.LUA_LIBDIR.."\\"..name) then | 365 | 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 | 366 | end |
355 | 367 | ||
356 | for _, e in ipairs{ [[\]], [[\lib\]], [[\bin\]]} do | 368 | for _, dir in ipairs(directories) do |
357 | for name in vars.LUA_LIB_NAMES:gmatch("[^%s]+") do | 369 | for name in vars.LUA_LIB_NAMES:gmatch("[^%s]+") do |
358 | print(" checking for "..directory..e.."\\"..name) | 370 | local full_name = dir .. "\\" .. name |
359 | if exists(directory..e.."\\"..name) then | 371 | print(" checking for " .. full_name) |
360 | vars.LUA_LIBDIR = directory .. e | 372 | if exists(full_name) then |
373 | vars.LUA_LIBDIR = dir | ||
361 | vars.LUA_LIBNAME = name | 374 | vars.LUA_LIBNAME = name |
362 | print(" Found "..name) | 375 | print(" Found " .. name) |
363 | return true | 376 | return true |
364 | end | 377 | end |
365 | end | 378 | end |
366 | end | 379 | end |
380 | |||
381 | if vars.LUA_LIBDIR then | ||
382 | die(S"link library (one of; $LUA_LIB_NAMES) not found in $LUA_LIBDIR") | ||
383 | end | ||
367 | return false | 384 | return false |
368 | end | 385 | end |
369 | 386 | ||
370 | local function look_for_headers (directory) | 387 | local function look_for_headers(directory) |
388 | local directories | ||
371 | if vars.LUA_INCDIR then | 389 | if vars.LUA_INCDIR then |
372 | print(S" checking for $LUA_INCDIR\\lua.h") | 390 | directories = {vars.LUA_INCDIR} |
373 | if exists(S"$LUA_INCDIR\\lua.h") then | 391 | else |
374 | print(" Found lua.h") | 392 | directories = { |
375 | return true | 393 | directory .. S"\\include\\lua\\$LUA_VERSION", |
376 | end | 394 | directory .. S"\\include\\lua$LUA_SHORTV", |
377 | die(S"lua.h not found in $LUA_INCDIR") | 395 | directory .. S"\\include\\lua$LUA_VERSION", |
396 | directory .. "\\include", | ||
397 | directory | ||
398 | } | ||
378 | end | 399 | end |
379 | 400 | ||
380 | for _, e in ipairs{ | 401 | for _, dir in ipairs(directories) do |
381 | S([[\include\lua\$LUA_VERSION]]), | 402 | local full_name = dir .. "\\lua.h" |
382 | S([[\include\lua$LUA_SHORTV]]), | 403 | print(" checking for " .. full_name) |
383 | S([[\include\lua$LUA_VERSION]]), | 404 | if exists(full_name) then |
384 | S([[\include\$LUA_VERSION]]), | 405 | 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") | 406 | print(" Found lua.h") |
392 | return true | 407 | return true |
393 | end | 408 | end |
394 | end | 409 | end |
410 | |||
411 | if vars.LUA_INCDIR then | ||
412 | die(S"lua.h not found in $LUA_INCDIR") | ||
413 | end | ||
395 | return false | 414 | return false |
396 | end | 415 | end |
397 | 416 | ||
@@ -548,51 +567,47 @@ local function get_msvc_env_setup_cmd() | |||
548 | return "" | 567 | return "" |
549 | end | 568 | end |
550 | 569 | ||
551 | local function look_for_lua_install () | 570 | local function get_possible_lua_directories() |
552 | print("Looking for Lua interpreter") | ||
553 | local directories | ||
554 | if vars.LUA_PREFIX then | 571 | if vars.LUA_PREFIX then |
555 | directories = { vars.LUA_PREFIX } | 572 | return {vars.LUA_PREFIX} |
556 | else | 573 | end |
557 | -- no prefix given, so use path | 574 | |
558 | directories = (os.getenv("PATH",";") or "") | 575 | -- No prefix given, so use PATH. |
559 | directories = directories:gsub(";+", ";") --remove all doubles | 576 | local path = os.getenv("PATH") or "" |
560 | directories = split_string(directories,";") | 577 | path = path:gsub(";+", ";") -- Remove duplicates. |
561 | -- if a path element ends with "\bin\" then remove it, as the searcher will check there anyway | 578 | local directories = split_string(path, ";") |
562 | for i, val in ipairs(directories) do | 579 | for i, dir in ipairs(directories) do |
563 | -- remove trailing backslash | 580 | -- Remove trailing backslashes, but not from a drive letter like `C:\`. |
564 | while val:sub(-1,-1) == "\\" and val:sub(-2,-1) ~= ":\\" do | 581 | dir = dir:gsub("([^:])\\+$", "%1") |
565 | val = val:sub(1,-2) | 582 | -- Remove trailing `bin` subdirectory, the searcher will check there anyway. |
566 | end | 583 | if dir:upper():match("[:\\]BIN$") then |
567 | -- remove trailing 'bin' | 584 | dir = dir:sub(1, -5) |
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 | 585 | end |
573 | -- finaly add some other default paths | 586 | directories[i] = 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 | 587 | end |
588 | -- Finally add some other default paths. | ||
589 | table.insert(directories, [[c:\lua5.1.2]]) | ||
590 | table.insert(directories, [[c:\lua]]) | ||
591 | table.insert(directories, [[c:\kepler\1.1]]) | ||
592 | return directories | ||
593 | end | ||
594 | |||
595 | local function look_for_lua_install () | ||
596 | print("Looking for Lua interpreter") | ||
578 | if vars.LUA_BINDIR and vars.LUA_LIBDIR and vars.LUA_INCDIR then | 597 | if vars.LUA_BINDIR and vars.LUA_LIBDIR and vars.LUA_INCDIR then |
579 | if look_for_interpreter(vars.LUA_BINDIR) and | 598 | if look_for_interpreter(vars.LUA_BINDIR) and |
580 | look_for_link_libraries(vars.LUA_LIBDIR) and | 599 | look_for_link_libraries(vars.LUA_LIBDIR) and |
581 | look_for_headers(vars.LUA_INCDIR) | 600 | look_for_headers(vars.LUA_INCDIR) |
582 | then | 601 | then |
583 | if get_runtime() then | 602 | if get_runtime() then |
584 | print("Runtime check completed, now testing interpreter...") | 603 | print("Runtime check completed.") |
585 | if exec(S[["$LUA_BINDIR\$LUA_INTERPRETER" -v 2>NUL]]) then | 604 | return true |
586 | print(" Ok") | ||
587 | return true | ||
588 | end | ||
589 | print(" Interpreter returned an error, not ok") | ||
590 | end | 605 | end |
591 | end | 606 | end |
592 | return false | 607 | return false |
593 | end | 608 | end |
594 | 609 | ||
595 | for _, directory in ipairs(directories) do | 610 | for _, directory in ipairs(get_possible_lua_directories()) do |
596 | print(" checking " .. directory) | 611 | print(" checking " .. directory) |
597 | if exists(directory) then | 612 | if exists(directory) then |
598 | if look_for_interpreter(directory) then | 613 | if look_for_interpreter(directory) then |
@@ -602,12 +617,8 @@ local function look_for_lua_install () | |||
602 | if look_for_headers(directory) then | 617 | if look_for_headers(directory) then |
603 | print("Headers found, checking runtime to use...") | 618 | print("Headers found, checking runtime to use...") |
604 | if get_runtime() then | 619 | if get_runtime() then |
605 | print("Runtime check completed, now testing interpreter...") | 620 | print("Runtime check completed.") |
606 | if exec(S[["$LUA_BINDIR\$LUA_INTERPRETER" -v 2>NUL]]) then | 621 | return true |
607 | print(" Ok") | ||
608 | return true | ||
609 | end | ||
610 | print(" Interpreter returned an error, not ok") | ||
611 | end | 622 | end |
612 | end | 623 | end |
613 | end | 624 | end |