.PHONY: help clean build publish release tag verify

# Portable in-place sed: works on both BSD (macOS) and GNU (Linux).
SED_INPLACE := sed -i.bak

help:
	@echo "Targets:"
	@echo "  build            Clean dist/ and build wheel + sdist"
	@echo "  publish          Build and upload to PyPI (needs UV_PUBLISH_TOKEN)"
	@echo "  release VERSION=x.y.z"
	@echo "                   Bump pyproject.toml, commit, tag, publish, push"
	@echo "  tag VERSION=x.y.z"
	@echo "                   Create and push a git tag without publishing"
	@echo "  verify           Install from PyPI via uvx and run --help"
	@echo "  clean            Remove dist/"

clean:
	rm -rf dist

build: clean
	uv build

publish: build
	uv publish

release:
ifndef VERSION
	$(error VERSION is required. Usage: make release VERSION=0.1.1)
endif
	@if [ -n "$$(git status --porcelain)" ]; then \
		echo "working tree not clean; commit or stash first"; exit 1; \
	fi
	$(SED_INPLACE) 's/^version = .*/version = "$(VERSION)"/' pyproject.toml
	rm -f pyproject.toml.bak
	git commit -am "v$(VERSION)"
	git tag "v$(VERSION)"
	$(MAKE) publish
	git push origin HEAD
	git push origin "v$(VERSION)"

tag:
ifndef VERSION
	$(error VERSION is required. Usage: make tag VERSION=0.1.1)
endif
	git tag "v$(VERSION)"
	git push origin "v$(VERSION)"

verify:
	uvx --no-cache llmwiki-cli --help
