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

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

# Prebuilt OGDF static library; its presence marks a completed bootstrap.
OGDF_LIB := thirdparty/ogdf/build/libOGDF.a

# Default target
all: build

# Clone OGDF at the pinned tag and build its static libraries from source.
bootstrap:
	@./scripts/bootstrap_ogdf.sh

# Auto-bootstrap: build OGDF only if it has not been built yet.
$(OGDF_LIB):
	@./scripts/bootstrap_ogdf.sh

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

# Build/rebuild the extension after code changes.
# The distribution is named "ogdf-py" (see pyproject.toml); --refresh-package
# busts uv's build cache so C++ source edits are actually recompiled.
build: $(OGDF_LIB)
	@uv sync --reinstall-package ogdf-py --refresh-package ogdf-py

# Alias for build
rebuild: build

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

# Run the illustrative demos (writes SVGs and data files to build/demo-output)
demos:
	@uv run python demos/run_all.py

# Lint with ruff (applies fixes)
lint:
	@uv run ruff check --fix src/ tests/

# Lint with ruff (check only, no fixes)
lint-check:
	@uv run ruff check src/ tests/

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

# Check formatting without modifying files
format-check:
	@uv run ruff format --check src/ tests/

# Type check with mypy
typecheck:
	@uv run mypy src/ogdf

# Run a full quality assurance check (non-mutating; mirrors CI)
qa: lint-check format-check typecheck test

# Build wheel
wheel:
	@uv build --wheel

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

# Check distributions with twine
check:
	@uv run twine check dist/*

# Build both wheel and sdist
dist: wheel sdist check

# 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/ogdf --cov-report=term-missing

# Generate HTML coverage report
coverage-html:
	@uv run pytest tests/ -v --cov=src/ogdf --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

# Create a release (bump version, tag, push)
release:
	@echo "Current version: $$(grep '^version' pyproject.toml | head -1)"
	@read -p "New version: " version; 	sed "s/^version = .*/version = \"$$version\"/" pyproject.toml > pyproject.toml.tmp && mv pyproject.toml.tmp pyproject.toml; 	git add pyproject.toml; 	git commit -m "Bump version to $$version"; 	git tag -a "v$$version" -m "Release $$version"; 	echo "Tagged v$$version. Run 'git push && git push --tags' to publish."

# 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 "  bootstrap    - Clone OGDF at the pinned tag and build it from source"
	@echo "  sync         - Sync environment (initial setup)"
	@echo "  build        - Rebuild extension after code changes"
	@echo "  rebuild      - Alias for build"
	@echo "  test         - Run tests"
	@echo "  demos        - Run demos (output to build/demo-output)"
	@echo "  lint         - Lint with ruff (applies fixes)"
	@echo "  lint-check   - Lint with ruff (check only)"
	@echo "  format       - Format with ruff"
	@echo "  format-check - Check formatting without modifying files"
	@echo "  typecheck    - Type check with mypy"
	@echo "  qa           - Run full quality assurance (non-mutating: lint-check, format-check, typecheck, test)"
	@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 "  clean        - Remove build artifacts"
	@echo "  distclean    - Remove all generated files"
	@echo "  help         - Show this help message"
