#!/usr/bin/env bash
# ===========================================================================
#  Paper Atlas - build a self-contained program (Ubuntu / Linux / macOS)
#
#    ./build.sh              build dist/PaperAtlas
#    ./build.sh --zip        also create a shareable zip
#    ./build.sh --check      only show the build plan
#
#  The result needs no Python on the target machine.  It only runs on the same
#  OS family it was built on, so build the Linux binary on Linux.
# ===========================================================================
set -uo pipefail
cd "$(dirname "$0")"

PY=""
for candidate in .venv/bin/python python3.13 python3.12 python3.11 python3.10 python3 python; do
  if [ -x "$candidate" ] || command -v "$candidate" >/dev/null 2>&1; then PY="$candidate"; break; fi
done

if [ -z "$PY" ]; then
  echo "  [!] No Python found. Run ./start.sh once (it installs its own Python) or install Python 3.10+."
  exit 1
fi

exec "$PY" build.py "$@"