# Builds and installs mailctl.
#
#   make          compiles to ./mailctl
#   make install  puts the binary in /usr/local/sbin/mailctl and the zsh
#                 completion in /usr/local/share/zsh/site-functions
#
# CGO_ENABLED=0: the SQLite driver is pure Go, so the binary runs without
# any libraries from the system.

GO       ?= go
PREFIX   ?= /usr/local/sbin
ZSHCOMP  ?= /usr/local/share/zsh/site-functions

mailctl: $(wildcard *.go) go.mod go.sum
	CGO_ENABLED=0 $(GO) build -trimpath -ldflags="-s -w" -o $@ .

.PHONY: check
check:
	$(GO) vet ./...
	CGO_ENABLED=0 $(GO) build -o /dev/null .

.PHONY: install
install: mailctl
	install -o root -g root -m 0750 mailctl $(PREFIX)/mailctl
	install -d -m 0755 $(ZSHCOMP)
	install -o root -g root -m 0644 _mailctl $(ZSHCOMP)/_mailctl

.PHONY: clean
clean:
	rm -f mailctl
