#!/bin/sh
set -euC

cd "$(dirname "$0")/.."

file="$(basename "$0")"
target="gltraits-test-$file"
build_dir="_build"
in_file="$build_dir/$target"
out_file="doc/$file.i"

rm    -rf     "$build_dir"
cmake -B      "$build_dir" -DCMAKE_BUILD_TYPE='RelWithDebInfo'
cmake --build "$build_dir" --target "$target"

${GDB:-gdb} \
  -n -batch \
  -ex 'set print asm-demangle on' \
  -ex 'disassemble/s main' \
  "$in_file" \
| sed "s|$(pwd)/||;s/^[0-9]\+//" \
>| "$out_file"
