├── .gitignore ├── COPYING ├── COPYING_7z ├── README.md ├── lr244_cfg.lua_54 ├── lr244_install.bat_54 ├── make.bat ├── scripts ├── build.bat ├── clean_path.lua ├── download.bat └── setlua.bat └── tools ├── 7z.dll ├── 7z.exe └── wget.exe /.gitignore: -------------------------------------------------------------------------------- 1 | /lua-5.1* 2 | /lua-5.2* 3 | /lua-5.3* 4 | /lua-5.4* 5 | /luarocks* 6 | /luawinmake* 7 | pax_global_header 8 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | 2 | This package includes additional Windows components which are under the 3 | following licenses: 4 | 5 | * For 7z.exe and 7z.dll, please see COPYING_7z for details. 6 | 7 | * wget.exe, is part of UnxUtils, check 8 | http://unxutils.sourceforge.net/ for license information. 9 | 10 | The remainder is licensed under the MIT license; https://opensource.org/licenses/MIT 11 | -------------------------------------------------------------------------------- /COPYING_7z: -------------------------------------------------------------------------------- 1 | 7-Zip 2 | ~~~~~ 3 | License for use and distribution 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 5 | 6 | 7-Zip Copyright (C) 1999-2010 Igor Pavlov. 7 | 8 | Licenses for files are: 9 | 10 | 1) 7z.dll: GNU LGPL + unRAR restriction 11 | 2) All other files: GNU LGPL 12 | 13 | The GNU LGPL + unRAR restriction means that you must follow both 14 | GNU LGPL rules and unRAR restriction rules. 15 | 16 | 17 | Note: 18 | You can use 7-Zip on any computer, including a computer in a commercial 19 | organization. You don't need to register or pay for 7-Zip. 20 | 21 | 22 | GNU LGPL information 23 | -------------------- 24 | 25 | This library is free software; you can redistribute it and/or 26 | modify it under the terms of the GNU Lesser General Public 27 | License as published by the Free Software Foundation; either 28 | version 2.1 of the License, or (at your option) any later version. 29 | 30 | This library is distributed in the hope that it will be useful, 31 | but WITHOUT ANY WARRANTY; without even the implied warranty of 32 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 33 | Lesser General Public License for more details. 34 | 35 | You can receive a copy of the GNU Lesser General Public License from 36 | http://www.gnu.org/ 37 | 38 | 39 | unRAR restriction 40 | ----------------- 41 | 42 | The decompression engine for RAR archives was developed using source 43 | code of unRAR program. 44 | All copyrights to original unRAR code are owned by Alexander Roshal. 45 | 46 | The license for original unRAR code has the following restriction: 47 | 48 | The unRAR sources cannot be used to re-create the RAR compression algorithm, 49 | which is proprietary. Distribution of modified unRAR sources in separate form 50 | or as a part of other software is permitted, provided that it is clearly 51 | stated in the documentation and source comments that the code may 52 | not be used to develop a RAR (WinRAR) compatible archiver. 53 | 54 | 55 | -- 56 | Igor Pavlov 57 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Multi-lua for Windows script 2 | ============================ 3 | 4 | This batchfile will download, compile and configure a Lua installation with 5 | versions 5.1, 5.2, 5.3, and 5.4 in parallel. Including the accompanying 6 | LuaRocks package manager for each version. 7 | 8 | Prerequisites 9 | ============= 10 | Make sure you have a compiler in your path; 11 | 12 | - MinGW in your system path (msys is not required) 13 | - for MS compilers, call `make.bat` from the Visual Studio (or Win SDK) commandshell 14 | 15 | Command 16 | ======= 17 | 18 | ```` 19 | Command: 20 | MAKE [--clean] [--cleantarget] [--nocompat] [--51] [--52] [--53] [--54] [install []] 21 | 22 | --51,--52,--53,--54: specify the versions to install, default is to install 23 | all versions. Applies only to installing, all versions will be 24 | build independent of this option. 25 | The first version listed will be set as the unversioned default. 26 | --clean : removes downloaded and build artifacts, forcing a rebuild 27 | --cleantarget : removes the target directory before installing. NOTE: the LuaRocks 28 | installation will ALWAYS be removed, independent of this option! 29 | --nocompat : build Lua without compatibility options. NOTE: this option 30 | will not automatically clean. So clean when switching compatibility. 31 | install : will install (and build if necessary) the Lua versions. Default 32 | location is 'C:\Lua' 33 | 34 | --help : Display this help text 35 | 36 | Example: the following commands, executed after each other will; 37 | make install 38 | Will download, build and install 4 Lua versions in 'C:\Lua', 5.1 will 39 | be set as the default. 40 | 41 | make --51 --52 install C:\lua2 42 | Will only install (no rebuild, binaries allready exist) 5.1 and 5.2 in 43 | 'C:\Lua2'. 5.1 will be set as the default. 44 | 45 | make --clean --53 --nocompat install C:\Lua_NoCompat 46 | Will download and build all versions again, without compatibility options, 47 | and then install only 5.3 in 'C:\Lua_NoCompat'. 5.3 will be set as the 48 | default. 49 | ```` 50 | 51 | 52 | 53 | What it does 54 | ============ 55 | 56 | - Downloads and unpacks sources of LuaRocks, LuaWinmake (used for building), and Lua 57 | - Compiles the Lua versions from source (using [LuaWinMake](https://github.com/Tieske/luawinmake)) 58 | - Installs the Lua versions (versioned; using the LuaWinMake command `installv`) 59 | - Installs LuaRocks for each version 60 | - default Lua version will be set to Lua 5.1 (see `setlua` below) 61 | 62 | 63 | Usage 64 | ===== 65 | 66 | Each Lua version will have its own executable; `lua51.exe`, `lua52.exe`, `lua53.exe`, and 67 | `lua54.exe`. And for LuaRocks 4 batchfiles will be generated; `luarocks51.bat`, 68 | `luarocks52.bat`, `luarocks53.bat`, and `luarocks54.bat`. 69 | 70 | The luarocks batch files will be in the same directory as the lua executables, so 71 | only the Lua path has to be added to the system path. 72 | 73 | The utility `setlua.bat` will setup default versions for Lua and LuaRocks unversioned 74 | commands. eg. `setlua 54` will create a copy of `lua54.exe` as `lua.exe`, and will 75 | create a batch file `luarocks.bat` that will invoke `luarocks54.bat`. 76 | Besides that it will add the Lua location to the system path and install all LuaRocks 77 | system rocktrees into the respective Lua path environment variables. 78 | 79 | Calling `setlua.bat` without a parameter will only set the paths and not change the 80 | unversioned `lua` and `luarocks` commands. This can be used as a Lua commandshell 81 | specific for this environment. For example; create a shortcut with target 82 | `C:\Windows\System32\cmd.exe /k c:\lua\bin\setlua.bat` (assuming the default Lua 83 | location `c:\lua`). 84 | 85 | License 86 | ======= 87 | Copyright 2015-2023, Thijs Schreijer. 88 | MIT license for this project. Please note that other components are included 89 | which are covered by different licenses. See COPYING file for details. 90 | -------------------------------------------------------------------------------- /lr244_cfg.lua_54: -------------------------------------------------------------------------------- 1 | --- Configuration for LuaRocks. 2 | -- Tries to load the user's configuration file and 3 | -- defines defaults for unset values. See the 4 | -- config 5 | -- file format documentation for details. 6 | -- 7 | -- End-users shouldn't edit this file. They can override any defaults 8 | -- set in this file using their system-wide or user-specific configuration 9 | -- files. Run `luarocks` with no arguments to see the locations of 10 | -- these files in your platform. 11 | 12 | local rawset, next, table, pairs, require, io, os, setmetatable, pcall, ipairs, package, tonumber, type, assert, _VERSION = 13 | rawset, next, table, pairs, require, io, os, setmetatable, pcall, ipairs, package, tonumber, type, assert, _VERSION 14 | 15 | --module("luarocks.cfg") 16 | local cfg = {} 17 | package.loaded["luarocks.cfg"] = cfg 18 | 19 | local util = require("luarocks.util") 20 | 21 | cfg.lua_version = _VERSION:match(" (5%.[1234])$") or "5.1" 22 | local version_suffix = cfg.lua_version:gsub("%.", "_") 23 | 24 | -- Load site-local global configurations 25 | local ok, site_config = pcall(require, "luarocks.site_config_"..version_suffix) 26 | if not ok then 27 | ok, site_config = pcall(require, "luarocks.site_config") 28 | end 29 | if not ok then 30 | io.stderr:write("Site-local luarocks/site_config.lua file not found. Incomplete installation?\n") 31 | site_config = {} 32 | end 33 | 34 | cfg.program_version = "2.4.4" 35 | cfg.program_series = "2.4" 36 | cfg.major_version = (cfg.program_version:match("([^.]%.[^.])")) or cfg.program_series 37 | cfg.variables = {} 38 | cfg.rocks_trees = {} 39 | cfg.platforms = {} 40 | 41 | local persist = require("luarocks.persist") 42 | 43 | cfg.errorcodes = setmetatable({ 44 | OK = 0, 45 | UNSPECIFIED = 1, 46 | PERMISSIONDENIED = 2, 47 | CONFIGFILE = 3, 48 | CRASH = 99 49 | },{ 50 | __index = function(t, key) 51 | local val = rawget(t, key) 52 | if not val then 53 | error("'"..tostring(key).."' is not a valid errorcode", 2) 54 | end 55 | return val 56 | end 57 | }) 58 | 59 | 60 | local popen_ok, popen_result = pcall(io.popen, "") 61 | if popen_ok then 62 | if popen_result then 63 | popen_result:close() 64 | end 65 | else 66 | io.stderr:write("Your version of Lua does not support io.popen,\n") 67 | io.stderr:write("which is required by LuaRocks. Please check your Lua installation.\n") 68 | os.exit(cfg.errorcodes.UNSPECIFIED) 69 | end 70 | 71 | -- System detection: 72 | 73 | -- A proper installation of LuaRocks will hardcode the system 74 | -- and proc values with site_config.LUAROCKS_UNAME_S and site_config.LUAROCKS_UNAME_M, 75 | -- so that this detection does not run every time. When it is 76 | -- performed, we use the Unix way to identify the system, 77 | -- even on Windows (assuming UnxUtils or Cygwin). 78 | local system = site_config.LUAROCKS_UNAME_S or io.popen("uname -s"):read("*l") 79 | local proc = site_config.LUAROCKS_UNAME_M or io.popen("uname -m"):read("*l") 80 | if proc:match("i[%d]86") then 81 | cfg.target_cpu = "x86" 82 | elseif proc:match("amd64") or proc:match("x86_64") then 83 | cfg.target_cpu = "x86_64" 84 | elseif proc:match("Power Macintosh") then 85 | cfg.target_cpu = "powerpc" 86 | else 87 | cfg.target_cpu = proc 88 | end 89 | 90 | if system == "FreeBSD" then 91 | cfg.platforms.unix = true 92 | cfg.platforms.freebsd = true 93 | cfg.platforms.bsd = true 94 | elseif system == "OpenBSD" then 95 | cfg.platforms.unix = true 96 | cfg.platforms.openbsd = true 97 | cfg.platforms.bsd = true 98 | elseif system == "NetBSD" then 99 | cfg.platforms.unix = true 100 | cfg.platforms.netbsd = true 101 | cfg.platforms.bsd = true 102 | elseif system == "Darwin" then 103 | cfg.platforms.unix = true 104 | cfg.platforms.macosx = true 105 | cfg.platforms.bsd = true 106 | elseif system == "Linux" then 107 | cfg.platforms.unix = true 108 | cfg.platforms.linux = true 109 | elseif system == "SunOS" then 110 | cfg.platforms.unix = true 111 | cfg.platforms.solaris = true 112 | elseif system and system:match("^CYGWIN") then 113 | cfg.platforms.unix = true 114 | cfg.platforms.cygwin = true 115 | elseif system and system:match("^MSYS") then 116 | cfg.platforms.unix = true 117 | cfg.platforms.msys = true 118 | cfg.platforms.cygwin = true 119 | elseif system and system:match("^Windows") then 120 | cfg.platforms.windows = true 121 | cfg.platforms.win32 = true 122 | elseif system and system:match("^MINGW") then 123 | cfg.platforms.windows = true 124 | cfg.platforms.mingw32 = true 125 | cfg.platforms.win32 = true 126 | elseif system == "Haiku" then 127 | cfg.platforms.unix = true 128 | cfg.platforms.haiku = true 129 | else 130 | cfg.platforms.unix = true 131 | -- Fall back to Unix in unknown systems. 132 | end 133 | 134 | -- Set order for platform overrides. 135 | -- More general platform identifiers should be listed first, 136 | -- more specific ones later. 137 | local platform_order = { 138 | -- Unixes 139 | "unix", 140 | "bsd", 141 | "solaris", 142 | "netbsd", 143 | "openbsd", 144 | "freebsd", 145 | "linux", 146 | "macosx", 147 | "cygwin", 148 | "msys", 149 | "haiku", 150 | -- Windows 151 | "win32", 152 | "mingw32", 153 | "windows", 154 | } 155 | 156 | -- Path configuration: 157 | local sys_config_file, home_config_file 158 | local sys_config_file_default, home_config_file_default 159 | local sys_config_dir, home_config_dir 160 | local sys_config_ok, home_config_ok = false, false 161 | local extra_luarocks_module_dir 162 | sys_config_dir = site_config.LUAROCKS_SYSCONFDIR or site_config.LUAROCKS_PREFIX 163 | if cfg.platforms.windows then 164 | cfg.home = os.getenv("APPDATA") or "c:" 165 | sys_config_dir = sys_config_dir or "c:/luarocks" 166 | home_config_dir = cfg.home.."/luarocks" 167 | cfg.home_tree = cfg.home.."/luarocks/" 168 | else 169 | cfg.home = os.getenv("HOME") or "" 170 | sys_config_dir = sys_config_dir or "/etc/luarocks" 171 | home_config_dir = cfg.home.."/.luarocks" 172 | cfg.home_tree = (os.getenv("USER") ~= "root") and cfg.home.."/.luarocks/" 173 | end 174 | 175 | -- Create global environment for the config files; 176 | local env_for_config_file = function() 177 | local e 178 | e = { 179 | home = cfg.home, 180 | lua_version = cfg.lua_version, 181 | platforms = util.make_shallow_copy(cfg.platforms), 182 | processor = cfg.target_cpu, -- remains for compat reasons 183 | target_cpu = cfg.target_cpu, -- replaces `processor` 184 | os_getenv = os.getenv, 185 | dump_env = function() 186 | -- debug function, calling it from a config file will show all 187 | -- available globals to that config file 188 | print(util.show_table(e, "global environment")) 189 | end, 190 | } 191 | return e 192 | end 193 | 194 | -- Merge values from config files read into the `cfg` table 195 | local merge_overrides = function(overrides) 196 | -- remove some stuff we do not want to integrate 197 | overrides.os_getenv = nil 198 | overrides.dump_env = nil 199 | -- remove tables to be copied verbatim instead of deeply merged 200 | if overrides.rocks_trees then cfg.rocks_trees = nil end 201 | if overrides.rocks_servers then cfg.rocks_servers = nil end 202 | -- perform actual merge 203 | util.deep_merge(cfg, overrides) 204 | end 205 | 206 | -- load config file from a list until first succesful one. Info is 207 | -- added to `cfg` module table, returns filepath of succesfully loaded 208 | -- file or nil if it failed 209 | local load_config_file = function(list) 210 | for _, filepath in ipairs(list) do 211 | local result, err, errcode = persist.load_into_table(filepath, env_for_config_file()) 212 | if (not result) and errcode ~= "open" then 213 | -- errcode is either "load" or "run"; bad config file, so error out 214 | io.stderr:write(err.."\n") 215 | os.exit(cfg.errorcodes.CONFIGFILE) 216 | end 217 | if result then 218 | -- succes in loading and running, merge contents and exit 219 | merge_overrides(result) 220 | return filepath 221 | end 222 | end 223 | return nil -- nothing was loaded 224 | end 225 | 226 | 227 | -- Load system configuration file 228 | do 229 | sys_config_file_default = sys_config_dir.."/config-"..cfg.lua_version..".lua" 230 | sys_config_file = load_config_file({ 231 | site_config.LUAROCKS_SYSCONFIG or sys_config_file_default, 232 | sys_config_dir.."/config.lua", 233 | }) 234 | sys_config_ok = (sys_config_file ~= nil) 235 | end 236 | 237 | -- Load user configuration file (if allowed) 238 | if not site_config.LUAROCKS_FORCE_CONFIG then 239 | 240 | home_config_file_default = home_config_dir.."/config-"..cfg.lua_version..".lua" 241 | 242 | local config_env_var = "LUAROCKS_CONFIG_" .. version_suffix 243 | local config_env_value = os.getenv(config_env_var) 244 | if not config_env_value then 245 | config_env_var = "LUAROCKS_CONFIG" 246 | config_env_value = os.getenv(config_env_var) 247 | end 248 | 249 | -- first try environment provided file, so we can explicitly warn when it is missing 250 | if config_env_value then 251 | local list = { config_env_value } 252 | home_config_file = load_config_file(list) 253 | home_config_ok = (home_config_file ~= nil) 254 | if not home_config_ok then 255 | io.stderr:write("Warning: could not load configuration file `"..config_env_value.."` given in environment variable "..config_env_var.."\n") 256 | end 257 | end 258 | 259 | -- try the alternative defaults if there was no environment specified file or it didn't work 260 | if not home_config_ok then 261 | local list = { 262 | home_config_file_default, 263 | home_config_dir.."/config.lua", 264 | } 265 | home_config_file = load_config_file(list) 266 | home_config_ok = (home_config_file ~= nil) 267 | end 268 | end 269 | 270 | 271 | if not next(cfg.rocks_trees) then 272 | if cfg.home_tree then 273 | table.insert(cfg.rocks_trees, { name = "user", root = cfg.home_tree } ) 274 | end 275 | if site_config.LUAROCKS_ROCKS_TREE then 276 | table.insert(cfg.rocks_trees, { name = "system", root = site_config.LUAROCKS_ROCKS_TREE } ) 277 | end 278 | end 279 | 280 | -- update platforms list; keyed -> array 281 | do 282 | -- if explicitly given by user, 283 | if cfg.platforms[1] then 284 | local is_windows = cfg.platforms.windows 285 | -- Clear auto-detected values 286 | for k, _ in pairs(cfg.platforms) do 287 | if type(k) == "string" then 288 | cfg.platforms[k] = nil 289 | end 290 | end 291 | -- and set the ones given by the user. 292 | for _, plat in ipairs(cfg.platforms) do 293 | cfg.platforms[plat] = true 294 | end 295 | -- If no major platform family was set by the user, 296 | if not (cfg.platforms.unix or cfg.platforms.windows) then 297 | -- set some fallback defaults in case the user provides an incomplete configuration. 298 | -- LuaRocks expects a set of defaults to be available. 299 | -- This is used for setting defaults here only; the platform overrides 300 | -- will use only the user's list. 301 | if is_windows then 302 | cfg.platforms.windows = true 303 | table.insert(cfg.platforms, "windows") 304 | else 305 | cfg.platforms.unix = true 306 | table.insert(cfg.platforms, "unix") 307 | end 308 | end 309 | else 310 | -- Sort detected platform defaults 311 | local order = {} 312 | for i, v in ipairs(platform_order) do 313 | order[v] = i 314 | end 315 | local entries = {} 316 | for k, v in pairs(cfg.platforms) do 317 | if type(k) == "string" and v == true then 318 | table.insert(entries, k) 319 | end 320 | end 321 | table.sort(entries, function(a, b) return order[a] < order[b] end) 322 | util.deep_merge(cfg.platforms, entries) 323 | end 324 | end 325 | 326 | -- Configure defaults: 327 | local defaults = { 328 | 329 | local_by_default = false, 330 | accept_unknown_fields = false, 331 | fs_use_modules = true, 332 | hooks_enabled = true, 333 | deps_mode = "one", 334 | check_certificates = false, 335 | perm_read = "0644", 336 | perm_exec = "0755", 337 | 338 | lua_modules_path = "/share/lua/"..cfg.lua_version, 339 | lib_modules_path = "/lib/lua/"..cfg.lua_version, 340 | rocks_subdir = site_config.LUAROCKS_ROCKS_SUBDIR or "/lib/luarocks/rocks", 341 | 342 | arch = "unknown", 343 | lib_extension = "unknown", 344 | obj_extension = "unknown", 345 | link_lua_explicitly = false, 346 | 347 | rocks_servers = { 348 | { 349 | "https://luarocks.org", 350 | "https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master/", 351 | "http://luafr.org/moonrocks/", 352 | "http://luarocks.logiceditor.com/rocks", 353 | } 354 | }, 355 | disabled_servers = {}, 356 | 357 | upload = { 358 | server = "https://luarocks.org", 359 | tool_version = "1.0.0", 360 | api_version = "1", 361 | }, 362 | 363 | lua_extension = "lua", 364 | lua_interpreter = site_config.LUA_INTERPRETER or "lua", 365 | downloader = site_config.LUAROCKS_DOWNLOADER or "wget", 366 | md5checker = site_config.LUAROCKS_MD5CHECKER or "md5sum", 367 | connection_timeout = 30, -- 0 = no timeout 368 | 369 | variables = { 370 | MAKE = "make", 371 | CC = "cc", 372 | LD = "ld", 373 | 374 | CVS = "cvs", 375 | GIT = "git", 376 | SSCM = "sscm", 377 | SVN = "svn", 378 | HG = "hg", 379 | 380 | RSYNC = "rsync", 381 | WGET = "wget", 382 | SCP = "scp", 383 | CURL = "curl", 384 | 385 | PWD = "pwd", 386 | MKDIR = "mkdir", 387 | RMDIR = "rmdir", 388 | CP = "cp", 389 | LS = "ls", 390 | RM = "rm", 391 | FIND = "find", 392 | TEST = "test", 393 | CHMOD = "chmod", 394 | MKTEMP = "mktemp", 395 | 396 | ZIP = "zip", 397 | UNZIP = "unzip -n", 398 | GUNZIP = "gunzip", 399 | BUNZIP2 = "bunzip2", 400 | TAR = "tar", 401 | 402 | MD5SUM = "md5sum", 403 | OPENSSL = "openssl", 404 | MD5 = "md5", 405 | STAT = "stat", 406 | TOUCH = "touch", 407 | 408 | CMAKE = "cmake", 409 | SEVENZ = "7z", 410 | 411 | RSYNCFLAGS = "--exclude=.git -Oavz", 412 | STATPERMFLAG = "-c '%a'", 413 | STATOWNERFLAG = "-c '%U'", 414 | CURLNOCERTFLAG = "", 415 | WGETNOCERTFLAG = "", 416 | }, 417 | 418 | external_deps_subdirs = site_config.LUAROCKS_EXTERNAL_DEPS_SUBDIRS or { 419 | bin = "bin", 420 | lib = "lib", 421 | include = "include" 422 | }, 423 | runtime_external_deps_subdirs = site_config.LUAROCKS_RUNTIME_EXTERNAL_DEPS_SUBDIRS or { 424 | bin = "bin", 425 | lib = "lib", 426 | include = "include" 427 | }, 428 | 429 | rocks_provided = {} 430 | } 431 | 432 | if cfg.platforms.windows then 433 | local full_prefix = (site_config.LUAROCKS_PREFIX or (os.getenv("PROGRAMFILES")..[[\LuaRocks]])) 434 | extra_luarocks_module_dir = full_prefix.."/lua/?.lua" 435 | 436 | home_config_file = home_config_file and home_config_file:gsub("\\","/") 437 | defaults.fs_use_modules = false 438 | defaults.arch = "win32-"..cfg.target_cpu 439 | defaults.lib_extension = "dll" 440 | defaults.external_lib_extension = "dll" 441 | defaults.obj_extension = "obj" 442 | defaults.external_deps_dirs = { "c:/external/" } 443 | defaults.variables.LUA_BINDIR = site_config.LUA_BINDIR and site_config.LUA_BINDIR:gsub("\\", "/") or "c:/lua"..cfg.lua_version.."/bin" 444 | defaults.variables.LUA_INCDIR = site_config.LUA_INCDIR and site_config.LUA_INCDIR:gsub("\\", "/") or "c:/lua"..cfg.lua_version.."/include" 445 | defaults.variables.LUA_LIBDIR = site_config.LUA_LIBDIR and site_config.LUA_LIBDIR:gsub("\\", "/") or "c:/lua"..cfg.lua_version.."/lib" 446 | 447 | defaults.makefile = "Makefile.win" 448 | defaults.variables.MAKE = "nmake" 449 | defaults.variables.CC = "cl" 450 | defaults.variables.RC = "rc" 451 | defaults.variables.WRAPPER = full_prefix.."\\rclauncher.c" 452 | defaults.variables.LD = "link" 453 | defaults.variables.MT = "mt" 454 | defaults.variables.LUALIB = "lua"..cfg.lua_version..".lib" 455 | defaults.variables.CFLAGS = "/nologo /MD /O2" 456 | defaults.variables.LIBFLAG = "/nologo /dll" 457 | 458 | local bins = { "SEVENZ", "CP", "FIND", "LS", "MD5SUM", 459 | "MKDIR", "MV", "PWD", "RMDIR", "TEST", "UNAME", "WGET" } 460 | for _, var in ipairs(bins) do 461 | if defaults.variables[var] then 462 | defaults.variables[var] = full_prefix.."\\tools\\"..defaults.variables[var] 463 | end 464 | end 465 | 466 | defaults.external_deps_patterns = { 467 | bin = { "?.exe", "?.bat" }, 468 | lib = { "?.lib", "?.dll", "lib?.dll" }, 469 | include = { "?.h" } 470 | } 471 | defaults.runtime_external_deps_patterns = { 472 | bin = { "?.exe", "?.bat" }, 473 | lib = { "?.dll", "lib?.dll" }, 474 | include = { "?.h" } 475 | } 476 | defaults.export_path = "SET PATH=%s" 477 | defaults.export_path_separator = ";" 478 | defaults.export_lua_path = "SET LUA_PATH=%s" 479 | defaults.export_lua_cpath = "SET LUA_CPATH=%s" 480 | defaults.wrapper_suffix = ".bat" 481 | 482 | local localappdata = os.getenv("LOCALAPPDATA") 483 | if not localappdata then 484 | -- for Windows versions below Vista 485 | localappdata = os.getenv("USERPROFILE").."/Local Settings/Application Data" 486 | end 487 | defaults.local_cache = localappdata.."/LuaRocks/Cache" 488 | defaults.web_browser = "start" 489 | end 490 | 491 | if cfg.platforms.mingw32 then 492 | defaults.obj_extension = "o" 493 | defaults.cmake_generator = "MinGW Makefiles" 494 | defaults.variables.MAKE = "mingw32-make" 495 | defaults.variables.CC = "mingw32-gcc" 496 | defaults.variables.RC = "windres" 497 | defaults.variables.LD = "mingw32-gcc" 498 | defaults.variables.CFLAGS = "-O2" 499 | defaults.variables.LIBFLAG = "-shared" 500 | defaults.makefile = "Makefile" 501 | defaults.external_deps_patterns = { 502 | bin = { "?.exe", "?.bat" }, 503 | -- mingw lookup list from http://stackoverflow.com/a/15853231/1793220 504 | -- ...should we keep ?.lib at the end? It's not in the above list. 505 | lib = { "lib?.dll.a", "?.dll.a", "lib?.a", "cyg?.dll", "lib?.dll", "?.dll", "?.lib" }, 506 | include = { "?.h" } 507 | } 508 | defaults.runtime_external_deps_patterns = { 509 | bin = { "?.exe", "?.bat" }, 510 | lib = { "cyg?.dll", "?.dll", "lib?.dll" }, 511 | include = { "?.h" } 512 | } 513 | 514 | end 515 | 516 | if cfg.platforms.unix then 517 | defaults.lib_extension = "so" 518 | defaults.external_lib_extension = "so" 519 | defaults.obj_extension = "o" 520 | defaults.external_deps_dirs = { "/usr/local", "/usr" } 521 | defaults.variables.LUA_BINDIR = site_config.LUA_BINDIR or "/usr/local/bin" 522 | defaults.variables.LUA_INCDIR = site_config.LUA_INCDIR or "/usr/local/include" 523 | defaults.variables.LUA_LIBDIR = site_config.LUA_LIBDIR or "/usr/local/lib" 524 | defaults.variables.CFLAGS = "-O2" 525 | defaults.cmake_generator = "Unix Makefiles" 526 | defaults.variables.CC = "gcc" 527 | defaults.variables.LD = "gcc" 528 | defaults.gcc_rpath = true 529 | defaults.variables.LIBFLAG = "-shared" 530 | defaults.external_deps_patterns = { 531 | bin = { "?" }, 532 | lib = { "lib?.a", "lib?.so", "lib?.so.*" }, 533 | include = { "?.h" } 534 | } 535 | defaults.runtime_external_deps_patterns = { 536 | bin = { "?" }, 537 | lib = { "lib?.so", "lib?.so.*" }, 538 | include = { "?.h" } 539 | } 540 | defaults.export_path = "export PATH='%s'" 541 | defaults.export_path_separator = ":" 542 | defaults.export_lua_path = "export LUA_PATH='%s'" 543 | defaults.export_lua_cpath = "export LUA_CPATH='%s'" 544 | defaults.wrapper_suffix = "" 545 | defaults.local_cache = cfg.home.."/.cache/luarocks" 546 | if not defaults.variables.CFLAGS:match("-fPIC") then 547 | defaults.variables.CFLAGS = defaults.variables.CFLAGS.." -fPIC" 548 | end 549 | defaults.web_browser = "xdg-open" 550 | end 551 | 552 | if cfg.platforms.cygwin then 553 | defaults.lib_extension = "so" -- can be overridden in the config file for mingw builds 554 | defaults.arch = "cygwin-"..cfg.target_cpu 555 | defaults.cmake_generator = "Unix Makefiles" 556 | defaults.variables.CC = "echo -llua | xargs gcc" 557 | defaults.variables.LD = "echo -llua | xargs gcc" 558 | defaults.variables.LIBFLAG = "-shared" 559 | defaults.link_lua_explicitly = true 560 | end 561 | 562 | if cfg.platforms.msys then 563 | -- msys is basically cygwin made out of mingw, meaning the subsytem is unixish 564 | -- enough, yet we can freely mix with native win32 565 | defaults.external_deps_patterns = { 566 | bin = { "?.exe", "?.bat", "?" }, 567 | lib = { "lib?.so", "lib?.so.*", "lib?.dll.a", "?.dll.a", 568 | "lib?.a", "lib?.dll", "?.dll", "?.lib" }, 569 | include = { "?.h" } 570 | } 571 | defaults.runtime_external_deps_patterns = { 572 | bin = { "?.exe", "?.bat" }, 573 | lib = { "lib?.so", "?.dll", "lib?.dll" }, 574 | include = { "?.h" } 575 | } 576 | end 577 | 578 | 579 | if cfg.platforms.bsd then 580 | defaults.variables.MAKE = "gmake" 581 | defaults.variables.STATPERMFLAG = "-f '%OLp'" 582 | defaults.variables.STATOWNERFLAG = "-f '%Su'" 583 | end 584 | 585 | if cfg.platforms.macosx then 586 | defaults.variables.MAKE = "make" 587 | defaults.external_lib_extension = "dylib" 588 | defaults.arch = "macosx-"..cfg.target_cpu 589 | defaults.variables.LIBFLAG = "-bundle -undefined dynamic_lookup -all_load" 590 | defaults.variables.STAT = "/usr/bin/stat" 591 | defaults.variables.STATFLAG = "-f '%A'" 592 | local version = io.popen("sw_vers -productVersion"):read("*l") 593 | version = tonumber(version and version:match("^[^.]+%.([^.]+)")) or 3 594 | if version >= 10 then 595 | version = 8 596 | elseif version >= 5 then 597 | version = 5 598 | else 599 | defaults.gcc_rpath = false 600 | end 601 | defaults.variables.CC = "env MACOSX_DEPLOYMENT_TARGET=10."..version.." gcc" 602 | defaults.variables.LD = "env MACOSX_DEPLOYMENT_TARGET=10."..version.." gcc" 603 | defaults.web_browser = "open" 604 | end 605 | 606 | if cfg.platforms.linux then 607 | defaults.arch = "linux-"..cfg.target_cpu 608 | end 609 | 610 | if cfg.platforms.freebsd then 611 | defaults.arch = "freebsd-"..cfg.target_cpu 612 | defaults.gcc_rpath = false 613 | defaults.variables.CC = "cc" 614 | defaults.variables.LD = "cc" 615 | end 616 | 617 | if cfg.platforms.openbsd then 618 | defaults.arch = "openbsd-"..cfg.target_cpu 619 | end 620 | 621 | if cfg.platforms.netbsd then 622 | defaults.arch = "netbsd-"..cfg.target_cpu 623 | end 624 | 625 | if cfg.platforms.solaris then 626 | defaults.arch = "solaris-"..cfg.target_cpu 627 | --defaults.platforms = {"unix", "solaris"} 628 | defaults.variables.MAKE = "gmake" 629 | end 630 | 631 | -- Expose some more values detected by LuaRocks for use by rockspec authors. 632 | defaults.variables.LIB_EXTENSION = defaults.lib_extension 633 | defaults.variables.OBJ_EXTENSION = defaults.obj_extension 634 | defaults.variables.LUAROCKS_PREFIX = site_config.LUAROCKS_PREFIX 635 | defaults.variables.LUA = site_config.LUA_DIR_SET and (defaults.variables.LUA_BINDIR.."/"..defaults.lua_interpreter) or defaults.lua_interpreter 636 | 637 | -- Add built-in modules to rocks_provided 638 | defaults.rocks_provided["lua"] = cfg.lua_version.."-1" 639 | 640 | if bit32 then -- Lua 5.2+ 641 | defaults.rocks_provided["bit32"] = cfg.lua_version.."-1" 642 | end 643 | 644 | if utf8 then -- Lua 5.3+ 645 | defaults.rocks_provided["utf8"] = cfg.lua_version.."-1" 646 | end 647 | 648 | if package.loaded.jit then 649 | -- LuaJIT 650 | local lj_version = package.loaded.jit.version:match("LuaJIT (.*)"):gsub("%-","") 651 | --defaults.rocks_provided["luajit"] = lj_version.."-1" 652 | defaults.rocks_provided["luabitop"] = lj_version.."-1" 653 | end 654 | 655 | -- Use defaults: 656 | 657 | -- Populate some arrays with values from their 'defaults' counterparts 658 | -- if they were not already set by user. 659 | for _, entry in ipairs({"variables", "rocks_provided"}) do 660 | if not cfg[entry] then 661 | cfg[entry] = {} 662 | end 663 | for k,v in pairs(defaults[entry]) do 664 | if not cfg[entry][k] then 665 | cfg[entry][k] = v 666 | end 667 | end 668 | end 669 | 670 | -- For values not set in the config file, use values from the 'defaults' table. 671 | local cfg_mt = { 672 | __index = function(t, k) 673 | local default = defaults[k] 674 | if default then 675 | rawset(t, k, default) 676 | end 677 | return default 678 | end 679 | } 680 | setmetatable(cfg, cfg_mt) 681 | 682 | if not cfg.check_certificates then 683 | cfg.variables.CURLNOCERTFLAG = "-k" 684 | cfg.variables.WGETNOCERTFLAG = "--no-check-certificate" 685 | end 686 | 687 | function cfg.make_paths_from_tree(tree) 688 | local lua_path, lib_path, bin_path 689 | if type(tree) == "string" then 690 | lua_path = tree..cfg.lua_modules_path 691 | lib_path = tree..cfg.lib_modules_path 692 | bin_path = tree.."/bin" 693 | else 694 | lua_path = tree.lua_dir or tree.root..cfg.lua_modules_path 695 | lib_path = tree.lib_dir or tree.root..cfg.lib_modules_path 696 | bin_path = tree.bin_dir or tree.root.."/bin" 697 | end 698 | return lua_path, lib_path, bin_path 699 | end 700 | 701 | function cfg.package_paths(current) 702 | local new_path, new_cpath, new_bin = {}, {}, {} 703 | local function add_tree_to_paths(tree) 704 | local lua_path, lib_path, bin_path = cfg.make_paths_from_tree(tree) 705 | table.insert(new_path, lua_path.."/?.lua") 706 | table.insert(new_path, lua_path.."/?/init.lua") 707 | table.insert(new_cpath, lib_path.."/?."..cfg.lib_extension) 708 | table.insert(new_bin, bin_path) 709 | end 710 | if current then 711 | add_tree_to_paths(current) 712 | end 713 | for _,tree in ipairs(cfg.rocks_trees) do 714 | add_tree_to_paths(tree) 715 | end 716 | if extra_luarocks_module_dir then 717 | table.insert(new_path, extra_luarocks_module_dir) 718 | end 719 | return table.concat(new_path, ";"), table.concat(new_cpath, ";"), table.concat(new_bin, cfg.export_path_separator) 720 | end 721 | 722 | function cfg.init_package_paths() 723 | local lr_path, lr_cpath, lr_bin = cfg.package_paths() 724 | package.path = util.remove_path_dupes(package.path .. ";" .. lr_path, ";") 725 | package.cpath = util.remove_path_dupes(package.cpath .. ";" .. lr_cpath, ";") 726 | end 727 | 728 | function cfg.which_config() 729 | local ret = { 730 | system = { 731 | file = sys_config_file or sys_config_file_default, 732 | ok = sys_config_ok, 733 | }, 734 | user = { 735 | file = home_config_file or home_config_file_default, 736 | ok = home_config_ok, 737 | } 738 | } 739 | ret.nearest = (ret.user.ok and ret.user.file) or ret.system.file 740 | return ret 741 | end 742 | 743 | cfg.user_agent = "LuaRocks/"..cfg.program_version.." "..cfg.arch 744 | 745 | cfg.http_proxy = os.getenv("http_proxy") 746 | cfg.https_proxy = os.getenv("https_proxy") 747 | cfg.no_proxy = os.getenv("no_proxy") 748 | 749 | --- Check if platform was detected 750 | -- @param query string: The platform name to check. 751 | -- @return boolean: true if LuaRocks is currently running on queried platform. 752 | function cfg.is_platform(query) 753 | assert(type(query) == "string") 754 | 755 | for _, platform in ipairs(cfg.platforms) do 756 | if platform == query then 757 | return true 758 | end 759 | end 760 | end 761 | 762 | return cfg 763 | -------------------------------------------------------------------------------- /lr244_install.bat_54: -------------------------------------------------------------------------------- 1 | rem=rem --[[ 2 | @setlocal& set luafile="%~f0" & if exist "%~f0.bat" set luafile="%~f0.bat" 3 | @win32\lua5.1\bin\lua5.1.exe %luafile% %*& exit /b ]] 4 | 5 | local vars = {} 6 | 7 | 8 | vars.PREFIX = nil 9 | vars.VERSION = "2.4" 10 | vars.SYSCONFDIR = nil 11 | vars.SYSCONFFORCE = nil 12 | vars.CONFBACKUPDIR = nil 13 | vars.SYSCONFFILENAME = nil 14 | vars.CONFIG_FILE = nil 15 | vars.TREE_ROOT = nil 16 | vars.TREE_BIN = nil 17 | vars.TREE_LMODULE = nil 18 | vars.TREE_CMODULE = nil 19 | vars.LUA_INTERPRETER = nil 20 | vars.LUA_PREFIX = nil 21 | vars.LUA_BINDIR = nil 22 | vars.LUA_INCDIR = nil 23 | vars.LUA_LIBDIR = nil 24 | vars.LUA_LIBNAME = nil 25 | vars.LUA_VERSION = "5.1" 26 | vars.LUA_SHORTV = nil -- "51" 27 | vars.LUA_RUNTIME = nil 28 | vars.UNAME_M = 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 37 | 38 | local FORCE = false 39 | local FORCE_CONFIG = false 40 | local INSTALL_LUA = false 41 | local USE_MINGW = false 42 | local USE_MSVC_MANUAL = false 43 | local REGISTRY = true 44 | local NOADMIN = false 45 | local PROMPT = true 46 | local SELFCONTAINED = false 47 | 48 | local lua_version_set = false 49 | 50 | --- 51 | -- Some helpers 52 | -- 53 | 54 | local pe = assert(loadfile(".\\win32\\pe-parser.lua"))() 55 | 56 | local function die(message) 57 | if message then print(message) end 58 | print() 59 | print("Failed installing LuaRocks. Run with /? for help.") 60 | os.exit(1) 61 | end 62 | 63 | local function exec(cmd) 64 | --print(cmd) 65 | local status = os.execute("type NUL && "..cmd) 66 | return (status == 0 or status == true) -- compat 5.1/5.2 67 | end 68 | 69 | local function exists(filename) 70 | local cmd = [[.\win32\tools\test -e "]]..filename..[["]] 71 | return exec(cmd) 72 | end 73 | 74 | local function mkdir (dir) 75 | return exec([[.\win32\tools\mkdir -p "]]..dir..[[" >NUL]]) 76 | end 77 | 78 | -- does the current user have admin privileges ( = elevated) 79 | local function permission() 80 | return exec("net session >NUL 2>&1") -- fails if not admin 81 | end 82 | 83 | -- rename filename (full path) to backupname (name only), appending number if required 84 | -- returns the new name (name only) 85 | local function backup(filename, backupname) 86 | local path = filename:match("(.+)%\\.-$").."\\" 87 | local nname = backupname 88 | local i = 0 89 | while exists(path..nname) do 90 | i = i + 1 91 | nname = backupname..tostring(i) 92 | end 93 | exec([[REN "]]..filename..[[" "]]..nname..[[" > NUL]]) 94 | return nname 95 | end 96 | 97 | -- interpolate string with values from 'vars' table 98 | local function S (tmpl) 99 | return (tmpl:gsub('%$([%a_][%w_]*)', vars)) 100 | end 101 | 102 | local function print_help() 103 | print(S[[ 104 | Installs LuaRocks. 105 | 106 | /P [dir] Where to install LuaRocks. 107 | Default is %PROGRAMFILES%\LuaRocks 108 | 109 | Configuring the destinations: 110 | /TREE [dir] Root of the local system tree of installed rocks. 111 | Default is {BIN}\..\ if {BIN} ends with '\bin' 112 | otherwise it is {BIN}\systree. 113 | /SCRIPTS [dir] Where to install commandline scripts installed by 114 | rocks. Default is {TREE}\bin. 115 | /LUAMOD [dir] Where to install Lua modules installed by rocks. 116 | Default is {TREE}\share\lua\{LV}. 117 | /CMOD [dir] Where to install c modules installed by rocks. 118 | Default is {TREE}\lib\lua\{LV}. 119 | /CONFIG [dir] Location where the config file should be installed. 120 | Default is to follow /P option 121 | /SELFCONTAINED Creates a self contained installation in a single 122 | directory given by /P. 123 | Sets the /TREE and /CONFIG options to the same 124 | location as /P. And does not load registry info 125 | with option /NOREG. The only option NOT self 126 | contained is the user rock tree, so don't use that 127 | if you create a self contained installation. 128 | 129 | Configuring the Lua interpreter: 130 | /LV [version] Lua version to use; either 5.1, 5.2, or 5.3. 131 | Default is auto-detected. 132 | /LUA [dir] Location where Lua is installed - e.g. c:\lua\5.1\ 133 | If not provided, the installer will search the system 134 | path and some default locations for a valid Lua 135 | installation. 136 | This is the base directory, the installer will look 137 | for subdirectories bin, lib, include. Alternatively 138 | these can be specified explicitly using the /INC, 139 | /LIB, and /BIN options. 140 | /INC [dir] Location of Lua includes - e.g. c:\lua\5.1\include 141 | If provided overrides sub directory found using /LUA. 142 | /LIB [dir] Location of Lua libraries (.dll/.lib) - e.g. c:\lua\5.1\lib 143 | If provided overrides sub directory found using /LUA. 144 | /BIN [dir] Location of Lua executables - e.g. c:\lua\5.1\bin 145 | If provided overrides sub directory found using /LUA. 146 | /L Install LuaRocks' own copy of Lua even if detected, 147 | this will always be a 5.1 installation. 148 | (/LUA, /INC, /LIB, /BIN cannot be used with /L) 149 | 150 | Compiler configuration: 151 | By default the installer will try to determine the 152 | Microsoft toolchain to use. And will automatically use 153 | a setup command to initialize that toolchain when 154 | LuaRocks is run. If it cannot find it, it will default 155 | to the /MSVC switch. 156 | /MSVC Use MS toolchain, without a setup command (tools must 157 | be in your path) 158 | /MW Use mingw as build system (tools must be in your path) 159 | 160 | Other options: 161 | /FORCECONFIG Use a single config location. Do not use the 162 | LUAROCKS_CONFIG variable or the user's home directory. 163 | Useful to avoid conflicts when LuaRocks 164 | is embedded within an application. 165 | /F Remove installation directory if it already exists. 166 | /NOREG Do not load registry info to register '.rockspec' 167 | extension with LuaRocks commands (right-click). 168 | /NOADMIN The installer requires admin privileges. If not 169 | available it will elevate a new process. Use this 170 | switch to prevent elevation, but make sure the 171 | destination paths are all accessible for the current 172 | user. 173 | /Q Do not prompt for confirmation of settings 174 | 175 | ]]) 176 | end 177 | 178 | -- *********************************************************** 179 | -- Option parser 180 | -- *********************************************************** 181 | local function parse_options(args) 182 | for _, option in ipairs(args) do 183 | local name = option.name:upper() 184 | if name == "/?" then 185 | print_help() 186 | os.exit(0) 187 | elseif name == "/P" then 188 | vars.PREFIX = option.value 189 | elseif name == "/CONFIG" then 190 | vars.SYSCONFDIR = option.value 191 | vars.SYSCONFFORCE = true 192 | elseif name == "/TREE" then 193 | vars.TREE_ROOT = option.value 194 | elseif name == "/SCRIPTS" then 195 | vars.TREE_BIN = option.value 196 | elseif name == "/LUAMOD" then 197 | vars.TREE_LMODULE = option.value 198 | elseif name == "/CMOD" then 199 | vars.TREE_CMODULE = option.value 200 | elseif name == "/LV" then 201 | vars.LUA_VERSION = option.value 202 | lua_version_set = true 203 | elseif name == "/L" then 204 | INSTALL_LUA = true 205 | elseif name == "/MW" then 206 | USE_MINGW = true 207 | elseif name == "/MSVC" then 208 | USE_MSVC_MANUAL = true 209 | elseif name == "/LUA" then 210 | vars.LUA_PREFIX = option.value 211 | elseif name == "/LIB" then 212 | vars.LUA_LIBDIR = option.value 213 | elseif name == "/INC" then 214 | vars.LUA_INCDIR = option.value 215 | elseif name == "/BIN" then 216 | vars.LUA_BINDIR = option.value 217 | elseif name == "/FORCECONFIG" then 218 | FORCE_CONFIG = true 219 | elseif name == "/F" then 220 | FORCE = true 221 | elseif name == "/SELFCONTAINED" then 222 | SELFCONTAINED = true 223 | elseif name == "/NOREG" then 224 | REGISTRY = false 225 | elseif name == "/NOADMIN" then 226 | NOADMIN = true 227 | elseif name == "/Q" then 228 | PROMPT = false 229 | else 230 | die("Unrecognized option: " .. name) 231 | end 232 | end 233 | end 234 | 235 | -- check for combination/required flags 236 | local function check_flags() 237 | if SELFCONTAINED then 238 | if not vars.PREFIX then 239 | die("Option /P is required when using /SELFCONTAINED") 240 | end 241 | if vars.SYSCONFDIR or vars.TREE_ROOT or vars.TREE_BIN or vars.TREE_LMODULE or vars.TREE_CMODULE then 242 | die("Cannot combine /TREE, /SCRIPTS, /LUAMOD, /CMOD, or /CONFIG with /SELFCONTAINED") 243 | end 244 | end 245 | if INSTALL_LUA then 246 | if vars.LUA_INCDIR or vars.LUA_BINDIR or vars.LUA_LIBDIR or vars.LUA_PREFIX then 247 | die("Cannot combine option /L with any of /LUA /BIN /LIB /INC") 248 | end 249 | if vars.LUA_VERSION ~= "5.1" then 250 | die("Bundled Lua version is 5.1, cannot install "..vars.LUA_VERSION) 251 | end 252 | end 253 | if not vars.LUA_VERSION:match("^5%.[1234]$") then 254 | die("Bad argument: /LV must either be 5.1, 5.2, or 5.3") 255 | end 256 | if USE_MSVC_MANUAL and USE_MINGW then 257 | die("Cannot combine option /MSVC and /MW") 258 | end 259 | end 260 | 261 | -- *********************************************************** 262 | -- Detect Lua 263 | -- *********************************************************** 264 | local function detect_lua_version(interpreter_path) 265 | local handler = io.popen(('type NUL && "%s" -e "io.stdout:write(_VERSION)" 2>NUL'):format(interpreter_path), "r") 266 | if not handler then 267 | return nil, "interpreter does not work" 268 | end 269 | local full_version = handler:read("*a") 270 | handler:close() 271 | 272 | local version = full_version:match(" (5%.[1234])$") 273 | if not version then 274 | return nil, "unknown interpreter version '" .. full_version .. "'" 275 | end 276 | return version 277 | end 278 | 279 | local function look_for_interpreter(directory) 280 | local names 281 | if lua_version_set then 282 | names = {S"lua$LUA_VERSION.exe", S"lua$LUA_SHORTV.exe"} 283 | else 284 | names = {"lua5.4.exe", "lua54.exe", "lua5.3.exe", "lua53.exe", "lua5.2.exe", "lua52.exe", "lua5.1.exe", "lua51.exe"} 285 | end 286 | table.insert(names, "lua.exe") 287 | table.insert(names, "luajit.exe") 288 | 289 | local directories 290 | if vars.LUA_BINDIR then 291 | -- If LUA_BINDIR is specified, look only in that directory. 292 | directories = {vars.LUA_BINDIR} 293 | else 294 | -- Try candidate directory and its `bin` subdirectory. 295 | directories = {directory, directory .. "\\bin"} 296 | end 297 | 298 | for _, dir in ipairs(directories) do 299 | for _, name in ipairs(names) do 300 | local full_name = dir .. "\\" .. name 301 | if exists(full_name) then 302 | print(" Found " .. name .. ", testing it...") 303 | local version, err = detect_lua_version(full_name) 304 | if not version then 305 | print(" Error: " .. err) 306 | else 307 | if version ~= vars.LUA_VERSION then 308 | if lua_version_set then 309 | die("Version of interpreter clashes with the value of /LV. Please check your configuration.") 310 | else 311 | vars.LUA_VERSION = version 312 | vars.LUA_SHORTV = version:gsub("%.", "") 313 | end 314 | end 315 | 316 | vars.LUA_INTERPRETER = name 317 | vars.LUA_BINDIR = dir 318 | return true 319 | end 320 | end 321 | end 322 | end 323 | 324 | if vars.LUA_BINDIR then 325 | die(("Working Lua executable (one of %s) not found in %s"):format(table.concat(names, ", "), vars.LUA_BINDIR)) 326 | end 327 | return false 328 | end 329 | 330 | local function look_for_link_libraries(directory) 331 | -- MinGW does not generate .lib, nor needs it to link, but MSVC does, 332 | -- so .lib must be listed first to ensure they are found first if present, 333 | -- to prevent MSVC trying to link to a .dll, which won't work. 334 | 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"} 335 | local directories 336 | if vars.LUA_LIBDIR then 337 | directories = {vars.LUA_LIBDIR} 338 | else 339 | directories = {directory, directory .. "\\lib", directory .. "\\bin"} 340 | end 341 | 342 | for _, dir in ipairs(directories) do 343 | for _, name in ipairs(names) do 344 | local full_name = dir .. "\\" .. name 345 | print(" checking for " .. full_name) 346 | if exists(full_name) then 347 | vars.LUA_LIBDIR = dir 348 | vars.LUA_LIBNAME = name 349 | print(" Found " .. name) 350 | return true 351 | end 352 | end 353 | end 354 | 355 | if vars.LUA_LIBDIR then 356 | die(("Link library (one of %s) not found in %s"):format(table.concat(names, ", "), vars.LUA_LIBDIR)) 357 | end 358 | return false 359 | end 360 | 361 | local function look_for_headers(directory) 362 | local directories 363 | if vars.LUA_INCDIR then 364 | directories = {vars.LUA_INCDIR} 365 | else 366 | directories = { 367 | directory .. S"\\include\\lua\\$LUA_VERSION", 368 | directory .. S"\\include\\lua$LUA_SHORTV", 369 | directory .. S"\\include\\lua$LUA_VERSION", 370 | directory .. "\\include", 371 | directory 372 | } 373 | end 374 | 375 | for _, dir in ipairs(directories) do 376 | local full_name = dir .. "\\lua.h" 377 | print(" checking for " .. full_name) 378 | if exists(full_name) then 379 | vars.LUA_INCDIR = dir 380 | print(" Found lua.h") 381 | return true 382 | end 383 | end 384 | 385 | if vars.LUA_INCDIR then 386 | die(S"lua.h not found in $LUA_INCDIR") 387 | end 388 | return false 389 | end 390 | 391 | 392 | local function get_runtime() 393 | local f 394 | vars.LUA_RUNTIME, f = pe.msvcrt(vars.LUA_BINDIR.."\\"..vars.LUA_INTERPRETER) 395 | if type(vars.LUA_RUNTIME) ~= "string" then 396 | -- analysis failed, issue a warning 397 | vars.LUA_RUNTIME = "MSVCR80" 398 | print("*** WARNING ***: could not analyse the runtime used, defaulting to "..vars.LUA_RUNTIME) 399 | else 400 | print(" "..f.." uses "..vars.LUA_RUNTIME..".DLL as runtime") 401 | end 402 | return true 403 | end 404 | 405 | local function get_architecture() 406 | -- detect processor arch interpreter was compiled for 407 | local proc = (pe.parse(vars.LUA_BINDIR.."\\"..vars.LUA_INTERPRETER) or {}).Machine 408 | if not proc then 409 | die("Could not detect processor architecture used in "..vars.LUA_INTERPRETER) 410 | end 411 | proc = pe.const.Machine[proc] -- collect name from constant value 412 | if proc == "IMAGE_FILE_MACHINE_I386" then 413 | proc = "x86" 414 | else 415 | proc = "x86_64" 416 | end 417 | return proc 418 | end 419 | 420 | -- get a string value from windows registry. 421 | local function get_registry(key, value) 422 | local keys = {key} 423 | local key64, replaced = key:gsub("(%u+\\Software\\)", "%1Wow6432Node\\", 1) 424 | 425 | if replaced == 1 then 426 | keys = {key64, key} 427 | end 428 | 429 | for _, k in ipairs(keys) do 430 | local h = io.popen('reg query "'..k..'" /v '..value..' 2>NUL') 431 | local output = h:read("*a") 432 | h:close() 433 | 434 | local v = output:match("REG_SZ%s+([^\n]+)") 435 | if v then 436 | return v 437 | end 438 | end 439 | return nil 440 | end 441 | 442 | local function get_visual_studio_directory() 443 | assert(type(vars.LUA_RUNTIME)=="string", "requires vars.LUA_RUNTIME to be set before calling this function.") 444 | local major, minor = vars.LUA_RUNTIME:match('VCR%u*(%d+)(%d)$') -- MSVCR or VCRUNTIME 445 | if not major then 446 | print(S[[ Cannot auto-detect Visual Studio version from $LUA_RUNTIME]]) 447 | return nil 448 | end 449 | local keys = { 450 | "HKLM\\Software\\Microsoft\\VisualStudio\\%d.%d\\Setup\\VC", 451 | "HKLM\\Software\\Microsoft\\VCExpress\\%d.%d\\Setup\\VS" 452 | } 453 | for _, key in ipairs(keys) do 454 | local versionedkey = key:format(major, minor) 455 | local vcdir = get_registry(versionedkey, "ProductDir") 456 | print(" checking: "..versionedkey) 457 | if vcdir then 458 | print(" Found: "..vcdir) 459 | return vcdir 460 | end 461 | end 462 | return nil 463 | end 464 | 465 | local function get_windows_sdk_directory() 466 | assert(type(vars.LUA_RUNTIME) == "string", "requires vars.LUA_RUNTIME to be set before calling this function.") 467 | -- Only v7.1 and v6.1 shipped with compilers 468 | -- Other versions requires a separate installation of Visual Studio. 469 | -- see https://github.com/luarocks/luarocks/pull/443#issuecomment-152792516 470 | local wsdks = { 471 | ["MSVCR100"] = "v7.1", -- shipped with Visual Studio 2010 compilers. 472 | ["MSVCR100D"] = "v7.1", -- shipped with Visual Studio 2010 compilers. 473 | ["MSVCR90"] = "v6.1", -- shipped with Visual Studio 2008 compilers. 474 | ["MSVCR90D"] = "v6.1", -- shipped with Visual Studio 2008 compilers. 475 | } 476 | local wsdkver = wsdks[vars.LUA_RUNTIME] 477 | if not wsdkver then 478 | print(S[[ Cannot auto-detect Windows SDK version from $LUA_RUNTIME]]) 479 | return nil 480 | end 481 | 482 | local key = "HKLM\\Software\\Microsoft\\Microsoft SDKs\\Windows\\"..wsdkver 483 | print(" checking: "..key) 484 | local dir = get_registry(key, "InstallationFolder") 485 | if dir then 486 | print(" Found: "..dir) 487 | return dir 488 | end 489 | print(" No SDK found") 490 | return nil 491 | end 492 | 493 | -- returns the batch command to setup msvc compiler path. 494 | -- or an empty string (eg. "") if not found 495 | local function get_msvc_env_setup_cmd() 496 | print(S[[Looking for Microsoft toolchain matching runtime $LUA_RUNTIME and architecture $UNAME_M]]) 497 | 498 | assert(type(vars.UNAME_M) == "string", "requires vars.UNAME_M to be set before calling this function.") 499 | local x64 = vars.UNAME_M=="x86_64" 500 | 501 | -- 1. try visual studio command line tools 502 | local vcdir = get_visual_studio_directory() 503 | if vcdir then 504 | local vcvars_bats = { 505 | x86 = { 506 | "bin\\vcvars32.bat", -- prefers native compiler 507 | "bin\\amd64_x86\\vcvarsamd64_x86.bat"-- then cross compiler 508 | }, 509 | x86_64 = { 510 | "bin\\amd64\\vcvars64.bat", -- prefers native compiler 511 | "bin\\x86_amd64\\vcvarsx86_amd64.bat" -- then cross compiler 512 | } 513 | } 514 | assert(vcvars_bats[vars.UNAME_M], "vars.UNAME_M: only x86 and x86_64 are supported") 515 | for _, bat in ipairs(vcvars_bats[vars.UNAME_M]) do 516 | local full_path = vcdir .. bat 517 | if exists(full_path) then 518 | return ('call "%s"'):format(full_path) 519 | end 520 | end 521 | 522 | -- try vcvarsall.bat in case MS changes the undocumented bat files above. 523 | -- but this way we don't konw if specified compiler is installed... 524 | local vcvarsall = vcdir .. 'vcvarsall.bat' 525 | if exists(vcvarsall) then 526 | local vcvarsall_args = { x86 = "", x86_64 = " amd64" } 527 | return ('call "%s"%s'):format(vcvarsall, vcvarsall_args[vars.UNAME_M]) 528 | end 529 | end 530 | 531 | -- 2. try for Windows SDKs command line tools. 532 | local wsdkdir = get_windows_sdk_directory() 533 | if wsdkdir then 534 | local setenv = wsdkdir.."Bin\\SetEnv.cmd" 535 | if exists(setenv) then 536 | return ('call "%s" /%s'):format(setenv, x64 and "x64" or "x86") 537 | end 538 | end 539 | 540 | -- finally, we can't detect more, just don't setup the msvc compiler in luarocks.bat. 541 | return "" 542 | end 543 | 544 | local function get_possible_lua_directories() 545 | if vars.LUA_PREFIX then 546 | return {vars.LUA_PREFIX} 547 | end 548 | 549 | -- No prefix given, so use PATH. 550 | local path = os.getenv("PATH") or "" 551 | local directories = {} 552 | for dir in path:gmatch("[^;]+") do 553 | -- Remove trailing backslashes, but not from a drive letter like `C:\`. 554 | dir = dir:gsub("([^:])\\+$", "%1") 555 | -- Remove trailing `bin` subdirectory, the searcher will check there anyway. 556 | if dir:upper():match("[:\\]BIN$") then 557 | dir = dir:sub(1, -5) 558 | end 559 | table.insert(directories, dir) 560 | end 561 | -- Finally add some other default paths. 562 | table.insert(directories, [[c:\lua5.1.2]]) 563 | table.insert(directories, [[c:\lua]]) 564 | table.insert(directories, [[c:\kepler\1.1]]) 565 | return directories 566 | end 567 | 568 | local function look_for_lua_install () 569 | print("Looking for Lua interpreter") 570 | if vars.LUA_BINDIR and vars.LUA_LIBDIR and vars.LUA_INCDIR then 571 | if look_for_interpreter(vars.LUA_BINDIR) and 572 | look_for_link_libraries(vars.LUA_LIBDIR) and 573 | look_for_headers(vars.LUA_INCDIR) 574 | then 575 | if get_runtime() then 576 | print("Runtime check completed.") 577 | return true 578 | end 579 | end 580 | return false 581 | end 582 | 583 | for _, directory in ipairs(get_possible_lua_directories()) do 584 | print(" checking " .. directory) 585 | if exists(directory) then 586 | if look_for_interpreter(directory) then 587 | print("Interpreter found, now looking for link libraries...") 588 | if look_for_link_libraries(directory) then 589 | print("Link library found, now looking for headers...") 590 | if look_for_headers(directory) then 591 | print("Headers found, checking runtime to use...") 592 | if get_runtime() then 593 | print("Runtime check completed.") 594 | return true 595 | end 596 | end 597 | end 598 | end 599 | end 600 | end 601 | return false 602 | end 603 | 604 | -- backup config[x.x].lua[.bak] and site_config[_x_x].lua 605 | local function backup_config_files() 606 | local temppath 607 | while not temppath do 608 | temppath = os.getenv("temp").."\\LR-config-backup-"..tostring(math.random(10000)) 609 | if exists(temppath) then temppath = nil end 610 | end 611 | vars.CONFBACKUPDIR = temppath 612 | mkdir(vars.CONFBACKUPDIR) 613 | exec(S[[COPY "$PREFIX\config*.*" "$CONFBACKUPDIR" >NUL]]) 614 | exec(S[[COPY "$PREFIX\lua\luarocks\site_config*.*" "$CONFBACKUPDIR" >NUL]]) 615 | end 616 | 617 | -- restore previously backed up config files 618 | local function restore_config_files() 619 | if not vars.CONFBACKUPDIR then return end -- there is no backup to restore 620 | exec(S[[COPY "$CONFBACKUPDIR\config*.*" "$PREFIX" >NUL]]) 621 | exec(S[[COPY "$CONFBACKUPDIR\site_config*.*" "$PREFIX\lua\luarocks" >NUL]]) 622 | -- cleanup 623 | exec(S[[RD /S /Q "$CONFBACKUPDIR"]]) 624 | vars.CONFBACKUPDIR = nil 625 | end 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 | 687 | -- *********************************************************** 688 | -- Installer script start 689 | -- *********************************************************** 690 | 691 | -- Poor man's command-line parsing 692 | local config = {} 693 | local with_arg = { -- options followed by an argument, others are flags 694 | ["/P"] = true, 695 | ["/CONFIG"] = true, 696 | ["/TREE"] = true, 697 | ["/SCRIPTS"] = true, 698 | ["/LUAMOD"] = true, 699 | ["/CMOD"] = true, 700 | ["/LV"] = true, 701 | ["/LUA"] = true, 702 | ["/INC"] = true, 703 | ["/BIN"] = true, 704 | ["/LIB"] = true, 705 | } 706 | -- reconstruct argument values with spaces and double quotes 707 | -- this will be damaged by the batch construction at the start of this file 708 | local oarg = arg -- retain old table 709 | if #arg > 0 then 710 | local farg = table.concat(arg, " ") .. " " 711 | arg = {} 712 | farg = farg:gsub('%"', "") 713 | local i = 0 714 | while #farg>0 do 715 | i = i + 1 716 | if (farg:sub(1,1) ~= "/") and ((arg[i-1] or ""):sub(1,1) ~= "/") then 717 | i = i - 1 -- continued previous arg 718 | if i == 0 then i = 1 end 719 | end 720 | if arg[i] then 721 | arg[i] = arg[i] .. " " 722 | else 723 | arg[i] = "" 724 | end 725 | local v,r = farg:match("^(.-)%s(.*)$") 726 | arg[i], farg = arg[i]..v, r 727 | while farg:sub(1,1) == " " do farg = farg:sub(2,-1) end -- remove prefix spaces 728 | end 729 | end 730 | for k,v in pairs(oarg) do if k < 1 then arg[k] = v end end -- copy 0 and negative indexes 731 | 732 | -- build config option table with name and value elements 733 | local i = 1 734 | while i <= #arg do 735 | local opt = arg[i] 736 | if with_arg[opt:upper()] then 737 | local value = arg[i + 1] 738 | if not value then 739 | die("Missing value for option "..opt) 740 | end 741 | config[#config + 1] = { name = opt, value = value } 742 | i = i + 1 743 | else 744 | config[#config + 1] = { name = opt } 745 | end 746 | i = i + 1 747 | end 748 | 749 | print(S"LuaRocks $VERSION.x installer.\n") 750 | 751 | parse_options(config) 752 | 753 | print([[ 754 | 755 | ======================== 756 | == Checking system... == 757 | ======================== 758 | 759 | ]]) 760 | 761 | check_flags() 762 | 763 | if not permission() then 764 | if not NOADMIN then 765 | -- must elevate the process with admin privileges 766 | if not exec("PowerShell /? >NUL 2>&1") then 767 | -- powershell is not available, so error out 768 | die("No administrative privileges detected and cannot auto-elevate. Please run with admin privileges or use the /NOADMIN switch") 769 | end 770 | print("Need admin privileges, now elevating a new process to continue installing...") 771 | local runner = os.getenv("TEMP").."\\".."LuaRocks_Installer.bat" 772 | local f = io.open(runner, "w") 773 | f:write("@echo off\n") 774 | f:write("CHDIR /D "..arg[0]:match("(.+)%\\.-$").."\n") -- return to current dir, elevation changes current path 775 | f:write('"'..arg[-1]..'" "'..table.concat(arg, '" "', 0)..'"\n') 776 | f:write("ECHO Press any key to close this window...\n") 777 | f:write("PAUSE > NUL\n") 778 | f:write('DEL "'..runner..'"') -- temp batch file deletes itself 779 | f:close() 780 | -- run the created temp batch file in elevated mode 781 | exec("PowerShell -Command (New-Object -com 'Shell.Application').ShellExecute('"..runner.."', '', '', 'runas')\n") 782 | print("Now exiting unprivileged installer") 783 | os.exit() -- exit here, the newly created elevated process will do the installing 784 | else 785 | print("Attempting to install without admin privileges...") 786 | end 787 | else 788 | print("Admin privileges available for installing") 789 | end 790 | 791 | vars.PREFIX = vars.PREFIX or os.getenv("PROGRAMFILES")..[[\LuaRocks]] 792 | vars.BINDIR = vars.PREFIX 793 | vars.LIBDIR = vars.PREFIX 794 | vars.LUADIR = S"$PREFIX\\lua" 795 | vars.INCDIR = S"$PREFIX\\include" 796 | vars.LUA_SHORTV = vars.LUA_VERSION:gsub("%.", "") 797 | 798 | if INSTALL_LUA then 799 | vars.LUA_INTERPRETER = "lua5.1" 800 | vars.LUA_BINDIR = vars.BINDIR 801 | vars.LUA_LIBDIR = vars.LIBDIR 802 | vars.LUA_INCDIR = vars.INCDIR 803 | vars.LUA_LIBNAME = "lua5.1.lib" 804 | vars.LUA_RUNTIME = "MSVCR80" 805 | vars.UNAME_M = "x86" 806 | else 807 | if not look_for_lua_install() then 808 | die("Could not find Lua. See /? for options for specifying the location of Lua, or installing a bundled copy of Lua 5.1.") 809 | end 810 | vars.UNAME_M = get_architecture() -- can only do when installation was found 811 | end 812 | 813 | -- check location of system tree 814 | if not vars.TREE_ROOT then 815 | -- no system tree location given, so we need to construct a default value 816 | if vars.LUA_BINDIR:lower():match([[([\/]+bin[\/]*)$]]) then 817 | -- lua binary is located in a 'bin' subdirectory, so assume 818 | -- default Lua layout and match rocktree on top 819 | vars.TREE_ROOT = vars.LUA_BINDIR:lower():gsub([[[\/]+bin[\/]*$]], [[\]]) 820 | else 821 | -- no 'bin', so use a named tree next to the Lua executable 822 | vars.TREE_ROOT = vars.LUA_BINDIR .. [[\systree]] 823 | end 824 | end 825 | 826 | vars.SYSCONFDIR = vars.SYSCONFDIR or vars.PREFIX 827 | vars.SYSCONFFILENAME = S"config-$LUA_VERSION.lua" 828 | vars.CONFIG_FILE = vars.SYSCONFDIR.."\\"..vars.SYSCONFFILENAME 829 | if SELFCONTAINED then 830 | vars.SYSCONFDIR = vars.PREFIX 831 | vars.SYSCONFFORCE = true 832 | vars.TREE_ROOT = vars.PREFIX..[[\systree]] 833 | REGISTRY = false 834 | end 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 844 | 845 | print(S[[ 846 | 847 | ========================== 848 | == System check results == 849 | ========================== 850 | 851 | Will configure LuaRocks with the following paths: 852 | LuaRocks : $PREFIX 853 | Config file : $CONFIG_FILE 854 | Rocktree : $TREE_ROOT 855 | 856 | Lua interpreter : $LUA_BINDIR\$LUA_INTERPRETER 857 | binaries : $LUA_BINDIR 858 | libraries : $LUA_LIBDIR 859 | includes : $LUA_INCDIR 860 | architecture: $UNAME_M 861 | binary link : $LUA_LIBNAME with runtime $LUA_RUNTIME.dll 862 | ]]) 863 | 864 | if USE_MINGW then 865 | print(S[[Compiler : MinGW/gcc (make sure it is in your path before using LuaRocks)]]) 866 | print(S[[ in: $MINGW_BIN_PATH]]) 867 | else 868 | if vars.COMPILER_ENV_CMD == "" then 869 | print("Compiler : Microsoft (make sure it is in your path before using LuaRocks)") 870 | else 871 | print(S[[Compiler : Microsoft, using; $COMPILER_ENV_CMD]]) 872 | end 873 | end 874 | 875 | if PROMPT then 876 | print("\nPress to start installing, or press + to abort. Use install /? for installation options.") 877 | io.read() 878 | end 879 | 880 | print([[ 881 | 882 | ============================ 883 | == Installing LuaRocks... == 884 | ============================ 885 | 886 | ]]) 887 | 888 | -- *********************************************************** 889 | -- Install LuaRocks files 890 | -- *********************************************************** 891 | 892 | if exists(vars.PREFIX) then 893 | if not FORCE then 894 | die(S"$PREFIX exists. Use /F to force removal and reinstallation.") 895 | else 896 | backup_config_files() 897 | print(S"Removing $PREFIX...") 898 | exec(S[[RD /S /Q "$PREFIX"]]) 899 | print() 900 | end 901 | end 902 | 903 | print(S"Installing LuaRocks in $PREFIX...") 904 | if not exists(vars.BINDIR) then 905 | if not mkdir(vars.BINDIR) then 906 | die() 907 | end 908 | end 909 | 910 | if INSTALL_LUA then 911 | -- Copy the included Lua interpreter binaries 912 | if not exists(vars.LUA_BINDIR) then 913 | mkdir(vars.LUA_BINDIR) 914 | end 915 | if not exists(vars.LUA_INCDIR) then 916 | mkdir(vars.LUA_INCDIR) 917 | end 918 | exec(S[[COPY win32\lua5.1\bin\*.* "$LUA_BINDIR" >NUL]]) 919 | exec(S[[COPY win32\lua5.1\include\*.* "$LUA_INCDIR" >NUL]]) 920 | print(S"Installed the LuaRocks bundled Lua interpreter in $LUA_BINDIR") 921 | end 922 | 923 | -- Copy the LuaRocks binaries 924 | if not exists(S[[$BINDIR\tools]]) then 925 | if not mkdir(S[[$BINDIR\tools]]) then 926 | die() 927 | end 928 | end 929 | if not exec(S[[COPY win32\tools\*.* "$BINDIR\tools" >NUL]]) then 930 | die() 931 | end 932 | -- Copy LR bin helper files 933 | if not exec(S[[COPY win32\*.* "$BINDIR" >NUL]]) then 934 | die() 935 | end 936 | -- Copy the LuaRocks lua source files 937 | if not exists(S[[$LUADIR\luarocks]]) then 938 | if not mkdir(S[[$LUADIR\luarocks]]) then 939 | die() 940 | end 941 | end 942 | if not exec(S[[XCOPY /S src\luarocks\*.* "$LUADIR\luarocks" >NUL]]) then 943 | die() 944 | end 945 | -- Create start scripts 946 | if not exec(S[[COPY src\bin\*.* "$BINDIR" >NUL]]) then 947 | die() 948 | end 949 | for _, c in ipairs{"luarocks", "luarocks-admin"} do 950 | -- rename unix-lua scripts to .lua files 951 | if not exec( (S[[RENAME "$BINDIR\%s" %s.lua]]):format(c, c) ) then 952 | die() 953 | end 954 | -- create a bootstrap batch file for the lua file, to start them 955 | exec(S[[DEL /F /Q "$BINDIR\]]..c..[[.bat" 2>NUL]]) 956 | local f = io.open(vars.BINDIR.."\\"..c..".bat", "w") 957 | f:write(S[[ 958 | @ECHO OFF 959 | SETLOCAL ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS 960 | $COMPILER_ENV_CMD 961 | SET "LUA_PATH=$LUADIR\?.lua;$LUADIR\?\init.lua;%LUA_PATH%" 962 | IF NOT "%LUA_PATH_5_2%"=="" ( 963 | SET "LUA_PATH_5_2=$LUADIR\?.lua;$LUADIR\?\init.lua;%LUA_PATH_5_2%" 964 | ) 965 | IF NOT "%LUA_PATH_5_3%"=="" ( 966 | SET "LUA_PATH_5_3=$LUADIR\?.lua;$LUADIR\?\init.lua;%LUA_PATH_5_3%" 967 | ) 968 | IF NOT "%LUA_PATH_5_4%"=="" ( 969 | SET "LUA_PATH_5_4=$LUADIR\?.lua;$LUADIR\?\init.lua;%LUA_PATH_5_4%" 970 | ) 971 | SET "PATH=$BINDIR;%PATH%" 972 | "$LUA_BINDIR\$LUA_INTERPRETER" "$BINDIR\]]..c..[[.lua" %* 973 | SET EXITCODE=%ERRORLEVEL% 974 | IF NOT "%EXITCODE%"=="2" GOTO EXITLR 975 | 976 | REM Permission denied error, try and auto elevate... 977 | REM already an admin? (checking to prevent loops) 978 | NET SESSION >NUL 2>&1 979 | IF "%ERRORLEVEL%"=="0" GOTO EXITLR 980 | 981 | REM Do we have PowerShell available? 982 | PowerShell /? >NUL 2>&1 983 | IF NOT "%ERRORLEVEL%"=="0" GOTO EXITLR 984 | 985 | :GETTEMPNAME 986 | SET TMPFILE=%TEMP%\LuaRocks-Elevator-%RANDOM%.bat 987 | IF EXIST "%TMPFILE%" GOTO :GETTEMPNAME 988 | 989 | ECHO @ECHO OFF > "%TMPFILE%" 990 | ECHO CHDIR /D %CD% >> "%TMPFILE%" 991 | ECHO ECHO %0 %* >> "%TMPFILE%" 992 | ECHO ECHO. >> "%TMPFILE%" 993 | ECHO CALL %0 %* >> "%TMPFILE%" 994 | ECHO ECHO. >> "%TMPFILE%" 995 | ECHO ECHO Press any key to close this window... >> "%TMPFILE%" 996 | ECHO PAUSE ^> NUL >> "%TMPFILE%" 997 | ECHO DEL "%TMPFILE%" >> "%TMPFILE%" 998 | 999 | ECHO Now retrying as a privileged user... 1000 | PowerShell -Command (New-Object -com 'Shell.Application').ShellExecute('%TMPFILE%', '', '', 'runas') 1001 | 1002 | :EXITLR 1003 | exit /b %EXITCODE% 1004 | ]]) 1005 | f:close() 1006 | print(S"Created LuaRocks command: $BINDIR\\"..c..".bat") 1007 | end 1008 | 1009 | -- *********************************************************** 1010 | -- Configure LuaRocks 1011 | -- *********************************************************** 1012 | 1013 | restore_config_files() 1014 | print() 1015 | print("Configuring LuaRocks...") 1016 | 1017 | -- Create a site-config file 1018 | local site_config = S("site_config_$LUA_VERSION"):gsub("%.","_") 1019 | if exists(S([[$LUADIR\luarocks\]]..site_config..[[.lua]])) then 1020 | local nname = backup(S([[$LUADIR\luarocks\]]..site_config..[[.lua]]), site_config..".lua.bak") 1021 | print("***************") 1022 | print("*** WARNING *** LuaRocks site_config file already exists: '"..site_config..".lua'. The old file has been renamed to '"..nname.."'") 1023 | print("***************") 1024 | end 1025 | local f = io.open(vars.LUADIR.."\\luarocks\\"..site_config..".lua", "w") 1026 | f:write(S[=[ 1027 | local site_config = {} 1028 | site_config.LUA_INCDIR=[[$LUA_INCDIR]] 1029 | site_config.LUA_LIBDIR=[[$LUA_LIBDIR]] 1030 | site_config.LUA_BINDIR=[[$LUA_BINDIR]] 1031 | site_config.LUA_INTERPRETER=[[$LUA_INTERPRETER]] 1032 | ]=]) 1033 | if USE_MINGW then 1034 | f:write("site_config.LUAROCKS_UNAME_S=[[MINGW]]\n") 1035 | else 1036 | f:write("site_config.LUAROCKS_UNAME_S=[[WindowsNT]]\n") 1037 | end 1038 | f:write(S[=[ 1039 | site_config.LUAROCKS_UNAME_M=[[$UNAME_M]] 1040 | site_config.LUAROCKS_ROCKS_TREE=[[$TREE_ROOT]] 1041 | site_config.LUAROCKS_PREFIX=[[$PREFIX]] 1042 | site_config.LUAROCKS_DOWNLOADER=[[wget]] 1043 | site_config.LUAROCKS_MD5CHECKER=[[md5sum]] 1044 | ]=]) 1045 | if FORCE_CONFIG then 1046 | f:write("site_config.LUAROCKS_FORCE_CONFIG=true\n") 1047 | end 1048 | if vars.SYSCONFFORCE then -- only write this value when explcitly given, otherwise rely on defaults 1049 | f:write(S("site_config.LUAROCKS_SYSCONFDIR=[[$SYSCONFDIR]]\n")) 1050 | end 1051 | f:write("return site_config\n") 1052 | f:close() 1053 | print(S([[Created LuaRocks site-config file: $LUADIR\luarocks\]]..site_config..[[.lua]])) 1054 | 1055 | -- create config file 1056 | if not exists(vars.SYSCONFDIR) then 1057 | mkdir(vars.SYSCONFDIR) 1058 | end 1059 | if exists(vars.CONFIG_FILE) then 1060 | local nname = backup(vars.CONFIG_FILE, vars.SYSCONFFILENAME..".bak") 1061 | print("***************") 1062 | print(S"*** WARNING *** LuaRocks config file already exists: '$CONFIG_FILE'. The old file has been renamed to '"..nname.."'") 1063 | print("***************") 1064 | end 1065 | local f = io.open(vars.CONFIG_FILE, "w") 1066 | f:write([=[ 1067 | rocks_trees = { 1068 | ]=]) 1069 | if FORCE_CONFIG then 1070 | f:write(" home..[[/luarocks]],\n") 1071 | end 1072 | f:write(S" { name = [[user]],\n") 1073 | f:write(S" root = home..[[/luarocks]],\n") 1074 | f:write(S" },\n") 1075 | f:write(S" { name = [[system]],\n") 1076 | f:write(S" root = [[$TREE_ROOT]],\n") 1077 | if vars.TREE_BIN then 1078 | f:write(S" bin_dir = [[$TREE_BIN]],\n") 1079 | end 1080 | if vars.TREE_CMODULE then 1081 | f:write(S" lib_dir = [[$TREE_CMODULE]],\n") 1082 | end 1083 | if vars.TREE_LMODULE then 1084 | f:write(S" lua_dir = [[$TREE_LMODULE]],\n") 1085 | end 1086 | f:write(S" },\n") 1087 | f:write("}\n") 1088 | f:write("variables = {\n") 1089 | if USE_MINGW and vars.LUA_RUNTIME == "MSVCRT" then 1090 | f:write(" MSVCRT = 'm', -- make MinGW use MSVCRT.DLL as runtime\n") 1091 | else 1092 | f:write(" MSVCRT = '"..vars.LUA_RUNTIME.."',\n") 1093 | end 1094 | f:write(S" LUALIB = '$LUA_LIBNAME',\n") 1095 | if USE_MINGW then 1096 | f:write(S[[ 1097 | CC = $MINGW_CC, 1098 | MAKE = $MINGW_MAKE, 1099 | RC = $MINGW_RC, 1100 | LD = $MINGW_LD, 1101 | AR = $MINGW_AR, 1102 | RANLIB = $MINGW_RANLIB, 1103 | ]]) 1104 | end 1105 | f:write("}\n") 1106 | f:write("verbose = false -- set to 'true' to enable verbose output\n") 1107 | f:close() 1108 | 1109 | print(S"Created LuaRocks config file: $CONFIG_FILE") 1110 | 1111 | 1112 | print() 1113 | print("Creating rocktrees...") 1114 | if not exists(vars.TREE_ROOT) then 1115 | mkdir(vars.TREE_ROOT) 1116 | print(S[[Created system rocktree : "$TREE_ROOT"]]) 1117 | else 1118 | print(S[[System rocktree exists : "$TREE_ROOT"]]) 1119 | end 1120 | 1121 | vars.APPDATA = os.getenv("APPDATA") 1122 | vars.LOCAL_TREE = vars.APPDATA..[[\LuaRocks]] 1123 | if not exists(vars.LOCAL_TREE) then 1124 | mkdir(vars.LOCAL_TREE) 1125 | print(S[[Created local user rocktree: "$LOCAL_TREE"]]) 1126 | else 1127 | print(S[[Local user rocktree exists : "$LOCAL_TREE"]]) 1128 | end 1129 | 1130 | -- Load registry information 1131 | if REGISTRY then 1132 | -- expand template with correct path information 1133 | print() 1134 | print([[Loading registry information for ".rockspec" files]]) 1135 | exec( S[[win32\lua5.1\bin\lua5.1.exe "$PREFIX\LuaRocks.reg.lua" "$PREFIX\LuaRocks.reg.template"]] ) 1136 | exec( S[[regedit /S "$PREFIX\\LuaRocks.reg"]] ) 1137 | end 1138 | 1139 | -- *********************************************************** 1140 | -- Cleanup 1141 | -- *********************************************************** 1142 | -- remove regsitry related files, no longer needed 1143 | exec( S[[del "$PREFIX\LuaRocks.reg.*" >NUL]] ) 1144 | -- remove pe-parser module 1145 | exec( S[[del "$PREFIX\pe-parser.lua" >NUL]] ) 1146 | 1147 | -- *********************************************************** 1148 | -- Exit handlers 1149 | -- *********************************************************** 1150 | vars.TREE_BIN = vars.TREE_BIN or vars.TREE_ROOT..[[\bin]] 1151 | vars.TREE_LMODULE = vars.TREE_LMODULE or vars.TREE_ROOT..[[\share\lua\]]..vars.LUA_VERSION 1152 | vars.TREE_CMODULE = vars.TREE_CMODULE or vars.TREE_ROOT..[[\lib\lua\]]..vars.LUA_VERSION 1153 | print(S[[ 1154 | 1155 | ============================ 1156 | == LuaRocks is installed! == 1157 | ============================ 1158 | 1159 | 1160 | You may want to add the following elements to your paths; 1161 | Lua interpreter; 1162 | PATH : $LUA_BINDIR 1163 | PATHEXT : .LUA 1164 | LuaRocks; 1165 | PATH : $PREFIX 1166 | LUA_PATH : $PREFIX\lua\?.lua;$PREFIX\lua\?\init.lua 1167 | Local user rocktree (Note: %APPDATA% is user dependent); 1168 | PATH : %APPDATA%\LuaRocks\bin 1169 | LUA_PATH : %APPDATA%\LuaRocks\share\lua\$LUA_VERSION\?.lua;%APPDATA%\LuaRocks\share\lua\$LUA_VERSION\?\init.lua 1170 | LUA_CPATH: %APPDATA%\LuaRocks\lib\lua\$LUA_VERSION\?.dll 1171 | System rocktree 1172 | PATH : $TREE_BIN 1173 | LUA_PATH : $TREE_LMODULE\?.lua;$TREE_LMODULE\?\init.lua 1174 | LUA_CPATH: $TREE_CMODULE\?.dll 1175 | 1176 | Note that the %APPDATA% element in the paths above is user specific and it MUST be replaced by its actual value. 1177 | For the current user that value is: $APPDATA. 1178 | 1179 | ]]) 1180 | os.exit(0) 1181 | -------------------------------------------------------------------------------- /make.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | SETLOCAL 3 | 4 | REM __NOTE__: Some additional customizations in 'scripts\download.bat' 5 | 6 | REM Target locations for Lua 7 | SET TARGET= 8 | SET COMPAT= 9 | SET ALLVERSIONS=TRUE 10 | SET VERSION51= 11 | SET VERSION52= 12 | SET VERSION53= 13 | SET VERSION54= 14 | SET CLEAN= 15 | SET CLEANTARGET= 16 | SET DEFAULT= 17 | SET TOOLCHAIN= 18 | SET LRCOMPILER= 19 | 20 | :HandleParameter 21 | IF [%1]==[] GOTO Continue 22 | IF [%1]==[--help] GOTO Help 23 | IF [%1]==[-help] GOTO Help 24 | IF [%1]==[help] GOTO Help 25 | IF [%1]==[--?] GOTO Help 26 | IF [%1]==[-?] GOTO Help 27 | IF [%1]==[?] GOTO Help 28 | IF [%1]==[/?] GOTO Help 29 | 30 | if [%1]==[--clean] ( 31 | set CLEAN=--clean 32 | SHIFT 33 | GOTO HandleParameter 34 | ) 35 | if [%1]==[--cleantarget] ( 36 | set CLEANTARGET=--clean 37 | SHIFT 38 | GOTO HandleParameter 39 | ) 40 | if [%1]==[--nocompat] ( 41 | set COMPAT=--nocompat 42 | SHIFT 43 | GOTO HandleParameter 44 | ) 45 | if [%1]==[--gcc] ( 46 | set TOOLCHAIN=GCC 47 | SHIFT 48 | GOTO HandleParameter 49 | ) 50 | if [%1]==[--ms] ( 51 | set TOOLCHAIN=MS 52 | SHIFT 53 | GOTO HandleParameter 54 | ) 55 | if [%1]==[--51] ( 56 | set ALLVERSIONS= 57 | set VERSION51=%1 58 | if [%DEFAULT%]==[] SET DEFAULT=51 59 | SHIFT 60 | GOTO HandleParameter 61 | ) 62 | if [%1]==[--52] ( 63 | set ALLVERSIONS= 64 | set VERSION52=%1 65 | if [%DEFAULT%]==[] SET DEFAULT=52 66 | SHIFT 67 | GOTO HandleParameter 68 | ) 69 | if [%1]==[--53] ( 70 | set ALLVERSIONS= 71 | set VERSION53=%1 72 | if [%DEFAULT%]==[] SET DEFAULT=53 73 | SHIFT 74 | GOTO HandleParameter 75 | ) 76 | if [%1]==[--54] ( 77 | set ALLVERSIONS= 78 | set VERSION54=%1 79 | if [%DEFAULT%]==[] SET DEFAULT=54 80 | SHIFT 81 | GOTO HandleParameter 82 | ) 83 | if [%1]==[install] ( 84 | if [%2]==[] ( 85 | SHIFT 86 | SET TARGET=C:\Lua 87 | GOTO Continue 88 | ) 89 | SET TARGET=%~2 90 | if [%3]==[] GOTO Continue 91 | echo Error: 'install' must be the final option on the commandline, '%3' is not allowed here. 92 | exit /b 1 93 | ) 94 | 95 | echo Error handling commandline option '%1'. Use '--help' for usage information. 96 | echo. 97 | exit /b 1 98 | 99 | :Help 100 | echo Commandline script to download and install Lua 5.1, 5.2, 5.3, and 5.4 with a LuaRocks installation for each. 101 | echo A 'setlua' script is made available to setup the environment for each version. 102 | echo. 103 | echo Usage: 104 | echo MAKE [--clean] [--cleantarget] [--nocompat] [--51] [--52] [--53] [--54] [--ms^|gcc] [install [^]] 105 | echo. 106 | echo --51,--52,--53,--54: specify the versions to install, default is to install 107 | echo all versions. Applies only to installing, all versions will be 108 | echo build independent of this option. 109 | echo The first version listed will be set as the unversioned default. 110 | echo --clean : removes downloaded and build artifacts, forcing a rebuild 111 | echo --cleantarget : removes the target directory before installing. NOTE: the LuaRocks 112 | echo installation will ALWAYS be removed, independent of this option! 113 | echo --nocompat : build Lua without compatibility options. NOTE: this option 114 | echo will not automatically clean. So clean when switching compatibility. 115 | echo --ms^|gcc : force usage of either Microsoft (--ms) or gcc (--gcc) toolchain, if 116 | echo not provided it will be auto-detected. 117 | echo install ^ : will install (and build if necessary) the Lua versions. Default 118 | echo location is 'C:\Lua' 119 | echo. 120 | echo --help : Display this help text 121 | echo. 122 | echo Example: the following commands, executed after each other will; 123 | echo make install 124 | echo Will download, build and install 4 Lua versions in 'C:\Lua', 5.1 will 125 | echo be set as the default. 126 | echo. 127 | echo make --51 --52 install C:\lua2 128 | echo Will only install (no rebuild, binaries allready exist) 5.1 and 5.2 in 129 | echo 'C:\Lua2'. 5.1 will be set as the default. 130 | echo. 131 | echo make --clean --53 --nocompat install C:\Lua_NoCompat 132 | echo Will download and build all versions again, without compatibility options, 133 | echo and then install only 5.3 in 'C:\Lua_NoCompat'. 5.3 will be set as the 134 | echo default. 135 | echo. 136 | exit /b 137 | :Continue 138 | 139 | if [%ALLVERSIONS%]==[TRUE] ( 140 | SET VERSION51=--51 141 | SET VERSION52=--52 142 | SET VERSION53=--53 143 | SET VERSION54=--54 144 | SET DEFAULT=51 145 | ) 146 | 147 | REM Commands which, if exiting without error, indicate presence of the toolchain 148 | SET CHECK_GCC=gcc --version 149 | SET CHECK_MS=cl /help ^> %TEMP%\NULL 150 | 151 | SET LRTARGET=%TARGET%\LuaRocks 152 | SET MAKE=luawinmake 153 | 154 | REM Cleanup first 155 | if not [%CLEANTARGET%]==[] ( 156 | if "%TARGET%"=="" ( 157 | echo Error: '--cleantarget' requires the 'install' option to be specified. 158 | exit /b 1 159 | ) 160 | echo Cleaning target: %TARGET% 161 | RMDIR /S /Q "%LRTARGET%" 162 | RMDIR /S /Q "%TARGET%" 163 | echo . 164 | ) 165 | 166 | if not [%TOOLCHAIN%]==[] goto TOOLCHAIN_SET 167 | REM Auto-detect compiler 168 | Echo Testing for Microsoft toolchain... 169 | %CHECK_MS% 170 | IF %ERRORLEVEL%==0 ( 171 | echo Found Microsoft toolchain 172 | SET TOOLCHAIN=MS 173 | goto TOOLCHAIN_SET 174 | ) 175 | Echo Testing for GCC... 176 | %CHECK_GCC% 177 | IF %ERRORLEVEL%==0 ( 178 | SET TOOLCHAIN=GCC 179 | echo Found gcc toolchain 180 | goto TOOLCHAIN_SET 181 | ) 182 | echo. 183 | echo No toolchain detected, please make sure you have the toolchain 184 | echo set up in your system path. 185 | exit /b 1 186 | 187 | 188 | :TOOLCHAIN_SET 189 | if [%TOOLCHAIN%]==[MS] ( 190 | echo Using Microsoft toolchain 191 | SET LRCOMPILER= 192 | ) else ( 193 | echo Using GCC/MinGW toolchain 194 | SET LRCOMPILER=/MW 195 | ) 196 | 197 | REM Download and unpack sources 198 | Echo. 199 | Echo Starting download... 200 | call scripts\download.bat %CLEAN% 201 | 202 | REM Temporary fix until upgrade to LuaRocks 3 203 | REM Fix LR 2.4.4 installer to support Lua 5.4 204 | copy lr244_install.bat_54 luarocks\install.bat 205 | copy lr244_cfg.lua_54 luarocks\src\luarocks\cfg.lua 206 | 207 | REM Build the binaries 208 | Echo. 209 | Echo Start building... 210 | call scripts\build.bat %TOOLCHAIN% %COMPAT% 211 | 212 | Echo Build completed 213 | Echo. 214 | if "%TARGET%"=="" goto SkipInstall 215 | 216 | if not [%VERSION51%]==[] ( 217 | REM Install 51 218 | CD lua-5.1 219 | CALL etc\winmake installv "%TARGET%" 220 | CD ..\luarocks 221 | CALL install /P "%LRTARGET%" /LV 5.1 /LUA "%TARGET%" /F /NOADMIN /Q /NOREG %LRCOMPILER% 222 | COPY "%LRTARGET%\luarocks.bat" "%TARGET%\bin\luarocks51.bat" 223 | CD .. 224 | REM Now pulling a trick to insert a versioned path to the rocks directory into the 225 | REM created 'site_config' file 226 | SET INSERTLINE=site_config.LUAROCKS_ROCKS_SUBDIR=[[/lib/luarocks/rocks-5.1]] 227 | SETLOCAL ENABLEDELAYEDEXPANSION 228 | for /F "usebackq tokens=*" %%A in ("%LRTARGET%\lua\luarocks\site_config_5_1.lua") do ( 229 | echo %%A >> "%LRTARGET%\lua\luarocks\site_config_5_1.lua2" 230 | echo !INSERTLINE! >> "%LRTARGET%\lua\luarocks\site_config_5_1.lua2" 231 | SET INSERTLINE=-- 232 | ) 233 | copy "%LRTARGET%\lua\luarocks\site_config_5_1.lua2" "%LRTARGET%\lua\luarocks\site_config_5_1.lua" 234 | del "%LRTARGET%\lua\luarocks\site_config_5_1.lua2" 235 | ENDLOCAL 236 | ) 237 | 238 | if not [%VERSION52%]==[] ( 239 | REM Install 52 240 | CD lua-5.2 241 | CALL etc\winmake installv "%TARGET%" 242 | CD ..\luarocks 243 | CALL install /P "%LRTARGET%" /LV 5.2 /LUA "%TARGET%" /F /NOADMIN /Q /NOREG %LRCOMPILER% 244 | COPY "%LRTARGET%\luarocks.bat" "%TARGET%\bin\luarocks52.bat" 245 | CD .. 246 | REM Now pulling a trick to insert a versioned path to the rocks directory into the 247 | REM created 'site_config' file 248 | SET INSERTLINE=site_config.LUAROCKS_ROCKS_SUBDIR=[[/lib/luarocks/rocks-5.2]] 249 | SETLOCAL ENABLEDELAYEDEXPANSION 250 | for /F "usebackq tokens=*" %%A in ("%LRTARGET%\lua\luarocks\site_config_5_2.lua") do ( 251 | echo %%A >> "%LRTARGET%\lua\luarocks\site_config_5_2.lua2" 252 | echo !INSERTLINE! >> "%LRTARGET%\lua\luarocks\site_config_5_2.lua2" 253 | SET INSERTLINE=-- 254 | ) 255 | copy "%LRTARGET%\lua\luarocks\site_config_5_2.lua2" "%LRTARGET%\lua\luarocks\site_config_5_2.lua" 256 | del "%LRTARGET%\lua\luarocks\site_config_5_2.lua2" 257 | ENDLOCAL 258 | ) 259 | 260 | if not [%VERSION53%]==[] ( 261 | REM Install 53 262 | CD lua-5.3 263 | CALL etc\winmake installv "%TARGET%" 264 | CD ..\luarocks 265 | CALL install /P "%LRTARGET%" /LV 5.3 /LUA "%TARGET%" /F /NOADMIN /Q /NOREG %LRCOMPILER% 266 | COPY "%LRTARGET%\luarocks.bat" "%TARGET%\bin\luarocks53.bat" 267 | CD .. 268 | REM Now pulling a trick to insert a versioned path to the rocks directory into the 269 | REM created 'site_config' file 270 | SET INSERTLINE=site_config.LUAROCKS_ROCKS_SUBDIR=[[/lib/luarocks/rocks-5.3]] 271 | SETLOCAL ENABLEDELAYEDEXPANSION 272 | for /F "usebackq tokens=*" %%A in ("%LRTARGET%\lua\luarocks\site_config_5_3.lua") do ( 273 | echo %%A >> "%LRTARGET%\lua\luarocks\site_config_5_3.lua2" 274 | echo !INSERTLINE! >> "%LRTARGET%\lua\luarocks\site_config_5_3.lua2" 275 | SET INSERTLINE=-- 276 | ) 277 | copy "%LRTARGET%\lua\luarocks\site_config_5_3.lua2" "%LRTARGET%\lua\luarocks\site_config_5_3.lua" 278 | del "%LRTARGET%\lua\luarocks\site_config_5_3.lua2" 279 | ENDLOCAL 280 | ) 281 | 282 | if not [%VERSION54%]==[] ( 283 | REM Install 54 284 | CD lua-5.4 285 | CALL etc\winmake installv "%TARGET%" 286 | CD ..\luarocks 287 | CALL install /P "%LRTARGET%" /LV 5.4 /LUA "%TARGET%" /F /NOADMIN /Q /NOREG %LRCOMPILER% 288 | COPY "%LRTARGET%\luarocks.bat" "%TARGET%\bin\luarocks54.bat" 289 | CD .. 290 | REM Now pulling a trick to insert a versioned path to the rocks directory into the 291 | REM created 'site_config' file 292 | SET INSERTLINE=site_config.LUAROCKS_ROCKS_SUBDIR=[[/lib/luarocks/rocks-5.4]] 293 | SETLOCAL ENABLEDELAYEDEXPANSION 294 | for /F "usebackq tokens=*" %%A in ("%LRTARGET%\lua\luarocks\site_config_5_4.lua") do ( 295 | echo %%A >> "%LRTARGET%\lua\luarocks\site_config_5_4.lua2" 296 | echo !INSERTLINE! >> "%LRTARGET%\lua\luarocks\site_config_5_4.lua2" 297 | SET INSERTLINE=-- 298 | ) 299 | copy "%LRTARGET%\lua\luarocks\site_config_5_4.lua2" "%LRTARGET%\lua\luarocks\site_config_5_4.lua" 300 | del "%LRTARGET%\lua\luarocks\site_config_5_4.lua2" 301 | ENDLOCAL 302 | ) 303 | 304 | REM install setlua.bat utility 305 | copy .\scripts\setlua.bat "%TARGET%\bin" 306 | copy .\scripts\clean_path.lua "%TARGET%\bin" 307 | 308 | echo. 309 | Echo Done installing, now setting an unversioned default; 310 | REM set the default now 311 | call "%TARGET%\bin\setlua.bat" %DEFAULT% 312 | 313 | :SkipInstall 314 | -------------------------------------------------------------------------------- /scripts/build.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | SETLOCAL 3 | 4 | if not [%1]==[GCC] ( 5 | if not [%1]==[MS] ( 6 | echo. 7 | echo Bad first parameter, specify either GCC or MS 8 | echo Usage: scripts\build.bat GCC^|MS [--nocompat] 9 | echo. 10 | exit /b 1 11 | ) 12 | ) 13 | set TOOLCHAIN=%1 14 | 15 | if [%2]==[--nocompat] ( 16 | set COMPAT=--NOCOMPAT 17 | ) else ( 18 | set COMPAT= 19 | if not [%2]==[] ( 20 | echo. 21 | echo Invalid commandline option; %2 22 | echo Usage: scripts\build.bat GCC^|MS [--nocompat] 23 | echo. 24 | exit /b 1 25 | ) 26 | ) 27 | 28 | SET MAKE=luawinmake 29 | 30 | REM Build 51 31 | if exist lua-5.1\src\lua51.dll ( 32 | echo Skipping Lua 5.1 build, binaries already exist 33 | ) else ( 34 | XCOPY /E/Y/Q "%MAKE%" "lua-5.1" 35 | CD lua-5.1 36 | CALL etc\winmake clean 37 | CALL etc\winmake %TOOLCHAIN% %COMPAT% 38 | CD .. 39 | ) 40 | 41 | REM Build 52 42 | if exist lua-5.2\src\lua52.dll ( 43 | echo Skipping Lua 5.2 build, binaries already exist 44 | ) else ( 45 | XCOPY /E/Y/Q "%MAKE%" "lua-5.2" 46 | CD lua-5.2 47 | CALL etc\winmake clean 48 | CALL etc\winmake %TOOLCHAIN% %COMPAT% 49 | CD .. 50 | ) 51 | 52 | REM Build 53 53 | if exist lua-5.3\src\lua53.dll ( 54 | echo Skipping Lua 5.3 build, binaries already exist 55 | ) else ( 56 | XCOPY /E/Y/Q "%MAKE%" "lua-5.3" 57 | CD lua-5.3 58 | CALL etc\winmake clean 59 | CALL etc\winmake %TOOLCHAIN% %COMPAT% 60 | CD .. 61 | ) 62 | 63 | REM Build 54 64 | if exist lua-5.4\src\lua54.dll ( 65 | echo Skipping Lua 5.4 build, binaries already exist 66 | ) else ( 67 | XCOPY /E/Y/Q "%MAKE%" "lua-5.4" 68 | CD lua-5.4 69 | CALL etc\winmake clean 70 | CALL etc\winmake %TOOLCHAIN% %COMPAT% 71 | CD .. 72 | ) 73 | 74 | -------------------------------------------------------------------------------- /scripts/clean_path.lua: -------------------------------------------------------------------------------- 1 | -- commandline script that cleans a PATH variable by removing duplicates. 2 | -- this belongs to 'setlua.bat' in case it is ran multiple times. 3 | -- call as: "lua setlua_clean.lua " 4 | 5 | -- NOTE: this code must be able to run on ALL Lua versions 6 | 7 | local var = assert(arg[1], "Name of environment variable to clean was not specified on the command line") 8 | local path_value = os.getenv(var) 9 | if path_value then 10 | local entries = {} 11 | local s,e 12 | s = 1 13 | e = path_value:find(";", s) 14 | while s do 15 | local entry = path_value:sub(s, (e or 0)) 16 | s = e 17 | if s then s = s + 1 end 18 | if not entries[entry] then 19 | entries[entry] = true 20 | entries[#entries+1] = entry 21 | end 22 | e = path_value:find(";", s) 23 | end 24 | print(table.concat(entries)) 25 | end 26 | -------------------------------------------------------------------------------- /scripts/download.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | REM Will download and unpack LuaWinMake, LuaRocks and Lua tarballs 3 | 4 | REM *************** CUSTOMIZATION SECTION ********************* 5 | 6 | REM relative nameparts with source code 7 | SET LUA51=lua-5.1.5 8 | SET LUA52=lua-5.2.4 9 | SET LUA53=lua-5.3.6 10 | SET LUA54=lua-5.4.7 11 | SET LRVERSION=2.4.4 12 | 13 | REM Archive suffix to use for all downloads 14 | SET DL_SUFFIX=.tar.gz 15 | REM URL for Lua archives (relative nameparts and archive suffixes will be appended) 16 | SET DL_PREFIX=http://www.lua.org/ftp/ 17 | 18 | REM LuaWinMake url and top folder name 19 | SET DL_LUAWINMAKE=https://github.com/Tieske/luawinmake/archive/master 20 | SET LUAWINMAKE_TOPFOLDER=luawinmake-master 21 | 22 | REM LuaRocks url and top folder name 23 | SET DL_LUAROCKS=https://github.com/keplerproject/luarocks/archive/v%LRVERSION% 24 | SET LUAROCKS_TOPFOLDER=luarocks-%LRVERSION% 25 | 26 | REM *************** NOTHING TO CUSTOMIZE BELOW ********************* 27 | 28 | REM location for temp files 29 | SET DOWNLOADS=%temp%\lwm-downloads\ 30 | 31 | if [%1]==[--clean] ( 32 | echo start cleaning... 33 | RMDIR /S /Q "%DOWNLOADS%" 34 | RMDIR /S /Q "lua-5.1" 35 | RMDIR /S /Q "lua-5.2" 36 | RMDIR /S /Q "lua-5.3" 37 | RMDIR /S /Q "lua-5.4" 38 | RMDIR /S /Q "luawinmake" 39 | RMDIR /S /Q "luarocks" 40 | echo done cleaning... 41 | ) else ( 42 | if not [%1]==[] ( 43 | echo. 44 | echo Invalid commandline option; %1 45 | echo Usage: scripts\download.bat [--clean] 46 | echo. 47 | exit /b 1 48 | ) 49 | ) 50 | 51 | set WORKDIR=%CD%\ 52 | RMDIR /S /Q "%DOWNLOADS%" 53 | mkdir "%DOWNLOADS%" 54 | cd "%DOWNLOADS%" 55 | 56 | if not exist "%WORKDIR%luawinmake\*.*" ( 57 | "%WORKDIR%tools\wget" --no-check-certificate --output-document=luawinmake%DL_SUFFIX% %DL_LUAWINMAKE%%DL_SUFFIX% 58 | "%WORKDIR%tools\7z" x -y luawinmake.tar.gz >NUL 59 | "%WORKDIR%tools\7z" x -y luawinmake.tar >NUL 60 | mkdir "%WORKDIR%luawinmake" 61 | xcopy "%LUAWINMAKE_TOPFOLDER%\*.*" "%workdir%luawinmake\" /E /Y /Q 62 | ) else ( 63 | echo Skipping LuaWinMake download, directory already exists 64 | ) 65 | 66 | if not exist "%WORKDIR%luarocks\*.*" ( 67 | "%WORKDIR%tools\wget" --no-check-certificate --output-document=luarocks%DL_SUFFIX% %DL_LUAROCKS%%DL_SUFFIX% 68 | "%WORKDIR%tools\7z" x -y luarocks.tar.gz >NUL 69 | "%WORKDIR%tools\7z" x -y luarocks.tar >NUL 70 | xcopy "%LUAROCKS_TOPFOLDER%\*.*" "%WORKDIR%luarocks\" /E /Y /Q 71 | ) else ( 72 | echo Skipping LuaRocks download, directory already exists 73 | ) 74 | 75 | if not exist "%WORKDIR%lua-5.1\*.*" ( 76 | "%WORKDIR%tools\wget" --no-check-certificate --output-document=%LUA51%%DL_SUFFIX% %DL_PREFIX%%LUA51%%DL_SUFFIX% 77 | "%WORKDIR%tools\7z" x -y %LUA51%.tar.gz >NUL 78 | "%WORKDIR%tools\7z" x -y %LUA51%.tar >NUL 79 | xcopy "%LUA51%\*.*" "%WORKDIR%lua-5.1\" /E /Y /Q 80 | ) else ( 81 | echo Skipping Lua 5.1 download, directory already exists 82 | ) 83 | 84 | if not exist "%WORKDIR%lua-5.2\*.*" ( 85 | "%WORKDIR%tools\wget" --no-check-certificate --output-document=%LUA52%%DL_SUFFIX% %DL_PREFIX%%LUA52%%DL_SUFFIX% 86 | "%WORKDIR%tools\7z" x -y %LUA52%.tar.gz >NUL 87 | "%WORKDIR%tools\7z" x -y %LUA52%.tar >NUL 88 | xcopy "%LUA52%\*.*" "%WORKDIR%lua-5.2\" /E /Y /Q 89 | ) else ( 90 | echo Skipping Lua 5.2 download, directory already exists 91 | ) 92 | 93 | if not exist "%WORKDIR%lua-5.3\*.*" ( 94 | "%WORKDIR%tools\wget" --no-check-certificate --output-document=%LUA53%%DL_SUFFIX% %DL_PREFIX%%LUA53%%DL_SUFFIX% 95 | "%WORKDIR%tools\7z" x -y %LUA53%.tar.gz >NUL 96 | "%WORKDIR%tools\7z" x -y %LUA53%.tar >NUL 97 | xcopy "%LUA53%\*.*" "%WORKDIR%lua-5.3\" /E /Y /Q 98 | ) else ( 99 | echo Skipping Lua 5.3 download, directory already exists 100 | ) 101 | 102 | if not exist "%WORKDIR%lua-5.4\*.*" ( 103 | "%WORKDIR%tools\wget" --no-check-certificate --output-document=%LUA54%%DL_SUFFIX% %DL_PREFIX%%LUA54%%DL_SUFFIX% 104 | "%WORKDIR%tools\7z" x -y %LUA54%.tar.gz >NUL 105 | "%WORKDIR%tools\7z" x -y %LUA54%.tar >NUL 106 | xcopy "%LUA54%\*.*" "%WORKDIR%lua-5.4\" /E /Y /Q 107 | ) else ( 108 | echo Skipping Lua 5.4 download, directory already exists 109 | ) 110 | 111 | REM The 'RMDIR' below might fail because of background processes like virus scanners etc having files open 112 | RMDIR /S /Q "%DOWNLOADS%" 113 | CD "%WORKDIR%" 114 | -------------------------------------------------------------------------------- /scripts/setlua.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | IF [%1]==[] goto VersionOK 4 | IF [%1]==[51] goto VersionOK 5 | IF [%1]==[52] goto VersionOK 6 | IF [%1]==[53] goto VersionOK 7 | IF [%1]==[54] goto VersionOK 8 | IF [%1]==[--help] GOTO Help 9 | IF [%1]==[-help] GOTO Help 10 | IF [%1]==[help] GOTO Help 11 | IF [%1]==[--?] GOTO Help 12 | IF [%1]==[-?] GOTO Help 13 | IF [%1]==[?] GOTO Help 14 | IF [%1]==[/?] GOTO Help 15 | 16 | echo Error: unknown commandline argument '%1'. Use '%~n0 --help' for usage information. 17 | exit /b 1 18 | 19 | :Help 20 | echo Will setup the environment for the Lua installation; system path and Lua paths. 21 | echo. 22 | echo Usage: 23 | echo %~n0 [version] 24 | echo. 25 | echo Options: 26 | echo version Lua-version to be set as the unversioned default. 27 | echo Valid values; 51, 52, 53, or 54 28 | echo. 29 | exit /b 30 | 31 | :VersionOK 32 | SET myownpath=%~dp0 33 | 34 | setlocal ENABLEDELAYEDEXPANSION 35 | IF not [%1]==[] ( 36 | REM verify the version actually exists 37 | if not exist "%myownpath%lua%1.exe" ( 38 | echo Error: "%myownpath%lua%1.exe" not found, make sure the version is installed before setting it. 39 | exit /b 1 40 | ) 41 | 42 | REM compare files, so we do not execute any admin-priviledged 43 | REM commands unnecessary 44 | fc "%myownpath%lua%1.exe" "%myownpath%lua.exe" > NUL 2>&1 45 | if [!ERRORLEVEL!]==[0] ( 46 | echo lua%1.exe was already set as default. 47 | ) else ( 48 | REM they differ, so we must update them 49 | 50 | copy "%myownpath%lua%1.exe" "%myownpath%lua.exe" /B /Y > NUL 51 | if not [!ERRORLEVEL!]==[0] ( 52 | echo Error: could not set the proper defaults. Do you have the right permissions? 53 | exit /b 1 54 | ) 55 | Echo Installed lua%1.exe as lua.exe. 56 | 57 | copy "%myownpath%luac%1.exe" "%myownpath%luac.exe" /B /Y > NUL 58 | if not [!ERRORLEVEL!]==[0] ( 59 | echo Error: could not set the proper defaults. Do you have the right permissions? 60 | exit /b 1 61 | ) 62 | Echo Installed luac%1.exe as luac.exe. 63 | 64 | REM create wrapper to LuaRocks 65 | ECHO @ECHO OFF > "%~dp0luarocks.bat" 66 | ECHO SETLOCAL >> "%~dp0luarocks.bat" 67 | ECHO CALL "%%~dpn0%1.bat" %%* >> "%~dp0luarocks.bat" 68 | ECHO exit /b %%ERRORLEVEL%% >> "%~dp0luarocks.bat" 69 | Echo Installed luarocks%1.bat as luarocks.bat. 70 | ) 71 | ) 72 | endlocal 73 | 74 | REM setup system path 75 | set path=%appdata%\luarocks\bin;%myownpath%;%PATH% 76 | 77 | REM all paths: luarocks user-tree, luarocks system-tree, defaults 78 | REM setup Lua paths for 5.1 79 | set LUA_CPATH=%appdata%\luarocks\lib\lua\5.1\?.dll;%myownpath%..\lib\lua\5.1\?.dll;; 80 | set LUA_PATH=%appdata%\luarocks\share\lua\5.1\?.lua;%appdata%\luarocks\share\lua\5.1\?\init.lua;%myownpath%..\share\lua\5.1\?.lua;%myownpath%..\share\lua\5.1\?\init.lua;; 81 | 82 | REM setup Lua paths for 5.2 83 | set LUA_CPATH_5_2=%appdata%\luarocks\lib\lua\5.2\?.dll;%myownpath%..\lib\lua\5.2\?.dll;; 84 | set LUA_PATH_5_2=%appdata%\luarocks\share\lua\5.2\?.lua;%appdata%\luarocks\share\lua\5.2\?\init.lua;%myownpath%..\share\lua\5.2\?.lua;%myownpath%..\share\lua\5.2\?\init.lua;; 85 | 86 | REM setup Lua paths for 5.3, defaults will do, but we need to add the user-tree 87 | set LUA_CPATH_5_3=%appdata%\luarocks\lib\lua\5.3\?.dll;; 88 | set LUA_PATH_5_3=%appdata%\luarocks\share\lua\5.3\?.lua;%appdata%\luarocks\share\lua\5.3\?\init.lua;; 89 | 90 | REM setup Lua paths for 5.4, defaults will do, but we need to add the user-tree 91 | set LUA_CPATH_5_4=%appdata%\luarocks\lib\lua\5.4\?.dll;; 92 | set LUA_PATH_5_4=%appdata%\luarocks\share\lua\5.4\?.lua;%appdata%\luarocks\share\lua\5.4\?\init.lua;; 93 | 94 | 95 | REM cleanup the paths in case of duplicate entries 96 | REM to prevent a mess when calling this multiple times 97 | for /f "tokens=*" %%i in ('lua %myownpath%clean_path.lua path') do set path=%%i 98 | for /f "tokens=*" %%i in ('lua %myownpath%clean_path.lua LUA_CPATH') do set LUA_CPATH=%%i 99 | for /f "tokens=*" %%i in ('lua %myownpath%clean_path.lua LUA_PATH') do set LUA_PATH=%%i 100 | for /f "tokens=*" %%i in ('lua %myownpath%clean_path.lua LUA_CPATH_5_2') do set LUA_CPATH_5_2=%%i 101 | for /f "tokens=*" %%i in ('lua %myownpath%clean_path.lua LUA_PATH_5_2') do set LUA_PATH_5_2=%%i 102 | for /f "tokens=*" %%i in ('lua %myownpath%clean_path.lua LUA_CPATH_5_3') do set LUA_CPATH_5_3=%%i 103 | for /f "tokens=*" %%i in ('lua %myownpath%clean_path.lua LUA_PATH_5_3') do set LUA_PATH_5_3=%%i 104 | for /f "tokens=*" %%i in ('lua %myownpath%clean_path.lua LUA_CPATH_5_4') do set LUA_CPATH_5_4=%%i 105 | for /f "tokens=*" %%i in ('lua %myownpath%clean_path.lua LUA_PATH_5_4') do set LUA_PATH_5_4=%%i 106 | 107 | echo Paths have been set up for Lua binaries and modules. Active version; 108 | where lua 109 | lua -v 110 | 111 | :cleanup 112 | set myownpath= 113 | exit /b 114 | -------------------------------------------------------------------------------- /tools/7z.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tieske/luawinmulti/dae0b8b4f214626871451f414aba60346142e604/tools/7z.dll -------------------------------------------------------------------------------- /tools/7z.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tieske/luawinmulti/dae0b8b4f214626871451f414aba60346142e604/tools/7z.exe -------------------------------------------------------------------------------- /tools/wget.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tieske/luawinmulti/dae0b8b4f214626871451f414aba60346142e604/tools/wget.exe --------------------------------------------------------------------------------