-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·114 lines (96 loc) · 2.22 KB
/
build.sh
File metadata and controls
executable file
·114 lines (96 loc) · 2.22 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env bash
set -e
trap 'die "Command failed at line $LINENO"' ERR
die() {
echo
echo "[ERROR] $1" >&2
exit 1
}
usage() {
echo
echo "Usage: $0 [-d] [-r [args]]"
echo
echo " -d Build in Debug mode (default is Release)"
echo " -r [args] Run the executable after build with optional arguments"
echo " -c Run Cppcheck only"
echo
}
run_cppcheck() {
echo
echo "Running Cppcheck..."
CPPCHECK_CMD=$(command -v cppcheck || true)
if [[ -z "$CPPCHECK_CMD" ]]; then
die "Cppcheck not found"
fi
"$CPPCHECK_CMD" \
--enable=all \
--inconclusive \
--force \
--inline-suppr \
--std=c11 \
--std=c++23 \
--quiet \
--check-level=exhaustive \
--suppress=missingIncludeSystem \
-I"$(pwd)/include" \
"$(pwd)/src" \
"$(pwd)/dlls"
local CPPCHECK_EXIT=$?
echo "Cppcheck finished with exit code $CPPCHECK_EXIT"
exit $CPPCHECK_EXIT
}
# Defaults
BUILD_TYPE="Release"
RUN_EXEC=0
EXEC_NAME="sessionstealer"
RUN_ARGS=()
# Argument parsing
while [[ $# -gt 0 ]]; do
case "$1" in
-d)
BUILD_TYPE="Debug"
shift
;;
-r)
RUN_EXEC=1
shift
# Collect remaining args for runtime
while [[ $# -gt 0 ]]; do
RUN_ARGS+=("$1")
shift
done
;;
-c)
run_cppcheck
;;
*)
echo "Unknown argument: $1"
usage
exit 1
;;
esac
done
# Build
BUILD_DIR="build"
mkdir -p "$BUILD_DIR"
echo
echo "Configuring ($BUILD_TYPE)..."
cmake -S . -B "$BUILD_DIR" \
-DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
-DEXECUTABLE_OUTPUT_NAME="$EXEC_NAME" \
|| die "CMake configuration failed"
echo
echo "Building..."
cmake --build "$BUILD_DIR" --config "$BUILD_TYPE" \
|| die "Build failed"
# Run
if [[ $RUN_EXEC -eq 1 ]]; then
EXEC="$BUILD_DIR/bin/$EXEC_NAME"
if [[ ! -x "$EXEC" ]]; then
echo "Error: executable not found or not executable: $EXEC"
exit 1
fi
echo
echo "Running $EXEC ${RUN_ARGS[*]}"
"$EXEC" "${RUN_ARGS[@]}"
fi