#!/bin/bash

# Kotlin Build Script

SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
cd "$SCRIPT_DIR"

echo "=== Kotlin Build ==="
echo ""

# Check for kotlinc
if ! command -v kotlinc &> /dev/null; then
    echo "✗ Kotlin-kompilator hittades inte!"
    echo "  Installera Kotlin: brew install kotlin"
    exit 1
fi

echo "Använder: kotlinc"

# Compile
mkdir -p bin
if kotlinc -include-runtime -d bin/print_hej.jar src/print_hej.kt 2>&1; then
    echo "✓ Kompilering lyckades!"
    echo "  Executable: bin/print_hej.jar"
    echo ""
    
    # Skapa wrapper script
    cat > bin/print_hej << 'EOF'
#!/bin/bash
SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
cd "$SCRIPT_DIR"
java -jar bin/print_hej.jar "$@"
EOF
    chmod +x bin/print_hej
    
    echo "För att köra:"
    echo "  ./bin/print_hej <decimaler>"
else
    echo "✗ Kompilering misslyckades!"
    exit 1
fi