aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--install.bat1068
1 files changed, 572 insertions, 496 deletions
diff --git a/install.bat b/install.bat
index 2a0e677b..2150d2c3 100644
--- a/install.bat
+++ b/install.bat
@@ -1,499 +1,575 @@
1@ECHO OFF 1rem=rem --[[
2@setlocal& set luafile="%~f0" & if exist "%~f0.bat" set luafile="%~f0.bat"
3@lua5.1\bin\lua5.1.exe %luafile% %*& exit /b ]]
2 4
3REM Boy, it feels like 1994 all over again. 5local vars = {}
4 6
5SETLOCAL ENABLEDELAYEDEXPANSION 7vars.PREFIX = [[C:\LuaRocks]]
6 8vars.VERSION = "2.0"
7SET PREFIX=C:\LuaRocks 9vars.SYSCONFDIR = [[C:\LuaRocks]]
8SET VERSION=2.0 10vars.ROCKS_TREE = [[C:\LuaRocks]]
9SET SYSCONFDIR=C:\LuaRocks 11vars.SCRIPTS_DIR = nil
10SET ROCKS_TREE=C:\LuaRocks 12vars.LUA_INTERPRETER = nil
11SET SCRIPTS_DIR= 13vars.LUA_PREFIX = nil
12SET FORCE=OFF 14vars.LUA_BINDIR = nil
13SET INSTALL_LUA=OFF 15vars.LUA_INCDIR = nil
14SET LUA_INTERPRETER= 16vars.LUA_LIBDIR = nil
15SET LUA_PREFIX= 17vars.LUA_LIBNAME = nil
16SET LUA_BINDIR= 18vars.LUA_VERSION = "5.1"
17SET LUA_INCDIR= 19vars.LUA_SHORTV = nil
18SET LUA_LIBDIR= 20vars.LUA_LIB_NAMES = "lua5.1.lib lua51.dll liblua.dll.a"
19SET LUA_LIBNAME= 21
20SET FORCE_CONFIG= 22local P_SET = false
21SET USE_MINGW= 23local FORCE = false
22SET MKDIR=.\bin\mkdir -p 24local FORCE_CONFIG = false
23SET LUA_VERSION=5.1 25local INSTALL_LUA = false
24SET LUA_SHORTV= 26local USE_MINGW = false
25SET LUA_LIB_NAMES=lua5.1.lib lua51.dll liblua.dll.a 27local REGISTRY = false
26SET REGISTRY=OFF 28
27SET P_SET=FALSE 29---
28 30-- Some helpers
29REM *********************************************************** 31--
30REM Option parser 32local function die(message)
31REM *********************************************************** 33 if message then print(message) end
32ECHO LuaRocks %VERSION%.x installer. 34 print()
33ECHO. 35 print("Failed installing LuaRocks. Run with /? for help.")
34 36 os.exit(1)
35:PARSE_LOOP 37end
36IF [%1]==[] GOTO DONE_PARSING 38
37IF [%1]==[/?] ( 39local function exec(cmd)
38 ECHO Installs LuaRocks. 40 --print(cmd)
39 ECHO. 41 local status = os.execute(cmd)
40 ECHO /P [dir] ^(REQUIRED^) Where to install. 42 return status == 0
41 ECHO Note that version; %VERSION%, will be 43end
42 ECHO appended to this path. 44
43 ECHO /CONFIG [dir] Location where the config file should be installed. 45local function exists(filename)
44 ECHO Default is same place of installation 46 local cmd = [[.\bin\test -e "]]..filename..[["]]
45 ECHO /TREE [dir] Root of the local tree of installed rocks. 47 return exec(cmd)
46 ECHO Default is same place of installation 48end
47 ECHO /SCRIPTS [dir] Where to install scripts installed by rocks. 49
48 ECHO Default is TREE/bin. 50local function mkdir (dir)
49 ECHO. 51 return exec([[.\bin\mkdir -p "]]..dir..[[" >NUL]])
50 ECHO /LV [version] Lua version to use; either 5.1 or 5.2. 52end
51 ECHO Default is 5.1 53
52 ECHO /L Install LuaRocks' own copy of Lua even if detected, 54-- interpolate string with values from 'vars' table
53 ECHO this will always be a 5.1 installation. 55local function S (tmpl)
54 ECHO ^(/LUA, /INC, /LIB, /BIN cannot be used with /L^) 56 return (tmpl:gsub('%$([%a_][%w_]*)', vars))
55 ECHO /LUA [dir] Location where Lua is installed - e.g. c:\lua\5.1\ 57end
56 ECHO This is the base directory, the installer will look 58
57 ECHO for subdirectories bin, lib, include. Alternatively 59local function print_help()
58 ECHO these can be specified explicitly using the /INC, 60 print(S[[
59 ECHO /LIB, and /BIN options. 61Installs LuaRocks.
60 ECHO /INC [dir] Location of Lua includes - e.g. c:\lua\5.1\include 62
61 ECHO If provided overrides sub directory found using /LUA. 63/P [dir] (REQUIRED) Where to install.
62 ECHO /LIB [dir] Location of Lua libraries -e.g. c:\lua\5.1\lib 64 Note that version; $VERSION, will be
63 ECHO If provided overrides sub directory found using /LUA. 65 appended to this path.
64 ECHO /BIN [dir] Location of Lua executables - e.g. c:\lua\5.1\bin 66/CONFIG [dir] Location where the config file should be installed.
65 ECHO If provided overrides sub directory found using /LUA. 67 Default is same place of installation
66 ECHO. 68/TREE [dir] Root of the local tree of installed rocks.
67 ECHO /MW Use mingw as build system instead of MSVC 69 Default is same place of installation
68 ECHO. 70/SCRIPTS [dir] Where to install scripts installed by rocks.
69 ECHO /FORCECONFIG Use a single config location. Do not use the 71 Default is TREE/bin.
70 ECHO LUAROCKS_CONFIG variable or the user's home directory. 72
71 ECHO Useful to avoid conflicts when LuaRocks 73/LV [version] Lua version to use; either 5.1 or 5.2.
72 ECHO is embedded within an application. 74 Default is 5.1
73 ECHO. 75/L Install LuaRocks' own copy of Lua even if detected,
74 ECHO /F Remove installation directory if it already exists. 76 this will always be a 5.1 installation.
75 ECHO. 77 (/LUA, /INC, /LIB, /BIN cannot be used with /L)
76 ECHO /R Load registry information to register '.rockspec' 78/LUA [dir] Location where Lua is installed - e.g. c:\lua\5.1\
77 ECHO extension with LuaRocks commands ^(right-click^). 79 This is the base directory, the installer will look
78 ECHO. 80 for subdirectories bin, lib, include. Alternatively
79 GOTO QUIT 81 these can be specified explicitly using the /INC,
80) 82 /LIB, and /BIN options.
81IF /I [%1]==[/P] ( 83/INC [dir] Location of Lua includes - e.g. c:\lua\5.1\include
82 SET PREFIX=%~2 84 If provided overrides sub directory found using /LUA.
83 SET SYSCONFDIR=%~2 85/LIB [dir] Location of Lua libraries -e.g. c:\lua\5.1\lib
84 SET ROCKS_TREE=%~2 86 If provided overrides sub directory found using /LUA.
85 SET P_SET=TRUE 87/BIN [dir] Location of Lua executables - e.g. c:\lua\5.1\bin
86 SHIFT /1 88 If provided overrides sub directory found using /LUA.
87 SHIFT /1 89
88 GOTO PARSE_LOOP 90/MW Use mingw as build system instead of MSVC
89) 91
90IF /I [%1]==[/CONFIG] ( 92/FORCECONFIG Use a single config location. Do not use the
91 SET SYSCONFDIR=%~2 93 LUAROCKS_CONFIG variable or the user's home directory.
92 SHIFT /1 94 Useful to avoid conflicts when LuaRocks
93 SHIFT /1 95 is embedded within an application.
94 GOTO PARSE_LOOP 96
95) 97/F Remove installation directory if it already exists.
96IF /I [%1]==[/TREE] ( 98
97 SET ROCKS_TREE=%~2 99/R Load registry information to register '.rockspec'
98 SHIFT /1 100 extension with LuaRocks commands (right-click).
99 SHIFT /1 101
100 GOTO PARSE_LOOP 102]])
101) 103end
102IF /I [%1]==[/SCRIPTS] ( 104
103 SET SCRIPTS_DIR=%~2 105-- ***********************************************************
104 SHIFT /1 106-- Option parser
105 SHIFT /1 107-- ***********************************************************
106 GOTO PARSE_LOOP 108local function parse_options(args)
107) 109 for _, option in ipairs(args) do
108IF /I [%1]==[/LV] ( 110 local name = option.name:upper()
109 SET LUA_VERSION=%~2 111 if name == "/?" then
110 SHIFT /1 112 print_help()
111 SHIFT /1 113 os.exit(0)
112 GOTO PARSE_LOOP 114 elseif name == "/P" then
113) 115 vars.PREFIX = option.value
114IF /I [%1]==[/L] ( 116 vars.SYSCONFDIR = option.value
115 SET INSTALL_LUA=ON 117 vars.ROCKS_TREE = option.value
116 SHIFT /1 118 P_SET = true
117 GOTO PARSE_LOOP 119 elseif name == "/CONFIG" then
118) 120 vars.SYSCONFDIR = option.value
119IF /I [%1]==[/MW] ( 121 elseif name == "/TREE" then
120 SET USE_MINGW=ON 122 vars.ROCKS_TREE = option.value
121 SHIFT /1 123 elseif name == "/SCRIPTS" then
122 GOTO PARSE_LOOP 124 vars.SCRIPTS_DIR = option.value
123) 125 elseif name == "/LV" then
124IF /I [%1]==[/LUA] ( 126 vars.LUA_VERSION = option.value
125 SET LUA_PREFIX=%~2 127 elseif name == "/L" then
126 SHIFT /1 128 INSTALL_LUA = true
127 SHIFT /1 129 elseif name == "/MW" then
128 GOTO PARSE_LOOP 130 USE_MINGW = true
129) 131 elseif name == "/LUA" then
130IF /I [%1]==[/LIB] ( 132 vars.LUA_PREFIX = option.value
131 SET LUA_LIBDIR=%~2 133 elseif name == "/LIB" then
132 SHIFT /1 134 vars.LUA_LIBDIR = option.value
133 SHIFT /1 135 elseif name == "/INC" then
134 GOTO PARSE_LOOP 136 vars.LUA_INCDIR = option.value
135) 137 elseif name == "/BIN" then
136IF /I [%1]==[/INC] ( 138 vars.LUA_BINDIR = option.value
137 SET LUA_INCDIR=%~2 139 elseif name == "/FORCECONFIG" then
138 SHIFT /1 140 FORCE_CONFIG = true
139 SHIFT /1 141 elseif name == "/F" then
140 GOTO PARSE_LOOP 142 FORCE = true
141) 143 elseif name == "/R" then
142IF /I [%1]==[/BIN] ( 144 REGISTRY = true
143 SET LUA_BINDIR=%~2 145 else
144 SHIFT /1 146 die("Unrecognized option: " .. name)
145 SHIFT /1 147 end
146 GOTO PARSE_LOOP 148 end
147) 149end
148IF /I [%1]==[/FORCECONFIG] ( 150
149 SET FORCE_CONFIG=ON 151-- check for combination/required flags
150 SHIFT /1 152local function check_flags()
151 GOTO PARSE_LOOP 153 if not P_SET then
152) 154 die("Missing required parameter /P")
153IF /I [%1]==[/F] ( 155 end
154 SET FORCE=ON 156 if INSTALL_LUA then
155 SHIFT /1 157 if vars.LUA_INCDIR or vars.LUA_BINDIR or vars.LUA_LIBDIR or vars.LUA_PREFIX then
156 GOTO PARSE_LOOP 158 die("Cannot combine option /L with any of /LUA /BIN /LIB /INC")
157) 159 end
158IF /I [%1]==[/R] ( 160 if vars.LUA_VERSION ~= "5.1" then
159 SET REGISTRY=ON 161 die("Bundled Lua version is 5.1, cannot install 5.2")
160 SHIFT /1 162 end
161 GOTO PARSE_LOOP 163 end
162) 164 if vars.LUA_VERSION ~= "5.1" then
163ECHO Unrecognized option: %1 165 if vars.LUA_VERSION == "5.2" then
164GOTO ERROR 166 vars.LUA_LIB_NAMES = vars.LUA_LIB_NAMES:gsub("5([%.]?)1", "5%12")
165:DONE_PARSING 167 else
166 168 die("Bad argument: /LV must either be 5.1 or 5.2")
167REM check for combination/required flags 169 end
168IF NOT [%P_SET%]==[TRUE] ( 170 end
169 Echo Missing required parameter /P 171end
170 GOTO ERROR 172
171) 173-- ***********************************************************
172IF [%INSTALL_LUA%]==[ON] ( 174-- Detect Lua
173 IF NOT [%LUA_INCDIR%%LUA_BINDIR%%LUA_LIBDIR%%LUA_PREFIX%]==[] ( 175-- ***********************************************************
174 ECHO Cannot combine option /L with any of /LUA /BIN /LIB /INC 176local function look_for_interpreter (directory)
175 GOTO ERROR 177 if vars.LUA_BINDIR then
176 ) 178 if exists( S"$LUA_BINDIR\\lua$LUA_VERSION.exe" ) then
177 IF NOT [%LUA_VERSION%]==[5.1] ( 179 vars.LUA_INTERPRETER = S"lua$LUA_VERSION.exe"
178 ECHO Bundled Lua version is 5.1, cannot install 5.2 180 print(S" Found $LUA_BINDIR\\$LUA_INTERPRETER")
179 GOTO ERROR 181 return true
180 ) 182 elseif exists(S"$LUA_BINDIR\\lua.exe") then
181) 183 vars.LUA_INTERPRETER = "lua.exe"
182IF NOT [%LUA_VERSION%]==[5.1] ( 184 print(S" Found $LUA_BINDIR\\$LUA_INTERPRETER")
183 IF [%LUA_VERSION%]==[5.2] ( 185 return true
184 SET LUA_LIB_NAMES=%LUA_LIB_NAMES:5.1=5.2% 186 elseif exists(S"$LUA_BINDIR\\luajit.exe") then
185 SET LUA_LIB_NAMES=%LUA_LIB_NAMES:51=52% 187 vars.LUA_INTERPRETER = "luajit.exe"
186 ) ELSE ( 188 print(S" Found $LUA_BINDIR\\$LUA_INTERPRETER")
187 ECHO Bad argument: /LV must either be 5.1 or 5.2 189 return true
188 GOTO ERROR 190 end
189 ) 191 die(S"Lua executable lua.exe, luajit.exe or lua$LUA_VERSION.exe not found in $LUA_BINDIR")
190) 192 end
191 193
192SET FULL_PREFIX=%PREFIX%\%VERSION% 194 for _, e in ipairs{ [[\]], [[\bin\]] } do
193SET BINDIR=%FULL_PREFIX% 195 if exists(directory..e.."\\lua"..vars.LUA_VERSION..".exe") then
194SET LIBDIR=%FULL_PREFIX% 196 vars.LUA_INTERPRETER = S"lua$LUA_VERSION.exe"
195SET LUADIR=%FULL_PREFIX%\lua 197 vars.LUA_BINDIR = directory .. e
196SET INCDIR=%FULL_PREFIX%\include 198 print(" Found ."..e..vars.LUA_INTERPRETER)
197SET LUA_SHORTV=%LUA_VERSION:.=% 199 return true
198 200
199REM *********************************************************** 201 elseif exists(directory..e.."\\lua.exe") then
200REM Detect Lua 202 vars.LUA_INTERPRETER = "lua.exe"
201REM *********************************************************** 203 vars.LUA_BINDIR = directory..e
202 204 print(" Found ."..e..vars.LUA_INTERPRETER)
203IF [%INSTALL_LUA%]==[ON] GOTO USE_OWN_LUA 205 return true
204 206
205ECHO Looking for Lua interpreter 207 elseif exists(directory..e.."\\luajit.exe") then
206FOR %%L IN (%LUA_PREFIX% c:\lua\5.1.2 c:\lua c:\kepler\1.1) DO ( 208 vars.LUA_INTERPRETER = "luajit.exe"
207 ECHO checking %%L 209 vars.LUA_BINDIR = directory..e
208 SET CURR=%%L 210 print(" Found ."..e..vars.LUA_INTERPRETER)
209 IF EXIST "%%L" ( 211 return true
210 IF NOT [%LUA_BINDIR%]==[] ( 212 end
211 IF EXIST %LUA_BINDIR%\lua%LUA_VERSION%.exe ( 213 end
212 SET LUA_INTERPRETER=lua%LUA_VERSION%.exe 214 print(" No Lua interpreter found")
213 ECHO Found .\!LUA_INTERPRETER! 215 return false
214 GOTO INTERPRETER_IS_SET 216end
215 ) 217
216 IF EXIST %LUA_BINDIR%\lua.exe ( 218local function look_for_link_libraries (directory)
217 SET LUA_INTERPRETER=lua.exe 219 if vars.LUA_LIBDIR then
218 ECHO Found .\!LUA_INTERPRETER! 220 for name in vars.LUA_LIB_NAMES:gmatch("[^%s]+") do
219 GOTO INTERPRETER_IS_SET 221 print(S" checking for $LUA_LIBDIR\\"..name)
220 ) 222 if exists(vars.LUA_LIBDIR.."\\"..name) then
221 IF EXIST %LUA_BINDIR%\luajit.exe ( 223 vars.LUA_LIBNAME = name
222 SET LUA_INTERPRETER=luajit.exe 224 print(" Found "..name)
223 ECHO Found .\!LUA_INTERPRETER! 225 return true
224 GOTO INTERPRETER_IS_SET 226 end
225 ) 227 end
226 ECHO Lua executable lua.exe, luajit.exe or lua%LUA_VERSION%.exe not found in %LUA_BINDIR% 228 die(S"link library (one of; $LUA_LIB_NAMES) not found in $LUA_LIBDIR")
227 GOTO ERROR 229 end
228 ) 230
229 SET CURR=%%L 231 for _, e in ipairs{ [[\]], [[\lib\]], [[\bin\]]} do
230 FOR %%E IN (\ \bin\) DO ( 232 for name in vars.LUA_LIB_NAMES:gmatch("[^%s]+") do
231 IF EXIST "%%L%%E\lua%LUA_VERSION%.exe" ( 233 print(" checking for "..directory..e.."\\"..name)
232 SET LUA_INTERPRETER=lua%LUA_VERSION%.exe 234 if exists(directory..e.."\\"..name) then
233 SET LUA_BINDIR=%%L%%E 235 vars.LUA_LIBDIR = directory .. e
234 ECHO Found .\%%E\!LUA_INTERPRETER! 236 vars.LUA_LIBNAME = name
235 GOTO INTERPRETER_IS_SET 237 print(" Found "..name)
236 ) 238 return true
237 IF EXIST "%%L%%E\lua.exe" ( 239 end
238 SET LUA_INTERPRETER=lua.exe 240 end
239 SET LUA_BINDIR=%%L%%E 241 end
240 ECHO Found .\%%E\!LUA_INTERPRETER! 242 return false
241 GOTO INTERPRETER_IS_SET 243end
242 )
243 IF EXIST "%%L%%E\luajit.exe" (
244 SET LUA_INTERPRETER=luajit.exe
245 SET LUA_BINDIR=%%L%%E
246 ECHO Found .\%%E\!LUA_INTERPRETER!
247 GOTO INTERPRETER_IS_SET
248 )
249 )
250 ECHO No Lua interpreter found
251 GOTO TRY_NEXT_LUA_DIR
252 :INTERPRETER_IS_SET
253 ECHO Interpreter found, now looking for link libraries...
254 IF NOT [%LUA_LIBDIR%]==[] (
255 FOR %%T IN (%LUA_LIB_NAMES%) DO (
256 ECHO checking for %LUA_LIBDIR%\%%T
257 IF EXIST "%LUA_LIBDIR%\%%T" (
258 SET LUA_LIBNAME=%%T
259 ECHO Found %%T
260 GOTO LIBDIR_IS_SET
261 )
262 )
263 ECHO link library ^(one of; %LUA_LIB_NAMES%^) not found in %LUA_LIBDIR%
264 GOTO ERROR
265 )
266 FOR %%E IN (\ \lib\ \bin\) DO (
267 FOR %%S IN (%LUA_LIB_NAMES%) DO (
268 ECHO checking for %CURR%%%E\%%S
269 IF EXIST "%CURR%%%E\%%S" (
270 SET LUA_LIBDIR=%CURR%%%E
271 SET LUA_LIBNAME=%%S
272 ECHO Found %%S
273 GOTO LIBDIR_IS_SET
274 )
275 )
276 )
277 GOTO TRY_NEXT_LUA_DIR
278 :LIBDIR_IS_SET
279 ECHO Link library found, now looking for headers...
280 IF NOT [%LUA_INCDIR%]==[] (
281 ECHO checking for %LUA_INCDIR%\lua.h
282 IF EXIST %LUA_INCDIR%\lua.h (
283 ECHO Found lua.h
284 GOTO INCDIR_IS_SET
285 )
286 ECHO lua.h not found in %LUA_INCDIR%
287 GOTO ERROR
288 )
289 FOR %%E IN (\ \include\) DO (
290 ECHO checking for %CURR%%%E\lua.h
291 IF EXIST "%CURR%%%E\lua.h" (
292 SET LUA_INCDIR=%CURR%%%E
293 ECHO Found lua.h
294 GOTO INCDIR_IS_SET
295 )
296 )
297 GOTO TRY_NEXT_LUA_DIR
298 :INCDIR_IS_SET
299 ECHO Headers found, now testing interpreter...
300 %LUA_BINDIR%\%LUA_INTERPRETER% -v 2>NUL
301 IF NOT ERRORLEVEL 1 (
302 ECHO Ok
303 GOTO LUA_IS_SET
304 )
305 ECHO Interpreter returned an error, not ok
306 )
307:TRY_NEXT_LUA_DIR
308 REM wtf
309)
310ECHO Could not find Lua. Will install its own copy.
311ECHO See /? for options for specifying the location of Lua.
312:USE_OWN_LUA
313IF NOT [%LUA_VERSION%]==[5.1] (
314 ECHO Cannot install own copy because no 5.2 version is bundled
315 GOTO ERROR
316)
317SET INSTALL_LUA=ON
318SET LUA_INTERPRETER=lua5.1
319SET LUA_BINDIR=%BINDIR%
320SET LUA_LIBDIR=%LIBDIR%
321SET LUA_INCDIR=%INCDIR%
322SET LUA_LIBNAME=lua5.1.lib
323:LUA_IS_SET
324ECHO.
325ECHO Will configure LuaRocks with the following paths:
326ECHO LuaRocks : %FULL_PREFIX%
327ECHO Lua interpreter: %LUA_BINDIR%\%LUA_INTERPRETER%
328ECHO Lua binaries : %LUA_BINDIR%
329ECHO Lua libraries : %LUA_LIBDIR%
330ECHO Lua includes : %LUA_INCDIR%
331ECHO Binaries will be linked against: %LUA_LIBNAME%
332ECHO.
333
334REM ***********************************************************
335REM Install LuaRocks files
336REM ***********************************************************
337
338IF [%FORCE%]==[ON] (
339 ECHO Removing %FULL_PREFIX%...
340 RD /S /Q "%FULL_PREFIX%"
341 ECHO.
342)
343
344IF NOT EXIST "%FULL_PREFIX%" GOTO NOT_EXIST_PREFIX
345 ECHO %FULL_PREFIX% exists. Use /F to force removal and reinstallation.
346 GOTO ERROR
347:NOT_EXIST_PREFIX
348
349ECHO Installing LuaRocks in %FULL_PREFIX%...
350IF NOT EXIST "%BINDIR%" %MKDIR% "%BINDIR%"
351IF ERRORLEVEL 1 GOTO ERROR
352IF [%INSTALL_LUA%]==[ON] (
353 REM Copy the included Lua interpreter binaries
354 IF NOT EXIST "%LUA_BINDIR%" %MKDIR% "%LUA_BINDIR%"
355 IF NOT EXIST "%LUA_INCDIR%" %MKDIR% "%LUA_INCDIR%"
356 COPY lua5.1\bin\*.* "%LUA_BINDIR%" >NUL
357 COPY lua5.1\include\*.* "%LUA_INCDIR%" >NUL
358 ECHO Installed the LuaRocks bundled Lua interpreter in %LUA_BINDIR%
359)
360REM Copy the LuaRocks binaries
361COPY bin\*.* "%BINDIR%" >NUL
362IF ERRORLEVEL 1 GOTO ERROR
363REM Copy the LuaRocks lua source files
364IF NOT EXIST "%LUADIR%\luarocks" %MKDIR% "%LUADIR%\luarocks"
365IF ERRORLEVEL 1 GOTO ERROR
366XCOPY /S src\luarocks\*.* "%LUADIR%\luarocks" >NUL
367IF ERRORLEVEL 1 GOTO ERROR
368REM Create start scripts
369COPY src\bin\*.* "%BINDIR%" >NUL
370IF ERRORLEVEL 1 GOTO ERROR
371FOR %%C IN (luarocks luarocks-admin) DO (
372 REM rename unix-lua scripts to .lua files
373 RENAME "%BINDIR%\%%C" %%C.lua
374 IF ERRORLEVEL 1 GOTO ERROR
375 REM create a bootstrap batch file for the lua file, to start them
376 DEL /F /Q "%BINDIR%\%%C.bat" 2>NUL
377 ECHO @ECHO OFF>> "%BINDIR%\%%C.bat"
378 ECHO SETLOCAL>> "%BINDIR%\%%C.bat"
379 ECHO SET LUA_PATH=%LUADIR%\?.lua;%LUADIR%\?\init.lua;%%LUA_PATH%%>> "%BINDIR%\%%C.bat"
380 ECHO SET PATH=%BINDIR%\;%%PATH%%>> "%BINDIR%\%%C.bat"
381 ECHO "%LUA_INTERPRETER%" "%BINDIR%\%%C.lua" %%*>> "%BINDIR%\%%C.bat"
382 ECHO ENDLOCAL>> "%BINDIR%\%%C.bat"
383 ECHO Created LuaRocks command: %BINDIR%\%%C.bat
384)
385REM configure 'scripts' directory
386IF [%SCRIPTS_DIR%]==[] (
387 %MKDIR% "%ROCKS_TREE%"\bin >NUL
388 IF [%USE_MINGW%]==[] (
389 REM definitly not for MinGW because of conflicting runtimes
390 REM but is it ok to do it for others???
391 COPY lua5.1\bin\*.dll "%ROCKS_TREE%"\bin >NUL
392 )
393) ELSE (
394 %MKDIR% "%SCRIPTS_DIR%" >NUL
395 IF [%USE_MINGW%]==[] (
396 REM definitly not for MinGW because of conflicting runtimes
397 REM but is it ok to do it for others???
398 COPY lua5.1\bin\*.dll "%SCRIPTS_DIR%" >NUL
399 )
400)
401
402
403ECHO.
404ECHO Configuring LuaRocks...
405REM Create a site-config file
406IF EXIST "%LUADIR%\luarocks\site_config.lua" RENAME "%LUADIR%\luarocks\site_config.lua" site_config.lua.bak
407ECHO module("luarocks.site_config")>> "%LUADIR%\luarocks\site_config.lua"
408ECHO LUA_INCDIR=[[%LUA_INCDIR%]]>> "%LUADIR%\luarocks\site_config.lua"
409ECHO LUA_LIBDIR=[[%LUA_LIBDIR%]]>> "%LUADIR%\luarocks\site_config.lua"
410ECHO LUA_BINDIR=[[%LUA_BINDIR%]]>> "%LUADIR%\luarocks\site_config.lua"
411ECHO LUA_INTERPRETER=[[%LUA_INTERPRETER%]]>> "%LUADIR%\luarocks\site_config.lua"
412IF [%USE_MINGW%]==[ON] (
413ECHO LUAROCKS_UNAME_S=[[MINGW]]>> "%LUADIR%\luarocks\site_config.lua"
414) ELSE (
415ECHO LUAROCKS_UNAME_S=[[WindowsNT]]>> "%LUADIR%\luarocks\site_config.lua"
416)
417ECHO LUAROCKS_UNAME_M=[[x86]]>> "%LUADIR%\luarocks\site_config.lua"
418ECHO LUAROCKS_SYSCONFIG=[[%SYSCONFDIR%/config.lua]]>> "%LUADIR%\luarocks\site_config.lua"
419ECHO LUAROCKS_ROCKS_TREE=[[%ROCKS_TREE%]]>> "%LUADIR%\luarocks\site_config.lua"
420ECHO LUAROCKS_PREFIX=[[%PREFIX%]]>> "%LUADIR%\luarocks\site_config.lua"
421ECHO LUAROCKS_DOWNLOADER=[[wget]]>> "%LUADIR%\luarocks\site_config.lua"
422ECHO LUAROCKS_MD5CHECKER=[[md5sum]]>> "%LUADIR%\luarocks\site_config.lua"
423IF NOT [%FORCE_CONFIG%]==[] ECHO local LUAROCKS_FORCE_CONFIG=true>> "%LUADIR%\luarocks\site_config.lua"
424IF EXIST "%LUADIR%\luarocks\site_config.lua.bak" TYPE "%LUADIR%\luarocks\site_config.lua.bak">> "%LUADIR%\luarocks\site_config.lua"
425
426IF EXIST "%LUADIR%\luarocks\site_config.lua.bak" DEL /F /Q "%LUADIR%\luarocks\site_config.lua.bak"
427ECHO Created LuaRocks site-config file: %LUADIR%\luarocks\site_config.lua
428
429REM create config file
430SET CONFIG_FILE=%SYSCONFDIR%\config.lua
431
432IF NOT EXIST "%SYSCONFDIR%" %MKDIR% "%SYSCONFDIR%"
433IF NOT EXIST "%CONFIG_FILE%" (
434 ECHO rocks_servers = {>> "%CONFIG_FILE%"
435 ECHO [[http://luarocks.org/repositories/rocks]]>> "%CONFIG_FILE%"
436 ECHO }>> "%CONFIG_FILE%"
437 ECHO rocks_trees = {>> "%CONFIG_FILE%"
438 IF [%FORCE_CONFIG%]==[] ECHO home..[[/luarocks]],>> "%CONFIG_FILE%"
439 ECHO [[%ROCKS_TREE%]]>> "%CONFIG_FILE%"
440 ECHO }>> "%CONFIG_FILE%"
441 IF NOT [%SCRIPTS_DIR%]==[] ECHO scripts_dir=[[%SCRIPTS_DIR%]]>> "%CONFIG_FILE%"
442 ECHO variables = {>> "%CONFIG_FILE%"
443 IF [%USE_MINGW%]==[ON] (
444 ECHO MSVCRT = 'm',>> "%CONFIG_FILE%"
445 ) ELSE (
446 ECHO MSVCRT = 'msvcr80',>> "%CONFIG_FILE%"
447 )
448 ECHO LUALIB = '%LUA_LIBNAME%'>> "%CONFIG_FILE%"
449 ECHO }>> "%CONFIG_FILE%"
450 ECHO Created LuaRocks config file: %CONFIG_FILE%
451) ELSE (
452 ECHO LuaRocks config file already exists: %CONFIG_FILE%
453)
454
455ECHO.
456ECHO Creating rocktrees...
457IF NOT EXIST "%ROCKS_TREE%" (
458 %MKDIR% "%ROCKS_TREE%"
459 ECHO Created rocktree: "%ROCKS_TREE%"
460) ELSE (
461 ECHO Rocktree exists: "%ROCKS_TREE%"
462)
463IF NOT EXIST "%APPDATA%/luarocks" (
464 %MKDIR% "%APPDATA%/luarocks"
465 ECHO Created rocktree: "%APPDATA%\luarocks"
466) ELSE (
467 ECHO Rocktree exists: "%APPDATA%\luarocks"
468)
469
470REM Load registry information
471IF [%REGISTRY%]==[ON] (
472 REM expand template with correct path information
473 ECHO.
474 ECHO Loading registry information for ".rockspec" files
475 lua5.1\bin\lua5.1.exe "%FULL_PREFIX%\create_reg_file.lua" "%FULL_PREFIX%\LuaRocks.reg.template"
476 %FULL_PREFIX%\LuaRocks.reg
477)
478
479REM ***********************************************************
480REM Exit handlers
481REM ***********************************************************
482
483ECHO.
484ECHO *** LuaRocks is installed! ***
485ECHO.
486ECHO You may want to add the following elements to your paths;
487ECHO PATH : %LUA_BINDIR%;%FULL_PREFIX%
488ECHO LUA_PATH : %ROCKS_TREE%\share\lua\%LUA_VERSION%\?.lua;%ROCKS_TREE%\share\lua\%LUA_VERSION%\?\init.lua
489ECHO LUA_CPATH: %LUA_LIBDIR%\lua\%LUA_VERSION%\?.dll
490ECHO.
491:QUIT
492ENDLOCAL
493EXIT /B 0
494 244
495:ERROR 245local function look_for_headers (directory)
496ECHO. 246 if vars.LUA_INCDIR then
497ECHO Failed installing LuaRocks. Run with /? for help. 247 print(S" checking for $LUA_INCDIR\\lua.h")
248 if exists(S"$LUA_INCDIR\\lua.h") then
249 print(" Found lua.h")
250 return true
251 end
252 die(S"lua.h not found in $LUA_INCDIR")
253 end
254
255 for _, e in ipairs{ [[\]], [[\include\]]} do
256 print(" checking for "..directory..e.."\\lua.h")
257 if exists(directory..e.."\\lua.h") then
258 vars.LUA_INCDIR = directory..e
259 print(" Found lua.h")
260 return true
261 end
262 end
263 return false
264end
265
266local function look_for_lua_install ()
267 print("Looking for Lua interpreter")
268 local directories = { [[c:\lua5.1.2]], [[c:\lua]], [[c:\kepler\1.1]] }
269 if vars.LUA_PREFIX then
270 table.insert(directories, 1, vars.LUA_PREFIX)
271 end
272 if vars.LUA_BINDIR and vars.LUA_LIBDIR and vars.LUA_INCDIR then
273 if look_for_interpreter(vars.LUA_BINDIR) and
274 look_for_link_libraries(vars.LUA_LIBDIR) and
275 look_for_headers(vars.LUA_INCDIR)
276 then
277 if exec(S"$LUA_BINDIR\\$LUA_INTERPRETER -v 2>NUL") then
278 print(" Ok")
279 return true
280 end
281 end
282 return false
283 end
284
285 for _, directory in ipairs(directories) do
286 print(" checking " .. directory)
287 if exists(directory) then
288 if look_for_interpreter(directory) then
289 print("Interpreter found, now looking for link libraries...")
290 if look_for_link_libraries(directory) then
291 print("Link library found, now looking for headers...")
292 if look_for_headers(directory) then
293 print("Headers found, now testing interpreter...")
294 if exec(S[[$LUA_BINDIR\$LUA_INTERPRETER -v 2>NUL]]) then
295 print(" Ok")
296 return true
297 end
298 print(" Interpreter returned an error, not ok")
299 end
300 end
301 end
302 end
303 end
304 return false
305end
306
307---
308-- Poor man's command-line parsing
309local config = {}
310local with_arg = { -- options followed by an argument, others are flags
311 ["/P"] = true,
312 ["/CONFIG"] = true,
313 ["/TREE"] = true,
314 ["/SCRIPTS"] = true,
315 ["/LV"] = true,
316 ["/LUA"] = true,
317 ["/INC"] = true,
318 ["/BIN"] = true,
319 ["/LIB"] = true,
320}
321local i = 1
322while i <= #arg do
323 local opt = arg[i]
324 if with_arg[opt] then
325 local value = arg[i + 1]
326 if not value then
327 die("Missing value for option "..opt)
328 end
329 config[#config + 1] = { name = opt, value = value }
330 i = i + 1
331 else
332 config[#config + 1] = { name = opt }
333 end
334 i = i + 1
335end
336
337print(S"LuaRocks $VERSION.x installer.\n")
338
339parse_options(config)
340check_flags()
341
342vars.FULL_PREFIX = S"$PREFIX\\$VERSION"
343vars.BINDIR = vars.FULL_PREFIX
344vars.LIBDIR = vars.FULL_PREFIX
345vars.LUADIR = S"$FULL_PREFIX\\lua"
346vars.INCDIR = S"$FULL_PREFIX\\include"
347vars.LUA_SHORTV = vars.LUA_VERSION:gsub("%.", "")
348
349if not look_for_lua_install() then
350 print("Could not find Lua. Will install its own copy.")
351 print("See /? for options for specifying the location of Lua.")
352 if vars.LUA_VERSION ~= "5.1" then
353 die("Cannot install own copy because no 5.2 version is bundled")
354 end
355 INSTALL_LUA = true
356 vars.LUA_INTERPRETER = "lua5.1"
357 vars.LUA_BINDIR = vars.BINDIR
358 vars.LUA_LIBDIR = vars.LIBDIR
359 vars.LUA_INCDIR = vars.INCDIR
360 vars.LUA_LIBNAME = "lua5.1.lib"
361else
362 print(S[[
363
364Will configure LuaRocks with the following paths:
365LuaRocks : $FULL_PREFIX
366Lua interpreter: $LUA_BINDIR\$LUA_INTERPRETER
367Lua binaries : $LUA_BINDIR
368Lua libraries : $LUA_LIBDIR
369Lua includes : $LUA_INCDIR
370Binaries will be linked against: $LUA_LIBNAME
371
372]])
373end
374
375-- ***********************************************************
376-- Install LuaRocks files
377-- ***********************************************************
378if FORCE then
379 print(S"Removing $FULL_PREFIX...")
380 exec(S[[RD /S /Q "$FULL_PREFIX"]])
381 print()
382end
383
384if exists(vars.FULL_PREFIX) then
385 die(S"$FULL_PREFIX exists. Use /F to force removal and reinstallation.")
386end
387
388print(S"Installing LuaRocks in $FULL_PREFIX...")
389if not exists(vars.BINDIR) then
390 if not mkdir(vars.BINDIR) then
391 die()
392 end
393end
394
395if INSTALL_LUA then
396 -- Copy the included Lua interpreter binaries
397 if not exists(vars.LUA_BINDIR) then
398 mkdir(vars.LUA_BINDIR)
399 end
400 if not exists(vars.LUA_INCDIR) then
401 mkdir(vars.LUA_INCDIR)
402 end
403 exec(S[[COPY lua5.1\bin\*.* "$LUA_BINDIR" >NUL]])
404 exec(S[[COPY lua5.1\include\*.* "$LUA_INCDIR" >NUL]])
405 print(S"Installed the LuaRocks bundled Lua interpreter in $LUA_BINDIR")
406end
407
408-- Copy the LuaRocks binaries
409if not exec(S[[COPY bin\*.* "$BINDIR" >NUL]]) then
410 die()
411end
412-- Copy the LuaRocks lua source files
413if not exists(S[[$LUADIR\luarocks]]) then
414 if not mkdir(S[[$LUADIR\luarocks]]) then
415 die()
416 end
417end
418if not exec(S[[XCOPY /S src\luarocks\*.* "$LUADIR\luarocks" >NUL]]) then
419 die()
420end
421-- Create start scripts
422if not exec(S[[COPY src\bin\*.* "$BINDIR" >NUL]]) then
423 die()
424end
425for _, c in ipairs{"luarocks", "luarocks-admin"} do
426 -- rename unix-lua scripts to .lua files
427 if not exec( (S[[RENAME "$BINDIR\%s" %s.lua]]):format(c, c) ) then
428 die()
429 end
430 -- create a bootstrap batch file for the lua file, to start them
431 exec(S[[DEL /F /Q "$BINDIR\]]..c..[[.bat" 2>NUL]])
432 local f = io.open(vars.BINDIR.."\\"..c..".bat", "w")
433 f:write(S[[
434@ECHO OFF
435SETLOCAL
436SET LUA_PATH=$LUADIR\?.lua;$LUADIR\?\init.lua;%LUA_PATH%
437SET PATH=$BINDIR\;%PATH%
438"$LUA_INTERPRETER" "$BINDIR\]]..c..[[.lua" %*
498ENDLOCAL 439ENDLOCAL
499EXIT /B 1 440]])
441 f:close()
442 print(S"Created LuaRocks command: $BINDIR\\"..c..".bat")
443end
444-- configure 'scripts' directory
445if vars.SCRIPTS_DIR then
446 mkdir(vars.SCRIPTS_DIR)
447 if not USE_MINGW then
448 -- definitly not for MinGW because of conflicting runtimes
449 -- but is it ok to do it for others???
450 exec(S[[COPY lua5.1\bin\*.dll "$SCRIPTS_DIR" >NUL]])
451 end
452else
453 if not USE_MINGW then
454 mkdir(S[[$ROCKS_TREE\bin]])
455 -- definitly not for MinGW because of conflicting runtimes
456 -- but is it ok to do it for others???
457 exec(S[[COPY lua5.1\bin\*.dll "$ROCKS_TREE"\bin >NUL]])
458 end
459end
460
461
462print()
463print("Configuring LuaRocks...")
464-- Create a site-config file
465if exists(S[[$LUADIR\luarocks\site_config.lua]]) then
466 exec(S[[RENAME "$LUADIR\luarocks\site_config.lua" site_config.lua.bak]])
467end
468local f = io.open(vars.LUADIR.."\\luarocks\\site_config.lua", "w")
469f:write(S[=[
470module("luarocks.site_config")
471LUA_INCDIR=[[$LUA_INCDIR]]
472LUA_LIBDIR=[[$LUA_LIBDIR]]
473LUA_BINDIR=[[$LUA_BINDIR]]
474LUA_INTERPRETER=[[$LUA_INTERPRETER]]
475]=])
476if USE_MINGW then
477 f:write("LUAROCKS_UNAME_S=[[MINGW]]\n")
478else
479 f:write("LUAROCKS_UNAME_S=[[WindowsNT]]\n")
480end
481f:write(S[=[
482LUAROCKS_UNAME_M=[[x86]]
483LUAROCKS_SYSCONFIG=[[$SYSCONFDIR\config.lua]]
484LUAROCKS_ROCKS_TREE=[[$ROCKS_TREE]]
485LUAROCKS_PREFIX=[[$PREFIX]]
486LUAROCKS_DOWNLOADER=[[wget]]
487LUAROCKS_MD5CHECKER=[[md5sum]]
488]=])
489if FORCE_CONFIG then
490 f:write("local LUAROCKS_FORCE_CONFIG=true\n")
491end
492if exists(vars.LUADIR.."\\luarocks\\site_config.lua.bak") then
493 for line in io.lines(vars.LUADIR.."\\luarocks\\site_config.lua.bak", "r") do
494 f:write(line)
495 f:write("\n")
496 end
497 exec(S[[DEL /F /Q "$LUADIR\luarocks\site_config.lua.bak"]])
498end
499f:close()
500print(S[[Created LuaRocks site-config file: $LUADIR\luarocks\site_config.lua]])
501
502-- create config file
503vars.CONFIG_FILE = vars.SYSCONFDIR.."\\config.lua"
504if not exists(vars.SYSCONFDIR) then
505 mkdir(vars.SYSCONFDIR)
506end
507if not exists(vars.CONFIG_FILE) then
508 local f = io.open(vars.CONFIG_FILE, "w")
509 f:write([=[
510rocks_servers = {
511 [[http://luarocks.org/repositories/rocks]]
512}
513rocks_trees = {
514]=])
515 if FORCE_CONFIG then
516 f:write(" home..[[/luarocks]],\n")
517 end
518 f:write(S" [[$ROCKS_TREE]]\n")
519 f:write("}\n")
520 if vars.SCRIPTS_DIR then
521 f:write(S"scripts_dir=[[$SCRIPTS_DIR]]\n")
522 end
523 f:write("variables = {\n")
524 if USE_MINGW then
525 f:write(" MSVCRT = 'm',\n")
526 else
527 f:write(" MSVCRT = 'msvcr80',\n")
528 end
529 f:write(S" LUALIB = '$LUA_LIBNAME'\n")
530 f:write("}\n")
531 f:close()
532 print(S"Created LuaRocks config file: $CONFIG_FILE")
533else
534 print(S"LuaRocks config file already exists: $CONFIG_FILE")
535end
536
537print()
538print("Creating rocktrees...")
539if not exists(vars.ROCKS_TREE) then
540 mkdir(vars.ROCKS_TREE)
541 print(S[[Created rocktree: "$ROCKS_TREE"]])
542else
543 print(S[[Rocktree exists: "$ROCKS_TREE"]])
544end
545local APPDATA = os.getenv("APPDATA")
546if not exists(APPDATA.."\\luarocks") then
547 mkdir(APPDATA.."\\luarocks")
548 print([[Created rocktree: "]]..APPDATA..[[\luarocks"]])
549else
550 print([[Rocktree exists: "]]..APPDATA..[[\luarocks"]])
551end
552
553-- Load registry information
554if REGISTRY then
555 -- expand template with correct path information
556 print()
557 print([[Loading registry information for ".rockspec" files]])
558 exec( S[[lua5.1\bin\lua5.1.exe "$FULL_PREFIX\create_reg_file.lua" "$FULL_PREFIX\LuaRocks.reg.template"]] )
559 exec( S"$FULL_PREFIX\\LuaRocks.reg" )
560end
561
562-- ***********************************************************
563-- Exit handlers
564-- ***********************************************************
565
566print(S[[
567*** LuaRocks is installed! ***
568
569 You may want to add the following elements to your paths;
570PATH : $LUA_BINDIR;$FULL_PREFIX
571LUA_PATH : $ROCKS_TREE\share\lua\$LUA_VERSION\?.lua;$ROCKS_TREE\share\lua\$LUA_VERSION\?\init.lua
572LUA_CPATH: $LUA_LIBDIR\lua\$LUA_VERSION\?.dll
573
574]])
575os.exit(0)