diff options
| author | nasr <nsrddyn@gmail.com> | 2026-03-13 22:31:21 +0100 |
|---|---|---|
| committer | nasr <nsrddyn@gmail.com> | 2026-03-13 22:31:21 +0100 |
| commit | 444bfa2f41143aff7490e4fa21565947565b7d30 (patch) | |
| tree | 696b06d40140c85805d171597e37deb8290ead73 /build.sh | |
| parent | 3913d1778318cd0c6bfb871148d38abb33ec7fd3 (diff) | |
cleanup: generalisation
Diffstat (limited to 'build.sh')
| -rwxr-xr-x | build.sh | 42 |
1 files changed, 20 insertions, 22 deletions
| @@ -1,31 +1,29 @@ | |||
| 1 | #!/bin/sh | 1 | #!/bin/sh |
| 2 | set -eu | 2 | set -eu |
| 3 | 3 | ||
| 4 | # Toolchain | 4 | script_dir="$(dirname "$(readlink -f "$0")")" |
| 5 | CC=clang | 5 | cd "$script_dir" |
| 6 | 6 | ||
| 7 | # Files | 7 | build_dir="build" |
| 8 | SRC=main.c | 8 | mkdir -p "$build_dir" |
| 9 | OUT=main | ||
| 10 | 9 | ||
| 11 | # Include paths | 10 | compile() |
| 12 | INCLUDES="-I." | 11 | { |
| 12 | source="$1" | ||
| 13 | out="$2" | ||
| 14 | flags="${3:-}" | ||
| 13 | 15 | ||
| 14 | # Compiler flags | 16 | common_flags="-I. -Wall -Wextra -Wno-unused-function -Wno-unused-variable" |
| 15 | CFLAGS=" | 17 | linker_flags="-lX11 -lm" |
| 16 | -g | ||
| 17 | -O0 | ||
| 18 | " | ||
| 19 | 18 | ||
| 20 | # Linker flags | 19 | flags="$common_flags $flags $linker_flags" |
| 21 | LDFLAGS=" | ||
| 22 | -lX11 | ||
| 23 | -I. | ||
| 24 | -lm | ||
| 25 | " | ||
| 26 | 20 | ||
| 27 | echo "==> Building $OUT" | 21 | gcc $flags "$(readlink -f "$source")" -o "$build_dir"/"$out" |
| 28 | $CC $CFLAGS $INCLUDES "$SRC" -o "$OUT" $LDFLAGS | 22 | } |
| 23 | |||
| 24 | # Build core shared lib | ||
| 25 | compile "source/core/core.h" "libcore.so" "-fPIC -shared -DCORE_UNITY" | ||
| 26 | |||
| 27 | # Build app | ||
| 28 | compile "source/core/core.c" "app" "-L$build_dir -lcore" | ||
| 29 | 29 | ||
| 30 | echo "==> Running $OUT" | ||
| 31 | ./"$OUT" | ||
