.PHONY: all clean test run build upgrade docs install publish help $(SUBDIR)

all: $(SUBDIR) 		# default action
	@[ -f .git/hooks/pre-commit ] || pre-commit install --install-hooks
	@git config commit.template .git-commit-template

clean: $(SUBDIR)	# clean-up environment
	@find . -name '*.sw[po]' -delete
	cargo clean

test:				# run test
	cargo test --all-features

run:				# run in the local environment

build:				# build the binary/library
	cargo build
	cargo build --release

upgrade:			# upgrade all the necessary packages
	pre-commit autoupdate

docs:				# show rustdoc
	cargo doc --open

install:			# install in the local system

publish:			# publish to crates.io
	cargo publish

help:				# show this message
	@printf "Usage: make [OPTION]\n"
	@printf "\n"
	@perl -nle 'print $$& if m{^[\w-]+:.*?#.*$$}' $(MAKEFILE_LIST) | \
		awk 'BEGIN {FS = ":.*?#"} {printf "    %-18s %s\n", $$1, $$2}'
