.PHONY: all setup agent ui clean check help

# Default target: builds everything
all: ui

# Install the required rust target for static agent builds
setup:
	rustup target add x86_64-unknown-linux-musl

# Build the agent statically (Zero dynamic dependencies)
agent:
	@echo "Building rmon-agent (static x86_64-musl)..."
	cargo build --release --target x86_64-unknown-linux-musl -p rmon-agent

# Build the UI
# Note: This depends on 'agent' because rmon-ui embeds the agent binary via include_bytes!
ui: agent
	@echo "Building rmon-ui..."
	cargo build --release -p rmon-ui

# Run all workspace tests
check:
	cargo test --workspace -- --test-threads=1

# Generate coverage report (requires cargo-tarpaulin)
coverage:
	cargo tarpaulin --workspace --timeout 120 --out Lcov --output-dir target/coverage

# Clean all build artifacts
clean:
	cargo clean

# Show help
help:
	@echo "RMon Build System"
	@echo ""
	@echo "Targets:"
	@echo "  setup   - Install the x86_64-musl rust target"
	@echo "  agent   - Build the statically-linked agent binary"
	@echo "  ui      - Build the desktop UI (includes the agent binary)"
	@echo "  all     - Build both (default)"
	@echo "  check   - Run all workspace tests"
	@echo "  clean   - Remove build artifacts"
