-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.bat
163 lines (141 loc) · 5.24 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
@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
set PROG_NAME=ostinato
set SRC_DIR=src
set BIN_DIR=bin
set TMP_DIR=tmp
set EXT_DIR=ext
set INC_DIR=%EXT_DIR%\inc
set DATA_DIR=%BIN_DIR%\data
set PROG_DIR=%BIN_DIR%\prog
set XCORE_DIR=%EXT_DIR%\crosscore
set VEMA_DIR=%EXT_DIR%\vema
set BUNDLE_NAME=%PROG_NAME%.bnd
set PROG_PATH=%PROG_DIR%\%PROG_NAME%.exe
set BUNDLE_PATH=%DATA_DIR%\%BUNDLE_NAME%
if not exist %BIN_DIR% mkdir %BIN_DIR%
if not exist %PROG_DIR% mkdir %PROG_DIR%
if not exist %DATA_DIR% mkdir %DATA_DIR%
set BND_URL=https://glebnovodran.github.io/demo/ostinato.data
echo ~ Compiling Ostinato for Windows ~
goto :start
:mk_hget
echo /* WSH HTTP downloader */ > %_HGET_%
echo var req = new ActiveXObject("MSXML2.XMLHTTP.6.0"); >> %_HGET_%
echo var url = WScript.Arguments(0); var res = null; >> %_HGET_%
echo WScript.StdErr.WriteLine("Downloading " + url + "..."); >> %_HGET_%
echo try{req.Open("GET",url,false);req.Send();if(req.Status==200)res=req.ResponseText; >> %_HGET_%
echo } catch (e) { WScript.StdErr.WriteLine(e.description); } >> %_HGET_%
echo if (res) { WScript.StdErr.WriteLine("OK^!"); WScript.Echo(res); } >> %_HGET_%
echo else { WScript.StdErr.WriteLine("Failed."); } >> %_HGET_%
goto :EOF
:mk_bndget
set bnd=%BUNDLE_PATH:\=\\%
echo /* WSH bundle downloader */ > %_BNDGET_%
echo var req = new ActiveXObject("MSXML2.XMLHTTP.6.0"); >> %_BNDGET_%
echo var url = "%BND_URL%"; >> %_BNDGET_%
echo var res = null; req.Open("GET", url, false); req.Send(); >> %_BNDGET_%
echo if (req.Status == 200) { >> %_BNDGET_%
echo var data=WScript.CreateObject("ADODB.Stream"); >> %_BNDGET_%
echo data.Open(); data.Type=1;data.Write(req.ResponseBody);data.Position=0; >> %_BNDGET_%
echo data.SaveToFile("%bnd%", 2);data.Close(); >> %_BNDGET_%
echo } >> %_BNDGET_%
goto :EOF
:start
set TDM_DIR=%~dp0ext\tools\TDM-GCC
if not x%TDM_HOME%==x (
set TDM_DIR=%TDM_HOME%
)
echo [Setting up compiler tools...]
if not exist %TDM_DIR%\bin (
echo ^^! Please install TDM-GCC tools:
echo ^^! https://jmeubank.github.io/tdm-gcc/download/
echo ^^! To build:
echo ^^! cmd /c "set TDM_HOME=^<path^>&&build.bat"
exit /B -1
)
set TDM_BIN=%TDM_DIR%\bin
set TDM_GCC=%TDM_BIN%\gcc.exe
set TDM_GPP=%TDM_BIN%\g++.exe
set TDM_MAK=%TDM_BIN%\mingw32-make.exe
set TDM_WRS=%TDM_BIN%\windres.exe
echo [C++ compiler path: %TDM_GPP%]
set _CSCR_=cscript.exe /nologo
if not exist %TMP_DIR% mkdir %TMP_DIR%
set _HGET_=%TMP_DIR%\hget.js
set _BNDGET_=%TMP_DIR%\bndget.js
echo [Checking OpenGL headers...]
if not exist %_HGET_% call :mk_hget
if not exist %INC_DIR%\GL mkdir %INC_DIR%\GL
if not exist %INC_DIR%\KHR mkdir %INC_DIR%\KHR
set KHR_REG=https://registry.khronos.org
for %%i in (GL\glcorearb.h GL\glext.h GL\wglext.h KHR\khrplatform.h) do (
if not exist %INC_DIR%\%%i (
set rel=%%i
set rel=!rel:GL\=OpenGL/api/GL/!
set rel=!rel:KHR\=EGL/api/KHR/!
%_CSCR_% %_HGET_% %KHR_REG%/!rel! > %INC_DIR%\%%i
)
)
rem goto :xskip
echo [Checking crosscore sources...]
if not exist %XCORE_DIR% mkdir %XCORE_DIR%
if not exist %XCORE_DIR%\ogl mkdir %XCORE_DIR%\ogl
set XCORE_BASE=https://raw.githubusercontent.com/schaban/crosscore_dev/main/src
for %%i in (crosscore.hpp crosscore.cpp demo.hpp demo.cpp draw.hpp oglsys.hpp oglsys.cpp oglsys.inc scene.hpp scene.cpp smprig.hpp smprig.cpp draw_ogl.cpp ogl\gpu_defs.h ogl\progs.inc ogl\shaders.inc) do (
if not exist %XCORE_DIR%\%%i (
set rel=%%i
%_CSCR_% %_HGET_% %XCORE_BASE%/!rel:\=/! > %XCORE_DIR%\%%i
)
)
:xskip
if not exist %BUNDLE_PATH% (
echo ^^! Cannot find resource bundle^^!
echo ^^! Downloading from %BND_URL%
if not exist %_BNDGET_% call :mk_bndget
%_CSCR_% %_BNDGET_%
)
if exist %BUNDLE_PATH% (
echo [Bundle location: %BUNDLE_PATH%]
)
if exist %PROG_PATH% (
echo [Removing previously compiled executable %PROG_PATH%...]
del %PROG_PATH%
)
set SRC_FILES=
for /f %%i in ('dir /b %SRC_DIR%\*.cpp') do (
set SRC_FILES=!SRC_FILES! %SRC_DIR%/%%i
)
for /f %%i in ('dir /b %XCORE_DIR%\*.cpp') do (
set SRC_FILES=!SRC_FILES! %XCORE_DIR%/%%i
)
set BUILD_OPTS=%*
set VEMA_OPTS=
if x%1==x__vema__ (
echo [Building with vema...]
if not exist %VEMA_DIR% mkdir %VEMA_DIR%
for %%i in (vema.c vema.h) do (
if not exist %VEMA_DIR%\%%i (
%_CSCR_% %_HGET_% https://schaban.github.io/vema/%%i > %VEMA_DIR%\%%i
)
)
copy /Y %VEMA_DIR%\vema.c %VEMA_DIR%\vema.cpp
set SRC_FILES=!SRC_FILES! %VEMA_DIR%\vema.cpp %VEMA_DIR%\vema.h
set VEMA_OPTS=-I %VEMA_DIR% -DXD_USE_VEMA -DVEMA_GCC_BUILTINS
set BUILD_OPTS=%BUILD_OPTS:__vema__=%
)
set CPP_OFLGS=-ffast-math -ftree-vectorize
rem -O3 -flto
set XCORE_FLAGS=-DOGLSYS_ES=0 -DOGLSYS_CL=0 -DDRW_NO_VULKAN=1 -DXD_TSK_NATIVE=1 -DSCN_CMN_PKG_NAME=\"common\"
rem -fno-use-linker-plugin
set CPP_OPTS=%CPP_OFLGS% -std=c++11 -ggdb -Wno-psabi -Wno-deprecated-declarations
set LNK_OPTS=-l gdi32 -l ole32 -l windowscodecs
echo [Compiling %PROG_PATH%...]
%TDM_GPP% %CPP_OPTS% %XCORE_FLAGS% -I %INC_DIR% -I %XCORE_DIR% -I %SRC_DIR% %VEMA_OPTS% %SRC_FILES% -o %PROG_PATH% %LNK_OPTS% %BUILD_OPTS%
if exist %PROG_PATH% (
echo Success^^!
%TDM_BIN%\objdump.exe -M intel -d -C %PROG_PATH% > %PROG_DIR%\%PROG_NAME%.txt
rem %TDM_BIN%\strip.exe %PROG_PATH%
) else (
echo Failure :(
)