diff options
| author | nasr <nsrddyn@gmail.com> | 2026-03-26 22:35:30 +0100 |
|---|---|---|
| committer | nasr <nsrddyn@gmail.com> | 2026-04-13 17:24:42 +0200 |
| commit | dd5586abec207dd4acd16d51ce0d392c03e5e957 (patch) | |
| tree | e56573f49ebb2a3236a39148842dc80bde5a286d /build.sh | |
feature(main): initmain
feature(main): init
Diffstat (limited to 'build.sh')
| -rwxr-xr-x | build.sh | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..678f327 --- /dev/null +++ b/build.sh | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | set -eu | ||
| 4 | |||
| 5 | DIR="$(dirname "$(readlink -f "$0")")" | ||
| 6 | cd "$DIR" | ||
| 7 | |||
| 8 | BUILD="build" | ||
| 9 | mkdir -p "$BUILD" | ||
| 10 | |||
| 11 | COMPILER="clang" | ||
| 12 | CLEAN=0 | ||
| 13 | ASAN=0 | ||
| 14 | DEBUG=1 | ||
| 15 | RELEASE=0 | ||
| 16 | TARGET_FAJR=0 | ||
| 17 | |||
| 18 | [ "$#" = 0 ] && TARGET_FAJR=1 | ||
| 19 | for ARG in "$@"; do eval "$ARG=1" 2>/dev/null || :; done | ||
| 20 | |||
| 21 | [ "$RELEASE" = 1 ] && DEBUG=0 | ||
| 22 | |||
| 23 | compile() { | ||
| 24 | local SOURCE="$1" | ||
| 25 | local OUT="$2" | ||
| 26 | local EXTRA="${3:-}" | ||
| 27 | |||
| 28 | local COMMON="-I$DIR -I$DIR/source -D_GNU_SOURCE=1 -fno-threadsafe-statics -nostdinc++" | ||
| 29 | local WARNINGS="-Wall -Wextra -Wconversion -Wno-sign-conversion -Wno-unused-parameter -Wno-missing-field-initializers -Wno-main-return-type -Wno-unused-variable -Wno-unused-but-set-variable -Wno-switch -Wno-unused-function" | ||
| 30 | local CLANG="-fno-omit-frame-pointer -fdiagnostics-absolute-paths -Wno-null-dereference" | ||
| 31 | local LINKER="-lm -ldl -lpthread" | ||
| 32 | |||
| 33 | local FLAGS="$COMMON $WARNINGS $CLANG" | ||
| 34 | |||
| 35 | [ "$DEBUG" = 1 ] && FLAGS="$FLAGS -g -ggdb3" | ||
| 36 | [ "$RELEASE" = 1 ] && FLAGS="$FLAGS -O3" | ||
| 37 | [ "$ASAN" = 1 ] && FLAGS="$FLAGS -fsanitize=address -fsanitize-trap -Isource" | ||
| 38 | |||
| 39 | echo "Building $OUT..." | ||
| 40 | $COMPILER $FLAGS $SOURCE $EXTRA $LINKER -o "$BUILD/$OUT" | ||
| 41 | } | ||
| 42 | |||
| 43 | if [ "$CLEAN" = 1 ]; then | ||
| 44 | rm -rf "$BUILD"/* | ||
| 45 | echo "Cleaned $BUILD" | ||
| 46 | fi | ||
| 47 | |||
| 48 | if [ "$TARGET_FAJR" = 1 ] || [ "${fajr:-0}" = 1 ]; then | ||
| 49 | compile "./source/fajr/fajr_main.c" "compiler" | ||
| 50 | fi | ||
| 51 | |||
| 52 | echo "Done." | ||
