-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·423 lines (383 loc) · 10.1 KB
/
build.sh
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
#!/bin/sh
PROG_NAME=roam_bench
BUILD_DATE="$(date)"
SYS_NAME="`uname -s`"
BUILD_PATH=$PWD
MACOS_SYSNAME=${MACOS_SYSNAME-"Darwin"}
PROG_DIR=prog
CORE_DIR=core
DATA_DIR=data
PINT_DIR=pint
INC_DIR=inc
SRC_DIR=src
TMP_DIR=tmp
ACTS_DIR=acts
WEB_TMP_DIR=tmp/web
PROG_PATH=$PROG_DIR/$PROG_NAME
RUN_PATH=run.sh
if [ "$SYS_NAME" = "FreeBSD" ]; then
NO_FMT=""
fi
FMT_BOLD=${NO_FMT-"\e[1m"}
FMT_UNDER=${NO_FMT-"\e[4m"}
FMT_BLACK=${NO_FMT-"\e[30m"}
FMT_BLACK_BG=${NO_FMT-"\e[40m"}
FMT_RED=${NO_FMT-"\e[31m"}
FMT_RED_BG=${NO_FMT-"\e[41m"}
FMT_GREEN=${NO_FMT-"\e[32m"}
FMT_GREEN_BG=${NO_FMT-"\e[42m"}
FMT_YELLOW=${NO_FMT-"\e[33m"}
FMT_YELLOW_BG=${NO_FMT-"\e[43m"}
FMT_BLUE=${NO_FMT-"\e[34m"}
FMT_BLUE_BG=${NO_FMT-"\e[44m"}
FMT_MAGENTA=${NO_FMT-"\e[35m"}
FMT_MAGENTA_BG=${NO_FMT-"\e[45m"}
FMT_CYAN=${NO_FMT-"\e[36m"}
FMT_CYAN_BG=${NO_FMT-"\e[46m"}
FMT_WHITE=${NO_FMT-"\e[37m"}
FMT_WHITE_BG=${NO_FMT-"\e[47m"}
FMT_GRAY=${NO_FMT-"\e[90m"}
FMT_GRAY_BG=${NO_FMT-"\e[100m"}
FMT_B_RED=${NO_FMT-"\e[91m"}
FMT_B_RED_BG=${NO_FMT-"\e[101m"}
FMT_B_GREEN=${NO_FMT-"\e[92m"}
FMT_B_GREEN_BG=${NO_FMT-"\e[102m"}
FMT_B_YELLOW=${NO_FMT-"\e[93m"}
FMT_B_YELLOW_BG=${NO_FMT-"\e[103m"}
FMT_B_BLUE=${NO_FMT-"\e[94m"}
FMT_B_BLUE_BG=${NO_FMT-"\e[104m"}
FMT_B_MAGENTA=${NO_FMT-"\e[95m"}
FMT_B_MAGENTA_BG=${NO_FMT-"\e[105m"}
FMT_B_CYAN=${NO_FMT-"\e[96m"}
FMT_B_CYAN_BG=${NO_FMT-"\e[106m"}
FMT_B_WHITE=${NO_FMT-"\e[97m"}
FMT_B_WHITE_BG=${NO_FMT-"\e[107m"}
FMT_OFF=${NO_FMT-"\e[0m"}
LUA_LIB_PATH=lua/lua.a
QJS_LIB_PATH=qjs/quickjs.a
WEB_CXX=""
WEB_BUILD=0
WEB_WASM=0
WEB_TGT="JS"
if [ "$#" -gt 0 ]; then
case $1 in
clean)
printf "$FMT_RED$FMT_BOLD""Removing temporary files!""$FMT_OFF\n"
for tdir in core pint inc prog tmp wrench minion $SHADERS_TGT_DIR; do
if [ -d $tdir ]; then
printf " * ""$FMT_BOLD""$tdir""$FMT_OFF\n"
rm -rf $tdir/*
rmdir $tdir
fi
done
if [ -f $RUN_PATH ]; then
printf " - ""$FMT_BOLD""$RUN_PATH""$FMT_OFF\n"
rm -f $RUN_PATH
fi
CMK_FILE="CMakeLists.txt"
if [ -f $CMK_FILE ]; then
rm -f $CMK_FILE
fi
printf "$FMT_RED$FMT_BOLD""Removing external libs!""$FMT_OFF\n"
if [ -f $LUA_LIB_PATH ]; then
rm -f $LUA_LIB_PATH
fi
if [ -f $QJS_LIB_PATH ]; then
rm -f $QJS_LIB_PATH
fi
exit 0
;;
web)
WEB_BUILD=1
if [ -n "$EMSDK" ]; then
shift
if [ "$1" = "wasm" ]; then
WEB_WASM=1
WEB_TGT="WASM"
shift
fi
WEB_CXX="em++"
fi
;;
esac
fi
printf "$FMT_MAGENTA$FMT_BOLD""*-----------------------------------------* ""$FMT_OFF\n"
printf " ""$FMT_BLUE_BG$FMT_B_YELLOW"" .: Building roam_bench project :. ""$FMT_OFF\n"
printf "$FMT_MAGENTA$FMT_BOLD""*-----------------------------------------* ""$FMT_OFF\n"
if [ $WEB_BUILD -ne 0 ]; then
if [ -z "$WEB_CXX" ]; then
printf "$FMT_RED$FMT_BOLD""web-build: can't find emscripten""$FMT_OFF\n"
exit 1
fi
fi
if [ ! -d $PROG_DIR ]; then
mkdir -p $PROG_DIR
fi
if [ ! -d $DATA_DIR/$ACTS_DIR ]; then
mkdir -p $DATA_DIR/$ACTS_DIR
fi
cp $SRC_DIR/$ACTS_DIR/*.* $DATA_DIR/$ACTS_DIR
PINT_SRC_URL="https://raw.githubusercontent.com/glebnovodran/proto-plop/main/pint/src"
PINT_SRCS="pint.hpp pint.cpp"
CORE_SRC_URL="https://raw.githubusercontent.com/schaban/crosscore_dev/main/src"
CORE_SRCS="crosscore.hpp crosscore.cpp demo.hpp demo.cpp draw.hpp oglsys.hpp oglsys.cpp oglsys.inc scene.hpp scene.cpp smprig.hpp smprig.cpp smpchar.hpp smpchar.cpp draw_ogl.cpp main.cpp"
CORE_OGL_SRCS="gpu_defs.h progs.inc shaders.inc"
CORE_MAC_SRCS=""
if [ "$SYS_NAME" = $MACOS_SYSNAME ]; then
CORE_MAC_SRCS="mac_main.m mac_ifc.h"
fi
DL_MODE="NONE"
DL_CMD=""
if [ -x "`command -v curl`" ]; then
DL_MODE="CURL"
DL_CMD="curl -o"
elif [ -x "`command -v wget`" ]; then
DL_MODE="WGET"
DL_CMD="wget -O"
fi
NEED_PINT=0
if [ ! -d $PINT_DIR ]; then
mkdir -p $PINT_DIR
NEED_PINT=1
else
for src in $PINT_SRCS; do
if [ $NEED_PINT -ne 1 ]; then
if [ ! -f $PINT_DIR/$src ]; then
NEED_PINT=1
fi
fi
done
fi
NEED_CORE=0
if [ ! -d $CORE_DIR ]; then
mkdir -p $CORE_DIR
mkdir -p $CORE_DIR/ogl
NEED_CORE=1
else
for src in $CORE_SRCS; do
if [ $NEED_CORE -ne 1 ]; then
if [ ! -f $CORE_DIR/$src ]; then
NEED_CORE=1
fi
fi
done
if [ ! -d $CORE_DIR/ogl ]; then
mkdir -p $CORE_DIR/ogl
NEED_CORE=1
fi
if [ $NEED_CORE -ne 1 ]; then
for src in $CORE_OGL_SRCS; do
if [ ! -f $CORE_DIR/ogl/$src ]; then
NEED_CORE=1
fi
done
fi
if [ $NEED_CORE -ne 1 ]; then
if [ -n "$CORE_MAC_SRCS" ]; then
for src in $CORE_MAC_SRCS; do
if [ ! -f $CORE_DIR/mac/$src ]; then
NEED_CORE=1
fi
done
fi
fi
fi
if [ $NEED_PINT -ne 0 ]; then
printf "$FMT_B_RED""-> Downloading pint sources...""$FMT_OFF\n"
for src in $PINT_SRCS; do
if [ ! -f $PINT_DIR/$src ]; then
printf "$FMT_B_YELLOW"" $src""$FMT_OFF\n"
$DL_CMD $PINT_DIR/$src $PINT_SRC_URL/$src
fi
done
fi
if [ $NEED_CORE -ne 0 ]; then
printf "$FMT_B_RED""-> Downloading crosscore sources...""$FMT_OFF\n"
for src in $CORE_SRCS; do
if [ ! -f $CORE_DIR/$src ]; then
printf "$FMT_B_BLUE"" $src""$FMT_OFF\n"
$DL_CMD $CORE_DIR/$src $CORE_SRC_URL/$src
fi
done
for src in $CORE_OGL_SRCS; do
if [ ! -f $CORE_DIR/ogl/$src ]; then
printf "$FMT_CYAN"" $src""$FMT_OFF\n"
$DL_CMD $CORE_DIR/ogl/$src $CORE_SRC_URL/ogl/$src
fi
done
if [ -n "$CORE_MAC_SRCS" ]; then
mkdir -p $CORE_DIR/mac
for src in $CORE_MAC_SRCS; do
if [ ! -f $CORE_DIR/mac/$src ]; then
printf "$FMT_CYAN"" $src""$FMT_OFF\n"
$DL_CMD $CORE_DIR/mac/$src $CORE_SRC_URL/mac/$src
fi
done
fi
fi
NEED_OGL_INC=0
if [ $WEB_BUILD -eq 0 ]; then
case $SYS_NAME in
Linux | SunOS)
NEED_OGL_INC=1
;;
esac
fi
if [ $NEED_OGL_INC -ne 0 ]; then
KHR_REG_URL=https://registry.khronos.org
INC_OGL=$INC_DIR/GL
if [ ! -d $INC_OGL ]; then
mkdir -p $INC_OGL
fi
OGL_INC_DL=0
for kh in glext.h glcorearb.h; do
if [ ! -f $INC_OGL/$kh ]; then
if [ $OGL_INC_DL -ne 1 ]; then
printf "$FMT_OFF""-> Downloading OpenGL headers...\n"
OGL_INC_DL=1
fi
printf "$FMT_B_GREEN"" $kh""$FMT_OFF\n"
$DL_CMD $INC_OGL/$kh $KHR_REG_URL/OpenGL/api/GL/$kh
fi
done
INC_KHR=$INC_DIR/KHR
if [ ! -d $INC_KHR ]; then
mkdir -p $INC_KHR
fi
for kh in khrplatform.h; do
if [ ! -f $INC_KHR/$kh ]; then
if [ $OGL_INC_DL -ne 1 ]; then
printf "$FMT_OFF""-> Downloading OpenGL headers...\n"
OGL_INC_DL=1
fi
printf "$FMT_B_GREEN"" $kh""$FMT_OFF\n"
$DL_CMD $INC_KHR/$kh $KHR_REG_URL/EGL/api/KHR/$kh
fi
done
fi
INCS="-I $CORE_DIR -I $INC_DIR -I $PINT_DIR"
SRCS="`ls $SRC_DIR/*.cpp` `ls $CORE_DIR/*.cpp` `ls $PINT_DIR/*.cpp`"
DEFS=${ALT_DEFS-"-DX11"}
LIBS=${ALT_LIBS-"-lX11"}
DEF_CXX="g++"
case $SYS_NAME in
OpenBSD)
INCS="$INCS -I/usr/X11R6/include"
LIBS="$LIBS -L/usr/X11R6/lib"
DEF_CXX="clang++"
;;
FreeBSD)
INCS="$INCS -I/usr/local/include"
LIBS="$LIBS -lpthread -L/usr/local/lib"
DEF_CXX="clang++"
;;
$MACOS_SYSNAME)
DEFS=""
LIBS="-framework Foundation -framework Cocoa -framework OpenGL -Xlinker -w"
DEF_CXX="clang++"
;;
Linux)
LIBS="$LIBS -ldl -lpthread"
;;
esac
CXX=${CXX:-$DEF_CXX}
if [ "$#" -gt 0 ]; then
case $1 in
srcs)
shift
SRCS_OUT=
printf "$FMT_GREEN""-> Dumping sources list...""$FMT_OFF\n"
if [ "$#" -gt 0 ]; then
SRCS_OUT=$1
shift
fi
SCRCS_FLG=0
if [ "$#" -gt 0 ]; then
if [ "$1" = "append" ]; then
SCRCS_FLG=1
fi
shift
fi
for src in $SRCS; do
if [ -n "$SRCS_OUT" ]; then
if [ $SCRCS_FLG -ne 0 ]; then
echo $src >> $SRCS_OUT
else
echo $src > $SRCS_OUT
fi
else
echo $src
fi
SCRCS_FLG=1
done
printf "Done.\n"
exit 0
;;
esac
fi
if [ $WEB_BUILD -ne 0 ]; then
PROG_HTML=$PROG_PATH.html
if [ ! -d "$WEB_TMP_DIR" ]; then
mkdir -p $WEB_TMP_DIR
fi
XROM_PATH="$BUILD_PATH/$WEB_TMP_DIR/xrom.cpp"
MKROM_SRC="$WEB_TMP_DIR/mkrom.cpp"
if [ ! -f "$MKROM_SRC" ]; then
printf "$FMT_B_BLUE""Downloading mkrom...""$FMT_OFF\n"
$DL_CMD $MKROM_SRC $CORE_SRC_URL/etc/rom/mkrom.cpp
fi
MKROM_EXE="$BUILD_PATH/$WEB_TMP_DIR/mkrom"
if [ ! -f "$MKROM_EXE" ]; then
printf "$FMT_B_BLUE""Compiling mkrom...""$FMT_OFF\n"
MKROM_CXX_FLGS="-O2 -flto -pthread -I $CORE_DIR"
MKROM_CXX_SRCS="$CORE_DIR/crosscore.cpp $MKROM_SRC"
$CXX $MKROM_CXX_FLGS $MKROM_CXX_SRCS -o $MKROM_EXE
fi
printf "Making ROM file:\n"
cd $DATA_DIR
ls -1d */* | $MKROM_EXE -nobin:1 -txt:$XROM_PATH
cd $BUILD_PATH
WEB_OPTS="-std=c++11 -O3"
WEB_OPTS="$WEB_OPTS -s WASM=$WEB_WASM -s SINGLE_FILE"
WEB_OPTS="$WEB_OPTS -s SINGLE_FILE -s USE_SDL=2 -s ASSERTIONS=1"
WEB_OPTS="$WEB_OPTS -s INITIAL_MEMORY=50MB -s ALLOW_MEMORY_GROWTH=1"
WEB_OPTS="$WEB_OPTS -DXD_THREADFUNCS_ENABLED=0 -DXD_FILEFUNCS_ENABLED=0"
WEB_OPTS="$WEB_OPTS -DOGLSYS_WEB -DUSE_XROM_ARCHIVE"
printf "Compiling \"$FMT_BOLD$FMT_B_MAGENTA$PROG_HTML$FMT_OFF\" with $FMT_BOLD$WEB_CXX$FMT_OFF.\n"
$WEB_CXX $WEB_OPTS $INCS $SRCS $XROM_PATH --pre-js src/web/opt.js --shell-file src/web/shell.html -o $PROG_HTML -s EXPORTED_RUNTIME_METHODS='["ccall","cwrap"]' -s EXPORTED_FUNCTIONS='["_main","_wi_set_key_state"]' $*
if [ -f "$PROG_HTML" ]; then
sed -i 's/antialias:!1/antialias:1/g' $PROG_HTML
DATE_EXPR="s/Build date:.../Build date: $BUILD_DATE | $WEB_TGT\/ROM ver./g"
sed -i "$DATE_EXPR" $PROG_HTML
printf "web-build: ""$FMT_B_GREEN""Success""$FMT_OFF""$FMT_BOLD""!!""$FMT_OFF\n"
else
printf "web-build: ""$FMT_B_RED""Failure""$FMT_OFF...\n"
fi
exit
fi
printf "Compiling \"$FMT_BOLD$FMT_B_MAGENTA$PROG_PATH$FMT_OFF\" with $FMT_BOLD$CXX$FMT_OFF.\n"
rm -f $PROG_PATH
rm -f $RUN_PATH
if [ "$SYS_NAME" = "$MACOS_SYSNAME" ]; then
if [ ! -d $TMP_DIR ]; then
mkdir -p $TMP_DIR
fi
MAC_MAIN_SRC=$CORE_DIR/mac/mac_main.m
MAC_MAIN_OBJ=$TMP_DIR/mac_main.o
rm -f $MAC_MAIN_OBJ
clang -Wno-deprecated-declarations $MAC_MAIN_SRC -Og -c -o $MAC_MAIN_OBJ
if [ ! -f $MAC_MAIN_OBJ ]; then
exit 1
fi
SRCS="$SRCS $MAC_MAIN_OBJ"
INCS="$INCS -I $CORE_DIR/mac"
fi
$CXX -std=c++11 -ggdb -DXD_MAIN_DEF_NWRK=0 $DEFS $INCS $SRCS -o $PROG_PATH $LIBS $*
if [ -f "$PROG_PATH" ]; then
printf "#!/bin/sh\n\n" > $RUN_PATH
printf "./$PROG_PATH -nwrk:0 -mood_period:10 -avg_smps:10 \$*\n" >> $RUN_PATH
chmod +x $RUN_PATH
printf "$FMT_B_GREEN""Success""$FMT_OFF""$FMT_BOLD""!!""$FMT_OFF\n"
else
printf "$FMT_B_RED""Failure""$FMT_OFF...\n"
fi