aboutsummaryrefslogtreecommitdiffstats
path: root/build.sh
blob: 3ebfee41b4ff830ae01d1814d5ee81ed3f269899 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash

set -e

BIN="build/tb_ml"
SRC="source/tb_ml/tb_ml.c"
CC="${CC:-gcc}"
CFLAGS="-Wall -Wextra -Wpedantic -Wno-attributes -fno-omit-frame-pointer -Wno-unused-variable -Wno-unused-function -fno-asynchronous-unwind-tables -ftime-report -O0 --std=c99 -g"
LDFLAGS="-lm"

usage() {
    cat <<EOF
Usage: $0 [command]

Commands:
    build       Build the project (default)
    run         Build and run
    clean       Clean build artifacts
    help        Show this message
EOF
    exit 0
}

build() {
    echo "[*] Building $BIN..."
    mkdir -p "$(dirname "$BIN")"
    $CC $CFLAGS "$SRC" -o "$BIN" $LDFLAGS
    echo "[+] Build complete: $BIN"
}

run() {
    build
    echo "[*] Running $BIN..."
    ./"$BIN"
}

clean() {
    echo "[*] Cleaning..."
    rm -rf build
    echo "[+] Clean complete"
}

cmd="${1:-build}"

case "$cmd" in
    build) build ;;
    run) run ;;
    clean) clean ;;
    help) usage ;;
    *) echo "Unknown command: $cmd"; usage ;;
esac