forked from etlegacy/etlegacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
easybuild.bat
338 lines (296 loc) · 7.85 KB
/
easybuild.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
::
:: Easybuild - Generate a clean ET:L build
::
:: Change MSVS version to your own
:: Install assets in fs_homepath/etmain
::
@echo off
@setLocal EnableDelayedExpansion
:: variables
SET game_homepath=%USERPROFILE%\Documents\ETLegacy
SET game_basepath=%USERPROFILE%\Documents\ETLegacy-Build
SET modname=legacy
SET build_type=Release
SET batloc=%~dp0
SET build_dir=!batloc!build
SET project_dir=!batloc!project
SET build_64=0
SET mod_only=0
SET use_autoupdate=1
SET use_extra=1
SET build_r2=0
SET generator=
REM SET generator=Visual Studio 16 2019
REM SET platform_toolset=-T v142
:: pickup some parameters before proceeding
set i=0
:loop
IF NOT "%1"=="" (
IF /I "%1"=="-help" (
ECHO.
ECHO ET: Legacy Easy Builder Help
ECHO ===============================
ECHO clean - clean up the build
ECHO build - run the build process
ECHO package - run the package process
ECHO install - install the game into the system
ECHO download - download assets
ECHO crust - run the uncrustify to the source
ECHO project - generate the project files for your platform
ECHO release - run the entire release process
ECHO open - open explorer to game path
ECHO help - print this help
ECHO.
ECHO Properties
ECHO -64, -debug, -mod, -noupdate, -noextra, -nor2, -generator [generator], -toolset [version] -build_dir [dir]
ECHO.
GOTO:EOF
) ELSE IF /I "%1"=="-64" (
SET build_64=1
) ELSE IF /I "%1"=="-mod" (
SET mod_only=1
) ELSE IF /I "%1"=="-noupdate" (
SET use_autoupdate=0
) ELSE IF /I "%1"=="-noextra" (
SET use_extra=0
) ELSE IF /I "%1"=="-debug" (
SET build_type=Debug
) ELSE IF /I "%1"=="-nor2" (
SET build_r2=0
) ELSE IF /I "%1"=="-generator" (
SET generator=%~2
SHIFT
) ELSE IF /I "%1"=="-toolset" (
SET platform_toolset=-T %~2
SHIFT
) ELSE IF /I "%1"=="-build_dir" (
SET build_dir=%~dpnx2
SHIFT
) ELSE (
SET /A i+=1
SET commands[!i!]=%~1
)
SHIFT
GOTO :loop
)
SET tasks=%i%
IF NOT "%generator%"=="" (
SET generator=-G "%generator%
)
REM for /L %%i in (1,1,%tasks%) do echo Task number %%i: "!commands[%%i]!"
if !errorlevel!==1 exit /b !errorlevel!
REM ECHO Checking application status
where /q cmake >nul 2>&1 && (
REM ECHO CMake ok.
) || (
ECHO Missing CMake cannot proceed.
GOTO:EOF
)
REM ECHO Applications ok. Proceeding.
:: Init the submdule
CALL:INITSUBMODULE
IF "%tasks%"=="0" (
GOTO:DEFAULTPROCESS
) ELSE (
GOTO:PROCESSCOMMANDS
)
GOTO:EOF
:: process commands if any
:PROCESSCOMMANDS
FOR /L %%i in (1,1,%tasks%) DO (
if !errorlevel!==1 exit /b !errorlevel!
CALL:FUNCTIONS "!commands[%%i]!"
)
GOTO:EOF
:FUNCTIONS
set curvar=%~1
IF /I "!curvar!"=="clean" CALL:DOCLEAN
IF /I "!curvar!"=="build" CALL:DOBUILD
IF /I "!curvar!"=="install" CALL:DOINSTALL
IF /I "!curvar!"=="package" CALL:DOPACKAGE
IF /I "!curvar!"=="crust" GOTO:UNCRUSTCODE
IF /I "!curvar!"=="project" CALL:OPENPROJECT
:: download assets to the homepath if they do not exist
IF /I "!curvar!"=="download" CALL:DOWNLOADPAKS "https://mirror.etlegacy.com/etmain/"
IF /I "!curvar!"=="open" explorer !game_basepath!
IF /I "!curvar!"=="release" CALL:DORELEASE
GOTO:EOF
:DORELEASE
CALL:DOCLEAN
CALL:DOBUILD
CALL:DOPACKAGE
GOTO:EOF
:INITSUBMODULE
IF NOT EXIST "!batloc!libs\CMakeLists.txt" (
ECHO Getting bundled libs...
CD !batloc!
git submodule init
git submodule update
)
GOTO:EOF
:SETUPFOLDERS
IF NOT EXIST "!game_basepath!" (
ECHO Will create base directory: "!game_basepath!"
mkdir "!game_basepath!"
)
CD !build_dir!
CALL:CLEANPATH "!game_basepath!\%modname%\" "*.pk3 *.dll *.dat"
CALL:CLEANPATH "!game_homepath!\%modname%\" "*.pk3 *.dll *.dat"
CALL:COPYFROMPATH "%cd%\" "et*.exe renderer_opengl*.dll" "!game_basepath!\"
CALL:COPYFROMPATH "%cd%\legacy\" "*.pk3 qagame*.dll *.dat" "!game_basepath!\%modname%\"
CD !batloc!
CALL:COPYFROMPATH "%cd%\misc\etmain\" "*" "!game_basepath!\etmain\"
CALL:COPYFROMPATH "%cd%\misc\" "description.txt" "!game_basepath!\%modname%\"
CALL:COPYFROMPATH "%cd%\docs\" "INSTALL.txt" "!game_basepath!"
CALL:COPYFROMPATH "%cd%\" "COPYING.txt" "!game_basepath!"
GOTO:EOF
:CLEANPATH
IF NOT EXIST %~1 GOTO:EOF
set bacpath=%cd%
cd %~1
FOR %%F IN (%~2) DO (
DEL %%F
)
cd !bacpath!
GOTO:EOF
:COPYFROMPATH
set bacpath=%cd%
cd %~1
FOR %%F IN (%~2) DO (
CALL:COPYFILE "%%F" %~3
)
cd %bacpath%
GOTO:EOF
:COPYFILE
REM /D
IF EXIST %~1 XCOPY %~1 %~2 /Y >nul
GOTO:EOF
:DEFAULTPROCESS
TITLE Building ET: Legacy
ECHO ETLegacy easybuild for Windows
CALL:DOCLEAN
CALL:DOBUILD
if errorlevel 1 (
ECHO There was an issue with the build so no files are copied
PAUSE
GOTO:EOF
)
CALL:DOINSTALL
GOTO:EOF
:DOCLEAN
:: clean
ECHO Cleaning...
IF EXIST !game_basepath! RMDIR /s /q !game_basepath!
IF EXIST !build_dir! RMDIR /s /q !build_dir!
IF EXIST !batloc!libs (
cd "!batloc!libs"
git clean -d -f
)
GOTO:EOF
:: GenerateProject(targetDir, sourceDir, compileType, crossCompile, buildR2)
:GENERATEPROJECT
ECHO Generating...
IF EXIST "%~1" RMDIR /s /q "%~1"
MKDIR "%~1"
CD "%~1"
set build_string=
CALL:GENERATECMAKE build_string
IF %build_64%==1 (
cmake !generator! !platform_toolset! -A Win64 %build_string% "%~2"
ECHO cmake !generator! !platform_toolset! -A Win64 %build_string% "%~2"
) ELSE (
cmake !generator! !platform_toolset! -A Win32 %build_string% "%~2"
ECHO cmake !generator! !platform_toolset! -A Win32 %build_string% "%~2"
)
GOTO:EOF
:OPENPROJECT
CALL:GENERATEPROJECT !project_dir! "!batloc!"
ETLEGACY.sln
GOTO:EOF
:DOBUILD
:: build
CALL:GENERATEPROJECT !build_dir! "!batloc!"
ECHO Building...
REM msbuild ETLEGACY.sln /target:CMake\ALL_BUILD /p:Configuration=%build_type%
cmake --build . --config %build_type%
GOTO:EOF
:DOINSTALL
:: install
ECHO Setting up the game
CALL:SETUPFOLDERS
:: done
CALL:CREATELINK "ETLegacy" "!game_basepath!\etl.exe" "!game_basepath!"
ECHO The %build_type% build has been installed in %game_basepath%, and shortcut has been added to your desktop
GOTO:EOF
:DOPACKAGE
:: package
ECHO Packaging...
CD %build_dir%
cpack
GOTO:EOF
:UNCRUSTCODE
echo Uncrustifying code...
FOR /R "!batloc!src" %%G IN (*.h *.c *.cpp *.glsl) DO call:UNCRUSTFILE %%G
GOTO:EOF
:UNCRUSTFILE
set pathstr=%~1
if not x%pathstr:unzip.c=%==x%pathstr% GOTO:EOF
if not x%pathstr:sha-1=%==x%pathstr% GOTO:EOF
if not x%pathstr:Omnibot=%==x%pathstr% GOTO:EOF
uncrustify --no-backup -c %batloc%uncrustify.cfg %~1
GOTO:EOF
:CREATELINK
set SCRIPT="%TEMP%\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs"
echo Set oWS = WScript.CreateObject("WScript.Shell") >> !SCRIPT!
echo sLinkFile = "%USERPROFILE%\Desktop\%~1.lnk" >> !SCRIPT!
echo Set oLink = oWS.CreateShortcut(sLinkFile) >> !SCRIPT!
echo oLink.TargetPath = "%~2" >> !SCRIPT!
echo oLink.WorkingDirectory = "%~3" >> !SCRIPT!
echo oLink.Save >> !SCRIPT!
cscript /nologo !SCRIPT!
del !SCRIPT!
GOTO:EOF
:DOWNLOADPAKS
IF NOT EXIST "!game_homepath!\etmain" (
md "!game_homepath!\etmain"
)
IF NOT EXIST "!game_homepath!\etmain\pak0.pk3" (
bitsadmin /transfer "pak0" %~1pak0.pk3 "!game_homepath!\etmain\pak0.pk3"
)
GOTO:EOF
:Substring
::Substring(retVal,string,startIndex,length)
:: extracts the substring from string starting at startIndex for the specified length
SET string=%2%
SET startIndex=%3%
SET length=%4%
if "%4" == "0" goto :noLength
CALL SET _substring=%%string:~%startIndex%,%length%%%
goto :substringResult
:noLength
CALL SET _substring=%%string:~%startIndex%%%
:substringResult
set "%~1=%_substring%"
GOTO :EOF
:: GenerateCmake(outputVar, crosscompile, buildR2)
:GENERATECMAKE
SETLOCAL
IF %build_64%==1 (
SET CROSSCOMP=NO
) ELSE (
SET CROSSCOMP=YES
)
SET loca_build_string=-DBUNDLED_LIBS=YES ^
-DCMAKE_BUILD_TYPE=!build_type! ^
-DFEATURE_AUTOUPDATE=!use_autoupdate! ^
-DINSTALL_EXTRA=!use_extra! ^
-DCROSS_COMPILE32=!CROSSCOMP! ^
-DRENDERER_DYNAMIC=!build_r2! ^
-DFEATURE_RENDERER2=!build_r2!
IF !mod_only!==1 (
SET loca_build_string=!loca_build_string! ^
-DBUILD_CLIENT=0 ^
-DBUILD_SERVER=0
)
ENDLOCAL&SET "%~1=%loca_build_string%"
GOTO:EOF