-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.bat
More file actions
282 lines (225 loc) · 8.22 KB
/
build.bat
File metadata and controls
282 lines (225 loc) · 8.22 KB
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
@echo off
SETLOCAL
REM ===========================================================================
REM -- WINDOWS BUILD SCRIPT FOR C PROJECTS --
REM ===========================================================================
REM Include required dependencies
set LIBRARY_LIST=GLFW SDL2 GLEW FREETYPE POGLIB
set GLFW_URL=https://github.com/glfw/glfw/releases/download/3.3.8/glfw-3.3.8.bin.WIN64.zip
set SDL2_URL=https://www.libsdl.org/release/SDL2-devel-2.0.20-VC.zip
set GLEW_URL=https://github.com/nigels-com/glew/releases/download/glew-2.2.0/glew-2.2.0-win32.zip
set FREETYPE_URL=https://github.com/ubawurinna/freetype-windows-binaries/archive/refs/heads/master.zip
set POGLIB_URL=https://github.com/gimploo/poglib/archive/refs/heads/dev.zip
REM Include compiler of choice (here its msvc)
set CC=cl
set CC_PATH="C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
set CC_DEFAULT_FLAGS=/std:c11 /W4 /wd4244 /wd4996 /wd4477 /wd4267 /w14996 /FC /TC /Zi /experimental:c11atomics
set CC_DEFAULT_LIBS=User32.lib Gdi32.lib Shell32.lib winmm.lib dbghelp.lib shlwapi.lib
REM Source and executalble path (default)
set EXE_FOLDER_DEFAULT_PATH=.\bin
set SRC_FOLDER_DEFAULT_PATH=.\src
set LIBRARY_DEFAULT_PATH=.\lib
REM Source files and exe name
set SRC_FILE_NAME=main.c
set EXE_FILE_NAME=GetBack.exe
:main
if "%1" == "clean" (
call :cleanup
goto :end
)
if "%1" == "deepclean" (
call :deepcleanup
goto :end
)
cls
echo [*] Running build script for windows...
echo [*] Checking `%CC%` compiler is installed ...
call :check_compiler_is_installed || goto :end
echo [*] Checking if all dependenices are installed ...
if exist "%LIBRARY_DEFAULT_PATH%" (
echo [!] `lib` directory found!
) else (
echo [!] `lib` directory not found!
echo [*] Checking dependenices ...
call :check_dependencies_are_installed && (
echo [!] Dependencies all installed !
) || (
echo [!] Error installing dependencies !
goto :end
)
)
echo [*] Checking for `bin` folder ...
if exist bin (
echo [!] `bin` directory found!
) else (
echo [!] `bin` directory not found!
mkdir bin
call :copy_all_dlls_to_bin
echo [!] `bin` directory made!
)
REM EITHER A RELEASE BUILD OR A DEBUG BUILD
if "%1" == "release" (
echo [*] Building project [RELEASE BUILD]...
call :build_project_with_msvc "release" || goto :end
echo [*] Running executable ...
call :run_executable
echo [!] Exited!
) else (
echo [*] Building project [DEBUG BUILD]...
call :build_project_with_msvc "debug" || goto :end
)
REM RUNS THE EXECUTABLE THROUGH A DEBUGGER (ONLY DEBUG BUILD)
if "%1" == "debug" (
if "%2" == "--vs" (
call :run_executable_with_vsdebugger
goto :end
) else if "%2" == "--rad" (
call :run_executable_with_raddebug
goto :end
)
)
REM RUNS THE EXECUTABLE NORMALLY (ONLY DEBUG BUILD)
if "%1" == "run" (
echo [*] Running executable ...
call :run_executable
echo [!] Exited!
)
goto :end
REM ===========================================================================
REM -- BUILD RECIPE --
REM ===========================================================================
REM (change whats in here to ) -
REM |
REM v
:build_project_with_msvc
set INCLUDES=/I %LIBRARY_DEFAULT_PATH%\GLEW\include ^
/I %LIBRARY_DEFAULT_PATH%\FREETYPE\include ^
/I %LIBRARY_DEFAULT_PATH%\poglib\external\assimp\include ^
/I %LIBRARY_DEFAULT_PATH%\SDL2\include ^
/I %LIBRARY_DEFAULT_PATH%\GLFW\include ^
/I %LIBRARY_DEFAULT_PATH%\
if "%~1" == "debug" (
set FLAGS=/DGLEW_STATIC /DDEBUG
echo [*] Generating Pre-processor file ...
%CC% %CC_DEFAULT_FLAGS% %FLAGS%^
/P %INCLUDES% %SRC_FOLDER_DEFAULT_PATH%\%SRC_FILE_NAME% || echo [!] Failed to preprocess! && exit /b 1
) else (
set FLAGS=/DGLEW_STATIC
)
set LIBS=%LIBRARY_DEFAULT_PATH%\GLEW\lib\Release\x64\glew32s.lib ^
%LIBRARY_DEFAULT_PATH%\FREETYPE\lib\win64\freetype.lib ^
%LIBRARY_DEFAULT_PATH%\poglib\external\assimp\lib\Debug\assimp-vc143-mtd.lib ^
%LIBRARY_DEFAULT_PATH%\GLFW\lib\glfw3dll.lib ^
%LIBRARY_DEFAULT_PATH%\SDL2\lib\x64\SDL2.lib ^
%LIBRARY_DEFAULT_PATH%\SDL2\lib\x64\SDL2main.lib ^
Opengl32.lib glu32.lib
%CC% %CC_DEFAULT_FLAGS% %FLAGS%^
%INCLUDES% ^
/Fe%EXE_FOLDER_DEFAULT_PATH%\%EXE_FILE_NAME% ^
%SRC_FOLDER_DEFAULT_PATH%\%SRC_FILE_NAME% ^
/link %CC_DEFAULT_LIBS% %LIBS% -SUBSYSTEM:console && (
echo [!] Compiled Successfully!
) ||(
echo [!] Failed to compile! && exit /b 1
)
move *.pdb %EXE_FOLDER_DEFAULT_PATH% >nul
move *.obj %EXE_FOLDER_DEFAULT_PATH% >nul
exit /b %errorlevel%
REM =======================================================================================
REM -- HELPER FUNCTIONS --
REM =======================================================================================
:run_executable
echo.
%EXE_FOLDER_DEFAULT_PATH%\%EXE_FILE_NAME%
echo.
exit /b %errorlevel%
:run_executable_with_vsdebugger
echo [!] Running executable through the VS debugger!
devenv /DebugExe %EXE_FOLDER_DEFAULT_PATH%\%EXE_FILE_NAME%
exit /b 0
:run_executable_with_raddebug
echo [!] Running executable through the raddebugger!
raddbg %EXE_FOLDER_DEFAULT_PATH%\%EXE_FILE_NAME% --project .\
exit /b 0
:check_dependencies_are_installed
mkdir "%LIBRARY_DEFAULT_PATH%"
pushd %LIBRARY_DEFAULT_PATH%
for %%x in (%LIBRARY_LIST%) do (
if not exist %%x (
echo [!] `%%x` directory not found!
call :download_dependency %%x
) else (
echo [!] `%%x` folder found!
)
)
popd
exit /b 0
:check_compiler_is_installed
%CC_PATH% || echo [!] Compiler %CC% not found! && goto :end
echo [!] Compiler %CC% found!
exit /b 0
:copy_all_dlls_to_bin
echo [*] Copying all DLLs to bin ...
REM ADD New dlls here!
pushd %LIBRARY_DEFAULT_PATH%
if exist SDL2 (
copy SDL2\lib\x64\SDL2.dll ..\%EXE_FOLDER_DEFAULT_PATH% >nul
)
if exist GLFW (
copy GLFW\lib\glfw3.dll ..\%EXE_FOLDER_DEFAULT_PATH% >nul
)
if exist poglib (
copy poglib\external\assimp\lib\Debug\assimp-vc143-mtd.dll ..\%EXE_FOLDER_DEFAULT_PATH% >nul
copy poglib\external\assimp\lib\Debug\assimp-vc143-mtd.pdb ..\%EXE_FOLDER_DEFAULT_PATH% >nul
)
popd
exit /b 0
:download_dependency
echo [*] Installing %~1 ...
call echo [!] link: %%%~1_URL%%%
call curl -L --output %~1.zip %%%~1_URL%%%
mkdir %~1
tar -xf %~1.zip -C %~1 --strip-components 1 && del %~1.zip
REM (to future me) U had sdl2 setup this way in ubuntu
if "%~1" == "SDL2" (
pushd SDL2\include
mkdir SDL2
move *.h SDL2\ >nul
popd
)
if "%~1" == "FREETYPE" (
pushd FreeType\
rename "release static" lib
move "lib\vs2015-2022\win64" lib\ >nul
move "lib\vs2015-2022\win32" lib\ >nul
rd /s /q "lib\vs2015-2022"
popd
)
if "%~1" == "POGLIB" (
rename "POGLIB" poglib
)
if "%~1" == "GLFW" (
pushd GLFW\
rename "lib-static-ucrt" lib
popd
)
echo [!] Successfully installed %~1!
exit /b 0
:cleanup
if exist bin (
rd /s /q bin || echo [!] `bin` folder not found!
echo [!] `bin` directory deleted!
)
exit /b 0
:deepcleanup
echo [*] Cleanup in progress ...
if exist "%LIBRARY_DEFAULT_PATH%" (
rd /s /q "%LIBRARY_DEFAULT_PATH%"
echo [!] `%LIBRARY_DEFAULT_PATH%` directory deleted!
)
call :cleanup
echo [!] Cleanup done!
exit /b 0
:end
echo [!] Script exiting!
ENDLOCAL