#!/usr/bin/env bash
# Build the profiling binary: "dbg configuration with O2", i.e. optimized like the
# experiment build but with debug info + frame pointers so perf can walk the stack.
# No source changes; binary is written into the analysis dir (repo stays clean).
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${HERE}/cases.sh"

SRCS=(main.cpp prim.cpp shake.cpp tsplib_graph.cpp vnd1.cpp vnd2.cpp vnd3.cpp vnd4.cpp)
FLAGS=(-std=c++17 -Wall -Wextra -O2 -g -fno-omit-frame-pointer)

echo "Building ${BIN}"
echo "  flags: ${FLAGS[*]}"
( cd "${REPO}" && g++ "${FLAGS[@]}" -o "${BIN}" "${SRCS[@]}" )

echo "OK. Binary info:"
file "${BIN}"
# Confirm debug info is present (not stripped).
if file "${BIN}" | grep -q "with debug_info"; then
  echo "debug_info: present"
else
  echo "WARNING: debug_info not detected"
fi
