From 86d3f93ee338b28ab7d40aa83c129cf6b97ef4b7 Mon Sep 17 00:00:00 2001 From: dweller Date: Sat, 9 Mar 2024 00:55:36 +0200 Subject: Initial commit, 2 years later --- c/build | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100755 c/build (limited to 'c/build') 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 "$@" -- cgit v1.2.3