set shell := ["sh", "-eu", "-c"]

# List available recipes.
default:
    @just --list

# Build the native release binaries.
build:
    moon build --target native --release

# Build and run the native GUI.
run: build
    ./_build/native/release/build/cmd/moonmix/moonmix.exe

# Build and install the native app, desktop entry and icons for your user.
install: build
    #!/bin/sh
    set -eu
    data_home=${XDG_DATA_HOME:-"$HOME/.local/share"}
    install -Dm755 _build/native/release/build/cmd/moonmix/moonmix.exe "$HOME/.local/bin/moonmix"
    install -Dm644 data/org.latha.moonmix.desktop "$data_home/applications/org.latha.moonmix.desktop"
    install -Dm644 data/icons/hicolor/scalable/apps/org.latha.moonmix.svg "$data_home/icons/hicolor/scalable/apps/org.latha.moonmix.svg"
    install -Dm644 data/icons/hicolor/symbolic/apps/org.latha.moonmix-symbolic.svg "$data_home/icons/hicolor/symbolic/apps/org.latha.moonmix-symbolic.svg"
    install -Dm644 -t "$data_home/icons/hicolor/scalable/actions" data/icons/hicolor/scalable/actions/moonmix-*.svg
    install -Dm644 data/icons/LICENSE.lucide "$data_home/doc/moonmix/LICENSE.lucide"
    if command -v gtk-update-icon-cache >/dev/null 2>&1; then
        gtk-update-icon-cache -f -t "$data_home/icons/hicolor"
    fi
    if command -v update-desktop-database >/dev/null 2>&1; then
        update-desktop-database "$data_home/applications"
    fi

# Type-check all native packages and check MoonBit formatting.
check:
    moon check --target native
    moon fmt --check

# Format the MoonBit sources.
fmt:
    moon fmt

# Run the portable model tests and container/desktop packaging tests.
test: test-container
    moon test --target wasm-gc

# Test the container runner and installer without building an image.
test-container:
    python3 tools/test-container.py

# Build and print the current audio graph without changing it.
probe: build
    ./_build/native/release/build/cmd/moonmix-probe/moonmix-probe.exe

# Build debug binaries and run the private audio/GUI smoke test.
smoke prefix="_build/screenshots/moonmix":
    moon build --target native
    mkdir -p "$(dirname -- {{ quote(prefix) }})"
    tools/smoke-test.sh {{ quote(prefix) }}

# Build the local OCI image (override its tag with MOONMIX_IMAGE).
container-build:
    podman build --format=oci -t "${MOONMIX_IMAGE:-localhost/moonmix:latest}" .

# Build and run the OCI image using the checkout's current launcher.
container-run: container-build
    ./tools/moonmix-container

# Build the OCI image and install its per-user desktop launcher.
container-install: container-build
    python3 tools/install-container.py
