#!/bin/bash
# ---------------------------------------------------------------------------------
# Odin compiler install recipe
# Target: Pop!_OS / Ubuntu / Debian
# Builds from source - recommended method on Linux
# ---------------------------------------------------------------------------------
set -e
ODIN_DIR="$HOME/.odin"

echo "Installing Odin build dependencies..."
sudo apt update
sudo apt install -y llvm-18-dev clang-18 git-lfs build-essential
git lfs install --force

echo "Cloning Odin repository..."
if [ -d "$ODIN_DIR" ]; then
    echo "Directory $ODIN_DIR already exists. Pulling latest..."
    cd "$ODIN_DIR" && git pull
else
    git clone https://github.com/odin-lang/Odin "$ODIN_DIR"
    cd "$ODIN_DIR"
fi

echo "Building Odin compiler..."
LLVM_CONFIG=llvm-config-18 make release-native

echo ""
echo "✓ Odin install complete."
echo "  Add to your path if needed: export PATH=\"\$HOME/.odin:\$PATH\""
echo "  Then verify with: odin version"