#!/usr/bin/env bash set -euo pipefail cd "$(dirname "$0")/.." usage() { cat < commands: debug configure, build, and test into build/ release configure, build, and test into build-release/ asan configure, build, and test with ASan and UBSan into build-asan/ wasm configure, build, and test with Emscripten into build-wasm/ all debug, asan, then wasm clean remove all build directories EOF } build() { local dir=$1 launcher=$2 shift 2 $launcher cmake -S . -B "$dir" -G Ninja "$@" cmake --build "$dir" ctest --test-dir "$dir" --output-on-failure } link_compile_commands() { ln -sf build/compile_commands.json compile_commands.json } case "${1:-}" in debug) build build "" -DCMAKE_BUILD_TYPE=Debug link_compile_commands ;; release) build build-release "" -DCMAKE_BUILD_TYPE=Release ;; asan) build build-asan "" -DCMAKE_BUILD_TYPE=Debug -DREGOLITH_SANITIZE=ON ;; wasm) build build-wasm emcmake -DCMAKE_BUILD_TYPE=Debug ;; all) "$0" debug "$0" asan "$0" wasm ;; clean) rm -rf build build-release build-asan build-wasm compile_commands.json ;; *) usage exit 1 ;; esac