WEB2_PACKAGE_ID := html-theme-web2-1.0.0
WEB2_PACKAGE_URL := https://bitbucket.org/byteb4rb1e/html-theme-web2/downloads/$(WEB2_PACKAGE_ID).tar.gz
PYPKG_DIR := src/byteb4rb1e/sphinxcontrib/theme/web20
WITH_GPG = $(shell command -v gpg && echo yes)

PYTHON3=$(if $(wildcard .venv/.*),.venv/bin/python3,python3)

VERSION=$(shell $(PYTHON3) -m setuptools_scm)

.chore: requirements.txt requirements-dev.txt Pipfile.lock configure

.clean:
	rm -rvf dist/ build/

configure:
	autoconf

dist: src/
	$(PYTHON3) -m build

Pipfile.lock:
	pipenv lock

requirements.txt:
	$(PYTHON3) -m pipenv requirements > requirements.txt

requirements-dev.txt:
	$(PYTHON3) -m pipenv requirements --dev-only > requirements-dev.txt

src src/: $(PYPKG_DIR)/_static_extra.tar $(PYPKG_DIR)/_static_extra.tar.sha256

$(PYPKG_DIR)/_static_extra.tar: vendor/$(WEB2_PACKAGE_ID).tar
	cp -vf "$<" "$@"

$(PYPKG_DIR)/_static_extra.tar.sha256: vendor/$(WEB2_PACKAGE_ID).tar.sha256
	cp -vf "$<" "$@"

test-reports test-reports/: test-reports/integration

test-reports/integration:
	$(PYTHON3) -m tox -m integration

test-reports/audit.json:
	$(PYTHON3) -m tox -m integration

vendor/$(WEB2_PACKAGE_ID).tar.gz: $(if $(WITH_GPG),vendor/$(WEB2_PACKAGE_ID).tar.gz.asc,)
	curl -L --fail --output "$@" "$(WEB2_PACKAGE_URL)"
ifneq ($(WITH_GPG),)
	gpg --verify "$<" "$@"
endif

vendor/$(WEB2_PACKAGE_ID).tar.gz.asc:
	curl -L --fail --output "$@" "$(WEB2_PACKAGE_URL).asc"

vendor/$(WEB2_PACKAGE_ID).tar: vendor/$(WEB2_PACKAGE_ID).tar.gz
	gzip --decompress --keep --stdout  "$<" > $@

vendor/$(WEB2_PACKAGE_ID).tar.sha256:
	curl -L --fail --output "vendor/$(WEB2_PACKAGE_ID).tar.sha256" "$(patsubst %.gz,%.sha256,$(WEB2_PACKAGE_URL))"
