aboutsummaryrefslogtreecommitdiff
path: root/compile.sh
diff options
context:
space:
mode:
authorfschildt <florian.schildt@protonmail.com>2025-11-25 06:21:26 +0100
committerfschildt <florian.schildt@protonmail.com>2025-11-25 06:21:26 +0100
commit3f95bc6b463f629c620ba5811ca3ce53ed9c03a2 (patch)
tree8e2637270472b3ff787f95b24c9567d0c4d3df2b /compile.sh
parent746819470de51c4f7331b64980f3da9bfb750a12 (diff)
add MemoryManager, enhance cmake,compile.sh
Diffstat (limited to 'compile.sh')
-rwxr-xr-xcompile.sh71
1 files changed, 57 insertions, 14 deletions
diff --git a/compile.sh b/compile.sh
index c70dfe6..4b5a82d 100755
--- a/compile.sh
+++ b/compile.sh
@@ -1,16 +1,59 @@
-#!/bin/sh
-
-mkdir -p build
-cd build
-
-if [[ "$1" == "release" ]]; then
- echo "Release"
- cmake -DCMAKE_BUILD_TYPE=Release ../cmake
- cmake --build .
-else
- echo "Debug"
- cmake -DCMAKE_BUILD_TYPE=Debug ../cmake
- cmake --build .
+#!/usr/bin/env bash
+set -euo pipefail
+
+
+
+# Config
+BUILD_DIR=${BUILD_DIR:-build}
+BUILD_TYPE=${BUILD_TYPE:-Debug}
+NUM_JOBS=$(nproc 2>/dev/null || sysctl -n hw.logicalcpu 2>/dev/null || echo 8)
+CMAKE_GENERATOR=${CMAKE_GENERATOR:-}
+PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+
+
+
+# Parse Arguments
+while [[ $# -gt 0 ]]; do
+ case $1 in
+ release|--release) BUILD_TYPE=Release ;;
+ debug|--debug) BUILD_TYPE=Debug ;;
+ ninja|--ninja) CMAKE_GENERATOR="-G Ninja" ;;
+ clean|--clean) rm -rf "$BUILD_DIR"; echo "Cleaned $BUILD_DIR"; exit 0 ;;
+ *) echo "Unknown argument: $1"; exit 1 ;;
+ esac
+ shift
+done
+
+
+
+# Create and enter build direcotry
+mkdir -p "$BUILD_DIR"
+cd "$BUILD_DIR"
+
+
+
+# Configure CMake
+echo "Configuring ($BUILD_TYPE) in $BUILD_DIR ..."
+cmake ../cmake \
+ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
+ -DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
+ $CMAKE_GENERATOR \
+ "${CMAKE_ARGS:-}" # allow CMAKE_ARGS="..." ./compile.sh for extra flags
+
+
+
+# Refresh compile_commands.json
+rm -f ../compile_commands.json
+if [[ -f compile_commands.json ]]; then
+ ln -sf "$(pwd)/compile_commands.json" ../compile_commands.json
+ chmod a-x ../compile_commands.json 2>/dev/null || true
+ echo "compile_commands.json linked"
fi
-cd ..
+
+
+# ----------- Build -----------------------------------------------------
+echo "Building with $NUM_JOBS jobs ..."
+cmake --build . -- -j"$NUM_JOBS"
+
+