#!/usr/bin/env bash

set -e # Exit immediately if a command exits with a non-zero status

echo "Building Lumacs..."

# Ensure we are in the Nix shell environment for building
# This command will either enter the shell or execute the subsequent commands within it.
# It will ensure all build inputs (cmake, pkg-config, gtkmm4 etc.) are available.
nix-shell --run "
  # Create build directory if it doesn't exist
  mkdir -p build

  echo 'Configuring with CMake...'
  cmake -S . -B build

  echo 'Building project...'
  cmake --build build

  if [ -f build/lumacs ]; then
    echo '✓ Build successful! Binary created at build/lumacs'
    echo 'Run 'build/lumacs' to start the editor'
  else
    echo '✗ Build failed: No binary found at build/lumacs'
    exit 1
  fi
"
