-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·57 lines (47 loc) · 1.27 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
#!/bin/sh
dir="$(dirname "$0")"
cd "$dir" || exit
abspath="$(realpath "$dir")"
mkdir -p ./bin >/dev/null 2>&1
mkdir -p ./obj >/dev/null 2>&1
. ./cflags.sh
# /path/to/meme.c -> meme
exename() {
basename "$1" | rev | cut -d. -f2- | rev | cut -d_ -f2-
}
compile() {
${cc:-gcc} $cflags "$@" $ldflags -lGL -lX11 -lm
}
case "$1" in
lib)
echo ":: building lib"
shift
compile "$@" -I"$abspath" -D_XOPEN_SOURCE=600 -shared -fPIC -o WeebCore.so \
Platform/PlatformLib.c || exit
exit 0
;;
esac
# I explicitly build core separately just to make sure it's built with the absolute minimum cflags
# so that any non-portable code is more likely to generate a warning
echo ":: building core"
compile -DWEEBCORE_IMPLEMENTATION -c -o obj/WeebCore.o WeebCore.c || exit
cflags="$cflags
-I\"$abspath\"
-DWEEBCORE_OVERRIDE_MONOLITHIC_BUILD=1
-D_XOPEN_SOURCE=600 obj/WeebCore.o"
case "$1" in
*.c)
compile "$@" -I"$abspath" -o "./bin/$(exename "$1")" || exit
;;
*)
echo ":: building examples"
for x in Examples/*.c; do
compile "$@" "$x" -I"$abspath" -o "./bin/$(exename "$x")"\
|| exit
done
echo ":: building utils"
for x in Utils/*.c; do
compile "$@" "$x" -I"$abspath" -o "./bin/$(exename "$x")" || exit
done
;;
esac