#!/usr/bin/make -f

VERSION = $(lastword $(shell ./sopv-gpgv version))

COMPLETIONS = completions/bash/sopv-gpgv completions/fish/sopv-gpgv.fish completions/zsh/_sopv-gpgv
Reported_version = $(shell ./sopv-gpgv version | cut -f2 -d\ )
Changelog_version = $(shell grep Version ./Changelog.md | head -n1 | cut -f3 -d\ )

all: sopv-gpgv.1 $(COMPLETIONS)

sopv-gpgv.1: sopv-gpgv
	argparse-manpage --pyfile $< \
	--project-name sopv-gpgv \
	--author 'Daniel Kahn Gillmor <dkg@fifthhorseman.net>' \
	--version $(VERSION) \
	--function get_parser \
	--description 'Stateless OpenPGP Signature Verification backed by gpgv' \
	--output $@

completions/zsh/_sopv-gpgv: sopv-gpgv
	mkdir -p $(dir $@)
	register-python-argcomplete --shell zsh $< > $@.tmp
	mv $@.tmp $@

completions/bash/sopv-gpgv: sopv-gpgv
	mkdir -p $(dir $@)
	register-python-argcomplete --shell bash $< > $@.tmp
	mv $@.tmp $@

completions/fish/sopv-gpgv.fish: sopv-gpgv
	mkdir -p $(dir $@)
	register-python-argcomplete --shell fish $< > $@.tmp
	mv $@.tmp $@

check: typecheck spellcheck formatcheck versioncheck
	./test sqop
typecheck:
	mypy --strict sopv-gpgv
spellcheck:
	codespell README.md sopv.gpgv test LICENSE
formatcheck:
	black --check sopv-gpgv
versioncheck:
	test $(Changelog_version) = $(Reported_version)

clean:
	rm -f *.key *.cert *.cert.bin test.* sopv-gpgv.1
	rm -rf completions .mypy_cache


.PHONY: all clean typecheck spellcheck check formatcheck
