# Makefile frontend for scikit-build-core project
# Generated by buildgen for: cydsp
#
# This Makefile wraps common build commands for convenience.
# The actual build is handled by scikit-build-core via pyproject.toml

.PHONY: all sync build rebuild test lint format typecheck qa clean \
        distclean wheel sdist dist check publish-test publish upgrade \
        coverage coverage-html docs release help release demos

# Default target
all: build

# Sync environment (initial setup, installs dependencies + package)
sync:
	@uv sync

# Build/rebuild the extension after code changes
build:
	@uv sync --reinstall-package cydsp

# Alias for build
rebuild: build

# Run tests
test:
	@uv run pytest tests/ -v

# Lint with ruff
lint:
	@uv run ruff check --fix src/ tests/

# Format with ruff
format:
	@uv run ruff format src/ tests/

# Type check with mypy
typecheck:
	@uv run mypy src/cydsp tests/ --exclude '.venv'

# Run a full quality assurance check
qa: test lint typecheck format

# Build wheel
wheel:
	@uv build --wheel

# Build source distribution
sdist:
	@uv build --sdist

# Check distributions with twine
check:
	@uv run twine check dist/*.whl dist/*.tar.gz

# Build both wheel and sdist
dist: wheel sdist check

# Build wheels
release:
	@rm -rf dist
	@uv build --sdist
	@uv build --wheel --python 3.10
	@uv build --wheel --python 3.11
	@uv build --wheel --python 3.12
	@uv build --wheel --python 3.13
	@uv build --wheel --python 3.14
	@uv run twine check dist/*.whl dist/*.tar.gz

# Publish to TestPyPI
publish-test: check
	@uv run twine upload --repository testpypi dist/*

# Publish to PyPI
publish: check
	@uv run twine upload dist/*

# Upgrade all dependencies
upgrade:
	@uv lock --upgrade
	@uv sync

# Run tests with coverage
coverage:
	@uv run pytest tests/ -v --cov=src/cydsp --cov-report=term-missing

# Generate HTML coverage report
coverage-html:
	@uv run pytest tests/ -v --cov=src/cydsp --cov-report=html
	@echo "Coverage report: htmlcov/index.html"

# Build documentation (requires sphinx in dev dependencies)
docs:
	@uv run sphinx-build -b html docs/ docs/_build/html

# Run all demo scripts (output to build/demo-output/)
DEMO_INPUT ?= demos/s01.wav
demos:
	@mkdir -p build/demo-output
	@uv run python demos/demo_filters.py $(DEMO_INPUT)
	@uv run python demos/demo_modulation.py $(DEMO_INPUT)
	@uv run python demos/demo_distortion.py $(DEMO_INPUT)
	@uv run python demos/demo_reverb.py $(DEMO_INPUT)
	@uv run python demos/demo_dynamics.py $(DEMO_INPUT)
	@uv run python demos/demo_delay.py $(DEMO_INPUT)
	@uv run python demos/demo_pitch.py $(DEMO_INPUT)
	@uv run python demos/demo_spectral.py $(DEMO_INPUT)
	@uv run python demos/demo_daisysp_filters.py $(DEMO_INPUT)
	@uv run python demos/demo_composed.py $(DEMO_INPUT)
	@uv run python demos/demo_spectral_extra.py $(DEMO_INPUT)
	@uv run python demos/demo_ops.py $(DEMO_INPUT)
	@uv run python demos/demo_resample.py $(DEMO_INPUT)
	@uv run python demos/demo_synthesis.py
	@uv run python demos/demo_analysis.py $(DEMO_INPUT)
	@uv run python demos/demo_grainflow.py $(DEMO_INPUT)
	@uv run python demos/demo_fxdsp.py $(DEMO_INPUT)
	@uv run python demos/demo_iir_filters.py $(DEMO_INPUT)

# Clean build artifacts
clean:
	@rm -rf build/
	@rm -rf dist/
	@rm -rf *.egg-info/
	@rm -rf src/*.egg-info/
	@rm -rf .pytest_cache/
	@find . -name "*.so" -delete
	@find . -name "*.pyd" -delete
	@find . -name "__pycache__" -type d -exec rm -rf {} + 2>/dev/null || true

# Clean everything including CMake cache
distclean: clean
	@rm -rf CMakeCache.txt CMakeFiles/

# Show help
help:
	@echo "Available targets:"
	@echo "  all          - Build/rebuild the extension (default)"
	@echo "  sync         - Sync environment (initial setup)"
	@echo "  build        - Rebuild extension after code changes"
	@echo "  rebuild      - Alias for build"
	@echo "  test         - Run tests"
	@echo "  lint         - Lint with ruff"
	@echo "  format       - Format with ruff"
	@echo "  typecheck    - Type check with mypy"
	@echo "  qa           - Run full quality assurance (test, lint, typecheck, format)"
	@echo "  wheel        - Build wheel distribution"
	@echo "  sdist        - Build source distribution"
	@echo "  dist         - Build both wheel and sdist"
	@echo "  check        - Check distributions with twine"
	@echo "  publish-test - Publish to TestPyPI"
	@echo "  publish      - Publish to PyPI"
	@echo "  upgrade      - Upgrade all dependencies"
	@echo "  coverage     - Run tests with coverage"
	@echo "  coverage-html- Generate HTML coverage report"
	@echo "  docs         - Build documentation with Sphinx"
	@echo "  release      - Bump version, tag, and prepare release"
	@echo "  demos        - Run all demo scripts (DEMO_INPUT=demos/s01.wav)"
	@echo "  clean        - Remove build artifacts"
	@echo "  distclean    - Remove all generated files"
	@echo "  help         - Show this help message"
