summaryrefslogtreecommitdiff
path: root/lib/build.sh
blob: 725c237e11cbeddedf822b3434ba44bf566b46cd (plain)
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
#!/bin/sh

fail() {
	echo "$0: $*" >&2
	exit 1
}

CC=cc
CFLAGS="-std=c99 -Wall -Wextra -Wpedantic -D_POSIX_C_SOURCE=200809L"
LDFLAGS="-fPIC"
SOURCES="test.c vec2.c world.c log.c"
output="build"

for arg ; do
	case "$arg" in
		--runtime=*)
			runtime="${arg#*=}"
			;;
		--output=*)
			output="${arg#*=}"
			;;
		*)
			echo "usage"
			;;
	esac
done

if [ -z "$runtime" ]; then
	echo "Guessing runtime ..."

	case "$(uname -s)" in
		Linux)
			case "$(uname -m)" in
				x86_64)
					runtime="linux-x64"
					;;
			esac
			;;
	esac
fi

case "$runtime" in
	linux-x64)
		sofile="libdjup.so"
		;;
	*)
		fail "Unsupported runtime $runtime"
esac

echo Building for runtime "$runtime ..."
mkdir -p "$output/$runtime" && $CC $CFLAGS $SOURCES -shared $LDFLAGS -o "$output/$runtime/$sofile" && echo Done