diff options
author | dweller <dweller@cabin.digital> | 2024-03-09 00:55:36 +0200 |
---|---|---|
committer | dweller <dweller@cabin.digital> | 2024-03-09 00:55:36 +0200 |
commit | 86d3f93ee338b28ab7d40aa83c129cf6b97ef4b7 (patch) | |
tree | 507a8d66932e6dea9b121dfcbf980f7925575c9f /c/build |
Initial commit, 2 years later
Diffstat (limited to '')
-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 "$@" |