summaryrefslogtreecommitdiff
path: root/c/build
diff options
context:
space:
mode:
Diffstat (limited to 'c/build')
-rwxr-xr-xc/build82
1 files changed, 82 insertions, 0 deletions
diff --git a/c/build b/c/build
new file mode 100755
index 0000000..f452e5a
--- /dev/null
+++ b/c/build
@@ -0,0 +1,82 @@
+#!/usr/bin/env sh
+set -e
+#set -x #trace
+
+CC=gcc
+CFLAGS=" \
+ -pipe \
+ -Wall -Wextra -Wshadow -Wpedantic -Wformat=2 \
+ -std=c99"
+
+
+CFASTF="-O2 -flto"
+CDBGF="-g3 -Og -D _DEBUG"
+
+
+# avoid "bin" just in case something goes wrong and we wipe /bin
+# #paranoia
+LIBDIR="libraries"
+SRCDIR="sources"
+BUILDDIR="binaries"
+
+main()
+{
+ case "$1" in
+ "") build_debug ;;
+ "debug") build_debug ;;
+ "release") build_release ;;
+ "clean") clean ;;
+ "help") help ;;
+ *)
+ echo "Error: Unknown argument '$1'"
+ help
+ ;;
+ esac
+}
+
+help()
+{
+ echo "Build script for Linux OSes"
+ echo "Usage: $0 [debug|release|clean|help]"
+ echo " debug - build debug mode (default)"
+ echo " release - build in release mode, aka optimized"
+ echo " clean - delete the build artifacts"
+ echo " help - print this message"
+ exit
+}
+
+build_unity()
+{
+ "$CC" -D _UNITY_BUILD $CFLAGS -fwhole-program -I $(realpath "$SRCDIR") \
+ -I $(realpath "$LIBDIR") $1 "$SRCDIR"/server.c \
+ -o "$BUILDDIR"/server
+
+ "$CC" -D _UNITY_BUILD $CFLAGS -fwhole-program -I $(realpath "$SRCDIR") \
+ -I $(realpath "$LIBDIR") $1 "$SRCDIR"/client.c \
+ -o "$BUILDDIR"/client
+}
+
+build()
+{
+ mkdir -p "$BUILDDIR"
+
+ build_unity "$1"
+}
+
+build_debug()
+{
+ build "$CDBGF"
+}
+
+build_release()
+{
+ build "$CFASTF"
+}
+
+clean()
+{
+ rm -rf $(realpath ${BUILDDIR:?})
+}
+
+
+main "$@"