summaryrefslogtreecommitdiffhomepage
path: root/compile
blob: a3d07a828b7ba96b31537ef6b5922a4f49c20eaa (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
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
#!/bin/sh -e
# This file is dedicated to the public domain.

case "`uname -s`" in
	# weird people using Windows Bash might type ./compile, help them out :)
	*NT*) # msys2 or busybox-w32
		echo "You're on Windows, idiot! Running compile.bat for you.">&2
		exec cmd /c compile.bat ;;
esac
case "`uname -r`" in
	*Microsoft*)
		echo "NOTE: building inside WSL. Use compile.bat to build for Windows!">&2
esac

mkdir -p .build/include

: "${CC:=clang --target=-i686-pc-linux-gnu -fuse-ld=lld}"
: "${HOSTCC:=clang -fuse-ld=lld}"

warnings="-Wall -pedantic -Wno-parentheses -Wno-missing-braces \
-Wno-gnu-zero-variadic-macro-arguments"

dbg=0
if [ "$dbg" = 1 ]; then
	cflags="-Og -g3"
	ldflags="-Og -g3"
else
	cflags="-O2"
	ldflags="-O2 -s"
fi

objs=
cc() {
	_bn="`basename "$1"`"
	objs="$objs .build/${_bn%%.c}.o"
	_mn=" -DMODULE_NAME=${_bn%%.c}"
	# ugly annoying special case
	if [ "$_mn" = " -DMODULE_NAME=con_" ]; then _mn=" -DMODULE_NAME=con"
	elif [ "$_mn" = "-DMODULE_NAME=sst" ]; then _mn=; fi
	# note: using typeof and bool from C23 - see detailed comment in compile.bat
	$CC -m32 -c -flto -fpic $cflags $warnings -I.build/include \
		-D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64$_mn \
		-Dtypeof=__typeof -include stdbool.h -o ".build/${_bn%%.c}.o" "src/$1"
}

ld() {
	$CC -m32 -shared -flto -fpic -fno-ident -fuse-ld=lld $ldflags \
		-L.build -ldl -ltier0 -lvstdlib -o sst.so$objs
}

src="\
	ac.c
	bind.c
	crypto.c
	alias.c
	autojump.c
	con_.c
	democustom.c
	demorec.c
	engineapi.c
	ent.c
	errmsg.c
	extmalloc.c
	fixes.c
	fov.c
	gamedata.c
	gameinfo.c
	hook.c
	kv.c
	l4d2vote.c
	l4dwarp.c
	nosleep.c
	portalcolours.c
	sst.c
	x86.c"
if [ "$dbg" = 1 ]; then src="$src \
	dbg.c
	udis86.c"
fi

$HOSTCC -O2 -fuse-ld=lld $warnings -D_FILE_OFFSET_BITS=64 -include stdbool.h \
		-o .build/codegen src/build/codegen.c src/build/cmeta.c
$HOSTCC -O2 -fuse-ld=lld $warnings -D_FILE_OFFSET_BITS=64 -include stdbool.h \
		-o .build/mkgamedata src/build/mkgamedata.c src/kv.c
$HOSTCC -O2 -fuse-ld=lld $warnings -D_FILE_OFFSET_BITS=64 -include stdbool.h \
		-o .build/mkentprops src/build/mkentprops.c src/kv.c
.build/codegen `for s in $src; do echo "src/$s"; done`
.build/mkgamedata gamedata/engine.kv gamedata/gamelib.kv gamedata/inputsystem.kv
.build/mkentprops gamedata/entprops.kv
for s in $src; do cc "$s"; done
$CC -shared -fpic -fuse-ld=lld -O0 -w -o .build/libtier0.so src/stubs/tier0.c
$CC -shared -fpic -fuse-ld=lld -O0 -w -o .build/libvstdlib.so src/stubs/vstdlib.c
ld

$HOSTCC -O2 -g3 -include test/test.h -o .build/bitbuf.test test/bitbuf.test.c
.build/bitbuf.test
# skipping this test on linux for now, since inline hooks aren't compiled in
#$HOSTCC -m32 -O2 -g3 -include test/test.h -o .build/hook.test test/hook.test.c
#.build/hook.test
$HOSTCC -O2 -g3 -include test/test.h -o .build/kv.test test/kv.test.c
.build/kv.test

# vi: sw=4 tw=4 noet tw=80 cc=80