-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.bat
198 lines (169 loc) · 5.73 KB
/
build.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
@echo off
set name="edim"
set "projDirectory=%cd%"
set compiler=%1
set command=%compiler%
set arch=%2
set type=%3
rem.TODO- Fix these:
if exist "%projDirectory%\src\win32\NUL" (
set win32sources="%projDirectory%\src\win32\*.c"
)
if not exist "%projDirectory%\src\libs\NUL" goto :continue
set libc="%projDirectory%\src\libs\*.c"
set libh="-I%projDirectory%\src\libs"
set msvclibh="/I%projDirectory%\src\libs"
:continue
if /i "%compiler%"=="gcc" goto :gcc
if /i "%compiler%"=="clang" goto :clang
if /i "%compiler%"=="msvc" goto :msvc
if /i "%compiler%"=="" goto :msvc
if /i "%command%"=="run" goto :run
if /i "%command%"=="clean" goto :clean
if /i "%command%"=="init" goto :initmsvc
if /i "%command%"=="help" goto :help
echo Error: Unknown command [argument 2]
goto :end
:gcc
if /i "%arch%"=="x86" goto :gccx86
if /i "%arch%"=="x64" goto :gccx64
if /i "%arch%"=="" goto :gccx86
echo Error: Unknown architecture. Must enter either 'x86' or 'x86_64' [argument 2]
goto :end
:gccx86
mkdir build\debug >NUL 2>NUL
cd build\debug
echo Using GCC
gcc -m32 -Wall -g -D_CRT_SECURE_NO_WARNINGS ..\..\src\*.c %win32sources% %libc% -I..\..\src\headers\ %libh% -o %name%.exe
cd ..\..
goto :end
:gccx64
mkdir build\debug >NUL 2>NUL
cd build\debug
echo Using GCC
gcc -m64 -Wall -g -D_CRT_SECURE_NO_WARNINGS ..\..\src\*.c %win32sources% %libc% -I..\..\src\headers\ %libh% -o %name%.exe
cd ..\..
goto :end
:clang
if /i "%arch%"=="x86" goto :clangx86
if /i "%arch%"=="x64" goto :clangx64
if /i "%arch%"=="" goto :clangx86
echo Error: Unknown architecture. Must enter either 'x86' or 'x86_64' [argument 2]
goto :end
:clangx86
mkdir build\debug >NUL 2>NUL
cd build\debug
echo Using Clang for Windows
clang -m32 -Wall -g -D_CRT_SECURE_NO_WARNINGS ..\..\src\*.c %win32sources% %libc% -I..\..\src\headers\ %libh% -o %name%.exe
cd ..\..
goto :end
:clangx64
mkdir build\debug >NUL 2>NUL
cd build\debug
echo Using Clang for Windows
clang -m64 -Wall -g -D_CRT_SECURE_NO_WARNINGS ..\..\src\*.c %win32sources% %libc% -I..\..\src\headers\ %libh% -o %name%.exe
cd ..\..
goto :end
:msvc
where cl >NUL 2>NUL
if %ERRORLEVEL%==0 goto :msvcdo
if /i "%arch%"=="x86" goto :msvcx86
if /i "%arch%"=="x64" goto :msvcx64
if /i "%arch%"=="" goto :msvcx64
echo Error: Unknown architecture. Must enter either 'x86' or 'x86_64' [argument 2]
goto :end
:msvcx86
if exist "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\*" (
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86
goto :msvcdo
)
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build" (
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvars32.bat"
goto :msvcdo
)
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build" (
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars32.bat"
goto :msvcdo
)
echo Error: Failed to find MSVC 2015 or 2017. Make sure it is installed!
goto :end
:msvcx64
if exist "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\*" (
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64
goto :msvcdo
)
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build" (
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvars64.bat"
goto :msvcdo
)
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build" (
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
goto :msvcdo
)
echo Error: Failed to find MSVC 2015 or 2017. Make sure it is installed!
goto :end
:msvcdo
if /i "%type%"=="release" goto :msvcdorelease
cd %projDirectory%
mkdir build\debug
rem.cd build\debug
echo Using MSVC
cl /D_CRT_SECURE_NO_WARNINGS /TC /nologo /Oi /Gm- /MP /FC /fp:fast /fp:except- /Zi /Zo /DEBUG %projDirectory%\src\*.c %win32sources% %libc% /I%projDirectory%\src\headers\ %msvclibh% /link -OUT:%projDirectory%\build\debug\\%name%.exe -incremental:no -opt:ref -subsystem:console
rem.cd ..\..
goto :end
:msvcdorelease
cd %projDirectory%
mkdir build\release
rem.cd build\release
echo Using MSVC
cl /D_CRT_SECURE_NO_WARNINGS /TC /nologo /O2i /Gm- /MP /FC /fp:fast /fp:except- %projDirectory%\src\*.c %win32sources% %libc% /I%projDirectory%\src\headers\ %msvclibh% /link -OUT:%projDirectory%\build\release\\%name%.exe -incremental:no -opt:ref -subsystem:console
rem.cd ..\..
goto :end
:initmsvc
where cl >NUL 2>NUL
if %ERRORLEVEL%==0 goto :initmsvcalreadydone
if /i "%arch%"=="x86" goto :initmsvcx86
if /i "%arch%"=="x64" goto :initmsvcx64
if /i "%arch%"=="" goto :initmsvcx86
echo Error: Unknown architecture. Must enter 'x86' or 'x64' [argument 2]
goto :end
:initmsvcx86
if exist "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\*" (
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86
goto :end
)
echo Error: Failed to find MSVC 2015. Make sure it is installed!
goto :end
:initmsvcx64
if exist "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\*" (
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64
goto :end
)
echo Error: Failed to find MSVC 2015. Make sure it is installed!
goto :end
:initmsvcalreadydone
echo Info: MSVC has already been initialized.
goto :end
:run
if "%arch%"=="release" goto runrelease
if "%type%"=="release" goto runrelease
if not exist build\debug\%name%.exe (
echo Must compile project before you can run it.
goto :end
)
call build\debug\%name%.exe
goto :end
:runrelease
if not exist build\release\%name%.exe (
echo Must compile project before you can run it.
goto :end
)
call build\release\%name%.exe
goto :end
:clean
rmdir /S build
:end
set "win32sources="
set "libc="
set "libh="
set "msvclibh="