summaryrefslogtreecommitdiff
path: root/build.sh
diff options
context:
space:
mode:
authornasr <nsrddyn@gmail.com>2026-03-26 22:35:30 +0100
committernasr <nsrddyn@gmail.com>2026-04-13 17:24:42 +0200
commitdd5586abec207dd4acd16d51ce0d392c03e5e957 (patch)
treee56573f49ebb2a3236a39148842dc80bde5a286d /build.sh
feature(main): initmain
feature(main): init
Diffstat (limited to 'build.sh')
-rwxr-xr-xbuild.sh52
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
3set -eu
4
5DIR="$(dirname "$(readlink -f "$0")")"
6cd "$DIR"
7
8BUILD="build"
9mkdir -p "$BUILD"
10
11COMPILER="clang"
12CLEAN=0
13ASAN=0
14DEBUG=1
15RELEASE=0
16TARGET_FAJR=0
17
18[ "$#" = 0 ] && TARGET_FAJR=1
19for ARG in "$@"; do eval "$ARG=1" 2>/dev/null || :; done
20
21[ "$RELEASE" = 1 ] && DEBUG=0
22
23compile() {
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
43if [ "$CLEAN" = 1 ]; then
44 rm -rf "$BUILD"/*
45 echo "Cleaned $BUILD"
46fi
47
48if [ "$TARGET_FAJR" = 1 ] || [ "${fajr:-0}" = 1 ]; then
49 compile "./source/fajr/fajr_main.c" "compiler"
50fi
51
52echo "Done."