From 444bfa2f41143aff7490e4fa21565947565b7d30 Mon Sep 17 00:00:00 2001 From: nasr Date: Fri, 13 Mar 2026 22:31:21 +0100 Subject: cleanup: generalisation --- build.sh | 54 ++++++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) (limited to 'build.sh') diff --git a/build.sh b/build.sh index 80f3d5a..e602edb 100755 --- a/build.sh +++ b/build.sh @@ -1,31 +1,29 @@ #!/bin/sh set -eu -# Toolchain -CC=clang - -# Files -SRC=main.c -OUT=main - -# Include paths -INCLUDES="-I." - -# Compiler flags -CFLAGS=" --g --O0 -" - -# Linker flags -LDFLAGS=" --lX11 --I. --lm -" - -echo "==> Building $OUT" -$CC $CFLAGS $INCLUDES "$SRC" -o "$OUT" $LDFLAGS - -echo "==> Running $OUT" -./"$OUT" +script_dir="$(dirname "$(readlink -f "$0")")" +cd "$script_dir" + +build_dir="build" +mkdir -p "$build_dir" + +compile() +{ + source="$1" + out="$2" + flags="${3:-}" + + common_flags="-I. -Wall -Wextra -Wno-unused-function -Wno-unused-variable" + linker_flags="-lX11 -lm" + + flags="$common_flags $flags $linker_flags" + + gcc $flags "$(readlink -f "$source")" -o "$build_dir"/"$out" +} + +# Build core shared lib +compile "source/core/core.h" "libcore.so" "-fPIC -shared -DCORE_UNITY" + +# Build app +compile "source/core/core.c" "app" "-L$build_dir -lcore" + -- cgit v1.3