#!/usr/bin/env bash
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"

CXX="${CXX:-g++}"
OUT="${OUT:-main.exe}"

CXXFLAGS=(
  -std=c++17
  -O2
  -Wall
  -Wextra
  -pedantic
)

SOURCES=(
  main.cpp
  capture_file_writer.cpp
  tty_protocol_writer.cpp
)

LDFLAGS=(
  -ldl
  -lutil
  -lpthread
)

"$CXX" "${CXXFLAGS[@]}" "${SOURCES[@]}" "${LDFLAGS[@]}" -o "$OUT"

echo "Built $OUT"
