-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.sh
executable file
·139 lines (126 loc) · 4.47 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
#!/bin/sh
# NOTE(rnp): to rebuild raylib run `touch build.sh` (or delete the so/dll)
cflags="-march=native -std=c11 -Wall -I./external/include"
#cflags="${cflags} -fsanitize=address,undefined"
#cflags="${cflags} -fproc-stat-report"
#cflags="${cflags} -Rpass-missed=.*"
libcflags="${cflags} -fPIC -shared -Wno-unused-variable"
ldflags="-lm"
cc=${CC:-cc}
build=release
for arg in $@; do
case "$arg" in
clang) cc=clang ;;
gcc) cc=gcc ;;
debug) build=debug ;;
release) build=release ;;
*) echo "usage: $0 [release|debug] [gcc|clang]"; exit 1;;
esac
done
case $(uname -sm) in
MINGW64*)
win32=1
glfw="libglfw.dll"
glfw_flags="-lgdi32 -lwinmm"
raylib="libraylib.dll"
main="main_w32.c"
libname="beamformer.dll"
ldflags="${ldflags} -lgdi32 -lwinmm"
if [ ! ${NO_MATLAB} ]; then
libcflags="${libcflags} -DMATLAB_CONSOLE"
extra_ldflags="-llibmat -llibmex"
fi
${cc} ${libcflags} helpers/ogl_beamformer_lib.c -o helpers/ogl_beamformer_lib.dll \
-L'C:/Program Files/MATLAB/R2022a/extern/lib/win64/microsoft' \
${extra_ldflags}
;;
Linux*)
glfw="libglfw.so.3"
glfw_flags="-D_GLFW_X11"
raylib="libraylib.so"
main="main_linux.c"
libname="beamformer.so"
cflags="${cflags} -D_DEFAULT_SOURCE"
${cc} ${libcflags} helpers/ogl_beamformer_lib.c -o helpers/ogl_beamformer_lib.so
;;
esac
if [ ! -f external/raylib/README.md ] || [ "$(git status --short external/raylib)" ]; then
git submodule update --init --depth=1 external/raylib
fi
mkdir -p external/lib
build_raylib()
{
cp external/raylib/src/raylib.h external/raylib/src/rlgl.h external/include/
cppflags="${2} -DPLATFORM_DESKTOP_GLFW -DGRAPHICS_API_OPENGL_43"
cppflags="${cppflags} -Iexternal/raylib/src -Iexternal/raylib/src/external/glfw/include"
case ${1} in
shared)
${cc} ${cflags} ${cppflags} -fPIC -shared -DBUILD_LIBTYPE_SHARED \
external/raylib/src/raudio.c external/raylib/src/rcore.c \
external/raylib/src/rmodels.c external/raylib/src/rshapes.c \
external/raylib/src/rtext.c external/raylib/src/rtextures.c \
external/raylib/src/utils.c \
-o ${raylib}
;;
static)
${cc} ${cflags} ${cppflags} -c external/raylib/src/raudio.c -o external/lib/raudio.c.o
${cc} ${cflags} ${cppflags} -c external/raylib/src/rcore.c -o external/lib/rcore.c.o
${cc} ${cflags} ${cppflags} -c external/raylib/src/rmodels.c -o external/lib/rmodels.c.o
${cc} ${cflags} ${cppflags} -c external/raylib/src/rshapes.c -o external/lib/rshapes.c.o
${cc} ${cflags} ${cppflags} -c external/raylib/src/rtext.c -o external/lib/rtext.c.o
${cc} ${cflags} ${cppflags} -c external/raylib/src/rtextures.c -o external/lib/rtextures.c.o
${cc} ${cflags} ${cppflags} -c external/raylib/src/utils.c -o external/lib/utils.c.o
ar rc external/lib/libraylib.a external/lib/raudio.c.o external/lib/rcore.c.o \
external/lib/rmodels.c.o external/lib/rshapes.c.o external/lib/rtext.c.o \
external/lib/rtextures.c.o external/lib/rtextures.c.o external/lib/utils.c.o
;;
esac
}
check_and_rebuild_libs()
{
# NOTE(rnp): we need to build glfw separately so that we can use functions from
# glfw directly - raylib doesn't let us open multiple opengl contexts even if
# we never plan on using them with raylib
case "${1}" in
static)
if [ "./build.sh" -nt "${glfw}" ] || [ ! -f ${glfw} ]; then
${cc} ${cflags} ${glfw_flags} -static \
-c external/raylib/src/rglfw.c -o external/lib/rglfw.o
ar rc ${glfw} external/lib/rglfw.o
fi
;;
shared)
if [ "./build.sh" -nt "${glfw}" ] || [ ! -f "${glfw}" ]; then
[ "${win32}" ] && glfw_flags="${glfw_flags} -D_GLFW_BUILD_DLL"
${cc} ${cflags} ${glfw_flags} -fPIC -shared \
external/raylib/src/rglfw.c -o ${glfw}
fi
;;
esac
if [ "./build.sh" -nt "${raylib}" ] || [ ! -f "${raylib}" ]; then
[ ${1} = "static" ] && build_raylib ${1} "-static"
[ ${1} = "shared" ] && build_raylib ${1} "-L. -lglfw ${ldflags}"
fi
}
case "${build}" in
debug)
cflags="${cflags} -O0 -D_DEBUG -Wno-unused-function"
if [ "${win32}" ]; then
# NOTE(rnp): export pdb on win32; requires clang
cflags="${cflags} -fuse-ld=lld -g -gcodeview -Wl,--pdb="
else
cflags="${cflags} -ggdb -Wl,-rpath,."
fi
check_and_rebuild_libs "shared"
ldflags="-L. -lglfw -lraylib ${ldflags}"
${cc} ${cflags} -fPIC -shared beamformer.c -o ${libname} ${ldflags}
;;
release)
cflags="${cflags} -O3"
raylib="external/lib/libraylib.a"
glfw="external/lib/libglfw.a"
ldflags="${raylib} ${glfw} ${ldflags}"
check_and_rebuild_libs "static"
;;
esac
${cc} ${cflags} -o ogl ${main} ${ldflags}