diff options
Diffstat (limited to 'c/build')
-rwxr-xr-x | c/build | 82 |
1 files changed, 82 insertions, 0 deletions
@@ -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 "$@" |