.PHONY: setup
.PHONY: show-authordeps install-authordeps reinstall-authordeps
.PHONY: show-deps install-deps reinstall-deps
.PHONY: t tv zt test format lint clean build install release
.PHONY: cover cover-html cover-compilation cover-nvim cover-all

setup:
	utils/run setup

show-authordeps:
	@dzil authordeps

install-authordeps:
	dzil authordeps --missing | cpm install -g -

reinstall-authordeps:
	dzil authordeps | cpm install -g --reinstall --no-prebuilt -

show-deps:
	@dzil listdeps --develop

install-deps: setup
	dzil listdeps --develop --missing | cpm install -g -

reinstall-deps:
	dzil listdeps --develop | cpm install -g --reinstall --no-prebuilt -

t:
	yath test -j20 --qvf -T --term-width=$$(tput cols 2>/dev/null || echo 80)

tv:
	yath test -j20 --qvf -T \
		--term-width=$$(tput cols 2>/dev/null || echo 80) -v

zt: clean
	dzil test -j20

test: zt
	:

format:
	@mkdir -p tmp/perltidy
	@files=$$(git ls-files -z | xargs -0 utils/perl-hook list); \
	test -n "$$files" || exit 0; \
	for file in $$files; do cp "$$file" "$$file.tdybak"; done; \
	perlimports --inplace-edit --no-preserve-unused $$files 2>/dev/null \
		|| true; \
	perl -Ilib script/perl-quote-fix --inplace $$files || exit 1; \
	utils/perl-hook format $$files || exit 1; \
	for file in $$files; do \
		if ! diff -q "$$file.tdybak" "$$file" >/dev/null 2>&1; then \
			echo "Formatted $$file"; \
		fi; \
		mv "$$file.tdybak" tmp/perltidy/; \
	done

lint:
	pre-commit run --all-files

clean:
	dzil clean

build: clean
	dzil build

install: build
	dzil install

release:
	utils/run release

cover: build
	cover --delete
	HARNESS_PERL_SWITCHES=-MDevel::Cover=+ignore,^t/ make t

cover-html: cover
	cover --report=html --launch

cover-compilation: cover
	cover --report=compilation

cover-nvim: cover
	cover --report=nvim

cover-all: cover
	cover --report=nvim
	cover --report=compilation
