#!/usr/bin/env bash set -euo pipefail # Determine absolute project root (script’s parent directory) PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # Helper to configure & build # $1 = build directory name under PROJECT_ROOT/build # $2 = CMake build type (arbitrary string; flags are driven by -DCMAKE_CXX_FLAGS) # $3 = CXX flags cmake_build() { local name=$1 local type=$2 local flags=$3 local build_dir="${PROJECT_ROOT}/build/${name}" echo "=== Configuring ${name} (${flags}) ===" rm -rf "${build_dir}" mkdir -p "${build_dir}" pushd "${build_dir}" >/dev/null cmake \ -DCMAKE_BUILD_TYPE="${type}" \ -DCMAKE_CXX_FLAGS="${flags}" \ "${PROJECT_ROOT}" make -j$(nproc) popd >/dev/null } # 1) Debug: -g cmake_build "Debug" "Debug" "-g" # 2) Release: -O3 cmake_build "Release" "Release" "-O3" # 3) RelWithDebugInfo: -g -O3 cmake_build "RelWithDebugInfo" "RelWithDebInfo" "-g -O3" # 4) Generate verbose assembly (.S) for all translation units in RelWithDebugInfo echo "=== Generating .S assembly in build/RelWithDebugInfo ===" ASM_OUT_DIR="${PROJECT_ROOT}/build/RelWithDebugInfo/asm" mkdir -p "${ASM_OUT_DIR}" # adjust the source‐file patterns as needed (e.g. .cc, .cxx) find "${PROJECT_ROOT}" -type f \( -name '*.cpp' -o -name '*.cc' \) | while read -r src; do fname="$(basename "${src}")" base="${fname%.*}" g++ -g -O3 -masm=intel -fno-verbose-asm -std=c++20 -S "${src}" \ -o "${ASM_OUT_DIR}/${base}.S" done echo "All builds complete."