diff options
author | Thijs Schreijer <thijs@thijsschreijer.nl> | 2018-01-09 18:48:42 +0100 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-03-12 21:03:50 -0300 |
commit | db49037aff80f7bc4cec25fdecd642c49ff63252 (patch) | |
tree | 41555da54ef693a935fc2e4522e445852160ca4e | |
parent | 0409a52f478849fb47d1793ed5a85853460d863e (diff) | |
download | luarocks-db49037aff80f7bc4cec25fdecd642c49ff63252.tar.gz luarocks-db49037aff80f7bc4cec25fdecd642c49ff63252.tar.bz2 luarocks-db49037aff80f7bc4cec25fdecd642c49ff63252.zip |
Update Windows installer to better handle gcc toolchains (#759)
Update the Windows installer to better handle gcc toolchain in different environments
-rw-r--r-- | install.bat | 92 |
1 files changed, 89 insertions, 3 deletions
diff --git a/install.bat b/install.bat index 07264ab2..56c7b831 100644 --- a/install.bat +++ b/install.bat | |||
@@ -27,6 +27,13 @@ vars.LUA_SHORTV = nil -- "51" | |||
27 | vars.LUA_RUNTIME = nil | 27 | vars.LUA_RUNTIME = nil |
28 | vars.UNAME_M = nil | 28 | vars.UNAME_M = nil |
29 | vars.COMPILER_ENV_CMD = nil | 29 | vars.COMPILER_ENV_CMD = nil |
30 | vars.MINGW_BIN_PATH = nil | ||
31 | vars.MINGW_CC = nil | ||
32 | vars.MINGW_MAKE = nil | ||
33 | vars.MINGW_RC = nil | ||
34 | vars.MINGW_LD = nil | ||
35 | vars.MINGW_AR = nil | ||
36 | vars.MINGW_RANLIB = nil | ||
30 | 37 | ||
31 | local FORCE = false | 38 | local FORCE = false |
32 | local FORCE_CONFIG = false | 39 | local FORCE_CONFIG = false |
@@ -617,6 +624,66 @@ local function restore_config_files() | |||
617 | vars.CONFBACKUPDIR = nil | 624 | vars.CONFBACKUPDIR = nil |
618 | end | 625 | end |
619 | 626 | ||
627 | -- Find GCC based toolchain | ||
628 | local find_gcc_suite = function() | ||
629 | |||
630 | -- read output os-command | ||
631 | local read_output = function(cmd) | ||
632 | local f = io.popen("type NUL && " .. cmd .. ' 2>NUL') | ||
633 | if not f then return nil, "failed to open command: " .. tostring(cmd) end | ||
634 | local lines = {} | ||
635 | while true do | ||
636 | local l = f:read() | ||
637 | if not l then | ||
638 | f:close() | ||
639 | return lines | ||
640 | end | ||
641 | table.insert(lines, l) | ||
642 | end | ||
643 | end | ||
644 | |||
645 | -- returns: full filename, path, filename | ||
646 | local find_file = function(mask, path) | ||
647 | local cmd | ||
648 | if path then | ||
649 | cmd = 'where.exe /R "' .. path .. '" ' .. mask | ||
650 | else | ||
651 | cmd = 'where.exe ' .. mask | ||
652 | end | ||
653 | local files, err = read_output(cmd) | ||
654 | if not files or not files[1] then | ||
655 | return nil, "couldn't find '".. mask .. "', " .. (err or "not found") | ||
656 | end | ||
657 | local path, file = string.match(files[1], "^(.+)%\\([^%\\]+)$") | ||
658 | return files[1], path, file | ||
659 | end | ||
660 | |||
661 | local first_one = "*gcc.exe" -- first file we're assuming to point to the compiler suite | ||
662 | local full, path, filename = find_file(first_one, nil) | ||
663 | if not full then | ||
664 | return nil, path | ||
665 | end | ||
666 | vars.MINGW_BIN_PATH = path | ||
667 | |||
668 | local result = { | ||
669 | gcc = full | ||
670 | } | ||
671 | for i, name in ipairs({"make", "ar", "windres", "ranlib"}) do | ||
672 | result[name] = find_file(name..".exe", path) | ||
673 | if not result[name] then | ||
674 | result[name] = find_file("*"..name.."*.exe", path) | ||
675 | end | ||
676 | end | ||
677 | |||
678 | vars.MINGW_MAKE = (result.make and '[['..result.make..']]') or "nil -- not found by installer" | ||
679 | vars.MINGW_CC = (result.gcc and '[['..result.gcc..']]') or "nil -- not found by installer" | ||
680 | vars.MINGW_RC = (result.windres and '[['..result.windres..']]') or "nil -- not found by installer" | ||
681 | vars.MINGW_LD = (result.gcc and '[['..result.gcc..']]') or "nil -- not found by installer" | ||
682 | vars.MINGW_AR = (result.ar and '[['..result.ar..']]') or "nil -- not found by installer" | ||
683 | vars.MINGW_RANLIB = (result.ranlib and '[['..result.ranlib..']]') or "nil -- not found by installer" | ||
684 | return true | ||
685 | end | ||
686 | |||
620 | -- *********************************************************** | 687 | -- *********************************************************** |
621 | -- Installer script start | 688 | -- Installer script start |
622 | -- *********************************************************** | 689 | -- *********************************************************** |
@@ -765,7 +832,15 @@ if SELFCONTAINED then | |||
765 | vars.TREE_ROOT = vars.PREFIX..[[\systree]] | 832 | vars.TREE_ROOT = vars.PREFIX..[[\systree]] |
766 | REGISTRY = false | 833 | REGISTRY = false |
767 | end | 834 | end |
768 | vars.COMPILER_ENV_CMD = (USE_MINGW and "") or (USE_MSVC_MANUAL and "") or get_msvc_env_setup_cmd() | 835 | if USE_MINGW then |
836 | vars.COMPILER_ENV_CMD = "" | ||
837 | local found, err = find_gcc_suite() | ||
838 | if not found then | ||
839 | die("Failed to find MinGW/gcc based toolchain, make sure it is in your path: " .. tostring(err)) | ||
840 | end | ||
841 | else | ||
842 | vars.COMPILER_ENV_CMD = (USE_MSVC_MANUAL and "") or get_msvc_env_setup_cmd() | ||
843 | end | ||
769 | 844 | ||
770 | print(S[[ | 845 | print(S[[ |
771 | 846 | ||
@@ -787,7 +862,8 @@ Lua interpreter : $LUA_BINDIR\$LUA_INTERPRETER | |||
787 | ]]) | 862 | ]]) |
788 | 863 | ||
789 | if USE_MINGW then | 864 | if USE_MINGW then |
790 | print("Compiler : MinGW (make sure it is in your path before using LuaRocks)") | 865 | print(S[[Compiler : MinGW/gcc (make sure it is in your path before using LuaRocks)]]) |
866 | print(S[[ in: $MINGW_BIN_PATH]]) | ||
791 | else | 867 | else |
792 | if vars.COMPILER_ENV_CMD == "" then | 868 | if vars.COMPILER_ENV_CMD == "" then |
793 | print("Compiler : Microsoft (make sure it is in your path before using LuaRocks)") | 869 | print("Compiler : Microsoft (make sure it is in your path before using LuaRocks)") |
@@ -1012,7 +1088,17 @@ if USE_MINGW and vars.LUA_RUNTIME == "MSVCRT" then | |||
1012 | else | 1088 | else |
1013 | f:write(" MSVCRT = '"..vars.LUA_RUNTIME.."',\n") | 1089 | f:write(" MSVCRT = '"..vars.LUA_RUNTIME.."',\n") |
1014 | end | 1090 | end |
1015 | f:write(S" LUALIB = '$LUA_LIBNAME'\n") | 1091 | f:write(S" LUALIB = '$LUA_LIBNAME',\n") |
1092 | if USE_MINGW then | ||
1093 | f:write(S[[ | ||
1094 | CC = $MINGW_CC, | ||
1095 | MAKE = $MINGW_MAKE, | ||
1096 | RC = $MINGW_RC, | ||
1097 | LD = $MINGW_LD, | ||
1098 | AR = $MINGW_AR, | ||
1099 | RANLIB = $MINGW_RANLIB, | ||
1100 | ]]) | ||
1101 | end | ||
1016 | f:write("}\n") | 1102 | f:write("}\n") |
1017 | f:write("verbose = false -- set to 'true' to enable verbose output\n") | 1103 | f:write("verbose = false -- set to 'true' to enable verbose output\n") |
1018 | f:close() | 1104 | f:close() |