-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
build.msvs.bat
380 lines (284 loc) · 8.68 KB
/
build.msvs.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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
@REM MIT License
@REM
@REM Copyright (c) 2017-2021 Cody Tilkins
@REM
@REM Permission is hereby granted, free of charge, to any person obtaining a copy
@REM of this software and associated documentation files (the "Software"), to deal
@REM in the Software without restriction, including without limitation the rights
@REM to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@REM copies of the Software, and to permit persons to whom the Software is
@REM furnished to do so, subject to the following conditions:
@REM
@REM The above copyright notice and this permission notice shall be included in all
@REM copies or substantial portions of the Software.
@REM
@REM THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
@REM IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
@REM FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@REM AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
@REM LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
@REM OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
@REM SOFTWARE.
@echo off
REM MSVS Build File
setlocal
REM - Basic Variables --------------------------------------------------
IF NOT DEFINED debug set debug=0
REM - Basic Switches ---------------------------------------------------
IF [] == [%1] (
goto help
)
IF [/?] == [%1] (
goto help
)
IF [-?] == [%1] (
goto help
)
IF [--help] == [%1] (
goto help
)
REM - Basic Dependencies Checking --------------------------------------
REM -- TODO: add in executable checking
REM - Basic Innerworking Variables -------------------------------------
set "CWD=%cd%"
REM - Basic Cleaner ----------------------------------------------------
IF [clean] == [%1] (
echo Cleaning build directory %CWD% ...
echo Remove %CWD%\include\*.h
del %CWD%\include\*.h
echo Remove %CWD%\dll\*.dll
del %CWD%\dll\*.dll
echo Remove %CWD%\dll\*.lib
del %CWD%\dll\*.lib
echo Remove %CWD%\dll\*.exp
del %CWD%\dll\*.exp
echo Remove %CWD%\obj\*.obj
del %CWD%\obj\*.obj
rmdir /S /Q %CWD%\bin
echo Done.
exit /b 0
)
REM - Basic Installer --------------------------------------------------
IF [install] == [%1] (
IF [] == [%2] (
echo please specify where to install to
goto failure
)
IF NOT EXIST "%2" (
echo please create the destination folder first
goto failure
)
echo Installing to directory %2 ...
xcopy /Y %CWD%\bin\Release\* %2
echo Done.
exit /b 0
)
REM - Basic MSVS Setup -------------------------------------------------
IF [0] EQU [%debug%] (
set attrib=/O2
set root=%CWD%\bin\Release
) ELSE (
set attrib=/Od
set root=%CWD%\bin\Debug
)
set objdir=%CWD%\obj
set libdir=%CWD%\lib
set resdir=%CWD%\res
set rootdir=%CWD%\root
set dlldir=%CWD%\dll
set srcdir=%CWD%\src
set incdir=%CWD%\include
set dirs=/I%srcdir% /I%libdir% /I%incdir% /I%dlldir%
REM - Basic Cache Checking ---------------------------------------------
IF NOT EXIST "%CWD%\lua-all" (
echo please run prereqs.bat download to get lua-all
goto failure
)
IF NOT EXIST "%CWD%\luajit-2.0" (
echo please run prereqs.bat download to get luajit
goto failure
)
REM --------------------------------------------------------------------
IF [%1] == [driver] (
echo Cleaning workspace %CWD% ...
REM Resets bin
IF EXIST "%root%" rmdir /S /Q %root%
REM Resets dll
del %dlldir%\*.dll %dlldir%\*.lib %dlldir%\*.exp
REM Output build structure
mkdir %root%\res
mkdir %root%\dll
mkdir %root%\lang
REM Build dependencies
IF [%2] == [luajit] (
call :build_luajit
IF NOT EXIST "%root%\jit" (
mkdir %root%\jit
xcopy /E /Y %CWD%\luajit-2.0\src\jit\* %root%\jit
)
) ELSE (
IF NOT EXIST "%CWD%\lua-all\%2" (
echo supplied argument %2 is not a valid lua version in lua-all
goto failure
)
call :build_lua %2
)
REM Build driver
call :build_driver %2
REM Build install
move /Y luaw.exe %root%\luaw.exe
xcopy /E /Y %resdir%\* %root%\res
xcopy /E /Y %rootdir%\* %root%
call :build_install %2
echo Finished.
exit /b 0
)
REM --------------------------------------------------------------------
IF [%1] == [package] (
REM Force driver to be built
IF NOT EXIST "%root%\luaw.exe" (
echo please run build.mingw.bat driver lua-5.x.x first
goto failure
)
echo Cleaning workspace...
REM Resets dll
del %dlldir%\*.dll %dlldir%\*.lib %dlldir%\*.exp
IF [%2] == [luajit] (
call :build_luajit
IF NOT EXIST "%root%\jit" (
mkdir %root%\jit
xcopy /E /Y %CWD%\luajit-2.0\src\jit\* %root%\jit
)
) ELSE (
IF NOT EXIST "%CWD%\lua-all\%2" (
echo supplied argument %2 is not a valid lua version in lua-all
goto failure
)
call :build_lua %2
)
call :build_package %2
call :build_install %2
echo Finished
exit /b 0
)
REM --------------------------------------------------------------------
echo This shouldn't be reached!
goto failure
REM --------------------------------------------------------------------
:build_luajit
setlocal
echo Locally building luajit %CWD%\luajit-2.0 ...
pushd %CWD%\luajit-2.0\src
IF NOT EXIST "msvs_lua51.lib" (
call msvcbuild.bat
move lua51.lib msvs_lua51.lib
move lua51.dll msvs_lua51.dll
move lua51.exp msvs_lua51.exp
) ELSE (
echo msvs_lua51.lib already cached.
)
echo Locally installing luajit %CWD% ...
xcopy /Y lua.h %incdir%
xcopy /Y luaconf.h %incdir%
xcopy /Y lualib.h %incdir%
xcopy /Y lauxlib.h %incdir%
xcopy /Y luajit.h %incdir%
copy /Y msvs_lua51.dll %dlldir%\libluajit.dll
copy /Y msvs_lua51.lib %dlldir%\libluajit.lib
copy /Y msvs_lua51.exp %dlldir%\libluajit.exp
popd
echo Finished locally building / installing luajit.
goto :EOF
endlocal
:build_lua
setlocal
echo Locally building lua %CWD%\lua-all\%1 ...
pushd %CWD%\lua-all\%1
IF EXIST "msvs_lib%1.lib" (
echo msvs_lib%1.lib already cached.
) ELSE (
echo Building %1 ...
REM TODO: upright deleting lua.c is bad
IF EXIST "lua.c" del lua.c
REM TODO: I don't know if LUA_BUILD_AS_DLL is necessary
cl.exe /O2 /D_USRDLL /D_WINDLL /DLUA_BUILD_AS_DLL *.c /link /DLL /EXPORT:luac_main=main /OUT:lib%1.dll
move lib%1.dll msvs_lib%1.dll
move lib%1.lib msvs_lib%1.lib
move lib%1.exp msvs_lib%1.exp
)
echo Locally installing %CWD% ...
xcopy /Y lua.h %incdir%
xcopy /Y luaconf.h %incdir%
xcopy /Y lualib.h %incdir%
xcopy /Y lauxlib.h %incdir%
copy /Y msvs_lib%1.dll %dlldir%\lib%1.dll
copy /Y msvs_lib%1.lib %dlldir%\lib%1.lib
copy /Y msvs_lib%1.exp %dlldir%\lib%1.exp
popd
echo Finished installing %1.
goto :EOF
endlocal
:build_install
setlocal
echo Migrating %1 to %root%...
move /Y *.obj %objdir%
IF [luajit] == [%1] (
copy /Y %dlldir%\libluajit.dll %root%
copy /Y %dlldir%\libluajit.lib %root%
) ELSE (
copy /Y %dlldir%\lib%1.dll %root%
copy /Y %dlldir%\lib%1.lib %root%
)
move liblc%1.dll %root%
move liblc%1.lib %dlldir%
move liblc%1.exp %dlldir%
echo Finished migrating %1 to %root%.
goto :EOF
endlocal
:build_package
setlocal
IF [%1] == [luajit] (
set luaverdef=/DLUA_JIT_51
set luaverout=%dlldir%\libluajit.lib
) ELSE (
set luaverout=%dlldir%\lib%1.lib
)
echo Building luaw driver package %1...
cl.exe %attrib% %dirs% %luaverdef% /D_USRDLL /D_WINDLL /DLC_LD_DLL %srcdir%\ldata.c %srcdir%\jitsupport.c %luaverout% /link /DLL /OUT:liblc%1.dll
echo Finished building driver package %1.
goto :EOF
endlocal
:build_driver
setlocal
echo Building luaw driver...
cl.exe %attrib% %dirs% /DDEFAULT_LUA=\"liblc%1.dll\" %srcdir%\luadriver.c /link /OUT:luaw.exe
echo Building default lua package %1...
call :build_package %1
echo Finished building driver %1.
goto :EOF
endlocal
endlocal
REM Simplex help message
:help
echo Usage:
echo.
echo build build lua-x.x.x Builds the driver with a default package
echo build package lua-x.x.x Creates packages for the driver
echo build clean Cleans the environment of built files
echo build install [directory] Installs to a pre-created directory
echo build -? /? --help Shows this help message
echo.
echo build and package accepts:
echo luajit, lua-5.1, lua-5.1.5, lua-5.2.0, etc
echo.
echo Listens to these variables:
echo debug
echo.
echo debug - 0, 1 Default: 0
echo.
exit /b 0
REM General failure message
:failure
echo An error has occured!
pause
exit /b 1