-
Notifications
You must be signed in to change notification settings - Fork 5
/
make.bat
313 lines (289 loc) · 9.47 KB
/
make.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
@echo off
SETLOCAL
REM __NOTE__: Some additional customizations in 'scripts\download.bat'
REM Target locations for Lua
SET TARGET=
SET COMPAT=
SET ALLVERSIONS=TRUE
SET VERSION51=
SET VERSION52=
SET VERSION53=
SET VERSION54=
SET CLEAN=
SET CLEANTARGET=
SET DEFAULT=
SET TOOLCHAIN=
SET LRCOMPILER=
:HandleParameter
IF [%1]==[] GOTO Continue
IF [%1]==[--help] GOTO Help
IF [%1]==[-help] GOTO Help
IF [%1]==[help] GOTO Help
IF [%1]==[--?] GOTO Help
IF [%1]==[-?] GOTO Help
IF [%1]==[?] GOTO Help
IF [%1]==[/?] GOTO Help
if [%1]==[--clean] (
set CLEAN=--clean
SHIFT
GOTO HandleParameter
)
if [%1]==[--cleantarget] (
set CLEANTARGET=--clean
SHIFT
GOTO HandleParameter
)
if [%1]==[--nocompat] (
set COMPAT=--nocompat
SHIFT
GOTO HandleParameter
)
if [%1]==[--gcc] (
set TOOLCHAIN=GCC
SHIFT
GOTO HandleParameter
)
if [%1]==[--ms] (
set TOOLCHAIN=MS
SHIFT
GOTO HandleParameter
)
if [%1]==[--51] (
set ALLVERSIONS=
set VERSION51=%1
if [%DEFAULT%]==[] SET DEFAULT=51
SHIFT
GOTO HandleParameter
)
if [%1]==[--52] (
set ALLVERSIONS=
set VERSION52=%1
if [%DEFAULT%]==[] SET DEFAULT=52
SHIFT
GOTO HandleParameter
)
if [%1]==[--53] (
set ALLVERSIONS=
set VERSION53=%1
if [%DEFAULT%]==[] SET DEFAULT=53
SHIFT
GOTO HandleParameter
)
if [%1]==[--54] (
set ALLVERSIONS=
set VERSION54=%1
if [%DEFAULT%]==[] SET DEFAULT=54
SHIFT
GOTO HandleParameter
)
if [%1]==[install] (
if [%2]==[] (
SHIFT
SET TARGET=C:\Lua
GOTO Continue
)
SET TARGET=%~2
if [%3]==[] GOTO Continue
echo Error: 'install' must be the final option on the commandline, '%3' is not allowed here.
exit /b 1
)
echo Error handling commandline option '%1'. Use '--help' for usage information.
echo.
exit /b 1
:Help
echo Commandline script to download and install Lua 5.1, 5.2, 5.3, and 5.4 with a LuaRocks installation for each.
echo A 'setlua' script is made available to setup the environment for each version.
echo.
echo Usage:
echo MAKE [--clean] [--cleantarget] [--nocompat] [--51] [--52] [--53] [--54] [--ms^|gcc] [install [^<location^>]]
echo.
echo --51,--52,--53,--54: specify the versions to install, default is to install
echo all versions. Applies only to installing, all versions will be
echo build independent of this option.
echo The first version listed will be set as the unversioned default.
echo --clean : removes downloaded and build artifacts, forcing a rebuild
echo --cleantarget : removes the target directory before installing. NOTE: the LuaRocks
echo installation will ALWAYS be removed, independent of this option!
echo --nocompat : build Lua without compatibility options. NOTE: this option
echo will not automatically clean. So clean when switching compatibility.
echo --ms^|gcc : force usage of either Microsoft (--ms) or gcc (--gcc) toolchain, if
echo not provided it will be auto-detected.
echo install ^<location^> : will install (and build if necessary) the Lua versions. Default
echo location is 'C:\Lua'
echo.
echo --help : Display this help text
echo.
echo Example: the following commands, executed after each other will;
echo make install
echo Will download, build and install 4 Lua versions in 'C:\Lua', 5.1 will
echo be set as the default.
echo.
echo make --51 --52 install C:\lua2
echo Will only install (no rebuild, binaries allready exist) 5.1 and 5.2 in
echo 'C:\Lua2'. 5.1 will be set as the default.
echo.
echo make --clean --53 --nocompat install C:\Lua_NoCompat
echo Will download and build all versions again, without compatibility options,
echo and then install only 5.3 in 'C:\Lua_NoCompat'. 5.3 will be set as the
echo default.
echo.
exit /b
:Continue
if [%ALLVERSIONS%]==[TRUE] (
SET VERSION51=--51
SET VERSION52=--52
SET VERSION53=--53
SET VERSION54=--54
SET DEFAULT=51
)
REM Commands which, if exiting without error, indicate presence of the toolchain
SET CHECK_GCC=gcc --version
SET CHECK_MS=cl /help ^> %TEMP%\NULL
SET LRTARGET=%TARGET%\LuaRocks
SET MAKE=luawinmake
REM Cleanup first
if not [%CLEANTARGET%]==[] (
if "%TARGET%"=="" (
echo Error: '--cleantarget' requires the 'install' option to be specified.
exit /b 1
)
echo Cleaning target: %TARGET%
RMDIR /S /Q "%LRTARGET%"
RMDIR /S /Q "%TARGET%"
echo .
)
if not [%TOOLCHAIN%]==[] goto TOOLCHAIN_SET
REM Auto-detect compiler
Echo Testing for Microsoft toolchain...
%CHECK_MS%
IF %ERRORLEVEL%==0 (
echo Found Microsoft toolchain
SET TOOLCHAIN=MS
goto TOOLCHAIN_SET
)
Echo Testing for GCC...
%CHECK_GCC%
IF %ERRORLEVEL%==0 (
SET TOOLCHAIN=GCC
echo Found gcc toolchain
goto TOOLCHAIN_SET
)
echo.
echo No toolchain detected, please make sure you have the toolchain
echo set up in your system path.
exit /b 1
:TOOLCHAIN_SET
if [%TOOLCHAIN%]==[MS] (
echo Using Microsoft toolchain
SET LRCOMPILER=
) else (
echo Using GCC/MinGW toolchain
SET LRCOMPILER=/MW
)
REM Download and unpack sources
Echo.
Echo Starting download...
call scripts\download.bat %CLEAN%
REM Temporary fix until upgrade to LuaRocks 3
REM Fix LR 2.4.4 installer to support Lua 5.4
copy lr244_install.bat_54 luarocks\install.bat
copy lr244_cfg.lua_54 luarocks\src\luarocks\cfg.lua
REM Build the binaries
Echo.
Echo Start building...
call scripts\build.bat %TOOLCHAIN% %COMPAT%
Echo Build completed
Echo.
if "%TARGET%"=="" goto SkipInstall
if not [%VERSION51%]==[] (
REM Install 51
CD lua-5.1
CALL etc\winmake installv "%TARGET%"
CD ..\luarocks
CALL install /P "%LRTARGET%" /LV 5.1 /LUA "%TARGET%" /F /NOADMIN /Q /NOREG %LRCOMPILER%
COPY "%LRTARGET%\luarocks.bat" "%TARGET%\bin\luarocks51.bat"
CD ..
REM Now pulling a trick to insert a versioned path to the rocks directory into the
REM created 'site_config' file
SET INSERTLINE=site_config.LUAROCKS_ROCKS_SUBDIR=[[/lib/luarocks/rocks-5.1]]
SETLOCAL ENABLEDELAYEDEXPANSION
for /F "usebackq tokens=*" %%A in ("%LRTARGET%\lua\luarocks\site_config_5_1.lua") do (
echo %%A >> "%LRTARGET%\lua\luarocks\site_config_5_1.lua2"
echo !INSERTLINE! >> "%LRTARGET%\lua\luarocks\site_config_5_1.lua2"
SET INSERTLINE=--
)
copy "%LRTARGET%\lua\luarocks\site_config_5_1.lua2" "%LRTARGET%\lua\luarocks\site_config_5_1.lua"
del "%LRTARGET%\lua\luarocks\site_config_5_1.lua2"
ENDLOCAL
)
if not [%VERSION52%]==[] (
REM Install 52
CD lua-5.2
CALL etc\winmake installv "%TARGET%"
CD ..\luarocks
CALL install /P "%LRTARGET%" /LV 5.2 /LUA "%TARGET%" /F /NOADMIN /Q /NOREG %LRCOMPILER%
COPY "%LRTARGET%\luarocks.bat" "%TARGET%\bin\luarocks52.bat"
CD ..
REM Now pulling a trick to insert a versioned path to the rocks directory into the
REM created 'site_config' file
SET INSERTLINE=site_config.LUAROCKS_ROCKS_SUBDIR=[[/lib/luarocks/rocks-5.2]]
SETLOCAL ENABLEDELAYEDEXPANSION
for /F "usebackq tokens=*" %%A in ("%LRTARGET%\lua\luarocks\site_config_5_2.lua") do (
echo %%A >> "%LRTARGET%\lua\luarocks\site_config_5_2.lua2"
echo !INSERTLINE! >> "%LRTARGET%\lua\luarocks\site_config_5_2.lua2"
SET INSERTLINE=--
)
copy "%LRTARGET%\lua\luarocks\site_config_5_2.lua2" "%LRTARGET%\lua\luarocks\site_config_5_2.lua"
del "%LRTARGET%\lua\luarocks\site_config_5_2.lua2"
ENDLOCAL
)
if not [%VERSION53%]==[] (
REM Install 53
CD lua-5.3
CALL etc\winmake installv "%TARGET%"
CD ..\luarocks
CALL install /P "%LRTARGET%" /LV 5.3 /LUA "%TARGET%" /F /NOADMIN /Q /NOREG %LRCOMPILER%
COPY "%LRTARGET%\luarocks.bat" "%TARGET%\bin\luarocks53.bat"
CD ..
REM Now pulling a trick to insert a versioned path to the rocks directory into the
REM created 'site_config' file
SET INSERTLINE=site_config.LUAROCKS_ROCKS_SUBDIR=[[/lib/luarocks/rocks-5.3]]
SETLOCAL ENABLEDELAYEDEXPANSION
for /F "usebackq tokens=*" %%A in ("%LRTARGET%\lua\luarocks\site_config_5_3.lua") do (
echo %%A >> "%LRTARGET%\lua\luarocks\site_config_5_3.lua2"
echo !INSERTLINE! >> "%LRTARGET%\lua\luarocks\site_config_5_3.lua2"
SET INSERTLINE=--
)
copy "%LRTARGET%\lua\luarocks\site_config_5_3.lua2" "%LRTARGET%\lua\luarocks\site_config_5_3.lua"
del "%LRTARGET%\lua\luarocks\site_config_5_3.lua2"
ENDLOCAL
)
if not [%VERSION54%]==[] (
REM Install 54
CD lua-5.4
CALL etc\winmake installv "%TARGET%"
CD ..\luarocks
CALL install /P "%LRTARGET%" /LV 5.4 /LUA "%TARGET%" /F /NOADMIN /Q /NOREG %LRCOMPILER%
COPY "%LRTARGET%\luarocks.bat" "%TARGET%\bin\luarocks54.bat"
CD ..
REM Now pulling a trick to insert a versioned path to the rocks directory into the
REM created 'site_config' file
SET INSERTLINE=site_config.LUAROCKS_ROCKS_SUBDIR=[[/lib/luarocks/rocks-5.4]]
SETLOCAL ENABLEDELAYEDEXPANSION
for /F "usebackq tokens=*" %%A in ("%LRTARGET%\lua\luarocks\site_config_5_4.lua") do (
echo %%A >> "%LRTARGET%\lua\luarocks\site_config_5_4.lua2"
echo !INSERTLINE! >> "%LRTARGET%\lua\luarocks\site_config_5_4.lua2"
SET INSERTLINE=--
)
copy "%LRTARGET%\lua\luarocks\site_config_5_4.lua2" "%LRTARGET%\lua\luarocks\site_config_5_4.lua"
del "%LRTARGET%\lua\luarocks\site_config_5_4.lua2"
ENDLOCAL
)
REM install setlua.bat utility
copy .\scripts\setlua.bat "%TARGET%\bin"
copy .\scripts\clean_path.lua "%TARGET%\bin"
echo.
Echo Done installing, now setting an unversioned default;
REM set the default now
call "%TARGET%\bin\setlua.bat" %DEFAULT%
:SkipInstall