# Makefile for pynulid
#
# Usage:
#   make help          - Show all available targets
#   make ci            - Run all CI checks (fmt-check, clippy, lint, test)
#   make pre-commit    - Run pre-commit checks (fmt, clippy, test)

.PHONY: help
help: ## Show this help message
	@echo "Available targets:"
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "  \033[36m%-20s\033[0m %s\n", $$1, $$2}'

RUST_VERSION := $(shell grep 'rust-version = ' Cargo.toml | head -1 | sed 's/.*rust-version = "\(.*\)"/\1/')

.PHONY: install-rust
install-rust: ## Install Rust toolchain with required components
	rustup toolchain install $(RUST_VERSION)
	rustup component add rustfmt clippy --toolchain $(RUST_VERSION)

.PHONY: develop
develop: ## Build and install in development mode
	maturin develop --release

.PHONY: build
build: ## Build wheels
	maturin build --release

.PHONY: fmt
fmt: ## Format all code (Python + Rust)
	ruff format python/ tests/
	cargo +$(RUST_VERSION) fmt

.PHONY: fmt-check
fmt-check: ## Check code formatting (Python + Rust)
	ruff format --check python/ tests/
	cargo +$(RUST_VERSION) fmt --check

.PHONY: clippy
clippy: ## Run clippy lints on Rust code
	cargo +$(RUST_VERSION) clippy -- -D warnings

.PHONY: lint
lint: ## Run Python linter
	ruff check python/ tests/

.PHONY: test
test: develop ## Run all tests
	pytest tests/ -v

.PHONY: clean
clean: ## Clean build artifacts
	cargo clean
	rm -rf dist/ *.egg-info/

.PHONY: ci
ci: fmt-check clippy lint test ## Run all CI checks

.PHONY: pre-commit
pre-commit: fmt clippy test ## Run pre-commit checks

.PHONY: publish
publish: ## Publish to PyPI (requires MATURIN_PYPI_TOKEN)
	maturin publish --release
